Changeset 19383 for trunk/psLib/src/fits/psFitsImage.c
- Timestamp:
- Sep 4, 2008, 9:51:09 PM (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
r19270 r19383 7 7 * @author Robert DeSonia, MHPCC 8 8 * 9 * @version $Revision: 1.3 8$ $Name: not supported by cvs2svn $10 * @date $Date: 2008-0 8-29 01:01:39 $9 * @version $Revision: 1.39 $ $Name: not supported by cvs2svn $ 10 * @date $Date: 2008-09-05 07:51:09 $ 11 11 * 12 12 * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii … … 28 28 #include "psLogMsg.h" 29 29 #include "psTrace.h" 30 #include "psVector.h"31 30 #include "psRandom.h" 31 #include "psImage.h" 32 32 #include "psImageStructManip.h" 33 33 … … 249 249 psFitsFloat *floatType, // Type of custom floating-point 250 250 psFits *fits, // FITS file pointer 251 const psImage *image, // Current type 251 const psImage *image, // Image to convert 252 const psImage *mask, // Mask image, or NULL 253 psMaskType maskVal, // Value to mask 252 254 psRandom *rng, // Random number generator 253 255 bool newScaleZero // Determine a new BSCALE and BZERO? … … 285 287 if (newScaleZero) { 286 288 // Choose an appropriate BSCALE and BZERO 287 if (!psFitsScaleDetermine(bscale, bzero, blank, image, fits)) {289 if (!psFitsScaleDetermine(bscale, bzero, blank, image, mask, maskVal, fits)) { 288 290 // We can't have the write dying for this reason --- try to save it somehow! 289 291 psWarning("Unable to determine BSCALE and BZERO for image --- refusing to quantise."); … … 404 406 } 405 407 406 psImage *psFitsReadImage(const psFits *fits, // the psFits object408 psImage *psFitsReadImage(const psFits *fits, // the psFits object 407 409 psRegion region, // the region in the FITS image to read 408 410 int z // the z-plane in the FITS image cube to read … … 445 447 } 446 448 447 psImage *psFitsReadImageBuffer(psImage *outImage, // Output image buffer449 psImage *psFitsReadImageBuffer(psImage *outImage, // Output image buffer 448 450 const psFits *fits, // the psFits object 449 451 psRegion region, // the region in the FITS image to read … … 497 499 } 498 500 499 bool psFitsWriteImage(psFits* fits, 500 psMetadata* header, 501 const psImage* input, 502 int numZPlanes, 503 const char* extname) 501 bool psFitsWriteImage(psFits *fits, psMetadata *header, const psImage *input, 502 int numZPlanes, const char *extname) 503 { 504 return psFitsWriteImageWithMask(fits, header, input, NULL, 0, numZPlanes, extname); 505 } 506 507 bool psFitsWriteImageWithMask(psFits *fits, psMetadata *header, const psImage *input, 508 const psImage *mask, psMaskType maskVal, int numZPlanes, 509 const char *extname) 504 510 { 505 511 PS_ASSERT_FITS_NON_NULL(fits, false); … … 509 515 510 516 psFitsMoveLast(fits); 511 return psFitsInsertImage(fits,header,input,numZPlanes,extname,true); 512 } 513 514 bool psFitsInsertImage(psFits* fits, psMetadata* header, const psImage* image, int numZPlanes, 515 const char* extname, bool after) 517 return psFitsInsertImageWithMask(fits, header, input, mask, maskVal, numZPlanes, extname, true); 518 } 519 520 bool psFitsInsertImage(psFits *fits, psMetadata *header, const psImage *image, int numZPlanes, 521 const char *extname, bool after) 522 { 523 return psFitsInsertImageWithMask(fits, header, image, NULL, 0, numZPlanes, extname, after); 524 } 525 526 bool psFitsInsertImageWithMask(psFits *fits, psMetadata *header, const psImage *image, 527 const psImage *mask, psMaskType maskVal, int numZPlanes, 528 const char *extname, bool after) 516 529 { 517 530 PS_ASSERT_FITS_NON_NULL(fits, false); 518 531 PS_ASSERT_FITS_WRITABLE(fits, false); 519 532 PS_ASSERT_IMAGE_NON_NULL(image, false); 533 if (mask) { 534 PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, false); 535 PS_ASSERT_IMAGES_SIZE_EQUAL(mask, image, false); 536 } 520 537 521 538 int numCols = image->numCols; // Number of columns for image … … 529 546 psFitsFloat floatType; // Custom floating-point convention type 530 547 psImage *diskImage = imageToDiskRepresentation(&bscale, &bzero, &blank, &floatType, fits, image, 531 NULL, true); // Image to write out548 mask, maskVal, NULL, true); // Image to write out 532 549 if (!diskImage) { 533 550 psError(PS_ERR_UNKNOWN, false, "Unable to convert image to desired disk format."); … … 557 574 } 558 575 if (cfitsioBzero != 0.0) { 559 // p_psFitsTypeToCfitsio and imageToDiskRepresentation must not clash!560 psAssert(bzero == 0.0 && bscale == 1.0, "impossible");576 psAssert(bzero == 0.0 && bscale == 1.0, 577 "p_psFitsTypeToCfitsio and imageToDiskRepresentation must not clash!"); 561 578 bscale = 1.0; 562 579 bzero = cfitsioBzero; … … 564 581 565 582 psFitsOptions *options = fits->options; // FITS I/O options 566 psAssert(!useRequestedScale || !options || bitPix == options->bitpix || options->bitpix == 0, "impossible"); 583 psAssert(!useRequestedScale || !options || bitPix == options->bitpix || options->bitpix == 0, 584 "Something's not consistent"); 567 585 568 586 int naxis = 3; // Number of axes … … 630 648 // own quantisation, the correct keyword is always "BLANK" instead of "ZBLANK". 631 649 fits_write_key_lng(fits->fd, "BLANK", blank, "Value for undefined pixels", &status); 650 // But it seems that cfitsio uses ZBLANK 651 fits_write_key_lng(fits->fd, "ZBLANK", blank, "Value for undefined pixels", &status); 632 652 fits_set_imgnull(fits->fd, blank, &status); 633 653 if (psFitsError(status, true, "Could not write BLANK header to file.")) { … … 681 701 } 682 702 683 bool psFitsUpdateImage(psFits* fits, const psImage* input, int x0, int y0, int z) 703 bool psFitsUpdateImage(psFits *fits, const psImage *input, int x0, int y0, int z) 704 { 705 return psFitsUpdateImageWithMask(fits, input, NULL, 0, x0, y0, z); 706 } 707 708 bool psFitsUpdateImageWithMask(psFits *fits, const psImage *input, const psImage *mask, psMaskType maskVal, 709 int x0, int y0, int z) 684 710 { 685 711 PS_ASSERT_FITS_NON_NULL(fits, false); 686 712 PS_ASSERT_FITS_WRITABLE(fits, false); 687 713 PS_ASSERT_IMAGE_NON_NULL(input, false); 714 if (mask) { 715 PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, false); 716 PS_ASSERT_IMAGES_SIZE_EQUAL(mask, input, false); 717 } 688 718 689 719 int status = 0; … … 709 739 psFitsFloat floatType; // Custom floating-point convention type 710 740 psImage *diskImage = imageToDiskRepresentation(&bscale, &bzero, &blank, &floatType, fits, input, 711 NULL, false); // Image to write out741 mask, maskVal, NULL, false); // Image to write out 712 742 if (!diskImage) { 713 743 psError(PS_ERR_UNKNOWN, false, "Unable to convert image to desired disk format."); … … 737 767 } 738 768 if (cfitsioBzero != 0.0) { 739 // p_psFitsTypeToCfitsio and imageToDiskRepresentation must not clash!740 psAssert(bzero == 0.0 && bscale == 1.0, "impossible");769 psAssert(bzero == 0.0 && bscale == 1.0, 770 "p_psFitsTypeToCfitsio and imageToDiskRepresentation must not clash!"); 741 771 bscale = 1.0; 742 772 bzero = cfitsioBzero; 743 773 } 744 774 psFitsOptions *options = fits->options; // FITS I/O options 745 psAssert(!useRequestedScale || !options || bitPix == options->bitpix || options->bitpix == 0, "impossible"); 775 psAssert(!useRequestedScale || !options || bitPix == options->bitpix || options->bitpix == 0, 776 "Something's not consistent"); 746 777 747 778 // Check to see if the HDU has the same datatype
Note:
See TracChangeset
for help on using the changeset viewer.
