]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Fixes unrecoverable exceptions causing BatchDiffer to fail.
authorJeremias Maerki <jeremias@apache.org>
Wed, 24 Aug 2005 13:43:00 +0000 (13:43 +0000)
committerJeremias Maerki <jeremias@apache.org>
Wed, 24 Aug 2005 13:43:00 +0000 (13:43 +0000)
Doing a clean separation of encoded and decoded data inside the image implementations. Helps fix a problem with the encoded CCITT TIFF being sent to the PS output even though this is not yet implemented.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@239661 13f79535-47bb-0310-9956-ffa450edef68

src/java-1.4/org/apache/fop/image/ImageIOImage.java
src/java/org/apache/fop/image/AbstractFopImage.java
src/java/org/apache/fop/image/BatikImage.java
src/java/org/apache/fop/image/BmpImage.java
src/java/org/apache/fop/image/GifImage.java
src/java/org/apache/fop/image/JAIImage.java
src/java/org/apache/fop/image/JimiImage.java
src/java/org/apache/fop/image/JpegImage.java
src/java/org/apache/fop/image/TIFFImage.java
src/java/org/apache/fop/render/pdf/FopPDFImage.java
src/java/org/apache/fop/render/ps/PSImageUtils.java

index 56bb863b769519c772a402e7d1e5fce800476564..111011918f4989b15c178d5f3b1b8ec726d7bedc 100644 (file)
@@ -127,8 +127,7 @@ public class ImageIOImage extends AbstractFopImage {
             }
 
             // Should take care of the ColorSpace and bitsPerPixel
-            this.bitmapsSize = this.width * this.height * 3;
-            this.bitmaps = new byte[this.bitmapsSize];
+            this.bitmaps = new byte[this.width * this.height * 3];
             for (int i = 0; i < this.height; i++) {
                 for (int j = 0; j < this.width; j++) {
                     int p = tmpMap[i * this.width + j];
index 2a9136f8084caadf860a8d66c51ad7eb5a236cae..461b474eaebde02c27c6c2e7a381b53dce43c437 100644 (file)
@@ -82,14 +82,14 @@ public abstract class AbstractFopImage implements FopImage {
     protected int bitsPerPixel = 0;
 
     /**
-     * Image data (uncompressed).
+     * Image data (pixels, uncompressed).
      */
     protected byte[] bitmaps = null;
 
     /**
-     * Image data size.
+     * Image data (undecoded, compressed, for image formats that can be embedded without decoding.
      */
-    protected int bitmapsSize = 0;
+    protected byte[] raw = null;
 
     /**
      * Image transparency.
@@ -298,7 +298,7 @@ public abstract class AbstractFopImage implements FopImage {
     }
 
     /**
-     * Return the image data (uncompressed).
+     * Return the image data (pixels, uncompressed).
      * @return the image data
      */
     public byte[] getBitmaps() {
@@ -306,11 +306,11 @@ public abstract class AbstractFopImage implements FopImage {
     }
 
     /**
-     * Return the image data size (uncompressed).
+     * Return the image data size (number of bytes taken up by the uncompressed pixels).
      * @return the image data size
      */
     public int getBitmapsSize() {
-        return this.bitmapsSize;
+        return (bitmaps != null ? bitmaps.length : 0);
     }
 
     /**
@@ -318,7 +318,7 @@ public abstract class AbstractFopImage implements FopImage {
      * @return the original image data
      */
     public byte[] getRessourceBytes() {
-        return null;
+        return raw;
     }
 
     /**
@@ -326,7 +326,7 @@ public abstract class AbstractFopImage implements FopImage {
      * @return the original image data size
      */
     public int getRessourceBytesSize() {
-        return 0;
+        return (raw != null ? raw.length : 0);
     }
 
 }
index 380b21ab6c47dfae013517849f71b4ef04f0ab89..1f6d7405b893ec771a7e1ed9910cb14555fe43f2 100644 (file)
@@ -140,7 +140,7 @@ public abstract class BatikImage extends AbstractFopImage {
      * @see org.apache.fop.image.FopImage#hasSoftMask()
      */
     public boolean hasSoftMask() {
-        if (this.bitmaps == null) {
+        if (this.bitmaps == null && this.raw == null) {
             loadImage();
         }
 
@@ -172,15 +172,20 @@ public abstract class BatikImage extends AbstractFopImage {
     protected void loadImage() {
         if (loadDimensions()) {
             try {
+                if (cr == null) {
+                    throw new IllegalStateException(
+                            "Can't load the bitmaps data without the CachableRed instance");
+                }
+                
                 // Get our current ColorModel
                 ColorModel cm = cr.getColorModel();
 
                 // It has an alpha channel so generate a soft mask.
-                if (!this.isTransparent && cm.hasAlpha())
+                if (!this.isTransparent && cm.hasAlpha()) {
                     this.softMask = new byte[this.width * this.height];
+                }
 
-                this.bitmapsSize = this.width * this.height * 3;
-                this.bitmaps = new byte[this.bitmapsSize];
+                this.bitmaps = new byte[this.width * this.height * 3];
 
                 WritableRaster wr = (WritableRaster)cr.getData();
                 BufferedImage bi = new BufferedImage
index 3e256cf7721515e0449d260a38ca9b9e4c86bfb5..64c43e8d19c9bd73219015f663806d2a3314e97c 100644 (file)
@@ -125,8 +125,7 @@ public class BmpImage extends AbstractFopImage {
         }
 
         // Should take care of the ColorSpace and bitsPerPixel
-        this.bitmapsSize = this.width * this.height * 3;
-        this.bitmaps = new byte[this.bitmapsSize];
+        this.bitmaps = new byte[this.width * this.height * 3];
 
         int[] temp = new int[bytes * this.height];
         try {
index 20c24525b11eeb834220001ff97d42998b5c907e..10a3d6328d066ad6d81a6d7eabe085afdf3b463a 100644 (file)
@@ -150,8 +150,7 @@ public class GifImage extends AbstractFopImage {
         }
 
         // Should take care of the ColorSpace and bitsPerPixel
-        this.bitmapsSize = this.width * this.height * 3;
-        this.bitmaps = new byte[this.bitmapsSize];
+        this.bitmaps = new byte[this.width * this.height * 3];
         for (int i = 0; i < this.height; i++) {
             for (int j = 0; j < this.width; j++) {
                 int p = tmpMap[i * this.width + j];
index a3e5a533c084f4bd70984b437c713fd54181c74f..c5fcd2304c1b442a90d5e6a459d83fcf1ffcfefa 100644 (file)
@@ -22,7 +22,6 @@ package org.apache.fop.image;
 import java.awt.image.ColorModel;
 import java.awt.image.IndexColorModel;
 import java.awt.image.BufferedImage;
-import java.awt.color.ColorSpace;
 import java.awt.Color;
 
 // JAI
@@ -150,8 +149,7 @@ public class JAIImage extends AbstractFopImage {
             }
 
             // Should take care of the ColorSpace and bitsPerPixel
-            this.bitmapsSize = this.width * this.height * 3;
-            this.bitmaps = new byte[this.bitmapsSize];
+            this.bitmaps = new byte[this.width * this.height * 3];
             for (int i = 0; i < this.height; i++) {
                 for (int j = 0; j < this.width; j++) {
                     int p = tmpMap[i * this.width + j];
index 103a067c480716e36928761eb91bdf70f161db3b..35db0bbc1dd76b026ab83ceb7609370d602a2d36 100644 (file)
@@ -76,8 +76,7 @@ public class JimiImage extends AbstractFopImage {
     protected void loadImage() {
         int[] tmpMap = null;
         try {
-            ImageProducer ip =
-              Jimi.getImageProducer(inputStream,
+            ImageProducer ip = Jimi.getImageProducer(inputStream,
                                     Jimi.SYNCHRONOUS | Jimi.IN_MEMORY);
             FopImageConsumer consumer = new FopImageConsumer(ip);
             ip.startProduction(consumer);
@@ -163,8 +162,7 @@ public class JimiImage extends AbstractFopImage {
 
 
         // Should take care of the ColorSpace and bitsPerPixel
-        this.bitmapsSize = this.width * this.height * 3;
-        this.bitmaps = new byte[this.bitmapsSize];
+        this.bitmaps = new byte[this.width * this.height * 3];
         for (int i = 0; i < this.height; i++) {
             for (int j = 0; j < this.width; j++) {
                 int p = tmpMap[i * this.width + j];
index 6a40e449595d64696fde977f4f795694b6c5dd5c..ad4f6fe408eb2e4a4c285bc2d094e3d3733e8cc1 100644 (file)
@@ -36,7 +36,6 @@ import org.apache.fop.util.CMYKColorSpace;
 public class JpegImage extends AbstractFopImage {
     private ICC_Profile iccProfile = null;
     private boolean foundICCProfile = false;
-    private boolean foundDimensions = false;
 
     /**
      * Create a jpeg image with the info.
@@ -74,38 +73,38 @@ public class JpegImage extends AbstractFopImage {
             inputStream = null;
         }
 
-        this.bitmaps = baos.toByteArray();
+        this.raw = baos.toByteArray();
         this.bitsPerPixel = 8;
         this.isTransparent = false;
 
         //Check for SOI (Start of image) marker (FFD8)
-        if (this.bitmaps.length > (index + 2)
-                && uByte(this.bitmaps[index]) == 255 /*0xFF*/
-                && uByte(this.bitmaps[index + 1]) == 216 /*0xD8*/) {
+        if (this.raw.length > (index + 2)
+                && uByte(this.raw[index]) == 255 /*0xFF*/
+                && uByte(this.raw[index + 1]) == 216 /*0xD8*/) {
             index += 2;
 
-            while (index < this.bitmaps.length && cont) {
+            while (index < this.raw.length && cont) {
                 //check to be sure this is the begining of a header
-                if (this.bitmaps.length > (index + 2)
-                        && uByte(this.bitmaps[index]) == 255 /*0xFF*/) {
+                if (this.raw.length > (index + 2)
+                        && uByte(this.raw[index]) == 255 /*0xFF*/) {
 
                     //192 or 194 are the header bytes that contain
                     // the jpeg width height and color depth.
-                    if (uByte(this.bitmaps[index + 1]) == 192 /*0xC0*/
-                            || uByte(this.bitmaps[index + 1]) == 194 /*0xC2*/) {
+                    if (uByte(this.raw[index + 1]) == 192 /*0xC0*/
+                            || uByte(this.raw[index + 1]) == 194 /*0xC2*/) {
 
-                        this.height = calcBytes(this.bitmaps[index + 5],
-                                                  this.bitmaps[index + 6]);
-                        this.width = calcBytes(this.bitmaps[index + 7],
-                                                 this.bitmaps[index + 8]);
+                        this.height = calcBytes(this.raw[index + 5],
+                                                  this.raw[index + 6]);
+                        this.width = calcBytes(this.raw[index + 7],
+                                                 this.raw[index + 8]);
 
-                        if (this.bitmaps[index + 9] == 1) {
+                        if (this.raw[index + 9] == 1) {
                             this.colorSpace = ColorSpace.getInstance(
                               ColorSpace.CS_GRAY);
-                        } else if (this.bitmaps[index + 9] == 3) {
+                        } else if (this.raw[index + 9] == 3) {
                             this.colorSpace = ColorSpace.getInstance(
                               ColorSpace.CS_LINEAR_RGB);
-                        } else if (this.bitmaps[index + 9] == 4) {
+                        } else if (this.raw[index + 9] == 4) {
                             // howto create CMYK color space
                             /*
                             this.colorSpace = ColorSpace.getInstance(
@@ -118,36 +117,35 @@ public class JpegImage extends AbstractFopImage {
                             return false;
                         }
 
-                        foundDimensions = true;
                         if (foundICCProfile) {
                             cont = false;
                             break;
                         }
-                        index += calcBytes(this.bitmaps[index + 2],
-                                           this.bitmaps[index + 3]) + 2;
+                        index += calcBytes(this.raw[index + 2],
+                                           this.raw[index + 3]) + 2;
 
-                    } else if (uByte(this.bitmaps[index + 1]) == 226 /*0xE2*/
-                                   && this.bitmaps.length > (index + 60)) {
+                    } else if (uByte(this.raw[index + 1]) == 226 /*0xE2*/
+                                   && this.raw.length > (index + 60)) {
                         // Check if ICC profile
                         byte[] iccString = new byte[11];
-                        System.arraycopy(this.bitmaps, index + 4,
+                        System.arraycopy(this.raw, index + 4,
                                          iccString, 0, 11);
 
                         if ("ICC_PROFILE".equals(new String(iccString))) {
                             int chunkSize = calcBytes(
-                                              this.bitmaps[index + 2],
-                                              this.bitmaps[index + 3]) + 2;
+                                              this.raw[index + 2],
+                                              this.raw[index + 3]) + 2;
 
-                            iccStream.write(this.bitmaps,
+                            iccStream.write(this.raw,
                                             index + 18, chunkSize - 18);
 
                         }
 
-                        index += calcBytes(this.bitmaps[index + 2],
-                                           this.bitmaps[index + 3]) + 2;
+                        index += calcBytes(this.raw[index + 2],
+                                           this.raw[index + 3]) + 2;
                     } else {
-                        index += calcBytes(this.bitmaps[index + 2],
-                                           this.bitmaps[index + 3]) + 2;
+                        index += calcBytes(this.raw[index + 2],
+                                           this.raw[index + 3]) + 2;
                     }
 
                 } else {
index 6be59663b12083bb04b7d64e551e85decdca2d0b..7aa327c99d6710be7952ee4fd3eb2c4cec60f30e 100644 (file)
@@ -62,9 +62,7 @@ public class TIFFImage extends BatikImage {
         return stripCount;
     }
 
-    /**
-     * @see org.apache.fop.image.BatikImage#decodeImage(org.apache.batik.ext.awt.image.codec.SeekableStream)
-     */
+    /** @see org.apache.fop.image.BatikImage */
     protected CachableRed decodeImage(SeekableStream stream) throws IOException {
         org.apache.batik.ext.awt.image.codec.tiff.TIFFImage img
             = new org.apache.batik.ext.awt.image.codec.tiff.TIFFImage
@@ -135,7 +133,7 @@ public class TIFFImage extends BatikImage {
                     return false;
                 }
 
-                this.bitmaps = readBuf;
+                this.raw = readBuf;
                 return true;
             } catch (IOException ioe) {
                 log.error("Error while loading image strip 1 (TIFF): ", ioe);
index e38c9f111cfba7035a4fc665d05eb88013735f00..97fee08f9238c78d117acaa34a38aaa245cac0dc 100644 (file)
@@ -213,7 +213,11 @@ public class FopPDFImage implements PDFImage {
         if (isPS) {
             outputPostScriptContents(out);
         } else {
-            out.write(fopImage.getBitmaps());
+            if (fopImage.getBitmapsSize() > 0) {
+                out.write(fopImage.getBitmaps());
+            } else {
+                out.write(fopImage.getRessourceBytes());
+            }
         }
     }
 
index 30998d8ca37bea6b1569614125423f77f3f8de30..c620dafb1e35ee798d78cf9593eeff5945802950 100644 (file)
@@ -66,7 +66,12 @@ public class PSImageUtils {
         }
         boolean iscolor = img.getColorSpace().getType()
                           != ColorSpace.CS_GRAY;
-        byte[] imgmap = img.getBitmaps();
+        byte[] imgmap;
+        if (img.getBitmapsSize() > 0) {
+            imgmap = img.getBitmaps();
+        } else {
+            imgmap = img.getRessourceBytes();
+        }
 
         gen.saveGraphicsState();
         gen.writeln(x + " " + y + " translate");