1 51 package org.apache.fop.image; 52 53 import org.apache.fop.datatypes.ColorSpace; 55 import org.apache.fop.pdf.PDFColor; 56 import org.apache.fop.pdf.PDFFilter; 57 import org.apache.fop.image.analyser.ImageReaderFactory; 58 import org.apache.fop.image.analyser.ImageReader; 59 60 import java.net.URL ; 62 63 69 public abstract class AbstractFopImage implements FopImage { 70 71 74 protected boolean m_invertImage = false; 75 76 79 protected int m_width = 0; 80 81 84 protected int m_height = 0; 85 86 89 protected URL m_href = null; 90 91 94 protected ImageReader m_imageReader = null; 95 96 99 protected ColorSpace m_colorSpace = null; 100 101 104 protected int m_bitsPerPixel = 0; 105 106 109 protected byte[] m_bitmaps = null; 110 111 114 protected int m_bitmapsSize = 0; 115 116 119 protected boolean m_isTransparent = false; 120 121 124 protected PDFColor m_transparentColor = null; 125 126 130 protected PDFFilter m_compressionType = null; 131 132 143 public AbstractFopImage(URL href) throws FopImageException { 144 this.m_href = href; 145 try { 146 this.m_imageReader = 147 ImageReaderFactory.Make(this.m_href.toExternalForm(), 148 this.m_href.openStream()); 149 } catch (Exception e) { 150 throw new FopImageException(e.getMessage()); 151 } 152 this.m_width = this.m_imageReader.getWidth(); 153 this.m_height = this.m_imageReader.getHeight(); 154 } 155 156 168 public AbstractFopImage(URL href, 169 ImageReader imgReader) throws FopImageException { 170 this.m_href = href; 171 this.m_imageReader = imgReader; 172 this.m_width = this.m_imageReader.getWidth(); 173 this.m_height = this.m_imageReader.getHeight(); 174 } 175 176 181 protected abstract void loadImage() throws FopImageException; 182 183 184 187 public boolean invertImage() { 188 return m_invertImage; 189 } 190 191 195 public String getURL() { 196 return this.m_href.toString(); 197 } 198 199 204 public int getWidth() throws FopImageException { 205 synchronized(this) { 206 if (this.m_width == 0) 207 this.loadImage(); 208 } 209 210 return this.m_width; 211 } 212 213 218 public int getHeight() throws FopImageException { 219 synchronized(this) { 220 if (this.m_height == 0) 221 this.loadImage(); 222 } 223 224 return this.m_height; 225 } 226 227 232 public ColorSpace getColorSpace() throws FopImageException { 233 synchronized(this) { 234 if (this.m_colorSpace == null) 235 this.loadImage(); 236 } 237 238 return this.m_colorSpace; 239 } 240 241 246 public int getBitsPerPixel() throws FopImageException { 247 synchronized(this) { 248 if (this.m_bitsPerPixel == 0) 249 this.loadImage(); 250 } 251 252 return this.m_bitsPerPixel; 253 } 254 255 260 public boolean isTransparent() throws FopImageException { 261 return this.m_isTransparent; 262 } 263 264 269 public PDFColor getTransparentColor() throws FopImageException { 270 return this.m_transparentColor; 271 } 272 273 278 public byte[] getBitmaps() throws FopImageException { 279 synchronized(this) { 280 if (this.m_bitmaps == null) 281 this.loadImage(); 282 } 283 284 return this.m_bitmaps; 285 } 286 287 292 public int getBitmapsSize() throws FopImageException { 293 synchronized(this) { 294 if (this.m_bitmapsSize == 0) 295 this.loadImage(); 296 } 297 298 return this.m_bitmapsSize; 299 } 300 301 306 public byte[] getRessourceBytes() throws FopImageException { 307 return null; 308 } 309 310 315 public int getRessourceBytesSize() throws FopImageException { 316 return 0; 317 } 318 319 324 public PDFFilter getPDFFilter() throws FopImageException { 325 326 331 synchronized(this) { 332 if (this.m_bitsPerPixel == 0) 333 this.loadImage(); 334 } 335 336 return m_compressionType; 337 } 338 339 342 public void close() { 343 350 synchronized(this) { 351 this.m_bitmaps = null; 357 this.m_bitmapsSize = 0; 358 } 361 } 362 363 } 364 365 | Popular Tags |