IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 10, 2004, 10:20:42 AM (22 years ago)
Author:
harman
Message:

Added psAlloc alloc and free functions

File:
1 edited

Legend:

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

    r599 r633  
    77 *  @author Ross Harman, MHPCC
    88 *   
    9  *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-05-07 02:56:52 $
     9 *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-05-10 20:20:42 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1717/******************************************************************************/
    1818#include "psMemory.h"
     19#include "psError.h"
    1920#include "psArray.h"
     21#include "psImage.h"
    2022
    2123/******************************************************************************/
     
    5355/*****************************************************************************/
    5456
    55 psImage *psImageAlloc(int nx, int ny, psType type)
     57psImage *psImageAlloc(int nCols, int nRows, psType type)
    5658{
    5759    psImage *image = NULL;
    5860
    59     psImage = psAlloc(psImage);
    60     psImage->type = type;
    61     psImage->nx = nx;
    62     psImage->ny = ny;
    63     psImage->x0 = 0;
    64     psImage->y0 = 0;
    65     psImage->parent = NULL;
    66     psImage->nChildren = 0;
    67     psImage->children = NULL;
     61    image = psAlloc(sizeof(psImage));
     62    image->type = type;
     63    image->nCols = nCols;
     64    image->nRows = nRows;
     65    image->col0 = 0;
     66    image->row0 = 0;
     67    image->parent = NULL;
     68    image->nChildren = 0;
     69    image->children = NULL;
    6870
    6971    switch(type.type) {
    7072    case PS_TYPE_SHORT:
    71         image->rows.rows_si = psAlloc(nx*ny*sizeof(short));
     73        image->rows.rows_s = psAlloc(nCols*nRows*sizeof(short));
    7274        break;
    7375    case PS_TYPE_INT:
    74         image->rows.rows_i = psAlloc(nx*ny*sizeof(int));
     76        image->rows.rows_i = psAlloc(nCols*nRows*sizeof(int));
    7577        break;
    7678    case PS_TYPE_LONG:
    77         image->rows.rows_li = psAlloc(nx*ny*sizeof(long));
     79        image->rows.rows_l = psAlloc(nCols*nRows*sizeof(long));
    7880        break;
    7981    case PS_TYPE_USHORT:
    80         image->rows.rows_us = psAlloc(nx*ny*sizeof(unsigned short));
     82        image->rows.rows_us = psAlloc(nCols*nRows*sizeof(unsigned short));
    8183        break;
    8284    case PS_TYPE_UINT:
    83         image->rows.rows_ui = psAlloc(nx*ny*sizeof(unsigned int));
     85        image->rows.rows_ui = psAlloc(nCols*nRows*sizeof(unsigned int));
    8486        break;
    8587    case PS_TYPE_ULONG:
    86         image->rows.rows_ul = psAlloc(nx*ny*sizeof(unsigned long));
     88        image->rows.rows_ul = psAlloc(nCols*nRows*sizeof(unsigned long));
    8789        break;
    8890    case PS_TYPE_FLOAT:
    89         image->rows.rows_f = psAlloc(nx*ny*sizeof(float));
     91        image->rows.rows_f = psAlloc(nCols*nRows*sizeof(float));
    9092        break;
    9193    case PS_TYPE_DOUBLE:
    92         image->rows.rows_d = psAlloc(nx*ny*sizeof(double));
     94        image->rows.rows_d = psAlloc(nCols*nRows*sizeof(double));
    9395        break;
    9496    case PS_TYPE_COMPLEX:
    95         image->rows.rows_cf = psAlloc(nx*ny*sizeof(complex float));
    96         break;
    97     case PS_TYPE_OTHER:
    98         psError(__func__, " : Line %d - Invalid psBitMask binary operation: %s\n", __LINE__);
     97        image->rows.rows_cf = psAlloc(nCols*nRows*sizeof(complex float));
    9998        break;
    10099    default:
    101         psError(__func__, " : Line %d - Invalid psBitMask binary operation: %s\n", __LINE__);
     100        psError(__func__, " : Line %d - Invalid psImage type: %d\n", __LINE__, type.type);
    102101    }
    103102
     103    return image;
     104}
    104105
     106void psImageFree(psImage *image)
     107{
     108    int i = 0;
     109    int nChildren = 0;
     110    psElemType imageType = 0;
     111    psImage *children = NULL;
     112
     113    if(image != NULL) {
     114        imageType = image->type.type;
     115        nChildren = image->nChildren;
     116        children = image->children;
     117
     118        switch(imageType) {
     119        case PS_TYPE_SHORT:
     120            psFree(image->rows.rows_s);
     121            break;
     122        case PS_TYPE_INT:
     123            psFree(image->rows.rows_i);
     124            break;
     125        case PS_TYPE_LONG:
     126            psFree(image->rows.rows_l);
     127            break;
     128        case PS_TYPE_USHORT:
     129            psFree(image->rows.rows_us);
     130            break;
     131        case PS_TYPE_UINT:
     132            psFree(image->rows.rows_ui);
     133            break;
     134        case PS_TYPE_ULONG:
     135            psFree(image->rows.rows_ul);
     136            break;
     137        case PS_TYPE_FLOAT:
     138            psFree(image->rows.rows_f);
     139            break;
     140        case PS_TYPE_DOUBLE:
     141            psFree(image->rows.rows_d);
     142            break;
     143        case PS_TYPE_COMPLEX:
     144            psFree(image->rows.rows_cf);
     145            break;
     146        case PS_TYPE_OTHER:
     147            psError(__func__, " : Line %d - Can't delete images of type PS_TYPE_OTHER\n", __LINE__);
     148            break;
     149        default:
     150            psError(__func__, " : Line %d - Invalid psImage type: %d\n", __LINE__, imageType);
     151        }
     152
     153        for(i=0; i<nChildren; i++) {
     154            psImageFree(children);
     155        }
     156    }
    105157}
Note: See TracChangeset for help on using the changeset viewer.