IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 12814


Ignore:
Timestamp:
Apr 12, 2007, 8:54:51 AM (19 years ago)
Author:
magnier
Message:

use macro to set col0,row0; subimage needs to offset pixels based on parent->col0,row0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/imageops/psImageStructManip.c

    r12431 r12814  
    88 *  @author Robert DeSonia, MHPCC
    99 *
    10  *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2007-03-14 00:39:50 $
     10 *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2007-04-12 18:54:51 $
    1212 *
    1313 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    2020
    2121#include <string.h>
     22#include <assert.h>
    2223
    2324#include "psMemory.h"
     
    2627
    2728
    28 
     29// col0,row0 are the starting pixel in the input image coordinate frame
     30// col1,row1 are the ending pixel in the input image coordinate frame
     31// note that these are relative to the input col0,row0
     32// also note that col0,row0 may not be less than input->col0,row0
    2933static psImage* imageSubset(psImage* out,
    3034                            psImage* image,
     
    3539{
    3640    psU32 elementSize;          // size of image element in bytes
    37     psS32 inputColOffset;       // offset in bytes to first subset pixel in input row
     41    psS32 inputColOffset;       // offset in **bytes** to first subset pixel in input row
     42    psS32 inputRowOffset;       // offset in **rows*** to first input row
    3843
    3944    if (image == NULL || image->data.V == NULL) {
     
    4449
    4550    if ( col0 < image->col0 || row0 < image->row0 ) {
    46         //        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    47         //                _("Specified subset range, [%d:%d,%d:%d], is invalid or outside input psImage's boundaries, [0:%d,0:%d]."));
     51        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     52                _("Specified subset range, [%d:%d,%d:%d], is invalid or outside input psImage's boundaries, [0:%d,0:%d]."),
     53                col0, col1-1, row0, row1-1, image->numCols-1, image->numRows-1);
     54        return NULL;
     55    }
     56
     57    if (image->type.dimen != PS_DIMEN_IMAGE) {
     58        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
     59                _("The input psImage must have a PS_DIMEN_IMAGE dimension type."));
     60        return NULL;
     61    }
     62
     63    if (col1 < 1) {
     64        col1 = image->col0 + image->numCols + col1;
     65    }
     66    if (row1 < 1) {
     67        row1 = image->row0 + image->numRows + row1;
     68    }
     69
     70    if (col1 <= col0 ||
     71        row1 <= row0 ||
     72        col0 >= image->col0 + image->numCols ||
     73        row0 >= image->row0 + image->numRows ||
     74        col1 > image->col0 + image->numCols ||
     75        row1 > image->row0 + image->numRows ) {
    4876        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    4977                _("Specified subset range, [%d:%d,%d:%d], is invalid or outside input psImage's boundaries, [0:%d,0:%d]."),
     
    5381    }
    5482
    55     if (image->type.dimen != PS_DIMEN_IMAGE) {
    56         psError(PS_ERR_BAD_PARAMETER_TYPE, true,
    57                 _("The input psImage must have a PS_DIMEN_IMAGE dimension type."));
    58         return NULL;
    59     }
    60 
    61     if (col1 < 1) {
    62         col1 = image->col0 + image->numCols + col1;
    63     }
    64     if (row1 < 1) {
    65         row1 = image->row0 + image->numRows + row1;
    66     }
    67 
    68     if (    col1 <= col0 ||
    69             row1 <= row0 ||
    70             col0 >= image->col0 + image->numCols ||
    71             row0 >= image->row0 + image->numRows ||
    72             col1 > image->col0 + image->numCols ||
    73             row1 > image->row0 + image->numRows ) {
    74         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    75                 _("Specified subset range, [%d:%d,%d:%d], is invalid or outside input psImage's boundaries, [0:%d,0:%d]."),
    76                 col0, col1-1, row0, row1-1,
    77                 image->numCols-1, image->numRows-1);
    78         return NULL;
    79     }
    80 
    81 
    82 
    8383    psS32 numRows = row1-row0;
    8484    psS32 numCols = col1-col0;
     
    8686    elementSize = PSELEMTYPE_SIZEOF(image->type.type);
    8787
    88     if (image->parent != NULL) { // if this is a child, we need to start working with parent.
    89         // XXX EAM : we now treat the region as parent coordinates
    90         // col0 += image->col0;
    91         // col1 += image->col0;
    92         // row0 += image->row0;
    93         // row1 += image->row0;
     88    // if this is a child, we need to start working with parent pixels
     89    // the subset region (col0,row0 - col1,row1) is in the parent frame
     90    if (image->parent != NULL) {
    9491        image = (psImage*)image->parent;
    9592    }
     
    116113    P_PSIMAGE_SET_NUMCOLS(out, numCols);
    117114    P_PSIMAGE_SET_NUMROWS(out, numRows);
    118 
    119     out->row0 = row0;
    120     out->col0 = col0;
     115    P_PSIMAGE_SET_COL0(out, col0);
     116    P_PSIMAGE_SET_ROW0(out, row0);
     117
    121118    out->parent = image;
    122119    out->children = NULL;
     
    126123    psMemSetDeallocator(out,psMemGetDeallocator(image));
    127124
    128     inputColOffset = elementSize * col0;
     125    inputRowOffset = (row0 - image->row0);
     126    inputColOffset = (col0 - image->col0)*elementSize;
     127    assert (inputRowOffset >= 0);
     128    assert (inputColOffset >= 0);
    129129    for (psS32 row = 0; row < numRows; row++) {
    130         out->data.V[row] = image->data.U8[row0 + row] + inputColOffset;
     130        out->data.V[row] = image->data.U8[row + inputRowOffset] + inputColOffset;
    131131    }
    132132
     
    183183
    184184    output = psImageRecycle(output, numCols, numRows, type);
    185     output->col0 = input->col0;
    186     output->row0 = input->row0;
     185    P_PSIMAGE_SET_COL0(output, input->col0);
     186    P_PSIMAGE_SET_ROW0(output, input->row0);
    187187
    188188    // cover the trival case of copy of the same
Note: See TracChangeset for help on using the changeset viewer.