Changeset 11793 for trunk/psModules/src/camera/pmFPARead.c
- Timestamp:
- Feb 14, 2007, 2:34:00 PM (19 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/camera/pmFPARead.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/camera/pmFPARead.c
r11687 r11793 26 26 FPA_READ_TYPE_IMAGE, // Read image 27 27 FPA_READ_TYPE_MASK, // Read mask 28 FPA_READ_TYPE_WEIGHT // Read weight map 28 FPA_READ_TYPE_WEIGHT, // Read weight map 29 FPA_READ_TYPE_HEADER // Read header 29 30 } fpaReadType; 30 31 … … 35 36 // Carve a readout from the image pixels 36 37 static bool readoutCarve(pmReadout *readout, // Readout to be carved up 37 psImage **target, // Target pointer for the carved image38 38 psImage *image, // Image that will be carved 39 39 const psRegion *trimsec, // Trim section 40 const psList *biassecs // Bias sections 40 const psList *biassecs, // Bias sections 41 fpaReadType type 41 42 ) 42 43 { … … 59 60 PS_MIN(trimsec->y1 - readout->row0, image->numRows) // y1 60 61 ); 61 if (readout->image) { 62 psFree(readout->image); // Make way! 63 } 64 *target = psMemIncrRefCounter(psImageSubset(image, region)); 65 62 63 // place the image subset in the appropriate target location, freeing if needed 64 // XXX why psMemIncrRefCounter on psImageSubset?? 65 switch (type) { 66 case FPA_READ_TYPE_IMAGE: 67 if (readout->image) { 68 psFree (readout->image); 69 } 70 readout->image = psMemIncrRefCounter(psImageSubset(image, region)); 71 break; 72 case FPA_READ_TYPE_MASK: 73 if (readout->mask) { 74 psFree (readout->mask); 75 } 76 readout->mask = psMemIncrRefCounter(psImageSubset(image, region)); 77 break; 78 case FPA_READ_TYPE_WEIGHT: 79 if (readout->weight) { 80 psFree (readout->weight); 81 } 82 readout->weight = psMemIncrRefCounter(psImageSubset(image, region)); 83 break; 84 default: 85 psAbort("Unknown read type: %x\n", type); 86 } 87 66 88 // Get the list of overscans 89 // XXX should this step only be performed for IMAGE, not MASK and WEIGHT types? 90 // XXX that would allow us to overlay a MASK and WEIGHT which have been trimmed... 67 91 if (readout->bias->n != 0) { 68 92 // Make way! … … 184 208 } 185 209 210 // check if we have read the desired data, read it if needed 186 211 bool (*hduReadFunc)(pmHDU*, psFits*) = NULL; // Function to use to read the HDU 187 psArray **imageArray = NULL; // Array of images in the HDU 188 psElemType imageType = PS_TYPE_F32; // Expected type for image 212 void *dataPointer = NULL; // pointer to location of desired data 189 213 switch (type) { 190 case FPA_READ_TYPE_IMAGE:214 case FPA_READ_TYPE_IMAGE: 191 215 hduReadFunc = pmHDURead; 192 imageArray = &hdu->images; 193 imageType = PS_TYPE_F32; 216 dataPointer = hdu->images; 194 217 break; 195 case FPA_READ_TYPE_MASK: 218 case FPA_READ_TYPE_HEADER: 219 hduReadFunc = pmHDUReadHeader; 220 dataPointer = hdu->header; 221 break; 222 case FPA_READ_TYPE_MASK: 196 223 hduReadFunc = pmHDUReadMask; 197 imageArray = &hdu->masks; 198 imageType = PS_TYPE_MASK; 224 dataPointer = hdu->masks; 199 225 break; 200 case FPA_READ_TYPE_WEIGHT:226 case FPA_READ_TYPE_WEIGHT: 201 227 hduReadFunc = pmHDUReadWeight; 202 imageArray = &hdu->weights; 203 imageType = PS_TYPE_F32; 228 dataPointer = hdu->weights; 204 229 break; 205 default:230 default: 206 231 psAbort("Unknown read type: %x\n", type); 207 232 } 208 233 209 if (!(*imageArray) && !hduReadFunc(hdu, fits)) { 210 psError(PS_ERR_UNKNOWN, false, "Unable to read HDU for cell.\n"); 211 return false; 212 } 213 234 // do we have the data we want (image, header, or etc). 235 if (!dataPointer) { 236 // attempt to read in the desired data 237 if (!hduReadFunc(hdu, fits)) { 238 psError(PS_ERR_UNKNOWN, false, "Unable to read HDU for cell.\n"); 239 return false; 240 } 241 } 242 243 // load in the concept information for this cell 214 244 if (!pmConceptsReadCell(cell, PM_CONCEPT_SOURCE_HEADER, true, NULL)) { 215 245 //psError(PS_ERR_UNKNOWN, false, "Failed to read concepts for cell"); 216 246 //return false; 217 247 psWarning("Difficulty reading concepts for cell; attempting to proceed."); 248 } 249 250 // skip the image arrays completely for the header-only files 251 if (type == FPA_READ_TYPE_HEADER) { 252 pmCellSetDataStatus(cell, true); 253 return true; 254 } 255 256 // set up pointers for the different possible image arrays 257 psArray *imageArray = NULL; // Array of images in the HDU 258 psElemType imageType = PS_TYPE_F32; // Expected type for image 259 switch (type) { 260 case FPA_READ_TYPE_IMAGE: 261 imageArray = hdu->images; 262 imageType = PS_TYPE_F32; 263 break; 264 case FPA_READ_TYPE_MASK: 265 imageArray = hdu->masks; 266 imageType = PS_TYPE_MASK; 267 break; 268 case FPA_READ_TYPE_WEIGHT: 269 imageArray = hdu->weights; 270 imageType = PS_TYPE_F32; 271 break; 272 default: 273 psAbort("Unknown read type: %x\n", type); 218 274 } 219 275 … … 228 284 // Iterate over each of the image planes, converting type if necessary, and extracting the bits that 229 285 // matter (CELL.TRIMSEC, CELL.BIASSEC) into readouts with readoutCarve. 230 for (int i = 0; i < (*imageArray)->n; i++) {231 psImage *source = (*imageArray)->data[i]; // Source image, from the i-th plane286 for (int i = 0; i < imageArray->n; i++) { 287 psImage *source = imageArray->data[i]; // Source image, from the i-th plane 232 288 233 289 // Type conversion here to support the modules, which don't have multiple type support yet 234 290 if (source->type.type != imageType) { 235 291 psImage *temp = psImageCopy(NULL, source, imageType); // Temporary image 236 psFree( (*imageArray)->data[i]);237 (*imageArray)->data[i] = temp;292 psFree(imageArray->data[i]); 293 imageArray->data[i] = temp; 238 294 source = temp; 239 295 } … … 246 302 } 247 303 248 psImage **target = NULL; // Place in readout to put carved image 249 switch (type) { 250 case FPA_READ_TYPE_IMAGE: 251 target = &readout->image; 252 break; 253 case FPA_READ_TYPE_MASK: 254 target = &readout->mask; 255 break; 256 case FPA_READ_TYPE_WEIGHT: 257 target = &readout->weight; 258 break; 259 default: 260 psAbort("Unknown read type: %x\n", type); 261 } 262 263 if (!readoutCarve(readout, target, source, trimsec, biassecs)) { 304 if (!readoutCarve(readout, source, trimsec, biassecs, type)) { 264 305 psError(PS_ERR_UNEXPECTED_NULL, false, 265 306 "Unable to carve readout into image and bias sections for %d the plane.", i); … … 594 635 595 636 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 637 // Reading the image header 638 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 639 640 bool pmCellReadHeaderSet(pmCell *cell, psFits *fits, psDB *db) 641 { 642 PS_ASSERT_PTR_NON_NULL(cell, false); 643 PS_ASSERT_PTR_NON_NULL(fits, false); 644 645 return cellRead(cell, fits, db, FPA_READ_TYPE_HEADER); 646 } 647 648 bool pmChipReadHeaderSet(pmChip *chip, psFits *fits, psDB *db) 649 { 650 PS_ASSERT_PTR_NON_NULL(chip, false); 651 PS_ASSERT_PTR_NON_NULL(fits, false); 652 653 return chipRead(chip, fits, db, FPA_READ_TYPE_HEADER); 654 } 655 656 bool pmFPAReadHeaderSet(pmFPA *fpa, psFits *fits, psDB *db) 657 { 658 PS_ASSERT_PTR_NON_NULL(fpa, false); 659 PS_ASSERT_PTR_NON_NULL(fits, false); 660 661 return fpaRead(fpa, fits, db, FPA_READ_TYPE_HEADER); 662 } 663 664 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 596 665 // Reading FITS tables 597 666 //////////////////////////////////////////////////////////////////////////////////////////////////////////////
Note:
See TracChangeset
for help on using the changeset viewer.
