1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.imaging.formats.tiff;
18
19 import static org.junit.jupiter.api.Assertions.assertNotNull;
20 import static org.junit.jupiter.api.Assertions.assertTrue;
21
22 import java.awt.image.BufferedImage;
23 import java.io.File;
24 import java.io.IOException;
25
26 import org.apache.commons.imaging.Imaging;
27 import org.apache.commons.imaging.ImagingTestConstants;
28 import org.junit.jupiter.api.Test;
29
30
31
32
33 public class TiffBigTiffTest extends TiffBaseTest {
34
35 private boolean doImagesMatch(final int w, final int h, final int[] classicRgb, final BufferedImage image) {
36 final int iW = image.getWidth();
37 final int iH = image.getHeight();
38 if (iW != w || iH != h) {
39 return false;
40 }
41 final int[] argb = new int[w * h];
42 image.getRGB(0, 0, w, h, argb, 0, w);
43 for (int i = 0; i < argb.length; i++) {
44 if ((argb[i] & 0x00ffffff) != (classicRgb[i] & 0x00ffffff)) {
45 return false;
46 }
47 }
48 return true;
49 }
50
51 @Test
52 public void test() throws IOException {
53 final File tiffFolder = new File(ImagingTestConstants.TEST_IMAGE_FOLDER, "tiff");
54 final File bigTiffFolder = new File(tiffFolder, "13");
55
56 final File classicFile = new File(bigTiffFolder, "Classic.tif");
57 final BufferedImage classicImage = Imaging.getBufferedImage(classicFile);
58 assertNotNull(classicImage);
59 final int w = classicImage.getWidth();
60 final int h = classicImage.getHeight();
61 final int[] classicRgb = new int[w * h];
62 classicImage.getRGB(0, 0, w, h, classicRgb, 0, w);
63
64 int nTest = 0;
65 final File[] files = bigTiffFolder.listFiles();
66 for (final File f : files) {
67 final String name = f.getName();
68 if (!name.toLowerCase().startsWith("bigtiff")) {
69 continue;
70 }
71 final BufferedImage image = Imaging.getBufferedImage(f);
72 assertNotNull(image);
73 final boolean status = doImagesMatch(w, h, classicRgb, image);
74 assertTrue(status, "BigTIFF content does not match test image for " + name);
75 nTest++;
76 }
77
78 assertTrue(nTest > 0, "JUnit test failed to find sample BigTIFF files");
79 }
80
81 }