Changeset 7168 for trunk/psModules/src/camera/pmFPARead.c
- Timestamp:
- May 22, 2006, 2:23:08 PM (20 years ago)
- File:
-
- 1 edited
-
trunk/psModules/src/camera/pmFPARead.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psModules/src/camera/pmFPARead.c
r7017 r7168 5 5 6 6 #include "pmFPA.h" 7 #include "pmFPARead.h"8 7 #include "pmHDU.h" 9 8 #include "pmHDUUtils.h" … … 11 10 #include "psRegionIsBad.h" 12 11 #include "pmFPAHeader.h" 12 13 #include "pmFPARead.h" 13 14 14 15 #define MAX(x,y) ((x) > (y) ? (x) : (y)) … … 74 75 } 75 76 77 // Read a component of a readout 78 psImage *readoutReadComponent(psFits *fits, // FITS file from which to read 79 const psRegion *region, // Region to read 80 int readdir, // Read direction (1=rows, 2=cols) 81 int min, // Minimum row/col number to read 82 int max, // Maximum row/col number to read 83 int z, // Image plane to read 84 float bad // Bad value 85 ) 86 { 87 bool resize = false; // Do we need to resize the image once read? 88 psRegion toRead = psRegionSet(region->x0, region->x1, region->y0, region->y1); // Region to read 89 psRegion fullSize = toRead; // Full sized region 90 if (readdir == 1) { 91 if (toRead.y0 <= min) { 92 toRead.y0 = min; 93 } else { 94 fullSize.y0 = min; 95 resize = true; 96 } 97 if (toRead.y1 >= max) { 98 toRead.y1 = max; 99 } else { 100 fullSize.y1 = max; 101 resize = false; 102 } 103 } else if (readdir == 2) { 104 if (toRead.x0 <= min) { 105 toRead.x0 = min; 106 } else { 107 fullSize.x0 = min; 108 resize = true; 109 } 110 if (toRead.x1 >= max) { 111 toRead.x1 = max; 112 } else { 113 fullSize.x1 = max; 114 resize = false; 115 } 116 } else { 117 psAbort(__func__, "Read direction can only be 1 (rows) or 2 (cols).\n"); 118 } 119 120 psImage *image = psFitsReadImage(fits, toRead, z); // Desired pixels 121 122 if (resize) { 123 // For some reason, the region of interest is smaller than the number of pixels we want. 124 psImage *temp = psImageAlloc(fullSize.x1 - fullSize.x0, fullSize.y1 - fullSize.y0, image->type.type); 125 psImageInit(temp, bad); 126 psImageOverlaySection(temp, image, toRead.x0, toRead.y0, "="); 127 psFree(image); 128 image = temp; 129 } 130 131 return image; 132 } 133 76 134 ////////////////////////////////////////////////////////////////////////////////////////////////////////////// 77 135 // Public functions … … 79 137 80 138 // Read the next readout; return true if we read pixels in. 139 // 140 // Note that this doesn't put pixels in the HDU. It is therefore NOT COMPATIBLE with pmCellWrite, 141 // pmChipWrite, and pmFPAWrite. Use pmReadoutWriteNext to write the data that's read by this function. 81 142 bool pmReadoutReadNext(pmReadout *readout, // Readout into which to read 82 143 psFits *fits, // FITS file from which to read … … 98 159 99 160 // Make sure we have the information we need 100 pmConceptsReadCell(cell, PM_CONCEPT_SOURCE_HEADER, false, NULL); 161 pmConceptsReadCell(cell, PM_CONCEPT_SOURCE_HEADER | PM_CONCEPT_SOURCE_CAMERA | PM_CONCEPT_SOURCE_DEFAULTS, 162 false, NULL); 101 163 102 164 // Get the trim and bias sections … … 113 175 } 114 176 int readdir = psMetadataLookupS32(&mdok, cell->concepts, "CELL.READDIR"); // Read direction 115 if (!mdok || readdir == 0 || (readdir != -1 && readdir != 1)) {177 if (!mdok || readdir == 0 || (readdir != 1 && readdir != 2)) { 116 178 psError(PS_ERR_IO, true, "CELL.READDIR is not set to -1 or +1.\n"); 117 179 return false; 180 } 181 float bad = psMetadataLookupF32(&mdok, cell->concepts, "CELL.BAD"); // Bad level 182 if (!mdok) { 183 psLogMsg(__func__, PS_LOG_WARN, "CELL.BAD is not set --- assuming zero.\n"); 184 bad = 0.0; 118 185 } 119 186 … … 159 226 160 227 // Read the FITS image 161 int offset = readout->row0; // The row number to read228 int offset = 0; // The offset from the start of the image to where we are now 162 229 if (readout->image) { 163 if (readdir > 0) {230 if (readdir == 1) { 164 231 // Reading rows 165 offset += readout->image->numRows; 232 readout->row0 += readout->image->numRows; 233 offset = readout->row0; 166 234 } else { 167 235 // Reading columns 168 offset += readout->image->numCols; 169 } 170 } 171 if ((readdir > 0 && offset >= naxis2) || (readdir < 0 && offset > naxis1)) { 236 readout->col0 += readout->image->numCols; 237 offset = readout->col0; 238 } 239 } 240 if ((readdir == 1 && offset >= naxis2) || (readdir == 2 && offset > naxis1)) { 172 241 // We've read everything there is 173 242 return false; 174 243 } 175 244 int upper = offset + numScans; // The upper limit for the pixel read 176 if (readdir > 0&& upper > naxis2) {245 if (readdir == 1 && upper > naxis2) { 177 246 upper = naxis2; 178 } else if (readdir < 0&& upper > naxis1) {247 } else if (readdir == 2 && upper > naxis1) { 179 248 upper = naxis1; 180 249 } 181 psRegion region = {0, 0, 0, 0}; // Region to be read 182 if (readdir > 0) { 183 region = psRegionSet(0, naxis1, offset, upper); // Read rows 184 } else { 185 region = psRegionSet(offset, upper, 0, naxis2); // Read columns 186 } 187 psImage *image = psFitsReadImage(fits, region, z); // The image 188 189 // Stick the image into the HDU and the readout 190 if (!hdu->images) { 191 hdu->images = psArrayAlloc(naxis3); 192 hdu->images->n = naxis3; 193 } 194 if (hdu->images->nalloc != naxis3) { 195 hdu->images = psArrayRealloc(hdu->images, naxis3); 196 hdu->images->n = naxis3; 197 } 198 if (hdu->images->data[z]) { 199 psFree(hdu->images->data[z]); 200 } 201 hdu->images->data[z] = image; 202 readout->row0 = region.y0; 203 readout->col0 = region.x0; 204 readoutCarve(readout, image, trimsec, biassecs); 250 251 // Blow away existing data 252 psFree(readout->image); 253 while (readout->bias->n > 0) { 254 psListRemove(readout->bias, PS_LIST_HEAD); 255 } 256 257 // Get the new the trim section 258 readout->image = readoutReadComponent(fits, trimsec, readdir, offset, upper, z, bad); // The image 259 260 // Get the new bias sections 261 psListIterator *biassecsIter = psListIteratorAlloc(biassecs, PS_LIST_HEAD, false); // Iterator for BIASSEC 262 psRegion *biassec = NULL; // Bias section from iteration 263 while ((biassec = psListGetAndIncrement(biassecsIter))) { 264 psImage *bias = readoutReadComponent(fits, biassec, readdir, offset, upper, z, bad); // The bias 265 psListAdd(readout->bias, PS_LIST_TAIL, bias); 266 } 267 psFree(biassecsIter); 205 268 206 269 return true;
Note:
See TracChangeset
for help on using the changeset viewer.
