annotate test/automated/surface/surface.c @ 3481:c32c53fca10d

Fixed include paths for Visual C++
author Sam Lantinga <slouken@libsdl.org>
date Sun, 22 Nov 2009 06:42:58 +0000
parents 2c07bb579922
children f638ded38b8a
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_surface.h"
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 #include "SDL_video.h"
3481
c32c53fca10d Fixed include paths for Visual C++
Sam Lantinga <slouken@libsdl.org>
parents: 3477
diff changeset
13 #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
14
3481
c32c53fca10d Fixed include paths for Visual C++
Sam Lantinga <slouken@libsdl.org>
parents: 3477
diff changeset
15 #include "../common/common.h"
3259
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
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 * Pull in images for testcases.
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 */
3481
c32c53fca10d Fixed include paths for Visual C++
Sam Lantinga <slouken@libsdl.org>
parents: 3477
diff changeset
21 #include "../common/images.h"
3259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 /*
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 * Prototypes.
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 /* Testcases. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28 static void surface_testLoad( SDL_Surface *testsur );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 static void surface_testPrimitives( SDL_Surface *testsur );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 static void surface_testPrimitivesBlend( SDL_Surface *testsur );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 static void surface_testBlit( SDL_Surface *testsur );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 static int surface_testBlitBlendMode( SDL_Surface *testsur, SDL_Surface *face, int mode );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 static void surface_testBlitBlend( SDL_Surface *testsur );
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
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 /**
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 * @brief Tests sprite loading.
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 static void surface_testLoad( SDL_Surface *testsur )
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 int ret;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 SDL_Surface *face, *rface;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 SDL_ATbegin( "Load Test" );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 /* Clear surface. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 ret = SDL_FillRect( testsur, NULL,
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 SDL_MapRGB( testsur->format, 0, 0, 0 ) );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 if (SDL_ATassert( "SDL_FillRect", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 /* Create the blit surface. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 face = SDL_LoadBMP("../icon.bmp");
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 if (SDL_ATassert( "SDL_CreateLoadBmp", face != NULL))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 /* Set transparent pixel as the pixel at (0,0) */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 if (face->format->palette) {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 ret = SDL_SetColorKey(face, (SDL_SRCCOLORKEY | SDL_RLEACCEL),
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 *(Uint8 *) face->pixels);
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 if (SDL_ATassert( "SDL_SetColorKey", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 /* Convert to 32 bit to compare. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 rface = SDL_ConvertSurface( face, testsur->format, 0 );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 if (SDL_ATassert( "SDL_ConvertSurface", rface != NULL))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 /* See if it's the same. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 if (SDL_ATassert( "Primitives output not the same.",
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: 3471
diff changeset
72 surface_compare( rface, &img_face, 0 )==0 ))
3259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 return;
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 /* Clean up. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 SDL_FreeSurface( rface );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 SDL_FreeSurface( face );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 SDL_ATend();
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 /**
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 * @brief Tests the SDL primitives for rendering.
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 static void surface_testPrimitives( SDL_Surface *testsur )
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 int ret;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 int x, y;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 SDL_Rect rect;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 SDL_ATbegin( "Primitives Test" );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 /* Clear surface. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 ret = SDL_FillRect( testsur, NULL,
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 SDL_MapRGB( testsur->format, 0, 0, 0 ) );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 if (SDL_ATassert( "SDL_FillRect", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 /* Draw a rectangle. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 rect.x = 40;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 rect.y = 0;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103 rect.w = 40;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 rect.h = 80;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 ret = SDL_FillRect( testsur, &rect,
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 SDL_MapRGB( testsur->format, 13, 73, 200 ) );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 if (SDL_ATassert( "SDL_FillRect", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 /* Draw a rectangle. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 rect.x = 10;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 rect.y = 10;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 rect.w = 60;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 rect.h = 40;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115 ret = SDL_FillRect( testsur, &rect,
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 SDL_MapRGB( testsur->format, 200, 0, 100 ) );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 if (SDL_ATassert( "SDL_FillRect", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 /* Draw some points like so:
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 * X.X.X.X..
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 * .X.X.X.X.
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 * X.X.X.X.. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 for (y=0; y<3; y++) {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 x = y % 2;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126 for (; x<80; x+=2) {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 ret = SDL_DrawPoint( testsur, x, y,
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 SDL_MapRGB( testsur->format, x*y, x*y/2, x*y/3 ) );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 if (SDL_ATassert( "SDL_DrawPoint", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 /* Draw some lines. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 ret = SDL_DrawLine( testsur, 0, 30, 80, 30,
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 SDL_MapRGB( testsur->format, 0, 255, 0 ) );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 if (SDL_ATassert( "SDL_DrawLine", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 ret = SDL_DrawLine( testsur, 40, 30, 40, 60,
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 SDL_MapRGB( testsur->format, 55, 55, 5 ) );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 if (SDL_ATassert( "SDL_DrawLine", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 return;
3471
da53c4046c65 Use 45 degree lines for the diagonal test to avoid aliasing errors in line drawing.
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
143 ret = SDL_DrawLine( testsur, 0, 0, 29, 29,
da53c4046c65 Use 45 degree lines for the diagonal test to avoid aliasing errors in line drawing.
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
144 SDL_MapRGB( testsur->format, 5, 105, 105 ) );
da53c4046c65 Use 45 degree lines for the diagonal test to avoid aliasing errors in line drawing.
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
145 if (SDL_ATassert( "SDL_DrawLine", ret == 0))
da53c4046c65 Use 45 degree lines for the diagonal test to avoid aliasing errors in line drawing.
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
146 return;
da53c4046c65 Use 45 degree lines for the diagonal test to avoid aliasing errors in line drawing.
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
147 ret = SDL_DrawLine( testsur, 29, 30, 0, 59,
da53c4046c65 Use 45 degree lines for the diagonal test to avoid aliasing errors in line drawing.
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
148 SDL_MapRGB( testsur->format, 5, 105, 105 ) );
da53c4046c65 Use 45 degree lines for the diagonal test to avoid aliasing errors in line drawing.
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
149 if (SDL_ATassert( "SDL_DrawLine", ret == 0))
da53c4046c65 Use 45 degree lines for the diagonal test to avoid aliasing errors in line drawing.
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
150 return;
da53c4046c65 Use 45 degree lines for the diagonal test to avoid aliasing errors in line drawing.
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
151 ret = SDL_DrawLine( testsur, 79, 0, 50, 29,
da53c4046c65 Use 45 degree lines for the diagonal test to avoid aliasing errors in line drawing.
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
152 SDL_MapRGB( testsur->format, 5, 105, 105 ) );
da53c4046c65 Use 45 degree lines for the diagonal test to avoid aliasing errors in line drawing.
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
153 if (SDL_ATassert( "SDL_DrawLine", ret == 0))
da53c4046c65 Use 45 degree lines for the diagonal test to avoid aliasing errors in line drawing.
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
154 return;
da53c4046c65 Use 45 degree lines for the diagonal test to avoid aliasing errors in line drawing.
Sam Lantinga <slouken@libsdl.org>
parents: 3439
diff changeset
155 ret = SDL_DrawLine( testsur, 79, 59, 50, 30,
3259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 SDL_MapRGB( testsur->format, 5, 105, 105 ) );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 if (SDL_ATassert( "SDL_DrawLine", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 /* See if it's the same. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 if (SDL_ATassert( "Primitives output not the same.",
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: 3471
diff changeset
162 surface_compare( testsur, &img_primitives, 0 )==0 ))
3259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 SDL_ATend();
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 /**
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 * @brief Tests the SDL primitives with alpha for rendering.
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 static void surface_testPrimitivesBlend( SDL_Surface *testsur )
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173 {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 int ret;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 int i, j;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 SDL_Rect rect;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 SDL_ATbegin( "Primitives Blend Test" );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 /* Clear surface. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 ret = SDL_FillRect( testsur, NULL,
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 SDL_MapRGB( testsur->format, 0, 0, 0 ) );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 if (SDL_ATassert( "SDL_FillRect", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 /* Create some rectangles for each blend mode. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 ret = SDL_BlendRect( testsur, NULL, SDL_BLENDMODE_NONE, 255, 255, 255, 0 );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188 if (SDL_ATassert( "SDL_BlendRect", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 rect.x = 10;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 rect.y = 25;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 rect.w = 40;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 rect.h = 25;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194 ret = SDL_BlendRect( testsur, &rect, SDL_BLENDMODE_ADD, 240, 10, 10, 75 );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195 if (SDL_ATassert( "SDL_BlendRect", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 rect.x = 30;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 rect.y = 40;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 rect.w = 45;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200 rect.h = 15;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 ret = SDL_BlendRect( testsur, &rect, SDL_BLENDMODE_BLEND, 10, 240, 10, 100 );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202 if (SDL_ATassert( "SDL_BlendRect", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 rect.x = 25;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205 rect.y = 25;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 rect.w = 25;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 rect.h = 25;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208 ret = SDL_BlendRect( testsur, &rect, SDL_BLENDMODE_MOD, 10, 10, 240, 125 );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209 if (SDL_ATassert( "SDL_BlendRect", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 /* Draw blended lines, lines for everyone. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213 for (i=0; i<testsur->w; i+=2) {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214 ret = SDL_BlendLine( testsur, 0, 0, i, 59,
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 (((i/2)%3)==0) ? SDL_BLENDMODE_BLEND :
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216 (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD,
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217 60+2*i, 240-2*i, 50, 3*i );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218 if (SDL_ATassert( "SDL_BlendLine", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
220 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221 for (i=0; i<testsur->h; i+=2) {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 ret = SDL_BlendLine( testsur, 0, 0, 79, i,
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
223 (((i/2)%3)==0) ? SDL_BLENDMODE_BLEND :
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224 (((i/2)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD,
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225 60+2*i, 240-2*i, 50, 3*i );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226 if (SDL_ATassert( "SDL_BlendLine", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
229
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230 /* Draw points. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231 for (j=0; j<testsur->h; j+=3) {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232 for (i=0; i<testsur->w; i+=3) {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233 ret = SDL_BlendPoint( testsur, i, j,
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 ((((i+j)/3)%3)==0) ? SDL_BLENDMODE_BLEND :
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
235 ((((i+j)/3)%3)==1) ? SDL_BLENDMODE_ADD : SDL_BLENDMODE_MOD,
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
236 j*4, i*3, j*4, i*3 );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
237 if (SDL_ATassert( "SDL_BlendPoint", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
238 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
239 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
240 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242 /* See if it's the same. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243 if (SDL_ATassert( "Primitives output not the same.",
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: 3471
diff changeset
244 surface_compare( testsur, &img_blend, 0 )==0 ))
3259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
246
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
247 SDL_ATend();
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
248 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
250
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
251 /**
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
252 * @brief Tests some blitting routines.
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
253 */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
254 static void surface_testBlit( SDL_Surface *testsur )
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
255 {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
256 int ret;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
257 SDL_Rect rect;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
258 SDL_Surface *face;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259 int i, j, ni, nj;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
261 SDL_ATbegin( "Blit Tests" );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
262
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
263 /* Clear surface. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
264 ret = SDL_FillRect( testsur, NULL,
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265 SDL_MapRGB( testsur->format, 0, 0, 0 ) );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
266 if (SDL_ATassert( "SDL_FillRect", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269 /* Create face surface. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data,
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
271 img_face.width, img_face.height, 32, img_face.width*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
272 #if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
273 0xff000000, /* Red bit mask. */
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
274 0x00ff0000, /* Green bit mask. */
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
275 0x0000ff00, /* Blue bit mask. */
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
276 0x000000ff /* Alpha bit mask. */
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
277 #else
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
278 0x000000ff, /* Red bit mask. */
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
279 0x0000ff00, /* Green bit mask. */
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
280 0x00ff0000, /* Blue bit mask. */
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
281 0xff000000 /* Alpha bit mask. */
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
282 #endif
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
283 );
3259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
284 if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", face != NULL))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
285 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
286
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
287 /* Constant values. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
288 rect.w = face->w;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
289 rect.h = face->h;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
290 ni = testsur->w - face->w;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
291 nj = testsur->h - face->h;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
292
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
293 /* Loop blit. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
294 for (j=0; j <= nj; j+=4) {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
295 for (i=0; i <= ni; i+=4) {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
296 /* Blitting. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
297 rect.x = i;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
298 rect.y = j;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
299 ret = SDL_BlitSurface( face, NULL, testsur, &rect );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
300 if (SDL_ATassert( "SDL_BlitSurface", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
301 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
302 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
303 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
304
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
305 /* See if it's the same. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
306 if (SDL_ATassert( "Blitting output not the same (normal blit).",
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: 3471
diff changeset
307 surface_compare( testsur, &img_blit, 0 )==0 ))
3259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
308 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
309
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
310 /* Clear surface. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
311 ret = SDL_FillRect( testsur, NULL,
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
312 SDL_MapRGB( testsur->format, 0, 0, 0 ) );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
313 if (SDL_ATassert( "SDL_FillRect", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
314 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
315
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
316 /* Test blitting with colour mod. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
317 for (j=0; j <= nj; j+=4) {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
318 for (i=0; i <= ni; i+=4) {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
319 /* Set colour mod. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
320 ret = SDL_SetSurfaceColorMod( face, (255/nj)*j, (255/ni)*i, (255/nj)*j );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
321 if (SDL_ATassert( "SDL_SetSurfaceColorMod", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
322 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
323
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
324 /* Blitting. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
325 rect.x = i;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
326 rect.y = j;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
327 ret = SDL_BlitSurface( face, NULL, testsur, &rect );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
328 if (SDL_ATassert( "SDL_BlitSurface", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
329 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
330 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
331 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
332
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
333 /* See if it's the same. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
334 if (SDL_ATassert( "Blitting output not the same (using SDL_SetSurfaceColorMod).",
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: 3471
diff changeset
335 surface_compare( testsur, &img_blitColour, 0 )==0 ))
3259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
336 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
337
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
338 /* Clear surface. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
339 ret = SDL_FillRect( testsur, NULL,
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
340 SDL_MapRGB( testsur->format, 0, 0, 0 ) );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
341 if (SDL_ATassert( "SDL_FillRect", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
342 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
343
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
344 /* Restore colour. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
345 ret = SDL_SetSurfaceColorMod( face, 255, 255, 255 );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
346 if (SDL_ATassert( "SDL_SetSurfaceColorMod", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
347 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
348
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
349 /* Test blitting with colour mod. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
350 for (j=0; j <= nj; j+=4) {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
351 for (i=0; i <= ni; i+=4) {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
352 /* Set alpha mod. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
353 ret = SDL_SetSurfaceAlphaMod( face, (255/ni)*i );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
354 if (SDL_ATassert( "SDL_SetSurfaceAlphaMod", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
355 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
356
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
357 /* Blitting. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
358 rect.x = i;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
359 rect.y = j;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
360 ret = SDL_BlitSurface( face, NULL, testsur, &rect );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
361 if (SDL_ATassert( "SDL_BlitSurface", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
362 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
363 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
364 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
365
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
366 /* See if it's the same. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
367 if (SDL_ATassert( "Blitting output not the same (using SDL_SetSurfaceAlphaMod).",
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: 3471
diff changeset
368 surface_compare( testsur, &img_blitAlpha, 0 )==0 ))
3259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
369 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
370
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
371 /* Clean up. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
372 SDL_FreeSurface( face );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
373
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
374 SDL_ATend();
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
375 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
376
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
377
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
378 /**
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
379 * @brief Tests a blend mode.
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
380 */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
381 static int surface_testBlitBlendMode( SDL_Surface *testsur, SDL_Surface *face, int mode )
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
382 {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
383 int ret;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
384 int i, j, ni, nj;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
385 SDL_Rect rect;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
386
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
387 /* Clear surface. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
388 ret = SDL_FillRect( testsur, NULL,
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
389 SDL_MapRGB( testsur->format, 0, 0, 0 ) );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
390 if (SDL_ATassert( "SDL_FillRect", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
391 return 1;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
392
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
393 /* Steps to take. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
394 ni = testsur->w - face->w;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
395 nj = testsur->h - face->h;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
396
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
397 /* Constant values. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
398 rect.w = face->w;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
399 rect.h = face->h;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
400
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
401 /* Test blend mode. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
402 for (j=0; j <= nj; j+=4) {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
403 for (i=0; i <= ni; i+=4) {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
404 /* Set blend mode. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
405 ret = SDL_SetSurfaceBlendMode( face, mode );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
406 if (SDL_ATassert( "SDL_SetSurfaceBlendMode", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
407 return 1;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
408
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
409 /* Blitting. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
410 rect.x = i;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
411 rect.y = j;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
412 ret = SDL_BlitSurface( face, NULL, testsur, &rect );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
413 if (SDL_ATassert( "SDL_BlitSurface", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
414 return 1;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
415 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
416 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
417
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
418 return 0;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
419 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
420
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
421
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
422 /**
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
423 * @brief Tests some more blitting routines.
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
424 */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
425 static void surface_testBlitBlend( SDL_Surface *testsur )
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
426 {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
427 int ret;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
428 SDL_Rect rect;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
429 SDL_Surface *face;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
430 int i, j, ni, nj;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
431 int mode;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
432
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
433 SDL_ATbegin( "Blit Blending Tests" );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
434
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
435 /* Clear surface. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
436 ret = SDL_FillRect( testsur, NULL,
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
437 SDL_MapRGB( testsur->format, 0, 0, 0 ) );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
438 if (SDL_ATassert( "SDL_FillRect", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
439 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
440
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
441 /* Create the blit surface. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
442 face = SDL_CreateRGBSurfaceFrom( (void*)img_face.pixel_data,
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
443 img_face.width, img_face.height, 32, img_face.width*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
444 #if (SDL_BYTEORDER == SDL_BIG_ENDIAN)
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
445 0xff000000, /* Red bit mask. */
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
446 0x00ff0000, /* Green bit mask. */
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
447 0x0000ff00, /* Blue bit mask. */
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
448 0x000000ff /* Alpha bit mask. */
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
449 #else
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
450 0x000000ff, /* Red bit mask. */
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
451 0x0000ff00, /* Green bit mask. */
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
452 0x00ff0000, /* Blue bit mask. */
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
453 0xff000000 /* Alpha bit mask. */
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
454 #endif
0acec8c9f5c9 Fixed some bugs in the automated test suite, revealed by working SDL_RenderReadPixels()
Sam Lantinga <slouken@libsdl.org>
parents: 3259
diff changeset
455 );
3259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
456 if (SDL_ATassert( "SDL_CreateRGBSurfaceFrom", face != NULL))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
457 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
458
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
459 /* Set alpha mod. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
460 ret = SDL_SetSurfaceAlphaMod( face, 100 );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
461 if (SDL_ATassert( "SDL_SetSurfaceAlphaMod", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
462 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
463
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
464 /* Steps to take. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
465 ni = testsur->w - face->w;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
466 nj = testsur->h - face->h;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
467
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
468 /* Constant values. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
469 rect.w = face->w;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
470 rect.h = face->h;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
471
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
472 /* Test None. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
473 if (surface_testBlitBlendMode( testsur, face, SDL_BLENDMODE_NONE ))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
474 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
475 if (SDL_ATassert( "Blitting blending output not the same (using SDL_BLENDMODE_NONE).",
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: 3471
diff changeset
476 surface_compare( testsur, &img_blendNone, 0 )==0 ))
3259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
477 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
478
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
479 /* Test Mask. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
480 if (surface_testBlitBlendMode( testsur, face, SDL_BLENDMODE_MASK ))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
481 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
482 if (SDL_ATassert( "Blitting blending output not the same (using SDL_BLENDMODE_MASK).",
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: 3471
diff changeset
483 surface_compare( testsur, &img_blendMask, 0 )==0 ))
3259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
484 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
485
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
486 /* Test Blend. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
487 if (surface_testBlitBlendMode( testsur, face, SDL_BLENDMODE_BLEND ))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
488 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
489 if (SDL_ATassert( "Blitting blending output not the same (using SDL_BLENDMODE_BLEND).",
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: 3471
diff changeset
490 surface_compare( testsur, &img_blendBlend, 0 )==0 ))
3259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
491 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
492
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
493 /* Test Add. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
494 if (surface_testBlitBlendMode( testsur, face, SDL_BLENDMODE_ADD ))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
495 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
496 if (SDL_ATassert( "Blitting blending output not the same (using SDL_BLENDMODE_ADD).",
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: 3471
diff changeset
497 surface_compare( testsur, &img_blendAdd, 0 )==0 ))
3259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
498 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
499
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
500 /* Test Mod. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
501 if (surface_testBlitBlendMode( testsur, face, SDL_BLENDMODE_MOD ))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
502 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
503 if (SDL_ATassert( "Blitting blending output not the same (using SDL_BLENDMODE_MOD).",
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: 3471
diff changeset
504 surface_compare( testsur, &img_blendMod, 0 )==0 ))
3259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
505 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
506
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
507 /* Clear surface. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
508 ret = SDL_FillRect( testsur, NULL,
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
509 SDL_MapRGB( testsur->format, 0, 0, 0 ) );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
510 if (SDL_ATassert( "SDL_FillRect", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
511 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
512
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
513 /* Loop blit. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
514 for (j=0; j <= nj; j+=4) {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
515 for (i=0; i <= ni; i+=4) {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
516
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
517 /* Set colour mod. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
518 ret = SDL_SetSurfaceColorMod( face, (255/nj)*j, (255/ni)*i, (255/nj)*j );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
519 if (SDL_ATassert( "SDL_SetSurfaceColorMod", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
520 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
521
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
522 /* Set alpha mod. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
523 ret = SDL_SetSurfaceAlphaMod( face, (100/ni)*i );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
524 if (SDL_ATassert( "SDL_SetSurfaceAlphaMod", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
525 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
526
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
527 /* Crazy blending mode magic. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
528 mode = (i/4*j/4) % 4;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
529 if (mode==0) mode = SDL_BLENDMODE_MASK;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
530 else if (mode==1) mode = SDL_BLENDMODE_BLEND;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
531 else if (mode==2) mode = SDL_BLENDMODE_ADD;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
532 else if (mode==3) mode = SDL_BLENDMODE_MOD;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
533 ret = SDL_SetSurfaceBlendMode( face, mode );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
534 if (SDL_ATassert( "SDL_SetSurfaceBlendMode", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
535 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
536
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
537 /* Blitting. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
538 rect.x = i;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
539 rect.y = j;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
540 ret = SDL_BlitSurface( face, NULL, testsur, &rect );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
541 if (SDL_ATassert( "SDL_BlitSurface", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
542 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
543 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
544 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
545
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
546 /* Check to see if matches. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
547 if (SDL_ATassert( "Blitting blending output not the same (using SDL_BLEND_*).",
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: 3471
diff changeset
548 surface_compare( testsur, &img_blendAll, 0 )==0 ))
3259
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
549 return;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
550
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
551 /* Clean up. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
552 SDL_FreeSurface( face );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
553
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
554 SDL_ATend();
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
555 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
556
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
557
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
558 /**
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
559 * @brief Runs all the tests on the surface.
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
560 *
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
561 * @param testsur Surface to run tests on.
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
562 */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
563 void surface_runTests( SDL_Surface *testsur )
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
564 {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
565 /* Software surface blitting. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
566 surface_testPrimitives( testsur );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
567 surface_testPrimitivesBlend( testsur );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
568 surface_testBlit( testsur );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
569 surface_testBlitBlend( testsur );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
570 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
571
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
572
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
573 /**
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
574 * @brief Entry point.
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
575 */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
576 #ifdef TEST_STANDALONE
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
577 int main( int argc, const char *argv[] )
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
578 {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
579 (void) argc;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
580 (void) argv;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
581 #else /* TEST_STANDALONE */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
582 int test_surface (void)
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
583 {
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
584 #endif /* TEST_STANDALONE */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
585 int ret;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
586 SDL_Surface *testsur;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
587
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
588 SDL_ATinit( "SDL_Surface" );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
589
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
590 SDL_ATbegin( "Initializing" );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
591 /* Initializes the SDL subsystems. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
592 ret = SDL_Init(0);
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
593 if (SDL_ATassert( "SDL_Init(0)", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
594 goto err;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
595
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
596 /* Now run on the video mode. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
597 ret = SDL_InitSubSystem( SDL_INIT_VIDEO );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
598 if (SDL_ATassert( "SDL_InitSubSystem( SDL_INIT_VIDEO )", ret == 0))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
599 goto err;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
600
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
601 /*
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
602 * Surface on surface tests.
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
603 */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
604 /* Create the test surface. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
605 testsur = SDL_CreateRGBSurface( 0, 80, 60, 32,
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
606 RMASK, GMASK, BMASK, AMASK );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
607 if (SDL_ATassert( "SDL_CreateRGBSurface", testsur != NULL))
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
608 goto err;
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
609 SDL_ATend();
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
610 /* Run surface on surface tests. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
611 surface_testLoad( testsur );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
612 surface_runTests( testsur );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
613 /* Clean up. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
614 SDL_FreeSurface( testsur );
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
615
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
616 /* Exit SDL. */
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
617 SDL_Quit();
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
618
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
619 return SDL_ATfinish();
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
620
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
621 err:
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
622 return SDL_ATfinish();
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
623 }
22ac66da0765 Merged Edgar's code changes from Google Summer of Code 2009
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
624