Changeset 38441 for trunk/Ohana/src/libfits/matrix/F_uncompress_data.c
- Timestamp:
- Jun 12, 2015, 6:18:23 PM (11 years ago)
- Location:
- trunk/Ohana
- Files:
-
- 2 edited
-
. (modified) (1 prop)
-
src/libfits/matrix/F_uncompress_data.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana
-
Property svn:mergeinfo
set to
/branches/eam_branches/ohana.20150429 merged eligible
-
Property svn:mergeinfo
set to
-
trunk/Ohana/src/libfits/matrix/F_uncompress_data.c
r23815 r38441 26 26 int gfits_uncompress (Bytef *dest, uLongf *destLen, const Bytef *source, uLong sourceLen); 27 27 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 30 int 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) { 29 31 30 32 int status; 31 static int Ninsum = 0;32 static int Noutsum = 0;33 33 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; 36 46 37 47 // 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); 39 50 40 51 // 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 41 53 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"); 46 56 *Nout = tNout / out_pixsize; 57 // output value of *Nout is number of PIXELS 47 58 48 59 // 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); 50 61 51 62 return (TRUE); 52 63 } 53 64 54 if (!strcasecmp(cmptype, "RICE_1") ) {65 if (!strcasecmp(cmptype, "RICE_1") || !strcasecmp(cmptype, "RICE_ONE")) { 55 66 int i, blocksize; 56 67 // look for the BLOCKSIZE … … 66 77 } 67 78 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; 75 82 76 83 switch (out_pixsize) { 77 84 case 4: 78 85 // 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"); 83 94 } 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; 93 97 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; 100 100 default: 101 101 fprintf (stderr, "invalid output pixel size %d\n", out_pixsize); 102 return (FALSE); 102 status = FALSE; 103 break; 103 104 } 104 105 if (status) { 106 *Nout = 0; 107 return FALSE; 108 } 109 *Nout = Npix; 110 return TRUE; 105 111 } 106 112
Note:
See TracChangeset
for help on using the changeset viewer.
