Changeset 21363 for trunk/psModules/src/config/pmConfigMask.c
- Timestamp:
- Feb 5, 2009, 4:31:25 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/config/pmConfigMask.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/config/pmConfigMask.c
r21183 r21363 10 10 11 11 static pmConfigMaskInfo masks[] = { 12 { "DETECTOR", NULL, 0x00, true }, // Something is wrong with the detector13 { "DARK", "DETECTOR", 0x00, true }, // Pixel doesn't dark-subtract properly14 { "FLAT", "DETECTOR", 0x01, true },// Pixel doesn't flat-field properly15 { "BLANK", "DETECTOR", 0x01, true },// Pixel doesn't contain valid data16 { "RANGE", NULL, 0x00, true }, // Pixel is out-of-range of linearity17 { "SAT", "RANGE", 0x01, true }, // Pixel is saturated18 { "BAD", "RANGE", 0x01, true }, // Pixel is low19 { "BAD.WARP", NULL, 0x01, true }, // Pixel is bad after convolution with a bad pixel20 { "CR", NULL, 0x00, true }, // Pixel contains a cosmic ray21 { "GHOST", NULL, 0x00, true }, // Pixel contains an optical ghost22 { "POOR.WARP", NULL, 0x00, false }, // Pixel is poor after convolution with a bad pixel12 { "DETECTOR", NULL, 0x00, true }, // Something is wrong with the detector 13 { "DARK", "DETECTOR", 0x00, true }, // Pixel doesn't dark-subtract properly 14 { "FLAT", "DETECTOR", 0x01, true }, // Pixel doesn't flat-field properly 15 { "BLANK", "DETECTOR", 0x01, true }, // Pixel doesn't contain valid data 16 { "RANGE", NULL, 0x00, true }, // Pixel is out-of-range of linearity 17 { "SAT", "RANGE", 0x01, true }, // Pixel is saturated 18 { "BAD", "RANGE", 0x01, true }, // Pixel is low 19 { "BAD.WARP", NULL, 0x01, true }, // Pixel is bad after convolution with a bad pixel 20 { "CR", NULL, 0x00, true }, // Pixel contains a cosmic ray 21 { "GHOST", NULL, 0x00, true }, // Pixel contains an optical ghost 22 { "POOR.WARP", NULL, 0x00, false }, // Pixel is poor after convolution with a bad pixel 23 23 // "LOW" Pixel is low 24 24 // "CONV" Pixel is bad after convolution with a bad pixel … … 31 31 // bits in 8-bits of space). 32 32 33 // XXX this file does not have psError vs psWarning worked out correctly. some of the 33 // XXX this file does not have psError vs psWarning worked out correctly. some of the 34 34 // failure modes should result in errors, not just warnings. 35 35 … … 40 40 41 41 bool pmConfigMaskSetInMetadata(psImageMaskType *outMaskValue, // Value of MASK.VALUE, returned 42 psImageMaskType *outMarkValue, // Value of MARK.VALUE, returned43 psMetadata *source // Source of mask bits42 psImageMaskType *outMarkValue, // Value of MARK.VALUE, returned 43 psMetadata *source // Source of mask bits 44 44 ) 45 45 { 46 46 PS_ASSERT_METADATA_NON_NULL(source, false); 47 47 48 48 // Ensure all the bad mask names exist, and set the value to catch all bad pixels 49 49 psImageMaskType maskValue = 0; // Value to mask to catch all the bad pixels 50 psImageMaskType allMasks = 0; // Value to mask to catch all masked bits (to set MARK)50 psImageMaskType allMasks = 0; // Value to mask to catch all masked bits (to set MARK) 51 51 52 52 int nMasks = sizeof (masks) / sizeof (pmConfigMaskInfo); … … 55 55 bool mdok; // Status of MD lookup 56 56 psImageMaskType value = psMetadataLookupImageMaskFromGeneric(&mdok, source, masks[i].badMaskName); // Value of mask 57 if (!mdok) {58 psWarning ("problem with mask value %s\n", masks[i].badMaskName);59 }57 if (!mdok) { 58 psWarning ("problem with mask value %s\n", masks[i].badMaskName); 59 } 60 60 61 61 if (!value) { 62 if (masks[i].fallbackName) {63 value = psMetadataLookupImageMaskFromGeneric(&mdok, source, masks[i].fallbackName);64 }65 if (!value) {66 value = masks[i].defaultMaskValue;67 }68 psMetadataAddImageMask(source, PS_LIST_TAIL, masks[i].badMaskName, PS_META_REPLACE, NULL, value);69 } 70 if (masks[i].isBad) {71 maskValue |= value;72 }73 allMasks |= value;62 if (masks[i].fallbackName) { 63 value = psMetadataLookupImageMaskFromGeneric(&mdok, source, masks[i].fallbackName); 64 } 65 if (!value) { 66 value = masks[i].defaultMaskValue; 67 } 68 psMetadataAddImageMask(source, PS_LIST_TAIL, masks[i].badMaskName, PS_META_REPLACE, NULL, value); 69 } 70 if (masks[i].isBad) { 71 maskValue |= value; 72 } 73 allMasks |= value; 74 74 } 75 75 … … 107 107 // Get a mask value by name(s) 108 108 psImageMaskType pmConfigMaskGetFromMetadata(psMetadata *source, // Source of masks 109 const char *masks // Mask values to get109 const char *masks // Mask values to get 110 110 ) 111 111 { … … 139 139 } 140 140 141 // lookup an image mask value by name from a psMetadata, without requiring the entry to 141 // lookup an image mask value by name from a psMetadata, without requiring the entry to 142 142 // be of type psImageMaskType, but verifying that it will fit in psImageMaskType 143 psImageMaskType psMetadataLookupImageMaskFromGeneric (bool *status, const psMetadata *md, const char *name) { 144 143 psImageMaskType psMetadataLookupImageMaskFromGeneric(bool *status, const psMetadata *md, const char *name) 144 { 145 if (!md) { 146 psError(PS_ERR_UNEXPECTED_NULL, true, "Metadata is NULL."); 147 if (status) { 148 *status = false; 149 } 150 return 0; 151 } 152 if (!name) { 153 psError(PS_ERR_UNEXPECTED_NULL, true, "Keyword is NULL."); 154 if (status) { 155 *status = false; 156 } 157 return 0; 158 } 145 159 *status = true; 146 160 147 // select the mask bit name from the header 148 psMetadataItem *item = psMetadataLookup (md, name); 149 if (!item) { 150 psWarning("Unable to find header keyword %s when parsing mask", name); 151 *status = false; 152 return 0; 153 } 154 155 // the value may be any of the U8, U16, U32, U64 types : accept the value regardless of type size 156 psU64 fullValue = 0; 157 switch (item->type) { 158 case PS_DATA_U8: 159 fullValue = item->data.U8; 160 break; 161 case PS_DATA_U16: 162 fullValue = item->data.U16; 163 break; 164 case PS_DATA_U32: 165 fullValue = item->data.U32; 166 break; 167 case PS_DATA_U64: 168 fullValue = item->data.U64; 169 break; 170 case PS_DATA_S8: 171 fullValue = item->data.S8; 172 break; 173 case PS_DATA_S16: 174 fullValue = item->data.S16; 175 break; 176 case PS_DATA_S32: 177 fullValue = item->data.S32; 178 break; 179 case PS_DATA_S64: 180 fullValue = item->data.S64; 181 break; 182 default: 183 psWarning("Mask entry %s in metadata is not of a mask type", name); 184 *status = false; 185 return 0; 186 } 187 188 // will the incoming value fit within the current image mask type? 189 if (fullValue > PS_MAX_IMAGE_MASK_TYPE) { 190 psWarning("Mask entry %s in metadata is larger than allowed by the psImageMaskType", name); 191 *status = false; 192 return 0; 193 } 194 psImageMaskType value = fullValue; 195 // XXX validate that value is a 2^n value? 196 197 return value; 161 // select the mask bit name from the header 162 psMetadataItem *item = psMetadataLookup(md, name); 163 if (!item) { 164 if (status) { 165 *status = false; 166 } else { 167 psError(PS_ERR_BAD_PARAMETER_VALUE, "Unable to find keyword %s when parsing mask", name); 168 } 169 return 0; 170 } 171 172 // the value may be any of the U8, U16, U32, U64 types : accept the value regardless of type size 173 psU64 fullValue = 0; 174 switch (item->type) { 175 case PS_DATA_U8: 176 fullValue = item->data.U8; 177 break; 178 case PS_DATA_U16: 179 fullValue = item->data.U16; 180 break; 181 case PS_DATA_U32: 182 fullValue = item->data.U32; 183 break; 184 case PS_DATA_U64: 185 fullValue = item->data.U64; 186 break; 187 case PS_DATA_S8: 188 fullValue = item->data.S8; 189 break; 190 case PS_DATA_S16: 191 fullValue = item->data.S16; 192 break; 193 case PS_DATA_S32: 194 fullValue = item->data.S32; 195 break; 196 case PS_DATA_S64: 197 fullValue = item->data.S64; 198 break; 199 default: 200 if (status) { 201 *status = false; 202 } else { 203 psError(PS_ERR_BAD_PARAMETER_TYPE, true, 204 "Mask entry %s in metadata is not of a mask type", name); 205 } 206 return 0; 207 } 208 209 // will the incoming value fit within the current image mask type? 210 if (fullValue > PS_MAX_IMAGE_MASK_TYPE) { 211 if (status) { 212 *status = false; 213 } else { 214 psError(PS_ERR_BAD_PARAMETER_VALUE, true, 215 "Mask entry %s in metadata is larger than allowed by the psImageMaskType", name); 216 } 217 return 0; 218 } 219 psImageMaskType value = fullValue; 220 // XXX validate that value is a 2^n value? 221 222 return value; 198 223 } 199 224 200 225 // Remove from the header keywords starting with the provided string 201 226 int pmConfigMaskRemoveHeaderKeywords(psMetadata *header, // Header from which to remove keywords 202 const char *start // Remove keywords that start with this string227 const char *start // Remove keywords that start with this string 203 228 ) 204 229 { … … 229 254 return 0; 230 255 } 231 256 232 257 psImageMaskType mask = pmConfigMaskGetFromMetadata (recipe, masks); 233 258 return mask; … … 274 299 } 275 300 276 // How many mask values do we need to read? We raise an error if this is not found, 301 // How many mask values do we need to read? We raise an error if this is not found, 277 302 // unless the MASK.FORCE is set to true in the camera config 278 303 int nMask = psMetadataLookupS32(&status, header, "MSKNUM"); … … 300 325 } 301 326 302 psImageMaskType headerValue = psMetadataLookupImageMaskFromGeneric (&status, header, valuekey);303 if (!status) {327 psImageMaskType headerValue = psMetadataLookupImageMaskFromGeneric (&status, header, valuekey); 328 if (!status) { 304 329 psWarning("Failed to get mask value %s from header, skipping", valuekey); 305 continue;306 } 307 308 // since we may read multiple mask files, we need to warn (or error?) if any of the309 // header mask values conflict with other header mask values; However, the original310 // mask values from the recipe do not need to match the header values.311 312 // when we add a header mask value, we will also add the NAME.ALREADY entry; check for313 // the NAME.ALREADY entry to see if we have previously added this mask value from a314 // header.330 continue; 331 } 332 333 // since we may read multiple mask files, we need to warn (or error?) if any of the 334 // header mask values conflict with other header mask values; However, the original 335 // mask values from the recipe do not need to match the header values. 336 337 // when we add a header mask value, we will also add the NAME.ALREADY entry; check for 338 // the NAME.ALREADY entry to see if we have previously added this mask value from a 339 // header. 315 340 316 341 psString nameAlready = NULL; // Name of key with ".ALREADY" added … … 318 343 bool already = psMetadataLookupBool(&status, recipe, nameAlready); // Already read this one? 319 344 320 bool inRecipe = false;321 psImageMaskType recipeValue = psMetadataLookupImageMaskFromGeneric (&inRecipe, recipe, name);322 if (!inRecipe) {345 bool inRecipe = false; 346 psImageMaskType recipeValue = psMetadataLookupImageMaskFromGeneric (&inRecipe, recipe, name); 347 if (!inRecipe) { 323 348 psWarning("Mask value %s is not defined in the recipe", name); 324 } 349 } 325 350 326 351 if (already) { 327 assert (inRecipe); // XXX makes no sense for NAME.ALREADY to be in without NAME352 assert (inRecipe); // XXX makes no sense for NAME.ALREADY to be in without NAME 328 353 if (recipeValue != headerValue) { 329 354 psWarning("New mask header value does not match previously loaded entry: %x vs %x", headerValue, recipeValue); 330 psMetadataAddImageMask(recipe, PS_LIST_TAIL, name, PS_META_REPLACE, "Bitmask bit value", headerValue);331 // XXX alternatively, error here355 psMetadataAddImageMask(recipe, PS_LIST_TAIL, name, PS_META_REPLACE, "Bitmask bit value", headerValue); 356 // XXX alternatively, error here 332 357 } 333 358 } else { … … 369 394 while ((item = psMetadataGetAndIncrement(iter))) { 370 395 371 // XXX this would give a false positive for mask which include '.ALREADY' in their names372 char *ptr = strstr (item->name, ".ALREADY");373 if (ptr) continue;374 375 psU64 fullValue = 0;396 // XXX this would give a false positive for mask which include '.ALREADY' in their names 397 char *ptr = strstr (item->name, ".ALREADY"); 398 if (ptr) continue; 399 400 psU64 fullValue = 0; 376 401 switch (item->type) { 377 case PS_DATA_U8:378 fullValue = item->data.U8;379 break;380 case PS_DATA_U16:381 fullValue = item->data.U16;382 break;383 case PS_DATA_U32:384 fullValue = item->data.U32;385 break;386 case PS_DATA_U64:387 fullValue = item->data.U64;388 break;389 default:402 case PS_DATA_U8: 403 fullValue = item->data.U8; 404 break; 405 case PS_DATA_U16: 406 fullValue = item->data.U16; 407 break; 408 case PS_DATA_U32: 409 fullValue = item->data.U32; 410 break; 411 case PS_DATA_U64: 412 fullValue = item->data.U64; 413 break; 414 default: 390 415 psWarning("mask recipe entry %s is not a bit value\n", item->name); 391 416 continue; 392 417 } 393 assert (fullValue <= PS_MAX_IMAGE_MASK_TYPE); // this should have been asserted on read...418 assert (fullValue <= PS_MAX_IMAGE_MASK_TYPE); // this should have been asserted on read... 394 419 395 420 snprintf(namekey, 64, "MSKNAM%02d", nMask);
Note:
See TracChangeset
for help on using the changeset viewer.
