IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Aug 6, 2004, 2:06:06 PM (22 years ago)
Author:
desonia
Message:

another attempt to get astyle to get it right.

File:
1 edited

Legend:

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

    r1406 r1407  
     1
    12/** @file  psImage.c
    23 *
     
    910 *  @author Ross Harman, MHPCC
    1011 *
    11  *  @version $Revision: 1.37 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-08-06 22:34:05 $
     12 *  @version $Revision: 1.38 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-08-07 00:06:06 $
    1314 *
    1415 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    1819
    1920/******************************************************************************/
     21
    2022/*  INCLUDE FILES                                                             */
     23
    2124/******************************************************************************/
    2225
     
    2932#include "psImage.h"
    3033
    31 static void imageFree(psImage* image);
     34static void imageFree(psImage * image);
    3235
    3336/*****************************************************************************/
     37
    3438/* FUNCTION IMPLEMENTATION - PUBLIC                                          */
     39
    3540/*****************************************************************************/
    3641
    37 psImage *psImageAlloc(unsigned int numCols, unsigned int numRows,
    38                       const psElemType type)
     42psImage *psImageAlloc(unsigned int numCols, unsigned int numRows, const psElemType type)
    3943{
    4044    int area = 0;
    41     int elementSize = PSELEMTYPE_SIZEOF(type); // element size in bytes
    42     int rowSize = numCols*elementSize;  // row size in bytes.
    43 
    44     area = numCols*numRows;
     45    int elementSize = PSELEMTYPE_SIZEOF(type);  // element
     46
     47    // size in
     48    // bytes
     49    int rowSize = numCols * elementSize;        // row
     50
     51    // size
     52
     53    // in bytes.
     54
     55    area = numCols * numRows;
    4556
    4657    if (area < 1) {
    47         psError(__func__, "Invalid value for number of rows or columns "
    48                 "(numRows=%d, numCols=%d).", numRows, numCols);
     58        psError(__func__,
     59                "Invalid value for number of rows or columns " "(numRows=%d, numCols=%d).", numRows, numCols);
    4960        return NULL;
    5061    }
    5162
    52     psImage *image = (psImage *)psAlloc(sizeof(psImage));
    53     if(image == NULL) {
    54         psAbort(__func__," : Line %d - Failed to allocate memory", __LINE__);
    55     }
    56 
    57     p_psMemSetDeallocator(image,(psFreeFcn)imageFree);
    58 
    59     image->data.V = psAlloc(sizeof(void*)*numRows);
    60     if(image->data.V == NULL) {
    61         psAbort(__func__," : Line %d - Failed to allocate memory", __LINE__);
    62     }
    63 
    64 
    65     image->data.V[0] = psAlloc(area*elementSize);
    66     if(image->data.V[0] == NULL) {
    67         psAbort(__func__," : Line %d - Failed to allocate memory", __LINE__);
    68     }
    69 
    70     for(int i = 1; i < numRows; i++) {
    71         image->data.V[i] = (void*)((int8_t*)image->data.V[i-1]+rowSize);
    72     }
    73 
    74     *(int*)&image->col0 = 0;
    75     *(int*)&image->row0 = 0;
    76     *(unsigned int*)&image->numCols = numCols;
    77     *(unsigned int*)&image->numRows = numRows;
    78     *(psDimen*)&image->type.dimen = PS_DIMEN_IMAGE;
    79     *(psElemType*)&image->type.type = type;
     63    psImage *image = (psImage *) psAlloc(sizeof(psImage));
     64
     65    if (image == NULL) {
     66        psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__);
     67    }
     68
     69    p_psMemSetDeallocator(image, (psFreeFcn) imageFree);
     70
     71    image->data.V = psAlloc(sizeof(void *) * numRows);
     72    if (image->data.V == NULL) {
     73        psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__);
     74    }
     75
     76    image->data.V[0] = psAlloc(area * elementSize);
     77    if (image->data.V[0] == NULL) {
     78        psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__);
     79    }
     80
     81    for (int i = 1; i < numRows; i++) {
     82        image->data.V[i] = (void *)((int8_t *) image->data.V[i - 1] + rowSize);
     83    }
     84
     85    *(int *)&image->col0 = 0;
     86    *(int *)&image->row0 = 0;
     87    *(unsigned int *)&image->numCols = numCols;
     88    *(unsigned int *)&image->numRows = numRows;
     89    *(psDimen *) & image->type.dimen = PS_DIMEN_IMAGE;
     90    *(psElemType *) & image->type.type = type;
    8091    image->parent = NULL;
    8192    image->nChildren = 0;
     
    8596}
    8697
    87 static void imageFree(psImage* image)
     98static void imageFree(psImage * image)
    8899{
    89100    if (image == NULL) {
     
    92103
    93104    if (image->type.type == PS_TYPE_PTR) {
    94         // 2-D array of pointers -- must dereference
     105        // 2-D array of pointers -- must
     106        // dereference
    95107        unsigned int oldNumRows = image->numRows;
    96108        unsigned int oldNumCols = image->numCols;
    97         psPTR* rowPtr;
    98 
    99         for(unsigned int row=0;row<oldNumRows;row++) {
     109        psPTR *rowPtr;
     110
     111        for (unsigned int row = 0; row < oldNumRows; row++) {
    100112            rowPtr = image->data.PTR[row];
    101             for (unsigned int col=0;col<oldNumCols;col++) {
     113            for (unsigned int col = 0; col < oldNumCols; col++) {
    102114                psMemDecrRefCounter(rowPtr[col]);
    103115            }
     
    112124}
    113125
    114 psImage* psImageRecycle(psImage* old,
    115                         unsigned int numCols,
    116                         unsigned int numRows,
    117                         const psElemType type)
     126psImage *psImageRecycle(psImage * old, unsigned int numCols, unsigned int numRows, const psElemType type)
    118127{
    119     int elementSize = PSELEMTYPE_SIZEOF(type); // element size in bytes
    120     int rowSize = numCols*elementSize;  // row size in bytes.
     128    int elementSize = PSELEMTYPE_SIZEOF(type);  // element
     129
     130    // size in
     131    // bytes
     132    int rowSize = numCols * elementSize;        // row
     133
     134    // size
     135
     136    // in bytes.
    121137
    122138    if (old == NULL) {
    123         old = psImageAlloc(numCols,numRows,type);
     139        old = psImageAlloc(numCols, numRows, type);
    124140        return old;
    125141    }
    126142
    127143    if (old->type.dimen != PS_DIMEN_IMAGE) {
    128         psError(__func__,"Can not realloc image because input is not an image.");
     144        psError(__func__, "Can not realloc image because input is not an image.");
    129145        return NULL;
    130146    }
    131147
    132148    if (old->type.type == PS_TYPE_PTR) {
    133         // 2-D array of pointers -- must dereference
     149        // 2-D array of pointers -- must
     150        // dereference
    134151        unsigned int oldNumRows = old->numRows;
    135152        unsigned int oldNumCols = old->numCols;
    136         psPTR* rowPtr;
    137 
    138         for(unsigned int row=0;row<oldNumRows;row++) {
     153        psPTR *rowPtr;
     154
     155        for (unsigned int row = 0; row < oldNumRows; row++) {
    139156            rowPtr = old->data.PTR[row];
    140             for (unsigned int col=0;col<oldNumCols;col++) {
     157            for (unsigned int col = 0; col < oldNumCols; col++) {
    141158                psMemDecrRefCounter(rowPtr[col]);
    142159                rowPtr[col] = NULL;
     
    146163
    147164    /* image already the right size/type? */
    148     if (numCols == old->numCols && numRows == old->numRows &&
    149             type == old->type.type) {
     165    if (numCols == old->numCols && numRows == old->numRows && type == old->type.type) {
    150166        return old;
    151167    }
    152 
    153168    // Resize the image buffer
    154     old->data.V[0] = psRealloc(old->data.V[0],numCols * numRows * elementSize);
    155     old->data.V = (void**) psRealloc(old->data.V,numRows * sizeof(void*));
     169    old->data.V[0] = psRealloc(old->data.V[0], numCols * numRows * elementSize);
     170    old->data.V = (void **)psRealloc(old->data.V, numRows * sizeof(void *));
    156171
    157172    // recreate the row pointers
    158     for(int i = 1; i < numRows; i++) {
    159         old->data.V[i] = (void*)((int8_t*)old->data.V[i-1]+rowSize);
    160     }
    161 
    162     *(unsigned int*)&old->numCols = numCols;
    163     *(unsigned int*)&old->numRows = numRows;
    164     *(psElemType*)&old->type.type = type;
     173    for (int i = 1; i < numRows; i++) {
     174        old->data.V[i] = (void *)((int8_t *) old->data.V[i - 1] + rowSize);
     175    }
     176
     177    *(unsigned int *)&old->numCols = numCols;
     178    *(unsigned int *)&old->numRows = numRows;
     179    *(psElemType *) & old->type.type = type;
    165180
    166181    return old;
    167182}
    168183
    169 int psImageFreeChildren(psImage* image)
     184int psImageFreeChildren(psImage * image)
    170185{
    171186    int i = 0;
     
    181196    children = image->children;
    182197
    183     for(i=0; i<nChildren; i++) {
     198    for (i = 0; i < nChildren; i++) {
    184199        if (children[i] != NULL) {
    185200            numFreed++;
     
    191206    image->nChildren = 0;
    192207    image->children = NULL;
    193 
    194208
    195209    return numFreed;
     
    202216linear interpolation is performed on the image.
    203217 *****************************************************************************/
    204 psF32 psImagePixelInterpolate(
    205     const psImage *input,
    206     float x,
    207     float y,
    208     psF32 unexposedValue,
    209     psImageInterpolateMode mode)
     218psF32 psImagePixelInterpolate(const psImage * input,
     219                              float x, float y, psF32 unexposedValue, psImageInterpolateMode mode)
    210220{
    211221
    212222    if (input == NULL) {
    213         psError(__func__,"Image can not be NULL.");
     223        psError(__func__, "Image can not be NULL.");
    214224        return unexposedValue;
    215225    }
    216 
    217226    #define PSIMAGE_PIXEL_INTERPOLATE_CASE(TYPE) \
    218227case PS_TYPE_##TYPE: \
     
    243252        PSIMAGE_PIXEL_INTERPOLATE_CASE(C64);
    244253    default:
    245         psError(__func__,"Unsupported image datatype (%d)",input->type.type);
     254        psError(__func__, "Unsupported image datatype (%d)", input->type.type);
    246255    }
    247256
     
    303312PSIMAGE_PIXEL_INTERPOLATE_FLAT_COMPLEX(C32)
    304313PSIMAGE_PIXEL_INTERPOLATE_FLAT_COMPLEX(C64)
    305 
    306314#define PSIMAGE_PIXEL_INTERPOLATE_BILINEAR(TYPE) \
    307315inline psF64 p_psImagePixelInterpolateBILINEAR_##TYPE(const psImage *input, \
     
    359367    return(pixel); \
    360368}
    361 
    362369#define PSIMAGE_PIXEL_INTERPOLATE_BILINEAR_COMPLEX(TYPE) \
    363370inline psC64 p_psImagePixelInterpolateBILINEAR_##TYPE(const psImage *input, \
     
    428435PSIMAGE_PIXEL_INTERPOLATE_BILINEAR_COMPLEX(C32)
    429436PSIMAGE_PIXEL_INTERPOLATE_BILINEAR_COMPLEX(C64)
    430 
    431 
Note: See TracChangeset for help on using the changeset viewer.