testautomation_surface.c 87 KB

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