tbm_surface_internal: dump the surface with XRGB8888 36/144036/1 accepted/tizen/3.0/common/20170816.020359 accepted/tizen/3.0/ivi/20170816.020412 accepted/tizen/3.0/mobile/20170816.020344 accepted/tizen/3.0/wearable/20170816.020403 accepted/tizen/unified/20170816.053834 submit/tizen/20170814.110412 submit/tizen_3.0/20170814.110416
authorSooChan Lim <sc1.lim@samsung.com>
Mon, 14 Aug 2017 10:45:24 +0000 (19:45 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Mon, 14 Aug 2017 10:47:17 +0000 (19:47 +0900)
Change-Id: Idfeda3ca90a475edabbb4b7bdb83b5074a15c7cb

src/tbm_surface_internal.c

index e03570d..896d649 100644 (file)
@@ -1551,11 +1551,11 @@ _tbm_surface_internal_dump_file_raw(const char *file, void *data1, int size1,
 }
 
 static void
-_tbm_surface_internal_dump_file_png(const char *file, const void *data, int width, int height)
+_tbm_surface_internal_dump_file_png(const char *file, const void *data, int width, int height, int format)
 {
        unsigned int *blocks = (unsigned int *)data;
        FILE *fp;
-       const int pixel_size = 4;       // RGBA
+       int pixel_size;
        png_bytep *row_pointers;
        int depth = 8, y;
 
@@ -1582,14 +1582,27 @@ _tbm_surface_internal_dump_file_png(const char *file, const void *data, int widt
        }
 
        png_init_io(pPngStruct, fp);
-       png_set_IHDR(pPngStruct,
-                       pPngInfo,
-                       width,
-                       height,
-                       depth,
-                       PNG_COLOR_TYPE_RGBA,
-                       PNG_INTERLACE_NONE,
-                       PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
+       if (format == TBM_FORMAT_XRGB8888) {
+               pixel_size = 3;
+               png_set_IHDR(pPngStruct,
+                               pPngInfo,
+                               width,
+                               height,
+                               depth,
+                               PNG_COLOR_TYPE_RGB,
+                               PNG_INTERLACE_NONE,
+                               PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
+       } else {
+               pixel_size = 4;
+               png_set_IHDR(pPngStruct,
+                               pPngInfo,
+                               width,
+                               height,
+                               depth,
+                               PNG_COLOR_TYPE_RGBA,
+                               PNG_INTERLACE_NONE,
+                               PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
+       }
 
        png_set_bgr(pPngStruct);
        png_write_info(pPngStruct, pPngInfo);
@@ -1621,10 +1634,16 @@ _tbm_surface_internal_dump_file_png(const char *file, const void *data, int widt
                for (x = 0; x < width; ++x) {
                        unsigned int curBlock = blocks[y * width + x];
 
-                       row[x * pixel_size] = (curBlock & 0xFF);
-                       row[1 + x * pixel_size] = (curBlock >> 8) & 0xFF;
-                       row[2 + x * pixel_size] = (curBlock >> 16) & 0xFF;
-                       row[3 + x * pixel_size] = (curBlock >> 24) & 0xFF;
+                       if (pixel_size == 3) { // XRGB8888
+                               row[x * pixel_size] = (curBlock & 0xFF);
+                               row[1 + x * pixel_size] = (curBlock >> 8) & 0xFF;
+                               row[2 + x * pixel_size] = (curBlock >> 16) & 0xFF;
+                       } else { // ARGB8888
+                               row[x * pixel_size] = (curBlock & 0xFF);
+                               row[1 + x * pixel_size] = (curBlock >> 8) & 0xFF;
+                               row[2 + x * pixel_size] = (curBlock >> 16) & 0xFF;
+                               row[3 + x * pixel_size] = (curBlock >> 24) & 0xFF;
+                       }
                }
        }
 
@@ -1785,10 +1804,14 @@ tbm_surface_internal_dump_end(void)
 
                        switch (buf_info->info.format) {
                        case TBM_FORMAT_ARGB8888:
+                               _tbm_surface_internal_dump_file_png(file, bo_handle.ptr,
+                                                       buf_info->info.planes[0].stride >> 2,
+                                                       buf_info->info.height, TBM_FORMAT_ARGB8888);
+                               break;
                        case TBM_FORMAT_XRGB8888:
                                _tbm_surface_internal_dump_file_png(file, bo_handle.ptr,
                                                        buf_info->info.planes[0].stride >> 2,
-                                                       buf_info->info.height);
+                                                       buf_info->info.height, TBM_FORMAT_XRGB8888);
                                break;
                        case TBM_FORMAT_YVU420:
                        case TBM_FORMAT_YUV420:
@@ -1823,7 +1846,7 @@ tbm_surface_internal_dump_end(void)
                } else if (buf_info->dirty_shm)
                        _tbm_surface_internal_dump_file_png(file, bo_handle.ptr,
                                                        buf_info->shm_stride >> 2,
-                                                       buf_info->shm_h);
+                                                       buf_info->shm_h, 0);
 
                tbm_bo_unmap(buf_info->bo);
                tbm_bo_unref(buf_info->bo);
@@ -2251,10 +2274,14 @@ tbm_surface_internal_capture_buffer(tbm_surface_h surface, const char *path, con
 
        switch (info.format) {
        case TBM_FORMAT_ARGB8888:
+               _tbm_surface_internal_dump_file_png(file, info.planes[0].ptr,
+                                                       info.planes[0].stride >> 2,
+                                                       info.height, TBM_FORMAT_ARGB8888);
+               break;
        case TBM_FORMAT_XRGB8888:
                _tbm_surface_internal_dump_file_png(file, info.planes[0].ptr,
                                                        info.planes[0].stride >> 2,
-                                                       info.height);
+                                                       info.height, TBM_FORMAT_XRGB8888);
                break;
        case TBM_FORMAT_YVU420:
        case TBM_FORMAT_YUV420:
@@ -2311,13 +2338,13 @@ tbm_surface_internal_capture_shm_buffer(void *ptr, int w, int h, int stride,
        }
 
        if (!access(file, 0)) {
-               TBM_LOG_E("can't capture buffer, exist file %s", file);
+               TBM_LOG_E("can't capture buffer, exist file %sTBM_FORMAT_XRGB8888", file);
                return 0;
        }
 
        snprintf(file, sizeof(file), "%s/%s.%s", path , name, dump_postfix[0]);
 
-       _tbm_surface_internal_dump_file_png(file, ptr, stride, h);
+       _tbm_surface_internal_dump_file_png(file, ptr, stride, h, 0);
 
        TBM_TRACE("Capture %s \n", file);