Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Redor2014-09-18 15:56:17 +0000
committerLaurent Redor2014-09-19 07:22:47 +0000
commitb60c11419cef88bb52889bdde7f2b149e81641ed (patch)
tree608f6012d6cc88ab72e04fc8b0f3037bbdea35d1
parentc8b9c32ec7a1cd98d6c485aac7492341e972eb7a (diff)
downloadorg.eclipse.sirius-b60c11419cef88bb52889bdde7f2b149e81641ed.tar.gz
org.eclipse.sirius-b60c11419cef88bb52889bdde7f2b149e81641ed.tar.xz
org.eclipse.sirius-b60c11419cef88bb52889bdde7f2b149e81641ed.zip
[436579] Improve quality of exported JPG image
Before we used reflection to modify a private encoderQFactor field. This problem is now resolved directly in swt, in ImageLoader class, with a new field named compression. This commit removed the old code and use the new parameter instead (compression=100 better than default 75). Change-Id: Ie343b759cafc2699dfdcae4e1e224b1bf678f672 Signed-off-by: Laurent Redor <laurent.redor@obeo.fr>
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/part/DiagramEditPartService.java7
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/part/SiriusFileFormat.java78
-rw-r--r--plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/part/SiriusImageLoader.java75
3 files changed, 5 insertions, 155 deletions
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/part/DiagramEditPartService.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/part/DiagramEditPartService.java
index 20c3d3c873..35138e2c73 100644
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/part/DiagramEditPartService.java
+++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/api/part/DiagramEditPartService.java
@@ -38,11 +38,11 @@ import org.eclipse.sirius.diagram.DSemanticDiagram;
import org.eclipse.sirius.diagram.ui.internal.refresh.layout.SiriusCanonicalLayoutHandler;
import org.eclipse.sirius.diagram.ui.provider.DiagramUIPlugin;
import org.eclipse.sirius.diagram.ui.tools.internal.part.OffscreenEditPartFactory;
-import org.eclipse.sirius.diagram.ui.tools.internal.part.SiriusImageLoader;
import org.eclipse.sirius.ui.tools.api.actions.export.SizeTooLargeException;
import org.eclipse.sirius.viewpoint.SiriusPlugin;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.graphics.ImageLoader;
import org.eclipse.swt.graphics.PaletteData;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.widgets.Shell;
@@ -255,10 +255,13 @@ public class DiagramEditPartService extends org.eclipse.gmf.runtime.diagram.ui.r
monitor.worked(1);
- SiriusImageLoader imageLoader = new SiriusImageLoader();
+ ImageLoader imageLoader = new ImageLoader();
imageLoader.data = new ImageData[] { imageData };
imageLoader.logicalScreenHeight = image.getBounds().width;
imageLoader.logicalScreenHeight = image.getBounds().height;
+ if (imageFormat.equals(ImageFileFormat.JPG)) {
+ imageLoader.compression = 100;
+ }
imageLoader.save(stream, imageFormat.getOrdinal());
monitor.worked(1);
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/part/SiriusFileFormat.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/part/SiriusFileFormat.java
deleted file mode 100644
index 33c378e634..0000000000
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/part/SiriusFileFormat.java
+++ /dev/null
@@ -1,78 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 THALES GLOBAL SERVICES.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.sirius.diagram.ui.tools.internal.part;
-
-import java.io.OutputStream;
-
-import org.eclipse.sirius.common.tools.api.util.ReflectionHelper;
-import org.eclipse.sirius.ext.base.Option;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.ImageLoader;
-import org.eclipse.swt.internal.image.FileFormat;
-
-/**
- * A specific FileFormat class to modify the encoderQFactor of the
- * {@link org.eclipse.swt.internal.image.JPEGFileFormat} to 100 to have a better
- * quality for JPG file.
- *
- * @author laurent.redor@obeo.fr
- *
- */
-public final class SiriusFileFormat {
- private static final int NEW_ENCODER_Q_FACTOR = 100;
-
- /**
- * Default constructor to avoid instantiation.
- */
- private SiriusFileFormat() {
-
- }
-
- /**
- * Write the device independent image array stored in the specified loader
- * to the specified output stream using the specified file format.
- *
- * @param os
- * The current OutputStream
- * @param format
- * The chosen format
- * @param loader
- * The loader used for this image
- */
- public static void save(OutputStream os, int format, ImageLoader loader) {
-
- if (format != SWT.IMAGE_JPEG)
- SWT.error(SWT.ERROR_UNSUPPORTED_FORMAT);
- if (loader.data == null || loader.data.length < 1)
- SWT.error(SWT.ERROR_INVALID_ARGUMENT);
-
- // Use the reflection to launch the save of JPG file with an
- // encoderQFactor of 99. It the introspection failed, the default save
- // is used.
- boolean reflectionCallOK = false;
-
- Option<Object> streamOption = ReflectionHelper.instantiateWithoutException("org.eclipse.swt.internal.image.LEDataOutputStream", new Class[] { OutputStream.class }, new Object[] { os });
- if (streamOption.some()) {
- Option<Object> fileFormatOption = ReflectionHelper.instantiateWithoutException("org.eclipse.swt.internal.image.JPEGFileFormat", new Class[0], new Object[0]);
- if (fileFormatOption.some()) {
- if (ReflectionHelper.setFieldValueWithoutException(fileFormatOption.get(), "encoderQFactor", NEW_ENCODER_Q_FACTOR)) {
- reflectionCallOK = ReflectionHelper.invokeMethodWithoutException(fileFormatOption.get(), "unloadIntoStream", new Class[] { ImageLoader.class, streamOption.get().getClass() },
- new Object[] { loader, streamOption.get() });
- }
- }
- }
- if (!reflectionCallOK) {
- // The reflection way failed, do it with the normal way with default
- // (0.75) quality...
- FileFormat.save(os, format, loader);
- }
- }
-}
diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/part/SiriusImageLoader.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/part/SiriusImageLoader.java
deleted file mode 100644
index a893acf93c..0000000000
--- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/part/SiriusImageLoader.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 THALES GLOBAL SERVICES.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Obeo - initial API and implementation
- *******************************************************************************/
-package org.eclipse.sirius.diagram.ui.tools.internal.part;
-
-import java.io.OutputStream;
-
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.SWTException;
-import org.eclipse.swt.graphics.ImageLoader;
-import org.eclipse.swt.internal.image.FileFormat;
-
-/**
- * Override ImageLoader to change the encodingQFactor of the JPEGFileFormat.
- *
- * @author <a href="mailto:laurent.redor@obeo.fr">Laurent Redor</a>
- *
- */
-public class SiriusImageLoader extends ImageLoader {
-
- /**
- * Saves the image data in this ImageLoader to the specified stream. The
- * format parameter can have one of the following values:
- * <dl>
- * <dt><code>IMAGE_BMP</code></dt>
- * <dd>Windows BMP file format, no compression</dd>
- * <dt><code>IMAGE_BMP_RLE</code></dt>
- * <dd>Windows BMP file format, RLE compression if appropriate</dd>
- * <dt><code>IMAGE_GIF</code></dt>
- * <dd>GIF file format</dd>
- * <dt><code>IMAGE_ICO</code></dt>
- * <dd>Windows ICO file format</dd>
- * <dt><code>IMAGE_JPEG</code></dt>
- * <dd>JPEG file format</dd>
- * <dt><code>IMAGE_PNG</code></dt>
- * <dd>PNG file format</dd>
- * </dl>
- *
- * @param stream
- * the output stream to write the images to
- * @param format
- * the format to write the images in
- *
- * @exception IllegalArgumentException
- * <ul>
- * <li>ERROR_NULL_ARGUMENT - if the stream is null</li>
- * </ul>
- * @exception SWTException
- * <ul>
- * <li>ERROR_IO - if an IO error occurs while writing to the
- * stream</li>
- * <li>ERROR_INVALID_IMAGE - if the image data contains
- * invalid data</li>
- * <li>ERROR_UNSUPPORTED_FORMAT - if the image data cannot be
- * saved to the requested format</li>
- * </ul>
- */
- public void save(OutputStream stream, int format) throws IllegalArgumentException, SWTException {
- if (stream == null)
- SWT.error(SWT.ERROR_NULL_ARGUMENT);
- if (format == SWT.IMAGE_JPEG) {
- SiriusFileFormat.save(stream, format, this);
- } else {
- FileFormat.save(stream, format, this);
- }
-
- }
-}

Back to the top