IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 700


Ignore:
Timestamp:
May 14, 2004, 4:10:27 PM (22 years ago)
Author:
desonia
Message:

added psImageFreePixels & psImageFreeChildren.

Location:
trunk/psLib/src
Files:
4 edited

Legend:

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

    r693 r700  
    77 *  @author Ross Harman, MHPCC
    88 *   
    9  *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-05-15 00:14:56 $
     9 *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-05-15 02:10:27 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    6565void psImageFree(psImage *image)
    6666{
    67     int i = 0;
    68     int nChildren = 0;
    69     psImage **children = NULL;
    70 
    71     if(image != NULL) {
    72         nChildren = image->nChildren;
    73         children = image->children;
    74 
    75         for(i=0; i<nChildren; i++) {
    76             psImageFree(children[i]);
    77         }
    78 
    79         psFree(image->data.v[0]);
    80         psFree(image->data.v);
    81 
    82     }
     67    psImageFreeChildren(image);
     68    psImageFreePixels(image);
     69    psFree(image);
    8370}
    8471
     
    9178    unsigned int inputColOffset;        // offset in bytes to first subset pixel in input row
    9279
    93     if (image == NULL) {
    94         psError(__func__,"Can not subset image because input image is NULL.");
     80    if (image == NULL || image->data.v == NULL) {
     81        psError(__func__,"Can not subset image because input image or its pixel buffer is NULL.");
    9582        return NULL;
    9683    }
     
    139126    return (out);
    140127}
     128
     129void psImageFreePixels(psImage *restrict image)
     130{
     131    if (image == NULL || image->data.v == NULL) {
     132        return;
     133    }
     134
     135    psFree(image->data.v[0]);
     136    psFree(image->data.v);
     137    image->data.v = NULL;
     138
     139    // xxx - is this proper?
     140    *(unsigned int*)&image->numRows = 0;
     141    *(unsigned int*)&image->numCols = 0;
     142}
     143
     144int psImageFreeChildren(psImage* image)
     145{
     146    int i = 0;
     147    int nChildren = 0;
     148    psImage **children = NULL;
     149    int numFreed = 0;
     150
     151    if (image == NULL) {
     152        return numFreed;
     153    }
     154
     155    nChildren = image->nChildren;
     156    children = image->children;
     157
     158    for(i=0; i<nChildren; i++) {
     159        if (children[i] != NULL) {
     160            numFreed++;
     161            psImageFree(children[i]);
     162        }
     163    }
     164
     165    return numFreed;
     166}
  • trunk/psLib/src/image/psImage.h

    r692 r700  
    77 *  @author Ross Harman, MHPCC
    88 *   
    9  *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-05-14 22:39:58 $
     9 *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-05-15 02:10:27 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    9999 *  Uses psLib memory deallocation functions to free an image and any existing children.
    100100 *
    101  * @return psImage*: Pointer to psImage.
    102  *
    103101 */
    104102void psImageFree(
     
    106104);
    107105
     106/** Deallocate the image buffer of a psImage.
     107 *
     108 *  deallocates the image buffer while preserving the psImage struct and any children.
     109 *
     110 */
     111void psImageFreePixels(
     112    psImage *restrict image             ///< psImage to free pixel memory from
     113);
     114
     115/** Frees all children of a psImage.
     116 *
     117 *  return int      Number of children freed.
     118 *
     119 */
     120int psImageFreeChildren(
     121    psImage* image                      ///< psImage in which all children shall be deallocated
     122);
     123
     124
     125
    108126#endif
  • trunk/psLib/src/mathtypes/psImage.c

    r693 r700  
    77 *  @author Ross Harman, MHPCC
    88 *   
    9  *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-05-15 00:14:56 $
     9 *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-05-15 02:10:27 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    6565void psImageFree(psImage *image)
    6666{
    67     int i = 0;
    68     int nChildren = 0;
    69     psImage **children = NULL;
    70 
    71     if(image != NULL) {
    72         nChildren = image->nChildren;
    73         children = image->children;
    74 
    75         for(i=0; i<nChildren; i++) {
    76             psImageFree(children[i]);
    77         }
    78 
    79         psFree(image->data.v[0]);
    80         psFree(image->data.v);
    81 
    82     }
     67    psImageFreeChildren(image);
     68    psImageFreePixels(image);
     69    psFree(image);
    8370}
    8471
     
    9178    unsigned int inputColOffset;        // offset in bytes to first subset pixel in input row
    9279
    93     if (image == NULL) {
    94         psError(__func__,"Can not subset image because input image is NULL.");
     80    if (image == NULL || image->data.v == NULL) {
     81        psError(__func__,"Can not subset image because input image or its pixel buffer is NULL.");
    9582        return NULL;
    9683    }
     
    139126    return (out);
    140127}
     128
     129void psImageFreePixels(psImage *restrict image)
     130{
     131    if (image == NULL || image->data.v == NULL) {
     132        return;
     133    }
     134
     135    psFree(image->data.v[0]);
     136    psFree(image->data.v);
     137    image->data.v = NULL;
     138
     139    // xxx - is this proper?
     140    *(unsigned int*)&image->numRows = 0;
     141    *(unsigned int*)&image->numCols = 0;
     142}
     143
     144int psImageFreeChildren(psImage* image)
     145{
     146    int i = 0;
     147    int nChildren = 0;
     148    psImage **children = NULL;
     149    int numFreed = 0;
     150
     151    if (image == NULL) {
     152        return numFreed;
     153    }
     154
     155    nChildren = image->nChildren;
     156    children = image->children;
     157
     158    for(i=0; i<nChildren; i++) {
     159        if (children[i] != NULL) {
     160            numFreed++;
     161            psImageFree(children[i]);
     162        }
     163    }
     164
     165    return numFreed;
     166}
  • trunk/psLib/src/mathtypes/psImage.h

    r692 r700  
    77 *  @author Ross Harman, MHPCC
    88 *   
    9  *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-05-14 22:39:58 $
     9 *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-05-15 02:10:27 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    9999 *  Uses psLib memory deallocation functions to free an image and any existing children.
    100100 *
    101  * @return psImage*: Pointer to psImage.
    102  *
    103101 */
    104102void psImageFree(
     
    106104);
    107105
     106/** Deallocate the image buffer of a psImage.
     107 *
     108 *  deallocates the image buffer while preserving the psImage struct and any children.
     109 *
     110 */
     111void psImageFreePixels(
     112    psImage *restrict image             ///< psImage to free pixel memory from
     113);
     114
     115/** Frees all children of a psImage.
     116 *
     117 *  return int      Number of children freed.
     118 *
     119 */
     120int psImageFreeChildren(
     121    psImage* image                      ///< psImage in which all children shall be deallocated
     122);
     123
     124
     125
    108126#endif
Note: See TracChangeset for help on using the changeset viewer.