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
version 2.
+Graphics:
+=========
+
+* It was not possible to set the compression quality when exporting into jpeg.
+ See bug 5573 and SEP 52.
+
+
Localization:
=============
<refnamediv>
<refname>xs2bmp</refname>
- <refpurpose>send graphics to a BMP file.</refpurpose>
+ <refpurpose>Export graphics to BMP.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<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>
<refnamediv>
<refname>xs2eps</refname>
- <refpurpose>send graphics to an EPS file.</refpurpose>
+ <refpurpose>Export graphics to EPS.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<refnamediv>
<refname>xs2fig</refname>
- <refpurpose>send graphics to a FIG file.</refpurpose>
+ <refpurpose>Export graphics to FIG.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<refnamediv>
<refname>xs2gif</refname>
- <refpurpose>send graphics to a GIF file.</refpurpose>
+ <refpurpose>Export graphics to GIF.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<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>
<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>
//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>
<refnamediv>
<refname>xs2pdf</refname>
- <refpurpose>save graphics to a PDF file.</refpurpose>
+ <refpurpose>Export graphics to PDF.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<refnamediv>
<refname>xs2png</refname>
- <refpurpose>send graphics to a PNG file.</refpurpose>
+ <refpurpose>Export graphics to PNG.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<refnamediv>
<refname>xs2ppm</refname>
- <refpurpose>send graphics to a PPM file.</refpurpose>
+ <refpurpose>Export graphics to PPM.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<refnamediv>
<refname>xs2ps</refname>
- <refpurpose>send graphics to a PS file.</refpurpose>
+ <refpurpose>Export graphics to PS.</refpurpose>
</refnamediv>
<refsynopsisdiv>
<refnamediv>
<refname>xs2svg</refname>
- <refpurpose>save graphics to a SVG file.</refpurpose>
+ <refpurpose>Export graphics to SVG.</refpurpose>
</refnamediv>
<refsynopsisdiv>
/*
-* 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>
/*--------------------------------------------------------------------------*/
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;
}
/*--------------------------------------------------------------------------*/
-
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);
}
/*---------------------------------------------------------------------------------*/
int exportToFile(sciPointObj * pFigure,
const char * fileName,
ExportFileType fileType,
+ const float jpegCompressionQuality,
ExportOrientation orientation);
#ifdef __cplusplus
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;
}
/**
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();
/*
* 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
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;
* @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;
+ }
}
-
* @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();
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:
* 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);
* @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 = "";
}
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();
#include "FileExporter.hxx"
-/* Generated by GIWS (version 1.2.3) */
+/* Generated by GIWS (version 1.2.1) */
/*
Copyright 2007-2008 INRIA
curEnv->DeleteLocalRef(localInstance);
/* Methods ID set to NULL */
-jintfileExportjintjstringjintjintID=NULL;
+jintfileExportjintjstringjintjfloatjintID=NULL;
}
throw GiwsException::JniObjectCreationException(curEnv, this->className());
}
/* Methods ID set to NULL */
- jintfileExportjintjstringjintjintID=NULL;
+ jintfileExportjintjstringjintjfloatjintID=NULL;
}
}
// 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);
}
<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>
-/* Generated by GIWS (version 1.2.3) */
+/* Generated by GIWS (version 1.2.1) */
/*
Copyright 2007-2008 INRIA
JavaVM * jvm;
protected:
-jmethodID jintfileExportjintjstringjintjintID; // cache method id
+jmethodID jintfileExportjintjstringjintjfloatjintID; // cache method id
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);
/**