IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 13, 2004, 10:03:35 AM (22 years ago)
Author:
desonia
Message:

Removed the switch statements. It compiles now but just contains alloc/free.

File:
1 edited

Legend:

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

    r649 r664  
    77 *  @author Ross Harman, MHPCC
    88 *   
    9  *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-05-12 19:46:52 $
     9 *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-05-13 20:03:35 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1818#include "psMemory.h"
    1919#include "psError.h"
    20 #include "psArray.h"
     20#include "psVector.h"
    2121#include "psImage.h"
    2222
     
    5555/*****************************************************************************/
    5656
    57 psImage *psImageAlloc(int nCols, int nRows, psType type)
     57psImage *psImageAlloc(unsigned int numCols, unsigned int numRows, psType type)
    5858{
    5959    int area = 0;
    6060    psElemType imageType = 0;
    6161    psDimen imageDim = 0;
     62    int elementSize = PSELEMTYPE_SIZEOF(type.type); // element size in bytes
     63    int rowSize = numCols*elementSize;  // row size in bytes.
    6264
    6365    imageType = type.type;
    6466    imageDim =  type.dimen;
    65     area = nCols*nRows;
     67    area = numCols*numRows;
    6668
    6769    if(imageDim != PS_DIMEN_IMAGE) {
    68         psError(__func__, " : Line %d - Image dimensionality not PS_DIMEN_IMAGE=3 . Dimensionality: %d\n",
    69                 __LINE__, imageDim);
     70        psError(__func__, " : Image dimensionality not PS_DIMEN_IMAGE (3). Dimensionality: %d\n",
     71                imageDim);
    7072        return NULL;
    7173    } else if(area <= 0) {
    72         psError(__func__, " : Line %d - Invalid value for number of rows or columns. nRows: %d nCols: %d \n",
    73                 __LINE__, nRows, nCols);
     74        psError(__func__, " : Invalid value for number of rows or columns. numRows: %d numCols: %d\n",
     75                numRows, numCols);
    7476        return NULL;
    7577    }
     
    7779    psImage *image = (psImage *)psAlloc(sizeof(psImage));
    7880
    79     switch (type.type) {
    80     case PS_TYPE_CHAR:
    81         image->rows.rows_c = (char **)psAlloc(ny*sizeof(char *));
    82         image->rows.rows_c[0] = (char *)psAlloc(area*sizeof(char));
    83         for(int i = 1; i < ny; i++) {
    84             image->rows.rows_c[i] = &image->rows.rows_c[0][i*nx];
    85         }
    86         break;
    87     case PS_TYPE_SHORT:
    88         image->rows.rows_s = (short **)psAlloc(ny*sizeof(short *));
    89         image->rows.rows_s[0] = (short *)psAlloc(area*sizeof(short));
    90         for(int i = 1; i < ny; i++) {
    91             image->rows.rows_s[i] = &image->rows.rows_s[0][i*nx];
    92         }
    93         break;
    94     case PS_TYPE_INT:
    95         image->rows.rows_i = (int **)psAlloc(ny*sizeof(int *));
    96         image->rows.rows_i[0] = (int *)psAlloc(area*sizeof(int));
    97         for(int i = 1; i < ny; i++) {
    98             image->rows.rows_i[i] = &image->rows.rows_i[0][i*nx];
    99         }
    100         break;
    101     case PS_TYPE_LONG:
    102         image->rows.rows_l = (long **)psAlloc(ny*sizeof(long *));
    103         image->rows.rows_l[0] = (long *)psAlloc(area*sizeof(long));
    104         for(int i = 1; i < ny; i++) {
    105             image->rows.rows_l[i] = &image->rows.rows_l[0][i*nx];
    106         }
    107         break;
    108     case PS_TYPE_UCHAR:
    109         image->rows.rows_uc = (unsigned char **)psAlloc(ny*sizeof(unsigned char *));
    110         image->rows.rows_uc[0] = (unsigned char *)psAlloc(area*sizeof(unsigned char));
    111         for(int i = 1; i < ny; i++) {
    112             image->rows.rows_uc[i] = &image->rows.rows_uc[0][i*nx];
    113         }
    114         break;
    115     case PS_TYPE_USHORT:
    116         image->rows.rows_us = (unsigned short **)psAlloc(ny*sizeof(unsigned short *));
    117         image->rows.rows_us[0] = (unsigned short *)psAlloc(area*sizeof(unsigned short));
    118         for(int i = 1; i < ny; i++) {
    119             image->rows.rows_us[i] = &image->rows.rows_us[0][i*nx];
    120         }
    121         break;
    122     case PS_TYPE_UINT:
    123         image->rows.rows_ui = (unsigned int **)psAlloc(ny*sizeof(unsigned int *));
    124         image->rows.rows_ui[0] = (unsigned int *)psAlloc(area*sizeof(unsigned int));
    125         for(int i = 1; i < ny; i++) {
    126             image->rows.rows_ui[i] = &image->rows.rows_ui[0][i*nx];
    127         }
    128         break;
    129     case PS_TYPE_ULONG:
    130         image->rows.rows_ul = (unsigned long **)psAlloc(ny*sizeof(unsigned long *));
    131         image->rows.rows_ul[0] = (unsigned long *)psAlloc(area*sizeof(unsigned long));
    132         for(int i = 1; i < ny; i++) {
    133             image->rows.rows_ul[i] = &image->rows.rows_ul[0][i*nx];
    134         }
    135         break;
     81    image->data.v[0] = psAlloc(area*elementSize);
     82
     83    for(int i = 1; i < numRows; i++) {
     84        image->data.v[i] = (void*)((int8_t*)image->data.v[i-1]+rowSize);
    13685    }
    13786
    138     image->cols0 = 0;
    139     image->rows0 = 0;
    140     image->nCols = nCols;
    141     image->nRows = nRows;
     87    image->col0 = 0;
     88    image->row0 = 0;
     89    image->numCols = numCols;
     90    image->numRows = numRows;
    14291    image->type = type;
    14392    image->parent = NULL;
     
    160109        children = image->children;
    161110
    162         switch(imageType) {
    163         case PS_TYPE_SHORT:
    164             psFree(image->rows.rows_s);
    165             break;
    166         case PS_TYPE_INT:
    167             psFree(image->rows.rows_i);
    168             break;
    169         case PS_TYPE_LONG:
    170             psFree(image->rows.rows_l);
    171             break;
    172         case PS_TYPE_USHORT:
    173             psFree(image->rows.rows_us);
    174             break;
    175         case PS_TYPE_UINT:
    176             psFree(image->rows.rows_ui);
    177             break;
    178         case PS_TYPE_ULONG:
    179             psFree(image->rows.rows_ul);
    180             break;
    181         case PS_TYPE_FLOAT:
    182             psFree(image->rows.rows_f);
    183             break;
    184         case PS_TYPE_DOUBLE:
    185             psFree(image->rows.rows_d);
    186             break;
    187         case PS_TYPE_COMPLEX:
    188             psFree(image->rows.rows_cf);
    189             break;
    190         case PS_TYPE_OTHER:
    191             psError(__func__, " : Line %d - Can't delete images of type PS_TYPE_OTHER\n", __LINE__);
    192             break;
    193         default:
    194             psError(__func__, " : Line %d - Invalid psImage type: %d\n", __LINE__, imageType);
    195         }
     111        psFree(image->data.v[0]);
     112        psFree(image->data.v);
    196113
    197114        for(i=0; i<nChildren; i++) {
Note: See TracChangeset for help on using the changeset viewer.