annotate test/automated/common/common.c @ 3439:0acec8c9f5c9

Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
author Sam Lantinga <slouken@libsdl.org>
date Tue, 17 Nov 2009 05:17:11 +0000
parents 22ac66da0765
children 5271ce790fed
rev   line source
3259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /**
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 * Automated SDL_Surface test.
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 *
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4 * Written by Edgar Simo "bobbens"
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 *
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 * Released under Public Domain.
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 #include "SDL.h"
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 #include "SDL_at.h"
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 #include "common/common.h"
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 /**
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 * @brief Compares a surface and a surface image for equality.
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18 */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 int surface_compare( SDL_Surface *sur, const SurfaceImage_t *img )
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 int ret;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 int i,j;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23 int bpp;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 Uint8 *p, *pd;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 /* Make sure size is the same. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 if ((sur->w != img->width) || (sur->h != img->height))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 return -1;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 SDL_LockSurface( sur );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 ret = 0;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 bpp = sur->format->BytesPerPixel;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 /* Compare image - should be same format. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 for (j=0; j<sur->h; j++) {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 for (i=0; i<sur->w; i++) {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 p = (Uint8 *)sur->pixels + j * sur->pitch + i * bpp;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 pd = (Uint8 *)img->pixel_data + (j*img->width + i) * img->bytes_per_pixel;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 switch (bpp) {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 case 1:
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 case 2:
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43 case 3:
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 ret += 1;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 printf("%d BPP not supported yet.\n",bpp);
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 break;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 case 4:
3439
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
49 {
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
50 int fail;
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
51 Uint8 R, G, B, A;
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
52
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
53 SDL_GetRGBA(*(Uint32*)p, sur->format, &R, &G, &B, &A);
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
54
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
55 if (img->bytes_per_pixel == 3) {
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
56 fail = !( (R == pd[0]) &&
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
57 (G == pd[1]) &&
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
58 (B == pd[2]) );
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
59 } else {
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
60 fail = !( (R == pd[0]) &&
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
61 (G == pd[1]) &&
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
62 (B == pd[2]) &&
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
63 (A == pd[3]) );
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
64 }
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
65 if (fail) {
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
66 ++ret;
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
67 }
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
68 }
3259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 break;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 SDL_UnlockSurface( sur );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 return ret;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 }