Changeset 1654 for trunk/psLib/test/image/tst_psImageManip.c
- Timestamp:
- Aug 27, 2004, 3:19:26 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
r1605 r1654 6 6 * @author Robert DeSonia, MHPCC 7 7 * 8 * @version $Revision: 1.1 3$ $Name: not supported by cvs2svn $9 * @date $Date: 2004-08-2 0 02:55:42$8 * @version $Revision: 1.14 $ $Name: not supported by cvs2svn $ 9 * @date $Date: 2004-08-28 01:19:26 $ 10 10 * 11 11 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii … … 31 31 static int testImageRoll(void); 32 32 static int testImageRotate(void); 33 static int testImageShift(void); 34 static int testImageShiftCase(int cols, int rows, float colShift,float rowShift); 33 35 34 36 testDescription tests[] = { … … 53 55 { 54 56 testImageRotate,560,"psImageRotate",0,false 57 }, 58 { 59 testImageShift,561,"psImageShift",0,false 55 60 }, 56 61 { … … 1238 1243 return 0; 1239 1244 } 1245 1246 static int testImageShift(void) 1247 { 1248 /* psImageShift: 1249 1250 This functions shall generate a new psImage structure by shifting the 1251 input psImage structure a specified number of pixels in the horizontal 1252 and/or vertical directions. 1253 1254 Verify the returned psImage structure contains expected values, if the 1255 input psImage structure contains known values and a know shift in the 1256 vertical and/or horizontal directions. Cases should include no shift, 1257 vertical only(up,down), horizontal only(right, left), and combination 1258 shift. Cases should include fractional shifts. Comparison of expected 1259 values should include a delta to allow for testing on different 1260 platforms. 1261 1262 Verify the returned psImage structure contains values for pixels not in 1263 the original image set to the input parameter exposed. 1264 1265 */ 1266 1267 int retVal; 1268 1269 // integer shift 1270 retVal |= testImageShiftCase(64,128,0.0f,0.0f); 1271 retVal |= testImageShiftCase(64,128,0.0f,16.0f); 1272 retVal |= testImageShiftCase(64,128,0.0f,-16.0f); 1273 retVal |= testImageShiftCase(64,128,32.0f,0.0f); 1274 retVal |= testImageShiftCase(64,128,-32.0f,0.0f); 1275 retVal |= testImageShiftCase(64,128,32.0f,16.0f); 1276 retVal |= testImageShiftCase(64,128,32.0f,-16.0f); 1277 retVal |= testImageShiftCase(64,128,-32.0f,16.0f); 1278 retVal |= testImageShiftCase(64,128,-32.0f,-16.0f); 1279 1280 if (retVal != 0) { 1281 return retVal; 1282 } 1283 1284 // fractional shift 1285 retVal |= testImageShiftCase(64,128,0.0f,16.4f); 1286 retVal |= testImageShiftCase(64,128,0.0f,-16.4f); 1287 retVal |= testImageShiftCase(64,128,32.7f,0.0f); 1288 retVal |= testImageShiftCase(64,128,-32.7f,0.0f); 1289 retVal |= testImageShiftCase(64,128,32.6f,16.2f); 1290 retVal |= testImageShiftCase(64,128,32.6f,-16.2f); 1291 retVal |= testImageShiftCase(64,128,-32.6f,16.2f); 1292 retVal |= testImageShiftCase(64,128,-32.6f,-16.2f); 1293 1294 if (retVal != 0) { 1295 return retVal; 1296 } 1297 1298 /* 1299 Verify the returned psImage structure pointer is equal to the input 1300 parameter out if provided. 1301 */ 1302 psImage* fImg = psImageAlloc(32,32,PS_TYPE_F32); 1303 psImage* fRecycle = psImageAlloc(32,32,PS_TYPE_F32); 1304 psImage* fOut = psImageShift(fRecycle, fImg, 8,8, NAN, PS_INTERPOLATE_FLAT); 1305 1306 if (fRecycle != fOut) { 1307 psError(__func__,"psImageShift didn't recycle my image?"); 1308 return 10; 1309 } 1310 1311 /* 1312 Verify the returned psImage structure pointer is null and program 1313 execution doesn't stop, if the input psImage structure pointer is null. 1314 */ 1315 psLogMsg(__func__,PS_LOG_INFO,"Following should be an error..."); 1316 fOut = psImageShift(fOut,NULL,8,8,NAN,PS_INTERPOLATE_FLAT); 1317 if (fOut != NULL) { 1318 psError(__func__,"psImageShift didn't return NULL given a NULL input image."); 1319 return 11; 1320 } 1321 1322 psFree(fImg); 1323 1324 return 0; 1325 } 1326 1327 static int testImageShiftCase(int cols, 1328 int rows, 1329 float colShift, 1330 float rowShift) 1331 { 1332 psImage* fOut = NULL; 1333 psImage* sOut = NULL; 1334 1335 psLogMsg(__func__,PS_LOG_INFO,"Testing psImageShift with a %dx%d image for " 1336 "a shift of %g,%g.",cols,rows,colShift,rowShift); 1337 1338 psImage* fImg = psImageAlloc(cols,rows,PS_TYPE_F32); 1339 psImage* sImg = psImageAlloc(cols,rows,PS_TYPE_S16); 1340 1341 for(int row=0;row<rows;row++) { 1342 psF32* fRow = fImg->data.F32[row]; 1343 psS16* sRow = sImg->data.S16[row]; 1344 for (int col=0;col<cols;col++) { 1345 fRow[col] = (psF32)(row)+(psF32)(col)/100.0f; 1346 sRow[col] = row-2*col; 1347 } 1348 } 1349 1350 fOut = psImageShift(fOut, fImg, colShift, rowShift, NAN, PS_INTERPOLATE_FLAT); 1351 sOut = psImageShift(sOut, sImg, colShift, rowShift, -1, PS_INTERPOLATE_FLAT); 1352 1353 for(int row=0;row<rows;row++) { 1354 psF32* fRow = fOut->data.F32[row]; 1355 psS16* sRow = sOut->data.S16[row]; 1356 for (int col=0;col<cols;col++) { 1357 psF32 fValue = psImagePixelInterpolate(fImg,col+colShift, 1358 row+rowShift,NAN,PS_INTERPOLATE_FLAT); 1359 psS16 sValue = (psS16)psImagePixelInterpolate(sImg,col+colShift, 1360 row+rowShift,-1,PS_INTERPOLATE_FLAT); 1361 1362 if (fabsf(fRow[col] - fValue) > FLT_EPSILON) { 1363 psError(__func__,"Float image not shifted correctly at %d,%d (%g vs %g)", 1364 col,row,fRow[col],fValue); 1365 return 1; 1366 } 1367 if (sRow[col] != sValue) { 1368 psError(__func__,"Short image not shifted correctly at %d,%d (%d vs %d)", 1369 col,row,sRow[col],sValue); 1370 return 2; 1371 } 1372 } 1373 } 1374 1375 psFree(fImg); 1376 psFree(sImg); 1377 psFree(fOut); 1378 psFree(sOut); 1379 1380 return 0; 1381 }
Note:
See TracChangeset
for help on using the changeset viewer.
