Changeset 16095
- Timestamp:
- Jan 16, 2008, 10:10:35 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/psLib/src/fits/psFitsImage.c (modified) (15 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/src/fits/psFitsImage.c
r15920 r16095 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1.2 2$ $Name: not supported by cvs2svn $10 * @date $Date: 200 7-12-25 01:31:21$9 * @version $Revision: 1.23 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2008-01-16 20:10:35 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 243 243 # if (0) 244 244 // XXX this needs to be optional (eg, invalid for a mask) 245 // Apply the BSCALE and BZERO for an image with a "fuzz" 245 246 // Apply the BSCALE and BZERO for an image with a "fuzz", so that we get the image as it should be written to 247 // disk. 246 248 // The idea is that the "fuzz" (adding a random number between 0 and 1) preserves the expectation value of 247 249 // the image (e.g., a value of 0.1 will get translated to zero 90% of the time, and unity 10% of the time), 248 250 // though at the cost of adding an additional variance of 1/12 (a standard deviation of ~0.29). 249 static psImage *scaleImage Write(psImage *image, // Image to which to apply BSCALE and BZERO250 int bitpix, // Output BITPIX251 double bscale, // Scaling252 double bzero, // Zero point253 psRandom *rng // Random number generator (for the "fuzz"), or NULL254 )251 static psImage *scaleImageForDisk(psImage *image, // Image to which to apply BSCALE and BZERO 252 int bitpix, // Output BITPIX 253 double bscale, // Scaling 254 double bzero, // Zero point 255 psRandom *rng // Random number generator (for the "fuzz"), or NULL 256 ) 255 257 { 256 258 assert(image); … … 339 341 // Determine BSCALE and BZERO for an image, and generate a new image with it applied 340 342 // TRUE = BZERO + BSCALE * FITS 341 static psImage *scaleImageDetermine Write(double *bscale, // Scaling, to return342 double *bzero, // Zero point, to return343 psImage *image, // Image to scale344 int bitpix, // Desired bits per pixel345 psRandom *rng // Random number generator for scaleImageWrite346 )343 static psImage *scaleImageDetermine(double *bscale, // Scaling, to return 344 double *bzero, // Zero point, to return 345 psImage *image, // Image to scale 346 int bitpix, // Desired bits per pixel 347 psRandom *rng // Random number generator for scaleImageForDisk 348 ) 347 349 { 348 350 PS_ASSERT_PTR_NON_NULL(bscale, NULL); … … 412 414 psTrace("psLib.fits", 3, "BSCALE = %.10lf, BZERO = %.10lf\n", *bscale, *bzero); 413 415 414 return scaleImage Write(image, bitpix, *bscale, *bzero, rng);416 return scaleImageForDisk(image, bitpix, *bscale, *bzero, rng); 415 417 } 416 418 # endif … … 420 422 // the present time, since cfitsio should apply the scaling itself in the process of reading. However, we may 421 423 // later desire it. 422 static psImage *scaleImage Read(psFits *fits, psImage *image)424 static psImage *scaleImageFromDisk(psFits *fits, psImage *image) 423 425 { 424 426 PS_ASSERT_IMAGE_NON_NULL(image, NULL); … … 500 502 #endif 501 503 502 // Convert an image to the desired BITPIX 503 static psImage * convertImageWrite(double *bscale, // Scaling applied504 double *bzero, // Zero point applied505 psFitsFloat *floatType, // Type of custom floating-point506 psFits *fits, // FITS file pointer507 const psImage *image, // Current type508 psRandom *rng, // Random number generator509 bool newScaleZero // Determine a new BSCALE and BZERO?510 )504 // Convert an image to the desired BITPIX, i.e., the desired disk representation 505 static psImage *imageToDiskRepresentation(double *bscale, // Scaling applied 506 double *bzero, // Zero point applied 507 psFitsFloat *floatType, // Type of custom floating-point 508 psFits *fits, // FITS file pointer 509 const psImage *image, // Current type 510 psRandom *rng, // Random number generator 511 bool newScaleZero // Determine a new BSCALE and BZERO? 512 ) 511 513 { 512 514 assert(bscale); … … 524 526 fits->floatType != PS_FITS_FLOAT_NONE) { 525 527 *floatType = fits->floatType; 526 return psFitsFloatImage Write(image, fits->floatType);528 return psFitsFloatImageToDisk(image, fits->floatType); 527 529 } 528 530 … … 537 539 if (PS_IS_PSELEMTYPE_REAL(image->type.type) && fits->bitpix > 0) { 538 540 if (newScaleZero) { 539 return scaleImageDetermine Write(bscale, bzero, (psImage*)image, fits->bitpix, rng);541 return scaleImageDetermine(bscale, bzero, (psImage*)image, fits->bitpix, rng); 540 542 } 541 543 // Get the current BSCALE and BZERO … … 556 558 return NULL; 557 559 } 558 return scaleImage Write((psImage*)image, fits->bitpix, *bscale, *bzero, rng);560 return scaleImageForDisk((psImage*)image, fits->bitpix, *bscale, *bzero, rng); 559 561 } 560 562 # endif … … 655 657 656 658 if (floatType != PS_FITS_FLOAT_NONE) { 657 outImage = psFitsFloatImage Read(outImage, inImage, floatType);659 outImage = psFitsFloatImageFromDisk(outImage, inImage, floatType); 658 660 } 659 661 psFree(inImage); … … 707 709 708 710 if (floatType != PS_FITS_FLOAT_NONE) { 709 outImage = psFitsFloatImage Read(outImage, inImage, floatType);711 outImage = psFitsFloatImageFromDisk(outImage, inImage, floatType); 710 712 } 711 713 psFree(inImage); … … 742 744 double bscale = 0.0, bzero = 0.0; // Scale and zero point to put in header (*already* applied to data) 743 745 psFitsFloat floatType; // Custom floating-point convention type 744 psImage *diskImage = convertImageWrite(&bscale, &bzero, &floatType, fits, image,745 NULL, true); // Image to write out746 psImage *diskImage = imageToDiskRepresentation(&bscale, &bzero, &floatType, fits, image, 747 NULL, true); // Image to write out 746 748 if (!diskImage) { 747 749 psError(PS_ERR_UNKNOWN, false, "Unable to convert image to desired disk format."); … … 758 760 } 759 761 if (cfitsioBzero != 0.0) { 760 assert(bzero == 0.0 && bscale == 1.0); // p_psFitsTypeToCfitsio and convertImageWrite must not clash 762 // p_psFitsTypeToCfitsio and imageToDiskRepresentation must not clash! 763 assert(bzero == 0.0 && bscale == 1.0); 761 764 bscale = 1.0; 762 765 bzero = cfitsioBzero; … … 871 874 double bscale = 0.0, bzero = 0.0; // Scale and zero point to put in header (*already* applied to data) 872 875 psFitsFloat floatType; // Custom floating-point convention type 873 psImage *diskImage = convertImageWrite(&bscale, &bzero, &floatType, fits, input,874 NULL, false); // Image to write out876 psImage *diskImage = imageToDiskRepresentation(&bscale, &bzero, &floatType, fits, input, 877 NULL, false); // Image to write out 875 878 if (!diskImage) { 876 879 psError(PS_ERR_UNKNOWN, false, "Unable to convert image to desired disk format."); … … 882 885 double cfitsioBzero = 0.0; // Zero point for cfitsio to apply 883 886 int dataType; // cfitsio data type 884 if (! p_psFitsTypeToCfitsio(diskImage->type.type, &bitPix, &cfitsioBzero, &dataType)) {887 if (!p_psFitsTypeToCfitsio(diskImage->type.type, &bitPix, &cfitsioBzero, &dataType)) { 885 888 psFree(diskImage); 886 889 return false; 887 890 } 888 891 if (cfitsioBzero != 0.0) { 889 assert(bzero == 0.0 && bscale == 1.0); // p_psFitsTypeToCfitsio and convertImageWrite must not clash 892 // p_psFitsTypeToCfitsio and imageToDiskRepresentation must not clash! 893 assert(bzero == 0.0 && bscale == 1.0); 890 894 bscale = 1.0; 891 895 bzero = cfitsioBzero;
Note:
See TracChangeset
for help on using the changeset viewer.
