1 package nom.tam.fits.compression.provider.param.quant;
2
3 import nom.tam.fits.Header;
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
35
36 import nom.tam.fits.HeaderCard;
37 import nom.tam.fits.HeaderCardException;
38 import nom.tam.fits.compression.algorithm.quant.QuantizeOption;
39 import nom.tam.fits.compression.provider.param.base.CompressHeaderParameter;
40 import nom.tam.fits.header.Compression;
41
42
43
44
45 final class ZQuantizeParameter extends CompressHeaderParameter<QuantizeOption> {
46
47 ZQuantizeParameter(QuantizeOption quantizeOption) {
48 super(Compression.ZQUANTIZ.name(), quantizeOption);
49 }
50
51 @Override
52 public void getValueFromHeader(Header header) throws HeaderCardException {
53 if (getOption() == null) {
54 return;
55 }
56
57 HeaderCard card = header.getCard(getName());
58 String value = card != null ? card.getValue() : null;
59
60 getOption().setDither(false);
61 getOption().setDither2(false);
62
63 if (Compression.ZQUANTIZ_SUBTRACTIVE_DITHER_1.equals(value)) {
64 getOption().setDither(true);
65 } else if (Compression.ZQUANTIZ_SUBTRACTIVE_DITHER_2.equals(value)) {
66 getOption().setDither(true);
67 getOption().setDither2(true);
68 }
69 }
70
71 @Override
72 public void setValueInHeader(Header header) throws HeaderCardException {
73 if (getOption() == null) {
74 return;
75 }
76
77 String value;
78
79 if (getOption().isDither2()) {
80 value = Compression.ZQUANTIZ_SUBTRACTIVE_DITHER_2;
81 } else if (getOption().isDither()) {
82 value = Compression.ZQUANTIZ_SUBTRACTIVE_DITHER_1;
83 } else {
84 value = Compression.ZQUANTIZ_NO_DITHER;
85 }
86 header.addValue(Compression.ZQUANTIZ, value);
87 }
88 }