IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jun 1, 2004, 10:00:08 AM (22 years ago)
Author:
desonia
Message:

added psImageClip* functions.

File:
1 edited

Legend:

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

    r816 r820  
    99 *  @author Ross Harman, MHPCC
    1010 *
    11  *  @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-05-29 01:42:12 $
     11 *  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-06-01 20:00:08 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1818/*  INCLUDE FILES                                                             */
    1919/******************************************************************************/
     20
    2021#include <string.h>
     22#include <math.h>
    2123
    2224#include "psMemory.h"
     
    384386}
    385387
     388int psImageClip(psImage* input,float min,float vmin,float max,float vmax)
     389{
     390    int numClipped = 0;
     391    psU32 numRows;
     392    psU32 numCols;
     393
     394    if (input == NULL) {
     395        return 0;
     396    }
     397    numRows = input->numRows;
     398    numCols = input->numCols;
     399
     400    switch (input->type.type) {
     401
     402        #define psImageClipCase(type) \
     403    case PS_TYPE_##type: { \
     404            ps##type minimum = (ps##type) min; \
     405            ps##type maximum = (ps##type) max; \
     406            for (psU32 row = 0;row<numRows;row++) { \
     407                ps##type* inputRow = input->data.type[row]; \
     408                for (psU32 col = 0; col < numCols; col++) { \
     409                    if (inputRow[col] < minimum) { \
     410                        inputRow[col] = (ps##type)vmin; \
     411                        numClipped++; \
     412                    } else if (inputRow[col] > maximum) { \
     413                        inputRow[col] = (ps##type)vmax; \
     414                        numClipped++; \
     415                    } \
     416                } \
     417            } \
     418        } \
     419        break;
     420
     421        psImageClipCase(S8)
     422        psImageClipCase(S16)
     423        psImageClipCase(S32)
     424        psImageClipCase(S64)
     425        psImageClipCase(U8)
     426        psImageClipCase(U16)
     427        psImageClipCase(U32)
     428        psImageClipCase(U64)
     429        psImageClipCase(F32)
     430        psImageClipCase(F64)
     431
     432    default:
     433        psError(__func__,"psImageClip does not support the given datatype (%d)",
     434                input->type.type);
     435    }
     436
     437    return numClipped;
     438}
     439
     440int psImageClipNaN(psImage* input,float value)
     441{
     442    int numClipped = 0;
     443    psU32 numRows;
     444    psU32 numCols;
     445
     446    if (input == NULL) {
     447        return 0;
     448    }
     449    numRows = input->numRows;
     450    numCols = input->numCols;
     451
     452    switch (input->type.type) {
     453
     454        #define psImageClipNaNCase(type) \
     455    case PS_TYPE_##type: { \
     456            for (psU32 row = 0;row<numRows;row++) { \
     457                ps##type* inputRow = input->data.type[row]; \
     458                for (psU32 col = 0; col < numCols; col++) { \
     459                    if (! isfinite(inputRow[col])) { \
     460                        inputRow[col] = (ps##type)value; \
     461                        numClipped++; \
     462                    } \
     463                } \
     464            } \
     465        } \
     466        break;
     467
     468        psImageClipNaNCase(F32)
     469        psImageClipNaNCase(F64)
     470        psImageClipNaNCase(C32)
     471        psImageClipNaNCase(C64)
     472
     473    default:
     474        psError(__func__,"psImageClip does not support the given datatype (%d)",
     475                input->type.type);
     476    }
     477
     478    return numClipped;
     479}
Note: See TracChangeset for help on using the changeset viewer.