1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.imaging.formats.png.transparencyfilters;
18
19 import static org.apache.commons.imaging.common.BinaryFunctions.read2Bytes;
20
21 import java.io.ByteArrayInputStream;
22 import java.io.IOException;
23
24 import org.apache.commons.imaging.ImagingException;
25
26 public class TransparencyFilterGrayscale extends AbstractTransparencyFilter {
27 private final int transparentColor;
28
29 public TransparencyFilterGrayscale(final byte[] bytes) throws IOException {
30 super(bytes);
31
32 final ByteArrayInputStream is = new ByteArrayInputStream(bytes);
33 transparentColor = read2Bytes("transparentColor", is, "tRNS: Missing transparentColor", getByteOrder());
34 }
35
36 @Override
37 public int filter(final int rgb, final int index) throws ImagingException, IOException {
38 if (index != transparentColor) {
39 return rgb;
40 }
41 return 0x00;
42 }
43 }