7 #include <tbm_surface.h>
8 #include <tbm_surface_internal.h>
12 #include "tdm_private.h"
16 int tdm_helper_drm_fd = -1;
18 static const char *dump_prefix[2] = {"png", "yuv"};
21 _tdm_helper_dump_raw(const char *file, void *data1, int size1, void *data2,
22 int size2, void *data3, int size3)
25 FILE *fp = fopen(file, "w+");
26 TDM_RETURN_IF_FAIL(fp != NULL);
28 blocks = (unsigned int*)data1;
29 fwrite(blocks, 1, size1, fp);
33 blocks = (unsigned int*)data2;
34 fwrite(blocks, 1, size2, fp);
39 blocks = (unsigned int*)data3;
40 fwrite(blocks, 1, size3, fp);
47 _tdm_helper_dump_png(const char *file, const void *data, int width,
50 FILE *fp = fopen(file, "wb");
51 TDM_RETURN_IF_FAIL(fp != NULL);
53 png_structp pPngStruct =
54 png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
61 png_infop pPngInfo = png_create_info_struct(pPngStruct);
64 png_destroy_write_struct(&pPngStruct, NULL);
69 png_init_io(pPngStruct, fp);
70 png_set_IHDR(pPngStruct,
77 PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
79 png_set_bgr(pPngStruct);
80 png_write_info(pPngStruct, pPngInfo);
82 const int pixel_size = 4; // RGBA
83 png_bytep *row_pointers =
84 png_malloc(pPngStruct, height * sizeof(png_byte*));
86 unsigned int *blocks = (unsigned int*)data;
90 for (; y < height; ++y)
93 png_malloc(pPngStruct, sizeof(png_byte) * width * pixel_size);
94 row_pointers[y] = (png_bytep)row;
95 for (x = 0; x < width; ++x)
97 unsigned int curBlock = blocks[y * width + x];
98 row[x * pixel_size] = (curBlock & 0xFF);
99 row[1 + x * pixel_size] = (curBlock >> 8) & 0xFF;
100 row[2 + x * pixel_size] = (curBlock >> 16) & 0xFF;
101 row[3 + x * pixel_size] = (curBlock >> 24) & 0xFF;
105 png_write_image(pPngStruct, row_pointers);
106 png_write_end(pPngStruct, pPngInfo);
108 for (y = 0; y < height; y++)
109 png_free(pPngStruct, row_pointers[y]);
110 png_free(pPngStruct, row_pointers);
112 png_destroy_write_struct(&pPngStruct, &pPngInfo);
118 tdm_helper_dump_buffer(tbm_surface_h buffer, const char *file)
120 tbm_surface_info_s info;
124 TDM_RETURN_IF_FAIL(buffer != NULL);
125 TDM_RETURN_IF_FAIL(file != NULL);
127 tbm_surface_get_info(buffer, &info);
129 len = strnlen(file, 1024);
130 if (info.format == TBM_FORMAT_ARGB8888 || info.format == TBM_FORMAT_XRGB8888)
131 prefix = dump_prefix[0];
133 prefix = dump_prefix[1];
135 if (strncmp(file + (len - 3), prefix, 3))
137 TDM_ERR("can't dump to '%s' file", file + (len - 3));
143 case TBM_FORMAT_ARGB8888:
144 case TBM_FORMAT_XRGB8888:
145 _tdm_helper_dump_png(file, info.planes[0].ptr,
146 info.planes[0].stride >> 2, info.height);
148 case TBM_FORMAT_YVU420:
149 case TBM_FORMAT_YUV420:
150 _tdm_helper_dump_raw(file,
151 info.planes[0].ptr + info.planes[0].offset,
152 info.planes[0].stride * info.height,
153 info.planes[1].ptr + info.planes[1].offset,
154 info.planes[1].stride * (info.height >> 1),
155 info.planes[2].ptr + info.planes[2].offset,
156 info.planes[2].stride * (info.height >> 1));
158 case TBM_FORMAT_NV12:
159 case TBM_FORMAT_NV21:
160 _tdm_helper_dump_raw(file,
161 info.planes[0].ptr + info.planes[0].offset,
162 info.planes[0].stride * info.height,
163 info.planes[1].ptr + info.planes[1].offset,
164 info.planes[1].stride * (info.height >> 1), NULL,
167 case TBM_FORMAT_YUYV:
168 case TBM_FORMAT_UYVY:
169 _tdm_helper_dump_raw(file,
170 info.planes[0].ptr + info.planes[0].offset,
171 info.planes[0].stride * info.height, NULL, 0,
175 TDM_ERR("can't dump %c%c%c%c buffer", FOURCC_STR (info.format));
179 TDM_INFO("dump %s", file);