IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 719


Ignore:
Timestamp:
May 18, 2004, 1:26:26 PM (22 years ago)
Author:
desonia
Message:

various fixing cooresponding to testpoint #547 (psImageSubset).

Location:
trunk/psLib/src
Files:
1 deleted
4 edited

Legend:

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

    r715 r719  
    77 *  @author Ross Harman, MHPCC
    88 *   
    9  *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-05-18 18:39:43 $
     9 *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-05-18 23:26:26 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    7070}
    7171
     72psImage* psImageRealloc(psImage* old,unsigned int numCols, unsigned int numRows, const psElemType type)
     73{
     74    int elementSize = PSELEMTYPE_SIZEOF(type); // element size in bytes
     75    int rowSize = numCols*elementSize;  // row size in bytes.
     76
     77    if (old == NULL) {
     78        old = psImageAlloc(numCols,numRows,type);
     79        return old;
     80    }
     81
     82    if (old->type.dimen != PS_DIMEN_IMAGE) {
     83        psError(__func__,"Can not realloc image because image is not an image.");
     84        return NULL;
     85    }
     86
     87    /* image already the right size/type? */
     88    if (numCols == old->numCols && numRows == old->numRows && type == old->type.type) {
     89        return old;
     90    }
     91
     92    // Resize the image buffer
     93    old->data.v[0] = psRealloc(old->data.v[0],numCols * numRows * elementSize);
     94    old->data.v = (void**) psRealloc(old->data.v,numRows * sizeof(void*));
     95
     96    // recreate the row pointers
     97    for(int i = 1; i < numRows; i++) {
     98        old->data.v[i] = (void*)((int8_t*)old->data.v[i-1]+rowSize);
     99    }
     100
     101    *(unsigned int*)&old->numCols = numCols;
     102    *(unsigned int*)&old->numRows = numRows;
     103    *(psElemType*)&old->type.type = type;
     104
     105    return old;
     106}
     107
    72108psImage *psImageSubset(psImage *out,psImage *image,unsigned int numCols,
    73109                       unsigned int numRows, unsigned int col0, unsigned int row0)
    74110{
    75     psElemType type;
    76111    unsigned int elementSize;           // size of image element in bytes
    77112    unsigned int outputRowSize;         // output row size in bytes
     
    88123    }
    89124
     125    if (numCols < 1 || numRows < 1) {
     126        psError(__func__,"Can not subset image because number of rows or columns are zero (%dx%d).",
     127                numCols, numRows);
     128        return NULL;
     129    }
     130
     131    if (col0 >= image->numCols || row0 >= image->numRows) {
     132        psError(__func__,"Can not subset image because col0,row0 (%d,%d) is not a valid pixel "
     133                "location.", col0,row0);
     134        return NULL;
     135    }
     136
    90137    /* validate subimage size */
    91138    if (col0+numCols >= image->numCols || row0+numRows >= image->numRows) {
    92139        psError(__func__,"Can not subset image outside of image boundaries (size=%dx%d, "
    93                 "subset=[%d:%d,%d:%d]).",image->numCols,image->numRows,image->col0,
    94                 image->col0+numCols, image->row0, image->row0+numRows);
    95         return NULL;
    96     }
    97 
    98     type = image->type.type;
    99     elementSize = PSELEMTYPE_SIZEOF(type);
    100 
    101     if (out == NULL) {
    102         out = psImageAlloc(numCols,numRows,image->type.type);
    103     } else if (out->numCols != numCols || out->numRows != numRows || out->type.type != type) {
    104         // sizes/type different, can't reuse the given image buffer
    105         psImageFree(out);
    106         out = psImageAlloc(numCols,numRows,image->type.type);
    107     }
     140                "subset=[%d:%d,%d:%d]).",image->numCols,image->numRows,col0,
     141                col0+numCols, row0, row0+numRows);
     142        return NULL;
     143    }
     144
     145
     146    elementSize = PSELEMTYPE_SIZEOF(image->type.type);
     147
     148    out = psImageRealloc(out,numCols,numRows,image->type.type);
    108149
    109150    // set the parent information into the child output image
     
    199240    }
    200241
    201 
    202     if (output == NULL) {
    203         output = psImageAlloc(numCols,numRows,type);
    204     } else if (output->numCols != numCols || output->numRows != numRows ||
    205                output->type.type != type) {        // sizes/type different, can't reuse the given image buffer
    206         psImageFree(output);
    207         output = psImageAlloc(numCols,numRows,type);
    208     }
    209 
    210     // cover the trival case of copy of the same type.
     242    output = psImageRealloc(output,numCols,numRows,type);
     243
     244    // cover the trival case of copy of the same datatype.
    211245    if (type == inDatatype) {
    212246        memcpy(output->data.v[0],input->data.v[0],elementSize*numRows*numCols);
  • trunk/psLib/src/image/psImage.h

    r714 r719  
    77 *  @author Ross Harman, MHPCC
    88 *   
    9  *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-05-18 02:33:59 $
     9 *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-05-18 23:26:26 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    138138);
    139139
     140/** Resize a given image to the given size/type.
     141 *
     142 *  return psImage* Resized psImage.
     143 *
     144 */
     145psImage* psImageRealloc(
     146    psImage* old,                   ///< the psImage to recycle by resizing image buffer
     147    unsigned int numCols,           ///< the desired number of columns in image
     148    unsigned int numRows,           ///< the desired number of rows in image
     149    const psElemType type           ///< the desired datatype of the image
     150);
     151
    140152#endif
  • trunk/psLib/src/mathtypes/psImage.c

    r715 r719  
    77 *  @author Ross Harman, MHPCC
    88 *   
    9  *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-05-18 18:39:43 $
     9 *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-05-18 23:26:26 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    7070}
    7171
     72psImage* psImageRealloc(psImage* old,unsigned int numCols, unsigned int numRows, const psElemType type)
     73{
     74    int elementSize = PSELEMTYPE_SIZEOF(type); // element size in bytes
     75    int rowSize = numCols*elementSize;  // row size in bytes.
     76
     77    if (old == NULL) {
     78        old = psImageAlloc(numCols,numRows,type);
     79        return old;
     80    }
     81
     82    if (old->type.dimen != PS_DIMEN_IMAGE) {
     83        psError(__func__,"Can not realloc image because image is not an image.");
     84        return NULL;
     85    }
     86
     87    /* image already the right size/type? */
     88    if (numCols == old->numCols && numRows == old->numRows && type == old->type.type) {
     89        return old;
     90    }
     91
     92    // Resize the image buffer
     93    old->data.v[0] = psRealloc(old->data.v[0],numCols * numRows * elementSize);
     94    old->data.v = (void**) psRealloc(old->data.v,numRows * sizeof(void*));
     95
     96    // recreate the row pointers
     97    for(int i = 1; i < numRows; i++) {
     98        old->data.v[i] = (void*)((int8_t*)old->data.v[i-1]+rowSize);
     99    }
     100
     101    *(unsigned int*)&old->numCols = numCols;
     102    *(unsigned int*)&old->numRows = numRows;
     103    *(psElemType*)&old->type.type = type;
     104
     105    return old;
     106}
     107
    72108psImage *psImageSubset(psImage *out,psImage *image,unsigned int numCols,
    73109                       unsigned int numRows, unsigned int col0, unsigned int row0)
    74110{
    75     psElemType type;
    76111    unsigned int elementSize;           // size of image element in bytes
    77112    unsigned int outputRowSize;         // output row size in bytes
     
    88123    }
    89124
     125    if (numCols < 1 || numRows < 1) {
     126        psError(__func__,"Can not subset image because number of rows or columns are zero (%dx%d).",
     127                numCols, numRows);
     128        return NULL;
     129    }
     130
     131    if (col0 >= image->numCols || row0 >= image->numRows) {
     132        psError(__func__,"Can not subset image because col0,row0 (%d,%d) is not a valid pixel "
     133                "location.", col0,row0);
     134        return NULL;
     135    }
     136
    90137    /* validate subimage size */
    91138    if (col0+numCols >= image->numCols || row0+numRows >= image->numRows) {
    92139        psError(__func__,"Can not subset image outside of image boundaries (size=%dx%d, "
    93                 "subset=[%d:%d,%d:%d]).",image->numCols,image->numRows,image->col0,
    94                 image->col0+numCols, image->row0, image->row0+numRows);
    95         return NULL;
    96     }
    97 
    98     type = image->type.type;
    99     elementSize = PSELEMTYPE_SIZEOF(type);
    100 
    101     if (out == NULL) {
    102         out = psImageAlloc(numCols,numRows,image->type.type);
    103     } else if (out->numCols != numCols || out->numRows != numRows || out->type.type != type) {
    104         // sizes/type different, can't reuse the given image buffer
    105         psImageFree(out);
    106         out = psImageAlloc(numCols,numRows,image->type.type);
    107     }
     140                "subset=[%d:%d,%d:%d]).",image->numCols,image->numRows,col0,
     141                col0+numCols, row0, row0+numRows);
     142        return NULL;
     143    }
     144
     145
     146    elementSize = PSELEMTYPE_SIZEOF(image->type.type);
     147
     148    out = psImageRealloc(out,numCols,numRows,image->type.type);
    108149
    109150    // set the parent information into the child output image
     
    199240    }
    200241
    201 
    202     if (output == NULL) {
    203         output = psImageAlloc(numCols,numRows,type);
    204     } else if (output->numCols != numCols || output->numRows != numRows ||
    205                output->type.type != type) {        // sizes/type different, can't reuse the given image buffer
    206         psImageFree(output);
    207         output = psImageAlloc(numCols,numRows,type);
    208     }
    209 
    210     // cover the trival case of copy of the same type.
     242    output = psImageRealloc(output,numCols,numRows,type);
     243
     244    // cover the trival case of copy of the same datatype.
    211245    if (type == inDatatype) {
    212246        memcpy(output->data.v[0],input->data.v[0],elementSize*numRows*numCols);
  • trunk/psLib/src/mathtypes/psImage.h

    r714 r719  
    77 *  @author Ross Harman, MHPCC
    88 *   
    9  *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
    10  *  @date $Date: 2004-05-18 02:33:59 $
     9 *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
     10 *  @date $Date: 2004-05-18 23:26:26 $
    1111 *
    1212 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    138138);
    139139
     140/** Resize a given image to the given size/type.
     141 *
     142 *  return psImage* Resized psImage.
     143 *
     144 */
     145psImage* psImageRealloc(
     146    psImage* old,                   ///< the psImage to recycle by resizing image buffer
     147    unsigned int numCols,           ///< the desired number of columns in image
     148    unsigned int numRows,           ///< the desired number of rows in image
     149    const psElemType type           ///< the desired datatype of the image
     150);
     151
    140152#endif
Note: See TracChangeset for help on using the changeset viewer.