diff options
author | marha <marha@users.sourceforge.net> | 2012-12-05 09:14:52 +0100 |
---|---|---|
committer | marha <marha@users.sourceforge.net> | 2012-12-05 09:14:52 +0100 |
commit | e82692e521240c5f8592f9ce56c9d5b3d68870ec (patch) | |
tree | 3293b7fa02b1f5aa58b74f1fe02444085be2281e /mesalib/src/gallium/auxiliary/util/u_debug.c | |
parent | b8da71ffb17d3d16706db04115e9ba1dd8bc49b9 (diff) | |
download | vcxsrv-e82692e521240c5f8592f9ce56c9d5b3d68870ec.tar.gz vcxsrv-e82692e521240c5f8592f9ce56c9d5b3d68870ec.tar.bz2 vcxsrv-e82692e521240c5f8592f9ce56c9d5b3d68870ec.zip |
mesa git update 5 dec 2012
mesa: 484a8dcfa8c8b91b8e99174b5e4953264f32789e
Diffstat (limited to 'mesalib/src/gallium/auxiliary/util/u_debug.c')
-rw-r--r-- | mesalib/src/gallium/auxiliary/util/u_debug.c | 56 |
1 files changed, 24 insertions, 32 deletions
diff --git a/mesalib/src/gallium/auxiliary/util/u_debug.c b/mesalib/src/gallium/auxiliary/util/u_debug.c index b26192a8b..ee97b7adb 100644 --- a/mesalib/src/gallium/auxiliary/util/u_debug.c +++ b/mesalib/src/gallium/auxiliary/util/u_debug.c @@ -436,7 +436,7 @@ void debug_funclog_enter_exit(const char* f, const int line, const char* file) #ifdef DEBUG /** - * Dump an image to a .raw or .ppm file (depends on OS). + * Dump an image to .ppm file. * \param format PIPE_FORMAT_x * \param cpp bytes per pixel * \param width width in pixels @@ -444,56 +444,48 @@ void debug_funclog_enter_exit(const char* f, const int line, const char* file) * \param stride row stride in bytes */ void debug_dump_image(const char *prefix, - unsigned format, unsigned cpp, + enum pipe_format format, unsigned cpp, unsigned width, unsigned height, unsigned stride, const void *data) { /* write a ppm file */ char filename[256]; + unsigned char *rgb8; FILE *f; util_snprintf(filename, sizeof(filename), "%s.ppm", prefix); - f = fopen(filename, "w"); - if (f) { - int i, x, y; - int r, g, b; - const uint8_t *ptr = (uint8_t *) data; - - /* XXX this is a hack */ - switch (format) { - case PIPE_FORMAT_B8G8R8A8_UNORM: - r = 2; - g = 1; - b = 0; - break; - default: - r = 0; - g = 1; - b = 1; - } + rgb8 = MALLOC(height * width * 3); + if (!rgb8) { + return; + } + + util_format_translate( + PIPE_FORMAT_R8G8B8_UNORM, + rgb8, width * 3, + 0, 0, + format, + data, stride, + 0, 0, width, height); + /* Must be opened in binary mode or DOS line ending causes data + * to be read with one byte offset. + */ + f = fopen(filename, "wb"); + if (f) { fprintf(f, "P6\n"); - fprintf(f, "# ppm-file created by osdemo.c\n"); + fprintf(f, "# ppm-file created by gallium\n"); fprintf(f, "%i %i\n", width, height); fprintf(f, "255\n"); - fclose(f); - - f = fopen(filename, "ab"); /* reopen in binary append mode */ - for (y = 0; y < height; y++) { - for (x = 0; x < width; x++) { - i = y * stride + x * cpp; - fputc(ptr[i + r], f); /* write red */ - fputc(ptr[i + g], f); /* write green */ - fputc(ptr[i + b], f); /* write blue */ - } - } + fwrite(rgb8, 1, height * width * 3, f); fclose(f); } else { fprintf(stderr, "Can't open %s for writing\n", filename); } + + FREE(rgb8); } /* FIXME: dump resources, not surfaces... */ |