View Javadoc
1   package nom.tam.fits.compression.provider.param.quant;
2   
3   import nom.tam.fits.Header;
4   
5   /*
6    * #%L
7    * nom.tam FITS library
8    * %%
9    * Copyright (C) 1996 - 2024 nom-tam-fits
10   * %%
11   * This is free and unencumbered software released into the public domain.
12   *
13   * Anyone is free to copy, modify, publish, use, compile, sell, or
14   * distribute this software, either in source code form or as a compiled
15   * binary, for any purpose, commercial or non-commercial, and by any
16   * means.
17   *
18   * In jurisdictions that recognize copyright laws, the author or authors
19   * of this software dedicate any and all copyright interest in the
20   * software to the public domain. We make this dedication for the benefit
21   * of the public at large and to the detriment of our heirs and
22   * successors. We intend this dedication to be an overt act of
23   * relinquishment in perpetuity of all present and future rights to this
24   * software under copyright law.
25   *
26   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
27   * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
28   * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
29   * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
30   * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
31   * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
32   * OTHER DEALINGS IN THE SOFTWARE.
33   * #L%
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   * (<i>for internal use</i>) The quantization method name as recorded in the FITS header.
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          HeaderCard card = header.getCard(getName());
54          String value = card != null ? card.getValue() : null;
55  
56          getOption().setDither(false);
57          getOption().setDither2(false);
58  
59          if (Compression.ZQUANTIZ_SUBTRACTIVE_DITHER_1.equals(value)) {
60              getOption().setDither(true);
61          } else if (Compression.ZQUANTIZ_SUBTRACTIVE_DITHER_2.equals(value)) {
62              getOption().setDither(true);
63              getOption().setDither2(true);
64          }
65      }
66  
67      @Override
68      public void setValueInHeader(Header header) throws HeaderCardException {
69          String value;
70  
71          if (getOption().isDither2()) {
72              value = Compression.ZQUANTIZ_SUBTRACTIVE_DITHER_2;
73          } else if (getOption().isDither()) {
74              value = Compression.ZQUANTIZ_SUBTRACTIVE_DITHER_1;
75          } else {
76              value = Compression.ZQUANTIZ_NO_DITHER;
77          }
78          header.addValue(Compression.ZQUANTIZ, value);
79      }
80  }