- Timestamp:
- May 28, 2015, 8:27:00 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ohana.20150429/src/libfits/matrix/F_compress_data.c
r38322 r38329 3 3 # include <zlib.h> 4 4 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 */ 6 int fits_rcomp(int a[], int nx, unsigned char *c, int clen, int nblock); 7 int fits_rdecomp (unsigned char *c, int clen, unsigned int array[], int nx, int nblock); 8 int fits_rdecomp_short (unsigned char *c, int clen, unsigned short array[], int nx, int nblock); 9 int 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 13 int fits_hcompress(int *a, int ny, int nx, int scale, char *output, long *nbytes, int *status); 14 int fits_hcompress64(LONGLONG *a, int ny, int nx, int scale, char *output, long *nbytes, int *status); 15 16 /* functions defined in fits_hdeccompress.c */ 17 int fits_hdecompress(unsigned char *input, int smooth, int *a, int *ny, int *nx, int *scale, int *status); 18 int fits_hdecompress64(unsigned char *input, int smooth, LONGLONG *a, int *ny, int *nx, int *scale, int *status); 19 20 /* functions defined in pliocomp.c */ 21 int pl_p2li (int *pxsrc, int xs, short *lldst, int npix); 22 int pl_l2pi (short *ll_src, int xs, int *px_dst, int npix); 23 24 /* functions defined in gzip.c */ 25 int gfits_gz_stripheader (unsigned char *data, int *ndata); 26 int gfits_uncompress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen); 27 int gfits_compress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen); 28 29 static int pass = 0; 30 31 int gfits_compress_data (char *zdata, int *Nzdata, char *cmptype, 32 char **optname, char **optvalue, int Nopt, 33 char *rawdata, int Nrawpix, int rawpix_size) { 6 34 7 35 int status; 8 static int Ninsum = 0;9 static int Noutsum = 0;10 36 11 37 if (!strcasecmp(cmptype, "GZIP_1")) { 12 unsigned long tNraw = Nraw * out_pixsize;38 unsigned long Nbytes = Nrawpix * rawpix_size; 13 39 14 40 // 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); 16 42 17 43 // 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; 20 48 if (status != Z_OK) { 21 49 fprintf (stderr, "error in compress (GZIP)\n"); … … 23 51 } 24 52 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 } 25 85 return (TRUE); 26 86 }
Note:
See TracChangeset
for help on using the changeset viewer.
