}
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;
}
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);
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;
+ }
}
}
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:
} 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);
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:
}
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);