Changeset 9983 for trunk/psModules/src/camera/pmHDUGenerate.c
- Timestamp:
- Nov 14, 2006, 2:40:02 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/camera/pmHDUGenerate.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/camera/pmHDUGenerate.c
r9730 r9983 218 218 219 219 pmReadout *readout = cell->readouts->data[0]; // The first readout, as representative 220 psImage *image = readout->image;// The proper image 220 // The proper image, used to get the size 221 psImage *image = readout->image ? readout->image : (readout->mask ? readout->mask : readout->weight); 221 222 if (!image) { 222 223 continue; 224 } 225 if (readout->mask && 226 (readout->mask->numCols != image->numCols || readout->mask->numRows != image->numRows)) { 227 psLogMsg(__func__, PS_LOG_WARN, "Image and mask have different sizes (%dx%d vs %dx%d)!\n", 228 image->numCols, image->numRows, readout->mask->numCols, readout->mask->numRows); 229 } 230 if (readout->weight && 231 (readout->weight->numCols != image->numCols || readout->weight->numRows != image->numRows)) { 232 psLogMsg(__func__, PS_LOG_WARN, "Image and weight have different sizes (%dx%d vs %dx%d)!\n", 233 image->numCols, image->numRows, readout->weight->numCols, readout->weight->numRows); 223 234 } 224 235 // New reference … … 239 250 return (position > 0); 240 251 } 252 253 // Check the type for a current image against a previous type 254 static psElemType checkTypes(psElemType previous, // Previously defined type, or 0 255 psElemType current // Current type 256 ) 257 { 258 if (previous == 0) { 259 return current; 260 } 261 262 if (previous != current) { 263 psLogMsg(__func__, PS_LOG_WARN, "Images within the HDU are of different types " 264 "(%x vs %x) --- promoting\n", previous, current); 265 return PS_MAX(previous, current); 266 } 267 268 return previous; 269 } 270 271 272 // Paste the source image into the target, according to the provided region. The source is then updated to 273 // reference the region within the target. 274 static void pasteImage(psImage *target, // Target image, into which the paste is made 275 psImage **sourcePtr,// Source image, from which the paste is made, and then changed 276 psRegion *region // Image section into which to paste 277 ) 278 { 279 psImage *source = *sourcePtr; // Dereference pointer, for convenience 280 if (source->numCols != region->x1 - region->x0 || source->numRows != region->y1 - region->y0) { 281 psString regionString = psRegionToString(*region); 282 psLogMsg(__func__, PS_LOG_WARN, "Image size (%dx%d) does not match region (%s).\n", 283 source->numCols, source->numRows, regionString); 284 psFree(regionString); 285 } 286 psImageOverlaySection(target, source, region->x0, region->y0, "="); 287 288 // Reference the HDU version, so that subsequent changes will touch the HDU 289 psFree(source); 290 *sourcePtr = psImageSubset(target, *region); 291 292 return; 293 } 294 241 295 242 296 // Generate the HDU, given a list of cells below that HDU. This is the main engine function, that does all … … 248 302 // Check the number of readouts is consistent within the HDU 249 303 int numReadouts = -1; // Number of readouts 250 psElemType type = 0; // Type of readout images 304 psElemType imageType = 0; // Type of readout images 305 psElemType maskType = 0; // Type of readout masks 306 psElemType weightType = 0; // Type of readout weights 251 307 { 252 308 psListIterator *iter = psListIteratorAlloc(cells, PS_LIST_HEAD, false); // Iterator for cells … … 264 320 for (int i = 0; i < numReadouts; i++) { 265 321 pmReadout *readout = readouts->data[i]; // The readout 266 if (!readout || !readout->image) {322 if (!readout) { 267 323 continue; 268 324 } 269 psElemType imageType = readout->image->type.type; // Type for this image 270 if (type == 0) { 271 type = imageType; 272 } else if (type != imageType) { 273 psLogMsg(__func__, PS_LOG_WARN, "Images within the HDU are of different types " 274 "(%x vs %x) --- promoting\n", type, imageType); 275 type = PS_MAX(type, imageType); 325 326 if (readout->image) { 327 imageType = checkTypes(imageType, readout->image->type.type); 328 } 329 if (readout->mask) { 330 maskType = checkTypes(maskType, readout->mask->type.type); 331 } 332 if (readout->weight) { 333 weightType = checkTypes(weightType, readout->weight->type.type); 276 334 } 277 335 } … … 279 337 psFree(iter); 280 338 } 281 if (numReadouts == 0 || type == 0) {339 if (numReadouts == 0 || (imageType == 0 && maskType == 0 && weightType == 0)) { 282 340 // Nothing from which to create an HDU 283 341 psFree(cells); … … 293 351 294 352 // Generate the HDU 295 hdu->images = psArrayAlloc(numReadouts); 296 for (int i = 0; i < numReadouts; i++) { 297 psImage *image = psImageAlloc(xSize, ySize, type); 298 psImageInit(image, 0.0); 299 hdu->images->data[i] = image; 353 if (imageType) { 354 hdu->images = psArrayAlloc(numReadouts); 355 for (int i = 0; i < numReadouts; i++) { 356 psImage *image = psImageAlloc(xSize, ySize, imageType); 357 psImageInit(image, 0.0); 358 hdu->images->data[i] = image; 359 } 360 } 361 if (maskType) { 362 hdu->masks = psArrayAlloc(numReadouts); 363 for (int i = 0; i < numReadouts; i++) { 364 psImage *mask = psImageAlloc(xSize, ySize, maskType); 365 psImageInit(mask, 0); 366 hdu->masks->data[i] = mask; 367 } 368 } 369 if (weightType) { 370 hdu->weights = psArrayAlloc(numReadouts); 371 for (int i = 0; i < numReadouts; i++) { 372 psImage *weight = psImageAlloc(xSize, ySize, weightType); 373 psImageInit(weight, 0.0); 374 hdu->weights->data[i] = weight; 375 } 300 376 } 301 377 … … 319 395 psArray *readouts = cell->readouts; // Array of readouts 320 396 psArray *hduImages = hdu->images; // Array of images in the HDU 397 psArray *hduMasks = hdu->masks; // Array of masks in the HDU 398 psArray *hduWeights = hdu->weights; // Array of weights in the HDU 321 399 for (int i = 0; i < readouts->n; i++) { 322 400 pmReadout *readout = readouts->data[i]; // The readout of interest … … 324 402 continue; 325 403 } 326 psImage *image = readout->image; // The image pixels 327 psImage *hduImage = hduImages->data[i]; // The HDU image of interest 328 329 if (image->numCols != trimsec->x1 - trimsec->x0 || 330 image->numRows != trimsec->y1 - trimsec->y0) { 331 psString trimsecString = psRegionToString(*trimsec); 332 psLogMsg(__func__, PS_LOG_WARN, "Image size (%dx%d) does not match CELL.TRIMSEC (%s).\n", 333 image->numCols, image->numRows, trimsecString); 334 psFree(trimsecString); 335 } 336 psImageOverlaySection(hduImage, image, trimsec->x0, trimsec->y0, "="); 337 338 // Reference the HDU version, so that subsequent changes will touch the HDU 339 psFree(image); 340 readout->image = psImageSubset(hduImage, *trimsec); 404 405 if (readout->image) { 406 pasteImage(hduImages->data[i], &readout->image, trimsec); 407 } 408 if (readout->mask) { 409 pasteImage(hduMasks->data[i], &readout->mask, trimsec); 410 } 411 if (readout->weight) { 412 pasteImage(hduWeights->data[i], &readout->weight, trimsec); 413 } 341 414 342 415 if (biassecs->n != readout->bias->n) { … … 351 424 while ((bias = psListGetAndIncrement(biasIter)) && 352 425 (biassec = psListGetAndIncrement(biassecsIter))) { 353 if (bias->numCols != biassec->x1 - biassec->x0 || 354 bias->numRows != biassec->y1 - biassec->y0) { 355 psString biassecString = psRegionToString(*biassec); 356 psLogMsg(__func__, PS_LOG_WARN, "Bias size (%dx%d) does not match CELL.BIASSEC (%s)." 357 "\n", bias->numCols, bias->numRows, biassecString); 358 psFree(biassecString); 359 } 360 361 psImageOverlaySection(hduImage, bias, biassec->x0, biassec->y0, "="); 362 363 // Reference the HDU version, so that subsequent changes will touch the HDU 364 bias = psImageSubset(hduImage, *biassec); 426 pasteImage(hduImages->data[i], &bias, biassec); 365 427 psListAdd(newBias, PS_LIST_TAIL, bias); 366 428 }
Note:
See TracChangeset
for help on using the changeset viewer.
