IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 12, 2007, 12:22:33 PM (19 years ago)
Author:
magnier
Message:

fix region inconsistency for pmReadoutReadNext

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psModules/src/camera/pmFPARead.c

    r13190 r13768  
    120120}
    121121
    122 // Read a component of a readout
     122// Read a component of a readout.  We read in only the rows from min to max for plane z, for
     123// the full region requested.  if we request a range outside the region, we will pad to fill
     124// out the edges of the region with 'bad' pixels.  The output image always has max-min rows.
     125// The region represents the maximum bounds of the full image
     126
    123127psImage *readoutReadComponent(psImage *image, // Image into which to read
    124128                              psFits *fits, // FITS file from which to read
    125                               const psRegion *region, // Region to read
     129                              const psRegion *fullImage, // full image region, read a subset
    126130                              int readdir, // Read direction (1=rows, 2=cols)
    127131                              int min,  // Minimum row/col number to read
     
    132136{
    133137    assert(fits);
    134     assert(region);
    135 
    136     bool resize = false;                // Do we need to resize the image once read?
    137     psRegion toRead = psRegionSet(region->x0, region->x1, region->y0, region->y1); // Region to read
    138     psRegion fullSize = toRead;         // Full sized region
     138    assert(fullImage);
     139    assert((readdir == 1) || (readdir == 2));
     140
     141    int nRead = 0;
     142    int nScans = max - min;
     143    assert (nScans > 0);
     144
     145    psRegion toRead = *fullImage;  // full image region
     146   
     147    int dX = 0;
     148    int dY = 0;
     149    int nX = 0;
     150    int nY = 0;
     151
    139152    if (readdir == 1) {
    140         if (toRead.y0 <= min) {
    141             toRead.y0 = min;
    142         } else {
    143             fullSize.y0 = min;
    144             resize = true;
    145         }
    146         if (toRead.y1 >= max) {
    147             toRead.y1 = max;
    148         } else {
    149             fullSize.y1 = max;
    150             resize = false;
    151         }
    152     } else if (readdir == 2) {
    153         if (toRead.x0 <= min) {
    154             toRead.x0 = min;
    155         } else {
    156             fullSize.x0 = min;
    157             resize = true;
    158         }
    159         if (toRead.x1 >= max) {
    160             toRead.x1 = max;
    161         } else {
    162             fullSize.x1 = max;
    163             resize = false;
    164         }
     153        toRead.y0 = PS_MAX (toRead.y0, min);
     154        toRead.y1 = PS_MIN (toRead.y1, max);
     155        nRead = toRead.y1 - toRead.y0;
     156        if (min < fullImage->y0) {
     157            dY = toRead.y0;
     158        }
     159        nX = toRead.x1 - toRead.x0;
     160        nY = nScans;
    165161    } else {
    166         psAbort("Read direction can only be 1 (rows) or 2 (cols).\n");
     162        toRead.x0 = PS_MAX (toRead.x0, min);
     163        toRead.x1 = PS_MIN (toRead.x1, max);
     164        nRead = toRead.x1 - toRead.x0;
     165        if (min < fullImage->x0) {
     166            dX = toRead.x0;
     167        }
     168        nX = nScans;
     169        nY = toRead.y1 - toRead.y0;
    167170    }
    168171
     
    179182    }
    180183
    181     if (resize) {
    182         // For some reason, the region of interest is smaller than the number of pixels we want.
    183         psTrace("psModules.camera", 5, "Resizing image to %.0fx%.0f\n",
    184                 fullSize.x1 - fullSize.x0, fullSize.y1 - fullSize.y0);
    185         psImage *temp = psImageAlloc(fullSize.x1 - fullSize.x0, fullSize.y1 - fullSize.y0, image->type.type);
     184    // XXX this modification is not carried back up stream: it affects readout->row0,col0
     185    if (nRead < nScans) {
     186        // The region of interest is smaller than the number of pixels we want.
     187        psTrace("psModules.camera", 5, "Resizing image to %d,%d\n", nX, nY);
     188        psImage *temp = psImageAlloc(nX, nY, image->type.type);
    186189        psImageInit(temp, bad);
    187         psImageOverlaySection(temp, image, toRead.x0, toRead.y0, "=");
     190        psImageOverlaySection(temp, image, dX, dY, "=");
    188191        psFree(image);
    189192        image = temp;
     
    385388//////////////////////////////////////////////////////////////////////////////////////////////////////////////
    386389
    387 bool pmReadoutReadNext(pmReadout *readout, psFits *fits, int z, int numScans)
     390// XXX need to pass back the error conditions as well as the 'keep going' state
     391bool pmReadoutReadNext(bool *status, pmReadout *readout, psFits *fits, int z, int numScans)
    388392{
    389393    PS_ASSERT_PTR_NON_NULL(readout, false);
     
    392396    PS_ASSERT_INT_NONNEGATIVE(numScans, false);
    393397
     398    assert (numScans || !readout->image); // cannot have readout->image and !numScans
     399
     400    *status = false;
     401
    394402    // Get the HDU and read the header
    395403    pmCell *cell = readout->parent;     // The parent cell
     
    397405    pmHDU *hdu = pmHDUFromCell(cell);   // The HDU
    398406    if (!hdu || hdu->blankPHU) {
     407        // XXX is this an error condition?
     408        *status = true;
    399409        return false;
    400410    }
     
    443453    if (naxis == 0) {
    444454        // No pixels to read, as for a PHU.
     455        *status = true;
    445456        return false;
    446457    }
     
    460471    if (z >= naxis3) {
    461472        // Nothing to see here.  Move along.
     473        *status = true;
    462474        return false;
    463475    }
     
    486498    int maxSize;                        // Number of cols,rows in image
    487499    if (readdir == 1) {
    488         maxSize = PS_MIN(naxis2, trimsec->y1);
     500        maxSize = PS_MIN(naxis2, trimsec->y1 - trimsec->y0);
    489501    } else {
    490         maxSize = PS_MIN(naxis1, trimsec->x1);
    491     }
    492 
    493     // Read the FITS image
    494     int offset = 0;                     // The offset from the start of the image to where we are now
    495     if (readout->image) {
    496         if (readdir == 1) {
    497             // Reading rows
    498             if (numScans == 0) {
    499                 numScans = naxis2 - readout->row0;
    500             }
    501             readout->row0 += readout->image->numRows;
    502             offset = readout->row0;
    503         } else {
    504             // Reading columns
    505             if (numScans == 0) {
    506                 numScans = naxis1 - readout->col0;
    507             }
    508             readout->col0 += readout->image->numCols;
    509             offset = readout->col0;
    510         }
     502        maxSize = PS_MIN(naxis1, trimsec->x1 - trimsec->x0);
     503    }
     504
     505    int offset;                         // start of the segment
     506    int upper;                          // end of the segment
     507    int lastScan;                       // last possible scan
     508
     509    // Calculate the segment offset and upper limit, adjust readout->row0,col0
     510    if (readdir == 1) {
     511        // Reading rows
     512        offset = (readout->image) ? readout->row0 + numScans : 0; // extend to next section or start at beginning?
     513        offset = (numScans == 0) ? trimsec->x0 : offset; // full array ? read full trimsec : read section
     514        readout->row0 = offset;
     515        readout->col0 = trimsec->x0;
     516        lastScan = trimsec->y1;
    511517    } else {
    512         if (numScans == 0) {
    513             if (readdir == 1) {
    514                 numScans = naxis2;
    515             } else
    516                 numScans = naxis1;
    517         }
    518     }
     518        // Reading cols
     519        offset = (readout->image) ? readout->col0 + numScans : 0;
     520        offset = (numScans == 0) ? trimsec->y0 : offset; // full array ? read full trimsec : read section
     521        readout->col0 = offset;
     522        readout->row0 = trimsec->y0;
     523        lastScan = trimsec->x1;
     524    }
     525    upper = offset + numScans;
    519526
    520527    // Blow away existing data.
     
    527534    }
    528535
    529     if (offset >= maxSize) {
     536    if (offset >= lastScan) {
    530537        // We've read everything there is
    531538        psTrace("psModules.camera", 7, "Read everything.\n");
    532         psFree(readout->image);
    533         return false;
    534     }
    535     int upper = PS_MIN(offset + numScans, maxSize); // The upper limit for the pixel read
     539        *status = true;
     540        return false;
     541    }
     542
    536543    psTrace("psModules.camera", 7, "offset=%d, upper = %d, image is %dx%d, trimsec [%.0f:%.0f,%.0f:%.0f]\n",
    537544            offset, upper, naxis1, naxis2, trimsec->x0, trimsec->x1, trimsec->y0, trimsec->y1);
    538545
    539546    // Get the new the trim section
    540     readout->image = readoutReadComponent(readout->image, fits, trimsec, readdir,
    541                                           offset, upper, z, bad); // The image
     547    readout->image = readoutReadComponent(readout->image, fits, trimsec, readdir, offset, upper, z, bad); // The image
    542548
    543549    // Get the new bias sections
     
    551557    psFree(biassecsIter);
    552558
     559    *status = true;
    553560    return true;
    554561}
Note: See TracChangeset for help on using the changeset viewer.