diff libinterp/corefcn/gl2ps-renderer.cc @ 18671:78fac67300e8

maint: Periodic merge of gui-release to default.
author Rik <rik@octave.org>
date Thu, 24 Apr 2014 08:41:30 -0700
parents 652d9ed6f88d 3277514f36da
children ee7b23a48947
line wrap: on
line diff
--- a/libinterp/corefcn/gl2ps-renderer.cc	Thu Apr 24 07:13:37 2014 -0700
+++ b/libinterp/corefcn/gl2ps-renderer.cc	Thu Apr 24 08:41:30 2014 -0700
@@ -193,13 +193,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);
 }
 
@@ -207,10 +208,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);
 }