IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jan 16, 2008, 10:10:35 AM (18 years ago)
Author:
Paul Price
Message:

Renaming functions for clarity. e.g., "convertImageWrite" did not
actually convert the image and then write, but converted an image in
preparation for writing; the writing was performed elsewhere.
Hopefully this new naming makes the operations a bit clearer.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/fits/psFitsImage.c

    r15920 r16095  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2007-12-25 01:31:21 $
     9 *  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2008-01-16 20:10:35 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    243243# if (0)
    244244// 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.
    246248// The idea is that the "fuzz" (adding a random number between 0 and 1) preserves the expectation value of
    247249// the image (e.g., a value of 0.1 will get translated to zero 90% of the time, and unity 10% of the time),
    248250// though at the cost of adding an additional variance of 1/12 (a standard deviation of ~0.29).
    249 static psImage *scaleImageWrite(psImage *image, // Image to which to apply BSCALE and BZERO
    250                                 int bitpix, // Output BITPIX
    251                                 double bscale, // Scaling
    252                                 double bzero, // Zero point
    253                                 psRandom *rng // Random number generator (for the "fuzz"), or NULL
    254     )
     251static 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                                  )
    255257{
    256258    assert(image);
     
    339341// Determine BSCALE and BZERO for an image, and generate a new image with it applied
    340342// TRUE = BZERO + BSCALE * FITS
    341 static psImage *scaleImageDetermineWrite(double *bscale, // Scaling, to return
    342                                          double *bzero, // Zero point, to return
    343                                          psImage *image, // Image to scale
    344                                          int bitpix, // Desired bits per pixel
    345                                          psRandom *rng // Random number generator for scaleImageWrite
    346     )
     343static 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                                    )
    347349{
    348350    PS_ASSERT_PTR_NON_NULL(bscale, NULL);
     
    412414    psTrace("psLib.fits", 3, "BSCALE = %.10lf, BZERO = %.10lf\n", *bscale, *bzero);
    413415
    414     return scaleImageWrite(image, bitpix, *bscale, *bzero, rng);
     416    return scaleImageForDisk(image, bitpix, *bscale, *bzero, rng);
    415417}
    416418# endif
     
    420422// the present time, since cfitsio should apply the scaling itself in the process of reading.  However, we may
    421423// later desire it.
    422 static psImage *scaleImageRead(psFits *fits, psImage *image)
     424static psImage *scaleImageFromDisk(psFits *fits, psImage *image)
    423425{
    424426    PS_ASSERT_IMAGE_NON_NULL(image, NULL);
     
    500502#endif
    501503
    502 // Convert an image to the desired BITPIX
    503 static psImage *convertImageWrite(double *bscale, // Scaling applied
    504                                   double *bzero, // Zero point applied
    505                                   psFitsFloat *floatType, // Type of custom floating-point
    506                                   psFits *fits, // FITS file pointer
    507                                   const psImage *image, // Current type
    508                                   psRandom *rng, // Random number generator
    509                                   bool newScaleZero // Determine a new BSCALE and BZERO?
    510     )
     504// Convert an image to the desired BITPIX, i.e., the desired disk representation
     505static 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                                          )
    511513{
    512514    assert(bscale);
     
    524526        fits->floatType != PS_FITS_FLOAT_NONE) {
    525527        *floatType = fits->floatType;
    526         return psFitsFloatImageWrite(image, fits->floatType);
     528        return psFitsFloatImageToDisk(image, fits->floatType);
    527529    }
    528530
     
    537539    if (PS_IS_PSELEMTYPE_REAL(image->type.type) && fits->bitpix > 0) {
    538540        if (newScaleZero) {
    539             return scaleImageDetermineWrite(bscale, bzero, (psImage*)image, fits->bitpix, rng);
     541            return scaleImageDetermine(bscale, bzero, (psImage*)image, fits->bitpix, rng);
    540542        }
    541543        // Get the current BSCALE and BZERO
     
    556558            return NULL;
    557559        }
    558         return scaleImageWrite((psImage*)image, fits->bitpix, *bscale, *bzero, rng);
     560        return scaleImageForDisk((psImage*)image, fits->bitpix, *bscale, *bzero, rng);
    559561    }
    560562    # endif
     
    655657
    656658    if (floatType != PS_FITS_FLOAT_NONE) {
    657         outImage = psFitsFloatImageRead(outImage, inImage, floatType);
     659        outImage = psFitsFloatImageFromDisk(outImage, inImage, floatType);
    658660    }
    659661    psFree(inImage);
     
    707709
    708710    if (floatType != PS_FITS_FLOAT_NONE) {
    709         outImage = psFitsFloatImageRead(outImage, inImage, floatType);
     711        outImage = psFitsFloatImageFromDisk(outImage, inImage, floatType);
    710712    }
    711713    psFree(inImage);
     
    742744    double bscale = 0.0, bzero = 0.0;   // Scale and zero point to put in header (*already* applied to data)
    743745    psFitsFloat floatType;              // Custom floating-point convention type
    744     psImage *diskImage = convertImageWrite(&bscale, &bzero, &floatType, fits, image,
    745                                            NULL, true); // Image to write out
     746    psImage *diskImage = imageToDiskRepresentation(&bscale, &bzero, &floatType, fits, image,
     747                                                   NULL, true); // Image to write out
    746748    if (!diskImage) {
    747749        psError(PS_ERR_UNKNOWN, false, "Unable to convert image to desired disk format.");
     
    758760    }
    759761    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);
    761764        bscale = 1.0;
    762765        bzero = cfitsioBzero;
     
    871874    double bscale = 0.0, bzero = 0.0;   // Scale and zero point to put in header (*already* applied to data)
    872875    psFitsFloat floatType;              // Custom floating-point convention type
    873     psImage *diskImage = convertImageWrite(&bscale, &bzero, &floatType, fits, input,
    874                                            NULL, false); // Image to write out
     876    psImage *diskImage = imageToDiskRepresentation(&bscale, &bzero, &floatType, fits, input,
     877                                                   NULL, false); // Image to write out
    875878    if (!diskImage) {
    876879        psError(PS_ERR_UNKNOWN, false, "Unable to convert image to desired disk format.");
     
    882885    double cfitsioBzero = 0.0;          // Zero point for cfitsio to apply
    883886    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)) {
    885888        psFree(diskImage);
    886889        return false;
    887890    }
    888891    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);
    890894        bscale = 1.0;
    891895        bzero = cfitsioBzero;
Note: See TracChangeset for help on using the changeset viewer.