KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > fop > pdf > BitmapImage


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
18 /* $Id: BitmapImage.java 426576 2006-07-28 15:44:37Z jeremias $ */
19  
20 package org.apache.fop.pdf;
21
22 import java.io.IOException JavaDoc;
23 import java.io.OutputStream JavaDoc;
24 //import java.util.Map;
25

26 /**
27  * Bitmap image.
28  * This is used to create a bitmap image that will be inserted
29  * into pdf.
30  */

31 public class BitmapImage implements PDFImage {
32     private int height;
33     private int width;
34     private int bitsPerPixel;
35     private PDFDeviceColorSpace colorSpace;
36     private byte[] bitmaps;
37     private String JavaDoc maskRef;
38     private PDFColor transparent = null;
39     private String JavaDoc key;
40     private PDFDocument pdfDoc;
41
42     /**
43      * Create a bitmap image.
44      * Creates a new bitmap image with the given data.
45      *
46      * @param k the key to be used to lookup the image
47      * @param width the width of the image
48      * @param height the height of the image
49      * @param data the bitmap data
50      * @param mask the transparancy mask reference if any
51      */

52     public BitmapImage(String JavaDoc k, int width, int height, byte[] data,
53                   String JavaDoc mask) {
54         this.key = k;
55         this.height = height;
56         this.width = width;
57         this.bitsPerPixel = 8;
58         this.colorSpace = new PDFDeviceColorSpace(PDFDeviceColorSpace.DEVICE_RGB);
59         this.bitmaps = data;
60         maskRef = mask;
61     }
62
63     /**
64      * Setup this image with the pdf document.
65      *
66      * @param doc the pdf document this will be inserted into
67      */

68     public void setup(PDFDocument doc) {
69         this.pdfDoc = doc;
70     }
71
72     /**
73      * Get the key for this image.
74      * This key is used by the pdf document so that it will only
75      * insert an image once. All other references to the same image
76      * will use the same XObject reference.
77      *
78      * @return the unique key to identify this image
79      */

80     public String JavaDoc getKey() {
81         return key;
82     }
83
84     /**
85      * Get the width of this image.
86      *
87      * @return the width of the image
88      */

89     public int getWidth() {
90         return width;
91     }
92
93     /**
94      * Get the height of this image.
95      *
96      * @return the height of the image
97      */

98     public int getHeight() {
99         return height;
100     }
101
102     /**
103      * Set the color space for this image.
104      *
105      * @param cs the pdf color space
106      */

107     public void setColorSpace(PDFDeviceColorSpace cs) {
108         colorSpace = cs;
109     }
110
111     /**
112      * Get the color space for the image data.
113      * Possible options are: DeviceGray, DeviceRGB, or DeviceCMYK
114      *
115      * @return the pdf doclor space
116      */

117     public PDFDeviceColorSpace getColorSpace() {
118         return colorSpace;
119     }
120
121     /**
122      * Get the number of bits per pixel.
123      *
124      * @return the number of bits per pixel
125      */

126     public int getBitsPerPixel() {
127         return bitsPerPixel;
128     }
129
130     /**
131      * Set the transparent color for this iamge.
132      *
133      * @param t the transparent color
134      */

135     public void setTransparent(PDFColor t) {
136         transparent = t;
137     }
138
139     /**
140      * Check if this image has a transparent color.
141      *
142      * @return true if it has a transparent color
143      */

144     public boolean isTransparent() {
145         return transparent != null;
146     }
147
148     /**
149      * Get the transparent color for this image.
150      *
151      * @return the transparent color if any
152      */

153     public PDFColor getTransparentColor() {
154         return transparent;
155     }
156
157     /**
158      * Get the bitmap mask reference for this image.
159      * Current not supported.
160      *
161      * @return the bitmap mask reference
162      */

163     public String JavaDoc getMask() {
164         return null;
165     }
166
167     /**
168      * Get the soft mask reference for this image.
169      *
170      * @return the soft mask reference if any
171      */

172     public String JavaDoc getSoftMask() {
173         return maskRef;
174     }
175
176     /** @see org.apache.fop.pdf.PDFImage#isInverted() */
177     public boolean isInverted() {
178         return false;
179     }
180     
181     /**
182      * @see org.apache.fop.pdf.PDFImage#outputContents(OutputStream)
183      */

184     public void outputContents(OutputStream JavaDoc out) throws IOException JavaDoc {
185         out.write(bitmaps);
186     }
187     
188     /**
189      * Get the ICC stream.
190      * @return always returns null since this has no icc color space
191      */

192     public PDFICCStream getICCStream() {
193         return null;
194     }
195
196     /**
197      * Check if this is a postscript image.
198      * @return always returns false
199      */

200     public boolean isPS() {
201         return false;
202     }
203
204     /**
205      * @see org.apache.fop.pdf.PDFImage#getFilterHint()
206      */

207     public String JavaDoc getFilterHint() {
208         return PDFFilterList.IMAGE_FILTER;
209     }
210
211     /**
212      * @see org.apache.fop.pdf.PDFImage#getPDFFilter()
213      */

214     public PDFFilter getPDFFilter() {
215         return null;
216     }
217
218 }
219
220
221
Popular Tags