SDL_blit_N.c 113 KB

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