1 | /* | |
2 | * | |
3 | * Copyright 2018 Andreas Rosdal | |
4 | * | |
5 | * The contents of this file are subject to the Mozilla Public License Version 1.1 | |
6 | * (the "License"); you may not use this file except in compliance with the License. | |
7 | * You may obtain a copy of the License at http://www.mozilla.org/MPL/ | |
8 | * | |
9 | * Software distributed under the License is distributed on an "AS IS" basis, | |
10 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License | |
11 | * for the specific language governing rights and limitations under the License. | |
12 | * | |
13 | * The Original Code is 'iText, a free JAVA-PDF library'. | |
14 | * | |
15 | * The Initial Developer of the Original Code is Bruno Lowagie. Portions created by | |
16 | * the Initial Developer are Copyright (C) 1999, 2000, 2001, 2002 by Bruno Lowagie. | |
17 | * All Rights Reserved. | |
18 | * Co-Developer of the code is Paulo Soares. Portions created by the Co-Developer | |
19 | * are Copyright (C) 2000, 2001, 2002 by Paulo Soares. All Rights Reserved. | |
20 | * | |
21 | * Contributor(s): all the names of the contributors are added in the source code | |
22 | * where applicable. | |
23 | * | |
24 | * Alternatively, the contents of this file may be used under the terms of the | |
25 | * LGPL license (the "GNU LIBRARY GENERAL PUBLIC LICENSE"), in which case the | |
26 | * provisions of LGPL are applicable instead of those above. If you wish to | |
27 | * allow use of your version of this file only under the terms of the LGPL | |
28 | * License and not to allow others to use your version of this file under | |
29 | * the MPL, indicate your decision by deleting the provisions above and | |
30 | * replace them with the notice and other provisions required by the LGPL. | |
31 | * If you do not delete the provisions above, a recipient may use your version | |
32 | * of this file under either the MPL or the GNU LIBRARY GENERAL PUBLIC LICENSE. | |
33 | * | |
34 | * This library is free software; you can redistribute it and/or modify it | |
35 | * under the terms of the MPL as stated above or under the terms of the GNU | |
36 | * Library General Public License as published by the Free Software Foundation; | |
37 | * either version 2 of the License, or any later version. | |
38 | * | |
39 | * This library is distributed in the hope that it will be useful, but WITHOUT | |
40 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
41 | * FOR A PARTICULAR PURPOSE. See the GNU Library general Public License for more | |
42 | * details. | |
43 | * | |
44 | */ | |
45 | ||
46 | package com.lowagie.text; | |
47 | ||
48 | import javax.imageio.ImageIO; | |
49 | import java.awt.image.BufferedImage; | |
50 | import java.io.ByteArrayInputStream; | |
51 | import java.io.InputStream; | |
52 | import java.net.URL; | |
53 | ||
54 | /** | |
55 | * Loads image files such as PNG, JPEG, GIF, TIFF and BMP. | |
56 | * | |
57 | * TODO: The goal of this class is to use Java ImageIO to parse images and metadata, | |
58 | * and embed the image in the PDF in the best way (the compressed image format, not the raw pixels). | |
59 | * | |
60 | * | |
61 | * We don't want to maintain our own image codecs. | |
62 | * | |
63 | * @author Andreas Rosdal | |
64 | */ | |
65 | public class ImageLoader { | |
66 | ||
67 | /** | |
68 | * Creates an Image from a PNG image file in an URL. | |
69 | * | |
70 | * | |
71 | * @param url | |
72 | * @return | |
73 | */ | |
74 | public static Image getPngImage(URL url) { | |
75 | try { | |
76 | InputStream is = url.openStream(); | |
77 | BufferedImage bufferedImage = ImageIO.read(is); | |
78 |
1
1. getPngImage : removed call to java/io/InputStream::close → NO_COVERAGE |
is.close(); |
79 |
1
1. getPngImage : mutated return of Object value for com/lowagie/text/ImageLoader::getPngImage to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return Image.getInstance(bufferedImage, null, false); |
80 | ||
81 | } catch (Exception e) { | |
82 | throw new ExceptionConverter(e); | |
83 | } | |
84 | } | |
85 | ||
86 | public static Image getGifImage(URL url) { | |
87 | try { | |
88 | InputStream is = url.openStream(); | |
89 | BufferedImage bufferedImage = ImageIO.read(is); | |
90 |
1
1. getGifImage : removed call to java/io/InputStream::close → NO_COVERAGE |
is.close(); |
91 |
1
1. getGifImage : mutated return of Object value for com/lowagie/text/ImageLoader::getGifImage to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return Image.getInstance(bufferedImage, null, false); |
92 | ||
93 | } catch (Exception e) { | |
94 | throw new ExceptionConverter(e); | |
95 | } | |
96 | } | |
97 | ||
98 | public static Image getTiffImage(URL url) { | |
99 | try { | |
100 | InputStream is = url.openStream(); | |
101 | BufferedImage bufferedImage = ImageIO.read(is); | |
102 |
1
1. getTiffImage : removed call to java/io/InputStream::close → NO_COVERAGE |
is.close(); |
103 |
1
1. getTiffImage : mutated return of Object value for com/lowagie/text/ImageLoader::getTiffImage to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return Image.getInstance(bufferedImage, null, false); |
104 | ||
105 | } catch (Exception e) { | |
106 | throw new ExceptionConverter(e); | |
107 | } | |
108 | } | |
109 | ||
110 | ||
111 | public static Image getBmpImage(URL url) { | |
112 | try { | |
113 | InputStream is = url.openStream(); | |
114 | BufferedImage bufferedImage = ImageIO.read(is); | |
115 |
1
1. getBmpImage : removed call to java/io/InputStream::close → NO_COVERAGE |
is.close(); |
116 |
1
1. getBmpImage : mutated return of Object value for com/lowagie/text/ImageLoader::getBmpImage to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return Image.getInstance(bufferedImage, null, false); |
117 | ||
118 | } catch (Exception e) { | |
119 | throw new ExceptionConverter(e); | |
120 | } | |
121 | } | |
122 | ||
123 | /** | |
124 | * Creates an Image from a JPEG image file in an URL. | |
125 | * | |
126 | * @param url | |
127 | * @return | |
128 | */ | |
129 | public static Image getJpegImage(URL url) { | |
130 | try { | |
131 | InputStream is = url.openStream(); | |
132 | byte[] imageBytes = Utilities.toByteArray(is); | |
133 |
1
1. getJpegImage : removed call to java/io/InputStream::close → NO_COVERAGE |
is.close(); |
134 |
1
1. getJpegImage : mutated return of Object value for com/lowagie/text/ImageLoader::getJpegImage to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new Jpeg(imageBytes); |
135 | ||
136 | } catch (Exception e) { | |
137 | throw new ExceptionConverter(e); | |
138 | } | |
139 | } | |
140 | ||
141 | public static Image getJpeg2000Image(URL url) { | |
142 | try { | |
143 | InputStream is = url.openStream(); | |
144 | byte[] imageBytes = Utilities.toByteArray(is); | |
145 |
1
1. getJpeg2000Image : removed call to java/io/InputStream::close → NO_COVERAGE |
is.close(); |
146 |
1
1. getJpeg2000Image : mutated return of Object value for com/lowagie/text/ImageLoader::getJpeg2000Image to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new Jpeg2000(imageBytes); |
147 | ||
148 | } catch (Exception e) { | |
149 | throw new ExceptionConverter(e); | |
150 | } | |
151 | } | |
152 | ||
153 | public static Image getGifImage(byte[] imageData) { | |
154 | try { | |
155 | BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream(imageData)); | |
156 |
1
1. getGifImage : mutated return of Object value for com/lowagie/text/ImageLoader::getGifImage to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return Image.getInstance(bufferedImage, null, false); |
157 | ||
158 | } catch (Exception e) { | |
159 | throw new ExceptionConverter(e); | |
160 | } | |
161 | } | |
162 | ||
163 | public static Image getPngImage(byte[] imageData) { | |
164 | try { | |
165 | BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream(imageData)); | |
166 |
1
1. getPngImage : mutated return of Object value for com/lowagie/text/ImageLoader::getPngImage to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return Image.getInstance(bufferedImage, null, false); |
167 | ||
168 | } catch (Exception e) { | |
169 | throw new ExceptionConverter(e); | |
170 | } | |
171 | } | |
172 | ||
173 | public static Image getBmpImage(byte[] imageData) { | |
174 | try { | |
175 | BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream(imageData)); | |
176 |
1
1. getBmpImage : mutated return of Object value for com/lowagie/text/ImageLoader::getBmpImage to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return Image.getInstance(bufferedImage, null, false); |
177 | ||
178 | } catch (Exception e) { | |
179 | throw new ExceptionConverter(e); | |
180 | } | |
181 | } | |
182 | ||
183 | public static Image getTiffImage(byte[] imageData) { | |
184 | try { | |
185 | BufferedImage bufferedImage = ImageIO.read(new ByteArrayInputStream(imageData)); | |
186 |
1
1. getTiffImage : mutated return of Object value for com/lowagie/text/ImageLoader::getTiffImage to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return Image.getInstance(bufferedImage, null, false); |
187 | ||
188 | } catch (Exception e) { | |
189 | throw new ExceptionConverter(e); | |
190 | } | |
191 | } | |
192 | ||
193 | /** | |
194 | * Creates an Image from a JPEG image file in a byte array. | |
195 | * | |
196 | * | |
197 | * @param imageData | |
198 | * @return | |
199 | */ | |
200 | public static Image getJpegImage(byte[] imageData) { | |
201 | try { | |
202 |
1
1. getJpegImage : mutated return of Object value for com/lowagie/text/ImageLoader::getJpegImage to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new Jpeg(imageData); |
203 | ||
204 | } catch (Exception e) { | |
205 | throw new ExceptionConverter(e); | |
206 | } | |
207 | } | |
208 | ||
209 | public static Image getJpeg2000Image(byte[] imageData) { | |
210 | try { | |
211 |
1
1. getJpeg2000Image : mutated return of Object value for com/lowagie/text/ImageLoader::getJpeg2000Image to ( if (x != null) null else throw new RuntimeException ) → NO_COVERAGE |
return new Jpeg2000(imageData); |
212 | ||
213 | } catch (Exception e) { | |
214 | throw new ExceptionConverter(e); | |
215 | } | |
216 | } | |
217 | ||
218 | } | |
Mutations | ||
78 |
1.1 |
|
79 |
1.1 |
|
90 |
1.1 |
|
91 |
1.1 |
|
102 |
1.1 |
|
103 |
1.1 |
|
115 |
1.1 |
|
116 |
1.1 |
|
133 |
1.1 |
|
134 |
1.1 |
|
145 |
1.1 |
|
146 |
1.1 |
|
156 |
1.1 |
|
166 |
1.1 |
|
176 |
1.1 |
|
186 |
1.1 |
|
202 |
1.1 |
|
211 |
1.1 |