IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 17, 2006, 10:38:19 AM (20 years ago)
Author:
drobbin
Message:

Updated ImageRow, Col, Slice with respect to Sub-image v. parent-image specs.

File:
1 edited

Legend:

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

    r6484 r6631  
    88 *  @author Robert DeSonia, MHPCC
    99 *
    10  *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2006-02-24 23:43:15 $
     10 *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2006-03-17 20:38:19 $
    1212 *
    1313 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    5151                     int row)
    5252{
    53     if (input == NULL) {
    54         psError(PS_ERR_BAD_PARAMETER_NULL, true, PS_ERRORTEXT_psImage_IMAGE_NULL);
    55         return NULL;
    56     }
    57     if (row >= input->numRows) {
     53    if (input == NULL || input->data.V == NULL) {
     54        psError(PS_ERR_BAD_PARAMETER_NULL, true,
     55                PS_ERRORTEXT_psImage_IMAGE_NULL);
     56        psFree(out);
     57        return NULL;
     58    }
     59    PS_ASSERT_INT_NONNEGATIVE(input->col0, NULL);
     60    PS_ASSERT_INT_NONNEGATIVE(input->row0, NULL);
     61    PS_ASSERT_INT_POSITIVE(input->numCols, NULL);
     62    PS_ASSERT_INT_POSITIVE(input->numRows, NULL);
     63    if (row >= (input->numRows + input->row0) ) {
    5864        psError(PS_ERR_BAD_PARAMETER_NULL, true,
    5965                "Specified row number is out of range for specified image.\n");
    6066        return NULL;
    61     }
    62     if (row < 0) {
     67    } else if ( row < input->row0 && row >= 0 ) {
     68        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     69                "Specified row number is out of range for specified image.\n");
     70        return NULL;
     71    } else if ( row < 0 ) {
    6372        row += input->numRows;
    64         if (row < 0) {
     73        if ( row < 0 ) {
    6574            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    6675                    "Specified row number is out of range for specified image.\n");
    6776            return NULL;
    6877        }
    69     }
     78    } else {
     79        row -= input->row0;
     80    }
     81
    7082    psVectorRecycle(out, input->numCols, input->type.type);
    7183
     
    146158                     int column)
    147159{
    148     if (input == NULL) {
    149         psError(PS_ERR_BAD_PARAMETER_NULL, true, PS_ERRORTEXT_psImage_IMAGE_NULL);
    150         return NULL;
    151     }
    152     if (column >= input->numCols) {
     160    if (input == NULL || input->data.V == NULL) {
     161        psError(PS_ERR_BAD_PARAMETER_NULL, true,
     162                PS_ERRORTEXT_psImage_IMAGE_NULL);
     163        psFree(out);
     164        return NULL;
     165    }
     166    PS_ASSERT_INT_NONNEGATIVE(input->col0, NULL);
     167    PS_ASSERT_INT_NONNEGATIVE(input->row0, NULL);
     168    PS_ASSERT_INT_POSITIVE(input->numCols, NULL);
     169    PS_ASSERT_INT_POSITIVE(input->numRows, NULL);
     170    if (column >= (input->numCols + input->col0) ) {
    153171        psError(PS_ERR_BAD_PARAMETER_NULL, true,
    154172                "Specified column number is out of range for specified image.\n");
    155173        return NULL;
    156     }
    157     if (column < 0) {
     174    } else if ( column < input->col0 && column >= 0 ) {
     175        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     176                "Specified column number is out of range for specified image.\n");
     177        return NULL;
     178    } else if ( column < 0 ) {
    158179        column += input->numCols;
    159         if (column < 0) {
     180        if ( column < 0 ) {
    160181            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    161182                    "Specified column number is out of range for specified image.\n");
    162183            return NULL;
    163184        }
    164     }
    165 
     185    } else {
     186        column -= input->col0;
     187    }
    166188
    167189    psVectorRecycle(out, input->numRows, input->type.type);
     
    213235
    214236}
    215 
    216237
    217238psVector* psImageSlice(psVector* out,
     
    242263        return NULL;
    243264    }
    244 
    245     if (col1 < 1) {
     265    PS_ASSERT_INT_NONNEGATIVE(input->col0, NULL);
     266    PS_ASSERT_INT_NONNEGATIVE(input->row0, NULL);
     267    PS_ASSERT_INT_POSITIVE(input->numCols, NULL);
     268    PS_ASSERT_INT_POSITIVE(input->numRows, NULL);
     269    /*
     270        if (col1 < 1) {
     271            col1 += input->numCols;
     272        }
     273     
     274        if (row1 < 1) {
     275            row1 += input->numRows;
     276        }
     277     
     278        if (    col0 < 0 ||
     279                row0 < 0 ||
     280                col1 > input->numCols ||
     281                row1 > input->numRows ||
     282                col0 >= col1 ||
     283                row0 >= row1) {
     284            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     285                    PS_ERRORTEXT_psImage_SUBSET_RANGE_INVALID,
     286                    col0, col1, row0, row1,
     287                    input->numCols, input->numRows);
     288            psFree(out);
     289            return NULL;
     290        }
     291    */
     292    //Make sure x0 of region is inside image.  If so, set col0 to corresponding index number.
     293    if (col0 >= input->col0 && col0 < (input->col0 + input->numCols) ) {
     294        col0 -= input->col0;
     295    } else {
     296        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     297                "Specified psRegion parameter, x0=%f, is out of range [%d,%d].\n",
     298                region.x0, input->col0, input->col0+input->numCols);
     299        return NULL;
     300    }
     301    //Make sure y0 of region is inside image.  If so, set row0 to corresponding index number.
     302    if (row0 >= input->row0 && row0 < (input->row0 + input->numRows) ) {
     303        row0 -= input->row0;
     304    } else {
     305        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     306                "Specified psRegion parameter, y0=%f, is out of range [%d,%d].\n",
     307                region.y0, input->row0, input->row0+input->numRows);
     308        return NULL;
     309    }
     310
     311    //Make sure x1 of region is valid.  If negative, index from tail (if valid).
     312    if (col1 < 0) {
    246313        col1 += input->numCols;
    247     }
    248 
    249     if (row1 < 1) {
     314        if (col1 < 0) {
     315            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     316                    "Specified psRegion parameter, x1=%f=%d, is out of range [%d,%d].\n",
     317                    region.x1, col1+input->col0, input->col0, input->col0+input->numCols);
     318            return NULL;
     319        }
     320    } else if (col1 >= input->col0 && col1 < (input->col0 + input->numCols) ) {
     321        col1 -= input->col0;
     322    } else {
     323        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     324                "Specified psRegion parameter, x1=%f=%d, is out of range [%d,%d].\n",
     325                region.x1, col1, input->col0, input->col0+input->numCols);
     326        return NULL;
     327    }
     328    //Make sure y1 of region is valid.  If negative, index from tail (if valid).
     329    if (row1 < 0) {
    250330        row1 += input->numRows;
    251     }
    252 
    253     if (    col0 < 0 ||
    254             row0 < 0 ||
    255             col1 > input->numCols ||
    256             row1 > input->numRows ||
    257             col0 >= col1 ||
    258             row0 >= row1) {
    259         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    260                 PS_ERRORTEXT_psImage_SUBSET_RANGE_INVALID,
    261                 col0, col1, row0, row1,
    262                 input->numCols, input->numRows);
    263         psFree(out);
     331        if (row1 < 0) {
     332            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     333                    "Specified psRegion parameter, y1=%f=%d, is out of range [%d,%d].\n",
     334                    region.y1, row1+input->row0, input->row0, input->row0+input->numRows);
     335            return NULL;
     336        }
     337    } else if (row1 >= input->row0 && row1 < (input->row0 + input->numRows) ) {
     338        row1 -= input->row0;
     339    } else {
     340        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     341                "Specified psRegion parameter, y1=%f=%d, is out of range [%d,%d].\n",
     342                region.y1, row1, input->row0, input->row0+input->numRows);
     343        return NULL;
     344    }
     345    //Now make sure that the region makes sense.
     346    if (col0 > col1 || row0 > row1) {
     347        if (col0 > col1) {
     348            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     349                    "Invalid psRegion specified.  x0=%f=%d is greater than x1=%f=%d.\n",
     350                    region.x0, col0, region.x1, col1);
     351        } else {
     352            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     353                    "Invalid psRegion specified.  y0=%f=%d is greater than y1=%f=%d.\n",
     354                    region.y0, row0, region.y1, row1);
     355        }
     356        return NULL;
     357    } else if (col0 == col1 && row0 == row1) {
     358        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     359                "Invalid psRegion specified.  Region contains only 1 pixel.\n");
    264360        return NULL;
    265361    }
     
    487583        return NULL;
    488584    }
     585    //    PS_ASSERT_INT_NONNEGATIVE(input->col0, NULL);
     586    //    PS_ASSERT_INT_NONNEGATIVE(input->row0, NULL);
     587    //    PS_ASSERT_INT_POSITIVE(input->numCols, NULL);
     588    //    PS_ASSERT_INT_POSITIVE(input->numRows, NULL);
    489589    psS32 numCols = input->numCols;
    490590    psS32 numRows = input->numRows;
     
    497597        return NULL;
    498598    }
     599
    499600
    500601    float startCol = region.x0;
Note: See TracChangeset for help on using the changeset viewer.