- Timestamp:
- Jun 3, 2015, 4:10:26 AM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/eam_branches/ohana.20150429/src/libfits/matrix/F_compress_data.c
r38340 r38355 5 5 /* functions defined in ricecomp.c */ 6 6 int fits_rcomp(int a[], int nx, unsigned char *c, int clen, int nblock); 7 int fits_rcomp_short(short a[], int nx, unsigned char *c, int clen, int nblock); 8 int fits_rcomp_byte(char a[], int nx, unsigned char *c, int clen, int nblock); 7 9 int fits_rdecomp (unsigned char *c, int clen, unsigned int array[], int nx, int nblock); 8 10 int fits_rdecomp_short (unsigned char *c, int clen, unsigned short array[], int nx, int nblock); … … 29 31 # define ESCAPE(RET) { fprintf (stderr, "gzip error in %s @ %s:%d\n", __func__, __FILE__, __LINE__); return (RET); } 30 32 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 31 35 int gfits_compress_data (char *zdata, int *Nzdata, char *cmptype, 32 36 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) { 34 39 40 int Nout; 35 41 int status; 36 42 … … 59 65 } 60 66 61 # if (0)62 67 if (!strcasecmp(cmptype, "RICE_1")) { 63 68 int i, blocksize; … … 74 79 } 75 80 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; 82 83 // fprintf (stderr, "%d comp bytes; %d uncomp 'pixels', totals: %d %d\n", Nzdata, Npix, Ninsum, Noutsum); 83 84 84 switch ( out_pixsize) {85 switch (rawpix_size) { 85 86 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; 93 90 94 91 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; 100 94 101 95 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; 107 98 108 99 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; 110 102 return (FALSE); 111 103 } 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; 113 111 } 114 112 115 113 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); 122 118 return (TRUE); 123 119 } 124 120 125 121 if (!strcasecmp(cmptype, "HCOMPRESS_1")) { 126 int Nx, Ny, scale; 122 long Nbytes = Nrawpix * rawpix_size; 123 int scale = 0; 127 124 status = 0; 128 125 // 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 130 134 if (status) { 131 135 fprintf (stderr, "error in hdecompress\n"); … … 134 138 // fprintf (stderr, "decompression yields image %d x %d (scale: %d)\n", Nx, Ny, scale); 135 139 136 if (Nx * Ny != *Nout) { 137 fprintf (stderr, "error in hdecompress: mismatched output size\n"); 138 return (FALSE); 139 } 140 *Nzdata = Nbytes / rawpix_size; 140 141 return (TRUE); 141 142 } 142 # endif143 143 144 144 fprintf (stderr, "unknown compression %s\n", cmptype);
Note:
See TracChangeset
for help on using the changeset viewer.
