Changeset 18598 for trunk/psModules/src/config/pmConfigMask.c
- Timestamp:
- Jul 17, 2008, 10:37:20 AM (18 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/config/pmConfigMask.c (modified) (10 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/config/pmConfigMask.c
r18554 r18598 11 11 psMaskType pmConfigMaskGet(const char *masks, const pmConfig *config) 12 12 { 13 assert (config);13 psAssert(config, "Require configuration"); 14 14 PS_ASSERT_STRING_NON_EMPTY(masks, 0); 15 15 … … 42 42 bool pmConfigMaskSet(const pmConfig *config, const char *maskName, psMaskType maskValue) 43 43 { 44 assert (config);44 psAssert(config, "Require configuration"); 45 45 PS_ASSERT_STRING_NON_EMPTY(maskName, false); 46 46 … … 58 58 // replace the named masks in the recipe with values in the header: 59 59 // replace only the names in the header in the recipe 60 bool pmConfigMaskReadHeader (pmConfig *config, psMetadata *header) { 60 bool pmConfigMaskReadHeader(pmConfig *config, const psMetadata *header) 61 { 62 PS_ASSERT_PTR_NON_NULL(config, false); 63 PS_ASSERT_METADATA_NON_NULL(header, false); 61 64 62 65 bool status = false; … … 78 81 for (int i = 0; i < nMask; i++) { 79 82 80 snprintf (namekey, 64, "MSKNAM%02d", i);81 snprintf (valuekey, 64, "MSKVAL%02d", i);82 83 char *name = psMetadataLookupStr (&status, header, namekey);84 psU8 bit = psMetadataLookupU8 (&status, header, valuekey);85 86 // XXX validate that bit is a 2^n value?87 88 psMetadataItem *item = psMetadataLookup (header, name);89 if (!item) {90 psWarning("mask recipe entry %s not in recipe\n", name);91 psMetadataAddU8 (recipe, PS_LIST_TAIL, name, 0, "Bitmask bit value", bit);92 } else {93 item->data.U8 = bit;94 }95 } 96 83 snprintf (namekey, 64, "MSKNAM%02d", i); 84 snprintf (valuekey, 64, "MSKVAL%02d", i); 85 86 char *name = psMetadataLookupStr (&status, header, namekey); 87 psU8 bit = psMetadataLookupU8 (&status, header, valuekey); 88 89 // XXX validate that bit is a 2^n value? 90 91 psMetadataItem *item = psMetadataLookup (header, name); 92 if (!item) { 93 psWarning("mask recipe entry %s not in recipe\n", name); 94 psMetadataAddU8 (recipe, PS_LIST_TAIL, name, 0, "Bitmask bit value", bit); 95 } else { 96 item->data.U8 = bit; 97 } 98 } 99 97 100 return true; 98 101 } 99 102 100 103 // write the named mask bits to the header 101 bool pmConfigMaskWriteHeader (pmConfig *config, psMetadata *header) { 104 bool pmConfigMaskWriteHeader(const pmConfig *config, psMetadata *header) 105 { 106 PS_ASSERT_PTR_NON_NULL(config, false); 107 PS_ASSERT_METADATA_NON_NULL(header, false); 102 108 103 109 char namekey[80]; … … 117 123 while ((item = psMetadataGetAndIncrement(iter))) { 118 124 119 if (item->type != PS_DATA_U8) {120 psWarning("mask recipe entry %s is not a bit value\n", item->name);121 continue;122 }123 124 snprintf (namekey, 64, "MSKNAM%02d", nMask);125 snprintf (valuekey, 64, "MSKVAL%02d", nMask);126 127 psMetadataAddStr (header, PS_LIST_TAIL, namekey, 0, "Bitmask bit name", item->name);128 psMetadataAddU8 (header, PS_LIST_TAIL, valuekey, 0, "Bitmask bit value", item->data.U8);129 nMask ++;130 } 131 125 if (item->type != PS_DATA_U8) { 126 psWarning("mask recipe entry %s is not a bit value\n", item->name); 127 continue; 128 } 129 130 snprintf (namekey, 64, "MSKNAM%02d", nMask); 131 snprintf (valuekey, 64, "MSKVAL%02d", nMask); 132 133 psMetadataAddStr (header, PS_LIST_TAIL, namekey, 0, "Bitmask bit name", item->name); 134 psMetadataAddU8 (header, PS_LIST_TAIL, valuekey, 0, "Bitmask bit value", item->data.U8); 135 nMask ++; 136 } 137 132 138 psMetadataAddS32 (header, PS_LIST_TAIL, "MSKNUM", 0, "Bitmask bit count", nMask); 133 139 return true; … … 135 141 136 142 // examine named mask values in mask recipe and set the bits for maskValue and markValue 137 // this function sets an appropriate value for the following required named mask concepts: 143 // this function sets an appropriate value for the following required named mask concepts: 138 144 // FLAT (used to mark out-of-range corrections in the flat-fielding) 139 145 // BLANK (used to mark non-existent pixels) … … 143 149 // If these latter do not exist, the value 0x01 is used. 144 150 // The values actually used for these names are written back to the config file 145 bool pmConfigMaskSetBits (psMaskType *outMaskValue, psMaskType *outMarkValue, pmConfig *config) { 151 bool pmConfigMaskSetBits(psMaskType *outMaskValue, psMaskType *outMarkValue, const pmConfig *config) 152 { 153 PS_ASSERT_PTR_NON_NULL(config, false); 146 154 147 155 psMaskType maskValue = 0; 148 156 149 157 // mask for generic detector defect 150 psMaskType detectorMask = pmConfigMaskGet("DETECTOR", config); 158 psMaskType detectorMask = pmConfigMaskGet("DETECTOR", config); 151 159 maskValue |= detectorMask; 152 160 … … 156 164 157 165 // mask for non-linear flat regions (default to DETECTOR if not defined) 158 psMaskType flatMask = pmConfigMaskGet("FLAT", config); 166 psMaskType flatMask = pmConfigMaskGet("FLAT", config); 159 167 if (!flatMask) { 160 flatMask = detectorMask;161 pmConfigMaskSet (config, "FLAT", flatMask);168 flatMask = detectorMask; 169 pmConfigMaskSet (config, "FLAT", flatMask); 162 170 } 163 171 if (!flatMask) { 164 flatMask = 0x01;165 pmConfigMaskSet (config, "FLAT", flatMask);172 flatMask = 0x01; 173 pmConfigMaskSet (config, "FLAT", flatMask); 166 174 } 167 175 maskValue |= flatMask; 168 176 169 177 // mask for non-existent data (default to DETECTOR if not defined) 170 psMaskType blankMask = pmConfigMaskGet("BLANK", config); 178 psMaskType blankMask = pmConfigMaskGet("BLANK", config); 171 179 if (!blankMask) { 172 blankMask = detectorMask;173 pmConfigMaskSet (config, "BLANK", blankMask);180 blankMask = detectorMask; 181 pmConfigMaskSet (config, "BLANK", blankMask); 174 182 } 175 183 if (!blankMask) { 176 blankMask = 0x01;177 pmConfigMaskSet (config, "BLANK", blankMask);184 blankMask = 0x01; 185 pmConfigMaskSet (config, "BLANK", blankMask); 178 186 } 179 187 maskValue |= blankMask; … … 186 194 psMaskType satMask = pmConfigMaskGet("SAT", config); 187 195 if (!satMask) { 188 satMask = rangeMask;189 pmConfigMaskSet (config, "SAT", satMask);196 satMask = rangeMask; 197 pmConfigMaskSet (config, "SAT", satMask); 190 198 } 191 199 if (!satMask) { 192 satMask = 0x01;193 pmConfigMaskSet (config, "SAT", satMask);200 satMask = 0x01; 201 pmConfigMaskSet (config, "SAT", satMask); 194 202 } 195 203 maskValue |= satMask; 196 204 197 205 // mask for below-range data (default to RANGE if not defined) 198 206 psMaskType badMask = pmConfigMaskGet("BAD", config); 199 207 if (!badMask) { 200 badMask = rangeMask;201 pmConfigMaskSet (config, "BAD", badMask);208 badMask = rangeMask; 209 pmConfigMaskSet (config, "BAD", badMask); 202 210 } 203 211 if (!badMask) { 204 badMask = 0x01;205 pmConfigMaskSet (config, "BAD", badMask);212 badMask = 0x01; 213 pmConfigMaskSet (config, "BAD", badMask); 206 214 } 207 215 maskValue |= badMask; … … 219 227 int nBits = sizeof(psMaskType) * 8; 220 228 for (int i = 0; !markValue && (i < nBits); i++) { 221 if (maskValue & markValue) {222 markValue >>= 1;223 } else {224 markValue = markValue;225 }229 if (maskValue & markValue) { 230 markValue >>= 1; 231 } else { 232 markValue = markValue; 233 } 226 234 } 227 235 if (!markValue) { 228 psError (PS_ERR_UNKNOWN, true, "Unable to define the MARK bit mask: all bits taken!"); 229 return false; 230 } 236 psError (PS_ERR_UNKNOWN, true, "Unable to define the MARK bit mask: all bits taken!"); 237 return false; 238 } 239 231 240 232 241 // update the config table 233 pmConfigMaskSet (config, "MASK.VALUE", maskValue); 234 pmConfigMaskSet (config, "MARK.VALUE", markValue); 235 236 *outMaskValue = maskValue; 237 *outMarkValue = markValue; 238 239 return true; 240 } 242 pmConfigMaskSet(config, "MASK.VALUE", maskValue); 243 pmConfigMaskSet(config, "MARK.VALUE", markValue); 244 245 if (outMaskValue) { 246 *outMaskValue = maskValue; 247 } 248 if (outMarkValue) { 249 *outMarkValue = markValue; 250 } 251 252 return true; 253 }
Note:
See TracChangeset
for help on using the changeset viewer.
