annotate test/automated/common/common.c @ 5266:595814f561f7

There is only one width and height for the window. If those are changed during the course of a fullscreen mode change, then they'll stay that size when returning to windowed mode.
author Sam Lantinga <slouken@libsdl.org>
date Fri, 11 Feb 2011 20:49:13 -0800
parents 5f038ec1a1af
children
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"
3481
c32c53fca10d Fixed include paths for Visual C++
Sam Lantinga <slouken@libsdl.org>
parents: 3477
diff changeset
11 #include "../SDL_at.h"
3259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12
3481
c32c53fca10d Fixed include paths for Visual C++
Sam Lantinga <slouken@libsdl.org>
parents: 3477
diff changeset
13 #include "common.h"
3259
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 */
3477
2c07bb579922 We want to be strict on software renderer tests and opaque tests, but give a decent margin for blending inaccuracy for the blended tests.
Sam Lantinga <slouken@libsdl.org>
parents: 3476
diff changeset
19 int surface_compare( SDL_Surface *sur, const SurfaceImage_t *img, int allowable_error )
3259
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;
3482
78db4f7ae2f3 More fixes to compile under Visual C++
Sam Lantinga <slouken@libsdl.org>
parents: 3481
diff changeset
45 /*printf("%d BPP not supported yet.\n",bpp);*/
3259
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 {
3456
6b182cbe38ac Allow some variation in the pixel values to account for blending accuracy differences.
Sam Lantinga <slouken@libsdl.org>
parents: 3441
diff changeset
50 int dist = 0;
3439
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) {
3456
6b182cbe38ac Allow some variation in the pixel values to account for blending accuracy differences.
Sam Lantinga <slouken@libsdl.org>
parents: 3441
diff changeset
56 dist += (R-pd[0])*(R-pd[0]);
6b182cbe38ac Allow some variation in the pixel values to account for blending accuracy differences.
Sam Lantinga <slouken@libsdl.org>
parents: 3441
diff changeset
57 dist += (G-pd[1])*(G-pd[1]);
6b182cbe38ac Allow some variation in the pixel values to account for blending accuracy differences.
Sam Lantinga <slouken@libsdl.org>
parents: 3441
diff changeset
58 dist += (B-pd[2])*(B-pd[2]);
3439
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 {
3456
6b182cbe38ac Allow some variation in the pixel values to account for blending accuracy differences.
Sam Lantinga <slouken@libsdl.org>
parents: 3441
diff changeset
60 dist += (R-pd[0])*(R-pd[0]);
6b182cbe38ac Allow some variation in the pixel values to account for blending accuracy differences.
Sam Lantinga <slouken@libsdl.org>
parents: 3441
diff changeset
61 dist += (G-pd[1])*(G-pd[1]);
6b182cbe38ac Allow some variation in the pixel values to account for blending accuracy differences.
Sam Lantinga <slouken@libsdl.org>
parents: 3441
diff changeset
62 dist += (B-pd[2])*(B-pd[2]);
6b182cbe38ac Allow some variation in the pixel values to account for blending accuracy differences.
Sam Lantinga <slouken@libsdl.org>
parents: 3441
diff changeset
63 dist += (A-pd[3])*(A-pd[3]);
3439
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
64 }
3477
2c07bb579922 We want to be strict on software renderer tests and opaque tests, but give a decent margin for blending inaccuracy for the blended tests.
Sam Lantinga <slouken@libsdl.org>
parents: 3476
diff changeset
65 /* Allow some difference in blending accuracy */
2c07bb579922 We want to be strict on software renderer tests and opaque tests, but give a decent margin for blending inaccuracy for the blended tests.
Sam Lantinga <slouken@libsdl.org>
parents: 3476
diff changeset
66 if (dist > allowable_error) {
3456
6b182cbe38ac Allow some variation in the pixel values to account for blending accuracy differences.
Sam Lantinga <slouken@libsdl.org>
parents: 3441
diff changeset
67 /*printf("pixel %d,%d varies by %d\n", i, j, dist);*/
3439
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
68 ++ret;
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
69 }
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
70 }
3259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 break;
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 }
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 SDL_UnlockSurface( sur );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77
3441
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
78 if (ret) {
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
79 SDL_SaveBMP(sur, "fail.bmp");
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 SDL_LockSurface( sur );
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 bpp = sur->format->BytesPerPixel;
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
84
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
85 if (bpp == 4) {
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
86 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
87 for (i=0; i<sur->w; i++) {
3482
78db4f7ae2f3 More fixes to compile under Visual C++
Sam Lantinga <slouken@libsdl.org>
parents: 3481
diff changeset
88 Uint8 R, G, B, A;
3441
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
89 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
90 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
91
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
92 R = pd[0];
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
93 G = pd[1];
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
94 B = pd[2];
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
95 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
96 A = pd[3];
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
97 } else {
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
98 A = 0;
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
99 }
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
100 *(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
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
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
105 SDL_UnlockSurface( sur );
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
106
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
107 SDL_SaveBMP(sur, "good.bmp");
5271ce790fed Debug info to help track down render test failures
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
108 }
3259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 return ret;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 }