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