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_utils.c

    r39457 r41474  
    104104  // fprintf (stderr, "swapping %d bytes in pix of size %d bytes...\n", Nzdata, pixsize);
    105105  switch (pixsize) {
     106    case 0:
    106107    case 1:
    107108      break;
     
    186187}
    187188
    188 int gfits_uncompressed_data_pixsize (char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions) {
     189// the size of the compressed data pixels, needed to perform swaps
     190int gfits_compressed_data_pixsize (char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions) {
     191
     192  // NONE should be swapped to mimic swapping types
     193  if (!strcasecmp(cmptype, "NONE") || !strcasecmp(cmptype, "NONE_1")) {
     194    if (out_bitpix ==   8) return (1);
     195    if (out_bitpix ==  16) return (2);
     196    if (out_bitpix ==  32) return (4);
     197    if (out_bitpix == -32) return (4);
     198    if (out_bitpix == -64) return (8);
     199    return (1);
     200  }
     201
     202  // GZIP_1, GZIP_2 should not be swapped after compression / before decompression
     203  if (!strcasecmp(cmptype, "GZIP_1") ||
     204      !strcasecmp(cmptype, "GZIP_2") ||
     205      !strcasecmp(cmptype, "NONE_2")) {
     206    if (out_bitpix ==   8) return (1);
     207    if (out_bitpix ==  16) return (1);
     208    if (out_bitpix ==  32) return (1);
     209    if (out_bitpix == -32) return (1);
     210    if (out_bitpix == -64) return (1);
     211    return (1);
     212  }
     213
     214  // RICE_1 should not be swapped after compression / before decompression
     215  if (!strcasecmp(cmptype, "RICE_1") ||
     216      !strcasecmp(cmptype, "RICE_ONE")) {
     217    return (1);
     218  }
     219
     220  // PLIO_1 always results in 4-byte ints (not 2 byte ints?)
     221  if (!strcasecmp(cmptype, "PLIO_1")) {
     222    return (4);
     223  }
     224
     225  if (!strcasecmp(cmptype, "HCOMPRESS_1")) {
     226    if (out_bitpix == 8)  return (4);
     227    if (out_bitpix == 16) return (4);
     228    return (8);
     229  }
     230  return (0);
     231}
     232
     233int gfits_uncompressed_data_pixsize (char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions, int rice_use_bitpix) {
    189234
    190235  int i, Nbyte;
     
    207252  if (!strcasecmp(cmptype, "RICE_1") ||
    208253      !strcasecmp(cmptype, "RICE_ONE")) {
     254    // on compression, user may set BYTEPIX based on header.bitpix:
     255    if (rice_use_bitpix) {
     256      if (out_bitpix ==   8) return (1);
     257      if (out_bitpix ==  16) return (2);
     258      if (out_bitpix ==  32) return (4);
     259    }
    209260    // if BYTEPIX option is specified, use that for Nbyte
    210261    for (i = 0; i < Noptions; i++) {
     
    214265      }
    215266    }
    216     if (out_bitpix ==   8) return (1);
    217     if (out_bitpix ==  16) return (2);
    218     if (out_bitpix ==  32) return (4);
    219     return (4);
     267    return (4); // RICE_1 default is 4 byte int if BYTEPIX undefined (White et al 6.2)
    220268  }
    221269
     
    233281}
    234282
    235 int gfits_compressed_data_pixsize (char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions) {
    236 
    237   int i, Nbyte;
    238 
    239   // NONE should be swapped to mimic swapping types
    240   if (!strcasecmp(cmptype, "NONE") || !strcasecmp(cmptype, "NONE_1")) {
    241     if (out_bitpix ==   8) return (1);
    242     if (out_bitpix ==  16) return (2);
    243     if (out_bitpix ==  32) return (4);
    244     if (out_bitpix == -32) return (4);
    245     if (out_bitpix == -64) return (8);
    246     return (1);
    247   }
    248 
    249   // GZIP_1, GZIP_2 should not be swapped after compression
    250   if (!strcasecmp(cmptype, "GZIP_1") ||
    251       !strcasecmp(cmptype, "GZIP_2") ||
    252       !strcasecmp(cmptype, "NONE_2")) {
    253     if (out_bitpix ==   8) return (1);
    254     if (out_bitpix ==  16) return (1);
    255     if (out_bitpix ==  32) return (1);
    256     if (out_bitpix == -32) return (1);
    257     if (out_bitpix == -64) return (1);
    258     return (1);
    259   }
    260 
    261   // RICE_1 must operate on integer pixels
    262   if (!strcasecmp(cmptype, "RICE_1") ||
    263       !strcasecmp(cmptype, "RICE_ONE")) {
    264     // if BYTEPIX option is specified, use that for Nbyte
    265     for (i = 0; i < Noptions; i++) {
    266       if (!strcmp(optname[i], "BYTEPIX")) {
    267         Nbyte = atoi (optvalue[i]);
    268         return (Nbyte);
    269       }
    270     }
    271     if (out_bitpix ==   8) return (1);
    272     if (out_bitpix ==  16) return (2);
    273     if (out_bitpix ==  32) return (4);
    274     return (4);
    275   }
    276 
    277   // PLIO_1 always results in 4-byte ints (not 2 byte ints?)
    278   if (!strcasecmp(cmptype, "PLIO_1")) {
    279     return (4);
    280   }
    281 
    282   if (!strcasecmp(cmptype, "HCOMPRESS_1")) {
    283     if (out_bitpix == 8)  return (4);
    284     if (out_bitpix == 16) return (4);
    285     return (8);
    286   }
    287   return (0);
    288 }
    289 
    290 int gfits_uncompressed_data_bitpix (char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions) {
     283int gfits_uncompressed_data_bitpix (char *cmptype, int out_bitpix, char **optname, char **optvalue, int Noptions, int rice_use_bitpix) {
    291284
    292285  int i, Nbyte;
     
    304297  if (!strcasecmp(cmptype, "RICE_1") ||
    305298      !strcasecmp(cmptype, "RICE_ONE")) {
     299    if (rice_use_bitpix) {
     300      if (out_bitpix ==   8) return (out_bitpix);
     301      if (out_bitpix ==  16) return (out_bitpix);
     302      if (out_bitpix ==  32) return (out_bitpix);
     303    }
    306304    // if BYTEPIX option is specified, use that for Nbyte
    307305    for (i = 0; i < Noptions; i++) {
     
    311309      }
    312310    }
    313     if (out_bitpix ==   8) return (out_bitpix);
    314     if (out_bitpix ==  16) return (out_bitpix);
    315     if (out_bitpix ==  32) return (out_bitpix);
    316311    return (32);
    317312  }
Note: See TracChangeset for help on using the changeset viewer.