IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1226


Ignore:
Timestamp:
Jul 15, 2004, 9:58:37 AM (22 years ago)
Author:
desonia
Message:

Added psImageRoll.

Location:
trunk/psLib/src
Files:
4 edited

Legend:

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

    r1216 r1226  
    1010 *  @author Ross Harman, MHPCC
    1111 *
    12  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-07-14 23:22:49 $
     12 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-07-15 19:58:37 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1818#include <stdlib.h>
    1919#include <stdbool.h>
     20#include <string.h>                    // for memcpy, etc.
    2021
    2122#include "psError.h"
     
    5051            if (vmin < PS_MIN_##type || vmin > PS_MAX_##type) { \
    5152                psError(__func__, "Specified vmin (%g) is outside of image's " \
    52                         typename " pixel range", \
    53                         vmin); \
     53                        typename " pixel range (%g to %g)", \
     54                        vmin,(psF64)PS_MIN_##type,(psF64)PS_MAX_##type); \
    5455            } \
    5556            if (vmax > PS_MAX_##type || vmax < PS_MIN_##type) { \
    5657                psError(__func__, "Specified vmax (%g) is outside of image's " \
    57                         typename " pixel range", \
    58                         vmax); \
    59             } \
    60             ps##type minimum = (ps##type) min; \
    61             ps##type maximum = (ps##type) max; \
     58                        typename " pixel range (%g to %g)", \
     59                        vmax,(psF64)PS_MIN_##type,(psF64)PS_MAX_##type); \
     60            } \
    6261            for (unsigned int row = 0;row<numRows;row++) { \
    6362                ps##type* inputRow = input->data.type[row]; \
    6463                for (unsigned int col = 0; col < numCols; col++) { \
    65                     if (inputRow[col] < minimum) { \
     64                    if ((psF64)inputRow[col] < min) { \
    6665                        inputRow[col] = (ps##type)vmin; \
    6766                        numClipped++; \
    68                     } else if (inputRow[col] > maximum) { \
     67                    } else if ((psF64)inputRow[col] > max) { \
    6968                        inputRow[col] = (ps##type)vmax; \
    7069                        numClipped++; \
     
    341340
    342341    switch (stats->options &
    343             ! (PS_STAT_USE_RANGE | PS_STAT_USE_BINSIZE | PS_STAT_ROBUST_FOR_SAMPLE)) {
     342            ~ (PS_STAT_USE_RANGE | PS_STAT_USE_BINSIZE | PS_STAT_ROBUST_FOR_SAMPLE)) {
    344343    case PS_STAT_SAMPLE_MEAN:
    345344        *value = stats->sampleMean;
     
    484483    return out;
    485484}
     485
     486psImage* psImageRoll(psImage* out, const psImage* in, int dx, int dy)
     487{
     488    int outRows;
     489    int outCols;
     490    int elementSize;
     491
     492    if (in == NULL) {
     493        psError(__func__,"Input image can not be NULL.");
     494        return NULL;
     495    }
     496
     497    // create an output image of the same size and type
     498    outRows = in->numRows;
     499    outCols = in->numCols;
     500    elementSize = PSELEMTYPE_SIZEOF(in->type.type);
     501    out = psImageRecycle(out,outCols, outRows, in->type.type);
     502
     503    // make dx and dy between 0 and outCols or outRows, respectively
     504    dx = dx % outCols;
     505    dy = dy % outRows;
     506    if (dx < 0) {
     507        dx += outCols;
     508    }
     509    if (dy < 0) {
     510        dy += outRows;
     511    }
     512
     513    int segment1Size = elementSize*(outCols-dx);
     514    int segment2Size = elementSize*dx;
     515
     516    for (int row=0;row<outRows;row++) {
     517        int inRowNumber = row+dy;
     518        if (inRowNumber >= outRows) {
     519            inRowNumber -= outRows;
     520        }
     521        psU8* inRow = in->data.U8[inRowNumber]; // to allow byte arithmetic, but for all types
     522        psU8* outRow = out->data.U8[row];
     523        memcpy(outRow,inRow+segment2Size,segment1Size);
     524        memcpy(outRow+segment1Size,inRow,segment2Size);
     525    }
     526
     527    return out;
     528}
  • trunk/psLib/src/image/psImageManip.h

    r1216 r1226  
    1010 *  @author Ross Harman, MHPCC
    1111 *
    12  *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-07-14 23:22:49 $
     12 *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-07-15 19:58:37 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    104104);
    105105
     106/** Roll image by an integer number of pixels in either direction.
     107 *
     108 *  The output image is the same dimensions as the input image.  Edge pixels
     109 *  wrap to the other side (no values are lost).  This function is
     110 *  defined for psU8, psS8, psS16, psF32, psF64, psC32, and psC64.
     111 *
     112 *  @return psImage*    the rolled version of the input image.
     113 */
     114psImage* psImageRoll(
     115    psImage* out,                   ///< an psImage to recycle.  If NULL, a new image is created
     116    const psImage* in,              ///< input image
     117    int dx,                         ///< number of pixels to roll in the x-dimension
     118    int dy                          ///< number of pixels to roll in the y-dimension
     119);
     120
    106121#endif
    107122
  • trunk/psLib/src/sys/psType.h

    r1216 r1226  
    1010 *  @author Ross Harman, MHPCC
    1111 *
    12  *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-07-14 23:22:49 $
     12 *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-07-15 19:58:37 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    7979#define PS_MIN_U32       0
    8080#define PS_MIN_U64       0
    81 #define PS_MIN_F32       FLT_MIN
    82 #define PS_MIN_F64       DBL_MIN
    83 #define PS_MIN_C32       FLT_MIN
    84 #define PS_MIN_C64       DBL_MIN
     81#define PS_MIN_F32       -FLT_MAX
     82#define PS_MIN_F64       -DBL_MAX
     83#define PS_MIN_C32       -FLT_MAX
     84#define PS_MIN_C64       -DBL_MAX
    8585
    8686#define PS_MAX_S8        INT8_MAX
  • trunk/psLib/src/sysUtils/psType.h

    r1216 r1226  
    1010 *  @author Ross Harman, MHPCC
    1111 *
    12  *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-07-14 23:22:49 $
     12 *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-07-15 19:58:37 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    7979#define PS_MIN_U32       0
    8080#define PS_MIN_U64       0
    81 #define PS_MIN_F32       FLT_MIN
    82 #define PS_MIN_F64       DBL_MIN
    83 #define PS_MIN_C32       FLT_MIN
    84 #define PS_MIN_C64       DBL_MIN
     81#define PS_MIN_F32       -FLT_MAX
     82#define PS_MIN_F64       -DBL_MAX
     83#define PS_MIN_C32       -FLT_MAX
     84#define PS_MIN_C64       -DBL_MAX
    8585
    8686#define PS_MAX_S8        INT8_MAX
Note: See TracChangeset for help on using the changeset viewer.