]> source.dussan.org Git - xmlgraphics-fop.git/commitdiff
Bugzilla #42406:
authorJeremias Maerki <jeremias@apache.org>
Mon, 21 May 2007 07:59:05 +0000 (07:59 +0000)
committerJeremias Maerki <jeremias@apache.org>
Mon, 21 May 2007 07:59:05 +0000 (07:59 +0000)
Use source resolution setting for bitmap images which don't provide their own resolution.
Submitted by: Hussein Shafie <hussein.at.xmlmind.com>

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

src/java/org/apache/fop/image/analyser/BMPReader.java
src/java/org/apache/fop/image/analyser/GIFReader.java
src/java/org/apache/fop/image/analyser/JPEGReader.java
src/java/org/apache/fop/image/analyser/PNGReader.java
src/java/org/apache/fop/image/analyser/TIFFReader.java
status.xml

index 7dfb29dc79274d2e1559e37cac00bf349d94e599..a4f401462dbfc535164014491341db73d361776d 100644 (file)
@@ -54,7 +54,11 @@ public class BMPReader implements ImageReader {
         boolean supported = ((header[0] == (byte) 0x42)
                 && (header[1] == (byte) 0x4d));
         if (supported) {
-            FopImage.ImageInfo info = getDimension(header);
+            FopImage.ImageInfo info = new FopImage.ImageInfo();
+            info.dpiHorizontal = ua.getFactory().getSourceResolution();
+            info.dpiVertical = info.dpiHorizontal;
+
+            getDimension(header, info);
             info.originalURI = uri;
             info.mimeType = getMimeType();
             info.inputStream = bis;
@@ -73,9 +77,7 @@ public class BMPReader implements ImageReader {
         return "image/bmp";
     }
 
-    private FopImage.ImageInfo getDimension(byte[] header) {
-        FopImage.ImageInfo info = new FopImage.ImageInfo();
-
+    private void getDimension(byte[] header, FopImage.ImageInfo info) {
         // little endian notation
         int byte1 = header[WIDTH_OFFSET] & 0xff;
         int byte2 = header[WIDTH_OFFSET + 1] & 0xff;
@@ -109,8 +111,6 @@ public class BMPReader implements ImageReader {
         if (l > 0) {
             info.dpiVertical = l / 39.37d;
         }
-        
-        return info;
     }
 
     private byte[] getDefaultHeader(InputStream imageStream)
index 74e52848192aeac3e54e31abe093d64d8549c158..206947f8872f1cf759a479c5494277413eb6eaff 100644 (file)
@@ -48,7 +48,11 @@ public class GIFReader implements ImageReader {
                 && (header[4] == '7' || header[4] == '9')
                 && (header[5] == 'a'));
         if (supported) {
-            FopImage.ImageInfo info = getDimension(header);
+            FopImage.ImageInfo info = new FopImage.ImageInfo();
+            info.dpiHorizontal = ua.getFactory().getSourceResolution();
+            info.dpiVertical = info.dpiHorizontal;
+
+            getDimension(header, info);
             info.originalURI = uri;
             info.mimeType = getMimeType();
             info.inputStream = bis;
@@ -67,8 +71,7 @@ public class GIFReader implements ImageReader {
         return "image/gif";
     }
 
-    private FopImage.ImageInfo getDimension(byte[] header) {
-        FopImage.ImageInfo info = new FopImage.ImageInfo();
+    private void getDimension(byte[] header, FopImage.ImageInfo info) {
         // little endian notation
         int byte1 = header[6] & 0xff;
         int byte2 = header[7] & 0xff;
@@ -77,7 +80,6 @@ public class GIFReader implements ImageReader {
         byte1 = header[8] & 0xff;
         byte2 = header[9] & 0xff;
         info.height = ((byte2 << 8) | byte1) & 0xffff;
-        return info;
     }
 
     private byte[] getDefaultHeader(InputStream imageStream)
index 1cb1d9212a2204805ff346eb2bdb0bd7747e2615..bfa7d78d8f4ccdd58169dbf5d4258f2c7fd8cfb1 100644 (file)
@@ -61,7 +61,11 @@ public class JPEGReader implements ImageReader {
         boolean supported = ((header[0] == (byte) 0xff)
                     && (header[1] == (byte) 0xd8));
         if (supported) {
-            FopImage.ImageInfo info = getDimension(fis);
+            FopImage.ImageInfo info = new FopImage.ImageInfo();
+            info.dpiHorizontal = ua.getFactory().getSourceResolution();
+            info.dpiVertical = info.dpiHorizontal;
+
+            getDimension(fis, info);
             info.originalURI = uri;
             info.mimeType = getMimeType();
             info.inputStream = fis;
@@ -97,8 +101,9 @@ public class JPEGReader implements ImageReader {
         return header;
     }
 
-    private FopImage.ImageInfo getDimension(InputStream imageStream) throws IOException {
-        FopImage.ImageInfo info = new FopImage.ImageInfo();
+    private void getDimension(InputStream imageStream,
+                              FopImage.ImageInfo info)
+        throws IOException {
         try {
             int pos=0, avail = imageStream.available();
             imageStream.mark(avail);
@@ -163,7 +168,8 @@ outer:
                             info.dpiHorizontal = xdensity;
                             info.dpiVertical = ydensity;
                         } else {
-                            //nop, nyi --> 72dpi
+                            // Use resolution specified in
+                            // FOUserAgent.getFactory() (default 72dpi).
                         }
                         
                         int restlen = reclen - 12;
@@ -237,7 +243,6 @@ outer:
             }
             throw ioe;
         }
-        return info;
     }
 
     private int read2bytes(InputStream imageStream) throws IOException {
index ab2c6bff354760e7e40d8f391a17048e2fe89ffe..1c46f8d6ebc5e378197f356ed2fb963d636755b3 100644 (file)
@@ -51,7 +51,11 @@ public class PNGReader implements ImageReader {
                 && (header[7] == (byte) 0x0a));
 
         if (supported) {
-            FopImage.ImageInfo info = getDimension(header);
+            FopImage.ImageInfo info = new FopImage.ImageInfo();
+            info.dpiHorizontal = ua.getFactory().getSourceResolution();
+            info.dpiVertical = info.dpiHorizontal;
+
+            getDimension(header, info);
             info.originalURI = uri;
             info.mimeType = getMimeType();
             info.inputStream = bis;
@@ -70,9 +74,7 @@ public class PNGReader implements ImageReader {
         return "image/png";
     }
 
-    private FopImage.ImageInfo getDimension(byte[] header) {
-        FopImage.ImageInfo info = new FopImage.ImageInfo();
-
+    private void getDimension(byte[] header, FopImage.ImageInfo info) {
         // png is always big endian
         int byte1 = header[16] & 0xff;
         int byte2 = header[17] & 0xff;
@@ -90,7 +92,6 @@ public class PNGReader implements ImageReader {
         byte4 = header[23] & 0xff;
         l = (long) ((byte1 << 24) | (byte2 << 16) | (byte3 << 8) | byte4);
         info.height = (int) l;
-        return info;
     }
 
     private byte[] getDefaultHeader(InputStream imageStream)
index 049e154a093af83bc0112945b338a05d38461273..a70a105d7cacebf1639b312ebac45f33441f4e9d 100644 (file)
@@ -62,7 +62,11 @@ public class TIFFReader implements ImageReader {
         }
 
         if (supported) {
-            FopImage.ImageInfo info = getDimension(header);
+            FopImage.ImageInfo info = new FopImage.ImageInfo();
+            info.dpiHorizontal = ua.getFactory().getSourceResolution();
+            info.dpiVertical = info.dpiHorizontal;
+
+            getDimension(header, info);
             info.originalURI = uri;
             info.mimeType = getMimeType();
             info.inputStream = bis;
@@ -81,33 +85,14 @@ public class TIFFReader implements ImageReader {
         return "image/tiff";
     }
 
-    private FopImage.ImageInfo getDimension(byte[] header) {
+    private void getDimension(byte[] header, FopImage.ImageInfo info) {
         // currently not setting the width and height
         // these are set again by the Jimi image reader.
         // I suppose I'll do it one day to be complete.  Or
         // someone else will.
         // Note: bytes 4,5,6,7 contain the byte offset in the stream of the first IFD block
-        /*
-         * //png is always big endian
-         * int byte1 = header[ 16 ] & 0xff;
-         * int byte2 = header[ 17 ] & 0xff;
-         * int byte3 = header[ 18 ] & 0xff;
-         * int byte4 = header[ 19 ] & 0xff;
-         * long l = ( long ) ( ( byte1 << 24 ) | ( byte2 << 16 ) |
-         * ( byte3 << 8 ) | byte4 );
-         * this.width = ( int ) ( l );
-         * byte1 = header[ 20 ] & 0xff;
-         * byte2 = header[ 21 ] & 0xff;
-         * byte3 = header[ 22 ] & 0xff;
-         * byte4 = header[ 23 ] & 0xff;
-         * l = ( long ) ( ( byte1 << 24 ) | ( byte2 << 16 ) | ( byte3 << 8 ) |
-         * byte4 );
-         * this.height = ( int ) ( l );
-         */
-        FopImage.ImageInfo info = new FopImage.ImageInfo();
         info.width = -1;
         info.height = -1;
-        return info;
     }
 
     private byte[] getDefaultHeader(InputStream imageStream)
index 2eee9a5e633dca9c08b6d7e01df43222ad08cb28..8e4e25a0c1f2aee303b9e7e7b087ab3e67076cd7 100644 (file)
 
   <changes>
     <release version="FOP Trunk">
+      <action context="Code" dev="JM" type="update" fixes-bug="42406" due-to="Hussein Shafie">
+        Use source resolution setting for bitmap images which don't provide their own
+        resolution.
+      </action>
       <action context="Code" dev="JM" type="fix" fixes-bug="42109" due-to="Paul Vinkenoog">
         Fixed the rendering of zero-width spaces for certain fonts by not generating them into
         the area tree.