Force image to be a RGB image (there is no writer to convert ARGB type to Bitmap... 50/16150/3
Vincent COUVERT [Thu, 12 Mar 2015 13:36:53 +0000 (14:36 +0100)]
Since JoGL 2.2.4, it seems that the image got from a JoGLCanvas is a ARGB one and no more a RGB one.

To test:
test_run graphic_export bmp_non_empty_file
test_run graphic_export gif_non_empty_file
test_run graphic_export jpg_non_empty_file

Change-Id: Ic5111ccccc153c04a750cb3185cfb149f7420328

scilab/modules/graphic_export/src/java/org/scilab/modules/graphic_export/Export.java
scilab/modules/scirenderer/src/org/scilab/forge/scirenderer/implementation/jogl/JoGLCanvas.java

index bf38ca1..138dfed 100644 (file)
@@ -364,9 +364,8 @@ public class Export {
             }
 
             if (joglCanvas != null) {
-                BufferedImage image = joglCanvas.getImage();
-                //joglCanvas.destroy();
                 PNGExporter exporter = (PNGExporter) getExporter(type);
+                BufferedImage image = joglCanvas.getImage(exporter.isAlphaChannelSupported());
                 exporter.setImage(file, image, params);
                 exporter.write();
                 exporter.dispose();
@@ -541,6 +540,11 @@ public class Export {
                 g2d.dispose();
             }
         }
+
+        public boolean isAlphaChannelSupported() {
+            return true;
+        }
+
     }
 
     /**
@@ -554,6 +558,11 @@ public class Export {
         public void write() throws IOException {
             ExportBitmap.writeFile(image, "gif", file);
         }
+
+        public boolean isAlphaChannelSupported() {
+            return false;
+        }
+
     }
 
     /**
@@ -577,6 +586,11 @@ public class Export {
         public void write() throws IOException {
             ExportBitmap.writeFile(image, "bmp", file);
         }
+
+        public boolean isAlphaChannelSupported() {
+            return false;
+        }
+
     }
 
     /**
@@ -594,6 +608,11 @@ public class Export {
                 ExportBitmap.writeJPEG(image, params.compressionQuality, file);
             }
         }
+
+        public boolean isAlphaChannelSupported() {
+            return false;
+        }
+
     }
 
     /**
index 169067f..538d476 100644 (file)
@@ -233,6 +233,14 @@ public final class JoGLCanvas implements Canvas, GLEventListener {
      * @return an image
      */
     public BufferedImage getImage() {
+        return getImage(true);
+    }
+
+    /**
+     * Get an image from the autoDrawable
+     * @return an image
+     */
+    public BufferedImage getImage(final boolean alpha) {
         while (!canvasAnimator.isDrawFinished() || !displayFinished) {
             try {
                 Thread.sleep(10);
@@ -246,7 +254,7 @@ public final class JoGLCanvas implements Canvas, GLEventListener {
 
         if (SwingUtilities.isEventDispatchThread()) {
             context.makeCurrent();
-            AWTGLReadBufferUtil buffer = new AWTGLReadBufferUtil(GLProfile.getDefault(), true);
+            AWTGLReadBufferUtil buffer = new AWTGLReadBufferUtil(GLProfile.getDefault(), alpha);
             image[0] = buffer.readPixelsToBufferedImage(getGl(), 0, 0, autoDrawable.getSurfaceWidth(), autoDrawable.getSurfaceHeight(), true);
             context.release();
         } else {
@@ -254,7 +262,7 @@ public final class JoGLCanvas implements Canvas, GLEventListener {
                 SwingUtilities.invokeAndWait(new Runnable() {
                     public void run() {
                         context.makeCurrent();
-                        AWTGLReadBufferUtil buffer = new AWTGLReadBufferUtil(GLProfile.getDefault(), true);
+                        AWTGLReadBufferUtil buffer = new AWTGLReadBufferUtil(GLProfile.getDefault(), alpha);
                         image[0] = buffer.readPixelsToBufferedImage(getGl(), 0, 0, autoDrawable.getSurfaceWidth(), autoDrawable.getSurfaceHeight(), true);
                         context.release();
                     }