diff options
author | José Fonseca <[email protected]> | 2012-12-02 18:57:53 +0000 |
---|---|---|
committer | José Fonseca <[email protected]> | 2012-12-04 19:35:19 +0000 |
commit | de76101672a83fd7fda8033b2d5ec8c5b756707a (patch) | |
tree | 57b53360f0e6a12152b66451a3116b8353a87b71 /src/gallium | |
parent | a416a4a91dd167f9f018932b0a1c7045bfc08bd8 (diff) |
util/u_debug: Cleanup/fix debug_dump_image.
- Handle other formats.
- Prevent CRLF on Windows.
Reviewed-by: Brian Paul <[email protected]>
Diffstat (limited to 'src/gallium')
-rw-r--r-- | src/gallium/auxiliary/util/u_debug.c | 56 | ||||
-rw-r--r-- | src/gallium/auxiliary/util/u_debug.h | 4 |
2 files changed, 27 insertions, 33 deletions
diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c index b26192a8b58..ee97b7adb81 100644 --- a/src/gallium/auxiliary/util/u_debug.c +++ b/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... */ diff --git a/src/gallium/auxiliary/util/u_debug.h b/src/gallium/auxiliary/util/u_debug.h index 3b42c2f07f7..0eb74433379 100644 --- a/src/gallium/auxiliary/util/u_debug.h +++ b/src/gallium/auxiliary/util/u_debug.h @@ -41,6 +41,8 @@ #include "os/os_misc.h" +#include "pipe/p_format.h" + #ifdef __cplusplus extern "C" { @@ -418,7 +420,7 @@ struct pipe_transfer; struct pipe_resource; 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); |