IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 1920 for trunk/psLib/src/image


Ignore:
Timestamp:
Sep 28, 2004, 1:26:49 PM (22 years ago)
Author:
desonia
Message:

changed function prototypes to match changes in the SDRS.

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

Legend:

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

    r1897 r1920  
    1010 *  @author Ross Harman, MHPCC
    1111 *
    12  *  @version $Revision: 1.46 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-09-25 02:06:12 $
     12 *  @version $Revision: 1.47 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-09-28 23:26:48 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    6868    *(psElemType* ) & image->type.type = type;
    6969    image->parent = NULL;
    70     image->nChildren = 0;
    7170    image->children = NULL;
    7271
     
    8180
    8281    if (image->type.type == PS_TYPE_PTR) {
    83         // 2-D array of pointers -- must
    84         // dereference
     82        // 2-D array of pointers -- must dereference elements
    8583        unsigned int oldNumRows = image->numRows;
    8684        unsigned int oldNumCols = image->numCols;
     
    9593    }
    9694
     95    if (image->parent != NULL) {
     96        psArrayRemove(image->parent->children,image);
     97        image->parent = NULL;
     98    }
     99
    97100    psImageFreeChildren(image);
    98101
    99102    psFree(image->rawDataBuffer);
    100103    psFree(image->data.V);
    101     image->data.V = NULL;
    102104}
    103105
     
    164166int psImageFreeChildren(psImage* image)
    165167{
    166     int i = 0;
    167     int nChildren = 0;
    168     psImage* *children = NULL;
    169168    int numFreed = 0;
    170169
     
    173172    }
    174173
    175     nChildren = image->nChildren;
    176     children = image->children;
    177 
    178     for (i = 0; i < nChildren; i++) {
    179         if (children[i] != NULL) {
    180             numFreed++;
    181             psFree(children[i]);
     174    if (image->children != NULL) {
     175        psImage** children = (psImage**)image->children->data;
     176        numFreed = image->children->n;
     177
     178        // orphan the children first
     179        // (so psFree doesn't try to modify the parent's children array while I'm using it)
     180        for (int i=0;i<numFreed;i++) {
     181            children[i]->parent = NULL;
    182182        }
    183     }
    184     psFree(children);
    185 
    186     image->nChildren = 0;
    187     image->children = NULL;
     183
     184        psFree(image->children);
     185        image->children = NULL;
     186    }
    188187
    189188    return numFreed;
  • trunk/psLib/src/image/psImage.h

    r1897 r1920  
    1111 *  @author Ross Harman, MHPCC
    1212 *
    13  *  @version $Revision: 1.37 $ $Name: not supported by cvs2svn $
    14  *  @date $Date: 2004-09-25 02:06:12 $
     13 *  @version $Revision: 1.38 $ $Name: not supported by cvs2svn $
     14 *  @date $Date: 2004-09-28 23:26:48 $
    1515 *
    1616 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2222
    2323#include "psType.h"
     24#include "psArray.h"
    2425
    2526/// @addtogroup Image
     
    6768    } data;                            ///< Union for data types.
    6869    const struct psImage* parent;      ///< Parent, if a subimage.
    69     int nChildren;                     ///< Number of subimages.
    70     struct psImage* *children;         ///< Children of this region.
     70    psArray* children;                 ///< Children of this region.
    7171
    7272    void* rawDataBuffer;
  • trunk/psLib/src/image/psImageExtraction.c

    r1918 r1920  
    1 
    21/** @file  psImageExtraction.c
    3 *
    4 *  @brief Contains basic image extraction operations, as specified in the
    5 *         PSLIB SDRS sections "Image Pixel Extractions" and "Image Structure
    6 *         Manipulation".
    7 *
    8 *  @ingroup Image
    9 *
    10 *  @author Robert DeSonia, MHPCC
    11 *
    12 *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2004-09-28 02:27:58 $
    14 *
    15 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
    16 *
    17 */
     2 *
     3 *  @brief Contains basic image extraction operations, as specified in the
     4 *         PSLIB SDRS sections "Image Pixel Extractions" and "Image Structure
     5 *         Manipulation".
     6 *
     7 *  @ingroup Image
     8 *
     9 *  @author Robert DeSonia, MHPCC
     10 *
     11 *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-09-28 23:26:48 $
     13 *
     14 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     15 *
     16 */
    1817
    1918#include <string.h>
     
    2524#include "psImageErrors.h"
    2625
    27 psImage* psImageSubset(psImage* image,
    28                        int col0,
    29                        int row0,
    30                        int col1,
    31                        int row1)
     26
     27psImage* imageSubset(psImage* out,
     28                     psImage* image,
     29                     int col0,
     30                     int row0,
     31                     int col1,
     32                     int row1)
    3233{
    33     psImage* out;
    3434    unsigned int elementSize;          // size of image element in bytes
    3535    unsigned int inputColOffset;       // offset in bytes to first subset pixel in input row
     
    7070    }
    7171    int numRows = row1-row0;
    72     int numCols = col1-row0;
     72    int numCols = col1-col0;
    7373
    7474    elementSize = PSELEMTYPE_SIZEOF(image->type.type);
    7575
    76     out = psAlloc(sizeof(psImage));
     76    if (image->parent != NULL) { // if this is a child, we need to start working with parent.
     77        col0 += image->col0;
     78        col1 += image->col0;
     79        row0 += image->row0;
     80        row1 += image->row0;
     81        image = (psImage*)image->parent;
     82    }
     83
     84    // increment the raw data buffer before freeing anything in the 'out'
     85    void* rawData = psMemIncrRefCounter(image->rawDataBuffer);
     86
     87    if (out != NULL) {
     88        // if a child, need to orphan (disassociate from parent) first
     89        if (out->parent != NULL) {
     90            psArrayRemove(out->parent->children,out); // remove from parent's knowledge
     91            out->parent = NULL; // break link to parent
     92        }
     93
     94        psFree(out->rawDataBuffer); // free the previous data reference
     95    } else {
     96        out = psAlloc(sizeof(psImage));
     97        out->data.V = NULL;
     98    }
     99
     100    out->data.V = psRealloc(out->data.V,sizeof(void*)*numRows); // resize row pointer array
    77101    *(psType*)&out->type = image->type;
    78102    *(unsigned int*)&out->numCols = numCols;
     
    81105    *(int*)&out->col0 = col0;
    82106    out->parent = image;
    83     out->nChildren = 0;
    84107    out->children = NULL;
    85     out->rawDataBuffer = psMemIncrRefCounter(image->rawDataBuffer);
    86     out->data.V = psAlloc(sizeof(void*)*numRows);
     108    out->rawDataBuffer = rawData;
    87109
    88110    // set the new psImage's deallocator to the same as the input image
     
    94116    }
    95117
    96     // add output image as a child of the input
    97     // image.
    98     image->nChildren++;
    99     image->children = (psImage**) psRealloc(image->children, image->nChildren * sizeof(psImage* ));
    100     image->children[image->nChildren - 1] = out;
     118    // add output image as a child of the input image.
     119    int n = 0;
     120    psArray* children = image->children;
     121    if (children == NULL) {
     122        children = psArrayAlloc(16); // start with a reasonable size for growth
     123    } else if (children->nalloc == children->n) { // full?
     124        n = children->n;
     125        children = psArrayRealloc(children,n*2); // double the array size
     126    } else {
     127        n = children->n;
     128    }
     129    children->data[n] = out;
     130    children->n = n+1;
     131    image->children = children; // push back any change (esp. if children==NULL before)
    101132
    102133    return (out);
     134}
     135
     136psImage* psImageSubset(psImage* image,
     137                       int col0,
     138                       int row0,
     139                       int col1,
     140                       int row1)
     141{
     142    return imageSubset(NULL,image,col0,row0,col1,row1);
    103143}
    104144
     
    126166        return NULL;
    127167    }
    128     return psImageSubset(image,x1,y1,x2,y2);
     168    return imageSubset(NULL,image,x1,y1,x2,y2);
    129169}
    130170
    131 psImage* psImageTrim(psImage* image, int x0, int x1, int y0, int y1)
     171psImage* psImageTrim(psImage* image, int x0, int y0, int x1, int y1)
    132172{
    133173    if (image == NULL || image->data.V == NULL) {
     
    139179
    140180    if (image->parent != NULL) {
    141         psErrorMsg(PS_ERRORNAME_DOMAIN "psImageTrim",
    142                    PS_ERR_BAD_PARAMETER_NULL, true,
    143                    PS_ERRORTEXT_psImage_NOT_PARENT);
    144         return NULL;
     181        return imageSubset(image,
     182                           (psImage*)image->parent,
     183                           x0+image->col0,
     184                           y0+image->row0,
     185                           x1+image->col0,
     186                           y1+image->row0);
    145187    }
    146188
     
    904946                    int n = buffer[r]->n;
    905947                    if (n == buffer[r]->nalloc) { // in case buffers already full, expand
    906                         buffer[r] = psVectorRealloc(n*2, buffer[r]);
     948                        buffer[r] = psVectorRealloc(buffer[r], n*2);
    907949                        if (bufferMask[r] != NULL) {
    908                             bufferMask[r] = psVectorRealloc(n*2, bufferMask[r]);
     950                            bufferMask[r] = psVectorRealloc(bufferMask[r], n*2);
    909951                        }
    910952                    }
  • trunk/psLib/src/image/psImageExtraction.h

    r1918 r1920  
    1010*  @author Robert DeSonia, MHPCC
    1111*
    12 *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2004-09-28 02:27:58 $
     12*  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2004-09-28 23:26:48 $
    1414*
    1515*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    7676 *
    7777 *  Trim the specified image in-place, which involves shuffling the pixels
    78  *  around in memory.  The pixels in the region [x0:x1,y0:y1] (inclusive)
    79  *  shall consist the output image.
    80  *
    81  *  N.b., An image that has a parent image will be orphaned from the parent
    82  *  upon trimming.  Any children of the trimmed image will also be obliterated,
     78 *  around in memory.  The pixels in the region [col0:col1,row0:row1] shall consist
     79 *  the output image.  The column col1 and row row1 are NOT included in the range.
     80 *  In the event that x1 or y1 are non-positive, they shall be interpreted as
     81 *  being relative to the size of the parent image in that dimension.
     82 *
     83 *  If the entire specified subimage is not contained within the parent
     84 *  image, an error results and the return value will be NULL.
     85 *
     86 *  N.B. If the input psImage is a child of another psImage, no pixel data
     87 *  will be trimmed, rather it equivalent to calling psImageSubset.  If the input
     88 *  psImage is, however, a parent psImage, any children will be obliterated,
    8389 *  i.e., freed from memory.
    8490 *
     
    8793psImage* psImageTrim(
    8894    psImage* image,                    ///< image to trim
    89     int x0,                            ///< column of trim region's left boundary
    90     int x1,                            ///< column of trim region's right boundary
    91     int y0,                            ///< row of trim region's lower boundary
    92     int y1                             ///< row of trim region's upper boundary
     95    int col0,                          ///< column of trim region's left boundary
     96    int row0,                          ///< row of trim region's lower boundary
     97    int col1,                          ///< column of trim region's right boundary
     98    int row1                           ///< row of trim region's upper boundary
    9399);
    94100
Note: See TracChangeset for help on using the changeset viewer.