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.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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. import java.awt.color.ColorSpace;
  11. import java.awt.color.ICC_Profile;
  12. // FOP
  13. import org.apache.fop.pdf.PDFColor;
  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 FopImage.ImageInfo imageInfo = null;
  41. /**
  42. * Image color space (java.awt.color.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. * Constructor.
  67. * Construct a new FopImage object and initialize its default properties:
  68. * <UL>
  69. * <LI>image width
  70. * <LI>image height
  71. * </UL>
  72. * The image data isn't kept in memory.
  73. * @param href image URL
  74. * imgReader ImageReader object
  75. * @return a new FopImage object
  76. */
  77. public AbstractFopImage(URL href, FopImage.ImageInfo info) {
  78. this.m_href = href;
  79. this.imageInfo = info;
  80. if(this.imageInfo.width != -1) {
  81. m_width = imageInfo.width;
  82. m_height = imageInfo.height;
  83. loaded = loaded | DIMENSIONS;
  84. }
  85. }
  86. public String getMimeType() {
  87. return imageInfo.mimeType;
  88. }
  89. /**
  90. * Load image data and initialize its properties.
  91. */
  92. public synchronized boolean load(int type, FOUserAgent ua) {
  93. if((loaded & type) != 0) {
  94. return true;
  95. }
  96. boolean success = true;
  97. if(((type & DIMENSIONS) != 0) && ((loaded & DIMENSIONS) == 0)) {
  98. success = success && loadDimensions(ua);
  99. if(!success) {
  100. return false;
  101. }
  102. loaded = loaded | DIMENSIONS;
  103. }
  104. if(((type & BITMAP) != 0) && ((loaded & BITMAP) == 0)) {
  105. success = success && loadBitmap(ua);
  106. if(success) {
  107. loaded = loaded | BITMAP;
  108. }
  109. }
  110. if(((type & ORIGINAL_DATA) != 0) && ((loaded & ORIGINAL_DATA) == 0)) {
  111. success = success && loadOriginalData(ua);
  112. if(success) {
  113. loaded = loaded | ORIGINAL_DATA;
  114. }
  115. }
  116. return success;
  117. }
  118. protected boolean loadDimensions(FOUserAgent ua) {
  119. return false;
  120. }
  121. protected boolean loadBitmap(FOUserAgent ua) {
  122. return false;
  123. }
  124. protected boolean loadOriginalData(FOUserAgent ua) {
  125. return false;
  126. }
  127. /**
  128. * Return the image URL.
  129. * @return the image URL (as String)
  130. */
  131. public String getURL() {
  132. return this.m_href.toString();
  133. }
  134. /**
  135. * Return the image width.
  136. * @return the image width
  137. */
  138. public int getWidth() {
  139. return this.m_width;
  140. }
  141. /**
  142. * Return the image height.
  143. * @return the image height
  144. */
  145. public int getHeight() {
  146. return this.m_height;
  147. }
  148. /**
  149. * Return the image color space.
  150. * @return the image color space (java.awt.color.ColorSpace)
  151. */
  152. public ColorSpace getColorSpace() {
  153. return this.m_colorSpace;
  154. }
  155. public ICC_Profile getICCProfile() {
  156. return null;
  157. }
  158. /**
  159. * Return the number of bits per pixel.
  160. * @return number of bits per pixel
  161. */
  162. public int getBitsPerPixel() {
  163. return this.m_bitsPerPixel;
  164. }
  165. /**
  166. * Return the image transparency.
  167. * @return true if the image is transparent
  168. */
  169. public boolean isTransparent() {
  170. return this.m_isTransparent;
  171. }
  172. public boolean hasSoftMask() {
  173. return false;
  174. }
  175. public byte[] getSoftMask() {
  176. return null;
  177. }
  178. /**
  179. * Return the transparent color.
  180. * @return the transparent color (org.apache.fop.pdf.PDFColor)
  181. */
  182. public PDFColor getTransparentColor() {
  183. return this.m_transparentColor;
  184. }
  185. /**
  186. * Return the image data (uncompressed).
  187. * @return the image data
  188. */
  189. public byte[] getBitmaps() {
  190. return this.m_bitmaps;
  191. }
  192. /**
  193. * Return the image data size (uncompressed).
  194. * @return the image data size
  195. */
  196. public int getBitmapsSize() {
  197. return this.m_bitmapsSize;
  198. }
  199. /**
  200. * Return the original image data (compressed).
  201. * @return the original image data
  202. */
  203. public byte[] getRessourceBytes() {
  204. return null;
  205. }
  206. /**
  207. * Return the original image data size (compressed).
  208. * @return the original image data size
  209. */
  210. public int getRessourceBytesSize() {
  211. return 0;
  212. }
  213. }