RenderObjectPtr<Bitmap> RenderObject::addDynamicBitmap(uint width, uint height) { RenderObjectPtr<Bitmap> bitmapPtr((new DynamicBitmap(this->getHandle(), width, height))->getHandle()); if (bitmapPtr.isValid() && bitmapPtr->getInitSuccess()) return bitmapPtr; else { if (bitmapPtr.isValid()) bitmapPtr.erase(); return RenderObjectPtr<Bitmap>(); } }
RenderObjectPtr<Bitmap> RenderObject::addBitmap(const Common::String &filename) { RenderObjectPtr<Bitmap> bitmapPtr((new StaticBitmap(this->getHandle(), filename))->getHandle()); if (bitmapPtr.isValid() && bitmapPtr->getInitSuccess()) return RenderObjectPtr<Bitmap>(bitmapPtr); else { if (bitmapPtr.isValid()) bitmapPtr.erase(); return RenderObjectPtr<Bitmap>(); } }
void DumpImageBufferToTempFile( std::string filename, std::string targetFilename, const LoadFunctions& functions ) { FILE* fp = fopen( filename.c_str() , "rb" ); AutoCloseFile autoClose( fp ); Dali::Integration::Bitmap* bitmap = Dali::Integration::Bitmap::New( Dali::Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false ); Dali::Integration::BitmapPtr bitmapPtr( bitmap ); Dali::ImageAttributes attributes; DALI_TEST_CHECK( functions.loader( fp, *bitmap, attributes ) ); Dali::PixelBuffer* bufferPtr( bitmapPtr->GetBuffer() ); FILE* writeFp = fopen( targetFilename.c_str(), "wb" ); AutoCloseFile autoCloseWrite( writeFp ); fwrite( bufferPtr, sizeof( Dali::PixelBuffer ), attributes.GetWidth() * attributes.GetHeight(), writeFp ); }
void TestImageLoading( const ImageDetails& image, const LoadFunctions& functions ) { FILE* fp = fopen( image.name.c_str() , "rb" ); AutoCloseFile autoClose( fp ); DALI_TEST_CHECK( fp != NULL ); // Check the header file. unsigned int width(0), height(0); Dali::ImageAttributes attributes; DALI_TEST_CHECK( functions.header( fp, attributes, width, height ) ); DALI_TEST_EQUALS( width, image.reportedWidth, TEST_LOCATION ); DALI_TEST_EQUALS( height, image.reportedHeight, TEST_LOCATION ); // Loading the header moves the pointer within the file so reset to start of file. fseek( fp, 0, 0 ); // Create a bitmap object and store a pointer to that object so it is destroyed at the end. Dali::Integration::Bitmap * bitmap = Dali::Integration::Bitmap::New( Dali::Integration::Bitmap::BITMAP_2D_PACKED_PIXELS, false ); Dali::Integration::BitmapPtr bitmapPtr( bitmap ); // Load Bitmap and check its return values. DALI_TEST_CHECK( functions.loader( fp, *bitmap, attributes ) ); DALI_TEST_EQUALS( image.width, attributes.GetWidth(), TEST_LOCATION ); DALI_TEST_EQUALS( image.height, attributes.GetHeight(), TEST_LOCATION ); // Compare buffer generated with reference buffer. Dali::PixelBuffer* bufferPtr( bitmapPtr->GetBuffer() ); Dali::PixelBuffer* refBufferPtr( image.refBuffer ); for ( unsigned int i = 0; i < image.refBufferSize; ++i, ++bufferPtr, ++refBufferPtr ) { if( *bufferPtr != *refBufferPtr ) { tet_result( TET_FAIL ); tet_printf("%s Failed in %s at line %d\n", __PRETTY_FUNCTION__, __FILE__, __LINE__); break; } } }