From 019b0a2750ab389bf26575caf8cbf832b64bc64b Mon Sep 17 00:00:00 2001 From: YoungJun Cho Date: Thu, 5 Sep 2019 19:06:04 +0900 Subject: [PATCH] tbm_surface_internal: Removes avoidable malloc() for png dump This patch removes avoidable malloc() for png dump. Change-Id: I7e64c7b5d14f752aa5c209138cefad9fe2f6bb3a Signed-off-by: YoungJun Cho --- src/tbm_surface_internal.c | 40 ++++------------------------------------ 1 file changed, 4 insertions(+), 36 deletions(-) diff --git a/src/tbm_surface_internal.c b/src/tbm_surface_internal.c index 4cc186f..532d51f 100644 --- a/src/tbm_surface_internal.c +++ b/src/tbm_surface_internal.c @@ -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); -- 2.7.4