IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 3, 2015, 4:10:26 AM (11 years ago)
Author:
eugene
Message:

clarify image vs compression buffer vs compressed pixel sizes to allow hcompress and rice

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branches/ohana.20150429/src/libfits/matrix/F_compress_data.c

    r38340 r38355  
    55/* functions defined in ricecomp.c */
    66int fits_rcomp(int a[], int nx, unsigned char *c, int clen, int nblock);
     7int fits_rcomp_short(short a[], int nx, unsigned char *c, int clen, int nblock);
     8int fits_rcomp_byte(char a[], int nx, unsigned char *c, int clen, int nblock);
    79int fits_rdecomp (unsigned char *c, int clen, unsigned int array[], int nx, int nblock);
    810int fits_rdecomp_short (unsigned char *c, int clen, unsigned short array[], int nx, int nblock);
     
    2931# define ESCAPE(RET) { fprintf (stderr, "gzip error in %s @ %s:%d\n", __func__, __FILE__, __LINE__); return (RET); }
    3032
     33// XXX I'm putting Nx and Ny on the argument list -- only used by hcompress
     34// with a little work, these could go on the option list
    3135int gfits_compress_data (char *zdata, int *Nzdata, char *cmptype,
    3236                         char **optname, char **optvalue, int Nopt,
    33                          char *rawdata, int Nrawpix, int rawpix_size) {
     37                         char *rawdata, int Nrawpix, int rawpix_size,
     38                         int Nx, int Ny) {
    3439
     40  int Nout;
    3541  int status;
    3642
     
    5965  }
    6066
    61 # if (0)
    6267  if (!strcasecmp(cmptype, "RICE_1")) {
    6368    int i, blocksize;
     
    7479    }
    7580
    76     int Npix;
    77     // Npix = *Nout * (out_pixsize / 4.0);
    78     Npix = *Nout;
    79 
    80     Ninsum += Nzdata;
    81     Noutsum += *Nout;
     81    // Ninsum += Nzdata;
     82    // Noutsum += *Nout;
    8283    // fprintf (stderr, "%d comp bytes; %d uncomp 'pixels', totals: %d %d\n", Nzdata, Npix, Ninsum, Noutsum);
    8384
    84     switch (out_pixsize) {
     85    switch (rawpix_size) {
    8586      case 4:
    86         // rice decompression from the CFITSIO source tree : we need to tell it the expected number of pixels
    87         // is also REQUIRES 4byte output, which is fairly stupid.
    88         if (fits_rdecomp ((unsigned char *) zdata, Nzdata, (unsigned int *) outdata, Npix, blocksize)) {
    89           fprintf (stderr, "error in rice decompression\n");
    90           return (FALSE);
    91         }
    92         return (TRUE);
     87        // rice compression from the CFITSIO source tree
     88        Nout = fits_rcomp ((int *) rawdata, Nrawpix, (unsigned char *) zdata, *Nzdata, blocksize);
     89        break;
    9390
    9491      case 2:
    95         if (fits_rdecomp_short ((unsigned char *) zdata, Nzdata, (unsigned short *) outdata, Npix, blocksize)) {
    96           fprintf (stderr, "error in rice decompression\n");
    97           return (FALSE);
    98         }
    99         return (TRUE);
     92        Nout = fits_rcomp_short ((short *) rawdata, Nrawpix, (unsigned char *) zdata, *Nzdata, blocksize);
     93        break;
    10094
    10195      case 1:
    102         if (fits_rdecomp_byte ((unsigned char *) zdata, Nzdata, (unsigned char *) outdata, Npix, blocksize)) {
    103           fprintf (stderr, "error in rice decompression\n");
    104           return (FALSE);
    105         }
    106         return (TRUE);
     96        Nout = fits_rcomp_byte ((char *) rawdata, Nrawpix, (unsigned char *) zdata, *Nzdata, blocksize);
     97        break;
    10798       
    10899      default:
    109         fprintf (stderr, "invalid output pixel size %d\n", out_pixsize);
     100        fprintf (stderr, "invalid output pixel size %d\n", rawpix_size);
     101        *Nzdata = 0;
    110102        return (FALSE);
    111103    }
    112    
     104    if (Nout < 0) {
     105      fprintf (stderr, "error in rice decompression\n");
     106      *Nzdata = 0;
     107      return (FALSE);
     108    }
     109    *Nzdata = Nout;
     110    return TRUE;
    113111  }
    114112 
    115113  if (!strcasecmp(cmptype, "PLIO_1")) {
    116     int Npix;
    117     Npix = pl_l2pi ((short *) zdata, 1, (int *) outdata, *Nout);
    118     if (Npix != *Nout) {
    119       fprintf (stderr, "error in plio decompression\n");
    120       return (FALSE);
    121     }
     114    // note the fortan starting point: zdata is decremented at start
     115    Nout = pl_p2li ((int *) rawdata, 1, (short *) zdata, Nrawpix);
     116    *Nzdata = Nout;
     117    if (!Nout) return (FALSE);
    122118    return (TRUE);
    123119  }
    124120
    125121  if (!strcasecmp(cmptype, "HCOMPRESS_1")) {
    126     int Nx, Ny, scale;
     122    long Nbytes = Nrawpix * rawpix_size;
     123    int scale = 0;
    127124    status = 0;
    128125    // call hdecompress without smoothing
    129     fits_hdecompress ((unsigned char *) zdata, FALSE, (int *) outdata, &Nx, &Ny, &scale, &status);
     126
     127    if (rawpix_size == 4) {
     128      fits_hcompress ((int *) rawdata, Nx, Ny, scale, (char *) zdata, &Nbytes, &status);
     129    }
     130    if (rawpix_size == 8) {
     131      fits_hcompress64 ((long long *) rawdata, Nx, Ny, scale, (char *) zdata, &Nbytes, &status);
     132    }
     133
    130134    if (status) {
    131135      fprintf (stderr, "error in hdecompress\n");
     
    134138    // fprintf (stderr, "decompression yields image %d x %d (scale: %d)\n", Nx, Ny, scale);
    135139   
    136     if (Nx * Ny != *Nout) {
    137       fprintf (stderr, "error in hdecompress: mismatched output size\n");
    138       return (FALSE);
    139     }
     140    *Nzdata = Nbytes / rawpix_size;
    140141    return (TRUE);
    141142  }
    142 # endif
    143143
    144144  fprintf (stderr, "unknown compression %s\n", cmptype);
Note: See TracChangeset for help on using the changeset viewer.