X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-adaptor-internal%2Fimage-loaders.cpp;h=843cb92f8b91dd3d91ee0064135e0f181768d2ad;hb=97568a209c309d5f99bf288afa951a77f7fdcddd;hp=a5fd26eaaa3ec7db390a5fa76478662f0d5ea794;hpb=929a307639e847b44d0c3d23f90798ab7ecc96ee;p=platform%2Fcore%2Fuifw%2Fdali-adaptor.git diff --git a/automated-tests/src/dali-adaptor-internal/image-loaders.cpp b/automated-tests/src/dali-adaptor-internal/image-loaders.cpp index a5fd26e..843cb92 100644 --- a/automated-tests/src/dali-adaptor-internal/image-loaders.cpp +++ b/automated-tests/src/dali-adaptor-internal/image-loaders.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2016 Samsung Electronics Co., Ltd. + * Copyright (c) 2020 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -17,176 +17,176 @@ #include "image-loaders.h" #include +#include - -AutoCloseFile::AutoCloseFile( FILE *fp ) -: filePtr( fp ) +AutoCloseFile::AutoCloseFile(FILE* fp) +: filePtr(fp) { } AutoCloseFile::~AutoCloseFile() { - if ( filePtr ) + if(filePtr) { - fclose( filePtr ); + fclose(filePtr); } } - -ImageDetails::ImageDetails( const char * const _name, unsigned int _width, unsigned int _height ) -: name( _name ), - width( _width ), - height( _height ), - reportedWidth( _width ), - reportedHeight( _height ), - refBufferSize( _width * _height ), - refBuffer( new Dali::PixelBuffer[ refBufferSize ] ) +ImageDetails::ImageDetails(const char* const _name, unsigned int _width, unsigned int _height) +: name(_name), + width(_width), + height(_height), + reportedWidth(_width), + reportedHeight(_height), + refBufferSize(0u), + refBuffer(nullptr) { LoadBuffer(); } -ImageDetails::ImageDetails( const char * const _name, unsigned int _width, unsigned int _height, unsigned int _reportedWidth, unsigned int _reportedHeight ) -: name( _name ), - width( _width ), - height( _height ), - reportedWidth( _reportedWidth ), - reportedHeight( _reportedHeight ), - refBufferSize( _width * _height ), - refBuffer( new Dali::PixelBuffer[ refBufferSize ] ) +ImageDetails::ImageDetails(const char* const _name, unsigned int _width, unsigned int _height, unsigned int _reportedWidth, unsigned int _reportedHeight) +: name(_name), + width(_width), + height(_height), + reportedWidth(_reportedWidth), + reportedHeight(_reportedHeight), + refBufferSize(0u), + refBuffer(nullptr) { LoadBuffer(); } ImageDetails::~ImageDetails() { - delete [] refBuffer; + if(refBuffer) + { + delete[] refBuffer; + } } void ImageDetails::LoadBuffer() { // Load the reference buffer from the buffer file + std::string refBufferFilename(name + ".buffer"); + FILE* fp = fopen(refBufferFilename.c_str(), "rb"); + AutoCloseFile autoCloseBufferFile(fp); - std::string refBufferFilename( name + ".buffer" ); - FILE *fp = fopen ( refBufferFilename.c_str(), "rb" ); - AutoCloseFile autoCloseBufferFile( fp ); - - if ( fp ) + if(fp) { - fread( refBuffer, sizeof( Dali::PixelBuffer ), refBufferSize, fp ); + fseek(fp, 0, SEEK_END); + refBufferSize = ftell(fp); + fseek(fp, 0, SEEK_SET); + refBuffer = reinterpret_cast(malloc(refBufferSize)); + fread(refBuffer, sizeof(Dali::Integration::PixelBuffer), refBufferSize, fp); } } - -LoadFunctions::LoadFunctions( LoadBitmapHeaderFunction _header, LoadBitmapFunction _loader ) -: header( _header ), - loader( _loader ) +LoadFunctions::LoadFunctions(LoadBitmapHeaderFunction _header, LoadBitmapFunction _loader) +: header(_header), + loader(_loader) { } -void TestImageLoading( const ImageDetails& image, const LoadFunctions& functions, Dali::Integration::Bitmap::Profile bitmapProfile ) +void TestImageLoading(const ImageDetails& image, const LoadFunctions& functions, Dali::Integration::Bitmap::Profile bitmapProfile) { - FILE* fp = fopen( image.name.c_str() , "rb" ); - AutoCloseFile autoClose( fp ); - DALI_TEST_CHECK( fp != NULL ); + 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); - const Dali::TizenPlatform::ImageLoader::Input input( fp ); - DALI_TEST_CHECK( functions.header( input, width, height ) ); + unsigned int width(0), height(0); + const Dali::ImageLoader::Input input(fp); + DALI_TEST_CHECK(functions.header(input, width, height)); - DALI_TEST_EQUALS( width, image.reportedWidth, TEST_LOCATION ); - DALI_TEST_EQUALS( height, image.reportedHeight, TEST_LOCATION ); + 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 ); + 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( bitmapProfile, ResourcePolicy::OWNED_RETAIN ); - Dali::Integration::BitmapPtr bitmapPtr( bitmap ); + Dali::Devel::PixelBuffer bitmap; // Load Bitmap and check its return values. - DALI_TEST_CHECK( functions.loader( input, *bitmap ) ); - DALI_TEST_EQUALS( image.width, bitmap->GetImageWidth(), TEST_LOCATION ); - DALI_TEST_EQUALS( image.height, bitmap->GetImageHeight(), TEST_LOCATION ); + DALI_TEST_CHECK(functions.loader(input, bitmap)); + DALI_TEST_EQUALS(image.width, bitmap.GetWidth(), TEST_LOCATION); + DALI_TEST_EQUALS(image.height, bitmap.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 ) + Dali::Integration::PixelBuffer* bufferPtr(bitmap.GetBuffer()); + Dali::Integration::PixelBuffer* refBufferPtr(image.refBuffer); + for(unsigned int i = 0; i < image.refBufferSize; ++i, ++bufferPtr, ++refBufferPtr) { - if( *bufferPtr != *refBufferPtr ) + if(*bufferPtr != *refBufferPtr) { - tet_result( TET_FAIL ); + tet_result(TET_FAIL); tet_printf("%s Failed in %s at line %d\n", __PRETTY_FUNCTION__, __FILE__, __LINE__); break; } } } -void CompareLoadedImageData( const ImageDetails& image, const LoadFunctions& functions, const uint32_t* master ) +void CompareLoadedImageData(const ImageDetails& image, const LoadFunctions& functions, const uint32_t* master) { - FILE* filePointer = fopen( image.name.c_str() , "rb" ); - AutoCloseFile autoClose( filePointer ); - DALI_TEST_CHECK( filePointer != NULL ); + FILE* filePointer = fopen(image.name.c_str(), "rb"); + AutoCloseFile autoClose(filePointer); + DALI_TEST_CHECK(filePointer != NULL); // Check the header file. - unsigned int width = 0, height = 0; - const Dali::TizenPlatform::ImageLoader::Input input( filePointer ); - DALI_TEST_CHECK( functions.header( input, width, height ) ); + unsigned int width = 0, height = 0; + const Dali::ImageLoader::Input input(filePointer); + DALI_TEST_CHECK(functions.header(input, width, height)); - DALI_TEST_EQUALS( width, image.reportedWidth, TEST_LOCATION ); - DALI_TEST_EQUALS( height, image.reportedHeight, TEST_LOCATION ); + 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( filePointer, 0, SEEK_SET ); + fseek(filePointer, 0, SEEK_SET); - // 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, ResourcePolicy::OWNED_RETAIN ); - Dali::Integration::BitmapPtr bitmapPointer( bitmap ); + Dali::Devel::PixelBuffer bitmap; // Load Bitmap and check its return values. - DALI_TEST_CHECK( functions.loader( input, *bitmap ) ); - DALI_TEST_EQUALS( image.width, bitmap->GetImageWidth(), TEST_LOCATION ); - DALI_TEST_EQUALS( image.height, bitmap->GetImageHeight(), TEST_LOCATION ); + DALI_TEST_CHECK(functions.loader(input, bitmap)); + DALI_TEST_EQUALS(image.width, bitmap.GetWidth(), TEST_LOCATION); + DALI_TEST_EQUALS(image.height, bitmap.GetHeight(), TEST_LOCATION); // Check the bytes per pixel. - const Pixel::Format pixelFormat = bitmap->GetPixelFormat(); - const unsigned int bytesPerPixel = Pixel::GetBytesPerPixel( pixelFormat ); + const Pixel::Format pixelFormat = bitmap.GetPixelFormat(); + const unsigned int bytesPerPixel = Pixel::GetBytesPerPixel(pixelFormat); // Compare buffer generated with reference buffer. - Dali::PixelBuffer* pBitmapData( bitmapPointer->GetBuffer() ); - const uint32_t* pMaster( master ); + Dali::Integration::PixelBuffer* pBitmapData(bitmap.GetBuffer()); + const uint32_t* pMaster(master); // Loop through each pixel in the bitmap. - for ( unsigned int i = 0; i < image.refBufferSize; ++i, ++pMaster ) + for(unsigned int i = 0; i < image.refBufferSize; ++i, ++pMaster) { unsigned int color = 0; // Loop through each byte per pixel, to build up a color value for that pixel. - for( unsigned int j = 0; j < bytesPerPixel; ++j, ++pBitmapData ) + for(unsigned int j = 0; j < bytesPerPixel; ++j, ++pBitmapData) { - color = ( color << 8 ) | *pBitmapData; + color = (color << 8) | *pBitmapData; } // Check the color value is what we expect. - DALI_TEST_EQUALS( color, *pMaster, TEST_LOCATION ); + DALI_TEST_EQUALS(color, *pMaster, TEST_LOCATION); } } -void DumpImageBufferToTempFile( std::string filename, std::string targetFilename, const LoadFunctions& functions ) +void DumpImageBufferToTempFile(std::string filename, std::string targetFilename, const LoadFunctions& functions) { - FILE* fp = fopen( filename.c_str() , "rb" ); - AutoCloseFile autoClose( fp ); + 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, ResourcePolicy::OWNED_RETAIN ); - Dali::Integration::BitmapPtr bitmapPtr( bitmap ); - const Dali::TizenPlatform::ImageLoader::Input input( fp ); + Dali::Devel::PixelBuffer bitmap; + const Dali::ImageLoader::Input input(fp); - DALI_TEST_CHECK( functions.loader( input, *bitmap ) ); + DALI_TEST_CHECK(functions.loader(input, bitmap)); - Dali::PixelBuffer* bufferPtr( bitmapPtr->GetBuffer() ); + Dali::Integration::PixelBuffer* bufferPtr(bitmap.GetBuffer()); - FILE* writeFp = fopen( targetFilename.c_str(), "wb" ); - AutoCloseFile autoCloseWrite( writeFp ); - fwrite( bufferPtr, 1, bitmap->GetBufferSize(), writeFp ); + FILE* writeFp = fopen(targetFilename.c_str(), "wb"); + AutoCloseFile autoCloseWrite(writeFp); + auto& impl = GetImplementation(bitmap); + fwrite(bufferPtr, 1, impl.GetBufferSize(), writeFp); }