1 package nom.tam.fits.compression.algorithm.hcompress;
2
3
4
5
6
7
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 import nom.tam.fits.compression.algorithm.api.ICompressOption;
35 import nom.tam.fits.compression.provider.param.api.ICompressParameters;
36 import nom.tam.fits.compression.provider.param.hcompress.HCompressParameters;
37
38
39
40
41
42
43
44
45
46 public class HCompressorOption implements ICompressOption {
47
48
49 private final Config config;
50
51
52 private HCompressParameters parameters;
53
54 private int tileHeight;
55
56 private int tileWidth;
57
58
59
60
61 public HCompressorOption() {
62 config = new Config();
63 setParameters(new HCompressParameters(this));
64 }
65
66 @Override
67 public HCompressorOption copy() {
68 try {
69 HCompressorOption copy = (HCompressorOption) clone();
70 copy.parameters = parameters.copy(copy);
71 return copy;
72 } catch (CloneNotSupportedException e) {
73 throw new IllegalStateException("option could not be cloned", e);
74 }
75 }
76
77 @Override
78 public HCompressParameters getCompressionParameters() {
79 return parameters;
80 }
81
82
83
84
85
86
87
88
89 public int getScale() {
90 return config.scale;
91 }
92
93 @Override
94 public int getTileHeight() {
95 return tileHeight;
96 }
97
98 @Override
99 public int getTileWidth() {
100 return tileWidth;
101 }
102
103 @Override
104 public boolean isLossyCompression() {
105 return config.scale > 0 || config.smooth;
106 }
107
108
109
110
111
112
113
114
115 public boolean isSmooth() {
116 return config.smooth;
117 }
118
119 @Override
120 public void setParameters(ICompressParameters parameters) {
121 if (!(parameters instanceof HCompressParameters)) {
122 throw new IllegalArgumentException("Wrong type of parameters: " + parameters.getClass().getName());
123 }
124 this.parameters = (HCompressParameters) parameters;
125 }
126
127
128
129
130
131
132
133
134
135
136
137
138
139 public HCompressorOption setScale(double value) throws IllegalArgumentException {
140 if (value < 0.0) {
141 throw new IllegalArgumentException("Scale value cannot be negative: " + value);
142 }
143 config.scale = (int) Math.round(value);
144 return this;
145 }
146
147
148
149
150
151
152
153
154 public HCompressorOption setSmooth(boolean value) {
155 config.smooth = value;
156 return this;
157 }
158
159 @Override
160 public <T> T unwrap(Class<T> clazz) {
161 if (clazz.isAssignableFrom(this.getClass())) {
162 return clazz.cast(this);
163 }
164 return null;
165 }
166
167 @Override
168 public HCompressorOption setTileHeight(int value) {
169 tileHeight = value;
170 return this;
171 }
172
173 @Override
174 public HCompressorOption setTileWidth(int value) {
175 tileWidth = value;
176 return this;
177 }
178
179
180
181
182
183
184
185
186 private static final class Config {
187
188 private int scale;
189
190 private boolean smooth;
191
192 }
193 }