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.

BitmapImage.java 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. */
  17. /* $Id$ */
  18. package org.apache.fop.pdf;
  19. import java.io.IOException;
  20. import java.io.OutputStream;
  21. /**
  22. * Bitmap image.
  23. * This is used to create a bitmap image that will be inserted
  24. * into pdf.
  25. */
  26. public class BitmapImage implements PDFImage {
  27. private int height;
  28. private int width;
  29. private int bitsPerComponent;
  30. private PDFDeviceColorSpace colorSpace;
  31. private byte[] bitmaps;
  32. private PDFReference maskRef;
  33. private PDFColor transparent = null;
  34. private String key;
  35. private PDFDocument pdfDoc;
  36. /**
  37. * Create a bitmap image.
  38. * Creates a new bitmap image with the given data.
  39. *
  40. * @param k the key to be used to lookup the image
  41. * @param width the width of the image
  42. * @param height the height of the image
  43. * @param data the bitmap data
  44. * @param mask the transparency mask reference if any
  45. */
  46. public BitmapImage(String k, int width, int height, byte[] data,
  47. String mask) {
  48. this.key = k;
  49. this.height = height;
  50. this.width = width;
  51. this.bitsPerComponent = 8;
  52. this.colorSpace = new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_RGB);
  53. this.bitmaps = data;
  54. if (mask != null) {
  55. maskRef = new PDFReference(mask);
  56. }
  57. }
  58. /**
  59. * Setup this image with the pdf document.
  60. *
  61. * @param doc the pdf document this will be inserted into
  62. */
  63. public void setup(PDFDocument doc) {
  64. this.pdfDoc = doc;
  65. }
  66. /**
  67. * Get the key for this image.
  68. * This key is used by the pdf document so that it will only
  69. * insert an image once. All other references to the same image
  70. * will use the same XObject reference.
  71. *
  72. * @return the unique key to identify this image
  73. */
  74. public String getKey() {
  75. return key;
  76. }
  77. /**
  78. * Get the width of this image.
  79. *
  80. * @return the width of the image
  81. */
  82. public int getWidth() {
  83. return width;
  84. }
  85. /**
  86. * Get the height of this image.
  87. *
  88. * @return the height of the image
  89. */
  90. public int getHeight() {
  91. return height;
  92. }
  93. /**
  94. * Set the color space for this image.
  95. *
  96. * @param cs the pdf color space
  97. */
  98. public void setColorSpace(PDFDeviceColorSpace cs) {
  99. colorSpace = cs;
  100. }
  101. /**
  102. * Get the color space for the image data.
  103. * Possible options are: DeviceGray, DeviceRGB, or DeviceCMYK
  104. *
  105. * @return the pdf doclor space
  106. */
  107. public PDFDeviceColorSpace getColorSpace() {
  108. return colorSpace;
  109. }
  110. /** {@inheritDoc} */
  111. public int getBitsPerComponent() {
  112. return bitsPerComponent;
  113. }
  114. /**
  115. * Set the transparent color for this iamge.
  116. *
  117. * @param t the transparent color
  118. */
  119. public void setTransparent(PDFColor t) {
  120. transparent = t;
  121. }
  122. /**
  123. * Check if this image has a transparent color.
  124. *
  125. * @return true if it has a transparent color
  126. */
  127. public boolean isTransparent() {
  128. return transparent != null;
  129. }
  130. /**
  131. * Get the transparent color for this image.
  132. *
  133. * @return the transparent color if any
  134. */
  135. public PDFColor getTransparentColor() {
  136. return transparent;
  137. }
  138. /**
  139. * Get the bitmap mask reference for this image.
  140. * Current not supported.
  141. *
  142. * @return the bitmap mask reference
  143. */
  144. public String getMask() {
  145. return null;
  146. }
  147. /** {@inheritDoc} */
  148. public PDFReference getSoftMaskReference() {
  149. return maskRef;
  150. }
  151. /** {@inheritDoc} */
  152. public boolean isInverted() {
  153. return false;
  154. }
  155. /** {@inheritDoc} */
  156. public void outputContents(OutputStream out) throws IOException {
  157. out.write(bitmaps);
  158. }
  159. /** {@inheritDoc} */
  160. public void populateXObjectDictionary(PDFDictionary dict) {
  161. //nop
  162. }
  163. /**
  164. * Get the ICC stream.
  165. * @return always returns null since this has no icc color space
  166. */
  167. public PDFICCStream getICCStream() {
  168. return null;
  169. }
  170. /**
  171. * Check if this is a postscript image.
  172. * @return always returns false
  173. */
  174. public boolean isPS() {
  175. return false;
  176. }
  177. /**
  178. * {@inheritDoc}
  179. */
  180. public String getFilterHint() {
  181. return PDFFilterList.IMAGE_FILTER;
  182. }
  183. /**
  184. * {@inheritDoc}
  185. */
  186. public PDFFilter getPDFFilter() {
  187. return null;
  188. }
  189. }