Skip to content

Commit 67686b4

Browse files
committed
Rename ImageFactory to ImageDataFactory
1 parent b97211c commit 67686b4

File tree

21 files changed

+136
-136
lines changed

21 files changed

+136
-136
lines changed

forms/src/main/java/com/itextpdf/forms/fields/PdfFormField.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ This file is part of the iText (R) project.
4444
*/
4545
package com.itextpdf.forms.fields;
4646

47+
import com.itextpdf.io.image.ImageDataFactory;
4748
import com.itextpdf.kernel.PdfException;
4849
import com.itextpdf.kernel.color.Color;
4950
import com.itextpdf.kernel.color.DeviceCmyk;
@@ -74,7 +75,6 @@ This file is part of the iText (R) project.
7475
import com.itextpdf.io.font.FontConstants;
7576
import com.itextpdf.io.font.PdfEncodings;
7677
import com.itextpdf.io.image.ImageData;
77-
import com.itextpdf.io.image.ImageFactory;
7878
import com.itextpdf.io.source.PdfTokenizer;
7979
import com.itextpdf.io.source.RandomAccessFileOrArray;
8080
import com.itextpdf.io.source.RandomAccessSourceFactory;
@@ -914,7 +914,7 @@ public PdfFormField setValue(String value, boolean generateAppearance) {
914914
} else if (PdfName.Btn.equals(formType)) {
915915
if ((getFieldFlags() & PdfButtonFormField.FF_PUSH_BUTTON) != 0) {
916916
try {
917-
img = ImageFactory.getImage(Base64.decode(value));
917+
img = ImageDataFactory.create(Base64.decode(value));
918918
} catch (Exception e) {
919919
text = value;
920920
}

io/src/main/java/com/itextpdf/io/image/AwtImageFactory.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public static ImageData getImage(java.awt.Image image, java.awt.Color color, boo
144144
wMarker = 0;
145145
}
146146
}
147-
return ImageFactory.getImage(w, h, 1, 1, pixelsByte, transparency);
147+
return ImageDataFactory.create(w, h, 1, 1, pixelsByte, transparency);
148148
} else {
149149
byte[] pixelsByte = new byte[w * h * 3];
150150
byte[] smask = null;
@@ -204,9 +204,9 @@ public static ImageData getImage(java.awt.Image image, java.awt.Color color, boo
204204
else
205205
smask = null;
206206
}
207-
ImageData img = ImageFactory.getImage(w, h, 3, 8, pixelsByte, transparency);
207+
ImageData img = ImageDataFactory.create(w, h, 3, 8, pixelsByte, transparency);
208208
if (smask != null) {
209-
ImageData sm = ImageFactory.getImage(w, h, 1, 8, smask, null);
209+
ImageData sm = ImageDataFactory.create(w, h, 1, 8, smask, null);
210210
sm.makeMask();
211211
img.setImageMask(sm);
212212
}

io/src/main/java/com/itextpdf/io/image/ImageFactory.java renamed to io/src/main/java/com/itextpdf/io/image/ImageDataFactory.java

Lines changed: 44 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ This file is part of the iText (R) project.
5757
import java.util.Arrays;
5858
import java.util.List;
5959

60-
public final class ImageFactory {
60+
public final class ImageDataFactory {
6161

6262
private static final byte[] gif = new byte[]{'G', 'I', 'F'};
6363
private static final byte[] jpeg = new byte[]{(byte) 0xFF, (byte) 0xD8};
@@ -70,33 +70,33 @@ public final class ImageFactory {
7070
private static final byte[] tiff_2 = new byte[]{'I', 'I', 42, 0};
7171
private static final byte[] jbig2 = new byte[]{(byte) 0x97, 'J', 'B', '2', '\r', '\n', 0x1a, '\n'};
7272

73-
public static ImageData getImage(byte[] bytes, boolean recoverImage) {
74-
return getImageInstance(bytes, recoverImage);
73+
public static ImageData create(byte[] bytes, boolean recoverImage) {
74+
return createImageInstance(bytes, recoverImage);
7575
}
7676

77-
public static ImageData getImage(byte[] bytes) {
78-
return getImage(bytes, false);
77+
public static ImageData create(byte[] bytes) {
78+
return create(bytes, false);
7979
}
8080

81-
public static ImageData getImage(URL url, boolean recoverImage) {
82-
return getImageInstance(url, recoverImage);
81+
public static ImageData create(URL url, boolean recoverImage) {
82+
return createImageInstance(url, recoverImage);
8383
}
8484

85-
public static ImageData getImage(URL url) {
86-
return getImage(url, false);
85+
public static ImageData create(URL url) {
86+
return create(url, false);
8787
}
8888

89-
public static ImageData getImage(String filename, boolean recoverImage) throws MalformedURLException {
90-
return getImage(UrlUtil.toURL(filename), recoverImage);
89+
public static ImageData create(String filename, boolean recoverImage) throws MalformedURLException {
90+
return create(UrlUtil.toURL(filename), recoverImage);
9191
}
9292

93-
public static ImageData getImage(String filename) throws MalformedURLException {
94-
return getImage(filename, false);
93+
public static ImageData create(String filename) throws MalformedURLException {
94+
return create(filename, false);
9595
}
9696

97-
public static ImageData getImage(int width, int height, boolean reverseBits,
98-
int typeCCITT, int parameters, byte[] data,
99-
int[] transparency) {
97+
public static ImageData create(int width, int height, boolean reverseBits,
98+
int typeCCITT, int parameters, byte[] data,
99+
int[] transparency) {
100100
if (transparency != null && transparency.length != 2)
101101
throw new IOException(IOException.TransparencyLengthMustBeEqualTo2WithCcittImages);
102102
if (typeCCITT != RawImageData.CCITTG4 && typeCCITT != RawImageData.CCITTG3_1D && typeCCITT != RawImageData.CCITTG3_2D)
@@ -112,13 +112,13 @@ public static ImageData getImage(int width, int height, boolean reverseBits,
112112
return image;
113113
}
114114

115-
public static ImageData getImage(int width, int height, int components,
116-
int bpc, byte[] data, int[] transparency) {
115+
public static ImageData create(int width, int height, int components,
116+
int bpc, byte[] data, int[] transparency) {
117117
if (transparency != null && transparency.length != components * 2)
118118
throw new IOException(IOException.TransparencyLengthMustBeEqualTo2WithCcittImages);
119119
if (components == 1 && bpc == 1) {
120120
byte[] g4 = CCITTG4Encoder.compress(data, width, height);
121-
return ImageFactory.getImage(width, height, false, RawImageData.CCITTG4, RawImageData.CCITT_BLACKIS1, g4, transparency);
121+
return ImageDataFactory.create(width, height, false, RawImageData.CCITTG4, RawImageData.CCITT_BLACKIS1, g4, transparency);
122122
}
123123
RawImageData image = new RawImageData(data, ImageType.RAW);
124124
image.height = height;
@@ -141,8 +141,8 @@ public static ImageData getImage(int width, int height, int components,
141141
* @param color if different from <CODE>null</CODE> the transparency pixels are replaced by this color
142142
* @return RawImage
143143
*/
144-
public static ImageData getImage(java.awt.Image image, java.awt.Color color) throws java.io.IOException {
145-
return ImageFactory.getImage(image, color, false);
144+
public static ImageData create(java.awt.Image image, java.awt.Color color) throws java.io.IOException {
145+
return ImageDataFactory.create(image, color, false);
146146
}
147147

148148
/**
@@ -153,11 +153,11 @@ public static ImageData getImage(java.awt.Image image, java.awt.Color color) thr
153153
* @param forceBW if <CODE>true</CODE> the image is treated as black and white
154154
* @return RawImage
155155
*/
156-
public static ImageData getImage(java.awt.Image image, java.awt.Color color, boolean forceBW) throws java.io.IOException {
156+
public static ImageData create(java.awt.Image image, java.awt.Color color, boolean forceBW) throws java.io.IOException {
157157
return AwtImageFactory.getImage(image, color, forceBW);
158158
}
159159

160-
public static ImageData getBmpImage(URL url, boolean noHeader, int size) {
160+
public static ImageData createBmp(URL url, boolean noHeader, int size) {
161161
byte[] imageType = readImageType(url);
162162
if (imageTypeIs(imageType, bmp)) {
163163
ImageData image = new BmpImageData(url, noHeader, size);
@@ -167,7 +167,7 @@ public static ImageData getBmpImage(URL url, boolean noHeader, int size) {
167167
throw new IllegalArgumentException("BMP image expected.");
168168
}
169169

170-
public static ImageData getBmpImage(byte[] bytes, boolean noHeader, int size) {
170+
public static ImageData createBmp(byte[] bytes, boolean noHeader, int size) {
171171
byte[] imageType = readImageType(bytes);
172172
if (noHeader || imageTypeIs(imageType, bmp)) {
173173
ImageData image = new BmpImageData(bytes, noHeader, size);
@@ -183,7 +183,7 @@ public static ImageData getBmpImage(byte[] bytes, boolean noHeader, int size) {
183183
* @param bytes
184184
* @return
185185
*/
186-
public static GifImageData getGifImage(byte[] bytes) {
186+
public static GifImageData createGif(byte[] bytes) {
187187
byte[] imageType = readImageType(bytes);
188188
if (imageTypeIs(imageType, gif)) {
189189
GifImageData image = new GifImageData(bytes);
@@ -200,7 +200,7 @@ public static GifImageData getGifImage(byte[] bytes) {
200200
* @param frame number of frame to be returned
201201
* @return
202202
*/
203-
public static ImageData getGifFrame(URL url, int frame) {
203+
public static ImageData createGifFrame(URL url, int frame) {
204204
byte[] imageType = readImageType(url);
205205
if (imageTypeIs(imageType, gif)) {
206206
GifImageData image = new GifImageData(url);
@@ -217,7 +217,7 @@ public static ImageData getGifFrame(URL url, int frame) {
217217
* @param frame number of frame to be returned
218218
* @return
219219
*/
220-
public static ImageData getGifFrame(byte[] bytes, int frame) {
220+
public static ImageData createGifFrame(byte[] bytes, int frame) {
221221
byte[] imageType = readImageType(bytes);
222222
if (imageTypeIs(imageType, gif)) {
223223
GifImageData image = new GifImageData(bytes);
@@ -234,7 +234,7 @@ public static ImageData getGifFrame(byte[] bytes, int frame) {
234234
* @param frameNumbers array of frame numbers of gif image
235235
* @return
236236
*/
237-
public static List<ImageData> getGifFrames(byte[] bytes, int[] frameNumbers) {
237+
public static List<ImageData> createGifFrames(byte[] bytes, int[] frameNumbers) {
238238
byte[] imageType = readImageType(bytes);
239239
if (imageTypeIs(imageType, gif)) {
240240
GifImageData image = new GifImageData(bytes);
@@ -256,7 +256,7 @@ public static List<ImageData> getGifFrames(byte[] bytes, int[] frameNumbers) {
256256
* @param frameNumbers array of frame numbers of gif image
257257
* @return
258258
*/
259-
public static List<ImageData> getGifFrames(URL url, int[] frameNumbers) {
259+
public static List<ImageData> createGifFrames(URL url, int[] frameNumbers) {
260260
byte[] imageType = readImageType(url);
261261
if (imageTypeIs(imageType, gif)) {
262262
GifImageData image = new GifImageData(url);
@@ -277,7 +277,7 @@ public static List<ImageData> getGifFrames(URL url, int[] frameNumbers) {
277277
* @param bytes byte array of gif image
278278
* @return all frames of gif image
279279
*/
280-
public static List<ImageData> getGifFrames(byte[] bytes) {
280+
public static List<ImageData> createGifFrames(byte[] bytes) {
281281
byte[] imageType = readImageType(bytes);
282282
if (imageTypeIs(imageType, gif)) {
283283
GifImageData image = new GifImageData(bytes);
@@ -293,7 +293,7 @@ public static List<ImageData> getGifFrames(byte[] bytes) {
293293
* @param url url of gif image
294294
* @return all frames of gif image
295295
*/
296-
public static List<ImageData> getGifFrames(URL url) {
296+
public static List<ImageData> createGifFrames(URL url) {
297297
byte[] imageType = readImageType(url);
298298
if (imageTypeIs(imageType, gif)) {
299299
GifImageData image = new GifImageData(url);
@@ -303,7 +303,7 @@ public static List<ImageData> getGifFrames(URL url) {
303303
throw new IllegalArgumentException("GIF image expected.");
304304
}
305305

306-
public static ImageData getJbig2Image(URL url, int page) {
306+
public static ImageData createJbig2(URL url, int page) {
307307
if (page < 1)
308308
throw new IllegalArgumentException("The page number must be greater than 0");
309309
byte[] imageType = readImageType(url);
@@ -315,7 +315,7 @@ public static ImageData getJbig2Image(URL url, int page) {
315315
throw new IllegalArgumentException("JBIG2 image expected.");
316316
}
317317

318-
public static ImageData getJbig2Image(byte[] bytes, int page) {
318+
public static ImageData createJbig2(byte[] bytes, int page) {
319319
if (page < 1)
320320
throw new IllegalArgumentException("The page number must be greater than 0");
321321
byte[] imageType = readImageType(bytes);
@@ -328,7 +328,7 @@ public static ImageData getJbig2Image(byte[] bytes, int page) {
328328

329329
}
330330

331-
public static ImageData getJpegImage(URL url) {
331+
public static ImageData createJpeg(URL url) {
332332
byte[] imageType = readImageType(url);
333333
if (imageTypeIs(imageType, jpeg)) {
334334
ImageData image = new JpegImageData(url);
@@ -338,7 +338,7 @@ public static ImageData getJpegImage(URL url) {
338338
throw new IllegalArgumentException("JPEG image expected.");
339339
}
340340

341-
public static ImageData getJpegImage(byte[] bytes) {
341+
public static ImageData createJpeg(byte[] bytes) {
342342
byte[] imageType = readImageType(bytes);
343343
if (imageTypeIs(imageType, jpeg)) {
344344
ImageData image = new JpegImageData(bytes);
@@ -349,7 +349,7 @@ public static ImageData getJpegImage(byte[] bytes) {
349349

350350
}
351351

352-
public static ImageData getJpeg2000Image(URL url) {
352+
public static ImageData createJpeg2000(URL url) {
353353
byte[] imageType = readImageType(url);
354354
if (imageTypeIs(imageType, jpeg2000_1) || imageTypeIs(imageType, jpeg2000_2)) {
355355
ImageData image = new Jpeg2000ImageData(url);
@@ -359,7 +359,7 @@ public static ImageData getJpeg2000Image(URL url) {
359359
throw new IllegalArgumentException("JPEG2000 image expected.");
360360
}
361361

362-
public static ImageData getJpeg2000Image(byte[] bytes) {
362+
public static ImageData createJpeg2000(byte[] bytes) {
363363
byte[] imageType = readImageType(bytes);
364364
if (imageTypeIs(imageType, jpeg2000_1) || imageTypeIs(imageType, jpeg2000_2)) {
365365
ImageData image = new Jpeg2000ImageData(bytes);
@@ -370,7 +370,7 @@ public static ImageData getJpeg2000Image(byte[] bytes) {
370370

371371
}
372372

373-
public static ImageData getPngImage(URL url) {
373+
public static ImageData createPng(URL url) {
374374
byte[] imageType = readImageType(url);
375375
if (imageTypeIs(imageType, png)) {
376376
ImageData image = new PngImageData(url);
@@ -380,7 +380,7 @@ public static ImageData getPngImage(URL url) {
380380
throw new IllegalArgumentException("PNG image expected.");
381381
}
382382

383-
public static ImageData getPngImage(byte[] bytes) {
383+
public static ImageData createPng(byte[] bytes) {
384384
byte[] imageType = readImageType(bytes);
385385
if (imageTypeIs(imageType, png)) {
386386
ImageData image = new PngImageData(bytes);
@@ -390,7 +390,7 @@ public static ImageData getPngImage(byte[] bytes) {
390390
throw new IllegalArgumentException("PNG image expected.");
391391
}
392392

393-
public static ImageData getTiffImage(URL url, boolean recoverFromImageError, int page, boolean direct) {
393+
public static ImageData createTiff(URL url, boolean recoverFromImageError, int page, boolean direct) {
394394
byte[] imageType = readImageType(url);
395395
if (imageTypeIs(imageType, tiff_1) || imageTypeIs(imageType, tiff_2)) {
396396
ImageData image = new TiffImageData(url, recoverFromImageError, page, direct);
@@ -400,7 +400,7 @@ public static ImageData getTiffImage(URL url, boolean recoverFromImageError, int
400400
throw new IllegalArgumentException("TIFF image expected.");
401401
}
402402

403-
public static ImageData getTiffImage(byte[] bytes, boolean recoverFromImageError, int page, boolean direct) {
403+
public static ImageData createTiff(byte[] bytes, boolean recoverFromImageError, int page, boolean direct) {
404404
byte[] imageType = readImageType(bytes);
405405
if (imageTypeIs(imageType, tiff_1) || imageTypeIs(imageType, tiff_2)) {
406406
ImageData image = new TiffImageData(bytes, recoverFromImageError, page, direct);
@@ -410,11 +410,11 @@ public static ImageData getTiffImage(byte[] bytes, boolean recoverFromImageError
410410
throw new IllegalArgumentException("TIFF image expected.");
411411
}
412412

413-
public static ImageData getRawImage(byte[] bytes) {
413+
public static ImageData createRawImage(byte[] bytes) {
414414
return new RawImageData(bytes, ImageType.RAW);
415415
}
416416

417-
private static ImageData getImageInstance(URL source, boolean recoverImage) {
417+
private static ImageData createImageInstance(URL source, boolean recoverImage) {
418418
byte[] imageType = readImageType(source);
419419
if (imageTypeIs(imageType, gif)) {
420420
GifImageData image = new GifImageData(source);
@@ -448,7 +448,7 @@ private static ImageData getImageInstance(URL source, boolean recoverImage) {
448448
throw new IOException(IOException.ImageFormatCannotBeRecognized);
449449
}
450450

451-
private static ImageData getImageInstance(byte[] bytes, boolean recoverImage) {
451+
private static ImageData createImageInstance(byte[] bytes, boolean recoverImage) {
452452
byte[] imageType = readImageType(bytes);
453453
if (imageTypeIs(imageType, gif)) {
454454
GifImageData image = new GifImageData(bytes);

io/src/main/java/com/itextpdf/io/image/PngImageHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,13 +262,13 @@ private static void processPng(InputStream pngStream, PngParameters png) throws
262262
if (png.iccProfile != null)
263263
png.image.setProfile(png.iccProfile);
264264
if (png.palShades) {
265-
RawImageData im2 = (RawImageData) ImageFactory.getRawImage(null);
265+
RawImageData im2 = (RawImageData) ImageDataFactory.createRawImage(null);
266266
RawImageHelper.updateRawImageParameters(im2, png.width, png.height, 1, 8, png.smask);
267267
im2.makeMask();
268268
png.image.setImageMask(im2);
269269
}
270270
if (png.genBWMask) {
271-
RawImageData im2 = (RawImageData) ImageFactory.getRawImage(null);
271+
RawImageData im2 = (RawImageData) ImageDataFactory.createRawImage(null);
272272
RawImageHelper.updateRawImageParameters(im2, png.width, png.height, 1, 1, png.smask);
273273
im2.makeMask();
274274
png.image.setImageMask(im2);

io/src/main/java/com/itextpdf/io/image/TiffImageHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ else if (rot == TIFFConstants.ORIENTATION_RIGHTTOP || rot == TIFFConstants.ORIEN
563563
tiff.image.setRotation(rotation);
564564
if (extraSamples > 0) {
565565
mzip.close();
566-
RawImageData mimg = (RawImageData)ImageFactory.getRawImage(null);
566+
RawImageData mimg = (RawImageData) ImageDataFactory.createRawImage(null);
567567
RawImageHelper.updateRawImageParameters(mimg, w, h, 1, bitsPerSample, mstream.toByteArray());
568568
mimg.makeMask();
569569
mimg.setDeflated(true);

io/src/test/java/com/itextpdf/io/image/BmpTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,23 @@ public class BmpTest {
1414

1515
@Test
1616
public void openBmp1() throws IOException {
17-
ImageData img = ImageFactory.getImage(sourceFolder + "WP_20140410_001.bmp");
17+
ImageData img = ImageDataFactory.create(sourceFolder + "WP_20140410_001.bmp");
1818
Assert.assertEquals(2592, img.getWidth(), 0);
1919
Assert.assertEquals(1456, img.getHeight(), 0);
2020
Assert.assertEquals(8, img.getBpc());
2121
}
2222

2323
@Test
2424
public void openBmp2() throws IOException {
25-
ImageData img = ImageFactory.getImage(sourceFolder + "WP_20140410_001_gray.bmp");
25+
ImageData img = ImageDataFactory.create(sourceFolder + "WP_20140410_001_gray.bmp");
2626
Assert.assertEquals(2592, img.getWidth(), 0);
2727
Assert.assertEquals(1456, img.getHeight(), 0);
2828
Assert.assertEquals(8, img.getBpc());
2929
}
3030

3131
@Test
3232
public void openBmp3() throws IOException {
33-
ImageData img = ImageFactory.getImage(sourceFolder + "WP_20140410_001_monochrome.bmp");
33+
ImageData img = ImageDataFactory.create(sourceFolder + "WP_20140410_001_monochrome.bmp");
3434
Assert.assertEquals(2592, img.getWidth(), 0);
3535
Assert.assertEquals(1456, img.getHeight(), 0);
3636
Assert.assertEquals(1, img.getBpc());

0 commit comments

Comments
 (0)