1 package nom.tam.image.compression.tile.mask;
2
3 import java.nio.ByteBuffer;
4
5 import nom.tam.fits.compression.algorithm.api.ICompressorControl;
6 import nom.tam.fits.compression.provider.CompressorProvider;
7 import nom.tam.image.tile.operation.buffer.TileBuffer;
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 @SuppressWarnings("javadoc")
44 public class ImageNullPixelMask {
45
46 private final AbstractNullPixelMask[] nullPixelMasks;
47
48 private final long nullValue;
49
50 private final ICompressorControl compressorControl;
51
52 private final String compressAlgorithm;
53
54 public ImageNullPixelMask(int tileCount, long nullValue, String compressAlgorithm) {
55 nullPixelMasks = new AbstractNullPixelMask[tileCount];
56 this.nullValue = nullValue;
57 this.compressAlgorithm = compressAlgorithm;
58 compressorControl = CompressorProvider.findCompressorControl(null, this.compressAlgorithm, byte.class);
59 }
60
61 public NullPixelMaskPreserver createTilePreserver(TileBuffer tileBuffer, int tileIndex) {
62 return add(new NullPixelMaskPreserver(tileBuffer, tileIndex, nullValue, compressorControl));
63 }
64
65 public NullPixelMaskRestorer createTileRestorer(TileBuffer tileBuffer, int tileIndex) {
66 return add(new NullPixelMaskRestorer(tileBuffer, tileIndex, nullValue, compressorControl));
67 }
68
69 @SuppressWarnings("deprecation")
70 public byte[][] getColumn() {
71 byte[][] column = new byte[nullPixelMasks.length][];
72 for (AbstractNullPixelMask tileMask : nullPixelMasks) {
73 column[tileMask.getTileIndex()] = tileMask.getMaskBytes();
74 }
75 return column;
76 }
77
78 public String getCompressAlgorithm() {
79 return compressAlgorithm;
80 }
81
82 public void setColumn(byte[][] nullPixels) {
83 for (AbstractNullPixelMask tileMask : nullPixelMasks) {
84 byte[] tileMaskBytes = nullPixels[tileMask.getTileIndex()];
85 if (tileMaskBytes != null && tileMaskBytes.length > 0) {
86 tileMask.setMask(ByteBuffer.wrap(tileMaskBytes));
87 }
88 }
89 }
90
91 private <T extends AbstractNullPixelMask> T add(T nullPixelMask) {
92 nullPixelMasks[nullPixelMask.getTileIndex()] = nullPixelMask;
93 return nullPixelMask;
94 }
95
96 }