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 public class ImageNullPixelMask {
44
45 private final AbstractNullPixelMask[] nullPixelMasks;
46
47 private final long nullValue;
48
49 private final ICompressorControl compressorControl;
50
51 private final String compressAlgorithm;
52
53 public ImageNullPixelMask(int tileCount, long nullValue, String compressAlgorithm) {
54 nullPixelMasks = new AbstractNullPixelMask[tileCount];
55 this.nullValue = nullValue;
56 this.compressAlgorithm = compressAlgorithm;
57 compressorControl = CompressorProvider.findCompressorControl(null, this.compressAlgorithm, byte.class);
58 }
59
60 public NullPixelMaskPreserver createTilePreserver(TileBuffer tileBuffer, int tileIndex) {
61 return add(new NullPixelMaskPreserver(tileBuffer, tileIndex, nullValue, compressorControl));
62 }
63
64 public NullPixelMaskRestorer createTileRestorer(TileBuffer tileBuffer, int tileIndex) {
65 return add(new NullPixelMaskRestorer(tileBuffer, tileIndex, nullValue, compressorControl));
66 }
67
68 @SuppressWarnings("deprecation")
69 public byte[][] getColumn() {
70 byte[][] column = new byte[nullPixelMasks.length][];
71 for (AbstractNullPixelMask tileMask : nullPixelMasks) {
72 column[tileMask.getTileIndex()] = tileMask.getMaskBytes();
73 }
74 return column;
75 }
76
77 public String getCompressAlgorithm() {
78 return compressAlgorithm;
79 }
80
81 public void setColumn(byte[][] nullPixels) {
82 for (AbstractNullPixelMask tileMask : nullPixelMasks) {
83 byte[] tileMaskBytes = nullPixels[tileMask.getTileIndex()];
84 if (tileMaskBytes != null && tileMaskBytes.length > 0) {
85 tileMask.setMask(ByteBuffer.wrap(tileMaskBytes));
86 }
87 }
88 }
89
90 private <T extends AbstractNullPixelMask> T add(T nullPixelMask) {
91 nullPixelMasks[nullPixelMask.getTileIndex()] = nullPixelMask;
92 return nullPixelMask;
93 }
94
95 }