annotate test/automated/common/common.c @ 3449:7bd010656baf

Fixes for the automated rendering test
author Sam Lantinga <slouken@libsdl.org>
date Wed, 18 Nov 2009 09:07:13 +0000
parents 5271ce790fed
children 6b182cbe38ac
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
3441
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
76 if (ret) {
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
77 SDL_SaveBMP(sur, "fail.bmp");
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
78
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
79 SDL_LockSurface( sur );
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
80
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
81 bpp = sur->format->BytesPerPixel;
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
82
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
83 /* Compare image - should be same format. */
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
84 if (bpp == 4) {
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
85 for (j=0; j<sur->h; j++) {
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
86 for (i=0; i<sur->w; i++) {
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
87 p = (Uint8 *)sur->pixels + j * sur->pitch + i * bpp;
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
88 pd = (Uint8 *)img->pixel_data + (j*img->width + i) * img->bytes_per_pixel;
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
89 Uint8 R, G, B, A;
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
90
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
91 R = pd[0];
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
92 G = pd[1];
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
93 B = pd[2];
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
94 if (img->bytes_per_pixel == 4) {
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
95 A = pd[3];
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
96 } else {
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
97 A = 0;
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
98 }
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
99 *(Uint32*)p = (A << 24) | (R << 16) | (G << 8) | B;
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
100 }
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
101 }
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
102 }
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
103
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
104 SDL_UnlockSurface( sur );
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
105
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
106 SDL_SaveBMP(sur, "good.bmp");
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
107 }
3259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 return ret;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 }