branch develop updated (978274d -> 5b33e3b)
This is an automated email from the git hooks/post-receive script. New change to branch develop in repository izi-eval. See http://git.codelutin.com/izi-eval.git from 978274d fixes #7562: mise à jour de l'evaluation dexi eval lors de l'affichage des onglets evaluation, graphique et graphique synoptique new 5b33e3b refs #7578: Format d'export des graphiques The 1 revisions listed above as "new" are entirely new to this repository and will be described in separate emails. The revisions listed as "adds" were already present in the repository and have only been added to this reference. Detailed log of new commits: commit 5b33e3b41e3e86a3abb855c9ee8a10786e50a46c Author: Eric Chatellier <chatellier@codelutin.com> Date: Fri Jan 8 11:44:30 2016 +0100 refs #7578: Format d'export des graphiques Summary of changes: .../imageio/AbstractImageIORegistryEntry.java | 167 +++++++++++++++++ .../awt/image/codec/imageio/ImageIODebugUtil.java | 57 ++++++ .../image/codec/imageio/ImageIOImageWriter.java | 208 +++++++++++++++++++++ .../codec/imageio/ImageIOJPEGImageWriter.java | 146 +++++++++++++++ .../codec/imageio/ImageIOJPEGRegistryEntry.java | 41 ++++ .../image/codec/imageio/ImageIOPNGImageWriter.java | 35 ++++ .../codec/imageio/ImageIOPNGRegistryEntry.java | 36 ++++ .../codec/imageio/ImageIOTIFFImageWriter.java | 35 ++++ .../codec/imageio/ImageIOTIFFRegistryEntry.java | 45 +++++ .../imageio/PNGTranscoderImageIOWriteAdapter.java | 102 ++++++++++ .../imageio/TIFFTranscoderImageIOWriteAdapter.java | 103 ++++++++++ .../org.apache.batik.ext.awt.image.spi.ImageWriter | 31 +++ .../main/java/fr/inra/masc/ui/MascUIHelper.java | 3 +- .../masc/ui/widget/SimpleImagePanelHandler.java | 4 +- .../inra/masc/ui/widget/SvgImagePanelHandler.java | 27 ++- .../main/resources/i18n/masc-ui_en_GB.properties | 3 +- .../main/resources/i18n/masc-ui_fr_FR.properties | 5 +- 17 files changed, 1039 insertions(+), 9 deletions(-) create mode 100644 masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/AbstractImageIORegistryEntry.java create mode 100644 masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIODebugUtil.java create mode 100644 masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIOImageWriter.java create mode 100644 masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIOJPEGImageWriter.java create mode 100644 masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIOJPEGRegistryEntry.java create mode 100644 masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIOPNGImageWriter.java create mode 100644 masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIOPNGRegistryEntry.java create mode 100644 masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIOTIFFImageWriter.java create mode 100644 masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIOTIFFRegistryEntry.java create mode 100644 masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/PNGTranscoderImageIOWriteAdapter.java create mode 100644 masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/TIFFTranscoderImageIOWriteAdapter.java create mode 100644 masc-api/src/main/resources/META-INF/services/org.apache.batik.ext.awt.image.spi.ImageWriter -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository izi-eval. See http://git.codelutin.com/izi-eval.git commit 5b33e3b41e3e86a3abb855c9ee8a10786e50a46c Author: Eric Chatellier <chatellier@codelutin.com> Date: Fri Jan 8 11:44:30 2016 +0100 refs #7578: Format d'export des graphiques --- .../imageio/AbstractImageIORegistryEntry.java | 167 +++++++++++++++++ .../awt/image/codec/imageio/ImageIODebugUtil.java | 57 ++++++ .../image/codec/imageio/ImageIOImageWriter.java | 208 +++++++++++++++++++++ .../codec/imageio/ImageIOJPEGImageWriter.java | 146 +++++++++++++++ .../codec/imageio/ImageIOJPEGRegistryEntry.java | 41 ++++ .../image/codec/imageio/ImageIOPNGImageWriter.java | 35 ++++ .../codec/imageio/ImageIOPNGRegistryEntry.java | 36 ++++ .../codec/imageio/ImageIOTIFFImageWriter.java | 35 ++++ .../codec/imageio/ImageIOTIFFRegistryEntry.java | 45 +++++ .../imageio/PNGTranscoderImageIOWriteAdapter.java | 102 ++++++++++ .../imageio/TIFFTranscoderImageIOWriteAdapter.java | 103 ++++++++++ .../org.apache.batik.ext.awt.image.spi.ImageWriter | 31 +++ .../main/java/fr/inra/masc/ui/MascUIHelper.java | 3 +- .../masc/ui/widget/SimpleImagePanelHandler.java | 4 +- .../inra/masc/ui/widget/SvgImagePanelHandler.java | 27 ++- .../main/resources/i18n/masc-ui_en_GB.properties | 3 +- .../main/resources/i18n/masc-ui_fr_FR.properties | 5 +- 17 files changed, 1039 insertions(+), 9 deletions(-) diff --git a/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/AbstractImageIORegistryEntry.java b/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/AbstractImageIORegistryEntry.java new file mode 100644 index 0000000..69893b4 --- /dev/null +++ b/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/AbstractImageIORegistryEntry.java @@ -0,0 +1,167 @@ +/* see https://issues.apache.org/jira/browse/BATIK-1007 + %%Ignore-License + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ +package org.apache.batik.ext.awt.image.codec.imageio; + +import java.awt.geom.Rectangle2D; +import java.awt.image.BufferedImage; +import java.awt.image.ColorModel; +import java.awt.image.WritableRaster; +import java.io.IOException; +import java.io.InputStream; +import java.util.Iterator; + +import javax.imageio.ImageIO; +import javax.imageio.ImageReader; +import javax.imageio.stream.ImageInputStream; + +import org.apache.batik.ext.awt.image.GraphicsUtil; +import org.apache.batik.ext.awt.image.renderable.DeferRable; +import org.apache.batik.ext.awt.image.renderable.Filter; +import org.apache.batik.ext.awt.image.renderable.RedRable; +import org.apache.batik.ext.awt.image.rendered.Any2sRGBRed; +import org.apache.batik.ext.awt.image.rendered.CachableRed; +import org.apache.batik.ext.awt.image.rendered.FormatRed; +import org.apache.batik.ext.awt.image.spi.ImageTagRegistry; +import org.apache.batik.ext.awt.image.spi.MagicNumberRegistryEntry; +import org.apache.batik.util.ParsedURL; + +/** + * This is the base class for all ImageIO-based RegistryEntry implementations. They + * have a slightly lower priority than the RegistryEntry implementations using the + * internal codecs, so these take precedence if they are available. + * + * @version $Id: AbstractImageIORegistryEntry.java 1070137 2011-02-12 19:33:12Z jeremias $ + */ +public abstract class AbstractImageIORegistryEntry + extends MagicNumberRegistryEntry { + + /** + * Constructor + * @param name Format Name + * @param exts Standard set of extensions + * @param magicNumbers array of magic numbers any of which can match. + */ + public AbstractImageIORegistryEntry(String name, + String [] exts, + String [] mimeTypes, + MagicNumber [] magicNumbers) { + super(name, PRIORITY + 100, exts, mimeTypes, magicNumbers); + } + + /** + * Constructor, simplifies construction of entry when only + * one extension and one magic number is required. + * @param name Format Name + * @param ext Standard extension + * @param offset Offset of magic number + * @param magicNumber byte array to match. + */ + public AbstractImageIORegistryEntry(String name, + String ext, + String mimeType, + int offset, byte[] magicNumber) { + super(name, PRIORITY + 100, ext, mimeType, offset, magicNumber); + } + + /** + * Decode the Stream into a RenderableImage + * + * @param inIS The input stream that contains the image. + * @param origURL The original URL, if any, for documentation + * purposes only. This may be null. + * @param needRawData If true the image returned should not have + * any default color correction the file may + * specify applied. + */ + public Filter handleStream(InputStream inIS, + ParsedURL origURL, + boolean needRawData) { + final DeferRable dr = new DeferRable(); + final InputStream is = inIS; + final String errCode; + final Object [] errParam; + if (origURL != null) { + errCode = ERR_URL_FORMAT_UNREADABLE; + errParam = new Object[] {getFormatName(), origURL}; + } else { + errCode = ERR_STREAM_FORMAT_UNREADABLE; + errParam = new Object[] {getFormatName()}; + } + + Thread t = new Thread() { + @Override + public void run() { + Filter filt; + try{ + Iterator<ImageReader> iter = ImageIO.getImageReadersByMIMEType( + getMimeTypes().get(0).toString()); + if (!iter.hasNext()) { + throw new UnsupportedOperationException( + "No image reader for " + + getFormatName() + " available!"); + } + ImageReader reader = iter.next(); + ImageInputStream imageIn = ImageIO.createImageInputStream(is); + reader.setInput(imageIn, true); + + int imageIndex = 0; + dr.setBounds(new Rectangle2D.Double + (0, 0, + reader.getWidth(imageIndex), + reader.getHeight(imageIndex))); + CachableRed cr; + //Naive approach possibly wasting lots of memory + //and ignoring the gamma correction done by PNGRed :-( + //Matches the code used by the former JPEGRegistryEntry, though. + BufferedImage bi = reader.read(imageIndex); + cr = GraphicsUtil.wrap(bi); + cr = new Any2sRGBRed(cr); + cr = new FormatRed(cr, GraphicsUtil.sRGB_Unpre); + WritableRaster wr = (WritableRaster)cr.getData(); + ColorModel cm = cr.getColorModel(); + BufferedImage image = new BufferedImage + (cm, wr, cm.isAlphaPremultiplied(), null); + cr = GraphicsUtil.wrap(image); + filt = new RedRable(cr); + } catch (IOException ioe) { + // Something bad happened here... + filt = ImageTagRegistry.getBrokenLinkImage + (AbstractImageIORegistryEntry.this, + errCode, errParam); + } catch (ThreadDeath td) { + filt = ImageTagRegistry.getBrokenLinkImage + (AbstractImageIORegistryEntry.this, + errCode, errParam); + dr.setSource(filt); + throw td; + } catch (Throwable t) { + filt = ImageTagRegistry.getBrokenLinkImage + (AbstractImageIORegistryEntry.this, + errCode, errParam); + } + + dr.setSource(filt); + } + }; + t.start(); + return dr; + } + +} diff --git a/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIODebugUtil.java b/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIODebugUtil.java new file mode 100644 index 0000000..27a7059 --- /dev/null +++ b/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIODebugUtil.java @@ -0,0 +1,57 @@ +/* %%Ignore-License + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ +package org.apache.batik.ext.awt.image.codec.imageio; + +import javax.imageio.metadata.IIOMetadata; +import javax.xml.transform.Result; +import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; + +import org.w3c.dom.Node; + +/** + * Helper class for debugging stuff in Image I/O. + * + * @version $Id: ImageIODebugUtil.java 502538 2007-02-02 08:52:56Z dvholten $ + */ +public class ImageIODebugUtil { + + public static void dumpMetadata(IIOMetadata meta) { + String format = meta.getNativeMetadataFormatName(); + Node node = meta.getAsTree(format); + dumpNode(node); + } + + public static void dumpNode(Node node) { + try { + TransformerFactory tf = TransformerFactory.newInstance(); + Transformer t = tf.newTransformer(); + Source src = new DOMSource(node); + Result res = new StreamResult(System.out); + t.transform(src, res); + System.out.println(); + } catch (Exception e) { + e.printStackTrace(); + } + } + +} diff --git a/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIOImageWriter.java b/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIOImageWriter.java new file mode 100644 index 0000000..6f43a1e --- /dev/null +++ b/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIOImageWriter.java @@ -0,0 +1,208 @@ +/* %%Ignore-License + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ +package org.apache.batik.ext.awt.image.codec.imageio; + +import java.awt.image.RenderedImage; +import java.io.IOException; +import java.io.OutputStream; +import java.util.Iterator; + +import javax.imageio.IIOImage; +import javax.imageio.ImageIO; +import javax.imageio.ImageTypeSpecifier; +import javax.imageio.ImageWriteParam; +import javax.imageio.event.IIOWriteWarningListener; +import javax.imageio.metadata.IIOInvalidTreeException; +import javax.imageio.metadata.IIOMetadata; +import javax.imageio.metadata.IIOMetadataNode; +import javax.imageio.stream.ImageOutputStream; + +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import org.apache.batik.ext.awt.image.spi.ImageWriter; +import org.apache.batik.ext.awt.image.spi.ImageWriterParams; + +/** + * ImageWriter implementation that uses Image I/O to write images. + * + * @version $Id: ImageIOImageWriter.java 1377295 2012-08-25 13:44:25Z deweese $ + */ +public class ImageIOImageWriter implements ImageWriter, IIOWriteWarningListener { + + private String targetMIME; + + /** + * Main constructor. + * @param mime the MIME type of the image format + */ + public ImageIOImageWriter(String mime) { + this.targetMIME = mime; + } + + /** + * @see ImageWriter#writeImage(java.awt.image.RenderedImage, java.io.OutputStream) + */ + public void writeImage(RenderedImage image, OutputStream out) throws IOException { + writeImage(image, out, null); + } + + /** + * @see ImageWriter#writeImage(java.awt.image.RenderedImage, java.io.OutputStream, ImageWriterParams) + */ + public void writeImage(RenderedImage image, OutputStream out, + ImageWriterParams params) + throws IOException { + Iterator iter; + iter = ImageIO.getImageWritersByMIMEType(getMIMEType()); + javax.imageio.ImageWriter iiowriter = null; + try { + iiowriter = (javax.imageio.ImageWriter)iter.next(); + if (iiowriter != null) { + iiowriter.addIIOWriteWarningListener(this); + + ImageOutputStream imgout = null; + try { + imgout = ImageIO.createImageOutputStream(out); + ImageWriteParam iwParam = getDefaultWriteParam(iiowriter, image, params); + + ImageTypeSpecifier type; + if (iwParam.getDestinationType() != null) { + type = iwParam.getDestinationType(); + } else { + type = ImageTypeSpecifier.createFromRenderedImage(image); + } + + //Handle metadata + IIOMetadata meta = iiowriter.getDefaultImageMetadata( + type, iwParam); + //meta might be null for some JAI codecs as they don't support metadata + if (params != null && meta != null) { + meta = updateMetadata(meta, params); + } + + //Write image + iiowriter.setOutput(imgout); + IIOImage iioimg = new IIOImage(image, null, meta); + iiowriter.write(null, iioimg, iwParam); + } finally { + if (imgout != null) { + imgout.close(); + } + } + } else { + throw new UnsupportedOperationException("No ImageIO codec for writing " + + getMIMEType() + " is available!"); + } + } finally { + if (iiowriter != null) { + iiowriter.dispose(); + } + } + } + + /** + * Returns the default write parameters for encoding the image. + * @param iiowriter The IIO ImageWriter that will be used + * @param image the image to be encoded + * @param params the parameters for this writer instance + * @return the IIO ImageWriteParam instance + */ + protected ImageWriteParam getDefaultWriteParam( + javax.imageio.ImageWriter iiowriter, RenderedImage image, + ImageWriterParams params) { + ImageWriteParam param = iiowriter.getDefaultWriteParam(); + if ((params != null) && (params.getCompressionMethod() != null)) { + param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); + param.setCompressionType(params.getCompressionMethod()); + } + return param; + } + + /** + * Updates the metadata information based on the parameters to this writer. + * @param meta the metadata + * @param params the parameters + * @return the updated metadata + */ + protected IIOMetadata updateMetadata(IIOMetadata meta, ImageWriterParams params) { + final String stdmeta = "javax_imageio_1.0"; + if (meta.isStandardMetadataFormatSupported()) { + IIOMetadataNode root = (IIOMetadataNode)meta.getAsTree(stdmeta); + IIOMetadataNode dim = getChildNode(root, "Dimension"); + IIOMetadataNode child; + if (params.getResolution() != null) { + child = getChildNode(dim, "HorizontalPixelSize"); + if (child == null) { + child = new IIOMetadataNode("HorizontalPixelSize"); + dim.appendChild(child); + } + child.setAttribute("value", + Double.toString(params.getResolution().doubleValue() / 25.4)); + child = getChildNode(dim, "VerticalPixelSize"); + if (child == null) { + child = new IIOMetadataNode("VerticalPixelSize"); + dim.appendChild(child); + } + child.setAttribute("value", + Double.toString(params.getResolution().doubleValue() / 25.4)); + } + try { + meta.mergeTree(stdmeta, root); + } catch (IIOInvalidTreeException e) { + throw new RuntimeException("Cannot update image metadata: " + + e.getMessage()); + } + } + return meta; + } + + /** + * Returns a specific metadata child node + * @param n the base node + * @param name the name of the child + * @return the requested child node + */ + protected static IIOMetadataNode getChildNode(Node n, String name) { + NodeList nodes = n.getChildNodes(); + for (int i = 0; i < nodes.getLength(); i++) { + Node child = nodes.item(i); + if (name.equals(child.getNodeName())) { + return (IIOMetadataNode)child; + } + } + return null; + } + + /** + * @see ImageWriter#getMIMEType() + */ + public String getMIMEType() { + return this.targetMIME; + } + + /** + * @see javax.imageio.event.IIOWriteWarningListener#warningOccurred(javax.imageio.ImageWriter, int, java.lang.String) + */ + public void warningOccurred(javax.imageio.ImageWriter source, + int imageIndex, String warning) { + System.err.println("Problem while writing image using ImageI/O: " + + warning); + } +} diff --git a/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIOJPEGImageWriter.java b/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIOJPEGImageWriter.java new file mode 100644 index 0000000..e769744 --- /dev/null +++ b/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIOJPEGImageWriter.java @@ -0,0 +1,146 @@ +/* %%Ignore-License + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ +package org.apache.batik.ext.awt.image.codec.imageio; + +import java.awt.image.RenderedImage; + +import javax.imageio.ImageWriteParam; +import javax.imageio.ImageWriter; +import javax.imageio.metadata.IIOInvalidTreeException; +import javax.imageio.metadata.IIOMetadata; +import javax.imageio.metadata.IIOMetadataNode; +import javax.imageio.plugins.jpeg.JPEGImageWriteParam; + +import org.apache.batik.ext.awt.image.spi.ImageWriterParams; + +/** + * ImageWriter that encodes JPEG images using Image I/O. + * + * @version $Id: ImageIOJPEGImageWriter.java 1068104 2011-02-07 20:29:48Z jeremias $ + */ +public class ImageIOJPEGImageWriter extends ImageIOImageWriter { + + private static final String JPEG_NATIVE_FORMAT = "javax_imageio_jpeg_image_1.0"; + + /** + * Main constructor. + */ + public ImageIOJPEGImageWriter() { + super("image/jpeg"); + } + + /** {@inheritDoc} */ + @Override + protected IIOMetadata updateMetadata(IIOMetadata meta, ImageWriterParams params) { + //ImageIODebugUtil.dumpMetadata(meta); + if (JPEG_NATIVE_FORMAT.equals(meta.getNativeMetadataFormatName())) { + meta = addAdobeTransform(meta); + + IIOMetadataNode root = (IIOMetadataNode)meta.getAsTree(JPEG_NATIVE_FORMAT); + + IIOMetadataNode jv = getChildNode(root, "JPEGvariety"); + if (jv == null) { + jv = new IIOMetadataNode("JPEGvariety"); + root.appendChild(jv); + } + IIOMetadataNode child; + if (params.getResolution() != null) { + child = getChildNode(jv, "app0JFIF"); + if (child == null) { + child = new IIOMetadataNode("app0JFIF"); + jv.appendChild(child); + } + //JPEG gets special treatment because there seems to be a bug in + //the JPEG codec in ImageIO converting the pixel size incorrectly + //(or not at all) when using standard metadata format. + child.setAttribute("majorVersion", null); + child.setAttribute("minorVersion", null); + child.setAttribute("resUnits", "1"); //dots per inch + child.setAttribute("Xdensity", params.getResolution().toString()); + child.setAttribute("Ydensity", params.getResolution().toString()); + child.setAttribute("thumbWidth", null); + child.setAttribute("thumbHeight", null); + + } + + try { + meta.setFromTree(JPEG_NATIVE_FORMAT, root); + } catch (IIOInvalidTreeException e) { + throw new RuntimeException("Cannot update image metadata: " + + e.getMessage(), e); + } + + //ImageIODebugUtil.dumpMetadata(meta); + } + + return meta; + } + + private static IIOMetadata addAdobeTransform(IIOMetadata meta) { + // add the adobe transformation (transform 1 -> to YCbCr) + IIOMetadataNode root = (IIOMetadataNode)meta.getAsTree(JPEG_NATIVE_FORMAT); + + IIOMetadataNode markerSequence = getChildNode(root, "markerSequence"); + if (markerSequence == null) { + throw new RuntimeException("Invalid metadata!"); + } + + IIOMetadataNode adobeTransform = getChildNode(markerSequence, "app14Adobe"); + if (adobeTransform == null) { + adobeTransform = new IIOMetadataNode("app14Adobe"); + adobeTransform.setAttribute("transform" , "1"); // convert RGB to YCbCr + adobeTransform.setAttribute("version", "101"); + adobeTransform.setAttribute("flags0", "0"); + adobeTransform.setAttribute("flags1", "0"); + + markerSequence.appendChild(adobeTransform); + } else { + adobeTransform.setAttribute("transform" , "1"); + } + + try { + meta.setFromTree(JPEG_NATIVE_FORMAT, root); + } catch (IIOInvalidTreeException e) { + throw new RuntimeException("Cannot update image metadata: " + + e.getMessage(), e); + } + return meta; + } + + /** {@inheritDoc} */ + @Override + protected ImageWriteParam getDefaultWriteParam( + ImageWriter iiowriter, RenderedImage image, + ImageWriterParams params) { + JPEGImageWriteParam param = new JPEGImageWriteParam(iiowriter.getLocale()); + param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); + param.setCompressionQuality(params.getJPEGQuality()); + if (params.getCompressionMethod() != null + && !"JPEG".equals(params.getCompressionMethod())) { + throw new IllegalArgumentException( + "No compression method other than JPEG is supported for JPEG output!"); + } + if (params.getJPEGForceBaseline()) { + param.setProgressiveMode(JPEGImageWriteParam.MODE_DISABLED); + } + return param; + } + + +} diff --git a/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIOJPEGRegistryEntry.java b/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIOJPEGRegistryEntry.java new file mode 100644 index 0000000..6cf78a5 --- /dev/null +++ b/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIOJPEGRegistryEntry.java @@ -0,0 +1,41 @@ +/* %%Ignore-License + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ +package org.apache.batik.ext.awt.image.codec.imageio; + +/** + * RegistryEntry implementation for loading JPEG images through Image I/O. + * + * @version $Id: ImageIOJPEGRegistryEntry.java 502538 2007-02-02 08:52:56Z dvholten $ + */ +public class ImageIOJPEGRegistryEntry + extends AbstractImageIORegistryEntry { + + static final byte [] sigJPEG = {(byte)0xFF, (byte)0xd8, + (byte)0xFF}; + static final String [] exts = {"jpeg", "jpg" }; + static final String [] mimeTypes = {"image/jpeg", "image/jpg" }; + static final MagicNumber [] magicNumbers = { + new MagicNumber(0, sigJPEG) + }; + + public ImageIOJPEGRegistryEntry() { + super("JPEG", exts, mimeTypes, magicNumbers); + } + +} diff --git a/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIOPNGImageWriter.java b/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIOPNGImageWriter.java new file mode 100644 index 0000000..4cf3e99 --- /dev/null +++ b/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIOPNGImageWriter.java @@ -0,0 +1,35 @@ +/* %%Ignore-License + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ +package org.apache.batik.ext.awt.image.codec.imageio; + +/** + * ImageWriter that encodes PNG images using Image I/O. + * + * @version $Id: ImageIOPNGImageWriter.java 502538 2007-02-02 08:52:56Z dvholten $ + */ +public class ImageIOPNGImageWriter extends ImageIOImageWriter { + + /** + * Main constructor. + */ + public ImageIOPNGImageWriter() { + super("image/png"); + } + +} diff --git a/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIOPNGRegistryEntry.java b/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIOPNGRegistryEntry.java new file mode 100644 index 0000000..055cd61 --- /dev/null +++ b/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIOPNGRegistryEntry.java @@ -0,0 +1,36 @@ +/* %%Ignore-License + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ +package org.apache.batik.ext.awt.image.codec.imageio; + +/** + * RegistryEntry implementation for loading PNG images through Image I/O. + * + * @version $Id: ImageIOPNGRegistryEntry.java 502538 2007-02-02 08:52:56Z dvholten $ + */ +public class ImageIOPNGRegistryEntry + extends AbstractImageIORegistryEntry { + + + static final byte [] signature = {(byte)0x89, 80, 78, 71, 13, 10, 26, 10}; + + public ImageIOPNGRegistryEntry() { + super("PNG", "png", "image/png", 0, signature); + } + +} diff --git a/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIOTIFFImageWriter.java b/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIOTIFFImageWriter.java new file mode 100644 index 0000000..fb3a911 --- /dev/null +++ b/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIOTIFFImageWriter.java @@ -0,0 +1,35 @@ +/* %%Ignore-License + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ +package org.apache.batik.ext.awt.image.codec.imageio; + +/** + * ImageWriter that encodes TIFF images using Image I/O. + * + * @version $Id: ImageIOTIFFImageWriter.java 502538 2007-02-02 08:52:56Z dvholten $ + */ +public class ImageIOTIFFImageWriter extends ImageIOImageWriter { + + /** + * Main constructor. + */ + public ImageIOTIFFImageWriter() { + super("image/tiff"); + } + +} diff --git a/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIOTIFFRegistryEntry.java b/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIOTIFFRegistryEntry.java new file mode 100644 index 0000000..a079d74 --- /dev/null +++ b/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/ImageIOTIFFRegistryEntry.java @@ -0,0 +1,45 @@ +/* %%Ignore-License + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ +package org.apache.batik.ext.awt.image.codec.imageio; + +import org.apache.batik.ext.awt.image.spi.MagicNumberRegistryEntry; + +/** + * RegistryEntry implementation for loading TIFF images through Image I/O. + * + * @version $Id: ImageIOTIFFRegistryEntry.java 502538 2007-02-02 08:52:56Z dvholten $ + */ +public class ImageIOTIFFRegistryEntry + extends AbstractImageIORegistryEntry { + + static final byte [] sig1 = {(byte)0x49, (byte)0x49, 42, 0}; + static final byte [] sig2 = {(byte)0x4D, (byte)0x4D, 0, 42}; + + static MagicNumberRegistryEntry.MagicNumber [] magicNumbers = { + new MagicNumberRegistryEntry.MagicNumber(0, sig1), + new MagicNumberRegistryEntry.MagicNumber(0, sig2) }; + + static final String [] exts = {"tiff", "tif" }; + static final String [] mimeTypes = {"image/tiff", "image/tif" }; + + public ImageIOTIFFRegistryEntry() { + super("TIFF", exts, mimeTypes, magicNumbers); + } + +} diff --git a/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/PNGTranscoderImageIOWriteAdapter.java b/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/PNGTranscoderImageIOWriteAdapter.java new file mode 100644 index 0000000..116ff1f --- /dev/null +++ b/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/PNGTranscoderImageIOWriteAdapter.java @@ -0,0 +1,102 @@ +/* %%Ignore-License + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ +package org.apache.batik.ext.awt.image.codec.imageio; + +import java.awt.image.BufferedImage; +import java.io.IOException; +import java.io.OutputStream; + +import org.apache.batik.ext.awt.image.rendered.IndexImage; +import org.apache.batik.ext.awt.image.spi.ImageWriter; +import org.apache.batik.ext.awt.image.spi.ImageWriterParams; +import org.apache.batik.ext.awt.image.spi.ImageWriterRegistry; +import org.apache.batik.transcoder.TranscoderException; +import org.apache.batik.transcoder.TranscoderOutput; +import org.apache.batik.transcoder.TranscodingHints; +import org.apache.batik.transcoder.image.PNGTranscoder; + +/** + * This class is a helper to <code>PNGTranscoder</code> that writes PNG images + * through the Image I/O API. + * + * @version $Id: PNGTranscoderImageIOWriteAdapter.java 1372129 2012-08-12 15:31:50Z helder $ + */ +public class PNGTranscoderImageIOWriteAdapter implements + PNGTranscoder.WriteAdapter { + + /** + * @throws TranscoderException + * @see org.apache.batik.transcoder.image.PNGTranscoder.WriteAdapter#writeImage(org.apache.batik.transcoder.image.PNGTranscoder, java.awt.image.BufferedImage, org.apache.batik.transcoder.TranscoderOutput) + */ + public void writeImage(PNGTranscoder transcoder, BufferedImage img, + TranscoderOutput output) throws TranscoderException { + + TranscodingHints hints = transcoder.getTranscodingHints(); + + int n = -1; + if (hints.containsKey(PNGTranscoder.KEY_INDEXED)) { + n=((Integer)hints.get(PNGTranscoder.KEY_INDEXED)).intValue(); + if (n==1||n==2||n==4||n==8) + //PNGEncodeParam.Palette can handle these numbers only. + img = IndexImage.getIndexedImage(img, 1<<n); + } + + ImageWriter writer = ImageWriterRegistry.getInstance() + .getWriterFor("image/png"); + ImageWriterParams params = new ImageWriterParams(); + + /* NYI!!!!! + PNGEncodeParam params = PNGEncodeParam.getDefaultEncodeParam(img); + if (params instanceof PNGEncodeParam.RGB) { + ((PNGEncodeParam.RGB)params).setBackgroundRGB + (new int [] { 255, 255, 255 }); + }*/ + + // If they specify GAMMA key with a value of '0' then omit + // gamma chunk. If they do not provide a GAMMA then just + // generate an sRGB chunk. Otherwise supress the sRGB chunk + // and just generate gamma and chroma chunks. + /* NYI!!!!!! + if (hints.containsKey(PNGTranscoder.KEY_GAMMA)) { + float gamma = ((Float)hints.get(PNGTranscoder.KEY_GAMMA)).floatValue(); + if (gamma > 0) { + params.setGamma(gamma); + } + params.setChromaticity(PNGTranscoder.DEFAULT_CHROMA); + } else { + // We generally want an sRGB chunk and our encoding intent + // is perceptual + params.setSRGBIntent(PNGEncodeParam.INTENT_PERCEPTUAL); + }*/ + + + float PixSzMM = transcoder.getUserAgent().getPixelUnitToMillimeter(); + int PixSzInch = (int)(25.4 / PixSzMM + 0.5); + params.setResolution(PixSzInch); + + try { + OutputStream ostream = output.getOutputStream(); + writer.writeImage(img, ostream, params); + ostream.flush(); + } catch (IOException ex) { + throw new TranscoderException(ex); + } + } + +} diff --git a/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/TIFFTranscoderImageIOWriteAdapter.java b/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/TIFFTranscoderImageIOWriteAdapter.java new file mode 100644 index 0000000..9accefd --- /dev/null +++ b/masc-api/src/main/java/org/apache/batik/ext/awt/image/codec/imageio/TIFFTranscoderImageIOWriteAdapter.java @@ -0,0 +1,103 @@ +/* %%Ignore-License + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + */ +package org.apache.batik.ext.awt.image.codec.imageio; + +import java.awt.image.BufferedImage; +import java.awt.image.DataBuffer; +import java.awt.image.PixelInterleavedSampleModel; +import java.awt.image.RenderedImage; +import java.awt.image.SampleModel; +import java.awt.image.SinglePixelPackedSampleModel; +import java.io.IOException; +import java.io.OutputStream; + +import org.apache.batik.ext.awt.image.GraphicsUtil; +import org.apache.batik.ext.awt.image.rendered.FormatRed; +import org.apache.batik.ext.awt.image.spi.ImageWriter; +import org.apache.batik.ext.awt.image.spi.ImageWriterParams; +import org.apache.batik.ext.awt.image.spi.ImageWriterRegistry; +import org.apache.batik.transcoder.TranscoderException; +import org.apache.batik.transcoder.TranscoderOutput; +import org.apache.batik.transcoder.TranscodingHints; +import org.apache.batik.transcoder.image.TIFFTranscoder; + +/** + * This class is a helper to <code>TIFFTranscoder</code> that writes TIFF images + * through the Image I/O API. + * + * @version $Id: TIFFTranscoderImageIOWriteAdapter.java 1372129 2012-08-12 15:31:50Z helder $ + */ +public class TIFFTranscoderImageIOWriteAdapter + implements TIFFTranscoder.WriteAdapter { + + /** + * @throws TranscoderException + * @see org.apache.batik.transcoder.image.TIFFTranscoder.WriteAdapter#writeImage(TIFFTranscoder, java.awt.image.BufferedImage, org.apache.batik.transcoder.TranscoderOutput) + */ + public void writeImage(TIFFTranscoder transcoder, BufferedImage img, + TranscoderOutput output) throws TranscoderException { + + TranscodingHints hints = transcoder.getTranscodingHints(); + + ImageWriter writer = ImageWriterRegistry.getInstance() + .getWriterFor("image/tiff"); + ImageWriterParams params = new ImageWriterParams(); + + float PixSzMM = transcoder.getUserAgent().getPixelUnitToMillimeter(); + int PixSzInch = (int)(25.4 / PixSzMM + 0.5); + params.setResolution(PixSzInch); + + if (hints.containsKey(TIFFTranscoder.KEY_COMPRESSION_METHOD)) { + String method = (String)hints.get(TIFFTranscoder.KEY_COMPRESSION_METHOD); + //Values set here as defined in TIFFImageWriteParam of JAI Image I/O Tools + if ("packbits".equals(method)) { + params.setCompressionMethod("PackBits"); + } else if ("deflate".equals(method)) { + params.setCompressionMethod("Deflate"); + } else if ("lzw".equals(method)) { + params.setCompressionMethod("LZW"); + } else if ("jpeg".equals(method)) { + params.setCompressionMethod("JPEG"); + } else { + //nop + } + } + + try { + OutputStream ostream = output.getOutputStream(); + int w = img.getWidth(); + int h = img.getHeight(); + SinglePixelPackedSampleModel sppsm; + sppsm = (SinglePixelPackedSampleModel)img.getSampleModel(); + int bands = sppsm.getNumBands(); + int [] off = new int[bands]; + for (int i = 0; i < bands; i++) + off[i] = i; + SampleModel sm = new PixelInterleavedSampleModel + (DataBuffer.TYPE_BYTE, w, h, bands, w * bands, off); + + RenderedImage rimg = new FormatRed(GraphicsUtil.wrap(img), sm); + writer.writeImage(rimg, ostream, params); + ostream.flush(); + } catch (IOException ex) { + throw new TranscoderException(ex); + } + } + +} diff --git a/masc-api/src/main/resources/META-INF/services/org.apache.batik.ext.awt.image.spi.ImageWriter b/masc-api/src/main/resources/META-INF/services/org.apache.batik.ext.awt.image.spi.ImageWriter new file mode 100644 index 0000000..5a18e46 --- /dev/null +++ b/masc-api/src/main/resources/META-INF/services/org.apache.batik.ext.awt.image.spi.ImageWriter @@ -0,0 +1,31 @@ +# see https://issues.apache.org/jira/browse/BATIK-1007 +# %%Ignore-License +# ----------------------------------------------------------------------------- +# +# Licensed to the Apache Software Foundation (ASF) under one or more +# contributor license agreements. See the NOTICE file distributed with +# this work for additional information regarding copyright ownership. +# The ASF licenses this file to You under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with +# the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# This file registers PNG and JPEG writer classes. +# +# $Id: org.apache.batik.ext.awt.image.spi.ImageWriter 1366666 2012-07-28 13:09:53Z helder $ +# ----------------------------------------------------------------------------- + +# NOTE: the "codec" package is deprecated, there entries are kept here for compatibility with older JVM versions +# (uses "sun.image", which is only supported in Sun Java implementations and was retired in JDK 7) +#org.apache.batik.ext.awt.image.codec.png.PNGImageWriter + +org.apache.batik.ext.awt.image.codec.imageio.ImageIOPNGImageWriter +org.apache.batik.ext.awt.image.codec.imageio.ImageIOTIFFImageWriter +org.apache.batik.ext.awt.image.codec.imageio.ImageIOJPEGImageWriter diff --git a/masc-ui/src/main/java/fr/inra/masc/ui/MascUIHelper.java b/masc-ui/src/main/java/fr/inra/masc/ui/MascUIHelper.java index 3950a31..238862c 100644 --- a/masc-ui/src/main/java/fr/inra/masc/ui/MascUIHelper.java +++ b/masc-ui/src/main/java/fr/inra/masc/ui/MascUIHelper.java @@ -63,7 +63,8 @@ public class MascUIHelper extends JAXXWidgetUtil { DEXI_EVAL_APP(_("masc.file.app.dexiEval.dialog"), null, _("masc.fileType.app.dexiEval"), ".exe"), DEXI_APP(_("masc.file.app.dexi.dialog"), null, _("masc.fileType.app.dexi"), ".exe"), R_APP(_("masc.file.app.r.dialog"), null, _("masc.fileType.app.r"), ".exe"), - IMAGE(_("masc.file.app.image.dialog"), null, _("masc.fileType.app.image"), ".png"), + PNG(_("masc.file.app.image.dialog"), null, _("masc.fileType.app.png"), ".png"), + JPG(_("masc.file.app.image.dialog"), null, _("masc.fileType.app.jpg"), ".jpg", ".jpeg"), SVG(_("masc.file.app.image.svg"), null, _("masc.fileType.app.svg"), ".svg"), CSV(_("masc.file.app.import.csv"), null, _("masc.fileType.app.csv"), ".csv"), REPORT(null, _("masc.file.report.dialog"), _("masc.fileType.pdf"), ".pdf"); diff --git a/masc-ui/src/main/java/fr/inra/masc/ui/widget/SimpleImagePanelHandler.java b/masc-ui/src/main/java/fr/inra/masc/ui/widget/SimpleImagePanelHandler.java index c6c198c..23f81b2 100644 --- a/masc-ui/src/main/java/fr/inra/masc/ui/widget/SimpleImagePanelHandler.java +++ b/masc-ui/src/main/java/fr/inra/masc/ui/widget/SimpleImagePanelHandler.java @@ -6,7 +6,7 @@ package fr.inra.masc.ui.widget; * $Id:$ * $HeadURL:$ * %% - * Copyright (C) 2011 - 2013 Inra, Codelutin + * Copyright (C) 2011 - 2016 Inra, Codelutin * %% * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as @@ -71,7 +71,7 @@ public class SimpleImagePanelHandler extends ImagePanelHandler<SimpleImagePanel> @Override public void exportAsFile() { File file = MascUIHelper.saveAsFile( - ui, MascUIHelper.MascFileType.IMAGE, "masc"); + ui, MascUIHelper.MascFileType.PNG, "izi-eval"); if (file != null) { try { diff --git a/masc-ui/src/main/java/fr/inra/masc/ui/widget/SvgImagePanelHandler.java b/masc-ui/src/main/java/fr/inra/masc/ui/widget/SvgImagePanelHandler.java index 91e6559..3bdcd32 100644 --- a/masc-ui/src/main/java/fr/inra/masc/ui/widget/SvgImagePanelHandler.java +++ b/masc-ui/src/main/java/fr/inra/masc/ui/widget/SvgImagePanelHandler.java @@ -39,6 +39,8 @@ import java.util.Date; import javax.swing.JComponent; import javax.swing.JOptionPane; +import org.apache.batik.ext.awt.image.spi.ImageWriter; +import org.apache.batik.ext.awt.image.spi.ImageWriterRegistry; import org.apache.batik.swing.JSVGCanvas; import org.apache.batik.swing.JSVGScrollPane; import org.apache.batik.swing.svg.GVTTreeBuilderAdapter; @@ -47,10 +49,12 @@ import org.apache.batik.swing.svg.JSVGComponent; import org.apache.batik.transcoder.Transcoder; import org.apache.batik.transcoder.TranscoderInput; import org.apache.batik.transcoder.TranscoderOutput; +import org.apache.batik.transcoder.image.JPEGTranscoder; import org.apache.batik.transcoder.image.PNGTranscoder; import org.apache.batik.transcoder.svg2svg.SVGTranscoder; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.apache.xmlgraphics.image.writer.imageio.ImageIOJPEGImageWriter; import org.w3c.dom.svg.SVGDocument; import fr.inra.masc.ui.MascUIHelper; @@ -129,18 +133,35 @@ public class SvgImagePanelHandler extends ImagePanelHandler<SvgImagePanel> { public void exportAsFile() { File file = MascUIHelper.saveAsFile( - ui, MascUIHelper.MascFileType.SVG.getSaveTitle(), "masc", MascUIHelper.MascFileType.SVG, MascUIHelper.MascFileType.IMAGE); + ui, MascUIHelper.MascFileType.SVG.getSaveTitle(), "izi-eval", + MascUIHelper.MascFileType.SVG, MascUIHelper.MascFileType.JPG, MascUIHelper.MascFileType.PNG); if (file != null) { try { Transcoder transcoder; TranscoderOutput transcoderOutput; - if (file.getName().endsWith(".png")) { + String filenameLC = file.getName().toLowerCase(); + if (filenameLC.endsWith(".png")) { transcoderOutput = new TranscoderOutput(new FileOutputStream(file)); transcoder = new PNGTranscoder(); + + // to handle memory leak + // 7680*4320 fails (but ok with 2048 xmx) + // 3840*2160 fails (but ok with 2048 xmx) + // 1920*1080 ok + transcoder.addTranscodingHint(PNGTranscoder.KEY_MAX_HEIGHT, new Float(4320)); + transcoder.addTranscodingHint(PNGTranscoder.KEY_MAX_WIDTH, new Float(7680)); + + } else if (filenameLC.endsWith(".jpg") || filenameLC.endsWith(".jpeg")) { + transcoderOutput = new TranscoderOutput(new FileOutputStream(file)); + transcoder = new JPEGTranscoder(); + + // to handle memory leak + transcoder.addTranscodingHint(PNGTranscoder.KEY_MAX_HEIGHT, new Float(4320)); + transcoder.addTranscodingHint(PNGTranscoder.KEY_MAX_WIDTH, new Float(7680)); } else { - transcoder = new SVGTranscoder(); transcoderOutput = new TranscoderOutput(new FileWriter(file)); + transcoder = new SVGTranscoder(); } transcoder.transcode(new TranscoderInput(jsvgCanvas.getSVGDocument()), transcoderOutput); diff --git a/masc-ui/src/main/resources/i18n/masc-ui_en_GB.properties b/masc-ui/src/main/resources/i18n/masc-ui_en_GB.properties index 74513b8..d27c183 100644 --- a/masc-ui/src/main/resources/i18n/masc-ui_en_GB.properties +++ b/masc-ui/src/main/resources/i18n/masc-ui_en_GB.properties @@ -106,7 +106,8 @@ masc.file.saveAs.dialog=Save as a IZI-EVAL file masc.fileType.app.csv=CSV file (*.csv) masc.fileType.app.dexi=Executable file (*.exe) masc.fileType.app.dexiEval=Executable file (*.exe) -masc.fileType.app.image=PNG Image (*.png) +masc.fileType.app.jpg=JPEG Image (*.jpg) +masc.fileType.app.png=PNG Image (*.png) masc.fileType.app.r=Please select R executable file. masc.fileType.app.svg=SVG Image (*.svg) masc.fileType.dexi=DEXi file (*.dxi) diff --git a/masc-ui/src/main/resources/i18n/masc-ui_fr_FR.properties b/masc-ui/src/main/resources/i18n/masc-ui_fr_FR.properties index d07991a..8595dcf 100644 --- a/masc-ui/src/main/resources/i18n/masc-ui_fr_FR.properties +++ b/masc-ui/src/main/resources/i18n/masc-ui_fr_FR.properties @@ -100,13 +100,14 @@ masc.file.app.import.csv=Merci de sélectionner un fichier CSV. masc.file.app.r.dialog=Merci de sélectionner l'application R. masc.file.export.dialog=Merci de sélectionner un fichier à exporter. masc.file.import.dialog=Merci d'ouvrir un fichier DEXi. -masc.file.open.dialog=Ouvrir un fichier DEXi (*.dxi) ou IZI-EVAL (*.izi). +masc.file.open.dialog=Ouvrir un fichier DEXi (*.dxi) ou IZI-EVAL (*.izi) masc.file.report.dialog=Merci de sélectionner un fichier pour les exports. masc.file.saveAs.dialog=Sauvegarde d'un fichier IZI-EVAL sous masc.fileType.app.csv=Fichier CSV (*.csv) masc.fileType.app.dexi=Fichier exécutable (*.exe) masc.fileType.app.dexiEval=Fichier exécutable (*.exe) -masc.fileType.app.image=Image PNG (*.png) +masc.fileType.app.jpg=Image JPEG (*.jpg) +masc.fileType.app.png=Image PNG (*.png) masc.fileType.app.r=Fichier exécutable (*.exe) masc.fileType.app.svg=Image SVG (*.svg) masc.fileType.dexi=Fichier DEXi (*.dxi) -- To stop receiving notification emails like this one, please contact codelutin.com SCM administrator <admin+scm@codelutin.com>.
participants (1)
-
codelutin.com scm