| 1 | /** @file tst_psImage.c
|
|---|
| 2 | *
|
|---|
| 3 | * @brief Contains the tests for psImage.[ch]
|
|---|
| 4 | *
|
|---|
| 5 | *
|
|---|
| 6 | * @author Robert DeSonia, MHPCC
|
|---|
| 7 | *
|
|---|
| 8 | * @version $Revision: 1.24 $ $Name: $
|
|---|
| 9 | * @date $Date: 2004/08/31 19:36:02 $
|
|---|
| 10 | *
|
|---|
| 11 | * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
|
|---|
| 12 | */
|
|---|
| 13 |
|
|---|
| 14 | #include <math.h>
|
|---|
| 15 | #include <float.h>
|
|---|
| 16 | #include <string.h>
|
|---|
| 17 | #include <stdlib.h>
|
|---|
| 18 |
|
|---|
| 19 | #include "psTest.h"
|
|---|
| 20 | #include "pslib.h"
|
|---|
| 21 | #include "psType.h"
|
|---|
| 22 |
|
|---|
| 23 | static int testImageAlloc(void);
|
|---|
| 24 | static int testImageSubset(void);
|
|---|
| 25 | static int testImageCopy(void);
|
|---|
| 26 |
|
|---|
| 27 | testDescription tests[] = {
|
|---|
| 28 | {
|
|---|
| 29 | testImageAlloc,546,"psImageAlloc",0,false
|
|---|
| 30 | },
|
|---|
| 31 | {
|
|---|
| 32 | testImageAlloc,548,"psImageFree",0,true
|
|---|
| 33 | },
|
|---|
| 34 | {
|
|---|
| 35 | testImageSubset,547,"psImageSubset",0,false
|
|---|
| 36 | },
|
|---|
| 37 | {
|
|---|
| 38 | testImageSubset,550,"psImageSubset",0,true
|
|---|
| 39 | },
|
|---|
| 40 | {
|
|---|
| 41 | testImageCopy,551,"psImageCopy",0,false
|
|---|
| 42 | },
|
|---|
| 43 | {
|
|---|
| 44 | NULL
|
|---|
| 45 | }
|
|---|
| 46 | };
|
|---|
| 47 |
|
|---|
| 48 | int main(int argc, char* argv[])
|
|---|
| 49 | {
|
|---|
| 50 | psLogSetLevel(PS_LOG_INFO);
|
|---|
| 51 |
|
|---|
| 52 | return ! runTestSuite(stderr,"psImage",tests,argc,argv);
|
|---|
| 53 | }
|
|---|
| 54 |
|
|---|
| 55 | int testImageAlloc(void)
|
|---|
| 56 | {
|
|---|
| 57 | psImage* image = NULL;
|
|---|
| 58 | unsigned int sizes = 6;
|
|---|
| 59 | unsigned int numCols[] = {
|
|---|
| 60 | 0,1,1,100,100,150
|
|---|
| 61 | };
|
|---|
| 62 | unsigned int numRows[] = {
|
|---|
| 63 | 0,1,100,1,150,100
|
|---|
| 64 | };
|
|---|
| 65 | unsigned int types = 13;
|
|---|
| 66 | psElemType type[] = { PS_TYPE_S8, PS_TYPE_S16, PS_TYPE_S32, PS_TYPE_S64,
|
|---|
| 67 | PS_TYPE_U8, PS_TYPE_U16, PS_TYPE_U32, PS_TYPE_U64,
|
|---|
| 68 | PS_TYPE_F32, PS_TYPE_F64, PS_TYPE_C32, PS_TYPE_C64,
|
|---|
| 69 | PS_TYPE_PTR };
|
|---|
| 70 |
|
|---|
| 71 | psLogMsg(__func__,PS_LOG_INFO,"#546 - psImageAlloc shall allocate memory for a psImage structure");
|
|---|
| 72 |
|
|---|
| 73 | for (unsigned int t=0;t<types;t++) {
|
|---|
| 74 | psLogMsg(__func__,PS_LOG_INFO,"Testing psImage with type %xh",type[t]);
|
|---|
| 75 |
|
|---|
| 76 | for (unsigned int i=0;i<sizes;i++) {
|
|---|
| 77 |
|
|---|
| 78 | if (numRows[i] == 0 || numCols[i] == 0) {
|
|---|
| 79 | psLogMsg(__func__,PS_LOG_INFO,"Following should be an error.");
|
|---|
| 80 | }
|
|---|
| 81 |
|
|---|
| 82 | image = psImageAlloc(numCols[i],numRows[i],type[t]);
|
|---|
| 83 |
|
|---|
| 84 | if (image == NULL) {
|
|---|
| 85 | if (numRows[i] == 0 || numCols[i] == 0) {
|
|---|
| 86 | continue;
|
|---|
| 87 | }
|
|---|
| 88 | psError(__func__,"psImageAlloc returned NULL for type %x, size %dx%d.",
|
|---|
| 89 | type[t], numCols[i], numRows[i]);
|
|---|
| 90 | psFree(image);
|
|---|
| 91 | return 1;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | if (image->type.dimen != PS_DIMEN_IMAGE || image->type.type != type[t]) {
|
|---|
| 95 | psError(__func__,"psImageAlloc allocated wrong dimen/type (%d/%d), should be "
|
|---|
| 96 | "PS_IMAGE_DIMEN/%d", image->type.dimen, image->type.type, type[t]);
|
|---|
| 97 | psFree(image);
|
|---|
| 98 | return 2;
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | if (image->numCols != numCols[i] || image->numRows != numRows[i]) {
|
|---|
| 102 | psError(__func__,"psImageAlloc allocated wrong size %dx%d, should be %dx%d (type = %d)",
|
|---|
| 103 | image->numCols, image->numRows, numCols[i], numRows[i],type[t]);
|
|---|
| 104 | psFree(image);
|
|---|
| 105 | return 3;
|
|---|
| 106 | }
|
|---|
| 107 |
|
|---|
| 108 | if (image->col0 != 0 || image->row0 != 0) {
|
|---|
| 109 | psError(__func__,"psImageAlloc returned row0/col0 of %d/%d. Should be 0/0.",
|
|---|
| 110 | image->row0, image->row0);
|
|---|
| 111 | psFree(image);
|
|---|
| 112 | return 4;
|
|---|
| 113 | }
|
|---|
| 114 |
|
|---|
| 115 | if (image->parent != NULL) {
|
|---|
| 116 | psError(__func__,"psImageAlloc returned non-NULL parent");
|
|---|
| 117 | psFree(image);
|
|---|
| 118 | return 5;
|
|---|
| 119 | }
|
|---|
| 120 |
|
|---|
| 121 | if (image->nChildren != 0) {
|
|---|
| 122 | psError(__func__,"psImageAlloc returned non-zero number of children");
|
|---|
| 123 | psFree(image);
|
|---|
| 124 | return 6;
|
|---|
| 125 | }
|
|---|
| 126 |
|
|---|
| 127 | if (image->children != NULL) {
|
|---|
| 128 | psError(__func__,"psImageAlloc returned non-NULL children vector");
|
|---|
| 129 | psFree(image);
|
|---|
| 130 | return 7;
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | switch (type[t]) {
|
|---|
| 134 | case PS_TYPE_U16: {
|
|---|
| 135 | unsigned int rows = numRows[i];
|
|---|
| 136 | unsigned int cols = numCols[i];
|
|---|
| 137 |
|
|---|
| 138 | for (int r=0;r<rows;r++) {
|
|---|
| 139 | for (int c=0;c<cols;c++) {
|
|---|
| 140 | image->data.U16[r][c] = 2*c+r;
|
|---|
| 141 | }
|
|---|
| 142 | }
|
|---|
| 143 | for (int r=0;r<rows;r++) {
|
|---|
| 144 | for (int c=0;c<cols;c++) {
|
|---|
| 145 | if (image->data.U16[r][c] != 2*c+r) {
|
|---|
| 146 | psError(__func__,"Could not set all pixels in uint16 image at (%d,%d)",c,r);
|
|---|
| 147 | psFree(image);
|
|---|
| 148 | return 8;
|
|---|
| 149 | }
|
|---|
| 150 | }
|
|---|
| 151 | }
|
|---|
| 152 | }
|
|---|
| 153 | break;
|
|---|
| 154 | case PS_TYPE_F32: {
|
|---|
| 155 | unsigned int rows = numRows[i];
|
|---|
| 156 | unsigned int cols = numCols[i];
|
|---|
| 157 |
|
|---|
| 158 | for (int r=0;r<rows;r++) {
|
|---|
| 159 | for (int c=0;c<cols;c++) {
|
|---|
| 160 | image->data.F32[r][c] = 2.0f*c+r;
|
|---|
| 161 | }
|
|---|
| 162 | }
|
|---|
| 163 | for (int r=0;r<rows;r++) {
|
|---|
| 164 | for (int c=0;c<cols;c++) {
|
|---|
| 165 | if (fabsf(image->data.F32[r][c] - (2.0f*c+r)) > FLT_EPSILON) {
|
|---|
| 166 | psError(__func__,"Could not set all pixels in float image at (%d,%d)",c,r);
|
|---|
| 167 | psFree(image);
|
|---|
| 168 | return 8;
|
|---|
| 169 | }
|
|---|
| 170 | }
|
|---|
| 171 | }
|
|---|
| 172 | }
|
|---|
| 173 | break;
|
|---|
| 174 | case PS_TYPE_F64: {
|
|---|
| 175 | unsigned int rows = numRows[i];
|
|---|
| 176 | unsigned int cols = numCols[i];
|
|---|
| 177 |
|
|---|
| 178 | for (int r=0;r<rows;r++) {
|
|---|
| 179 | for (int c=0;c<cols;c++) {
|
|---|
| 180 | image->data.F64[r][c] = 2.0f*c+r;
|
|---|
| 181 | }
|
|---|
| 182 | }
|
|---|
| 183 | for (int r=0;r<rows;r++) {
|
|---|
| 184 | for (int c=0;c<cols;c++) {
|
|---|
| 185 | if (fabs(image->data.F64[r][c] - (2.0f*c+r)) > DBL_EPSILON) {
|
|---|
| 186 | psError(__func__,"Could not set all pixels in double image at (%d,%d)",c,r);
|
|---|
| 187 | psFree(image);
|
|---|
| 188 | return 8;
|
|---|
| 189 | }
|
|---|
| 190 | }
|
|---|
| 191 | }
|
|---|
| 192 | }
|
|---|
| 193 | break;
|
|---|
| 194 | case PS_TYPE_C32: {
|
|---|
| 195 | unsigned int rows = numRows[i];
|
|---|
| 196 | unsigned int cols = numCols[i];
|
|---|
| 197 |
|
|---|
| 198 | for (int r=0;r<rows;r++) {
|
|---|
| 199 | for (int c=0;c<cols;c++) {
|
|---|
| 200 | image->data.C32[r][c] = r + I * c;
|
|---|
| 201 | }
|
|---|
| 202 | }
|
|---|
| 203 | for (int r=0;r<rows;r++) {
|
|---|
| 204 | for (int c=0;c<cols;c++) {
|
|---|
| 205 | if (fabsf(crealf(image->data.C32[r][c]) - r) > FLT_EPSILON ||
|
|---|
| 206 | fabsf(cimagf(image->data.C32[r][c]) - c) > FLT_EPSILON ) {
|
|---|
| 207 | psError(__func__,"Could not set all pixels in complex image at (%d,%d)",c,r);
|
|---|
| 208 | psFree(image);
|
|---|
| 209 | return 8;
|
|---|
| 210 | }
|
|---|
| 211 | }
|
|---|
| 212 | }
|
|---|
| 213 | }
|
|---|
| 214 | break;
|
|---|
| 215 | case PS_TYPE_PTR: {
|
|---|
| 216 | unsigned int rows = numRows[i];
|
|---|
| 217 | unsigned int cols = numCols[i];
|
|---|
| 218 | psImage* temp = psImageAlloc(1,1,PS_TYPE_F32);
|
|---|
| 219 |
|
|---|
| 220 | for (int r=0;r<rows;r++) {
|
|---|
| 221 | for (int c=0;c<cols;c++) {
|
|---|
| 222 | image->data.PTR[r][c] = psMemIncrRefCounter(temp);
|
|---|
| 223 | }
|
|---|
| 224 | }
|
|---|
| 225 | for (int r=0;r<rows;r++) {
|
|---|
| 226 | for (int c=0;c<cols;c++) {
|
|---|
| 227 | if (image->data.PTR[r][c] != temp) {
|
|---|
| 228 | psError(__func__, "Could not set pixel in pointer image at (%d,%d): %x %x",
|
|---|
| 229 | c,r,image->data.PTR[r][c],temp);
|
|---|
| 230 | psFree(image);
|
|---|
| 231 | psFree(temp);
|
|---|
| 232 | return 8;
|
|---|
| 233 | }
|
|---|
| 234 | }
|
|---|
| 235 | }
|
|---|
| 236 | psFree(temp);
|
|---|
| 237 | }
|
|---|
| 238 | break;
|
|---|
| 239 | default: {
|
|---|
| 240 | // ignore type and just use as byte bucket.
|
|---|
| 241 | unsigned int rows = numRows[i];
|
|---|
| 242 | unsigned int cols = numCols[i]*PSELEMTYPE_SIZEOF(type[t]);
|
|---|
| 243 |
|
|---|
| 244 | for (int r=0;r<rows;r++) {
|
|---|
| 245 | for (int c=0;c<cols;c++) {
|
|---|
| 246 | image->data.U8[r][c] = (uint8_t)(r + c);
|
|---|
| 247 | }
|
|---|
| 248 | }
|
|---|
| 249 | for (int r=0;r<rows;r++) {
|
|---|
| 250 | for (int c=0;c<cols;c++) {
|
|---|
| 251 | if (image->data.U8[r][c] != (uint8_t)(r + c)) {
|
|---|
| 252 | psError(__func__,"Could not set all pixels in image (type=%d) at (%d,%d)",
|
|---|
| 253 | type[t],c,r);
|
|---|
| 254 | psFree(image);
|
|---|
| 255 | return 8;
|
|---|
| 256 | }
|
|---|
| 257 | }
|
|---|
| 258 | }
|
|---|
| 259 | }
|
|---|
| 260 | }
|
|---|
| 261 |
|
|---|
| 262 | // #548: Verify no memory leaks or corruption are detected after a valid psImage structure with no
|
|---|
| 263 | // children is freed.
|
|---|
| 264 | psFree(image);
|
|---|
| 265 | }
|
|---|
| 266 | }
|
|---|
| 267 |
|
|---|
| 268 | // #548: Verify program execution doesn't stop, if the input psImage structure pointer is null.
|
|---|
| 269 | psFree(NULL);
|
|---|
| 270 |
|
|---|
| 271 | // #548: Verify no memory leaks or corruption are detected after a valid psImage structure with multiple
|
|---|
| 272 | // children isfreed.
|
|---|
| 273 | image = psImageAlloc(100,100,PS_TYPE_F32);
|
|---|
| 274 | psImageSubset(image,50,50,0,0);
|
|---|
| 275 | psImageSubset(image,50,50,20,20);
|
|---|
| 276 |
|
|---|
| 277 | psFree(image);
|
|---|
| 278 |
|
|---|
| 279 | return 0;
|
|---|
| 280 | }
|
|---|
| 281 |
|
|---|
| 282 | // #547: psImageSubset shall create child image of a specified size from a parent psImage structure
|
|---|
| 283 | int testImageSubset(void)
|
|---|
| 284 | {
|
|---|
| 285 | psImage preSubsetStruct;
|
|---|
| 286 | psImage* original;
|
|---|
| 287 | psImage* subset1 = NULL;
|
|---|
| 288 | psImage* subset2 = NULL;
|
|---|
| 289 | psImage* subset3 = NULL;
|
|---|
| 290 | int c = 128;
|
|---|
| 291 | int r = 256;
|
|---|
| 292 |
|
|---|
| 293 | original = psImageAlloc(c,r,PS_TYPE_U32);
|
|---|
| 294 | for (int row=0;row<r;row++) {
|
|---|
| 295 | for (int col=0;col<c;col++) {
|
|---|
| 296 | original->data.F32[row][col] = row*1000+col;
|
|---|
| 297 | }
|
|---|
| 298 | }
|
|---|
| 299 |
|
|---|
| 300 | memcpy(&preSubsetStruct,original,sizeof(psImage));
|
|---|
| 301 |
|
|---|
| 302 | subset2 = psImageSubset(original,c/2,r/2,c/4,r/4);
|
|---|
| 303 |
|
|---|
| 304 | subset3 = psImageSubset(original,c/2,r/2,0,0);
|
|---|
| 305 |
|
|---|
| 306 | psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure contains expected values in the "
|
|---|
| 307 | "row member, if the input psImage structure image contains known values.");
|
|---|
| 308 |
|
|---|
| 309 | for (int row=0;row<r/2;row++) {
|
|---|
| 310 | for (int col=0;col<c/2;col++) {
|
|---|
| 311 | if (subset2->data.U32[row][col] != original->data.U32[row+r/4][col+c/4]) {
|
|---|
| 312 | psError(__func__,"psImageSubset output #1 was wrong at %dx%d (%d vs %d).",
|
|---|
| 313 | row,col,subset2->data.U32[row][col], original->data.U32[row+r/4][col+c/4]);
|
|---|
| 314 | return 3;
|
|---|
| 315 | }
|
|---|
| 316 | if (subset3->data.U32[row][col] != original->data.U32[row][col]) {
|
|---|
| 317 | psError(__func__,"psImageSubset output #1 was wrong at %dx%d (%d vs %d).",
|
|---|
| 318 | row,col,subset2->data.U32[row][col], original->data.U32[row][col]);
|
|---|
| 319 | return 4;
|
|---|
| 320 | }
|
|---|
| 321 | }
|
|---|
| 322 | }
|
|---|
| 323 |
|
|---|
| 324 | psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure members nrow and ncol are equal to "
|
|---|
| 325 | "the input parameter nrow and ncol respectively.");
|
|---|
| 326 |
|
|---|
| 327 | if (subset3->numCols != c/2 || subset3->numRows != r/2) {
|
|---|
| 328 | psError(__func__,"psImageSubset output size was not proper(%dx%d, should be %dx%d).",
|
|---|
| 329 | subset3->numCols, subset3->numRows, c/2,r/2);
|
|---|
| 330 | return 5;
|
|---|
| 331 | }
|
|---|
| 332 |
|
|---|
| 333 | psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure member type is equal to the input "
|
|---|
| 334 | "psImage structure member type.");
|
|---|
| 335 |
|
|---|
| 336 | if (subset2->type.type != PS_TYPE_U32) {
|
|---|
| 337 | psError(__func__,"psImageSubset output type was not proper(%d, should be %d).",
|
|---|
| 338 | subset2->type.type, PS_TYPE_U32);
|
|---|
| 339 | return 6;
|
|---|
| 340 | }
|
|---|
| 341 | if (subset3->type.type != PS_TYPE_U32) {
|
|---|
| 342 | psError(__func__,"psImageSubset output type was not proper(%d, should be %d).",
|
|---|
| 343 | subset3->type.type, PS_TYPE_U32);
|
|---|
| 344 | return 7;
|
|---|
| 345 | }
|
|---|
| 346 |
|
|---|
| 347 | psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure members row0 and col0 are equal to "
|
|---|
| 348 | "the input parameters row0 and col0 respectively.");
|
|---|
| 349 |
|
|---|
| 350 | if (subset2->col0 != c/4 || subset2->row0 != r/4) {
|
|---|
| 351 | psError(__func__,"psImageSubset didn't set col0/row0 for subset2 (%d/%d, should be %d/%d).",
|
|---|
| 352 | subset2->col0,subset2->row0,c/4,r/4);
|
|---|
| 353 | return 8;
|
|---|
| 354 | }
|
|---|
| 355 | if (subset3->col0 != 0 || subset3->row0 != 0) {
|
|---|
| 356 | psError(__func__,"psImageSubset didn't set col0/row0 for subset3 (%d/%d, should be %d/%d).",
|
|---|
| 357 | subset3->col0,subset3->row0,0,0);
|
|---|
| 358 | return 9;
|
|---|
| 359 | }
|
|---|
| 360 |
|
|---|
| 361 | psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure member parent is equal to the "
|
|---|
| 362 | "input psImage structure pointer image.");
|
|---|
| 363 |
|
|---|
| 364 | if (subset2->parent != original || subset3->parent != original) {
|
|---|
| 365 | psError(__func__,"psImageSubset didn't set parent.");
|
|---|
| 366 | return 10;
|
|---|
| 367 | }
|
|---|
| 368 |
|
|---|
| 369 | psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure member Nchildren is equal to "
|
|---|
| 370 | "zero.");
|
|---|
| 371 |
|
|---|
| 372 | if (subset2->nChildren != 0 || subset3->nChildren != 0) {
|
|---|
| 373 | psError(__func__,"psImageSubset didn't set nChildren to zero.");
|
|---|
| 374 | return 11;
|
|---|
| 375 | }
|
|---|
| 376 |
|
|---|
| 377 | psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure member children is null.");
|
|---|
| 378 |
|
|---|
| 379 | if (subset2->children != NULL || subset3->children != NULL) {
|
|---|
| 380 | psError(__func__,"psImageSubset didn't set children to NULL.");
|
|---|
| 381 | return 11;
|
|---|
| 382 | }
|
|---|
| 383 |
|
|---|
| 384 | psLogMsg(__func__,PS_LOG_INFO,"Verify the input psImage structure image only has the following members "
|
|---|
| 385 | "changed: 1) Nchildren is increased by one. 2) parent contains pointer psImage structure "
|
|---|
| 386 | "out at parent[Nchildren-1].");
|
|---|
| 387 |
|
|---|
| 388 | if (original->nChildren != preSubsetStruct.nChildren+2) {
|
|---|
| 389 | psError(__func__,"psImageSubset didn't increment nChildren by one per subset.");
|
|---|
| 390 | return 12;
|
|---|
| 391 | }
|
|---|
| 392 | if (original->children[0] != subset2 || original->children[1] != subset3) {
|
|---|
| 393 | psError(__func__,"psImageSubset didn't properly store the children pointers.");
|
|---|
| 394 | return 13;
|
|---|
| 395 | }
|
|---|
| 396 |
|
|---|
| 397 | psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure pointer is null and program "
|
|---|
| 398 | "execution doesn't stop, if the input parameter image is null. Also verified the input "
|
|---|
| 399 | "psImage structure is not modified.");
|
|---|
| 400 |
|
|---|
| 401 | psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
|
|---|
| 402 | subset1 = psImageSubset(NULL,c/2,r/2,0,0);
|
|---|
| 403 | if (subset1 != NULL) {
|
|---|
| 404 | psError(__func__,"psImageSubset didn't return NULL when input image was NULL.");
|
|---|
| 405 | return 14;
|
|---|
| 406 | }
|
|---|
| 407 |
|
|---|
| 408 | psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure pointer is null and program "
|
|---|
| 409 | " execution doesn't stop, if the input parameters nrow and/or ncol are zero. Also verify "
|
|---|
| 410 | "input psImage structure is not modified.");
|
|---|
| 411 |
|
|---|
| 412 | memcpy(&preSubsetStruct,original,sizeof(psImage));
|
|---|
| 413 | psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
|
|---|
| 414 | subset1 = psImageSubset(original,c/2,0,0,0);
|
|---|
| 415 | if (subset1 != NULL) {
|
|---|
| 416 | psError(__func__,"psImageSubset didn't return NULL when numRows=0.");
|
|---|
| 417 | return 15;
|
|---|
| 418 | }
|
|---|
| 419 | psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
|
|---|
| 420 | subset1 = psImageSubset(original,0,r/2,0,0);
|
|---|
| 421 | if (subset1 != NULL) {
|
|---|
| 422 | psError(__func__,"psImageSubset didn't return NULL when numCols=0.");
|
|---|
| 423 | return 16;
|
|---|
| 424 | }
|
|---|
| 425 | if (memcmp(original,&preSubsetStruct,sizeof(psImage)) != 0) {
|
|---|
| 426 | psError(__func__,"psImageSubset changed the original struct though it failed to subset.");
|
|---|
| 427 | return 17;
|
|---|
| 428 | }
|
|---|
| 429 |
|
|---|
| 430 |
|
|---|
| 431 | psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure pointer is null and program "
|
|---|
| 432 | "execution doesn't stop, if the input parameters row0 and col0 are not within the range of "
|
|---|
| 433 | "values of psImage structure image.");
|
|---|
| 434 |
|
|---|
| 435 | psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
|
|---|
| 436 | subset1 = psImageSubset(original,c/2,r/2,c,0);
|
|---|
| 437 | if (subset1 != NULL) {
|
|---|
| 438 | psError(__func__,"psImageSubset didn't return NULL when subset origin was outside of "
|
|---|
| 439 | "image (via cols).");
|
|---|
| 440 | return 18;
|
|---|
| 441 | }
|
|---|
| 442 | psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
|
|---|
| 443 | subset1 = psImageSubset(original,c/2,r/2,0,r);
|
|---|
| 444 | if (subset1 != NULL) {
|
|---|
| 445 | psError(__func__,"psImageSubset didn't return NULL when subset origin was outside of "
|
|---|
| 446 | "image (via rows).");
|
|---|
| 447 | return 19;
|
|---|
| 448 | }
|
|---|
| 449 | psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
|
|---|
| 450 | subset1 = psImageSubset(original,c/2,r/2,-1,0);
|
|---|
| 451 | if (subset1 != NULL) {
|
|---|
| 452 | psError(__func__,"psImageSubset didn't return NULL when subset origin was outside of "
|
|---|
| 453 | "image (col0=-1).");
|
|---|
| 454 | return 20;
|
|---|
| 455 | }
|
|---|
| 456 | psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
|
|---|
| 457 | subset1 = psImageSubset(original,c/2,r/2,0,-1);
|
|---|
| 458 | if (subset1 != NULL) {
|
|---|
| 459 | psError(__func__,"psImageSubset didn't return NULL when subset origin was outside of "
|
|---|
| 460 | "image (row0=-1).");
|
|---|
| 461 | return 21;
|
|---|
| 462 | }
|
|---|
| 463 |
|
|---|
| 464 | psLogMsg(__func__,PS_LOG_INFO,"Verify the returned psImage structure pointer is null and program "
|
|---|
| 465 | "execution doesn't stop if the input parameters nrow, ncol, row0 and col0 specify a range of "
|
|---|
| 466 | "data not within the input psImage structure image. Also verify the input psImage structure "
|
|---|
| 467 | "is not modified.");
|
|---|
| 468 |
|
|---|
| 469 | psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
|
|---|
| 470 | subset1 = psImageSubset(original,c/2,r/2,c/2,0);
|
|---|
| 471 | if (subset1 != NULL) {
|
|---|
| 472 | psError(__func__,"psImageSubset didn't return NULL when subset was outside of image (via rows).");
|
|---|
| 473 | return 22;
|
|---|
| 474 | }
|
|---|
| 475 | psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
|
|---|
| 476 | subset1 = psImageSubset(original,c/2,r/2,0,r/2);
|
|---|
| 477 | if (subset1 != NULL) {
|
|---|
| 478 | psError(__func__,"psImageSubset didn't return NULL when subset was outside of image (via cols).");
|
|---|
| 479 | return 23;
|
|---|
| 480 | }
|
|---|
| 481 | psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
|
|---|
| 482 | subset1 = psImageSubset(original,c/2,r/2,c/2,r/2);
|
|---|
| 483 | if (subset1 != NULL) {
|
|---|
| 484 | psError(__func__,"psImageSubset didn't return NULL when subset was outside of image (via row+cols).");
|
|---|
| 485 | return 24;
|
|---|
| 486 | }
|
|---|
| 487 |
|
|---|
| 488 | psLogMsg(__func__, PS_LOG_INFO, "psImageFreeChildren shall deallocate any children images of a "
|
|---|
| 489 | "psImage structure");
|
|---|
| 490 |
|
|---|
| 491 | memcpy(&preSubsetStruct,original,sizeof(psImage));
|
|---|
| 492 |
|
|---|
| 493 | psImageFreeChildren(original);
|
|---|
| 494 |
|
|---|
| 495 | // Verify the returned psImage structure member Nchildren is set to zero.
|
|---|
| 496 | if (original->nChildren != 0) {
|
|---|
| 497 | psError(__func__,"psImageFreeChildren didn't set nChildren to zero.");
|
|---|
| 498 | return 25;
|
|---|
| 499 | }
|
|---|
| 500 |
|
|---|
| 501 | // Verify the returned psImage structure member children pointer is set to null.
|
|---|
| 502 | if (original->children != NULL) {
|
|---|
| 503 | psError(__func__,"psImageFreeChildren didn't set children ptr to NULL.");
|
|---|
| 504 | return 26;
|
|---|
| 505 | }
|
|---|
| 506 |
|
|---|
| 507 | //Verify the returned psImage structure members type, nrow, ncol, row0, col0, rows and parent are not
|
|---|
| 508 | // modified.
|
|---|
| 509 | if (preSubsetStruct.numRows != original->numRows ||
|
|---|
| 510 | preSubsetStruct.numCols != original->numCols ||
|
|---|
| 511 | preSubsetStruct.row0 != original->row0 ||
|
|---|
| 512 | preSubsetStruct.col0 != original->col0) {
|
|---|
| 513 |
|
|---|
| 514 | psError(__func__,"psImageFreeChildren modified parent's non-children elements.");
|
|---|
| 515 | return 27;
|
|---|
| 516 | }
|
|---|
| 517 |
|
|---|
| 518 | psFree(original);
|
|---|
| 519 |
|
|---|
| 520 | return 0;
|
|---|
| 521 | }
|
|---|
| 522 |
|
|---|
| 523 | int testImageCopy(void)
|
|---|
| 524 | {
|
|---|
| 525 | psImage* img = NULL;
|
|---|
| 526 | psImage* img2 = NULL;
|
|---|
| 527 | psImage* img3 = NULL;
|
|---|
| 528 | unsigned int c = 128;
|
|---|
| 529 | unsigned int r = 256;
|
|---|
| 530 |
|
|---|
| 531 | img = psImageAlloc(c,r,PS_TYPE_F32);
|
|---|
| 532 | for (unsigned row=0;row<r;row++) {
|
|---|
| 533 | psF32* imgRow = img->data.F32[row];
|
|---|
| 534 | for (unsigned col=0;col<c;col++) {
|
|---|
| 535 | imgRow[col] = (psF32)(row+col);
|
|---|
| 536 | }
|
|---|
| 537 | }
|
|---|
| 538 | img2 = psImageAlloc(c,r,PS_TYPE_F32);
|
|---|
| 539 | for (unsigned row=0;row<r;row++) {
|
|---|
| 540 | psF32* img2Row = img2->data.F32[row];
|
|---|
| 541 | for (unsigned col=0;col<c;col++) {
|
|---|
| 542 | img2Row[col] = 0.0f;
|
|---|
| 543 | }
|
|---|
| 544 | }
|
|---|
| 545 |
|
|---|
| 546 | img3 = psImageCopy(img2,img,PS_TYPE_F32);
|
|---|
| 547 |
|
|---|
| 548 | // Verify the returned psImage structure pointer is equal to the input parameter output.
|
|---|
| 549 | if (img2 != img3) {
|
|---|
| 550 | psError(__func__,"the image given for recycled wasn't");
|
|---|
| 551 | return 1;
|
|---|
| 552 | }
|
|---|
| 553 |
|
|---|
| 554 | // Verify the returned psImage structure member are equal to the values in
|
|---|
| 555 | // the input psImage structure input.
|
|---|
| 556 |
|
|---|
| 557 | #define testImageCopyType(IN,OUT) \
|
|---|
| 558 | img = psImageRecycle(img,c,r,PS_TYPE_##IN); \
|
|---|
| 559 | for (unsigned row=0;row<r;row++) { \
|
|---|
| 560 | ps##IN* imgRow = img->data.IN[row]; \
|
|---|
| 561 | for (unsigned col=0;col<c;col++) { \
|
|---|
| 562 | imgRow[col] = (ps##IN)(row+col); \
|
|---|
| 563 | } \
|
|---|
| 564 | } \
|
|---|
| 565 | img2 = psImageCopy(img2,img,PS_TYPE_##OUT); \
|
|---|
| 566 | if (img2 == NULL) { \
|
|---|
| 567 | psError(__func__,"psImageCopy failed to copy U8."); \
|
|---|
| 568 | return 2; \
|
|---|
| 569 | } \
|
|---|
| 570 | for (unsigned int row=0;row<r;row++) { \
|
|---|
| 571 | ps##IN* imgRow = img->data.IN[row]; \
|
|---|
| 572 | ps##OUT* img2Row = img2->data.OUT[row]; \
|
|---|
| 573 | for (unsigned int col=0;col<c;col++) { \
|
|---|
| 574 | if (abs(imgRow[col] - (ps##IN)(row+col)) > 0.5) { \
|
|---|
| 575 | psError(__func__,"Input image was changed at %d,%d!", \
|
|---|
| 576 | col,row); \
|
|---|
| 577 | return 2; \
|
|---|
| 578 | } \
|
|---|
| 579 | if (abs(img2Row[col] - (ps##OUT)(imgRow[col])) > 0.5) { \
|
|---|
| 580 | psError(__func__,"returned psImage values after copy don't match at %d,%d " \
|
|---|
| 581 | "(%d vs %d)",\
|
|---|
| 582 | col,row,img2Row[col], (ps##OUT)(imgRow[col])); \
|
|---|
| 583 | return 2; \
|
|---|
| 584 | } \
|
|---|
| 585 | } \
|
|---|
| 586 | }
|
|---|
| 587 |
|
|---|
| 588 | #define testImageCopyTypes(IN) \
|
|---|
| 589 | printf("to psF32\n"); \
|
|---|
| 590 | testImageCopyType(IN,F32);\
|
|---|
| 591 | printf("to psF64\n"); \
|
|---|
| 592 | testImageCopyType(IN,F64); \
|
|---|
| 593 | printf("to psU8\n"); \
|
|---|
| 594 | testImageCopyType(IN,U8); \
|
|---|
| 595 | printf("to psU16\n"); \
|
|---|
| 596 | testImageCopyType(IN,U16); \
|
|---|
| 597 | printf("to psU32\n"); \
|
|---|
| 598 | testImageCopyType(IN,U32); \
|
|---|
| 599 | printf("to psS8\n"); \
|
|---|
| 600 | testImageCopyType(IN,S8);\
|
|---|
| 601 | printf("to psS16\n"); \
|
|---|
| 602 | testImageCopyType(IN,S16);\
|
|---|
| 603 | printf("to psS32\n"); \
|
|---|
| 604 | testImageCopyType(IN,S32);
|
|---|
| 605 |
|
|---|
| 606 | psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psU8");
|
|---|
| 607 | testImageCopyTypes(U8);
|
|---|
| 608 | psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psU16");
|
|---|
| 609 | testImageCopyTypes(U16);
|
|---|
| 610 | psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psU32");
|
|---|
| 611 | testImageCopyTypes(U32);
|
|---|
| 612 | psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psS8");
|
|---|
| 613 | testImageCopyTypes(S8);
|
|---|
| 614 | psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psS16");
|
|---|
| 615 | testImageCopyTypes(S16);
|
|---|
| 616 | psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psS32");
|
|---|
| 617 | testImageCopyTypes(S32);
|
|---|
| 618 | psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psF32");
|
|---|
| 619 | testImageCopyTypes(F32);
|
|---|
| 620 | psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psF64");
|
|---|
| 621 | testImageCopyTypes(F64);
|
|---|
| 622 |
|
|---|
| 623 | // Verify the returned psImage structure pointer is null and program
|
|---|
| 624 | // execution doesn't stop, if the input parameter input is null.
|
|---|
| 625 | psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
|
|---|
| 626 | img3 = psImageCopy(NULL,NULL,PS_TYPE_F32);
|
|---|
| 627 | if (img3 != NULL) {
|
|---|
| 628 | psError(__func__,"psImageCopy didn't return NULL when input image was NULL.");
|
|---|
| 629 | return 3;
|
|---|
| 630 | }
|
|---|
| 631 |
|
|---|
| 632 | psFree(img);
|
|---|
| 633 | psFree(img2);
|
|---|
| 634 |
|
|---|
| 635 | return 0;
|
|---|
| 636 | }
|
|---|
| 637 |
|
|---|