IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 24, 2021, 3:37:52 PM (5 years ago)
Author:
eugene
Message:

clarify in comments the buffers and pixel sizes used in the different stages of compression/uncompression; catch unimplemented compression cases; fix error in pixel size for RICE1; cleanup verbose code; use correct sscanf format code in ASCII table reading code

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/libfits/matrix/F_compress_M.c

    r39457 r41474  
    7676  if (!gfits_modify (theader, "ZCMPTYPE", "%s", 1, zcmptype)) ESCAPE;
    7777
    78   // define compression-specific keywords, update header as needed.
    79   if (!strcasecmp(zcmptype, "GZIP_1") || !strcasecmp(zcmptype, "GZIP_2")) {
    80     if ((header[0].bitpix == -32) || (header[0].bitpix == -64)) {
    81       if (!gfits_modify (theader, "ZQUANTIZ", "%s", 1, "NONE")) ESCAPE;
    82     }
    83   }
    84 
    8578  if (!gfits_modify_alt (theader, "ZSIMPLE", "%t", 1, TRUE)) ESCAPE;
    8679  // gfits_modify (header, "ZTENSION", "%s", 1, exttype);
     
    124117  int oblank = 32767;
    125118  // gfits_modify (header, "BLANK", "%d", 1, oblank);
     119
     120  // define compression-specific keywords, update header as needed.
     121  if (!strcasecmp(zcmptype, "GZIP_1") || !strcasecmp(zcmptype, "GZIP_2")) {
     122    if ((header[0].bitpix == -32) || (header[0].bitpix == -64)) {
     123      if (!gfits_modify (theader, "ZQUANTIZ", "%s", 1, "NONE")) ESCAPE;
     124    }
     125  }
    126126
    127127# if (0)
     
    159159  unsigned long int max_tile_size = gfits_imtile_maxsize (matrix, ztile);
    160160
    161   // size of a pixel in the raw pixel buffer (before compression)
    162   int raw_pixsize = gfits_uncompressed_data_pixsize (zcmptype, header[0].bitpix, NULL, NULL, 0);
    163   int raw_bitpix  = gfits_uncompressed_data_bitpix (zcmptype, header[0].bitpix, NULL, NULL, 0);
     161  // size of a pixel in the compressed data (cmp_pixsize), used for byteswap below
    164162  int cmp_pixsize = gfits_compressed_data_pixsize (zcmptype, header[0].bitpix, NULL, NULL, 0);
     163
     164  // size of a pixel in the raw pixel buffer (before compression) (last option says RICE uses header.bitpix)
     165  int raw_pixsize = gfits_uncompressed_data_pixsize (zcmptype, header[0].bitpix, NULL, NULL, 0, TRUE);
     166
     167  // we also need the bitpix value for the raw uncompressed buffer to distinguish int and floats
     168  int raw_bitpix  = gfits_uncompressed_data_bitpix (zcmptype, header[0].bitpix, NULL, NULL, 0, TRUE);
    165169
    166170  // define compression-specific keywords, update header as needed.
     
    237241    }
    238242
    239     // GZIP_1 is swapped before compression; GZIP_2 implies swapping.  All other
    240     // compression modes require swapping after compression (compresssion & decompression
    241     // operate on native ENDIAN)
    242     if (strcasecmp(zcmptype, "NONE_2") && // strcasecmp(zcmptype, "NONE") &&
    243         strcasecmp(zcmptype, "GZIP_1") &&
    244         strcasecmp(zcmptype, "GZIP_2") &&
    245         strcasecmp(zcmptype, "RICE_1") &&
    246         strcasecmp(zcmptype, "RICE_ONE")) {
    247       // Nzdata is number of bytes
    248       if (!gfits_byteswap_zdata (zdata, Nzdata, cmp_pixsize)) ESCAPE;
    249     }
     243    // BYTESWAP the compressed data after compressing.  Compression algorithms which do
     244    // not need to byteswap here return 1 for cmp_pixsize.  GZIP_1 is swapped before
     245    // compression; GZIP_2 implies swapping.  All other compression modes require swapping
     246    // after compression (the compresssion & decompression functions operate on native
     247    // ENDIAN data values).
     248    if (!gfits_byteswap_zdata (zdata, Nzdata, cmp_pixsize)) ESCAPE;
    250249
    251250    if (VERBOSE_DUMP && (i == 0)) {
Note: See TracChangeset for help on using the changeset viewer.