SDL_blit_N.c 121 KB

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