# HG changeset patch # User Rik # Date 1397840708 25200 # Node ID 3277514f36da6e8bf4b3e943a7987ffc4b9bf7df # Parent 5fb180e37d7c3bb09a34c305b89573a282001d8a 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(). diff -r 5fb180e37d7c -r 3277514f36da libinterp/corefcn/gl2ps-renderer.cc --- a/libinterp/corefcn/gl2ps-renderer.cc Fri Apr 18 14:21:33 2014 +0200 +++ b/libinterp/corefcn/gl2ps-renderer.cc Fri Apr 18 10:05:08 2014 -0700 @@ -190,13 +190,14 @@ template 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 (data)); - else if (type == GL_UNSIGNED_BYTE) - ::draw_pixels (w, h, format, static_cast (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 (data), 255.0f); + else if (type == GL_UNSIGNED_SHORT) + ::draw_pixels (w, h, format, static_cast (data), 65535.0f); else gl2psDrawPixels (w, h, 0, 0, format, type, data); }