aboutsummaryrefslogtreecommitdiffstats
path: root/src/org/apache/fop/image/analyser/PNGReader.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/apache/fop/image/analyser/PNGReader.java')
-rw-r--r--src/org/apache/fop/image/analyser/PNGReader.java42
1 files changed, 23 insertions, 19 deletions
diff --git a/src/org/apache/fop/image/analyser/PNGReader.java b/src/org/apache/fop/image/analyser/PNGReader.java
index 29d794504..b41f19e37 100644
--- a/src/org/apache/fop/image/analyser/PNGReader.java
+++ b/src/org/apache/fop/image/analyser/PNGReader.java
@@ -11,6 +11,7 @@ package org.apache.fop.image.analyser;
import java.io.BufferedInputStream;
import java.io.IOException;
+import org.apache.fop.image.FopImage;
import org.apache.fop.fo.FOUserAgent;
/**
@@ -18,31 +19,33 @@ import org.apache.fop.fo.FOUserAgent;
* @author Pankaj Narula
* @version 1.0
*/
-public class PNGReader extends AbstractImageReader {
+public class PNGReader implements ImageReader {
static protected final int PNG_SIG_LENGTH = 24;
- protected byte[] header;
- public boolean verifySignature(String uri, BufferedInputStream fis,
+ public FopImage.ImageInfo verifySignature(String uri, BufferedInputStream fis,
FOUserAgent ua) throws IOException {
- this.imageStream = fis;
- this.setDefaultHeader();
+ byte[] header = getDefaultHeader(fis);
boolean supported = ((header[0] == (byte) 0x89) &&
(header[1] == (byte) 0x50) && (header[2] == (byte) 0x4e) &&
(header[3] == (byte) 0x47) && (header[4] == (byte) 0x0d) &&
(header[5] == (byte) 0x0a) &&
(header[6] == (byte) 0x1a) && (header[7] == (byte) 0x0a));
if (supported) {
- setDimension();
- return true;
- } else
- return false;
+ FopImage.ImageInfo info = getDimension(header);
+ info.mimeType = getMimeType();
+ return info;
+ } else {
+ return null;
+ }
}
public String getMimeType() {
return "image/png";
}
- protected void setDimension() {
+ protected FopImage.ImageInfo getDimension(byte[] header) {
+ FopImage.ImageInfo info = new FopImage.ImageInfo();
+
// png is always big endian
int byte1 = header[16] & 0xff;
int byte2 = header[17] & 0xff;
@@ -50,29 +53,30 @@ public class PNGReader extends AbstractImageReader {
int byte4 = header[19] & 0xff;
long l = (long)((byte1 << 24) | (byte2 << 16) |
(byte3 << 8) | byte4);
- this.width = (int)(l);
+ info.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);
-
+ info.height = (int)(l);
+ return info;
}
- protected void setDefaultHeader() throws IOException {
- this.header = new byte[PNG_SIG_LENGTH];
+ protected byte[] getDefaultHeader(BufferedInputStream imageStream) throws IOException {
+ byte[] header = new byte[PNG_SIG_LENGTH];
try {
- this.imageStream.mark(PNG_SIG_LENGTH + 1);
- this.imageStream.read(header);
- this.imageStream.reset();
+ imageStream.mark(PNG_SIG_LENGTH + 1);
+ imageStream.read(header);
+ imageStream.reset();
} catch (IOException ex) {
try {
- this.imageStream.reset();
+ imageStream.reset();
} catch (IOException exbis) {}
throw ex;
}
+ return header;
}
}