Changeset 2105 for trunk/psLib/test/image/tst_psImageManip.c
- Timestamp:
- Oct 13, 2004, 3:22:59 PM (22 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/image/tst_psImageManip.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/image/tst_psImageManip.c
r1943 r2105 6 6 * @author Robert DeSonia, MHPCC 7 7 * 8 * @version $Revision: 1.2 8$ $Name: not supported by cvs2svn $9 * @date $Date: 2004-10- 02 02:23:05$8 * @version $Revision: 1.29 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2004-10-14 01:22:59 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 34 34 static int testImageShift(void); 35 35 static int testImageShiftCase(int cols, int rows, float colShift,float rowShift); 36 static int testImageResample(void); 36 37 37 38 testDescription tests[] = { … … 44 45 {testImageRotate,560,"psImageRotate",0,false}, 45 46 {testImageShift,561,"psImageShift",0,false}, 47 {testImageResample,743,"psImageResample",0,false}, 46 48 {NULL} 47 49 }; … … 1704 1706 return 0; 1705 1707 } 1708 1709 static int testImageResample(void) 1710 { 1711 1712 int rows = 60; 1713 int cols = 80; 1714 psImage* result = NULL; 1715 int scale = 4; 1716 psErr* err; 1717 1718 psImage* image = psImageAlloc(cols,rows,PS_TYPE_F32); 1719 for(int row=0;row<rows;row++) { 1720 psF32* imageRow = image->data.F32[row]; 1721 for (int col=0;col<cols;col++) { 1722 imageRow[col] = row+2*col; 1723 } 1724 } 1725 result = psImageCopy(NULL,image,PS_TYPE_F64); 1726 psImage* orig = result; 1727 result = psImageResample(result,image,scale,PS_INTERPOLATE_FLAT); 1728 1729 if (result == NULL) { 1730 psLogMsg(__func__,PS_LOG_ERROR, 1731 "NULL return unexpected"); 1732 return 1; 1733 } 1734 1735 if (result != orig) { 1736 psLogMsg(__func__,PS_LOG_ERROR,"failure to recycle image."); 1737 return 2; 1738 } 1739 1740 if (result->type.type != PS_TYPE_F32) { 1741 psLogMsg(__func__,PS_LOG_ERROR,"unexpected type"); 1742 return 3; 1743 } 1744 1745 1746 if (result->numCols != image->numCols*scale || 1747 result->numRows != image->numRows*scale) { 1748 psLogMsg(__func__,PS_LOG_ERROR,"The size of the result is %dx%d, but %dx%d was expected.", 1749 result->numCols,result->numRows, 1750 image->numCols*scale, image->numRows*scale); 1751 return 4; 1752 } 1753 1754 psF32 truthValue; 1755 for(int row=0;row<result->numRows;row++) { 1756 for (int col=0;col<result->numCols;col++) { 1757 truthValue = psImagePixelInterpolate(image, 1758 (float)col/(float)scale,(float)row/(float)scale, 1759 NULL,0,-1,PS_INTERPOLATE_FLAT); 1760 if (fabs(truthValue - result->data.F32[row][col]) > FLT_EPSILON) { 1761 psLogMsg(__func__,PS_LOG_ERROR,"value bad at (%d,%d). Got %g, expected %g.", 1762 col,row,result->data.F32[row][col], truthValue); 1763 return 5; 1764 } 1765 } 1766 } 1767 1768 // verify that image=null is handled properly. 1769 psErrorClear(); 1770 result = psImageResample(result,NULL,scale,PS_INTERPOLATE_FLAT); 1771 1772 if (result != NULL) { 1773 psLogMsg(__func__,PS_LOG_ERROR, 1774 "return was not NULL, as expected."); 1775 return 6; 1776 } 1777 err = psErrorLast(); 1778 if (err->code != PS_ERR_BAD_PARAMETER_NULL) { 1779 psLogMsg(__func__,PS_LOG_ERROR, 1780 "error message was not appropriate type."); 1781 return 7; 1782 } 1783 psFree(err); 1784 1785 // verify that scale < 1 is handled properly 1786 psErrorClear(); 1787 result = psImageResample(result,image,0,PS_INTERPOLATE_FLAT); 1788 1789 if (result != NULL) { 1790 psLogMsg(__func__,PS_LOG_ERROR, 1791 "return was not NULL, as expected."); 1792 return 8; 1793 } 1794 err = psErrorLast(); 1795 if (err->code != PS_ERR_BAD_PARAMETER_VALUE) { 1796 psLogMsg(__func__,PS_LOG_ERROR, 1797 "error message was not appropriate type."); 1798 return 9; 1799 } 1800 psFree(err); 1801 1802 // verify that invalid interpolation mode is handled properly 1803 psErrorClear(); 1804 result = psImageResample(result,image,2,0); 1805 1806 if (result != NULL) { 1807 psLogMsg(__func__,PS_LOG_ERROR, 1808 "return was not NULL, as expected."); 1809 return 10; 1810 } 1811 err = psErrorLast(); 1812 if (err->code != PS_ERR_BAD_PARAMETER_VALUE) { 1813 psLogMsg(__func__,PS_LOG_ERROR, 1814 "error message was not appropriate type."); 1815 return 11; 1816 } 1817 psFree(err); 1818 1819 psFree(image); 1820 psFree(result); 1821 1822 return 0; 1823 } 1824
Note:
See TracChangeset
for help on using the changeset viewer.
