Mercurial > hg > octave-nkf
diff libinterp/corefcn/gl2ps-renderer.cc @ 18814:3277514f36da stable
Fix inverted colors when printing uint8/uint16 images (bug #42107).
* gl2ps-renderer.cc (draw_pixels): Convert the data type to GL_FLOAT, and
divide by the maximum data type value so that range is [0,1].
* gl2ps-renderer.cc (glps_renderer::draw_pixels): Convert and normalize
uint8/uint16 inputs to GL_FLOAT by calling draw_pixels().
author | Rik <rik@octave.org> |
---|---|
date | Fri, 18 Apr 2014 10:05:08 -0700 |
parents | 870f3e12e163 |
children | 78fac67300e8 446c46af4b42 |
line wrap: on
line diff
--- a/libinterp/corefcn/gl2ps-renderer.cc +++ b/libinterp/corefcn/gl2ps-renderer.cc @@ -190,13 +190,14 @@ template <typename T> static void -draw_pixels (GLsizei w, GLsizei h, GLenum format, const T *data) +draw_pixels (GLsizei w, GLsizei h, GLenum format, const T *data, float maxval) { OCTAVE_LOCAL_BUFFER (GLfloat, a, 3*w*h); - for (int i = 0; i < 3*w*h; i++) - a[i] = data[i]; - + // Convert to GL_FLOAT as it is the only type gl2ps accepts. + for (unsigned int i = 0; i < 3*w*h; i++) + a[i] = data[i] / maxval; + gl2psDrawPixels (w, h, 0, 0, format, GL_FLOAT, a); } @@ -204,10 +205,12 @@ glps_renderer::draw_pixels (GLsizei w, GLsizei h, GLenum format, GLenum type, const GLvoid *data) { - if (type == GL_UNSIGNED_SHORT) - ::draw_pixels (w, h, format, static_cast<const GLushort *> (data)); - else if (type == GL_UNSIGNED_BYTE) - ::draw_pixels (w, h, format, static_cast<const GLubyte *> (data)); + // gl2psDrawPixels only supports the GL_FLOAT type. + // Other formats, such as uint8, must be converted first. + if (type == GL_UNSIGNED_BYTE) + ::draw_pixels (w, h, format, static_cast<const GLubyte *> (data), 255.0f); + else if (type == GL_UNSIGNED_SHORT) + ::draw_pixels (w, h, format, static_cast<const GLushort *> (data), 65535.0f); else gl2psDrawPixels (w, h, 0, 0, format, type, data); }