View Javadoc
1   package nom.tam.fits.compression.provider.param.quant;
2   
3   import nom.tam.fits.compression.algorithm.api.ICompressOption;
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.compression.algorithm.quant.QuantizeOption;
37  import nom.tam.fits.compression.provider.param.api.ICompressColumnParameter;
38  import nom.tam.fits.compression.provider.param.api.ICompressHeaderParameter;
39  import nom.tam.fits.compression.provider.param.base.CompressParameters;
40  
41  /**
42   * (<i>for internal use</i>) A set of compression parameters recorded in the FITS that describe the quantization of
43   * floating point data. Quantization is the process of representing floating-point values by integers.
44   *
45   * @author Attila Kovacs
46   */
47  public class QuantizeParameters extends CompressParameters {
48  
49      private ZQuantizeParameter quantz;
50  
51      private ZBlankParameter blank;
52  
53      private ZDither0Parameter seed;
54  
55      private ZBlankColumnParameter blankColumn;
56  
57      private ZZeroColumnParameter zero;
58  
59      private ZScaleColumnParameter scale;
60  
61      private QuantizeOption options;
62  
63      /**
64       * Creates a set of compression parameters used for quantization of floating point data. Quantization is the process
65       * of representing floating-point values by integers.
66       *
67       * @param option The compression option that is configured with the particular parameter values of this object.
68       */
69      @SuppressWarnings("deprecation")
70      public QuantizeParameters(QuantizeOption option) {
71          options = option;
72          quantz = new ZQuantizeParameter(option);
73          blank = new ZBlankParameter(option);
74          seed = new ZDither0Parameter(option);
75          blankColumn = new ZBlankColumnParameter(option);
76          zero = new ZZeroColumnParameter(option);
77          scale = new ZScaleColumnParameter(option);
78      }
79  
80      private Integer getCurrentZBlank() {
81          return options.getBNull();
82      }
83  
84      @Override
85      protected ICompressColumnParameter[] columnParameters() {
86          return new ICompressColumnParameter[] {blankColumn, zero, scale};
87      }
88  
89      @Override
90      protected ICompressHeaderParameter[] headerParameters() {
91          return new ICompressHeaderParameter[] {quantz, blank, seed};
92      }
93  
94      @Override
95      protected ICompressColumnParameter[] activeColumnParameters() {
96          if (blankColumn.isUniform()) {
97              return new ICompressColumnParameter[] {zero, scale};
98          }
99          // We have per-tile blanking values
100         return new ICompressColumnParameter[] {blankColumn, zero, scale};
101     }
102 
103     @Override
104     protected ICompressHeaderParameter[] activeHeaderParameters() {
105         Integer zblank = getCurrentZBlank();
106 
107         if (zblank == null || !blankColumn.isUniform()) {
108             // We have per-tile blanking values
109             return new ICompressHeaderParameter[] {quantz, seed};
110         }
111         return new ICompressHeaderParameter[] {quantz, blank, seed};
112     }
113 
114     @Override
115     public void setTileIndex(int index) {
116         seed.setTileIndex(index);
117     }
118 
119     @Override
120     public QuantizeParameters copy(ICompressOption option) {
121         if (option instanceof QuantizeOption) {
122             QuantizeOption qo = (QuantizeOption) option;
123 
124             QuantizeParameters p = (QuantizeParameters) super.clone();
125             p.quantz = (ZQuantizeParameter) quantz.copy(qo);
126             p.blank = (ZBlankParameter) blank.copy(qo);
127             p.seed = (ZDither0Parameter) seed.copy(qo);
128             p.blankColumn = (ZBlankColumnParameter) blankColumn.copy(qo);
129             p.zero = (ZZeroColumnParameter) zero.copy(qo);
130             p.scale = (ZScaleColumnParameter) scale.copy(qo);
131 
132             return p;
133         }
134         return null;
135     }
136 }