IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 17, 2004, 4:34:00 PM (22 years ago)
Author:
desonia
Message:

modified psImage to match currect IfA input and added copy function.

File:
1 edited

Legend:

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

    r712 r714  
    77 *  @author Ross Harman, MHPCC
    88 *   
    9  *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-05-17 21:00:24 $
     9 *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-05-18 02:33:59 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    121121
    122122    for (int row = 0; row < numRows; row++) {
    123         memcpy(out->data.v[row],image->data.u8[row0+row] + inputColOffset,outputRowSize);
     123        memcpy(out->data.v[row],image->data.U8[row0+row] + inputColOffset,outputRowSize);
    124124    }
    125125
     
    165165    return numFreed;
    166166}
     167
     168psImage *psImageCopy(psImage* restrict output, const psImage *input, psElemType type)
     169{
     170    psElemType inDatatype;
     171    int elementSize;
     172    int numRows;
     173    int numCols;
     174
     175    if (input == NULL || input->data.v == NULL) {
     176        psError(__func__,"Can not copy image because input image or its pixel buffer is NULL.");
     177        return NULL;
     178    }
     179
     180    if (input == output) {
     181        psError(__func__,"Can not copy image because given input and output parameter reference the same "
     182                "psImage struct.");
     183        return NULL;
     184    }
     185
     186    if (input->type.dimen != PS_DIMEN_IMAGE) {
     187        psError(__func__,"Can not copy image because input image is not actually an image.");
     188        return NULL;
     189    }
     190
     191    inDatatype = input->type.type;
     192    numRows = input->numRows;
     193    numCols = input->numCols;
     194    elementSize = PSELEMTYPE_SIZEOF(inDatatype);
     195
     196    if (inDatatype == PS_TYPE_PTR || type == PS_TYPE_PTR) {
     197        psError(__func__,"Can not copy image to/from a void* matrix");
     198        return NULL;
     199    }
     200
     201
     202    if (output == NULL) {
     203        output = psImageAlloc(numCols,numRows,type);
     204    } else if (output->numCols != numCols || output->numRows != numRows ||
     205               output->type.type != type) {        // sizes/type different, can't reuse the given image buffer
     206        psImageFree(output);
     207        output = psImageAlloc(numCols,numRows,type);
     208    }
     209
     210    // cover the trival case of copy of the same type.
     211    if (type == inDatatype) {
     212        memcpy(output->data.v[0],input->data.v[0],elementSize*numRows*numCols);
     213        return output;
     214    }
     215
     216    #define PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,INTYPE,OUTTYPE) \
     217    { \
     218        ps##INTYPE *in; \
     219        ps##OUTTYPE *out; \
     220        for (int row=0;row<numRows;row++) { \
     221            in = IN->data.INTYPE[row]; \
     222            out = OUT->data.OUTTYPE[row]; \
     223            for (int col=0;col<numCols;col++) { \
     224                in[col] = (ps##INTYPE) out[col]; \
     225            } \
     226        } \
     227    }
     228
     229    #define PSIMAGE_ELEMENT_ASSIGN(OUT,IN,OUTTYPE) \
     230    switch (IN->type.type) { \
     231    case PS_TYPE_S8: \
     232        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,S8,OUTTYPE); \
     233        break; \
     234    case PS_TYPE_S16: \
     235        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,S16,OUTTYPE); \
     236        break; \
     237    case PS_TYPE_S32: \
     238        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,S32,OUTTYPE); \
     239        break; \
     240    case PS_TYPE_S64: \
     241        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,S64,OUTTYPE); \
     242        break; \
     243    case PS_TYPE_U8: \
     244        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,U8,OUTTYPE); \
     245        break; \
     246    case PS_TYPE_U16: \
     247        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,U16,OUTTYPE); \
     248        break; \
     249    case PS_TYPE_U32: \
     250        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,U32,OUTTYPE); \
     251        break; \
     252    case PS_TYPE_U64: \
     253        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,U64,OUTTYPE); \
     254        break; \
     255    case PS_TYPE_F32: \
     256        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,F32,OUTTYPE); \
     257        break; \
     258    case PS_TYPE_F64: \
     259        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,F64,OUTTYPE); \
     260        break; \
     261    case PS_TYPE_C32: \
     262        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,C32,OUTTYPE); \
     263        break; \
     264    default: \
     265        break; \
     266    }
     267
     268    switch (type) {
     269    case PS_TYPE_S8:
     270        PSIMAGE_ELEMENT_ASSIGN(output,input,S8);
     271        break;
     272    case PS_TYPE_S16:
     273        PSIMAGE_ELEMENT_ASSIGN(output,input,S16);
     274        break;
     275    case PS_TYPE_S32:
     276        PSIMAGE_ELEMENT_ASSIGN(output,input,S32);
     277        break;
     278    case PS_TYPE_S64:
     279        PSIMAGE_ELEMENT_ASSIGN(output,input,S64);
     280        break;
     281    case PS_TYPE_U8:
     282        PSIMAGE_ELEMENT_ASSIGN(output,input,U8);
     283        break;
     284    case PS_TYPE_U16:
     285        PSIMAGE_ELEMENT_ASSIGN(output,input,U16);
     286        break;
     287    case PS_TYPE_U32:
     288        PSIMAGE_ELEMENT_ASSIGN(output,input,U32);
     289        break;
     290    case PS_TYPE_U64:
     291        PSIMAGE_ELEMENT_ASSIGN(output,input,U64);
     292        break;
     293    case PS_TYPE_F32:
     294        PSIMAGE_ELEMENT_ASSIGN(output,input,F32);
     295        break;
     296    case PS_TYPE_F64:
     297        PSIMAGE_ELEMENT_ASSIGN(output,input,F64);
     298        break;
     299    case PS_TYPE_C32:
     300        PSIMAGE_ELEMENT_ASSIGN(output,input,C32);
     301        break;
     302    case PS_TYPE_C64:
     303        PSIMAGE_ELEMENT_ASSIGN(output,input,C64);
     304        break;
     305    case PS_TYPE_PTR:
     306        psError(__func__,"Can't copy image into a matrix of pointers.");
     307        psImageFree(output);
     308        return NULL;
     309    }
     310
     311    return output;
     312}
Note: See TracChangeset for help on using the changeset viewer.