IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 2375 for trunk/psLib/src/image


Ignore:
Timestamp:
Nov 16, 2004, 10:00:21 AM (22 years ago)
Author:
desonia
Message:

Added some psfits and pslist changes. More work needs to be done to make it match the current SDRS.

Location:
trunk/psLib/src/image
Files:
5 edited

Legend:

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

    r2291 r2375  
    99 *  @author Ross Harman, MHPCC
    1010 *
    11  *  @version $Revision: 1.53 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-11-06 00:44:56 $
     11 *  @version $Revision: 1.54 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-11-16 20:00:21 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2626#include "psImageErrors.h"
    2727
    28 static void imageFree(psImage* image);
     28static void imageFree(psImage* image)
     29{
     30    if (image == NULL) {
     31        return;
     32    }
     33
     34    if (image->type.type == PS_TYPE_PTR) {
     35        // 2-D array of pointers -- must dereference elements
     36        psU32 oldNumRows = image->numRows;
     37        psU32 oldNumCols = image->numCols;
     38        psPtr* rowPtr;
     39
     40        for (psU32 row = 0; row < oldNumRows; row++) {
     41            rowPtr = image->data.PTR[row];
     42            for (psU32 col = 0; col < oldNumCols; col++) {
     43                psMemDecrRefCounter(rowPtr[col]);
     44            }
     45        }
     46    }
     47
     48    if (image->parent != NULL) {
     49        psArrayRemove(image->parent->children,image);
     50        image->parent = NULL;
     51    }
     52
     53    psImageFreeChildren(image);
     54
     55    psFree(image->rawDataBuffer);
     56    psFree(image->data.V);
     57}
    2958
    3059psImage* psImageAlloc(psU32 numCols,
     
    71100}
    72101
    73 static void imageFree(psImage* image)
     102psRegion* psRegionAlloc(double x0,
     103                        double x1,
     104                        double y0,
     105                        double y1)
    74106{
    75     if (image == NULL) {
    76         return;
    77     }
    78 
    79     if (image->type.type == PS_TYPE_PTR) {
    80         // 2-D array of pointers -- must dereference elements
    81         psU32 oldNumRows = image->numRows;
    82         psU32 oldNumCols = image->numCols;
    83         psPtr* rowPtr;
    84 
    85         for (psU32 row = 0; row < oldNumRows; row++) {
    86             rowPtr = image->data.PTR[row];
    87             for (psU32 col = 0; col < oldNumCols; col++) {
    88                 psMemDecrRefCounter(rowPtr[col]);
    89             }
    90         }
    91     }
    92 
    93     if (image->parent != NULL) {
    94         psArrayRemove(image->parent->children,image);
    95         image->parent = NULL;
    96     }
    97 
    98     psImageFreeChildren(image);
    99 
    100     psFree(image->rawDataBuffer);
    101     psFree(image->data.V);
    102 }
     107    psRegion* out = psAlloc(sizeof(psRegion));
     108
     109    out->x0 = x0;
     110    out->y0 = y0;
     111    out->x1 = x1;
     112    out->y1 = y1;
     113
     114    return out;
     115}
     116
     117
     118
     119psRegion* psRegionFromString(char* region)
     120{
     121    psS32 col0;
     122    psS32 col1;
     123    psS32 row0;
     124    psS32 row1;
     125
     126    // section should be of the form '[col0:col1,row0:row1]'
     127    if (region == NULL) {
     128        psError(PS_ERR_BAD_PARAMETER_NULL, true,
     129                PS_ERRORTEXT_psImage_SUBSECTION_NULL);
     130        return NULL;
     131    }
     132
     133    if (sscanf(region,"[%d:%d,%d:%d]",&col0,&col1,&row0,&row1) < 4) {
     134        psError(PS_ERR_BAD_PARAMETER_NULL, true,
     135                PS_ERRORTEXT_psImage_SUBSECTION_INVALID,
     136                region);
     137        return NULL;
     138    }
     139
     140    if (col0 > col1 || row0 > row1) {
     141        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     142                PS_ERRORTEXT_psImage_SUBSET_RANGE_MALFORMED,
     143                col0,col1,row0,row1);
     144        return NULL;
     145    }
     146
     147    return psRegionAlloc(col0,col1,row0,row1);
     148}
     149
    103150
    104151psImage* psImageRecycle(psImage* old,
  • trunk/psLib/src/image/psImage.h

    r2204 r2375  
    1111 *  @author Ross Harman, MHPCC
    1212 *
    13  *  @version $Revision: 1.42 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2004-10-27 00:57:31 $
     13 *  @version $Revision: 1.43 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2004-11-16 20:00:21 $
    1515 *
    1616 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    7575psImage;
    7676
     77/** Basic image region structure.
     78 *
     79 * Struct for specifying a rectangular area in an image.
     80 *
     81 */
     82typedef struct
     83{
     84    double x0;                         ///< the first column of the region.
     85    double x1;                         ///< the last column of the region.
     86    double y0;                         ///< the first row of the region.
     87    double y1;                         ///< the last row of the region.
     88}
     89psRegion;
     90
    7791/** Create an image of the specified size and type.
    7892 *
     
    8498 */
    8599psImage* psImageAlloc(
    86     psU32 numCols,              ///< Number of rows in image.
    87     psU32 numRows,              ///< Number of columns in image.
     100    psU32 numCols,                     ///< Number of rows in image.
     101    psU32 numRows,                     ///< Number of columns in image.
    88102    const psElemType type              ///< Type of data for image.
     103);
     104
     105/** Create an image of the specified size and type.
     106 *
     107 * Uses psLib memory allocation functions to create an image struct of the
     108 * specified size and type.
     109 *
     110 * @return psImage* : Pointer to psImage.
     111 *
     112 */
     113psRegion* psRegionAlloc(
     114    double x0,                         ///< the first column of the region.
     115    double x1,                         ///< the last column of the region.
     116    double y0,                         ///< the first row of the region.
     117    double y1                          ///< the last row of the region.
     118);
     119
     120psRegion* psRegionFromString(
     121    char* region                       ///< image rectangular region in the form '[x0:x1,y0:y1]'
    89122);
    90123
     
    96129psImage* psImageRecycle(
    97130    psImage* old,                      ///< the psImage to recycle by resizing image buffer
    98     psU32 numCols,              ///< the desired number of columns in image
    99     psU32 numRows,              ///< the desired number of rows in image
     131    psU32 numCols,                     ///< the desired number of columns in image
     132    psU32 numRows,                     ///< the desired number of rows in image
    100133    const psElemType type              ///< the desired datatype of the image
    101134);
  • trunk/psLib/src/image/psImageConvolve.c

    r2273 r2375  
    55 *  @author Robert DeSonia, MHPCC
    66 *
    7  *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
    8  *  @date $Date: 2004-11-04 01:05:00 $
     7 *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
     8 *  @date $Date: 2004-11-16 20:00:21 $
    99 *
    1010 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    9393                           psBool relative)
    9494{
    95     psS32 x = 0;
    96     psS32 y = 0;
    97     psS32 t = 0;
    98     psS32 deltaT;
     95    psS32 lastX;
     96    psS32 lastY;
     97    psS32 lastT;
     98    psS32 x;
     99    psS32 y;
     100    psS32 t;
    99101    psS32 oldX;
    100102    psS32 oldY;
     
    148150        ps##TYPE *xShiftData = xShifts->data.TYPE; \
    149151        ps##TYPE *yShiftData = yShifts->data.TYPE; \
    150         x = 0; \
    151         y = 0; \
    152         t = 0; \
    153         for (psS32 lcv = 0; lcv < length; lcv++) { \
    154             if (relative) { \
    155                 x += xShiftData[lcv]; \
    156                 y += yShiftData[lcv]; \
    157                 t += tShiftData[lcv]; \
    158             } else { \
    159                 x = xShiftData[lcv]; \
    160                 y = yShiftData[lcv]; \
    161                 t = tShiftData[lcv]; \
    162             } \
     152        lastX =  xShiftData[length-1]; \
     153        lastY =  yShiftData[length-1]; \
     154        \
     155        for (int lcv = 0; lcv < length; lcv++) { \
     156            x = lastX - xShiftData[lcv]; \
     157            y = lastY - yShiftData[lcv]; \
     158            \
    163159            if (x < xMin) { \
    164160                xMin = x; \
     
    172168            } \
    173169        } \
     170        \
     171        normalizeTime = 1.0 / (psKernelType)(lastT - tShiftData[0]); \
    174172        result = psKernelAlloc(xMin,xMax,yMin,yMax); \
    175173        kernel = result->kernel; \
    176174        \
    177         normalizeTime = 1.0 / (psKernelType)(t); \
     175        lastT = 0; \
     176        for (int i = 0; i < length; i++) { \
     177            t = tShiftData[i] - lastT; \
     178            x = lastX - xShiftData[i]; \
     179            y = lastY - yShiftData[i]; \
     180            \
     181            kernel[y][x] += (psKernelType)t * normalizeTime; \
     182            lastT = t; \
     183        } \
     184        break; \
     185    }
     186
     187    #define RELATIVE_KERNEL_GENERATE_CASE(TYPE) \
     188case PS_TYPE_##TYPE: { \
     189        ps##TYPE *tShiftData = tShifts->data.TYPE; \
     190        ps##TYPE *xShiftData = xShifts->data.TYPE; \
     191        ps##TYPE *yShiftData = yShifts->data.TYPE; \
     192        \
    178193        x = 0; \
    179194        y = 0; \
    180195        t = 0; \
    181         for (psS32 i = 0; i < length; i++) { \
    182             deltaT = t; \
    183             oldX = x; \
    184             oldY = y; \
    185             if (relative) { \
    186                 t += tShiftData[i]; \
    187                 x += xShiftData[i]; \
    188                 y += yShiftData[i]; \
    189             } else { \
    190                 t = tShiftData[i]; \
    191                 x = xShiftData[i]; \
    192                 y = yShiftData[i]; \
     196        \
     197        for (int lcv = length-1; lcv >= 0; lcv--) { \
     198            t += tShiftData[lcv]; \
     199            \
     200            if (x < xMin) { \
     201                xMin = x; \
     202            } else if (x > xMax) { \
     203                xMax = x; \
    193204            } \
    194             deltaT = t - deltaT; \
     205            if (y < yMin) { \
     206                yMin = y; \
     207            } else if (y > yMax) { \
     208                yMax = y; \
     209            } \
     210            x += xShiftData[lcv]; \
     211            y += yShiftData[lcv]; \
    195212            \
    196             kernel[oldY][oldX] += deltaT * normalizeTime; \
     213        } \
     214        result = psKernelAlloc(xMin,xMax,yMin,yMax); \
     215        kernel = result->kernel; \
     216        \
     217        normalizeTime = 1.0 / (psKernelType)t; \
     218        x = 0; \
     219        y = 0; \
     220        for (psS32 i = length-1; i >= 0; i--) { \
     221            kernel[y][x] += (psKernelType)(tShiftData[i]) * normalizeTime; \
     222            x += xShiftData[i]; \
     223            y += yShiftData[i]; \
     224            \
    197225        } \
    198226        break; \
    199227    }
    200228
    201     switch (xShifts->type.type) {
    202         KERNEL_GENERATE_CASE(U8);
    203         KERNEL_GENERATE_CASE(U16);
    204         KERNEL_GENERATE_CASE(U32);
    205         KERNEL_GENERATE_CASE(U64);
    206         KERNEL_GENERATE_CASE(S8);
    207         KERNEL_GENERATE_CASE(S16);
    208         KERNEL_GENERATE_CASE(S32);
    209         KERNEL_GENERATE_CASE(S64);
    210         KERNEL_GENERATE_CASE(F32);
    211         KERNEL_GENERATE_CASE(F64);
    212         KERNEL_GENERATE_CASE(C32);
    213         KERNEL_GENERATE_CASE(C64);
    214 
    215     default: {
    216             char* typeStr;
    217             PS_TYPE_NAME(typeStr,xShifts->type.type);
    218             psError(PS_ERR_BAD_PARAMETER_TYPE, true,
    219                     PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED,
    220                     typeStr);
     229    if (relative) {
     230        switch (xShifts->type.type) {
     231            RELATIVE_KERNEL_GENERATE_CASE(U8);
     232            RELATIVE_KERNEL_GENERATE_CASE(U16);
     233            RELATIVE_KERNEL_GENERATE_CASE(U32);
     234            RELATIVE_KERNEL_GENERATE_CASE(U64);
     235            RELATIVE_KERNEL_GENERATE_CASE(S8);
     236            RELATIVE_KERNEL_GENERATE_CASE(S16);
     237            RELATIVE_KERNEL_GENERATE_CASE(S32);
     238            RELATIVE_KERNEL_GENERATE_CASE(S64);
     239            RELATIVE_KERNEL_GENERATE_CASE(F32);
     240            RELATIVE_KERNEL_GENERATE_CASE(F64);
     241            RELATIVE_KERNEL_GENERATE_CASE(C32);
     242            RELATIVE_KERNEL_GENERATE_CASE(C64);
     243
     244        default: {
     245                char* typeStr;
     246                PS_TYPE_NAME(typeStr,xShifts->type.type);
     247                psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     248                        PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED,
     249                        typeStr);
     250            }
     251        }
     252    } else {
     253        switch (xShifts->type.type) {
     254            KERNEL_GENERATE_CASE(U8);
     255            KERNEL_GENERATE_CASE(U16);
     256            KERNEL_GENERATE_CASE(U32);
     257            KERNEL_GENERATE_CASE(U64);
     258            KERNEL_GENERATE_CASE(S8);
     259            KERNEL_GENERATE_CASE(S16);
     260            KERNEL_GENERATE_CASE(S32);
     261            KERNEL_GENERATE_CASE(S64);
     262            KERNEL_GENERATE_CASE(F32);
     263            KERNEL_GENERATE_CASE(F64);
     264            KERNEL_GENERATE_CASE(C32);
     265            KERNEL_GENERATE_CASE(C64);
     266
     267        default: {
     268                char* typeStr;
     269                PS_TYPE_NAME(typeStr,xShifts->type.type);
     270                psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     271                        PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED,
     272                        typeStr);
     273            }
    221274        }
    222275    }
  • trunk/psLib/src/image/psImageErrors.h

    r2093 r2375  
    77 *  @author Robert DeSonia, MHPCC
    88 *
    9  *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-10-13 23:34:57 $
     9 *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-11-16 20:00:21 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
  • trunk/psLib/src/image/psImageManip.h

    r2204 r2375  
    1111 *  @author Ross Harman, MHPCC
    1212 *
    13  *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2004-10-27 00:57:31 $
     13 *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2004-11-16 20:00:21 $
    1515 *
    1616 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    8383    psImage* image,                    ///< target image
    8484    const psImage* overlay,            ///< the overlay image
    85     psS32 col0,                          ///< the column to start overlay
    86     psS32 row0,                          ///< the row to start overlay
     85    psS32 col0,                        ///< the column to start overlay
     86    psS32 row0,                        ///< the row to start overlay
    8787    const char *op                     ///< the operation to perform for overlay
    8888);
     
    103103    const psImage* restrict mask,      ///< mask for input image.  If NULL, no masking is done.
    104104    psMaskType maskVal,                ///< the bits to check in mask.
    105     psU32 scale,                ///< the scale to rebin for each dimension
     105    psU32 scale,                       ///< the scale to rebin for each dimension
    106106    const psStats* stats
    107107    ///< the statistic to perform when rebinning.  Only one method should be set.
     
    121121    psImage* out,                      ///< an psImage to recycle.  If NULL, a new image is created
    122122    const psImage* in,                 ///< input image
    123     psS32 scale,                         ///< resample scaling factor
     123    psS32 scale,                       ///< resample scaling factor
    124124    psImageInterpolateMode mode        ///< the interpolation mode used in resampling
    125125);
     
    176176    psImage* out,                      ///< an psImage to recycle.  If NULL, a new image is created
    177177    const psImage* in,                 ///< input image
    178     psS32 dx,                            ///< number of pixels to roll in the x-dimension
    179     psS32 dy                             ///< number of pixels to roll in the y-dimension
     178    psS32 dx,                          ///< number of pixels to roll in the x-dimension
     179    psS32 dy                           ///< number of pixels to roll in the y-dimension
    180180);
    181181
Note: See TracChangeset for help on using the changeset viewer.