1 | /* | |
2 | * $Id: Image.java 4065 2009-09-16 23:09:11Z psoares33 $ | |
3 | * | |
4 | * Copyright 1999, 2000, 2001, 2002 by Bruno Lowagie. | |
5 | * | |
6 | * The contents of this file are subject to the Mozilla Public License Version 1.1 | |
7 | * (the "License"); you may not use this file except in compliance with the License. | |
8 | * You may obtain a copy of the License at http://www.mozilla.org/MPL/ | |
9 | * | |
10 | * Software distributed under the License is distributed on an "AS IS" basis, | |
11 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
12 | * for the specific language governing rights and limitations under the License. | |
13 | * | |
14 | * The Original Code is 'iText, a free JAVA-PDF library'. | |
15 | * | |
16 | * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by | |
17 | * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie. | |
18 | * All Rights Reserved. | |
19 | * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer | |
20 | * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved. | |
21 | * | |
22 | * Contributor(s): all the names of the contributors are added in the source code | |
23 | * where applicable. | |
24 | * | |
25 | * Alternatively, the contents of this file may be used under the terms of the | |
26 | * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the | |
27 | * provisions of LGPL are applicable instead of those above. If you wish to | |
28 | * allow use of your version of this file only under the terms of the LGPL | |
29 | * License and not to allow others to use your version of this file under | |
30 | * the MPL, indicate your decision by deleting the provisions above and | |
31 | * replace them with the notice and other provisions required by the LGPL. | |
32 | * If you do not delete the provisions above, a recipient may use your version | |
33 | * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE. | |
34 | * | |
35 | * This library is free software; you can redistribute it and/or modify it | |
36 | * under the terms of the MPL as stated above or under the terms of the GNU | |
37 | * Library General Public License as published by the Free Software Foundation; | |
38 | * either version 2 of the License, or any later version. | |
39 | * | |
40 | * This library is distributed in the hope that it will be useful, but WITHOUT | |
41 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
42 | * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more | |
43 | * details. | |
44 | * | |
45 | * If you didn't download this code from the following link, you should check if | |
46 | * you aren't using an obsolete version: | |
47 | * http://www.lowagie.com/iText/ | |
48 | */ | |
49 | ||
50 | package com.lowagie.text; | |
51 | ||
52 | import java.awt.Graphics2D; | |
53 | import java.awt.color.ICC_Profile; | |
54 | import java.awt.image.BufferedImage; | |
55 | import java.io.IOException; | |
56 | import java.io.InputStream; | |
57 | import java.lang.reflect.Constructor; | |
58 | import java.net.MalformedURLException; | |
59 | import java.net.URL; | |
60 | import com.lowagie.text.error_messages.MessageLocalization; | |
61 | ||
62 | import com.lowagie.text.ExceptionConverter; | |
63 | import com.lowagie.text.pdf.PRIndirectReference; | |
64 | import com.lowagie.text.pdf.PdfArray; | |
65 | import com.lowagie.text.pdf.PdfContentByte; | |
66 | import com.lowagie.text.pdf.PdfDictionary; | |
67 | import com.lowagie.text.pdf.PdfIndirectReference; | |
68 | import com.lowagie.text.pdf.PdfName; | |
69 | import com.lowagie.text.pdf.PdfNumber; | |
70 | import com.lowagie.text.pdf.PdfOCG; | |
71 | import com.lowagie.text.pdf.PdfObject; | |
72 | import com.lowagie.text.pdf.PdfReader; | |
73 | import com.lowagie.text.pdf.PdfStream; | |
74 | import com.lowagie.text.pdf.PdfTemplate; | |
75 | import com.lowagie.text.pdf.PdfWriter; | |
76 | import com.lowagie.text.pdf.codec.CCITTG4Encoder; | |
77 | ||
78 | ||
79 | /** | |
80 | * An <CODE>Image</CODE> is the representation of a graphic element (JPEG, PNG | |
81 | * or GIF) that has to be inserted into the document | |
82 | * | |
83 | * @see Element | |
84 | * @see Rectangle | |
85 | */ | |
86 | ||
87 | public abstract class Image extends Rectangle { | |
88 | ||
89 | // static final membervariables | |
90 | ||
91 | /** this is a kind of image alignment. */ | |
92 | public static final int DEFAULT = 0; | |
93 | ||
94 | /** this is a kind of image alignment. */ | |
95 | public static final int RIGHT = 2; | |
96 | ||
97 | /** this is a kind of image alignment. */ | |
98 | public static final int LEFT = 0; | |
99 | ||
100 | /** this is a kind of image alignment. */ | |
101 | public static final int MIDDLE = 1; | |
102 | ||
103 | /** this is a kind of image alignment. */ | |
104 | public static final int TEXTWRAP = 4; | |
105 | ||
106 | /** this is a kind of image alignment. */ | |
107 | public static final int UNDERLYING = 8; | |
108 | ||
109 | /** This represents a coordinate in the transformation matrix. */ | |
110 | public static final int AX = 0; | |
111 | ||
112 | /** This represents a coordinate in the transformation matrix. */ | |
113 | public static final int AY = 1; | |
114 | ||
115 | /** This represents a coordinate in the transformation matrix. */ | |
116 | public static final int BX = 2; | |
117 | ||
118 | /** This represents a coordinate in the transformation matrix. */ | |
119 | public static final int BY = 3; | |
120 | ||
121 | /** This represents a coordinate in the transformation matrix. */ | |
122 | public static final int CX = 4; | |
123 | ||
124 | /** This represents a coordinate in the transformation matrix. */ | |
125 | public static final int CY = 5; | |
126 | ||
127 | /** This represents a coordinate in the transformation matrix. */ | |
128 | public static final int DX = 6; | |
129 | ||
130 | /** This represents a coordinate in the transformation matrix. */ | |
131 | public static final int DY = 7; | |
132 | ||
133 | /** type of image */ | |
134 | public static final int ORIGINAL_NONE = 0; | |
135 | ||
136 | /** type of image */ | |
137 | public static final int ORIGINAL_JPEG = 1; | |
138 | ||
139 | /** type of image */ | |
140 | public static final int ORIGINAL_PNG = 2; | |
141 | ||
142 | /** type of image */ | |
143 | public static final int ORIGINAL_GIF = 3; | |
144 | ||
145 | /** type of image */ | |
146 | public static final int ORIGINAL_BMP = 4; | |
147 | ||
148 | /** type of image */ | |
149 | public static final int ORIGINAL_TIFF = 5; | |
150 | ||
151 | /** type of image */ | |
152 | public static final int ORIGINAL_WMF = 6; | |
153 | ||
154 | /** type of image */ | |
155 | public static final int ORIGINAL_PS = 7; | |
156 | ||
157 | /** type of image */ | |
158 | public static final int ORIGINAL_JPEG2000 = 8; | |
159 | ||
160 | /** | |
161 | * type of image | |
162 | * @since 2.1.5 | |
163 | */ | |
164 | public static final int ORIGINAL_JBIG2 = 9; | |
165 | ||
166 | // member variables | |
167 | ||
168 | /** The image type. */ | |
169 | protected int type; | |
170 | ||
171 | /** The URL of the image. */ | |
172 | protected URL url; | |
173 | ||
174 | /** | |
175 | * The raw data of the image. | |
176 | */ | |
177 | protected byte[] rawData; | |
178 | ||
179 | /** The bits per component of the raw image. It also flags a CCITT image. */ | |
180 | protected int bpc = 1; | |
181 | ||
182 | /** | |
183 | * The template to be treated as an image. | |
184 | */ | |
185 | protected PdfTemplate[] template = new PdfTemplate[1]; | |
186 | ||
187 | /** The alignment of the Image. */ | |
188 | protected int alignment; | |
189 | ||
190 | /** Text that can be shown instead of the image. */ | |
191 | protected String alt; | |
192 | ||
193 | /** This is the absolute X-position of the image. */ | |
194 | protected float absoluteX = Float.NaN; | |
195 | ||
196 | /** This is the absolute Y-position of the image. */ | |
197 | protected float absoluteY = Float.NaN; | |
198 | ||
199 | /** This is the width of the image without rotation. */ | |
200 | protected float plainWidth; | |
201 | ||
202 | /** This is the width of the image without rotation. */ | |
203 | protected float plainHeight; | |
204 | ||
205 | /** This is the scaled width of the image taking rotation into account. */ | |
206 | protected float scaledWidth; | |
207 | ||
208 | /** This is the original height of the image taking rotation into account. */ | |
209 | protected float scaledHeight; | |
210 | ||
211 | /** | |
212 | * The compression level of the content streams. | |
213 | * @since 2.1.3 | |
214 | */ | |
215 | protected int compressionLevel = PdfStream.DEFAULT_COMPRESSION; | |
216 | ||
217 | /** an iText attributed unique id for this image. */ | |
218 | protected Long mySerialId = getSerialId(); | |
219 | ||
220 | public static final int[] PNGID = {137, 80, 78, 71, 13, 10, 26, 10}; | |
221 | ||
222 | ||
223 | // image from file or URL | |
224 | ||
225 | /** | |
226 | * Constructs an <CODE>Image</CODE> -object, using an <VAR>url </VAR>. | |
227 | * | |
228 | * @param url | |
229 | * the <CODE>URL</CODE> where the image can be found. | |
230 | */ | |
231 | public Image(URL url) { | |
232 | super(0, 0); | |
233 | this.url = url; | |
234 | this.alignment = DEFAULT; | |
235 | rotationRadians = 0; | |
236 | } | |
237 | ||
238 | /** | |
239 | * Gets an instance of an Image. | |
240 | * | |
241 | * @param url | |
242 | * an URL | |
243 | * @return an Image | |
244 | * @throws BadElementException | |
245 | * @throws MalformedURLException | |
246 | * @throws IOException | |
247 | */ | |
248 | public static Image getInstance(URL url) throws BadElementException, | |
249 | IOException { | |
250 | InputStream is = null; | |
251 | Image img = null; | |
252 | try { | |
253 | is = url.openStream(); | |
254 | int c1 = is.read(); | |
255 | int c2 = is.read(); | |
256 | int c3 = is.read(); | |
257 | int c4 = is.read(); | |
258 | // jbig2 | |
259 | int c5 = is.read(); | |
260 | int c6 = is.read(); | |
261 | int c7 = is.read(); | |
262 | int c8 = is.read(); | |
263 |
1
1. getInstance : removed call to java/io/InputStream::close → NO_COVERAGE |
is.close(); |
264 | ||
265 | is = null; | |
266 |
3
1. getInstance : negated conditional → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE 3. getInstance : negated conditional → NO_COVERAGE |
if (c1 == 'G' && c2 == 'I' && c3 == 'F') { |
267 | img = ImageLoader.getGifImage(url); | |
268 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return img; |
269 | } | |
270 |
2
1. getInstance : negated conditional → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE |
if (c1 == 0xFF && c2 == 0xD8) { |
271 | img = ImageLoader.getJpegImage(url); | |
272 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return img; |
273 | } | |
274 |
4
1. getInstance : negated conditional → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE 3. getInstance : negated conditional → NO_COVERAGE 4. getInstance : negated conditional → NO_COVERAGE |
if (c1 == 0x00 && c2 == 0x00 && c3 == 0x00 && c4 == 0x0c) { |
275 | img = ImageLoader.getJpeg2000Image(url); | |
276 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return img; |
277 | } | |
278 |
4
1. getInstance : negated conditional → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE 3. getInstance : negated conditional → NO_COVERAGE 4. getInstance : negated conditional → NO_COVERAGE |
if (c1 == 0xff && c2 == 0x4f && c3 == 0xff && c4 == 0x51) { |
279 | img = ImageLoader.getJpeg2000Image(url); | |
280 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return img; |
281 | } | |
282 |
4
1. getInstance : negated conditional → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE 3. getInstance : negated conditional → NO_COVERAGE 4. getInstance : negated conditional → NO_COVERAGE |
if (c1 == PNGID[0] && c2 == PNGID[1] |
283 | && c3 == PNGID[2] && c4 == PNGID[3]) { | |
284 | img = ImageLoader.getPngImage(url); | |
285 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return img; |
286 | } | |
287 |
2
1. getInstance : negated conditional → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE |
if (c1 == 0xD7 && c2 == 0xCD) { |
288 | img = new ImgWMF(url); | |
289 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return img; |
290 | } | |
291 |
2
1. getInstance : negated conditional → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE |
if (c1 == 'B' && c2 == 'M') { |
292 | img = ImageLoader.getBmpImage(url); | |
293 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return img; |
294 | } | |
295 |
8
1. getInstance : negated conditional → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE 3. getInstance : negated conditional → NO_COVERAGE 4. getInstance : negated conditional → NO_COVERAGE 5. getInstance : negated conditional → NO_COVERAGE 6. getInstance : negated conditional → NO_COVERAGE 7. getInstance : negated conditional → NO_COVERAGE 8. getInstance : negated conditional → NO_COVERAGE |
if ((c1 == 'M' && c2 == 'M' && c3 == 0 && c4 == 42) |
296 | || (c1 == 'I' && c2 == 'I' && c3 == 42 && c4 == 0)) { | |
297 | img = ImageLoader.getTiffImage(url); | |
298 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return img; |
299 | } | |
300 |
8
1. getInstance : negated conditional → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE 3. getInstance : negated conditional → NO_COVERAGE 4. getInstance : negated conditional → NO_COVERAGE 5. getInstance : negated conditional → NO_COVERAGE 6. getInstance : negated conditional → NO_COVERAGE 7. getInstance : negated conditional → NO_COVERAGE 8. getInstance : negated conditional → NO_COVERAGE |
if ( c1 == 0x97 && c2 == 'J' && c3 == 'B' && c4 == '2' && |
301 | c5 == '\r' && c6 == '\n' && c7 == 0x1a && c8 == '\n' ) { | |
302 | throw new IOException(url.toString() | |
303 | + " is not a recognized imageformat. JBIG2 support has been removed."); | |
304 | } | |
305 | throw new IOException(url.toString() | |
306 | + " is not a recognized imageformat."); | |
307 | } finally { | |
308 |
1
1. getInstance : negated conditional → NO_COVERAGE |
if (is != null) { |
309 |
1
1. getInstance : removed call to java/io/InputStream::close → NO_COVERAGE |
is.close(); |
310 | } | |
311 |
1
1. getInstance : negated conditional → NO_COVERAGE |
if (img != null) { |
312 | // Make sure the URL is always set | |
313 |
1
1. getInstance : removed call to com/lowagie/text/Image::setUrl → NO_COVERAGE |
img.setUrl(url); |
314 | } | |
315 | } | |
316 | } | |
317 | ||
318 | /** | |
319 | * Gets an instance of an Image. | |
320 | * | |
321 | * @param filename | |
322 | * a filename | |
323 | * @return an object of type <CODE>Gif</CODE>,<CODE>Jpeg</CODE> or | |
324 | * <CODE>Png</CODE> | |
325 | * @throws BadElementException | |
326 | * @throws MalformedURLException | |
327 | * @throws IOException | |
328 | */ | |
329 | public static Image getInstance(String filename) | |
330 | throws BadElementException, IOException { | |
331 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return getInstance(Utilities.toURL(filename)); |
332 | } | |
333 | ||
334 | /** | |
335 | * gets an instance of an Image | |
336 | * | |
337 | * @param imgb | |
338 | * raw image date | |
339 | * @return an Image object | |
340 | * @throws BadElementException | |
341 | * @throws MalformedURLException | |
342 | * @throws IOException | |
343 | */ | |
344 | public static Image getInstance(byte[] imgb) throws BadElementException, | |
345 | IOException { | |
346 | InputStream is = null; | |
347 | try { | |
348 | is = new java.io.ByteArrayInputStream(imgb); | |
349 | int c1 = is.read(); | |
350 | int c2 = is.read(); | |
351 | int c3 = is.read(); | |
352 | int c4 = is.read(); | |
353 |
1
1. getInstance : removed call to java/io/InputStream::close → NO_COVERAGE |
is.close(); |
354 | ||
355 | is = null; | |
356 |
3
1. getInstance : negated conditional → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE 3. getInstance : negated conditional → NO_COVERAGE |
if (c1 == 'G' && c2 == 'I' && c3 == 'F') { |
357 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return ImageLoader.getGifImage(imgb); |
358 | } | |
359 |
2
1. getInstance : negated conditional → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE |
if (c1 == 0xFF && c2 == 0xD8) { |
360 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return ImageLoader.getJpegImage(imgb); |
361 | } | |
362 |
4
1. getInstance : negated conditional → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE 3. getInstance : negated conditional → NO_COVERAGE 4. getInstance : negated conditional → NO_COVERAGE |
if (c1 == 0x00 && c2 == 0x00 && c3 == 0x00 && c4 == 0x0c) { |
363 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return ImageLoader.getJpeg2000Image(imgb); |
364 | } | |
365 |
4
1. getInstance : negated conditional → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE 3. getInstance : negated conditional → NO_COVERAGE 4. getInstance : negated conditional → NO_COVERAGE |
if (c1 == 0xff && c2 == 0x4f && c3 == 0xff && c4 == 0x51) { |
366 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return ImageLoader.getJpeg2000Image(imgb); |
367 | } | |
368 |
4
1. getInstance : negated conditional → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE 3. getInstance : negated conditional → NO_COVERAGE 4. getInstance : negated conditional → NO_COVERAGE |
if (c1 == PNGID[0] && c2 == PNGID[1] |
369 | && c3 == PNGID[2] && c4 == PNGID[3]) { | |
370 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return ImageLoader.getPngImage(imgb); |
371 | } | |
372 |
2
1. getInstance : negated conditional → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE |
if (c1 == 0xD7 && c2 == 0xCD) { |
373 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new ImgWMF(imgb); |
374 | } | |
375 |
2
1. getInstance : negated conditional → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE |
if (c1 == 'B' && c2 == 'M') { |
376 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return ImageLoader.getBmpImage(imgb); |
377 | } | |
378 |
8
1. getInstance : negated conditional → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE 3. getInstance : negated conditional → NO_COVERAGE 4. getInstance : negated conditional → NO_COVERAGE 5. getInstance : negated conditional → NO_COVERAGE 6. getInstance : negated conditional → NO_COVERAGE 7. getInstance : negated conditional → NO_COVERAGE 8. getInstance : negated conditional → NO_COVERAGE |
if ((c1 == 'M' && c2 == 'M' && c3 == 0 && c4 == 42) |
379 | || (c1 == 'I' && c2 == 'I' && c3 == 42 && c4 == 0)) { | |
380 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return ImageLoader.getTiffImage(imgb); |
381 | } | |
382 |
4
1. getInstance : negated conditional → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE 3. getInstance : negated conditional → NO_COVERAGE 4. getInstance : negated conditional → NO_COVERAGE |
if ( c1 == 0x97 && c2 == 'J' && c3 == 'B' && c4 == '2' ) { |
383 | is = new java.io.ByteArrayInputStream(imgb); | |
384 | is.skip(4); | |
385 | int c5 = is.read(); | |
386 | int c6 = is.read(); | |
387 | int c7 = is.read(); | |
388 | int c8 = is.read(); | |
389 |
4
1. getInstance : negated conditional → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE 3. getInstance : negated conditional → NO_COVERAGE 4. getInstance : negated conditional → NO_COVERAGE |
if ( c5 == '\r' && c6 == '\n' && c7 == 0x1a && c8 == '\n' ) { |
390 | throw new IOException(MessageLocalization.getComposedMessage("the.byte.array.is.not.a.recognized.imageformat")); | |
391 | } | |
392 | } | |
393 | throw new IOException(MessageLocalization.getComposedMessage("the.byte.array.is.not.a.recognized.imageformat")); | |
394 | } finally { | |
395 |
1
1. getInstance : negated conditional → NO_COVERAGE |
if (is != null) { |
396 |
1
1. getInstance : removed call to java/io/InputStream::close → NO_COVERAGE |
is.close(); |
397 | } | |
398 | } | |
399 | } | |
400 | ||
401 | /** | |
402 | * Gets an instance of an Image in raw mode. | |
403 | * | |
404 | * @param width | |
405 | * the width of the image in pixels | |
406 | * @param height | |
407 | * the height of the image in pixels | |
408 | * @param components | |
409 | * 1,3 or 4 for GrayScale, RGB and CMYK | |
410 | * @param data | |
411 | * the image data | |
412 | * @param bpc | |
413 | * bits per component | |
414 | * @return an object of type <CODE>ImgRaw</CODE> | |
415 | * @throws BadElementException | |
416 | * on error | |
417 | */ | |
418 | public static Image getInstance(int width, int height, int components, | |
419 | int bpc, byte[] data) throws BadElementException { | |
420 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return Image.getInstance(width, height, components, bpc, data, null); |
421 | } | |
422 | ||
423 | /** | |
424 | * Creates a JBIG2 Image. | |
425 | * @param width the width of the image | |
426 | * @param height the height of the image | |
427 | * @param data the raw image data | |
428 | * @param globals JBIG2 globals | |
429 | * @since 2.1.5 | |
430 | */ | |
431 | public static Image getInstance(int width, int height, byte[] data, byte[] globals) { | |
432 | Image img = new ImgJBIG2(width, height, data, globals); | |
433 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return img; |
434 | } | |
435 | ||
436 | /** | |
437 | * Creates an Image with CCITT G3 or G4 compression. It assumes that the | |
438 | * data bytes are already compressed. | |
439 | * | |
440 | * @param width | |
441 | * the exact width of the image | |
442 | * @param height | |
443 | * the exact height of the image | |
444 | * @param reverseBits | |
445 | * reverses the bits in <code>data</code>. Bit 0 is swapped | |
446 | * with bit 7 and so on | |
447 | * @param typeCCITT | |
448 | * the type of compression in <code>data</code>. It can be | |
449 | * CCITTG4, CCITTG31D, CCITTG32D | |
450 | * @param parameters | |
451 | * parameters associated with this stream. Possible values are | |
452 | * CCITT_BLACKIS1, CCITT_ENCODEDBYTEALIGN, CCITT_ENDOFLINE and | |
453 | * CCITT_ENDOFBLOCK or a combination of them | |
454 | * @param data | |
455 | * the image data | |
456 | * @return an Image object | |
457 | * @throws BadElementException | |
458 | * on error | |
459 | */ | |
460 | public static Image getInstance(int width, int height, boolean reverseBits, | |
461 | int typeCCITT, int parameters, byte[] data) | |
462 | throws BadElementException { | |
463 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return Image.getInstance(width, height, reverseBits, typeCCITT, |
464 | parameters, data, null); | |
465 | } | |
466 | ||
467 | /** | |
468 | * Creates an Image with CCITT G3 or G4 compression. It assumes that the | |
469 | * data bytes are already compressed. | |
470 | * | |
471 | * @param width | |
472 | * the exact width of the image | |
473 | * @param height | |
474 | * the exact height of the image | |
475 | * @param reverseBits | |
476 | * reverses the bits in <code>data</code>. Bit 0 is swapped | |
477 | * with bit 7 and so on | |
478 | * @param typeCCITT | |
479 | * the type of compression in <code>data</code>. It can be | |
480 | * CCITTG4, CCITTG31D, CCITTG32D | |
481 | * @param parameters | |
482 | * parameters associated with this stream. Possible values are | |
483 | * CCITT_BLACKIS1, CCITT_ENCODEDBYTEALIGN, CCITT_ENDOFLINE and | |
484 | * CCITT_ENDOFBLOCK or a combination of them | |
485 | * @param data | |
486 | * the image data | |
487 | * @param transparency | |
488 | * transparency information in the Mask format of the image | |
489 | * dictionary | |
490 | * @return an Image object | |
491 | * @throws BadElementException | |
492 | * on error | |
493 | */ | |
494 | public static Image getInstance(int width, int height, boolean reverseBits, | |
495 | int typeCCITT, int parameters, byte[] data, int[] transparency) | |
496 | throws BadElementException { | |
497 |
2
1. getInstance : negated conditional → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE |
if (transparency != null && transparency.length != 2) |
498 | throw new BadElementException(MessageLocalization.getComposedMessage("transparency.length.must.be.equal.to.2.with.ccitt.images")); | |
499 | Image img = new ImgCCITT(width, height, reverseBits, typeCCITT, | |
500 | parameters, data); | |
501 | img.transparency = transparency; | |
502 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return img; |
503 | } | |
504 | ||
505 | /** | |
506 | * Gets an instance of an Image in raw mode. | |
507 | * | |
508 | * @param width | |
509 | * the width of the image in pixels | |
510 | * @param height | |
511 | * the height of the image in pixels | |
512 | * @param components | |
513 | * 1,3 or 4 for GrayScale, RGB and CMYK | |
514 | * @param data | |
515 | * the image data | |
516 | * @param bpc | |
517 | * bits per component | |
518 | * @param transparency | |
519 | * transparency information in the Mask format of the image | |
520 | * dictionary | |
521 | * @return an object of type <CODE>ImgRaw</CODE> | |
522 | * @throws BadElementException | |
523 | * on error | |
524 | */ | |
525 | public static Image getInstance(int width, int height, int components, | |
526 | int bpc, byte[] data, int[] transparency) | |
527 | throws BadElementException { | |
528 |
3
1. getInstance : Replaced integer multiplication with division → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE 3. getInstance : negated conditional → NO_COVERAGE |
if (transparency != null && transparency.length != components * 2) |
529 | throw new BadElementException(MessageLocalization.getComposedMessage("transparency.length.must.be.equal.to.componentes.2")); | |
530 |
2
1. getInstance : negated conditional → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE |
if (components == 1 && bpc == 1) { |
531 | byte[] g4 = CCITTG4Encoder.compress(data, width, height); | |
532 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return Image.getInstance(width, height, false, Image.CCITTG4, |
533 | Image.CCITT_BLACKIS1, g4, transparency); | |
534 | } | |
535 | Image img = new ImgRaw(width, height, components, bpc, data); | |
536 | img.transparency = transparency; | |
537 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return img; |
538 | } | |
539 | ||
540 | // images from a PdfTemplate | |
541 | ||
542 | /** | |
543 | * gets an instance of an Image | |
544 | * | |
545 | * @param template | |
546 | * a PdfTemplate that has to be wrapped in an Image object | |
547 | * @return an Image object | |
548 | * @throws BadElementException | |
549 | */ | |
550 | public static Image getInstance(PdfTemplate template) | |
551 | throws BadElementException { | |
552 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new ImgTemplate(template); |
553 | } | |
554 | ||
555 | // images from a java.awt.Image | |
556 | ||
557 | /** | |
558 | * Gets an instance of an Image from a java.awt.Image. | |
559 | * | |
560 | * @param image | |
561 | * the <CODE>java.awt.Image</CODE> to convert | |
562 | * @param color | |
563 | * if different from <CODE>null</CODE> the transparency pixels | |
564 | * are replaced by this color | |
565 | * @param forceBW | |
566 | * if <CODE>true</CODE> the image is treated as black and white | |
567 | * @return an object of type <CODE>ImgRaw</CODE> | |
568 | * @throws BadElementException | |
569 | * on error | |
570 | * @throws IOException | |
571 | * on error | |
572 | */ | |
573 | public static Image getInstance(java.awt.Image image, java.awt.Color color, | |
574 | boolean forceBW) throws BadElementException, IOException { | |
575 | ||
576 |
1
1. getInstance : negated conditional → NO_COVERAGE |
if(image instanceof BufferedImage){ |
577 | BufferedImage bi = (BufferedImage) image; | |
578 |
1
1. getInstance : negated conditional → NO_COVERAGE |
if(bi.getType()==BufferedImage.TYPE_BYTE_BINARY) { |
579 | forceBW=true; | |
580 | } | |
581 | } | |
582 | ||
583 | java.awt.image.PixelGrabber pg = new java.awt.image.PixelGrabber(image, | |
584 | 0, 0, -1, -1, true); | |
585 | try { | |
586 | pg.grabPixels(); | |
587 | } catch (InterruptedException e) { | |
588 | throw new IOException(MessageLocalization.getComposedMessage("java.awt.image.interrupted.waiting.for.pixels")); | |
589 | } | |
590 |
2
1. getInstance : Replaced bitwise AND with OR → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE |
if ((pg.getStatus() & java.awt.image.ImageObserver.ABORT) != 0) { |
591 | throw new IOException(MessageLocalization.getComposedMessage("java.awt.image.fetch.aborted.or.errored")); | |
592 | } | |
593 | int w = pg.getWidth(); | |
594 | int h = pg.getHeight(); | |
595 | int[] pixels = (int[]) pg.getPixels(); | |
596 |
1
1. getInstance : negated conditional → NO_COVERAGE |
if (forceBW) { |
597 |
4
1. getInstance : Replaced integer division with multiplication → NO_COVERAGE 2. getInstance : Replaced bitwise AND with OR → NO_COVERAGE 3. getInstance : Replaced integer addition with subtraction → NO_COVERAGE 4. getInstance : negated conditional → NO_COVERAGE |
int byteWidth = (w / 8) + ((w & 7) != 0 ? 1 : 0); |
598 |
1
1. getInstance : Replaced integer multiplication with division → NO_COVERAGE |
byte[] pixelsByte = new byte[byteWidth * h]; |
599 | ||
600 | int index = 0; | |
601 |
1
1. getInstance : Replaced integer multiplication with division → NO_COVERAGE |
int size = h * w; |
602 | int transColor = 1; | |
603 |
1
1. getInstance : negated conditional → NO_COVERAGE |
if (color != null) { |
604 |
1
1. getInstance : Replaced integer addition with subtraction → NO_COVERAGE |
transColor = (color.getRed() + color.getGreen() |
605 |
3
1. getInstance : changed conditional boundary → NO_COVERAGE 2. getInstance : Replaced integer addition with subtraction → NO_COVERAGE 3. getInstance : negated conditional → NO_COVERAGE |
+ color.getBlue() < 384) ? 0 : 1; |
606 | } | |
607 | int[] transparency = null; | |
608 | int cbyte = 0x80; | |
609 | int wMarker = 0; | |
610 | int currByte = 0; | |
611 |
1
1. getInstance : negated conditional → NO_COVERAGE |
if (color != null) { |
612 |
3
1. getInstance : changed conditional boundary → NO_COVERAGE 2. getInstance : Changed increment from 1 to -1 → NO_COVERAGE 3. getInstance : negated conditional → NO_COVERAGE |
for (int j = 0; j < size; j++) { |
613 |
2
1. getInstance : Replaced Shift Right with Shift Left → NO_COVERAGE 2. getInstance : Replaced bitwise AND with OR → NO_COVERAGE |
int alpha = (pixels[j] >> 24) & 0xff; |
614 |
2
1. getInstance : changed conditional boundary → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE |
if (alpha < 250) { |
615 |
1
1. getInstance : negated conditional → NO_COVERAGE |
if (transColor == 1) |
616 |
1
1. getInstance : Replaced bitwise OR with AND → NO_COVERAGE |
currByte |= cbyte; |
617 | } else { | |
618 |
2
1. getInstance : Replaced bitwise AND with OR → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE |
if ((pixels[j] & 0x888) != 0) |
619 |
1
1. getInstance : Replaced bitwise OR with AND → NO_COVERAGE |
currByte |= cbyte; |
620 | } | |
621 |
1
1. getInstance : Replaced Shift Right with Shift Left → NO_COVERAGE |
cbyte >>= 1; |
622 |
4
1. getInstance : changed conditional boundary → NO_COVERAGE 2. getInstance : Replaced integer addition with subtraction → NO_COVERAGE 3. getInstance : negated conditional → NO_COVERAGE 4. getInstance : negated conditional → NO_COVERAGE |
if (cbyte == 0 || wMarker + 1 >= w) { |
623 |
1
1. getInstance : Changed increment from 1 to -1 → NO_COVERAGE |
pixelsByte[index++] = (byte) currByte; |
624 | cbyte = 0x80; | |
625 | currByte = 0; | |
626 | } | |
627 |
1
1. getInstance : Changed increment from 1 to -1 → NO_COVERAGE |
++wMarker; |
628 |
2
1. getInstance : changed conditional boundary → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE |
if (wMarker >= w) |
629 | wMarker = 0; | |
630 | } | |
631 | } else { | |
632 |
3
1. getInstance : changed conditional boundary → NO_COVERAGE 2. getInstance : Changed increment from 1 to -1 → NO_COVERAGE 3. getInstance : negated conditional → NO_COVERAGE |
for (int j = 0; j < size; j++) { |
633 |
1
1. getInstance : negated conditional → NO_COVERAGE |
if (transparency == null) { |
634 |
2
1. getInstance : Replaced Shift Right with Shift Left → NO_COVERAGE 2. getInstance : Replaced bitwise AND with OR → NO_COVERAGE |
int alpha = (pixels[j] >> 24) & 0xff; |
635 |
1
1. getInstance : negated conditional → NO_COVERAGE |
if (alpha == 0) { |
636 | transparency = new int[2]; | |
637 | /* bugfix by M.P. Liston, ASC, was: ... ? 1: 0; */ | |
638 |
2
1. getInstance : Replaced bitwise AND with OR → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE |
transparency[0] = transparency[1] = ((pixels[j] & 0x888) != 0) ? 0xff : 0; |
639 | } | |
640 | } | |
641 |
2
1. getInstance : Replaced bitwise AND with OR → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE |
if ((pixels[j] & 0x888) != 0) |
642 |
1
1. getInstance : Replaced bitwise OR with AND → NO_COVERAGE |
currByte |= cbyte; |
643 |
1
1. getInstance : Replaced Shift Right with Shift Left → NO_COVERAGE |
cbyte >>= 1; |
644 |
4
1. getInstance : changed conditional boundary → NO_COVERAGE 2. getInstance : Replaced integer addition with subtraction → NO_COVERAGE 3. getInstance : negated conditional → NO_COVERAGE 4. getInstance : negated conditional → NO_COVERAGE |
if (cbyte == 0 || wMarker + 1 >= w) { |
645 |
1
1. getInstance : Changed increment from 1 to -1 → NO_COVERAGE |
pixelsByte[index++] = (byte) currByte; |
646 | cbyte = 0x80; | |
647 | currByte = 0; | |
648 | } | |
649 |
1
1. getInstance : Changed increment from 1 to -1 → NO_COVERAGE |
++wMarker; |
650 |
2
1. getInstance : changed conditional boundary → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE |
if (wMarker >= w) |
651 | wMarker = 0; | |
652 | } | |
653 | } | |
654 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return Image.getInstance(w, h, 1, 1, pixelsByte, transparency); |
655 | } else { | |
656 |
2
1. getInstance : Replaced integer multiplication with division → NO_COVERAGE 2. getInstance : Replaced integer multiplication with division → NO_COVERAGE |
byte[] pixelsByte = new byte[w * h * 3]; |
657 | byte[] smask = null; | |
658 | ||
659 | int index = 0; | |
660 |
1
1. getInstance : Replaced integer multiplication with division → NO_COVERAGE |
int size = h * w; |
661 | int red = 255; | |
662 | int green = 255; | |
663 | int blue = 255; | |
664 |
1
1. getInstance : negated conditional → NO_COVERAGE |
if (color != null) { |
665 | red = color.getRed(); | |
666 | green = color.getGreen(); | |
667 | blue = color.getBlue(); | |
668 | } | |
669 | int[] transparency = null; | |
670 |
1
1. getInstance : negated conditional → NO_COVERAGE |
if (color != null) { |
671 |
3
1. getInstance : changed conditional boundary → NO_COVERAGE 2. getInstance : Changed increment from 1 to -1 → NO_COVERAGE 3. getInstance : negated conditional → NO_COVERAGE |
for (int j = 0; j < size; j++) { |
672 |
2
1. getInstance : Replaced Shift Right with Shift Left → NO_COVERAGE 2. getInstance : Replaced bitwise AND with OR → NO_COVERAGE |
int alpha = (pixels[j] >> 24) & 0xff; |
673 |
2
1. getInstance : changed conditional boundary → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE |
if (alpha < 250) { |
674 |
1
1. getInstance : Changed increment from 1 to -1 → NO_COVERAGE |
pixelsByte[index++] = (byte) red; |
675 |
1
1. getInstance : Changed increment from 1 to -1 → NO_COVERAGE |
pixelsByte[index++] = (byte) green; |
676 |
1
1. getInstance : Changed increment from 1 to -1 → NO_COVERAGE |
pixelsByte[index++] = (byte) blue; |
677 | } else { | |
678 |
3
1. getInstance : Changed increment from 1 to -1 → NO_COVERAGE 2. getInstance : Replaced Shift Right with Shift Left → NO_COVERAGE 3. getInstance : Replaced bitwise AND with OR → NO_COVERAGE |
pixelsByte[index++] = (byte) ((pixels[j] >> 16) & 0xff); |
679 |
3
1. getInstance : Changed increment from 1 to -1 → NO_COVERAGE 2. getInstance : Replaced Shift Right with Shift Left → NO_COVERAGE 3. getInstance : Replaced bitwise AND with OR → NO_COVERAGE |
pixelsByte[index++] = (byte) ((pixels[j] >> 8) & 0xff); |
680 |
2
1. getInstance : Changed increment from 1 to -1 → NO_COVERAGE 2. getInstance : Replaced bitwise AND with OR → NO_COVERAGE |
pixelsByte[index++] = (byte) ((pixels[j]) & 0xff); |
681 | } | |
682 | } | |
683 | } else { | |
684 | int transparentPixel = 0; | |
685 |
1
1. getInstance : Replaced integer multiplication with division → NO_COVERAGE |
smask = new byte[w * h]; |
686 | boolean shades = false; | |
687 |
3
1. getInstance : changed conditional boundary → NO_COVERAGE 2. getInstance : Changed increment from 1 to -1 → NO_COVERAGE 3. getInstance : negated conditional → NO_COVERAGE |
for (int j = 0; j < size; j++) { |
688 |
2
1. getInstance : Replaced Shift Right with Shift Left → NO_COVERAGE 2. getInstance : Replaced bitwise AND with OR → NO_COVERAGE |
byte alpha = smask[j] = (byte) ((pixels[j] >> 24) & 0xff); |
689 | /* bugfix by Chris Nokleberg */ | |
690 |
1
1. getInstance : negated conditional → NO_COVERAGE |
if (!shades) { |
691 |
2
1. getInstance : negated conditional → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE |
if (alpha != 0 && alpha != -1) { |
692 | shades = true; | |
693 |
1
1. getInstance : negated conditional → NO_COVERAGE |
} else if (transparency == null) { |
694 |
1
1. getInstance : negated conditional → NO_COVERAGE |
if (alpha == 0) { |
695 |
1
1. getInstance : Replaced bitwise AND with OR → NO_COVERAGE |
transparentPixel = pixels[j] & 0xffffff; |
696 | transparency = new int[6]; | |
697 |
2
1. getInstance : Replaced Shift Right with Shift Left → NO_COVERAGE 2. getInstance : Replaced bitwise AND with OR → NO_COVERAGE |
transparency[0] = transparency[1] = (transparentPixel >> 16) & 0xff; |
698 |
2
1. getInstance : Replaced Shift Right with Shift Left → NO_COVERAGE 2. getInstance : Replaced bitwise AND with OR → NO_COVERAGE |
transparency[2] = transparency[3] = (transparentPixel >> 8) & 0xff; |
699 |
1
1. getInstance : Replaced bitwise AND with OR → NO_COVERAGE |
transparency[4] = transparency[5] = transparentPixel & 0xff; |
700 | } | |
701 |
2
1. getInstance : Replaced bitwise AND with OR → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE |
} else if ((pixels[j] & 0xffffff) != transparentPixel) { |
702 | shades = true; | |
703 | } | |
704 | } | |
705 |
3
1. getInstance : Changed increment from 1 to -1 → NO_COVERAGE 2. getInstance : Replaced Shift Right with Shift Left → NO_COVERAGE 3. getInstance : Replaced bitwise AND with OR → NO_COVERAGE |
pixelsByte[index++] = (byte) ((pixels[j] >> 16) & 0xff); |
706 |
3
1. getInstance : Changed increment from 1 to -1 → NO_COVERAGE 2. getInstance : Replaced Shift Right with Shift Left → NO_COVERAGE 3. getInstance : Replaced bitwise AND with OR → NO_COVERAGE |
pixelsByte[index++] = (byte) ((pixels[j] >> 8) & 0xff); |
707 |
2
1. getInstance : Changed increment from 1 to -1 → NO_COVERAGE 2. getInstance : Replaced bitwise AND with OR → NO_COVERAGE |
pixelsByte[index++] = (byte) ((pixels[j]) & 0xff); |
708 | } | |
709 |
1
1. getInstance : negated conditional → NO_COVERAGE |
if (shades) |
710 | transparency = null; | |
711 | else | |
712 | smask = null; | |
713 | } | |
714 | Image img = Image.getInstance(w, h, 3, 8, pixelsByte, transparency); | |
715 |
1
1. getInstance : negated conditional → NO_COVERAGE |
if (smask != null) { |
716 | Image sm = Image.getInstance(w, h, 1, 8, smask); | |
717 | try { | |
718 |
1
1. getInstance : removed call to com/lowagie/text/Image::makeMask → NO_COVERAGE |
sm.makeMask(); |
719 |
1
1. getInstance : removed call to com/lowagie/text/Image::setImageMask → NO_COVERAGE |
img.setImageMask(sm); |
720 | } catch (DocumentException de) { | |
721 | throw new ExceptionConverter(de); | |
722 | } | |
723 | } | |
724 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return img; |
725 | } | |
726 | } | |
727 | ||
728 | /** | |
729 | * Gets an instance of an Image from a java.awt.Image. | |
730 | * | |
731 | * @param image | |
732 | * the <CODE>java.awt.Image</CODE> to convert | |
733 | * @param color | |
734 | * if different from <CODE>null</CODE> the transparency pixels | |
735 | * are replaced by this color | |
736 | * @return an object of type <CODE>ImgRaw</CODE> | |
737 | * @throws BadElementException | |
738 | * on error | |
739 | * @throws IOException | |
740 | * on error | |
741 | */ | |
742 | public static Image getInstance(java.awt.Image image, java.awt.Color color) | |
743 | throws BadElementException, IOException { | |
744 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return Image.getInstance(image, color, false); |
745 | } | |
746 | ||
747 | /** | |
748 | * Gets an instance of a Image from a java.awt.Image. | |
749 | * The image is added as a JPEG with a user defined quality. | |
750 | * | |
751 | * @param writer | |
752 | * the <CODE>PdfWriter</CODE> object to which the image will be added | |
753 | * @param awtImage | |
754 | * the <CODE>java.awt.Image</CODE> to convert | |
755 | * @param quality | |
756 | * a float value between 0 and 1 | |
757 | * @return an object of type <CODE>PdfTemplate</CODE> | |
758 | * @throws BadElementException | |
759 | * on error | |
760 | * @throws IOException | |
761 | */ | |
762 | public static Image getInstance(PdfWriter writer, java.awt.Image awtImage, float quality) throws BadElementException, IOException { | |
763 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return getInstance(new PdfContentByte(writer), awtImage, quality); |
764 | } | |
765 | ||
766 | /** | |
767 | * Gets an instance of a Image from a java.awt.Image. | |
768 | * The image is added as a JPEG with a user defined quality. | |
769 | * | |
770 | * @param cb | |
771 | * the <CODE>PdfContentByte</CODE> object to which the image will be added | |
772 | * @param awtImage | |
773 | * the <CODE>java.awt.Image</CODE> to convert | |
774 | * @param quality | |
775 | * a float value between 0 and 1 | |
776 | * @return an object of type <CODE>PdfTemplate</CODE> | |
777 | * @throws BadElementException | |
778 | * on error | |
779 | * @throws IOException | |
780 | */ | |
781 | public static Image getInstance(PdfContentByte cb, java.awt.Image awtImage, float quality) throws BadElementException, IOException { | |
782 | java.awt.image.PixelGrabber pg = new java.awt.image.PixelGrabber(awtImage, | |
783 | 0, 0, -1, -1, true); | |
784 | try { | |
785 | pg.grabPixels(); | |
786 | } catch (InterruptedException e) { | |
787 | throw new IOException(MessageLocalization.getComposedMessage("java.awt.image.interrupted.waiting.for.pixels")); | |
788 | } | |
789 |
2
1. getInstance : Replaced bitwise AND with OR → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE |
if ((pg.getStatus() & java.awt.image.ImageObserver.ABORT) != 0) { |
790 | throw new IOException(MessageLocalization.getComposedMessage("java.awt.image.fetch.aborted.or.errored")); | |
791 | } | |
792 | int w = pg.getWidth(); | |
793 | int h = pg.getHeight(); | |
794 | PdfTemplate tp = cb.createTemplate(w, h); | |
795 | Graphics2D g2d = tp.createGraphics(w, h, true, quality); | |
796 | g2d.drawImage(awtImage, 0, 0, null); | |
797 |
1
1. getInstance : removed call to java/awt/Graphics2D::dispose → NO_COVERAGE |
g2d.dispose(); |
798 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return getInstance(tp); |
799 | } | |
800 | ||
801 | // image from indirect reference | |
802 | ||
803 | /** | |
804 | * Holds value of property directReference. | |
805 | * An image is embedded into a PDF as an Image XObject. | |
806 | * This object is referenced by a PdfIndirectReference object. | |
807 | */ | |
808 | private PdfIndirectReference directReference; | |
809 | ||
810 | /** | |
811 | * Getter for property directReference. | |
812 | * @return Value of property directReference. | |
813 | */ | |
814 | public PdfIndirectReference getDirectReference() { | |
815 | return this.directReference; | |
816 | } | |
817 | ||
818 | /** | |
819 | * Setter for property directReference. | |
820 | * @param directReference New value of property directReference. | |
821 | */ | |
822 | public void setDirectReference(PdfIndirectReference directReference) { | |
823 | this.directReference = directReference; | |
824 | } | |
825 | ||
826 | /** | |
827 | * Reuses an existing image. | |
828 | * @param ref the reference to the image dictionary | |
829 | * @throws BadElementException on error | |
830 | * @return the image | |
831 | */ | |
832 | public static Image getInstance(PRIndirectReference ref) throws BadElementException { | |
833 | PdfDictionary dic = (PdfDictionary)PdfReader.getPdfObjectRelease(ref); | |
834 | int width = ((PdfNumber)PdfReader.getPdfObjectRelease(dic.get(PdfName.WIDTH))).intValue(); | |
835 | int height = ((PdfNumber)PdfReader.getPdfObjectRelease(dic.get(PdfName.HEIGHT))).intValue(); | |
836 | Image imask = null; | |
837 | PdfObject obj = dic.get(PdfName.SMASK); | |
838 |
2
1. getInstance : negated conditional → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE |
if (obj != null && obj.isIndirect()) { |
839 | imask = getInstance((PRIndirectReference)obj); | |
840 | } | |
841 | else { | |
842 | obj = dic.get(PdfName.MASK); | |
843 |
2
1. getInstance : negated conditional → NO_COVERAGE 2. getInstance : negated conditional → NO_COVERAGE |
if (obj != null && obj.isIndirect()) { |
844 | PdfObject obj2 = PdfReader.getPdfObjectRelease(obj); | |
845 |
1
1. getInstance : negated conditional → NO_COVERAGE |
if (obj2 instanceof PdfDictionary) |
846 | imask = getInstance((PRIndirectReference)obj); | |
847 | } | |
848 | } | |
849 | Image img = new ImgRaw(width, height, 1, 1, null); | |
850 | img.imageMask = imask; | |
851 | img.directReference = ref; | |
852 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return img; |
853 | } | |
854 | ||
855 | // copy constructor | |
856 | ||
857 | /** | |
858 | * Constructs an <CODE>Image</CODE> -object, using an <VAR>url </VAR>. | |
859 | * | |
860 | * @param image | |
861 | * another Image object. | |
862 | */ | |
863 | protected Image(Image image) { | |
864 | super(image); | |
865 | this.type = image.type; | |
866 | this.url = image.url; | |
867 | this.rawData = image.rawData; | |
868 | this.bpc = image.bpc; | |
869 | this.template = image.template; | |
870 | this.alignment = image.alignment; | |
871 | this.alt = image.alt; | |
872 | this.absoluteX = image.absoluteX; | |
873 | this.absoluteY = image.absoluteY; | |
874 | this.plainWidth = image.plainWidth; | |
875 | this.plainHeight = image.plainHeight; | |
876 | this.scaledWidth = image.scaledWidth; | |
877 | this.scaledHeight = image.scaledHeight; | |
878 | this.mySerialId = image.mySerialId; | |
879 | ||
880 | this.directReference = image.directReference; | |
881 | ||
882 | this.rotationRadians = image.rotationRadians; | |
883 | this.initialRotation = image.initialRotation; | |
884 | this.indentationLeft = image.indentationLeft; | |
885 | this.indentationRight = image.indentationRight; | |
886 | this.spacingBefore = image.spacingBefore; | |
887 | this.spacingAfter = image.spacingAfter; | |
888 | ||
889 | this.widthPercentage = image.widthPercentage; | |
890 | this.annotation = image.annotation; | |
891 | this.layer = image.layer; | |
892 | this.interpolation = image.interpolation; | |
893 | this.originalType = image.originalType; | |
894 | this.originalData = image.originalData; | |
895 | this.deflated = image.deflated; | |
896 | this.dpiX = image.dpiX; | |
897 | this.dpiY = image.dpiY; | |
898 | this.XYRatio = image.XYRatio; | |
899 | ||
900 | this.colorspace = image.colorspace; | |
901 | this.invert = image.invert; | |
902 | this.profile = image.profile; | |
903 | this.additional = image.additional; | |
904 | this.mask = image.mask; | |
905 | this.imageMask = image.imageMask; | |
906 | this.smask = image.smask; | |
907 | this.transparency = image.transparency; | |
908 | } | |
909 | ||
910 | /** | |
911 | * gets an instance of an Image | |
912 | * | |
913 | * @param image | |
914 | * an Image object | |
915 | * @return a new Image object | |
916 | */ | |
917 | public static Image getInstance(Image image) { | |
918 |
1
1. getInstance : negated conditional → NO_COVERAGE |
if (image == null) |
919 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return null; |
920 | try { | |
921 | Class cs = image.getClass(); | |
922 | Constructor constructor = cs | |
923 | .getDeclaredConstructor(Image.class); | |
924 |
1
1. getInstance : mutated return of Object value for com/lowagie/text/Image::getInstance to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return (Image) constructor.newInstance(image); |
925 | } catch (Exception e) { | |
926 | throw new ExceptionConverter(e); | |
927 | } | |
928 | } | |
929 | ||
930 | // implementation of the Element interface | |
931 | ||
932 | /** | |
933 | * Returns the type. | |
934 | * | |
935 | * @return a type | |
936 | */ | |
937 | ||
938 | public int type() { | |
939 | return type; | |
940 | } | |
941 | ||
942 | /** | |
943 | * @see com.lowagie.text.Element#isNestable() | |
944 | * @since iText 2.0.8 | |
945 | */ | |
946 | public boolean isNestable() { | |
947 | return true; | |
948 | } | |
949 | ||
950 | // checking the type of Image | |
951 | ||
952 | /** | |
953 | * Returns <CODE>true</CODE> if the image is a <CODE>Jpeg</CODE> | |
954 | * -object. | |
955 | * | |
956 | * @return a <CODE>boolean</CODE> | |
957 | */ | |
958 | ||
959 | public boolean isJpeg() { | |
960 |
2
1. isJpeg : negated conditional → NO_COVERAGE 2. isJpeg : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return type == JPEG; |
961 | } | |
962 | ||
963 | /** | |
964 | * Returns <CODE>true</CODE> if the image is a <CODE>ImgRaw</CODE> | |
965 | * -object. | |
966 | * | |
967 | * @return a <CODE>boolean</CODE> | |
968 | */ | |
969 | ||
970 | public boolean isImgRaw() { | |
971 |
2
1. isImgRaw : negated conditional → NO_COVERAGE 2. isImgRaw : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return type == IMGRAW; |
972 | } | |
973 | ||
974 | /** | |
975 | * Returns <CODE>true</CODE> if the image is an <CODE>ImgTemplate</CODE> | |
976 | * -object. | |
977 | * | |
978 | * @return a <CODE>boolean</CODE> | |
979 | */ | |
980 | ||
981 | public boolean isImgTemplate() { | |
982 |
2
1. isImgTemplate : negated conditional → NO_COVERAGE 2. isImgTemplate : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return type == IMGTEMPLATE; |
983 | } | |
984 | ||
985 | // getters and setters | |
986 | ||
987 | /** | |
988 | * Gets the <CODE>String</CODE> -representation of the reference to the | |
989 | * image. | |
990 | * | |
991 | * @return a <CODE>String</CODE> | |
992 | */ | |
993 | ||
994 | public URL getUrl() { | |
995 | return url; | |
996 | } | |
997 | ||
998 | /** | |
999 | * Sets the url of the image | |
1000 | * | |
1001 | * @param url | |
1002 | * the url of the image | |
1003 | */ | |
1004 | public void setUrl(URL url) { | |
1005 | this.url = url; | |
1006 | } | |
1007 | ||
1008 | /** | |
1009 | * Gets the raw data for the image. | |
1010 | * <P> | |
1011 | * Remark: this only makes sense for Images of the type <CODE>RawImage | |
1012 | * </CODE>. | |
1013 | * | |
1014 | * @return the raw data | |
1015 | */ | |
1016 | public byte[] getRawData() { | |
1017 | return rawData; | |
1018 | } | |
1019 | ||
1020 | /** | |
1021 | * Gets the bpc for the image. | |
1022 | * <P> | |
1023 | * Remark: this only makes sense for Images of the type <CODE>RawImage | |
1024 | * </CODE>. | |
1025 | * | |
1026 | * @return a bpc value | |
1027 | */ | |
1028 | public int getBpc() { | |
1029 | return bpc; | |
1030 | } | |
1031 | ||
1032 | /** | |
1033 | * Gets the template to be used as an image. | |
1034 | * <P> | |
1035 | * Remark: this only makes sense for Images of the type <CODE>ImgTemplate | |
1036 | * </CODE>. | |
1037 | * | |
1038 | * @return the template | |
1039 | */ | |
1040 | public PdfTemplate getTemplateData() { | |
1041 |
1
1. getTemplateData : mutated return of Object value for com/lowagie/text/Image::getTemplateData to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return template[0]; |
1042 | } | |
1043 | ||
1044 | /** | |
1045 | * Sets data from a PdfTemplate | |
1046 | * | |
1047 | * @param template | |
1048 | * the template with the content | |
1049 | */ | |
1050 | public void setTemplateData(PdfTemplate template) { | |
1051 | this.template[0] = template; | |
1052 | } | |
1053 | ||
1054 | /** | |
1055 | * Gets the alignment for the image. | |
1056 | * | |
1057 | * @return a value | |
1058 | */ | |
1059 | public int getAlignment() { | |
1060 | return alignment; | |
1061 | } | |
1062 | ||
1063 | /** | |
1064 | * Sets the alignment for the image. | |
1065 | * | |
1066 | * @param alignment | |
1067 | * the alignment | |
1068 | */ | |
1069 | ||
1070 | public void setAlignment(int alignment) { | |
1071 | this.alignment = alignment; | |
1072 | } | |
1073 | ||
1074 | /** | |
1075 | * Gets the alternative text for the image. | |
1076 | * | |
1077 | * @return a <CODE>String</CODE> | |
1078 | */ | |
1079 | ||
1080 | public String getAlt() { | |
1081 | return alt; | |
1082 | } | |
1083 | ||
1084 | /** | |
1085 | * Sets the alternative information for the image. | |
1086 | * | |
1087 | * @param alt | |
1088 | * the alternative information | |
1089 | */ | |
1090 | ||
1091 | public void setAlt(String alt) { | |
1092 | this.alt = alt; | |
1093 | } | |
1094 | ||
1095 | /** | |
1096 | * Sets the absolute position of the <CODE>Image</CODE>. | |
1097 | * | |
1098 | * @param absoluteX | |
1099 | * @param absoluteY | |
1100 | */ | |
1101 | ||
1102 | public void setAbsolutePosition(float absoluteX, float absoluteY) { | |
1103 | this.absoluteX = absoluteX; | |
1104 | this.absoluteY = absoluteY; | |
1105 | } | |
1106 | ||
1107 | /** | |
1108 | * Checks if the <CODE>Images</CODE> has to be added at an absolute X | |
1109 | * position. | |
1110 | * | |
1111 | * @return a boolean | |
1112 | */ | |
1113 | public boolean hasAbsoluteX() { | |
1114 |
2
1. hasAbsoluteX : negated conditional → NO_COVERAGE 2. hasAbsoluteX : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return !Float.isNaN(absoluteX); |
1115 | } | |
1116 | ||
1117 | /** | |
1118 | * Returns the absolute X position. | |
1119 | * | |
1120 | * @return a position | |
1121 | */ | |
1122 | public float getAbsoluteX() { | |
1123 | return absoluteX; | |
1124 | } | |
1125 | ||
1126 | /** | |
1127 | * Checks if the <CODE>Images</CODE> has to be added at an absolute | |
1128 | * position. | |
1129 | * | |
1130 | * @return a boolean | |
1131 | */ | |
1132 | public boolean hasAbsoluteY() { | |
1133 |
2
1. hasAbsoluteY : negated conditional → NO_COVERAGE 2. hasAbsoluteY : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return !Float.isNaN(absoluteY); |
1134 | } | |
1135 | ||
1136 | /** | |
1137 | * Returns the absolute Y position. | |
1138 | * | |
1139 | * @return a position | |
1140 | */ | |
1141 | public float getAbsoluteY() { | |
1142 | return absoluteY; | |
1143 | } | |
1144 | ||
1145 | // width and height | |
1146 | ||
1147 | /** | |
1148 | * Gets the scaled width of the image. | |
1149 | * | |
1150 | * @return a value | |
1151 | */ | |
1152 | public float getScaledWidth() { | |
1153 | return scaledWidth; | |
1154 | } | |
1155 | ||
1156 | /** | |
1157 | * Gets the scaled height of the image. | |
1158 | * | |
1159 | * @return a value | |
1160 | */ | |
1161 | public float getScaledHeight() { | |
1162 | return scaledHeight; | |
1163 | } | |
1164 | ||
1165 | /** | |
1166 | * Gets the plain width of the image. | |
1167 | * | |
1168 | * @return a value | |
1169 | */ | |
1170 | public float getPlainWidth() { | |
1171 | return plainWidth; | |
1172 | } | |
1173 | ||
1174 | /** | |
1175 | * Gets the plain height of the image. | |
1176 | * | |
1177 | * @return a value | |
1178 | */ | |
1179 | public float getPlainHeight() { | |
1180 | return plainHeight; | |
1181 | } | |
1182 | ||
1183 | /** | |
1184 | * Scale the image to an absolute width and an absolute height. | |
1185 | * | |
1186 | * @param newWidth | |
1187 | * the new width | |
1188 | * @param newHeight | |
1189 | * the new height | |
1190 | */ | |
1191 | public void scaleAbsolute(float newWidth, float newHeight) { | |
1192 | plainWidth = newWidth; | |
1193 | plainHeight = newHeight; | |
1194 | float[] matrix = matrix(); | |
1195 |
1
1. scaleAbsolute : Replaced float subtraction with addition → NO_COVERAGE |
scaledWidth = matrix[DX] - matrix[CX]; |
1196 |
1
1. scaleAbsolute : Replaced float subtraction with addition → NO_COVERAGE |
scaledHeight = matrix[DY] - matrix[CY]; |
1197 |
1
1. scaleAbsolute : removed call to com/lowagie/text/Image::setWidthPercentage → NO_COVERAGE |
setWidthPercentage(0); |
1198 | } | |
1199 | ||
1200 | /** | |
1201 | * Scale the image to an absolute width. | |
1202 | * | |
1203 | * @param newWidth | |
1204 | * the new width | |
1205 | */ | |
1206 | public void scaleAbsoluteWidth(float newWidth) { | |
1207 | plainWidth = newWidth; | |
1208 | float[] matrix = matrix(); | |
1209 |
1
1. scaleAbsoluteWidth : Replaced float subtraction with addition → NO_COVERAGE |
scaledWidth = matrix[DX] - matrix[CX]; |
1210 |
1
1. scaleAbsoluteWidth : Replaced float subtraction with addition → NO_COVERAGE |
scaledHeight = matrix[DY] - matrix[CY]; |
1211 |
1
1. scaleAbsoluteWidth : removed call to com/lowagie/text/Image::setWidthPercentage → NO_COVERAGE |
setWidthPercentage(0); |
1212 | } | |
1213 | ||
1214 | /** | |
1215 | * Scale the image to an absolute height. | |
1216 | * | |
1217 | * @param newHeight | |
1218 | * the new height | |
1219 | */ | |
1220 | public void scaleAbsoluteHeight(float newHeight) { | |
1221 | plainHeight = newHeight; | |
1222 | float[] matrix = matrix(); | |
1223 |
1
1. scaleAbsoluteHeight : Replaced float subtraction with addition → NO_COVERAGE |
scaledWidth = matrix[DX] - matrix[CX]; |
1224 |
1
1. scaleAbsoluteHeight : Replaced float subtraction with addition → NO_COVERAGE |
scaledHeight = matrix[DY] - matrix[CY]; |
1225 |
1
1. scaleAbsoluteHeight : removed call to com/lowagie/text/Image::setWidthPercentage → NO_COVERAGE |
setWidthPercentage(0); |
1226 | } | |
1227 | ||
1228 | /** | |
1229 | * Scale the image to a certain percentage. | |
1230 | * | |
1231 | * @param percent | |
1232 | * the scaling percentage | |
1233 | */ | |
1234 | public void scalePercent(float percent) { | |
1235 | scalePercent(percent, percent); | |
1236 | } | |
1237 | ||
1238 | /** | |
1239 | * Scale the width and height of an image to a certain percentage. | |
1240 | * | |
1241 | * @param percentX | |
1242 | * the scaling percentage of the width | |
1243 | * @param percentY | |
1244 | * the scaling percentage of the height | |
1245 | */ | |
1246 | public void scalePercent(float percentX, float percentY) { | |
1247 |
2
1. scalePercent : Replaced float multiplication with division → NO_COVERAGE 2. scalePercent : Replaced float division with multiplication → NO_COVERAGE |
plainWidth = (getWidth() * percentX) / 100f; |
1248 |
2
1. scalePercent : Replaced float multiplication with division → NO_COVERAGE 2. scalePercent : Replaced float division with multiplication → NO_COVERAGE |
plainHeight = (getHeight() * percentY) / 100f; |
1249 | float[] matrix = matrix(); | |
1250 |
1
1. scalePercent : Replaced float subtraction with addition → NO_COVERAGE |
scaledWidth = matrix[DX] - matrix[CX]; |
1251 |
1
1. scalePercent : Replaced float subtraction with addition → NO_COVERAGE |
scaledHeight = matrix[DY] - matrix[CY]; |
1252 |
1
1. scalePercent : removed call to com/lowagie/text/Image::setWidthPercentage → NO_COVERAGE |
setWidthPercentage(0); |
1253 | } | |
1254 | ||
1255 | /** | |
1256 | * Scales the image so that it fits a certain width and height. | |
1257 | * | |
1258 | * @param fitWidth | |
1259 | * the width to fit | |
1260 | * @param fitHeight | |
1261 | * the height to fit | |
1262 | */ | |
1263 | public void scaleToFit(float fitWidth, float fitHeight) { | |
1264 |
1
1. scaleToFit : removed call to com/lowagie/text/Image::scalePercent → NO_COVERAGE |
scalePercent(100); |
1265 |
2
1. scaleToFit : Replaced float multiplication with division → NO_COVERAGE 2. scaleToFit : Replaced float division with multiplication → NO_COVERAGE |
float percentX = (fitWidth * 100) / getScaledWidth(); |
1266 |
2
1. scaleToFit : Replaced float multiplication with division → NO_COVERAGE 2. scaleToFit : Replaced float division with multiplication → NO_COVERAGE |
float percentY = (fitHeight * 100) / getScaledHeight(); |
1267 |
3
1. scaleToFit : changed conditional boundary → NO_COVERAGE 2. scaleToFit : negated conditional → NO_COVERAGE 3. scaleToFit : removed call to com/lowagie/text/Image::scalePercent → NO_COVERAGE |
scalePercent(percentX < percentY ? percentX : percentY); |
1268 |
1
1. scaleToFit : removed call to com/lowagie/text/Image::setWidthPercentage → NO_COVERAGE |
setWidthPercentage(0); |
1269 | } | |
1270 | ||
1271 | /** | |
1272 | * Returns the transformation matrix of the image. | |
1273 | * | |
1274 | * @return an array [AX, AY, BX, BY, CX, CY, DX, DY] | |
1275 | */ | |
1276 | public float[] matrix() { | |
1277 | float[] matrix = new float[8]; | |
1278 | float cosX = (float) Math.cos(rotationRadians); | |
1279 | float sinX = (float) Math.sin(rotationRadians); | |
1280 |
1
1. matrix : Replaced float multiplication with division → NO_COVERAGE |
matrix[AX] = plainWidth * cosX; |
1281 |
1
1. matrix : Replaced float multiplication with division → NO_COVERAGE |
matrix[AY] = plainWidth * sinX; |
1282 |
2
1. matrix : removed negation → NO_COVERAGE 2. matrix : Replaced float multiplication with division → NO_COVERAGE |
matrix[BX] = (-plainHeight) * sinX; |
1283 |
1
1. matrix : Replaced float multiplication with division → NO_COVERAGE |
matrix[BY] = plainHeight * cosX; |
1284 |
2
1. matrix : changed conditional boundary → NO_COVERAGE 2. matrix : negated conditional → NO_COVERAGE |
if (rotationRadians < Math.PI / 2f) { |
1285 | matrix[CX] = matrix[BX]; | |
1286 | matrix[CY] = 0; | |
1287 | matrix[DX] = matrix[AX]; | |
1288 |
1
1. matrix : Replaced float addition with subtraction → NO_COVERAGE |
matrix[DY] = matrix[AY] + matrix[BY]; |
1289 |
2
1. matrix : changed conditional boundary → NO_COVERAGE 2. matrix : negated conditional → NO_COVERAGE |
} else if (rotationRadians < Math.PI) { |
1290 |
1
1. matrix : Replaced float addition with subtraction → NO_COVERAGE |
matrix[CX] = matrix[AX] + matrix[BX]; |
1291 | matrix[CY] = matrix[BY]; | |
1292 | matrix[DX] = 0; | |
1293 | matrix[DY] = matrix[AY]; | |
1294 |
2
1. matrix : changed conditional boundary → NO_COVERAGE 2. matrix : negated conditional → NO_COVERAGE |
} else if (rotationRadians < Math.PI * 1.5f) { |
1295 | matrix[CX] = matrix[AX]; | |
1296 |
1
1. matrix : Replaced float addition with subtraction → NO_COVERAGE |
matrix[CY] = matrix[AY] + matrix[BY]; |
1297 | matrix[DX] = matrix[BX]; | |
1298 | matrix[DY] = 0; | |
1299 | } else { | |
1300 | matrix[CX] = 0; | |
1301 | matrix[CY] = matrix[AY]; | |
1302 |
1
1. matrix : Replaced float addition with subtraction → NO_COVERAGE |
matrix[DX] = matrix[AX] + matrix[BX]; |
1303 | matrix[DY] = matrix[BY]; | |
1304 | } | |
1305 |
1
1. matrix : mutated return of Object value for com/lowagie/text/Image::matrix to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return matrix; |
1306 | } | |
1307 | ||
1308 | // serial stamping | |
1309 | ||
1310 | /** a static that is used for attributing a unique id to each image. */ | |
1311 | static long serialId = 0; | |
1312 | ||
1313 | /** Creates a new serial id. */ | |
1314 | static protected synchronized Long getSerialId() { | |
1315 |
1
1. getSerialId : Replaced long addition with subtraction → NO_COVERAGE |
++serialId; |
1316 |
1
1. getSerialId : mutated return of Object value for com/lowagie/text/Image::getSerialId to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return serialId; |
1317 | } | |
1318 | ||
1319 | /** | |
1320 | * Returns a serial id for the Image (reuse the same image more than once) | |
1321 | * | |
1322 | * @return a serialId | |
1323 | */ | |
1324 | public Long getMySerialId() { | |
1325 | return mySerialId; | |
1326 | } | |
1327 | ||
1328 | // rotation, note that the superclass also has a rotation value. | |
1329 | ||
1330 | /** This is the rotation of the image in radians. */ | |
1331 | protected float rotationRadians; | |
1332 | ||
1333 | /** Holds value of property initialRotation. */ | |
1334 | private float initialRotation; | |
1335 | ||
1336 | /** | |
1337 | * Gets the current image rotation in radians. | |
1338 | * @return the current image rotation in radians | |
1339 | */ | |
1340 | public float getImageRotation() { | |
1341 | double d = 2.0 * Math.PI; | |
1342 |
2
1. getImageRotation : Replaced float subtraction with addition → NO_COVERAGE 2. getImageRotation : Replaced double modulus with multiplication → NO_COVERAGE |
float rot = (float) ((rotationRadians - initialRotation) % d); |
1343 |
2
1. getImageRotation : changed conditional boundary → NO_COVERAGE 2. getImageRotation : negated conditional → NO_COVERAGE |
if (rot < 0) { |
1344 |
1
1. getImageRotation : Replaced double addition with subtraction → NO_COVERAGE |
rot += d; |
1345 | } | |
1346 |
1
1. getImageRotation : replaced return of float value with -(x + 1) for com/lowagie/text/Image::getImageRotation → NO_COVERAGE |
return rot; |
1347 | } | |
1348 | ||
1349 | /** | |
1350 | * Sets the rotation of the image in radians. | |
1351 | * | |
1352 | * @param r | |
1353 | * rotation in radians | |
1354 | */ | |
1355 | public void setRotation(float r) { | |
1356 | double d = 2.0 * Math.PI; | |
1357 |
2
1. setRotation : Replaced float addition with subtraction → NO_COVERAGE 2. setRotation : Replaced double modulus with multiplication → NO_COVERAGE |
rotationRadians = (float) ((r + initialRotation) % d); |
1358 |
2
1. setRotation : changed conditional boundary → NO_COVERAGE 2. setRotation : negated conditional → NO_COVERAGE |
if (rotationRadians < 0) { |
1359 |
1
1. setRotation : Replaced double addition with subtraction → NO_COVERAGE |
rotationRadians += d; |
1360 | } | |
1361 | float[] matrix = matrix(); | |
1362 |
1
1. setRotation : Replaced float subtraction with addition → NO_COVERAGE |
scaledWidth = matrix[DX] - matrix[CX]; |
1363 |
1
1. setRotation : Replaced float subtraction with addition → NO_COVERAGE |
scaledHeight = matrix[DY] - matrix[CY]; |
1364 | } | |
1365 | ||
1366 | /** | |
1367 | * Sets the rotation of the image in degrees. | |
1368 | * | |
1369 | * @param deg | |
1370 | * rotation in degrees | |
1371 | */ | |
1372 | public void setRotationDegrees(float deg) { | |
1373 | double d = Math.PI; | |
1374 |
3
1. setRotationDegrees : Replaced float division with multiplication → NO_COVERAGE 2. setRotationDegrees : Replaced float multiplication with division → NO_COVERAGE 3. setRotationDegrees : removed call to com/lowagie/text/Image::setRotation → NO_COVERAGE |
setRotation(deg / 180 * (float) d); |
1375 | } | |
1376 | ||
1377 | /** | |
1378 | * Getter for property initialRotation. | |
1379 | * @return Value of property initialRotation. | |
1380 | */ | |
1381 | public float getInitialRotation() { | |
1382 | return this.initialRotation; | |
1383 | } | |
1384 | ||
1385 | /** | |
1386 | * Some image formats, like TIFF may present the images rotated that have | |
1387 | * to be compensated. | |
1388 | * @param initialRotation New value of property initialRotation. | |
1389 | */ | |
1390 | public void setInitialRotation(float initialRotation) { | |
1391 |
1
1. setInitialRotation : Replaced float subtraction with addition → NO_COVERAGE |
float old_rot = rotationRadians - this.initialRotation; |
1392 | this.initialRotation = initialRotation; | |
1393 |
1
1. setInitialRotation : removed call to com/lowagie/text/Image::setRotation → NO_COVERAGE |
setRotation(old_rot); |
1394 | } | |
1395 | ||
1396 | // indentations | |
1397 | ||
1398 | /** the indentation to the left. */ | |
1399 | protected float indentationLeft = 0; | |
1400 | ||
1401 | /** the indentation to the right. */ | |
1402 | protected float indentationRight = 0; | |
1403 | ||
1404 | /** The spacing before the image. */ | |
1405 | protected float spacingBefore; | |
1406 | ||
1407 | /** The spacing after the image. */ | |
1408 | protected float spacingAfter; | |
1409 | ||
1410 | /** | |
1411 | * Gets the left indentation. | |
1412 | * | |
1413 | * @return the left indentation | |
1414 | */ | |
1415 | public float getIndentationLeft() { | |
1416 | return indentationLeft; | |
1417 | } | |
1418 | ||
1419 | /** | |
1420 | * Sets the left indentation. | |
1421 | * | |
1422 | * @param f | |
1423 | */ | |
1424 | public void setIndentationLeft(float f) { | |
1425 | indentationLeft = f; | |
1426 | } | |
1427 | ||
1428 | /** | |
1429 | * Gets the right indentation. | |
1430 | * | |
1431 | * @return the right indentation | |
1432 | */ | |
1433 | public float getIndentationRight() { | |
1434 | return indentationRight; | |
1435 | } | |
1436 | ||
1437 | /** | |
1438 | * Sets the right indentation. | |
1439 | * | |
1440 | * @param f | |
1441 | */ | |
1442 | public void setIndentationRight(float f) { | |
1443 | indentationRight = f; | |
1444 | } | |
1445 | ||
1446 | /** | |
1447 | * Gets the spacing before this image. | |
1448 | * | |
1449 | * @return the spacing | |
1450 | */ | |
1451 | public float getSpacingBefore() { | |
1452 | return spacingBefore; | |
1453 | } | |
1454 | ||
1455 | /** | |
1456 | * Sets the spacing before this image. | |
1457 | * | |
1458 | * @param spacing | |
1459 | * the new spacing | |
1460 | */ | |
1461 | ||
1462 | public void setSpacingBefore(float spacing) { | |
1463 | this.spacingBefore = spacing; | |
1464 | } | |
1465 | ||
1466 | /** | |
1467 | * Gets the spacing before this image. | |
1468 | * | |
1469 | * @return the spacing | |
1470 | */ | |
1471 | public float getSpacingAfter() { | |
1472 | return spacingAfter; | |
1473 | } | |
1474 | ||
1475 | /** | |
1476 | * Sets the spacing after this image. | |
1477 | * | |
1478 | * @param spacing | |
1479 | * the new spacing | |
1480 | */ | |
1481 | ||
1482 | public void setSpacingAfter(float spacing) { | |
1483 | this.spacingAfter = spacing; | |
1484 | } | |
1485 | ||
1486 | // widthpercentage (for the moment only used in ColumnText) | |
1487 | ||
1488 | /** | |
1489 | * Holds value of property widthPercentage. | |
1490 | */ | |
1491 | private float widthPercentage = 100; | |
1492 | ||
1493 | /** | |
1494 | * Getter for property widthPercentage. | |
1495 | * | |
1496 | * @return Value of property widthPercentage. | |
1497 | */ | |
1498 | public float getWidthPercentage() { | |
1499 | return this.widthPercentage; | |
1500 | } | |
1501 | ||
1502 | /** | |
1503 | * Setter for property widthPercentage. | |
1504 | * | |
1505 | * @param widthPercentage | |
1506 | * New value of property widthPercentage. | |
1507 | */ | |
1508 | public void setWidthPercentage(float widthPercentage) { | |
1509 | this.widthPercentage = widthPercentage; | |
1510 | } | |
1511 | ||
1512 | // annotation | |
1513 | ||
1514 | /** if the annotation is not null the image will be clickable. */ | |
1515 | protected Annotation annotation = null; | |
1516 | ||
1517 | /** | |
1518 | * Sets the annotation of this Image. | |
1519 | * | |
1520 | * @param annotation | |
1521 | * the annotation | |
1522 | */ | |
1523 | public void setAnnotation(Annotation annotation) { | |
1524 | this.annotation = annotation; | |
1525 | } | |
1526 | ||
1527 | /** | |
1528 | * Gets the annotation. | |
1529 | * | |
1530 | * @return the annotation that is linked to this image | |
1531 | */ | |
1532 | public Annotation getAnnotation() { | |
1533 | return annotation; | |
1534 | } | |
1535 | ||
1536 | // Optional Content | |
1537 | ||
1538 | /** Optional Content layer to which we want this Image to belong. */ | |
1539 | protected PdfOCG layer; | |
1540 | ||
1541 | /** | |
1542 | * Gets the layer this image belongs to. | |
1543 | * | |
1544 | * @return the layer this image belongs to or <code>null</code> for no | |
1545 | * layer defined | |
1546 | */ | |
1547 | public PdfOCG getLayer() { | |
1548 | return layer; | |
1549 | } | |
1550 | ||
1551 | /** | |
1552 | * Sets the layer this image belongs to. | |
1553 | * | |
1554 | * @param layer | |
1555 | * the layer this image belongs to | |
1556 | */ | |
1557 | public void setLayer(PdfOCG layer) { | |
1558 | this.layer = layer; | |
1559 | } | |
1560 | ||
1561 | // interpolation | |
1562 | ||
1563 | /** Holds value of property interpolation. */ | |
1564 | protected boolean interpolation; | |
1565 | ||
1566 | /** | |
1567 | * Getter for property interpolation. | |
1568 | * | |
1569 | * @return Value of property interpolation. | |
1570 | */ | |
1571 | public boolean isInterpolation() { | |
1572 | return interpolation; | |
1573 | } | |
1574 | ||
1575 | /** | |
1576 | * Sets the image interpolation. Image interpolation attempts to produce a | |
1577 | * smooth transition between adjacent sample values. | |
1578 | * | |
1579 | * @param interpolation | |
1580 | * New value of property interpolation. | |
1581 | */ | |
1582 | public void setInterpolation(boolean interpolation) { | |
1583 | this.interpolation = interpolation; | |
1584 | } | |
1585 | ||
1586 | // original type and data | |
1587 | ||
1588 | /** Holds value of property originalType. */ | |
1589 | protected int originalType = ORIGINAL_NONE; | |
1590 | ||
1591 | /** Holds value of property originalData. */ | |
1592 | protected byte[] originalData; | |
1593 | ||
1594 | /** | |
1595 | * Getter for property originalType. | |
1596 | * | |
1597 | * @return Value of property originalType. | |
1598 | * | |
1599 | */ | |
1600 | public int getOriginalType() { | |
1601 | return this.originalType; | |
1602 | } | |
1603 | ||
1604 | /** | |
1605 | * Setter for property originalType. | |
1606 | * | |
1607 | * @param originalType | |
1608 | * New value of property originalType. | |
1609 | * | |
1610 | */ | |
1611 | public void setOriginalType(int originalType) { | |
1612 | this.originalType = originalType; | |
1613 | } | |
1614 | ||
1615 | /** | |
1616 | * Getter for property originalData. | |
1617 | * | |
1618 | * @return Value of property originalData. | |
1619 | * | |
1620 | */ | |
1621 | public byte[] getOriginalData() { | |
1622 | return this.originalData; | |
1623 | } | |
1624 | ||
1625 | /** | |
1626 | * Setter for property originalData. | |
1627 | * | |
1628 | * @param originalData | |
1629 | * New value of property originalData. | |
1630 | * | |
1631 | */ | |
1632 | public void setOriginalData(byte[] originalData) { | |
1633 | this.originalData = originalData; | |
1634 | } | |
1635 | ||
1636 | // the following values are only set for specific types of images. | |
1637 | ||
1638 | /** Holds value of property deflated. */ | |
1639 | protected boolean deflated = false; | |
1640 | ||
1641 | /** | |
1642 | * Getter for property deflated. | |
1643 | * | |
1644 | * @return Value of property deflated. | |
1645 | * | |
1646 | */ | |
1647 | public boolean isDeflated() { | |
1648 | return this.deflated; | |
1649 | } | |
1650 | ||
1651 | /** | |
1652 | * Setter for property deflated. | |
1653 | * | |
1654 | * @param deflated | |
1655 | * New value of property deflated. | |
1656 | */ | |
1657 | public void setDeflated(boolean deflated) { | |
1658 | this.deflated = deflated; | |
1659 | } | |
1660 | ||
1661 | // DPI info | |
1662 | ||
1663 | /** Holds value of property dpiX. */ | |
1664 | protected int dpiX = 0; | |
1665 | ||
1666 | /** Holds value of property dpiY. */ | |
1667 | protected int dpiY = 0; | |
1668 | ||
1669 | /** | |
1670 | * Gets the dots-per-inch in the X direction. Returns 0 if not available. | |
1671 | * | |
1672 | * @return the dots-per-inch in the X direction | |
1673 | */ | |
1674 | public int getDpiX() { | |
1675 | return dpiX; | |
1676 | } | |
1677 | ||
1678 | /** | |
1679 | * Gets the dots-per-inch in the Y direction. Returns 0 if not available. | |
1680 | * | |
1681 | * @return the dots-per-inch in the Y direction | |
1682 | */ | |
1683 | public int getDpiY() { | |
1684 | return dpiY; | |
1685 | } | |
1686 | ||
1687 | /** | |
1688 | * Sets the dots per inch value | |
1689 | * | |
1690 | * @param dpiX | |
1691 | * dpi for x coordinates | |
1692 | * @param dpiY | |
1693 | * dpi for y coordinates | |
1694 | */ | |
1695 | public void setDpi(int dpiX, int dpiY) { | |
1696 | this.dpiX = dpiX; | |
1697 | this.dpiY = dpiY; | |
1698 | } | |
1699 | ||
1700 | // XY Ratio | |
1701 | ||
1702 | /** Holds value of property XYRatio. */ | |
1703 | private float XYRatio = 0; | |
1704 | ||
1705 | /** | |
1706 | * Gets the X/Y pixel dimensionless aspect ratio. | |
1707 | * | |
1708 | * @return the X/Y pixel dimensionless aspect ratio | |
1709 | */ | |
1710 | public float getXYRatio() { | |
1711 | return this.XYRatio; | |
1712 | } | |
1713 | ||
1714 | /** | |
1715 | * Sets the X/Y pixel dimensionless aspect ratio. | |
1716 | * | |
1717 | * @param XYRatio | |
1718 | * the X/Y pixel dimensionless aspect ratio | |
1719 | */ | |
1720 | public void setXYRatio(float XYRatio) { | |
1721 | this.XYRatio = XYRatio; | |
1722 | } | |
1723 | ||
1724 | // color, colorspaces and transparency | |
1725 | ||
1726 | /** this is the colorspace of a jpeg-image. */ | |
1727 | protected int colorspace = -1; | |
1728 | ||
1729 | /** | |
1730 | * Gets the colorspace for the image. | |
1731 | * <P> | |
1732 | * Remark: this only makes sense for Images of the type <CODE>Jpeg</CODE>. | |
1733 | * | |
1734 | * @return a colorspace value | |
1735 | */ | |
1736 | public int getColorspace() { | |
1737 | return colorspace; | |
1738 | } | |
1739 | ||
1740 | /** Image color inversion */ | |
1741 | protected boolean invert = false; | |
1742 | ||
1743 | /** | |
1744 | * Getter for the inverted value | |
1745 | * | |
1746 | * @return true if the image is inverted | |
1747 | */ | |
1748 | public boolean isInverted() { | |
1749 | return invert; | |
1750 | } | |
1751 | ||
1752 | /** | |
1753 | * Sets inverted true or false | |
1754 | * | |
1755 | * @param invert | |
1756 | * true or false | |
1757 | */ | |
1758 | public void setInverted(boolean invert) { | |
1759 | this.invert = invert; | |
1760 | } | |
1761 | ||
1762 | /** ICC Profile attached */ | |
1763 | protected ICC_Profile profile = null; | |
1764 | ||
1765 | /** | |
1766 | * Tags this image with an ICC profile. | |
1767 | * | |
1768 | * @param profile | |
1769 | * the profile | |
1770 | */ | |
1771 | public void tagICC(ICC_Profile profile) { | |
1772 | this.profile = profile; | |
1773 | } | |
1774 | ||
1775 | /** | |
1776 | * Checks is the image has an ICC profile. | |
1777 | * | |
1778 | * @return the ICC profile or <CODE>null</CODE> | |
1779 | */ | |
1780 | public boolean hasICCProfile() { | |
1781 |
2
1. hasICCProfile : negated conditional → NO_COVERAGE 2. hasICCProfile : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return (this.profile != null); |
1782 | } | |
1783 | ||
1784 | /** | |
1785 | * Gets the images ICC profile. | |
1786 | * | |
1787 | * @return the ICC profile | |
1788 | */ | |
1789 | public ICC_Profile getICCProfile() { | |
1790 | return profile; | |
1791 | } | |
1792 | ||
1793 | /** a dictionary with additional information */ | |
1794 | private PdfDictionary additional = null; | |
1795 | ||
1796 | /** | |
1797 | * Getter for the dictionary with additional information. | |
1798 | * | |
1799 | * @return a PdfDictionary with additional information. | |
1800 | */ | |
1801 | public PdfDictionary getAdditional() { | |
1802 | return this.additional; | |
1803 | } | |
1804 | ||
1805 | /** | |
1806 | * Sets the /Colorspace key. | |
1807 | * | |
1808 | * @param additional | |
1809 | * a PdfDictionary with additional information. | |
1810 | */ | |
1811 | public void setAdditional(PdfDictionary additional) { | |
1812 | this.additional = additional; | |
1813 | } | |
1814 | ||
1815 | /** | |
1816 | * Replaces CalRGB and CalGray colorspaces with DeviceRGB and DeviceGray. | |
1817 | */ | |
1818 | public void simplifyColorspace() { | |
1819 |
1
1. simplifyColorspace : negated conditional → NO_COVERAGE |
if (additional == null) |
1820 | return; | |
1821 | PdfArray value = additional.getAsArray(PdfName.COLORSPACE); | |
1822 |
1
1. simplifyColorspace : negated conditional → NO_COVERAGE |
if (value == null) |
1823 | return; | |
1824 | PdfObject cs = simplifyColorspace(value); | |
1825 | PdfObject newValue; | |
1826 |
1
1. simplifyColorspace : negated conditional → NO_COVERAGE |
if (cs.isName()) |
1827 | newValue = cs; | |
1828 | else { | |
1829 | newValue = value; | |
1830 | PdfName first = value.getAsName(0); | |
1831 |
1
1. simplifyColorspace : negated conditional → NO_COVERAGE |
if (PdfName.INDEXED.equals(first)) { |
1832 |
2
1. simplifyColorspace : changed conditional boundary → NO_COVERAGE 2. simplifyColorspace : negated conditional → NO_COVERAGE |
if (value.size() >= 2) { |
1833 | PdfArray second = value.getAsArray(1); | |
1834 |
1
1. simplifyColorspace : negated conditional → NO_COVERAGE |
if (second != null) { |
1835 | value.set(1, simplifyColorspace(second)); | |
1836 | } | |
1837 | } | |
1838 | } | |
1839 | } | |
1840 |
1
1. simplifyColorspace : removed call to com/lowagie/text/pdf/PdfDictionary::put → NO_COVERAGE |
additional.put(PdfName.COLORSPACE, newValue); |
1841 | } | |
1842 | ||
1843 | /** | |
1844 | * Gets a PDF Name from an array or returns the object that was passed. | |
1845 | */ | |
1846 | private PdfObject simplifyColorspace(PdfArray obj) { | |
1847 |
1
1. simplifyColorspace : negated conditional → NO_COVERAGE |
if (obj == null) |
1848 |
1
1. simplifyColorspace : mutated return of Object value for com/lowagie/text/Image::simplifyColorspace to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return obj; |
1849 | PdfName first = obj.getAsName(0); | |
1850 |
1
1. simplifyColorspace : negated conditional → NO_COVERAGE |
if (PdfName.CALGRAY.equals(first)) |
1851 |
1
1. simplifyColorspace : mutated return of Object value for com/lowagie/text/Image::simplifyColorspace to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return PdfName.DEVICEGRAY; |
1852 |
1
1. simplifyColorspace : negated conditional → NO_COVERAGE |
else if (PdfName.CALRGB.equals(first)) |
1853 |
1
1. simplifyColorspace : mutated return of Object value for com/lowagie/text/Image::simplifyColorspace to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return PdfName.DEVICERGB; |
1854 | else | |
1855 |
1
1. simplifyColorspace : mutated return of Object value for com/lowagie/text/Image::simplifyColorspace to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return obj; |
1856 | } | |
1857 | ||
1858 | /** Is this image a mask? */ | |
1859 | protected boolean mask = false; | |
1860 | ||
1861 | /** The image that serves as a mask for this image. */ | |
1862 | protected Image imageMask; | |
1863 | ||
1864 | /** Holds value of property smask. */ | |
1865 | private boolean smask; | |
1866 | ||
1867 | /** | |
1868 | * Returns <CODE>true</CODE> if this <CODE>Image</CODE> is a mask. | |
1869 | * | |
1870 | * @return <CODE>true</CODE> if this <CODE>Image</CODE> is a mask | |
1871 | */ | |
1872 | public boolean isMask() { | |
1873 | return mask; | |
1874 | } | |
1875 | ||
1876 | /** | |
1877 | * Make this <CODE>Image</CODE> a mask. | |
1878 | * | |
1879 | * @throws DocumentException | |
1880 | * if this <CODE>Image</CODE> can not be a mask | |
1881 | */ | |
1882 | public void makeMask() throws DocumentException { | |
1883 |
1
1. makeMask : negated conditional → NO_COVERAGE |
if (!isMaskCandidate()) |
1884 | throw new DocumentException(MessageLocalization.getComposedMessage("this.image.can.not.be.an.image.mask")); | |
1885 | mask = true; | |
1886 | } | |
1887 | ||
1888 | /** | |
1889 | * Returns <CODE>true</CODE> if this <CODE>Image</CODE> has the | |
1890 | * requisites to be a mask. | |
1891 | * | |
1892 | * @return <CODE>true</CODE> if this <CODE>Image</CODE> can be a mask | |
1893 | */ | |
1894 | public boolean isMaskCandidate() { | |
1895 |
1
1. isMaskCandidate : negated conditional → NO_COVERAGE |
if (type == IMGRAW) { |
1896 |
2
1. isMaskCandidate : changed conditional boundary → NO_COVERAGE 2. isMaskCandidate : negated conditional → NO_COVERAGE |
if (bpc > 0xff) |
1897 |
1
1. isMaskCandidate : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return true; |
1898 | } | |
1899 |
2
1. isMaskCandidate : negated conditional → NO_COVERAGE 2. isMaskCandidate : replaced return of integer sized value with (x == 0 ? 1 : 0) → NO_COVERAGE |
return colorspace == 1; |
1900 | } | |
1901 | ||
1902 | /** | |
1903 | * Gets the explicit masking. | |
1904 | * | |
1905 | * @return the explicit masking | |
1906 | */ | |
1907 | public Image getImageMask() { | |
1908 | return imageMask; | |
1909 | } | |
1910 | ||
1911 | /** | |
1912 | * Sets the explicit masking. | |
1913 | * | |
1914 | * @param mask | |
1915 | * the mask to be applied | |
1916 | * @throws DocumentException | |
1917 | * on error | |
1918 | */ | |
1919 | public void setImageMask(Image mask) throws DocumentException { | |
1920 |
1
1. setImageMask : negated conditional → NO_COVERAGE |
if (this.mask) |
1921 | throw new DocumentException(MessageLocalization.getComposedMessage("an.image.mask.cannot.contain.another.image.mask")); | |
1922 |
1
1. setImageMask : negated conditional → NO_COVERAGE |
if (!mask.mask) |
1923 | throw new DocumentException(MessageLocalization.getComposedMessage("the.image.mask.is.not.a.mask.did.you.do.makemask")); | |
1924 | imageMask = mask; | |
1925 |
4
1. setImageMask : changed conditional boundary → NO_COVERAGE 2. setImageMask : changed conditional boundary → NO_COVERAGE 3. setImageMask : negated conditional → NO_COVERAGE 4. setImageMask : negated conditional → NO_COVERAGE |
smask = (mask.bpc > 1 && mask.bpc <= 8); |
1926 | } | |
1927 | ||
1928 | /** | |
1929 | * Getter for property smask. | |
1930 | * | |
1931 | * @return Value of property smask. | |
1932 | * | |
1933 | */ | |
1934 | public boolean isSmask() { | |
1935 | return this.smask; | |
1936 | } | |
1937 | ||
1938 | /** | |
1939 | * Setter for property smask. | |
1940 | * | |
1941 | * @param smask | |
1942 | * New value of property smask. | |
1943 | */ | |
1944 | public void setSmask(boolean smask) { | |
1945 | this.smask = smask; | |
1946 | } | |
1947 | ||
1948 | /** | |
1949 | * this is the transparency information of the raw image | |
1950 | */ | |
1951 | protected int[] transparency; | |
1952 | ||
1953 | /** | |
1954 | * Returns the transparency. | |
1955 | * | |
1956 | * @return the transparency values | |
1957 | */ | |
1958 | ||
1959 | public int[] getTransparency() { | |
1960 | return transparency; | |
1961 | } | |
1962 | ||
1963 | /** | |
1964 | * Sets the transparency values | |
1965 | * | |
1966 | * @param transparency | |
1967 | * the transparency values | |
1968 | */ | |
1969 | public void setTransparency(int[] transparency) { | |
1970 | this.transparency = transparency; | |
1971 | } | |
1972 | ||
1973 | ||
1974 | /** | |
1975 | * Returns the compression level used for images written as a compressed stream. | |
1976 | * @return the compression level (0 = best speed, 9 = best compression, -1 is default) | |
1977 | * @since 2.1.3 | |
1978 | */ | |
1979 | public int getCompressionLevel() { | |
1980 | return compressionLevel; | |
1981 | } | |
1982 | ||
1983 | /** | |
1984 | * Sets the compression level to be used if the image is written as a compressed stream. | |
1985 | * @param compressionLevel a value between 0 (best speed) and 9 (best compression) | |
1986 | * @since 2.1.3 | |
1987 | */ | |
1988 | public void setCompressionLevel(int compressionLevel) { | |
1989 |
4
1. setCompressionLevel : changed conditional boundary → NO_COVERAGE 2. setCompressionLevel : changed conditional boundary → NO_COVERAGE 3. setCompressionLevel : negated conditional → NO_COVERAGE 4. setCompressionLevel : negated conditional → NO_COVERAGE |
if (compressionLevel < PdfStream.NO_COMPRESSION || compressionLevel > PdfStream.BEST_COMPRESSION) |
1990 | this.compressionLevel = PdfStream.DEFAULT_COMPRESSION; | |
1991 | else | |
1992 | this.compressionLevel = compressionLevel; | |
1993 | } | |
1994 | } | |
Mutations | ||
263 |
1.1 |
|
266 |
1.1 2.2 3.3 |
|
268 |
1.1 |
|
270 |
1.1 2.2 |
|
272 |
1.1 |
|
274 |
1.1 2.2 3.3 4.4 |
|
276 |
1.1 |
|
278 |
1.1 2.2 3.3 4.4 |
|
280 |
1.1 |
|
282 |
1.1 2.2 3.3 4.4 |
|
285 |
1.1 |
|
287 |
1.1 2.2 |
|
289 |
1.1 |
|
291 |
1.1 2.2 |
|
293 |
1.1 |
|
295 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |
|
298 |
1.1 |
|
300 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |
|
308 |
1.1 |
|
309 |
1.1 |
|
311 |
1.1 |
|
313 |
1.1 |
|
331 |
1.1 |
|
353 |
1.1 |
|
356 |
1.1 2.2 3.3 |
|
357 |
1.1 |
|
359 |
1.1 2.2 |
|
360 |
1.1 |
|
362 |
1.1 2.2 3.3 4.4 |
|
363 |
1.1 |
|
365 |
1.1 2.2 3.3 4.4 |
|
366 |
1.1 |
|
368 |
1.1 2.2 3.3 4.4 |
|
370 |
1.1 |
|
372 |
1.1 2.2 |
|
373 |
1.1 |
|
375 |
1.1 2.2 |
|
376 |
1.1 |
|
378 |
1.1 2.2 3.3 4.4 5.5 6.6 7.7 8.8 |
|
380 |
1.1 |
|
382 |
1.1 2.2 3.3 4.4 |
|
389 |
1.1 2.2 3.3 4.4 |
|
395 |
1.1 |
|
396 |
1.1 |
|
420 |
1.1 |
|
433 |
1.1 |
|
463 |
1.1 |
|
497 |
1.1 2.2 |
|
502 |
1.1 |
|
528 |
1.1 2.2 3.3 |
|
530 |
1.1 2.2 |
|
532 |
1.1 |
|
537 |
1.1 |
|
552 |
1.1 |
|
576 |
1.1 |
|
578 |
1.1 |
|
590 |
1.1 2.2 |
|
596 |
1.1 |
|
597 |
1.1 2.2 3.3 4.4 |
|
598 |
1.1 |
|
601 |
1.1 |
|
603 |
1.1 |
|
604 |
1.1 |
|
605 |
1.1 2.2 3.3 |
|
611 |
1.1 |
|
612 |
1.1 2.2 3.3 |
|
613 |
1.1 2.2 |
|
614 |
1.1 2.2 |
|
615 |
1.1 |
|
616 |
1.1 |
|
618 |
1.1 2.2 |
|
619 |
1.1 |
|
621 |
1.1 |
|
622 |
1.1 2.2 3.3 4.4 |
|
623 |
1.1 |
|
627 |
1.1 |
|
628 |
1.1 2.2 |
|
632 |
1.1 2.2 3.3 |
|
633 |
1.1 |
|
634 |
1.1 2.2 |
|
635 |
1.1 |
|
638 |
1.1 2.2 |
|
641 |
1.1 2.2 |
|
642 |
1.1 |
|
643 |
1.1 |
|
644 |
1.1 2.2 3.3 4.4 |
|
645 |
1.1 |
|
649 |
1.1 |
|
650 |
1.1 2.2 |
|
654 |
1.1 |
|
656 |
1.1 2.2 |
|
660 |
1.1 |
|
664 |
1.1 |
|
670 |
1.1 |
|
671 |
1.1 2.2 3.3 |
|
672 |
1.1 2.2 |
|
673 |
1.1 2.2 |
|
674 |
1.1 |
|
675 |
1.1 |
|
676 |
1.1 |
|
678 |
1.1 2.2 3.3 |
|
679 |
1.1 2.2 3.3 |
|
680 |
1.1 2.2 |
|
685 |
1.1 |
|
687 |
1.1 2.2 3.3 |
|
688 |
1.1 2.2 |
|
690 |
1.1 |
|
691 |
1.1 2.2 |
|
693 |
1.1 |
|
694 |
1.1 |
|
695 |
1.1 |
|
697 |
1.1 2.2 |
|
698 |
1.1 2.2 |
|
699 |
1.1 |
|
701 |
1.1 2.2 |
|
705 |
1.1 2.2 3.3 |
|
706 |
1.1 2.2 3.3 |
|
707 |
1.1 2.2 |
|
709 |
1.1 |
|
715 |
1.1 |
|
718 |
1.1 |
|
719 |
1.1 |
|
724 |
1.1 |
|
744 |
1.1 |
|
763 |
1.1 |
|
789 |
1.1 2.2 |
|
797 |
1.1 |
|
798 |
1.1 |
|
838 |
1.1 2.2 |
|
843 |
1.1 2.2 |
|
845 |
1.1 |
|
852 |
1.1 |
|
918 |
1.1 |
|
919 |
1.1 |
|
924 |
1.1 |
|
960 |
1.1 2.2 |
|
971 |
1.1 2.2 |
|
982 |
1.1 2.2 |
|
1041 |
1.1 |
|
1114 |
1.1 2.2 |
|
1133 |
1.1 2.2 |
|
1195 |
1.1 |
|
1196 |
1.1 |
|
1197 |
1.1 |
|
1209 |
1.1 |
|
1210 |
1.1 |
|
1211 |
1.1 |
|
1223 |
1.1 |
|
1224 |
1.1 |
|
1225 |
1.1 |
|
1247 |
1.1 2.2 |
|
1248 |
1.1 2.2 |
|
1250 |
1.1 |
|
1251 |
1.1 |
|
1252 |
1.1 |
|
1264 |
1.1 |
|
1265 |
1.1 2.2 |
|
1266 |
1.1 2.2 |
|
1267 |
1.1 2.2 3.3 |
|
1268 |
1.1 |
|
1280 |
1.1 |
|
1281 |
1.1 |
|
1282 |
1.1 2.2 |
|
1283 |
1.1 |
|
1284 |
1.1 2.2 |
|
1288 |
1.1 |
|
1289 |
1.1 2.2 |
|
1290 |
1.1 |
|
1294 |
1.1 2.2 |
|
1296 |
1.1 |
|
1302 |
1.1 |
|
1305 |
1.1 |
|
1315 |
1.1 |
|
1316 |
1.1 |
|
1342 |
1.1 2.2 |
|
1343 |
1.1 2.2 |
|
1344 |
1.1 |
|
1346 |
1.1 |
|
1357 |
1.1 2.2 |
|
1358 |
1.1 2.2 |
|
1359 |
1.1 |
|
1362 |
1.1 |
|
1363 |
1.1 |
|
1374 |
1.1 2.2 3.3 |
|
1391 |
1.1 |
|
1393 |
1.1 |
|
1781 |
1.1 2.2 |
|
1819 |
1.1 |
|
1822 |
1.1 |
|
1826 |
1.1 |
|
1831 |
1.1 |
|
1832 |
1.1 2.2 |
|
1834 |
1.1 |
|
1840 |
1.1 |
|
1847 |
1.1 |
|
1848 |
1.1 |
|
1850 |
1.1 |
|
1851 |
1.1 |
|
1852 |
1.1 |
|
1853 |
1.1 |
|
1855 |
1.1 |
|
1883 |
1.1 |
|
1895 |
1.1 |
|
1896 |
1.1 2.2 |
|
1897 |
1.1 |
|
1899 |
1.1 2.2 |
|
1920 |
1.1 |
|
1922 |
1.1 |
|
1925 |
1.1 2.2 3.3 4.4 |
|
1989 |
1.1 2.2 3.3 4.4 |