Bug 5573 fixed: When exporting into JPEG, it was not possible to set the compression... 38/3538/5
Calixte DENIZET [Tue, 15 Mar 2011 21:17:33 +0000 (22:17 +0100)]
Change-Id: I78becf6175e12d81b0acb042b6dea3e438b0e66c

25 files changed:
SEP/INDEX
SEP/SEP_52_jpg_quality.odt [new file with mode: 0644]
scilab/CHANGES_5.3.X
scilab/modules/graphic_export/help/en_US/xs2bmp.xml
scilab/modules/graphic_export/help/en_US/xs2emf.xml
scilab/modules/graphic_export/help/en_US/xs2eps.xml
scilab/modules/graphic_export/help/en_US/xs2fig.xml
scilab/modules/graphic_export/help/en_US/xs2gif.xml
scilab/modules/graphic_export/help/en_US/xs2jpg.xml
scilab/modules/graphic_export/help/en_US/xs2pdf.xml
scilab/modules/graphic_export/help/en_US/xs2png.xml
scilab/modules/graphic_export/help/en_US/xs2ppm.xml
scilab/modules/graphic_export/help/en_US/xs2ps.xml
scilab/modules/graphic_export/help/en_US/xs2svg.xml
scilab/modules/graphic_export/src/c/xs2file.c
scilab/modules/graphic_export/src/cpp/exportToFile.cpp
scilab/modules/graphic_export/src/cpp/exportToFile.hxx
scilab/modules/graphic_export/src/java/org/scilab/modules/graphic_export/BitmapRenderer.java
scilab/modules/graphic_export/src/java/org/scilab/modules/graphic_export/ExportBitmap.java
scilab/modules/graphic_export/src/java/org/scilab/modules/graphic_export/ExportRenderer.java
scilab/modules/graphic_export/src/java/org/scilab/modules/graphic_export/ExportToFile.java
scilab/modules/graphic_export/src/java/org/scilab/modules/graphic_export/FileExporter.java
scilab/modules/graphic_export/src/jni/FileExporter.cpp
scilab/modules/graphic_export/src/jni/FileExporter.giws.xml
scilab/modules/graphic_export/src/jni/FileExporter.hxx

index fb6f149..a404000 100644 (file)
--- a/SEP/INDEX
+++ b/SEP/INDEX
@@ -47,4 +47,5 @@ SEP #47 : Scilab Desktop
 SEP #48 : Scilab Preferences
 SEP #49 : repmat function
 SEP #50 : Xcos Help Folders
-SEP #51 : Linear Programming
\ No newline at end of file
+SEP #51 : Linear Programming
+SEP #52 : Quality argument added to xs2jpg
diff --git a/SEP/SEP_52_jpg_quality.odt b/SEP/SEP_52_jpg_quality.odt
new file mode 100644 (file)
index 0000000..8e22cb3
Binary files /dev/null and b/SEP/SEP_52_jpg_quality.odt differ
index 8685bc9..4f4b77a 100644 (file)
@@ -54,6 +54,13 @@ Javasci:
                    version 2.
 
 
+Graphics:
+=========
+
+* It was not possible to set the compression quality when exporting into jpeg.
+  See bug 5573 and SEP 52.
+
+
 Localization:
 =============
 
index 14a7e4a..6738efe 100644 (file)
@@ -24,7 +24,7 @@
   <refnamediv>
     <refname>xs2bmp</refname>
 
-    <refpurpose>send graphics to a BMP file.</refpurpose>
+    <refpurpose>Export graphics to BMP.</refpurpose>
   </refnamediv>
 
   <refsynopsisdiv>
index 12b3dab..e287542 100644 (file)
@@ -24,8 +24,7 @@
   <refnamediv>
     <refname>xs2emf</refname>
 
-    <refpurpose>send graphics to an EMF file (Only for
-    Windows).</refpurpose>
+    <refpurpose>Export graphics to EMF (Only under Windows).</refpurpose>
   </refnamediv>
 
   <refsynopsisdiv>
index 598588c..e38a1cd 100644 (file)
@@ -24,7 +24,7 @@
   <refnamediv>
     <refname>xs2eps</refname>
 
-    <refpurpose>send graphics to an EPS file.</refpurpose>
+    <refpurpose>Export graphics to EPS.</refpurpose>
   </refnamediv>
 
   <refsynopsisdiv>
index b4c4d7b..2f42358 100644 (file)
@@ -24,7 +24,7 @@
   <refnamediv>
     <refname>xs2fig</refname>
 
-    <refpurpose>send graphics to a FIG file.</refpurpose>
+    <refpurpose>Export graphics to FIG.</refpurpose>
   </refnamediv>
 
   <refsynopsisdiv>
index d025d28..58a6953 100644 (file)
@@ -24,7 +24,7 @@
   <refnamediv>
     <refname>xs2gif</refname>
 
-    <refpurpose>send graphics to a GIF file.</refpurpose>
+    <refpurpose>Export graphics to GIF.</refpurpose>
   </refnamediv>
 
   <refsynopsisdiv>
index add45b3..7b64e60 100644 (file)
   <refnamediv>
     <refname>xs2jpg</refname>
 
-    <refpurpose>send graphics to a JPG file.</refpurpose>
+    <refpurpose>Export graphics to JPG.</refpurpose>
   </refnamediv>
 
   <refsynopsisdiv>
     <title>Calling Sequence</title>
 
-    <synopsis>xs2jpg(win_num, file_name)
-xs2jpg(fig, file_name)</synopsis>
+    <synopsis>xs2jpg(win_num, file_name [, compression_quality])
+xs2jpg(fig, file_name [, compression_quality])</synopsis>
   </refsynopsisdiv>
 
   <refsection>
@@ -61,6 +61,15 @@ xs2jpg(fig, file_name)</synopsis>
           <para>string, name of the exported file.</para>
         </listitem>
       </varlistentry>
+
+      <varlistentry>
+        <term>compression_quality</term>
+
+        <listitem>
+          <para>real, a number between 0 and 1 (best quality). The default compression quality is set to 0.75.</para>
+          <para>Argument available since Scilab 5.3.2</para>
+        </listitem>
+      </varlistentry>
     </variablelist>
   </refsection>
 
@@ -78,6 +87,8 @@ plot2d();
 //JPG export
 xs2jpg(0,'foo.jpg');
 xs2jpg(gcf(),'foo.jpg');
+xs2jpg(0,'foo_0.jpg', 0); // poor quality
+xs2jpg(gcf(),'foo_1.jpg', 1); // best quality
  ]]></programlisting>
   </refsection>
 
index ff245c2..99e1372 100644 (file)
@@ -24,7 +24,7 @@
   <refnamediv>
     <refname>xs2pdf</refname>
 
-    <refpurpose>save graphics to a PDF file.</refpurpose>
+    <refpurpose>Export graphics to PDF.</refpurpose>
   </refnamediv>
 
   <refsynopsisdiv>
index 6d7436f..b819736 100644 (file)
@@ -24,7 +24,7 @@
   <refnamediv>
     <refname>xs2png</refname>
 
-    <refpurpose>send graphics to a PNG file.</refpurpose>
+    <refpurpose>Export graphics to PNG.</refpurpose>
   </refnamediv>
 
   <refsynopsisdiv>
index a41ecd1..8816b3f 100644 (file)
@@ -24,7 +24,7 @@
   <refnamediv>
     <refname>xs2ppm</refname>
 
-    <refpurpose>send graphics to a PPM file.</refpurpose>
+    <refpurpose>Export graphics to PPM.</refpurpose>
   </refnamediv>
 
   <refsynopsisdiv>
index 710d8ce..1e00b47 100644 (file)
@@ -24,7 +24,7 @@
   <refnamediv>
     <refname>xs2ps</refname>
 
-    <refpurpose>send graphics to a PS file.</refpurpose>
+    <refpurpose>Export graphics to PS.</refpurpose>
   </refnamediv>
 
   <refsynopsisdiv>
index 1d91a07..12f23e4 100644 (file)
@@ -24,7 +24,7 @@
   <refnamediv>
     <refname>xs2svg</refname>
 
-    <refpurpose>save graphics to a SVG file.</refpurpose>
+    <refpurpose>Export graphics to SVG.</refpurpose>
   </refnamediv>
 
   <refsynopsisdiv>
index 32359df..1f5c290 100644 (file)
@@ -1,17 +1,17 @@
 /*
-* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
-* Copyright (C) 2006 - INRIA - Fabrice Leray
-* Copyright (C) 2006 - INRIA - Jean-Baptiste Silvy
-* Copyright (C) 2009 - DIGITEO - Allan CORNET
-* desc : interface for xs2file routine
-* 
-* This file must be used under the terms of the CeCILL.
-* This source file is licensed as described in the file COPYING, which
-* you should have received as part of this distribution.  The terms
-* are also available at    
-* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
-*
-*/
+ * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
+ * Copyright (C) 2006 - INRIA - Fabrice Leray
+ * Copyright (C) 2006 - INRIA - Jean-Baptiste Silvy
+ * Copyright (C) 2009 - DIGITEO - Allan CORNET
+ * desc : interface for xs2file routine
+ * 
+ * This file must be used under the terms of the CeCILL.
+ * This source file is licensed as described in the file COPYING, which
+ * you should have received as part of this distribution.  The terms
+ * are also available at    
+ * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ *
+ */
 
 #include <string.h>
 #include <stdio.h>
@@ -37,199 +37,220 @@ static BOOL isVectorialExport(ExportFileType fileType);
 /*--------------------------------------------------------------------------*/
 int xs2file(char * fname, ExportFileType fileType )
 {
-       /* Check input and output sizes */
-       CheckLhs(0,1);
-       if (isVectorialExport(fileType))
-       {
-               CheckRhs(2,3);
-       }
-       else
-       {
-               CheckRhs(2,2);
-       }
-
-       if (GetType(1) != sci_matrix && GetType(1) != sci_handles)
-       {
-               Scierror(999,_("%s: Wrong type for input argument #%d: An integer or a handle expected.\n"),fname, 1);
-         LhsVar(1) = 0;
-         C2F(putlhsvar)();
-               return 0;
-       }
-
-       if ( (GetType(2) == sci_strings) )
-       {       
-               char **fileName = NULL;
-               char *real_filename = NULL;
-               ExportOrientation orientation = EXPORT_PORTRAIT; /* default orientation */
-               long int lout = 0;
-               int out_n = 0;
-               int m1 = 0, n1 = 0, l1 = 0;
-               int figurenum = -1;
-    sciPointObj* figurePtr = NULL;
-               int status = 0;
-
-               /* get handle by figure number */
-    if(GetType(1) == sci_matrix)
+  /* Check input and output sizes */
+  CheckLhs(0,1);
+  if (isVectorialExport(fileType) || fileType == JPG_EXPORT)
     {
-               GetRhsVar(1,MATRIX_OF_INTEGER_DATATYPE,&m1,&n1,&l1);
-      if(m1*n1 != 1)
-      {
-        Scierror(999,_("%s: Wrong size for input argument #%d: A scalar expected.\n"),fname, 1);        
-                         LhsVar(1) = 0;
-                         C2F(putlhsvar)();
-                         return 0;
-      }
-
-               figurenum = *istk(l1);
-                 if (!sciIsExistingFigure(figurenum))
-                 {
-                         Scierror(999, "%s: Input argument #%d must be a valid figure_id.\n",fname, 1);
-                         LhsVar(1) = 0;
-                         C2F(putlhsvar)();
-                         return 0;
-                 }
-      figurePtr = getFigureFromIndex(figurenum);
+      CheckRhs(2,3);
     }
-    /* check given handle */
-    if(GetType(1) == sci_handles)
+  else
     {
-      GetRhsVar(1,GRAPHICAL_HANDLE_DATATYPE,&m1,&n1,&l1);
-      if(m1*n1 != 1)
-      {
-        Scierror(999,_("%s: Wrong size for input argument #%d: A graphic handle expected.\n"),fname, 1);        
-                         LhsVar(1) = 0;
-                         C2F(putlhsvar)();
-                         return 0;
-      }
-      figurePtr = sciGetPointerFromHandle(getHandleFromStack(l1));
-
-      if(figurePtr == NULL)
-      {
-                         Scierror(999, "%s: Input argument #%d must be a valid handle.\n",fname, 1);
-                         LhsVar(1) = 0;
-                         C2F(putlhsvar)();
-                         return 0;        
-      }
-      startFigureDataReading(figurePtr);
-      if(sciGetEntityType(figurePtr)!=SCI_FIGURE)
-      {
-                         Scierror(999, "%s: Input argument #%d must be a handle on a figure.\n", fname, 1);
-                         LhsVar(1) = 0;
-                         C2F(putlhsvar)();
-                         return 0;        
-      }
-      endFigureDataReading(figurePtr);
+      CheckRhs(2,2);
     }
 
-               /* get file name */
-               GetRhsVar(2,MATRIX_OF_STRING_DATATYPE,&m1,&n1,&fileName);
-               if (m1*n1 == 1)
-               {
-                       if (Rhs == 3)
-                       {
-                               int nbCol = 0;
-                               int nbRow = 0;
-                               char **sciOrientation = NULL;
+  if (GetType(1) != sci_matrix && GetType(1) != sci_handles)
+    {
+      Scierror(999,_("%s: Wrong type for input argument #%d: An integer or a handle expected.\n"),fname, 1);
+      LhsVar(1) = 0;
+      C2F(putlhsvar)();
+      return 0;
+    }
 
-                               if (GetType(3) != sci_strings)
-                               {
-                                       freeArrayOfString(fileName,m1*n1);
-                                       Scierror(999,_("%s: Wrong type for input argument #%d: Single character string expected.\n"),fname, 3);
-                                       return 0;
-                               }
+  if ( (GetType(2) == sci_strings) )
+    {  
+      char **fileName = NULL;
+      char *real_filename = NULL;
+      float jpegCompressionQuality = 0.75f;
+      ExportOrientation orientation = EXPORT_PORTRAIT; /* default orientation */
+      long int lout = 0;
+      int out_n = 0;
+      int m1 = 0, n1 = 0, l1 = 0;
+      int figurenum = -1;
+      sciPointObj* figurePtr = NULL;
+      int status = 0;
 
-                               GetRhsVar(3,MATRIX_OF_STRING_DATATYPE,&nbRow,&nbCol,&sciOrientation);
-                               if (nbRow*nbCol == 1)
-                               {
-                                       /* Value should be 'landscape' or 'portrait' but check only the first character */
-                                       /* for compatibility with Scilab 4*/
-                                       if (strcmp(sciOrientation[0], "landscape") == 0 || strcmp(sciOrientation[0], "l") == 0)
-                                       {
-                                               freeArrayOfString(sciOrientation,nbRow*nbCol);
-                                               orientation = EXPORT_LANDSCAPE;
-                                       }
-                                       else if(strcmp(sciOrientation[0], "portrait") == 0 || strcmp(sciOrientation[0], "p") == 0)
-                                       {
-                                               freeArrayOfString(sciOrientation,nbRow*nbCol);
-                                               orientation = EXPORT_PORTRAIT;
-                                       }
-                                       else
-                                       {
-                                               freeArrayOfString(fileName,m1*n1);
-                                               freeArrayOfString(sciOrientation,nbRow*nbCol);
-                                               Scierror(999,_("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"),fname, 3, "portrait", "landscape");
-                                               return 0;
-                                       }
-                               }
-                               else
-                               {
-                                       freeArrayOfString(fileName,m1*n1);
-                                       freeArrayOfString(sciOrientation,nbRow*nbCol);
-                                       Scierror(999,_("%s: Wrong size for input argument #%d: Single character string expected.\n"),fname, 3);
-                                       return 0;
-                               }
-                       }
+      /* get handle by figure number */
+      if(GetType(1) == sci_matrix)
+       {
+         GetRhsVar(1,MATRIX_OF_INTEGER_DATATYPE,&m1,&n1,&l1);
+         if(m1*n1 != 1)
+           {
+             Scierror(999,_("%s: Wrong size for input argument #%d: A scalar expected.\n"),fname, 1);        
+             LhsVar(1) = 0;
+             C2F(putlhsvar)();
+             return 0;
+           }
 
-                       /* Replaces SCI, ~, HOME, TMPDIR by the real path */
-                       real_filename = expandPathVariable(fileName[0]);
+         figurenum = *istk(l1);
+         if (!sciIsExistingFigure(figurenum))
+           {
+             Scierror(999, "%s: Input argument #%d must be a valid figure_id.\n",fname, 1);
+             LhsVar(1) = 0;
+             C2F(putlhsvar)();
+             return 0;
+           }
+         figurePtr = getFigureFromIndex(figurenum);
+       }
+      /* check given handle */
+      if(GetType(1) == sci_handles)
+       {
+         GetRhsVar(1,GRAPHICAL_HANDLE_DATATYPE,&m1,&n1,&l1);
+         if(m1*n1 != 1)
+           {
+             Scierror(999,_("%s: Wrong size for input argument #%d: A graphic handle expected.\n"),fname, 1);        
+             LhsVar(1) = 0;
+             C2F(putlhsvar)();
+             return 0;
+           }
+         figurePtr = sciGetPointerFromHandle(getHandleFromStack(l1));
 
-                       /* Call the function for exporting file */
-                       status = exportToFile(figurePtr, real_filename, fileType, orientation);
+         if(figurePtr == NULL)
+           {
+             Scierror(999, "%s: Input argument #%d must be a valid handle.\n",fname, 1);
+             LhsVar(1) = 0;
+             C2F(putlhsvar)();
+             return 0;        
+           }
+         startFigureDataReading(figurePtr);
+         if(sciGetEntityType(figurePtr)!=SCI_FIGURE)
+           {
+             Scierror(999, "%s: Input argument #%d must be a handle on a figure.\n", fname, 1);
+             LhsVar(1) = 0;
+             C2F(putlhsvar)();
+             return 0;        
+           }
+         endFigureDataReading(figurePtr);
+       }
 
-                       /* free pointers no more used */
-                       if (real_filename){FREE(real_filename);real_filename = NULL;}
-                       freeArrayOfString(fileName,m1*n1);
+      /* get file name */
+      GetRhsVar(2,MATRIX_OF_STRING_DATATYPE,&m1,&n1,&fileName);
+      if (m1*n1 == 1)
+       {
+         if (Rhs == 3)
+           {
+             int nbCol = 0;
+             int nbRow = 0;
+             
+             if (isVectorialExport(fileType))
+               {
 
-                       /* treat errors */
-                       switch(status)
+                 char **sciOrientation = NULL;
+                 
+                 if (GetType(3) != sci_strings)
+                   {
+                     freeArrayOfString(fileName,m1*n1);
+                     Scierror(999,_("%s: Wrong type for input argument #%d: Single character string expected.\n"),fname, 3);
+                     return 0;
+                   }
+                 
+                 GetRhsVar(3,MATRIX_OF_STRING_DATATYPE,&nbRow,&nbCol,&sciOrientation);
+                 if (nbRow*nbCol == 1)
+                   {
+                     /* Value should be 'landscape' or 'portrait' but check only the first character */
+                     /* for compatibility with Scilab 4*/
+                     if (strcmp(sciOrientation[0], "landscape") == 0 || strcmp(sciOrientation[0], "l") == 0)
+                       {
+                         freeArrayOfString(sciOrientation,nbRow*nbCol);
+                         orientation = EXPORT_LANDSCAPE;
+                       }
+                     else if(strcmp(sciOrientation[0], "portrait") == 0 || strcmp(sciOrientation[0], "p") == 0)
+                       {
+                         freeArrayOfString(sciOrientation,nbRow*nbCol);
+                         orientation = EXPORT_PORTRAIT;
+                       }
+                     else
                        {
-                       case EXPORT_UNKNOWN_GLEXCEPTION_ERROR :
-                               Scierror(999,_("%s: OpenGL error during export.\n"),fname);
-                               return 0;
-                       case EXPORT_IOEXCEPTION_ERROR :
-                               Scierror(999,_("%s: Unable to create export file, permission denied.\n"),fname);
-                               return 0;
-                       case EXPORT_INVALID_FILE :
-                               Scierror(999,_("%s: Unable to create export file, invalid file.\n"),fname);
-                               return 0;
-                       case EXPORT_GL2PS_ERROR :
-                               Scierror(999,_("%s: GL2PS error during export.\n"),fname);
-                               return 0;
-                       case EXPORT_GL2PS_OVERFLOW :
-                               Scierror(999,_("%s: Unable to create export file, figure is too big.\n"),fname);
-                               return 0;
-                       case EXPORT_GL2PS_UNINITIALIZED :
-                               Scierror(999,_("%s: GL2PS error during export.\n"),fname);
-                               return 0;
-                       default :
-                               // NO ERROR
-                               break;
+                         freeArrayOfString(fileName,m1*n1);
+                         freeArrayOfString(sciOrientation,nbRow*nbCol);
+                         Scierror(999,_("%s: Wrong value for input argument #%d: '%s' or '%s' expected.\n"),fname, 3, "portrait", "landscape");
+                         return 0;
                        }
+                   }
+                 else
+                   {
+                     freeArrayOfString(fileName,m1*n1);
+                     freeArrayOfString(sciOrientation,nbRow*nbCol);
+                     Scierror(999,_("%s: Wrong size for input argument #%d: Single character string expected.\n"),fname, 3);
+                     return 0;
+                   }
                }
-               else
+             else
                {
-                       freeArrayOfString(fileName,m1*n1);
-                       Scierror(999,_("%s: Wrong size for input argument #%d: Single character string expected.\n"),fname, 2);
-                       return 0;
+                 int quality = 0;
+                 GetRhsVar(3, MATRIX_OF_DOUBLE_DATATYPE, &nbRow, &nbCol, &quality);
+                 if (nbRow != 1 || nbCol != 1 || *stk(quality) < 0 || *stk(quality) > 1)
+                   {
+                     freeArrayOfString(fileName, m1 * n1);
+                     Scierror(999,_("%s: Wrong type for input argument #%d: A real between 0 and 1 expected.\n"),fname, 3);
+                     return 0;
+                   }
+                 jpegCompressionQuality = (float) *stk(quality);
                }
+           }
+
+         /* Replaces SCI, ~, HOME, TMPDIR by the real path */
+         real_filename = expandPathVariable(fileName[0]);
+
+         /* Call the function for exporting file */
+         status = exportToFile(figurePtr, real_filename, fileType, jpegCompressionQuality, orientation);
+         
+         /* free pointers no more used */
+         if (real_filename)
+           {
+             FREE(real_filename);
+             real_filename = NULL;
+           }
+         freeArrayOfString(fileName,m1*n1);
+
+         /* treat errors */
+         switch(status)
+           {
+           case EXPORT_UNKNOWN_GLEXCEPTION_ERROR :
+             Scierror(999,_("%s: OpenGL error during export.\n"),fname);
+             return 0;
+           case EXPORT_IOEXCEPTION_ERROR :
+             Scierror(999,_("%s: Unable to create export file, permission denied.\n"),fname);
+             return 0;
+           case EXPORT_INVALID_FILE :
+             Scierror(999,_("%s: Unable to create export file, invalid file.\n"),fname);
+             return 0;
+           case EXPORT_GL2PS_ERROR :
+             Scierror(999,_("%s: GL2PS error during export.\n"),fname);
+             return 0;
+           case EXPORT_GL2PS_OVERFLOW :
+             Scierror(999,_("%s: Unable to create export file, figure is too big.\n"),fname);
+             return 0;
+           case EXPORT_GL2PS_UNINITIALIZED :
+             Scierror(999,_("%s: GL2PS error during export.\n"),fname);
+             return 0;
+           default :
+             // NO ERROR
+             break;
+           }
        }
-       else
+      else
        {
-               Scierror(999,_("%s: Wrong type for input argument #%d: Single character string expected.\n"),fname, 2);
-               return 0;
+         freeArrayOfString(fileName,m1*n1);
+         Scierror(999,_("%s: Wrong size for input argument #%d: Single character string expected.\n"),fname, 2);
+         return 0;
        }
+    }
+  else
+    {
+      Scierror(999,_("%s: Wrong type for input argument #%d: Single character string expected.\n"),fname, 2);
+      return 0;
+    }
 
-       LhsVar(1) = 0;
-       C2F(putlhsvar)();
-       return 0;
+  LhsVar(1) = 0;
+  C2F(putlhsvar)();
+  return 0;
 }
 /*--------------------------------------------------------------------------*/
 static BOOL isVectorialExport(ExportFileType fileType)
 {
-       return   fileType == EPS_EXPORT
-               || fileType == PS_EXPORT
-               || fileType == PDF_EXPORT
-               || fileType == SVG_EXPORT;
+  return fileType == EPS_EXPORT
+    || fileType == PS_EXPORT
+    || fileType == PDF_EXPORT
+    || fileType == SVG_EXPORT;
 }
 /*--------------------------------------------------------------------------*/
-
index 01624c9..834fd0a 100644 (file)
@@ -27,13 +27,14 @@ extern "C"
 int exportToFile(sciPointObj * pFigure,
                  const char * fileName,
                  ExportFileType fileType,
+                const float jpegCompressionQuality,
                  ExportOrientation orientation)
 {
-
   return org_scilab_modules_graphic_export::FileExporter::fileExport(getScilabJavaVM(),
                                                                     sciGetNum(pFigure),
                                                                     (char *)fileName,
                                                                     fileType,
+                                                                    jpegCompressionQuality,
                                                                      orientation);
 }
 /*---------------------------------------------------------------------------------*/
index da21856..c7207fc 100644 (file)
@@ -55,6 +55,7 @@ typedef enum
 int exportToFile(sciPointObj * pFigure,
                  const char * fileName,
                  ExportFileType fileType,
+                const float jpegCompressionQuality,
                  ExportOrientation orientation);
 
 #ifdef __cplusplus
index fdf2901..1a00712 100644 (file)
@@ -24,14 +24,17 @@ public class BitmapRenderer  extends ExportRenderer {
 
        private static String fileName;
 
+        private float jpegCompressionQuality;
+
        /**
         * Default constructor
         * @param fileName name of the figure to render
         * @param fileType type of the figure to render
         * @param fileOrientation orientation of the figure to render
         */
-       public BitmapRenderer(String fileName, int fileType, int fileOrientation) {
+       public BitmapRenderer(String fileName, int fileType, float jpegCompressionQuality, int fileOrientation) {
                super(fileName, fileType, fileOrientation);
+               this.jpegCompressionQuality = jpegCompressionQuality;
        }
        
        /**
@@ -82,7 +85,7 @@ public class BitmapRenderer  extends ExportRenderer {
                gl.glReadBuffer(GL.GL_FRONT);
                
                
-               ExportToFile export = ExportToFile.createExporter(super.getFileName(), super.getFileType());
+               ExportToFile export = ExportToFile.createExporter(super.getFileName(), super.getFileType(), jpegCompressionQuality);
                export.setFileSize(gLDrawable.getWidth(), gLDrawable.getHeight());
                export.exportToBitmap();
                
index 16a74e8..20aef46 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
  * Copyright (C) 2008 - INRIA - Sylvestre Koumar
- * 
+ *
  * This file must be used under the terms of the CeCILL.
  * This source file is licensed as described in the file COPYING, which
  * you should have received as part of this distribution.  The terms
@@ -15,8 +15,13 @@ package org.scilab.modules.graphic_export;
 import java.awt.image.BufferedImage;
 import java.io.File;
 import java.io.IOException;
+import java.util.Iterator;
 
+import javax.imageio.IIOImage;
 import javax.imageio.ImageIO;
+import javax.imageio.ImageWriteParam;
+import javax.imageio.ImageWriter;
+import javax.imageio.stream.FileImageOutputStream;
 import javax.media.opengl.GLContext;
 import javax.media.opengl.GLException;
 
@@ -29,113 +34,151 @@ import com.sun.opengl.util.Screenshot;
  * @author Sylvestre Koumar
  *
  */
-public class ExportBitmap extends ExportToFile {       
-
-       /** File which contains the screen-shot */
-       private File file;
-       private BufferedImage dump;
-       private String fileExtension;
-
-       /**
-        * Default Constructor
-        * @param filename name of the exported file
-        * @param filetype type of the exported file
-        */
-       public ExportBitmap(String filename, int filetype) {
-               super(filename, filetype);                      
-       }       
-
-       /**
-        * Create a bitmap file which is the screen-shot of the figure
-        * @return a int which is a type of error
-        */
-       public int exportToBitmap() {                           
-       String suffix = ExportRenderer.getFileExtension();
-
-       if (suffix.length() == 0) {
-                 switch (getFiletype()) {
-                       case ExportRenderer.BMP_EXPORT:
-                               suffix = "bmp";
-                       break;
-                       case ExportRenderer.GIF_EXPORT:
-                               suffix = "gif";
-                       break;
-                       case ExportRenderer.JPG_EXPORT:
-                               suffix = "jpg";
-                       break;
-                       case ExportRenderer.PNG_EXPORT:
-                               suffix = "png";
-                       break;
-                       default: 
-                               return ExportRenderer.INVALID_FILE;
-         }
-       }
-
-               /** Select the screen-shot format */            
-               switch (getFiletype()) {
-               case ExportRenderer.BMP_EXPORT:  
-               case ExportRenderer.GIF_EXPORT:  
-               case ExportRenderer.JPG_EXPORT:  
-               case ExportRenderer.PNG_EXPORT:  
-                       file = new File(getFilename() + "." + suffix);
-                       break;          
-
-               default: return ExportRenderer.INVALID_FILE;
-               }
-
-               try {                   
-                       /** Generate the screen-shot */         
-                       //Check if we have the permission to export                     
-                       if (Utils.checkWritePermission(file) == ExportRenderer.SUCCESS) {
-                               dump = Screenshot.readToBufferedImage(getWidth(), getHeight());
-                               //flip the screen-shot if the dump is mirrored
-                               dumpFlip();
-                       } else {
-                               return ExportRenderer.INVALID_FILE;
-                       }
-               } catch (GLException ex1) {
-                       return ExportRenderer.UNKNOWN_GLEXCEPTION_ERROR;
-               }
-               
-               return ExportRenderer.SUCCESS;                  
-       }
-
-       /**
-        * flip the screen-shot if it's mirrored
-        * @return result of dumpFlip (success or fail)
-        */
-       private int dumpFlip() {
-               // check if it was the case
-               boolean needFlip;
-               try {
-                       // raises an exception if hardware acceleration is on
-                       needFlip = !((GLContextImpl) GLContext.getCurrent()).offscreenImageNeedsVerticalFlip();
-               } catch (GLException e) {
-                       // hardware acceleration is on
-                       needFlip = false;
-               }
-               if (needFlip) {
-                       // flip it back
-                       ImageUtil.flipImageVertically(dump);
-               }
-               try {
-                       ImageIO.write(dump, getFileExtension(), file);
-               } catch (IOException e) {
-                       return ExportRenderer.IOEXCEPTION_ERROR;
+public class ExportBitmap extends ExportToFile {
+
+    /** File which contains the screen-shot */
+    private File file;
+    private BufferedImage dump;
+    private String fileExtension;
+    private float jpegCompressionQuality = -1;
+
+    /**
+     * Default Constructor
+     * @param filename name of the exported file
+     * @param filetype type of the exported file
+     */
+    public ExportBitmap(String filename, int filetype) {
+        super(filename, filetype);
+    }
+
+    /**
+     * Default Constructor
+     * @param filename name of the exported file
+     * @param filetype type of the exported file
+     * @param jpegCompressionQuality the jpeg compression rate between 0 and 1
+     */
+    public ExportBitmap(String filename, int filetype, float jpegCompressionQuality) {
+        super(filename, filetype);
+       this.jpegCompressionQuality = jpegCompressionQuality;
+    }
+
+    /**
+     * Create a bitmap file which is the screen-shot of the figure
+     * @return a int which is a type of error
+     */
+    public int exportToBitmap() {
+        String suffix = ExportRenderer.getFileExtension();
+
+        if (suffix.length() == 0) {
+            switch (getFiletype()) {
+            case ExportRenderer.BMP_EXPORT:
+                suffix = "bmp";
+                break;
+            case ExportRenderer.GIF_EXPORT:
+                suffix = "gif";
+                break;
+            case ExportRenderer.JPG_EXPORT:
+                suffix = "jpg";
+                break;
+            case ExportRenderer.PNG_EXPORT:
+                suffix = "png";
+                break;
+            default:
+                return ExportRenderer.INVALID_FILE;
+            }
+        }
+
+        /** Select the screen-shot format */
+        switch (getFiletype()) {
+        case ExportRenderer.BMP_EXPORT:
+        case ExportRenderer.GIF_EXPORT:
+        case ExportRenderer.JPG_EXPORT:
+        case ExportRenderer.PNG_EXPORT:
+            file = new File(getFilename() + "." + suffix);
+            break;
+
+        default: return ExportRenderer.INVALID_FILE;
+        }
+
+        try {
+            /** Generate the screen-shot */
+            //Check if we have the permission to export
+            if (Utils.checkWritePermission(file) == ExportRenderer.SUCCESS) {
+                dump = Screenshot.readToBufferedImage(getWidth(), getHeight());
+                //flip the screen-shot if the dump is mirrored
+                dumpFlip();
+            } else {
+                return ExportRenderer.INVALID_FILE;
+            }
+        } catch (GLException ex1) {
+            return ExportRenderer.UNKNOWN_GLEXCEPTION_ERROR;
+        }
+
+        return ExportRenderer.SUCCESS;
+    }
+
+    /**
+     * flip the screen-shot if it's mirrored
+     * @return result of dumpFlip (success or fail)
+     */
+    private int dumpFlip() {
+        // check if it was the case
+        boolean needFlip;
+        try {
+            // raises an exception if hardware acceleration is on
+            needFlip = !((GLContextImpl) GLContext.getCurrent()).offscreenImageNeedsVerticalFlip();
+        } catch (GLException e) {
+            // hardware acceleration is on
+            needFlip = false;
+        }
+        if (needFlip) {
+            // flip it back
+            ImageUtil.flipImageVertically(dump);
+        }
+        try {
+           if (jpegCompressionQuality != -1) {
+               if (!writeJPEG(dump, jpegCompressionQuality, file)) {
+                   return ExportRenderer.IOEXCEPTION_ERROR;
                }
-               return ExportRenderer.SUCCESS;
+           } else {
+               ImageIO.write(dump, getFileExtension(), file);
+           }
+        } catch (IOException e) {
+            return ExportRenderer.IOEXCEPTION_ERROR;
+        }
+        return ExportRenderer.SUCCESS;
+    }
+
+    /**
+     * Gives the extension of a file name
+     * @return the extension of the file
+     */
+    private String getFileExtension() {
+        String fileName = file.getName().toLowerCase();
+        fileExtension = fileName.substring(fileName.lastIndexOf('.') + 1, fileName.length());
+        return fileExtension;
+    }
+
+    /**
+     * @param image the image to compress
+     * @param compressionQuality the compression rate
+     * @param file the output file
+     */
+    private boolean writeJPEG(BufferedImage image, float compressionQuality, File file) throws IOException {
+       Iterator iter = ImageIO.getImageWritersByFormatName("jpeg");
+       ImageWriter writer;
+       if (iter.hasNext()) {
+            writer = (ImageWriter) iter.next();
+       } else {
+           return false;
        }
-
-       /**
-        * Gives the extension of a file name
-        * @return the extension of the file
-        */
-       private String getFileExtension() {             
-               
-               String fileName = file.getName().toLowerCase();
-               fileExtension = fileName.substring(fileName.lastIndexOf('.') + 1, fileName.length());
-               return fileExtension;
-       }       
-
+       ImageWriteParam param = writer.getDefaultWriteParam();
+       param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
+       param.setCompressionQuality(compressionQuality);
+       FileImageOutputStream output = new FileImageOutputStream(file);
+       writer.setOutput(output);
+       writer.write(null, new IIOImage(image, null, null), param);
+       writer.dispose();
+       return true;
+    }
 }
-
index c14f2f6..006e8b7 100644 (file)
@@ -84,7 +84,7 @@ public abstract class ExportRenderer implements GLEventListener {
         * @param fileOrientation orientation of the file
         * @return GL2PSRenderer export a postscript screen-shot
         */
-       public static ExportRenderer createExporter(int figureIndex, String fileName, int fileType, int fileOrientation) {
+       public static ExportRenderer createExporter(int figureIndex, String fileName, int fileType, float jpegCompressionQuality, int fileOrientation) {
                
                GL2PS gl2ps = new GL2PS();
                
@@ -95,7 +95,7 @@ public abstract class ExportRenderer implements GLEventListener {
                case JPG_EXPORT:
                case PNG_EXPORT:
                case PPM_EXPORT:
-                       return new BitmapRenderer(fileName, fileType, fileOrientation);
+                       return new BitmapRenderer(fileName, fileType, jpegCompressionQuality, fileOrientation);
                case EPS_EXPORT:
                case PDF_EXPORT:
                case SVG_EXPORT:
index 99eff99..a131c7f 100644 (file)
@@ -106,16 +106,18 @@ public abstract class ExportToFile {
         * Choose which kind of filetype will be exported 
         * @param filetype type of the file
         * @param fileName name of the file
+        * @param jpegCompressionQuality the jpeg compression rate
         * @return new ExportBitmap of
         */
-       public static ExportToFile createExporter(String fileName, int filetype) {      
+        public static ExportToFile createExporter(String fileName, int filetype, float jpegCompressionQuality) {       
                /** Select in which type the file will be exported */
                switch (filetype) {
                case ExportRenderer.BMP_EXPORT:  
                case ExportRenderer.GIF_EXPORT:
-               case ExportRenderer.JPG_EXPORT:
                case ExportRenderer.PNG_EXPORT:
                        return new ExportBitmap(fileName, filetype);
+               case ExportRenderer.JPG_EXPORT:
+                       return new ExportBitmap(fileName, filetype, jpegCompressionQuality);
                case ExportRenderer.PPM_EXPORT:
                        return new ExportPPM(fileName, filetype);         
                default: System.err.println(ExportRenderer.INVALID_FILE);
index bbaa323..980aa63 100644 (file)
@@ -49,7 +49,7 @@ public class FileExporter {
      * @return 0 if everything worked fine, a non null integer if an exception occured
      *         depending on the kind of error
      */
-    public static int fileExport(int figureIndex, String fileName, int fileType, int fileOrientation) {
+    public static int fileExport(int figureIndex, String fileName, int fileType, float jpegCompressionQuality, int fileOrientation) {
         int saveFileType = -1;
         String saveFileName = "";
     
@@ -129,7 +129,7 @@ public class FileExporter {
         }
     
         ExportRenderer export;
-        export = ExportRenderer.createExporter(figureIndex, fileName, fileType, fileOrientation);
+        export = ExportRenderer.createExporter(figureIndex, fileName, fileType, jpegCompressionQuality, fileOrientation);
 
         // To be sure that their is a GLContext active for export
         exportedFig.openGraphicCanvas();
index 894e8d8..3110979 100644 (file)
@@ -1,5 +1,5 @@
 #include "FileExporter.hxx"
-/* Generated by GIWS (version 1.2.3) */
+/* Generated by GIWS (version 1.2.1) */
 /*
 
 Copyright 2007-2008 INRIA
@@ -104,7 +104,7 @@ throw GiwsException::JniObjectCreationException(curEnv, this->className());
 curEnv->DeleteLocalRef(localInstance);
 
                 /* Methods ID set to NULL */
-jintfileExportjintjstringjintjintID=NULL; 
+jintfileExportjintjstringjintjfloatjintID=NULL; 
 
 
 }
@@ -127,7 +127,7 @@ throw GiwsException::JniObjectCreationException(curEnv, this->className());
 throw GiwsException::JniObjectCreationException(curEnv, this->className());
         }
         /* Methods ID set to NULL */
-        jintfileExportjintjstringjintjintID=NULL; 
+        jintfileExportjintjstringjintjfloatjintID=NULL; 
 
 
 }
@@ -147,20 +147,20 @@ throw GiwsException::JniMonitorException(getCurrentEnv(), "FileExporter");
 }
 // Method(s)
 
-int FileExporter::fileExport (JavaVM * jvm_, int figureIndex, char * fileName, int fileType, int orientation){
+int FileExporter::fileExport (JavaVM * jvm_, int figureIndex, char * fileName, int fileType, float jpegCompressionQuality, int orientation){
 
 JNIEnv * curEnv = NULL;
 jvm_->AttachCurrentThread(reinterpret_cast<void **>(&curEnv), NULL);
 jclass cls = curEnv->FindClass( className().c_str() );
 
-jmethodID jintfileExportjintjstringjintjintID = curEnv->GetStaticMethodID(cls, "fileExport", "(ILjava/lang/String;II)I" ) ;
-if (jintfileExportjintjstringjintjintID == NULL) {
+jmethodID jintfileExportjintjstringjintjfloatjintID = curEnv->GetStaticMethodID(cls, "fileExport", "(ILjava/lang/String;IFI)I" ) ;
+if (jintfileExportjintjstringjintjfloatjintID == NULL) {
 throw GiwsException::JniMethodNotFoundException(curEnv, "fileExport");
 }
 
 jstring fileName_ = curEnv->NewStringUTF( fileName );
 
-                        jint res =  static_cast<jint>( curEnv->CallStaticIntMethod(cls, jintfileExportjintjstringjintjintID ,figureIndex, fileName_, fileType, orientation));
+                        jint res =  static_cast<jint>( curEnv->CallStaticIntMethod(cls, jintfileExportjintjstringjintjfloatjintID ,figureIndex, fileName_, fileType, jpegCompressionQuality, orientation));
                         if (curEnv->ExceptionCheck()) {
 throw GiwsException::JniCallMethodException(curEnv);
 }
index 157cada..ad08169 100644 (file)
@@ -16,6 +16,7 @@
       <parameter name="figureIndex" type="int"/>
       <parameter name="fileName" type="String"/>
       <parameter name="fileType" type="int"/>
+      <parameter name="jpegCompressionQuality" type="float"/>
       <parameter name="orientation" type="int"/>
     </method>
   </object>
index b645ce6..6beb9e7 100644 (file)
@@ -1,4 +1,4 @@
-/* Generated by GIWS (version 1.2.3) */
+/* Generated by GIWS (version 1.2.1) */
 /*
 
 Copyright 2007-2008 INRIA
@@ -64,7 +64,7 @@ private:
 JavaVM * jvm;
 
 protected:
-jmethodID jintfileExportjintjstringjintjintID; // cache method id
+jmethodID jintfileExportjintjstringjintjfloatjintID; // cache method id
 
 
 
@@ -121,7 +121,7 @@ void synchronize();
 void endSynchronize();
 
 // Methods
-static int fileExport(JavaVM * jvm_, int figureIndex, char * fileName, int fileType, int orientation);
+static int fileExport(JavaVM * jvm_, int figureIndex, char * fileName, int fileType, float jpegCompressionQuality, int orientation);
 
 
                         /**