IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 12, 2015, 6:18:23 PM (11 years ago)
Author:
eugene
Message:

merge changes from EAM dev branch ohana.20150429

Location:
trunk/Ohana
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Ohana

  • trunk/Ohana/src/libfits/matrix/F_uncompress_data.c

    r23815 r38441  
    2626int gfits_uncompress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);
    2727
    28 int gfits_uncompress_data (char *zdata, int Nzdata, char *cmptype, char **optname, char **optvalue, int Nopt, char *outdata, int *Nout, int out_pixsize) {
     28# define ESCAPE(RET) { fprintf (stderr, "gzip error in %s @ %s:%d\n", __func__, __FILE__, __LINE__); return (RET); }
     29
     30int gfits_uncompress_data (char *zdata, int Nzdata, char *cmptype, char **optname, char **optvalue, int Nopt, char *outdata, int *Nout, int Nout_alloc, int out_pixsize) {
    2931
    3032  int status;
    31   static int Ninsum = 0;
    32   static int Noutsum = 0;
    3333
    34   if (!strcasecmp(cmptype, "GZIP_1")) {
    35     unsigned long tNout = *Nout * out_pixsize;
     34  // do not actually uncompress : this is used for testing
     35  if (!strcasecmp(cmptype, "NONE") || !strcasecmp(cmptype, "NONE_1") || !strcasecmp(cmptype, "NONE_2")) {
     36    memcpy (outdata, zdata, Nzdata);
     37    myAssert (*Nout == Nzdata, "invalid size");
     38    *Nout = Nzdata / out_pixsize;
     39    return (TRUE);
     40  }
     41
     42  if (!strcasecmp(cmptype, "GZIP_1") || !strcasecmp(cmptype, "GZIP_2")) {
     43    // unsigned long tNout = *Nout * out_pixsize;
     44    // input value of *Nout is number of BYTES
     45    unsigned long tNout = Nout_alloc;
    3646
    3747    // for GZIP data, I need to check for and remove the header on the first block:
    38     gfits_gz_stripheader ((unsigned char *)zdata, &Nzdata);
     48    // XXX maybe not anymore
     49    // gfits_gz_stripheader ((unsigned char *)zdata, &Nzdata);
    3950
    4051    // uncompress does not require us to know the expected number of pixel; it tells us the number
     52    // XXX shouldn't we validate the result : we think we know the size
    4153    status = gfits_uncompress ((Bytef *) outdata, &tNout, (Bytef *) zdata, Nzdata);
    42     if (status != Z_OK) {
    43       fprintf (stderr, "error in uncompress (GZIP)\n");
    44       return (FALSE);
    45     }
     54    if (status != Z_OK) ESCAPE(FALSE);
     55    myAssert (*Nout == tNout, "uncompressed size mismatch");
    4656    *Nout = tNout / out_pixsize;
     57    // output value of *Nout is number of PIXELS
    4758
    4859    // the resulting uncompressed data is byteswapped
    49     if (!gfits_byteswap_zdata (outdata, *Nout, out_pixsize)) return (FALSE);
     60    // if (!gfits_byteswap_zdata (outdata, *Nout, out_pixsize)) return (FALSE);
    5061
    5162    return (TRUE);
    5263  }
    5364
    54   if (!strcasecmp(cmptype, "RICE_1")) {
     65  if (!strcasecmp(cmptype, "RICE_1") || !strcasecmp(cmptype, "RICE_ONE")) {
    5566    int i, blocksize;
    5667    // look for the BLOCKSIZE
     
    6677    }
    6778
    68     int Npix;
    69     // Npix = *Nout * (out_pixsize / 4.0);
    70     Npix = *Nout;
    71 
    72     Ninsum += Nzdata;
    73     Noutsum += *Nout;
    74     // fprintf (stderr, "%d comp bytes; %d uncomp 'pixels', totals: %d %d\n", Nzdata, Npix, Ninsum, Noutsum);
     79    int status = FALSE;
     80    int Npix = *Nout / out_pixsize;
     81    int k;
    7582
    7683    switch (out_pixsize) {
    7784      case 4:
    7885        // rice decompression from the CFITSIO source tree : we need to tell it the expected number of pixels
    79         // is also REQUIRES 4byte output, which is fairly stupid.
    80         if (fits_rdecomp ((unsigned char *) zdata, Nzdata, (unsigned int *) outdata, Npix, blocksize)) {
    81           fprintf (stderr, "error in rice decompression\n");
    82           return (FALSE);
     86        status = fits_rdecomp ((unsigned char *) zdata, Nzdata, (unsigned int *) outdata, Npix, blocksize);
     87        break;
     88      case 2:
     89        if (0) {
     90          fprintf (stderr, "Nout: %d, Nrawpix: %d\n", Nzdata, Npix);
     91          fprintf (stderr, "cmp out: ");
     92          for (k = 0; k < Nzdata; k++) { fprintf (stderr, "0x%02hhx ", zdata[k]); }
     93          fprintf (stderr, "\n");
    8394        }
    84         return (TRUE);
    85 
    86       case 2:
    87         if (fits_rdecomp_short ((unsigned char *) zdata, Nzdata, (unsigned short *) outdata, Npix, blocksize)) {
    88           fprintf (stderr, "error in rice decompression\n");
    89           return (FALSE);
    90         }
    91         return (TRUE);
    92 
     95        status = fits_rdecomp_short ((unsigned char *) zdata, Nzdata, (unsigned short *) outdata, Npix, blocksize);
     96        break;
    9397      case 1:
    94         if (fits_rdecomp_byte ((unsigned char *) zdata, Nzdata, (unsigned char *) outdata, Npix, blocksize)) {
    95           fprintf (stderr, "error in rice decompression\n");
    96           return (FALSE);
    97         }
    98         return (TRUE);
    99        
     98        status = fits_rdecomp_byte ((unsigned char *) zdata, Nzdata, (unsigned char *) outdata, Npix, blocksize);
     99        break;
    100100      default:
    101101        fprintf (stderr, "invalid output pixel size %d\n", out_pixsize);
    102         return (FALSE);
     102        status = FALSE;
     103        break;
    103104    }
    104    
     105    if (status) {
     106      *Nout = 0;
     107      return FALSE;
     108    }
     109    *Nout = Npix;
     110    return TRUE;
    105111  }
    106112 
Note: See TracChangeset for help on using the changeset viewer.