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.assertEquals;
20
21 import java.awt.Color;
22 import java.awt.Graphics2D;
23 import java.awt.image.BufferedImage;
24 import java.io.File;
25 import java.io.IOException;
26
27 import org.apache.commons.imaging.Imaging;
28 import org.apache.commons.imaging.ImagingException;
29 import org.apache.commons.imaging.ImagingTestConstants;
30 import org.junit.jupiter.api.Test;
31
32
33
34
35 public class TiffReadAlphaTest {
36
37 private final static String[] names = { "TransparencyTestStripAssociated.tif", "TransparencyTestStripUnassociated.tif",
38 "TransparencyTestTileAssociated.tif", "TransparencyTestTileUnassociated.tif" };
39
40 private final static int[][] testSite = { { 40, 40, 0xffff0000 }, { 60, 40, 0xff77ff77 }, { 40, 60, 0xffff0000 }, { 60, 60, 0xff008800 } };
41
42
43
44
45
46
47
48 private File getTiffFile(final String name) {
49 final File tiffFolder = new File(ImagingTestConstants.TEST_IMAGE_FOLDER, "tiff");
50 final File alphaFolder = new File(tiffFolder, "12");
51 return new File(alphaFolder, name);
52 }
53
54 @Test
55 public void test() throws ImagingException, IOException {
56 for (final String name : names) {
57 final File subject = getTiffFile(name);
58 final BufferedImage overlay = Imaging.getBufferedImage(subject);
59 final BufferedImage composite = new BufferedImage(100, 100, BufferedImage.TYPE_INT_ARGB);
60 final Graphics2D g2d = composite.createGraphics();
61 g2d.setColor(Color.white);
62 g2d.fillRect(0, 0, 101, 101);
63 g2d.setColor(Color.black);
64 g2d.fillRect(0, 50, 101, 51);
65 g2d.drawImage(overlay, 0, 0, null);
66
67 for (final int[] element : testSite) {
68 final int x = element[0];
69 final int y = element[1];
70 final int p = element[2];
71 final int t = composite.getRGB(x, y);
72 assertEquals(t, p, "Error for " + name + " at position " + x + ", " + y);
73 }
74 }
75 }
76 }