You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AbstractFopImage.java 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. /*
  2. * $Id$
  3. * Copyright (C) 2001 The Apache Software Foundation. All rights reserved.
  4. * For details on use and redistribution please refer to the
  5. * LICENSE file included with these sources.
  6. */
  7. package org.apache.fop.image;
  8. // Java
  9. import java.net.URL;
  10. // FOP
  11. import org.apache.fop.datatypes.ColorSpace;
  12. import org.apache.fop.pdf.PDFColor;
  13. import org.apache.fop.pdf.PDFFilter;
  14. import org.apache.fop.image.analyser.ImageReaderFactory;
  15. import org.apache.fop.image.analyser.ImageReader;
  16. import org.apache.fop.fo.FOUserAgent;
  17. /**
  18. * Base class to implement the FopImage interface.
  19. * @author Eric SCHAEFFER
  20. * @author Modified by Eric Dalquist - 9/14/2001 - ebdalqui@mtu.edu
  21. * @see FopImage
  22. */
  23. public abstract class AbstractFopImage implements FopImage {
  24. protected int loaded = 0;
  25. /**
  26. * Image width (in pixel).
  27. */
  28. protected int m_width = 0;
  29. /**
  30. * Image height (in pixel).
  31. */
  32. protected int m_height = 0;
  33. /**
  34. * Image URL.
  35. */
  36. protected URL m_href = null;
  37. /**
  38. * ImageReader object (to obtain image header informations).
  39. */
  40. protected ImageReader m_imageReader = null;
  41. /**
  42. * Image color space (org.apache.fop.datatypes.ColorSpace).
  43. */
  44. protected ColorSpace m_colorSpace = null;
  45. /**
  46. * Bits per pixel.
  47. */
  48. protected int m_bitsPerPixel = 0;
  49. /**
  50. * Image data (uncompressed).
  51. */
  52. protected byte[] m_bitmaps = null;
  53. /**
  54. * Image data size.
  55. */
  56. protected int m_bitmapsSize = 0;
  57. /**
  58. * Image transparency.
  59. */
  60. protected boolean m_isTransparent = false;
  61. /**
  62. * Transparent color (org.apache.fop.pdf.PDFColor).
  63. */
  64. protected PDFColor m_transparentColor = null;
  65. /**
  66. * Image compression type.
  67. * Added by Eric Dalquist
  68. */
  69. protected PDFFilter m_compressionType = null;
  70. /**
  71. * Constructor.
  72. * Construct a new FopImage object and initialize its default properties:
  73. * <UL>
  74. * <LI>image width
  75. * <LI>image height
  76. * </UL>
  77. * The image data isn't kept in memory.
  78. * @param href image URL
  79. * imgReader ImageReader object
  80. * @return a new FopImage object
  81. */
  82. public AbstractFopImage(URL href, ImageReader imgReader) {
  83. this.m_href = href;
  84. this.m_imageReader = imgReader;
  85. this.m_width = this.m_imageReader.getWidth();
  86. this.m_height = this.m_imageReader.getHeight();
  87. loaded = loaded & DIMENSIONS;
  88. }
  89. public String getMimeType() {
  90. return m_imageReader.getMimeType();
  91. }
  92. /**
  93. * Load image data and initialize its properties.
  94. */
  95. public synchronized boolean load(int type, FOUserAgent ua) {
  96. if((loaded & type) != 0) {
  97. return true;
  98. }
  99. boolean success = true;
  100. if(((type & DIMENSIONS) != 0) && ((loaded & DIMENSIONS) == 0)) {
  101. success = success && loadDimensions(ua);
  102. if(!success) {
  103. return false;
  104. }
  105. loaded = loaded & DIMENSIONS;
  106. }
  107. if(((type & BITMAP) != 0) && ((loaded & BITMAP) == 0)) {
  108. success = success && loadBitmap(ua);
  109. if(success) {
  110. loaded = loaded & BITMAP;
  111. }
  112. }
  113. return success;
  114. }
  115. protected boolean loadDimensions(FOUserAgent ua) {
  116. return false;
  117. }
  118. protected boolean loadBitmap(FOUserAgent ua) {
  119. return false;
  120. }
  121. /**
  122. * Return the image URL.
  123. * @return the image URL (as String)
  124. */
  125. public String getURL() {
  126. return this.m_href.toString();
  127. }
  128. /**
  129. * Return the image width.
  130. * @return the image width
  131. */
  132. public int getWidth() {
  133. return this.m_width;
  134. }
  135. /**
  136. * Return the image height.
  137. * @return the image height
  138. */
  139. public int getHeight() {
  140. return this.m_height;
  141. }
  142. /**
  143. * Return the image color space.
  144. * @return the image color space (org.apache.fop.datatypes.ColorSpace)
  145. */
  146. public ColorSpace getColorSpace() {
  147. return this.m_colorSpace;
  148. }
  149. /**
  150. * Return the number of bits per pixel.
  151. * @return number of bits per pixel
  152. */
  153. public int getBitsPerPixel() {
  154. return this.m_bitsPerPixel;
  155. }
  156. /**
  157. * Return the image transparency.
  158. * @return true if the image is transparent
  159. */
  160. public boolean isTransparent() {
  161. return this.m_isTransparent;
  162. }
  163. /**
  164. * Return the transparent color.
  165. * @return the transparent color (org.apache.fop.pdf.PDFColor)
  166. */
  167. public PDFColor getTransparentColor() {
  168. return this.m_transparentColor;
  169. }
  170. /**
  171. * Return the image data (uncompressed).
  172. * @return the image data
  173. */
  174. public byte[] getBitmaps() {
  175. return this.m_bitmaps;
  176. }
  177. /**
  178. * Return the image data size (uncompressed).
  179. * @return the image data size
  180. */
  181. public int getBitmapsSize() {
  182. return this.m_bitmapsSize;
  183. }
  184. /**
  185. * Return the original image data (compressed).
  186. * @return the original image data
  187. */
  188. public byte[] getRessourceBytes() {
  189. return null;
  190. }
  191. /**
  192. * Return the original image data size (compressed).
  193. * @return the original image data size
  194. */
  195. public int getRessourceBytesSize() {
  196. return 0;
  197. }
  198. /**
  199. * Return the original image compression type.
  200. * @return the original image compression type (org.apache.fop.pdf.PDFFilter)
  201. */
  202. public PDFFilter getPDFFilter() {
  203. /*
  204. * Added by Eric Dalquist
  205. * Using the bitsPerPixel var as our flag since many imges will
  206. * have a null m_compressionType even after being loaded
  207. */
  208. return m_compressionType;
  209. }
  210. }