X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=automated-tests%2Fsrc%2Fdali-adaptor-internal%2Fimage-loaders.cpp;h=faebbf319820d57b2a3f0520f39eefc981028bce;hb=761f75cd51351b7a4e072130f4a2ad0b3e3231bb;hp=f1e083618eb328f90145f80a3e6c1dd2c64cac8d;hpb=c7c8fee632a3133b9599237247a07c8c3391b4c5;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 f1e0836..faebbf3 100644 --- a/automated-tests/src/dali-adaptor-internal/image-loaders.cpp +++ b/automated-tests/src/dali-adaptor-internal/image-loaders.cpp @@ -1,21 +1,23 @@ -// -// Copyright (c) 2014 Samsung Electronics Co., Ltd. -// -// Licensed under the Flora License, Version 1.0 (the License); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// http://floralicense.org/license/ -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an AS IS BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// +/* + * Copyright (c) 2018 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. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ #include "image-loaders.h" #include +#include AutoCloseFile::AutoCloseFile( FILE *fp ) : filePtr( fp ) @@ -37,8 +39,8 @@ ImageDetails::ImageDetails( const char * const _name, unsigned int _width, unsig height( _height ), reportedWidth( _width ), reportedHeight( _height ), - refBufferSize( _width * _height ), - refBuffer( new Dali::PixelBuffer[ refBufferSize ] ) + refBufferSize( 0u ), + refBuffer( nullptr ) { LoadBuffer(); } @@ -49,27 +51,33 @@ ImageDetails::ImageDetails( const char * const _name, unsigned int _width, unsig height( _height ), reportedWidth( _reportedWidth ), reportedHeight( _reportedHeight ), - refBufferSize( _width * _height ), - refBuffer( new Dali::PixelBuffer[ refBufferSize ] ) + 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 ); if ( fp ) { + fseek( fp, 0, SEEK_END ); + refBufferSize = ftell( fp ); + fseek( fp, 0, SEEK_SET ); + refBuffer = reinterpret_cast( malloc( refBufferSize ) ); fread( refBuffer, sizeof( Dali::PixelBuffer ), refBufferSize, fp ); } } @@ -81,7 +89,7 @@ LoadFunctions::LoadFunctions( LoadBitmapHeaderFunction _header, LoadBitmapFuncti { } -void TestImageLoading( const ImageDetails& image, const LoadFunctions& functions ) +void TestImageLoading( const ImageDetails& image, const LoadFunctions& functions, Dali::Integration::Bitmap::Profile bitmapProfile ) { FILE* fp = fopen( image.name.c_str() , "rb" ); AutoCloseFile autoClose( fp ); @@ -90,8 +98,8 @@ void TestImageLoading( const ImageDetails& image, const LoadFunctions& functions // Check the header file. unsigned int width(0), height(0); - Dali::ImageAttributes attributes; - DALI_TEST_CHECK( functions.header( fp, attributes, width, height ) ); + const Dali::TizenPlatform::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 ); @@ -99,18 +107,15 @@ void TestImageLoading( const ImageDetails& image, const LoadFunctions& functions // 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 ); - + Dali::Devel::PixelBuffer 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 ); + 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* bufferPtr( bitmap.GetBuffer() ); Dali::PixelBuffer* refBufferPtr( image.refBuffer ); for ( unsigned int i = 0; i < image.refBufferSize; ++i, ++bufferPtr, ++refBufferPtr ) { @@ -123,20 +128,67 @@ void TestImageLoading( const ImageDetails& image, const LoadFunctions& functions } } +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 ); + + // 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 ) ); + + 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 ); + + Dali::Devel::PixelBuffer bitmap; + + // Load Bitmap and check its return values. + 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 ); + + // Compare buffer generated with reference buffer. + Dali::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 ) + { + 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 ) + { + color = ( color << 8 ) | *pBitmapData; + } + + // Check the color value is what we expect. + DALI_TEST_EQUALS( color, *pMaster, TEST_LOCATION ); + } +} + 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::Devel::PixelBuffer bitmap; + const Dali::TizenPlatform::ImageLoader::Input input( fp ); - DALI_TEST_CHECK( functions.loader( fp, *bitmap, attributes ) ); + DALI_TEST_CHECK( functions.loader( input, bitmap ) ); - Dali::PixelBuffer* bufferPtr( bitmapPtr->GetBuffer() ); + Dali::PixelBuffer* bufferPtr( bitmap.GetBuffer() ); FILE* writeFp = fopen( targetFilename.c_str(), "wb" ); AutoCloseFile autoCloseWrite( writeFp ); - fwrite( bufferPtr, sizeof( Dali::PixelBuffer ), attributes.GetWidth() * attributes.GetHeight(), writeFp ); + auto& impl = GetImplementation(bitmap); + fwrite( bufferPtr, 1, impl.GetBufferSize(), writeFp ); }