comparison test/automated/surface/surface.c @ 3720:09bbf9dc41ed gsoc2009_unit_tests

Changed the surface blit test to test colour and alpha mod individually.
author Edgar Simo <bobbens@gmail.com>
date Thu, 09 Jul 2009 10:21:03 +0000
parents 15373e31daff
children 9bb7758a9741
comparison
equal deleted inserted replaced
3719:15373e31daff 3720:09bbf9dc41ed
70 for (i=0; i<sur->w; i++) { 70 for (i=0; i<sur->w; i++) {
71 p = (Uint8 *)sur->pixels + j * sur->pitch + i * bpp; 71 p = (Uint8 *)sur->pixels + j * sur->pitch + i * bpp;
72 pd = (Uint8 *)img->pixel_data + (j*img->width + i) * img->bytes_per_pixel; 72 pd = (Uint8 *)img->pixel_data + (j*img->width + i) * img->bytes_per_pixel;
73 switch (bpp) { 73 switch (bpp) {
74 case 1: 74 case 1:
75 /* Paletted not supported atm. */ 75 case 2:
76 case 3:
76 ret += 1; 77 ret += 1;
77 break; 78 printf("%d BPP not supported yet.\n",bpp);
78
79 case 2:
80 /* 16 BPP not supported atm. */
81 ret += 1;
82 break;
83
84 case 3:
85 /* 24 BPP not supported atm. */
86 ret += 1;
87 break; 79 break;
88 80
89 case 4: 81 case 4:
90 ret += !( (p[0] == pd[0]) && 82 ret += !( (p[0] == pd[0]) &&
91 (p[1] == pd[1]) && 83 (p[1] == pd[1]) &&
92 (p[2] == pd[2]) ); 84 (p[2] == pd[2]) );
93 break; 85 break;
94 } 86 }
95 } 87 }
96 } 88 }
97 89
98 SDL_UnlockSurface( sur ); 90 SDL_UnlockSurface( sur );
99 91
100 return ret; 92 return ret;
101 } 93 }
102 94
227 219
228 220
229 /** 221 /**
230 * @brief Tests the SDL primitives with alpha for rendering. 222 * @brief Tests the SDL primitives with alpha for rendering.
231 */ 223 */
232 static void surface_testPrimitivesAlpha (void) 224 static void surface_testPrimitivesBlend (void)
233 { 225 {
234 int ret; 226 int ret;
235 int i, j; 227 int i, j;
236 SDL_Rect rect; 228 SDL_Rect rect;
237 SDL_Surface *testsur; 229 SDL_Surface *testsur;
238 230
239 SDL_ATbegin( "Primitives Alpha Test" ); 231 SDL_ATbegin( "Primitives Blend Test" );
240 232
241 /* Create the surface. */ 233 /* Create the surface. */
242 testsur = SDL_CreateRGBSurface( 0, 80, 60, 32, 234 testsur = SDL_CreateRGBSurface( 0, 80, 60, 32,
243 RMASK, GMASK, BMASK, AMASK ); 235 RMASK, GMASK, BMASK, AMASK );
244 if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL)) 236 if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL))
321 SDL_Rect rect; 313 SDL_Rect rect;
322 SDL_Surface *face, *testsur; 314 SDL_Surface *face, *testsur;
323 int i, j, ni, nj; 315 int i, j, ni, nj;
324 int mode; 316 int mode;
325 317
326 SDL_ATbegin( "Blit Test" ); 318 SDL_ATbegin( "Blit Tests" );
327 319
328 /* Create face surface. */ 320 /* Create face surface. */
329 face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data, 321 face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data,
330 img_face.width, img_face.height, 32, img_face.width*4, 322 img_face.width, img_face.height, 32, img_face.width*4,
331 RMASK, GMASK, BMASK, AMASK ); 323 RMASK, GMASK, BMASK, AMASK );
336 testsur = SDL_CreateRGBSurface( 0, 80, 60, 32, 328 testsur = SDL_CreateRGBSurface( 0, 80, 60, 32,
337 RMASK, GMASK, BMASK, AMASK ); 329 RMASK, GMASK, BMASK, AMASK );
338 if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL)) 330 if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL))
339 return; 331 return;
340 332
341 /* Steps to take. */
342 ni = 40;
343 nj = 30;
344
345 /* Constant values. */ 333 /* Constant values. */
346 rect.w = face->w; 334 rect.w = face->w;
347 rect.h = face->h; 335 rect.h = face->h;
336 ni = testsur->w - face->w;
337 nj = testsur->h - face->h;
348 338
349 /* Loop blit. */ 339 /* Loop blit. */
350 for (j=0; j <= testsur->h - face->h; j+=4) { 340 for (j=0; j <= nj; j+=4) {
351 for (i=0; i <= testsur->w - face->w; i+=4) { 341 for (i=0; i <= ni; i+=4) {
352 /* Blitting. */ 342 /* Blitting. */
353 rect.x = i; 343 rect.x = i;
354 rect.y = j; 344 rect.y = j;
355 ret = SDL_BlitSurface( face, NULL, testsur, &rect ); 345 ret = SDL_BlitSurface( face, NULL, testsur, &rect );
356 if (SDL_ATassert( "SDL_BlitSurface", ret == 0)) 346 if (SDL_ATassert( "SDL_BlitSurface", ret == 0))
357 return; 347 return;
358 } 348 }
359 } 349 }
360 350
361 /* See if it's the same. */ 351 /* See if it's the same. */
362 if (SDL_ATassert( "Blitting output not the same.", 352 if (SDL_ATassert( "Blitting output not the same (normal blit).",
363 surface_compare( testsur, &img_blit )==0 )) 353 surface_compare( testsur, &img_blit )==0 ))
354 return;
355
356 /* Clear surface. */
357 ret = SDL_FillRect( testsur, NULL,
358 SDL_MapRGB( testsur->format, 0, 0, 0 ) );
359 if (SDL_ATassert( "SDL_FillRect", ret == 0))
360 return;
361
362 /* Test blitting with colour mod. */
363 for (j=0; j <= nj; j+=4) {
364 for (i=0; i <= ni; i+=4) {
365 /* Set colour mod. */
366 ret = SDL_SetSurfaceColorMod( face, (255/nj)*j, (255/ni)*i, (255/nj)*j );
367 if (SDL_ATassert( "SDL_SetSurfaceColorMod", ret == 0))
368 return;
369
370 /* Blitting. */
371 rect.x = i;
372 rect.y = j;
373 ret = SDL_BlitSurface( face, NULL, testsur, &rect );
374 if (SDL_ATassert( "SDL_BlitSurface", ret == 0))
375 return;
376 }
377 }
378
379 /* See if it's the same. */
380 if (SDL_ATassert( "Blitting output not the same (using SDL_SetSurfaceColorMod).",
381 surface_compare( testsur, &img_blitColour )==0 ))
382 return;
383
384 /* Clear surface. */
385 ret = SDL_FillRect( testsur, NULL,
386 SDL_MapRGB( testsur->format, 0, 0, 0 ) );
387 if (SDL_ATassert( "SDL_FillRect", ret == 0))
388 return;
389
390 /* Restore colour. */
391 ret = SDL_SetSurfaceColorMod( face, 255, 255, 255 );
392 if (SDL_ATassert( "SDL_SetSurfaceColorMod", ret == 0))
393 return;
394
395 /* Test blitting with colour mod. */
396 for (j=0; j <= nj; j+=4) {
397 for (i=0; i <= ni; i+=4) {
398 /* Set alpha mod. */
399 ret = SDL_SetSurfaceAlphaMod( face, (255/ni)*i );
400 if (SDL_ATassert( "SDL_SetSurfaceAlphaMod", ret == 0))
401 return;
402
403 /* Blitting. */
404 rect.x = i;
405 rect.y = j;
406 ret = SDL_BlitSurface( face, NULL, testsur, &rect );
407 if (SDL_ATassert( "SDL_BlitSurface", ret == 0))
408 return;
409 }
410 }
411
412 /* See if it's the same. */
413 if (SDL_ATassert( "Blitting output not the same (using SDL_SetSurfaceAlphaMod).",
414 surface_compare( testsur, &img_blitAlpha )==0 ))
364 return; 415 return;
365 416
366 /* Clean up. */ 417 /* Clean up. */
367 SDL_FreeSurface( face ); 418 SDL_FreeSurface( face );
368 SDL_FreeSurface( testsur ); 419 SDL_FreeSurface( testsur );
372 423
373 424
374 /** 425 /**
375 * @brief Tests some more blitting routines. 426 * @brief Tests some more blitting routines.
376 */ 427 */
377 static void surface_testBlitAlpha (void) 428 static void surface_testBlitBlend (void)
378 { 429 {
379 int ret; 430 int ret;
380 SDL_Rect rect; 431 SDL_Rect rect;
381 SDL_Surface *face, *testsur; 432 SDL_Surface *face, *testsur;
382 int i, j, ni, nj; 433 int i, j, ni, nj;
383 int mode; 434 int mode;
384 435
385 SDL_ATbegin( "Blit Alpha Test" ); 436 SDL_ATbegin( "Blit Blending Tests" );
386 437
387 /* Create the blit surface. */ 438 /* Create the blit surface. */
388 face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data, 439 face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data,
389 img_face.width, img_face.height, 32, img_face.width*4, 440 img_face.width, img_face.height, 32, img_face.width*4,
390 RMASK, GMASK, BMASK, AMASK ); 441 RMASK, GMASK, BMASK, AMASK );
402 nj = 30; 453 nj = 30;
403 454
404 /* Constant values. */ 455 /* Constant values. */
405 rect.w = face->w; 456 rect.w = face->w;
406 rect.h = face->h; 457 rect.h = face->h;
458
459 /* Test blitting with colour mod. */
460 for (j=0; j <= nj; j+=4) {
461 for (i=0; i <= ni; i+=4) {
462 /* Set alpha mod. */
463 ret = SDL_SetSurfaceAlphaMod( face, (255/ni)*i );
464 if (SDL_ATassert( "SDL_SetSurfaceAlphaMod", ret == 0))
465 return;
466
467 /* Blitting. */
468 rect.x = i;
469 rect.y = j;
470 ret = SDL_BlitSurface( face, NULL, testsur, &rect );
471 if (SDL_ATassert( "SDL_BlitSurface", ret == 0))
472 return;
473 }
474 }
475
476 SDL_SaveBMP( testsur, "testsur.bmp" );
407 477
408 /* Loop blit. */ 478 /* Loop blit. */
409 for (j=0; j <= testsur->h - face->h; j+=4) { 479 for (j=0; j <= testsur->h - face->h; j+=4) {
410 for (i=0; i <= testsur->w - face->w; i+=4) { 480 for (i=0; i <= testsur->w - face->w; i+=4) {
411 481
459 /* Initializes the SDL subsystems. */ 529 /* Initializes the SDL subsystems. */
460 SDL_Init(0); 530 SDL_Init(0);
461 531
462 surface_testLoad(); 532 surface_testLoad();
463 surface_testPrimitives(); 533 surface_testPrimitives();
464 surface_testPrimitivesAlpha(); 534 surface_testPrimitivesBlend();
465 surface_testBlit(); 535 surface_testBlit();
466 /*surface_testBlitAlpha();*/ 536 /*surface_testBlitBlend();*/
467 537
468 /* Exit SDL. */ 538 /* Exit SDL. */
469 SDL_Quit(); 539 SDL_Quit();
470 540
471 return SDL_ATfinish(1); 541 return SDL_ATfinish(1);