Mercurial > sdl-ios-xcode
comparison test/automated/surface/surface.c @ 3721:9bb7758a9741 gsoc2009_unit_tests
Doing individual blend mode testing when blitting.
author | Edgar Simo <bobbens@gmail.com> |
---|---|
date | Thu, 09 Jul 2009 10:36:09 +0000 |
parents | 09bbf9dc41ed |
children | d8772964e402 |
comparison
equal
deleted
inserted
replaced
3720:09bbf9dc41ed | 3721:9bb7758a9741 |
---|---|
37 */ | 37 */ |
38 #include "primitives.c" | 38 #include "primitives.c" |
39 #include "blend.c" | 39 #include "blend.c" |
40 #include "face.c" | 40 #include "face.c" |
41 #include "blit.c" | 41 #include "blit.c" |
42 #include "blitblend.c" | |
42 | 43 |
43 | 44 |
44 /** | 45 /** |
45 * @brief Compares a surface and a surface image for equality. | 46 * @brief Compares a surface and a surface image for equality. |
46 * | 47 * |
421 SDL_ATend(); | 422 SDL_ATend(); |
422 } | 423 } |
423 | 424 |
424 | 425 |
425 /** | 426 /** |
427 * @brief Tests a blend mode. | |
428 */ | |
429 static int surface_testBlitBlendMode( SDL_Surface *testsur, SDL_Surface *face, int mode ) | |
430 { | |
431 int ret; | |
432 int i, j, ni, nj; | |
433 SDL_Rect rect; | |
434 | |
435 /* Clear surface. */ | |
436 ret = SDL_FillRect( testsur, NULL, | |
437 SDL_MapRGB( testsur->format, 0, 0, 0 ) ); | |
438 if (SDL_ATassert( "SDL_FillRect", ret == 0)) | |
439 return 1; | |
440 | |
441 /* Steps to take. */ | |
442 ni = testsur->w - face->w; | |
443 nj = testsur->h - face->h; | |
444 | |
445 /* Constant values. */ | |
446 rect.w = face->w; | |
447 rect.h = face->h; | |
448 | |
449 /* Test blend mode. */ | |
450 for (j=0; j <= nj; j+=4) { | |
451 for (i=0; i <= ni; i+=4) { | |
452 /* Set blend mode. */ | |
453 ret = SDL_SetSurfaceBlendMode( face, mode ); | |
454 if (SDL_ATassert( "SDL_SetSurfaceBlendMode", ret == 0)) | |
455 return 1; | |
456 | |
457 /* Blitting. */ | |
458 rect.x = i; | |
459 rect.y = j; | |
460 ret = SDL_BlitSurface( face, NULL, testsur, &rect ); | |
461 if (SDL_ATassert( "SDL_BlitSurface", ret == 0)) | |
462 return 1; | |
463 } | |
464 } | |
465 | |
466 return 0; | |
467 } | |
468 | |
469 | |
470 /** | |
426 * @brief Tests some more blitting routines. | 471 * @brief Tests some more blitting routines. |
427 */ | 472 */ |
428 static void surface_testBlitBlend (void) | 473 static void surface_testBlitBlend (void) |
429 { | 474 { |
430 int ret; | 475 int ret; |
446 testsur = SDL_CreateRGBSurface( 0, 80, 60, 32, | 491 testsur = SDL_CreateRGBSurface( 0, 80, 60, 32, |
447 RMASK, GMASK, BMASK, AMASK ); | 492 RMASK, GMASK, BMASK, AMASK ); |
448 if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL)) | 493 if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL)) |
449 return; | 494 return; |
450 | 495 |
451 /* Steps to take. */ | 496 /* Set alpha mod. */ |
452 ni = 40; | 497 ret = SDL_SetSurfaceAlphaMod( face, 100 ); |
453 nj = 30; | 498 if (SDL_ATassert( "SDL_SetSurfaceAlphaMod", ret == 0)) |
454 | 499 return; |
455 /* Constant values. */ | 500 |
456 rect.w = face->w; | 501 /* Test None. */ |
457 rect.h = face->h; | 502 if (surface_testBlitBlendMode( testsur, face, SDL_BLENDMODE_NONE )) |
458 | 503 return; |
459 /* Test blitting with colour mod. */ | 504 if (SDL_ATassert( "Blitting blending output not the same (using SDL_BLENDMODE_NONE).", |
460 for (j=0; j <= nj; j+=4) { | 505 surface_compare( testsur, &img_blendNone )==0 )) |
461 for (i=0; i <= ni; i+=4) { | 506 return; |
462 /* Set alpha mod. */ | 507 |
463 ret = SDL_SetSurfaceAlphaMod( face, (255/ni)*i ); | 508 /* Test Mask. */ |
464 if (SDL_ATassert( "SDL_SetSurfaceAlphaMod", ret == 0)) | 509 if (surface_testBlitBlendMode( testsur, face, SDL_BLENDMODE_MASK )) |
465 return; | 510 return; |
466 | 511 if (SDL_ATassert( "Blitting blending output not the same (using SDL_BLENDMODE_MASK).", |
467 /* Blitting. */ | 512 surface_compare( testsur, &img_blendMask )==0 )) |
468 rect.x = i; | 513 return; |
469 rect.y = j; | 514 |
470 ret = SDL_BlitSurface( face, NULL, testsur, &rect ); | 515 /* Test Blend. */ |
471 if (SDL_ATassert( "SDL_BlitSurface", ret == 0)) | 516 if (surface_testBlitBlendMode( testsur, face, SDL_BLENDMODE_BLEND )) |
472 return; | 517 return; |
473 } | 518 if (SDL_ATassert( "Blitting blending output not the same (using SDL_BLENDMODE_BLEND).", |
474 } | 519 surface_compare( testsur, &img_blendBlend )==0 )) |
475 | 520 return; |
476 SDL_SaveBMP( testsur, "testsur.bmp" ); | 521 |
522 /* Test Add. */ | |
523 if (surface_testBlitBlendMode( testsur, face, SDL_BLENDMODE_ADD )) | |
524 return; | |
525 if (SDL_ATassert( "Blitting blending output not the same (using SDL_BLENDMODE_ADD).", | |
526 surface_compare( testsur, &img_blendAdd )==0 )) | |
527 return; | |
528 | |
529 /* Test Mod. */ | |
530 if (surface_testBlitBlendMode( testsur, face, SDL_BLENDMODE_MOD )) | |
531 return; | |
532 if (SDL_ATassert( "Blitting blending output not the same (using SDL_BLENDMODE_MOD).", | |
533 surface_compare( testsur, &img_blendMod )==0 )) | |
534 return; | |
535 | |
536 /* Clear surface. */ | |
537 ret = SDL_FillRect( testsur, NULL, | |
538 SDL_MapRGB( testsur->format, 0, 0, 0 ) ); | |
539 if (SDL_ATassert( "SDL_FillRect", ret == 0)) | |
540 return; | |
477 | 541 |
478 /* Loop blit. */ | 542 /* Loop blit. */ |
479 for (j=0; j <= testsur->h - face->h; j+=4) { | 543 for (j=0; j <= testsur->h - face->h; j+=4) { |
480 for (i=0; i <= testsur->w - face->w; i+=4) { | 544 for (i=0; i <= testsur->w - face->w; i+=4) { |
481 | 545 |
531 | 595 |
532 surface_testLoad(); | 596 surface_testLoad(); |
533 surface_testPrimitives(); | 597 surface_testPrimitives(); |
534 surface_testPrimitivesBlend(); | 598 surface_testPrimitivesBlend(); |
535 surface_testBlit(); | 599 surface_testBlit(); |
536 /*surface_testBlitBlend();*/ | 600 surface_testBlitBlend(); |
537 | 601 |
538 /* Exit SDL. */ | 602 /* Exit SDL. */ |
539 SDL_Quit(); | 603 SDL_Quit(); |
540 | 604 |
541 return SDL_ATfinish(1); | 605 return SDL_ATfinish(1); |