IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 13, 2008, 3:27:25 PM (18 years ago)
Author:
Paul Price
Message:

Some fixes to image I/O: (1) when BITPIX=8, the FITS standard says unsigned ints (cf two's complement for BITPIX=16,32,64). Added some special cases for quantising to BITPIX=8 to accomodate this. (2) Adding support for marking bad pixels when doing compression. Out-of-range and non-finite pixels are written with value 2(BITPIX-1)-1, which is recovered (to NAN) when reading (through use of (Z)BLANK keyword). Added test for this. It doesn't pass yet --- the highest pixel in the image is being interpreted as NAN when it shouldn't be. Solution probably involves tweaking scaleRange() in psFitsScale.c, but not worrying about that now.

File:
1 edited

Legend:

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

    r17447 r17660  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2008-04-17 23:43:02 $
     9 *  @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2008-05-14 01:27:25 $
    1111 *
    1212 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    246246static psImage *imageToDiskRepresentation(double *bscale, // Scaling applied
    247247                                          double *bzero, // Zero point applied
     248                                          long *blank, // Blank value (integer data)
    248249                                          psFitsFloat *floatType, // Type of custom floating-point
    249250                                          psFits *fits, // FITS file pointer
     
    284285        if (newScaleZero) {
    285286            // Choose an appropriate BSCALE and BZERO
    286             if (!psFitsScaleDetermine(bscale, bzero, image, fits)) {
     287            if (!psFitsScaleDetermine(bscale, bzero, blank, image, fits)) {
    287288                // We can't have the write dying for this reason --- try to save it somehow!
    288289                psWarning("Unable to determine BSCALE and BZERO for image --- setting to 1.0, 0.0");
     
    365366    psAssert(!output->parent, "impossible");            // No parents means the buffer is contiguous
    366367
     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
    367392    int anynull = 0;                    // Are there any NULLs in the data?
    368393    int status = 0;                     // cfitsio status
    369394    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) {
    371396        psFitsError(status, true, "Reading FITS file failed.");
    372397        return false;
     
    498523
    499524    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
    500526    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,
    502528                                                   NULL, true); // Image to write out
    503529    if (!diskImage) {
     
    576602    }
    577603
     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
    578617    if (floatType != PS_FITS_FLOAT_NONE) {
    579618        psFitsFloatImageSet(fits, floatType);
     
    629668
    630669    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
    631671    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,
    633673                                                   NULL, false); // Image to write out
    634674    if (!diskImage) {
Note: See TracChangeset for help on using the changeset viewer.