--- /dev/null
+#ifndef __DALI_TEST_IMG_UTILS_H__
+#define __DALI_TEST_IMG_UTILS_H__
+
+/*
+ * Copyright (c) 2017 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.
+ *
+ */
+
+// EXTERNAL INCLUDES
+#include <cstdarg>
+#include <cstdio>
+#include <iostream>
+#include <cstring>
+
+// INTERNAL INCLUDES
+#include <dali/dali.h>
+#include <dali/devel-api/adaptor-framework/image-loading.h>
+#include <dali/public-api/dali-core.h>
+
+
+using namespace Dali;
+
+namespace
+{
+
+/**
+ * Test whether two buffers are equal with tolerance value.
+ * @param[in] buffer1 The first buffer
+ * @param[in] buffer2 The second pixelbuffer
+ * @param[in] tolerance value, maximum difference to accept the similarity of buffers.
+ * @param[in] location The TEST_LOCATION macro should be used here
+ */
+
+inline void DALI_TEST_EQUALS( const unsigned char* buffer1, const unsigned char* buffer2, unsigned int tolerance, long size, const char* location)
+{
+ if( !tolerance )
+ {
+ if ( memcmp( buffer1, buffer2, size) )
+ {
+ fprintf(stderr, "%s, checking buffer1 == buffer2\n", location );
+ tet_result(TET_FAIL);
+ }
+ else
+ {
+ tet_result(TET_PASS);
+ }
+ }
+ else
+ {
+ const unsigned char* buff1 = buffer1;
+ const unsigned char* buff2 = buffer2;
+ unsigned int i = 0;
+ //Create a mask to fast compare, it is expected to be similar values.
+ unsigned int maskBits = 0;
+ while( maskBits < tolerance )
+ {
+ maskBits |= (1 << i);
+ i++;
+ }
+ maskBits &= ~(1 << --i);
+ maskBits = ~maskBits;
+
+ bool equal = true;
+ for( i = 0; i < size; ++i, ++buff1, ++buff2 )
+ {
+ //Check bit difference, if exist, do more exhaustive comparison with tolerance value
+ if( (*buff1 ^ *buff2 ) & maskBits )
+ {
+ if( *buff1 < *buff2 )
+ {
+ unsigned int diff = *buff2 - *buff1;
+ if( diff > tolerance )
+ {
+ equal = false;
+ break;
+ }
+ }
+ else
+ {
+ unsigned int diff = *buff1 - *buff2;
+ if( diff > tolerance )
+ {
+ equal = false;
+ break;
+ }
+ }
+ }
+ }
+ if ( !equal )
+ {
+ fprintf(stderr, "%s, byte %d, checking %u == %u\n", location, i, *buff1, *buff2 );
+ tet_result(TET_FAIL);
+ }
+ else
+ {
+ tet_result(TET_PASS);
+ }
+ }
+}
+
+/**
+ * Test whether two pixelbuffers are equal with tolerance value, with check of width and height.
+ * @param[in] pixelBuffer1 The first buffer
+ * @param[in] pixelBuffer2 The second pixelbuffer
+ * @param[in] tolerance value, maximum difference to accept the similarity of pixel buffers.
+ * @param[in] location The TEST_LOCATION macro should be used here
+ */
+
+inline void DALI_IMAGE_TEST_EQUALS( Dali::Devel::PixelBuffer pixelBuffer1, Dali::Devel::PixelBuffer pixelBuffer2, unsigned int tolerance, const char* location)
+{
+ if( ( pixelBuffer1.GetPixelFormat() != Pixel::RGB888 ) || ( pixelBuffer2.GetPixelFormat() != Pixel::RGB888 ) )
+ {
+ fprintf(stderr, "%s, PixelFormat != Pixel::RGB888, test only support Pixel::RGB888 formats\n", location );
+ tet_result(TET_FAIL);
+ }
+ else if( ( pixelBuffer1.GetWidth() != pixelBuffer1.GetWidth() ) || ( pixelBuffer1.GetHeight() != pixelBuffer1.GetHeight() ) )
+ {
+ fprintf(stderr, "%s, Different Image sizes\n", location );
+ tet_result(TET_FAIL);
+ }
+ else
+ {
+ DALI_TEST_EQUALS( pixelBuffer1.GetBuffer(), pixelBuffer2.GetBuffer(), tolerance, pixelBuffer1.GetHeight() * pixelBuffer1.GetWidth() * 3, location);
+ }
+}
+
+}
+
+#endif // __DALI_TEST_SUITE_UTILS_H__
#include <stdlib.h>
#include <dali/dali.h>
#include <dali-test-suite-utils.h>
+#include <dali-test-img-utils.h>
#include <dali/devel-api/adaptor-framework/image-loading.h>
using namespace Dali;
namespace
{
// resolution: 34*34, pixel format: RGBA8888
-static const char* gImage_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
+const char* IMAGE_34_RGBA = TEST_RESOURCE_DIR "/icon-edit.png";
// resolution: 128*128, pixel format: RGB888
-static const char* gImage_128_RGB = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
+const char* IMAGE_128_RGB = TEST_RESOURCE_DIR "/gallery-small-1.jpg";
+
+// resolution: 2000*2560, pixel format: RGB888
+const char* IMAGE_LARGE_EXIF3_RGB = TEST_RESOURCE_DIR "/f-large-exif-3.jpg";
+
+// resolution: 55*64, pixel format: RGB888
+const char* IMAGE_WIDTH_ODD_EXIF1_RGB = TEST_RESOURCE_DIR "/f-odd-exif-1.jpg";
+// resolution: 55*64, pixel format: RGB888
+const char* IMAGE_WIDTH_ODD_EXIF2_RGB = TEST_RESOURCE_DIR "/f-odd-exif-2.jpg";
+// resolution: 55*64, pixel format: RGB888
+const char* IMAGE_WIDTH_ODD_EXIF3_RGB = TEST_RESOURCE_DIR "/f-odd-exif-3.jpg";
+// resolution: 55*64, pixel format: RGB888
+const char* IMAGE_WIDTH_ODD_EXIF4_RGB = TEST_RESOURCE_DIR "/f-odd-exif-4.jpg";
+// resolution: 55*64, pixel format: RGB888
+const char* IMAGE_WIDTH_ODD_EXIF5_RGB = TEST_RESOURCE_DIR "/f-odd-exif-5.jpg";
+// resolution: 55*64, pixel format: RGB888
+const char* IMAGE_WIDTH_ODD_EXIF6_RGB = TEST_RESOURCE_DIR "/f-odd-exif-6.jpg";
+// resolution: 55*64, pixel format: RGB888
+const char* IMAGE_WIDTH_ODD_EXIF7_RGB = TEST_RESOURCE_DIR "/f-odd-exif-7.jpg";
+// resolution: 55*64, pixel format: RGB888
+const char* IMAGE_WIDTH_ODD_EXIF8_RGB = TEST_RESOURCE_DIR "/f-odd-exif-8.jpg";
+
+// resolution: 50*64, pixel format: RGB888
+const char* IMAGE_WIDTH_EVEN_EXIF1_RGB = TEST_RESOURCE_DIR "/f-even-exif-1.jpg";
+// resolution: 50*64, pixel format: RGB888
+const char* IMAGE_WIDTH_EVEN_EXIF2_RGB = TEST_RESOURCE_DIR "/f-even-exif-2.jpg";
+// resolution: 50*64, pixel format: RGB888
+const char* IMAGE_WIDTH_EVEN_EXIF3_RGB = TEST_RESOURCE_DIR "/f-even-exif-3.jpg";
+// resolution: 50*64, pixel format: RGB888
+const char* IMAGE_WIDTH_EVEN_EXIF4_RGB = TEST_RESOURCE_DIR "/f-even-exif-4.jpg";
+// resolution: 50*64, pixel format: RGB888
+const char* IMAGE_WIDTH_EVEN_EXIF5_RGB = TEST_RESOURCE_DIR "/f-even-exif-5.jpg";
+// resolution: 50*64, pixel format: RGB888
+const char* IMAGE_WIDTH_EVEN_EXIF6_RGB = TEST_RESOURCE_DIR "/f-even-exif-6.jpg";
+// resolution: 50*64, pixel format: RGB888
+const char* IMAGE_WIDTH_EVEN_EXIF7_RGB = TEST_RESOURCE_DIR "/f-even-exif-7.jpg";
+// resolution: 50*64, pixel format: RGB888
+const char* IMAGE_WIDTH_EVEN_EXIF8_RGB = TEST_RESOURCE_DIR "/f-even-exif-8.jpg";
+
// this is image is not exist, for negative test
-static const char* gImageNonExist = "non-exist.jpg";
+const char* IMAGENONEXIST = "non-exist.jpg";
}
void utc_dali_load_image_startup(void)
int UtcDaliLoadImageP(void)
{
- Devel::PixelBuffer pixelBuffer = Dali::LoadImageFromFile( gImage_34_RGBA );
+ Devel::PixelBuffer pixelBuffer = Dali::LoadImageFromFile( IMAGE_34_RGBA );
DALI_TEST_CHECK( pixelBuffer );
DALI_TEST_EQUALS( pixelBuffer.GetWidth(), 34u, TEST_LOCATION );
DALI_TEST_EQUALS( pixelBuffer.GetHeight(), 34u, TEST_LOCATION );
DALI_TEST_EQUALS( pixelBuffer.GetPixelFormat(), Pixel::RGBA8888, TEST_LOCATION );
- Devel::PixelBuffer pixelBuffer2 = Dali::LoadImageFromFile( gImage_128_RGB );
+ Devel::PixelBuffer pixelBuffer2 = Dali::LoadImageFromFile( IMAGE_128_RGB );
DALI_TEST_CHECK( pixelBuffer2 );
DALI_TEST_EQUALS( pixelBuffer2.GetWidth(), 128u, TEST_LOCATION );
DALI_TEST_EQUALS( pixelBuffer2.GetHeight(), 128u, TEST_LOCATION );
DALI_TEST_EQUALS( pixelBuffer2.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION );
+ Devel::PixelBuffer pixelBufferJpeg = Dali::LoadImageFromFile( IMAGE_LARGE_EXIF3_RGB );
+ DALI_TEST_CHECK( pixelBufferJpeg );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetWidth(), 2000u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetHeight(), 2560u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION );
+
+ Devel::PixelBuffer BufferJpeg1 = Dali::LoadImageFromFile( IMAGE_WIDTH_ODD_EXIF1_RGB );
+ DALI_TEST_CHECK( BufferJpeg1 );
+ DALI_TEST_EQUALS( BufferJpeg1.GetWidth(), 55u, TEST_LOCATION );
+ DALI_TEST_EQUALS( BufferJpeg1.GetHeight(), 64u, TEST_LOCATION );
+ DALI_TEST_EQUALS( BufferJpeg1.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION );
+
+ pixelBufferJpeg = Dali::LoadImageFromFile( IMAGE_WIDTH_ODD_EXIF2_RGB );
+ DALI_TEST_CHECK( pixelBufferJpeg );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetWidth(), 55u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetHeight(), 64u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION );
+ DALI_IMAGE_TEST_EQUALS( BufferJpeg1, pixelBufferJpeg, 8, TEST_LOCATION);
+
+ pixelBufferJpeg = Dali::LoadImageFromFile( IMAGE_WIDTH_ODD_EXIF3_RGB );
+ DALI_TEST_CHECK( pixelBufferJpeg );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetWidth(), 55u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetHeight(), 64u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION );
+ DALI_IMAGE_TEST_EQUALS( BufferJpeg1, pixelBufferJpeg, 8, TEST_LOCATION);
+
+ pixelBufferJpeg = Dali::LoadImageFromFile( IMAGE_WIDTH_ODD_EXIF4_RGB );
+ DALI_TEST_CHECK( pixelBufferJpeg );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetWidth(), 55u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetHeight(), 64u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION );
+ DALI_IMAGE_TEST_EQUALS( BufferJpeg1, pixelBufferJpeg, 8, TEST_LOCATION);
+
+ pixelBufferJpeg = Dali::LoadImageFromFile( IMAGE_WIDTH_ODD_EXIF5_RGB );
+ DALI_TEST_CHECK( pixelBufferJpeg );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetWidth(), 55u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetHeight(), 64u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION );
+ DALI_IMAGE_TEST_EQUALS( BufferJpeg1, pixelBufferJpeg, 8, TEST_LOCATION);
+
+ pixelBufferJpeg = Dali::LoadImageFromFile( IMAGE_WIDTH_ODD_EXIF6_RGB );
+ DALI_TEST_CHECK( pixelBufferJpeg );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetWidth(), 55u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetHeight(), 64u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION );
+ DALI_IMAGE_TEST_EQUALS( BufferJpeg1, pixelBufferJpeg, 8, TEST_LOCATION);
+
+ pixelBufferJpeg = Dali::LoadImageFromFile( IMAGE_WIDTH_ODD_EXIF7_RGB );
+ DALI_TEST_CHECK( pixelBufferJpeg );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetWidth(), 55u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetHeight(), 64u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION );
+ DALI_IMAGE_TEST_EQUALS( BufferJpeg1, pixelBufferJpeg, 8, TEST_LOCATION);
+
+ pixelBufferJpeg = Dali::LoadImageFromFile( IMAGE_WIDTH_ODD_EXIF8_RGB );
+ DALI_TEST_CHECK( pixelBufferJpeg );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetWidth(), 55u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetHeight(), 64u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION );
+ DALI_IMAGE_TEST_EQUALS( BufferJpeg1, pixelBufferJpeg, 8, TEST_LOCATION);
+
+ BufferJpeg1 = Dali::LoadImageFromFile( IMAGE_WIDTH_EVEN_EXIF1_RGB );
+ DALI_TEST_CHECK( BufferJpeg1 );
+ DALI_TEST_EQUALS( BufferJpeg1.GetWidth(), 50u, TEST_LOCATION );
+ DALI_TEST_EQUALS( BufferJpeg1.GetHeight(), 64u, TEST_LOCATION );
+ DALI_TEST_EQUALS( BufferJpeg1.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION );
+
+ pixelBufferJpeg = Dali::LoadImageFromFile( IMAGE_WIDTH_EVEN_EXIF2_RGB );
+ DALI_TEST_CHECK( pixelBufferJpeg );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetWidth(), 50u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetHeight(), 64u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION );
+ DALI_IMAGE_TEST_EQUALS( BufferJpeg1, pixelBufferJpeg, 8, TEST_LOCATION);
+
+ pixelBufferJpeg = Dali::LoadImageFromFile( IMAGE_WIDTH_EVEN_EXIF3_RGB );
+ DALI_TEST_CHECK( pixelBufferJpeg );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetWidth(), 50u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetHeight(), 64u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION );
+ DALI_IMAGE_TEST_EQUALS( BufferJpeg1, pixelBufferJpeg, 8, TEST_LOCATION);
+
+ pixelBufferJpeg = Dali::LoadImageFromFile( IMAGE_WIDTH_EVEN_EXIF4_RGB );
+ DALI_TEST_CHECK( pixelBufferJpeg );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetWidth(), 50u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetHeight(), 64u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION );
+ DALI_IMAGE_TEST_EQUALS( BufferJpeg1, pixelBufferJpeg, 8, TEST_LOCATION);
+
+ pixelBufferJpeg = Dali::LoadImageFromFile( IMAGE_WIDTH_EVEN_EXIF5_RGB );
+ DALI_TEST_CHECK( pixelBufferJpeg );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetWidth(), 50u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetHeight(), 64u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION );
+ DALI_IMAGE_TEST_EQUALS( BufferJpeg1, pixelBufferJpeg, 8, TEST_LOCATION);
+
+ pixelBufferJpeg = Dali::LoadImageFromFile( IMAGE_WIDTH_EVEN_EXIF6_RGB );
+ DALI_TEST_CHECK( pixelBufferJpeg );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetWidth(), 50u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetHeight(), 64u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION );
+ DALI_IMAGE_TEST_EQUALS( BufferJpeg1, pixelBufferJpeg, 8, TEST_LOCATION);
+
+ pixelBufferJpeg = Dali::LoadImageFromFile( IMAGE_WIDTH_EVEN_EXIF7_RGB );
+ DALI_TEST_CHECK( pixelBufferJpeg );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetWidth(), 50u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetHeight(), 64u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION );
+ DALI_IMAGE_TEST_EQUALS( BufferJpeg1, pixelBufferJpeg, 8, TEST_LOCATION);
+
+ pixelBufferJpeg = Dali::LoadImageFromFile( IMAGE_WIDTH_EVEN_EXIF8_RGB );
+ DALI_TEST_CHECK( pixelBufferJpeg );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetWidth(), 50u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetHeight(), 64u, TEST_LOCATION );
+ DALI_TEST_EQUALS( pixelBufferJpeg.GetPixelFormat(), Pixel::RGB888, TEST_LOCATION );
+ DALI_IMAGE_TEST_EQUALS( BufferJpeg1, pixelBufferJpeg, 8, TEST_LOCATION);
+
END_TEST;
}
int UtcDaliLoadImageN(void)
{
- Devel::PixelBuffer pixelBuffer = Dali::LoadImageFromFile( gImageNonExist );
+ Devel::PixelBuffer pixelBuffer = Dali::LoadImageFromFile( IMAGENONEXIST );
DALI_TEST_CHECK( !pixelBuffer );
END_TEST;
int UtcDaliDownloadImageP(void)
{
std::string url("file://");
- url.append( gImage_34_RGBA );
+ url.append( IMAGE_34_RGBA );
std::string url2("file://");
- url2.append( gImage_128_RGB );
+ url2.append( IMAGE_128_RGB );
Devel::PixelBuffer pixelBuffer = Dali::DownloadImageSynchronously( url );
DALI_TEST_CHECK( pixelBuffer );
int UtcDaliDownloadImageN(void)
{
- Devel::PixelBuffer pixelBuffer = Dali::DownloadImageSynchronously( gImageNonExist );
+ Devel::PixelBuffer pixelBuffer = Dali::DownloadImageSynchronously( IMAGENONEXIST );
DALI_TEST_CHECK( !pixelBuffer );
END_TEST;
struct RGB888Type
{
- char R;
- char G;
- char B;
+ unsigned char R;
+ unsigned char G;
+ unsigned char B;
};
/**
const int MAX_TEXTURE_HEIGHT = 4096;
} // namespace
-
-bool JpegRotate90 (unsigned char *buffer, int width, int height, int bpp);
-bool JpegRotate180(unsigned char *buffer, int width, int height, int bpp);
-bool JpegRotate270(unsigned char *buffer, int width, int height, int bpp);
+bool JpegFlipV( RGB888Type *buffer, int width, int height );
+bool JpegFlipH( RGB888Type *buffer, int width, int height );
+bool JpegTranspose( RGB888Type *buffer, int width, int height );
+bool JpegTransverse( RGB888Type *buffer, int width, int height );
+bool JpegRotate90 ( RGB888Type *buffer, int width, int height );
+bool JpegRotate180( RGB888Type *buffer, int width, int height );
+bool JpegRotate270( RGB888Type *buffer, int width, int height );
JPGFORM_CODE ConvertExifOrientation(ExifData* exifData);
bool TransformSize( int requiredWidth, int requiredHeight,
FittingMode::Type fittingMode, SamplingMode::Type samplingMode,
// Allocate a bitmap and decompress the jpeg buffer into its pixel buffer:
- unsigned char * const bitmapPixelBuffer = bitmap.GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGB888, scaledPostXformWidth, scaledPostXformHeight);
+ RGB888Type * bitmapPixelBuffer = reinterpret_cast<RGB888Type*>( bitmap.GetPackedPixelsProfile()->ReserveBuffer( Pixel::RGB888, scaledPostXformWidth, scaledPostXformHeight ) );
- if( tjDecompress2( autoJpg.GetHandle(), jpegBufferPtr, jpegBufferSize, bitmapPixelBuffer, scaledPreXformWidth, 0, scaledPreXformHeight, DECODED_PIXEL_LIBJPEG_TYPE, flags ) == -1 )
+ if( tjDecompress2( autoJpg.GetHandle(), jpegBufferPtr, jpegBufferSize, reinterpret_cast<unsigned char*>( bitmapPixelBuffer ), scaledPreXformWidth, 0, scaledPreXformHeight, DECODED_PIXEL_LIBJPEG_TYPE, flags ) == -1 )
{
std::string errorString = tjGetErrorStr();
if( IsJpegErrorFatal( errorString ) )
{
- DALI_LOG_ERROR("%s\n", errorString.c_str());
+ DALI_LOG_ERROR("%s\n", errorString.c_str() );
return false;
}
else
{
- DALI_LOG_WARNING("%s\n", errorString.c_str());
+ DALI_LOG_WARNING("%s\n", errorString.c_str() );
}
}
// 3 orientation changes for a camera held perpendicular to the ground or upside-down:
case JPGFORM_ROT_180:
{
- result = JpegRotate180(bitmapPixelBuffer, bufferWidth, bufferHeight, DECODED_PIXEL_SIZE);
+ result = JpegRotate180( bitmapPixelBuffer, bufferWidth, bufferHeight );
break;
}
case JPGFORM_ROT_270:
{
- result = JpegRotate270(bitmapPixelBuffer, bufferWidth, bufferHeight, DECODED_PIXEL_SIZE);
+ result = JpegRotate270( bitmapPixelBuffer, bufferWidth, bufferHeight );
break;
}
case JPGFORM_ROT_90:
{
- result = JpegRotate90(bitmapPixelBuffer, bufferWidth, bufferHeight, DECODED_PIXEL_SIZE);
+ result = JpegRotate90( bitmapPixelBuffer, bufferWidth, bufferHeight );
+ break;
+ }
+ case JPGFORM_FLIP_V:
+ {
+ result = JpegFlipV( bitmapPixelBuffer, bufferWidth, bufferHeight );
break;
}
/// Less-common orientation changes, since they don't correspond to a camera's
// physical orientation:
case JPGFORM_FLIP_H:
- case JPGFORM_FLIP_V:
+ {
+ result = JpegFlipH( bitmapPixelBuffer, bufferWidth, bufferHeight );
+ break;
+ }
case JPGFORM_TRANSPOSE:
+ {
+ result = JpegTranspose( bitmapPixelBuffer, bufferWidth, bufferHeight );
+ break;
+ }
case JPGFORM_TRANSVERSE:
{
+ result = JpegTransverse( bitmapPixelBuffer, bufferWidth, bufferHeight );
+ break;
+ }
+ default:
+ {
DALI_LOG_WARNING( "Unsupported JPEG Orientation transformation: %x.\n", transform );
break;
}
return result;
}
-///@Todo: Move all these rotation functions to portable/image-operations and take "Jpeg" out of their names.
-bool JpegRotate90(unsigned char *buffer, int width, int height, int bpp)
+bool JpegFlipV(RGB888Type *buffer, int width, int height )
{
- int w, iw, ih, hw = 0;
- int ix, iy = 0;
- iw = width;
- ih = height;
- Vector<unsigned char> data;
- data.Resize(width * height * bpp);
- unsigned char *dataPtr = data.Begin();
- memcpy(dataPtr, buffer, width * height * bpp);
- w = ih;
- ih = iw;
- iw = w;
- hw = iw * ih;
- hw = - hw - 1;
- switch(bpp)
+ int bwidth = width;
+ int bheight = height;
+ //Destination pixel, set as the first pixel of screen
+ RGB888Type* to = buffer;
+ //Source pixel, as the image is flipped horizontally and vertically,
+ //the source pixel is the end of the buffer of size bwidth * bheight
+ RGB888Type* from = buffer + bwidth * bheight - 1;
+ RGB888Type temp;
+ unsigned int endLoop = ( bwidth * bheight ) / 2;
+
+ for(unsigned ix = 0; ix < endLoop; ++ ix, ++ to, -- from )
{
- case 3:
- {
- RGB888Type* to = reinterpret_cast<RGB888Type*>(buffer) + iw - 1;
- RGB888Type* from = reinterpret_cast<RGB888Type*>( dataPtr );
+ temp = *from;
+ *from = *to;
+ *to = temp;
+ }
- for(ix = iw; -- ix >= 0;)
- {
- for(iy = ih; -- iy >= 0; ++from )
- {
- *to = *from;
- to += iw;
- }
- to += hw;
- }
- break;
- }
+ return true;
+}
- default:
+bool JpegFlipH(RGB888Type *buffer, int width, int height )
+{
+ int ix, iy;
+ int bwidth = width;
+ int bheight = height;
+
+ RGB888Type* to;
+ RGB888Type* from;
+ RGB888Type temp;
+
+ for(iy = 0; iy < bheight; iy ++)
+ {
+ //Set the destination pixel as the beginning of the row
+ to = buffer + bwidth * iy;
+ //Set the source pixel as the end of the row to flip in X axis
+ from = buffer + bwidth * (iy + 1) - 1;
+ for(ix = 0; ix < bwidth / 2; ix ++ , ++ to, -- from )
{
- return false;
+ temp = *from;
+ *from = *to;
+ *to = temp;
}
}
-
return true;
}
-bool JpegRotate180(unsigned char *buffer, int width, int height, int bpp)
+bool JpegTranspose( RGB888Type *buffer, int width, int height )
{
- int ix, iw, ih, hw = 0;
- iw = width;
- ih = height;
- hw = iw * ih;
- ix = hw;
+ int ix, iy;
+ int bwidth = width;
+ int bheight = height;
- switch(bpp)
+ RGB888Type* to;
+ RGB888Type* from;
+ RGB888Type temp;
+ //Flip vertically only
+ for(iy = 0; iy < bheight / 2; iy ++)
{
- case 3:
+ for(ix = 0; ix < bwidth; ix ++)
{
- RGB888Type tmp;
- RGB888Type* to = reinterpret_cast<RGB888Type*>(buffer) ;
- RGB888Type* from = reinterpret_cast<RGB888Type*>( buffer ) + hw - 1;
- for(; --ix >= (hw / 2); ++to, --from)
- {
- tmp = *to;
- *to = *from;
- *from = tmp;
- }
- break;
+ to = buffer + iy * bwidth + ix;
+ from = buffer + (bheight - 1 - iy) * bwidth + ix;
+ temp = *from;
+ *from = *to;
+ *to = temp;
}
+ }
- default:
+ return true;
+}
+
+bool JpegTransverse( RGB888Type *buffer, int width, int height )
+{
+ int bwidth = width;
+ int bheight = height;
+ Vector<RGB888Type> data;
+ data.Resize( bwidth * bheight );
+ RGB888Type *dataPtr = data.Begin();
+ memcpy(dataPtr, buffer, bwidth * bheight * DECODED_PIXEL_SIZE );
+
+ RGB888Type* to = buffer;
+ RGB888Type* from;
+ for( int iy = 0; iy < bwidth; iy++ )
+ {
+ for( int ix = 0; ix < bheight; ix++ )
{
- return false;
+ from = dataPtr + ix * bwidth + iy;
+ *to = *from;
+ to ++;
}
}
return true;
}
-bool JpegRotate270(unsigned char *buffer, int width, int height, int bpp)
+///@Todo: Move all these rotation functions to portable/image-operations and take "Jpeg" out of their names.
+bool JpegRotate90(RGB888Type *buffer, int width, int height )
{
- int w, iw, ih, hw = 0;
+ int w, hw = 0;
int ix, iy = 0;
+ int bwidth = width;
+ int bheight = height;
+ Vector<RGB888Type> data;
+ data.Resize(width * height);
+ RGB888Type *dataPtr = data.Begin();
+ memcpy(dataPtr, buffer, width * height * DECODED_PIXEL_SIZE );
+ w = bheight;
+ bheight = bwidth;
+ bwidth = w;
+ hw = bwidth * bheight;
+ hw = - hw - 1;
- iw = width;
- ih = height;
- Vector<unsigned char> data;
- data.Resize(width * height * bpp);
- unsigned char *dataPtr = data.Begin();
- memcpy(dataPtr, buffer, width * height * bpp);
- w = ih;
- ih = iw;
- iw = w;
- hw = iw * ih;
+ RGB888Type* to = buffer + bwidth - 1;
+ RGB888Type* from = dataPtr;
- switch(bpp)
+ for(ix = bwidth; -- ix >= 0;)
{
- case 3:
+ for(iy = bheight; -- iy >= 0; ++from )
{
- RGB888Type* to = reinterpret_cast<RGB888Type*>(buffer) + hw - iw;
- RGB888Type* from = reinterpret_cast<RGB888Type*>( dataPtr );
+ *to = *from;
+ to += bwidth;
+ }
+ to += hw;
+ }
- w = -w;
- hw = hw + 1;
- for(ix = iw; -- ix >= 0;)
- {
- for(iy = ih; -- iy >= 0;)
- {
- *to = *from;
- from += 1;
- to += w;
- }
- to += hw;
- }
- break;
+ return true;
+}
+
+bool JpegRotate180( RGB888Type *buffer, int width, int height )
+{
+ int bwidth = width;
+ int bheight = height;
+ Vector<RGB888Type> data;
+ data.Resize( bwidth * bheight );
+ RGB888Type *dataPtr = data.Begin();
+ memcpy(dataPtr, buffer, bwidth * bheight * DECODED_PIXEL_SIZE );
+
+ RGB888Type* to = buffer;
+ RGB888Type* from;
+ for( int iy = 0; iy < bwidth; iy++ )
+ {
+ for( int ix = 0; ix < bheight; ix++ )
+ {
+ from = dataPtr + ( bheight - ix) * bwidth - 1 - iy;
+ *to = *from;
+ to ++;
}
- default:
+ }
+
+ return true;
+}
+
+bool JpegRotate270( RGB888Type *buffer, int width, int height )
+{
+ int w, hw = 0;
+ int ix, iy = 0;
+
+ int bwidth = width;
+ int bheight = height;
+ Vector<RGB888Type> data;
+ data.Resize( width * height );
+ RGB888Type *dataPtr = data.Begin();
+ memcpy(dataPtr, buffer, width * height * DECODED_PIXEL_SIZE );
+ w = bheight;
+ bheight = bwidth;
+ bwidth = w;
+ hw = bwidth * bheight;
+
+ RGB888Type* to = buffer + hw - bwidth;
+ RGB888Type* from = dataPtr;
+
+ w = -w;
+ hw = hw + 1;
+ for(ix = bwidth; -- ix >= 0;)
+ {
+ for(iy = bheight; -- iy >= 0;)
{
- return false;
+ *to = *from;
+ from ++;
+ to += w;
}
+ to += hw;
}
return true;
{
bool success = true;
- if( transform == JPGFORM_ROT_90 || transform == JPGFORM_ROT_270 )
+ if( transform == JPGFORM_ROT_90 || transform == JPGFORM_ROT_270 || transform == JPGFORM_ROT_180 || transform == JPGFORM_TRANSVERSE)
{
std::swap( requiredWidth, requiredHeight );
std::swap( postXformImageWidth, postXformImageHeight );