- 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_uncompress_M.c
r38340 r38355 46 46 float zscale, zzero; 47 47 48 int zdata_pixsize, odata_pixsize;49 50 48 int *ztile = NULL; 51 49 int *otile = NULL; … … 242 240 243 241 // size of an element in the vartable heap section 244 zdata_pixsize = gfits_vartable_heap_pixsize (zdef.format);242 // zdata_pixsize = gfits_vartable_heap_pixsize (zdef.format); XXX 245 243 246 244 // size of a pixel in the final image (not needed) … … 248 246 249 247 // size of a pixel in the output from the decompression routine 250 odata_pixsize = gfits_uncompressed_data_pixsize (cmptype, header[0].bitpix, optname, optvalue, Noptions); 251 252 int Nout_alloc = odata_pixsize*max_tile_size; 248 int cmp_pixsize = gfits_compressed_data_pixsize (cmptype, header[0].bitpix, optname, optvalue, Noptions); 249 int raw_bitpix = gfits_uncompressed_data_bitpix (cmptype, header[0].bitpix, optname, optvalue, Noptions); 250 int raw_pixsize = gfits_uncompressed_data_pixsize (cmptype, header[0].bitpix, optname, optvalue, Noptions); 251 252 int Nout_alloc = raw_pixsize*max_tile_size; 253 253 ALLOCATE (out, char, Nout_alloc); 254 254 255 255 off_t row; 256 257 if (0) { 258 int k; 259 fprintf (stderr, "unc tbl: "); 260 for (k = 0; k < 32; k++) { fprintf (stderr, "0x%02hhx ", ftable->buffer[k]); } 261 fprintf (stderr, "\n"); 262 } 256 263 257 264 // uncompress the data … … 266 273 if (!zdata) ESCAPE; 267 274 268 // XXX not certain this is the correct place to do the swap (or if zdata_pixsize is269 // the correct size to guide the swap)270 271 275 if (strcasecmp(cmptype, "GZIP_1")) { 272 if (!gfits_byteswap_zdata (zdata, Nzdata, zdata_pixsize)) ESCAPE; 276 if (!gfits_byteswap_zdata (zdata, Nzdata, cmp_pixsize)) ESCAPE; 277 } 278 279 if (0 && (row == 0)) { 280 int k; 281 fprintf (stderr, "unc dat: "); 282 for (k = 0; k < 32; k++) { fprintf (stderr, "0x%02hhx ", zdata[k]); } 283 fprintf (stderr, "\n"); 273 284 } 274 285 275 286 // gfits_uncompress_data uncompresses from zdata to the temporary output buffer which must be allocated 276 287 // XXX the tile must not be > 2GB 277 if (!gfits_uncompress_data ((char *)zdata, Nzdata, cmptype, optname, optvalue, Noptions, out, &Nout, odata_pixsize)) ESCAPE; 278 288 if (!gfits_uncompress_data ((char *)zdata, Nzdata, cmptype, optname, optvalue, Noptions, out, &Nout, raw_pixsize)) ESCAPE; 289 290 if (0 && (row == 0)) { 291 int k; 292 fprintf (stderr, "unc swp: "); 293 for (k = 0; k < 32; k++) { fprintf (stderr, "0x%02hhx ", out[k]); } 294 fprintf (stderr, "\n"); 295 } 296 279 297 if (!strcasecmp(cmptype, "GZIP_1")) { 280 if (!gfits_byteswap_zdata (out, Nout, odata_pixsize)) ESCAPE; 298 if (!gfits_byteswap_zdata (out, Nout, raw_pixsize)) ESCAPE; 299 } 300 301 if (0 && (row == 0)) { 302 int k; 303 fprintf (stderr, "unc raw: "); 304 for (k = 0; k < 32; k++) { fprintf (stderr, "0x%02hhx ", out[k]); } 305 fprintf (stderr, "\n"); 281 306 } 282 307 283 308 // copy the uncompressed pixels into their correct locations 284 if (!gfits_distribute_data (matrix, odata_pixsize, out, Nout, otile, oblank, ztile, zblank, zscale, zzero)) ESCAPE; 309 if (!gfits_distribute_data (matrix, out, Nout, raw_bitpix, otile, oblank, ztile, zblank, zscale, zzero)) ESCAPE; 310 311 if (0 && (row == 0)) { 312 int k; 313 fprintf (stderr, "unc mat: "); 314 for (k = 0; k < 32; k++) { fprintf (stderr, "0x%02hhx ", matrix->buffer[k]); } 315 fprintf (stderr, "\n"); 316 } 285 317 286 318 // update the tile counters, carrying to the next dimension if needed … … 311 343 312 344 // bitpix is the input data size/type 313 int gfits_distribute_data (Matrix *matrix, int bitpix, char *data, int Ndata, int *otile, int oblank, int *ztile, int zblank, float zscale, float zzero) {345 int gfits_distribute_data (Matrix *matrix, char *raw, int Nraw, int raw_bitpix, int *otile, int oblank, int *ztile, int zblank, float zscale, float zzero) { 314 346 315 347 int i, j, start, offset, coord, Nline; … … 334 366 335 367 // double check reported size (needs the Isize) 336 assert (N data== Ztile[0]*Nline);368 assert (Nraw == Ztile[0]*Nline); 337 369 338 370 // set the starting point of the tile: … … 350 382 // we need to set up switches for all of the possible combinations: 351 383 // this macro is used at the inner switch to run the actual loop 352 # define SCALE_AND_DIST (TYPE, SIZE) {\353 TYPE * Optr = (TYPE *) &matrix->buffer[SIZE*(offset + start)];\354 for (j = 0; j < Ztile[0]; j++, Iptr++, Optr++) {\355 if (* Iptr == zblank) {\356 *Optr = oblank;\357 } else { \358 *Optr = *Iptr * zscale + zzero;\384 # define SCALE_AND_DIST_INT(TYPE, SIZE) { \ 385 TYPE *TILEptr = (TYPE *) &matrix->buffer[SIZE*(offset + start)]; \ 386 for (j = 0; j < Ztile[0]; j++, TILEptr++, RAWptr++) { \ 387 if (*TILEptr == zblank) { \ 388 *TILEptr = oblank; \ 389 } else { \ 390 *TILEptr = *RAWptr * zscale + zzero; \ 359 391 } } } 360 392 393 // we need to set up switches for all of the possible combinations: 394 // this macro is used at the inner switch to run the actual loop 395 # define SCALE_AND_DIST_FLOAT(TYPE, SIZE) { \ 396 TYPE *TILEptr = (TYPE *) &matrix->buffer[SIZE*(offset + start)]; \ 397 for (j = 0; j < Ztile[0]; j++, TILEptr++, RAWptr++) { \ 398 if (!isfinite(*TILEptr)) { \ 399 *TILEptr = oblank; \ 400 } else { \ 401 *TILEptr = *RAWptr * zscale + zzero; \ 402 } } } 403 361 404 // this macro sets up the outer switch and calls above macro with all output bitpix options 362 # define SETUP_INSIZE(TYPE, SIZE) { \ 363 TYPE *Iptr = (TYPE *) &data[i*SIZE*Ztile[0]]; \ 364 switch (matrix->bitpix) { \ 365 case 8: \ 366 SCALE_AND_DIST (char, 1); \ 367 break; \ 368 case 16: \ 369 SCALE_AND_DIST (short, 2); \ 370 break; \ 371 case 32: \ 372 SCALE_AND_DIST (int, 4); \ 373 break; \ 374 case -32: \ 375 SCALE_AND_DIST (float, 4); \ 376 break; \ 377 case -64: \ 378 SCALE_AND_DIST (double, 8); \ 379 break; \ 380 default: \ 381 abort(); \ 405 # define SETUP_RAWSIZE(TYPE, SIZE) { \ 406 TYPE *RAWptr = (TYPE *) &raw[i*SIZE*Ztile[0]]; \ 407 switch (matrix->bitpix) { \ 408 case 8: SCALE_AND_DIST_INT (char, 1); break; \ 409 case 16: SCALE_AND_DIST_INT (short, 2); break; \ 410 case 32: SCALE_AND_DIST_INT (int, 4); break; \ 411 case -32: SCALE_AND_DIST_FLOAT (float, 4); break; \ 412 case -64: SCALE_AND_DIST_FLOAT (double, 8); break; \ 413 default: abort(); \ 382 414 } } 383 415 384 416 // loop over lines in the tile 385 417 for (i = 0; i < Nline; i++) { 386 switch (bitpix) { 387 case 1: 388 SETUP_INSIZE (char, 1); 389 break; 390 case 2: 391 SETUP_INSIZE (short, 2); 392 break; 393 case 4: 394 SETUP_INSIZE (int, 4); 395 break; 396 case 8: 397 SETUP_INSIZE (double, 8); 398 break; 399 default: 400 abort(); 418 switch (raw_bitpix) { 419 case 8: SETUP_RAWSIZE (char, 1); break; 420 case 16: SETUP_RAWSIZE (short, 2); break; 421 case 32: SETUP_RAWSIZE (int, 4); break; 422 case -32: SETUP_RAWSIZE (float, 4); break; 423 case -64: SETUP_RAWSIZE (double, 8); break; 424 default: abort(); 401 425 } 402 426
Note:
See TracChangeset
for help on using the changeset viewer.
