changeset 22392:4dfb28724863

Clip double RGB data before passing to gl2psDrawPixels (bug #48873). * gl2ps-print.cc (gl2ps_renderer::draw_pixels): clip data between 0 and 1. * imshow.m: Correct title of demo #8.
author Pantxo Diribarne <pantxo.diribarne@gmail.com>
date Thu, 25 Aug 2016 10:02:22 +0200
parents c5da5e5e9846
children 026067ffcf66
files libinterp/corefcn/gl2ps-print.cc scripts/image/imshow.m
diffstat 2 files changed, 8 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/gl2ps-print.cc	Fri Aug 26 16:21:04 2016 +0200
+++ b/libinterp/corefcn/gl2ps-print.cc	Thu Aug 25 10:02:22 2016 +0200
@@ -691,7 +691,13 @@
   void
   gl2ps_renderer::draw_pixels (int w, int h, const float *data)
   {
-    gl2psDrawPixels (w, h, 0, 0, GL_RGB, GL_FLOAT, data);
+    // Clip data between 0 and 1 for float values 
+    OCTAVE_LOCAL_BUFFER (float, tmp_data, 3*w*h);
+
+    for (int i = 0; i < 3*h*w; i++)
+      tmp_data[i] = (data[i] < 0.0f ? 0.0f : (data[i] > 1.0f ? 1.0f : data[i]));
+        
+    gl2psDrawPixels (w, h, 0, 0, GL_RGB, GL_FLOAT, tmp_data);
   }
 
   void
--- a/scripts/image/imshow.m	Fri Aug 26 16:21:04 2016 +0200
+++ b/scripts/image/imshow.m	Thu Aug 25 10:02:22 2016 +0200
@@ -256,7 +256,7 @@
 %!demo
 %! clf;
 %! imshow (100*rand (100, 100, 3));
-%! title ({"imshow with random 100x100x3 matrix", "Indexed color"});
+%! title ({"imshow with random 100x100x3 matrix", "RGB values > 1 are clipped"});
 
 ## Test input validation
 %!error imshow ()