Changeset 19649
- Timestamp:
- Sep 22, 2008, 3:46:02 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/camera/pmFPA_JPEG.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/camera/pmFPA_JPEG.c
r19648 r19649 5 5 * @author EAM, IfA 6 6 * 7 * @version $Revision: 1.2 4$ $Name: not supported by cvs2svn $8 * @date $Date: 2008-09-23 0 0:12:30$7 * @version $Revision: 1.25 $ $Name: not supported by cvs2svn $ 8 * @date $Date: 2008-09-23 01:46:02 $ 9 9 * 10 10 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 134 134 135 135 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"); 145 145 return false; 146 146 } … … 148 148 psMetadata *options = psMetadataLookupMetadata(&status, recipe, file->name); 149 149 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 } 158 153 159 154 // measure the image statistics for scaling … … 162 157 stats->nSubsample = 10000; 163 158 psMaskType maskVal = pmConfigMaskGet("MASK.VALUE", config); // Value to mask 159 float mean = 0, delta = 0; // 164 160 if (!psImageBackground(stats, NULL, readout->image, readout->mask, maskVal, rng)) { 165 161 psStats *statsAlt = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV); 166 162 stats->nSubsample = 10000; 167 163 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"); 169 166 mean = 0; 170 167 delta = 1; 171 168 } else { 172 169 mean = statsAlt->sampleMean; 173 delta = 2 *statsAlt->sampleStdev;170 delta = 2.0 * statsAlt->sampleStdev; 174 171 } 175 172 psFree(statsAlt); … … 181 178 psFree(stats); 182 179 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) { 191 190 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) { 194 194 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")) { 197 200 min = mean + fmin*delta; 198 201 max = mean + fmax*delta; 199 } 200 if (!strcasecmp (mode, "FRACTION")) { 202 } else if (!strcasecmp(mode, "FRACTION")) { 201 203 min = fmin*mean; 202 204 max = fmax*mean; 203 } 204 if (!strcasecmp (mode, "VALUE")) { 205 } else if (!strcasecmp(mode, "VALUE")) { 205 206 min = fmin; 206 207 max = fmax; 208 } else { 209 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Unrecognised scaling mode: %s", mode); 210 return false; 207 211 } 208 212 209 213 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"); 211 216 min = 0; 212 217 max = 1; 213 218 } 214 219 215 psImageJpegColormap *map = psImageJpegColormapSet (NULL, colormapName);220 psImageJpegColormap *map = psImageJpegColormapSet(NULL, colormapName); 216 221 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 } 221 230 222 231 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.
