3728
|
1 /**
|
|
2 * Automated SDL_Surface test.
|
|
3 *
|
|
4 * Written by Edgar Simo "bobbens"
|
|
5 *
|
|
6 * Released under Public Domain.
|
|
7 */
|
|
8
|
|
9
|
|
10 #include "SDL.h"
|
|
11 #include "SDL_at.h"
|
|
12
|
|
13 #include "common/common.h"
|
|
14
|
|
15
|
|
16 /**
|
|
17 * @brief Compares a surface and a surface image for equality.
|
|
18 */
|
|
19 int surface_compare( SDL_Surface *sur, const SurfaceImage_t *img )
|
|
20 {
|
|
21 int ret;
|
|
22 int i,j;
|
|
23 int bpp;
|
|
24 Uint8 *p, *pd;
|
|
25
|
|
26 /* Make sure size is the same. */
|
|
27 if ((sur->w != img->width) || (sur->h != img->height))
|
|
28 return -1;
|
|
29
|
|
30 SDL_LockSurface( sur );
|
|
31
|
|
32 ret = 0;
|
|
33 bpp = sur->format->BytesPerPixel;
|
|
34
|
|
35 /* Compare image - should be same format. */
|
|
36 for (j=0; j<sur->h; j++) {
|
|
37 for (i=0; i<sur->w; i++) {
|
|
38 p = (Uint8 *)sur->pixels + j * sur->pitch + i * bpp;
|
|
39 pd = (Uint8 *)img->pixel_data + (j*img->width + i) * img->bytes_per_pixel;
|
|
40 switch (bpp) {
|
|
41 case 1:
|
|
42 case 2:
|
|
43 case 3:
|
|
44 ret += 1;
|
|
45 printf("%d BPP not supported yet.\n",bpp);
|
|
46 break;
|
|
47
|
|
48 case 4:
|
|
49 ret += !( (p[0] == pd[0]) &&
|
|
50 (p[1] == pd[1]) &&
|
|
51 (p[2] == pd[2]) );
|
|
52 break;
|
|
53 }
|
|
54 }
|
|
55 }
|
|
56
|
|
57 SDL_UnlockSurface( sur );
|
|
58
|
|
59 return ret;
|
|
60 }
|