1 51 package org.apache.fop.image.analyser; 52 53 import java.io.BufferedInputStream ; 55 import java.io.IOException ; 56 57 61 public class BMPReader extends AbstractImageReader { 62 63 protected static final int BMP_SIG_LENGTH = 26; 64 65 protected byte[] header; 66 67 public boolean verifySignature(String uri, BufferedInputStream fis) 68 throws IOException { 69 this.imageStream = fis; 70 this.setDefaultHeader(); 71 boolean supported = ((header[0] == (byte)0x42) 72 && (header[1] == (byte)0x4d)); 73 if (supported) { 74 setDimension(); 75 return true; 76 } else 77 return false; 78 } 79 80 public String getMimeType() { 81 return "image/bmp"; 82 } 83 84 protected void setDimension() { 85 int byte1 = header[18] & 0xff; 87 int byte2 = header[19] & 0xff; 88 int byte3 = header[20] & 0xff; 89 int byte4 = header[21] & 0xff; 90 long l = (long)((byte4 << 24) | (byte3 << 16) | (byte2 << 8) | byte1); 91 this.width = (int)(l & 0xffffffff); 92 93 byte1 = header[22] & 0xff; 94 byte2 = header[23] & 0xff; 95 byte3 = header[24] & 0xff; 96 byte4 = header[25] & 0xff; 97 l = (long)((byte4 << 24) | (byte3 << 16) | (byte2 << 8) | byte1); 98 this.height = (int)(l & 0xffffffff); 99 } 100 101 protected void setDefaultHeader() throws IOException { 102 this.header = new byte[BMP_SIG_LENGTH]; 103 try { 104 this.imageStream.mark(BMP_SIG_LENGTH + 1); 105 this.imageStream.read(header); 106 this.imageStream.reset(); 107 } catch (IOException ex) { 108 try { 109 this.imageStream.reset(); 110 } catch (IOException exbis) {} 111 throw ex; 112 } 113 } 114 115 } 116 117 | Popular Tags |