tbm_surface_internal: Removes avoidable malloc() for png dump
[platform/core/uifw/libtbm.git] / src / tbm_surface_internal.c
index 4cc186f..532d51f 100644 (file)
@@ -1767,13 +1767,12 @@ _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, int format)
+_tbm_surface_internal_dump_file_png(const char *file, void *data, int width, int height, int format)
 {
-       unsigned int *blocks = (unsigned int *)data;
        FILE *fp;
        int pixel_size;
        png_bytep *row_pointers;
-       int depth = 8, y;
+       int depth = 8;
 
        if (_tbm_surface_check_file_is_symbolic_link(file))
                TBM_ERR("%s is symbolic link\n", file);
@@ -1831,43 +1830,12 @@ _tbm_surface_internal_dump_file_png(const char *file, const void *data, int widt
                return;
        }
 
-       for (y = 0; y < height; ++y) {
-               png_bytep row;
-               int x = 0;
-
-               row = png_malloc(pPngStruct, sizeof(png_byte) * width * pixel_size);
-               if (!row) {
-                       TBM_ERR("fail to allocate the png row.\n");
-                       for (x = 0; x < y; x++)
-                               png_free(pPngStruct, row_pointers[x]);
-                       png_free(pPngStruct, row_pointers);
-                       png_destroy_write_struct(&pPngStruct, &pPngInfo);
-                       fclose(fp);
-                       return;
-               }
-               row_pointers[y] = (png_bytep)row;
-
-               for (x = 0; x < width; ++x) {
-                       unsigned int curBlock = blocks[y * width + x];
-
-                       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;
-                       }
-               }
-       }
+       for (int y = 0; y < height; ++y)
+               row_pointers[y] = data + width * pixel_size * y;
 
        png_write_image(pPngStruct, row_pointers);
        png_write_end(pPngStruct, pPngInfo);
 
-       for (y = 0; y < height; y++)
-               png_free(pPngStruct, row_pointers[y]);
        png_free(pPngStruct, row_pointers);
 
        png_destroy_write_struct(&pPngStruct, &pPngInfo);