Mesa (master): mesa: support more format/type combos in _mesa_dump_image()

Brian Paul brianp at kemper.freedesktop.org
Tue Feb 7 00:56:59 UTC 2012


Module: Mesa
Branch: master
Commit: aed51e3e6a90dd667bd9915817d16ba14a79720c
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=aed51e3e6a90dd667bd9915817d16ba14a79720c

Author: Brian Paul <brianp at vmware.com>
Date:   Mon Feb  6 17:56:43 2012 -0700

mesa: support more format/type combos in _mesa_dump_image()

---

 src/mesa/main/debug.c |   29 ++++++++++++++++++++++++++++-
 1 files changed, 28 insertions(+), 1 deletions(-)

diff --git a/src/mesa/main/debug.c b/src/mesa/main/debug.c
index 72aa8cb..71d7f1a 100644
--- a/src/mesa/main/debug.c
+++ b/src/mesa/main/debug.c
@@ -554,8 +554,35 @@ _mesa_dump_image(const char *filename, const void *image, GLuint w, GLuint h,
    else if (format == GL_LUMINANCE_ALPHA && type == GL_UNSIGNED_BYTE) {
       write_ppm(filename, image, w, h, 2, 1, 0, 0, invert);
    }
+   else if (format == GL_RED && type == GL_UNSIGNED_BYTE) {
+      write_ppm(filename, image, w, h, 1, 0, 0, 0, invert);
+   }
+   else if (format == GL_RGBA && type == GL_FLOAT) {
+      /* convert floats to ubyte */
+      GLubyte *buf = (GLubyte *) malloc(w * h * 4 * sizeof(GLubyte));
+      const GLfloat *f = (const GLfloat *) image;
+      GLuint i;
+      for (i = 0; i < w * h * 4; i++) {
+         UNCLAMPED_FLOAT_TO_UBYTE(buf[i], f[i]);
+      }
+      write_ppm(filename, buf, w, h, 4, 0, 1, 2, invert);
+      free(buf);
+   }
+   else if (format == GL_RED && type == GL_FLOAT) {
+      /* convert floats to ubyte */
+      GLubyte *buf = (GLubyte *) malloc(w * h * sizeof(GLubyte));
+      const GLfloat *f = (const GLfloat *) image;
+      GLuint i;
+      for (i = 0; i < w * h; i++) {
+         UNCLAMPED_FLOAT_TO_UBYTE(buf[i], f[i]);
+      }
+      write_ppm(filename, buf, w, h, 1, 0, 0, 0, invert);
+      free(buf);
+   }
    else {
-      _mesa_problem(NULL, "Unsupported format/type in _mesa_dump_image()");
+      _mesa_problem(NULL,
+                 "Unsupported format 0x%x / type 0x%x in _mesa_dump_image()",
+                 format, type);
    }
 }
 




More information about the mesa-commit mailing list