IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 18981


Ignore:
Timestamp:
Aug 8, 2008, 3:43:20 PM (18 years ago)
Author:
bills
Message:

simplify the extractStamp function to prepare to move it to pslib,
but need to work on the arg list a bit. I'm misusing regions

File:
1 edited

Legend:

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

    r18851 r18981  
    101101// Extract pixels from an image. If part of the bounds of the region are
    102102// partially outside of the input those pixels are set to zero.
    103 psImage *extractStamp(psImage *image, psRegion region)
     103psImage *extractStampOld(psImage *image, psRegion region)
    104104{
    105105    int width  = region.x1 - region.x0;
     
    168168    }
    169169
     170
     171    return output;
     172}
     173// Extract pixels from an image. If part of the bounds of the region are
     174// partially outside of the input those pixels are set to zero.
     175static psImage *extractStamp(psImage *image, psRegion region, double value)
     176{
     177    int width  = region.x1 - region.x0;
     178    int height = region.y1 - region.y0;
     179
     180    if (width < 0) {
     181        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "negative width\n");
     182        return NULL;
     183    }
     184    if (height < 0) {
     185        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "negative height\n");
     186        return NULL;
     187    }
     188
     189    int srcX  = region.x0;
     190    int srcY  = region.y0;
     191    int lastX = region.x1;
     192    int lastY = region.y1;
     193    if (lastX > (image->col0 + image->numCols)) {
     194        lastX = image->col0 + image->numCols;
     195    }
     196    if (lastY > (image->row0 + image->numRows)) {
     197        lastY = image->row0 + image->numRows;
     198    }
     199
     200    int leftBlank = 0;
     201    int dstX  = 0;
     202    if (srcX < image->col0) {
     203        leftBlank = image->col0 - srcX;
     204        dstX += leftBlank;
     205        srcX = 0;
     206    }
     207
     208    int copyWidth  = lastX - srcX;
     209//    int rightBlank = width - copyWidth - leftBlank;
     210    if (copyWidth <= 0) {
     211        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "copyWidth is invalid: %d\n", copyWidth);
     212        return NULL;
     213    }
     214
     215    psImage *output = psImageAlloc(width, height, image->type.type);
     216    if (!output) {
     217        psError(PS_ERR_UNKNOWN, false, "psImageAlloc failed\n");
     218        return NULL;
     219    }
     220
     221    if (!psImageInit(output, value)) {
     222        psError(PS_ERR_UNKNOWN, false, "psInitImage failed\n");
     223        return NULL;
     224    }
     225
     226    psElemType  type = image->type.type;
     227    psS32       elementSize =  PSELEMTYPE_SIZEOF(type);
     228    int         copySize = copyWidth * elementSize;
     229
     230    int     dstY = 0;
     231    psS32   skip = image->row0 - srcY;
     232    if (skip > 0) {
     233        dstY = skip;
     234        height -= skip;
     235        srcY = image->row0;
     236    }
     237    for ( ; dstY < height; srcY++, dstY++) {
     238        if (srcY >= lastY) {
     239            break;
     240        }
     241        psU8 *pdst = output->data.U8[dstY];
     242
     243        psU8 *psrc = image->data.U8[srcY]  + (srcX * elementSize);
     244
     245        // copy copyWidth pixels from srcX,srcY to dstX, dstY
     246        pdst += dstX*elementSize;
     247        memcpy(pdst, psrc, copySize);
     248    }
    170249
    171250    return output;
     
    243322        }
    244323
    245         outReadout->image = extractStamp(readout->image, extractRegion);
     324        outReadout->image = extractStamp(readout->image, extractRegion,  0);
    246325        if (!outReadout->image) {
    247             psError(PS_ERR_UNKNOWN, false, "failed to allocate create postage stamp image\n");
     326            psError(PS_ERR_UNKNOWN, false, "failed to create postage stamp image\n");
    248327            status = false;
    249328            break;
Note: See TracChangeset for help on using the changeset viewer.