IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 25446


Ignore:
Timestamp:
Sep 18, 2009, 1:19:57 PM (17 years ago)
Author:
bills
Message:

Wasn't copying enough pixels when stamp extends past the bottom of the image.
Initialize floating point images to NAN. Zero causes compression to get confused when
there are many pixels in the stamp that aren't in the input image.
Delete some dead code.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/pstamp/src/ppstampMakeStamp.c

    r25197 r25446  
    100100// Extract pixels from an image. If part of the bounds of the region are
    101101// partially outside of the input those pixels are set to zero.
    102 psImage *extractStampOld(psImage *image, psRegion region)
    103 {
    104     int width  = region.x1 - region.x0;
    105     int height = region.y1 - region.y0;
     102static psImage *extractStamp(psImage *image, psRegion region, double value)
     103{
     104    int width  = region.x1 - region.x0 + 0.5;
     105    int height = region.y1 - region.y0 + 0.5;
    106106
    107107    if (width < 0) {
     108        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "negative width\n");
    108109        return NULL;
    109110    }
    110111    if (height < 0) {
     112        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "negative height\n");
    111113        return NULL;
    112114    }
     
    132134
    133135    int copyWidth  = lastX - srcX;
    134     int rightBlank = width - copyWidth - leftBlank;
    135     if (copyWidth <= 0) {
    136         return NULL;
    137     }
    138 
    139     psImage *output = psImageAlloc(width, height, image->type.type);
    140 
    141     psElemType  type = image->type.type;
    142     psS32       elementSize =  PSELEMTYPE_SIZEOF(type);
    143     int         copySize = copyWidth * elementSize;
    144 
    145     for (int dstY=0 ; dstY < height; srcY++, dstY++) {
    146         psU8 *pdst = output->data.U8[dstY];
    147 
    148         if ((srcY < image->row0) || (srcY >= lastY)) {
    149             // zero the row
    150             memset(pdst, 0, width*elementSize);
    151         } else {
    152             psU8 *psrc = image->data.U8[srcY]  + (srcX * elementSize);
    153 
    154             if (leftBlank) {
    155                 memset(pdst, 0, leftBlank*elementSize);
    156             }
    157 
    158             // copy copyWidth pixels from srcX,srcY to dstX, dstY
    159             pdst += dstX*elementSize;
    160             memcpy(pdst, psrc, copySize);
    161 
    162             if (rightBlank) {
    163                 pdst += copyWidth * elementSize;
    164                 memset(pdst, 0, rightBlank);
    165             }
    166         }
    167     }
    168 
    169 
    170     return output;
    171 }
    172 // Extract pixels from an image. If part of the bounds of the region are
    173 // partially outside of the input those pixels are set to zero.
    174 static psImage *extractStamp(psImage *image, psRegion region, double value)
    175 {
    176     int width  = region.x1 - region.x0 + 0.5;
    177     int height = region.y1 - region.y0 + 0.5;
    178 
    179     if (width < 0) {
    180         psError(PS_ERR_BAD_PARAMETER_VALUE, true, "negative width\n");
    181         return NULL;
    182     }
    183     if (height < 0) {
    184         psError(PS_ERR_BAD_PARAMETER_VALUE, true, "negative height\n");
    185         return NULL;
    186     }
    187 
    188     int srcX  = region.x0;
    189     int srcY  = region.y0;
    190     int lastX = region.x1;
    191     int lastY = region.y1;
    192     if (lastX > (image->col0 + image->numCols)) {
    193         lastX = image->col0 + image->numCols;
    194     }
    195     if (lastY > (image->row0 + image->numRows)) {
    196         lastY = image->row0 + image->numRows;
    197     }
    198 
    199     int leftBlank = 0;
    200     int dstX  = 0;
    201     if (srcX < image->col0) {
    202         leftBlank = image->col0 - srcX;
    203         dstX += leftBlank;
    204         srcX = 0;
    205     }
    206 
    207     int copyWidth  = lastX - srcX;
    208 //    int rightBlank = width - copyWidth - leftBlank;
    209136    if (copyWidth <= 0) {
    210137        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "copyWidth is invalid: %d\n", copyWidth);
     
    231158    if (skip > 0) {
    232159        dstY = skip;
    233         height -= skip;
    234160        srcY = image->row0;
    235161    }
     
    238164            break;
    239165        }
    240         psU8 *pdst = output->data.U8[dstY];
     166        // copy copyWidth pixels from srcX,srcY to dstX, dstY
     167        psU8 *pdst = output->data.U8[dstY] + (dstX * elementSize);
    241168
    242169        psU8 *psrc = image->data.U8[srcY]  + (srcX * elementSize);
    243170
    244         // copy copyWidth pixels from srcX,srcY to dstX, dstY
    245         pdst += dstX*elementSize;
    246171        memcpy(pdst, psrc, copySize);
    247172    }
     
    320245        }
    321246
    322         outReadout->image = extractStamp(readout->image, extractRegion,  0);
     247        outReadout->image = extractStamp(readout->image, extractRegion,  NAN);
    323248        if (!outReadout->image) {
    324249            psError(PS_ERR_UNKNOWN, false, "failed to create postage stamp image\n");
     
    327252        }
    328253        if (readout->variance) {
    329             outReadout->variance = extractStamp(readout->variance, extractRegion,  0);
     254            outReadout->variance = extractStamp(readout->variance, extractRegion,  NAN);
    330255            if (!outReadout->variance) {
    331256                psError(PS_ERR_UNKNOWN, false, "failed to create postage stamp weight image\n");
Note: See TracChangeset for help on using the changeset viewer.