IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 23, 2004, 12:36:04 PM (22 years ago)
Author:
desonia
Message:

changed psImageSubset to subset an image without making a deep copy.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/image/psImageExtraction.c

    r1603 r1606  
    1010*  @author Robert DeSonia, MHPCC
    1111*
    12 *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2004-08-20 01:10:54 $
     12*  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2004-08-23 22:36:03 $
    1414*
    1515*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2323#include "psError.h"
    2424
    25 psImage* psImageSubset(psImage* out,
    26                        psImage* image,
     25psImage* psImageSubset(psImage* image,
    2726                       unsigned int numCols,
    2827                       unsigned int numRows,
     
    3029                       unsigned int row0)
    3130{
    32     unsigned int elementSize;   // size of image
    33 
    34     // element in
    35     // bytes
    36     unsigned int outputRowSize; // output row
    37 
    38     // size in bytes
    39     unsigned int inputColOffset;        // offset
    40 
    41     // in
    42     // bytes
    43     // to
    44     // first
    45     // subset
    46 
    47     // pixel in input row
     31    psImage* out;
     32    unsigned int elementSize;          // size of image element in bytes
     33    unsigned int inputColOffset;       // offset in bytes to first subset pixel in input row
    4834
    4935    if (image == NULL || image->data.V == NULL) {
     
    8066    elementSize = PSELEMTYPE_SIZEOF(image->type.type);
    8167
    82     out = psImageRecycle(out, numCols, numRows, image->type.type);
    83 
    84     // set the parent information into the child
    85     // output image
    86     *(int *)&out->row0 = row0;
    87     *(int *)&out->col0 = col0;
    88     *(psImage* *) & out->parent = (psImage* ) image;
     68    out = psAlloc(sizeof(psImage));
     69    *(psType*)&out->type = image->type;
     70    *(unsigned int*)&out->numCols = numCols;
     71    *(unsigned int*)&out->numRows = numRows;
     72    *(int*)&out->row0 = row0;
     73    *(int*)&out->col0 = col0;
     74    out->parent = image;
     75    out->nChildren = 0;
     76    out->children = NULL;
     77    out->rawDataBuffer = psMemIncrRefCounter(image->rawDataBuffer);
     78    out->data.V = psAlloc(sizeof(void*)*numRows);
     79
     80    // set the new psImage's deallocator to the same as the input image
     81    p_psMemSetDeallocator(out,p_psMemGetDeallocator(image));
     82
     83    inputColOffset = elementSize * col0;
     84    for (int row = 0; row < numRows; row++) {
     85        out->data.V[row] = image->data.U8[row0 + row] + inputColOffset;
     86    }
    8987
    9088    // add output image as a child of the input
    9189    // image.
    9290    image->nChildren++;
    93     image->children = (psImage* *) psRealloc(image->children, image->nChildren * sizeof(psImage* ));
     91    image->children = (psImage**) psRealloc(image->children, image->nChildren * sizeof(psImage* ));
    9492    image->children[image->nChildren - 1] = out;
    95 
    96     inputColOffset = elementSize * col0;
    97     outputRowSize = elementSize * numCols;
    98 
    99     for (int row = 0; row < numRows; row++) {
    100         memcpy(out->data.V[row], image->data.U8[row0 + row] + inputColOffset, outputRowSize);
    101     }
    10293
    10394    return (out);
     
    151142    // datatype.
    152143    if (type == inDatatype) {
    153         memcpy(output->data.V[0], input->data.V[0], elementSize * elements);
     144        for (int row=0;row<numRows;row++) {
     145            memcpy(output->data.V[row], input->data.V[row], elementSize * numCols);
     146        }
    154147        return output;
    155148    }
    156149    #define PSIMAGE_ELEMENT_COPY(IN,INTYPE,OUT,OUTTYPE,ELEMENTS) { \
    157         ps##INTYPE *in = IN->data.INTYPE[0]; \
    158         ps##OUTTYPE *out = OUT->data.OUTTYPE[0]; \
    159         for (int e=0;e<ELEMENTS;e++) { \
    160             *(out++) = *(in++); \
     150        ps##INTYPE *in; \
     151        ps##OUTTYPE *out; \
     152        for(int row=0;row<numRows;row++) { \
     153            in = IN->data.INTYPE[row]; \
     154            out = OUT->data.OUTTYPE[row]; \
     155            for (int col=0;col<numCols;col++) { \
     156                *(out++) = *(in++); \
     157            } \
    161158        } \
    162159    }
Note: See TracChangeset for help on using the changeset viewer.