Fix native image capture code and DALi image saving
[platform/core/uifw/dali-adaptor.git] / platform-abstractions / tizen / image-loaders / loader-png.cpp
index d6d6273..7d19b56 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2014 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2015 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.
@@ -236,6 +236,13 @@ bool LoadBitmapFromPng( const ResourceLoadingClient& client, const ImageLoader::
   {
     switch(colordepth)
     {
+      case 1:
+      {
+        pixelFormat = Pixel::LA88;
+        valid = true;
+        break;
+      }
+
       case 2:
       case 4:
       case 8:
@@ -320,7 +327,6 @@ struct AutoPngWrite
   : png(_png),
     info(_info)
   {
-    DALI_ASSERT_DEBUG(&_png != 0 && &_info != 0);
   }
 
   ~AutoPngWrite()
@@ -347,30 +353,31 @@ namespace
    * */
   extern "C" void WriteData(png_structp png_ptr, png_bytep data, png_size_t length)
   {
-    using Dali::TizenPlatform::PngBuffer;
     DALI_ASSERT_DEBUG(png_ptr && data);
     if(!png_ptr || !data)
     {
       return;
     }
     // Make sure we don't try to propagate a C++ exception up the call stack of a pure C library:
-    try {
+    try
+    {
       // Recover our buffer for writing into:
-      PngBuffer* const encoded_img = (PngBuffer*) png_get_io_ptr(png_ptr);
+      Vector<unsigned char>* const encoded_img = static_cast< Vector<unsigned char>* >( png_get_io_ptr(png_ptr) );
       if(encoded_img)
       {
-        const PngBuffer::size_type bufferSize = encoded_img->size();
-        encoded_img->resize(encoded_img->size() + length); //< Can throw OOM.
-        PngBuffer::value_type* const bufferBack = &((*encoded_img)[bufferSize]);
+        const Vector<unsigned char>::SizeType bufferSize = encoded_img->Count();
+        encoded_img->Resize( bufferSize + length ); //< Can throw OOM.
+        unsigned char* const bufferBack = encoded_img->Begin() + bufferSize;
         memcpy(bufferBack, data, length);
       }
       else
       {
-        DALI_LOG_ERROR("PNG buffer for write to memory was passed from libpng as null.");
+        DALI_LOG_ERROR("PNG buffer for write to memory was passed from libpng as null.\n");
       }
-    } catch(...)
+    }
+    catch(...)
     {
-      DALI_LOG_ERROR("C++ Exception caught");
+      DALI_LOG_ERROR("C++ Exception caught\n");
     }
   }
 
@@ -395,7 +402,7 @@ namespace
  * 7. If caller asks for no compression, bypass libpng and blat raw data to
  *    disk, topped and tailed with header/tail blocks.
  */
-bool EncodeToPng( const unsigned char* const pixelBuffer, PngBuffer& encodedPixels, std::size_t width, std::size_t height, Pixel::Format pixelFormat )
+bool EncodeToPng( const unsigned char* const pixelBuffer, Vector<unsigned char>& encodedPixels, std::size_t width, std::size_t height, Pixel::Format pixelFormat )
 {
   // Translate pixel format enum:
   int pngPixelFormat = -1;
@@ -424,7 +431,7 @@ bool EncodeToPng( const unsigned char* const pixelBuffer, PngBuffer& encodedPixe
     }
     default:
     {
-      DALI_LOG_ERROR( "Unsupported pixel format for encoding to PNG." );
+      DALI_LOG_ERROR( "Unsupported pixel format for encoding to PNG.\n" );
       return false;
     }
   }
@@ -455,7 +462,7 @@ bool EncodeToPng( const unsigned char* const pixelBuffer, PngBuffer& encodedPixe
 
   // Since we are going to write to memory instead of a file, lets provide
   // libpng with a custom write function and ask it to pass back our
-  // std::vector buffer each time it calls back to flush data to "file":
+  // Vector buffer each time it calls back to flush data to "file":
   png_set_write_fn(png_ptr, &encodedPixels, WriteData, FlushData);
 
   // png_set_compression_level( png_ptr, Z_BEST_COMPRESSION);