| 1 |
package nom.tam.fits.compression.provider.param.base; |
| 2 |
|
| 3 |
/*- |
| 4 |
* #%L |
| 5 |
* nom.tam FITS library |
| 6 |
* %% |
| 7 |
* Copyright (C) 1996 - 2024 nom-tam-fits |
| 8 |
* %% |
| 9 |
* This is free and unencumbered software released into the public domain. |
| 10 |
* |
| 11 |
* Anyone is free to copy, modify, publish, use, compile, sell, or |
| 12 |
* distribute this software, either in source code form or as a compiled |
| 13 |
* binary, for any purpose, commercial or non-commercial, and by any |
| 14 |
* means. |
| 15 |
* |
| 16 |
* In jurisdictions that recognize copyright laws, the author or authors |
| 17 |
* of this software dedicate any and all copyright interest in the |
| 18 |
* software to the public domain. We make this dedication for the benefit |
| 19 |
* of the public at large and to the detriment of our heirs and |
| 20 |
* successors. We intend this dedication to be an overt act of |
| 21 |
* relinquishment in perpetuity of all present and future rights to this |
| 22 |
* software under copyright law. |
| 23 |
* |
| 24 |
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 25 |
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 26 |
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
| 27 |
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 28 |
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 29 |
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 30 |
* OTHER DEALINGS IN THE SOFTWARE. |
| 31 |
* #L% |
| 32 |
*/ |
| 33 |
|
| 34 |
import java.util.ArrayList; |
| 35 |
|
| 36 |
import nom.tam.fits.compression.algorithm.api.ICompressOption; |
| 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.api.ICompressParameters; |
| 40 |
|
| 41 |
/** |
| 42 |
* (<i>for internal use</i>) Compression parameters that are bundled together from distinct sets of component |
| 43 |
* parameters. For example, some tiled image compression methods will take parameters that consist of those specifically |
| 44 |
* for the compression algorithm (e.g. Rice vs HCompress) and a set of common parameters for the quantization |
| 45 |
* (floating-point to integer conversion). This class helps manage such composite parameter sets. The bundle behaves as |
| 46 |
* it it were a single set of all parameters across all its components. |
| 47 |
* |
| 48 |
* @author Attila Kovacs |
| 49 |
* |
| 50 |
* @since 1.18 |
| 51 |
*/ |
| 52 |
public class BundledParameters extends CompressParameters { |
| 53 |
|
| 54 |
private ArrayList<ICompressParameters> bundle; |
| 55 |
|
| 56 |
/** |
| 57 |
* Creates a new set of bundled compression parameters from the specified separate parameter components. |
| 58 |
* |
| 59 |
* @param components The components, which are to be bundled to provide a single set of parameters that span all of |
| 60 |
* them. |
| 61 |
* |
| 62 |
* @see #get(int) |
| 63 |
*/ |
| 64 |
public BundledParameters(ICompressParameters... components) { |
| 65 |
bundle = new ArrayList<>(); |
| 66 |
for (ICompressParameters p : components) { |
| 67 |
if (p != null) { |
| 68 |
bundle.add(p); |
| 69 |
} |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Returns the number of independent compression parameter components represented by this bundle. |
| 75 |
* |
| 76 |
* @return the number of component compression parameter sets in this bundle. |
| 77 |
* |
| 78 |
* @see #get(int) |
| 79 |
*/ |
| 80 |
public int size() { |
| 81 |
return bundle.size(); |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Resturn the compression parameters for the specified component index. |
| 86 |
* |
| 87 |
* @param index the index of the paramete set in the bundle. |
| 88 |
* |
| 89 |
* @return the compression parameters for the particular bundle component. |
| 90 |
* |
| 91 |
* @throws IndexOutOfBoundsException if the index it negative or beyond the index of the last component. |
| 92 |
* |
| 93 |
* @see #size() |
| 94 |
*/ |
| 95 |
public ICompressParameters get(int index) { |
| 96 |
return bundle.get(index); |
| 97 |
} |
| 98 |
|
| 99 |
@Override |
| 100 |
public BundledParameters copy(ICompressOption option) { |
| 101 |
throw new UnsupportedOperationException("Cannot copy parameter bundle"); |
| 102 |
} |
| 103 |
|
| 104 |
@Override |
| 105 |
protected ICompressColumnParameter[] columnParameters() { |
| 106 |
ArrayList<ICompressColumnParameter> list = new ArrayList<>(); |
| 107 |
|
| 108 |
for (ICompressParameters parms : bundle) { |
| 109 |
for (ICompressColumnParameter p : ((CompressParameters) parms).columnParameters()) { |
| 110 |
list.add(p); |
| 111 |
} |
| 112 |
} |
| 113 |
|
| 114 |
ICompressColumnParameter[] array = new ICompressColumnParameter[list.size()]; |
| 115 |
return list.toArray(array); |
| 116 |
} |
| 117 |
|
| 118 |
@Override |
| 119 |
protected ICompressHeaderParameter[] headerParameters() { |
| 120 |
ArrayList<ICompressHeaderParameter> list = new ArrayList<>(); |
| 121 |
for (ICompressParameters parms : bundle) { |
| 122 |
for (ICompressHeaderParameter p : ((CompressParameters) parms).headerParameters()) { |
| 123 |
list.add(p); |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
ICompressHeaderParameter[] array = new ICompressHeaderParameter[list.size()]; |
| 128 |
return list.toArray(array); |
| 129 |
} |
| 130 |
|
| 131 |
@Override |
| 132 |
public void setTileIndex(int index) { |
| 133 |
for (ICompressParameters parms : bundle) { |
| 134 |
parms.setTileIndex(index); |
| 135 |
} |
| 136 |
} |
| 137 |
} |