From: SooChan Lim Date: Mon, 14 Aug 2017 10:45:24 +0000 (+0900) Subject: tbm_surface_internal: dump the surface with XRGB8888 X-Git-Tag: accepted/tizen/3.0/common/20170816.020359^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c986f39678a5dcb45da9b833ff6cece6512344ac;p=platform%2Fcore%2Fuifw%2Flibtbm.git tbm_surface_internal: dump the surface with XRGB8888 Change-Id: Idfeda3ca90a475edabbb4b7bdb83b5074a15c7cb --- diff --git a/src/tbm_surface_internal.c b/src/tbm_surface_internal.c index e03570d..896d649 100644 --- a/src/tbm_surface_internal.c +++ b/src/tbm_surface_internal.c @@ -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);