IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 28, 2015, 8:27:00 PM (11 years ago)
Author:
eugene
Message:

adding code for table compress/uncompress; image compress works (but is not quite compatible with cfitsio for some reason and byteswap is broken)

File:
1 edited

Legend:

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

    r38322 r38329  
    33# include <zlib.h>
    44
    5 int gfits_compress_data (char *zdata, int *Nzdata, char *cmptype, char **optname, char **optvalue, int Nopt, char *rawdata, int Nraw, int raw_pixsize) {
     5/* functions defined in ricecomp.c */
     6int fits_rcomp(int a[], int nx, unsigned char *c, int clen, int nblock);
     7int fits_rdecomp (unsigned char *c, int clen, unsigned int array[], int nx, int nblock);
     8int fits_rdecomp_short (unsigned char *c, int clen, unsigned short array[], int nx, int nblock);
     9int fits_rdecomp_byte (unsigned char *c, int clen, unsigned char array[], int nx, int nblock);
     10
     11/* functions defined in fits_hcompress.c */
     12# define LONGLONG long long
     13int fits_hcompress(int *a, int ny, int nx, int scale, char *output, long *nbytes, int *status);
     14int fits_hcompress64(LONGLONG *a, int ny, int nx, int scale, char *output, long *nbytes, int *status);
     15
     16/* functions defined in fits_hdeccompress.c */
     17int fits_hdecompress(unsigned char *input, int smooth, int *a, int *ny, int *nx, int *scale, int *status);
     18int fits_hdecompress64(unsigned char *input, int smooth, LONGLONG *a, int *ny, int *nx, int *scale, int *status);
     19
     20/* functions defined in pliocomp.c */
     21int pl_p2li (int *pxsrc, int xs, short *lldst, int npix);
     22int pl_l2pi (short *ll_src, int xs, int *px_dst, int npix);
     23
     24/* functions defined in gzip.c */
     25int gfits_gz_stripheader (unsigned char *data, int *ndata);
     26int gfits_uncompress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);
     27int gfits_compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen);
     28
     29static int pass = 0;
     30
     31int gfits_compress_data (char *zdata, int *Nzdata, char *cmptype,
     32                         char **optname, char **optvalue, int Nopt,
     33                         char *rawdata, int Nrawpix, int rawpix_size) {
    634
    735  int status;
    8   static int Ninsum = 0;
    9   static int Noutsum = 0;
    1036
    1137  if (!strcasecmp(cmptype, "GZIP_1")) {
    12     unsigned long tNraw = Nraw * out_pixsize;
     38    unsigned long Nbytes = Nrawpix * rawpix_size;
    1339
    1440    // the data must be byteswapped before compression begins
    15     if (!gfits_byteswap_zdata (rawdata, Nraw, raw_pixsize)) return (FALSE);
     41    // if (!gfits_byteswap_zdata (rawdata, Nrawpix, rawpix_size)) return (FALSE);
    1642
    1743    // Nzdata is the size of the allocated buffer before the function is called, returns the actual size
    18     // tNraw is the number of bytes in the raw data buffer
    19     status = gfits_compress ((Bytef *) zdata, &Nzdata, (Bytef *) rawdata, tNraw);
     44    // Nbytes is the number of bytes in the raw data buffer
     45    uLongf destLen = *Nzdata;
     46    status = gfits_compress ((Bytef *) zdata, &destLen, (Bytef *) rawdata, Nbytes);
     47    *Nzdata = destLen;
    2048    if (status != Z_OK) {
    2149      fprintf (stderr, "error in compress (GZIP)\n");
     
    2351    }
    2452
     53    // test of deflate (vs I/O)
     54    {
     55      char *srcbuf, *tgtbuf;
     56      ALLOCATE (srcbuf, char, destLen);
     57      memcpy (srcbuf, zdata, destLen);
     58
     59      ALLOCATE (tgtbuf, char, Nbytes);
     60     
     61      uLongf Ndeflate = Nbytes;
     62      status = gfits_uncompress ((Bytef *) tgtbuf, &Ndeflate, (Bytef *) zdata, destLen);
     63      if (status != Z_OK) {
     64        fprintf (stderr, "error in uncompress (GZIP) : %d vs %d\n", status, Z_OK);
     65        return (FALSE);
     66      }
     67     
     68      myAssert (Ndeflate == Nbytes, "invalid output size?");
     69
     70      int i;
     71      for (i = 0; i < Ndeflate; i++) {
     72        myAssert (rawdata[i] == tgtbuf[i], "data mismatch?");
     73      }
     74
     75    }
     76
     77    if (pass == 0) {
     78      int i;
     79      for (i = 0; i < 32; i++) {
     80        fprintf (stderr, "0x%02hhx ", zdata[i]);
     81      }
     82      fprintf (stderr, "\n");
     83      pass = 1;
     84    }
    2585    return (TRUE);
    2686  }
Note: See TracChangeset for help on using the changeset viewer.