7 #include <tbm_surface.h>
8 #include <tbm_surface_internal.h>
12 #include "tdm_private.h"
16 static const char *dump_prefix[2] = {"png", "yuv"};
19 _tdm_helper_dump_raw(const char *file, void *data1, int size1, void *data2,
20 int size2, void *data3, int size3)
23 FILE *fp = fopen(file, "w+");
24 TDM_RETURN_IF_FAIL(fp != NULL);
26 blocks = (unsigned int*)data1;
27 fwrite(blocks, 1, size1, fp);
31 blocks = (unsigned int*)data2;
32 fwrite(blocks, 1, size2, fp);
37 blocks = (unsigned int*)data3;
38 fwrite(blocks, 1, size3, fp);
45 _tdm_helper_dump_png(const char *file, const void *data, int width,
48 FILE *fp = fopen(file, "wb");
49 TDM_RETURN_IF_FAIL(fp != NULL);
51 png_structp pPngStruct =
52 png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
59 png_infop pPngInfo = png_create_info_struct(pPngStruct);
62 png_destroy_write_struct(&pPngStruct, NULL);
67 png_init_io(pPngStruct, fp);
68 png_set_IHDR(pPngStruct,
75 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
77 png_set_bgr(pPngStruct);
78 png_write_info(pPngStruct, pPngInfo);
80 const int pixel_size = 4; // RGBA
81 png_bytep *row_pointers =
82 png_malloc(pPngStruct, height * sizeof(png_byte*));
84 unsigned int *blocks = (unsigned int*)data;
88 for (; y < height; ++y)
91 png_malloc(pPngStruct, sizeof(png_byte) * width * pixel_size);
92 row_pointers[y] = (png_bytep)row;
93 for (x = 0; x < width; ++x)
95 unsigned int curBlock = blocks[y * width + x];
96 row[x * pixel_size] = (curBlock & 0xFF);
97 row[1 + x * pixel_size] = (curBlock >> 8) & 0xFF;
98 row[2 + x * pixel_size] = (curBlock >> 16) & 0xFF;
99 row[3 + x * pixel_size] = (curBlock >> 24) & 0xFF;
103 png_write_image(pPngStruct, row_pointers);
104 png_write_end(pPngStruct, pPngInfo);
106 for (y = 0; y < height; y++)
107 png_free(pPngStruct, row_pointers[y]);
108 png_free(pPngStruct, row_pointers);
110 png_destroy_write_struct(&pPngStruct, &pPngInfo);
116 tdm_helper_dump_buffer(tbm_surface_h buffer, const char *file)
118 tbm_surface_info_s info;
122 TDM_RETURN_IF_FAIL(buffer != NULL);
123 TDM_RETURN_IF_FAIL(file != NULL);
125 tbm_surface_get_info(buffer, &info);
127 len = strnlen(file, 1024);
128 if (info.format == TBM_FORMAT_ARGB8888 || info.format == TBM_FORMAT_XRGB8888)
129 prefix = dump_prefix[0];
131 prefix = dump_prefix[1];
133 if (strncmp(file + (len - 3), prefix, 3))
135 TDM_ERR("can't dump to '%s' file", file + (len - 3));
141 case TBM_FORMAT_ARGB8888:
142 case TBM_FORMAT_XRGB8888:
143 _tdm_helper_dump_png(file, info.planes[0].ptr,
144 info.planes[0].stride >> 2, info.height);
146 case TBM_FORMAT_YVU420:
147 case TBM_FORMAT_YUV420:
148 _tdm_helper_dump_raw(file,
149 info.planes[0].ptr + info.planes[0].offset,
150 info.planes[0].stride * info.height,
151 info.planes[1].ptr + info.planes[1].offset,
152 info.planes[1].stride * (info.height >> 1),
153 info.planes[2].ptr + info.planes[2].offset,
154 info.planes[2].stride * (info.height >> 1));
156 case TBM_FORMAT_NV12:
157 case TBM_FORMAT_NV21:
158 _tdm_helper_dump_raw(file,
159 info.planes[0].ptr + info.planes[0].offset,
160 info.planes[0].stride * info.height,
161 info.planes[1].ptr + info.planes[1].offset,
162 info.planes[1].stride * (info.height >> 1), NULL,
165 case TBM_FORMAT_YUYV:
166 case TBM_FORMAT_UYVY:
167 _tdm_helper_dump_raw(file,
168 info.planes[0].ptr + info.planes[0].offset,
169 info.planes[0].stride * info.height, NULL, 0,
173 TDM_ERR("can't dump %c%c%c%c buffer", FOURCC_STR (info.format));
177 TDM_INFO("dump %s", file);