1 51 package org.apache.fop.image; 52 53 54 import java.awt.image.ColorModel ; 56 import java.awt.image.ImageConsumer ; 57 import java.awt.image.ImageProducer ; 58 import java.awt.image.PixelGrabber ; 59 import java.util.Hashtable ; 60 61 65 public class FopImageConsumer implements ImageConsumer { 66 protected int width = -1; 67 protected int height = -1; 68 protected Integer imageStatus = new Integer (-1); 69 protected int hints = 0; 70 protected Hashtable properties = null; 71 protected ColorModel cm = null; 72 protected ImageProducer ip = null; 73 74 public FopImageConsumer(ImageProducer iprod) { 75 this.ip = iprod; 76 } 77 78 public void imageComplete(int status) { 79 101 synchronized (this.imageStatus) { 102 if (imageStatus.intValue() != ImageConsumer.STATICIMAGEDONE 104 && imageStatus.intValue() != ImageConsumer.SINGLEFRAMEDONE) 105 this.imageStatus = new Integer (status); 106 } 107 } 108 109 public void setColorModel(ColorModel model) { 110 this.cm = model; 112 } 113 114 public void setDimensions(int width, int height) { 115 this.width = width; 117 this.height = height; 118 } 119 120 public void setHints(int hintflags) { 121 this.hints = hintflags; 123 } 124 125 public void setProperties(Hashtable props) { 126 this.properties = props; 128 } 129 130 public void setPixels(int x, int y, int w, int h, ColorModel model, 131 byte[] pixels, int off, int scansize) {} 132 133 public void setPixels(int x, int y, int w, int h, ColorModel model, 134 int[] pixels, int off, int scansize) {} 135 136 public boolean isImageReady() throws Exception { 137 synchronized (this.imageStatus) { 138 if (this.imageStatus.intValue() == ImageConsumer.IMAGEABORTED) 139 throw new Exception ("Image aborted"); 140 if (this.imageStatus.intValue() == ImageConsumer.IMAGEERROR) 141 throw new Exception ("Image error"); 142 143 if (imageStatus.intValue() == ImageConsumer.STATICIMAGEDONE 144 || imageStatus.intValue() == ImageConsumer.SINGLEFRAMEDONE) 145 return true; 146 147 return false; 148 } 149 } 150 151 public int getWidth() { 152 return this.width; 153 } 154 155 public int getHeight() { 156 return this.height; 157 } 158 159 public ColorModel getColorModel() { 160 return this.cm; 161 } 162 163 public int[] getImage() throws Exception { 164 int tmpMap[] = new int[this.width * this.height]; 165 PixelGrabber pg = new PixelGrabber (this.ip, 0, 0, this.width, 166 this.height, tmpMap, 0, 167 this.width); 168 pg.setDimensions(this.width, this.height); 169 pg.setColorModel(this.cm); 170 pg.setHints(this.hints); 171 pg.setProperties(this.properties); 172 try { 173 pg.grabPixels(); 174 } catch (InterruptedException intex) { 175 throw new Exception ("Image grabbing interrupted : " 176 + intex.getMessage()); 177 } 178 return tmpMap; 179 } 180 181 } 182 | Popular Tags |