testautomation_surface.c 69 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586
  1. /**
  2. * Original code: automated SDL surface test written by Edgar Simo "bobbens"
  3. * Adapted/rewritten for test lib by Andreas Schiffler
  4. */
  5. /* Suppress C4996 VS compiler warnings for unlink() */
  6. #if defined(_MSC_VER) && !defined(_CRT_SECURE_NO_DEPRECATE)
  7. #define _CRT_SECURE_NO_DEPRECATE
  8. #endif
  9. #if defined(_MSC_VER) && !defined(_CRT_NONSTDC_NO_DEPRECATE)
  10. #define _CRT_NONSTDC_NO_DEPRECATE
  11. #endif
  12. #include <stdio.h>
  13. #ifndef _MSC_VER
  14. #include <unistd.h>
  15. #endif
  16. #include <sys/stat.h>
  17. #include <SDL3/SDL.h>
  18. #include <SDL3/SDL_test.h>
  19. #include "testautomation_suites.h"
  20. #include "testautomation_images.h"
  21. #define CHECK_FUNC(FUNC, PARAMS) \
  22. { \
  23. SDL_bool result = FUNC PARAMS; \
  24. if (!result) { \
  25. SDLTest_AssertCheck(result, "Validate result from %s, expected: SDL_TRUE, got: SDL_FALSE, %s", #FUNC, SDL_GetError()); \
  26. } \
  27. }
  28. /* ================= Test Case Implementation ================== */
  29. /* Shared test surface */
  30. static SDL_Surface *referenceSurface = NULL;
  31. static SDL_Surface *testSurface = NULL;
  32. /* Fixture */
  33. /* Create a 32-bit writable surface for blitting tests */
  34. static void surfaceSetUp(void **arg)
  35. {
  36. int result;
  37. SDL_BlendMode blendMode = SDL_BLENDMODE_NONE;
  38. SDL_BlendMode currentBlendMode;
  39. referenceSurface = SDLTest_ImageBlit(); /* For size info */
  40. testSurface = SDL_CreateSurface(referenceSurface->w, referenceSurface->h, SDL_PIXELFORMAT_RGBA32);
  41. SDLTest_AssertCheck(testSurface != NULL, "Check that testSurface is not NULL");
  42. if (testSurface != NULL) {
  43. /* Disable blend mode for target surface */
  44. result = SDL_SetSurfaceBlendMode(testSurface, blendMode);
  45. SDLTest_AssertCheck(result == SDL_TRUE, "Validate result from SDL_SetSurfaceBlendMode, expected: SDL_TRUE, got: %i", result);
  46. result = SDL_GetSurfaceBlendMode(testSurface, &currentBlendMode);
  47. SDLTest_AssertCheck(result == SDL_TRUE, "Validate result from SDL_GetSurfaceBlendMode, expected: SDL_TRUE, got: %i", result);
  48. SDLTest_AssertCheck(currentBlendMode == blendMode, "Validate blendMode, expected: %" SDL_PRIu32 ", got: %" SDL_PRIu32, blendMode, currentBlendMode);
  49. /* Clear the target surface */
  50. result = SDL_FillSurfaceRect(testSurface, NULL, SDL_MapSurfaceRGBA(testSurface, 0, 0, 0, 255));
  51. SDLTest_AssertCheck(result == SDL_TRUE, "Validate result from SDL_FillSurfaceRect, expected: SDL_TRUE, got: %i", result);
  52. }
  53. }
  54. static void surfaceTearDown(void *arg)
  55. {
  56. SDL_DestroySurface(referenceSurface);
  57. referenceSurface = NULL;
  58. SDL_DestroySurface(testSurface);
  59. testSurface = NULL;
  60. }
  61. static void DitherPalette(SDL_Palette *palette)
  62. {
  63. int i;
  64. for (i = 0; i < palette->ncolors; i++) {
  65. int r, g, b;
  66. /* map each bit field to the full [0, 255] interval,
  67. so 0 is mapped to (0, 0, 0) and 255 to (255, 255, 255) */
  68. r = i & 0xe0;
  69. r |= r >> 3 | r >> 6;
  70. palette->colors[i].r = (Uint8)r;
  71. g = (i << 3) & 0xe0;
  72. g |= g >> 3 | g >> 6;
  73. palette->colors[i].g = (Uint8)g;
  74. b = i & 0x3;
  75. b |= b << 2;
  76. b |= b << 4;
  77. palette->colors[i].b = (Uint8)b;
  78. palette->colors[i].a = SDL_ALPHA_OPAQUE;
  79. }
  80. }
  81. /**
  82. * Helper that blits in a specific blend mode, -1 for color mod, -2 for alpha mod
  83. */
  84. static void testBlitBlendModeWithFormats(int mode, SDL_PixelFormat src_format, SDL_PixelFormat dst_format)
  85. {
  86. /* Allow up to 1 delta from theoretical value to account for rounding error */
  87. const int MAXIMUM_ERROR = 1;
  88. int ret;
  89. SDL_Surface *src;
  90. SDL_Surface *dst;
  91. Uint32 color;
  92. Uint8 srcR = 10, srcG = 128, srcB = 240, srcA = 100;
  93. Uint8 dstR = 128, dstG = 128, dstB = 128, dstA = 128;
  94. Uint8 expectedR, expectedG, expectedB, expectedA;
  95. Uint8 actualR, actualG, actualB, actualA;
  96. int deltaR, deltaG, deltaB, deltaA;
  97. /* Create dst surface */
  98. dst = SDL_CreateSurface(1, 1, dst_format);
  99. SDLTest_AssertCheck(dst != NULL, "Verify dst surface is not NULL");
  100. if (dst == NULL) {
  101. return;
  102. }
  103. /* Clear surface. */
  104. if (SDL_ISPIXELFORMAT_INDEXED(dst_format)) {
  105. SDL_Palette *palette = SDL_CreateSurfacePalette(dst);
  106. DitherPalette(palette);
  107. palette->colors[0].r = dstR;
  108. palette->colors[0].g = dstG;
  109. palette->colors[0].b = dstB;
  110. palette->colors[0].a = dstA;
  111. color = 0;
  112. } else {
  113. color = SDL_MapSurfaceRGBA(dst, dstR, dstG, dstB, dstA);
  114. SDLTest_AssertPass("Call to SDL_MapSurfaceRGBA()");
  115. }
  116. ret = SDL_FillSurfaceRect(dst, NULL, color);
  117. SDLTest_AssertPass("Call to SDL_FillSurfaceRect()");
  118. SDLTest_AssertCheck(ret == SDL_TRUE, "Verify result from SDL_FillSurfaceRect, expected: SDL_TRUE, got: %i", ret);
  119. SDL_GetRGBA(color, SDL_GetPixelFormatDetails(dst->format), SDL_GetSurfacePalette(dst), &dstR, &dstG, &dstB, &dstA);
  120. /* Create src surface */
  121. src = SDL_CreateSurface(1, 1, src_format);
  122. SDLTest_AssertCheck(src != NULL, "Verify src surface is not NULL");
  123. if (src == NULL) {
  124. return;
  125. }
  126. if (SDL_ISPIXELFORMAT_INDEXED(src_format)) {
  127. SDL_Palette *palette = SDL_CreateSurfacePalette(src);
  128. palette->colors[0].r = srcR;
  129. palette->colors[0].g = srcG;
  130. palette->colors[0].b = srcB;
  131. palette->colors[0].a = srcA;
  132. }
  133. /* Reset alpha modulation */
  134. ret = SDL_SetSurfaceAlphaMod(src, 255);
  135. SDLTest_AssertPass("Call to SDL_SetSurfaceAlphaMod()");
  136. SDLTest_AssertCheck(ret == SDL_TRUE, "Verify result from SDL_SetSurfaceAlphaMod(), expected: SDL_TRUE, got: %i", ret);
  137. /* Reset color modulation */
  138. ret = SDL_SetSurfaceColorMod(src, 255, 255, 255);
  139. SDLTest_AssertPass("Call to SDL_SetSurfaceColorMod()");
  140. SDLTest_AssertCheck(ret == SDL_TRUE, "Verify result from SDL_SetSurfaceColorMod(), expected: SDL_TRUE, got: %i", ret);
  141. /* Reset color key */
  142. ret = SDL_SetSurfaceColorKey(src, SDL_FALSE, 0);
  143. SDLTest_AssertPass("Call to SDL_SetSurfaceColorKey()");
  144. SDLTest_AssertCheck(ret == SDL_TRUE, "Verify result from SDL_SetSurfaceColorKey(), expected: SDL_TRUE, got: %i", ret);
  145. /* Clear surface. */
  146. color = SDL_MapSurfaceRGBA(src, srcR, srcG, srcB, srcA);
  147. SDLTest_AssertPass("Call to SDL_MapSurfaceRGBA()");
  148. ret = SDL_FillSurfaceRect(src, NULL, color);
  149. SDLTest_AssertPass("Call to SDL_FillSurfaceRect()");
  150. SDLTest_AssertCheck(ret == SDL_TRUE, "Verify result from SDL_FillSurfaceRect, expected: SDL_TRUE, got: %i", ret);
  151. SDL_GetRGBA(color, SDL_GetPixelFormatDetails(src->format), SDL_GetSurfacePalette(src), &srcR, &srcG, &srcB, &srcA);
  152. /* Set blend mode. */
  153. if (mode >= 0) {
  154. ret = SDL_SetSurfaceBlendMode(src, (SDL_BlendMode)mode);
  155. SDLTest_AssertPass("Call to SDL_SetSurfaceBlendMode()");
  156. SDLTest_AssertCheck(ret == SDL_TRUE, "Verify result from SDL_SetSurfaceBlendMode(..., %i), expected: SDL_TRUE, got: %i", mode, ret);
  157. } else {
  158. ret = SDL_SetSurfaceBlendMode(src, SDL_BLENDMODE_BLEND);
  159. SDLTest_AssertPass("Call to SDL_SetSurfaceBlendMode()");
  160. SDLTest_AssertCheck(ret == SDL_TRUE, "Verify result from SDL_SetSurfaceBlendMode(..., %i), expected: SDL_TRUE, got: %i", mode, ret);
  161. }
  162. /* Test blend mode. */
  163. #define FLOAT(X) ((float)X / 255.0f)
  164. switch (mode) {
  165. case -1:
  166. /* Set color mod. */
  167. ret = SDL_SetSurfaceColorMod(src, srcR, srcG, srcB);
  168. SDLTest_AssertCheck(ret == SDL_TRUE, "Validate results from calls to SDL_SetSurfaceColorMod, expected: SDL_TRUE, got: %i", ret);
  169. expectedR = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcR) * FLOAT(srcR)) * FLOAT(srcA) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  170. expectedG = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcG) * FLOAT(srcG)) * FLOAT(srcA) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  171. expectedB = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcB) * FLOAT(srcB)) * FLOAT(srcA) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  172. expectedA = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcA) + FLOAT(dstA) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  173. break;
  174. case -2:
  175. /* Set alpha mod. */
  176. ret = SDL_SetSurfaceAlphaMod(src, srcA);
  177. SDLTest_AssertCheck(ret == SDL_TRUE, "Validate results from calls to SDL_SetSurfaceAlphaMod, expected: SDL_TRUE, got: %i", ret);
  178. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * (FLOAT(srcA) * FLOAT(srcA)) + FLOAT(dstR) * (1.0f - (FLOAT(srcA) * FLOAT(srcA))), 0.0f, 1.0f) * 255.0f);
  179. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * (FLOAT(srcA) * FLOAT(srcA)) + FLOAT(dstG) * (1.0f - (FLOAT(srcA) * FLOAT(srcA))), 0.0f, 1.0f) * 255.0f);
  180. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * (FLOAT(srcA) * FLOAT(srcA)) + FLOAT(dstB) * (1.0f - (FLOAT(srcA) * FLOAT(srcA))), 0.0f, 1.0f) * 255.0f);
  181. expectedA = (Uint8)SDL_roundf(SDL_clamp((FLOAT(srcA) * FLOAT(srcA)) + FLOAT(dstA) * (1.0f - (FLOAT(srcA) * FLOAT(srcA))), 0.0f, 1.0f) * 255.0f);
  182. break;
  183. case SDL_BLENDMODE_NONE:
  184. expectedR = srcR;
  185. expectedG = srcG;
  186. expectedB = srcB;
  187. expectedA = SDL_ISPIXELFORMAT_ALPHA(dst_format) ? srcA : 255;
  188. break;
  189. case SDL_BLENDMODE_BLEND:
  190. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(srcA) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  191. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(srcA) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  192. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(srcA) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  193. expectedA = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcA) + FLOAT(dstA) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  194. break;
  195. case SDL_BLENDMODE_BLEND_PREMULTIPLIED:
  196. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  197. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  198. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  199. expectedA = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcA) + FLOAT(dstA) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  200. break;
  201. case SDL_BLENDMODE_ADD:
  202. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(srcA) + FLOAT(dstR), 0.0f, 1.0f) * 255.0f);
  203. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(srcA) + FLOAT(dstG), 0.0f, 1.0f) * 255.0f);
  204. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(srcA) + FLOAT(dstB), 0.0f, 1.0f) * 255.0f);
  205. expectedA = dstA;
  206. break;
  207. case SDL_BLENDMODE_ADD_PREMULTIPLIED:
  208. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) + FLOAT(dstR), 0.0f, 1.0f) * 255.0f);
  209. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) + FLOAT(dstG), 0.0f, 1.0f) * 255.0f);
  210. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) + FLOAT(dstB), 0.0f, 1.0f) * 255.0f);
  211. expectedA = dstA;
  212. break;
  213. case SDL_BLENDMODE_MOD:
  214. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(dstR), 0.0f, 1.0f) * 255.0f);
  215. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(dstG), 0.0f, 1.0f) * 255.0f);
  216. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(dstB), 0.0f, 1.0f) * 255.0f);
  217. expectedA = dstA;
  218. break;
  219. case SDL_BLENDMODE_MUL:
  220. expectedR = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcR) * FLOAT(dstR) + FLOAT(dstR) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  221. expectedG = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcG) * FLOAT(dstG) + FLOAT(dstG) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  222. expectedB = (Uint8)SDL_roundf(SDL_clamp(FLOAT(srcB) * FLOAT(dstB) + FLOAT(dstB) * (1.0f - FLOAT(srcA)), 0.0f, 1.0f) * 255.0f);
  223. expectedA = dstA;
  224. break;
  225. default:
  226. SDLTest_LogError("Invalid blending mode: %d", mode);
  227. return;
  228. }
  229. if (SDL_ISPIXELFORMAT_INDEXED(dst_format)) {
  230. SDL_Palette *palette = SDL_GetSurfacePalette(dst);
  231. palette->colors[1].r = expectedR;
  232. palette->colors[1].g = expectedG;
  233. palette->colors[1].b = expectedB;
  234. palette->colors[1].a = expectedA;
  235. }
  236. /* Blitting. */
  237. ret = SDL_BlitSurface(src, NULL, dst, NULL);
  238. SDLTest_AssertCheck(ret == SDL_TRUE, "Validate results from calls to SDL_BlitSurface, expected: SDL_TRUE, got: %i: %s", ret, !ret ? SDL_GetError() : "success");
  239. if (ret) {
  240. SDL_ReadSurfacePixel(dst, 0, 0, &actualR, &actualG, &actualB, &actualA);
  241. deltaR = SDL_abs((int)actualR - expectedR);
  242. deltaG = SDL_abs((int)actualG - expectedG);
  243. deltaB = SDL_abs((int)actualB - expectedB);
  244. deltaA = SDL_abs((int)actualA - expectedA);
  245. SDLTest_AssertCheck(
  246. deltaR <= MAXIMUM_ERROR &&
  247. deltaG <= MAXIMUM_ERROR &&
  248. deltaB <= MAXIMUM_ERROR &&
  249. deltaA <= MAXIMUM_ERROR,
  250. "Checking %s -> %s blit results, expected %d,%d,%d,%d, got %d,%d,%d,%d",
  251. SDL_GetPixelFormatName(src_format),
  252. SDL_GetPixelFormatName(dst_format),
  253. expectedR, expectedG, expectedB, expectedA, actualR, actualG, actualB, actualA);
  254. }
  255. /* Clean up */
  256. SDL_DestroySurface(src);
  257. SDL_DestroySurface(dst);
  258. }
  259. static void testBlitBlendMode(int mode)
  260. {
  261. const SDL_PixelFormat src_formats[] = {
  262. SDL_PIXELFORMAT_INDEX8, SDL_PIXELFORMAT_XRGB8888, SDL_PIXELFORMAT_ARGB8888
  263. };
  264. const SDL_PixelFormat dst_formats[] = {
  265. SDL_PIXELFORMAT_XRGB8888, SDL_PIXELFORMAT_ARGB8888
  266. };
  267. int i, j;
  268. for (i = 0; i < SDL_arraysize(src_formats); ++i) {
  269. for (j = 0; j < SDL_arraysize(dst_formats); ++j) {
  270. testBlitBlendModeWithFormats(mode, src_formats[i], dst_formats[j]);
  271. }
  272. }
  273. }
  274. /* Helper to check that a file exists */
  275. static void AssertFileExist(const char *filename)
  276. {
  277. struct stat st;
  278. int ret = stat(filename, &st);
  279. SDLTest_AssertCheck(ret == 0, "Verify file '%s' exists", filename);
  280. }
  281. /* Test case functions */
  282. /**
  283. * Tests sprite saving and loading
  284. */
  285. static int surface_testSaveLoadBitmap(void *arg)
  286. {
  287. int ret;
  288. const char *sampleFilename = "testSaveLoadBitmap.bmp";
  289. SDL_Surface *face;
  290. SDL_Surface *rface;
  291. /* Create sample surface */
  292. face = SDLTest_ImageFace();
  293. SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
  294. if (face == NULL) {
  295. return TEST_ABORTED;
  296. }
  297. /* Delete test file; ignore errors */
  298. unlink(sampleFilename);
  299. /* Save a surface */
  300. ret = SDL_SaveBMP(face, sampleFilename);
  301. SDLTest_AssertPass("Call to SDL_SaveBMP()");
  302. SDLTest_AssertCheck(ret == SDL_TRUE, "Verify result from SDL_SaveBMP, expected: SDL_TRUE, got: %i", ret);
  303. AssertFileExist(sampleFilename);
  304. /* Load a surface */
  305. rface = SDL_LoadBMP(sampleFilename);
  306. SDLTest_AssertPass("Call to SDL_LoadBMP()");
  307. SDLTest_AssertCheck(rface != NULL, "Verify result from SDL_LoadBMP is not NULL");
  308. if (rface != NULL) {
  309. SDLTest_AssertCheck(face->w == rface->w, "Verify width of loaded surface, expected: %i, got: %i", face->w, rface->w);
  310. SDLTest_AssertCheck(face->h == rface->h, "Verify height of loaded surface, expected: %i, got: %i", face->h, rface->h);
  311. }
  312. /* Delete test file; ignore errors */
  313. unlink(sampleFilename);
  314. /* Clean up */
  315. SDL_DestroySurface(face);
  316. face = NULL;
  317. SDL_DestroySurface(rface);
  318. rface = NULL;
  319. return TEST_COMPLETED;
  320. }
  321. /**
  322. * Tests tiled blitting.
  323. */
  324. static int surface_testBlitTiled(void *arg)
  325. {
  326. SDL_Surface *face = NULL;
  327. SDL_Surface *testSurface2x = NULL;
  328. SDL_Surface *referenceSurface2x = NULL;
  329. int ret = 0;
  330. /* Create sample surface */
  331. face = SDLTest_ImageFace();
  332. SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
  333. if (face == NULL) {
  334. return TEST_ABORTED;
  335. }
  336. /* Tiled blit - 1.0 scale */
  337. {
  338. ret = SDL_BlitSurfaceTiled(face, NULL, testSurface, NULL);
  339. SDLTest_AssertCheck(ret == SDL_TRUE, "Verify result from SDL_BlitSurfaceTiled expected: SDL_TRUE, got: %i", ret);
  340. /* See if it's the same */
  341. SDL_DestroySurface(referenceSurface);
  342. referenceSurface = SDLTest_ImageBlitTiled();
  343. ret = SDLTest_CompareSurfaces(testSurface, referenceSurface, 0);
  344. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  345. }
  346. /* Tiled blit - 2.0 scale */
  347. {
  348. testSurface2x = SDL_CreateSurface(testSurface->w * 2, testSurface->h * 2, testSurface->format);
  349. SDLTest_AssertCheck(testSurface != NULL, "Check that testSurface2x is not NULL");
  350. ret = SDL_FillSurfaceRect(testSurface2x, NULL, SDL_MapSurfaceRGBA(testSurface2x, 0, 0, 0, 255));
  351. SDLTest_AssertCheck(ret == SDL_TRUE, "Validate result from SDL_FillSurfaceRect, expected: SDL_TRUE, got: %i", ret);
  352. ret = SDL_BlitSurfaceTiledWithScale(face, NULL, 2.0f, SDL_SCALEMODE_NEAREST, testSurface2x, NULL);
  353. SDLTest_AssertCheck(ret == SDL_TRUE, "Validate results from call to SDL_BlitSurfaceTiledWithScale, expected: SDL_TRUE, got: %i", ret);
  354. /* See if it's the same */
  355. referenceSurface2x = SDL_CreateSurface(referenceSurface->w * 2, referenceSurface->h * 2, referenceSurface->format);
  356. SDL_BlitSurfaceScaled(referenceSurface, NULL, referenceSurface2x, NULL, SDL_SCALEMODE_NEAREST);
  357. SDLTest_AssertCheck(ret == SDL_TRUE, "Validate results from call to SDL_BlitSurfaceScaled, expected: SDL_TRUE, got: %i", ret);
  358. ret = SDLTest_CompareSurfaces(testSurface2x, referenceSurface2x, 0);
  359. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  360. }
  361. /* Clean up. */
  362. SDL_DestroySurface(face);
  363. SDL_DestroySurface(testSurface2x);
  364. SDL_DestroySurface(referenceSurface2x);
  365. return TEST_COMPLETED;
  366. }
  367. static const Uint8 COLOR_SEPARATION = 85;
  368. static void Fill9GridReferenceSurface(SDL_Surface *surface, int left_width, int right_width, int top_height, int bottom_height)
  369. {
  370. SDL_Rect rect;
  371. // Upper left
  372. rect.x = 0;
  373. rect.y = 0;
  374. rect.w = left_width;
  375. rect.h = top_height;
  376. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 1 * COLOR_SEPARATION, 1 * COLOR_SEPARATION, 0));
  377. // Top
  378. rect.x = left_width;
  379. rect.y = 0;
  380. rect.w = surface->w - left_width - right_width;
  381. rect.h = top_height;
  382. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 2 * COLOR_SEPARATION, 1 * COLOR_SEPARATION, 0));
  383. // Upper right
  384. rect.x = surface->w - right_width;
  385. rect.y = 0;
  386. rect.w = right_width;
  387. rect.h = top_height;
  388. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 3 * COLOR_SEPARATION, 1 * COLOR_SEPARATION, 0));
  389. // Left
  390. rect.x = 0;
  391. rect.y = top_height;
  392. rect.w = left_width;
  393. rect.h = surface->h - top_height - bottom_height;
  394. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 1 * COLOR_SEPARATION, 2 * COLOR_SEPARATION, 0));
  395. // Center
  396. rect.x = left_width;
  397. rect.y = top_height;
  398. rect.w = surface->w - right_width - left_width;
  399. rect.h = surface->h - top_height - bottom_height;
  400. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 2 * COLOR_SEPARATION, 2 * COLOR_SEPARATION, 0));
  401. // Right
  402. rect.x = surface->w - right_width;
  403. rect.y = top_height;
  404. rect.w = right_width;
  405. rect.h = surface->h - top_height - bottom_height;
  406. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 3 * COLOR_SEPARATION, 2 * COLOR_SEPARATION, 0));
  407. // Lower left
  408. rect.x = 0;
  409. rect.y = surface->h - bottom_height;
  410. rect.w = left_width;
  411. rect.h = bottom_height;
  412. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 1 * COLOR_SEPARATION, 3 * COLOR_SEPARATION, 0));
  413. // Bottom
  414. rect.x = left_width;
  415. rect.y = surface->h - bottom_height;
  416. rect.w = surface->w - left_width - right_width;
  417. rect.h = bottom_height;
  418. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 2 * COLOR_SEPARATION, 3 * COLOR_SEPARATION, 0));
  419. // Lower right
  420. rect.x = surface->w - right_width;
  421. rect.y = surface->h - bottom_height;
  422. rect.w = right_width;
  423. rect.h = bottom_height;
  424. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 3 * COLOR_SEPARATION, 3 * COLOR_SEPARATION, 0));
  425. }
  426. /**
  427. * Tests 9-grid blitting.
  428. */
  429. static int surface_testBlit9Grid(void *arg)
  430. {
  431. SDL_Surface *source = NULL;
  432. int x, y;
  433. int ret = 0;
  434. /* Create source surface */
  435. source = SDL_CreateSurface(3, 3, SDL_PIXELFORMAT_RGBA32);
  436. SDLTest_AssertCheck(source != NULL, "Verify source surface is not NULL");
  437. for (y = 0; y < 3; ++y) {
  438. for (x = 0; x < 3; ++x) {
  439. SDL_WriteSurfacePixel(source, x, y, (Uint8)((1 + x) * COLOR_SEPARATION), (Uint8)((1 + y) * COLOR_SEPARATION), 0, 255);
  440. }
  441. }
  442. /* 9-grid blit - 1.0 scale */
  443. {
  444. /* Create reference surface */
  445. SDL_DestroySurface(referenceSurface);
  446. referenceSurface = SDL_CreateSurface(testSurface->w, testSurface->h, testSurface->format);
  447. SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
  448. Fill9GridReferenceSurface(referenceSurface, 1, 1, 1, 1);
  449. ret = SDL_BlitSurface9Grid(source, NULL, 1, 1, 1, 1, 0.0f, SDL_SCALEMODE_NEAREST, testSurface, NULL);
  450. SDLTest_AssertCheck(ret == SDL_TRUE, "Validate result from SDL_BlitSurface9Grid, expected: SDL_TRUE, got: %i", ret);
  451. ret = SDLTest_CompareSurfaces(testSurface, referenceSurface, 0);
  452. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  453. }
  454. /* 9-grid blit - 2.0 scale */
  455. {
  456. /* Create reference surface */
  457. SDL_DestroySurface(referenceSurface);
  458. referenceSurface = SDL_CreateSurface(testSurface->w, testSurface->h, testSurface->format);
  459. SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
  460. Fill9GridReferenceSurface(referenceSurface, 2, 2, 2, 2);
  461. ret = SDL_BlitSurface9Grid(source, NULL, 1, 1, 1, 1, 2.0f, SDL_SCALEMODE_NEAREST, testSurface, NULL);
  462. SDLTest_AssertCheck(ret == SDL_TRUE, "Validate result from SDL_BlitSurface9Grid, expected: SDL_TRUE, got: %i", ret);
  463. ret = SDLTest_CompareSurfaces(testSurface, referenceSurface, 0);
  464. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  465. }
  466. /* Clean up. */
  467. SDL_DestroySurface(source);
  468. /* Create complex source surface */
  469. source = SDL_CreateSurface(5, 5, SDL_PIXELFORMAT_RGBA32);
  470. SDLTest_AssertCheck(source != NULL, "Verify source surface is not NULL");
  471. SDL_WriteSurfacePixel(source, 0, 0, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
  472. SDL_WriteSurfacePixel(source, 1, 0, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
  473. SDL_WriteSurfacePixel(source, 2, 0, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
  474. SDL_WriteSurfacePixel(source, 3, 0, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
  475. SDL_WriteSurfacePixel(source, 4, 0, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
  476. SDL_WriteSurfacePixel(source, 0, 1, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  477. SDL_WriteSurfacePixel(source, 1, 1, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  478. SDL_WriteSurfacePixel(source, 2, 1, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  479. SDL_WriteSurfacePixel(source, 3, 1, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  480. SDL_WriteSurfacePixel(source, 4, 1, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  481. SDL_WriteSurfacePixel(source, 0, 2, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  482. SDL_WriteSurfacePixel(source, 1, 2, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  483. SDL_WriteSurfacePixel(source, 2, 2, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  484. SDL_WriteSurfacePixel(source, 3, 2, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  485. SDL_WriteSurfacePixel(source, 4, 2, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  486. SDL_WriteSurfacePixel(source, 0, 3, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  487. SDL_WriteSurfacePixel(source, 1, 3, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  488. SDL_WriteSurfacePixel(source, 2, 3, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  489. SDL_WriteSurfacePixel(source, 3, 3, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  490. SDL_WriteSurfacePixel(source, 4, 3, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  491. SDL_WriteSurfacePixel(source, 0, 4, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  492. SDL_WriteSurfacePixel(source, 1, 4, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  493. SDL_WriteSurfacePixel(source, 2, 4, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  494. SDL_WriteSurfacePixel(source, 3, 4, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  495. SDL_WriteSurfacePixel(source, 4, 4, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  496. /* complex 9-grid blit - 1.0 scale */
  497. {
  498. SDLTest_Log("complex 9-grid blit - 1.0 scale");
  499. /* Create reference surface */
  500. SDL_DestroySurface(referenceSurface);
  501. referenceSurface = SDL_CreateSurface(testSurface->w, testSurface->h, testSurface->format);
  502. SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
  503. Fill9GridReferenceSurface(referenceSurface, 1, 2, 1, 2);
  504. ret = SDL_BlitSurface9Grid(source, NULL, 1, 2, 1, 2, 0.0f, SDL_SCALEMODE_NEAREST, testSurface, NULL);
  505. SDLTest_AssertCheck(ret == SDL_TRUE, "Validate result from SDL_BlitSurface9Grid, expected: SDL_TRUE, got: %i", ret);
  506. ret = SDLTest_CompareSurfaces(testSurface, referenceSurface, 0);
  507. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  508. }
  509. /* complex 9-grid blit - 2.0 scale */
  510. {
  511. SDLTest_Log("complex 9-grid blit - 2.0 scale");
  512. /* Create reference surface */
  513. SDL_DestroySurface(referenceSurface);
  514. referenceSurface = SDL_CreateSurface(testSurface->w, testSurface->h, testSurface->format);
  515. SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
  516. Fill9GridReferenceSurface(referenceSurface, 2, 4, 2, 4);
  517. ret = SDL_BlitSurface9Grid(source, NULL, 1, 2, 1, 2, 2.0f, SDL_SCALEMODE_NEAREST, testSurface, NULL);
  518. SDLTest_AssertCheck(ret == SDL_TRUE, "Validate result from SDL_BlitSurface9Grid, expected: SDL_TRUE, got: %i", ret);
  519. ret = SDLTest_CompareSurfaces(testSurface, referenceSurface, 0);
  520. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  521. }
  522. /* Clean up. */
  523. SDL_DestroySurface(source);
  524. return TEST_COMPLETED;
  525. }
  526. /**
  527. * Tests blitting between multiple surfaces of the same format
  528. */
  529. static int surface_testBlitMultiple(void *arg)
  530. {
  531. SDL_Surface *source, *surface;
  532. SDL_Palette *palette;
  533. Uint8 *pixels;
  534. palette = SDL_CreatePalette(2);
  535. SDLTest_AssertCheck(palette != NULL, "SDL_CreatePalette()");
  536. palette->colors[0].r = 0;
  537. palette->colors[0].g = 0;
  538. palette->colors[0].b = 0;
  539. palette->colors[1].r = 0xFF;
  540. palette->colors[1].g = 0;
  541. palette->colors[1].b = 0;
  542. source = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_INDEX8);
  543. SDLTest_AssertCheck(source != NULL, "SDL_CreateSurface()");
  544. SDL_SetSurfacePalette(source, palette);
  545. *(Uint8 *)source->pixels = 1;
  546. /* Set up a blit to a surface using the palette */
  547. surface = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_INDEX8);
  548. SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()");
  549. SDL_SetSurfacePalette(surface, palette);
  550. pixels = (Uint8 *)surface->pixels;
  551. *pixels = 0;
  552. SDL_BlitSurface(source, NULL, surface, NULL);
  553. SDLTest_AssertCheck(*pixels == 1, "Expected *pixels == 1 got %u", *pixels);
  554. /* Set up a blit to another surface using the same palette */
  555. SDL_DestroySurface(surface);
  556. surface = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_INDEX8);
  557. SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()");
  558. SDL_SetSurfacePalette(surface, palette);
  559. pixels = (Uint8 *)surface->pixels;
  560. *pixels = 0;
  561. SDL_BlitSurface(source, NULL, surface, NULL);
  562. SDLTest_AssertCheck(*pixels == 1, "Expected *pixels == 1 got %u", *pixels);
  563. /* Set up a blit to new surface with a different format */
  564. SDL_DestroySurface(surface);
  565. surface = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_RGBA32);
  566. SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()");
  567. pixels = (Uint8 *)surface->pixels;
  568. SDL_BlitSurface(source, NULL, surface, NULL);
  569. SDLTest_AssertCheck(*pixels == 0xFF, "Expected *pixels == 0xFF got 0x%.2X", *pixels);
  570. /* Set up a blit to another surface with the same format */
  571. SDL_DestroySurface(surface);
  572. surface = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_RGBA32);
  573. SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()");
  574. pixels = (Uint8 *)surface->pixels;
  575. SDL_BlitSurface(source, NULL, surface, NULL);
  576. SDLTest_AssertCheck(*pixels == 0xFF, "Expected *pixels == 0xFF got 0x%.2X", *pixels);
  577. SDL_DestroyPalette(palette);
  578. SDL_DestroySurface(source);
  579. SDL_DestroySurface(surface);
  580. return TEST_COMPLETED;
  581. }
  582. /**
  583. * Tests surface conversion.
  584. */
  585. static int surface_testSurfaceConversion(void *arg)
  586. {
  587. SDL_Surface *rface = NULL, *face = NULL;
  588. int ret = 0;
  589. /* Create sample surface */
  590. face = SDLTest_ImageFace();
  591. SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
  592. if (face == NULL) {
  593. return TEST_ABORTED;
  594. }
  595. /* Set transparent pixel as the pixel at (0,0) */
  596. if (SDL_GetSurfacePalette(face)) {
  597. ret = SDL_SetSurfaceColorKey(face, SDL_TRUE, *(Uint8 *)face->pixels);
  598. SDLTest_AssertPass("Call to SDL_SetSurfaceColorKey()");
  599. SDLTest_AssertCheck(ret == SDL_TRUE, "Verify result from SDL_SetSurfaceColorKey, expected: SDL_TRUE, got: %i", ret);
  600. }
  601. /* Convert to 32 bit to compare. */
  602. rface = SDL_ConvertSurface(face, testSurface->format);
  603. SDLTest_AssertPass("Call to SDL_ConvertSurface()");
  604. SDLTest_AssertCheck(rface != NULL, "Verify result from SDL_ConvertSurface is not NULL");
  605. /* Compare surface. */
  606. ret = SDLTest_CompareSurfaces(rface, face, 0);
  607. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  608. /* Clean up. */
  609. SDL_DestroySurface(face);
  610. face = NULL;
  611. SDL_DestroySurface(rface);
  612. rface = NULL;
  613. return TEST_COMPLETED;
  614. }
  615. /**
  616. * Tests surface conversion across all pixel formats.
  617. */
  618. static int surface_testCompleteSurfaceConversion(void *arg)
  619. {
  620. Uint32 pixel_formats[] = {
  621. SDL_PIXELFORMAT_INDEX8,
  622. SDL_PIXELFORMAT_RGB332,
  623. SDL_PIXELFORMAT_XRGB4444,
  624. SDL_PIXELFORMAT_XBGR4444,
  625. SDL_PIXELFORMAT_XRGB1555,
  626. SDL_PIXELFORMAT_XBGR1555,
  627. SDL_PIXELFORMAT_ARGB4444,
  628. SDL_PIXELFORMAT_RGBA4444,
  629. SDL_PIXELFORMAT_ABGR4444,
  630. SDL_PIXELFORMAT_BGRA4444,
  631. SDL_PIXELFORMAT_ARGB1555,
  632. SDL_PIXELFORMAT_RGBA5551,
  633. SDL_PIXELFORMAT_ABGR1555,
  634. SDL_PIXELFORMAT_BGRA5551,
  635. SDL_PIXELFORMAT_RGB565,
  636. SDL_PIXELFORMAT_BGR565,
  637. SDL_PIXELFORMAT_RGB24,
  638. SDL_PIXELFORMAT_BGR24,
  639. SDL_PIXELFORMAT_XRGB8888,
  640. SDL_PIXELFORMAT_RGBX8888,
  641. SDL_PIXELFORMAT_XBGR8888,
  642. SDL_PIXELFORMAT_BGRX8888,
  643. SDL_PIXELFORMAT_ARGB8888,
  644. SDL_PIXELFORMAT_RGBA8888,
  645. SDL_PIXELFORMAT_ABGR8888,
  646. SDL_PIXELFORMAT_BGRA8888,
  647. #if 0 /* We aren't testing HDR10 colorspace conversion */
  648. SDL_PIXELFORMAT_XRGB2101010,
  649. SDL_PIXELFORMAT_XBGR2101010,
  650. SDL_PIXELFORMAT_ARGB2101010,
  651. SDL_PIXELFORMAT_ABGR2101010,
  652. #endif
  653. };
  654. SDL_Surface *face = NULL, *cvt1, *cvt2, *final;
  655. const SDL_PixelFormatDetails *fmt1, *fmt2;
  656. int i, j, ret = 0;
  657. /* Create sample surface */
  658. face = SDLTest_ImageFace();
  659. SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
  660. if (face == NULL) {
  661. return TEST_ABORTED;
  662. }
  663. /* Set transparent pixel as the pixel at (0,0) */
  664. if (SDL_GetSurfacePalette(face)) {
  665. ret = SDL_SetSurfaceColorKey(face, SDL_TRUE, *(Uint8 *)face->pixels);
  666. SDLTest_AssertPass("Call to SDL_SetSurfaceColorKey()");
  667. SDLTest_AssertCheck(ret == SDL_TRUE, "Verify result from SDL_SetSurfaceColorKey, expected: SDL_TRUE, got: %i", ret);
  668. }
  669. for (i = 0; i < SDL_arraysize(pixel_formats); ++i) {
  670. for (j = 0; j < SDL_arraysize(pixel_formats); ++j) {
  671. fmt1 = SDL_GetPixelFormatDetails(pixel_formats[i]);
  672. SDLTest_AssertCheck(fmt1 != NULL, "SDL_GetPixelFormatDetails(%s[0x%08" SDL_PRIx32 "]) should return a non-null pixel format",
  673. SDL_GetPixelFormatName(pixel_formats[i]), pixel_formats[i]);
  674. cvt1 = SDL_ConvertSurface(face, fmt1->format);
  675. SDLTest_AssertCheck(cvt1 != NULL, "SDL_ConvertSurface(..., %s[0x%08" SDL_PRIx32 "]) should return a non-null surface",
  676. SDL_GetPixelFormatName(pixel_formats[i]), pixel_formats[i]);
  677. fmt2 = SDL_GetPixelFormatDetails(pixel_formats[j]);
  678. SDLTest_AssertCheck(fmt2 != NULL, "SDL_GetPixelFormatDetails(%s[0x%08" SDL_PRIx32 "]) should return a non-null pixel format",
  679. SDL_GetPixelFormatName(pixel_formats[i]), pixel_formats[i]);
  680. cvt2 = SDL_ConvertSurface(cvt1, fmt2->format);
  681. SDLTest_AssertCheck(cvt2 != NULL, "SDL_ConvertSurface(..., %s[0x%08" SDL_PRIx32 "]) should return a non-null surface",
  682. SDL_GetPixelFormatName(pixel_formats[i]), pixel_formats[i]);
  683. if (fmt1 && fmt2 &&
  684. fmt1->bytes_per_pixel == SDL_BYTESPERPIXEL(face->format) &&
  685. fmt2->bytes_per_pixel == SDL_BYTESPERPIXEL(face->format) &&
  686. SDL_ISPIXELFORMAT_ALPHA(fmt1->format) == SDL_ISPIXELFORMAT_ALPHA(face->format) &&
  687. SDL_ISPIXELFORMAT_ALPHA(fmt2->format) == SDL_ISPIXELFORMAT_ALPHA(face->format)) {
  688. final = SDL_ConvertSurface(cvt2, face->format);
  689. SDL_assert(final != NULL);
  690. /* Compare surface. */
  691. ret = SDLTest_CompareSurfaces(face, final, 0);
  692. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  693. SDL_DestroySurface(final);
  694. }
  695. SDL_DestroySurface(cvt1);
  696. SDL_DestroySurface(cvt2);
  697. }
  698. }
  699. /* Clean up. */
  700. SDL_DestroySurface(face);
  701. return TEST_COMPLETED;
  702. }
  703. /**
  704. * Tests sprite loading. A failure case.
  705. */
  706. static int surface_testLoadFailure(void *arg)
  707. {
  708. SDL_Surface *face = SDL_LoadBMP("nonexistant.bmp");
  709. SDLTest_AssertCheck(face == NULL, "SDL_CreateLoadBmp");
  710. return TEST_COMPLETED;
  711. }
  712. /**
  713. * Tests some blitting routines.
  714. */
  715. static int surface_testBlit(void *arg)
  716. {
  717. /* Basic blitting */
  718. testBlitBlendMode(SDL_BLENDMODE_NONE);
  719. return TEST_COMPLETED;
  720. }
  721. /**
  722. * Tests some blitting routines with color mod
  723. */
  724. static int surface_testBlitColorMod(void *arg)
  725. {
  726. /* Basic blitting with color mod */
  727. testBlitBlendMode(-1);
  728. return TEST_COMPLETED;
  729. }
  730. /**
  731. * Tests some blitting routines with alpha mod
  732. */
  733. static int surface_testBlitAlphaMod(void *arg)
  734. {
  735. /* Basic blitting with alpha mod */
  736. testBlitBlendMode(-2);
  737. return TEST_COMPLETED;
  738. }
  739. /**
  740. * Tests some more blitting routines.
  741. */
  742. static int surface_testBlitBlendBlend(void *arg)
  743. {
  744. /* Blend blitting */
  745. testBlitBlendMode(SDL_BLENDMODE_BLEND);
  746. return TEST_COMPLETED;
  747. }
  748. /**
  749. * @brief Tests some more blitting routines.
  750. */
  751. static int surface_testBlitBlendPremultiplied(void *arg)
  752. {
  753. /* Blend premultiplied blitting */
  754. testBlitBlendMode(SDL_BLENDMODE_BLEND_PREMULTIPLIED);
  755. return TEST_COMPLETED;
  756. }
  757. /**
  758. * Tests some more blitting routines.
  759. */
  760. static int surface_testBlitBlendAdd(void *arg)
  761. {
  762. /* Add blitting */
  763. testBlitBlendMode(SDL_BLENDMODE_ADD);
  764. return TEST_COMPLETED;
  765. }
  766. /**
  767. * Tests some more blitting routines.
  768. */
  769. static int surface_testBlitBlendAddPremultiplied(void *arg)
  770. {
  771. /* Add premultiplied blitting */
  772. testBlitBlendMode(SDL_BLENDMODE_ADD_PREMULTIPLIED);
  773. return TEST_COMPLETED;
  774. }
  775. /**
  776. * Tests some more blitting routines.
  777. */
  778. static int surface_testBlitBlendMod(void *arg)
  779. {
  780. /* Mod blitting */
  781. testBlitBlendMode(SDL_BLENDMODE_MOD);
  782. return TEST_COMPLETED;
  783. }
  784. /**
  785. * Tests some more blitting routines.
  786. */
  787. static int surface_testBlitBlendMul(void *arg)
  788. {
  789. /* Mod blitting */
  790. testBlitBlendMode(SDL_BLENDMODE_MUL);
  791. return TEST_COMPLETED;
  792. }
  793. static int surface_testOverflow(void *arg)
  794. {
  795. char buf[1024];
  796. const char *expectedError;
  797. SDL_Surface *surface;
  798. SDL_memset(buf, '\0', sizeof(buf));
  799. expectedError = "Parameter 'width' is invalid";
  800. surface = SDL_CreateSurface(-3, 100, SDL_PIXELFORMAT_INDEX8);
  801. SDLTest_AssertCheck(surface == NULL, "Should detect negative width");
  802. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  803. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  804. surface = SDL_CreateSurfaceFrom(-1, 1, SDL_PIXELFORMAT_INDEX8, buf, 4);
  805. SDLTest_AssertCheck(surface == NULL, "Should detect negative width");
  806. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  807. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  808. surface = SDL_CreateSurfaceFrom(-1, 1, SDL_PIXELFORMAT_RGBA8888, buf, 4);
  809. SDLTest_AssertCheck(surface == NULL, "Should detect negative width");
  810. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  811. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  812. expectedError = "Parameter 'height' is invalid";
  813. surface = SDL_CreateSurface(100, -3, SDL_PIXELFORMAT_INDEX8);
  814. SDLTest_AssertCheck(surface == NULL, "Should detect negative height");
  815. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  816. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  817. surface = SDL_CreateSurfaceFrom(1, -1, SDL_PIXELFORMAT_INDEX8, buf, 4);
  818. SDLTest_AssertCheck(surface == NULL, "Should detect negative height");
  819. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  820. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  821. surface = SDL_CreateSurfaceFrom(1, -1, SDL_PIXELFORMAT_RGBA8888, buf, 4);
  822. SDLTest_AssertCheck(surface == NULL, "Should detect negative height");
  823. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  824. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  825. expectedError = "Parameter 'pitch' is invalid";
  826. surface = SDL_CreateSurfaceFrom(4, 1, SDL_PIXELFORMAT_INDEX8, buf, -1);
  827. SDLTest_AssertCheck(surface == NULL, "Should detect negative pitch");
  828. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  829. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  830. surface = SDL_CreateSurfaceFrom(1, 1, SDL_PIXELFORMAT_RGBA8888, buf, -1);
  831. SDLTest_AssertCheck(surface == NULL, "Should detect negative pitch");
  832. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  833. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  834. surface = SDL_CreateSurfaceFrom(1, 1, SDL_PIXELFORMAT_RGBA8888, buf, 0);
  835. SDLTest_AssertCheck(surface == NULL, "Should detect zero pitch");
  836. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  837. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  838. surface = SDL_CreateSurfaceFrom(1, 1, SDL_PIXELFORMAT_RGBA8888, NULL, 0);
  839. SDLTest_AssertCheck(surface != NULL, "Allow zero pitch for partially set up surfaces: %s",
  840. surface != NULL ? "(success)" : SDL_GetError());
  841. SDL_DestroySurface(surface);
  842. /* Less than 1 byte per pixel: the pitch can legitimately be less than
  843. * the width, but it must be enough to hold the appropriate number of
  844. * bits per pixel. SDL_PIXELFORMAT_INDEX4* needs 1 byte per 2 pixels. */
  845. surface = SDL_CreateSurfaceFrom(6, 1, SDL_PIXELFORMAT_INDEX4LSB, buf, 3);
  846. SDLTest_AssertCheck(surface != NULL, "6px * 4 bits per px fits in 3 bytes: %s",
  847. surface != NULL ? "(success)" : SDL_GetError());
  848. SDL_DestroySurface(surface);
  849. surface = SDL_CreateSurfaceFrom(6, 1, SDL_PIXELFORMAT_INDEX4MSB, buf, 3);
  850. SDLTest_AssertCheck(surface != NULL, "6px * 4 bits per px fits in 3 bytes: %s",
  851. surface != NULL ? "(success)" : SDL_GetError());
  852. SDL_DestroySurface(surface);
  853. surface = SDL_CreateSurfaceFrom(7, 1, SDL_PIXELFORMAT_INDEX4LSB, buf, 3);
  854. SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
  855. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  856. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  857. surface = SDL_CreateSurfaceFrom(7, 1, SDL_PIXELFORMAT_INDEX4MSB, buf, 3);
  858. SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
  859. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  860. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  861. surface = SDL_CreateSurfaceFrom(7, 1, SDL_PIXELFORMAT_INDEX4LSB, buf, 4);
  862. SDLTest_AssertCheck(surface != NULL, "7px * 4 bits per px fits in 4 bytes: %s",
  863. surface != NULL ? "(success)" : SDL_GetError());
  864. SDL_DestroySurface(surface);
  865. surface = SDL_CreateSurfaceFrom(7, 1, SDL_PIXELFORMAT_INDEX4MSB, buf, 4);
  866. SDLTest_AssertCheck(surface != NULL, "7px * 4 bits per px fits in 4 bytes: %s",
  867. surface != NULL ? "(success)" : SDL_GetError());
  868. SDL_DestroySurface(surface);
  869. /* SDL_PIXELFORMAT_INDEX2* needs 1 byte per 4 pixels. */
  870. surface = SDL_CreateSurfaceFrom(12, 1, SDL_PIXELFORMAT_INDEX2LSB, buf, 3);
  871. SDLTest_AssertCheck(surface != NULL, "12px * 2 bits per px fits in 3 bytes: %s",
  872. surface != NULL ? "(success)" : SDL_GetError());
  873. SDL_DestroySurface(surface);
  874. surface = SDL_CreateSurfaceFrom(12, 1, SDL_PIXELFORMAT_INDEX2MSB, buf, 3);
  875. SDLTest_AssertCheck(surface != NULL, "12px * 2 bits per px fits in 3 bytes: %s",
  876. surface != NULL ? "(success)" : SDL_GetError());
  877. SDL_DestroySurface(surface);
  878. surface = SDL_CreateSurfaceFrom(13, 1, SDL_PIXELFORMAT_INDEX2LSB, buf, 3);
  879. SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp (%d)", surface ? surface->pitch : 0);
  880. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  881. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  882. surface = SDL_CreateSurfaceFrom(13, 1, SDL_PIXELFORMAT_INDEX2MSB, buf, 3);
  883. SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
  884. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  885. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  886. surface = SDL_CreateSurfaceFrom(13, 1, SDL_PIXELFORMAT_INDEX2LSB, buf, 4);
  887. SDLTest_AssertCheck(surface != NULL, "13px * 2 bits per px fits in 4 bytes: %s",
  888. surface != NULL ? "(success)" : SDL_GetError());
  889. SDL_DestroySurface(surface);
  890. surface = SDL_CreateSurfaceFrom(13, 1, SDL_PIXELFORMAT_INDEX2MSB, buf, 4);
  891. SDLTest_AssertCheck(surface != NULL, "13px * 2 bits per px fits in 4 bytes: %s",
  892. surface != NULL ? "(success)" : SDL_GetError());
  893. SDL_DestroySurface(surface);
  894. /* SDL_PIXELFORMAT_INDEX1* needs 1 byte per 8 pixels. */
  895. surface = SDL_CreateSurfaceFrom(16, 1, SDL_PIXELFORMAT_INDEX1LSB, buf, 2);
  896. SDLTest_AssertCheck(surface != NULL, "16px * 1 bit per px fits in 2 bytes: %s",
  897. surface != NULL ? "(success)" : SDL_GetError());
  898. SDL_DestroySurface(surface);
  899. surface = SDL_CreateSurfaceFrom(16, 1, SDL_PIXELFORMAT_INDEX1MSB, buf, 2);
  900. SDLTest_AssertCheck(surface != NULL, "16px * 1 bit per px fits in 2 bytes: %s",
  901. surface != NULL ? "(success)" : SDL_GetError());
  902. SDL_DestroySurface(surface);
  903. surface = SDL_CreateSurfaceFrom(17, 1, SDL_PIXELFORMAT_INDEX1LSB, buf, 2);
  904. SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
  905. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  906. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  907. surface = SDL_CreateSurfaceFrom(17, 1, SDL_PIXELFORMAT_INDEX1MSB, buf, 2);
  908. SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
  909. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  910. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  911. surface = SDL_CreateSurfaceFrom(17, 1, SDL_PIXELFORMAT_INDEX1LSB, buf, 3);
  912. SDLTest_AssertCheck(surface != NULL, "17px * 1 bit per px fits in 3 bytes: %s",
  913. surface != NULL ? "(success)" : SDL_GetError());
  914. SDL_DestroySurface(surface);
  915. surface = SDL_CreateSurfaceFrom(17, 1, SDL_PIXELFORMAT_INDEX1MSB, buf, 3);
  916. SDLTest_AssertCheck(surface != NULL, "17px * 1 bit per px fits in 3 bytes: %s",
  917. surface != NULL ? "(success)" : SDL_GetError());
  918. SDL_DestroySurface(surface);
  919. /* SDL_PIXELFORMAT_INDEX8 and SDL_PIXELFORMAT_RGB332 require 1 byte per pixel. */
  920. surface = SDL_CreateSurfaceFrom(5, 1, SDL_PIXELFORMAT_RGB332, buf, 5);
  921. SDLTest_AssertCheck(surface != NULL, "5px * 8 bits per px fits in 5 bytes: %s",
  922. surface != NULL ? "(success)" : SDL_GetError());
  923. SDL_DestroySurface(surface);
  924. surface = SDL_CreateSurfaceFrom(5, 1, SDL_PIXELFORMAT_INDEX8, buf, 5);
  925. SDLTest_AssertCheck(surface != NULL, "5px * 8 bits per px fits in 5 bytes: %s",
  926. surface != NULL ? "(success)" : SDL_GetError());
  927. SDL_DestroySurface(surface);
  928. surface = SDL_CreateSurfaceFrom(6, 1, SDL_PIXELFORMAT_RGB332, buf, 5);
  929. SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
  930. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  931. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  932. surface = SDL_CreateSurfaceFrom(6, 1, SDL_PIXELFORMAT_INDEX8, buf, 5);
  933. SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
  934. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  935. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  936. /* Everything else requires more than 1 byte per pixel, and rounds up
  937. * each pixel to an integer number of bytes (e.g. RGB555 is really
  938. * XRGB1555, with 1 bit per pixel wasted). */
  939. surface = SDL_CreateSurfaceFrom(3, 1, SDL_PIXELFORMAT_XRGB1555, buf, 6);
  940. SDLTest_AssertCheck(surface != NULL, "3px * 15 (really 16) bits per px fits in 6 bytes: %s",
  941. surface != NULL ? "(success)" : SDL_GetError());
  942. SDL_DestroySurface(surface);
  943. surface = SDL_CreateSurfaceFrom(3, 1, SDL_PIXELFORMAT_XRGB1555, buf, 6);
  944. SDLTest_AssertCheck(surface != NULL, "5px * 15 (really 16) bits per px fits in 6 bytes: %s",
  945. surface != NULL ? "(success)" : SDL_GetError());
  946. SDL_DestroySurface(surface);
  947. surface = SDL_CreateSurfaceFrom(4, 1, SDL_PIXELFORMAT_XRGB1555, buf, 6);
  948. SDLTest_AssertCheck(surface == NULL, "4px * 15 (really 16) bits per px doesn't fit in 6 bytes");
  949. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  950. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  951. surface = SDL_CreateSurfaceFrom(4, 1, SDL_PIXELFORMAT_XRGB1555, buf, 6);
  952. SDLTest_AssertCheck(surface == NULL, "4px * 15 (really 16) bits per px doesn't fit in 6 bytes");
  953. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  954. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  955. if (sizeof(size_t) == 4 && sizeof(int) >= 4) {
  956. SDL_ClearError();
  957. expectedError = "aligning pitch would overflow";
  958. /* 0x5555'5555 * 3bpp = 0xffff'ffff which fits in size_t, but adding
  959. * alignment padding makes it overflow */
  960. surface = SDL_CreateSurface(0x55555555, 1, SDL_PIXELFORMAT_RGB24);
  961. SDLTest_AssertCheck(surface == NULL, "Should detect overflow in pitch + alignment");
  962. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  963. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  964. SDL_ClearError();
  965. expectedError = "width * bpp would overflow";
  966. /* 0x4000'0000 * 4bpp = 0x1'0000'0000 which (just) overflows */
  967. surface = SDL_CreateSurface(0x40000000, 1, SDL_PIXELFORMAT_ARGB8888);
  968. SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * bytes per pixel");
  969. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  970. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  971. SDL_ClearError();
  972. expectedError = "height * pitch would overflow";
  973. surface = SDL_CreateSurface((1 << 29) - 1, (1 << 29) - 1, SDL_PIXELFORMAT_INDEX8);
  974. SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * height");
  975. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  976. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  977. SDL_ClearError();
  978. expectedError = "height * pitch would overflow";
  979. surface = SDL_CreateSurface((1 << 15) + 1, (1 << 15) + 1, SDL_PIXELFORMAT_ARGB8888);
  980. SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * height * bytes per pixel");
  981. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  982. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  983. } else {
  984. SDLTest_Log("Can't easily overflow size_t on this platform");
  985. }
  986. return TEST_COMPLETED;
  987. }
  988. static int surface_testFlip(void *arg)
  989. {
  990. SDL_Surface *surface;
  991. Uint8 *pixels;
  992. int offset;
  993. const char *expectedError;
  994. surface = SDL_CreateSurface(3, 3, SDL_PIXELFORMAT_RGB24);
  995. SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()");
  996. SDL_ClearError();
  997. expectedError = "Parameter 'surface' is invalid";
  998. SDL_FlipSurface(NULL, SDL_FLIP_HORIZONTAL);
  999. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  1000. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  1001. SDL_ClearError();
  1002. expectedError = "Parameter 'flip' is invalid";
  1003. SDL_FlipSurface(surface, SDL_FLIP_NONE);
  1004. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  1005. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  1006. pixels = (Uint8 *)surface->pixels;
  1007. *pixels = 0xFF;
  1008. offset = 0;
  1009. SDLTest_AssertPass("Call to SDL_FlipSurface(surface, SDL_FLIP_VERTICAL)");
  1010. CHECK_FUNC(SDL_FlipSurface, (surface, SDL_FLIP_VERTICAL));
  1011. SDLTest_AssertCheck(pixels[offset] == 0x00,
  1012. "Expected pixels[%d] == 0x00 got 0x%.2X", offset, pixels[offset]);
  1013. offset = 2 * surface->pitch;
  1014. SDLTest_AssertCheck(pixels[offset] == 0xFF,
  1015. "Expected pixels[%d] == 0xFF got 0x%.2X", offset, pixels[offset]);
  1016. SDLTest_AssertPass("Call to SDL_FlipSurface(surface, SDL_FLIP_HORIZONTAL)");
  1017. CHECK_FUNC(SDL_FlipSurface, (surface, SDL_FLIP_HORIZONTAL));
  1018. SDLTest_AssertCheck(pixels[offset] == 0x00,
  1019. "Expected pixels[%d] == 0x00 got 0x%.2X", offset, pixels[offset]);
  1020. offset += (surface->w - 1) * SDL_BYTESPERPIXEL(surface->format);
  1021. SDLTest_AssertCheck(pixels[offset] == 0xFF,
  1022. "Expected pixels[%d] == 0xFF got 0x%.2X", offset, pixels[offset]);
  1023. SDL_DestroySurface(surface);
  1024. return TEST_COMPLETED;
  1025. }
  1026. static int surface_testPalette(void *arg)
  1027. {
  1028. SDL_Surface *source, *surface, *output;
  1029. SDL_Palette *palette;
  1030. Uint8 *pixels;
  1031. palette = SDL_CreatePalette(2);
  1032. SDLTest_AssertCheck(palette != NULL, "SDL_CreatePalette()");
  1033. source = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_INDEX8);
  1034. SDLTest_AssertCheck(source != NULL, "SDL_CreateSurface()");
  1035. SDLTest_AssertCheck(SDL_GetSurfacePalette(source) == NULL, "SDL_GetSurfacePalette(source)");
  1036. surface = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_INDEX8);
  1037. SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()");
  1038. SDLTest_AssertCheck(SDL_GetSurfacePalette(surface) == NULL, "SDL_GetSurfacePalette(surface)");
  1039. pixels = (Uint8 *)surface->pixels;
  1040. SDLTest_AssertCheck(*pixels == 0, "Expected *pixels == 0 got %u", *pixels);
  1041. /* Identity copy between indexed surfaces without a palette */
  1042. *(Uint8 *)source->pixels = 1;
  1043. SDL_BlitSurface(source, NULL, surface, NULL);
  1044. SDLTest_AssertCheck(*pixels == 1, "Expected *pixels == 1 got %u", *pixels);
  1045. /* Identity copy between indexed surfaces where the source has a palette */
  1046. palette->colors[0].r = 0;
  1047. palette->colors[0].g = 0;
  1048. palette->colors[0].b = 0;
  1049. palette->colors[1].r = 0xFF;
  1050. palette->colors[1].g = 0;
  1051. palette->colors[1].b = 0;
  1052. SDL_SetSurfacePalette(source, palette);
  1053. *pixels = 0;
  1054. SDL_BlitSurface(source, NULL, surface, NULL);
  1055. SDLTest_AssertCheck(*pixels == 1, "Expected *pixels == 1 got %u", *pixels);
  1056. /* Identity copy between indexed surfaces where the destination has a palette */
  1057. palette->colors[0].r = 0;
  1058. palette->colors[0].g = 0;
  1059. palette->colors[0].b = 0;
  1060. palette->colors[1].r = 0xFF;
  1061. palette->colors[1].g = 0;
  1062. palette->colors[1].b = 0;
  1063. SDL_SetSurfacePalette(source, NULL);
  1064. SDL_SetSurfacePalette(surface, palette);
  1065. *pixels = 0;
  1066. SDL_BlitSurface(source, NULL, surface, NULL);
  1067. SDLTest_AssertCheck(*pixels == 1, "Expected *pixels == 1 got %u", *pixels);
  1068. /* Identity copy between indexed surfaces where the source and destination share a palette */
  1069. palette->colors[0].r = 0;
  1070. palette->colors[0].g = 0;
  1071. palette->colors[0].b = 0;
  1072. palette->colors[1].r = 0xFF;
  1073. palette->colors[1].g = 0;
  1074. palette->colors[1].b = 0;
  1075. SDL_SetSurfacePalette(source, palette);
  1076. SDL_SetSurfacePalette(surface, palette);
  1077. *pixels = 0;
  1078. SDL_BlitSurface(source, NULL, surface, NULL);
  1079. SDLTest_AssertCheck(*pixels == 1, "Expected *pixels == 1 got %u", *pixels);
  1080. output = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_RGBA32);
  1081. SDLTest_AssertCheck(output != NULL, "SDL_CreateSurface()");
  1082. pixels = (Uint8 *)output->pixels;
  1083. SDL_BlitSurface(surface, NULL, output, NULL);
  1084. SDLTest_AssertCheck(*pixels == 0xFF, "Expected *pixels == 0xFF got 0x%.2X", *pixels);
  1085. /* Set the palette color and blit again */
  1086. palette->colors[1].r = 0xAA;
  1087. SDL_SetSurfacePalette(surface, palette);
  1088. SDL_BlitSurface(surface, NULL, output, NULL);
  1089. SDLTest_AssertCheck(*pixels == 0xAA, "Expected *pixels == 0xAA got 0x%.2X", *pixels);
  1090. SDL_DestroyPalette(palette);
  1091. SDL_DestroySurface(source);
  1092. SDL_DestroySurface(surface);
  1093. SDL_DestroySurface(output);
  1094. return TEST_COMPLETED;
  1095. }
  1096. static int surface_testPalettization(void *arg)
  1097. {
  1098. const SDL_Color palette_colors[] = {
  1099. { 0x80, 0x00, 0x00, 0xff },
  1100. { 0x00, 0x80, 0x00, 0xff },
  1101. { 0x00, 0x00, 0x80, 0xff },
  1102. { 0x40, 0x00, 0x00, 0xff },
  1103. { 0x00, 0x40, 0x00, 0xff },
  1104. { 0x00, 0x00, 0x40, 0xff },
  1105. { 0x00, 0x00, 0x00, 0xff },
  1106. { 0xff, 0x00, 0x00, 0xff },
  1107. { 0x00, 0xff, 0x00, 0xff },
  1108. { 0x00, 0x00, 0xff, 0xff },
  1109. { 0xff, 0xff, 0x00, 0xff },
  1110. { 0x00, 0xff, 0xff, 0xff },
  1111. { 0xff, 0x00, 0xff, 0xff },
  1112. };
  1113. const struct {
  1114. SDL_Color c;
  1115. Uint8 e;
  1116. } colors[] = {
  1117. { { 0xff, 0x00, 0x00, 0xff }, 7 },
  1118. { { 0xfe, 0x00, 0x00, 0xff }, 7 },
  1119. { { 0xfd, 0x00, 0x00, 0xff }, 7 },
  1120. { { 0xf0, 0x00, 0x00, 0xff }, 7 },
  1121. { { 0xd0, 0x00, 0x00, 0xff }, 7 },
  1122. { { 0xb0, 0x00, 0x00, 0xff }, 0 },
  1123. { { 0xa0, 0x00, 0x00, 0xff }, 0 },
  1124. { { 0xff, 0x00, 0x00, 0x00 }, 7 },
  1125. { { 0x00, 0x10, 0x21, 0xff }, 5 },
  1126. { { 0x00, 0x10, 0x19, 0xff }, 6 },
  1127. { { 0x81, 0x00, 0x41, 0xff }, 0 },
  1128. { { 0x80, 0xf0, 0xf0, 0x7f }, 11 },
  1129. { { 0x00, 0x00, 0x00, 0xff }, 6 },
  1130. { { 0x00, 0x00, 0x00, 0x01 }, 6 },
  1131. };
  1132. int i;
  1133. int result;
  1134. SDL_Surface *source, *output;
  1135. SDL_Palette *palette;
  1136. Uint8 *pixels;
  1137. palette = SDL_CreatePalette(SDL_arraysize(palette_colors));
  1138. SDLTest_AssertCheck(palette != NULL, "SDL_CreatePalette()");
  1139. result = SDL_SetPaletteColors(palette, palette_colors, 0, SDL_arraysize(palette_colors));
  1140. SDLTest_AssertCheck(result, "SDL_SetPaletteColors()");
  1141. source = SDL_CreateSurface(SDL_arraysize(palette_colors) + SDL_arraysize(colors), 1, SDL_PIXELFORMAT_RGBA8888);
  1142. SDLTest_AssertCheck(source != NULL, "SDL_CreateSurface()");
  1143. SDLTest_AssertCheck(source->w == SDL_arraysize(palette_colors) + SDL_arraysize(colors), "Expected source->w == %d, got %d", (int)(SDL_arraysize(palette_colors) + SDL_arraysize(colors)), source->w);
  1144. SDLTest_AssertCheck(source->h == 1, "Expected source->h == %d, got %d", 1, source->h);
  1145. SDLTest_AssertCheck(source->format == SDL_PIXELFORMAT_RGBA8888, "Expected source->format == SDL_PIXELFORMAT_RGBA8888, got 0x%x (%s)", source->format, SDL_GetPixelFormatName(source->format));
  1146. for (i = 0; i < SDL_arraysize(colors); i++) {
  1147. result = SDL_WriteSurfacePixel(source, i, 0, colors[i].c.r, colors[i].c.g, colors[i].c.b, colors[i].c.a);
  1148. SDLTest_AssertCheck(result == SDL_TRUE, "SDL_WriteSurfacePixel");
  1149. }
  1150. for (i = 0; i < SDL_arraysize(palette_colors); i++) {
  1151. result = SDL_WriteSurfacePixel(source, SDL_arraysize(colors) + i, 0, palette_colors[i].r, palette_colors[i].g, palette_colors[i].b, palette_colors[i].a);
  1152. SDLTest_AssertCheck(result == SDL_TRUE, "SDL_WriteSurfacePixel");
  1153. }
  1154. output = SDL_ConvertSurfaceAndColorspace(source, SDL_PIXELFORMAT_INDEX8, palette, SDL_COLORSPACE_UNKNOWN, 0);
  1155. SDLTest_AssertCheck(output != NULL, "SDL_ConvertSurfaceAndColorspace()");
  1156. SDLTest_AssertCheck(output->w == source->w, "Expected output->w == %d, got %d", source->w, output->w);
  1157. SDLTest_AssertCheck(output->h == source->h, "Expected output->h == %d, got %d", source->h, output->h);
  1158. SDLTest_AssertCheck(output->format == SDL_PIXELFORMAT_INDEX8, "Expected output->format == SDL_PIXELFORMAT_INDEX8, got 0x%x (%s)", output->format, SDL_GetPixelFormatName(output->format));
  1159. pixels = output->pixels;
  1160. for (i = 0; i < SDL_arraysize(colors); i++) {
  1161. int idx = i;
  1162. Uint8 actual = pixels[idx];
  1163. Uint8 expected = colors[i].e;
  1164. SDLTest_AssertCheck(0 <= actual && actual < SDL_arraysize(palette_colors), "0 <= output->pixels[%d] < %d", idx, (int)SDL_arraysize(palette_colors));
  1165. SDLTest_AssertCheck(actual == expected, "Expected output->pixels[%d] == %u, got %u", idx, expected, actual);
  1166. }
  1167. SDLTest_AssertPass("Check palette 1:1 mapping");
  1168. for (i = 0; i < SDL_arraysize(palette_colors); i++) {
  1169. int idx = SDL_arraysize(colors) + i;
  1170. Uint8 actual = pixels[idx];
  1171. Uint8 expected = i;
  1172. SDLTest_AssertCheck(0 <= actual && actual < SDL_arraysize(palette_colors), "0 <= output->pixels[%d] < %d", idx, (int)SDL_arraysize(palette_colors));
  1173. SDLTest_AssertCheck(actual == expected, "Expected output->pixels[%d] == %u, got %u", idx, expected, actual);
  1174. }
  1175. SDL_DestroyPalette(palette);
  1176. SDL_DestroySurface(source);
  1177. SDL_DestroySurface(output);
  1178. return TEST_COMPLETED;
  1179. }
  1180. static int surface_testClearSurface(void *arg)
  1181. {
  1182. SDL_PixelFormat formats[] = {
  1183. SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGBA8888,
  1184. SDL_PIXELFORMAT_ARGB2101010, SDL_PIXELFORMAT_ABGR2101010,
  1185. SDL_PIXELFORMAT_ARGB64, SDL_PIXELFORMAT_RGBA64,
  1186. SDL_PIXELFORMAT_ARGB128_FLOAT, SDL_PIXELFORMAT_RGBA128_FLOAT,
  1187. SDL_PIXELFORMAT_YV12, SDL_PIXELFORMAT_UYVY, SDL_PIXELFORMAT_NV12
  1188. };
  1189. SDL_Surface *surface;
  1190. SDL_PixelFormat format;
  1191. const float MAXIMUM_ERROR_RGB = 0.0001f;
  1192. const float MAXIMUM_ERROR_YUV = 0.01f;
  1193. float srcR = 10 / 255.0f, srcG = 128 / 255.0f, srcB = 240 / 255.0f, srcA = 1.0f;
  1194. float actualR, actualG, actualB, actualA;
  1195. float deltaR, deltaG, deltaB, deltaA;
  1196. int i, ret;
  1197. for (i = 0; i < SDL_arraysize(formats); ++i) {
  1198. const float MAXIMUM_ERROR = SDL_ISPIXELFORMAT_FOURCC(formats[i]) ? MAXIMUM_ERROR_YUV : MAXIMUM_ERROR_RGB;
  1199. format = formats[i];
  1200. surface = SDL_CreateSurface(1, 1, format);
  1201. SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()");
  1202. ret = SDL_ClearSurface(surface, srcR, srcG, srcB, srcA);
  1203. SDLTest_AssertCheck(ret == SDL_TRUE, "SDL_ClearSurface()");
  1204. ret = SDL_ReadSurfacePixelFloat(surface, 0, 0, &actualR, &actualG, &actualB, &actualA);
  1205. SDLTest_AssertCheck(ret == SDL_TRUE, "SDL_ReadSurfacePixelFloat()");
  1206. deltaR = SDL_fabsf(actualR - srcR);
  1207. deltaG = SDL_fabsf(actualG - srcG);
  1208. deltaB = SDL_fabsf(actualB - srcB);
  1209. deltaA = SDL_fabsf(actualA - srcA);
  1210. SDLTest_AssertCheck(
  1211. deltaR <= MAXIMUM_ERROR &&
  1212. deltaG <= MAXIMUM_ERROR &&
  1213. deltaB <= MAXIMUM_ERROR &&
  1214. deltaA <= MAXIMUM_ERROR,
  1215. "Checking %s surface clear results, expected %.4f,%.4f,%.4f,%.4f, got %.4f,%.4f,%.4f,%.4f",
  1216. SDL_GetPixelFormatName(format),
  1217. srcR, srcG, srcB, srcA, actualR, actualG, actualB, actualA);
  1218. SDL_DestroySurface(surface);
  1219. }
  1220. return TEST_COMPLETED;
  1221. }
  1222. static int surface_testPremultiplyAlpha(void *arg)
  1223. {
  1224. SDL_PixelFormat formats[] = {
  1225. SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGBA8888,
  1226. SDL_PIXELFORMAT_ARGB2101010, SDL_PIXELFORMAT_ABGR2101010,
  1227. SDL_PIXELFORMAT_ARGB64, SDL_PIXELFORMAT_RGBA64,
  1228. SDL_PIXELFORMAT_ARGB128_FLOAT, SDL_PIXELFORMAT_RGBA128_FLOAT,
  1229. };
  1230. SDL_Surface *surface;
  1231. SDL_PixelFormat format;
  1232. const float MAXIMUM_ERROR_LOW_PRECISION = 1 / 255.0f;
  1233. const float MAXIMUM_ERROR_HIGH_PRECISION = 0.0001f;
  1234. float srcR = 10 / 255.0f, srcG = 128 / 255.0f, srcB = 240 / 255.0f, srcA = 170 / 255.0f;
  1235. float expectedR = srcR * srcA;
  1236. float expectedG = srcG * srcA;
  1237. float expectedB = srcB * srcA;
  1238. float actualR, actualG, actualB;
  1239. float deltaR, deltaG, deltaB;
  1240. int i, ret;
  1241. for (i = 0; i < SDL_arraysize(formats); ++i) {
  1242. const float MAXIMUM_ERROR = (SDL_BITSPERPIXEL(formats[i]) > 32) ? MAXIMUM_ERROR_HIGH_PRECISION : MAXIMUM_ERROR_LOW_PRECISION;
  1243. format = formats[i];
  1244. surface = SDL_CreateSurface(1, 1, format);
  1245. SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()");
  1246. ret = SDL_SetSurfaceColorspace(surface, SDL_COLORSPACE_SRGB);
  1247. SDLTest_AssertCheck(ret == SDL_TRUE, "SDL_SetSurfaceColorspace()");
  1248. ret = SDL_ClearSurface(surface, srcR, srcG, srcB, srcA);
  1249. SDLTest_AssertCheck(ret == SDL_TRUE, "SDL_ClearSurface()");
  1250. ret = SDL_PremultiplySurfaceAlpha(surface, SDL_FALSE);
  1251. SDLTest_AssertCheck(ret == SDL_TRUE, "SDL_PremultiplySurfaceAlpha()");
  1252. ret = SDL_ReadSurfacePixelFloat(surface, 0, 0, &actualR, &actualG, &actualB, NULL);
  1253. SDLTest_AssertCheck(ret == SDL_TRUE, "SDL_ReadSurfacePixelFloat()");
  1254. deltaR = SDL_fabsf(actualR - expectedR);
  1255. deltaG = SDL_fabsf(actualG - expectedG);
  1256. deltaB = SDL_fabsf(actualB - expectedB);
  1257. SDLTest_AssertCheck(
  1258. deltaR <= MAXIMUM_ERROR &&
  1259. deltaG <= MAXIMUM_ERROR &&
  1260. deltaB <= MAXIMUM_ERROR,
  1261. "Checking %s alpha premultiply results, expected %.4f,%.4f,%.4f, got %.4f,%.4f,%.4f",
  1262. SDL_GetPixelFormatName(format),
  1263. expectedR, expectedG, expectedB, actualR, actualG, actualB);
  1264. SDL_DestroySurface(surface);
  1265. }
  1266. return TEST_COMPLETED;
  1267. }
  1268. /* ================= Test References ================== */
  1269. /* Surface test cases */
  1270. static const SDLTest_TestCaseReference surfaceTestSaveLoadBitmap = {
  1271. surface_testSaveLoadBitmap, "surface_testSaveLoadBitmap", "Tests sprite saving and loading.", TEST_ENABLED
  1272. };
  1273. static const SDLTest_TestCaseReference surfaceTestBlit = {
  1274. surface_testBlit, "surface_testBlit", "Tests basic blitting.", TEST_ENABLED
  1275. };
  1276. static const SDLTest_TestCaseReference surfaceTestBlitTiled = {
  1277. surface_testBlitTiled, "surface_testBlitTiled", "Tests tiled blitting.", TEST_ENABLED
  1278. };
  1279. static const SDLTest_TestCaseReference surfaceTestBlit9Grid = {
  1280. surface_testBlit9Grid, "surface_testBlit9Grid", "Tests 9-grid blitting.", TEST_ENABLED
  1281. };
  1282. static const SDLTest_TestCaseReference surfaceTestBlitMultiple = {
  1283. surface_testBlitMultiple, "surface_testBlitMultiple", "Tests blitting between multiple surfaces of the same format.", TEST_ENABLED
  1284. };
  1285. static const SDLTest_TestCaseReference surfaceTestLoadFailure = {
  1286. surface_testLoadFailure, "surface_testLoadFailure", "Tests sprite loading. A failure case.", TEST_ENABLED
  1287. };
  1288. static const SDLTest_TestCaseReference surfaceTestSurfaceConversion = {
  1289. surface_testSurfaceConversion, "surface_testSurfaceConversion", "Tests surface conversion.", TEST_ENABLED
  1290. };
  1291. static const SDLTest_TestCaseReference surfaceTestCompleteSurfaceConversion = {
  1292. surface_testCompleteSurfaceConversion, "surface_testCompleteSurfaceConversion", "Tests surface conversion across all pixel formats", TEST_ENABLED
  1293. };
  1294. static const SDLTest_TestCaseReference surfaceTestBlitColorMod = {
  1295. surface_testBlitColorMod, "surface_testBlitColorMod", "Tests some blitting routines with color mod.", TEST_ENABLED
  1296. };
  1297. static const SDLTest_TestCaseReference surfaceTestBlitAlphaMod = {
  1298. surface_testBlitAlphaMod, "surface_testBlitAlphaMod", "Tests some blitting routines with alpha mod.", TEST_ENABLED
  1299. };
  1300. static const SDLTest_TestCaseReference surfaceTestBlitBlendBlend = {
  1301. surface_testBlitBlendBlend, "surface_testBlitBlendBlend", "Tests blitting routines with blend blending mode.", TEST_ENABLED
  1302. };
  1303. static const SDLTest_TestCaseReference surfaceTestBlitBlendPremultiplied = {
  1304. surface_testBlitBlendPremultiplied, "surface_testBlitBlendPremultiplied", "Tests blitting routines with premultiplied blending mode.", TEST_ENABLED
  1305. };
  1306. static const SDLTest_TestCaseReference surfaceTestBlitBlendAdd = {
  1307. surface_testBlitBlendAdd, "surface_testBlitBlendAdd", "Tests blitting routines with add blending mode.", TEST_ENABLED
  1308. };
  1309. static const SDLTest_TestCaseReference surfaceTestBlitBlendAddPremultiplied = {
  1310. surface_testBlitBlendAddPremultiplied, "surface_testBlitBlendAddPremultiplied", "Tests blitting routines with premultiplied add blending mode.", TEST_ENABLED
  1311. };
  1312. static const SDLTest_TestCaseReference surfaceTestBlitBlendMod = {
  1313. surface_testBlitBlendMod, "surface_testBlitBlendMod", "Tests blitting routines with mod blending mode.", TEST_ENABLED
  1314. };
  1315. static const SDLTest_TestCaseReference surfaceTestBlitBlendMul = {
  1316. surface_testBlitBlendMul, "surface_testBlitBlendMul", "Tests blitting routines with mul blending mode.", TEST_ENABLED
  1317. };
  1318. static const SDLTest_TestCaseReference surfaceTestOverflow = {
  1319. surface_testOverflow, "surface_testOverflow", "Test overflow detection.", TEST_ENABLED
  1320. };
  1321. static const SDLTest_TestCaseReference surfaceTestFlip = {
  1322. surface_testFlip, "surface_testFlip", "Test surface flipping.", TEST_ENABLED
  1323. };
  1324. static const SDLTest_TestCaseReference surfaceTestPalette = {
  1325. surface_testPalette, "surface_testPalette", "Test surface palette operations.", TEST_ENABLED
  1326. };
  1327. static const SDLTest_TestCaseReference surfaceTestPalettization = {
  1328. surface_testPalettization, "surface_testPalettization", "Test surface palettization.", TEST_ENABLED
  1329. };
  1330. static const SDLTest_TestCaseReference surfaceTestClearSurface = {
  1331. surface_testClearSurface, "surface_testClearSurface", "Test clear surface operations.", TEST_ENABLED
  1332. };
  1333. static const SDLTest_TestCaseReference surfaceTestPremultiplyAlpha = {
  1334. surface_testPremultiplyAlpha, "surface_testPremultiplyAlpha", "Test alpha premultiply operations.", TEST_ENABLED
  1335. };
  1336. /* Sequence of Surface test cases */
  1337. static const SDLTest_TestCaseReference *surfaceTests[] = {
  1338. &surfaceTestSaveLoadBitmap,
  1339. &surfaceTestBlit,
  1340. &surfaceTestBlitTiled,
  1341. &surfaceTestBlit9Grid,
  1342. &surfaceTestBlitMultiple,
  1343. &surfaceTestLoadFailure,
  1344. &surfaceTestSurfaceConversion,
  1345. &surfaceTestCompleteSurfaceConversion,
  1346. &surfaceTestBlitColorMod,
  1347. &surfaceTestBlitAlphaMod,
  1348. &surfaceTestBlitBlendBlend,
  1349. &surfaceTestBlitBlendPremultiplied,
  1350. &surfaceTestBlitBlendAdd,
  1351. &surfaceTestBlitBlendAddPremultiplied,
  1352. &surfaceTestBlitBlendMod,
  1353. &surfaceTestBlitBlendMul,
  1354. &surfaceTestOverflow,
  1355. &surfaceTestFlip,
  1356. &surfaceTestPalette,
  1357. &surfaceTestPalettization,
  1358. &surfaceTestClearSurface,
  1359. &surfaceTestPremultiplyAlpha,
  1360. NULL
  1361. };
  1362. /* Surface test suite (global) */
  1363. SDLTest_TestSuiteReference surfaceTestSuite = {
  1364. "Surface",
  1365. surfaceSetUp,
  1366. surfaceTests,
  1367. surfaceTearDown
  1368. };