IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 692


Ignore:
Timestamp:
May 14, 2004, 12:39:58 PM (22 years ago)
Author:
desonia
Message:

Interim/pretest version.

Location:
trunk/psLib/src
Files:
4 edited

Legend:

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

    r664 r692  
    77 *  @author Ross Harman, MHPCC
    88 *   
    9  *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-05-13 20:03:35 $
     9 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-05-14 22:39:58 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1818#include "psMemory.h"
    1919#include "psError.h"
    20 #include "psVector.h"
    2120#include "psImage.h"
    2221
    23 /******************************************************************************/
    24 /*  DEFINE STATEMENTS                                                         */
    25 /******************************************************************************/
    26 
    27 // None
    28 
    29 /******************************************************************************/
    30 /*  TYPE DEFINITIONS                                                          */
    31 /******************************************************************************/
    32 
    33 // None
    34 
    35 /*****************************************************************************/
    36 /*  GLOBAL VARIABLES                                                         */
    37 /*****************************************************************************/
    38 
    39 // None
    40 
    41 /*****************************************************************************/
    42 /*  FILE STATIC VARIABLES                                                    */
    43 /*****************************************************************************/
    44 
    45 // None
    46 
    47 /*****************************************************************************/
    48 /*  FUNCTION IMPLEMENTATION - LOCAL                                          */
    49 /*****************************************************************************/
    50 
    51 // None
     22#include <string.h>
    5223
    5324/*****************************************************************************/
     
    5526/*****************************************************************************/
    5627
    57 psImage *psImageAlloc(unsigned int numCols, unsigned int numRows, psType type)
     28psImage *psImageAlloc(unsigned int numCols, unsigned int numRows, const psElemType type)
    5829{
    5930    int area = 0;
    60     psElemType imageType = 0;
    61     psDimen imageDim = 0;
    62     int elementSize = PSELEMTYPE_SIZEOF(type.type); // element size in bytes
     31    int elementSize = PSELEMTYPE_SIZEOF(type); // element size in bytes
    6332    int rowSize = numCols*elementSize;  // row size in bytes.
    6433
    65     imageType = type.type;
    66     imageDim =  type.dimen;
    6734    area = numCols*numRows;
    68 
    69     if(imageDim != PS_DIMEN_IMAGE) {
    70         psError(__func__, " : Image dimensionality not PS_DIMEN_IMAGE (3). Dimensionality: %d\n",
    71                 imageDim);
    72         return NULL;
    73     } else if(area <= 0) {
    74         psError(__func__, " : Invalid value for number of rows or columns. numRows: %d numCols: %d\n",
    75                 numRows, numCols);
    76         return NULL;
    77     }
    7835
    7936    psImage *image = (psImage *)psAlloc(sizeof(psImage));
    8037
    81     image->data.v[0] = psAlloc(area*elementSize);
     38    if(area < 1) {
     39        image->data.v[0] = NULL;
     40    } else {
     41        image->data.v[0] = psAlloc(area*elementSize);
    8242
    83     for(int i = 1; i < numRows; i++) {
    84         image->data.v[i] = (void*)((int8_t*)image->data.v[i-1]+rowSize);
     43        for(int i = 1; i < numRows; i++) {
     44            image->data.v[i] = (void*)((int8_t*)image->data.v[i-1]+rowSize);
     45        }
    8546    }
    8647
    87     image->col0 = 0;
    88     image->row0 = 0;
    89     image->numCols = numCols;
    90     image->numRows = numRows;
    91     image->type = type;
     48    *(int*)&image->col0 = 0;
     49    *(int*)&image->row0 = 0;
     50    *(unsigned int*)&image->numCols = numCols;
     51    *(unsigned int*)&image->numRows = numRows;
     52    *(psDimen*)&image->type.dimen = PS_DIMEN_IMAGE;
     53    *(psElemType*)&image->type.type = type;
    9254    image->parent = NULL;
    9355    image->nChildren = 0;
     
    10163    int i = 0;
    10264    int nChildren = 0;
    103     psElemType imageType = 0;
    104     psImage *children = NULL;
     65    psImage **children = NULL;
    10566
    10667    if(image != NULL) {
    107         imageType = image->type.type;
    10868        nChildren = image->nChildren;
    10969        children = image->children;
     70
     71        for(i=0; i<nChildren; i++) {
     72            psImageFree(children[i]);
     73        }
    11074
    11175        psFree(image->data.v[0]);
    11276        psFree(image->data.v);
    11377
    114         for(i=0; i<nChildren; i++) {
    115             psImageFree(&children[i]);
    116         }
    11778    }
    11879}
     80
     81psImage *psImageSubset(psImage *out,psImage *image,unsigned int numCols,
     82                       unsigned int numRows, unsigned int col0, unsigned int row0)
     83{
     84    psElemType type;
     85    unsigned int elementSize;           // size of image element in bytes
     86    unsigned int outputRowSize;         // output row size in bytes
     87    unsigned int inputColOffset;        // offset in bytes to first subset pixel in input row
     88
     89    if (image == NULL) {
     90        psError(__func__,"Can not subset image because input image is NULL.");
     91        return NULL;
     92    }
     93
     94    if (image->type.dimen != PS_DIMEN_IMAGE) {
     95        psError(__func__,"Can not subset image because input image is not an image.");
     96        return NULL;
     97    }
     98
     99    /* validate subimage size */
     100    if (col0+numCols >= image->numCols || row0+numRows >= image->numRows) {
     101        psError(__func__,"Can not subset image outside of image boundaries (size=%dx%d, "
     102                "subset=[%d:%d,%d:%d]).",image->numCols,image->numRows,image->col0,
     103                image->col0+numCols, image->row0, image->row0+numRows);
     104        return NULL;
     105    }
     106
     107    type = image->type.type;
     108    elementSize = PSELEMTYPE_SIZEOF(type);
     109
     110    if (out == NULL) {
     111        out = psImageAlloc(numCols,numRows,image->type.type);
     112    } else if (out->numCols != numCols || out->numRows != numRows || out->type.type != type) {
     113        // sizes/type different, can't reuse the given image buffer
     114        psImageFree(out);
     115        out = psImageAlloc(numCols,numRows,image->type.type);
     116    }
     117
     118    // set the parent information into the child output image
     119    *(int*)&out->row0 = row0;
     120    *(int*)&out->col0 = col0;
     121    *(psImage**)&out->parent = (psImage*)image;
     122
     123    // add output image as a child of the input image.
     124    image->nChildren++;
     125    image->children = (psImage **) psRealloc(image->children,image->nChildren*sizeof(psImage *));
     126    image->children[image->nChildren-1] = out;
     127
     128    inputColOffset = elementSize*col0;
     129    outputRowSize = elementSize*numCols;
     130
     131    for (int row = 0; row < numRows; row++) {
     132        memcpy(out->data.v[row],image->data.i8[row0+row] + inputColOffset,outputRowSize);
     133    }
     134
     135    return (out);
     136}
  • trunk/psLib/src/image/psImage.h

    r664 r692  
    77 *  @author Ross Harman, MHPCC
    88 *   
    9  *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-05-13 20:03:35 $
     9 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-05-14 22:39:58 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1616
    1717#include <complex.h>
     18
     19#include "psType.h"
    1820
    1921/******************************************************************************/
     
    3537typedef struct psImage
    3638{
    37     psType type;                        ///< Image data type and dimension.
    38     unsigned int numCols;               ///< Number of rows in image
    39     unsigned int numRows;               ///< Number of columns in image.
    40     int col0;                           ///< Row position relative to parent.
    41     int row0;                           ///< Column position relative to parent.
     39    const psType type;                  ///< Image data type and dimension.
     40    const unsigned int numCols;         ///< Number of columns in image
     41    const unsigned int numRows;         ///< Number of rows in image.
     42    const int col0;                     ///< Column position relative to parent.
     43    const int row0;                     ///< Row position relative to parent.
    4244
    4345    union {
    44         void    **v;                    ///< void pointer to data
    45         uint8_t **ui8;                  ///< Pointers to char integer data.
    46         int16_t **i16;                  ///< Pointers to short integer data.
    47         int32_t **i32;                  ///< Pointers to integer data.
    48         float **f32;                    ///< Pointers to floating point data.
    49         complex float **c32;            ///< Pointers to complex floating point data.
     46        uint8_t **ui8;                  ///< unsigned 8-bit integer data.
     47        uint16_t **ui16;                ///< unsigned 16-bit integer data.
     48        uint32_t **ui32;                ///< unsigned 32-bit integer data.
     49        int8_t **i8;                    ///< signed 8-bit integer data.
     50        int16_t **i16;                  ///< signed 16-bit integer data.
     51        int32_t **i32;                  ///< signed 32-bit integer data.
     52        float **f32;                    ///< single-precision float data.
     53        double **f64;                   ///< double-precision float data.
     54        complex float **c32;            ///< single-precision complex data.
     55        void    **v;                    ///< void pointers to data
    5056    } data;                             ///< Union for data types.
    51     struct psImage *parent;             ///< Parent, if a subimage.
     57    const struct psImage *parent;       ///< Parent, if a subimage.
    5258    int nChildren;                      ///< Number of subimages.
    53     struct psImage *children;           ///< Children of this region.
     59    struct psImage** children;          ///< Children of this region.
    5460}
    5561psImage;
     
    7076    unsigned int numCols,               ///< Number of rows in image.
    7177    unsigned int numRows,               ///< Number of columns in image.
    72     psType type                         ///< Type of data for image.
     78    const psElemType type               ///< Type of data for image.
    7379);
    7480
     
    8288psImage *psImageSubset(
    8389    psImage *out,                       ///< Subimage to return, or NULL.
    84     const psImage *image,               ///< Parent image.
     90    psImage *image,                     ///< Parent image.
    8591    unsigned int numCols,               ///< Subimage width (<= image.nCols - col0).
    8692    unsigned int numRows,               ///< Subimage height (<= image.nRows - row0).
    87     int col0,                           ///< Subimage col-offset (0 <= col0 < nCol).
    88     int row0                            ///< Subimage row-offset (0 <= row0 < nCol).
     93    unsigned int col0,                  ///< Subimage col-offset (0 <= col0 < nCol).
     94    unsigned int row0                   ///< Subimage row-offset (0 <= row0 < nCol).
    8995);
    9096
  • trunk/psLib/src/mathtypes/psImage.c

    r664 r692  
    77 *  @author Ross Harman, MHPCC
    88 *   
    9  *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-05-13 20:03:35 $
     9 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-05-14 22:39:58 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1818#include "psMemory.h"
    1919#include "psError.h"
    20 #include "psVector.h"
    2120#include "psImage.h"
    2221
    23 /******************************************************************************/
    24 /*  DEFINE STATEMENTS                                                         */
    25 /******************************************************************************/
    26 
    27 // None
    28 
    29 /******************************************************************************/
    30 /*  TYPE DEFINITIONS                                                          */
    31 /******************************************************************************/
    32 
    33 // None
    34 
    35 /*****************************************************************************/
    36 /*  GLOBAL VARIABLES                                                         */
    37 /*****************************************************************************/
    38 
    39 // None
    40 
    41 /*****************************************************************************/
    42 /*  FILE STATIC VARIABLES                                                    */
    43 /*****************************************************************************/
    44 
    45 // None
    46 
    47 /*****************************************************************************/
    48 /*  FUNCTION IMPLEMENTATION - LOCAL                                          */
    49 /*****************************************************************************/
    50 
    51 // None
     22#include <string.h>
    5223
    5324/*****************************************************************************/
     
    5526/*****************************************************************************/
    5627
    57 psImage *psImageAlloc(unsigned int numCols, unsigned int numRows, psType type)
     28psImage *psImageAlloc(unsigned int numCols, unsigned int numRows, const psElemType type)
    5829{
    5930    int area = 0;
    60     psElemType imageType = 0;
    61     psDimen imageDim = 0;
    62     int elementSize = PSELEMTYPE_SIZEOF(type.type); // element size in bytes
     31    int elementSize = PSELEMTYPE_SIZEOF(type); // element size in bytes
    6332    int rowSize = numCols*elementSize;  // row size in bytes.
    6433
    65     imageType = type.type;
    66     imageDim =  type.dimen;
    6734    area = numCols*numRows;
    68 
    69     if(imageDim != PS_DIMEN_IMAGE) {
    70         psError(__func__, " : Image dimensionality not PS_DIMEN_IMAGE (3). Dimensionality: %d\n",
    71                 imageDim);
    72         return NULL;
    73     } else if(area <= 0) {
    74         psError(__func__, " : Invalid value for number of rows or columns. numRows: %d numCols: %d\n",
    75                 numRows, numCols);
    76         return NULL;
    77     }
    7835
    7936    psImage *image = (psImage *)psAlloc(sizeof(psImage));
    8037
    81     image->data.v[0] = psAlloc(area*elementSize);
     38    if(area < 1) {
     39        image->data.v[0] = NULL;
     40    } else {
     41        image->data.v[0] = psAlloc(area*elementSize);
    8242
    83     for(int i = 1; i < numRows; i++) {
    84         image->data.v[i] = (void*)((int8_t*)image->data.v[i-1]+rowSize);
     43        for(int i = 1; i < numRows; i++) {
     44            image->data.v[i] = (void*)((int8_t*)image->data.v[i-1]+rowSize);
     45        }
    8546    }
    8647
    87     image->col0 = 0;
    88     image->row0 = 0;
    89     image->numCols = numCols;
    90     image->numRows = numRows;
    91     image->type = type;
     48    *(int*)&image->col0 = 0;
     49    *(int*)&image->row0 = 0;
     50    *(unsigned int*)&image->numCols = numCols;
     51    *(unsigned int*)&image->numRows = numRows;
     52    *(psDimen*)&image->type.dimen = PS_DIMEN_IMAGE;
     53    *(psElemType*)&image->type.type = type;
    9254    image->parent = NULL;
    9355    image->nChildren = 0;
     
    10163    int i = 0;
    10264    int nChildren = 0;
    103     psElemType imageType = 0;
    104     psImage *children = NULL;
     65    psImage **children = NULL;
    10566
    10667    if(image != NULL) {
    107         imageType = image->type.type;
    10868        nChildren = image->nChildren;
    10969        children = image->children;
     70
     71        for(i=0; i<nChildren; i++) {
     72            psImageFree(children[i]);
     73        }
    11074
    11175        psFree(image->data.v[0]);
    11276        psFree(image->data.v);
    11377
    114         for(i=0; i<nChildren; i++) {
    115             psImageFree(&children[i]);
    116         }
    11778    }
    11879}
     80
     81psImage *psImageSubset(psImage *out,psImage *image,unsigned int numCols,
     82                       unsigned int numRows, unsigned int col0, unsigned int row0)
     83{
     84    psElemType type;
     85    unsigned int elementSize;           // size of image element in bytes
     86    unsigned int outputRowSize;         // output row size in bytes
     87    unsigned int inputColOffset;        // offset in bytes to first subset pixel in input row
     88
     89    if (image == NULL) {
     90        psError(__func__,"Can not subset image because input image is NULL.");
     91        return NULL;
     92    }
     93
     94    if (image->type.dimen != PS_DIMEN_IMAGE) {
     95        psError(__func__,"Can not subset image because input image is not an image.");
     96        return NULL;
     97    }
     98
     99    /* validate subimage size */
     100    if (col0+numCols >= image->numCols || row0+numRows >= image->numRows) {
     101        psError(__func__,"Can not subset image outside of image boundaries (size=%dx%d, "
     102                "subset=[%d:%d,%d:%d]).",image->numCols,image->numRows,image->col0,
     103                image->col0+numCols, image->row0, image->row0+numRows);
     104        return NULL;
     105    }
     106
     107    type = image->type.type;
     108    elementSize = PSELEMTYPE_SIZEOF(type);
     109
     110    if (out == NULL) {
     111        out = psImageAlloc(numCols,numRows,image->type.type);
     112    } else if (out->numCols != numCols || out->numRows != numRows || out->type.type != type) {
     113        // sizes/type different, can't reuse the given image buffer
     114        psImageFree(out);
     115        out = psImageAlloc(numCols,numRows,image->type.type);
     116    }
     117
     118    // set the parent information into the child output image
     119    *(int*)&out->row0 = row0;
     120    *(int*)&out->col0 = col0;
     121    *(psImage**)&out->parent = (psImage*)image;
     122
     123    // add output image as a child of the input image.
     124    image->nChildren++;
     125    image->children = (psImage **) psRealloc(image->children,image->nChildren*sizeof(psImage *));
     126    image->children[image->nChildren-1] = out;
     127
     128    inputColOffset = elementSize*col0;
     129    outputRowSize = elementSize*numCols;
     130
     131    for (int row = 0; row < numRows; row++) {
     132        memcpy(out->data.v[row],image->data.i8[row0+row] + inputColOffset,outputRowSize);
     133    }
     134
     135    return (out);
     136}
  • trunk/psLib/src/mathtypes/psImage.h

    r664 r692  
    77 *  @author Ross Harman, MHPCC
    88 *   
    9  *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-05-13 20:03:35 $
     9 *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-05-14 22:39:58 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1616
    1717#include <complex.h>
     18
     19#include "psType.h"
    1820
    1921/******************************************************************************/
     
    3537typedef struct psImage
    3638{
    37     psType type;                        ///< Image data type and dimension.
    38     unsigned int numCols;               ///< Number of rows in image
    39     unsigned int numRows;               ///< Number of columns in image.
    40     int col0;                           ///< Row position relative to parent.
    41     int row0;                           ///< Column position relative to parent.
     39    const psType type;                  ///< Image data type and dimension.
     40    const unsigned int numCols;         ///< Number of columns in image
     41    const unsigned int numRows;         ///< Number of rows in image.
     42    const int col0;                     ///< Column position relative to parent.
     43    const int row0;                     ///< Row position relative to parent.
    4244
    4345    union {
    44         void    **v;                    ///< void pointer to data
    45         uint8_t **ui8;                  ///< Pointers to char integer data.
    46         int16_t **i16;                  ///< Pointers to short integer data.
    47         int32_t **i32;                  ///< Pointers to integer data.
    48         float **f32;                    ///< Pointers to floating point data.
    49         complex float **c32;            ///< Pointers to complex floating point data.
     46        uint8_t **ui8;                  ///< unsigned 8-bit integer data.
     47        uint16_t **ui16;                ///< unsigned 16-bit integer data.
     48        uint32_t **ui32;                ///< unsigned 32-bit integer data.
     49        int8_t **i8;                    ///< signed 8-bit integer data.
     50        int16_t **i16;                  ///< signed 16-bit integer data.
     51        int32_t **i32;                  ///< signed 32-bit integer data.
     52        float **f32;                    ///< single-precision float data.
     53        double **f64;                   ///< double-precision float data.
     54        complex float **c32;            ///< single-precision complex data.
     55        void    **v;                    ///< void pointers to data
    5056    } data;                             ///< Union for data types.
    51     struct psImage *parent;             ///< Parent, if a subimage.
     57    const struct psImage *parent;       ///< Parent, if a subimage.
    5258    int nChildren;                      ///< Number of subimages.
    53     struct psImage *children;           ///< Children of this region.
     59    struct psImage** children;          ///< Children of this region.
    5460}
    5561psImage;
     
    7076    unsigned int numCols,               ///< Number of rows in image.
    7177    unsigned int numRows,               ///< Number of columns in image.
    72     psType type                         ///< Type of data for image.
     78    const psElemType type               ///< Type of data for image.
    7379);
    7480
     
    8288psImage *psImageSubset(
    8389    psImage *out,                       ///< Subimage to return, or NULL.
    84     const psImage *image,               ///< Parent image.
     90    psImage *image,                     ///< Parent image.
    8591    unsigned int numCols,               ///< Subimage width (<= image.nCols - col0).
    8692    unsigned int numRows,               ///< Subimage height (<= image.nRows - row0).
    87     int col0,                           ///< Subimage col-offset (0 <= col0 < nCol).
    88     int row0                            ///< Subimage row-offset (0 <= row0 < nCol).
     93    unsigned int col0,                  ///< Subimage col-offset (0 <= col0 < nCol).
     94    unsigned int row0                   ///< Subimage row-offset (0 <= row0 < nCol).
    8995);
    9096
Note: See TracChangeset for help on using the changeset viewer.