[Mesa-dev] [PATCH 9/9] util/u_debug: Cleanup/fix debug_dump_image.
Brian Paul
brianp at vmware.com
Tue Dec 4 07:17:13 PST 2012
On 12/04/2012 07:13 AM, jfonseca at vmware.com wrote:
> From: José Fonseca<jfonseca at vmware.com>
>
> - Handle other formats.
> - Prevent CRLF on Windows.
> ---
> src/gallium/auxiliary/util/u_debug.c | 53 ++++++++++++++--------------------
> src/gallium/auxiliary/util/u_debug.h | 4 ++-
> 2 files changed, 25 insertions(+), 32 deletions(-)
>
> diff --git a/src/gallium/auxiliary/util/u_debug.c b/src/gallium/auxiliary/util/u_debug.c
> index b26192a..9993b67 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,47 @@ 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 */
Minor nit: I'd put the closing */ on the next line.
> + f = fopen(filename, "wb");
> + if (f) {
> fprintf(f, "P6\n");
> fprintf(f, "# ppm-file created by osdemo.c\n");
s/osdemo.c/gallium/
> 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 3b42c2f..0eb7443 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);
More information about the mesa-dev
mailing list