IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

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

changed function prototypes to match changes in the SDRS.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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                    }
Note: See TracChangeset for help on using the changeset viewer.