IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 16158


Ignore:
Timestamp:
Jan 18, 2008, 5:19:50 PM (18 years ago)
Author:
Paul Price
Message:

Need to check for underflow and overflow.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/pap_branch_080117/psLib/src/fits/psFitsScale.c

    r16141 r16158  
    319319        ps##INTYPE scale = 1.0 / bscale; \
    320320        ps##INTYPE zero = bzero; \
    321         if (options->fuzz) { \
    322             /* Add random factor [0,1): adds a variance of 1/12, but preserves the expectation value */ \
    323             for (int y = 0; y < numRows; y++) { \
    324                 for (int x = 0; x < numCols; x++) { \
    325                     ps##INTYPE random = psRandomUniform(rng); \
    326                     (OUT)->data.OUTTYPE[y][x] = ((IN)->data.INTYPE[y][x] - zero) * scale + random; \
     321        ps##INTYPE min = - (1 << (options->bitpix - 1)); \
     322        ps##INTYPE max = (1 << (options->bitpix - 1)) - 1; \
     323        for (int y = 0; y < numRows; y++) { \
     324            for (int x = 0; x < numCols; x++) { \
     325                ps##INTYPE value = ((IN)->data.INTYPE[y][x] - zero) * scale; \
     326                if (options->fuzz) { \
     327                   /* Add random factor [0,1): adds a variance of 1/12, */ \
     328                   /* but preserves the expectation value */ \
     329                    value += psRandomUniform(rng); \
    327330                } \
    328             } \
    329         } else { \
    330             /* No random factor added: data preserved, but expectation value is not */ \
    331             for (int y = 0; y < numRows; y++) { \
    332                 for (int x = 0; x < numCols; x++) { \
    333                     (OUT)->data.OUTTYPE[y][x] = ((IN)->data.INTYPE[y][x] - zero) * scale; \
    334                 } \
     331                /* Check for underflow and overflow */ \
     332                (OUT)->data.OUTTYPE[y][x] = (value < min ? min : (value > max ? max : value)); \
    335333            } \
    336334        } \
Note: See TracChangeset for help on using the changeset viewer.