IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 31, 2006, 4:43:57 PM (20 years ago)
Author:
drobbin
Message:

Made several changes to image functions/tests w.r.t. subimage v. parent image issue.

File:
1 edited

Legend:

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

    r6631 r6750  
    88 *  @author Robert DeSonia, MHPCC
    99 *
    10  *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2006-03-17 20:38:19 $
     10 *  @version $Revision: 1.14 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2006-04-01 02:43:57 $
    1212 *
    1313 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    5757        return NULL;
    5858    }
    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);
     59    if (input->col0 < 0) {
     60        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     61                "psImage input is invalid.  col0 cannot be negative.\n");
     62        psFree(out);
     63        return NULL;
     64    }
     65    if (input->row0 < 0) {
     66        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     67                "psImage input is invalid.  row0 cannot be negative.\n");
     68        psFree(out);
     69        return NULL;
     70    }
     71    if (input->numCols < 1) {
     72        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     73                "psImage input is invalid.  numCols must be greater than 0.\n");
     74        psFree(out);
     75        return NULL;
     76    }
     77    if (input->numRows < 1) {
     78        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     79                "psImage input is invalid.  numRows must be greater than 0.\n");
     80        psFree(out);
     81        return NULL;
     82    }
    6383    if (row >= (input->numRows + input->row0) ) {
    6484        psError(PS_ERR_BAD_PARAMETER_NULL, true,
    6585                "Specified row number is out of range for specified image.\n");
     86        psFree(out);
    6687        return NULL;
    6788    } else if ( row < input->row0 && row >= 0 ) {
    6889        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    6990                "Specified row number is out of range for specified image.\n");
     91        psFree(out);
    7092        return NULL;
    7193    } else if ( row < 0 ) {
     
    7496            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    7597                    "Specified row number is out of range for specified image.\n");
     98            psFree(out);
    7699            return NULL;
    77100        }
     
    164187        return NULL;
    165188    }
    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);
     189    if (input->col0 < 0) {
     190        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     191                "psImage input is invalid.  col0 cannot be negative.\n");
     192        psFree(out);
     193        return NULL;
     194    }
     195    if (input->row0 < 0) {
     196        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     197                "psImage input is invalid.  row0 cannot be negative.\n");
     198        psFree(out);
     199        return NULL;
     200    }
     201    if (input->numCols < 1) {
     202        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     203                "psImage input is invalid.  numCols must be greater than 0.\n");
     204        psFree(out);
     205        return NULL;
     206    }
     207    if (input->numRows < 1) {
     208        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     209                "psImage input is invalid.  numRows must be greater than 0.\n");
     210        psFree(out);
     211        return NULL;
     212    }
    170213    if (column >= (input->numCols + input->col0) ) {
    171214        psError(PS_ERR_BAD_PARAMETER_NULL, true,
    172215                "Specified column number is out of range for specified image.\n");
     216        psFree(out);
    173217        return NULL;
    174218    } else if ( column < input->col0 && column >= 0 ) {
    175219        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    176220                "Specified column number is out of range for specified image.\n");
     221        psFree(out);
    177222        return NULL;
    178223    } else if ( column < 0 ) {
     
    181226            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    182227                    "Specified column number is out of range for specified image.\n");
     228            psFree(out);
    183229            return NULL;
    184230        }
     
    263309        return NULL;
    264310    }
    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);
     311    if (input->col0 < 0) {
     312        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     313                "psImage input is invalid.  col0 cannot be negative.\n");
     314        psFree(out);
     315        return NULL;
     316    }
     317    if (input->row0 < 0) {
     318        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     319                "psImage input is invalid.  row0 cannot be negative.\n");
     320        psFree(out);
     321        return NULL;
     322    }
     323    if (input->numCols < 1) {
     324        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     325                "psImage input is invalid.  numCols must be greater than 0.\n");
     326        psFree(out);
     327        return NULL;
     328    }
     329    if (input->numRows < 1) {
     330        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     331                "psImage input is invalid.  numRows must be greater than 0.\n");
     332        psFree(out);
     333        return NULL;
     334    }
    269335    /*
    270336        if (col1 < 1) {
    271337            col1 += input->numCols;
    272338        }
    273      
     339
    274340        if (row1 < 1) {
    275341            row1 += input->numRows;
    276342        }
    277      
     343
    278344        if (    col0 < 0 ||
    279345                row0 < 0 ||
     
    296362        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    297363                "Specified psRegion parameter, x0=%f, is out of range [%d,%d].\n",
    298                 region.x0, input->col0, input->col0+input->numCols);
     364                region.x0, input->col0, input->col0+input->numCols-1);
    299365        return NULL;
    300366    }
     
    305371        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    306372                "Specified psRegion parameter, y0=%f, is out of range [%d,%d].\n",
    307                 region.y0, input->row0, input->row0+input->numRows);
     373                region.y0, input->row0, input->row0+input->numRows-1);
    308374        return NULL;
    309375    }
     
    315381            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    316382                    "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);
     383                    region.x1, col1+input->col0, input->col0, input->col0+input->numCols-1);
    318384            return NULL;
    319385        }
     
    323389        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    324390                "Specified psRegion parameter, x1=%f=%d, is out of range [%d,%d].\n",
    325                 region.x1, col1, input->col0, input->col0+input->numCols);
     391                region.x1, col1, input->col0, input->col0+input->numCols-1);
    326392        return NULL;
    327393    }
     
    332398            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    333399                    "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);
     400                    region.y1, row1+input->row0, input->row0, input->row0+input->numRows-1);
    335401            return NULL;
    336402        }
     
    340406        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    341407                "Specified psRegion parameter, y1=%f=%d, is out of range [%d,%d].\n",
    342                 region.y1, row1, input->row0, input->row0+input->numRows);
     408                region.y1, row1, input->row0, input->row0+input->numRows-1);
    343409        return NULL;
    344410    }
     
    583649        return NULL;
    584650    }
    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);
     651    if (input->col0 < 0) {
     652        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     653                "psImage input is invalid.  col0 cannot be negative.\n");
     654        psFree(out);
     655        return NULL;
     656    }
     657    if (input->row0 < 0) {
     658        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     659                "psImage input is invalid.  row0 cannot be negative.\n");
     660        psFree(out);
     661        return NULL;
     662    }
     663    if (input->numCols < 1) {
     664        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     665                "psImage input is invalid.  numCols must be greater than 0.\n");
     666        psFree(out);
     667        return NULL;
     668    }
     669    if (input->numRows < 1) {
     670        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     671                "psImage input is invalid.  numRows must be greater than 0.\n");
     672        psFree(out);
     673        return NULL;
     674    }
    589675    psS32 numCols = input->numCols;
    590676    psS32 numRows = input->numRows;
     
    598684    }
    599685
    600 
    601     float startCol = region.x0;
    602     float startRow = region.y0;
    603     float endCol = region.x1;
    604     float endRow = region.y1;
    605     if (startCol < 0 || startCol >= numCols ||
    606             startRow < 0 || startRow >= numRows ||
    607             endCol < 0 || endCol >= numCols ||
    608             endRow < 0 || endRow >= numRows) {
    609         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
    610                 PS_ERRORTEXT_psImage_LINE_NOT_IN_IMAGE,
    611                 startCol,startRow,endCol,endRow,
    612                 numCols-1,numRows-1);
    613         psFree(out);
    614         return NULL;
    615     }
     686    float col0 = region.x0;
     687    float row0 = region.y0;
     688    float col1 = region.x1;
     689    float row1 = region.y1;
     690
     691    //Make sure x0 of region is inside image.  If so, set col0 to corresponding index number.
     692    if (col0 >= input->col0 && col0 < (input->col0 + input->numCols) ) {
     693        col0 -= input->col0;
     694    } else {
     695        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     696                "Specified psRegion parameter, x0=%f, is out of range [%d,%d].\n",
     697                region.x0, input->col0, input->col0+input->numCols);
     698        psFree(out);
     699        return NULL;
     700    }
     701    //Make sure y0 of region is inside image.  If so, set row0 to corresponding index number.
     702    if (row0 >= input->row0 && row0 < (input->row0 + input->numRows) ) {
     703        row0 -= input->row0;
     704    } else {
     705        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     706                "Specified psRegion parameter, y0=%f, is out of range [%d,%d].\n",
     707                region.y0, input->row0, input->row0+input->numRows);
     708        psFree(out);
     709        return NULL;
     710    }
     711    /*
     712        //Make sure x1 of region is valid.  If negative, index from tail (if valid).
     713        if (col1 < 0) {
     714            col1 += input->numCols;
     715            if (col1 < 0) {
     716                psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     717                        "Specified psRegion parameter, x1=%f=%f, is out of range [%d,%d].\n",
     718                        region.x1, col1+input->col0, input->col0, input->col0+input->numCols);
     719                psFree(out);
     720                return NULL;
     721            }
     722        } else if (col1 >= input->col0 && col1 < (input->col0 + input->numCols) ) {
     723            col1 -= input->col0;
     724        } else {
     725            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     726                    "Specified psRegion parameter, x1=%f=%f, is out of range [%d,%d].\n",
     727                    region.x1, col1, input->col0, input->col0+input->numCols);
     728            psFree(out);
     729            return NULL;
     730        }
     731        //Make sure y1 of region is valid.  If negative, index from tail (if valid).
     732        if (row1 < 0) {
     733            row1 += input->numRows;
     734            if (row1 < 0) {
     735                psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     736                        "Specified psRegion parameter, y1=%f=%f, is out of range [%d,%d].\n",
     737                        region.y1, row1+input->row0, input->row0, input->row0+input->numRows);
     738                psFree(out);
     739                return NULL;
     740            }
     741        } else if (row1 >= input->row0 && row1 < (input->row0 + input->numRows) ) {
     742            row1 -= input->row0;
     743        } else {
     744            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     745                    "Specified psRegion parameter, y1=%f=%f, is out of range [%d,%d].\n",
     746                    region.y1, row1, input->row0, input->row0+input->numRows);
     747            psFree(out);
     748            return NULL;
     749        }
     750    */
     751    /*    //Now make sure that the region makes sense.
     752        if (col0 > col1 || row0 > row1) {
     753            if (col0 > col1) {
     754                psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     755                        "Invalid psRegion specified.  x0=%f=%f is greater than x1=%f=%f.\n",
     756                        region.x0, col0, region.x1, col1);
     757            } else {
     758                psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     759                        "Invalid psRegion specified.  y0=%f=%f is greater than y1=%f=%f.\n",
     760                        region.y0, row0, region.y1, row1);
     761            }
     762            psFree(out);
     763            return NULL;
     764        } else if (col0 == col1 && row0 == row1) {
     765            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     766                    "Invalid psRegion specified.  Region contains only 1 pixel.\n");
     767            psFree(out);
     768            return NULL;
     769        }
     770    */
     771    if (col1 < 0 || row1 < 0 || col0 < 0 || row0 < 0 || col0 >= numCols || col1 >= numCols ||
     772            row0 >= numRows || row1 >= numRows) {
     773        psFree(out);
     774        return NULL;
     775    }
     776    float startCol = col0;
     777    float startRow = row0;
     778    float endCol = col1;
     779    float endRow = row1;
     780    /*
     781        float startCol = region.x0;
     782        float startRow = region.y0;
     783        float endCol = region.x1;
     784        float endRow = region.y1;
     785        if (startCol < 0 || startCol >= numCols ||
     786                startRow < 0 || startRow >= numRows ||
     787                endCol < 0 || endCol >= numCols ||
     788                endRow < 0 || endRow >= numRows) {
     789            psError(PS_ERR_BAD_PARAMETER_VALUE, true,
     790                    PS_ERRORTEXT_psImage_LINE_NOT_IN_IMAGE,
     791                    startCol,startRow,endCol,endRow,
     792                    numCols-1,numRows-1);
     793            psFree(out);
     794            return NULL;
     795        }
     796    */
    616797
    617798    if (mode < PS_INTERPOLATE_FLAT ) {
Note: See TracChangeset for help on using the changeset viewer.