SDL_blit_N.c 121 KB

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