Mercurial > octave
comparison libinterp/corefcn/gl2ps-renderer.cc @ 18659: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 |
comparison
equal
deleted
inserted
replaced
18657:5fb180e37d7c | 18659:3277514f36da |
---|---|
188 // FIXME: add support for bold and italic | 188 // FIXME: add support for bold and italic |
189 } | 189 } |
190 | 190 |
191 template <typename T> | 191 template <typename T> |
192 static void | 192 static void |
193 draw_pixels (GLsizei w, GLsizei h, GLenum format, const T *data) | 193 draw_pixels (GLsizei w, GLsizei h, GLenum format, const T *data, float maxval) |
194 { | 194 { |
195 OCTAVE_LOCAL_BUFFER (GLfloat, a, 3*w*h); | 195 OCTAVE_LOCAL_BUFFER (GLfloat, a, 3*w*h); |
196 | 196 |
197 for (int i = 0; i < 3*w*h; i++) | 197 // Convert to GL_FLOAT as it is the only type gl2ps accepts. |
198 a[i] = data[i]; | 198 for (unsigned int i = 0; i < 3*w*h; i++) |
199 | 199 a[i] = data[i] / maxval; |
200 | |
200 gl2psDrawPixels (w, h, 0, 0, format, GL_FLOAT, a); | 201 gl2psDrawPixels (w, h, 0, 0, format, GL_FLOAT, a); |
201 } | 202 } |
202 | 203 |
203 void | 204 void |
204 glps_renderer::draw_pixels (GLsizei w, GLsizei h, GLenum format, | 205 glps_renderer::draw_pixels (GLsizei w, GLsizei h, GLenum format, |
205 GLenum type, const GLvoid *data) | 206 GLenum type, const GLvoid *data) |
206 { | 207 { |
207 if (type == GL_UNSIGNED_SHORT) | 208 // gl2psDrawPixels only supports the GL_FLOAT type. |
208 ::draw_pixels (w, h, format, static_cast<const GLushort *> (data)); | 209 // Other formats, such as uint8, must be converted first. |
209 else if (type == GL_UNSIGNED_BYTE) | 210 if (type == GL_UNSIGNED_BYTE) |
210 ::draw_pixels (w, h, format, static_cast<const GLubyte *> (data)); | 211 ::draw_pixels (w, h, format, static_cast<const GLubyte *> (data), 255.0f); |
212 else if (type == GL_UNSIGNED_SHORT) | |
213 ::draw_pixels (w, h, format, static_cast<const GLushort *> (data), 65535.0f); | |
211 else | 214 else |
212 gl2psDrawPixels (w, h, 0, 0, format, type, data); | 215 gl2psDrawPixels (w, h, 0, 0, format, type, data); |
213 } | 216 } |
214 | 217 |
215 void | 218 void |