IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 19649


Ignore:
Timestamp:
Sep 22, 2008, 3:46:02 PM (18 years ago)
Author:
Paul Price
Message:

Pulling recipe out of PPIMAGE and making its own.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/camera/pmFPA_JPEG.c

    r19648 r19649  
    55 *  @author EAM, IfA
    66 *
    7  *  @version $Revision: 1.24 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2008-09-23 00:12:30 $
     7 *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2008-09-23 01:46:02 $
    99 *
    1010 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    134134
    135135    if (file->type != PM_FPA_FILE_JPEG) {
    136         psError(PS_ERR_UNKNOWN, true, "warning: type mismatch");
    137         return false;
    138     }
    139 
    140     psTrace("psModules.camera", 3, "writing jpeg for readout %zd\n", (size_t) readout);
    141 
    142     psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, "PPIMAGE");
    143     if (!status) {
    144         psError(PS_ERR_UNKNOWN, true, "missing recipe PPIMAGE in config data");
     136        psError(PS_ERR_UNKNOWN, true, "File is not of type JPEG");
     137        return false;
     138    }
     139
     140    psTrace("psModules.camera", 3, "writing jpeg for readout %p\n", readout);
     141
     142    psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, "JPEG");
     143    if (!status) {
     144        psError(PS_ERR_UNKNOWN, true, "Unable to find JPEG recipe");
    145145        return false;
    146146    }
     
    148148    psMetadata *options = psMetadataLookupMetadata(&status, recipe, file->name);
    149149    if (!status) {
    150         psError(PS_ERR_UNKNOWN, true, "missing %s options in PPIMAGE recipe", file->name);
    151         return false;
    152     }
    153 
    154     float min = 0;
    155     float max = 0;                 // Minimum and maximum for stretch
    156     float mean = 0;
    157     float delta = 0;
     150        psError(PS_ERR_UNKNOWN, true, "Unable to find options for file %s in JPEG recipe", file->name);
     151        return false;
     152    }
    158153
    159154    // measure the image statistics for scaling
     
    162157    stats->nSubsample = 10000;
    163158    psMaskType maskVal = pmConfigMaskGet("MASK.VALUE", config); // Value to mask
     159    float mean = 0, delta = 0;          //
    164160    if (!psImageBackground(stats, NULL, readout->image, readout->mask, maskVal, rng)) {
    165161        psStats *statsAlt = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV);
    166162        stats->nSubsample = 10000;
    167163        if (!psImageBackground(stats, NULL, readout->image, readout->mask, maskVal, rng)) {
    168             psLogMsg("jpeg", PS_LOG_WARN, "Unable to measure statistics for image, writing blank jpeg\n");
     164            psLogMsg("psModules.jpeg", PS_LOG_WARN,
     165                     "Unable to measure statistics for image; writing blank jpeg");
    169166            mean = 0;
    170167            delta = 1;
    171168        } else {
    172169            mean = statsAlt->sampleMean;
    173             delta = 2*statsAlt->sampleStdev;
     170            delta = 2.0 * statsAlt->sampleStdev;
    174171        }
    175172        psFree(statsAlt);
     
    181178    psFree(stats);
    182179
    183     char *colormapName = psMemIncrRefCounter (psMetadataLookupStr (NULL, options, "COLORMAP"));
    184     if (!colormapName)
    185         colormapName = psStringCopy ("-greyscale");
    186     char *mode = psMemIncrRefCounter (psMetadataLookupStr (NULL, options, "SCALE.MODE"));
    187     if (!mode)
    188         mode = psStringCopy ("RANGE");
    189     float fmin = psMetadataLookupF32 (&status, options, "SCALE.MIN");
    190     if (!status)
     180    char *colormapName = psMetadataLookupStr(NULL, options, "COLORMAP"); // Name of colour map
     181    if (!colormapName) {
     182        colormapName = "-greyscale";
     183    }
     184    char *mode = psMetadataLookupStr(NULL, options, "SCALE.MODE"); // Mode for scaling image
     185    if (!mode) {
     186        mode = "RANGE";
     187    }
     188    float fmin = psMetadataLookupF32(&status, options, "SCALE.MIN"); // Minimum value/faction for scaling
     189    if (!status) {
    191190        fmin = -3.0;
    192     float fmax = psMetadataLookupF32 (&status, options, "SCALE.MAX");
    193     if (!status)
     191    }
     192    float fmax = psMetadataLookupF32(&status, options, "SCALE.MAX"); // Maximum value/faction for scaling
     193    if (!status) {
    194194        fmax = +6.0;
    195 
    196     if (!strcasecmp (mode, "RANGE")) {
     195    }
     196
     197    float min = 0, max = 0;             // Minimum and maximum for stretch
     198
     199    if (!strcasecmp(mode, "RANGE")) {
    197200        min = mean + fmin*delta;
    198201        max = mean + fmax*delta;
    199     }
    200     if (!strcasecmp (mode, "FRACTION")) {
     202    } else if (!strcasecmp(mode, "FRACTION")) {
    201203        min = fmin*mean;
    202204        max = fmax*mean;
    203     }
    204     if (!strcasecmp (mode, "VALUE")) {
     205    } else if (!strcasecmp(mode, "VALUE")) {
    205206        min = fmin;
    206207        max = fmax;
     208    } else {
     209        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unrecognised scaling mode: %s", mode);
     210        return false;
    207211    }
    208212
    209213    if (!isfinite(min) || !isfinite(max)) {
    210         psLogMsg("jpeg", PS_LOG_WARN, "The stretch parameters are not both finite, writing blank jpeg\n");
     214        psLogMsg("psModules.jpeg", PS_LOG_WARN,
     215                 "The stretch parameters are not both finite --- writing blank jpeg");
    211216        min = 0;
    212217        max = 1;
    213218    }
    214219
    215     psImageJpegColormap *map = psImageJpegColormapSet (NULL, colormapName);
     220    psImageJpegColormap *map = psImageJpegColormapSet(NULL, colormapName);
    216221    if (!map) {
    217         map = psImageJpegColormapSet (NULL, "-greyscale");
    218     }
    219 
    220     psImageJpeg (map, readout->image, file->filename, min, max);
     222        map = psImageJpegColormapSet(NULL, "-greyscale");
     223    }
     224
     225    if (!psImageJpeg(map, readout->image, file->filename, min, max)) {
     226        psError(PS_ERR_UNKNOWN, false, "Unable to write JPEG image");
     227        psFree(map);
     228        return false;
     229    }
    221230
    222231    psFree(map);
    223     psFree(colormapName);
    224     psFree(mode);
    225     return true;
    226 }
     232    return true;
     233}
Note: See TracChangeset for help on using the changeset viewer.