Debug Patch: Save received indicator images to disk as BMP 88/86488/6
authorTom Robinson <tom.robinson@samsung.com>
Thu, 1 Sep 2016 09:40:01 +0000 (10:40 +0100)
committerTom Robinson <tom.robinson@samsung.com>
Wed, 28 Sep 2016 10:55:30 +0000 (11:55 +0100)
Change-Id: I31c59ae79065be213810642d1b60d497b984e92c

adaptors/ecore/common/ecore-indicator-impl.cpp

index 7d4bb4b..7465444 100644 (file)
 #include <unistd.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <iomanip>
+#include <fstream>
 
 #include <dali/public-api/images/native-image.h>
 #include <dali/public-api/events/touch-event.h>
 #include <dali/public-api/events/touch-point.h>
 #include <dali/public-api/common/stage.h>
 #include <dali/public-api/images/buffer-image.h>
+#include <dali/public-api/images/pixel.h>
 
 #include <dali/integration-api/debug.h>
 
@@ -278,6 +281,59 @@ struct IpcDataEvMouseOut
   }
 };
 
+#ifdef ENABLE_INDICATOR_IMAGE_SAVING
+
+void SaveIndicatorImage( Dali::NativeImageSourcePtr nativeImageSource )
+{
+  // Save image data to disk in BMP form.
+  static int gFilenameCounter = 0;
+  static const char bmpHeader[] = {
+      0x42, 0x4d, 0x0a, 0xcb, 0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x8a, 0x00, 0x00, 0x00, 0x7c, 0x00,
+      0x00, 0x00,
+      0xe0, 0x01, 0x00, 0x00, // Width  (480)
+      0x1b, 0x00, 0x00, 0x00, // Height ( 27)
+      0x01, 0x00, 0x20, 0x00, 0x03, 0x00,
+      0x00, 0x00, 0x80, 0xca, 0x00, 0x00, 0x13, 0x0b,  0x00, 0x00, 0x13, 0x0b, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  0x00, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
+      0x00, 0x00, 0xff, 0x00, 0x00, 0x00, 0x42, 0x47,  0x52, 0x73, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00,
+      0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  0x00, 0x00
+    };
+
+  // This is a BMP header with width & height hard-coded in.
+  // The data was first determined by dumping the raw data and inspecting in GIMP, before creating this header data.
+  std::vector<unsigned char> buffer;
+  unsigned int w = 0;
+  unsigned int h = 0;
+  Dali::Pixel::Format pixelFormat;
+  if( nativeImageSource->GetPixels( buffer, w, h, pixelFormat ) )
+  {
+    int imageSize = w * h * 4;
+    std::stringstream fileName;
+    // Give each file an incremental filename.
+    fileName << "/opt/usr/media/Images/out-" << std::setfill( '0' ) << std::setw( 5 ) << gFilenameCounter << ".bmp";
+
+    std::ofstream outfile( fileName.str().c_str(), std::ofstream::binary );
+    if( outfile.is_open() )
+    {
+      DALI_LOG_WARNING( "Saving Indicator Image w:%d, h:%d, %s\n", w, h, fileName.str().c_str() );
+
+      outfile.write( bmpHeader, sizeof( bmpHeader ) / sizeof( bmpHeader[0] ) ); // Size of the BMP header.
+      outfile.write( (const char*)buffer.data(), imageSize );
+      outfile.close();
+      gFilenameCounter++;
+    }
+    else
+    {
+      DALI_LOG_ERROR( "COULD NOT OPEN FOR SAVING: %s\n", fileName.str().c_str() );
+    }
+  }
+}
+
+#endif
+
 } // anonymous namespace
 
 
@@ -1088,6 +1144,10 @@ void Indicator::CreateNewPixmapImage()
   DALI_LOG_TRACE_METHOD_FMT( gIndicatorLogFilter, "W:%d H:%d", mImageWidth, mImageHeight );
   Dali::NativeImageSourcePtr nativeImageSource = Dali::NativeImageSource::New( mPixmap );
 
+#ifdef ENABLE_INDICATOR_IMAGE_SAVING
+  SaveIndicatorImage( nativeImageSource );
+#endif
+
   if( nativeImageSource )
   {
     Dali::Texture texture = Dali::Texture::New( *nativeImageSource );