62 ((b[3]&0xff))); 63 } 64 65 byte[] read(int count) throws IOException { 66 byte[] result = new byte[count]; 67 for(int i = 0; i < count; i++) { 68 result[i] = read(); 69 } 70 return(result); 71 } 72 73 void checkEquality(byte[] b1, byte[] b2) { 74 if(!Arrays.equals(b1, b2)) { 75 throw(new JemmyException("Format error")); 76 } 77 } 78 79 /** 80 * Decodes image from an input stream passed into constructor. 81 * @return a BufferedImage object 82 * @throws IOException 83 */ 84 public Raster decode() throws IOException { 85 return decode(true); 86 } 87 88 protected abstract WriteableRaster createRaster(int width, int height); 89 90 /** 91 * Decodes image from an input stream passed into constructor. 92 * @return a BufferedImage object 93 * @param closeStream requests method to close the stream after the image is read 94 * @throws IOException 95 */ 96 public Raster decode(boolean closeStream) throws IOException { 97 98 byte[] id = read(12); 99 checkEquality(id, new byte[] {-119, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13}); 100 101 byte[] ihdr = read(4); 102 checkEquality(ihdr, "IHDR".getBytes()); 103 104 int width = readInt(); 105 int height = readInt(); 106 107 WriteableRaster result = createRaster(width, height); 108 109 byte[] head = read(5); 110 int mode; 111 if(Arrays.equals(head, new byte[]{1, 0, 0, 0, 0})) { 112 mode = PNGSaver.BW_MODE; 113 } else if(Arrays.equals(head, new byte[]{8, 0, 0, 0, 0})) { 114 mode = PNGSaver.GREYSCALE_MODE; | 62 ((b[3]&0xff))); 63 } 64 65 byte[] read(int count) throws IOException { 66 byte[] result = new byte[count]; 67 for(int i = 0; i < count; i++) { 68 result[i] = read(); 69 } 70 return(result); 71 } 72 73 void checkEquality(byte[] b1, byte[] b2) { 74 if(!Arrays.equals(b1, b2)) { 75 throw(new JemmyException("Format error")); 76 } 77 } 78 79 /** 80 * Decodes image from an input stream passed into constructor. 81 * @return a BufferedImage object 82 * @throws IOException todo document 83 */ 84 public Raster decode() throws IOException { 85 return decode(true); 86 } 87 88 protected abstract WriteableRaster createRaster(int width, int height); 89 90 /** 91 * Decodes image from an input stream passed into constructor. 92 * @return a BufferedImage object 93 * @param closeStream requests method to close the stream after the image is read 94 * @throws IOException todo document 95 */ 96 public Raster decode(boolean closeStream) throws IOException { 97 98 byte[] id = read(12); 99 checkEquality(id, new byte[] {-119, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13}); 100 101 byte[] ihdr = read(4); 102 checkEquality(ihdr, "IHDR".getBytes()); 103 104 int width = readInt(); 105 int height = readInt(); 106 107 WriteableRaster result = createRaster(width, height); 108 109 byte[] head = read(5); 110 int mode; 111 if(Arrays.equals(head, new byte[]{1, 0, 0, 0, 0})) { 112 mode = PNGSaver.BW_MODE; 113 } else if(Arrays.equals(head, new byte[]{8, 0, 0, 0, 0})) { 114 mode = PNGSaver.GREYSCALE_MODE; |