]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Merge from trunk revision 593452:
authorJeremias Maerki <jeremias@apache.org>
Fri, 9 Nov 2007 08:43:45 +0000 (08:43 +0000)
committerJeremias Maerki <jeremias@apache.org>
Fri, 9 Nov 2007 08:43:45 +0000 (08:43 +0000)
Bugfix: An invalid PDF was created if a grayscale JPEG image with an sRGB profile was embedded undecoded. I didn't find any other way than to disable the the ICC profile in this case.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/fop-0_93@593453 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/fop/image/JpegImage.java

index 820a728f982e97951af585d53a46919db29f2ecf..60d5347c878dc70d3218caf33b292032bb63d776 100644 (file)
  
 package org.apache.fop.image;
 
-// Java
 import java.awt.color.ColorSpace;
 import java.awt.color.ICC_Profile;
 
-// FOP
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.io.output.ByteArrayOutputStream;
 import org.apache.fop.util.CMYKColorSpace;
@@ -100,13 +98,14 @@ public class JpegImage extends AbstractFopImage {
                         this.width = calcBytes(this.raw[index + 7],
                                                  this.raw[index + 8]);
 
-                        if (this.raw[index + 9] == 1) {
+                        int numComponents = this.raw[index + 9];
+                        if (numComponents == 1) {
                             this.colorSpace = ColorSpace.getInstance(
                               ColorSpace.CS_GRAY);
-                        } else if (this.raw[index + 9] == 3) {
+                        } else if (numComponents == 3) {
                             this.colorSpace = ColorSpace.getInstance(
                               ColorSpace.CS_LINEAR_RGB);
-                        } else if (this.raw[index + 9] == 4) {
+                        } else if (numComponents == 4) {
                             // howto create CMYK color space
                             /*
                             this.colorSpace = ColorSpace.getInstance(
@@ -193,6 +192,14 @@ public class JpegImage extends AbstractFopImage {
                 log.error("Invalid ICC profile: " + e, e);
                 return false;
             }
+            if (iccProfile.getNumComponents() != this.colorSpace.getNumComponents()) {
+                log.warn("The number of components of the ICC profile ("
+                        + iccProfile.getNumComponents() 
+                        + ") doesn't match the image ("
+                        + this.colorSpace.getNumComponents()
+                        + "). Ignoring the ICC color profile.");
+                this.iccProfile = null;
+            }
         } else if (this.colorSpace == null) {
             log.error("ColorSpace not specified for JPEG image");
             return false;