IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 15655


Ignore:
Timestamp:
Nov 19, 2007, 8:02:41 PM (18 years ago)
Author:
eugene
Message:

fix decompression

Location:
trunk/Ohana/src/libfits
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana/src/libfits/include/gfitsio.h

    r15647 r15655  
    158158int     gfits_extension_is_compressed  PROTO((Header *header));
    159159int     gfits_tile_size                PROTO((Matrix *matrix, int *otile, int *ztile));
     160int     gfits_uncompressed_data_pixsize PROTO((char *cmptype));
     161int     gfits_vartable_heap_pixsize    PROTO((char format));
    160162
    161163/******************************* Table functions *************/
  • trunk/Ohana/src/libfits/matrix/F_compress_M.c

    r15649 r15655  
    3737  float zscale, zzero;
    3838
     39  int zdata_pixsize, odata_pixsize, idata_pixsize;
     40
    3941  int *ztile = NULL;
    4042  int *otile = NULL;
     
    4345  char **optvalue = NULL;
    4446  char *out = NULL;
     47  char *zdata = NULL;
    4548
    4649  // is ZIMAGE present?
     
    161164  }
    162165
    163   // max_tile_size is in pixels
    164   bytes_per_pixel = abs(header[0].bitpix) / 8;
    165   ALLOCATE (out, char, bytes_per_pixel*max_tile_size);
     166  // this takes place in three major steps:
     167  // 1) read the table data : zdef.format tells the size of the varlength heap element
     168  // 2) uncompress the data : pixel size depends on compression method
     169  // 3) distribute data to the tiles : output pixel size depends on header.bitpix
     170
     171  // heapdata -> zdata -> odata -> idata
     172
     173  // heapdata.pixsize : zdef.format
     174  // zdata.pixsize : depends on compression
     175  // odata.pixsize : depends on compression
     176  // idata.pixsize : header.bitpix
     177
     178  // size of an element in the vartable heap section
     179  zdata_pixsize = gfits_vartable_heap_pixsize (zdef.format);
     180
     181  // size of a pixel in the final image
     182  idata_pixsize = abs(header[0].bitpix) / 8;
     183
     184  // size of a pixel in the output from the decompression routine
     185  odata_pixsize = gfits_uncompressed_data_pixsize (cmptype);
     186  ALLOCATE (out, char, odata_pixsize*max_tile_size);
    166187
    167188  // uncompress the data
     
    172193    Nout = gfits_tile_size (matrix, otile, ztile);
    173194
    174     switch (zdef.format) {
    175       // gfits_varlength returns a pointer to a chunk of Nzdata of data elements starting at zdata.
    176       // uncompress_data uncompresses from zdata to the temporary output buffer which must be allocated
    177 
    178       // XXX need to have an API to send the user data
    179 
    180       // XXX need to byte-swap the table column; this needs to be worked out more clearly
    181       // in the APIs: do the table read / column extract functions swap or not?.  we have
    182       // put the byte-swapping in gifts_varlength_column_pointer, but this is fairly weak.
    183 
    184       // XXX inconsistency between data element size between compressed data, uncompressed data,
    185       // and output pixel data.....
    186 
    187       case 'B': {
    188         char *zdata;
    189         zdata = gfits_varlength_column_pointer (ftable, &zdef, i, &Nzdata);
    190         if (!zdata) return (FALSE);
    191         if (!gfits_byteswap_zdata ((char *)zdata, Nzdata, 8)) return (FALSE);
    192         if (!gfits_uncompress_data ((char *)zdata, Nzdata, cmptype, optname, optvalue, Noptions, out, &Nout, bytes_per_pixel)) return (FALSE);
    193         if (!gfits_distribute_data (matrix, 8, out, Nout, otile, ztile, zscale, zzero)) return (FALSE);
    194         // copy the uncompressed pixels into their correct locations       
    195         break;
    196       }
    197 
    198       case 'I': {
    199         short *zdata;
    200         zdata = gfits_varlength_column_pointer (ftable, &zdef, i, &Nzdata);
    201         if (!zdata) return (FALSE);
    202         if (!gfits_byteswap_zdata ((char *)zdata, Nzdata, 16)) return (FALSE);
    203         if (!gfits_uncompress_data ((char *)zdata, Nzdata, cmptype, optname, optvalue, Noptions, out, &Nout, bytes_per_pixel)) return (FALSE);
    204         if (!gfits_distribute_data (matrix, 16, out, Nout, otile, ztile, zscale, zzero)) return (FALSE);
    205         // copy the uncompressed pixels into their correct locations       
    206         break;
    207       }
    208 
    209       case 'J': {
    210         int *zdata;
    211         if (!zdata) return (FALSE);
    212         if (!gfits_byteswap_zdata ((char *)zdata, Nzdata, 32)) return (FALSE);
    213         if (!gfits_uncompress_data ((char *)zdata, Nzdata, cmptype, optname, optvalue, Noptions, out, &Nout, bytes_per_pixel)) return (FALSE);
    214         if (!gfits_distribute_data (matrix, 32, out, Nout, otile, ztile, zscale, zzero)) return (FALSE);
    215         // copy the uncompressed pixels into their correct locations       
    216         break;
    217       }
    218 
    219       default:
    220         fprintf (stderr, "invalid size for compressed data: %c\n", zdef.format); 
    221         return (FALSE);
    222     }
     195    zdata = gfits_varlength_column_pointer (ftable, &zdef, i, &Nzdata);
     196    if (!zdata) return (FALSE);
     197
     198    // XXX not certain this is the correct place to do the swap (or if zdata_pixsize is
     199    // the correct size to guide the swap)
     200    if (!gfits_byteswap_zdata (zdata, Nzdata, zdata_pixsize)) return (FALSE);
     201
     202    // gfits_uncompress_data uncompresses from zdata to the temporary output buffer which must be allocated
     203    if (!gfits_uncompress_data ((char *)zdata, Nzdata, cmptype, optname, optvalue, Noptions, out, &Nout, bytes_per_pixel)) return (FALSE);
     204
     205    // copy the uncompressed pixels into their correct locations           
     206    if (!gfits_distribute_data (matrix, odata_pixsize, out, Nout, otile, ztile, zscale, zzero)) return (FALSE);
    223207
    224208    // update the tile counters, carrying to the next dimension if needed
     
    234218  return (TRUE);
    235219}
     220
     221// gfits_varlength returns a pointer to a chunk of Nzdata of data elements starting at zdata.
     222
     223// XXX need to have an API to send the user data
     224
     225// XXX need to byte-swap the table column; this needs to be worked out more clearly
     226// in the APIs: do the table read / column extract functions swap or not?.  we have
     227// put the byte-swapping in gifts_varlength_column_pointer, but this is fairly weak.
     228
     229// XXX inconsistency between data element size between compressed data, uncompressed data,
     230// and output pixel data.....
    236231
    237232int gfits_tile_size (Matrix *matrix, int *otile, int *ztile) {
     
    321316  for (i = 0; i < Nline; i++) {
    322317    switch (bitpix) {
    323       case 8:
     318      case 1:
    324319        SETUP_INSIZE (char, 1);
    325320        break;
    326       case 16:
     321      case 2:
    327322        SETUP_INSIZE (short, 2);
    328323        break;
    329       case 32:
     324      case 4:
    330325        SETUP_INSIZE (int, 4);
    331326        break;
     
    361356}
    362357
    363 int gfits_byteswap_zdata (char *zdata, int Nzdata, int bitpix) {
     358int gfits_byteswap_zdata (char *zdata, int Nzdata, int pixsize) {
    364359
    365360# ifdef BYTE_SWAP
     
    368363  char tmp;
    369364
    370   switch (bitpix) {
    371     case +8:
    372     case -8:
     365  switch (pixsize) {
     366    case 1:
    373367      break;
    374368
    375     case +16:
    376     case -16:
     369    case 2:
    377370      for (i = 0; i < Nzdata; i+=2) {
    378371        tmp = zdata[i];
     
    382375      break;
    383376
    384     case +32:
    385     case -32:
     377    case 4:
    386378      for (i = 0; i < Nzdata; i+=4) {
    387379        tmp = zdata[i+1];
     
    394386      break;
    395387
    396     case +64:
    397     case -64:
     388    case 8:
    398389      for (i = 0; i < Nzdata; i+=8) {
    399390        tmp = zdata[i+0];
     
    444435    return (FALSE);
    445436}
     437
     438int gfits_uncompressed_data_pixsize (char *cmptype) {
     439
     440  if (!strcasecmp(cmptype, "GZIP")) {
     441    return (0);
     442  }
     443  if (!strcasecmp(cmptype, "RICE") || !strcasecmp(cmptype, "RICE_1")) {
     444    return (4);
     445  }
     446  if (!strcasecmp(cmptype, "PLIO")) {
     447    return (1);
     448  }
     449  if (!strcasecmp(cmptype, "HCOMPRESS")) {
     450    return (4);
     451  }
     452  return (0);
     453}
     454
     455int gfits_vartable_heap_pixsize (char format) {
     456
     457  if (format == 'B') {
     458      return (1);
     459  }
     460  if (format == 'I') {
     461      return (2);
     462  }
     463  if (format == 'J') {
     464      return (4);
     465  }
     466  fprintf (stderr, "invalid size for compressed data: %c\n", format); 
     467  abort ();
     468}
Note: See TracChangeset for help on using the changeset viewer.