[4.0] Exposing Exif Image metadata
[platform/core/uifw/dali-adaptor.git] / platform-abstractions / tizen / image-loaders / loader-bmp.cpp
index 37f3c26..1ab158a 100644 (file)
 #include "loader-bmp.h"
 
 #include <dali/public-api/common/vector-wrapper.h>
+#include <adaptors/devel-api/adaptor-framework/pixel-buffer.h>
 #include <dali/integration-api/debug.h>
-#include <dali/integration-api/bitmap.h>
-
-#include <cstdlib>
 
 namespace Dali
 {
-using Integration::Bitmap;
-using Dali::Integration::PixelBuffer;
+
 namespace TizenPlatform
 {
 
@@ -130,7 +127,7 @@ bool LoadBmpHeader(FILE *fp, unsigned int &width, unsigned int &height, BmpFileH
  * @return true, if decode successful, false otherwise
  */
 bool DecodeRGB24V5(FILE *fp,
-                   PixelBuffer *pixels,
+                   unsigned char* pixels,
                    unsigned int width,
                    unsigned int height,
                    unsigned int offset,
@@ -151,7 +148,7 @@ bool DecodeRGB24V5(FILE *fp,
 
   for(unsigned int yPos = 0; yPos < height; yPos ++)
   {
-    PixelBuffer *pixelsPtr = NULL;
+    unsigned char* pixelsPtr = NULL;
     if(topDown)
     {
       pixelsPtr = pixels + ( yPos * rowStride);
@@ -197,7 +194,7 @@ bool DecodeRGB24V5(FILE *fp,
  * @return true, if decode successful, false otherwise
  */
 bool DecodeBF32V4(FILE *fp,
-                  PixelBuffer *pixels,
+                  unsigned char* pixels,
                   unsigned int width,
                   unsigned int height,
                   unsigned int offset,
@@ -218,7 +215,7 @@ bool DecodeBF32V4(FILE *fp,
 
   for(unsigned int yPos = 0; yPos < height; yPos ++)
   {
-    PixelBuffer *pixelsPtr = NULL;
+    unsigned char* pixelsPtr = NULL;
     if(topDown)
     {
       pixelsPtr = pixels + ( yPos * rowStride);
@@ -264,7 +261,7 @@ bool DecodeBF32V4(FILE *fp,
  * @return true, if decode successful, false otherwise
  */
 bool DecodeBF32(FILE *fp,
-                PixelBuffer *pixels,
+                unsigned char* pixels,
                 unsigned int width,
                 unsigned int height,
                 unsigned int offset,
@@ -285,7 +282,7 @@ bool DecodeBF32(FILE *fp,
 
   for (unsigned int yPos = 0; yPos < height; yPos++)
   {
-    PixelBuffer *pixelsPtr;
+    unsigned char* pixelsPtr;
     if (topDown)
     {
       // the data in the file is top down, and we store the data top down
@@ -332,7 +329,7 @@ bool DecodeBF32(FILE *fp,
  * @return true, if decode successful, false otherwise
  */
 bool DecodeBF565(FILE *fp,
-                 PixelBuffer *pixels,
+                 unsigned char* pixels,
                  unsigned int width,
                  unsigned int height,
                  unsigned int offset,
@@ -354,7 +351,7 @@ bool DecodeBF565(FILE *fp,
 
   for(unsigned int i = 0; i < height; i++)
   {
-    PixelBuffer *pixelsPtr = NULL;
+    unsigned char* pixelsPtr = NULL;
     if (topDown)
     {
       // the data in the file is top down, and we store the data top down
@@ -385,7 +382,7 @@ bool DecodeBF565(FILE *fp,
  * @return true, if decode successful, false otherwise
  */
 bool DecodeBF555(FILE *fp,
-                 PixelBuffer *pixels,
+                 unsigned char* pixels,
                  unsigned int width,
                  unsigned int height,
                  unsigned int offset,
@@ -421,7 +418,7 @@ bool DecodeBF555(FILE *fp,
 
   for (unsigned int yPos = 0; yPos < height; yPos++)
   {
-    PixelBuffer *pixelsPtr = NULL;
+    unsigned char* pixelsPtr = NULL;
     if (topDown)
     {
       // the data in the file is top down, and we store the data top down
@@ -455,7 +452,7 @@ bool DecodeBF555(FILE *fp,
  * @return true, if decode successful, false otherwise
  */
 bool DecodeRGB555(FILE *fp,
-                  PixelBuffer *pixels,
+                  unsigned char* pixels,
                   unsigned int width,
                   unsigned int height,
                   unsigned int offset,
@@ -488,7 +485,7 @@ bool DecodeRGB555(FILE *fp,
   }
   for(unsigned int i = 0; i < height; i++)
   {
-    PixelBuffer *pixelsPtr = NULL;
+    unsigned char* pixelsPtr = NULL;
     if (topDown)
     {
       // the data in the file is top down, and we store the data top down
@@ -522,7 +519,7 @@ bool DecodeRGB555(FILE *fp,
  * @return true, if decode successful, false otherwise
  */
 bool DecodeRGB1(FILE *fp,
-                PixelBuffer *pixels,
+                unsigned char* pixels,
                 unsigned int width,
                 unsigned int height,
                 unsigned int offset,
@@ -570,7 +567,7 @@ bool DecodeRGB1(FILE *fp,
 
   for(unsigned int index = 0; index < height; index = index + 1)
   {
-    PixelBuffer *pixelsPtr = NULL;
+    unsigned char* pixelsPtr = NULL;
     if (topDown)
     {
       // the data in the file is top down, and we store the data top down
@@ -615,7 +612,7 @@ bool DecodeRGB1(FILE *fp,
  * @return true, if decode successful, false otherwise
  */
 bool DecodeRGB4(FILE *fp,
-                PixelBuffer *pixels,
+                unsigned char* pixels,
                 unsigned int width,
                 unsigned int height,
                 unsigned int offset,
@@ -657,7 +654,7 @@ bool DecodeRGB4(FILE *fp,
 
   for(unsigned int index = 0; index < height; index = index + 1)
   {
-    PixelBuffer *pixelsPtr = NULL;
+    unsigned char* pixelsPtr = NULL;
     if (topDown)
     {
       // the data in the file is top down, and we store the data top down
@@ -691,7 +688,7 @@ bool DecodeRGB4(FILE *fp,
  * @return true, if decode successful, false otherwise
  */
 bool DecodeRGB8(FILE *fp,
-                PixelBuffer *pixels,
+                unsigned char* pixels,
                 unsigned int width,
                 unsigned int height,
                 unsigned int offset,
@@ -730,7 +727,7 @@ bool DecodeRGB8(FILE *fp,
   unsigned int ctIndex = 0;
   for(unsigned int index = 0; index < height; index = index + 1)
   {
-    PixelBuffer *pixelsPtr = NULL;
+    unsigned char* pixelsPtr = NULL;
     if (topDown)
     {
       // the data in the file is top down, and we store the data top down
@@ -763,7 +760,7 @@ bool DecodeRGB8(FILE *fp,
  * @return true, if decode successful, false otherwise
  */
 bool DecodeRLE4(FILE *fp,
-                PixelBuffer *pixels,
+                unsigned char* pixels,
                 unsigned int width,
                 unsigned int height,
                 unsigned int offset,
@@ -774,7 +771,7 @@ bool DecodeRLE4(FILE *fp,
     DALI_LOG_ERROR("Error decoding BMP_RLE4 format\n");
     return false;
   }
-  PixelBuffer *pixelsPtr = pixels;
+  unsigned char* pixelsPtr = pixels;
   width = ((width & 3) != 0) ? width + 4 - (width & 3) : width;
   char cmd[2];
   unsigned int cmdStride = 2;
@@ -931,7 +928,7 @@ bool DecodeRLE4(FILE *fp,
  * @return true, if decode successful, false otherwise
  */
 bool DecodeRLE8(FILE *fp,
-                PixelBuffer *pixels,
+                unsigned char* pixels,
                 unsigned int width,
                 unsigned int height,
                 unsigned int offset,
@@ -942,7 +939,7 @@ bool DecodeRLE8(FILE *fp,
     DALI_LOG_ERROR("Error decoding BMP_RLE8 format\n");
     return false;
   }
-  PixelBuffer *pixelsPtr = pixels;
+  unsigned char* pixelsPtr = pixels;
   unsigned int x = 0;
   unsigned int y = 0;
   unsigned int cmdStride = 2;
@@ -1056,9 +1053,9 @@ bool LoadBmpHeader( const ImageLoader::Input& input, unsigned int& width, unsign
   return ret;
 }
 
-bool LoadBitmapFromBmp( const ImageLoader::Input& input, Integration::Bitmap& bitmap )
+bool LoadBitmapFromBmp( const ImageLoader::Input& input, Dali::Devel::PixelBuffer& bitmap )
 {
-  DALI_ASSERT_DEBUG( bitmap.GetPackedPixelsProfile() != 0 && "Need a packed pixel bitmap to load into." );
+  //DALI_ASSERT_DEBUG( bitmap.GetPackedPixelsProfile() != 0 && "Need a packed pixel bitmap to load into." );
   FILE* const fp = input.file;
   if(fp == NULL)
   {
@@ -1199,9 +1196,11 @@ bool LoadBitmapFromBmp( const ImageLoader::Input& input, Integration::Bitmap& bi
     padding = 4 - padding;
   }
 
-  PixelBuffer *pixels =  NULL;
   int imageW = infoHeader.width;
-  int pixelBufferW = 0;
+  int pixelBufferW = infoHeader.width;
+  int pixelBufferH = infoHeader.height;
+  auto newPixelFormat = Pixel::Format::INVALID;
+
   switch(customizedFormat)
   {
   case BMP_RLE8:
@@ -1212,43 +1211,45 @@ bool LoadBitmapFromBmp( const ImageLoader::Input& input, Integration::Bitmap& bi
   case BMP_BITFIELDS555:
   {
     pixelBufferW = ((imageW & 3) != 0) ? imageW + 4 - (imageW & 3) : imageW;
-    pixels = bitmap.GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGB888, pixelBufferW, abs(infoHeader.height));
+    pixelBufferH = abs(infoHeader.height);
+    newPixelFormat = Pixel::RGB888;
     break;
   }
   case BMP_RGB1:
   {
     pixelBufferW = ((imageW & 63) != 0) ? imageW + 64 - (imageW & 63) : imageW;
-    pixels = bitmap.GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGB888, pixelBufferW, abs(infoHeader.height));
+    pixelBufferH = abs(infoHeader.height);
+    newPixelFormat = Pixel::RGB888;
     break;
   }
   case BMP_BITFIELDS32:
   case BMP_BITFIELDS32V4:
   {
-    pixels = bitmap.GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGB8888, infoHeader.width, abs(infoHeader.height));
+    pixelBufferH = abs(infoHeader.height);
+    newPixelFormat = Pixel::RGB8888;
     break;
   }
   case BMP_RGB24V5:
   {
-    pixels = bitmap.GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGB888, infoHeader.width, infoHeader.height);
+    newPixelFormat = Pixel::RGB888;
     break;
   }
   default:
     if(pixelFormat == Pixel::RGB565 )
     {
       pixelBufferW = ((imageW & 3) != 0) ? imageW + 4 - (imageW & 3) : imageW;
-      pixels = bitmap.GetPackedPixelsProfile()->ReserveBuffer(Pixel::RGB565, pixelBufferW, abs(infoHeader.height));
-    }
-    else
-    {
-      pixels = bitmap.GetPackedPixelsProfile()->ReserveBuffer(pixelFormat, infoHeader.width, infoHeader.height);
+      pixelBufferH = abs(infoHeader.height);
+      newPixelFormat = Pixel::RGB565;
     }
     break;
   }
 
-  // TODO: Add scaling support
+  bitmap = Dali::Devel::PixelBuffer::New(pixelBufferW, pixelBufferH, newPixelFormat);
+  auto pixels = bitmap.GetBuffer();
 
   // Read the raw bitmap data
-  PixelBuffer *pixelsPtr;
+  decltype(pixels) pixelsIterator = nullptr;
+
   bool decodeResult(false);
   switch(customizedFormat)
   {
@@ -1315,15 +1316,15 @@ bool LoadBitmapFromBmp( const ImageLoader::Input& input, Integration::Bitmap& bi
           if (topDown)
           {
             // the data in the file is top down, and we store the data top down
-            pixelsPtr = pixels + ( yPos * rowStride);
+            pixelsIterator = pixels + ( yPos * rowStride);
           }
           else
           {
             // the data in the file is bottom up, and we store the data top down
-            pixelsPtr = pixels + (((height-1)-yPos) * rowStride);
+            pixelsIterator = pixels + (((height-1)-yPos) * rowStride);
           }
 
-          if (fread(pixelsPtr, 1, rowStride, fp) != rowStride)
+          if (fread(pixelsIterator, 1, rowStride, fp) != rowStride)
           {
             DALI_LOG_ERROR("Error reading the BMP image\n");
             break;
@@ -1335,9 +1336,9 @@ bool LoadBitmapFromBmp( const ImageLoader::Input& input, Integration::Bitmap& bi
           {
             for(unsigned int i = 0; i < rowStride; i += 3)
             {
-              unsigned char temp = pixelsPtr[i];
-              pixelsPtr[i] = pixelsPtr[i+2];
-              pixelsPtr[i+2] = temp;
+              unsigned char temp = pixelsIterator[i];
+              pixelsIterator[i] = pixelsIterator[i+2];
+              pixelsIterator[i+2] = temp;
             }
           }