You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xmlgraphics.apache.org by ma...@apache.org on 2009/07/29 10:11:13 UTC

svn commit: r798806 - in /xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl: ./ imageio/

Author: maxberger
Date: Wed Jul 29 08:11:13 2009
New Revision: 798806

URL: http://svn.apache.org/viewvc?rev=798806&view=rev
Log:
Bug #47561: Reverted changes from last week and added creation of ICC based color model instead.
This ensures the ColorModel matches the Profile

Modified:
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageBuffered.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterBuffered2Rendered.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterG2D2Bitmap.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderInternalTIFF.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageRendered.java
    xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/imageio/ImageLoaderImageIO.java

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageBuffered.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageBuffered.java?rev=798806&r1=798805&r2=798806&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageBuffered.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageBuffered.java Wed Jul 29 08:11:13 2009
@@ -20,7 +20,6 @@
 package org.apache.xmlgraphics.image.loader.impl;
 
 import java.awt.Color;
-import java.awt.color.ICC_Profile;
 import java.awt.image.BufferedImage;
 
 import org.apache.xmlgraphics.image.loader.ImageFlavor;
@@ -36,21 +35,9 @@
      * @param info the image info object
      * @param buffered the BufferedImage instance
      * @param transparentColor the transparent color or null
-     * @param iccProfile an ICC color profile or null if no profile is associated
-     */
-    public ImageBuffered(ImageInfo info, BufferedImage buffered, Color transparentColor,
-            ICC_Profile iccProfile) {
-        super(info, buffered, transparentColor, iccProfile);
-    }
-
-    /**
-     * Main constructor.
-     * @param info the image info object
-     * @param buffered the BufferedImage instance
-     * @param transparentColor the transparent color or null
      */
     public ImageBuffered(ImageInfo info, BufferedImage buffered, Color transparentColor) {
-        super(info, buffered, transparentColor, null);
+        super(info, buffered, transparentColor);
     }
 
     /** {@inheritDoc} */

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterBuffered2Rendered.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterBuffered2Rendered.java?rev=798806&r1=798805&r2=798806&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterBuffered2Rendered.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterBuffered2Rendered.java Wed Jul 29 08:11:13 2009
@@ -35,8 +35,7 @@
         checkSourceFlavor(src);
         ImageBuffered buffered = (ImageBuffered)src;
         return new ImageRendered(buffered.getInfo(), buffered
-                .getRenderedImage(), buffered.getTransparentColor(), buffered
-                .getICCProfile());
+                .getRenderedImage(), buffered.getTransparentColor());
     }
 
     /** {@inheritDoc} */

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterG2D2Bitmap.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterG2D2Bitmap.java?rev=798806&r1=798805&r2=798806&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterG2D2Bitmap.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageConverterG2D2Bitmap.java Wed Jul 29 08:11:13 2009
@@ -73,7 +73,7 @@
 
         BufferedImage bi = paintToBufferedImage(g2dImage, bitsPerPixel, withAlpha, resolution);
 
-        ImageBuffered bufImage = new ImageBuffered(src.getInfo(), bi, null, src.getICCProfile());
+        ImageBuffered bufImage = new ImageBuffered(src.getInfo(), bi, null);
         return bufImage;
     }
 

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderInternalTIFF.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderInternalTIFF.java?rev=798806&r1=798805&r2=798806&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderInternalTIFF.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageLoaderInternalTIFF.java Wed Jul 29 08:11:13 2009
@@ -71,7 +71,7 @@
             = new org.apache.xmlgraphics.image.codec.tiff.TIFFImage
                 (seekStream, null, 0);
         // TODO: This may ignore ICC Profiles stored in TIFF images.
-        return new ImageRendered(info, img, null, null);
+        return new ImageRendered(info, img, null);
     }
 
 }

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageRendered.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageRendered.java?rev=798806&r1=798805&r2=798806&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageRendered.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/ImageRendered.java Wed Jul 29 08:11:13 2009
@@ -45,35 +45,19 @@
      * @param transparentColor the transparent color or null
      * @param iccProfile an ICC color profile or null if no profile is associated
      */
-    public ImageRendered(ImageInfo info, RenderedImage red, Color transparentColor,
-            ICC_Profile iccProfile) {
+    public ImageRendered(ImageInfo info, RenderedImage red, Color transparentColor) {
         super(info);
         this.red = red;
         this.transparentColor = transparentColor;
-        if (iccProfile == null) {
-            this.colorSpace = red.getColorModel().getColorSpace();
-            if (this.colorSpace instanceof ICC_ColorSpace) {
-                ICC_ColorSpace icccs = (ICC_ColorSpace)this.colorSpace;
-                this.iccProfile = icccs.getProfile();
-            } else {
-                this.iccProfile = null;
-            }
+        this.colorSpace = red.getColorModel().getColorSpace();
+        if (this.colorSpace instanceof ICC_ColorSpace) {
+            ICC_ColorSpace icccs = (ICC_ColorSpace) this.colorSpace;
+            this.iccProfile = icccs.getProfile();
         } else {
-            this.iccProfile = iccProfile;
-            this.colorSpace = new ICC_ColorSpace(this.iccProfile);
+            this.iccProfile = null;
         }
     }
 
-    /**
-     * Main constructor.
-     * @param info the image info object
-     * @param red the RenderedImage instance
-     * @param transparentColor the transparent color or null
-     */
-    public ImageRendered(ImageInfo info, RenderedImage red, Color transparentColor) {
-        this(info, red, transparentColor, null);
-    }
-
     /** {@inheritDoc} */
     public ImageFlavor getFlavor() {
         return ImageFlavor.RENDERED_IMAGE;

Modified: xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/imageio/ImageLoaderImageIO.java
URL: http://svn.apache.org/viewvc/xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/imageio/ImageLoaderImageIO.java?rev=798806&r1=798805&r2=798806&view=diff
==============================================================================
--- xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/imageio/ImageLoaderImageIO.java (original)
+++ xmlgraphics/commons/trunk/src/java/org/apache/xmlgraphics/image/loader/impl/imageio/ImageLoaderImageIO.java Wed Jul 29 08:11:13 2009
@@ -20,12 +20,15 @@
 package org.apache.xmlgraphics.image.loader.impl.imageio;
 
 import java.awt.Color;
+import java.awt.color.ICC_ColorSpace;
 import java.awt.color.ICC_Profile;
 import java.awt.image.BufferedImage;
 import java.awt.image.ColorModel;
+import java.awt.image.ComponentColorModel;
 import java.awt.image.IndexColorModel;
 import java.awt.image.Raster;
 import java.awt.image.RenderedImage;
+import java.awt.image.WritableRaster;
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.util.HashSet;
@@ -172,16 +175,32 @@
             throw new ImageException("No ImageIO ImageReader found .");
         }
 
-        ICC_Profile iccProf = null;
-        
         ColorModel cm = imageData.getColorModel();
 
         Color transparentColor = null;
         if (cm instanceof IndexColorModel) {
             //transparent color will be extracted later from the image
         } else {
-            //ImageIOUtil.dumpMetadataToSystemOut(iiometa);
-            //Retrieve the transparent color from the metadata
+            if (providerIgnoresICC && cm instanceof ComponentColorModel) {
+                // Apply ICC Profile to Image by creating a new image with a new
+                // color model.
+                ICC_Profile iccProf = tryToExctractICCProfile(iiometa);
+                if (iccProf != null) {
+                    ColorModel cm2 = new ComponentColorModel(
+                            new ICC_ColorSpace(iccProf), cm.hasAlpha(), cm
+                                    .isAlphaPremultiplied(), cm
+                                    .getTransparency(), cm.getTransferType());
+                    WritableRaster wr = Raster.createWritableRaster(imageData
+                            .getSampleModel(), null);
+                    imageData.copyData(wr);
+                    BufferedImage bi = new BufferedImage(cm2, wr, cm2
+                            .isAlphaPremultiplied(), null);
+                    imageData = bi;
+                    cm = cm2;
+                }
+            }
+            // ImageIOUtil.dumpMetadataToSystemOut(iiometa);
+            // Retrieve the transparent color from the metadata
             if (iiometa != null && iiometa.isStandardMetadataFormatSupported()) {
                 Element metanode = (Element)iiometa.getAsTree(
                         IIOMetadataFormatImpl.standardMetadataFormatName);
@@ -205,16 +224,13 @@
                         }
                     }
                 }
-                if (providerIgnoresICC) {
-                    iccProf = tryToExctractICCProfile(iiometa);
-                }
             }
         }
 
         if (ImageFlavor.BUFFERED_IMAGE.equals(this.targetFlavor)) {
-            return new ImageBuffered(info, (BufferedImage)imageData, transparentColor, iccProf);
+            return new ImageBuffered(info, (BufferedImage)imageData, transparentColor);
         } else {
-            return new ImageRendered(info, imageData, transparentColor, iccProf);
+            return new ImageRendered(info, imageData, transparentColor);
         }
     }
 
@@ -347,13 +363,6 @@
     static {
         // TODO: This list could be kept in a resource file.
         providersIgnoringICC
-                .add("Java Advanced Imaging Image I/O Tools natively-accelerated PNG Image Reader/"
-                        + "Sun Microsystems, Inc./" + "1.1");
-        providersIgnoringICC
-                .add("Java Advanced Imaging Image I/O Tools natively-accelerated JPEG Image Reader/"
-                        + "Sun Microsystems, Inc./" + "1.1");
-
-        providersIgnoringICC
                 .add("Standard PNG image reader/Sun Microsystems, Inc./1.0");
         providersIgnoringICC
                 .add("Standard JPEG Image Reader/Sun Microsystems, Inc./0.5");



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org