SDL_blit_N.c 116 KB

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