View Javadoc
1   package nom.tam.image.compression.tile;
2   
3   import nom.tam.fits.FitsException;
4   import nom.tam.fits.Header;
5   import nom.tam.image.tile.operation.ITileOperationInitialisation;
6   import nom.tam.image.tile.operation.TileArea;
7   
8   /*
9    * #%L
10   * nom.tam FITS library
11   * %%
12   * Copyright (C) 1996 - 2024 nom-tam-fits
13   * %%
14   * This is free and unencumbered software released into the public domain.
15   *
16   * Anyone is free to copy, modify, publish, use, compile, sell, or
17   * distribute this software, either in source code form or as a compiled
18   * binary, for any purpose, commercial or non-commercial, and by any
19   * means.
20   *
21   * In jurisdictions that recognize copyright laws, the author or authors
22   * of this software dedicate any and all copyright interest in the
23   * software to the public domain. We make this dedication for the benefit
24   * of the public at large and to the detriment of our heirs and
25   * successors. We intend this dedication to be an overt act of
26   * relinquishment in perpetuity of all present and future rights to this
27   * software under copyright law.
28   *
29   * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
30   * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31   * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
32   * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
33   * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
34   * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
35   * OTHER DEALINGS IN THE SOFTWARE.
36   * #L%
37   */
38  
39  import static nom.tam.image.compression.tile.TileCompressionType.COMPRESSED;
40  import static nom.tam.image.compression.tile.TileCompressionType.GZIP_COMPRESSED;
41  import static nom.tam.image.compression.tile.TileCompressionType.UNCOMPRESSED;
42  
43  final class TileDecompressorInitialisation implements ITileOperationInitialisation<TileCompressionOperation> {
44  
45      private final Object[] uncompressed;
46  
47      private final Object[] compressed;
48  
49      private final Object[] gzipCompressed;
50  
51      private final Header header;
52  
53      private final TiledImageCompressionOperation imageTilesOperation;
54  
55      private int compressedOffset = 0;
56  
57      protected TileDecompressorInitialisation(TiledImageCompressionOperation imageTilesOperation, Object[] uncompressed,
58              Object[] compressed, Object[] gzipCompressed, Header header) {
59          this.imageTilesOperation = imageTilesOperation;
60          this.uncompressed = uncompressed;
61          this.compressed = compressed;
62          this.gzipCompressed = gzipCompressed;
63          this.header = header;
64      }
65  
66      @Override
67      public TileCompressionOperation createTileOperation(int tileIndex, TileArea area) {
68          return new TileDecompressor(imageTilesOperation, tileIndex, area);
69      }
70  
71      @Override
72      public void init(TileCompressionOperation tileOperation) {
73          tileOperation.setCompressedOffset(compressedOffset)//
74                  .setCompressed(compressed != null ? compressed[tileOperation.getTileIndex()] : null, COMPRESSED)//
75                  .setCompressed(uncompressed != null ? uncompressed[tileOperation.getTileIndex()] : null, UNCOMPRESSED)//
76                  .setCompressed(gzipCompressed != null ? gzipCompressed[tileOperation.getTileIndex()] : null,
77                          GZIP_COMPRESSED);
78          tileOperation.createImageNullPixelMask(imageTilesOperation.getImageNullPixelMask());
79          compressedOffset += tileOperation.getPixelSize();
80      }
81  
82      @Override
83      public void tileCount(int tileCount) throws FitsException {
84          imageTilesOperation.compressOptions().getCompressionParameters().initializeColumns(header,
85                  imageTilesOperation.getBinaryTable(), tileCount);
86      }
87  }