Changeset 41474 for trunk/Ohana/src/libfits/matrix/F_uncompress_M.c
- Timestamp:
- Jan 24, 2021, 3:37:52 PM (5 years ago)
- File:
-
- 1 edited
-
trunk/Ohana/src/libfits/matrix/F_uncompress_M.c (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Ohana/src/libfits/matrix/F_uncompress_M.c
r40549 r41474 40 40 gfits_modify (header, NAME, TYPE, 1, OUT); } 41 41 42 # define DUMP_ROWBYTES(BUF, INFO) \ 43 if (VERBOSE_DUMP && (row == 0)) { \ 44 int k; \ 45 fprintf (stderr, "%s: ", INFO); \ 46 for (k = 0; k < 64; k++) { \ 47 fprintf (stderr, "%02hhx", BUF[k]); \ 48 if (k % 4 == 3) fprintf (stderr, " "); \ 49 } fprintf (stderr, "\n"); } 50 42 51 int gfits_uncompress_image (Header *header, Matrix *matrix, FTable *ftable) { 43 52 … … 97 106 } else { 98 107 gfits_delete (header, "ZTILE1", 1); 108 // if ZTILE1 exists, all ZTILEn must exist: 99 109 for (axis = 1; axis < header->Naxes; axis++) { 100 110 snprintf (key, 10, "ZTILE%d", axis + 1); … … 127 137 } 128 138 129 // XXX get ZMASKCMP 130 int zsimple, have_zsimple; 131 int have_ztension; 139 // check for ZMASKCMP (not yet supported 2021.01.23) 140 char zmaskcmp[81]; 141 int have_zmaskcmp = gfits_scan (header, "ZMASKCMP", "%s", 1, zmaskcmp); 142 if (have_zmaskcmp) { 143 fprintf (stderr, "null pixels were compressed with %s, not implemented in Ohana\n", zmaskcmp); 144 ESCAPE; 145 } 132 146 133 147 // NOTE target of %t must be int length 134 have_zsimple = gfits_scan_alt (header, "ZSIMPLE", "%t", 1, &zsimple); 135 have_ztension = gfits_scan (header, "ZTENSION", "%s", 1, exttype); 136 137 // this is a very bogus case: we cannot have both keywords 148 int zsimple; 149 int have_zsimple = gfits_scan_alt (header, "ZSIMPLE", "%t", 1, &zsimple); 150 int have_ztension = gfits_scan (header, "ZTENSION", "%s", 1, exttype); 151 152 // this is a bogus case: we cannot have both keywords 138 153 if (have_zsimple && have_ztension) ESCAPE; 139 154 … … 179 194 } 180 195 } else { 196 // if this is a PHU (whether or not ZSIMPLE is present), PCOUNT & GCOUNT must be basic (0,1) 181 197 header->pcount = 0; 182 198 header->gcount = 1; … … 188 204 MOD_KEYWORD ("ZDATASUM", "DATASUM", "%s", datasum, datasum); 189 205 190 zscale = 1; 191 gfits_scan (header, "ZSCALE", "%f", 1, &zscale); 192 193 zblank = 32767; 194 gfits_scan (header, "ZBLANK", "%d", 1, &zblank); 195 196 oblank = 32767; 197 gfits_scan (header, "BLANK", "%d", 1, &oblank); 198 199 zzero = 0; 200 gfits_scan (header, "ZZERO", "%f", 1, &zzero); 206 // get other basic keywords (default values supplied) 207 zscale = 1; gfits_scan (header, "ZSCALE", "%f", 1, &zscale); 208 zblank = 32767; gfits_scan (header, "ZBLANK", "%d", 1, &zblank); 209 oblank = 32767; gfits_scan (header, "BLANK", "%d", 1, &oblank); 210 zzero = 0; gfits_scan (header, "ZZERO", "%f", 1, &zzero); 201 211 202 212 // find the COMPRESSED_DATA column (format should be 1PB, 1PI, 1PJ) 203 // is it required that this be the only column?213 // XXX is it required that this be the only column? -- not if ZMASKCMP exists (not yet supported) 204 214 int colnum; 205 215 for (colnum = 1; TRUE; colnum++) { … … 242 252 243 253 // heapdata.pixsize : zdef.format 244 // zdata.pixsize : depends on compression 245 // odata.pixsize : depends on compression 246 // idata.pixsize : header.bitpix254 // zdata.pixsize : depends on compression method (cmp_pixsize below) 255 // odata.pixsize : depends on compression method (raw_pixsize below) 256 // idata.pixsize : depends on header.bitpix 247 257 248 258 // size of an element in the vartable heap section 249 259 // zdata_pixsize = gfits_vartable_heap_pixsize (zdef.format); XXX 250 260 251 // size of a pixel in the output from the decompression routine 261 // depending on the compression method, the data may need to be byteswapped either before 262 // or after uncompression: 263 264 // size of a pixel in the compressed data (cmp_pixsize), used for byteswap below 252 265 int cmp_pixsize = gfits_compressed_data_pixsize (cmptype, header[0].bitpix, optname, optvalue, Noptions); 253 int raw_bitpix = gfits_uncompressed_data_bitpix (cmptype, header[0].bitpix, optname, optvalue, Noptions); 254 int raw_pixsize = gfits_uncompressed_data_pixsize (cmptype, header[0].bitpix, optname, optvalue, Noptions); 266 267 // size of a pixel in the raw uncomprssed buffer (raw_pixsize) after uncompression (last option says RICE ignores bitpix) 268 int raw_pixsize = gfits_uncompressed_data_pixsize (cmptype, header[0].bitpix, optname, optvalue, Noptions, FALSE); 269 270 // we also need the bitpix value for the raw uncompressed buffer to distinguish int and floats 271 int raw_bitpix = gfits_uncompressed_data_bitpix (cmptype, header[0].bitpix, optname, optvalue, Noptions, FALSE); 255 272 256 273 // size of a pixel in the final image (not needed) … … 261 278 ALLOCATE (out, char, Nout_alloc); 262 279 263 off_t row;264 265 if (VERBOSE_DUMP) {266 int k;267 fprintf (stderr, "unc tbl: ");268 for (k = 0; k < 64; k++) { fprintf (stderr, "%02hhx", ftable->buffer[k]); if (k % 4 == 3) fprintf (stderr, " "); }269 fprintf (stderr, "\n");270 }271 272 280 // uncompress the data 273 281 Nzrows = ftable->header->Naxis[1]; 274 for (row = 0; row < Nzrows; row++) { 282 for (off_t row = 0; row < Nzrows; row++) { 283 284 DUMP_ROWBYTES (ftable->buffer, "tbl dat"); 275 285 276 286 // expected output size for this tile … … 280 290 if (!zdata) ESCAPE; 281 291 282 if (VERBOSE_DUMP && (row == 0)) { 283 int k; 284 fprintf (stderr, "unc dat: "); 285 for (k = 0; k < 64; k++) { fprintf (stderr, "%02hhx", zdata[k]); if (k % 4 == 3) fprintf (stderr, " "); } 286 fprintf (stderr, "\n"); 287 } 288 289 if (strcasecmp(cmptype, "NONE_2") && // strcasecmp(cmptype, "NONE") && 290 strcasecmp(cmptype, "GZIP_1") && 291 strcasecmp(cmptype, "GZIP_2") && 292 strcasecmp(cmptype, "RICE_1") && 293 strcasecmp(cmptype, "RICE_ONE")) { 294 // Nzdata is number of bytes 295 if (!gfits_byteswap_zdata (zdata, Nzdata, cmp_pixsize)) ESCAPE; 296 } 297 298 if (VERBOSE_DUMP && (row == 0)) { 299 int k; 300 fprintf (stderr, "unc SWP: "); 301 for (k = 0; k < 64; k++) { fprintf (stderr, "%02hhx", zdata[k]); if (k % 4 == 3) fprintf (stderr, " "); } 302 fprintf (stderr, "\n"); 303 fprintf (stderr, "Nout : %lu -> ", Nout); 304 } 292 DUMP_ROWBYTES (zdata, "cmp dat"); 293 294 // byteswap the compressed data before uncompressing. 295 // compression algorithms which do not need to byteswap here return 1 for cmp_pixsize 296 if (!gfits_byteswap_zdata (zdata, Nzdata, cmp_pixsize)) ESCAPE; 297 298 DUMP_ROWBYTES (zdata, "cmp swp"); 305 299 306 300 // gfits_uncompress_data uncompresses from zdata to the temporary output buffer which must be allocated 307 // XXXthe tile must not be > 2GB308 // Nout going in is number of bytes301 // Note: the tile must not be > 2GB 302 // Nout going in is the expected number of bytes 309 303 if (!gfits_uncompress_data ((char *)zdata, Nzdata, cmptype, optname, optvalue, Noptions, out, &Nout, Nout_alloc, raw_pixsize)) ESCAPE; 310 304 311 if (VERBOSE_DUMP && (row == 0)) { 312 int k; 313 fprintf (stderr, "%lu\n", Nout); 314 fprintf (stderr, "unc swp: "); 315 for (k = 0; k < 64; k++) { fprintf (stderr, "%02hhx", out[k]); if (k % 4 == 3) fprintf (stderr, " "); } 316 fprintf (stderr, "\n"); 317 } 305 DUMP_ROWBYTES (out, "unc swp"); 318 306 319 307 if (!strcasecmp(cmptype, "GZIP_1")) { … … 322 310 } 323 311 324 if (VERBOSE_DUMP && (row == 0)) { 325 int k; 326 fprintf (stderr, "unc raw: "); 327 for (k = 0; k < 64; k++) { fprintf (stderr, "%02hhx", out[k]); if (k % 4 == 3) fprintf (stderr, " "); } 328 fprintf (stderr, "\n"); 329 } 312 DUMP_ROWBYTES (out, "unc raw"); 330 313 331 314 // copy the uncompressed pixels into their correct locations … … 336 319 } 337 320 338 if (VERBOSE_DUMP && (row == 0)) { 339 int k; 340 fprintf (stderr, "unc mat: "); 341 for (k = 0; k < 64; k++) { fprintf (stderr, "%02hhx", matrix->buffer[k]); if (k % 4 == 3) fprintf (stderr, " "); } 342 fprintf (stderr, "\n"); 343 } 321 DUMP_ROWBYTES (matrix->buffer, "out raw"); 344 322 345 323 // update the tile counters, carrying to the next dimension if needed … … 370 348 } 371 349 372 // bitpix is the input data size/type 350 // raw_bitpix is the data size/type for the temporary buffer of uncompressed data 351 // matrix->bitpix is the data size/type of the output image data 373 352 int gfits_distribute_data (Matrix *matrix, char *raw, unsigned long int Nraw, int raw_bitpix, int *otile, int oblank, unsigned long int *ztile, int zblank, float zscale, float zzero) { 374 353 … … 514 493 } 515 494 516 // bitpix is the input data size/type 495 // raw_bitpix is the data size/type for the temporary buffer of uncompressed data 496 // matrix->bitpix is the data size/type of the output image data 497 // The gzip2 algorithm organizes the compressed data in groups by significant byte sequence (most significant byte of all pixels first, etc). 498 // gfits_distribute_gzp2 needs to shuffle the bytes back into the correct location in the tile. 517 499 int gfits_distribute_gzp2 (Matrix *matrix, char *raw, unsigned long int Nraw, int raw_bitpix, int *otile, int oblank, unsigned long int *ztile, int zblank, float zscale, float zzero) { 500 // unused parameters are supplied to make this function have the same API as gfits_distribute_data() 518 501 OHANA_UNUSED_PARAM(oblank); 519 502 OHANA_UNUSED_PARAM(zblank);
Note:
See TracChangeset
for help on using the changeset viewer.
