testautomation_surface.c 87 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039
  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. bool result = FUNC PARAMS; \
  24. if (!result) { \
  25. SDLTest_AssertCheck(result, "Validate result from %s, expected: true, got: 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 SDLCALL 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 == true, "Validate result from SDL_SetSurfaceBlendMode, expected: true, got: %i", result);
  46. result = SDL_GetSurfaceBlendMode(testSurface, &currentBlendMode);
  47. SDLTest_AssertCheck(result == true, "Validate result from SDL_GetSurfaceBlendMode, expected: 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 == true, "Validate result from SDL_FillSurfaceRect, expected: true, got: %i", result);
  52. }
  53. }
  54. static void SDLCALL 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(9, 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 == true, "Verify result from SDL_FillSurfaceRect, expected: 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(9, 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 == true, "Verify result from SDL_SetSurfaceAlphaMod(), expected: 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 == true, "Verify result from SDL_SetSurfaceColorMod(), expected: true, got: %i", ret);
  141. /* Reset color key */
  142. ret = SDL_SetSurfaceColorKey(src, false, 0);
  143. SDLTest_AssertPass("Call to SDL_SetSurfaceColorKey()");
  144. SDLTest_AssertCheck(ret == true, "Verify result from SDL_SetSurfaceColorKey(), expected: 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 == true, "Verify result from SDL_FillSurfaceRect, expected: 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 == true, "Verify result from SDL_SetSurfaceBlendMode(..., %i), expected: 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 == true, "Verify result from SDL_SetSurfaceBlendMode(..., %i), expected: 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 == true, "Validate results from calls to SDL_SetSurfaceColorMod, expected: 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 == true, "Validate results from calls to SDL_SetSurfaceAlphaMod, expected: 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 == true, "Validate results from calls to SDL_BlitSurface, expected: 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. SDLTest_AssertCheck(SDL_GetPathInfo(filename, NULL), "Verify file '%s' exists", filename);
  278. }
  279. /* Test case functions */
  280. /**
  281. * Tests creating surface with invalid format
  282. */
  283. static int SDLCALL surface_testInvalidFormat(void *arg)
  284. {
  285. SDL_Surface *surface;
  286. surface = SDL_CreateSurface(32, 32, SDL_PIXELFORMAT_UNKNOWN);
  287. SDLTest_AssertCheck(surface == NULL, "Verify SDL_CreateSurface(SDL_PIXELFORMAT_UNKNOWN) returned NULL");
  288. SDL_DestroySurface(surface);
  289. surface = SDL_CreateSurfaceFrom(32, 32, SDL_PIXELFORMAT_UNKNOWN, NULL, 0);
  290. SDLTest_AssertCheck(surface == NULL, "Verify SDL_CreateSurfaceFrom(SDL_PIXELFORMAT_UNKNOWN) returned NULL");
  291. SDL_DestroySurface(surface);
  292. return TEST_COMPLETED;
  293. }
  294. /**
  295. * Tests sprite saving and loading
  296. */
  297. static int SDLCALL surface_testSaveLoad(void *arg)
  298. {
  299. int ret;
  300. const char *sampleFilename = "testSaveLoad.tmp";
  301. SDL_Surface *face;
  302. SDL_Surface *rface;
  303. /* Create sample surface */
  304. face = SDLTest_ImageFace();
  305. SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
  306. if (face == NULL) {
  307. return TEST_ABORTED;
  308. }
  309. /* Delete test file; ignore errors */
  310. unlink(sampleFilename);
  311. /* Save a BMP surface */
  312. ret = SDL_SaveBMP(face, sampleFilename);
  313. SDLTest_AssertPass("Call to SDL_SaveBMP()");
  314. SDLTest_AssertCheck(ret == true, "Verify result from SDL_SaveBMP, expected: true, got: %i", ret);
  315. AssertFileExist(sampleFilename);
  316. /* Load a BMP surface */
  317. rface = SDL_LoadBMP(sampleFilename);
  318. SDLTest_AssertPass("Call to SDL_LoadBMP()");
  319. SDLTest_AssertCheck(rface != NULL, "Verify result from SDL_LoadBMP is not NULL");
  320. if (rface != NULL) {
  321. SDLTest_AssertCheck(face->w == rface->w, "Verify width of loaded surface, expected: %i, got: %i", face->w, rface->w);
  322. SDLTest_AssertCheck(face->h == rface->h, "Verify height of loaded surface, expected: %i, got: %i", face->h, rface->h);
  323. SDL_DestroySurface(rface);
  324. rface = NULL;
  325. }
  326. /* Delete test file; ignore errors */
  327. unlink(sampleFilename);
  328. /* Save a PNG surface */
  329. ret = SDL_SavePNG(face, sampleFilename);
  330. SDLTest_AssertPass("Call to SDL_SavePNG()");
  331. SDLTest_AssertCheck(ret == true, "Verify result from SDL_SavePNG, expected: true, got: %i", ret);
  332. AssertFileExist(sampleFilename);
  333. /* Load a PNG surface */
  334. rface = SDL_LoadPNG(sampleFilename);
  335. SDLTest_AssertPass("Call to SDL_LoadPNG()");
  336. SDLTest_AssertCheck(rface != NULL, "Verify result from SDL_LoadPNG is not NULL");
  337. if (rface != NULL) {
  338. SDLTest_AssertCheck(face->w == rface->w, "Verify width of loaded surface, expected: %i, got: %i", face->w, rface->w);
  339. SDLTest_AssertCheck(face->h == rface->h, "Verify height of loaded surface, expected: %i, got: %i", face->h, rface->h);
  340. SDL_DestroySurface(rface);
  341. rface = NULL;
  342. }
  343. /* Delete test file; ignore errors */
  344. unlink(sampleFilename);
  345. /* Clean up */
  346. SDL_DestroySurface(face);
  347. face = NULL;
  348. return TEST_COMPLETED;
  349. }
  350. /**
  351. * Tests tiled blitting.
  352. */
  353. static int SDLCALL surface_testBlitTiled(void *arg)
  354. {
  355. SDL_Surface *face = NULL;
  356. SDL_Surface *testSurface2x = NULL;
  357. SDL_Surface *referenceSurface2x = NULL;
  358. int ret = 0;
  359. /* Create sample surface */
  360. face = SDLTest_ImageFace();
  361. SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
  362. if (face == NULL) {
  363. return TEST_ABORTED;
  364. }
  365. /* Tiled blit - 1.0 scale */
  366. {
  367. ret = SDL_BlitSurfaceTiled(face, NULL, testSurface, NULL);
  368. SDLTest_AssertCheck(ret == true, "Verify result from SDL_BlitSurfaceTiled expected: true, got: %i", ret);
  369. /* See if it's the same */
  370. SDL_DestroySurface(referenceSurface);
  371. referenceSurface = SDLTest_ImageBlitTiled();
  372. ret = SDLTest_CompareSurfaces(testSurface, referenceSurface, 0);
  373. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  374. }
  375. /* Tiled blit - 2.0 scale */
  376. {
  377. testSurface2x = SDL_CreateSurface(testSurface->w * 2, testSurface->h * 2, testSurface->format);
  378. SDLTest_AssertCheck(testSurface != NULL, "Check that testSurface2x is not NULL");
  379. ret = SDL_FillSurfaceRect(testSurface2x, NULL, SDL_MapSurfaceRGBA(testSurface2x, 0, 0, 0, 255));
  380. SDLTest_AssertCheck(ret == true, "Validate result from SDL_FillSurfaceRect, expected: true, got: %i", ret);
  381. ret = SDL_BlitSurfaceTiledWithScale(face, NULL, 2.0f, SDL_SCALEMODE_NEAREST, testSurface2x, NULL);
  382. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_BlitSurfaceTiledWithScale, expected: true, got: %i", ret);
  383. /* See if it's the same */
  384. referenceSurface2x = SDL_CreateSurface(referenceSurface->w * 2, referenceSurface->h * 2, referenceSurface->format);
  385. SDL_BlitSurfaceScaled(referenceSurface, NULL, referenceSurface2x, NULL, SDL_SCALEMODE_NEAREST);
  386. SDLTest_AssertCheck(ret == true, "Validate results from call to SDL_BlitSurfaceScaled, expected: true, got: %i", ret);
  387. ret = SDLTest_CompareSurfaces(testSurface2x, referenceSurface2x, 0);
  388. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  389. }
  390. /* Tiled blit - very small scale */
  391. {
  392. float tiny_scale = 0.01f;
  393. ret = SDL_BlitSurfaceTiledWithScale(face, NULL, tiny_scale, SDL_SCALEMODE_NEAREST, testSurface, NULL);
  394. SDLTest_AssertCheck(ret == true, "Expected SDL_BlitSurfaceTiledWithScale to succeed with very small scale: %f, got: %i", tiny_scale, ret);
  395. }
  396. /* Clean up. */
  397. SDL_DestroySurface(face);
  398. SDL_DestroySurface(testSurface2x);
  399. SDL_DestroySurface(referenceSurface2x);
  400. return TEST_COMPLETED;
  401. }
  402. static const Uint8 COLOR_SEPARATION = 85;
  403. static void Fill9GridReferenceSurface(SDL_Surface *surface, int left_width, int right_width, int top_height, int bottom_height)
  404. {
  405. SDL_Rect rect;
  406. // Upper left
  407. rect.x = 0;
  408. rect.y = 0;
  409. rect.w = left_width;
  410. rect.h = top_height;
  411. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 1 * COLOR_SEPARATION, 1 * COLOR_SEPARATION, 0));
  412. // Top
  413. rect.x = left_width;
  414. rect.y = 0;
  415. rect.w = surface->w - left_width - right_width;
  416. rect.h = top_height;
  417. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 2 * COLOR_SEPARATION, 1 * COLOR_SEPARATION, 0));
  418. // Upper right
  419. rect.x = surface->w - right_width;
  420. rect.y = 0;
  421. rect.w = right_width;
  422. rect.h = top_height;
  423. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 3 * COLOR_SEPARATION, 1 * COLOR_SEPARATION, 0));
  424. // Left
  425. rect.x = 0;
  426. rect.y = top_height;
  427. rect.w = left_width;
  428. rect.h = surface->h - top_height - bottom_height;
  429. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 1 * COLOR_SEPARATION, 2 * COLOR_SEPARATION, 0));
  430. // Center
  431. rect.x = left_width;
  432. rect.y = top_height;
  433. rect.w = surface->w - right_width - left_width;
  434. rect.h = surface->h - top_height - bottom_height;
  435. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 2 * COLOR_SEPARATION, 2 * COLOR_SEPARATION, 0));
  436. // Right
  437. rect.x = surface->w - right_width;
  438. rect.y = top_height;
  439. rect.w = right_width;
  440. rect.h = surface->h - top_height - bottom_height;
  441. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 3 * COLOR_SEPARATION, 2 * COLOR_SEPARATION, 0));
  442. // Lower left
  443. rect.x = 0;
  444. rect.y = surface->h - bottom_height;
  445. rect.w = left_width;
  446. rect.h = bottom_height;
  447. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 1 * COLOR_SEPARATION, 3 * COLOR_SEPARATION, 0));
  448. // Bottom
  449. rect.x = left_width;
  450. rect.y = surface->h - bottom_height;
  451. rect.w = surface->w - left_width - right_width;
  452. rect.h = bottom_height;
  453. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 2 * COLOR_SEPARATION, 3 * COLOR_SEPARATION, 0));
  454. // Lower right
  455. rect.x = surface->w - right_width;
  456. rect.y = surface->h - bottom_height;
  457. rect.w = right_width;
  458. rect.h = bottom_height;
  459. SDL_FillSurfaceRect(surface, &rect, SDL_MapSurfaceRGB(surface, 3 * COLOR_SEPARATION, 3 * COLOR_SEPARATION, 0));
  460. }
  461. /**
  462. * Tests 9-grid blitting.
  463. */
  464. static int SDLCALL surface_testBlit9Grid(void *arg)
  465. {
  466. SDL_Surface *source = NULL;
  467. int x, y;
  468. int ret = 0;
  469. /* Create source surface */
  470. source = SDL_CreateSurface(3, 3, SDL_PIXELFORMAT_RGBA32);
  471. SDLTest_AssertCheck(source != NULL, "Verify source surface is not NULL");
  472. for (y = 0; y < 3; ++y) {
  473. for (x = 0; x < 3; ++x) {
  474. SDL_WriteSurfacePixel(source, x, y, (Uint8)((1 + x) * COLOR_SEPARATION), (Uint8)((1 + y) * COLOR_SEPARATION), 0, 255);
  475. }
  476. }
  477. /* 9-grid blit - 1.0 scale */
  478. {
  479. /* Create reference surface */
  480. SDL_DestroySurface(referenceSurface);
  481. referenceSurface = SDL_CreateSurface(testSurface->w, testSurface->h, testSurface->format);
  482. SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
  483. Fill9GridReferenceSurface(referenceSurface, 1, 1, 1, 1);
  484. ret = SDL_BlitSurface9Grid(source, NULL, 1, 1, 1, 1, 0.0f, SDL_SCALEMODE_NEAREST, testSurface, NULL);
  485. SDLTest_AssertCheck(ret == true, "Validate result from SDL_BlitSurface9Grid, expected: true, got: %i", ret);
  486. ret = SDLTest_CompareSurfaces(testSurface, referenceSurface, 0);
  487. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  488. }
  489. /* 9-grid blit - 2.0 scale */
  490. {
  491. /* Create reference surface */
  492. SDL_DestroySurface(referenceSurface);
  493. referenceSurface = SDL_CreateSurface(testSurface->w, testSurface->h, testSurface->format);
  494. SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
  495. Fill9GridReferenceSurface(referenceSurface, 2, 2, 2, 2);
  496. ret = SDL_BlitSurface9Grid(source, NULL, 1, 1, 1, 1, 2.0f, SDL_SCALEMODE_NEAREST, testSurface, NULL);
  497. SDLTest_AssertCheck(ret == true, "Validate result from SDL_BlitSurface9Grid, expected: true, got: %i", ret);
  498. ret = SDLTest_CompareSurfaces(testSurface, referenceSurface, 0);
  499. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  500. }
  501. /* Clean up. */
  502. SDL_DestroySurface(source);
  503. /* Create complex source surface */
  504. source = SDL_CreateSurface(5, 5, SDL_PIXELFORMAT_RGBA32);
  505. SDLTest_AssertCheck(source != NULL, "Verify source surface is not NULL");
  506. SDL_WriteSurfacePixel(source, 0, 0, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
  507. SDL_WriteSurfacePixel(source, 1, 0, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
  508. SDL_WriteSurfacePixel(source, 2, 0, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
  509. SDL_WriteSurfacePixel(source, 3, 0, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
  510. SDL_WriteSurfacePixel(source, 4, 0, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((1) * COLOR_SEPARATION), 0, 255);
  511. SDL_WriteSurfacePixel(source, 0, 1, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  512. SDL_WriteSurfacePixel(source, 1, 1, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  513. SDL_WriteSurfacePixel(source, 2, 1, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  514. SDL_WriteSurfacePixel(source, 3, 1, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  515. SDL_WriteSurfacePixel(source, 4, 1, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  516. SDL_WriteSurfacePixel(source, 0, 2, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  517. SDL_WriteSurfacePixel(source, 1, 2, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  518. SDL_WriteSurfacePixel(source, 2, 2, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  519. SDL_WriteSurfacePixel(source, 3, 2, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  520. SDL_WriteSurfacePixel(source, 4, 2, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((2) * COLOR_SEPARATION), 0, 255);
  521. SDL_WriteSurfacePixel(source, 0, 3, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  522. SDL_WriteSurfacePixel(source, 1, 3, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  523. SDL_WriteSurfacePixel(source, 2, 3, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  524. SDL_WriteSurfacePixel(source, 3, 3, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  525. SDL_WriteSurfacePixel(source, 4, 3, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  526. SDL_WriteSurfacePixel(source, 0, 4, (Uint8)((1) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  527. SDL_WriteSurfacePixel(source, 1, 4, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  528. SDL_WriteSurfacePixel(source, 2, 4, (Uint8)((2) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  529. SDL_WriteSurfacePixel(source, 3, 4, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  530. SDL_WriteSurfacePixel(source, 4, 4, (Uint8)((3) * COLOR_SEPARATION), (Uint8)((3) * COLOR_SEPARATION), 0, 255);
  531. /* complex 9-grid blit - 1.0 scale */
  532. {
  533. SDLTest_Log("complex 9-grid blit - 1.0 scale");
  534. /* Create reference surface */
  535. SDL_DestroySurface(referenceSurface);
  536. referenceSurface = SDL_CreateSurface(testSurface->w, testSurface->h, testSurface->format);
  537. SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
  538. Fill9GridReferenceSurface(referenceSurface, 1, 2, 1, 2);
  539. ret = SDL_BlitSurface9Grid(source, NULL, 1, 2, 1, 2, 0.0f, SDL_SCALEMODE_NEAREST, testSurface, NULL);
  540. SDLTest_AssertCheck(ret == true, "Validate result from SDL_BlitSurface9Grid, expected: true, got: %i", ret);
  541. ret = SDLTest_CompareSurfaces(testSurface, referenceSurface, 0);
  542. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  543. }
  544. /* complex 9-grid blit - 2.0 scale */
  545. {
  546. SDLTest_Log("complex 9-grid blit - 2.0 scale");
  547. /* Create reference surface */
  548. SDL_DestroySurface(referenceSurface);
  549. referenceSurface = SDL_CreateSurface(testSurface->w, testSurface->h, testSurface->format);
  550. SDLTest_AssertCheck(referenceSurface != NULL, "Verify reference surface is not NULL");
  551. Fill9GridReferenceSurface(referenceSurface, 2, 4, 2, 4);
  552. ret = SDL_BlitSurface9Grid(source, NULL, 1, 2, 1, 2, 2.0f, SDL_SCALEMODE_NEAREST, testSurface, NULL);
  553. SDLTest_AssertCheck(ret == true, "Validate result from SDL_BlitSurface9Grid, expected: true, got: %i", ret);
  554. ret = SDLTest_CompareSurfaces(testSurface, referenceSurface, 0);
  555. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  556. }
  557. /* Clean up. */
  558. SDL_DestroySurface(source);
  559. return TEST_COMPLETED;
  560. }
  561. /**
  562. * Tests blitting between multiple surfaces of the same format
  563. */
  564. static int SDLCALL surface_testBlitMultiple(void *arg)
  565. {
  566. SDL_Surface *source, *surface;
  567. SDL_Palette *palette;
  568. Uint8 *pixels;
  569. palette = SDL_CreatePalette(2);
  570. SDLTest_AssertCheck(palette != NULL, "SDL_CreatePalette()");
  571. palette->colors[0].r = 0;
  572. palette->colors[0].g = 0;
  573. palette->colors[0].b = 0;
  574. palette->colors[1].r = 0xFF;
  575. palette->colors[1].g = 0;
  576. palette->colors[1].b = 0;
  577. source = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_INDEX8);
  578. SDLTest_AssertCheck(source != NULL, "SDL_CreateSurface()");
  579. SDL_SetSurfacePalette(source, palette);
  580. *(Uint8 *)source->pixels = 1;
  581. /* Set up a blit to a surface using the palette */
  582. surface = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_INDEX8);
  583. SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()");
  584. SDL_SetSurfacePalette(surface, palette);
  585. pixels = (Uint8 *)surface->pixels;
  586. *pixels = 0;
  587. SDL_BlitSurface(source, NULL, surface, NULL);
  588. SDLTest_AssertCheck(*pixels == 1, "Expected *pixels == 1 got %u", *pixels);
  589. /* Set up a blit to another surface using the same palette */
  590. SDL_DestroySurface(surface);
  591. surface = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_INDEX8);
  592. SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()");
  593. SDL_SetSurfacePalette(surface, palette);
  594. pixels = (Uint8 *)surface->pixels;
  595. *pixels = 0;
  596. SDL_BlitSurface(source, NULL, surface, NULL);
  597. SDLTest_AssertCheck(*pixels == 1, "Expected *pixels == 1 got %u", *pixels);
  598. /* Set up a blit to new surface with a different format */
  599. SDL_DestroySurface(surface);
  600. surface = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_RGBA32);
  601. SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()");
  602. pixels = (Uint8 *)surface->pixels;
  603. SDL_BlitSurface(source, NULL, surface, NULL);
  604. SDLTest_AssertCheck(*pixels == 0xFF, "Expected *pixels == 0xFF got 0x%.2X", *pixels);
  605. /* Set up a blit to another surface with the same format */
  606. SDL_DestroySurface(surface);
  607. surface = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_RGBA32);
  608. SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()");
  609. pixels = (Uint8 *)surface->pixels;
  610. SDL_BlitSurface(source, NULL, surface, NULL);
  611. SDLTest_AssertCheck(*pixels == 0xFF, "Expected *pixels == 0xFF got 0x%.2X", *pixels);
  612. SDL_DestroyPalette(palette);
  613. SDL_DestroySurface(source);
  614. SDL_DestroySurface(surface);
  615. return TEST_COMPLETED;
  616. }
  617. /**
  618. * Tests operations on surfaces with NULL pixels
  619. */
  620. static int SDLCALL surface_testSurfaceNULLPixels(void *arg)
  621. {
  622. SDL_Surface *a, *b, *face;
  623. bool result;
  624. face = SDLTest_ImageFace();
  625. SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
  626. if (face == NULL) {
  627. return TEST_ABORTED;
  628. }
  629. /* Test blitting with NULL pixels */
  630. a = SDL_CreateSurfaceFrom(face->w, face->h, SDL_PIXELFORMAT_ARGB8888, NULL, 0);
  631. SDLTest_AssertCheck(a != NULL, "Verify result from SDL_CreateSurfaceFrom() with NULL pixels is not NULL");
  632. result = SDL_BlitSurface(a, NULL, face, NULL);
  633. SDLTest_AssertCheck(!result, "Verify result from SDL_BlitSurface() with src having NULL pixels is false");
  634. result = SDL_BlitSurface(face, NULL, a, NULL);
  635. SDLTest_AssertCheck(!result, "Verify result from SDL_BlitSurface() with dst having NULL pixels is false");
  636. b = SDL_CreateSurfaceFrom(face->w * 2, face->h * 2, SDL_PIXELFORMAT_ARGB8888, NULL, 0);
  637. SDLTest_AssertCheck(b != NULL, "Verify result from SDL_CreateSurfaceFrom() with NULL pixels is not NULL");
  638. result = SDL_BlitSurfaceScaled(b, NULL, face, NULL, SDL_SCALEMODE_NEAREST);
  639. SDLTest_AssertCheck(!result, "Verify result from SDL_BlitSurfaceScaled() with src having NULL pixels is false");
  640. result = SDL_BlitSurfaceScaled(face, NULL, b, NULL, SDL_SCALEMODE_NEAREST);
  641. SDLTest_AssertCheck(!result, "Verify result from SDL_BlitSurfaceScaled() with dst having NULL pixels is false");
  642. SDL_DestroySurface(b);
  643. b = NULL;
  644. /* Test conversion with NULL pixels */
  645. b = SDL_ConvertSurfaceAndColorspace(a, SDL_PIXELFORMAT_ABGR8888, NULL, SDL_COLORSPACE_UNKNOWN, 0);
  646. SDLTest_AssertCheck(b != NULL, "Verify result from SDL_ConvertSurfaceAndColorspace() with NULL pixels is not NULL");
  647. SDL_DestroySurface(b);
  648. b = NULL;
  649. /* Test duplication with NULL pixels */
  650. b = SDL_DuplicateSurface(a);
  651. SDLTest_AssertCheck(b != NULL, "Verify result from SDL_DuplicateSurface() with NULL pixels is not NULL");
  652. SDL_DestroySurface(b);
  653. b = NULL;
  654. /* Test scaling with NULL pixels */
  655. b = SDL_ScaleSurface(a, a->w * 2, a->h * 2, SDL_SCALEMODE_NEAREST);
  656. SDLTest_AssertCheck(b != NULL, "Verify result from SDL_ScaleSurface() with NULL pixels is not NULL");
  657. SDLTest_AssertCheck(b->pixels == NULL, "Verify pixels from SDL_ScaleSurface() is NULL");
  658. SDL_DestroySurface(b);
  659. b = NULL;
  660. /* Test filling surface with NULL pixels */
  661. result = SDL_FillSurfaceRect(a, NULL, 0);
  662. SDLTest_AssertCheck(result, "Verify result from SDL_FillSurfaceRect() with dst having NULL pixels is true");
  663. /* Clean up. */
  664. SDL_DestroySurface(face);
  665. SDL_DestroySurface(a);
  666. SDL_DestroySurface(b);
  667. return TEST_COMPLETED;
  668. }
  669. /**
  670. * Tests operations on surfaces with RLE pixels
  671. */
  672. static int SDLCALL surface_testSurfaceRLEPixels(void *arg)
  673. {
  674. SDL_Surface *face, *a, *b, *tmp;
  675. bool result;
  676. face = SDLTest_ImageFace();
  677. SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
  678. if (face == NULL) {
  679. return TEST_ABORTED;
  680. }
  681. /* Create a temporary surface to trigger RLE encoding during blit */
  682. tmp = SDL_DuplicateSurface(face);
  683. SDLTest_AssertCheck(tmp != NULL, "Verify result from SDL_DuplicateSurface() with RLE pixels is not NULL");
  684. result = SDL_SetSurfaceRLE(face, true);
  685. SDLTest_AssertCheck(result, "Verify result from SDL_SetSurfaceRLE() is true");
  686. /* Test duplication with RLE pixels */
  687. a = SDL_DuplicateSurface(face);
  688. SDLTest_AssertCheck(a != NULL, "Verify result from SDL_DuplicateSurface() with RLE pixels is not NULL");
  689. SDLTest_AssertCheck(SDL_SurfaceHasRLE(a), "Verify result from SDL_DuplicateSurface() with RLE pixels has RLE set");
  690. /* Verify that blitting from an RLE surface does RLE encode it */
  691. SDLTest_AssertCheck(!SDL_MUSTLOCK(a), "Verify initial RLE surface does not need to be locked");
  692. SDLTest_AssertCheck(a->pixels != NULL, "Verify initial RLE surface has pixels available");
  693. result = SDL_BlitSurface(a, NULL, tmp, NULL);
  694. SDLTest_AssertCheck(result, "Verify result from SDL_BlitSurface() with RLE surface is true");
  695. SDLTest_AssertCheck(SDL_MUSTLOCK(a), "Verify RLE surface after blit needs to be locked");
  696. SDLTest_AssertCheck(a->pixels == NULL, "Verify RLE surface after blit does not have pixels available");
  697. /* Test scaling with RLE pixels */
  698. b = SDL_ScaleSurface(a, a->w * 2, a->h * 2, SDL_SCALEMODE_NEAREST);
  699. SDLTest_AssertCheck(b != NULL, "Verify result from SDL_ScaleSurface() is not NULL");
  700. SDLTest_AssertCheck(SDL_SurfaceHasRLE(b), "Verify result from SDL_ScaleSurface() with RLE pixels has RLE set");
  701. /* Test scaling blitting with RLE pixels */
  702. result = SDL_BlitSurfaceScaled(a, NULL, b, NULL, SDL_SCALEMODE_NEAREST);
  703. SDLTest_AssertCheck(result, "Verify result from SDL_BlitSurfaceScaled() with src having RLE pixels is true");
  704. SDL_BlitSurface(a, NULL, tmp, NULL);
  705. SDL_DestroySurface(b);
  706. b = NULL;
  707. /* Test conversion with RLE pixels */
  708. b = SDL_ConvertSurfaceAndColorspace(a, SDL_PIXELFORMAT_ABGR8888, NULL, SDL_COLORSPACE_UNKNOWN, 0);
  709. SDLTest_AssertCheck(b != NULL, "Verify result from SDL_ConvertSurfaceAndColorspace() with RLE pixels is not NULL");
  710. SDLTest_AssertCheck(SDL_SurfaceHasRLE(b), "Verify result from SDL_ConvertSurfaceAndColorspace() with RLE pixels has RLE set");
  711. SDL_BlitSurface(a, NULL, tmp, NULL);
  712. SDL_DestroySurface(b);
  713. b = NULL;
  714. #if 0 /* This will currently fail, you must lock the surface first */
  715. /* Test filling surface with RLE pixels */
  716. result = SDL_FillSurfaceRect(a, NULL, 0);
  717. SDLTest_AssertCheck(result, "Verify result from SDL_FillSurfaceRect() with dst having RLE pixels is true");
  718. #endif
  719. /* Make sure the RLE surface still needs to be locked after surface operations */
  720. SDLTest_AssertCheck(a->pixels == NULL, "Verify RLE surface after operations does not have pixels available");
  721. /* Clean up. */
  722. SDL_DestroySurface(face);
  723. SDL_DestroySurface(a);
  724. SDL_DestroySurface(b);
  725. SDL_DestroySurface(tmp);
  726. return TEST_COMPLETED;
  727. }
  728. /**
  729. * Tests surface conversion.
  730. */
  731. static int SDLCALL surface_testSurfaceConversion(void *arg)
  732. {
  733. SDL_Surface *rface = NULL, *face = NULL;
  734. int ret = 0;
  735. /* Create sample surface */
  736. face = SDLTest_ImageFace();
  737. SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
  738. if (face == NULL) {
  739. return TEST_ABORTED;
  740. }
  741. /* Set transparent pixel as the pixel at (0,0) */
  742. if (SDL_GetSurfacePalette(face)) {
  743. ret = SDL_SetSurfaceColorKey(face, true, *(Uint8 *)face->pixels);
  744. SDLTest_AssertPass("Call to SDL_SetSurfaceColorKey()");
  745. SDLTest_AssertCheck(ret == true, "Verify result from SDL_SetSurfaceColorKey, expected: true, got: %i", ret);
  746. }
  747. /* Convert to 32 bit to compare. */
  748. rface = SDL_ConvertSurface(face, testSurface->format);
  749. SDLTest_AssertPass("Call to SDL_ConvertSurface()");
  750. SDLTest_AssertCheck(rface != NULL, "Verify result from SDL_ConvertSurface is not NULL");
  751. /* Compare surface. */
  752. ret = SDLTest_CompareSurfaces(rface, face, 0);
  753. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  754. /* Clean up. */
  755. SDL_DestroySurface(face);
  756. SDL_DestroySurface(rface);
  757. return TEST_COMPLETED;
  758. }
  759. /**
  760. * Tests surface conversion across all pixel formats.
  761. */
  762. static int SDLCALL surface_testCompleteSurfaceConversion(void *arg)
  763. {
  764. Uint32 pixel_formats[] = {
  765. SDL_PIXELFORMAT_INDEX8,
  766. SDL_PIXELFORMAT_RGB332,
  767. SDL_PIXELFORMAT_XRGB4444,
  768. SDL_PIXELFORMAT_XBGR4444,
  769. SDL_PIXELFORMAT_XRGB1555,
  770. SDL_PIXELFORMAT_XBGR1555,
  771. SDL_PIXELFORMAT_ARGB4444,
  772. SDL_PIXELFORMAT_RGBA4444,
  773. SDL_PIXELFORMAT_ABGR4444,
  774. SDL_PIXELFORMAT_BGRA4444,
  775. SDL_PIXELFORMAT_ARGB1555,
  776. SDL_PIXELFORMAT_RGBA5551,
  777. SDL_PIXELFORMAT_ABGR1555,
  778. SDL_PIXELFORMAT_BGRA5551,
  779. SDL_PIXELFORMAT_RGB565,
  780. SDL_PIXELFORMAT_BGR565,
  781. SDL_PIXELFORMAT_RGB24,
  782. SDL_PIXELFORMAT_BGR24,
  783. SDL_PIXELFORMAT_XRGB8888,
  784. SDL_PIXELFORMAT_RGBX8888,
  785. SDL_PIXELFORMAT_XBGR8888,
  786. SDL_PIXELFORMAT_BGRX8888,
  787. SDL_PIXELFORMAT_ARGB8888,
  788. SDL_PIXELFORMAT_RGBA8888,
  789. SDL_PIXELFORMAT_ABGR8888,
  790. SDL_PIXELFORMAT_BGRA8888,
  791. #if 0 /* We aren't testing HDR10 colorspace conversion */
  792. SDL_PIXELFORMAT_XRGB2101010,
  793. SDL_PIXELFORMAT_XBGR2101010,
  794. SDL_PIXELFORMAT_ARGB2101010,
  795. SDL_PIXELFORMAT_ABGR2101010,
  796. #endif
  797. };
  798. SDL_Surface *face = NULL, *cvt1, *cvt2, *final;
  799. const SDL_PixelFormatDetails *fmt1, *fmt2;
  800. int i, j, ret = 0;
  801. /* Create sample surface */
  802. face = SDLTest_ImageFace();
  803. SDLTest_AssertCheck(face != NULL, "Verify face surface is not NULL");
  804. if (face == NULL) {
  805. return TEST_ABORTED;
  806. }
  807. /* Set transparent pixel as the pixel at (0,0) */
  808. if (SDL_GetSurfacePalette(face)) {
  809. ret = SDL_SetSurfaceColorKey(face, true, *(Uint8 *)face->pixels);
  810. SDLTest_AssertPass("Call to SDL_SetSurfaceColorKey()");
  811. SDLTest_AssertCheck(ret == true, "Verify result from SDL_SetSurfaceColorKey, expected: true, got: %i", ret);
  812. }
  813. for (i = 0; i < SDL_arraysize(pixel_formats); ++i) {
  814. for (j = 0; j < SDL_arraysize(pixel_formats); ++j) {
  815. fmt1 = SDL_GetPixelFormatDetails(pixel_formats[i]);
  816. SDLTest_AssertCheck(fmt1 != NULL, "SDL_GetPixelFormatDetails(%s[0x%08" SDL_PRIx32 "]) should return a non-null pixel format",
  817. SDL_GetPixelFormatName(pixel_formats[i]), pixel_formats[i]);
  818. cvt1 = SDL_ConvertSurface(face, fmt1->format);
  819. SDLTest_AssertCheck(cvt1 != NULL, "SDL_ConvertSurface(..., %s[0x%08" SDL_PRIx32 "]) should return a non-null surface",
  820. SDL_GetPixelFormatName(pixel_formats[i]), pixel_formats[i]);
  821. fmt2 = SDL_GetPixelFormatDetails(pixel_formats[j]);
  822. SDLTest_AssertCheck(fmt2 != NULL, "SDL_GetPixelFormatDetails(%s[0x%08" SDL_PRIx32 "]) should return a non-null pixel format",
  823. SDL_GetPixelFormatName(pixel_formats[i]), pixel_formats[i]);
  824. cvt2 = SDL_ConvertSurface(cvt1, fmt2->format);
  825. SDLTest_AssertCheck(cvt2 != NULL, "SDL_ConvertSurface(..., %s[0x%08" SDL_PRIx32 "]) should return a non-null surface",
  826. SDL_GetPixelFormatName(pixel_formats[i]), pixel_formats[i]);
  827. if (fmt1 && fmt2 &&
  828. fmt1->bytes_per_pixel == SDL_BYTESPERPIXEL(face->format) &&
  829. fmt2->bytes_per_pixel == SDL_BYTESPERPIXEL(face->format) &&
  830. SDL_ISPIXELFORMAT_ALPHA(fmt1->format) == SDL_ISPIXELFORMAT_ALPHA(face->format) &&
  831. SDL_ISPIXELFORMAT_ALPHA(fmt2->format) == SDL_ISPIXELFORMAT_ALPHA(face->format)) {
  832. final = SDL_ConvertSurface(cvt2, face->format);
  833. SDL_assert(final != NULL);
  834. /* Compare surface. */
  835. ret = SDLTest_CompareSurfaces(face, final, 0);
  836. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  837. SDL_DestroySurface(final);
  838. }
  839. SDL_DestroySurface(cvt1);
  840. SDL_DestroySurface(cvt2);
  841. }
  842. }
  843. /* Clean up. */
  844. SDL_DestroySurface(face);
  845. return TEST_COMPLETED;
  846. }
  847. /**
  848. * Tests sprite loading. A failure case.
  849. */
  850. static int SDLCALL surface_testLoadFailure(void *arg)
  851. {
  852. SDL_Surface *face = SDL_LoadBMP("nonexistant.bmp");
  853. SDLTest_AssertCheck(face == NULL, "SDL_CreateLoadBmp");
  854. return TEST_COMPLETED;
  855. }
  856. /**
  857. * Tests blitting from a zero sized source rectangle
  858. */
  859. static int SDLCALL surface_testBlitZeroSource(void *arg)
  860. {
  861. SDL_Surface *src = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_RGBA8888);
  862. SDL_Surface *dst = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_RGBA8888);
  863. SDL_Rect srcrect = { 0, 0, 0, 0 };
  864. int ret;
  865. SDLTest_AssertPass("Call to SDL_BlitSurfaceScaled() with zero sized source rectangle");
  866. SDL_FillSurfaceRect(src, NULL, SDL_MapSurfaceRGB(src, 255, 255, 255));
  867. SDL_BlitSurfaceScaled(src, &srcrect, dst, NULL, SDL_SCALEMODE_NEAREST);
  868. ret = SDLTest_CompareSurfaces(dst, src, 0);
  869. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  870. SDL_DestroySurface(src);
  871. SDL_DestroySurface(dst);
  872. return TEST_COMPLETED;
  873. }
  874. /**
  875. * Tests some blitting routines.
  876. */
  877. static int SDLCALL surface_testBlit(void *arg)
  878. {
  879. /* Basic blitting */
  880. testBlitBlendMode(SDL_BLENDMODE_NONE);
  881. return TEST_COMPLETED;
  882. }
  883. /**
  884. * Tests some blitting routines with color mod
  885. */
  886. static int SDLCALL surface_testBlitColorMod(void *arg)
  887. {
  888. /* Basic blitting with color mod */
  889. testBlitBlendMode(-1);
  890. return TEST_COMPLETED;
  891. }
  892. /**
  893. * Tests some blitting routines with alpha mod
  894. */
  895. static int SDLCALL surface_testBlitAlphaMod(void *arg)
  896. {
  897. /* Basic blitting with alpha mod */
  898. testBlitBlendMode(-2);
  899. return TEST_COMPLETED;
  900. }
  901. /**
  902. * Tests some more blitting routines.
  903. */
  904. static int SDLCALL surface_testBlitBlendBlend(void *arg)
  905. {
  906. /* Blend blitting */
  907. testBlitBlendMode(SDL_BLENDMODE_BLEND);
  908. return TEST_COMPLETED;
  909. }
  910. /**
  911. * @brief Tests some more blitting routines.
  912. */
  913. static int SDLCALL surface_testBlitBlendPremultiplied(void *arg)
  914. {
  915. /* Blend premultiplied blitting */
  916. testBlitBlendMode(SDL_BLENDMODE_BLEND_PREMULTIPLIED);
  917. return TEST_COMPLETED;
  918. }
  919. /**
  920. * Tests some more blitting routines.
  921. */
  922. static int SDLCALL surface_testBlitBlendAdd(void *arg)
  923. {
  924. /* Add blitting */
  925. testBlitBlendMode(SDL_BLENDMODE_ADD);
  926. return TEST_COMPLETED;
  927. }
  928. /**
  929. * Tests some more blitting routines.
  930. */
  931. static int SDLCALL surface_testBlitBlendAddPremultiplied(void *arg)
  932. {
  933. /* Add premultiplied blitting */
  934. testBlitBlendMode(SDL_BLENDMODE_ADD_PREMULTIPLIED);
  935. return TEST_COMPLETED;
  936. }
  937. /**
  938. * Tests some more blitting routines.
  939. */
  940. static int SDLCALL surface_testBlitBlendMod(void *arg)
  941. {
  942. /* Mod blitting */
  943. testBlitBlendMode(SDL_BLENDMODE_MOD);
  944. return TEST_COMPLETED;
  945. }
  946. /**
  947. * Tests some more blitting routines.
  948. */
  949. static int SDLCALL surface_testBlitBlendMul(void *arg)
  950. {
  951. /* Mod blitting */
  952. testBlitBlendMode(SDL_BLENDMODE_MUL);
  953. return TEST_COMPLETED;
  954. }
  955. /**
  956. * Tests blitting invalid surfaces.
  957. */
  958. static int SDLCALL surface_testBlitInvalid(void *arg)
  959. {
  960. SDL_Surface *valid, *invalid;
  961. bool result;
  962. valid = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_RGBA8888);
  963. SDLTest_AssertCheck(valid != NULL, "Check surface creation");
  964. invalid = SDL_CreateSurface(0, 0, SDL_PIXELFORMAT_RGBA8888);
  965. SDLTest_AssertCheck(invalid != NULL, "Check surface creation");
  966. SDLTest_AssertCheck(invalid->pixels == NULL, "Check surface pixels are NULL");
  967. result = SDL_BlitSurface(invalid, NULL, valid, NULL);
  968. SDLTest_AssertCheck(result == false, "SDL_BlitSurface(invalid, NULL, valid, NULL), result = %s\n", result ? "true" : "false");
  969. result = SDL_BlitSurface(valid, NULL, invalid, NULL);
  970. SDLTest_AssertCheck(result == false, "SDL_BlitSurface(valid, NULL, invalid, NULL), result = %s\n", result ? "true" : "false");
  971. result = SDL_BlitSurfaceScaled(invalid, NULL, valid, NULL, SDL_SCALEMODE_NEAREST);
  972. SDLTest_AssertCheck(result == false, "SDL_BlitSurfaceScaled(invalid, NULL, valid, NULL, SDL_SCALEMODE_NEAREST), result = %s\n", result ? "true" : "false");
  973. result = SDL_BlitSurfaceScaled(valid, NULL, invalid, NULL, SDL_SCALEMODE_NEAREST);
  974. SDLTest_AssertCheck(result == false, "SDL_BlitSurfaceScaled(valid, NULL, invalid, NULL, SDL_SCALEMODE_NEAREST), result = %s\n", result ? "true" : "false");
  975. SDL_DestroySurface(valid);
  976. SDL_DestroySurface(invalid);
  977. return TEST_COMPLETED;
  978. }
  979. static int SDLCALL surface_testBlitsWithBadCoordinates(void *arg)
  980. {
  981. const SDL_Rect rect[8] = {
  982. { SDL_MAX_SINT32, 0, 2, 2 },
  983. { 0, SDL_MAX_SINT32, 2, 2 },
  984. { 0, 0, SDL_MAX_SINT32, 2 },
  985. { 0, 0, 2, SDL_MAX_SINT32 },
  986. { SDL_MIN_SINT32, 0, 2, 2 },
  987. { 0, SDL_MIN_SINT32, 2, 2 },
  988. { 0, 0, SDL_MIN_SINT32, 2 },
  989. { 0, 0, 2, SDL_MIN_SINT32 }
  990. };
  991. SDL_Surface *s;
  992. bool result;
  993. int i;
  994. s = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_RGBA8888);
  995. SDLTest_AssertCheck(s != NULL, "Check surface creation");
  996. for (i = 0; i < 8; i++) {
  997. result = SDL_BlitSurface(s, NULL, s, &rect[i]);
  998. SDLTest_AssertCheck(result == true, "SDL_BlitSurface(valid, NULL, valid, &rect), result = %s", result ? "true" : "false");
  999. result = SDL_BlitSurface(s, &rect[i], s, NULL);
  1000. SDLTest_AssertCheck(result == true, "SDL_BlitSurface(valid, &rect, valid, NULL), result = %s", result ? "true" : "false");
  1001. result = SDL_BlitSurfaceScaled(s, NULL, s, &rect[i], SDL_SCALEMODE_NEAREST);
  1002. SDLTest_AssertCheck(result == true, "SDL_BlitSurfaceScaled(valid, NULL, valid, &rect, SDL_SCALEMODE_NEAREST), result = %s", result ? "true" : "false");
  1003. result = SDL_BlitSurfaceScaled(s, &rect[i], s, NULL, SDL_SCALEMODE_NEAREST);
  1004. SDLTest_AssertCheck(result == true, "SDL_BlitSurfaceScaled(valid, &rect, valid, NULL, SDL_SCALEMODE_NEAREST), result = %s", result ? "true" : "false");
  1005. }
  1006. SDL_DestroySurface(s);
  1007. return TEST_COMPLETED;
  1008. }
  1009. static int SDLCALL surface_testOverflow(void *arg)
  1010. {
  1011. char buf[1024];
  1012. const char *expectedError;
  1013. SDL_Surface *surface;
  1014. SDL_memset(buf, '\0', sizeof(buf));
  1015. expectedError = "Parameter 'width' is invalid";
  1016. surface = SDL_CreateSurface(-3, 100, SDL_PIXELFORMAT_INDEX8);
  1017. SDLTest_AssertCheck(surface == NULL, "Should detect negative width");
  1018. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  1019. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  1020. surface = SDL_CreateSurfaceFrom(-1, 1, SDL_PIXELFORMAT_INDEX8, buf, 4);
  1021. SDLTest_AssertCheck(surface == NULL, "Should detect negative width");
  1022. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  1023. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  1024. surface = SDL_CreateSurfaceFrom(-1, 1, SDL_PIXELFORMAT_RGBA8888, buf, 4);
  1025. SDLTest_AssertCheck(surface == NULL, "Should detect negative width");
  1026. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  1027. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  1028. expectedError = "Parameter 'height' is invalid";
  1029. surface = SDL_CreateSurface(100, -3, SDL_PIXELFORMAT_INDEX8);
  1030. SDLTest_AssertCheck(surface == NULL, "Should detect negative height");
  1031. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  1032. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  1033. surface = SDL_CreateSurfaceFrom(1, -1, SDL_PIXELFORMAT_INDEX8, buf, 4);
  1034. SDLTest_AssertCheck(surface == NULL, "Should detect negative height");
  1035. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  1036. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  1037. surface = SDL_CreateSurfaceFrom(1, -1, SDL_PIXELFORMAT_RGBA8888, buf, 4);
  1038. SDLTest_AssertCheck(surface == NULL, "Should detect negative height");
  1039. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  1040. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  1041. expectedError = "Parameter 'pitch' is invalid";
  1042. surface = SDL_CreateSurfaceFrom(4, 1, SDL_PIXELFORMAT_INDEX8, buf, -1);
  1043. SDLTest_AssertCheck(surface == NULL, "Should detect negative pitch");
  1044. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  1045. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  1046. surface = SDL_CreateSurfaceFrom(1, 1, SDL_PIXELFORMAT_RGBA8888, buf, -1);
  1047. SDLTest_AssertCheck(surface == NULL, "Should detect negative pitch");
  1048. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  1049. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  1050. surface = SDL_CreateSurfaceFrom(1, 1, SDL_PIXELFORMAT_RGBA8888, buf, 0);
  1051. SDLTest_AssertCheck(surface == NULL, "Should detect zero pitch");
  1052. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  1053. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  1054. surface = SDL_CreateSurfaceFrom(1, 1, SDL_PIXELFORMAT_RGBA8888, NULL, 0);
  1055. SDLTest_AssertCheck(surface != NULL, "Allow zero pitch for partially set up surfaces: %s",
  1056. surface != NULL ? "(success)" : SDL_GetError());
  1057. SDL_DestroySurface(surface);
  1058. /* Less than 1 byte per pixel: the pitch can legitimately be less than
  1059. * the width, but it must be enough to hold the appropriate number of
  1060. * bits per pixel. SDL_PIXELFORMAT_INDEX4* needs 1 byte per 2 pixels. */
  1061. surface = SDL_CreateSurfaceFrom(6, 1, SDL_PIXELFORMAT_INDEX4LSB, buf, 3);
  1062. SDLTest_AssertCheck(surface != NULL, "6px * 4 bits per px fits in 3 bytes: %s",
  1063. surface != NULL ? "(success)" : SDL_GetError());
  1064. SDL_DestroySurface(surface);
  1065. surface = SDL_CreateSurfaceFrom(6, 1, SDL_PIXELFORMAT_INDEX4MSB, buf, 3);
  1066. SDLTest_AssertCheck(surface != NULL, "6px * 4 bits per px fits in 3 bytes: %s",
  1067. surface != NULL ? "(success)" : SDL_GetError());
  1068. SDL_DestroySurface(surface);
  1069. surface = SDL_CreateSurfaceFrom(7, 1, SDL_PIXELFORMAT_INDEX4LSB, buf, 3);
  1070. SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
  1071. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  1072. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  1073. surface = SDL_CreateSurfaceFrom(7, 1, SDL_PIXELFORMAT_INDEX4MSB, buf, 3);
  1074. SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
  1075. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  1076. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  1077. surface = SDL_CreateSurfaceFrom(7, 1, SDL_PIXELFORMAT_INDEX4LSB, buf, 4);
  1078. SDLTest_AssertCheck(surface != NULL, "7px * 4 bits per px fits in 4 bytes: %s",
  1079. surface != NULL ? "(success)" : SDL_GetError());
  1080. SDL_DestroySurface(surface);
  1081. surface = SDL_CreateSurfaceFrom(7, 1, SDL_PIXELFORMAT_INDEX4MSB, buf, 4);
  1082. SDLTest_AssertCheck(surface != NULL, "7px * 4 bits per px fits in 4 bytes: %s",
  1083. surface != NULL ? "(success)" : SDL_GetError());
  1084. SDL_DestroySurface(surface);
  1085. /* SDL_PIXELFORMAT_INDEX2* needs 1 byte per 4 pixels. */
  1086. surface = SDL_CreateSurfaceFrom(12, 1, SDL_PIXELFORMAT_INDEX2LSB, buf, 3);
  1087. SDLTest_AssertCheck(surface != NULL, "12px * 2 bits per px fits in 3 bytes: %s",
  1088. surface != NULL ? "(success)" : SDL_GetError());
  1089. SDL_DestroySurface(surface);
  1090. surface = SDL_CreateSurfaceFrom(12, 1, SDL_PIXELFORMAT_INDEX2MSB, buf, 3);
  1091. SDLTest_AssertCheck(surface != NULL, "12px * 2 bits per px fits in 3 bytes: %s",
  1092. surface != NULL ? "(success)" : SDL_GetError());
  1093. SDL_DestroySurface(surface);
  1094. surface = SDL_CreateSurfaceFrom(13, 1, SDL_PIXELFORMAT_INDEX2LSB, buf, 3);
  1095. SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp (%d)", surface ? surface->pitch : 0);
  1096. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  1097. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  1098. surface = SDL_CreateSurfaceFrom(13, 1, SDL_PIXELFORMAT_INDEX2MSB, buf, 3);
  1099. SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
  1100. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  1101. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  1102. surface = SDL_CreateSurfaceFrom(13, 1, SDL_PIXELFORMAT_INDEX2LSB, buf, 4);
  1103. SDLTest_AssertCheck(surface != NULL, "13px * 2 bits per px fits in 4 bytes: %s",
  1104. surface != NULL ? "(success)" : SDL_GetError());
  1105. SDL_DestroySurface(surface);
  1106. surface = SDL_CreateSurfaceFrom(13, 1, SDL_PIXELFORMAT_INDEX2MSB, buf, 4);
  1107. SDLTest_AssertCheck(surface != NULL, "13px * 2 bits per px fits in 4 bytes: %s",
  1108. surface != NULL ? "(success)" : SDL_GetError());
  1109. SDL_DestroySurface(surface);
  1110. /* SDL_PIXELFORMAT_INDEX1* needs 1 byte per 8 pixels. */
  1111. surface = SDL_CreateSurfaceFrom(16, 1, SDL_PIXELFORMAT_INDEX1LSB, buf, 2);
  1112. SDLTest_AssertCheck(surface != NULL, "16px * 1 bit per px fits in 2 bytes: %s",
  1113. surface != NULL ? "(success)" : SDL_GetError());
  1114. SDL_DestroySurface(surface);
  1115. surface = SDL_CreateSurfaceFrom(16, 1, SDL_PIXELFORMAT_INDEX1MSB, buf, 2);
  1116. SDLTest_AssertCheck(surface != NULL, "16px * 1 bit per px fits in 2 bytes: %s",
  1117. surface != NULL ? "(success)" : SDL_GetError());
  1118. SDL_DestroySurface(surface);
  1119. surface = SDL_CreateSurfaceFrom(17, 1, SDL_PIXELFORMAT_INDEX1LSB, buf, 2);
  1120. SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
  1121. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  1122. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  1123. surface = SDL_CreateSurfaceFrom(17, 1, SDL_PIXELFORMAT_INDEX1MSB, buf, 2);
  1124. SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
  1125. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  1126. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  1127. surface = SDL_CreateSurfaceFrom(17, 1, SDL_PIXELFORMAT_INDEX1LSB, buf, 3);
  1128. SDLTest_AssertCheck(surface != NULL, "17px * 1 bit per px fits in 3 bytes: %s",
  1129. surface != NULL ? "(success)" : SDL_GetError());
  1130. SDL_DestroySurface(surface);
  1131. surface = SDL_CreateSurfaceFrom(17, 1, SDL_PIXELFORMAT_INDEX1MSB, buf, 3);
  1132. SDLTest_AssertCheck(surface != NULL, "17px * 1 bit per px fits in 3 bytes: %s",
  1133. surface != NULL ? "(success)" : SDL_GetError());
  1134. SDL_DestroySurface(surface);
  1135. /* SDL_PIXELFORMAT_INDEX8 and SDL_PIXELFORMAT_RGB332 require 1 byte per pixel. */
  1136. surface = SDL_CreateSurfaceFrom(5, 1, SDL_PIXELFORMAT_RGB332, buf, 5);
  1137. SDLTest_AssertCheck(surface != NULL, "5px * 8 bits per px fits in 5 bytes: %s",
  1138. surface != NULL ? "(success)" : SDL_GetError());
  1139. SDL_DestroySurface(surface);
  1140. surface = SDL_CreateSurfaceFrom(5, 1, SDL_PIXELFORMAT_INDEX8, buf, 5);
  1141. SDLTest_AssertCheck(surface != NULL, "5px * 8 bits per px fits in 5 bytes: %s",
  1142. surface != NULL ? "(success)" : SDL_GetError());
  1143. SDL_DestroySurface(surface);
  1144. surface = SDL_CreateSurfaceFrom(6, 1, SDL_PIXELFORMAT_RGB332, buf, 5);
  1145. SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
  1146. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  1147. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  1148. surface = SDL_CreateSurfaceFrom(6, 1, SDL_PIXELFORMAT_INDEX8, buf, 5);
  1149. SDLTest_AssertCheck(surface == NULL, "Should detect pitch < width * bpp");
  1150. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  1151. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  1152. /* Everything else requires more than 1 byte per pixel, and rounds up
  1153. * each pixel to an integer number of bytes (e.g. RGB555 is really
  1154. * XRGB1555, with 1 bit per pixel wasted). */
  1155. surface = SDL_CreateSurfaceFrom(3, 1, SDL_PIXELFORMAT_XRGB1555, buf, 6);
  1156. SDLTest_AssertCheck(surface != NULL, "3px * 15 (really 16) bits per px fits in 6 bytes: %s",
  1157. surface != NULL ? "(success)" : SDL_GetError());
  1158. SDL_DestroySurface(surface);
  1159. surface = SDL_CreateSurfaceFrom(3, 1, SDL_PIXELFORMAT_XRGB1555, buf, 6);
  1160. SDLTest_AssertCheck(surface != NULL, "5px * 15 (really 16) bits per px fits in 6 bytes: %s",
  1161. surface != NULL ? "(success)" : SDL_GetError());
  1162. SDL_DestroySurface(surface);
  1163. surface = SDL_CreateSurfaceFrom(4, 1, SDL_PIXELFORMAT_XRGB1555, buf, 6);
  1164. SDLTest_AssertCheck(surface == NULL, "4px * 15 (really 16) bits per px doesn't fit in 6 bytes");
  1165. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  1166. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  1167. surface = SDL_CreateSurfaceFrom(4, 1, SDL_PIXELFORMAT_XRGB1555, buf, 6);
  1168. SDLTest_AssertCheck(surface == NULL, "4px * 15 (really 16) bits per px doesn't fit in 6 bytes");
  1169. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  1170. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  1171. if (sizeof(size_t) == 4 && sizeof(int) >= 4) {
  1172. SDL_ClearError();
  1173. expectedError = "aligning pitch would overflow";
  1174. /* 0x5555'5555 * 3bpp = 0xffff'ffff which fits in size_t, but adding
  1175. * alignment padding makes it overflow */
  1176. surface = SDL_CreateSurface(0x55555555, 1, SDL_PIXELFORMAT_RGB24);
  1177. SDLTest_AssertCheck(surface == NULL, "Should detect overflow in pitch + alignment");
  1178. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  1179. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  1180. SDL_ClearError();
  1181. expectedError = "width * bpp would overflow";
  1182. /* 0x4000'0000 * 4bpp = 0x1'0000'0000 which (just) overflows */
  1183. surface = SDL_CreateSurface(0x40000000, 1, SDL_PIXELFORMAT_ARGB8888);
  1184. SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * bytes per pixel");
  1185. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  1186. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  1187. SDL_ClearError();
  1188. expectedError = "height * pitch would overflow";
  1189. surface = SDL_CreateSurface((1 << 29) - 1, (1 << 29) - 1, SDL_PIXELFORMAT_INDEX8);
  1190. SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * height");
  1191. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  1192. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  1193. SDL_ClearError();
  1194. expectedError = "height * pitch would overflow";
  1195. surface = SDL_CreateSurface((1 << 15) + 1, (1 << 15) + 1, SDL_PIXELFORMAT_ARGB8888);
  1196. SDLTest_AssertCheck(surface == NULL, "Should detect overflow in width * height * bytes per pixel");
  1197. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  1198. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  1199. } else {
  1200. SDLTest_Log("Can't easily overflow size_t on this platform");
  1201. }
  1202. return TEST_COMPLETED;
  1203. }
  1204. static int SDLCALL surface_testFlip(void *arg)
  1205. {
  1206. SDL_Surface *surface;
  1207. Uint8 *pixels;
  1208. int offset;
  1209. const char *expectedError;
  1210. surface = SDL_CreateSurface(3, 3, SDL_PIXELFORMAT_RGB24);
  1211. SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()");
  1212. SDL_ClearError();
  1213. expectedError = "Parameter 'surface' is invalid";
  1214. SDL_FlipSurface(NULL, SDL_FLIP_HORIZONTAL);
  1215. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  1216. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  1217. SDL_ClearError();
  1218. expectedError = "Parameter 'flip' is invalid";
  1219. SDL_FlipSurface(surface, SDL_FLIP_NONE);
  1220. SDLTest_AssertCheck(SDL_strcmp(SDL_GetError(), expectedError) == 0,
  1221. "Expected \"%s\", got \"%s\"", expectedError, SDL_GetError());
  1222. pixels = (Uint8 *)surface->pixels;
  1223. *pixels = 0xFF;
  1224. offset = 0;
  1225. SDLTest_AssertPass("Call to SDL_FlipSurface(surface, SDL_FLIP_VERTICAL)");
  1226. CHECK_FUNC(SDL_FlipSurface, (surface, SDL_FLIP_VERTICAL));
  1227. SDLTest_AssertCheck(pixels[offset] == 0x00,
  1228. "Expected pixels[%d] == 0x00 got 0x%.2X", offset, pixels[offset]);
  1229. offset = 2 * surface->pitch;
  1230. SDLTest_AssertCheck(pixels[offset] == 0xFF,
  1231. "Expected pixels[%d] == 0xFF got 0x%.2X", offset, pixels[offset]);
  1232. SDLTest_AssertPass("Call to SDL_FlipSurface(surface, SDL_FLIP_HORIZONTAL)");
  1233. CHECK_FUNC(SDL_FlipSurface, (surface, SDL_FLIP_HORIZONTAL));
  1234. SDLTest_AssertCheck(pixels[offset] == 0x00,
  1235. "Expected pixels[%d] == 0x00 got 0x%.2X", offset, pixels[offset]);
  1236. offset += (surface->w - 1) * SDL_BYTESPERPIXEL(surface->format);
  1237. SDLTest_AssertCheck(pixels[offset] == 0xFF,
  1238. "Expected pixels[%d] == 0xFF got 0x%.2X", offset, pixels[offset]);
  1239. SDL_DestroySurface(surface);
  1240. return TEST_COMPLETED;
  1241. }
  1242. static int SDLCALL surface_testPalette(void *arg)
  1243. {
  1244. SDL_Surface *source, *surface, *output;
  1245. SDL_Palette *palette;
  1246. Uint8 *pixels;
  1247. palette = SDL_CreatePalette(2);
  1248. SDLTest_AssertCheck(palette != NULL, "SDL_CreatePalette()");
  1249. source = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_INDEX8);
  1250. SDLTest_AssertCheck(source != NULL, "SDL_CreateSurface()");
  1251. SDLTest_AssertCheck(SDL_GetSurfacePalette(source) == NULL, "SDL_GetSurfacePalette(source)");
  1252. surface = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_INDEX8);
  1253. SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()");
  1254. SDLTest_AssertCheck(SDL_GetSurfacePalette(surface) == NULL, "SDL_GetSurfacePalette(surface)");
  1255. pixels = (Uint8 *)surface->pixels;
  1256. SDLTest_AssertCheck(*pixels == 0, "Expected *pixels == 0 got %u", *pixels);
  1257. /* Identity copy between indexed surfaces without a palette */
  1258. *(Uint8 *)source->pixels = 1;
  1259. SDL_BlitSurface(source, NULL, surface, NULL);
  1260. SDLTest_AssertCheck(*pixels == 1, "Expected *pixels == 1 got %u", *pixels);
  1261. /* Identity copy between indexed surfaces where the source has a palette */
  1262. palette->colors[0].r = 0;
  1263. palette->colors[0].g = 0;
  1264. palette->colors[0].b = 0;
  1265. palette->colors[1].r = 0xFF;
  1266. palette->colors[1].g = 0;
  1267. palette->colors[1].b = 0;
  1268. SDL_SetSurfacePalette(source, palette);
  1269. *pixels = 0;
  1270. SDL_BlitSurface(source, NULL, surface, NULL);
  1271. SDLTest_AssertCheck(*pixels == 1, "Expected *pixels == 1 got %u", *pixels);
  1272. /* Identity copy between indexed surfaces where the destination has a palette */
  1273. palette->colors[0].r = 0;
  1274. palette->colors[0].g = 0;
  1275. palette->colors[0].b = 0;
  1276. palette->colors[1].r = 0xFF;
  1277. palette->colors[1].g = 0;
  1278. palette->colors[1].b = 0;
  1279. SDL_SetSurfacePalette(source, NULL);
  1280. SDL_SetSurfacePalette(surface, palette);
  1281. *pixels = 0;
  1282. SDL_BlitSurface(source, NULL, surface, NULL);
  1283. SDLTest_AssertCheck(*pixels == 1, "Expected *pixels == 1 got %u", *pixels);
  1284. /* Identity copy between indexed surfaces where the source and destination share a palette */
  1285. palette->colors[0].r = 0;
  1286. palette->colors[0].g = 0;
  1287. palette->colors[0].b = 0;
  1288. palette->colors[1].r = 0xFF;
  1289. palette->colors[1].g = 0;
  1290. palette->colors[1].b = 0;
  1291. SDL_SetSurfacePalette(source, palette);
  1292. SDL_SetSurfacePalette(surface, palette);
  1293. *pixels = 0;
  1294. SDL_BlitSurface(source, NULL, surface, NULL);
  1295. SDLTest_AssertCheck(*pixels == 1, "Expected *pixels == 1 got %u", *pixels);
  1296. output = SDL_CreateSurface(1, 1, SDL_PIXELFORMAT_RGBA32);
  1297. SDLTest_AssertCheck(output != NULL, "SDL_CreateSurface()");
  1298. pixels = (Uint8 *)output->pixels;
  1299. SDL_BlitSurface(surface, NULL, output, NULL);
  1300. SDLTest_AssertCheck(*pixels == 0xFF, "Expected *pixels == 0xFF got 0x%.2X", *pixels);
  1301. /* Set the palette color and blit again */
  1302. palette->colors[1].r = 0xAA;
  1303. SDL_SetSurfacePalette(surface, palette);
  1304. SDL_BlitSurface(surface, NULL, output, NULL);
  1305. SDLTest_AssertCheck(*pixels == 0xAA, "Expected *pixels == 0xAA got 0x%.2X", *pixels);
  1306. SDL_DestroyPalette(palette);
  1307. SDL_DestroySurface(source);
  1308. SDL_DestroySurface(surface);
  1309. SDL_DestroySurface(output);
  1310. return TEST_COMPLETED;
  1311. }
  1312. static int SDLCALL surface_testPalettization(void *arg)
  1313. {
  1314. const SDL_Color palette_colors[] = {
  1315. { 0x80, 0x00, 0x00, 0xff },
  1316. { 0x00, 0x80, 0x00, 0xff },
  1317. { 0x00, 0x00, 0x80, 0xff },
  1318. { 0x40, 0x00, 0x00, 0xff },
  1319. { 0x00, 0x40, 0x00, 0xff },
  1320. { 0x00, 0x00, 0x40, 0xff },
  1321. { 0x00, 0x00, 0x00, 0xff },
  1322. { 0xff, 0x00, 0x00, 0xff },
  1323. { 0x00, 0xff, 0x00, 0xff },
  1324. { 0x00, 0x00, 0xff, 0xff },
  1325. { 0xff, 0xff, 0x00, 0xff },
  1326. { 0x00, 0xff, 0xff, 0xff },
  1327. { 0xff, 0x00, 0xff, 0xff },
  1328. };
  1329. const struct {
  1330. SDL_Color c;
  1331. Uint8 e;
  1332. } colors[] = {
  1333. { { 0xff, 0x00, 0x00, 0xff }, 7 },
  1334. { { 0xfe, 0x00, 0x00, 0xff }, 7 },
  1335. { { 0xfd, 0x00, 0x00, 0xff }, 7 },
  1336. { { 0xf0, 0x00, 0x00, 0xff }, 7 },
  1337. { { 0xd0, 0x00, 0x00, 0xff }, 7 },
  1338. { { 0xb0, 0x00, 0x00, 0xff }, 0 },
  1339. { { 0xa0, 0x00, 0x00, 0xff }, 0 },
  1340. { { 0xff, 0x00, 0x00, 0x00 }, 7 },
  1341. { { 0x00, 0x10, 0x21, 0xff }, 5 },
  1342. { { 0x00, 0x10, 0x19, 0xff }, 6 },
  1343. { { 0x81, 0x00, 0x41, 0xff }, 0 },
  1344. { { 0x80, 0xf0, 0xf0, 0x7f }, 11 },
  1345. { { 0x00, 0x00, 0x00, 0xff }, 6 },
  1346. { { 0x00, 0x00, 0x00, 0x01 }, 6 },
  1347. };
  1348. int i;
  1349. int result;
  1350. SDL_Surface *source, *output;
  1351. SDL_Palette *palette;
  1352. Uint8 *pixels;
  1353. palette = SDL_CreatePalette(SDL_arraysize(palette_colors));
  1354. SDLTest_AssertCheck(palette != NULL, "SDL_CreatePalette()");
  1355. result = SDL_SetPaletteColors(palette, palette_colors, 0, SDL_arraysize(palette_colors));
  1356. SDLTest_AssertCheck(result, "SDL_SetPaletteColors()");
  1357. source = SDL_CreateSurface(SDL_arraysize(palette_colors) + SDL_arraysize(colors), 1, SDL_PIXELFORMAT_RGBA8888);
  1358. SDLTest_AssertCheck(source != NULL, "SDL_CreateSurface()");
  1359. 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);
  1360. SDLTest_AssertCheck(source->h == 1, "Expected source->h == %d, got %d", 1, source->h);
  1361. SDLTest_AssertCheck(source->format == SDL_PIXELFORMAT_RGBA8888, "Expected source->format == SDL_PIXELFORMAT_RGBA8888, got 0x%x (%s)", source->format, SDL_GetPixelFormatName(source->format));
  1362. for (i = 0; i < SDL_arraysize(colors); i++) {
  1363. result = SDL_WriteSurfacePixel(source, i, 0, colors[i].c.r, colors[i].c.g, colors[i].c.b, colors[i].c.a);
  1364. SDLTest_AssertCheck(result == true, "SDL_WriteSurfacePixel");
  1365. }
  1366. for (i = 0; i < SDL_arraysize(palette_colors); i++) {
  1367. 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);
  1368. SDLTest_AssertCheck(result == true, "SDL_WriteSurfacePixel");
  1369. }
  1370. output = SDL_ConvertSurfaceAndColorspace(source, SDL_PIXELFORMAT_INDEX8, palette, SDL_COLORSPACE_UNKNOWN, 0);
  1371. SDLTest_AssertCheck(output != NULL, "SDL_ConvertSurfaceAndColorspace()");
  1372. SDLTest_AssertCheck(output->w == source->w, "Expected output->w == %d, got %d", source->w, output->w);
  1373. SDLTest_AssertCheck(output->h == source->h, "Expected output->h == %d, got %d", source->h, output->h);
  1374. SDLTest_AssertCheck(output->format == SDL_PIXELFORMAT_INDEX8, "Expected output->format == SDL_PIXELFORMAT_INDEX8, got 0x%x (%s)", output->format, SDL_GetPixelFormatName(output->format));
  1375. pixels = output->pixels;
  1376. for (i = 0; i < SDL_arraysize(colors); i++) {
  1377. int idx = i;
  1378. Uint8 actual = pixels[idx];
  1379. Uint8 expected = colors[i].e;
  1380. SDLTest_AssertCheck(actual < SDL_arraysize(palette_colors), "output->pixels[%d] < %d", idx, (int)SDL_arraysize(palette_colors));
  1381. SDLTest_AssertCheck(actual == expected, "Expected output->pixels[%d] == %u, got %u", idx, expected, actual);
  1382. }
  1383. SDLTest_AssertPass("Check palette 1:1 mapping");
  1384. for (i = 0; i < SDL_arraysize(palette_colors); i++) {
  1385. int idx = SDL_arraysize(colors) + i;
  1386. Uint8 actual = pixels[idx];
  1387. Uint8 expected = i;
  1388. SDLTest_AssertCheck(actual < SDL_arraysize(palette_colors), "output->pixels[%d] < %d", idx, (int)SDL_arraysize(palette_colors));
  1389. SDLTest_AssertCheck(actual == expected, "Expected output->pixels[%d] == %u, got %u", idx, expected, actual);
  1390. }
  1391. SDL_DestroyPalette(palette);
  1392. SDL_DestroySurface(source);
  1393. SDL_DestroySurface(output);
  1394. return TEST_COMPLETED;
  1395. }
  1396. static int SDLCALL surface_testClearSurface(void *arg)
  1397. {
  1398. SDL_PixelFormat formats[] = {
  1399. SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGBA8888,
  1400. SDL_PIXELFORMAT_ARGB2101010, SDL_PIXELFORMAT_ABGR2101010,
  1401. SDL_PIXELFORMAT_ARGB64, SDL_PIXELFORMAT_RGBA64,
  1402. SDL_PIXELFORMAT_ARGB128_FLOAT, SDL_PIXELFORMAT_RGBA128_FLOAT,
  1403. SDL_PIXELFORMAT_YV12, SDL_PIXELFORMAT_UYVY, SDL_PIXELFORMAT_NV12
  1404. };
  1405. SDL_Surface *surface;
  1406. SDL_PixelFormat format;
  1407. const float MAXIMUM_ERROR_RGB = 0.0001f;
  1408. const float MAXIMUM_ERROR_YUV = 0.01f;
  1409. float srcR = 10 / 255.0f, srcG = 128 / 255.0f, srcB = 240 / 255.0f, srcA = 1.0f;
  1410. float actualR, actualG, actualB, actualA;
  1411. float deltaR, deltaG, deltaB, deltaA;
  1412. int i, ret;
  1413. for (i = 0; i < SDL_arraysize(formats); ++i) {
  1414. const float MAXIMUM_ERROR = SDL_ISPIXELFORMAT_FOURCC(formats[i]) ? MAXIMUM_ERROR_YUV : MAXIMUM_ERROR_RGB;
  1415. format = formats[i];
  1416. surface = SDL_CreateSurface(1, 1, format);
  1417. SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()");
  1418. ret = SDL_ClearSurface(surface, srcR, srcG, srcB, srcA);
  1419. SDLTest_AssertCheck(ret == true, "SDL_ClearSurface()");
  1420. ret = SDL_ReadSurfacePixelFloat(surface, 0, 0, &actualR, &actualG, &actualB, &actualA);
  1421. SDLTest_AssertCheck(ret == true, "SDL_ReadSurfacePixelFloat()");
  1422. deltaR = SDL_fabsf(actualR - srcR);
  1423. deltaG = SDL_fabsf(actualG - srcG);
  1424. deltaB = SDL_fabsf(actualB - srcB);
  1425. deltaA = SDL_fabsf(actualA - srcA);
  1426. SDLTest_AssertCheck(
  1427. deltaR <= MAXIMUM_ERROR &&
  1428. deltaG <= MAXIMUM_ERROR &&
  1429. deltaB <= MAXIMUM_ERROR &&
  1430. deltaA <= MAXIMUM_ERROR,
  1431. "Checking %s surface clear results, expected %.4f,%.4f,%.4f,%.4f, got %.4f,%.4f,%.4f,%.4f",
  1432. SDL_GetPixelFormatName(format),
  1433. srcR, srcG, srcB, srcA, actualR, actualG, actualB, actualA);
  1434. SDL_DestroySurface(surface);
  1435. }
  1436. return TEST_COMPLETED;
  1437. }
  1438. static int SDLCALL surface_testPremultiplyAlpha(void *arg)
  1439. {
  1440. SDL_PixelFormat formats[] = {
  1441. SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGBA8888,
  1442. SDL_PIXELFORMAT_ARGB2101010, SDL_PIXELFORMAT_ABGR2101010,
  1443. SDL_PIXELFORMAT_ARGB64, SDL_PIXELFORMAT_RGBA64,
  1444. SDL_PIXELFORMAT_ARGB128_FLOAT, SDL_PIXELFORMAT_RGBA128_FLOAT,
  1445. };
  1446. SDL_Surface *surface;
  1447. SDL_PixelFormat format;
  1448. const float MAXIMUM_ERROR_LOW_PRECISION = 1 / 255.0f;
  1449. const float MAXIMUM_ERROR_HIGH_PRECISION = 0.0001f;
  1450. float srcR = 10 / 255.0f, srcG = 128 / 255.0f, srcB = 240 / 255.0f, srcA = 170 / 255.0f;
  1451. float expectedR = srcR * srcA;
  1452. float expectedG = srcG * srcA;
  1453. float expectedB = srcB * srcA;
  1454. float actualR, actualG, actualB;
  1455. float deltaR, deltaG, deltaB;
  1456. int i, ret;
  1457. for (i = 0; i < SDL_arraysize(formats); ++i) {
  1458. const float MAXIMUM_ERROR = (SDL_BITSPERPIXEL(formats[i]) > 32) ? MAXIMUM_ERROR_HIGH_PRECISION : MAXIMUM_ERROR_LOW_PRECISION;
  1459. format = formats[i];
  1460. surface = SDL_CreateSurface(1, 1, format);
  1461. SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()");
  1462. ret = SDL_SetSurfaceColorspace(surface, SDL_COLORSPACE_SRGB);
  1463. SDLTest_AssertCheck(ret == true, "SDL_SetSurfaceColorspace()");
  1464. ret = SDL_ClearSurface(surface, srcR, srcG, srcB, srcA);
  1465. SDLTest_AssertCheck(ret == true, "SDL_ClearSurface()");
  1466. ret = SDL_PremultiplySurfaceAlpha(surface, false);
  1467. SDLTest_AssertCheck(ret == true, "SDL_PremultiplySurfaceAlpha()");
  1468. ret = SDL_ReadSurfacePixelFloat(surface, 0, 0, &actualR, &actualG, &actualB, NULL);
  1469. SDLTest_AssertCheck(ret == true, "SDL_ReadSurfacePixelFloat()");
  1470. deltaR = SDL_fabsf(actualR - expectedR);
  1471. deltaG = SDL_fabsf(actualG - expectedG);
  1472. deltaB = SDL_fabsf(actualB - expectedB);
  1473. SDLTest_AssertCheck(
  1474. deltaR <= MAXIMUM_ERROR &&
  1475. deltaG <= MAXIMUM_ERROR &&
  1476. deltaB <= MAXIMUM_ERROR,
  1477. "Checking %s alpha premultiply results, expected %.4f,%.4f,%.4f, got %.4f,%.4f,%.4f",
  1478. SDL_GetPixelFormatName(format),
  1479. expectedR, expectedG, expectedB, actualR, actualG, actualB);
  1480. SDL_DestroySurface(surface);
  1481. }
  1482. return TEST_COMPLETED;
  1483. }
  1484. static int SDLCALL surface_testScale(void *arg)
  1485. {
  1486. SDL_PixelFormat formats[] = {
  1487. SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGBA8888,
  1488. SDL_PIXELFORMAT_ARGB2101010, SDL_PIXELFORMAT_ABGR2101010,
  1489. SDL_PIXELFORMAT_ARGB64, SDL_PIXELFORMAT_RGBA64,
  1490. SDL_PIXELFORMAT_ARGB128_FLOAT, SDL_PIXELFORMAT_RGBA128_FLOAT,
  1491. };
  1492. SDL_ScaleMode modes[] = {
  1493. SDL_SCALEMODE_NEAREST, SDL_SCALEMODE_LINEAR, SDL_SCALEMODE_PIXELART
  1494. };
  1495. SDL_Surface *surface, *result;
  1496. SDL_PixelFormat format;
  1497. SDL_ScaleMode mode;
  1498. const float MAXIMUM_ERROR = 0.0001f;
  1499. float srcR = 10 / 255.0f, srcG = 128 / 255.0f, srcB = 240 / 255.0f, srcA = 170 / 255.0f;
  1500. float actualR, actualG, actualB, actualA;
  1501. float deltaR, deltaG, deltaB, deltaA;
  1502. int i, j, ret;
  1503. for (i = 0; i < SDL_arraysize(formats); ++i) {
  1504. for (j = 0; j < SDL_arraysize(modes); ++j) {
  1505. format = formats[i];
  1506. mode = modes[j];
  1507. surface = SDL_CreateSurface(1, 1, format);
  1508. SDLTest_AssertCheck(surface != NULL, "SDL_CreateSurface()");
  1509. ret = SDL_SetSurfaceColorspace(surface, SDL_COLORSPACE_SRGB);
  1510. SDLTest_AssertCheck(ret == true, "SDL_SetSurfaceColorspace()");
  1511. ret = SDL_ClearSurface(surface, srcR, srcG, srcB, srcA);
  1512. SDLTest_AssertCheck(ret == true, "SDL_ClearSurface()");
  1513. result = SDL_ScaleSurface(surface, 2, 2, mode);
  1514. SDLTest_AssertCheck(ret == true, "SDL_PremultiplySurfaceAlpha()");
  1515. ret = SDL_ReadSurfacePixelFloat(result, 1, 1, &actualR, &actualG, &actualB, &actualA);
  1516. SDLTest_AssertCheck(ret == true, "SDL_ReadSurfacePixelFloat()");
  1517. deltaR = SDL_fabsf(actualR - srcR);
  1518. deltaG = SDL_fabsf(actualG - srcG);
  1519. deltaB = SDL_fabsf(actualB - srcB);
  1520. deltaA = SDL_fabsf(actualA - srcA);
  1521. SDLTest_AssertCheck(
  1522. deltaR <= MAXIMUM_ERROR &&
  1523. deltaG <= MAXIMUM_ERROR &&
  1524. deltaB <= MAXIMUM_ERROR &&
  1525. deltaA <= MAXIMUM_ERROR,
  1526. "Checking %s %s scaling results, expected %.4f,%.4f,%.4f,%.4f got %.4f,%.4f,%.4f,%.4f",
  1527. SDL_GetPixelFormatName(format),
  1528. mode == SDL_SCALEMODE_NEAREST ? "nearest" :
  1529. mode == SDL_SCALEMODE_LINEAR ? "linear" :
  1530. mode == SDL_SCALEMODE_PIXELART ? "pixelart" : "unknown",
  1531. srcR, srcG, srcB, srcA, actualR, actualG, actualB, actualA);
  1532. SDL_DestroySurface(surface);
  1533. SDL_DestroySurface(result);
  1534. }
  1535. }
  1536. return TEST_COMPLETED;
  1537. }
  1538. #define GENERATE_SHIFTS
  1539. static Uint32 Calculate(int v, int bits, int vmax, int shift)
  1540. {
  1541. #if defined(GENERATE_FLOOR)
  1542. return (Uint32)SDL_floor(v * 255.0f / vmax) << shift;
  1543. #elif defined(GENERATE_ROUND)
  1544. return (Uint32)SDL_roundf(v * 255.0f / vmax) << shift;
  1545. #elif defined(GENERATE_SHIFTS)
  1546. switch (bits) {
  1547. case 1:
  1548. v = (v << 7) | (v << 6) | (v << 5) | (v << 4) | (v << 3) | (v << 2) | (v << 1) | v;
  1549. break;
  1550. case 2:
  1551. v = (v << 6) | (v << 4) | (v << 2) | v;
  1552. break;
  1553. case 3:
  1554. v = (v << 5) | (v << 2) | (v >> 1);
  1555. break;
  1556. case 4:
  1557. v = (v << 4) | v;
  1558. break;
  1559. case 5:
  1560. v = (v << 3) | (v >> 2);
  1561. break;
  1562. case 6:
  1563. v = (v << 2) | (v >> 4);
  1564. break;
  1565. case 7:
  1566. v = (v << 1) | (v >> 6);
  1567. break;
  1568. case 8:
  1569. break;
  1570. }
  1571. return (Uint32)v << shift;
  1572. #endif
  1573. }
  1574. static Uint32 Calculate565toARGB(int v, const SDL_PixelFormatDetails *fmt)
  1575. {
  1576. Uint8 r = (v & 0xF800) >> 11;
  1577. Uint8 g = (v & 0x07E0) >> 5;
  1578. Uint8 b = (v & 0x001F);
  1579. return fmt->Amask |
  1580. Calculate(r, 5, 31, fmt->Rshift) |
  1581. Calculate(g, 6, 63, fmt->Gshift) |
  1582. Calculate(b, 5, 31, fmt->Bshift);
  1583. }
  1584. static int SDLCALL surface_test16BitTo32Bit(void *arg)
  1585. {
  1586. static const SDL_PixelFormat formats[] = {
  1587. SDL_PIXELFORMAT_ARGB8888,
  1588. SDL_PIXELFORMAT_ABGR8888,
  1589. SDL_PIXELFORMAT_RGBA8888,
  1590. SDL_PIXELFORMAT_BGRA8888
  1591. };
  1592. static Uint16 pixels[1 << 16];
  1593. static Uint32 expected[1 << 16];
  1594. int i, p, ret;
  1595. SDL_Surface *surface16;
  1596. SDL_Surface *surface32;
  1597. SDL_Surface *expected32;
  1598. for (p = 0; p < SDL_arraysize(pixels); ++p) {
  1599. pixels[p] = p;
  1600. }
  1601. surface16 = SDL_CreateSurfaceFrom(SDL_arraysize(pixels), 1, SDL_PIXELFORMAT_RGB565, pixels, sizeof(pixels));
  1602. for (i = 0; i < SDL_arraysize(formats); ++i) {
  1603. SDL_PixelFormat format = formats[i];
  1604. const SDL_PixelFormatDetails *fmt = SDL_GetPixelFormatDetails(format);
  1605. SDLTest_Log("Checking conversion from SDL_PIXELFORMAT_RGB565 to %s", SDL_GetPixelFormatName(format));
  1606. surface32 = SDL_ConvertSurface(surface16, format);
  1607. for (p = 0; p < SDL_arraysize(pixels); ++p) {
  1608. expected[p] = Calculate565toARGB(p, fmt);
  1609. }
  1610. expected32 = SDL_CreateSurfaceFrom(SDL_arraysize(expected), 1, format, expected, sizeof(expected));
  1611. ret = SDLTest_CompareSurfaces(surface32, expected32, 0);
  1612. SDLTest_AssertCheck(ret == 0, "Validate result from SDLTest_CompareSurfaces, expected: 0, got: %i", ret);
  1613. SDL_DestroySurface(surface32);
  1614. SDL_DestroySurface(expected32);
  1615. }
  1616. SDL_DestroySurface(surface16);
  1617. return TEST_COMPLETED;
  1618. }
  1619. /* ================= Test References ================== */
  1620. /* Surface test cases */
  1621. static const SDLTest_TestCaseReference surfaceTestInvalidFormat = {
  1622. surface_testInvalidFormat, "surface_testInvalidFormat", "Tests creating surface with invalid format", TEST_ENABLED
  1623. };
  1624. static const SDLTest_TestCaseReference surfaceTestSaveLoad = {
  1625. surface_testSaveLoad, "surface_testSaveLoad", "Tests sprite saving and loading.", TEST_ENABLED
  1626. };
  1627. static const SDLTest_TestCaseReference surfaceTestBlitZeroSource = {
  1628. surface_testBlitZeroSource, "surface_testBlitZeroSource", "Tests blitting from a zero sized source rectangle", TEST_ENABLED
  1629. };
  1630. static const SDLTest_TestCaseReference surfaceTestBlit = {
  1631. surface_testBlit, "surface_testBlit", "Tests basic blitting.", TEST_ENABLED
  1632. };
  1633. static const SDLTest_TestCaseReference surfaceTestBlitTiled = {
  1634. surface_testBlitTiled, "surface_testBlitTiled", "Tests tiled blitting.", TEST_ENABLED
  1635. };
  1636. static const SDLTest_TestCaseReference surfaceTestBlit9Grid = {
  1637. surface_testBlit9Grid, "surface_testBlit9Grid", "Tests 9-grid blitting.", TEST_ENABLED
  1638. };
  1639. static const SDLTest_TestCaseReference surfaceTestBlitMultiple = {
  1640. surface_testBlitMultiple, "surface_testBlitMultiple", "Tests blitting between multiple surfaces of the same format.", TEST_ENABLED
  1641. };
  1642. static const SDLTest_TestCaseReference surfaceTestLoadFailure = {
  1643. surface_testLoadFailure, "surface_testLoadFailure", "Tests sprite loading. A failure case.", TEST_ENABLED
  1644. };
  1645. static const SDLTest_TestCaseReference surfaceTestNULLPixels = {
  1646. surface_testSurfaceNULLPixels, "surface_testSurfaceNULLPixels", "Tests surface operations with NULL pixels.", TEST_ENABLED
  1647. };
  1648. static const SDLTest_TestCaseReference surfaceTestRLEPixels = {
  1649. surface_testSurfaceRLEPixels, "surface_testSurfaceRLEPixels", "Tests surface operations with RLE surfaces.", TEST_ENABLED
  1650. };
  1651. static const SDLTest_TestCaseReference surfaceTestSurfaceConversion = {
  1652. surface_testSurfaceConversion, "surface_testSurfaceConversion", "Tests surface conversion.", TEST_ENABLED
  1653. };
  1654. static const SDLTest_TestCaseReference surfaceTestCompleteSurfaceConversion = {
  1655. surface_testCompleteSurfaceConversion, "surface_testCompleteSurfaceConversion", "Tests surface conversion across all pixel formats", TEST_ENABLED
  1656. };
  1657. static const SDLTest_TestCaseReference surfaceTestBlitColorMod = {
  1658. surface_testBlitColorMod, "surface_testBlitColorMod", "Tests some blitting routines with color mod.", TEST_ENABLED
  1659. };
  1660. static const SDLTest_TestCaseReference surfaceTestBlitAlphaMod = {
  1661. surface_testBlitAlphaMod, "surface_testBlitAlphaMod", "Tests some blitting routines with alpha mod.", TEST_ENABLED
  1662. };
  1663. static const SDLTest_TestCaseReference surfaceTestBlitBlendBlend = {
  1664. surface_testBlitBlendBlend, "surface_testBlitBlendBlend", "Tests blitting routines with blend blending mode.", TEST_ENABLED
  1665. };
  1666. static const SDLTest_TestCaseReference surfaceTestBlitBlendPremultiplied = {
  1667. surface_testBlitBlendPremultiplied, "surface_testBlitBlendPremultiplied", "Tests blitting routines with premultiplied blending mode.", TEST_ENABLED
  1668. };
  1669. static const SDLTest_TestCaseReference surfaceTestBlitBlendAdd = {
  1670. surface_testBlitBlendAdd, "surface_testBlitBlendAdd", "Tests blitting routines with add blending mode.", TEST_ENABLED
  1671. };
  1672. static const SDLTest_TestCaseReference surfaceTestBlitBlendAddPremultiplied = {
  1673. surface_testBlitBlendAddPremultiplied, "surface_testBlitBlendAddPremultiplied", "Tests blitting routines with premultiplied add blending mode.", TEST_ENABLED
  1674. };
  1675. static const SDLTest_TestCaseReference surfaceTestBlitBlendMod = {
  1676. surface_testBlitBlendMod, "surface_testBlitBlendMod", "Tests blitting routines with mod blending mode.", TEST_ENABLED
  1677. };
  1678. static const SDLTest_TestCaseReference surfaceTestBlitBlendMul = {
  1679. surface_testBlitBlendMul, "surface_testBlitBlendMul", "Tests blitting routines with mul blending mode.", TEST_ENABLED
  1680. };
  1681. static const SDLTest_TestCaseReference surfaceTestBlitInvalid = {
  1682. surface_testBlitInvalid, "surface_testBlitInvalid", "Tests blitting routines with invalid surfaces.", TEST_ENABLED
  1683. };
  1684. static const SDLTest_TestCaseReference surfaceTestBlitsWithBadCoordinates = {
  1685. surface_testBlitsWithBadCoordinates, "surface_testBlitsWithBadCoordinates", "Test blitting routines with bad coordinates.", TEST_ENABLED
  1686. };
  1687. static const SDLTest_TestCaseReference surfaceTestOverflow = {
  1688. surface_testOverflow, "surface_testOverflow", "Test overflow detection.", TEST_ENABLED
  1689. };
  1690. static const SDLTest_TestCaseReference surfaceTestFlip = {
  1691. surface_testFlip, "surface_testFlip", "Test surface flipping.", TEST_ENABLED
  1692. };
  1693. static const SDLTest_TestCaseReference surfaceTestPalette = {
  1694. surface_testPalette, "surface_testPalette", "Test surface palette operations.", TEST_ENABLED
  1695. };
  1696. static const SDLTest_TestCaseReference surfaceTestPalettization = {
  1697. surface_testPalettization, "surface_testPalettization", "Test surface palettization.", TEST_ENABLED
  1698. };
  1699. static const SDLTest_TestCaseReference surfaceTestClearSurface = {
  1700. surface_testClearSurface, "surface_testClearSurface", "Test clear surface operations.", TEST_ENABLED
  1701. };
  1702. static const SDLTest_TestCaseReference surfaceTestPremultiplyAlpha = {
  1703. surface_testPremultiplyAlpha, "surface_testPremultiplyAlpha", "Test alpha premultiply operations.", TEST_ENABLED
  1704. };
  1705. static const SDLTest_TestCaseReference surfaceTestScale = {
  1706. surface_testScale, "surface_testScale", "Test scaling operations.", TEST_ENABLED
  1707. };
  1708. static const SDLTest_TestCaseReference surfaceTest16BitTo32Bit = {
  1709. surface_test16BitTo32Bit, "surface_test16BitTo32Bit", "Test conversion from 16-bit to 32-bit pixels.", TEST_ENABLED
  1710. };
  1711. /* Sequence of Surface test cases */
  1712. static const SDLTest_TestCaseReference *surfaceTests[] = {
  1713. &surfaceTestInvalidFormat,
  1714. &surfaceTestSaveLoad,
  1715. &surfaceTestBlitZeroSource,
  1716. &surfaceTestBlit,
  1717. &surfaceTestBlitTiled,
  1718. &surfaceTestBlit9Grid,
  1719. &surfaceTestBlitMultiple,
  1720. &surfaceTestLoadFailure,
  1721. &surfaceTestNULLPixels,
  1722. &surfaceTestRLEPixels,
  1723. &surfaceTestSurfaceConversion,
  1724. &surfaceTestCompleteSurfaceConversion,
  1725. &surfaceTestBlitColorMod,
  1726. &surfaceTestBlitAlphaMod,
  1727. &surfaceTestBlitBlendBlend,
  1728. &surfaceTestBlitBlendPremultiplied,
  1729. &surfaceTestBlitBlendAdd,
  1730. &surfaceTestBlitBlendAddPremultiplied,
  1731. &surfaceTestBlitBlendMod,
  1732. &surfaceTestBlitBlendMul,
  1733. &surfaceTestBlitInvalid,
  1734. &surfaceTestBlitsWithBadCoordinates,
  1735. &surfaceTestOverflow,
  1736. &surfaceTestFlip,
  1737. &surfaceTestPalette,
  1738. &surfaceTestPalettization,
  1739. &surfaceTestClearSurface,
  1740. &surfaceTestPremultiplyAlpha,
  1741. &surfaceTestScale,
  1742. &surfaceTest16BitTo32Bit,
  1743. NULL
  1744. };
  1745. /* Surface test suite (global) */
  1746. SDLTest_TestSuiteReference surfaceTestSuite = {
  1747. "Surface",
  1748. surfaceSetUp,
  1749. surfaceTests,
  1750. surfaceTearDown
  1751. };