Changeset 17660 for trunk/psLib
- Timestamp:
- May 13, 2008, 3:27:25 PM (18 years ago)
- Location:
- trunk/psLib
- Files:
-
- 1 added
- 6 edited
-
src/fits/psFitsImage.c (modified) (7 diffs)
-
src/fits/psFitsScale.c (modified) (12 diffs)
-
src/fits/psFitsScale.h (modified) (1 diff)
-
test/fits (modified) (1 prop)
-
test/fits/.cvsignore (modified) (1 diff)
-
test/fits/Makefile.am (modified) (1 diff)
-
test/fits/tap_psFitsImage.c (added)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/fits/psFitsImage.c
r17447 r17660 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1.2 8$ $Name: not supported by cvs2svn $10 * @date $Date: 2008-0 4-17 23:43:02$9 * @version $Revision: 1.29 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2008-05-14 01:27:25 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 246 246 static psImage *imageToDiskRepresentation(double *bscale, // Scaling applied 247 247 double *bzero, // Zero point applied 248 long *blank, // Blank value (integer data) 248 249 psFitsFloat *floatType, // Type of custom floating-point 249 250 psFits *fits, // FITS file pointer … … 284 285 if (newScaleZero) { 285 286 // Choose an appropriate BSCALE and BZERO 286 if (!psFitsScaleDetermine(bscale, bzero, image, fits)) {287 if (!psFitsScaleDetermine(bscale, bzero, blank, image, fits)) { 287 288 // We can't have the write dying for this reason --- try to save it somehow! 288 289 psWarning("Unable to determine BSCALE and BZERO for image --- setting to 1.0, 0.0"); … … 365 366 psAssert(!output->parent, "impossible"); // No parents means the buffer is contiguous 366 367 368 void *nullValue = NULL; // Null value for data 369 float nullFloat = NAN; // Null value for floating point 370 double nullDouble = NAN; // Null value for double 371 switch (info->psDatatype) { 372 case PS_TYPE_F32: 373 nullValue = &nullFloat; 374 break; 375 case PS_TYPE_F64: 376 nullValue = &nullDouble; 377 break; 378 case PS_TYPE_U8: 379 case PS_TYPE_U16: 380 case PS_TYPE_U32: 381 case PS_TYPE_U64: 382 case PS_TYPE_S8: 383 case PS_TYPE_S16: 384 case PS_TYPE_S32: 385 case PS_TYPE_S64: 386 // Can't mark bad pixels any further than what is in the FITS image 387 break; 388 default: 389 psAbort("Unknown type: %x", info->psDatatype); 390 } 391 367 392 int anynull = 0; // Are there any NULLs in the data? 368 393 int status = 0; // cfitsio status 369 394 if (fits_read_subset(fits->fd, info->fitsDatatype, info->firstPixel, info->lastPixel, 370 info->increment, NULL, output->data.V[0], &anynull, &status) != 0) {395 info->increment, nullValue, output->data.V[0], &anynull, &status) != 0) { 371 396 psFitsError(status, true, "Reading FITS file failed."); 372 397 return false; … … 498 523 499 524 double bscale = 0.0, bzero = 0.0; // Scale and zero point to put in header (*already* applied to data) 525 long blank = 0; // Blank (undefined) value for image 500 526 psFitsFloat floatType; // Custom floating-point convention type 501 psImage *diskImage = imageToDiskRepresentation(&bscale, &bzero, & floatType, fits, image,527 psImage *diskImage = imageToDiskRepresentation(&bscale, &bzero, &blank, &floatType, fits, image, 502 528 NULL, true); // Image to write out 503 529 if (!diskImage) { … … 576 602 } 577 603 604 if (blank != 0) { 605 // Some quantisation has taken place --- record the blank ("magic") pixel value 606 char *keyword = (psFitsCompressionGetType(fits) != PS_FITS_COMPRESS_NONE && 607 (!fits->options || fits->options->conventions.compression)) ? 608 "ZBLANK" : "BLANK"; // Keyword for recording blank pixel value 609 fits_write_key_lng(fits->fd, keyword, blank, "Value for undefined pixels", &status); 610 fits_set_imgnull(fits->fd, blank, &status); 611 if (psFitsError(status, true, "Could not write BLANK header to file.")) { 612 psFree(diskImage); 613 return false; 614 } 615 } 616 578 617 if (floatType != PS_FITS_FLOAT_NONE) { 579 618 psFitsFloatImageSet(fits, floatType); … … 629 668 630 669 double bscale = 0.0, bzero = 0.0; // Scale and zero point to put in header (*already* applied to data) 670 long blank = 0; // Blank (undefined) value for image 631 671 psFitsFloat floatType; // Custom floating-point convention type 632 psImage *diskImage = imageToDiskRepresentation(&bscale, &bzero, & floatType, fits, input,672 psImage *diskImage = imageToDiskRepresentation(&bscale, &bzero, &blank, &floatType, fits, input, 633 673 NULL, false); // Image to write out 634 674 if (!diskImage) { -
trunk/psLib/src/fits/psFitsScale.c
r17447 r17660 46 46 psAssert(options, "impossible"); 47 47 48 double range = pow(2.0, options->bitpix) ; // Range of values for target BITPIX48 double range = pow(2.0, options->bitpix) - 1.0; // Range of values for target BITPIX, reduced by the BLANK 49 49 double min = INFINITY, max = -INFINITY; // Minimum and maximum values 50 50 int numCols = image->numCols, numRows = image->numRows; // Size of image … … 86 86 *bzero = min; 87 87 } else { 88 *bscale = (max - min) / (range - 1.0);88 *bscale = (max - min) / range ; 89 89 *bzero = min + 0.5 * range * (*bscale); 90 90 } … … 157 157 158 158 return true; 159 160 161 return true;162 159 } 163 160 … … 168 165 bool psFitsScaleDetermine(double *bscale, // Scaling, to return 169 166 double *bzero, // Zero point, to return 167 long *blank, // Blank value, to return 170 168 const psImage *image, // Image to scale 171 169 const psFits *fits // FITS options … … 174 172 PS_ASSERT_PTR_NON_NULL(bscale, false); 175 173 PS_ASSERT_PTR_NON_NULL(bzero, false); 174 PS_ASSERT_PTR_NON_NULL(blank, false); 176 175 PS_ASSERT_IMAGE_NON_NULL(image, false); 177 176 PS_ASSERT_FITS_NON_NULL(fits, false); … … 179 178 *bscale = 1.0; 180 179 *bzero = 0.0; 180 *blank = 0; 181 181 182 182 psFitsOptions *options = fits->options; // FITS options … … 201 201 } 202 202 203 *blank = (1 << (options->bitpix - 1)) - 1; 204 203 205 switch (options->scaling) { 204 206 case PS_FITS_SCALE_NONE: … … 229 231 } 230 232 231 psTrace("psLib.fits", 3, "BSCALE = %.10lf, BZERO = %.10lf\n", *bscale, *bzero); 233 if (options->bitpix == 8) { 234 // FITS standard wants unsigned for BITPIX=8, two's-complement for BITPIX=16,32,64. 235 *bzero -= *bscale * 128; 236 *blank = 255; 237 } 238 239 240 psTrace("psLib.fits", 3, "BSCALE = %.10lf, BZERO = %.10lf, BLANK = %ld\n", *bscale, *bzero, *blank); 232 241 return true; 233 242 } … … 252 261 switch (bitpix) { 253 262 case 8: 254 outType = PS_TYPE_S8; 263 // Note: Use unsigned integer for BITPIX=8 264 outType = PS_TYPE_U8; 255 265 break; 256 266 case 16: … … 283 293 #define SCALE_WRITE_OUT_CASE(IN, INTYPE, OUT, OUTTYPE) \ 284 294 case PS_TYPE_##OUTTYPE: { \ 285 ps##INTYPE scale = 1.0 / bscale; \ 286 ps##INTYPE zero = bzero; \ 287 ps##INTYPE min = - (1 << (options->bitpix - 1)); \ 288 ps##INTYPE max = (1 << (options->bitpix - 1)) - 1; \ 295 double scale = 1.0 / bscale; \ 296 double zero = bzero; \ 297 /* Note: BITPIX=8 treated differently, since it uses unsigned values; the rest use signed */ \ 298 double min = bitpix == 8 ? 0 : -pow(2.0, options->bitpix - 1); \ 299 double max = bitpix == 8 ? 255 : (pow(2.0, options->bitpix - 1) - 1.0); \ 289 300 for (int y = 0; y < numRows; y++) { \ 290 301 for (int x = 0; x < numCols; x++) { \ … … 301 312 value += psRandomUniform(rng); \ 302 313 } \ 303 /* Check for underflow and overflow */ \304 (OUT)->data.OUTTYPE[y][x] = (value < min ? min : (value > max ? max : value)); \314 /* Check for underflow and overflow; set either to max */ \ 315 (OUT)->data.OUTTYPE[y][x] = (value < min || value > max ? max : value); \ 305 316 } \ 306 317 } \ … … 312 323 case PS_TYPE_##INTYPE: { \ 313 324 switch (outType) { \ 314 SCALE_WRITE_OUT_CASE(IN, INTYPE, OUT, S8); \325 SCALE_WRITE_OUT_CASE(IN, INTYPE, OUT, U8); \ 315 326 SCALE_WRITE_OUT_CASE(IN, INTYPE, OUT, S16); \ 316 327 SCALE_WRITE_OUT_CASE(IN, INTYPE, OUT, S32); \ -
trunk/psLib/src/fits/psFitsScale.h
r16197 r17660 10 10 bool psFitsScaleDetermine(double *bscale, ///< Scaling, to return 11 11 double *bzero, ///< Zero point, to return 12 long *blank, ///< Blank value, to return 12 13 const psImage *image, ///< Image to scale 13 14 const psFits *fits ///< FITS options -
trunk/psLib/test/fits
- Property svn:ignore
-
old new 13 13 gmon.out 14 14 tap_psFits 15 tap_psFitsImage
-
- Property svn:ignore
-
trunk/psLib/test/fits/.cvsignore
r12556 r17660 13 13 gmon.out 14 14 tap_psFits 15 tap_psFitsImage -
trunk/psLib/test/fits/Makefile.am
r11439 r17660 11 11 12 12 TEST_PROGS = \ 13 tap_psFits 14 tap_psFitsBlank_00 13 tap_psFits \ 14 tap_psFitsBlank_00 \ 15 tap_psFitsImage 15 16 16 17 if BUILD_TESTS
Note:
See TracChangeset
for help on using the changeset viewer.
