SDL_blit_N.c 121 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include "SDL_internal.h"
  19. #if SDL_HAVE_BLIT_N
  20. #include "SDL_blit.h"
  21. #include "SDL_blit_copy.h"
  22. /* General optimized routines that write char by char */
  23. #define HAVE_FAST_WRITE_INT8 1
  24. /* On some CPU, it's slower than combining and write a word */
  25. #ifdef __MIPS__
  26. #undef HAVE_FAST_WRITE_INT8
  27. #define HAVE_FAST_WRITE_INT8 0
  28. #endif
  29. /* Functions to blit from N-bit surfaces to other surfaces */
  30. enum blit_features
  31. {
  32. BLIT_FEATURE_NONE = 0,
  33. BLIT_FEATURE_HAS_MMX = 1,
  34. BLIT_FEATURE_HAS_ALTIVEC = 2,
  35. BLIT_FEATURE_ALTIVEC_DONT_USE_PREFETCH = 4,
  36. BLIT_FEATURE_HAS_ARM_SIMD = 8
  37. };
  38. #ifdef SDL_ALTIVEC_BLITTERS
  39. #ifdef __MACOS__
  40. #include <sys/sysctl.h>
  41. static size_t GetL3CacheSize(void)
  42. {
  43. const char key[] = "hw.l3cachesize";
  44. u_int64_t result = 0;
  45. size_t typeSize = sizeof(result);
  46. int err = sysctlbyname(key, &result, &typeSize, NULL, 0);
  47. if (0 != err) {
  48. return 0;
  49. }
  50. return result;
  51. }
  52. #else
  53. static size_t GetL3CacheSize(void)
  54. {
  55. /* XXX: Just guess G4 */
  56. return 2097152;
  57. }
  58. #endif /* __MACOS__ */
  59. #if (defined(__MACOS__) && (__GNUC__ < 4))
  60. #define VECUINT8_LITERAL(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) \
  61. (vector unsigned char)(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p)
  62. #define VECUINT16_LITERAL(a, b, c, d, e, f, g, h) \
  63. (vector unsigned short)(a, b, c, d, e, f, g, h)
  64. #else
  65. #define VECUINT8_LITERAL(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p) \
  66. (vector unsigned char) \
  67. { \
  68. a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p \
  69. }
  70. #define VECUINT16_LITERAL(a, b, c, d, e, f, g, h) \
  71. (vector unsigned short) \
  72. { \
  73. a, b, c, d, e, f, g, h \
  74. }
  75. #endif
  76. #define UNALIGNED_PTR(x) (((size_t)x) & 0x0000000F)
  77. #define VSWIZZLE32(a, b, c, d) (vector unsigned char)(0x00 + a, 0x00 + b, 0x00 + c, 0x00 + d, \
  78. 0x04 + a, 0x04 + b, 0x04 + c, 0x04 + d, \
  79. 0x08 + a, 0x08 + b, 0x08 + c, 0x08 + d, \
  80. 0x0C + a, 0x0C + b, 0x0C + c, 0x0C + d)
  81. #define MAKE8888(dstfmt, r, g, b, a) \
  82. (((r << dstfmt->Rshift) & dstfmt->Rmask) | \
  83. ((g << dstfmt->Gshift) & dstfmt->Gmask) | \
  84. ((b << dstfmt->Bshift) & dstfmt->Bmask) | \
  85. ((a << dstfmt->Ashift) & dstfmt->Amask))
  86. /*
  87. * Data Stream Touch...Altivec cache prefetching.
  88. *
  89. * Don't use this on a G5...however, the speed boost is very significant
  90. * on a G4.
  91. */
  92. #define DST_CHAN_SRC 1
  93. #define DST_CHAN_DEST 2
  94. /* macro to set DST control word value... */
  95. #define DST_CTRL(size, count, stride) \
  96. (((size) << 24) | ((count) << 16) | (stride))
  97. #define VEC_ALIGNER(src) ((UNALIGNED_PTR(src)) \
  98. ? vec_lvsl(0, src) \
  99. : vec_add(vec_lvsl(8, src), vec_splat_u8(8)))
  100. /* Calculate the permute vector used for 32->32 swizzling */
  101. static vector unsigned char calc_swizzle32(const SDL_PixelFormat *srcfmt, const SDL_PixelFormat *dstfmt)
  102. {
  103. /*
  104. * We have to assume that the bits that aren't used by other
  105. * colors is alpha, and it's one complete byte, since some formats
  106. * leave alpha with a zero mask, but we should still swizzle the bits.
  107. */
  108. /* ARGB */
  109. static const struct SDL_PixelFormat default_pixel_format = {
  110. 0, NULL, 0, 0, { 0, 0 }, 0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000, 0, 0, 0, 0, 16, 8, 0, 24, 0, NULL
  111. };
  112. const vector unsigned char plus = VECUINT8_LITERAL(0x00, 0x00, 0x00, 0x00,
  113. 0x04, 0x04, 0x04, 0x04,
  114. 0x08, 0x08, 0x08, 0x08,
  115. 0x0C, 0x0C, 0x0C,
  116. 0x0C);
  117. vector unsigned char vswiz;
  118. vector unsigned int srcvec;
  119. Uint32 rmask, gmask, bmask, amask;
  120. if (!srcfmt) {
  121. srcfmt = &default_pixel_format;
  122. }
  123. if (!dstfmt) {
  124. dstfmt = &default_pixel_format;
  125. }
  126. #define RESHIFT(X) (3 - ((X) >> 3))
  127. rmask = RESHIFT(srcfmt->Rshift) << (dstfmt->Rshift);
  128. gmask = RESHIFT(srcfmt->Gshift) << (dstfmt->Gshift);
  129. bmask = RESHIFT(srcfmt->Bshift) << (dstfmt->Bshift);
  130. /* Use zero for alpha if either surface doesn't have alpha */
  131. if (dstfmt->Amask) {
  132. amask =
  133. ((srcfmt->Amask) ? RESHIFT(srcfmt->Ashift) : 0x10) << (dstfmt->Ashift);
  134. } else {
  135. amask =
  136. 0x10101010 & ((dstfmt->Rmask | dstfmt->Gmask | dstfmt->Bmask) ^
  137. 0xFFFFFFFF);
  138. }
  139. #undef RESHIFT
  140. ((unsigned int *)(char *)&srcvec)[0] = (rmask | gmask | bmask | amask);
  141. vswiz = vec_add(plus, (vector unsigned char)vec_splat(srcvec, 0));
  142. return (vswiz);
  143. }
  144. #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  145. /* reorder bytes for PowerPC little endian */
  146. static vector unsigned char reorder_ppc64le_vec(vector unsigned char vpermute)
  147. {
  148. /* The result vector of calc_swizzle32 reorder bytes using vec_perm.
  149. The LE transformation for vec_perm has an implicit assumption
  150. that the permutation is being used to reorder vector elements,
  151. not to reorder bytes within those elements.
  152. Unfortunately the result order is not the expected one for powerpc
  153. little endian when the two first vector parameters of vec_perm are
  154. not of type 'vector char'. This is because the numbering from the
  155. left for BE, and numbering from the right for LE, produces a
  156. different interpretation of what the odd and even lanes are.
  157. Refer to fedora bug 1392465
  158. */
  159. const vector unsigned char ppc64le_reorder = VECUINT8_LITERAL(
  160. 0x01, 0x00, 0x03, 0x02,
  161. 0x05, 0x04, 0x07, 0x06,
  162. 0x09, 0x08, 0x0B, 0x0A,
  163. 0x0D, 0x0C, 0x0F, 0x0E);
  164. vector unsigned char vswiz_ppc64le;
  165. vswiz_ppc64le = vec_perm(vpermute, vpermute, ppc64le_reorder);
  166. return (vswiz_ppc64le);
  167. }
  168. #endif
  169. static void Blit_XRGB8888_RGB565(SDL_BlitInfo *info);
  170. static void Blit_XRGB8888_RGB565Altivec(SDL_BlitInfo *info)
  171. {
  172. int height = info->dst_h;
  173. Uint8 *src = (Uint8 *)info->src;
  174. int srcskip = info->src_skip;
  175. Uint8 *dst = (Uint8 *)info->dst;
  176. int dstskip = info->dst_skip;
  177. SDL_PixelFormat *srcfmt = info->src_fmt;
  178. vector unsigned char valpha = vec_splat_u8(0);
  179. vector unsigned char vpermute = calc_swizzle32(srcfmt, NULL);
  180. vector unsigned char vgmerge = VECUINT8_LITERAL(0x00, 0x02, 0x00, 0x06,
  181. 0x00, 0x0a, 0x00, 0x0e,
  182. 0x00, 0x12, 0x00, 0x16,
  183. 0x00, 0x1a, 0x00, 0x1e);
  184. vector unsigned short v1 = vec_splat_u16(1);
  185. vector unsigned short v3 = vec_splat_u16(3);
  186. vector unsigned short v3f =
  187. VECUINT16_LITERAL(0x003f, 0x003f, 0x003f, 0x003f,
  188. 0x003f, 0x003f, 0x003f, 0x003f);
  189. vector unsigned short vfc =
  190. VECUINT16_LITERAL(0x00fc, 0x00fc, 0x00fc, 0x00fc,
  191. 0x00fc, 0x00fc, 0x00fc, 0x00fc);
  192. vector unsigned short vf800 = (vector unsigned short)vec_splat_u8(-7);
  193. vf800 = vec_sl(vf800, vec_splat_u16(8));
  194. while (height--) {
  195. vector unsigned char valigner;
  196. vector unsigned char voverflow;
  197. vector unsigned char vsrc;
  198. int width = info->dst_w;
  199. int extrawidth;
  200. /* do scalar until we can align... */
  201. #define ONE_PIXEL_BLEND(condition, widthvar) \
  202. while (condition) { \
  203. Uint32 Pixel; \
  204. unsigned sR, sG, sB, sA; \
  205. DISEMBLE_RGBA((Uint8 *)src, 4, srcfmt, Pixel, \
  206. sR, sG, sB, sA); \
  207. *(Uint16 *)(dst) = (((sR << 8) & 0x0000F800) | \
  208. ((sG << 3) & 0x000007E0) | \
  209. ((sB >> 3) & 0x0000001F)); \
  210. dst += 2; \
  211. src += 4; \
  212. widthvar--; \
  213. }
  214. ONE_PIXEL_BLEND(((UNALIGNED_PTR(dst)) && (width)), width);
  215. /* After all that work, here's the vector part! */
  216. extrawidth = (width % 8); /* trailing unaligned stores */
  217. width -= extrawidth;
  218. vsrc = vec_ld(0, src);
  219. valigner = VEC_ALIGNER(src);
  220. while (width) {
  221. vector unsigned short vpixel, vrpixel, vgpixel, vbpixel;
  222. vector unsigned int vsrc1, vsrc2;
  223. vector unsigned char vdst;
  224. voverflow = vec_ld(15, src);
  225. vsrc = vec_perm(vsrc, voverflow, valigner);
  226. vsrc1 = (vector unsigned int)vec_perm(vsrc, valpha, vpermute);
  227. src += 16;
  228. vsrc = voverflow;
  229. voverflow = vec_ld(15, src);
  230. vsrc = vec_perm(vsrc, voverflow, valigner);
  231. vsrc2 = (vector unsigned int)vec_perm(vsrc, valpha, vpermute);
  232. /* 1555 */
  233. vpixel = (vector unsigned short)vec_packpx(vsrc1, vsrc2);
  234. vgpixel = (vector unsigned short)vec_perm(vsrc1, vsrc2, vgmerge);
  235. vgpixel = vec_and(vgpixel, vfc);
  236. vgpixel = vec_sl(vgpixel, v3);
  237. vrpixel = vec_sl(vpixel, v1);
  238. vrpixel = vec_and(vrpixel, vf800);
  239. vbpixel = vec_and(vpixel, v3f);
  240. vdst =
  241. vec_or((vector unsigned char)vrpixel,
  242. (vector unsigned char)vgpixel);
  243. /* 565 */
  244. vdst = vec_or(vdst, (vector unsigned char)vbpixel);
  245. vec_st(vdst, 0, dst);
  246. width -= 8;
  247. src += 16;
  248. dst += 16;
  249. vsrc = voverflow;
  250. }
  251. SDL_assert(width == 0);
  252. /* do scalar until we can align... */
  253. ONE_PIXEL_BLEND((extrawidth), extrawidth);
  254. #undef ONE_PIXEL_BLEND
  255. src += srcskip; /* move to next row, accounting for pitch. */
  256. dst += dstskip;
  257. }
  258. }
  259. static void Blit_RGB565_32Altivec(SDL_BlitInfo *info)
  260. {
  261. int height = info->dst_h;
  262. Uint8 *src = (Uint8 *)info->src;
  263. int srcskip = info->src_skip;
  264. Uint8 *dst = (Uint8 *)info->dst;
  265. int dstskip = info->dst_skip;
  266. SDL_PixelFormat *srcfmt = info->src_fmt;
  267. SDL_PixelFormat *dstfmt = info->dst_fmt;
  268. unsigned alpha;
  269. vector unsigned char valpha;
  270. vector unsigned char vpermute;
  271. vector unsigned short vf800;
  272. vector unsigned int v8 = vec_splat_u32(8);
  273. vector unsigned int v16 = vec_add(v8, v8);
  274. vector unsigned short v2 = vec_splat_u16(2);
  275. vector unsigned short v3 = vec_splat_u16(3);
  276. /*
  277. 0x10 - 0x1f is the alpha
  278. 0x00 - 0x0e evens are the red
  279. 0x01 - 0x0f odds are zero
  280. */
  281. vector unsigned char vredalpha1 = VECUINT8_LITERAL(0x10, 0x00, 0x01, 0x01,
  282. 0x10, 0x02, 0x01, 0x01,
  283. 0x10, 0x04, 0x01, 0x01,
  284. 0x10, 0x06, 0x01,
  285. 0x01);
  286. vector unsigned char vredalpha2 =
  287. (vector unsigned char)(vec_add((vector unsigned int)vredalpha1, vec_sl(v8, v16)));
  288. /*
  289. 0x00 - 0x0f is ARxx ARxx ARxx ARxx
  290. 0x11 - 0x0f odds are blue
  291. */
  292. vector unsigned char vblue1 = VECUINT8_LITERAL(0x00, 0x01, 0x02, 0x11,
  293. 0x04, 0x05, 0x06, 0x13,
  294. 0x08, 0x09, 0x0a, 0x15,
  295. 0x0c, 0x0d, 0x0e, 0x17);
  296. vector unsigned char vblue2 =
  297. (vector unsigned char)(vec_add((vector unsigned int)vblue1, v8));
  298. /*
  299. 0x00 - 0x0f is ARxB ARxB ARxB ARxB
  300. 0x10 - 0x0e evens are green
  301. */
  302. vector unsigned char vgreen1 = VECUINT8_LITERAL(0x00, 0x01, 0x10, 0x03,
  303. 0x04, 0x05, 0x12, 0x07,
  304. 0x08, 0x09, 0x14, 0x0b,
  305. 0x0c, 0x0d, 0x16, 0x0f);
  306. vector unsigned char vgreen2 =
  307. (vector unsigned char)(vec_add((vector unsigned int)vgreen1, vec_sl(v8, v8)));
  308. SDL_assert(srcfmt->BytesPerPixel == 2);
  309. SDL_assert(dstfmt->BytesPerPixel == 4);
  310. vf800 = (vector unsigned short)vec_splat_u8(-7);
  311. vf800 = vec_sl(vf800, vec_splat_u16(8));
  312. if (dstfmt->Amask && info->a) {
  313. ((unsigned char *)&valpha)[0] = alpha = info->a;
  314. valpha = vec_splat(valpha, 0);
  315. } else {
  316. alpha = 0;
  317. valpha = vec_splat_u8(0);
  318. }
  319. vpermute = calc_swizzle32(NULL, dstfmt);
  320. while (height--) {
  321. vector unsigned char valigner;
  322. vector unsigned char voverflow;
  323. vector unsigned char vsrc;
  324. int width = info->dst_w;
  325. int extrawidth;
  326. /* do scalar until we can align... */
  327. #define ONE_PIXEL_BLEND(condition, widthvar) \
  328. while (condition) { \
  329. unsigned sR, sG, sB; \
  330. unsigned short Pixel = *((unsigned short *)src); \
  331. sR = (Pixel >> 8) & 0xf8; \
  332. sG = (Pixel >> 3) & 0xfc; \
  333. sB = (Pixel << 3) & 0xf8; \
  334. ASSEMBLE_RGBA(dst, 4, dstfmt, sR, sG, sB, alpha); \
  335. src += 2; \
  336. dst += 4; \
  337. widthvar--; \
  338. }
  339. ONE_PIXEL_BLEND(((UNALIGNED_PTR(dst)) && (width)), width);
  340. /* After all that work, here's the vector part! */
  341. extrawidth = (width % 8); /* trailing unaligned stores */
  342. width -= extrawidth;
  343. vsrc = vec_ld(0, src);
  344. valigner = VEC_ALIGNER(src);
  345. while (width) {
  346. vector unsigned short vR, vG, vB;
  347. vector unsigned char vdst1, vdst2;
  348. voverflow = vec_ld(15, src);
  349. vsrc = vec_perm(vsrc, voverflow, valigner);
  350. vR = vec_and((vector unsigned short)vsrc, vf800);
  351. vB = vec_sl((vector unsigned short)vsrc, v3);
  352. vG = vec_sl(vB, v2);
  353. vdst1 =
  354. (vector unsigned char)vec_perm((vector unsigned char)vR,
  355. valpha, vredalpha1);
  356. vdst1 = vec_perm(vdst1, (vector unsigned char)vB, vblue1);
  357. vdst1 = vec_perm(vdst1, (vector unsigned char)vG, vgreen1);
  358. vdst1 = vec_perm(vdst1, valpha, vpermute);
  359. vec_st(vdst1, 0, dst);
  360. vdst2 =
  361. (vector unsigned char)vec_perm((vector unsigned char)vR,
  362. valpha, vredalpha2);
  363. vdst2 = vec_perm(vdst2, (vector unsigned char)vB, vblue2);
  364. vdst2 = vec_perm(vdst2, (vector unsigned char)vG, vgreen2);
  365. vdst2 = vec_perm(vdst2, valpha, vpermute);
  366. vec_st(vdst2, 16, dst);
  367. width -= 8;
  368. dst += 32;
  369. src += 16;
  370. vsrc = voverflow;
  371. }
  372. SDL_assert(width == 0);
  373. /* do scalar until we can align... */
  374. ONE_PIXEL_BLEND((extrawidth), extrawidth);
  375. #undef ONE_PIXEL_BLEND
  376. src += srcskip; /* move to next row, accounting for pitch. */
  377. dst += dstskip;
  378. }
  379. }
  380. static void Blit_RGB555_32Altivec(SDL_BlitInfo *info)
  381. {
  382. int height = info->dst_h;
  383. Uint8 *src = (Uint8 *)info->src;
  384. int srcskip = info->src_skip;
  385. Uint8 *dst = (Uint8 *)info->dst;
  386. int dstskip = info->dst_skip;
  387. SDL_PixelFormat *srcfmt = info->src_fmt;
  388. SDL_PixelFormat *dstfmt = info->dst_fmt;
  389. unsigned alpha;
  390. vector unsigned char valpha;
  391. vector unsigned char vpermute;
  392. vector unsigned short vf800;
  393. vector unsigned int v8 = vec_splat_u32(8);
  394. vector unsigned int v16 = vec_add(v8, v8);
  395. vector unsigned short v1 = vec_splat_u16(1);
  396. vector unsigned short v3 = vec_splat_u16(3);
  397. /*
  398. 0x10 - 0x1f is the alpha
  399. 0x00 - 0x0e evens are the red
  400. 0x01 - 0x0f odds are zero
  401. */
  402. vector unsigned char vredalpha1 = VECUINT8_LITERAL(0x10, 0x00, 0x01, 0x01,
  403. 0x10, 0x02, 0x01, 0x01,
  404. 0x10, 0x04, 0x01, 0x01,
  405. 0x10, 0x06, 0x01,
  406. 0x01);
  407. vector unsigned char vredalpha2 =
  408. (vector unsigned char)(vec_add((vector unsigned int)vredalpha1, vec_sl(v8, v16)));
  409. /*
  410. 0x00 - 0x0f is ARxx ARxx ARxx ARxx
  411. 0x11 - 0x0f odds are blue
  412. */
  413. vector unsigned char vblue1 = VECUINT8_LITERAL(0x00, 0x01, 0x02, 0x11,
  414. 0x04, 0x05, 0x06, 0x13,
  415. 0x08, 0x09, 0x0a, 0x15,
  416. 0x0c, 0x0d, 0x0e, 0x17);
  417. vector unsigned char vblue2 =
  418. (vector unsigned char)(vec_add((vector unsigned int)vblue1, v8));
  419. /*
  420. 0x00 - 0x0f is ARxB ARxB ARxB ARxB
  421. 0x10 - 0x0e evens are green
  422. */
  423. vector unsigned char vgreen1 = VECUINT8_LITERAL(0x00, 0x01, 0x10, 0x03,
  424. 0x04, 0x05, 0x12, 0x07,
  425. 0x08, 0x09, 0x14, 0x0b,
  426. 0x0c, 0x0d, 0x16, 0x0f);
  427. vector unsigned char vgreen2 =
  428. (vector unsigned char)(vec_add((vector unsigned int)vgreen1, vec_sl(v8, v8)));
  429. SDL_assert(srcfmt->BytesPerPixel == 2);
  430. SDL_assert(dstfmt->BytesPerPixel == 4);
  431. vf800 = (vector unsigned short)vec_splat_u8(-7);
  432. vf800 = vec_sl(vf800, vec_splat_u16(8));
  433. if (dstfmt->Amask && info->a) {
  434. ((unsigned char *)&valpha)[0] = alpha = info->a;
  435. valpha = vec_splat(valpha, 0);
  436. } else {
  437. alpha = 0;
  438. valpha = vec_splat_u8(0);
  439. }
  440. vpermute = calc_swizzle32(NULL, dstfmt);
  441. while (height--) {
  442. vector unsigned char valigner;
  443. vector unsigned char voverflow;
  444. vector unsigned char vsrc;
  445. int width = info->dst_w;
  446. int extrawidth;
  447. /* do scalar until we can align... */
  448. #define ONE_PIXEL_BLEND(condition, widthvar) \
  449. while (condition) { \
  450. unsigned sR, sG, sB; \
  451. unsigned short Pixel = *((unsigned short *)src); \
  452. sR = (Pixel >> 7) & 0xf8; \
  453. sG = (Pixel >> 2) & 0xf8; \
  454. sB = (Pixel << 3) & 0xf8; \
  455. ASSEMBLE_RGBA(dst, 4, dstfmt, sR, sG, sB, alpha); \
  456. src += 2; \
  457. dst += 4; \
  458. widthvar--; \
  459. }
  460. ONE_PIXEL_BLEND(((UNALIGNED_PTR(dst)) && (width)), width);
  461. /* After all that work, here's the vector part! */
  462. extrawidth = (width % 8); /* trailing unaligned stores */
  463. width -= extrawidth;
  464. vsrc = vec_ld(0, src);
  465. valigner = VEC_ALIGNER(src);
  466. while (width) {
  467. vector unsigned short vR, vG, vB;
  468. vector unsigned char vdst1, vdst2;
  469. voverflow = vec_ld(15, src);
  470. vsrc = vec_perm(vsrc, voverflow, valigner);
  471. vR = vec_and(vec_sl((vector unsigned short)vsrc, v1), vf800);
  472. vB = vec_sl((vector unsigned short)vsrc, v3);
  473. vG = vec_sl(vB, v3);
  474. vdst1 =
  475. (vector unsigned char)vec_perm((vector unsigned char)vR,
  476. valpha, vredalpha1);
  477. vdst1 = vec_perm(vdst1, (vector unsigned char)vB, vblue1);
  478. vdst1 = vec_perm(vdst1, (vector unsigned char)vG, vgreen1);
  479. vdst1 = vec_perm(vdst1, valpha, vpermute);
  480. vec_st(vdst1, 0, dst);
  481. vdst2 =
  482. (vector unsigned char)vec_perm((vector unsigned char)vR,
  483. valpha, vredalpha2);
  484. vdst2 = vec_perm(vdst2, (vector unsigned char)vB, vblue2);
  485. vdst2 = vec_perm(vdst2, (vector unsigned char)vG, vgreen2);
  486. vdst2 = vec_perm(vdst2, valpha, vpermute);
  487. vec_st(vdst2, 16, dst);
  488. width -= 8;
  489. dst += 32;
  490. src += 16;
  491. vsrc = voverflow;
  492. }
  493. SDL_assert(width == 0);
  494. /* do scalar until we can align... */
  495. ONE_PIXEL_BLEND((extrawidth), extrawidth);
  496. #undef ONE_PIXEL_BLEND
  497. src += srcskip; /* move to next row, accounting for pitch. */
  498. dst += dstskip;
  499. }
  500. }
  501. static void BlitNtoNKey(SDL_BlitInfo *info);
  502. static void BlitNtoNKeyCopyAlpha(SDL_BlitInfo *info);
  503. static void Blit32to32KeyAltivec(SDL_BlitInfo *info)
  504. {
  505. int height = info->dst_h;
  506. Uint32 *srcp = (Uint32 *)info->src;
  507. int srcskip = info->src_skip / 4;
  508. Uint32 *dstp = (Uint32 *)info->dst;
  509. int dstskip = info->dst_skip / 4;
  510. SDL_PixelFormat *srcfmt = info->src_fmt;
  511. int srcbpp = srcfmt->BytesPerPixel;
  512. SDL_PixelFormat *dstfmt = info->dst_fmt;
  513. int dstbpp = dstfmt->BytesPerPixel;
  514. int copy_alpha = (srcfmt->Amask && dstfmt->Amask);
  515. unsigned alpha = dstfmt->Amask ? info->a : 0;
  516. Uint32 rgbmask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask;
  517. Uint32 ckey = info->colorkey;
  518. vector unsigned int valpha;
  519. vector unsigned char vpermute;
  520. vector unsigned char vzero;
  521. vector unsigned int vckey;
  522. vector unsigned int vrgbmask;
  523. vpermute = calc_swizzle32(srcfmt, dstfmt);
  524. if (info->dst_w < 16) {
  525. if (copy_alpha) {
  526. BlitNtoNKeyCopyAlpha(info);
  527. } else {
  528. BlitNtoNKey(info);
  529. }
  530. return;
  531. }
  532. vzero = vec_splat_u8(0);
  533. if (alpha) {
  534. ((unsigned char *)&valpha)[0] = (unsigned char)alpha;
  535. valpha =
  536. (vector unsigned int)vec_splat((vector unsigned char)valpha, 0);
  537. } else {
  538. valpha = (vector unsigned int)vzero;
  539. }
  540. ckey &= rgbmask;
  541. ((unsigned int *)(char *)&vckey)[0] = ckey;
  542. vckey = vec_splat(vckey, 0);
  543. ((unsigned int *)(char *)&vrgbmask)[0] = rgbmask;
  544. vrgbmask = vec_splat(vrgbmask, 0);
  545. #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  546. /* reorder bytes for PowerPC little endian */
  547. vpermute = reorder_ppc64le_vec(vpermute);
  548. #endif
  549. while (height--) {
  550. #define ONE_PIXEL_BLEND(condition, widthvar) \
  551. if (copy_alpha) { \
  552. while (condition) { \
  553. Uint32 Pixel; \
  554. unsigned sR, sG, sB, sA; \
  555. DISEMBLE_RGBA((Uint8 *)srcp, srcbpp, srcfmt, Pixel, \
  556. sR, sG, sB, sA); \
  557. if ((Pixel & rgbmask) != ckey) { \
  558. ASSEMBLE_RGBA((Uint8 *)dstp, dstbpp, dstfmt, \
  559. sR, sG, sB, sA); \
  560. } \
  561. dstp = (Uint32 *)(((Uint8 *)dstp) + dstbpp); \
  562. srcp = (Uint32 *)(((Uint8 *)srcp) + srcbpp); \
  563. widthvar--; \
  564. } \
  565. } else { \
  566. while (condition) { \
  567. Uint32 Pixel; \
  568. unsigned sR, sG, sB; \
  569. RETRIEVE_RGB_PIXEL((Uint8 *)srcp, srcbpp, Pixel); \
  570. if (Pixel != ckey) { \
  571. RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB); \
  572. ASSEMBLE_RGBA((Uint8 *)dstp, dstbpp, dstfmt, \
  573. sR, sG, sB, alpha); \
  574. } \
  575. dstp = (Uint32 *)(((Uint8 *)dstp) + dstbpp); \
  576. srcp = (Uint32 *)(((Uint8 *)srcp) + srcbpp); \
  577. widthvar--; \
  578. } \
  579. }
  580. int width = info->dst_w;
  581. ONE_PIXEL_BLEND((UNALIGNED_PTR(dstp)) && (width), width);
  582. SDL_assert(width > 0);
  583. if (width > 0) {
  584. int extrawidth = (width % 4);
  585. vector unsigned char valigner = VEC_ALIGNER(srcp);
  586. vector unsigned int vs = vec_ld(0, srcp);
  587. width -= extrawidth;
  588. SDL_assert(width >= 4);
  589. while (width) {
  590. vector unsigned char vsel;
  591. vector unsigned int vd;
  592. vector unsigned int voverflow = vec_ld(15, srcp);
  593. /* load the source vec */
  594. vs = vec_perm(vs, voverflow, valigner);
  595. /* vsel is set for items that match the key */
  596. vsel = (vector unsigned char)vec_and(vs, vrgbmask);
  597. vsel = (vector unsigned char)vec_cmpeq(vs, vckey);
  598. /* permute the src vec to the dest format */
  599. vs = vec_perm(vs, valpha, vpermute);
  600. /* load the destination vec */
  601. vd = vec_ld(0, dstp);
  602. /* select the source and dest into vs */
  603. vd = (vector unsigned int)vec_sel((vector unsigned char)vs,
  604. (vector unsigned char)vd,
  605. vsel);
  606. vec_st(vd, 0, dstp);
  607. srcp += 4;
  608. width -= 4;
  609. dstp += 4;
  610. vs = voverflow;
  611. }
  612. ONE_PIXEL_BLEND((extrawidth), extrawidth);
  613. #undef ONE_PIXEL_BLEND
  614. srcp += srcskip;
  615. dstp += dstskip;
  616. }
  617. }
  618. }
  619. /* Altivec code to swizzle one 32-bit surface to a different 32-bit format. */
  620. /* Use this on a G5 */
  621. static void ConvertAltivec32to32_noprefetch(SDL_BlitInfo *info)
  622. {
  623. int height = info->dst_h;
  624. Uint32 *src = (Uint32 *)info->src;
  625. int srcskip = info->src_skip / 4;
  626. Uint32 *dst = (Uint32 *)info->dst;
  627. int dstskip = info->dst_skip / 4;
  628. SDL_PixelFormat *srcfmt = info->src_fmt;
  629. SDL_PixelFormat *dstfmt = info->dst_fmt;
  630. vector unsigned int vzero = vec_splat_u32(0);
  631. vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt);
  632. if (dstfmt->Amask && !srcfmt->Amask) {
  633. if (info->a) {
  634. vector unsigned char valpha;
  635. ((unsigned char *)&valpha)[0] = info->a;
  636. vzero = (vector unsigned int)vec_splat(valpha, 0);
  637. }
  638. }
  639. SDL_assert(srcfmt->BytesPerPixel == 4);
  640. SDL_assert(dstfmt->BytesPerPixel == 4);
  641. #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  642. /* reorder bytes for PowerPC little endian */
  643. vpermute = reorder_ppc64le_vec(vpermute);
  644. #endif
  645. while (height--) {
  646. vector unsigned char valigner;
  647. vector unsigned int vbits;
  648. vector unsigned int voverflow;
  649. Uint32 bits;
  650. Uint8 r, g, b, a;
  651. int width = info->dst_w;
  652. int extrawidth;
  653. /* do scalar until we can align... */
  654. while ((UNALIGNED_PTR(dst)) && (width)) {
  655. bits = *(src++);
  656. RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
  657. if (!srcfmt->Amask)
  658. a = info->a;
  659. *(dst++) = MAKE8888(dstfmt, r, g, b, a);
  660. width--;
  661. }
  662. /* After all that work, here's the vector part! */
  663. extrawidth = (width % 4);
  664. width -= extrawidth;
  665. valigner = VEC_ALIGNER(src);
  666. vbits = vec_ld(0, src);
  667. while (width) {
  668. voverflow = vec_ld(15, src);
  669. src += 4;
  670. width -= 4;
  671. vbits = vec_perm(vbits, voverflow, valigner); /* src is ready. */
  672. vbits = vec_perm(vbits, vzero, vpermute); /* swizzle it. */
  673. vec_st(vbits, 0, dst); /* store it back out. */
  674. dst += 4;
  675. vbits = voverflow;
  676. }
  677. SDL_assert(width == 0);
  678. /* cover pixels at the end of the row that didn't fit in 16 bytes. */
  679. while (extrawidth) {
  680. bits = *(src++); /* max 7 pixels, don't bother with prefetch. */
  681. RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
  682. if (!srcfmt->Amask)
  683. a = info->a;
  684. *(dst++) = MAKE8888(dstfmt, r, g, b, a);
  685. extrawidth--;
  686. }
  687. src += srcskip;
  688. dst += dstskip;
  689. }
  690. }
  691. /* Altivec code to swizzle one 32-bit surface to a different 32-bit format. */
  692. /* Use this on a G4 */
  693. static void ConvertAltivec32to32_prefetch(SDL_BlitInfo *info)
  694. {
  695. const int scalar_dst_lead = sizeof(Uint32) * 4;
  696. const int vector_dst_lead = sizeof(Uint32) * 16;
  697. int height = info->dst_h;
  698. Uint32 *src = (Uint32 *)info->src;
  699. int srcskip = info->src_skip / 4;
  700. Uint32 *dst = (Uint32 *)info->dst;
  701. int dstskip = info->dst_skip / 4;
  702. SDL_PixelFormat *srcfmt = info->src_fmt;
  703. SDL_PixelFormat *dstfmt = info->dst_fmt;
  704. vector unsigned int vzero = vec_splat_u32(0);
  705. vector unsigned char vpermute = calc_swizzle32(srcfmt, dstfmt);
  706. if (dstfmt->Amask && !srcfmt->Amask) {
  707. if (info->a) {
  708. vector unsigned char valpha;
  709. ((unsigned char *)&valpha)[0] = info->a;
  710. vzero = (vector unsigned int)vec_splat(valpha, 0);
  711. }
  712. }
  713. SDL_assert(srcfmt->BytesPerPixel == 4);
  714. SDL_assert(dstfmt->BytesPerPixel == 4);
  715. #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  716. /* reorder bytes for PowerPC little endian */
  717. vpermute = reorder_ppc64le_vec(vpermute);
  718. #endif
  719. while (height--) {
  720. vector unsigned char valigner;
  721. vector unsigned int vbits;
  722. vector unsigned int voverflow;
  723. Uint32 bits;
  724. Uint8 r, g, b, a;
  725. int width = info->dst_w;
  726. int extrawidth;
  727. /* do scalar until we can align... */
  728. while ((UNALIGNED_PTR(dst)) && (width)) {
  729. vec_dstt(src + scalar_dst_lead, DST_CTRL(2, 32, 1024),
  730. DST_CHAN_SRC);
  731. vec_dstst(dst + scalar_dst_lead, DST_CTRL(2, 32, 1024),
  732. DST_CHAN_DEST);
  733. bits = *(src++);
  734. RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
  735. if (!srcfmt->Amask)
  736. a = info->a;
  737. *(dst++) = MAKE8888(dstfmt, r, g, b, a);
  738. width--;
  739. }
  740. /* After all that work, here's the vector part! */
  741. extrawidth = (width % 4);
  742. width -= extrawidth;
  743. valigner = VEC_ALIGNER(src);
  744. vbits = vec_ld(0, src);
  745. while (width) {
  746. vec_dstt(src + vector_dst_lead, DST_CTRL(2, 32, 1024),
  747. DST_CHAN_SRC);
  748. vec_dstst(dst + vector_dst_lead, DST_CTRL(2, 32, 1024),
  749. DST_CHAN_DEST);
  750. voverflow = vec_ld(15, src);
  751. src += 4;
  752. width -= 4;
  753. vbits = vec_perm(vbits, voverflow, valigner); /* src is ready. */
  754. vbits = vec_perm(vbits, vzero, vpermute); /* swizzle it. */
  755. vec_st(vbits, 0, dst); /* store it back out. */
  756. dst += 4;
  757. vbits = voverflow;
  758. }
  759. SDL_assert(width == 0);
  760. /* cover pixels at the end of the row that didn't fit in 16 bytes. */
  761. while (extrawidth) {
  762. bits = *(src++); /* max 7 pixels, don't bother with prefetch. */
  763. RGBA_FROM_8888(bits, srcfmt, r, g, b, a);
  764. if (!srcfmt->Amask)
  765. a = info->a;
  766. *(dst++) = MAKE8888(dstfmt, r, g, b, a);
  767. extrawidth--;
  768. }
  769. src += srcskip;
  770. dst += dstskip;
  771. }
  772. vec_dss(DST_CHAN_SRC);
  773. vec_dss(DST_CHAN_DEST);
  774. }
  775. static enum blit_features GetBlitFeatures(void)
  776. {
  777. static enum blit_features features = -1;
  778. if (features == (enum blit_features) - 1) {
  779. /* Provide an override for testing .. */
  780. char *override = SDL_getenv("SDL_ALTIVEC_BLIT_FEATURES");
  781. if (override) {
  782. unsigned int features_as_uint = 0;
  783. SDL_sscanf(override, "%u", &features_as_uint);
  784. features = (enum blit_features)features_as_uint;
  785. } else {
  786. features = (0
  787. /* Feature 1 is has-MMX */
  788. | ((SDL_HasMMX()) ? BLIT_FEATURE_HAS_MMX : 0)
  789. /* Feature 2 is has-AltiVec */
  790. | ((SDL_HasAltiVec()) ? BLIT_FEATURE_HAS_ALTIVEC : 0)
  791. /* Feature 4 is dont-use-prefetch */
  792. /* !!!! FIXME: Check for G5 or later, not the cache size! Always prefetch on a G4. */
  793. | ((GetL3CacheSize() == 0) ? BLIT_FEATURE_ALTIVEC_DONT_USE_PREFETCH : 0));
  794. }
  795. }
  796. return features;
  797. }
  798. #ifdef __MWERKS__
  799. #pragma altivec_model off
  800. #endif
  801. #else
  802. /* Feature 1 is has-MMX */
  803. #define GetBlitFeatures() ((SDL_HasMMX() ? BLIT_FEATURE_HAS_MMX : 0) | (SDL_HasARMSIMD() ? BLIT_FEATURE_HAS_ARM_SIMD : 0))
  804. #endif
  805. #ifdef SDL_ARM_SIMD_BLITTERS
  806. void Blit_XBGR8888_XRGB8888ARMSIMDAsm(int32_t w, int32_t h, uint32_t *dst, int32_t dst_stride, uint32_t *src, int32_t src_stride);
  807. static void Blit_XBGR8888_XRGB8888ARMSIMD(SDL_BlitInfo *info)
  808. {
  809. int32_t width = info->dst_w;
  810. int32_t height = info->dst_h;
  811. uint32_t *dstp = (uint32_t *)info->dst;
  812. int32_t dststride = width + (info->dst_skip >> 2);
  813. uint32_t *srcp = (uint32_t *)info->src;
  814. int32_t srcstride = width + (info->src_skip >> 2);
  815. Blit_XBGR8888_XRGB8888ARMSIMDAsm(width, height, dstp, dststride, srcp, srcstride);
  816. }
  817. void Blit_RGB444_XRGB8888ARMSIMDAsm(int32_t w, int32_t h, uint32_t *dst, int32_t dst_stride, uint16_t *src, int32_t src_stride);
  818. static void Blit_RGB444_XRGB8888ARMSIMD(SDL_BlitInfo *info)
  819. {
  820. int32_t width = info->dst_w;
  821. int32_t height = info->dst_h;
  822. uint32_t *dstp = (uint32_t *)info->dst;
  823. int32_t dststride = width + (info->dst_skip >> 2);
  824. uint16_t *srcp = (uint16_t *)info->src;
  825. int32_t srcstride = width + (info->src_skip >> 1);
  826. Blit_RGB444_XRGB8888ARMSIMDAsm(width, height, dstp, dststride, srcp, srcstride);
  827. }
  828. #endif
  829. /* This is now endian dependent */
  830. #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  831. #define HI 1
  832. #define LO 0
  833. #else /* SDL_BYTEORDER == SDL_BIG_ENDIAN */
  834. #define HI 0
  835. #define LO 1
  836. #endif
  837. /* Special optimized blit for RGB 8-8-8 --> RGB 3-3-2 */
  838. #define RGB888_RGB332(dst, src) \
  839. { \
  840. dst = (Uint8)((((src)&0x00E00000) >> 16) | \
  841. (((src)&0x0000E000) >> 11) | \
  842. (((src)&0x000000C0) >> 6)); \
  843. }
  844. static void Blit_XRGB8888_index8(SDL_BlitInfo *info)
  845. {
  846. #ifndef USE_DUFFS_LOOP
  847. int c;
  848. #endif
  849. int width, height;
  850. Uint32 *src;
  851. const Uint8 *map;
  852. Uint8 *dst;
  853. int srcskip, dstskip;
  854. /* Set up some basic variables */
  855. width = info->dst_w;
  856. height = info->dst_h;
  857. src = (Uint32 *)info->src;
  858. srcskip = info->src_skip / 4;
  859. dst = info->dst;
  860. dstskip = info->dst_skip;
  861. map = info->table;
  862. if (map == NULL) {
  863. while (height--) {
  864. #ifdef USE_DUFFS_LOOP
  865. /* *INDENT-OFF* */ /* clang-format off */
  866. DUFFS_LOOP(
  867. RGB888_RGB332(*dst++, *src);
  868. , width);
  869. /* *INDENT-ON* */ /* clang-format on */
  870. #else
  871. for (c = width / 4; c; --c) {
  872. /* Pack RGB into 8bit pixel */
  873. ++src;
  874. RGB888_RGB332(*dst++, *src);
  875. ++src;
  876. RGB888_RGB332(*dst++, *src);
  877. ++src;
  878. RGB888_RGB332(*dst++, *src);
  879. ++src;
  880. }
  881. switch (width & 3) {
  882. case 3:
  883. RGB888_RGB332(*dst++, *src);
  884. ++src;
  885. SDL_FALLTHROUGH;
  886. case 2:
  887. RGB888_RGB332(*dst++, *src);
  888. ++src;
  889. SDL_FALLTHROUGH;
  890. case 1:
  891. RGB888_RGB332(*dst++, *src);
  892. ++src;
  893. }
  894. #endif /* USE_DUFFS_LOOP */
  895. src += srcskip;
  896. dst += dstskip;
  897. }
  898. } else {
  899. int Pixel;
  900. while (height--) {
  901. #ifdef USE_DUFFS_LOOP
  902. /* *INDENT-OFF* */ /* clang-format off */
  903. DUFFS_LOOP(
  904. RGB888_RGB332(Pixel, *src);
  905. *dst++ = map[Pixel];
  906. ++src;
  907. , width);
  908. /* *INDENT-ON* */ /* clang-format on */
  909. #else
  910. for (c = width / 4; c; --c) {
  911. /* Pack RGB into 8bit pixel */
  912. RGB888_RGB332(Pixel, *src);
  913. *dst++ = map[Pixel];
  914. ++src;
  915. RGB888_RGB332(Pixel, *src);
  916. *dst++ = map[Pixel];
  917. ++src;
  918. RGB888_RGB332(Pixel, *src);
  919. *dst++ = map[Pixel];
  920. ++src;
  921. RGB888_RGB332(Pixel, *src);
  922. *dst++ = map[Pixel];
  923. ++src;
  924. }
  925. switch (width & 3) {
  926. case 3:
  927. RGB888_RGB332(Pixel, *src);
  928. *dst++ = map[Pixel];
  929. ++src;
  930. SDL_FALLTHROUGH;
  931. case 2:
  932. RGB888_RGB332(Pixel, *src);
  933. *dst++ = map[Pixel];
  934. ++src;
  935. SDL_FALLTHROUGH;
  936. case 1:
  937. RGB888_RGB332(Pixel, *src);
  938. *dst++ = map[Pixel];
  939. ++src;
  940. }
  941. #endif /* USE_DUFFS_LOOP */
  942. src += srcskip;
  943. dst += dstskip;
  944. }
  945. }
  946. }
  947. /* Special optimized blit for RGB 10-10-10 --> RGB 3-3-2 */
  948. #define RGB101010_RGB332(dst, src) \
  949. { \
  950. dst = (Uint8)((((src)&0x38000000) >> 22) | \
  951. (((src)&0x000E0000) >> 15) | \
  952. (((src)&0x00000300) >> 8)); \
  953. }
  954. static void Blit_RGB101010_index8(SDL_BlitInfo *info)
  955. {
  956. #ifndef USE_DUFFS_LOOP
  957. int c;
  958. #endif
  959. int width, height;
  960. Uint32 *src;
  961. const Uint8 *map;
  962. Uint8 *dst;
  963. int srcskip, dstskip;
  964. /* Set up some basic variables */
  965. width = info->dst_w;
  966. height = info->dst_h;
  967. src = (Uint32 *)info->src;
  968. srcskip = info->src_skip / 4;
  969. dst = info->dst;
  970. dstskip = info->dst_skip;
  971. map = info->table;
  972. if (map == NULL) {
  973. while (height--) {
  974. #ifdef USE_DUFFS_LOOP
  975. /* *INDENT-OFF* */ /* clang-format off */
  976. DUFFS_LOOP(
  977. RGB101010_RGB332(*dst++, *src);
  978. , width);
  979. /* *INDENT-ON* */ /* clang-format on */
  980. #else
  981. for (c = width / 4; c; --c) {
  982. /* Pack RGB into 8bit pixel */
  983. ++src;
  984. RGB101010_RGB332(*dst++, *src);
  985. ++src;
  986. RGB101010_RGB332(*dst++, *src);
  987. ++src;
  988. RGB101010_RGB332(*dst++, *src);
  989. ++src;
  990. }
  991. switch (width & 3) {
  992. case 3:
  993. RGB101010_RGB332(*dst++, *src);
  994. ++src;
  995. SDL_FALLTHROUGH;
  996. case 2:
  997. RGB101010_RGB332(*dst++, *src);
  998. ++src;
  999. SDL_FALLTHROUGH;
  1000. case 1:
  1001. RGB101010_RGB332(*dst++, *src);
  1002. ++src;
  1003. }
  1004. #endif /* USE_DUFFS_LOOP */
  1005. src += srcskip;
  1006. dst += dstskip;
  1007. }
  1008. } else {
  1009. int Pixel;
  1010. while (height--) {
  1011. #ifdef USE_DUFFS_LOOP
  1012. /* *INDENT-OFF* */ /* clang-format off */
  1013. DUFFS_LOOP(
  1014. RGB101010_RGB332(Pixel, *src);
  1015. *dst++ = map[Pixel];
  1016. ++src;
  1017. , width);
  1018. /* *INDENT-ON* */ /* clang-format on */
  1019. #else
  1020. for (c = width / 4; c; --c) {
  1021. /* Pack RGB into 8bit pixel */
  1022. RGB101010_RGB332(Pixel, *src);
  1023. *dst++ = map[Pixel];
  1024. ++src;
  1025. RGB101010_RGB332(Pixel, *src);
  1026. *dst++ = map[Pixel];
  1027. ++src;
  1028. RGB101010_RGB332(Pixel, *src);
  1029. *dst++ = map[Pixel];
  1030. ++src;
  1031. RGB101010_RGB332(Pixel, *src);
  1032. *dst++ = map[Pixel];
  1033. ++src;
  1034. }
  1035. switch (width & 3) {
  1036. case 3:
  1037. RGB101010_RGB332(Pixel, *src);
  1038. *dst++ = map[Pixel];
  1039. ++src;
  1040. SDL_FALLTHROUGH;
  1041. case 2:
  1042. RGB101010_RGB332(Pixel, *src);
  1043. *dst++ = map[Pixel];
  1044. ++src;
  1045. SDL_FALLTHROUGH;
  1046. case 1:
  1047. RGB101010_RGB332(Pixel, *src);
  1048. *dst++ = map[Pixel];
  1049. ++src;
  1050. }
  1051. #endif /* USE_DUFFS_LOOP */
  1052. src += srcskip;
  1053. dst += dstskip;
  1054. }
  1055. }
  1056. }
  1057. /* Special optimized blit for RGB 8-8-8 --> RGB 5-5-5 */
  1058. #define RGB888_RGB555(dst, src) \
  1059. { \
  1060. *(Uint16 *)(dst) = (Uint16)((((*src) & 0x00F80000) >> 9) | \
  1061. (((*src) & 0x0000F800) >> 6) | \
  1062. (((*src) & 0x000000F8) >> 3)); \
  1063. }
  1064. #ifndef USE_DUFFS_LOOP
  1065. #define RGB888_RGB555_TWO(dst, src) \
  1066. { \
  1067. *(Uint32 *)(dst) = (((((src[HI]) & 0x00F80000) >> 9) | \
  1068. (((src[HI]) & 0x0000F800) >> 6) | \
  1069. (((src[HI]) & 0x000000F8) >> 3)) \
  1070. << 16) | \
  1071. (((src[LO]) & 0x00F80000) >> 9) | \
  1072. (((src[LO]) & 0x0000F800) >> 6) | \
  1073. (((src[LO]) & 0x000000F8) >> 3); \
  1074. }
  1075. #endif
  1076. static void Blit_XRGB8888_RGB555(SDL_BlitInfo *info)
  1077. {
  1078. #ifndef USE_DUFFS_LOOP
  1079. int c;
  1080. #endif
  1081. int width, height;
  1082. Uint32 *src;
  1083. Uint16 *dst;
  1084. int srcskip, dstskip;
  1085. /* Set up some basic variables */
  1086. width = info->dst_w;
  1087. height = info->dst_h;
  1088. src = (Uint32 *)info->src;
  1089. srcskip = info->src_skip / 4;
  1090. dst = (Uint16 *)info->dst;
  1091. dstskip = info->dst_skip / 2;
  1092. #ifdef USE_DUFFS_LOOP
  1093. while (height--) {
  1094. /* *INDENT-OFF* */ /* clang-format off */
  1095. DUFFS_LOOP(
  1096. RGB888_RGB555(dst, src);
  1097. ++src;
  1098. ++dst;
  1099. , width);
  1100. /* *INDENT-ON* */ /* clang-format on */
  1101. src += srcskip;
  1102. dst += dstskip;
  1103. }
  1104. #else
  1105. /* Memory align at 4-byte boundary, if necessary */
  1106. if ((long)dst & 0x03) {
  1107. /* Don't do anything if width is 0 */
  1108. if (width == 0) {
  1109. return;
  1110. }
  1111. --width;
  1112. while (height--) {
  1113. /* Perform copy alignment */
  1114. RGB888_RGB555(dst, src);
  1115. ++src;
  1116. ++dst;
  1117. /* Copy in 4 pixel chunks */
  1118. for (c = width / 4; c; --c) {
  1119. RGB888_RGB555_TWO(dst, src);
  1120. src += 2;
  1121. dst += 2;
  1122. RGB888_RGB555_TWO(dst, src);
  1123. src += 2;
  1124. dst += 2;
  1125. }
  1126. /* Get any leftovers */
  1127. switch (width & 3) {
  1128. case 3:
  1129. RGB888_RGB555(dst, src);
  1130. ++src;
  1131. ++dst;
  1132. SDL_FALLTHROUGH;
  1133. case 2:
  1134. RGB888_RGB555_TWO(dst, src);
  1135. src += 2;
  1136. dst += 2;
  1137. break;
  1138. case 1:
  1139. RGB888_RGB555(dst, src);
  1140. ++src;
  1141. ++dst;
  1142. break;
  1143. }
  1144. src += srcskip;
  1145. dst += dstskip;
  1146. }
  1147. } else {
  1148. while (height--) {
  1149. /* Copy in 4 pixel chunks */
  1150. for (c = width / 4; c; --c) {
  1151. RGB888_RGB555_TWO(dst, src);
  1152. src += 2;
  1153. dst += 2;
  1154. RGB888_RGB555_TWO(dst, src);
  1155. src += 2;
  1156. dst += 2;
  1157. }
  1158. /* Get any leftovers */
  1159. switch (width & 3) {
  1160. case 3:
  1161. RGB888_RGB555(dst, src);
  1162. ++src;
  1163. ++dst;
  1164. SDL_FALLTHROUGH;
  1165. case 2:
  1166. RGB888_RGB555_TWO(dst, src);
  1167. src += 2;
  1168. dst += 2;
  1169. break;
  1170. case 1:
  1171. RGB888_RGB555(dst, src);
  1172. ++src;
  1173. ++dst;
  1174. break;
  1175. }
  1176. src += srcskip;
  1177. dst += dstskip;
  1178. }
  1179. }
  1180. #endif /* USE_DUFFS_LOOP */
  1181. }
  1182. /* Special optimized blit for RGB 8-8-8 --> RGB 5-6-5 */
  1183. #define RGB888_RGB565(dst, src) \
  1184. { \
  1185. *(Uint16 *)(dst) = (Uint16)((((*src) & 0x00F80000) >> 8) | \
  1186. (((*src) & 0x0000FC00) >> 5) | \
  1187. (((*src) & 0x000000F8) >> 3)); \
  1188. }
  1189. #ifndef USE_DUFFS_LOOP
  1190. #define RGB888_RGB565_TWO(dst, src) \
  1191. { \
  1192. *(Uint32 *)(dst) = (((((src[HI]) & 0x00F80000) >> 8) | \
  1193. (((src[HI]) & 0x0000FC00) >> 5) | \
  1194. (((src[HI]) & 0x000000F8) >> 3)) \
  1195. << 16) | \
  1196. (((src[LO]) & 0x00F80000) >> 8) | \
  1197. (((src[LO]) & 0x0000FC00) >> 5) | \
  1198. (((src[LO]) & 0x000000F8) >> 3); \
  1199. }
  1200. #endif
  1201. static void Blit_XRGB8888_RGB565(SDL_BlitInfo *info)
  1202. {
  1203. #ifndef USE_DUFFS_LOOP
  1204. int c;
  1205. #endif
  1206. int width, height;
  1207. Uint32 *src;
  1208. Uint16 *dst;
  1209. int srcskip, dstskip;
  1210. /* Set up some basic variables */
  1211. width = info->dst_w;
  1212. height = info->dst_h;
  1213. src = (Uint32 *)info->src;
  1214. srcskip = info->src_skip / 4;
  1215. dst = (Uint16 *)info->dst;
  1216. dstskip = info->dst_skip / 2;
  1217. #ifdef USE_DUFFS_LOOP
  1218. while (height--) {
  1219. /* *INDENT-OFF* */ /* clang-format off */
  1220. DUFFS_LOOP(
  1221. RGB888_RGB565(dst, src);
  1222. ++src;
  1223. ++dst;
  1224. , width);
  1225. /* *INDENT-ON* */ /* clang-format on */
  1226. src += srcskip;
  1227. dst += dstskip;
  1228. }
  1229. #else
  1230. /* Memory align at 4-byte boundary, if necessary */
  1231. if ((long)dst & 0x03) {
  1232. /* Don't do anything if width is 0 */
  1233. if (width == 0) {
  1234. return;
  1235. }
  1236. --width;
  1237. while (height--) {
  1238. /* Perform copy alignment */
  1239. RGB888_RGB565(dst, src);
  1240. ++src;
  1241. ++dst;
  1242. /* Copy in 4 pixel chunks */
  1243. for (c = width / 4; c; --c) {
  1244. RGB888_RGB565_TWO(dst, src);
  1245. src += 2;
  1246. dst += 2;
  1247. RGB888_RGB565_TWO(dst, src);
  1248. src += 2;
  1249. dst += 2;
  1250. }
  1251. /* Get any leftovers */
  1252. switch (width & 3) {
  1253. case 3:
  1254. RGB888_RGB565(dst, src);
  1255. ++src;
  1256. ++dst;
  1257. SDL_FALLTHROUGH;
  1258. case 2:
  1259. RGB888_RGB565_TWO(dst, src);
  1260. src += 2;
  1261. dst += 2;
  1262. break;
  1263. case 1:
  1264. RGB888_RGB565(dst, src);
  1265. ++src;
  1266. ++dst;
  1267. break;
  1268. }
  1269. src += srcskip;
  1270. dst += dstskip;
  1271. }
  1272. } else {
  1273. while (height--) {
  1274. /* Copy in 4 pixel chunks */
  1275. for (c = width / 4; c; --c) {
  1276. RGB888_RGB565_TWO(dst, src);
  1277. src += 2;
  1278. dst += 2;
  1279. RGB888_RGB565_TWO(dst, src);
  1280. src += 2;
  1281. dst += 2;
  1282. }
  1283. /* Get any leftovers */
  1284. switch (width & 3) {
  1285. case 3:
  1286. RGB888_RGB565(dst, src);
  1287. ++src;
  1288. ++dst;
  1289. SDL_FALLTHROUGH;
  1290. case 2:
  1291. RGB888_RGB565_TWO(dst, src);
  1292. src += 2;
  1293. dst += 2;
  1294. break;
  1295. case 1:
  1296. RGB888_RGB565(dst, src);
  1297. ++src;
  1298. ++dst;
  1299. break;
  1300. }
  1301. src += srcskip;
  1302. dst += dstskip;
  1303. }
  1304. }
  1305. #endif /* USE_DUFFS_LOOP */
  1306. }
  1307. #if SDL_HAVE_BLIT_N_RGB565
  1308. /* Special optimized blit for RGB 5-6-5 --> 32-bit RGB surfaces */
  1309. #define RGB565_32(dst, src, map) (map[src[LO] * 2] + map[src[HI] * 2 + 1])
  1310. static void Blit_RGB565_32(SDL_BlitInfo *info, const Uint32 *map)
  1311. {
  1312. #ifndef USE_DUFFS_LOOP
  1313. int c;
  1314. #endif
  1315. int width, height;
  1316. Uint8 *src;
  1317. Uint32 *dst;
  1318. int srcskip, dstskip;
  1319. /* Set up some basic variables */
  1320. width = info->dst_w;
  1321. height = info->dst_h;
  1322. src = info->src;
  1323. srcskip = info->src_skip;
  1324. dst = (Uint32 *)info->dst;
  1325. dstskip = info->dst_skip / 4;
  1326. #ifdef USE_DUFFS_LOOP
  1327. while (height--) {
  1328. /* *INDENT-OFF* */ /* clang-format off */
  1329. DUFFS_LOOP(
  1330. {
  1331. *dst++ = RGB565_32(dst, src, map);
  1332. src += 2;
  1333. },
  1334. width);
  1335. /* *INDENT-ON* */ /* clang-format on */
  1336. src += srcskip;
  1337. dst += dstskip;
  1338. }
  1339. #else
  1340. while (height--) {
  1341. /* Copy in 4 pixel chunks */
  1342. for (c = width / 4; c; --c) {
  1343. *dst++ = RGB565_32(dst, src, map);
  1344. src += 2;
  1345. *dst++ = RGB565_32(dst, src, map);
  1346. src += 2;
  1347. *dst++ = RGB565_32(dst, src, map);
  1348. src += 2;
  1349. *dst++ = RGB565_32(dst, src, map);
  1350. src += 2;
  1351. }
  1352. /* Get any leftovers */
  1353. switch (width & 3) {
  1354. case 3:
  1355. *dst++ = RGB565_32(dst, src, map);
  1356. src += 2;
  1357. SDL_FALLTHROUGH;
  1358. case 2:
  1359. *dst++ = RGB565_32(dst, src, map);
  1360. src += 2;
  1361. SDL_FALLTHROUGH;
  1362. case 1:
  1363. *dst++ = RGB565_32(dst, src, map);
  1364. src += 2;
  1365. break;
  1366. }
  1367. src += srcskip;
  1368. dst += dstskip;
  1369. }
  1370. #endif /* USE_DUFFS_LOOP */
  1371. }
  1372. /* *INDENT-OFF* */ /* clang-format off */
  1373. /* Special optimized blit for RGB 5-6-5 --> ARGB 8-8-8-8 */
  1374. static const Uint32 RGB565_ARGB8888_LUT[512] = {
  1375. 0x00000000, 0xff000000, 0x00000008, 0xff002000,
  1376. 0x00000010, 0xff004000, 0x00000018, 0xff006100,
  1377. 0x00000020, 0xff008100, 0x00000029, 0xff00a100,
  1378. 0x00000031, 0xff00c200, 0x00000039, 0xff00e200,
  1379. 0x00000041, 0xff080000, 0x0000004a, 0xff082000,
  1380. 0x00000052, 0xff084000, 0x0000005a, 0xff086100,
  1381. 0x00000062, 0xff088100, 0x0000006a, 0xff08a100,
  1382. 0x00000073, 0xff08c200, 0x0000007b, 0xff08e200,
  1383. 0x00000083, 0xff100000, 0x0000008b, 0xff102000,
  1384. 0x00000094, 0xff104000, 0x0000009c, 0xff106100,
  1385. 0x000000a4, 0xff108100, 0x000000ac, 0xff10a100,
  1386. 0x000000b4, 0xff10c200, 0x000000bd, 0xff10e200,
  1387. 0x000000c5, 0xff180000, 0x000000cd, 0xff182000,
  1388. 0x000000d5, 0xff184000, 0x000000de, 0xff186100,
  1389. 0x000000e6, 0xff188100, 0x000000ee, 0xff18a100,
  1390. 0x000000f6, 0xff18c200, 0x000000ff, 0xff18e200,
  1391. 0x00000400, 0xff200000, 0x00000408, 0xff202000,
  1392. 0x00000410, 0xff204000, 0x00000418, 0xff206100,
  1393. 0x00000420, 0xff208100, 0x00000429, 0xff20a100,
  1394. 0x00000431, 0xff20c200, 0x00000439, 0xff20e200,
  1395. 0x00000441, 0xff290000, 0x0000044a, 0xff292000,
  1396. 0x00000452, 0xff294000, 0x0000045a, 0xff296100,
  1397. 0x00000462, 0xff298100, 0x0000046a, 0xff29a100,
  1398. 0x00000473, 0xff29c200, 0x0000047b, 0xff29e200,
  1399. 0x00000483, 0xff310000, 0x0000048b, 0xff312000,
  1400. 0x00000494, 0xff314000, 0x0000049c, 0xff316100,
  1401. 0x000004a4, 0xff318100, 0x000004ac, 0xff31a100,
  1402. 0x000004b4, 0xff31c200, 0x000004bd, 0xff31e200,
  1403. 0x000004c5, 0xff390000, 0x000004cd, 0xff392000,
  1404. 0x000004d5, 0xff394000, 0x000004de, 0xff396100,
  1405. 0x000004e6, 0xff398100, 0x000004ee, 0xff39a100,
  1406. 0x000004f6, 0xff39c200, 0x000004ff, 0xff39e200,
  1407. 0x00000800, 0xff410000, 0x00000808, 0xff412000,
  1408. 0x00000810, 0xff414000, 0x00000818, 0xff416100,
  1409. 0x00000820, 0xff418100, 0x00000829, 0xff41a100,
  1410. 0x00000831, 0xff41c200, 0x00000839, 0xff41e200,
  1411. 0x00000841, 0xff4a0000, 0x0000084a, 0xff4a2000,
  1412. 0x00000852, 0xff4a4000, 0x0000085a, 0xff4a6100,
  1413. 0x00000862, 0xff4a8100, 0x0000086a, 0xff4aa100,
  1414. 0x00000873, 0xff4ac200, 0x0000087b, 0xff4ae200,
  1415. 0x00000883, 0xff520000, 0x0000088b, 0xff522000,
  1416. 0x00000894, 0xff524000, 0x0000089c, 0xff526100,
  1417. 0x000008a4, 0xff528100, 0x000008ac, 0xff52a100,
  1418. 0x000008b4, 0xff52c200, 0x000008bd, 0xff52e200,
  1419. 0x000008c5, 0xff5a0000, 0x000008cd, 0xff5a2000,
  1420. 0x000008d5, 0xff5a4000, 0x000008de, 0xff5a6100,
  1421. 0x000008e6, 0xff5a8100, 0x000008ee, 0xff5aa100,
  1422. 0x000008f6, 0xff5ac200, 0x000008ff, 0xff5ae200,
  1423. 0x00000c00, 0xff620000, 0x00000c08, 0xff622000,
  1424. 0x00000c10, 0xff624000, 0x00000c18, 0xff626100,
  1425. 0x00000c20, 0xff628100, 0x00000c29, 0xff62a100,
  1426. 0x00000c31, 0xff62c200, 0x00000c39, 0xff62e200,
  1427. 0x00000c41, 0xff6a0000, 0x00000c4a, 0xff6a2000,
  1428. 0x00000c52, 0xff6a4000, 0x00000c5a, 0xff6a6100,
  1429. 0x00000c62, 0xff6a8100, 0x00000c6a, 0xff6aa100,
  1430. 0x00000c73, 0xff6ac200, 0x00000c7b, 0xff6ae200,
  1431. 0x00000c83, 0xff730000, 0x00000c8b, 0xff732000,
  1432. 0x00000c94, 0xff734000, 0x00000c9c, 0xff736100,
  1433. 0x00000ca4, 0xff738100, 0x00000cac, 0xff73a100,
  1434. 0x00000cb4, 0xff73c200, 0x00000cbd, 0xff73e200,
  1435. 0x00000cc5, 0xff7b0000, 0x00000ccd, 0xff7b2000,
  1436. 0x00000cd5, 0xff7b4000, 0x00000cde, 0xff7b6100,
  1437. 0x00000ce6, 0xff7b8100, 0x00000cee, 0xff7ba100,
  1438. 0x00000cf6, 0xff7bc200, 0x00000cff, 0xff7be200,
  1439. 0x00001000, 0xff830000, 0x00001008, 0xff832000,
  1440. 0x00001010, 0xff834000, 0x00001018, 0xff836100,
  1441. 0x00001020, 0xff838100, 0x00001029, 0xff83a100,
  1442. 0x00001031, 0xff83c200, 0x00001039, 0xff83e200,
  1443. 0x00001041, 0xff8b0000, 0x0000104a, 0xff8b2000,
  1444. 0x00001052, 0xff8b4000, 0x0000105a, 0xff8b6100,
  1445. 0x00001062, 0xff8b8100, 0x0000106a, 0xff8ba100,
  1446. 0x00001073, 0xff8bc200, 0x0000107b, 0xff8be200,
  1447. 0x00001083, 0xff940000, 0x0000108b, 0xff942000,
  1448. 0x00001094, 0xff944000, 0x0000109c, 0xff946100,
  1449. 0x000010a4, 0xff948100, 0x000010ac, 0xff94a100,
  1450. 0x000010b4, 0xff94c200, 0x000010bd, 0xff94e200,
  1451. 0x000010c5, 0xff9c0000, 0x000010cd, 0xff9c2000,
  1452. 0x000010d5, 0xff9c4000, 0x000010de, 0xff9c6100,
  1453. 0x000010e6, 0xff9c8100, 0x000010ee, 0xff9ca100,
  1454. 0x000010f6, 0xff9cc200, 0x000010ff, 0xff9ce200,
  1455. 0x00001400, 0xffa40000, 0x00001408, 0xffa42000,
  1456. 0x00001410, 0xffa44000, 0x00001418, 0xffa46100,
  1457. 0x00001420, 0xffa48100, 0x00001429, 0xffa4a100,
  1458. 0x00001431, 0xffa4c200, 0x00001439, 0xffa4e200,
  1459. 0x00001441, 0xffac0000, 0x0000144a, 0xffac2000,
  1460. 0x00001452, 0xffac4000, 0x0000145a, 0xffac6100,
  1461. 0x00001462, 0xffac8100, 0x0000146a, 0xffaca100,
  1462. 0x00001473, 0xffacc200, 0x0000147b, 0xfface200,
  1463. 0x00001483, 0xffb40000, 0x0000148b, 0xffb42000,
  1464. 0x00001494, 0xffb44000, 0x0000149c, 0xffb46100,
  1465. 0x000014a4, 0xffb48100, 0x000014ac, 0xffb4a100,
  1466. 0x000014b4, 0xffb4c200, 0x000014bd, 0xffb4e200,
  1467. 0x000014c5, 0xffbd0000, 0x000014cd, 0xffbd2000,
  1468. 0x000014d5, 0xffbd4000, 0x000014de, 0xffbd6100,
  1469. 0x000014e6, 0xffbd8100, 0x000014ee, 0xffbda100,
  1470. 0x000014f6, 0xffbdc200, 0x000014ff, 0xffbde200,
  1471. 0x00001800, 0xffc50000, 0x00001808, 0xffc52000,
  1472. 0x00001810, 0xffc54000, 0x00001818, 0xffc56100,
  1473. 0x00001820, 0xffc58100, 0x00001829, 0xffc5a100,
  1474. 0x00001831, 0xffc5c200, 0x00001839, 0xffc5e200,
  1475. 0x00001841, 0xffcd0000, 0x0000184a, 0xffcd2000,
  1476. 0x00001852, 0xffcd4000, 0x0000185a, 0xffcd6100,
  1477. 0x00001862, 0xffcd8100, 0x0000186a, 0xffcda100,
  1478. 0x00001873, 0xffcdc200, 0x0000187b, 0xffcde200,
  1479. 0x00001883, 0xffd50000, 0x0000188b, 0xffd52000,
  1480. 0x00001894, 0xffd54000, 0x0000189c, 0xffd56100,
  1481. 0x000018a4, 0xffd58100, 0x000018ac, 0xffd5a100,
  1482. 0x000018b4, 0xffd5c200, 0x000018bd, 0xffd5e200,
  1483. 0x000018c5, 0xffde0000, 0x000018cd, 0xffde2000,
  1484. 0x000018d5, 0xffde4000, 0x000018de, 0xffde6100,
  1485. 0x000018e6, 0xffde8100, 0x000018ee, 0xffdea100,
  1486. 0x000018f6, 0xffdec200, 0x000018ff, 0xffdee200,
  1487. 0x00001c00, 0xffe60000, 0x00001c08, 0xffe62000,
  1488. 0x00001c10, 0xffe64000, 0x00001c18, 0xffe66100,
  1489. 0x00001c20, 0xffe68100, 0x00001c29, 0xffe6a100,
  1490. 0x00001c31, 0xffe6c200, 0x00001c39, 0xffe6e200,
  1491. 0x00001c41, 0xffee0000, 0x00001c4a, 0xffee2000,
  1492. 0x00001c52, 0xffee4000, 0x00001c5a, 0xffee6100,
  1493. 0x00001c62, 0xffee8100, 0x00001c6a, 0xffeea100,
  1494. 0x00001c73, 0xffeec200, 0x00001c7b, 0xffeee200,
  1495. 0x00001c83, 0xfff60000, 0x00001c8b, 0xfff62000,
  1496. 0x00001c94, 0xfff64000, 0x00001c9c, 0xfff66100,
  1497. 0x00001ca4, 0xfff68100, 0x00001cac, 0xfff6a100,
  1498. 0x00001cb4, 0xfff6c200, 0x00001cbd, 0xfff6e200,
  1499. 0x00001cc5, 0xffff0000, 0x00001ccd, 0xffff2000,
  1500. 0x00001cd5, 0xffff4000, 0x00001cde, 0xffff6100,
  1501. 0x00001ce6, 0xffff8100, 0x00001cee, 0xffffa100,
  1502. 0x00001cf6, 0xffffc200, 0x00001cff, 0xffffe200
  1503. };
  1504. static void Blit_RGB565_ARGB8888(SDL_BlitInfo * info)
  1505. {
  1506. Blit_RGB565_32(info, RGB565_ARGB8888_LUT);
  1507. }
  1508. /* Special optimized blit for RGB 5-6-5 --> ABGR 8-8-8-8 */
  1509. static const Uint32 RGB565_ABGR8888_LUT[512] = {
  1510. 0xff000000, 0x00000000, 0xff080000, 0x00002000,
  1511. 0xff100000, 0x00004000, 0xff180000, 0x00006100,
  1512. 0xff200000, 0x00008100, 0xff290000, 0x0000a100,
  1513. 0xff310000, 0x0000c200, 0xff390000, 0x0000e200,
  1514. 0xff410000, 0x00000008, 0xff4a0000, 0x00002008,
  1515. 0xff520000, 0x00004008, 0xff5a0000, 0x00006108,
  1516. 0xff620000, 0x00008108, 0xff6a0000, 0x0000a108,
  1517. 0xff730000, 0x0000c208, 0xff7b0000, 0x0000e208,
  1518. 0xff830000, 0x00000010, 0xff8b0000, 0x00002010,
  1519. 0xff940000, 0x00004010, 0xff9c0000, 0x00006110,
  1520. 0xffa40000, 0x00008110, 0xffac0000, 0x0000a110,
  1521. 0xffb40000, 0x0000c210, 0xffbd0000, 0x0000e210,
  1522. 0xffc50000, 0x00000018, 0xffcd0000, 0x00002018,
  1523. 0xffd50000, 0x00004018, 0xffde0000, 0x00006118,
  1524. 0xffe60000, 0x00008118, 0xffee0000, 0x0000a118,
  1525. 0xfff60000, 0x0000c218, 0xffff0000, 0x0000e218,
  1526. 0xff000400, 0x00000020, 0xff080400, 0x00002020,
  1527. 0xff100400, 0x00004020, 0xff180400, 0x00006120,
  1528. 0xff200400, 0x00008120, 0xff290400, 0x0000a120,
  1529. 0xff310400, 0x0000c220, 0xff390400, 0x0000e220,
  1530. 0xff410400, 0x00000029, 0xff4a0400, 0x00002029,
  1531. 0xff520400, 0x00004029, 0xff5a0400, 0x00006129,
  1532. 0xff620400, 0x00008129, 0xff6a0400, 0x0000a129,
  1533. 0xff730400, 0x0000c229, 0xff7b0400, 0x0000e229,
  1534. 0xff830400, 0x00000031, 0xff8b0400, 0x00002031,
  1535. 0xff940400, 0x00004031, 0xff9c0400, 0x00006131,
  1536. 0xffa40400, 0x00008131, 0xffac0400, 0x0000a131,
  1537. 0xffb40400, 0x0000c231, 0xffbd0400, 0x0000e231,
  1538. 0xffc50400, 0x00000039, 0xffcd0400, 0x00002039,
  1539. 0xffd50400, 0x00004039, 0xffde0400, 0x00006139,
  1540. 0xffe60400, 0x00008139, 0xffee0400, 0x0000a139,
  1541. 0xfff60400, 0x0000c239, 0xffff0400, 0x0000e239,
  1542. 0xff000800, 0x00000041, 0xff080800, 0x00002041,
  1543. 0xff100800, 0x00004041, 0xff180800, 0x00006141,
  1544. 0xff200800, 0x00008141, 0xff290800, 0x0000a141,
  1545. 0xff310800, 0x0000c241, 0xff390800, 0x0000e241,
  1546. 0xff410800, 0x0000004a, 0xff4a0800, 0x0000204a,
  1547. 0xff520800, 0x0000404a, 0xff5a0800, 0x0000614a,
  1548. 0xff620800, 0x0000814a, 0xff6a0800, 0x0000a14a,
  1549. 0xff730800, 0x0000c24a, 0xff7b0800, 0x0000e24a,
  1550. 0xff830800, 0x00000052, 0xff8b0800, 0x00002052,
  1551. 0xff940800, 0x00004052, 0xff9c0800, 0x00006152,
  1552. 0xffa40800, 0x00008152, 0xffac0800, 0x0000a152,
  1553. 0xffb40800, 0x0000c252, 0xffbd0800, 0x0000e252,
  1554. 0xffc50800, 0x0000005a, 0xffcd0800, 0x0000205a,
  1555. 0xffd50800, 0x0000405a, 0xffde0800, 0x0000615a,
  1556. 0xffe60800, 0x0000815a, 0xffee0800, 0x0000a15a,
  1557. 0xfff60800, 0x0000c25a, 0xffff0800, 0x0000e25a,
  1558. 0xff000c00, 0x00000062, 0xff080c00, 0x00002062,
  1559. 0xff100c00, 0x00004062, 0xff180c00, 0x00006162,
  1560. 0xff200c00, 0x00008162, 0xff290c00, 0x0000a162,
  1561. 0xff310c00, 0x0000c262, 0xff390c00, 0x0000e262,
  1562. 0xff410c00, 0x0000006a, 0xff4a0c00, 0x0000206a,
  1563. 0xff520c00, 0x0000406a, 0xff5a0c00, 0x0000616a,
  1564. 0xff620c00, 0x0000816a, 0xff6a0c00, 0x0000a16a,
  1565. 0xff730c00, 0x0000c26a, 0xff7b0c00, 0x0000e26a,
  1566. 0xff830c00, 0x00000073, 0xff8b0c00, 0x00002073,
  1567. 0xff940c00, 0x00004073, 0xff9c0c00, 0x00006173,
  1568. 0xffa40c00, 0x00008173, 0xffac0c00, 0x0000a173,
  1569. 0xffb40c00, 0x0000c273, 0xffbd0c00, 0x0000e273,
  1570. 0xffc50c00, 0x0000007b, 0xffcd0c00, 0x0000207b,
  1571. 0xffd50c00, 0x0000407b, 0xffde0c00, 0x0000617b,
  1572. 0xffe60c00, 0x0000817b, 0xffee0c00, 0x0000a17b,
  1573. 0xfff60c00, 0x0000c27b, 0xffff0c00, 0x0000e27b,
  1574. 0xff001000, 0x00000083, 0xff081000, 0x00002083,
  1575. 0xff101000, 0x00004083, 0xff181000, 0x00006183,
  1576. 0xff201000, 0x00008183, 0xff291000, 0x0000a183,
  1577. 0xff311000, 0x0000c283, 0xff391000, 0x0000e283,
  1578. 0xff411000, 0x0000008b, 0xff4a1000, 0x0000208b,
  1579. 0xff521000, 0x0000408b, 0xff5a1000, 0x0000618b,
  1580. 0xff621000, 0x0000818b, 0xff6a1000, 0x0000a18b,
  1581. 0xff731000, 0x0000c28b, 0xff7b1000, 0x0000e28b,
  1582. 0xff831000, 0x00000094, 0xff8b1000, 0x00002094,
  1583. 0xff941000, 0x00004094, 0xff9c1000, 0x00006194,
  1584. 0xffa41000, 0x00008194, 0xffac1000, 0x0000a194,
  1585. 0xffb41000, 0x0000c294, 0xffbd1000, 0x0000e294,
  1586. 0xffc51000, 0x0000009c, 0xffcd1000, 0x0000209c,
  1587. 0xffd51000, 0x0000409c, 0xffde1000, 0x0000619c,
  1588. 0xffe61000, 0x0000819c, 0xffee1000, 0x0000a19c,
  1589. 0xfff61000, 0x0000c29c, 0xffff1000, 0x0000e29c,
  1590. 0xff001400, 0x000000a4, 0xff081400, 0x000020a4,
  1591. 0xff101400, 0x000040a4, 0xff181400, 0x000061a4,
  1592. 0xff201400, 0x000081a4, 0xff291400, 0x0000a1a4,
  1593. 0xff311400, 0x0000c2a4, 0xff391400, 0x0000e2a4,
  1594. 0xff411400, 0x000000ac, 0xff4a1400, 0x000020ac,
  1595. 0xff521400, 0x000040ac, 0xff5a1400, 0x000061ac,
  1596. 0xff621400, 0x000081ac, 0xff6a1400, 0x0000a1ac,
  1597. 0xff731400, 0x0000c2ac, 0xff7b1400, 0x0000e2ac,
  1598. 0xff831400, 0x000000b4, 0xff8b1400, 0x000020b4,
  1599. 0xff941400, 0x000040b4, 0xff9c1400, 0x000061b4,
  1600. 0xffa41400, 0x000081b4, 0xffac1400, 0x0000a1b4,
  1601. 0xffb41400, 0x0000c2b4, 0xffbd1400, 0x0000e2b4,
  1602. 0xffc51400, 0x000000bd, 0xffcd1400, 0x000020bd,
  1603. 0xffd51400, 0x000040bd, 0xffde1400, 0x000061bd,
  1604. 0xffe61400, 0x000081bd, 0xffee1400, 0x0000a1bd,
  1605. 0xfff61400, 0x0000c2bd, 0xffff1400, 0x0000e2bd,
  1606. 0xff001800, 0x000000c5, 0xff081800, 0x000020c5,
  1607. 0xff101800, 0x000040c5, 0xff181800, 0x000061c5,
  1608. 0xff201800, 0x000081c5, 0xff291800, 0x0000a1c5,
  1609. 0xff311800, 0x0000c2c5, 0xff391800, 0x0000e2c5,
  1610. 0xff411800, 0x000000cd, 0xff4a1800, 0x000020cd,
  1611. 0xff521800, 0x000040cd, 0xff5a1800, 0x000061cd,
  1612. 0xff621800, 0x000081cd, 0xff6a1800, 0x0000a1cd,
  1613. 0xff731800, 0x0000c2cd, 0xff7b1800, 0x0000e2cd,
  1614. 0xff831800, 0x000000d5, 0xff8b1800, 0x000020d5,
  1615. 0xff941800, 0x000040d5, 0xff9c1800, 0x000061d5,
  1616. 0xffa41800, 0x000081d5, 0xffac1800, 0x0000a1d5,
  1617. 0xffb41800, 0x0000c2d5, 0xffbd1800, 0x0000e2d5,
  1618. 0xffc51800, 0x000000de, 0xffcd1800, 0x000020de,
  1619. 0xffd51800, 0x000040de, 0xffde1800, 0x000061de,
  1620. 0xffe61800, 0x000081de, 0xffee1800, 0x0000a1de,
  1621. 0xfff61800, 0x0000c2de, 0xffff1800, 0x0000e2de,
  1622. 0xff001c00, 0x000000e6, 0xff081c00, 0x000020e6,
  1623. 0xff101c00, 0x000040e6, 0xff181c00, 0x000061e6,
  1624. 0xff201c00, 0x000081e6, 0xff291c00, 0x0000a1e6,
  1625. 0xff311c00, 0x0000c2e6, 0xff391c00, 0x0000e2e6,
  1626. 0xff411c00, 0x000000ee, 0xff4a1c00, 0x000020ee,
  1627. 0xff521c00, 0x000040ee, 0xff5a1c00, 0x000061ee,
  1628. 0xff621c00, 0x000081ee, 0xff6a1c00, 0x0000a1ee,
  1629. 0xff731c00, 0x0000c2ee, 0xff7b1c00, 0x0000e2ee,
  1630. 0xff831c00, 0x000000f6, 0xff8b1c00, 0x000020f6,
  1631. 0xff941c00, 0x000040f6, 0xff9c1c00, 0x000061f6,
  1632. 0xffa41c00, 0x000081f6, 0xffac1c00, 0x0000a1f6,
  1633. 0xffb41c00, 0x0000c2f6, 0xffbd1c00, 0x0000e2f6,
  1634. 0xffc51c00, 0x000000ff, 0xffcd1c00, 0x000020ff,
  1635. 0xffd51c00, 0x000040ff, 0xffde1c00, 0x000061ff,
  1636. 0xffe61c00, 0x000081ff, 0xffee1c00, 0x0000a1ff,
  1637. 0xfff61c00, 0x0000c2ff, 0xffff1c00, 0x0000e2ff
  1638. };
  1639. static void Blit_RGB565_ABGR8888(SDL_BlitInfo * info)
  1640. {
  1641. Blit_RGB565_32(info, RGB565_ABGR8888_LUT);
  1642. }
  1643. /* Special optimized blit for RGB 5-6-5 --> RGBA 8-8-8-8 */
  1644. static const Uint32 RGB565_RGBA8888_LUT[512] = {
  1645. 0x000000ff, 0x00000000, 0x000008ff, 0x00200000,
  1646. 0x000010ff, 0x00400000, 0x000018ff, 0x00610000,
  1647. 0x000020ff, 0x00810000, 0x000029ff, 0x00a10000,
  1648. 0x000031ff, 0x00c20000, 0x000039ff, 0x00e20000,
  1649. 0x000041ff, 0x08000000, 0x00004aff, 0x08200000,
  1650. 0x000052ff, 0x08400000, 0x00005aff, 0x08610000,
  1651. 0x000062ff, 0x08810000, 0x00006aff, 0x08a10000,
  1652. 0x000073ff, 0x08c20000, 0x00007bff, 0x08e20000,
  1653. 0x000083ff, 0x10000000, 0x00008bff, 0x10200000,
  1654. 0x000094ff, 0x10400000, 0x00009cff, 0x10610000,
  1655. 0x0000a4ff, 0x10810000, 0x0000acff, 0x10a10000,
  1656. 0x0000b4ff, 0x10c20000, 0x0000bdff, 0x10e20000,
  1657. 0x0000c5ff, 0x18000000, 0x0000cdff, 0x18200000,
  1658. 0x0000d5ff, 0x18400000, 0x0000deff, 0x18610000,
  1659. 0x0000e6ff, 0x18810000, 0x0000eeff, 0x18a10000,
  1660. 0x0000f6ff, 0x18c20000, 0x0000ffff, 0x18e20000,
  1661. 0x000400ff, 0x20000000, 0x000408ff, 0x20200000,
  1662. 0x000410ff, 0x20400000, 0x000418ff, 0x20610000,
  1663. 0x000420ff, 0x20810000, 0x000429ff, 0x20a10000,
  1664. 0x000431ff, 0x20c20000, 0x000439ff, 0x20e20000,
  1665. 0x000441ff, 0x29000000, 0x00044aff, 0x29200000,
  1666. 0x000452ff, 0x29400000, 0x00045aff, 0x29610000,
  1667. 0x000462ff, 0x29810000, 0x00046aff, 0x29a10000,
  1668. 0x000473ff, 0x29c20000, 0x00047bff, 0x29e20000,
  1669. 0x000483ff, 0x31000000, 0x00048bff, 0x31200000,
  1670. 0x000494ff, 0x31400000, 0x00049cff, 0x31610000,
  1671. 0x0004a4ff, 0x31810000, 0x0004acff, 0x31a10000,
  1672. 0x0004b4ff, 0x31c20000, 0x0004bdff, 0x31e20000,
  1673. 0x0004c5ff, 0x39000000, 0x0004cdff, 0x39200000,
  1674. 0x0004d5ff, 0x39400000, 0x0004deff, 0x39610000,
  1675. 0x0004e6ff, 0x39810000, 0x0004eeff, 0x39a10000,
  1676. 0x0004f6ff, 0x39c20000, 0x0004ffff, 0x39e20000,
  1677. 0x000800ff, 0x41000000, 0x000808ff, 0x41200000,
  1678. 0x000810ff, 0x41400000, 0x000818ff, 0x41610000,
  1679. 0x000820ff, 0x41810000, 0x000829ff, 0x41a10000,
  1680. 0x000831ff, 0x41c20000, 0x000839ff, 0x41e20000,
  1681. 0x000841ff, 0x4a000000, 0x00084aff, 0x4a200000,
  1682. 0x000852ff, 0x4a400000, 0x00085aff, 0x4a610000,
  1683. 0x000862ff, 0x4a810000, 0x00086aff, 0x4aa10000,
  1684. 0x000873ff, 0x4ac20000, 0x00087bff, 0x4ae20000,
  1685. 0x000883ff, 0x52000000, 0x00088bff, 0x52200000,
  1686. 0x000894ff, 0x52400000, 0x00089cff, 0x52610000,
  1687. 0x0008a4ff, 0x52810000, 0x0008acff, 0x52a10000,
  1688. 0x0008b4ff, 0x52c20000, 0x0008bdff, 0x52e20000,
  1689. 0x0008c5ff, 0x5a000000, 0x0008cdff, 0x5a200000,
  1690. 0x0008d5ff, 0x5a400000, 0x0008deff, 0x5a610000,
  1691. 0x0008e6ff, 0x5a810000, 0x0008eeff, 0x5aa10000,
  1692. 0x0008f6ff, 0x5ac20000, 0x0008ffff, 0x5ae20000,
  1693. 0x000c00ff, 0x62000000, 0x000c08ff, 0x62200000,
  1694. 0x000c10ff, 0x62400000, 0x000c18ff, 0x62610000,
  1695. 0x000c20ff, 0x62810000, 0x000c29ff, 0x62a10000,
  1696. 0x000c31ff, 0x62c20000, 0x000c39ff, 0x62e20000,
  1697. 0x000c41ff, 0x6a000000, 0x000c4aff, 0x6a200000,
  1698. 0x000c52ff, 0x6a400000, 0x000c5aff, 0x6a610000,
  1699. 0x000c62ff, 0x6a810000, 0x000c6aff, 0x6aa10000,
  1700. 0x000c73ff, 0x6ac20000, 0x000c7bff, 0x6ae20000,
  1701. 0x000c83ff, 0x73000000, 0x000c8bff, 0x73200000,
  1702. 0x000c94ff, 0x73400000, 0x000c9cff, 0x73610000,
  1703. 0x000ca4ff, 0x73810000, 0x000cacff, 0x73a10000,
  1704. 0x000cb4ff, 0x73c20000, 0x000cbdff, 0x73e20000,
  1705. 0x000cc5ff, 0x7b000000, 0x000ccdff, 0x7b200000,
  1706. 0x000cd5ff, 0x7b400000, 0x000cdeff, 0x7b610000,
  1707. 0x000ce6ff, 0x7b810000, 0x000ceeff, 0x7ba10000,
  1708. 0x000cf6ff, 0x7bc20000, 0x000cffff, 0x7be20000,
  1709. 0x001000ff, 0x83000000, 0x001008ff, 0x83200000,
  1710. 0x001010ff, 0x83400000, 0x001018ff, 0x83610000,
  1711. 0x001020ff, 0x83810000, 0x001029ff, 0x83a10000,
  1712. 0x001031ff, 0x83c20000, 0x001039ff, 0x83e20000,
  1713. 0x001041ff, 0x8b000000, 0x00104aff, 0x8b200000,
  1714. 0x001052ff, 0x8b400000, 0x00105aff, 0x8b610000,
  1715. 0x001062ff, 0x8b810000, 0x00106aff, 0x8ba10000,
  1716. 0x001073ff, 0x8bc20000, 0x00107bff, 0x8be20000,
  1717. 0x001083ff, 0x94000000, 0x00108bff, 0x94200000,
  1718. 0x001094ff, 0x94400000, 0x00109cff, 0x94610000,
  1719. 0x0010a4ff, 0x94810000, 0x0010acff, 0x94a10000,
  1720. 0x0010b4ff, 0x94c20000, 0x0010bdff, 0x94e20000,
  1721. 0x0010c5ff, 0x9c000000, 0x0010cdff, 0x9c200000,
  1722. 0x0010d5ff, 0x9c400000, 0x0010deff, 0x9c610000,
  1723. 0x0010e6ff, 0x9c810000, 0x0010eeff, 0x9ca10000,
  1724. 0x0010f6ff, 0x9cc20000, 0x0010ffff, 0x9ce20000,
  1725. 0x001400ff, 0xa4000000, 0x001408ff, 0xa4200000,
  1726. 0x001410ff, 0xa4400000, 0x001418ff, 0xa4610000,
  1727. 0x001420ff, 0xa4810000, 0x001429ff, 0xa4a10000,
  1728. 0x001431ff, 0xa4c20000, 0x001439ff, 0xa4e20000,
  1729. 0x001441ff, 0xac000000, 0x00144aff, 0xac200000,
  1730. 0x001452ff, 0xac400000, 0x00145aff, 0xac610000,
  1731. 0x001462ff, 0xac810000, 0x00146aff, 0xaca10000,
  1732. 0x001473ff, 0xacc20000, 0x00147bff, 0xace20000,
  1733. 0x001483ff, 0xb4000000, 0x00148bff, 0xb4200000,
  1734. 0x001494ff, 0xb4400000, 0x00149cff, 0xb4610000,
  1735. 0x0014a4ff, 0xb4810000, 0x0014acff, 0xb4a10000,
  1736. 0x0014b4ff, 0xb4c20000, 0x0014bdff, 0xb4e20000,
  1737. 0x0014c5ff, 0xbd000000, 0x0014cdff, 0xbd200000,
  1738. 0x0014d5ff, 0xbd400000, 0x0014deff, 0xbd610000,
  1739. 0x0014e6ff, 0xbd810000, 0x0014eeff, 0xbda10000,
  1740. 0x0014f6ff, 0xbdc20000, 0x0014ffff, 0xbde20000,
  1741. 0x001800ff, 0xc5000000, 0x001808ff, 0xc5200000,
  1742. 0x001810ff, 0xc5400000, 0x001818ff, 0xc5610000,
  1743. 0x001820ff, 0xc5810000, 0x001829ff, 0xc5a10000,
  1744. 0x001831ff, 0xc5c20000, 0x001839ff, 0xc5e20000,
  1745. 0x001841ff, 0xcd000000, 0x00184aff, 0xcd200000,
  1746. 0x001852ff, 0xcd400000, 0x00185aff, 0xcd610000,
  1747. 0x001862ff, 0xcd810000, 0x00186aff, 0xcda10000,
  1748. 0x001873ff, 0xcdc20000, 0x00187bff, 0xcde20000,
  1749. 0x001883ff, 0xd5000000, 0x00188bff, 0xd5200000,
  1750. 0x001894ff, 0xd5400000, 0x00189cff, 0xd5610000,
  1751. 0x0018a4ff, 0xd5810000, 0x0018acff, 0xd5a10000,
  1752. 0x0018b4ff, 0xd5c20000, 0x0018bdff, 0xd5e20000,
  1753. 0x0018c5ff, 0xde000000, 0x0018cdff, 0xde200000,
  1754. 0x0018d5ff, 0xde400000, 0x0018deff, 0xde610000,
  1755. 0x0018e6ff, 0xde810000, 0x0018eeff, 0xdea10000,
  1756. 0x0018f6ff, 0xdec20000, 0x0018ffff, 0xdee20000,
  1757. 0x001c00ff, 0xe6000000, 0x001c08ff, 0xe6200000,
  1758. 0x001c10ff, 0xe6400000, 0x001c18ff, 0xe6610000,
  1759. 0x001c20ff, 0xe6810000, 0x001c29ff, 0xe6a10000,
  1760. 0x001c31ff, 0xe6c20000, 0x001c39ff, 0xe6e20000,
  1761. 0x001c41ff, 0xee000000, 0x001c4aff, 0xee200000,
  1762. 0x001c52ff, 0xee400000, 0x001c5aff, 0xee610000,
  1763. 0x001c62ff, 0xee810000, 0x001c6aff, 0xeea10000,
  1764. 0x001c73ff, 0xeec20000, 0x001c7bff, 0xeee20000,
  1765. 0x001c83ff, 0xf6000000, 0x001c8bff, 0xf6200000,
  1766. 0x001c94ff, 0xf6400000, 0x001c9cff, 0xf6610000,
  1767. 0x001ca4ff, 0xf6810000, 0x001cacff, 0xf6a10000,
  1768. 0x001cb4ff, 0xf6c20000, 0x001cbdff, 0xf6e20000,
  1769. 0x001cc5ff, 0xff000000, 0x001ccdff, 0xff200000,
  1770. 0x001cd5ff, 0xff400000, 0x001cdeff, 0xff610000,
  1771. 0x001ce6ff, 0xff810000, 0x001ceeff, 0xffa10000,
  1772. 0x001cf6ff, 0xffc20000, 0x001cffff, 0xffe20000,
  1773. };
  1774. static void Blit_RGB565_RGBA8888(SDL_BlitInfo * info)
  1775. {
  1776. Blit_RGB565_32(info, RGB565_RGBA8888_LUT);
  1777. }
  1778. /* Special optimized blit for RGB 5-6-5 --> BGRA 8-8-8-8 */
  1779. static const Uint32 RGB565_BGRA8888_LUT[512] = {
  1780. 0x00000000, 0x000000ff, 0x08000000, 0x002000ff,
  1781. 0x10000000, 0x004000ff, 0x18000000, 0x006100ff,
  1782. 0x20000000, 0x008100ff, 0x29000000, 0x00a100ff,
  1783. 0x31000000, 0x00c200ff, 0x39000000, 0x00e200ff,
  1784. 0x41000000, 0x000008ff, 0x4a000000, 0x002008ff,
  1785. 0x52000000, 0x004008ff, 0x5a000000, 0x006108ff,
  1786. 0x62000000, 0x008108ff, 0x6a000000, 0x00a108ff,
  1787. 0x73000000, 0x00c208ff, 0x7b000000, 0x00e208ff,
  1788. 0x83000000, 0x000010ff, 0x8b000000, 0x002010ff,
  1789. 0x94000000, 0x004010ff, 0x9c000000, 0x006110ff,
  1790. 0xa4000000, 0x008110ff, 0xac000000, 0x00a110ff,
  1791. 0xb4000000, 0x00c210ff, 0xbd000000, 0x00e210ff,
  1792. 0xc5000000, 0x000018ff, 0xcd000000, 0x002018ff,
  1793. 0xd5000000, 0x004018ff, 0xde000000, 0x006118ff,
  1794. 0xe6000000, 0x008118ff, 0xee000000, 0x00a118ff,
  1795. 0xf6000000, 0x00c218ff, 0xff000000, 0x00e218ff,
  1796. 0x00040000, 0x000020ff, 0x08040000, 0x002020ff,
  1797. 0x10040000, 0x004020ff, 0x18040000, 0x006120ff,
  1798. 0x20040000, 0x008120ff, 0x29040000, 0x00a120ff,
  1799. 0x31040000, 0x00c220ff, 0x39040000, 0x00e220ff,
  1800. 0x41040000, 0x000029ff, 0x4a040000, 0x002029ff,
  1801. 0x52040000, 0x004029ff, 0x5a040000, 0x006129ff,
  1802. 0x62040000, 0x008129ff, 0x6a040000, 0x00a129ff,
  1803. 0x73040000, 0x00c229ff, 0x7b040000, 0x00e229ff,
  1804. 0x83040000, 0x000031ff, 0x8b040000, 0x002031ff,
  1805. 0x94040000, 0x004031ff, 0x9c040000, 0x006131ff,
  1806. 0xa4040000, 0x008131ff, 0xac040000, 0x00a131ff,
  1807. 0xb4040000, 0x00c231ff, 0xbd040000, 0x00e231ff,
  1808. 0xc5040000, 0x000039ff, 0xcd040000, 0x002039ff,
  1809. 0xd5040000, 0x004039ff, 0xde040000, 0x006139ff,
  1810. 0xe6040000, 0x008139ff, 0xee040000, 0x00a139ff,
  1811. 0xf6040000, 0x00c239ff, 0xff040000, 0x00e239ff,
  1812. 0x00080000, 0x000041ff, 0x08080000, 0x002041ff,
  1813. 0x10080000, 0x004041ff, 0x18080000, 0x006141ff,
  1814. 0x20080000, 0x008141ff, 0x29080000, 0x00a141ff,
  1815. 0x31080000, 0x00c241ff, 0x39080000, 0x00e241ff,
  1816. 0x41080000, 0x00004aff, 0x4a080000, 0x00204aff,
  1817. 0x52080000, 0x00404aff, 0x5a080000, 0x00614aff,
  1818. 0x62080000, 0x00814aff, 0x6a080000, 0x00a14aff,
  1819. 0x73080000, 0x00c24aff, 0x7b080000, 0x00e24aff,
  1820. 0x83080000, 0x000052ff, 0x8b080000, 0x002052ff,
  1821. 0x94080000, 0x004052ff, 0x9c080000, 0x006152ff,
  1822. 0xa4080000, 0x008152ff, 0xac080000, 0x00a152ff,
  1823. 0xb4080000, 0x00c252ff, 0xbd080000, 0x00e252ff,
  1824. 0xc5080000, 0x00005aff, 0xcd080000, 0x00205aff,
  1825. 0xd5080000, 0x00405aff, 0xde080000, 0x00615aff,
  1826. 0xe6080000, 0x00815aff, 0xee080000, 0x00a15aff,
  1827. 0xf6080000, 0x00c25aff, 0xff080000, 0x00e25aff,
  1828. 0x000c0000, 0x000062ff, 0x080c0000, 0x002062ff,
  1829. 0x100c0000, 0x004062ff, 0x180c0000, 0x006162ff,
  1830. 0x200c0000, 0x008162ff, 0x290c0000, 0x00a162ff,
  1831. 0x310c0000, 0x00c262ff, 0x390c0000, 0x00e262ff,
  1832. 0x410c0000, 0x00006aff, 0x4a0c0000, 0x00206aff,
  1833. 0x520c0000, 0x00406aff, 0x5a0c0000, 0x00616aff,
  1834. 0x620c0000, 0x00816aff, 0x6a0c0000, 0x00a16aff,
  1835. 0x730c0000, 0x00c26aff, 0x7b0c0000, 0x00e26aff,
  1836. 0x830c0000, 0x000073ff, 0x8b0c0000, 0x002073ff,
  1837. 0x940c0000, 0x004073ff, 0x9c0c0000, 0x006173ff,
  1838. 0xa40c0000, 0x008173ff, 0xac0c0000, 0x00a173ff,
  1839. 0xb40c0000, 0x00c273ff, 0xbd0c0000, 0x00e273ff,
  1840. 0xc50c0000, 0x00007bff, 0xcd0c0000, 0x00207bff,
  1841. 0xd50c0000, 0x00407bff, 0xde0c0000, 0x00617bff,
  1842. 0xe60c0000, 0x00817bff, 0xee0c0000, 0x00a17bff,
  1843. 0xf60c0000, 0x00c27bff, 0xff0c0000, 0x00e27bff,
  1844. 0x00100000, 0x000083ff, 0x08100000, 0x002083ff,
  1845. 0x10100000, 0x004083ff, 0x18100000, 0x006183ff,
  1846. 0x20100000, 0x008183ff, 0x29100000, 0x00a183ff,
  1847. 0x31100000, 0x00c283ff, 0x39100000, 0x00e283ff,
  1848. 0x41100000, 0x00008bff, 0x4a100000, 0x00208bff,
  1849. 0x52100000, 0x00408bff, 0x5a100000, 0x00618bff,
  1850. 0x62100000, 0x00818bff, 0x6a100000, 0x00a18bff,
  1851. 0x73100000, 0x00c28bff, 0x7b100000, 0x00e28bff,
  1852. 0x83100000, 0x000094ff, 0x8b100000, 0x002094ff,
  1853. 0x94100000, 0x004094ff, 0x9c100000, 0x006194ff,
  1854. 0xa4100000, 0x008194ff, 0xac100000, 0x00a194ff,
  1855. 0xb4100000, 0x00c294ff, 0xbd100000, 0x00e294ff,
  1856. 0xc5100000, 0x00009cff, 0xcd100000, 0x00209cff,
  1857. 0xd5100000, 0x00409cff, 0xde100000, 0x00619cff,
  1858. 0xe6100000, 0x00819cff, 0xee100000, 0x00a19cff,
  1859. 0xf6100000, 0x00c29cff, 0xff100000, 0x00e29cff,
  1860. 0x00140000, 0x0000a4ff, 0x08140000, 0x0020a4ff,
  1861. 0x10140000, 0x0040a4ff, 0x18140000, 0x0061a4ff,
  1862. 0x20140000, 0x0081a4ff, 0x29140000, 0x00a1a4ff,
  1863. 0x31140000, 0x00c2a4ff, 0x39140000, 0x00e2a4ff,
  1864. 0x41140000, 0x0000acff, 0x4a140000, 0x0020acff,
  1865. 0x52140000, 0x0040acff, 0x5a140000, 0x0061acff,
  1866. 0x62140000, 0x0081acff, 0x6a140000, 0x00a1acff,
  1867. 0x73140000, 0x00c2acff, 0x7b140000, 0x00e2acff,
  1868. 0x83140000, 0x0000b4ff, 0x8b140000, 0x0020b4ff,
  1869. 0x94140000, 0x0040b4ff, 0x9c140000, 0x0061b4ff,
  1870. 0xa4140000, 0x0081b4ff, 0xac140000, 0x00a1b4ff,
  1871. 0xb4140000, 0x00c2b4ff, 0xbd140000, 0x00e2b4ff,
  1872. 0xc5140000, 0x0000bdff, 0xcd140000, 0x0020bdff,
  1873. 0xd5140000, 0x0040bdff, 0xde140000, 0x0061bdff,
  1874. 0xe6140000, 0x0081bdff, 0xee140000, 0x00a1bdff,
  1875. 0xf6140000, 0x00c2bdff, 0xff140000, 0x00e2bdff,
  1876. 0x00180000, 0x0000c5ff, 0x08180000, 0x0020c5ff,
  1877. 0x10180000, 0x0040c5ff, 0x18180000, 0x0061c5ff,
  1878. 0x20180000, 0x0081c5ff, 0x29180000, 0x00a1c5ff,
  1879. 0x31180000, 0x00c2c5ff, 0x39180000, 0x00e2c5ff,
  1880. 0x41180000, 0x0000cdff, 0x4a180000, 0x0020cdff,
  1881. 0x52180000, 0x0040cdff, 0x5a180000, 0x0061cdff,
  1882. 0x62180000, 0x0081cdff, 0x6a180000, 0x00a1cdff,
  1883. 0x73180000, 0x00c2cdff, 0x7b180000, 0x00e2cdff,
  1884. 0x83180000, 0x0000d5ff, 0x8b180000, 0x0020d5ff,
  1885. 0x94180000, 0x0040d5ff, 0x9c180000, 0x0061d5ff,
  1886. 0xa4180000, 0x0081d5ff, 0xac180000, 0x00a1d5ff,
  1887. 0xb4180000, 0x00c2d5ff, 0xbd180000, 0x00e2d5ff,
  1888. 0xc5180000, 0x0000deff, 0xcd180000, 0x0020deff,
  1889. 0xd5180000, 0x0040deff, 0xde180000, 0x0061deff,
  1890. 0xe6180000, 0x0081deff, 0xee180000, 0x00a1deff,
  1891. 0xf6180000, 0x00c2deff, 0xff180000, 0x00e2deff,
  1892. 0x001c0000, 0x0000e6ff, 0x081c0000, 0x0020e6ff,
  1893. 0x101c0000, 0x0040e6ff, 0x181c0000, 0x0061e6ff,
  1894. 0x201c0000, 0x0081e6ff, 0x291c0000, 0x00a1e6ff,
  1895. 0x311c0000, 0x00c2e6ff, 0x391c0000, 0x00e2e6ff,
  1896. 0x411c0000, 0x0000eeff, 0x4a1c0000, 0x0020eeff,
  1897. 0x521c0000, 0x0040eeff, 0x5a1c0000, 0x0061eeff,
  1898. 0x621c0000, 0x0081eeff, 0x6a1c0000, 0x00a1eeff,
  1899. 0x731c0000, 0x00c2eeff, 0x7b1c0000, 0x00e2eeff,
  1900. 0x831c0000, 0x0000f6ff, 0x8b1c0000, 0x0020f6ff,
  1901. 0x941c0000, 0x0040f6ff, 0x9c1c0000, 0x0061f6ff,
  1902. 0xa41c0000, 0x0081f6ff, 0xac1c0000, 0x00a1f6ff,
  1903. 0xb41c0000, 0x00c2f6ff, 0xbd1c0000, 0x00e2f6ff,
  1904. 0xc51c0000, 0x0000ffff, 0xcd1c0000, 0x0020ffff,
  1905. 0xd51c0000, 0x0040ffff, 0xde1c0000, 0x0061ffff,
  1906. 0xe61c0000, 0x0081ffff, 0xee1c0000, 0x00a1ffff,
  1907. 0xf61c0000, 0x00c2ffff, 0xff1c0000, 0x00e2ffff
  1908. };
  1909. static void Blit_RGB565_BGRA8888(SDL_BlitInfo * info)
  1910. {
  1911. Blit_RGB565_32(info, RGB565_BGRA8888_LUT);
  1912. }
  1913. /* *INDENT-ON* */ /* clang-format on */
  1914. #endif /* SDL_HAVE_BLIT_N_RGB565 */
  1915. /* RGB555->ARGB1555, and BGR555->ABGR1555, SET_ALPHA */
  1916. static void Blit_RGB555_ARGB1555(SDL_BlitInfo *info)
  1917. {
  1918. int width = info->dst_w;
  1919. int height = info->dst_h;
  1920. Uint16 *src = (Uint16 *)info->src;
  1921. int srcskip = info->src_skip;
  1922. Uint16 *dst = (Uint16 *)info->dst;
  1923. int dstskip = info->dst_skip;
  1924. SDL_PixelFormat *dstfmt = info->dst_fmt;
  1925. Uint16 mask = ((Uint32)info->a >> dstfmt->Aloss) << dstfmt->Ashift;
  1926. while (height--) {
  1927. /* *INDENT-OFF* */ /* clang-format off */
  1928. DUFFS_LOOP(
  1929. {
  1930. *dst = *src | mask;
  1931. ++dst;
  1932. ++src;
  1933. },
  1934. width);
  1935. /* *INDENT-ON* */ /* clang-format on */
  1936. src = (Uint16 *)((Uint8 *)src + srcskip);
  1937. dst = (Uint16 *)((Uint8 *)dst + dstskip);
  1938. }
  1939. }
  1940. static void BlitNto1(SDL_BlitInfo *info)
  1941. {
  1942. #ifndef USE_DUFFS_LOOP
  1943. int c;
  1944. #endif
  1945. int width, height;
  1946. Uint8 *src;
  1947. const Uint8 *map;
  1948. Uint8 *dst;
  1949. int srcskip, dstskip;
  1950. int srcbpp;
  1951. Uint32 Pixel;
  1952. int sR, sG, sB;
  1953. SDL_PixelFormat *srcfmt;
  1954. /* Set up some basic variables */
  1955. width = info->dst_w;
  1956. height = info->dst_h;
  1957. src = info->src;
  1958. srcskip = info->src_skip;
  1959. dst = info->dst;
  1960. dstskip = info->dst_skip;
  1961. map = info->table;
  1962. srcfmt = info->src_fmt;
  1963. srcbpp = srcfmt->BytesPerPixel;
  1964. if (map == NULL) {
  1965. while (height--) {
  1966. #ifdef USE_DUFFS_LOOP
  1967. /* *INDENT-OFF* */ /* clang-format off */
  1968. DUFFS_LOOP(
  1969. DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel,
  1970. sR, sG, sB);
  1971. if ( 1 ) {
  1972. /* Pack RGB into 8bit pixel */
  1973. *dst = (Uint8)(((sR>>5)<<(3+2)) | ((sG>>5)<<(2)) | ((sB>>6)<<(0)));
  1974. }
  1975. dst++;
  1976. src += srcbpp;
  1977. , width);
  1978. /* *INDENT-ON* */ /* clang-format on */
  1979. #else
  1980. for (c = width; c; --c) {
  1981. DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB);
  1982. if (1) {
  1983. /* Pack RGB into 8bit pixel */
  1984. *dst = ((sR >> 5) << (3 + 2)) |
  1985. ((sG >> 5) << (2)) | ((sB >> 6) << (0));
  1986. }
  1987. dst++;
  1988. src += srcbpp;
  1989. }
  1990. #endif
  1991. src += srcskip;
  1992. dst += dstskip;
  1993. }
  1994. } else {
  1995. while (height--) {
  1996. #ifdef USE_DUFFS_LOOP
  1997. /* *INDENT-OFF* */ /* clang-format off */
  1998. DUFFS_LOOP(
  1999. DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel,
  2000. sR, sG, sB);
  2001. if ( 1 ) {
  2002. /* Pack RGB into 8bit pixel */
  2003. *dst = map[((sR>>5)<<(3+2))|
  2004. ((sG>>5)<<(2)) |
  2005. ((sB>>6)<<(0)) ];
  2006. }
  2007. dst++;
  2008. src += srcbpp;
  2009. , width);
  2010. /* *INDENT-ON* */ /* clang-format on */
  2011. #else
  2012. for (c = width; c; --c) {
  2013. DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB);
  2014. if (1) {
  2015. /* Pack RGB into 8bit pixel */
  2016. *dst = map[((sR >> 5) << (3 + 2)) |
  2017. ((sG >> 5) << (2)) | ((sB >> 6) << (0))];
  2018. }
  2019. dst++;
  2020. src += srcbpp;
  2021. }
  2022. #endif /* USE_DUFFS_LOOP */
  2023. src += srcskip;
  2024. dst += dstskip;
  2025. }
  2026. }
  2027. }
  2028. /* blits 32 bit RGB<->RGBA with both surfaces having the same R,G,B fields */
  2029. static void Blit4to4MaskAlpha(SDL_BlitInfo *info)
  2030. {
  2031. int width = info->dst_w;
  2032. int height = info->dst_h;
  2033. Uint32 *src = (Uint32 *)info->src;
  2034. int srcskip = info->src_skip;
  2035. Uint32 *dst = (Uint32 *)info->dst;
  2036. int dstskip = info->dst_skip;
  2037. SDL_PixelFormat *srcfmt = info->src_fmt;
  2038. SDL_PixelFormat *dstfmt = info->dst_fmt;
  2039. if (dstfmt->Amask) {
  2040. /* RGB->RGBA, SET_ALPHA */
  2041. Uint32 mask = ((Uint32)info->a >> dstfmt->Aloss) << dstfmt->Ashift;
  2042. while (height--) {
  2043. /* *INDENT-OFF* */ /* clang-format off */
  2044. DUFFS_LOOP(
  2045. {
  2046. *dst = *src | mask;
  2047. ++dst;
  2048. ++src;
  2049. },
  2050. width);
  2051. /* *INDENT-ON* */ /* clang-format on */
  2052. src = (Uint32 *)((Uint8 *)src + srcskip);
  2053. dst = (Uint32 *)((Uint8 *)dst + dstskip);
  2054. }
  2055. } else {
  2056. /* RGBA->RGB, NO_ALPHA */
  2057. Uint32 mask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask;
  2058. while (height--) {
  2059. /* *INDENT-OFF* */ /* clang-format off */
  2060. DUFFS_LOOP(
  2061. {
  2062. *dst = *src & mask;
  2063. ++dst;
  2064. ++src;
  2065. },
  2066. width);
  2067. /* *INDENT-ON* */ /* clang-format on */
  2068. src = (Uint32 *)((Uint8 *)src + srcskip);
  2069. dst = (Uint32 *)((Uint8 *)dst + dstskip);
  2070. }
  2071. }
  2072. }
  2073. /* permutation for mapping srcfmt to dstfmt, overloading or not the alpha channel */
  2074. static void get_permutation(SDL_PixelFormat *srcfmt, SDL_PixelFormat *dstfmt,
  2075. int *_p0, int *_p1, int *_p2, int *_p3, int *_alpha_channel)
  2076. {
  2077. int alpha_channel = 0, p0, p1, p2, p3;
  2078. #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  2079. int Pixel = 0x04030201; /* identity permutation */
  2080. #else
  2081. int Pixel = 0x01020304; /* identity permutation */
  2082. int srcbpp = srcfmt->BytesPerPixel;
  2083. int dstbpp = dstfmt->BytesPerPixel;
  2084. #endif
  2085. if (srcfmt->Amask) {
  2086. RGBA_FROM_PIXEL(Pixel, srcfmt, p0, p1, p2, p3);
  2087. } else {
  2088. RGB_FROM_PIXEL(Pixel, srcfmt, p0, p1, p2);
  2089. p3 = 0;
  2090. }
  2091. if (dstfmt->Amask) {
  2092. if (srcfmt->Amask) {
  2093. PIXEL_FROM_RGBA(Pixel, dstfmt, p0, p1, p2, p3);
  2094. } else {
  2095. PIXEL_FROM_RGBA(Pixel, dstfmt, p0, p1, p2, 0);
  2096. }
  2097. } else {
  2098. PIXEL_FROM_RGB(Pixel, dstfmt, p0, p1, p2);
  2099. }
  2100. #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  2101. p0 = Pixel & 0xFF;
  2102. p1 = (Pixel >> 8) & 0xFF;
  2103. p2 = (Pixel >> 16) & 0xFF;
  2104. p3 = (Pixel >> 24) & 0xFF;
  2105. #else
  2106. p3 = Pixel & 0xFF;
  2107. p2 = (Pixel >> 8) & 0xFF;
  2108. p1 = (Pixel >> 16) & 0xFF;
  2109. p0 = (Pixel >> 24) & 0xFF;
  2110. #endif
  2111. if (p0 == 0) {
  2112. p0 = 1;
  2113. alpha_channel = 0;
  2114. } else if (p1 == 0) {
  2115. p1 = 1;
  2116. alpha_channel = 1;
  2117. } else if (p2 == 0) {
  2118. p2 = 1;
  2119. alpha_channel = 2;
  2120. } else if (p3 == 0) {
  2121. p3 = 1;
  2122. alpha_channel = 3;
  2123. }
  2124. #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  2125. #else
  2126. if (srcbpp == 3 && dstbpp == 4) {
  2127. if (p0 != 1) {
  2128. p0--;
  2129. }
  2130. if (p1 != 1) {
  2131. p1--;
  2132. }
  2133. if (p2 != 1) {
  2134. p2--;
  2135. }
  2136. if (p3 != 1) {
  2137. p3--;
  2138. }
  2139. } else if (srcbpp == 4 && dstbpp == 3) {
  2140. p0 = p1;
  2141. p1 = p2;
  2142. p2 = p3;
  2143. }
  2144. #endif
  2145. *_p0 = p0 - 1;
  2146. *_p1 = p1 - 1;
  2147. *_p2 = p2 - 1;
  2148. *_p3 = p3 - 1;
  2149. if (_alpha_channel) {
  2150. *_alpha_channel = alpha_channel;
  2151. }
  2152. }
  2153. static void BlitNtoN(SDL_BlitInfo *info)
  2154. {
  2155. int width = info->dst_w;
  2156. int height = info->dst_h;
  2157. Uint8 *src = info->src;
  2158. int srcskip = info->src_skip;
  2159. Uint8 *dst = info->dst;
  2160. int dstskip = info->dst_skip;
  2161. SDL_PixelFormat *srcfmt = info->src_fmt;
  2162. int srcbpp = srcfmt->BytesPerPixel;
  2163. SDL_PixelFormat *dstfmt = info->dst_fmt;
  2164. int dstbpp = dstfmt->BytesPerPixel;
  2165. unsigned alpha = dstfmt->Amask ? info->a : 0;
  2166. #if HAVE_FAST_WRITE_INT8
  2167. /* Blit with permutation: 4->4 */
  2168. if (srcbpp == 4 && dstbpp == 4 &&
  2169. srcfmt->format != SDL_PIXELFORMAT_ARGB2101010 &&
  2170. dstfmt->format != SDL_PIXELFORMAT_ARGB2101010) {
  2171. /* Find the appropriate permutation */
  2172. int alpha_channel, p0, p1, p2, p3;
  2173. get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, &alpha_channel);
  2174. while (height--) {
  2175. /* *INDENT-OFF* */ /* clang-format off */
  2176. DUFFS_LOOP(
  2177. {
  2178. dst[0] = src[p0];
  2179. dst[1] = src[p1];
  2180. dst[2] = src[p2];
  2181. dst[3] = src[p3];
  2182. dst[alpha_channel] = (Uint8)alpha;
  2183. src += 4;
  2184. dst += 4;
  2185. }, width);
  2186. /* *INDENT-ON* */ /* clang-format on */
  2187. src += srcskip;
  2188. dst += dstskip;
  2189. }
  2190. return;
  2191. }
  2192. #endif
  2193. /* Blit with permutation: 4->3 */
  2194. if (srcbpp == 4 && dstbpp == 3 &&
  2195. srcfmt->format != SDL_PIXELFORMAT_ARGB2101010) {
  2196. /* Find the appropriate permutation */
  2197. int p0, p1, p2, p3;
  2198. get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, NULL);
  2199. while (height--) {
  2200. /* *INDENT-OFF* */ /* clang-format off */
  2201. DUFFS_LOOP(
  2202. {
  2203. dst[0] = src[p0];
  2204. dst[1] = src[p1];
  2205. dst[2] = src[p2];
  2206. src += 4;
  2207. dst += 3;
  2208. }, width);
  2209. /* *INDENT-ON* */ /* clang-format on */
  2210. src += srcskip;
  2211. dst += dstskip;
  2212. }
  2213. return;
  2214. }
  2215. #if HAVE_FAST_WRITE_INT8
  2216. /* Blit with permutation: 3->4 */
  2217. if (srcbpp == 3 && dstbpp == 4 &&
  2218. dstfmt->format != SDL_PIXELFORMAT_ARGB2101010) {
  2219. /* Find the appropriate permutation */
  2220. int alpha_channel, p0, p1, p2, p3;
  2221. get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, &alpha_channel);
  2222. while (height--) {
  2223. /* *INDENT-OFF* */ /* clang-format off */
  2224. DUFFS_LOOP(
  2225. {
  2226. dst[0] = src[p0];
  2227. dst[1] = src[p1];
  2228. dst[2] = src[p2];
  2229. dst[3] = src[p3];
  2230. dst[alpha_channel] = (Uint8)alpha;
  2231. src += 3;
  2232. dst += 4;
  2233. }, width);
  2234. /* *INDENT-ON* */ /* clang-format on */
  2235. src += srcskip;
  2236. dst += dstskip;
  2237. }
  2238. return;
  2239. }
  2240. #endif
  2241. while (height--) {
  2242. /* *INDENT-OFF* */ /* clang-format off */
  2243. DUFFS_LOOP(
  2244. {
  2245. Uint32 Pixel;
  2246. unsigned sR;
  2247. unsigned sG;
  2248. unsigned sB;
  2249. DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel, sR, sG, sB);
  2250. ASSEMBLE_RGBA(dst, dstbpp, dstfmt, sR, sG, sB, alpha);
  2251. dst += dstbpp;
  2252. src += srcbpp;
  2253. },
  2254. width);
  2255. /* *INDENT-ON* */ /* clang-format on */
  2256. src += srcskip;
  2257. dst += dstskip;
  2258. }
  2259. }
  2260. static void BlitNtoNCopyAlpha(SDL_BlitInfo *info)
  2261. {
  2262. int width = info->dst_w;
  2263. int height = info->dst_h;
  2264. Uint8 *src = info->src;
  2265. int srcskip = info->src_skip;
  2266. Uint8 *dst = info->dst;
  2267. int dstskip = info->dst_skip;
  2268. SDL_PixelFormat *srcfmt = info->src_fmt;
  2269. int srcbpp = srcfmt->BytesPerPixel;
  2270. SDL_PixelFormat *dstfmt = info->dst_fmt;
  2271. int dstbpp = dstfmt->BytesPerPixel;
  2272. int c;
  2273. #if HAVE_FAST_WRITE_INT8
  2274. /* Blit with permutation: 4->4 */
  2275. if (srcbpp == 4 && dstbpp == 4 &&
  2276. srcfmt->format != SDL_PIXELFORMAT_ARGB2101010 &&
  2277. dstfmt->format != SDL_PIXELFORMAT_ARGB2101010) {
  2278. /* Find the appropriate permutation */
  2279. int p0, p1, p2, p3;
  2280. get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, NULL);
  2281. while (height--) {
  2282. /* *INDENT-OFF* */ /* clang-format off */
  2283. DUFFS_LOOP(
  2284. {
  2285. dst[0] = src[p0];
  2286. dst[1] = src[p1];
  2287. dst[2] = src[p2];
  2288. dst[3] = src[p3];
  2289. src += 4;
  2290. dst += 4;
  2291. }, width);
  2292. /* *INDENT-ON* */ /* clang-format on */
  2293. src += srcskip;
  2294. dst += dstskip;
  2295. }
  2296. return;
  2297. }
  2298. #endif
  2299. while (height--) {
  2300. for (c = width; c; --c) {
  2301. Uint32 Pixel;
  2302. unsigned sR, sG, sB, sA;
  2303. DISEMBLE_RGBA(src, srcbpp, srcfmt, Pixel, sR, sG, sB, sA);
  2304. ASSEMBLE_RGBA(dst, dstbpp, dstfmt, sR, sG, sB, sA);
  2305. dst += dstbpp;
  2306. src += srcbpp;
  2307. }
  2308. src += srcskip;
  2309. dst += dstskip;
  2310. }
  2311. }
  2312. static void BlitNto1Key(SDL_BlitInfo *info)
  2313. {
  2314. int width = info->dst_w;
  2315. int height = info->dst_h;
  2316. Uint8 *src = info->src;
  2317. int srcskip = info->src_skip;
  2318. Uint8 *dst = info->dst;
  2319. int dstskip = info->dst_skip;
  2320. SDL_PixelFormat *srcfmt = info->src_fmt;
  2321. const Uint8 *palmap = info->table;
  2322. Uint32 ckey = info->colorkey;
  2323. Uint32 rgbmask = ~srcfmt->Amask;
  2324. int srcbpp;
  2325. Uint32 Pixel;
  2326. unsigned sR, sG, sB;
  2327. /* Set up some basic variables */
  2328. srcbpp = srcfmt->BytesPerPixel;
  2329. ckey &= rgbmask;
  2330. if (palmap == NULL) {
  2331. while (height--) {
  2332. /* *INDENT-OFF* */ /* clang-format off */
  2333. DUFFS_LOOP(
  2334. {
  2335. DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel,
  2336. sR, sG, sB);
  2337. if ( (Pixel & rgbmask) != ckey ) {
  2338. /* Pack RGB into 8bit pixel */
  2339. *dst = (Uint8)(((sR>>5)<<(3+2))|
  2340. ((sG>>5)<<(2)) |
  2341. ((sB>>6)<<(0)));
  2342. }
  2343. dst++;
  2344. src += srcbpp;
  2345. },
  2346. width);
  2347. /* *INDENT-ON* */ /* clang-format on */
  2348. src += srcskip;
  2349. dst += dstskip;
  2350. }
  2351. } else {
  2352. while (height--) {
  2353. /* *INDENT-OFF* */ /* clang-format off */
  2354. DUFFS_LOOP(
  2355. {
  2356. DISEMBLE_RGB(src, srcbpp, srcfmt, Pixel,
  2357. sR, sG, sB);
  2358. if ( (Pixel & rgbmask) != ckey ) {
  2359. /* Pack RGB into 8bit pixel */
  2360. *dst = (Uint8)palmap[((sR>>5)<<(3+2))|
  2361. ((sG>>5)<<(2)) |
  2362. ((sB>>6)<<(0)) ];
  2363. }
  2364. dst++;
  2365. src += srcbpp;
  2366. },
  2367. width);
  2368. /* *INDENT-ON* */ /* clang-format on */
  2369. src += srcskip;
  2370. dst += dstskip;
  2371. }
  2372. }
  2373. }
  2374. static void Blit2to2Key(SDL_BlitInfo *info)
  2375. {
  2376. int width = info->dst_w;
  2377. int height = info->dst_h;
  2378. Uint16 *srcp = (Uint16 *)info->src;
  2379. int srcskip = info->src_skip;
  2380. Uint16 *dstp = (Uint16 *)info->dst;
  2381. int dstskip = info->dst_skip;
  2382. Uint32 ckey = info->colorkey;
  2383. Uint32 rgbmask = ~info->src_fmt->Amask;
  2384. /* Set up some basic variables */
  2385. srcskip /= 2;
  2386. dstskip /= 2;
  2387. ckey &= rgbmask;
  2388. while (height--) {
  2389. /* *INDENT-OFF* */ /* clang-format off */
  2390. DUFFS_LOOP(
  2391. {
  2392. if ( (*srcp & rgbmask) != ckey ) {
  2393. *dstp = *srcp;
  2394. }
  2395. dstp++;
  2396. srcp++;
  2397. },
  2398. width);
  2399. /* *INDENT-ON* */ /* clang-format on */
  2400. srcp += srcskip;
  2401. dstp += dstskip;
  2402. }
  2403. }
  2404. static void BlitNtoNKey(SDL_BlitInfo *info)
  2405. {
  2406. int width = info->dst_w;
  2407. int height = info->dst_h;
  2408. Uint8 *src = info->src;
  2409. int srcskip = info->src_skip;
  2410. Uint8 *dst = info->dst;
  2411. int dstskip = info->dst_skip;
  2412. Uint32 ckey = info->colorkey;
  2413. SDL_PixelFormat *srcfmt = info->src_fmt;
  2414. SDL_PixelFormat *dstfmt = info->dst_fmt;
  2415. int srcbpp = srcfmt->BytesPerPixel;
  2416. int dstbpp = dstfmt->BytesPerPixel;
  2417. unsigned alpha = dstfmt->Amask ? info->a : 0;
  2418. Uint32 rgbmask = ~srcfmt->Amask;
  2419. int sfmt = srcfmt->format;
  2420. int dfmt = dstfmt->format;
  2421. /* Set up some basic variables */
  2422. ckey &= rgbmask;
  2423. /* BPP 4, same rgb */
  2424. if (srcbpp == 4 && dstbpp == 4 && srcfmt->Rmask == dstfmt->Rmask && srcfmt->Gmask == dstfmt->Gmask && srcfmt->Bmask == dstfmt->Bmask) {
  2425. Uint32 *src32 = (Uint32 *)src;
  2426. Uint32 *dst32 = (Uint32 *)dst;
  2427. if (dstfmt->Amask) {
  2428. /* RGB->RGBA, SET_ALPHA */
  2429. Uint32 mask = ((Uint32)info->a) << dstfmt->Ashift;
  2430. while (height--) {
  2431. /* *INDENT-OFF* */ /* clang-format off */
  2432. DUFFS_LOOP(
  2433. {
  2434. if ((*src32 & rgbmask) != ckey) {
  2435. *dst32 = *src32 | mask;
  2436. }
  2437. ++dst32;
  2438. ++src32;
  2439. }, width);
  2440. /* *INDENT-ON* */ /* clang-format on */
  2441. src32 = (Uint32 *)((Uint8 *)src32 + srcskip);
  2442. dst32 = (Uint32 *)((Uint8 *)dst32 + dstskip);
  2443. }
  2444. return;
  2445. } else {
  2446. /* RGBA->RGB, NO_ALPHA */
  2447. Uint32 mask = srcfmt->Rmask | srcfmt->Gmask | srcfmt->Bmask;
  2448. while (height--) {
  2449. /* *INDENT-OFF* */ /* clang-format off */
  2450. DUFFS_LOOP(
  2451. {
  2452. if ((*src32 & rgbmask) != ckey) {
  2453. *dst32 = *src32 & mask;
  2454. }
  2455. ++dst32;
  2456. ++src32;
  2457. }, width);
  2458. /* *INDENT-ON* */ /* clang-format on */
  2459. src32 = (Uint32 *)((Uint8 *)src32 + srcskip);
  2460. dst32 = (Uint32 *)((Uint8 *)dst32 + dstskip);
  2461. }
  2462. return;
  2463. }
  2464. }
  2465. #if HAVE_FAST_WRITE_INT8
  2466. /* Blit with permutation: 4->4 */
  2467. if (srcbpp == 4 && dstbpp == 4 &&
  2468. srcfmt->format != SDL_PIXELFORMAT_ARGB2101010 &&
  2469. dstfmt->format != SDL_PIXELFORMAT_ARGB2101010) {
  2470. /* Find the appropriate permutation */
  2471. int alpha_channel, p0, p1, p2, p3;
  2472. get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, &alpha_channel);
  2473. while (height--) {
  2474. /* *INDENT-OFF* */ /* clang-format off */
  2475. DUFFS_LOOP(
  2476. {
  2477. Uint32 *src32 = (Uint32*)src;
  2478. if ((*src32 & rgbmask) != ckey) {
  2479. dst[0] = src[p0];
  2480. dst[1] = src[p1];
  2481. dst[2] = src[p2];
  2482. dst[3] = src[p3];
  2483. dst[alpha_channel] = (Uint8)alpha;
  2484. }
  2485. src += 4;
  2486. dst += 4;
  2487. }, width);
  2488. /* *INDENT-ON* */ /* clang-format on */
  2489. src += srcskip;
  2490. dst += dstskip;
  2491. }
  2492. return;
  2493. }
  2494. #endif
  2495. /* BPP 3, same rgb triplet */
  2496. if ((sfmt == SDL_PIXELFORMAT_RGB24 && dfmt == SDL_PIXELFORMAT_RGB24) ||
  2497. (sfmt == SDL_PIXELFORMAT_BGR24 && dfmt == SDL_PIXELFORMAT_BGR24)) {
  2498. #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  2499. Uint8 k0 = ckey & 0xFF;
  2500. Uint8 k1 = (ckey >> 8) & 0xFF;
  2501. Uint8 k2 = (ckey >> 16) & 0xFF;
  2502. #else
  2503. Uint8 k0 = (ckey >> 16) & 0xFF;
  2504. Uint8 k1 = (ckey >> 8) & 0xFF;
  2505. Uint8 k2 = ckey & 0xFF;
  2506. #endif
  2507. while (height--) {
  2508. /* *INDENT-OFF* */ /* clang-format off */
  2509. DUFFS_LOOP(
  2510. {
  2511. Uint8 s0 = src[0];
  2512. Uint8 s1 = src[1];
  2513. Uint8 s2 = src[2];
  2514. if (k0 != s0 || k1 != s1 || k2 != s2) {
  2515. dst[0] = s0;
  2516. dst[1] = s1;
  2517. dst[2] = s2;
  2518. }
  2519. src += 3;
  2520. dst += 3;
  2521. },
  2522. width);
  2523. /* *INDENT-ON* */ /* clang-format on */
  2524. src += srcskip;
  2525. dst += dstskip;
  2526. }
  2527. return;
  2528. }
  2529. /* BPP 3, inversed rgb triplet */
  2530. if ((sfmt == SDL_PIXELFORMAT_RGB24 && dfmt == SDL_PIXELFORMAT_BGR24) ||
  2531. (sfmt == SDL_PIXELFORMAT_BGR24 && dfmt == SDL_PIXELFORMAT_RGB24)) {
  2532. #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  2533. Uint8 k0 = ckey & 0xFF;
  2534. Uint8 k1 = (ckey >> 8) & 0xFF;
  2535. Uint8 k2 = (ckey >> 16) & 0xFF;
  2536. #else
  2537. Uint8 k0 = (ckey >> 16) & 0xFF;
  2538. Uint8 k1 = (ckey >> 8) & 0xFF;
  2539. Uint8 k2 = ckey & 0xFF;
  2540. #endif
  2541. while (height--) {
  2542. /* *INDENT-OFF* */ /* clang-format off */
  2543. DUFFS_LOOP(
  2544. {
  2545. Uint8 s0 = src[0];
  2546. Uint8 s1 = src[1];
  2547. Uint8 s2 = src[2];
  2548. if (k0 != s0 || k1 != s1 || k2 != s2) {
  2549. /* Inversed RGB */
  2550. dst[0] = s2;
  2551. dst[1] = s1;
  2552. dst[2] = s0;
  2553. }
  2554. src += 3;
  2555. dst += 3;
  2556. },
  2557. width);
  2558. /* *INDENT-ON* */ /* clang-format on */
  2559. src += srcskip;
  2560. dst += dstskip;
  2561. }
  2562. return;
  2563. }
  2564. /* Blit with permutation: 4->3 */
  2565. if (srcbpp == 4 && dstbpp == 3 &&
  2566. srcfmt->format != SDL_PIXELFORMAT_ARGB2101010) {
  2567. /* Find the appropriate permutation */
  2568. int p0, p1, p2, p3;
  2569. get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, NULL);
  2570. while (height--) {
  2571. /* *INDENT-OFF* */ /* clang-format off */
  2572. DUFFS_LOOP(
  2573. {
  2574. Uint32 *src32 = (Uint32*)src;
  2575. if ((*src32 & rgbmask) != ckey) {
  2576. dst[0] = src[p0];
  2577. dst[1] = src[p1];
  2578. dst[2] = src[p2];
  2579. }
  2580. src += 4;
  2581. dst += 3;
  2582. }, width);
  2583. /* *INDENT-ON* */ /* clang-format on */
  2584. src += srcskip;
  2585. dst += dstskip;
  2586. }
  2587. return;
  2588. }
  2589. #if HAVE_FAST_WRITE_INT8
  2590. /* Blit with permutation: 3->4 */
  2591. if (srcbpp == 3 && dstbpp == 4 &&
  2592. dstfmt->format != SDL_PIXELFORMAT_ARGB2101010) {
  2593. #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  2594. Uint8 k0 = ckey & 0xFF;
  2595. Uint8 k1 = (ckey >> 8) & 0xFF;
  2596. Uint8 k2 = (ckey >> 16) & 0xFF;
  2597. #else
  2598. Uint8 k0 = (ckey >> 16) & 0xFF;
  2599. Uint8 k1 = (ckey >> 8) & 0xFF;
  2600. Uint8 k2 = ckey & 0xFF;
  2601. #endif
  2602. /* Find the appropriate permutation */
  2603. int alpha_channel, p0, p1, p2, p3;
  2604. get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, &alpha_channel);
  2605. while (height--) {
  2606. /* *INDENT-OFF* */ /* clang-format off */
  2607. DUFFS_LOOP(
  2608. {
  2609. Uint8 s0 = src[0];
  2610. Uint8 s1 = src[1];
  2611. Uint8 s2 = src[2];
  2612. if (k0 != s0 || k1 != s1 || k2 != s2) {
  2613. dst[0] = src[p0];
  2614. dst[1] = src[p1];
  2615. dst[2] = src[p2];
  2616. dst[3] = src[p3];
  2617. dst[alpha_channel] = (Uint8)alpha;
  2618. }
  2619. src += 3;
  2620. dst += 4;
  2621. }, width);
  2622. /* *INDENT-ON* */ /* clang-format on */
  2623. src += srcskip;
  2624. dst += dstskip;
  2625. }
  2626. return;
  2627. }
  2628. #endif
  2629. while (height--) {
  2630. /* *INDENT-OFF* */ /* clang-format off */
  2631. DUFFS_LOOP(
  2632. {
  2633. Uint32 Pixel;
  2634. unsigned sR;
  2635. unsigned sG;
  2636. unsigned sB;
  2637. RETRIEVE_RGB_PIXEL(src, srcbpp, Pixel);
  2638. if ( (Pixel & rgbmask) != ckey ) {
  2639. RGB_FROM_PIXEL(Pixel, srcfmt, sR, sG, sB);
  2640. ASSEMBLE_RGBA(dst, dstbpp, dstfmt, sR, sG, sB, alpha);
  2641. }
  2642. dst += dstbpp;
  2643. src += srcbpp;
  2644. },
  2645. width);
  2646. /* *INDENT-ON* */ /* clang-format on */
  2647. src += srcskip;
  2648. dst += dstskip;
  2649. }
  2650. }
  2651. static void BlitNtoNKeyCopyAlpha(SDL_BlitInfo *info)
  2652. {
  2653. int width = info->dst_w;
  2654. int height = info->dst_h;
  2655. Uint8 *src = info->src;
  2656. int srcskip = info->src_skip;
  2657. Uint8 *dst = info->dst;
  2658. int dstskip = info->dst_skip;
  2659. Uint32 ckey = info->colorkey;
  2660. SDL_PixelFormat *srcfmt = info->src_fmt;
  2661. SDL_PixelFormat *dstfmt = info->dst_fmt;
  2662. Uint32 rgbmask = ~srcfmt->Amask;
  2663. Uint8 srcbpp;
  2664. Uint8 dstbpp;
  2665. Uint32 Pixel;
  2666. unsigned sR, sG, sB, sA;
  2667. /* Set up some basic variables */
  2668. srcbpp = srcfmt->BytesPerPixel;
  2669. dstbpp = dstfmt->BytesPerPixel;
  2670. ckey &= rgbmask;
  2671. /* Fastpath: same source/destination format, with Amask, bpp 32, loop is vectorized. ~10x faster */
  2672. if (srcfmt->format == dstfmt->format) {
  2673. if (srcfmt->format == SDL_PIXELFORMAT_ARGB8888 ||
  2674. srcfmt->format == SDL_PIXELFORMAT_ABGR8888 ||
  2675. srcfmt->format == SDL_PIXELFORMAT_BGRA8888 ||
  2676. srcfmt->format == SDL_PIXELFORMAT_RGBA8888) {
  2677. Uint32 *src32 = (Uint32 *)src;
  2678. Uint32 *dst32 = (Uint32 *)dst;
  2679. while (height--) {
  2680. /* *INDENT-OFF* */ /* clang-format off */
  2681. DUFFS_LOOP(
  2682. {
  2683. if ((*src32 & rgbmask) != ckey) {
  2684. *dst32 = *src32;
  2685. }
  2686. ++src32;
  2687. ++dst32;
  2688. },
  2689. width);
  2690. /* *INDENT-ON* */ /* clang-format on */
  2691. src32 = (Uint32 *)((Uint8 *)src32 + srcskip);
  2692. dst32 = (Uint32 *)((Uint8 *)dst32 + dstskip);
  2693. }
  2694. }
  2695. return;
  2696. }
  2697. #if HAVE_FAST_WRITE_INT8
  2698. /* Blit with permutation: 4->4 */
  2699. if (srcbpp == 4 && dstbpp == 4 &&
  2700. srcfmt->format != SDL_PIXELFORMAT_ARGB2101010 &&
  2701. dstfmt->format != SDL_PIXELFORMAT_ARGB2101010) {
  2702. /* Find the appropriate permutation */
  2703. int p0, p1, p2, p3;
  2704. get_permutation(srcfmt, dstfmt, &p0, &p1, &p2, &p3, NULL);
  2705. while (height--) {
  2706. /* *INDENT-OFF* */ /* clang-format off */
  2707. DUFFS_LOOP(
  2708. {
  2709. Uint32 *src32 = (Uint32*)src;
  2710. if ((*src32 & rgbmask) != ckey) {
  2711. dst[0] = src[p0];
  2712. dst[1] = src[p1];
  2713. dst[2] = src[p2];
  2714. dst[3] = src[p3];
  2715. }
  2716. src += 4;
  2717. dst += 4;
  2718. }, width);
  2719. /* *INDENT-ON* */ /* clang-format on */
  2720. src += srcskip;
  2721. dst += dstskip;
  2722. }
  2723. return;
  2724. }
  2725. #endif
  2726. while (height--) {
  2727. /* *INDENT-OFF* */ /* clang-format off */
  2728. DUFFS_LOOP(
  2729. {
  2730. DISEMBLE_RGBA(src, srcbpp, srcfmt, Pixel, sR, sG, sB, sA);
  2731. if ( (Pixel & rgbmask) != ckey ) {
  2732. ASSEMBLE_RGBA(dst, dstbpp, dstfmt, sR, sG, sB, sA);
  2733. }
  2734. dst += dstbpp;
  2735. src += srcbpp;
  2736. },
  2737. width);
  2738. /* *INDENT-ON* */ /* clang-format on */
  2739. src += srcskip;
  2740. dst += dstskip;
  2741. }
  2742. }
  2743. /* Special optimized blit for ARGB 2-10-10-10 --> RGBA */
  2744. static void Blit2101010toN(SDL_BlitInfo *info)
  2745. {
  2746. int width = info->dst_w;
  2747. int height = info->dst_h;
  2748. Uint8 *src = info->src;
  2749. int srcskip = info->src_skip;
  2750. Uint8 *dst = info->dst;
  2751. int dstskip = info->dst_skip;
  2752. SDL_PixelFormat *dstfmt = info->dst_fmt;
  2753. int dstbpp = dstfmt->BytesPerPixel;
  2754. Uint32 Pixel;
  2755. unsigned sR, sG, sB, sA;
  2756. while (height--) {
  2757. /* *INDENT-OFF* */ /* clang-format off */
  2758. DUFFS_LOOP(
  2759. {
  2760. Pixel = *(Uint32 *)src;
  2761. RGBA_FROM_ARGB2101010(Pixel, sR, sG, sB, sA);
  2762. ASSEMBLE_RGBA(dst, dstbpp, dstfmt, sR, sG, sB, sA);
  2763. dst += dstbpp;
  2764. src += 4;
  2765. },
  2766. width);
  2767. /* *INDENT-ON* */ /* clang-format on */
  2768. src += srcskip;
  2769. dst += dstskip;
  2770. }
  2771. }
  2772. /* Special optimized blit for RGBA --> ARGB 2-10-10-10 */
  2773. static void BlitNto2101010(SDL_BlitInfo *info)
  2774. {
  2775. int width = info->dst_w;
  2776. int height = info->dst_h;
  2777. Uint8 *src = info->src;
  2778. int srcskip = info->src_skip;
  2779. Uint8 *dst = info->dst;
  2780. int dstskip = info->dst_skip;
  2781. SDL_PixelFormat *srcfmt = info->src_fmt;
  2782. int srcbpp = srcfmt->BytesPerPixel;
  2783. Uint32 Pixel;
  2784. unsigned sR, sG, sB, sA;
  2785. while (height--) {
  2786. /* *INDENT-OFF* */ /* clang-format off */
  2787. DUFFS_LOOP(
  2788. {
  2789. DISEMBLE_RGBA(src, srcbpp, srcfmt, Pixel, sR, sG, sB, sA);
  2790. ARGB2101010_FROM_RGBA(Pixel, sR, sG, sB, sA);
  2791. *(Uint32 *)dst = Pixel;
  2792. dst += 4;
  2793. src += srcbpp;
  2794. },
  2795. width);
  2796. /* *INDENT-ON* */ /* clang-format on */
  2797. src += srcskip;
  2798. dst += dstskip;
  2799. }
  2800. }
  2801. /* Blit_3or4_to_3or4__same_rgb: 3 or 4 bpp, same RGB triplet */
  2802. static void Blit_3or4_to_3or4__same_rgb(SDL_BlitInfo *info)
  2803. {
  2804. int width = info->dst_w;
  2805. int height = info->dst_h;
  2806. Uint8 *src = info->src;
  2807. int srcskip = info->src_skip;
  2808. Uint8 *dst = info->dst;
  2809. int dstskip = info->dst_skip;
  2810. SDL_PixelFormat *srcfmt = info->src_fmt;
  2811. int srcbpp = srcfmt->BytesPerPixel;
  2812. SDL_PixelFormat *dstfmt = info->dst_fmt;
  2813. int dstbpp = dstfmt->BytesPerPixel;
  2814. if (dstfmt->Amask) {
  2815. /* SET_ALPHA */
  2816. Uint32 mask = ((Uint32)info->a) << dstfmt->Ashift;
  2817. #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  2818. int i0 = 0, i1 = 1, i2 = 2;
  2819. #else
  2820. int i0 = srcbpp - 1 - 0;
  2821. int i1 = srcbpp - 1 - 1;
  2822. int i2 = srcbpp - 1 - 2;
  2823. #endif
  2824. while (height--) {
  2825. /* *INDENT-OFF* */ /* clang-format off */
  2826. DUFFS_LOOP(
  2827. {
  2828. Uint32 *dst32 = (Uint32*)dst;
  2829. Uint8 s0 = src[i0];
  2830. Uint8 s1 = src[i1];
  2831. Uint8 s2 = src[i2];
  2832. *dst32 = (s0) | (s1 << 8) | (s2 << 16) | mask;
  2833. dst += 4;
  2834. src += srcbpp;
  2835. }, width);
  2836. /* *INDENT-ON* */ /* clang-format on */
  2837. src += srcskip;
  2838. dst += dstskip;
  2839. }
  2840. } else {
  2841. /* NO_ALPHA */
  2842. #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  2843. int i0 = 0, i1 = 1, i2 = 2;
  2844. int j0 = 0, j1 = 1, j2 = 2;
  2845. #else
  2846. int i0 = srcbpp - 1 - 0;
  2847. int i1 = srcbpp - 1 - 1;
  2848. int i2 = srcbpp - 1 - 2;
  2849. int j0 = dstbpp - 1 - 0;
  2850. int j1 = dstbpp - 1 - 1;
  2851. int j2 = dstbpp - 1 - 2;
  2852. #endif
  2853. while (height--) {
  2854. /* *INDENT-OFF* */ /* clang-format off */
  2855. DUFFS_LOOP(
  2856. {
  2857. Uint8 s0 = src[i0];
  2858. Uint8 s1 = src[i1];
  2859. Uint8 s2 = src[i2];
  2860. dst[j0] = s0;
  2861. dst[j1] = s1;
  2862. dst[j2] = s2;
  2863. dst += dstbpp;
  2864. src += srcbpp;
  2865. }, width);
  2866. /* *INDENT-ON* */ /* clang-format on */
  2867. src += srcskip;
  2868. dst += dstskip;
  2869. }
  2870. }
  2871. }
  2872. /* Blit_3or4_to_3or4__inversed_rgb: 3 or 4 bpp, inversed RGB triplet */
  2873. static void Blit_3or4_to_3or4__inversed_rgb(SDL_BlitInfo *info)
  2874. {
  2875. int width = info->dst_w;
  2876. int height = info->dst_h;
  2877. Uint8 *src = info->src;
  2878. int srcskip = info->src_skip;
  2879. Uint8 *dst = info->dst;
  2880. int dstskip = info->dst_skip;
  2881. SDL_PixelFormat *srcfmt = info->src_fmt;
  2882. int srcbpp = srcfmt->BytesPerPixel;
  2883. SDL_PixelFormat *dstfmt = info->dst_fmt;
  2884. int dstbpp = dstfmt->BytesPerPixel;
  2885. if (dstfmt->Amask) {
  2886. if (srcfmt->Amask) {
  2887. /* COPY_ALPHA */
  2888. /* Only to switch ABGR8888 <-> ARGB8888 */
  2889. while (height--) {
  2890. #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  2891. int i0 = 0, i1 = 1, i2 = 2, i3 = 3;
  2892. #else
  2893. int i0 = 3, i1 = 2, i2 = 1, i3 = 0;
  2894. #endif
  2895. /* *INDENT-OFF* */ /* clang-format off */
  2896. DUFFS_LOOP(
  2897. {
  2898. Uint32 *dst32 = (Uint32*)dst;
  2899. Uint8 s0 = src[i0];
  2900. Uint8 s1 = src[i1];
  2901. Uint8 s2 = src[i2];
  2902. Uint32 alphashift = ((Uint32)src[i3]) << dstfmt->Ashift;
  2903. /* inversed, compared to Blit_3or4_to_3or4__same_rgb */
  2904. *dst32 = (s0 << 16) | (s1 << 8) | (s2) | alphashift;
  2905. dst += 4;
  2906. src += 4;
  2907. }, width);
  2908. /* *INDENT-ON* */ /* clang-format on */
  2909. src += srcskip;
  2910. dst += dstskip;
  2911. }
  2912. } else {
  2913. /* SET_ALPHA */
  2914. Uint32 mask = ((Uint32)info->a) << dstfmt->Ashift;
  2915. #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  2916. int i0 = 0, i1 = 1, i2 = 2;
  2917. #else
  2918. int i0 = srcbpp - 1 - 0;
  2919. int i1 = srcbpp - 1 - 1;
  2920. int i2 = srcbpp - 1 - 2;
  2921. #endif
  2922. while (height--) {
  2923. /* *INDENT-OFF* */ /* clang-format off */
  2924. DUFFS_LOOP(
  2925. {
  2926. Uint32 *dst32 = (Uint32*)dst;
  2927. Uint8 s0 = src[i0];
  2928. Uint8 s1 = src[i1];
  2929. Uint8 s2 = src[i2];
  2930. /* inversed, compared to Blit_3or4_to_3or4__same_rgb */
  2931. *dst32 = (s0 << 16) | (s1 << 8) | (s2) | mask;
  2932. dst += 4;
  2933. src += srcbpp;
  2934. }, width);
  2935. /* *INDENT-ON* */ /* clang-format on */
  2936. src += srcskip;
  2937. dst += dstskip;
  2938. }
  2939. }
  2940. } else {
  2941. /* NO_ALPHA */
  2942. #if SDL_BYTEORDER == SDL_LIL_ENDIAN
  2943. int i0 = 0, i1 = 1, i2 = 2;
  2944. int j0 = 2, j1 = 1, j2 = 0;
  2945. #else
  2946. int i0 = srcbpp - 1 - 0;
  2947. int i1 = srcbpp - 1 - 1;
  2948. int i2 = srcbpp - 1 - 2;
  2949. int j0 = dstbpp - 1 - 2;
  2950. int j1 = dstbpp - 1 - 1;
  2951. int j2 = dstbpp - 1 - 0;
  2952. #endif
  2953. while (height--) {
  2954. /* *INDENT-OFF* */ /* clang-format off */
  2955. DUFFS_LOOP(
  2956. {
  2957. Uint8 s0 = src[i0];
  2958. Uint8 s1 = src[i1];
  2959. Uint8 s2 = src[i2];
  2960. /* inversed, compared to Blit_3or4_to_3or4__same_rgb */
  2961. dst[j0] = s0;
  2962. dst[j1] = s1;
  2963. dst[j2] = s2;
  2964. dst += dstbpp;
  2965. src += srcbpp;
  2966. }, width);
  2967. /* *INDENT-ON* */ /* clang-format on */
  2968. src += srcskip;
  2969. dst += dstskip;
  2970. }
  2971. }
  2972. }
  2973. /* Normal N to N optimized blitters */
  2974. #define NO_ALPHA 1
  2975. #define SET_ALPHA 2
  2976. #define COPY_ALPHA 4
  2977. struct blit_table
  2978. {
  2979. Uint32 srcR, srcG, srcB;
  2980. int dstbpp;
  2981. Uint32 dstR, dstG, dstB;
  2982. enum blit_features blit_features;
  2983. SDL_BlitFunc blitfunc;
  2984. Uint32 alpha; /* bitwise NO_ALPHA, SET_ALPHA, COPY_ALPHA */
  2985. };
  2986. static const struct blit_table normal_blit_1[] = {
  2987. /* Default for 8-bit RGB source, never optimized */
  2988. { 0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0 }
  2989. };
  2990. static const struct blit_table normal_blit_2[] = {
  2991. #ifdef SDL_ALTIVEC_BLITTERS
  2992. /* has-altivec */
  2993. { 0x0000F800, 0x000007E0, 0x0000001F, 4, 0x00000000, 0x00000000, 0x00000000,
  2994. BLIT_FEATURE_HAS_ALTIVEC, Blit_RGB565_32Altivec, NO_ALPHA | COPY_ALPHA | SET_ALPHA },
  2995. { 0x00007C00, 0x000003E0, 0x0000001F, 4, 0x00000000, 0x00000000, 0x00000000,
  2996. BLIT_FEATURE_HAS_ALTIVEC, Blit_RGB555_32Altivec, NO_ALPHA | COPY_ALPHA | SET_ALPHA },
  2997. #endif
  2998. #ifdef SDL_ARM_SIMD_BLITTERS
  2999. { 0x00000F00, 0x000000F0, 0x0000000F, 4, 0x00FF0000, 0x0000FF00, 0x000000FF,
  3000. BLIT_FEATURE_HAS_ARM_SIMD, Blit_RGB444_XRGB8888ARMSIMD, NO_ALPHA | COPY_ALPHA },
  3001. #endif
  3002. #if SDL_HAVE_BLIT_N_RGB565
  3003. { 0x0000F800, 0x000007E0, 0x0000001F, 4, 0x00FF0000, 0x0000FF00, 0x000000FF,
  3004. 0, Blit_RGB565_ARGB8888, NO_ALPHA | COPY_ALPHA | SET_ALPHA },
  3005. { 0x0000F800, 0x000007E0, 0x0000001F, 4, 0x000000FF, 0x0000FF00, 0x00FF0000,
  3006. 0, Blit_RGB565_ABGR8888, NO_ALPHA | COPY_ALPHA | SET_ALPHA },
  3007. { 0x0000F800, 0x000007E0, 0x0000001F, 4, 0xFF000000, 0x00FF0000, 0x0000FF00,
  3008. 0, Blit_RGB565_RGBA8888, NO_ALPHA | COPY_ALPHA | SET_ALPHA },
  3009. { 0x0000F800, 0x000007E0, 0x0000001F, 4, 0x0000FF00, 0x00FF0000, 0xFF000000,
  3010. 0, Blit_RGB565_BGRA8888, NO_ALPHA | COPY_ALPHA | SET_ALPHA },
  3011. #endif
  3012. { 0x00007C00, 0x000003E0, 0x0000001F, 2, 0x00007C00, 0x000003E0, 0x0000001F,
  3013. 0, Blit_RGB555_ARGB1555, SET_ALPHA },
  3014. { 0x0000001F, 0x000003E0, 0x00007C00, 2, 0x0000001F, 0x000003E0, 0x00007C00,
  3015. 0, Blit_RGB555_ARGB1555, SET_ALPHA },
  3016. /* Default for 16-bit RGB source, used if no other blitter matches */
  3017. { 0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0 }
  3018. };
  3019. static const struct blit_table normal_blit_3[] = {
  3020. /* 3->4 with same rgb triplet */
  3021. { 0x000000FF, 0x0000FF00, 0x00FF0000, 4, 0x000000FF, 0x0000FF00, 0x00FF0000,
  3022. 0, Blit_3or4_to_3or4__same_rgb,
  3023. #if HAVE_FAST_WRITE_INT8
  3024. NO_ALPHA |
  3025. #endif
  3026. SET_ALPHA },
  3027. { 0x00FF0000, 0x0000FF00, 0x000000FF, 4, 0x00FF0000, 0x0000FF00, 0x000000FF,
  3028. 0, Blit_3or4_to_3or4__same_rgb,
  3029. #if HAVE_FAST_WRITE_INT8
  3030. NO_ALPHA |
  3031. #endif
  3032. SET_ALPHA },
  3033. /* 3->4 with inversed rgb triplet */
  3034. { 0x000000FF, 0x0000FF00, 0x00FF0000, 4, 0x00FF0000, 0x0000FF00, 0x000000FF,
  3035. 0, Blit_3or4_to_3or4__inversed_rgb,
  3036. #if HAVE_FAST_WRITE_INT8
  3037. NO_ALPHA |
  3038. #endif
  3039. SET_ALPHA },
  3040. { 0x00FF0000, 0x0000FF00, 0x000000FF, 4, 0x000000FF, 0x0000FF00, 0x00FF0000,
  3041. 0, Blit_3or4_to_3or4__inversed_rgb,
  3042. #if HAVE_FAST_WRITE_INT8
  3043. NO_ALPHA |
  3044. #endif
  3045. SET_ALPHA },
  3046. /* 3->3 to switch RGB 24 <-> BGR 24 */
  3047. { 0x000000FF, 0x0000FF00, 0x00FF0000, 3, 0x00FF0000, 0x0000FF00, 0x000000FF,
  3048. 0, Blit_3or4_to_3or4__inversed_rgb, NO_ALPHA },
  3049. { 0x00FF0000, 0x0000FF00, 0x000000FF, 3, 0x000000FF, 0x0000FF00, 0x00FF0000,
  3050. 0, Blit_3or4_to_3or4__inversed_rgb, NO_ALPHA },
  3051. /* Default for 24-bit RGB source, never optimized */
  3052. { 0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0 }
  3053. };
  3054. static const struct blit_table normal_blit_4[] = {
  3055. #ifdef SDL_ALTIVEC_BLITTERS
  3056. /* has-altivec | dont-use-prefetch */
  3057. { 0x00000000, 0x00000000, 0x00000000, 4, 0x00000000, 0x00000000, 0x00000000,
  3058. BLIT_FEATURE_HAS_ALTIVEC | BLIT_FEATURE_ALTIVEC_DONT_USE_PREFETCH, ConvertAltivec32to32_noprefetch, NO_ALPHA | COPY_ALPHA | SET_ALPHA },
  3059. /* has-altivec */
  3060. { 0x00000000, 0x00000000, 0x00000000, 4, 0x00000000, 0x00000000, 0x00000000,
  3061. BLIT_FEATURE_HAS_ALTIVEC, ConvertAltivec32to32_prefetch, NO_ALPHA | COPY_ALPHA | SET_ALPHA },
  3062. /* has-altivec */
  3063. { 0x00000000, 0x00000000, 0x00000000, 2, 0x0000F800, 0x000007E0, 0x0000001F,
  3064. BLIT_FEATURE_HAS_ALTIVEC, Blit_XRGB8888_RGB565Altivec, NO_ALPHA },
  3065. #endif
  3066. #ifdef SDL_ARM_SIMD_BLITTERS
  3067. { 0x000000FF, 0x0000FF00, 0x00FF0000, 4, 0x00FF0000, 0x0000FF00, 0x000000FF,
  3068. BLIT_FEATURE_HAS_ARM_SIMD, Blit_XBGR8888_XRGB8888ARMSIMD, NO_ALPHA | COPY_ALPHA },
  3069. #endif
  3070. /* 4->3 with same rgb triplet */
  3071. { 0x000000FF, 0x0000FF00, 0x00FF0000, 3, 0x000000FF, 0x0000FF00, 0x00FF0000,
  3072. 0, Blit_3or4_to_3or4__same_rgb, NO_ALPHA | SET_ALPHA },
  3073. { 0x00FF0000, 0x0000FF00, 0x000000FF, 3, 0x00FF0000, 0x0000FF00, 0x000000FF,
  3074. 0, Blit_3or4_to_3or4__same_rgb, NO_ALPHA | SET_ALPHA },
  3075. /* 4->3 with inversed rgb triplet */
  3076. { 0x000000FF, 0x0000FF00, 0x00FF0000, 3, 0x00FF0000, 0x0000FF00, 0x000000FF,
  3077. 0, Blit_3or4_to_3or4__inversed_rgb, NO_ALPHA | SET_ALPHA },
  3078. { 0x00FF0000, 0x0000FF00, 0x000000FF, 3, 0x000000FF, 0x0000FF00, 0x00FF0000,
  3079. 0, Blit_3or4_to_3or4__inversed_rgb, NO_ALPHA | SET_ALPHA },
  3080. /* 4->4 with inversed rgb triplet, and COPY_ALPHA to switch ABGR8888 <-> ARGB8888 */
  3081. { 0x000000FF, 0x0000FF00, 0x00FF0000, 4, 0x00FF0000, 0x0000FF00, 0x000000FF,
  3082. 0, Blit_3or4_to_3or4__inversed_rgb,
  3083. #if HAVE_FAST_WRITE_INT8
  3084. NO_ALPHA |
  3085. #endif
  3086. SET_ALPHA | COPY_ALPHA },
  3087. { 0x00FF0000, 0x0000FF00, 0x000000FF, 4, 0x000000FF, 0x0000FF00, 0x00FF0000,
  3088. 0, Blit_3or4_to_3or4__inversed_rgb,
  3089. #if HAVE_FAST_WRITE_INT8
  3090. NO_ALPHA |
  3091. #endif
  3092. SET_ALPHA | COPY_ALPHA },
  3093. /* RGB 888 and RGB 565 */
  3094. { 0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x0000F800, 0x000007E0, 0x0000001F,
  3095. 0, Blit_XRGB8888_RGB565, NO_ALPHA },
  3096. { 0x00FF0000, 0x0000FF00, 0x000000FF, 2, 0x00007C00, 0x000003E0, 0x0000001F,
  3097. 0, Blit_XRGB8888_RGB555, NO_ALPHA },
  3098. /* Default for 32-bit RGB source, used if no other blitter matches */
  3099. { 0, 0, 0, 0, 0, 0, 0, 0, BlitNtoN, 0 }
  3100. };
  3101. static const struct blit_table *const normal_blit[] = {
  3102. normal_blit_1, normal_blit_2, normal_blit_3, normal_blit_4
  3103. };
  3104. /* Mask matches table, or table entry is zero */
  3105. #define MASKOK(x, y) (((x) == (y)) || ((y) == 0x00000000))
  3106. SDL_BlitFunc SDL_CalculateBlitN(SDL_Surface *surface)
  3107. {
  3108. SDL_PixelFormat *srcfmt;
  3109. SDL_PixelFormat *dstfmt;
  3110. const struct blit_table *table;
  3111. int which;
  3112. SDL_BlitFunc blitfun;
  3113. /* Set up data for choosing the blit */
  3114. srcfmt = surface->format;
  3115. dstfmt = surface->map->dst->format;
  3116. /* We don't support destinations less than 8-bits */
  3117. if (dstfmt->BitsPerPixel < 8) {
  3118. return NULL;
  3119. }
  3120. switch (surface->map->info.flags & ~SDL_COPY_RLE_MASK) {
  3121. case 0:
  3122. blitfun = NULL;
  3123. if (dstfmt->BitsPerPixel == 8) {
  3124. if ((srcfmt->BytesPerPixel == 4) &&
  3125. (srcfmt->Rmask == 0x00FF0000) &&
  3126. (srcfmt->Gmask == 0x0000FF00) &&
  3127. (srcfmt->Bmask == 0x000000FF)) {
  3128. blitfun = Blit_XRGB8888_index8;
  3129. } else if ((srcfmt->BytesPerPixel == 4) &&
  3130. (srcfmt->Rmask == 0x3FF00000) &&
  3131. (srcfmt->Gmask == 0x000FFC00) &&
  3132. (srcfmt->Bmask == 0x000003FF)) {
  3133. blitfun = Blit_RGB101010_index8;
  3134. } else {
  3135. blitfun = BlitNto1;
  3136. }
  3137. } else {
  3138. /* Now the meat, choose the blitter we want */
  3139. Uint32 a_need = NO_ALPHA;
  3140. if (dstfmt->Amask) {
  3141. a_need = srcfmt->Amask ? COPY_ALPHA : SET_ALPHA;
  3142. }
  3143. table = normal_blit[srcfmt->BytesPerPixel - 1];
  3144. for (which = 0; table[which].dstbpp; ++which) {
  3145. if (MASKOK(srcfmt->Rmask, table[which].srcR) &&
  3146. MASKOK(srcfmt->Gmask, table[which].srcG) &&
  3147. MASKOK(srcfmt->Bmask, table[which].srcB) &&
  3148. MASKOK(dstfmt->Rmask, table[which].dstR) &&
  3149. MASKOK(dstfmt->Gmask, table[which].dstG) &&
  3150. MASKOK(dstfmt->Bmask, table[which].dstB) &&
  3151. dstfmt->BytesPerPixel == table[which].dstbpp &&
  3152. (a_need & table[which].alpha) == a_need &&
  3153. ((table[which].blit_features & GetBlitFeatures()) ==
  3154. table[which].blit_features)) {
  3155. break;
  3156. }
  3157. }
  3158. blitfun = table[which].blitfunc;
  3159. if (blitfun == BlitNtoN) { /* default C fallback catch-all. Slow! */
  3160. if (srcfmt->format == SDL_PIXELFORMAT_ARGB2101010) {
  3161. blitfun = Blit2101010toN;
  3162. } else if (dstfmt->format == SDL_PIXELFORMAT_ARGB2101010) {
  3163. blitfun = BlitNto2101010;
  3164. } else if (srcfmt->BytesPerPixel == 4 &&
  3165. dstfmt->BytesPerPixel == 4 &&
  3166. srcfmt->Rmask == dstfmt->Rmask &&
  3167. srcfmt->Gmask == dstfmt->Gmask &&
  3168. srcfmt->Bmask == dstfmt->Bmask) {
  3169. if (a_need == COPY_ALPHA) {
  3170. if (srcfmt->Amask == dstfmt->Amask) {
  3171. /* Fastpath C fallback: 32bit RGBA<->RGBA blit with matching RGBA */
  3172. blitfun = SDL_BlitCopy;
  3173. } else {
  3174. blitfun = BlitNtoNCopyAlpha;
  3175. }
  3176. } else {
  3177. /* Fastpath C fallback: 32bit RGB<->RGBA blit with matching RGB */
  3178. blitfun = Blit4to4MaskAlpha;
  3179. }
  3180. } else if (a_need == COPY_ALPHA) {
  3181. blitfun = BlitNtoNCopyAlpha;
  3182. }
  3183. }
  3184. }
  3185. return blitfun;
  3186. case SDL_COPY_COLORKEY:
  3187. /* colorkey blit: Here we don't have too many options, mostly
  3188. because RLE is the preferred fast way to deal with this.
  3189. If a particular case turns out to be useful we'll add it. */
  3190. if (srcfmt->BytesPerPixel == 2 && surface->map->identity != 0) {
  3191. return Blit2to2Key;
  3192. } else if (dstfmt->BytesPerPixel == 1) {
  3193. return BlitNto1Key;
  3194. } else {
  3195. #ifdef SDL_ALTIVEC_BLITTERS
  3196. if ((srcfmt->BytesPerPixel == 4) && (dstfmt->BytesPerPixel == 4) && SDL_HasAltiVec()) {
  3197. return Blit32to32KeyAltivec;
  3198. } else
  3199. #endif
  3200. if (srcfmt->Amask && dstfmt->Amask) {
  3201. return BlitNtoNKeyCopyAlpha;
  3202. } else {
  3203. return BlitNtoNKey;
  3204. }
  3205. }
  3206. }
  3207. return NULL;
  3208. }
  3209. #endif /* SDL_HAVE_BLIT_N */