Changeset 17330
- Timestamp:
- Apr 4, 2008, 4:46:25 PM (18 years ago)
- File:
-
- 1 edited
-
trunk/psLib/test/imageops/tap_psImageConvolve2.c (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/psLib/test/imageops/tap_psImageConvolve2.c
r17320 r17330 8 8 #define KERNEL_SIZE 3 9 9 #define TOL 1.0e-6 10 #define MASK_INITIAL 0x0f 11 #define MASK_FINAL 0xf0 10 12 11 13 … … 17 19 image->data.F32[IMAGE_SIZE/2][IMAGE_SIZE/2] = 1.0; 18 20 return image; 21 } 22 23 // Generate mask with single pixel set 24 static psImage *generateMask(void) 25 { 26 psImage *mask = psImageAlloc(IMAGE_SIZE, IMAGE_SIZE, PS_TYPE_MASK); 27 psImageInit(mask, 0); 28 mask->data.PS_TYPE_MASK_DATA[IMAGE_SIZE/2][IMAGE_SIZE/2] = MASK_INITIAL; 29 return mask; 19 30 } 20 31 … … 58 69 } 59 70 71 // Check the convolved mask matches the kernel 72 static bool checkConvolvedMask(const psImage *mask) 73 { 74 bool correct = true; 75 for (int y = 0; y < IMAGE_SIZE; y++) { 76 for (int x = 0; x < IMAGE_SIZE; x++) { 77 if (x < IMAGE_SIZE/2 - KERNEL_SIZE || x > IMAGE_SIZE/2 + KERNEL_SIZE || 78 y < IMAGE_SIZE/2 - KERNEL_SIZE || y > IMAGE_SIZE/2 + KERNEL_SIZE) { 79 if (mask->data.PS_TYPE_MASK_DATA[y][x] != 0) { 80 diag("%d,%d --> %d", x, y, mask->data.PS_TYPE_MASK_DATA[y][x]); 81 correct = false; 82 } 83 } else if (x == IMAGE_SIZE/2 && y == IMAGE_SIZE/2) { 84 if (mask->data.PS_TYPE_MASK_DATA[y][x] != (MASK_INITIAL | MASK_FINAL)) { 85 diag("%d,%d --> %d", x, y, mask->data.PS_TYPE_MASK_DATA[y][x]); 86 correct = false; 87 } 88 } else if (mask->data.PS_TYPE_MASK_DATA[y][x] != MASK_FINAL) { 89 diag("%d,%d --> %d", x, y, mask->data.PS_TYPE_MASK_DATA[y][x]); 90 correct = false; 91 } 92 } 93 } 94 return correct; 95 } 96 60 97 61 98 int main(int argc, char *argv[]) 62 99 { 63 plan_tests(1 0);100 plan_tests(15); 64 101 65 102 diag("psImageConvolve tests"); … … 111 148 } 112 149 150 { 151 // FFT mask convolution: 5 tests 152 psMemId id = psMemGetId(); 153 154 psImage *mask = generateMask(); 155 156 psImage *convolved = psImageConvolveMaskFFT(NULL, mask, MASK_INITIAL, MASK_FINAL, 157 -KERNEL_SIZE, KERNEL_SIZE, -KERNEL_SIZE, KERNEL_SIZE, 158 0.5); 159 ok(convolved, "convolution result"); 160 skip_start(!convolved, 3, "convolution failed"); 161 ok(convolved->type.type == PS_TYPE_MASK, "output type"); 162 ok(convolved->numCols == IMAGE_SIZE && convolved->numRows == IMAGE_SIZE, "output size %dx%d", 163 convolved->numCols, convolved->numRows); 164 ok(checkConvolvedMask(convolved), "convolved mask correct"); 165 psFree(convolved); 166 skip_end(); 167 168 psFree(mask); 169 170 ok(!psMemCheckLeaks(id, NULL, NULL, false), "no memory leaks"); 171 } 172 113 173 114 174 return exit_status();
Note:
See TracChangeset
for help on using the changeset viewer.
