d9d266f9be423e7372a0c09c657e5880a15d14c6
[platform/upstream/SDL.git] / src / video / SDL_blit_auto.c
1 /* DO NOT EDIT!  This file is generated by sdlgenblit.pl */
2 /*
3   Simple DirectMedia Layer
4   Copyright (C) 1997-2018 Sam Lantinga <slouken@libsdl.org>
5
6   This software is provided 'as-is', without any express or implied
7   warranty.  In no event will the authors be held liable for any damages
8   arising from the use of this software.
9
10   Permission is granted to anyone to use this software for any purpose,
11   including commercial applications, and to alter it and redistribute it
12   freely, subject to the following restrictions:
13
14   1. The origin of this software must not be misrepresented; you must not
15      claim that you wrote the original software. If you use this software
16      in a product, an acknowledgment in the product documentation would be
17      appreciated but is not required.
18   2. Altered source versions must be plainly marked as such, and must not be
19      misrepresented as being the original software.
20   3. This notice may not be removed or altered from any source distribution.
21 */
22 #include "../SDL_internal.h"
23
24 /* *INDENT-OFF* */
25
26 #include "SDL_video.h"
27 #include "SDL_blit.h"
28 #include "SDL_blit_auto.h"
29
30 static void SDL_Blit_RGB888_RGB888_Scale(SDL_BlitInfo *info)
31 {
32     int srcy, srcx;
33     int posy, posx;
34     int incy, incx;
35
36     srcy = 0;
37     posy = 0;
38     incy = (info->src_h << 16) / info->dst_h;
39     incx = (info->src_w << 16) / info->dst_w;
40
41     while (info->dst_h--) {
42         Uint32 *src = 0;
43         Uint32 *dst = (Uint32 *)info->dst;
44         int n = info->dst_w;
45         srcx = -1;
46         posx = 0x10000L;
47         while (posy >= 0x10000L) {
48             ++srcy;
49             posy -= 0x10000L;
50         }
51         while (n--) {
52             if (posx >= 0x10000L) {
53                 while (posx >= 0x10000L) {
54                     ++srcx;
55                     posx -= 0x10000L;
56                 }
57                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
58             }
59             *dst = *src;
60             posx += incx;
61             ++dst;
62         }
63         posy += incy;
64         info->dst += info->dst_pitch;
65     }
66 }
67
68 static void SDL_Blit_RGB888_RGB888_Blend(SDL_BlitInfo *info)
69 {
70     const int flags = info->flags;
71     Uint32 srcpixel;
72     Uint32 srcR, srcG, srcB, srcA;
73     Uint32 dstpixel;
74     Uint32 dstR, dstG, dstB;
75
76     while (info->dst_h--) {
77         Uint32 *src = (Uint32 *)info->src;
78         Uint32 *dst = (Uint32 *)info->dst;
79         int n = info->dst_w;
80         while (n--) {
81             srcpixel = *src;
82             srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
83             dstpixel = *dst;
84             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
85             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
86                 /* This goes away if we ever use premultiplied alpha */
87                 if (srcA < 255) {
88                     srcR = (srcR * srcA) / 255;
89                     srcG = (srcG * srcA) / 255;
90                     srcB = (srcB * srcA) / 255;
91                 }
92             }
93             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
94             case SDL_COPY_BLEND:
95                 dstR = srcR + ((255 - srcA) * dstR) / 255;
96                 dstG = srcG + ((255 - srcA) * dstG) / 255;
97                 dstB = srcB + ((255 - srcA) * dstB) / 255;
98                 break;
99             case SDL_COPY_ADD:
100                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
101                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
102                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
103                 break;
104             case SDL_COPY_MOD:
105                 dstR = (srcR * dstR) / 255;
106                 dstG = (srcG * dstG) / 255;
107                 dstB = (srcB * dstB) / 255;
108                 break;
109             }
110             dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
111             *dst = dstpixel;
112             ++src;
113             ++dst;
114         }
115         info->src += info->src_pitch;
116         info->dst += info->dst_pitch;
117     }
118 }
119
120 static void SDL_Blit_RGB888_RGB888_Blend_Scale(SDL_BlitInfo *info)
121 {
122     const int flags = info->flags;
123     Uint32 srcpixel;
124     Uint32 srcR, srcG, srcB, srcA;
125     Uint32 dstpixel;
126     Uint32 dstR, dstG, dstB;
127     int srcy, srcx;
128     int posy, posx;
129     int incy, incx;
130
131     srcy = 0;
132     posy = 0;
133     incy = (info->src_h << 16) / info->dst_h;
134     incx = (info->src_w << 16) / info->dst_w;
135
136     while (info->dst_h--) {
137         Uint32 *src = 0;
138         Uint32 *dst = (Uint32 *)info->dst;
139         int n = info->dst_w;
140         srcx = -1;
141         posx = 0x10000L;
142         while (posy >= 0x10000L) {
143             ++srcy;
144             posy -= 0x10000L;
145         }
146         while (n--) {
147             if (posx >= 0x10000L) {
148                 while (posx >= 0x10000L) {
149                     ++srcx;
150                     posx -= 0x10000L;
151                 }
152                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
153             }
154             srcpixel = *src;
155             srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
156             dstpixel = *dst;
157             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
158             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
159                 /* This goes away if we ever use premultiplied alpha */
160                 if (srcA < 255) {
161                     srcR = (srcR * srcA) / 255;
162                     srcG = (srcG * srcA) / 255;
163                     srcB = (srcB * srcA) / 255;
164                 }
165             }
166             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
167             case SDL_COPY_BLEND:
168                 dstR = srcR + ((255 - srcA) * dstR) / 255;
169                 dstG = srcG + ((255 - srcA) * dstG) / 255;
170                 dstB = srcB + ((255 - srcA) * dstB) / 255;
171                 break;
172             case SDL_COPY_ADD:
173                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
174                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
175                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
176                 break;
177             case SDL_COPY_MOD:
178                 dstR = (srcR * dstR) / 255;
179                 dstG = (srcG * dstG) / 255;
180                 dstB = (srcB * dstB) / 255;
181                 break;
182             }
183             dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
184             *dst = dstpixel;
185             posx += incx;
186             ++dst;
187         }
188         posy += incy;
189         info->dst += info->dst_pitch;
190     }
191 }
192
193 static void SDL_Blit_RGB888_RGB888_Modulate(SDL_BlitInfo *info)
194 {
195     const int flags = info->flags;
196     const Uint32 modulateR = info->r;
197     const Uint32 modulateG = info->g;
198     const Uint32 modulateB = info->b;
199     Uint32 pixel;
200     Uint32 R, G, B;
201
202     while (info->dst_h--) {
203         Uint32 *src = (Uint32 *)info->src;
204         Uint32 *dst = (Uint32 *)info->dst;
205         int n = info->dst_w;
206         while (n--) {
207             pixel = *src;
208             R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
209             if (flags & SDL_COPY_MODULATE_COLOR) {
210                 R = (R * modulateR) / 255;
211                 G = (G * modulateG) / 255;
212                 B = (B * modulateB) / 255;
213             }
214             pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
215             *dst = pixel;
216             ++src;
217             ++dst;
218         }
219         info->src += info->src_pitch;
220         info->dst += info->dst_pitch;
221     }
222 }
223
224 static void SDL_Blit_RGB888_RGB888_Modulate_Scale(SDL_BlitInfo *info)
225 {
226     const int flags = info->flags;
227     const Uint32 modulateR = info->r;
228     const Uint32 modulateG = info->g;
229     const Uint32 modulateB = info->b;
230     Uint32 pixel;
231     Uint32 R, G, B;
232     int srcy, srcx;
233     int posy, posx;
234     int incy, incx;
235
236     srcy = 0;
237     posy = 0;
238     incy = (info->src_h << 16) / info->dst_h;
239     incx = (info->src_w << 16) / info->dst_w;
240
241     while (info->dst_h--) {
242         Uint32 *src = 0;
243         Uint32 *dst = (Uint32 *)info->dst;
244         int n = info->dst_w;
245         srcx = -1;
246         posx = 0x10000L;
247         while (posy >= 0x10000L) {
248             ++srcy;
249             posy -= 0x10000L;
250         }
251         while (n--) {
252             if (posx >= 0x10000L) {
253                 while (posx >= 0x10000L) {
254                     ++srcx;
255                     posx -= 0x10000L;
256                 }
257                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
258             }
259             pixel = *src;
260             R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
261             if (flags & SDL_COPY_MODULATE_COLOR) {
262                 R = (R * modulateR) / 255;
263                 G = (G * modulateG) / 255;
264                 B = (B * modulateB) / 255;
265             }
266             pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
267             *dst = pixel;
268             posx += incx;
269             ++dst;
270         }
271         posy += incy;
272         info->dst += info->dst_pitch;
273     }
274 }
275
276 static void SDL_Blit_RGB888_RGB888_Modulate_Blend(SDL_BlitInfo *info)
277 {
278     const int flags = info->flags;
279     const Uint32 modulateR = info->r;
280     const Uint32 modulateG = info->g;
281     const Uint32 modulateB = info->b;
282     const Uint32 modulateA = info->a;
283     Uint32 srcpixel;
284     Uint32 srcR, srcG, srcB, srcA;
285     Uint32 dstpixel;
286     Uint32 dstR, dstG, dstB;
287
288     while (info->dst_h--) {
289         Uint32 *src = (Uint32 *)info->src;
290         Uint32 *dst = (Uint32 *)info->dst;
291         int n = info->dst_w;
292         while (n--) {
293             srcpixel = *src;
294             srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
295             dstpixel = *dst;
296             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
297             if (flags & SDL_COPY_MODULATE_COLOR) {
298                 srcR = (srcR * modulateR) / 255;
299                 srcG = (srcG * modulateG) / 255;
300                 srcB = (srcB * modulateB) / 255;
301             }
302             if (flags & SDL_COPY_MODULATE_ALPHA) {
303                 srcA = (srcA * modulateA) / 255;
304             }
305             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
306                 /* This goes away if we ever use premultiplied alpha */
307                 if (srcA < 255) {
308                     srcR = (srcR * srcA) / 255;
309                     srcG = (srcG * srcA) / 255;
310                     srcB = (srcB * srcA) / 255;
311                 }
312             }
313             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
314             case SDL_COPY_BLEND:
315                 dstR = srcR + ((255 - srcA) * dstR) / 255;
316                 dstG = srcG + ((255 - srcA) * dstG) / 255;
317                 dstB = srcB + ((255 - srcA) * dstB) / 255;
318                 break;
319             case SDL_COPY_ADD:
320                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
321                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
322                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
323                 break;
324             case SDL_COPY_MOD:
325                 dstR = (srcR * dstR) / 255;
326                 dstG = (srcG * dstG) / 255;
327                 dstB = (srcB * dstB) / 255;
328                 break;
329             }
330             dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
331             *dst = dstpixel;
332             ++src;
333             ++dst;
334         }
335         info->src += info->src_pitch;
336         info->dst += info->dst_pitch;
337     }
338 }
339
340 static void SDL_Blit_RGB888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info)
341 {
342     const int flags = info->flags;
343     const Uint32 modulateR = info->r;
344     const Uint32 modulateG = info->g;
345     const Uint32 modulateB = info->b;
346     const Uint32 modulateA = info->a;
347     Uint32 srcpixel;
348     Uint32 srcR, srcG, srcB, srcA;
349     Uint32 dstpixel;
350     Uint32 dstR, dstG, dstB;
351     int srcy, srcx;
352     int posy, posx;
353     int incy, incx;
354
355     srcy = 0;
356     posy = 0;
357     incy = (info->src_h << 16) / info->dst_h;
358     incx = (info->src_w << 16) / info->dst_w;
359
360     while (info->dst_h--) {
361         Uint32 *src = 0;
362         Uint32 *dst = (Uint32 *)info->dst;
363         int n = info->dst_w;
364         srcx = -1;
365         posx = 0x10000L;
366         while (posy >= 0x10000L) {
367             ++srcy;
368             posy -= 0x10000L;
369         }
370         while (n--) {
371             if (posx >= 0x10000L) {
372                 while (posx >= 0x10000L) {
373                     ++srcx;
374                     posx -= 0x10000L;
375                 }
376                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
377             }
378             srcpixel = *src;
379             srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
380             dstpixel = *dst;
381             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
382             if (flags & SDL_COPY_MODULATE_COLOR) {
383                 srcR = (srcR * modulateR) / 255;
384                 srcG = (srcG * modulateG) / 255;
385                 srcB = (srcB * modulateB) / 255;
386             }
387             if (flags & SDL_COPY_MODULATE_ALPHA) {
388                 srcA = (srcA * modulateA) / 255;
389             }
390             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
391                 /* This goes away if we ever use premultiplied alpha */
392                 if (srcA < 255) {
393                     srcR = (srcR * srcA) / 255;
394                     srcG = (srcG * srcA) / 255;
395                     srcB = (srcB * srcA) / 255;
396                 }
397             }
398             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
399             case SDL_COPY_BLEND:
400                 dstR = srcR + ((255 - srcA) * dstR) / 255;
401                 dstG = srcG + ((255 - srcA) * dstG) / 255;
402                 dstB = srcB + ((255 - srcA) * dstB) / 255;
403                 break;
404             case SDL_COPY_ADD:
405                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
406                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
407                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
408                 break;
409             case SDL_COPY_MOD:
410                 dstR = (srcR * dstR) / 255;
411                 dstG = (srcG * dstG) / 255;
412                 dstB = (srcB * dstB) / 255;
413                 break;
414             }
415             dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
416             *dst = dstpixel;
417             posx += incx;
418             ++dst;
419         }
420         posy += incy;
421         info->dst += info->dst_pitch;
422     }
423 }
424
425 static void SDL_Blit_RGB888_BGR888_Scale(SDL_BlitInfo *info)
426 {
427     Uint32 pixel;
428     Uint32 R, G, B;
429     int srcy, srcx;
430     int posy, posx;
431     int incy, incx;
432
433     srcy = 0;
434     posy = 0;
435     incy = (info->src_h << 16) / info->dst_h;
436     incx = (info->src_w << 16) / info->dst_w;
437
438     while (info->dst_h--) {
439         Uint32 *src = 0;
440         Uint32 *dst = (Uint32 *)info->dst;
441         int n = info->dst_w;
442         srcx = -1;
443         posx = 0x10000L;
444         while (posy >= 0x10000L) {
445             ++srcy;
446             posy -= 0x10000L;
447         }
448         while (n--) {
449             if (posx >= 0x10000L) {
450                 while (posx >= 0x10000L) {
451                     ++srcx;
452                     posx -= 0x10000L;
453                 }
454                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
455             }
456             pixel = *src;
457             R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
458             pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
459             *dst = pixel;
460             posx += incx;
461             ++dst;
462         }
463         posy += incy;
464         info->dst += info->dst_pitch;
465     }
466 }
467
468 static void SDL_Blit_RGB888_BGR888_Blend(SDL_BlitInfo *info)
469 {
470     const int flags = info->flags;
471     Uint32 srcpixel;
472     Uint32 srcR, srcG, srcB, srcA;
473     Uint32 dstpixel;
474     Uint32 dstR, dstG, dstB;
475
476     while (info->dst_h--) {
477         Uint32 *src = (Uint32 *)info->src;
478         Uint32 *dst = (Uint32 *)info->dst;
479         int n = info->dst_w;
480         while (n--) {
481             srcpixel = *src;
482             srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
483             dstpixel = *dst;
484             dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
485             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
486                 /* This goes away if we ever use premultiplied alpha */
487                 if (srcA < 255) {
488                     srcR = (srcR * srcA) / 255;
489                     srcG = (srcG * srcA) / 255;
490                     srcB = (srcB * srcA) / 255;
491                 }
492             }
493             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
494             case SDL_COPY_BLEND:
495                 dstR = srcR + ((255 - srcA) * dstR) / 255;
496                 dstG = srcG + ((255 - srcA) * dstG) / 255;
497                 dstB = srcB + ((255 - srcA) * dstB) / 255;
498                 break;
499             case SDL_COPY_ADD:
500                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
501                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
502                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
503                 break;
504             case SDL_COPY_MOD:
505                 dstR = (srcR * dstR) / 255;
506                 dstG = (srcG * dstG) / 255;
507                 dstB = (srcB * dstB) / 255;
508                 break;
509             }
510             dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
511             *dst = dstpixel;
512             ++src;
513             ++dst;
514         }
515         info->src += info->src_pitch;
516         info->dst += info->dst_pitch;
517     }
518 }
519
520 static void SDL_Blit_RGB888_BGR888_Blend_Scale(SDL_BlitInfo *info)
521 {
522     const int flags = info->flags;
523     Uint32 srcpixel;
524     Uint32 srcR, srcG, srcB, srcA;
525     Uint32 dstpixel;
526     Uint32 dstR, dstG, dstB;
527     int srcy, srcx;
528     int posy, posx;
529     int incy, incx;
530
531     srcy = 0;
532     posy = 0;
533     incy = (info->src_h << 16) / info->dst_h;
534     incx = (info->src_w << 16) / info->dst_w;
535
536     while (info->dst_h--) {
537         Uint32 *src = 0;
538         Uint32 *dst = (Uint32 *)info->dst;
539         int n = info->dst_w;
540         srcx = -1;
541         posx = 0x10000L;
542         while (posy >= 0x10000L) {
543             ++srcy;
544             posy -= 0x10000L;
545         }
546         while (n--) {
547             if (posx >= 0x10000L) {
548                 while (posx >= 0x10000L) {
549                     ++srcx;
550                     posx -= 0x10000L;
551                 }
552                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
553             }
554             srcpixel = *src;
555             srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
556             dstpixel = *dst;
557             dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
558             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
559                 /* This goes away if we ever use premultiplied alpha */
560                 if (srcA < 255) {
561                     srcR = (srcR * srcA) / 255;
562                     srcG = (srcG * srcA) / 255;
563                     srcB = (srcB * srcA) / 255;
564                 }
565             }
566             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
567             case SDL_COPY_BLEND:
568                 dstR = srcR + ((255 - srcA) * dstR) / 255;
569                 dstG = srcG + ((255 - srcA) * dstG) / 255;
570                 dstB = srcB + ((255 - srcA) * dstB) / 255;
571                 break;
572             case SDL_COPY_ADD:
573                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
574                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
575                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
576                 break;
577             case SDL_COPY_MOD:
578                 dstR = (srcR * dstR) / 255;
579                 dstG = (srcG * dstG) / 255;
580                 dstB = (srcB * dstB) / 255;
581                 break;
582             }
583             dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
584             *dst = dstpixel;
585             posx += incx;
586             ++dst;
587         }
588         posy += incy;
589         info->dst += info->dst_pitch;
590     }
591 }
592
593 static void SDL_Blit_RGB888_BGR888_Modulate(SDL_BlitInfo *info)
594 {
595     const int flags = info->flags;
596     const Uint32 modulateR = info->r;
597     const Uint32 modulateG = info->g;
598     const Uint32 modulateB = info->b;
599     Uint32 pixel;
600     Uint32 R, G, B;
601
602     while (info->dst_h--) {
603         Uint32 *src = (Uint32 *)info->src;
604         Uint32 *dst = (Uint32 *)info->dst;
605         int n = info->dst_w;
606         while (n--) {
607             pixel = *src;
608             R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
609             if (flags & SDL_COPY_MODULATE_COLOR) {
610                 R = (R * modulateR) / 255;
611                 G = (G * modulateG) / 255;
612                 B = (B * modulateB) / 255;
613             }
614             pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
615             *dst = pixel;
616             ++src;
617             ++dst;
618         }
619         info->src += info->src_pitch;
620         info->dst += info->dst_pitch;
621     }
622 }
623
624 static void SDL_Blit_RGB888_BGR888_Modulate_Scale(SDL_BlitInfo *info)
625 {
626     const int flags = info->flags;
627     const Uint32 modulateR = info->r;
628     const Uint32 modulateG = info->g;
629     const Uint32 modulateB = info->b;
630     Uint32 pixel;
631     Uint32 R, G, B;
632     int srcy, srcx;
633     int posy, posx;
634     int incy, incx;
635
636     srcy = 0;
637     posy = 0;
638     incy = (info->src_h << 16) / info->dst_h;
639     incx = (info->src_w << 16) / info->dst_w;
640
641     while (info->dst_h--) {
642         Uint32 *src = 0;
643         Uint32 *dst = (Uint32 *)info->dst;
644         int n = info->dst_w;
645         srcx = -1;
646         posx = 0x10000L;
647         while (posy >= 0x10000L) {
648             ++srcy;
649             posy -= 0x10000L;
650         }
651         while (n--) {
652             if (posx >= 0x10000L) {
653                 while (posx >= 0x10000L) {
654                     ++srcx;
655                     posx -= 0x10000L;
656                 }
657                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
658             }
659             pixel = *src;
660             R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
661             if (flags & SDL_COPY_MODULATE_COLOR) {
662                 R = (R * modulateR) / 255;
663                 G = (G * modulateG) / 255;
664                 B = (B * modulateB) / 255;
665             }
666             pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
667             *dst = pixel;
668             posx += incx;
669             ++dst;
670         }
671         posy += incy;
672         info->dst += info->dst_pitch;
673     }
674 }
675
676 static void SDL_Blit_RGB888_BGR888_Modulate_Blend(SDL_BlitInfo *info)
677 {
678     const int flags = info->flags;
679     const Uint32 modulateR = info->r;
680     const Uint32 modulateG = info->g;
681     const Uint32 modulateB = info->b;
682     const Uint32 modulateA = info->a;
683     Uint32 srcpixel;
684     Uint32 srcR, srcG, srcB, srcA;
685     Uint32 dstpixel;
686     Uint32 dstR, dstG, dstB;
687
688     while (info->dst_h--) {
689         Uint32 *src = (Uint32 *)info->src;
690         Uint32 *dst = (Uint32 *)info->dst;
691         int n = info->dst_w;
692         while (n--) {
693             srcpixel = *src;
694             srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
695             dstpixel = *dst;
696             dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
697             if (flags & SDL_COPY_MODULATE_COLOR) {
698                 srcR = (srcR * modulateR) / 255;
699                 srcG = (srcG * modulateG) / 255;
700                 srcB = (srcB * modulateB) / 255;
701             }
702             if (flags & SDL_COPY_MODULATE_ALPHA) {
703                 srcA = (srcA * modulateA) / 255;
704             }
705             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
706                 /* This goes away if we ever use premultiplied alpha */
707                 if (srcA < 255) {
708                     srcR = (srcR * srcA) / 255;
709                     srcG = (srcG * srcA) / 255;
710                     srcB = (srcB * srcA) / 255;
711                 }
712             }
713             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
714             case SDL_COPY_BLEND:
715                 dstR = srcR + ((255 - srcA) * dstR) / 255;
716                 dstG = srcG + ((255 - srcA) * dstG) / 255;
717                 dstB = srcB + ((255 - srcA) * dstB) / 255;
718                 break;
719             case SDL_COPY_ADD:
720                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
721                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
722                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
723                 break;
724             case SDL_COPY_MOD:
725                 dstR = (srcR * dstR) / 255;
726                 dstG = (srcG * dstG) / 255;
727                 dstB = (srcB * dstB) / 255;
728                 break;
729             }
730             dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
731             *dst = dstpixel;
732             ++src;
733             ++dst;
734         }
735         info->src += info->src_pitch;
736         info->dst += info->dst_pitch;
737     }
738 }
739
740 static void SDL_Blit_RGB888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info)
741 {
742     const int flags = info->flags;
743     const Uint32 modulateR = info->r;
744     const Uint32 modulateG = info->g;
745     const Uint32 modulateB = info->b;
746     const Uint32 modulateA = info->a;
747     Uint32 srcpixel;
748     Uint32 srcR, srcG, srcB, srcA;
749     Uint32 dstpixel;
750     Uint32 dstR, dstG, dstB;
751     int srcy, srcx;
752     int posy, posx;
753     int incy, incx;
754
755     srcy = 0;
756     posy = 0;
757     incy = (info->src_h << 16) / info->dst_h;
758     incx = (info->src_w << 16) / info->dst_w;
759
760     while (info->dst_h--) {
761         Uint32 *src = 0;
762         Uint32 *dst = (Uint32 *)info->dst;
763         int n = info->dst_w;
764         srcx = -1;
765         posx = 0x10000L;
766         while (posy >= 0x10000L) {
767             ++srcy;
768             posy -= 0x10000L;
769         }
770         while (n--) {
771             if (posx >= 0x10000L) {
772                 while (posx >= 0x10000L) {
773                     ++srcx;
774                     posx -= 0x10000L;
775                 }
776                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
777             }
778             srcpixel = *src;
779             srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
780             dstpixel = *dst;
781             dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
782             if (flags & SDL_COPY_MODULATE_COLOR) {
783                 srcR = (srcR * modulateR) / 255;
784                 srcG = (srcG * modulateG) / 255;
785                 srcB = (srcB * modulateB) / 255;
786             }
787             if (flags & SDL_COPY_MODULATE_ALPHA) {
788                 srcA = (srcA * modulateA) / 255;
789             }
790             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
791                 /* This goes away if we ever use premultiplied alpha */
792                 if (srcA < 255) {
793                     srcR = (srcR * srcA) / 255;
794                     srcG = (srcG * srcA) / 255;
795                     srcB = (srcB * srcA) / 255;
796                 }
797             }
798             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
799             case SDL_COPY_BLEND:
800                 dstR = srcR + ((255 - srcA) * dstR) / 255;
801                 dstG = srcG + ((255 - srcA) * dstG) / 255;
802                 dstB = srcB + ((255 - srcA) * dstB) / 255;
803                 break;
804             case SDL_COPY_ADD:
805                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
806                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
807                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
808                 break;
809             case SDL_COPY_MOD:
810                 dstR = (srcR * dstR) / 255;
811                 dstG = (srcG * dstG) / 255;
812                 dstB = (srcB * dstB) / 255;
813                 break;
814             }
815             dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
816             *dst = dstpixel;
817             posx += incx;
818             ++dst;
819         }
820         posy += incy;
821         info->dst += info->dst_pitch;
822     }
823 }
824
825 static void SDL_Blit_RGB888_ARGB8888_Scale(SDL_BlitInfo *info)
826 {
827     Uint32 pixel;
828     Uint32 R, G, B, A;
829     int srcy, srcx;
830     int posy, posx;
831     int incy, incx;
832
833     srcy = 0;
834     posy = 0;
835     incy = (info->src_h << 16) / info->dst_h;
836     incx = (info->src_w << 16) / info->dst_w;
837
838     while (info->dst_h--) {
839         Uint32 *src = 0;
840         Uint32 *dst = (Uint32 *)info->dst;
841         int n = info->dst_w;
842         srcx = -1;
843         posx = 0x10000L;
844         while (posy >= 0x10000L) {
845             ++srcy;
846             posy -= 0x10000L;
847         }
848         while (n--) {
849             if (posx >= 0x10000L) {
850                 while (posx >= 0x10000L) {
851                     ++srcx;
852                     posx -= 0x10000L;
853                 }
854                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
855             }
856             pixel = *src;
857             R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF;
858             pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
859             *dst = pixel;
860             posx += incx;
861             ++dst;
862         }
863         posy += incy;
864         info->dst += info->dst_pitch;
865     }
866 }
867
868 static void SDL_Blit_RGB888_ARGB8888_Blend(SDL_BlitInfo *info)
869 {
870     const int flags = info->flags;
871     Uint32 srcpixel;
872     Uint32 srcR, srcG, srcB, srcA;
873     Uint32 dstpixel;
874     Uint32 dstR, dstG, dstB, dstA;
875
876     while (info->dst_h--) {
877         Uint32 *src = (Uint32 *)info->src;
878         Uint32 *dst = (Uint32 *)info->dst;
879         int n = info->dst_w;
880         while (n--) {
881             srcpixel = *src;
882             srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
883             dstpixel = *dst;
884             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
885             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
886                 /* This goes away if we ever use premultiplied alpha */
887                 if (srcA < 255) {
888                     srcR = (srcR * srcA) / 255;
889                     srcG = (srcG * srcA) / 255;
890                     srcB = (srcB * srcA) / 255;
891                 }
892             }
893             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
894             case SDL_COPY_BLEND:
895                 dstR = srcR + ((255 - srcA) * dstR) / 255;
896                 dstG = srcG + ((255 - srcA) * dstG) / 255;
897                 dstB = srcB + ((255 - srcA) * dstB) / 255;
898                 dstA = srcA + ((255 - srcA) * dstA) / 255;
899                 break;
900             case SDL_COPY_ADD:
901                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
902                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
903                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
904                 break;
905             case SDL_COPY_MOD:
906                 dstR = (srcR * dstR) / 255;
907                 dstG = (srcG * dstG) / 255;
908                 dstB = (srcB * dstB) / 255;
909                 break;
910             }
911             dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
912             *dst = dstpixel;
913             ++src;
914             ++dst;
915         }
916         info->src += info->src_pitch;
917         info->dst += info->dst_pitch;
918     }
919 }
920
921 static void SDL_Blit_RGB888_ARGB8888_Blend_Scale(SDL_BlitInfo *info)
922 {
923     const int flags = info->flags;
924     Uint32 srcpixel;
925     Uint32 srcR, srcG, srcB, srcA;
926     Uint32 dstpixel;
927     Uint32 dstR, dstG, dstB, dstA;
928     int srcy, srcx;
929     int posy, posx;
930     int incy, incx;
931
932     srcy = 0;
933     posy = 0;
934     incy = (info->src_h << 16) / info->dst_h;
935     incx = (info->src_w << 16) / info->dst_w;
936
937     while (info->dst_h--) {
938         Uint32 *src = 0;
939         Uint32 *dst = (Uint32 *)info->dst;
940         int n = info->dst_w;
941         srcx = -1;
942         posx = 0x10000L;
943         while (posy >= 0x10000L) {
944             ++srcy;
945             posy -= 0x10000L;
946         }
947         while (n--) {
948             if (posx >= 0x10000L) {
949                 while (posx >= 0x10000L) {
950                     ++srcx;
951                     posx -= 0x10000L;
952                 }
953                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
954             }
955             srcpixel = *src;
956             srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
957             dstpixel = *dst;
958             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
959             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
960                 /* This goes away if we ever use premultiplied alpha */
961                 if (srcA < 255) {
962                     srcR = (srcR * srcA) / 255;
963                     srcG = (srcG * srcA) / 255;
964                     srcB = (srcB * srcA) / 255;
965                 }
966             }
967             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
968             case SDL_COPY_BLEND:
969                 dstR = srcR + ((255 - srcA) * dstR) / 255;
970                 dstG = srcG + ((255 - srcA) * dstG) / 255;
971                 dstB = srcB + ((255 - srcA) * dstB) / 255;
972                 dstA = srcA + ((255 - srcA) * dstA) / 255;
973                 break;
974             case SDL_COPY_ADD:
975                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
976                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
977                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
978                 break;
979             case SDL_COPY_MOD:
980                 dstR = (srcR * dstR) / 255;
981                 dstG = (srcG * dstG) / 255;
982                 dstB = (srcB * dstB) / 255;
983                 break;
984             }
985             dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
986             *dst = dstpixel;
987             posx += incx;
988             ++dst;
989         }
990         posy += incy;
991         info->dst += info->dst_pitch;
992     }
993 }
994
995 static void SDL_Blit_RGB888_ARGB8888_Modulate(SDL_BlitInfo *info)
996 {
997     const int flags = info->flags;
998     const Uint32 modulateR = info->r;
999     const Uint32 modulateG = info->g;
1000     const Uint32 modulateB = info->b;
1001     const Uint32 modulateA = info->a;
1002     Uint32 pixel;
1003     Uint32 R, G, B, A;
1004
1005     while (info->dst_h--) {
1006         Uint32 *src = (Uint32 *)info->src;
1007         Uint32 *dst = (Uint32 *)info->dst;
1008         int n = info->dst_w;
1009         while (n--) {
1010             pixel = *src;
1011             R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF;
1012             if (flags & SDL_COPY_MODULATE_COLOR) {
1013                 R = (R * modulateR) / 255;
1014                 G = (G * modulateG) / 255;
1015                 B = (B * modulateB) / 255;
1016             }
1017             if (flags & SDL_COPY_MODULATE_ALPHA) {
1018                 A = (A * modulateA) / 255;
1019             }
1020             pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
1021             *dst = pixel;
1022             ++src;
1023             ++dst;
1024         }
1025         info->src += info->src_pitch;
1026         info->dst += info->dst_pitch;
1027     }
1028 }
1029
1030 static void SDL_Blit_RGB888_ARGB8888_Modulate_Scale(SDL_BlitInfo *info)
1031 {
1032     const int flags = info->flags;
1033     const Uint32 modulateR = info->r;
1034     const Uint32 modulateG = info->g;
1035     const Uint32 modulateB = info->b;
1036     const Uint32 modulateA = info->a;
1037     Uint32 pixel;
1038     Uint32 R, G, B, A;
1039     int srcy, srcx;
1040     int posy, posx;
1041     int incy, incx;
1042
1043     srcy = 0;
1044     posy = 0;
1045     incy = (info->src_h << 16) / info->dst_h;
1046     incx = (info->src_w << 16) / info->dst_w;
1047
1048     while (info->dst_h--) {
1049         Uint32 *src = 0;
1050         Uint32 *dst = (Uint32 *)info->dst;
1051         int n = info->dst_w;
1052         srcx = -1;
1053         posx = 0x10000L;
1054         while (posy >= 0x10000L) {
1055             ++srcy;
1056             posy -= 0x10000L;
1057         }
1058         while (n--) {
1059             if (posx >= 0x10000L) {
1060                 while (posx >= 0x10000L) {
1061                     ++srcx;
1062                     posx -= 0x10000L;
1063                 }
1064                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
1065             }
1066             pixel = *src;
1067             R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF;
1068             if (flags & SDL_COPY_MODULATE_COLOR) {
1069                 R = (R * modulateR) / 255;
1070                 G = (G * modulateG) / 255;
1071                 B = (B * modulateB) / 255;
1072             }
1073             if (flags & SDL_COPY_MODULATE_ALPHA) {
1074                 A = (A * modulateA) / 255;
1075             }
1076             pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
1077             *dst = pixel;
1078             posx += incx;
1079             ++dst;
1080         }
1081         posy += incy;
1082         info->dst += info->dst_pitch;
1083     }
1084 }
1085
1086 static void SDL_Blit_RGB888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info)
1087 {
1088     const int flags = info->flags;
1089     const Uint32 modulateR = info->r;
1090     const Uint32 modulateG = info->g;
1091     const Uint32 modulateB = info->b;
1092     const Uint32 modulateA = info->a;
1093     Uint32 srcpixel;
1094     Uint32 srcR, srcG, srcB, srcA;
1095     Uint32 dstpixel;
1096     Uint32 dstR, dstG, dstB, dstA;
1097
1098     while (info->dst_h--) {
1099         Uint32 *src = (Uint32 *)info->src;
1100         Uint32 *dst = (Uint32 *)info->dst;
1101         int n = info->dst_w;
1102         while (n--) {
1103             srcpixel = *src;
1104             srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
1105             dstpixel = *dst;
1106             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
1107             if (flags & SDL_COPY_MODULATE_COLOR) {
1108                 srcR = (srcR * modulateR) / 255;
1109                 srcG = (srcG * modulateG) / 255;
1110                 srcB = (srcB * modulateB) / 255;
1111             }
1112             if (flags & SDL_COPY_MODULATE_ALPHA) {
1113                 srcA = (srcA * modulateA) / 255;
1114             }
1115             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
1116                 /* This goes away if we ever use premultiplied alpha */
1117                 if (srcA < 255) {
1118                     srcR = (srcR * srcA) / 255;
1119                     srcG = (srcG * srcA) / 255;
1120                     srcB = (srcB * srcA) / 255;
1121                 }
1122             }
1123             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
1124             case SDL_COPY_BLEND:
1125                 dstR = srcR + ((255 - srcA) * dstR) / 255;
1126                 dstG = srcG + ((255 - srcA) * dstG) / 255;
1127                 dstB = srcB + ((255 - srcA) * dstB) / 255;
1128                 dstA = srcA + ((255 - srcA) * dstA) / 255;
1129                 break;
1130             case SDL_COPY_ADD:
1131                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
1132                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
1133                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
1134                 break;
1135             case SDL_COPY_MOD:
1136                 dstR = (srcR * dstR) / 255;
1137                 dstG = (srcG * dstG) / 255;
1138                 dstB = (srcB * dstB) / 255;
1139                 break;
1140             }
1141             dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
1142             *dst = dstpixel;
1143             ++src;
1144             ++dst;
1145         }
1146         info->src += info->src_pitch;
1147         info->dst += info->dst_pitch;
1148     }
1149 }
1150
1151 static void SDL_Blit_RGB888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info)
1152 {
1153     const int flags = info->flags;
1154     const Uint32 modulateR = info->r;
1155     const Uint32 modulateG = info->g;
1156     const Uint32 modulateB = info->b;
1157     const Uint32 modulateA = info->a;
1158     Uint32 srcpixel;
1159     Uint32 srcR, srcG, srcB, srcA;
1160     Uint32 dstpixel;
1161     Uint32 dstR, dstG, dstB, dstA;
1162     int srcy, srcx;
1163     int posy, posx;
1164     int incy, incx;
1165
1166     srcy = 0;
1167     posy = 0;
1168     incy = (info->src_h << 16) / info->dst_h;
1169     incx = (info->src_w << 16) / info->dst_w;
1170
1171     while (info->dst_h--) {
1172         Uint32 *src = 0;
1173         Uint32 *dst = (Uint32 *)info->dst;
1174         int n = info->dst_w;
1175         srcx = -1;
1176         posx = 0x10000L;
1177         while (posy >= 0x10000L) {
1178             ++srcy;
1179             posy -= 0x10000L;
1180         }
1181         while (n--) {
1182             if (posx >= 0x10000L) {
1183                 while (posx >= 0x10000L) {
1184                     ++srcx;
1185                     posx -= 0x10000L;
1186                 }
1187                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
1188             }
1189             srcpixel = *src;
1190             srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
1191             dstpixel = *dst;
1192             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
1193             if (flags & SDL_COPY_MODULATE_COLOR) {
1194                 srcR = (srcR * modulateR) / 255;
1195                 srcG = (srcG * modulateG) / 255;
1196                 srcB = (srcB * modulateB) / 255;
1197             }
1198             if (flags & SDL_COPY_MODULATE_ALPHA) {
1199                 srcA = (srcA * modulateA) / 255;
1200             }
1201             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
1202                 /* This goes away if we ever use premultiplied alpha */
1203                 if (srcA < 255) {
1204                     srcR = (srcR * srcA) / 255;
1205                     srcG = (srcG * srcA) / 255;
1206                     srcB = (srcB * srcA) / 255;
1207                 }
1208             }
1209             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
1210             case SDL_COPY_BLEND:
1211                 dstR = srcR + ((255 - srcA) * dstR) / 255;
1212                 dstG = srcG + ((255 - srcA) * dstG) / 255;
1213                 dstB = srcB + ((255 - srcA) * dstB) / 255;
1214                 dstA = srcA + ((255 - srcA) * dstA) / 255;
1215                 break;
1216             case SDL_COPY_ADD:
1217                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
1218                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
1219                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
1220                 break;
1221             case SDL_COPY_MOD:
1222                 dstR = (srcR * dstR) / 255;
1223                 dstG = (srcG * dstG) / 255;
1224                 dstB = (srcB * dstB) / 255;
1225                 break;
1226             }
1227             dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
1228             *dst = dstpixel;
1229             posx += incx;
1230             ++dst;
1231         }
1232         posy += incy;
1233         info->dst += info->dst_pitch;
1234     }
1235 }
1236
1237 static void SDL_Blit_BGR888_RGB888_Scale(SDL_BlitInfo *info)
1238 {
1239     Uint32 pixel;
1240     Uint32 R, G, B;
1241     int srcy, srcx;
1242     int posy, posx;
1243     int incy, incx;
1244
1245     srcy = 0;
1246     posy = 0;
1247     incy = (info->src_h << 16) / info->dst_h;
1248     incx = (info->src_w << 16) / info->dst_w;
1249
1250     while (info->dst_h--) {
1251         Uint32 *src = 0;
1252         Uint32 *dst = (Uint32 *)info->dst;
1253         int n = info->dst_w;
1254         srcx = -1;
1255         posx = 0x10000L;
1256         while (posy >= 0x10000L) {
1257             ++srcy;
1258             posy -= 0x10000L;
1259         }
1260         while (n--) {
1261             if (posx >= 0x10000L) {
1262                 while (posx >= 0x10000L) {
1263                     ++srcx;
1264                     posx -= 0x10000L;
1265                 }
1266                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
1267             }
1268             pixel = *src;
1269             B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
1270             pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
1271             *dst = pixel;
1272             posx += incx;
1273             ++dst;
1274         }
1275         posy += incy;
1276         info->dst += info->dst_pitch;
1277     }
1278 }
1279
1280 static void SDL_Blit_BGR888_RGB888_Blend(SDL_BlitInfo *info)
1281 {
1282     const int flags = info->flags;
1283     Uint32 srcpixel;
1284     Uint32 srcR, srcG, srcB, srcA;
1285     Uint32 dstpixel;
1286     Uint32 dstR, dstG, dstB;
1287
1288     while (info->dst_h--) {
1289         Uint32 *src = (Uint32 *)info->src;
1290         Uint32 *dst = (Uint32 *)info->dst;
1291         int n = info->dst_w;
1292         while (n--) {
1293             srcpixel = *src;
1294             srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
1295             dstpixel = *dst;
1296             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
1297             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
1298                 /* This goes away if we ever use premultiplied alpha */
1299                 if (srcA < 255) {
1300                     srcR = (srcR * srcA) / 255;
1301                     srcG = (srcG * srcA) / 255;
1302                     srcB = (srcB * srcA) / 255;
1303                 }
1304             }
1305             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
1306             case SDL_COPY_BLEND:
1307                 dstR = srcR + ((255 - srcA) * dstR) / 255;
1308                 dstG = srcG + ((255 - srcA) * dstG) / 255;
1309                 dstB = srcB + ((255 - srcA) * dstB) / 255;
1310                 break;
1311             case SDL_COPY_ADD:
1312                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
1313                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
1314                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
1315                 break;
1316             case SDL_COPY_MOD:
1317                 dstR = (srcR * dstR) / 255;
1318                 dstG = (srcG * dstG) / 255;
1319                 dstB = (srcB * dstB) / 255;
1320                 break;
1321             }
1322             dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
1323             *dst = dstpixel;
1324             ++src;
1325             ++dst;
1326         }
1327         info->src += info->src_pitch;
1328         info->dst += info->dst_pitch;
1329     }
1330 }
1331
1332 static void SDL_Blit_BGR888_RGB888_Blend_Scale(SDL_BlitInfo *info)
1333 {
1334     const int flags = info->flags;
1335     Uint32 srcpixel;
1336     Uint32 srcR, srcG, srcB, srcA;
1337     Uint32 dstpixel;
1338     Uint32 dstR, dstG, dstB;
1339     int srcy, srcx;
1340     int posy, posx;
1341     int incy, incx;
1342
1343     srcy = 0;
1344     posy = 0;
1345     incy = (info->src_h << 16) / info->dst_h;
1346     incx = (info->src_w << 16) / info->dst_w;
1347
1348     while (info->dst_h--) {
1349         Uint32 *src = 0;
1350         Uint32 *dst = (Uint32 *)info->dst;
1351         int n = info->dst_w;
1352         srcx = -1;
1353         posx = 0x10000L;
1354         while (posy >= 0x10000L) {
1355             ++srcy;
1356             posy -= 0x10000L;
1357         }
1358         while (n--) {
1359             if (posx >= 0x10000L) {
1360                 while (posx >= 0x10000L) {
1361                     ++srcx;
1362                     posx -= 0x10000L;
1363                 }
1364                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
1365             }
1366             srcpixel = *src;
1367             srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
1368             dstpixel = *dst;
1369             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
1370             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
1371                 /* This goes away if we ever use premultiplied alpha */
1372                 if (srcA < 255) {
1373                     srcR = (srcR * srcA) / 255;
1374                     srcG = (srcG * srcA) / 255;
1375                     srcB = (srcB * srcA) / 255;
1376                 }
1377             }
1378             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
1379             case SDL_COPY_BLEND:
1380                 dstR = srcR + ((255 - srcA) * dstR) / 255;
1381                 dstG = srcG + ((255 - srcA) * dstG) / 255;
1382                 dstB = srcB + ((255 - srcA) * dstB) / 255;
1383                 break;
1384             case SDL_COPY_ADD:
1385                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
1386                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
1387                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
1388                 break;
1389             case SDL_COPY_MOD:
1390                 dstR = (srcR * dstR) / 255;
1391                 dstG = (srcG * dstG) / 255;
1392                 dstB = (srcB * dstB) / 255;
1393                 break;
1394             }
1395             dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
1396             *dst = dstpixel;
1397             posx += incx;
1398             ++dst;
1399         }
1400         posy += incy;
1401         info->dst += info->dst_pitch;
1402     }
1403 }
1404
1405 static void SDL_Blit_BGR888_RGB888_Modulate(SDL_BlitInfo *info)
1406 {
1407     const int flags = info->flags;
1408     const Uint32 modulateR = info->r;
1409     const Uint32 modulateG = info->g;
1410     const Uint32 modulateB = info->b;
1411     Uint32 pixel;
1412     Uint32 R, G, B;
1413
1414     while (info->dst_h--) {
1415         Uint32 *src = (Uint32 *)info->src;
1416         Uint32 *dst = (Uint32 *)info->dst;
1417         int n = info->dst_w;
1418         while (n--) {
1419             pixel = *src;
1420             B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
1421             if (flags & SDL_COPY_MODULATE_COLOR) {
1422                 R = (R * modulateR) / 255;
1423                 G = (G * modulateG) / 255;
1424                 B = (B * modulateB) / 255;
1425             }
1426             pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
1427             *dst = pixel;
1428             ++src;
1429             ++dst;
1430         }
1431         info->src += info->src_pitch;
1432         info->dst += info->dst_pitch;
1433     }
1434 }
1435
1436 static void SDL_Blit_BGR888_RGB888_Modulate_Scale(SDL_BlitInfo *info)
1437 {
1438     const int flags = info->flags;
1439     const Uint32 modulateR = info->r;
1440     const Uint32 modulateG = info->g;
1441     const Uint32 modulateB = info->b;
1442     Uint32 pixel;
1443     Uint32 R, G, B;
1444     int srcy, srcx;
1445     int posy, posx;
1446     int incy, incx;
1447
1448     srcy = 0;
1449     posy = 0;
1450     incy = (info->src_h << 16) / info->dst_h;
1451     incx = (info->src_w << 16) / info->dst_w;
1452
1453     while (info->dst_h--) {
1454         Uint32 *src = 0;
1455         Uint32 *dst = (Uint32 *)info->dst;
1456         int n = info->dst_w;
1457         srcx = -1;
1458         posx = 0x10000L;
1459         while (posy >= 0x10000L) {
1460             ++srcy;
1461             posy -= 0x10000L;
1462         }
1463         while (n--) {
1464             if (posx >= 0x10000L) {
1465                 while (posx >= 0x10000L) {
1466                     ++srcx;
1467                     posx -= 0x10000L;
1468                 }
1469                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
1470             }
1471             pixel = *src;
1472             B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
1473             if (flags & SDL_COPY_MODULATE_COLOR) {
1474                 R = (R * modulateR) / 255;
1475                 G = (G * modulateG) / 255;
1476                 B = (B * modulateB) / 255;
1477             }
1478             pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
1479             *dst = pixel;
1480             posx += incx;
1481             ++dst;
1482         }
1483         posy += incy;
1484         info->dst += info->dst_pitch;
1485     }
1486 }
1487
1488 static void SDL_Blit_BGR888_RGB888_Modulate_Blend(SDL_BlitInfo *info)
1489 {
1490     const int flags = info->flags;
1491     const Uint32 modulateR = info->r;
1492     const Uint32 modulateG = info->g;
1493     const Uint32 modulateB = info->b;
1494     const Uint32 modulateA = info->a;
1495     Uint32 srcpixel;
1496     Uint32 srcR, srcG, srcB, srcA;
1497     Uint32 dstpixel;
1498     Uint32 dstR, dstG, dstB;
1499
1500     while (info->dst_h--) {
1501         Uint32 *src = (Uint32 *)info->src;
1502         Uint32 *dst = (Uint32 *)info->dst;
1503         int n = info->dst_w;
1504         while (n--) {
1505             srcpixel = *src;
1506             srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
1507             dstpixel = *dst;
1508             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
1509             if (flags & SDL_COPY_MODULATE_COLOR) {
1510                 srcR = (srcR * modulateR) / 255;
1511                 srcG = (srcG * modulateG) / 255;
1512                 srcB = (srcB * modulateB) / 255;
1513             }
1514             if (flags & SDL_COPY_MODULATE_ALPHA) {
1515                 srcA = (srcA * modulateA) / 255;
1516             }
1517             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
1518                 /* This goes away if we ever use premultiplied alpha */
1519                 if (srcA < 255) {
1520                     srcR = (srcR * srcA) / 255;
1521                     srcG = (srcG * srcA) / 255;
1522                     srcB = (srcB * srcA) / 255;
1523                 }
1524             }
1525             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
1526             case SDL_COPY_BLEND:
1527                 dstR = srcR + ((255 - srcA) * dstR) / 255;
1528                 dstG = srcG + ((255 - srcA) * dstG) / 255;
1529                 dstB = srcB + ((255 - srcA) * dstB) / 255;
1530                 break;
1531             case SDL_COPY_ADD:
1532                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
1533                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
1534                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
1535                 break;
1536             case SDL_COPY_MOD:
1537                 dstR = (srcR * dstR) / 255;
1538                 dstG = (srcG * dstG) / 255;
1539                 dstB = (srcB * dstB) / 255;
1540                 break;
1541             }
1542             dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
1543             *dst = dstpixel;
1544             ++src;
1545             ++dst;
1546         }
1547         info->src += info->src_pitch;
1548         info->dst += info->dst_pitch;
1549     }
1550 }
1551
1552 static void SDL_Blit_BGR888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info)
1553 {
1554     const int flags = info->flags;
1555     const Uint32 modulateR = info->r;
1556     const Uint32 modulateG = info->g;
1557     const Uint32 modulateB = info->b;
1558     const Uint32 modulateA = info->a;
1559     Uint32 srcpixel;
1560     Uint32 srcR, srcG, srcB, srcA;
1561     Uint32 dstpixel;
1562     Uint32 dstR, dstG, dstB;
1563     int srcy, srcx;
1564     int posy, posx;
1565     int incy, incx;
1566
1567     srcy = 0;
1568     posy = 0;
1569     incy = (info->src_h << 16) / info->dst_h;
1570     incx = (info->src_w << 16) / info->dst_w;
1571
1572     while (info->dst_h--) {
1573         Uint32 *src = 0;
1574         Uint32 *dst = (Uint32 *)info->dst;
1575         int n = info->dst_w;
1576         srcx = -1;
1577         posx = 0x10000L;
1578         while (posy >= 0x10000L) {
1579             ++srcy;
1580             posy -= 0x10000L;
1581         }
1582         while (n--) {
1583             if (posx >= 0x10000L) {
1584                 while (posx >= 0x10000L) {
1585                     ++srcx;
1586                     posx -= 0x10000L;
1587                 }
1588                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
1589             }
1590             srcpixel = *src;
1591             srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
1592             dstpixel = *dst;
1593             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
1594             if (flags & SDL_COPY_MODULATE_COLOR) {
1595                 srcR = (srcR * modulateR) / 255;
1596                 srcG = (srcG * modulateG) / 255;
1597                 srcB = (srcB * modulateB) / 255;
1598             }
1599             if (flags & SDL_COPY_MODULATE_ALPHA) {
1600                 srcA = (srcA * modulateA) / 255;
1601             }
1602             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
1603                 /* This goes away if we ever use premultiplied alpha */
1604                 if (srcA < 255) {
1605                     srcR = (srcR * srcA) / 255;
1606                     srcG = (srcG * srcA) / 255;
1607                     srcB = (srcB * srcA) / 255;
1608                 }
1609             }
1610             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
1611             case SDL_COPY_BLEND:
1612                 dstR = srcR + ((255 - srcA) * dstR) / 255;
1613                 dstG = srcG + ((255 - srcA) * dstG) / 255;
1614                 dstB = srcB + ((255 - srcA) * dstB) / 255;
1615                 break;
1616             case SDL_COPY_ADD:
1617                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
1618                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
1619                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
1620                 break;
1621             case SDL_COPY_MOD:
1622                 dstR = (srcR * dstR) / 255;
1623                 dstG = (srcG * dstG) / 255;
1624                 dstB = (srcB * dstB) / 255;
1625                 break;
1626             }
1627             dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
1628             *dst = dstpixel;
1629             posx += incx;
1630             ++dst;
1631         }
1632         posy += incy;
1633         info->dst += info->dst_pitch;
1634     }
1635 }
1636
1637 static void SDL_Blit_BGR888_BGR888_Scale(SDL_BlitInfo *info)
1638 {
1639     int srcy, srcx;
1640     int posy, posx;
1641     int incy, incx;
1642
1643     srcy = 0;
1644     posy = 0;
1645     incy = (info->src_h << 16) / info->dst_h;
1646     incx = (info->src_w << 16) / info->dst_w;
1647
1648     while (info->dst_h--) {
1649         Uint32 *src = 0;
1650         Uint32 *dst = (Uint32 *)info->dst;
1651         int n = info->dst_w;
1652         srcx = -1;
1653         posx = 0x10000L;
1654         while (posy >= 0x10000L) {
1655             ++srcy;
1656             posy -= 0x10000L;
1657         }
1658         while (n--) {
1659             if (posx >= 0x10000L) {
1660                 while (posx >= 0x10000L) {
1661                     ++srcx;
1662                     posx -= 0x10000L;
1663                 }
1664                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
1665             }
1666             *dst = *src;
1667             posx += incx;
1668             ++dst;
1669         }
1670         posy += incy;
1671         info->dst += info->dst_pitch;
1672     }
1673 }
1674
1675 static void SDL_Blit_BGR888_BGR888_Blend(SDL_BlitInfo *info)
1676 {
1677     const int flags = info->flags;
1678     Uint32 srcpixel;
1679     Uint32 srcR, srcG, srcB, srcA;
1680     Uint32 dstpixel;
1681     Uint32 dstR, dstG, dstB;
1682
1683     while (info->dst_h--) {
1684         Uint32 *src = (Uint32 *)info->src;
1685         Uint32 *dst = (Uint32 *)info->dst;
1686         int n = info->dst_w;
1687         while (n--) {
1688             srcpixel = *src;
1689             srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
1690             dstpixel = *dst;
1691             dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
1692             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
1693                 /* This goes away if we ever use premultiplied alpha */
1694                 if (srcA < 255) {
1695                     srcR = (srcR * srcA) / 255;
1696                     srcG = (srcG * srcA) / 255;
1697                     srcB = (srcB * srcA) / 255;
1698                 }
1699             }
1700             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
1701             case SDL_COPY_BLEND:
1702                 dstR = srcR + ((255 - srcA) * dstR) / 255;
1703                 dstG = srcG + ((255 - srcA) * dstG) / 255;
1704                 dstB = srcB + ((255 - srcA) * dstB) / 255;
1705                 break;
1706             case SDL_COPY_ADD:
1707                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
1708                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
1709                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
1710                 break;
1711             case SDL_COPY_MOD:
1712                 dstR = (srcR * dstR) / 255;
1713                 dstG = (srcG * dstG) / 255;
1714                 dstB = (srcB * dstB) / 255;
1715                 break;
1716             }
1717             dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
1718             *dst = dstpixel;
1719             ++src;
1720             ++dst;
1721         }
1722         info->src += info->src_pitch;
1723         info->dst += info->dst_pitch;
1724     }
1725 }
1726
1727 static void SDL_Blit_BGR888_BGR888_Blend_Scale(SDL_BlitInfo *info)
1728 {
1729     const int flags = info->flags;
1730     Uint32 srcpixel;
1731     Uint32 srcR, srcG, srcB, srcA;
1732     Uint32 dstpixel;
1733     Uint32 dstR, dstG, dstB;
1734     int srcy, srcx;
1735     int posy, posx;
1736     int incy, incx;
1737
1738     srcy = 0;
1739     posy = 0;
1740     incy = (info->src_h << 16) / info->dst_h;
1741     incx = (info->src_w << 16) / info->dst_w;
1742
1743     while (info->dst_h--) {
1744         Uint32 *src = 0;
1745         Uint32 *dst = (Uint32 *)info->dst;
1746         int n = info->dst_w;
1747         srcx = -1;
1748         posx = 0x10000L;
1749         while (posy >= 0x10000L) {
1750             ++srcy;
1751             posy -= 0x10000L;
1752         }
1753         while (n--) {
1754             if (posx >= 0x10000L) {
1755                 while (posx >= 0x10000L) {
1756                     ++srcx;
1757                     posx -= 0x10000L;
1758                 }
1759                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
1760             }
1761             srcpixel = *src;
1762             srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
1763             dstpixel = *dst;
1764             dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
1765             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
1766                 /* This goes away if we ever use premultiplied alpha */
1767                 if (srcA < 255) {
1768                     srcR = (srcR * srcA) / 255;
1769                     srcG = (srcG * srcA) / 255;
1770                     srcB = (srcB * srcA) / 255;
1771                 }
1772             }
1773             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
1774             case SDL_COPY_BLEND:
1775                 dstR = srcR + ((255 - srcA) * dstR) / 255;
1776                 dstG = srcG + ((255 - srcA) * dstG) / 255;
1777                 dstB = srcB + ((255 - srcA) * dstB) / 255;
1778                 break;
1779             case SDL_COPY_ADD:
1780                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
1781                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
1782                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
1783                 break;
1784             case SDL_COPY_MOD:
1785                 dstR = (srcR * dstR) / 255;
1786                 dstG = (srcG * dstG) / 255;
1787                 dstB = (srcB * dstB) / 255;
1788                 break;
1789             }
1790             dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
1791             *dst = dstpixel;
1792             posx += incx;
1793             ++dst;
1794         }
1795         posy += incy;
1796         info->dst += info->dst_pitch;
1797     }
1798 }
1799
1800 static void SDL_Blit_BGR888_BGR888_Modulate(SDL_BlitInfo *info)
1801 {
1802     const int flags = info->flags;
1803     const Uint32 modulateR = info->r;
1804     const Uint32 modulateG = info->g;
1805     const Uint32 modulateB = info->b;
1806     Uint32 pixel;
1807     Uint32 R, G, B;
1808
1809     while (info->dst_h--) {
1810         Uint32 *src = (Uint32 *)info->src;
1811         Uint32 *dst = (Uint32 *)info->dst;
1812         int n = info->dst_w;
1813         while (n--) {
1814             pixel = *src;
1815             B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
1816             if (flags & SDL_COPY_MODULATE_COLOR) {
1817                 R = (R * modulateR) / 255;
1818                 G = (G * modulateG) / 255;
1819                 B = (B * modulateB) / 255;
1820             }
1821             pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
1822             *dst = pixel;
1823             ++src;
1824             ++dst;
1825         }
1826         info->src += info->src_pitch;
1827         info->dst += info->dst_pitch;
1828     }
1829 }
1830
1831 static void SDL_Blit_BGR888_BGR888_Modulate_Scale(SDL_BlitInfo *info)
1832 {
1833     const int flags = info->flags;
1834     const Uint32 modulateR = info->r;
1835     const Uint32 modulateG = info->g;
1836     const Uint32 modulateB = info->b;
1837     Uint32 pixel;
1838     Uint32 R, G, B;
1839     int srcy, srcx;
1840     int posy, posx;
1841     int incy, incx;
1842
1843     srcy = 0;
1844     posy = 0;
1845     incy = (info->src_h << 16) / info->dst_h;
1846     incx = (info->src_w << 16) / info->dst_w;
1847
1848     while (info->dst_h--) {
1849         Uint32 *src = 0;
1850         Uint32 *dst = (Uint32 *)info->dst;
1851         int n = info->dst_w;
1852         srcx = -1;
1853         posx = 0x10000L;
1854         while (posy >= 0x10000L) {
1855             ++srcy;
1856             posy -= 0x10000L;
1857         }
1858         while (n--) {
1859             if (posx >= 0x10000L) {
1860                 while (posx >= 0x10000L) {
1861                     ++srcx;
1862                     posx -= 0x10000L;
1863                 }
1864                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
1865             }
1866             pixel = *src;
1867             B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
1868             if (flags & SDL_COPY_MODULATE_COLOR) {
1869                 R = (R * modulateR) / 255;
1870                 G = (G * modulateG) / 255;
1871                 B = (B * modulateB) / 255;
1872             }
1873             pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
1874             *dst = pixel;
1875             posx += incx;
1876             ++dst;
1877         }
1878         posy += incy;
1879         info->dst += info->dst_pitch;
1880     }
1881 }
1882
1883 static void SDL_Blit_BGR888_BGR888_Modulate_Blend(SDL_BlitInfo *info)
1884 {
1885     const int flags = info->flags;
1886     const Uint32 modulateR = info->r;
1887     const Uint32 modulateG = info->g;
1888     const Uint32 modulateB = info->b;
1889     const Uint32 modulateA = info->a;
1890     Uint32 srcpixel;
1891     Uint32 srcR, srcG, srcB, srcA;
1892     Uint32 dstpixel;
1893     Uint32 dstR, dstG, dstB;
1894
1895     while (info->dst_h--) {
1896         Uint32 *src = (Uint32 *)info->src;
1897         Uint32 *dst = (Uint32 *)info->dst;
1898         int n = info->dst_w;
1899         while (n--) {
1900             srcpixel = *src;
1901             srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
1902             dstpixel = *dst;
1903             dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
1904             if (flags & SDL_COPY_MODULATE_COLOR) {
1905                 srcR = (srcR * modulateR) / 255;
1906                 srcG = (srcG * modulateG) / 255;
1907                 srcB = (srcB * modulateB) / 255;
1908             }
1909             if (flags & SDL_COPY_MODULATE_ALPHA) {
1910                 srcA = (srcA * modulateA) / 255;
1911             }
1912             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
1913                 /* This goes away if we ever use premultiplied alpha */
1914                 if (srcA < 255) {
1915                     srcR = (srcR * srcA) / 255;
1916                     srcG = (srcG * srcA) / 255;
1917                     srcB = (srcB * srcA) / 255;
1918                 }
1919             }
1920             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
1921             case SDL_COPY_BLEND:
1922                 dstR = srcR + ((255 - srcA) * dstR) / 255;
1923                 dstG = srcG + ((255 - srcA) * dstG) / 255;
1924                 dstB = srcB + ((255 - srcA) * dstB) / 255;
1925                 break;
1926             case SDL_COPY_ADD:
1927                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
1928                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
1929                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
1930                 break;
1931             case SDL_COPY_MOD:
1932                 dstR = (srcR * dstR) / 255;
1933                 dstG = (srcG * dstG) / 255;
1934                 dstB = (srcB * dstB) / 255;
1935                 break;
1936             }
1937             dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
1938             *dst = dstpixel;
1939             ++src;
1940             ++dst;
1941         }
1942         info->src += info->src_pitch;
1943         info->dst += info->dst_pitch;
1944     }
1945 }
1946
1947 static void SDL_Blit_BGR888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info)
1948 {
1949     const int flags = info->flags;
1950     const Uint32 modulateR = info->r;
1951     const Uint32 modulateG = info->g;
1952     const Uint32 modulateB = info->b;
1953     const Uint32 modulateA = info->a;
1954     Uint32 srcpixel;
1955     Uint32 srcR, srcG, srcB, srcA;
1956     Uint32 dstpixel;
1957     Uint32 dstR, dstG, dstB;
1958     int srcy, srcx;
1959     int posy, posx;
1960     int incy, incx;
1961
1962     srcy = 0;
1963     posy = 0;
1964     incy = (info->src_h << 16) / info->dst_h;
1965     incx = (info->src_w << 16) / info->dst_w;
1966
1967     while (info->dst_h--) {
1968         Uint32 *src = 0;
1969         Uint32 *dst = (Uint32 *)info->dst;
1970         int n = info->dst_w;
1971         srcx = -1;
1972         posx = 0x10000L;
1973         while (posy >= 0x10000L) {
1974             ++srcy;
1975             posy -= 0x10000L;
1976         }
1977         while (n--) {
1978             if (posx >= 0x10000L) {
1979                 while (posx >= 0x10000L) {
1980                     ++srcx;
1981                     posx -= 0x10000L;
1982                 }
1983                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
1984             }
1985             srcpixel = *src;
1986             srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
1987             dstpixel = *dst;
1988             dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
1989             if (flags & SDL_COPY_MODULATE_COLOR) {
1990                 srcR = (srcR * modulateR) / 255;
1991                 srcG = (srcG * modulateG) / 255;
1992                 srcB = (srcB * modulateB) / 255;
1993             }
1994             if (flags & SDL_COPY_MODULATE_ALPHA) {
1995                 srcA = (srcA * modulateA) / 255;
1996             }
1997             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
1998                 /* This goes away if we ever use premultiplied alpha */
1999                 if (srcA < 255) {
2000                     srcR = (srcR * srcA) / 255;
2001                     srcG = (srcG * srcA) / 255;
2002                     srcB = (srcB * srcA) / 255;
2003                 }
2004             }
2005             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
2006             case SDL_COPY_BLEND:
2007                 dstR = srcR + ((255 - srcA) * dstR) / 255;
2008                 dstG = srcG + ((255 - srcA) * dstG) / 255;
2009                 dstB = srcB + ((255 - srcA) * dstB) / 255;
2010                 break;
2011             case SDL_COPY_ADD:
2012                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
2013                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
2014                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
2015                 break;
2016             case SDL_COPY_MOD:
2017                 dstR = (srcR * dstR) / 255;
2018                 dstG = (srcG * dstG) / 255;
2019                 dstB = (srcB * dstB) / 255;
2020                 break;
2021             }
2022             dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
2023             *dst = dstpixel;
2024             posx += incx;
2025             ++dst;
2026         }
2027         posy += incy;
2028         info->dst += info->dst_pitch;
2029     }
2030 }
2031
2032 static void SDL_Blit_BGR888_ARGB8888_Scale(SDL_BlitInfo *info)
2033 {
2034     Uint32 pixel;
2035     Uint32 R, G, B, A;
2036     int srcy, srcx;
2037     int posy, posx;
2038     int incy, incx;
2039
2040     srcy = 0;
2041     posy = 0;
2042     incy = (info->src_h << 16) / info->dst_h;
2043     incx = (info->src_w << 16) / info->dst_w;
2044
2045     while (info->dst_h--) {
2046         Uint32 *src = 0;
2047         Uint32 *dst = (Uint32 *)info->dst;
2048         int n = info->dst_w;
2049         srcx = -1;
2050         posx = 0x10000L;
2051         while (posy >= 0x10000L) {
2052             ++srcy;
2053             posy -= 0x10000L;
2054         }
2055         while (n--) {
2056             if (posx >= 0x10000L) {
2057                 while (posx >= 0x10000L) {
2058                     ++srcx;
2059                     posx -= 0x10000L;
2060                 }
2061                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
2062             }
2063             pixel = *src;
2064             B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF;
2065             pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
2066             *dst = pixel;
2067             posx += incx;
2068             ++dst;
2069         }
2070         posy += incy;
2071         info->dst += info->dst_pitch;
2072     }
2073 }
2074
2075 static void SDL_Blit_BGR888_ARGB8888_Blend(SDL_BlitInfo *info)
2076 {
2077     const int flags = info->flags;
2078     Uint32 srcpixel;
2079     Uint32 srcR, srcG, srcB, srcA;
2080     Uint32 dstpixel;
2081     Uint32 dstR, dstG, dstB, dstA;
2082
2083     while (info->dst_h--) {
2084         Uint32 *src = (Uint32 *)info->src;
2085         Uint32 *dst = (Uint32 *)info->dst;
2086         int n = info->dst_w;
2087         while (n--) {
2088             srcpixel = *src;
2089             srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
2090             dstpixel = *dst;
2091             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
2092             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
2093                 /* This goes away if we ever use premultiplied alpha */
2094                 if (srcA < 255) {
2095                     srcR = (srcR * srcA) / 255;
2096                     srcG = (srcG * srcA) / 255;
2097                     srcB = (srcB * srcA) / 255;
2098                 }
2099             }
2100             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
2101             case SDL_COPY_BLEND:
2102                 dstR = srcR + ((255 - srcA) * dstR) / 255;
2103                 dstG = srcG + ((255 - srcA) * dstG) / 255;
2104                 dstB = srcB + ((255 - srcA) * dstB) / 255;
2105                 dstA = srcA + ((255 - srcA) * dstA) / 255;
2106                 break;
2107             case SDL_COPY_ADD:
2108                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
2109                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
2110                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
2111                 break;
2112             case SDL_COPY_MOD:
2113                 dstR = (srcR * dstR) / 255;
2114                 dstG = (srcG * dstG) / 255;
2115                 dstB = (srcB * dstB) / 255;
2116                 break;
2117             }
2118             dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
2119             *dst = dstpixel;
2120             ++src;
2121             ++dst;
2122         }
2123         info->src += info->src_pitch;
2124         info->dst += info->dst_pitch;
2125     }
2126 }
2127
2128 static void SDL_Blit_BGR888_ARGB8888_Blend_Scale(SDL_BlitInfo *info)
2129 {
2130     const int flags = info->flags;
2131     Uint32 srcpixel;
2132     Uint32 srcR, srcG, srcB, srcA;
2133     Uint32 dstpixel;
2134     Uint32 dstR, dstG, dstB, dstA;
2135     int srcy, srcx;
2136     int posy, posx;
2137     int incy, incx;
2138
2139     srcy = 0;
2140     posy = 0;
2141     incy = (info->src_h << 16) / info->dst_h;
2142     incx = (info->src_w << 16) / info->dst_w;
2143
2144     while (info->dst_h--) {
2145         Uint32 *src = 0;
2146         Uint32 *dst = (Uint32 *)info->dst;
2147         int n = info->dst_w;
2148         srcx = -1;
2149         posx = 0x10000L;
2150         while (posy >= 0x10000L) {
2151             ++srcy;
2152             posy -= 0x10000L;
2153         }
2154         while (n--) {
2155             if (posx >= 0x10000L) {
2156                 while (posx >= 0x10000L) {
2157                     ++srcx;
2158                     posx -= 0x10000L;
2159                 }
2160                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
2161             }
2162             srcpixel = *src;
2163             srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
2164             dstpixel = *dst;
2165             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
2166             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
2167                 /* This goes away if we ever use premultiplied alpha */
2168                 if (srcA < 255) {
2169                     srcR = (srcR * srcA) / 255;
2170                     srcG = (srcG * srcA) / 255;
2171                     srcB = (srcB * srcA) / 255;
2172                 }
2173             }
2174             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
2175             case SDL_COPY_BLEND:
2176                 dstR = srcR + ((255 - srcA) * dstR) / 255;
2177                 dstG = srcG + ((255 - srcA) * dstG) / 255;
2178                 dstB = srcB + ((255 - srcA) * dstB) / 255;
2179                 dstA = srcA + ((255 - srcA) * dstA) / 255;
2180                 break;
2181             case SDL_COPY_ADD:
2182                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
2183                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
2184                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
2185                 break;
2186             case SDL_COPY_MOD:
2187                 dstR = (srcR * dstR) / 255;
2188                 dstG = (srcG * dstG) / 255;
2189                 dstB = (srcB * dstB) / 255;
2190                 break;
2191             }
2192             dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
2193             *dst = dstpixel;
2194             posx += incx;
2195             ++dst;
2196         }
2197         posy += incy;
2198         info->dst += info->dst_pitch;
2199     }
2200 }
2201
2202 static void SDL_Blit_BGR888_ARGB8888_Modulate(SDL_BlitInfo *info)
2203 {
2204     const int flags = info->flags;
2205     const Uint32 modulateR = info->r;
2206     const Uint32 modulateG = info->g;
2207     const Uint32 modulateB = info->b;
2208     const Uint32 modulateA = info->a;
2209     Uint32 pixel;
2210     Uint32 R, G, B, A;
2211
2212     while (info->dst_h--) {
2213         Uint32 *src = (Uint32 *)info->src;
2214         Uint32 *dst = (Uint32 *)info->dst;
2215         int n = info->dst_w;
2216         while (n--) {
2217             pixel = *src;
2218             B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF;
2219             if (flags & SDL_COPY_MODULATE_COLOR) {
2220                 R = (R * modulateR) / 255;
2221                 G = (G * modulateG) / 255;
2222                 B = (B * modulateB) / 255;
2223             }
2224             if (flags & SDL_COPY_MODULATE_ALPHA) {
2225                 A = (A * modulateA) / 255;
2226             }
2227             pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
2228             *dst = pixel;
2229             ++src;
2230             ++dst;
2231         }
2232         info->src += info->src_pitch;
2233         info->dst += info->dst_pitch;
2234     }
2235 }
2236
2237 static void SDL_Blit_BGR888_ARGB8888_Modulate_Scale(SDL_BlitInfo *info)
2238 {
2239     const int flags = info->flags;
2240     const Uint32 modulateR = info->r;
2241     const Uint32 modulateG = info->g;
2242     const Uint32 modulateB = info->b;
2243     const Uint32 modulateA = info->a;
2244     Uint32 pixel;
2245     Uint32 R, G, B, A;
2246     int srcy, srcx;
2247     int posy, posx;
2248     int incy, incx;
2249
2250     srcy = 0;
2251     posy = 0;
2252     incy = (info->src_h << 16) / info->dst_h;
2253     incx = (info->src_w << 16) / info->dst_w;
2254
2255     while (info->dst_h--) {
2256         Uint32 *src = 0;
2257         Uint32 *dst = (Uint32 *)info->dst;
2258         int n = info->dst_w;
2259         srcx = -1;
2260         posx = 0x10000L;
2261         while (posy >= 0x10000L) {
2262             ++srcy;
2263             posy -= 0x10000L;
2264         }
2265         while (n--) {
2266             if (posx >= 0x10000L) {
2267                 while (posx >= 0x10000L) {
2268                     ++srcx;
2269                     posx -= 0x10000L;
2270                 }
2271                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
2272             }
2273             pixel = *src;
2274             B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF;
2275             if (flags & SDL_COPY_MODULATE_COLOR) {
2276                 R = (R * modulateR) / 255;
2277                 G = (G * modulateG) / 255;
2278                 B = (B * modulateB) / 255;
2279             }
2280             if (flags & SDL_COPY_MODULATE_ALPHA) {
2281                 A = (A * modulateA) / 255;
2282             }
2283             pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
2284             *dst = pixel;
2285             posx += incx;
2286             ++dst;
2287         }
2288         posy += incy;
2289         info->dst += info->dst_pitch;
2290     }
2291 }
2292
2293 static void SDL_Blit_BGR888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info)
2294 {
2295     const int flags = info->flags;
2296     const Uint32 modulateR = info->r;
2297     const Uint32 modulateG = info->g;
2298     const Uint32 modulateB = info->b;
2299     const Uint32 modulateA = info->a;
2300     Uint32 srcpixel;
2301     Uint32 srcR, srcG, srcB, srcA;
2302     Uint32 dstpixel;
2303     Uint32 dstR, dstG, dstB, dstA;
2304
2305     while (info->dst_h--) {
2306         Uint32 *src = (Uint32 *)info->src;
2307         Uint32 *dst = (Uint32 *)info->dst;
2308         int n = info->dst_w;
2309         while (n--) {
2310             srcpixel = *src;
2311             srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
2312             dstpixel = *dst;
2313             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
2314             if (flags & SDL_COPY_MODULATE_COLOR) {
2315                 srcR = (srcR * modulateR) / 255;
2316                 srcG = (srcG * modulateG) / 255;
2317                 srcB = (srcB * modulateB) / 255;
2318             }
2319             if (flags & SDL_COPY_MODULATE_ALPHA) {
2320                 srcA = (srcA * modulateA) / 255;
2321             }
2322             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
2323                 /* This goes away if we ever use premultiplied alpha */
2324                 if (srcA < 255) {
2325                     srcR = (srcR * srcA) / 255;
2326                     srcG = (srcG * srcA) / 255;
2327                     srcB = (srcB * srcA) / 255;
2328                 }
2329             }
2330             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
2331             case SDL_COPY_BLEND:
2332                 dstR = srcR + ((255 - srcA) * dstR) / 255;
2333                 dstG = srcG + ((255 - srcA) * dstG) / 255;
2334                 dstB = srcB + ((255 - srcA) * dstB) / 255;
2335                 dstA = srcA + ((255 - srcA) * dstA) / 255;
2336                 break;
2337             case SDL_COPY_ADD:
2338                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
2339                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
2340                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
2341                 break;
2342             case SDL_COPY_MOD:
2343                 dstR = (srcR * dstR) / 255;
2344                 dstG = (srcG * dstG) / 255;
2345                 dstB = (srcB * dstB) / 255;
2346                 break;
2347             }
2348             dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
2349             *dst = dstpixel;
2350             ++src;
2351             ++dst;
2352         }
2353         info->src += info->src_pitch;
2354         info->dst += info->dst_pitch;
2355     }
2356 }
2357
2358 static void SDL_Blit_BGR888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info)
2359 {
2360     const int flags = info->flags;
2361     const Uint32 modulateR = info->r;
2362     const Uint32 modulateG = info->g;
2363     const Uint32 modulateB = info->b;
2364     const Uint32 modulateA = info->a;
2365     Uint32 srcpixel;
2366     Uint32 srcR, srcG, srcB, srcA;
2367     Uint32 dstpixel;
2368     Uint32 dstR, dstG, dstB, dstA;
2369     int srcy, srcx;
2370     int posy, posx;
2371     int incy, incx;
2372
2373     srcy = 0;
2374     posy = 0;
2375     incy = (info->src_h << 16) / info->dst_h;
2376     incx = (info->src_w << 16) / info->dst_w;
2377
2378     while (info->dst_h--) {
2379         Uint32 *src = 0;
2380         Uint32 *dst = (Uint32 *)info->dst;
2381         int n = info->dst_w;
2382         srcx = -1;
2383         posx = 0x10000L;
2384         while (posy >= 0x10000L) {
2385             ++srcy;
2386             posy -= 0x10000L;
2387         }
2388         while (n--) {
2389             if (posx >= 0x10000L) {
2390                 while (posx >= 0x10000L) {
2391                     ++srcx;
2392                     posx -= 0x10000L;
2393                 }
2394                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
2395             }
2396             srcpixel = *src;
2397             srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
2398             dstpixel = *dst;
2399             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
2400             if (flags & SDL_COPY_MODULATE_COLOR) {
2401                 srcR = (srcR * modulateR) / 255;
2402                 srcG = (srcG * modulateG) / 255;
2403                 srcB = (srcB * modulateB) / 255;
2404             }
2405             if (flags & SDL_COPY_MODULATE_ALPHA) {
2406                 srcA = (srcA * modulateA) / 255;
2407             }
2408             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
2409                 /* This goes away if we ever use premultiplied alpha */
2410                 if (srcA < 255) {
2411                     srcR = (srcR * srcA) / 255;
2412                     srcG = (srcG * srcA) / 255;
2413                     srcB = (srcB * srcA) / 255;
2414                 }
2415             }
2416             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
2417             case SDL_COPY_BLEND:
2418                 dstR = srcR + ((255 - srcA) * dstR) / 255;
2419                 dstG = srcG + ((255 - srcA) * dstG) / 255;
2420                 dstB = srcB + ((255 - srcA) * dstB) / 255;
2421                 dstA = srcA + ((255 - srcA) * dstA) / 255;
2422                 break;
2423             case SDL_COPY_ADD:
2424                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
2425                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
2426                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
2427                 break;
2428             case SDL_COPY_MOD:
2429                 dstR = (srcR * dstR) / 255;
2430                 dstG = (srcG * dstG) / 255;
2431                 dstB = (srcB * dstB) / 255;
2432                 break;
2433             }
2434             dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
2435             *dst = dstpixel;
2436             posx += incx;
2437             ++dst;
2438         }
2439         posy += incy;
2440         info->dst += info->dst_pitch;
2441     }
2442 }
2443
2444 static void SDL_Blit_ARGB8888_RGB888_Scale(SDL_BlitInfo *info)
2445 {
2446     Uint32 pixel;
2447     Uint32 R, G, B;
2448     int srcy, srcx;
2449     int posy, posx;
2450     int incy, incx;
2451
2452     srcy = 0;
2453     posy = 0;
2454     incy = (info->src_h << 16) / info->dst_h;
2455     incx = (info->src_w << 16) / info->dst_w;
2456
2457     while (info->dst_h--) {
2458         Uint32 *src = 0;
2459         Uint32 *dst = (Uint32 *)info->dst;
2460         int n = info->dst_w;
2461         srcx = -1;
2462         posx = 0x10000L;
2463         while (posy >= 0x10000L) {
2464             ++srcy;
2465             posy -= 0x10000L;
2466         }
2467         while (n--) {
2468             if (posx >= 0x10000L) {
2469                 while (posx >= 0x10000L) {
2470                     ++srcx;
2471                     posx -= 0x10000L;
2472                 }
2473                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
2474             }
2475             pixel = *src;
2476             R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
2477             pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
2478             *dst = pixel;
2479             posx += incx;
2480             ++dst;
2481         }
2482         posy += incy;
2483         info->dst += info->dst_pitch;
2484     }
2485 }
2486
2487 static void SDL_Blit_ARGB8888_RGB888_Blend(SDL_BlitInfo *info)
2488 {
2489     const int flags = info->flags;
2490     Uint32 srcpixel;
2491     Uint32 srcR, srcG, srcB, srcA;
2492     Uint32 dstpixel;
2493     Uint32 dstR, dstG, dstB;
2494
2495     while (info->dst_h--) {
2496         Uint32 *src = (Uint32 *)info->src;
2497         Uint32 *dst = (Uint32 *)info->dst;
2498         int n = info->dst_w;
2499         while (n--) {
2500             srcpixel = *src;
2501             srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
2502             dstpixel = *dst;
2503             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
2504             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
2505                 /* This goes away if we ever use premultiplied alpha */
2506                 if (srcA < 255) {
2507                     srcR = (srcR * srcA) / 255;
2508                     srcG = (srcG * srcA) / 255;
2509                     srcB = (srcB * srcA) / 255;
2510                 }
2511             }
2512             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
2513             case SDL_COPY_BLEND:
2514                 dstR = srcR + ((255 - srcA) * dstR) / 255;
2515                 dstG = srcG + ((255 - srcA) * dstG) / 255;
2516                 dstB = srcB + ((255 - srcA) * dstB) / 255;
2517                 break;
2518             case SDL_COPY_ADD:
2519                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
2520                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
2521                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
2522                 break;
2523             case SDL_COPY_MOD:
2524                 dstR = (srcR * dstR) / 255;
2525                 dstG = (srcG * dstG) / 255;
2526                 dstB = (srcB * dstB) / 255;
2527                 break;
2528             }
2529             dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
2530             *dst = dstpixel;
2531             ++src;
2532             ++dst;
2533         }
2534         info->src += info->src_pitch;
2535         info->dst += info->dst_pitch;
2536     }
2537 }
2538
2539 static void SDL_Blit_ARGB8888_RGB888_Blend_Scale(SDL_BlitInfo *info)
2540 {
2541     const int flags = info->flags;
2542     Uint32 srcpixel;
2543     Uint32 srcR, srcG, srcB, srcA;
2544     Uint32 dstpixel;
2545     Uint32 dstR, dstG, dstB;
2546     int srcy, srcx;
2547     int posy, posx;
2548     int incy, incx;
2549
2550     srcy = 0;
2551     posy = 0;
2552     incy = (info->src_h << 16) / info->dst_h;
2553     incx = (info->src_w << 16) / info->dst_w;
2554
2555     while (info->dst_h--) {
2556         Uint32 *src = 0;
2557         Uint32 *dst = (Uint32 *)info->dst;
2558         int n = info->dst_w;
2559         srcx = -1;
2560         posx = 0x10000L;
2561         while (posy >= 0x10000L) {
2562             ++srcy;
2563             posy -= 0x10000L;
2564         }
2565         while (n--) {
2566             if (posx >= 0x10000L) {
2567                 while (posx >= 0x10000L) {
2568                     ++srcx;
2569                     posx -= 0x10000L;
2570                 }
2571                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
2572             }
2573             srcpixel = *src;
2574             srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
2575             dstpixel = *dst;
2576             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
2577             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
2578                 /* This goes away if we ever use premultiplied alpha */
2579                 if (srcA < 255) {
2580                     srcR = (srcR * srcA) / 255;
2581                     srcG = (srcG * srcA) / 255;
2582                     srcB = (srcB * srcA) / 255;
2583                 }
2584             }
2585             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
2586             case SDL_COPY_BLEND:
2587                 dstR = srcR + ((255 - srcA) * dstR) / 255;
2588                 dstG = srcG + ((255 - srcA) * dstG) / 255;
2589                 dstB = srcB + ((255 - srcA) * dstB) / 255;
2590                 break;
2591             case SDL_COPY_ADD:
2592                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
2593                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
2594                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
2595                 break;
2596             case SDL_COPY_MOD:
2597                 dstR = (srcR * dstR) / 255;
2598                 dstG = (srcG * dstG) / 255;
2599                 dstB = (srcB * dstB) / 255;
2600                 break;
2601             }
2602             dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
2603             *dst = dstpixel;
2604             posx += incx;
2605             ++dst;
2606         }
2607         posy += incy;
2608         info->dst += info->dst_pitch;
2609     }
2610 }
2611
2612 static void SDL_Blit_ARGB8888_RGB888_Modulate(SDL_BlitInfo *info)
2613 {
2614     const int flags = info->flags;
2615     const Uint32 modulateR = info->r;
2616     const Uint32 modulateG = info->g;
2617     const Uint32 modulateB = info->b;
2618     Uint32 pixel;
2619     Uint32 R, G, B;
2620
2621     while (info->dst_h--) {
2622         Uint32 *src = (Uint32 *)info->src;
2623         Uint32 *dst = (Uint32 *)info->dst;
2624         int n = info->dst_w;
2625         while (n--) {
2626             pixel = *src;
2627             R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
2628             if (flags & SDL_COPY_MODULATE_COLOR) {
2629                 R = (R * modulateR) / 255;
2630                 G = (G * modulateG) / 255;
2631                 B = (B * modulateB) / 255;
2632             }
2633             pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
2634             *dst = pixel;
2635             ++src;
2636             ++dst;
2637         }
2638         info->src += info->src_pitch;
2639         info->dst += info->dst_pitch;
2640     }
2641 }
2642
2643 static void SDL_Blit_ARGB8888_RGB888_Modulate_Scale(SDL_BlitInfo *info)
2644 {
2645     const int flags = info->flags;
2646     const Uint32 modulateR = info->r;
2647     const Uint32 modulateG = info->g;
2648     const Uint32 modulateB = info->b;
2649     Uint32 pixel;
2650     Uint32 R, G, B;
2651     int srcy, srcx;
2652     int posy, posx;
2653     int incy, incx;
2654
2655     srcy = 0;
2656     posy = 0;
2657     incy = (info->src_h << 16) / info->dst_h;
2658     incx = (info->src_w << 16) / info->dst_w;
2659
2660     while (info->dst_h--) {
2661         Uint32 *src = 0;
2662         Uint32 *dst = (Uint32 *)info->dst;
2663         int n = info->dst_w;
2664         srcx = -1;
2665         posx = 0x10000L;
2666         while (posy >= 0x10000L) {
2667             ++srcy;
2668             posy -= 0x10000L;
2669         }
2670         while (n--) {
2671             if (posx >= 0x10000L) {
2672                 while (posx >= 0x10000L) {
2673                     ++srcx;
2674                     posx -= 0x10000L;
2675                 }
2676                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
2677             }
2678             pixel = *src;
2679             R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
2680             if (flags & SDL_COPY_MODULATE_COLOR) {
2681                 R = (R * modulateR) / 255;
2682                 G = (G * modulateG) / 255;
2683                 B = (B * modulateB) / 255;
2684             }
2685             pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
2686             *dst = pixel;
2687             posx += incx;
2688             ++dst;
2689         }
2690         posy += incy;
2691         info->dst += info->dst_pitch;
2692     }
2693 }
2694
2695 static void SDL_Blit_ARGB8888_RGB888_Modulate_Blend(SDL_BlitInfo *info)
2696 {
2697     const int flags = info->flags;
2698     const Uint32 modulateR = info->r;
2699     const Uint32 modulateG = info->g;
2700     const Uint32 modulateB = info->b;
2701     const Uint32 modulateA = info->a;
2702     Uint32 srcpixel;
2703     Uint32 srcR, srcG, srcB, srcA;
2704     Uint32 dstpixel;
2705     Uint32 dstR, dstG, dstB;
2706
2707     while (info->dst_h--) {
2708         Uint32 *src = (Uint32 *)info->src;
2709         Uint32 *dst = (Uint32 *)info->dst;
2710         int n = info->dst_w;
2711         while (n--) {
2712             srcpixel = *src;
2713             srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
2714             dstpixel = *dst;
2715             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
2716             if (flags & SDL_COPY_MODULATE_COLOR) {
2717                 srcR = (srcR * modulateR) / 255;
2718                 srcG = (srcG * modulateG) / 255;
2719                 srcB = (srcB * modulateB) / 255;
2720             }
2721             if (flags & SDL_COPY_MODULATE_ALPHA) {
2722                 srcA = (srcA * modulateA) / 255;
2723             }
2724             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
2725                 /* This goes away if we ever use premultiplied alpha */
2726                 if (srcA < 255) {
2727                     srcR = (srcR * srcA) / 255;
2728                     srcG = (srcG * srcA) / 255;
2729                     srcB = (srcB * srcA) / 255;
2730                 }
2731             }
2732             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
2733             case SDL_COPY_BLEND:
2734                 dstR = srcR + ((255 - srcA) * dstR) / 255;
2735                 dstG = srcG + ((255 - srcA) * dstG) / 255;
2736                 dstB = srcB + ((255 - srcA) * dstB) / 255;
2737                 break;
2738             case SDL_COPY_ADD:
2739                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
2740                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
2741                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
2742                 break;
2743             case SDL_COPY_MOD:
2744                 dstR = (srcR * dstR) / 255;
2745                 dstG = (srcG * dstG) / 255;
2746                 dstB = (srcB * dstB) / 255;
2747                 break;
2748             }
2749             dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
2750             *dst = dstpixel;
2751             ++src;
2752             ++dst;
2753         }
2754         info->src += info->src_pitch;
2755         info->dst += info->dst_pitch;
2756     }
2757 }
2758
2759 static void SDL_Blit_ARGB8888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info)
2760 {
2761     const int flags = info->flags;
2762     const Uint32 modulateR = info->r;
2763     const Uint32 modulateG = info->g;
2764     const Uint32 modulateB = info->b;
2765     const Uint32 modulateA = info->a;
2766     Uint32 srcpixel;
2767     Uint32 srcR, srcG, srcB, srcA;
2768     Uint32 dstpixel;
2769     Uint32 dstR, dstG, dstB;
2770     int srcy, srcx;
2771     int posy, posx;
2772     int incy, incx;
2773
2774     srcy = 0;
2775     posy = 0;
2776     incy = (info->src_h << 16) / info->dst_h;
2777     incx = (info->src_w << 16) / info->dst_w;
2778
2779     while (info->dst_h--) {
2780         Uint32 *src = 0;
2781         Uint32 *dst = (Uint32 *)info->dst;
2782         int n = info->dst_w;
2783         srcx = -1;
2784         posx = 0x10000L;
2785         while (posy >= 0x10000L) {
2786             ++srcy;
2787             posy -= 0x10000L;
2788         }
2789         while (n--) {
2790             if (posx >= 0x10000L) {
2791                 while (posx >= 0x10000L) {
2792                     ++srcx;
2793                     posx -= 0x10000L;
2794                 }
2795                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
2796             }
2797             srcpixel = *src;
2798             srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
2799             dstpixel = *dst;
2800             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
2801             if (flags & SDL_COPY_MODULATE_COLOR) {
2802                 srcR = (srcR * modulateR) / 255;
2803                 srcG = (srcG * modulateG) / 255;
2804                 srcB = (srcB * modulateB) / 255;
2805             }
2806             if (flags & SDL_COPY_MODULATE_ALPHA) {
2807                 srcA = (srcA * modulateA) / 255;
2808             }
2809             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
2810                 /* This goes away if we ever use premultiplied alpha */
2811                 if (srcA < 255) {
2812                     srcR = (srcR * srcA) / 255;
2813                     srcG = (srcG * srcA) / 255;
2814                     srcB = (srcB * srcA) / 255;
2815                 }
2816             }
2817             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
2818             case SDL_COPY_BLEND:
2819                 dstR = srcR + ((255 - srcA) * dstR) / 255;
2820                 dstG = srcG + ((255 - srcA) * dstG) / 255;
2821                 dstB = srcB + ((255 - srcA) * dstB) / 255;
2822                 break;
2823             case SDL_COPY_ADD:
2824                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
2825                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
2826                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
2827                 break;
2828             case SDL_COPY_MOD:
2829                 dstR = (srcR * dstR) / 255;
2830                 dstG = (srcG * dstG) / 255;
2831                 dstB = (srcB * dstB) / 255;
2832                 break;
2833             }
2834             dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
2835             *dst = dstpixel;
2836             posx += incx;
2837             ++dst;
2838         }
2839         posy += incy;
2840         info->dst += info->dst_pitch;
2841     }
2842 }
2843
2844 static void SDL_Blit_ARGB8888_BGR888_Scale(SDL_BlitInfo *info)
2845 {
2846     Uint32 pixel;
2847     Uint32 R, G, B;
2848     int srcy, srcx;
2849     int posy, posx;
2850     int incy, incx;
2851
2852     srcy = 0;
2853     posy = 0;
2854     incy = (info->src_h << 16) / info->dst_h;
2855     incx = (info->src_w << 16) / info->dst_w;
2856
2857     while (info->dst_h--) {
2858         Uint32 *src = 0;
2859         Uint32 *dst = (Uint32 *)info->dst;
2860         int n = info->dst_w;
2861         srcx = -1;
2862         posx = 0x10000L;
2863         while (posy >= 0x10000L) {
2864             ++srcy;
2865             posy -= 0x10000L;
2866         }
2867         while (n--) {
2868             if (posx >= 0x10000L) {
2869                 while (posx >= 0x10000L) {
2870                     ++srcx;
2871                     posx -= 0x10000L;
2872                 }
2873                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
2874             }
2875             pixel = *src;
2876             R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
2877             pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
2878             *dst = pixel;
2879             posx += incx;
2880             ++dst;
2881         }
2882         posy += incy;
2883         info->dst += info->dst_pitch;
2884     }
2885 }
2886
2887 static void SDL_Blit_ARGB8888_BGR888_Blend(SDL_BlitInfo *info)
2888 {
2889     const int flags = info->flags;
2890     Uint32 srcpixel;
2891     Uint32 srcR, srcG, srcB, srcA;
2892     Uint32 dstpixel;
2893     Uint32 dstR, dstG, dstB;
2894
2895     while (info->dst_h--) {
2896         Uint32 *src = (Uint32 *)info->src;
2897         Uint32 *dst = (Uint32 *)info->dst;
2898         int n = info->dst_w;
2899         while (n--) {
2900             srcpixel = *src;
2901             srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
2902             dstpixel = *dst;
2903             dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
2904             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
2905                 /* This goes away if we ever use premultiplied alpha */
2906                 if (srcA < 255) {
2907                     srcR = (srcR * srcA) / 255;
2908                     srcG = (srcG * srcA) / 255;
2909                     srcB = (srcB * srcA) / 255;
2910                 }
2911             }
2912             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
2913             case SDL_COPY_BLEND:
2914                 dstR = srcR + ((255 - srcA) * dstR) / 255;
2915                 dstG = srcG + ((255 - srcA) * dstG) / 255;
2916                 dstB = srcB + ((255 - srcA) * dstB) / 255;
2917                 break;
2918             case SDL_COPY_ADD:
2919                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
2920                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
2921                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
2922                 break;
2923             case SDL_COPY_MOD:
2924                 dstR = (srcR * dstR) / 255;
2925                 dstG = (srcG * dstG) / 255;
2926                 dstB = (srcB * dstB) / 255;
2927                 break;
2928             }
2929             dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
2930             *dst = dstpixel;
2931             ++src;
2932             ++dst;
2933         }
2934         info->src += info->src_pitch;
2935         info->dst += info->dst_pitch;
2936     }
2937 }
2938
2939 static void SDL_Blit_ARGB8888_BGR888_Blend_Scale(SDL_BlitInfo *info)
2940 {
2941     const int flags = info->flags;
2942     Uint32 srcpixel;
2943     Uint32 srcR, srcG, srcB, srcA;
2944     Uint32 dstpixel;
2945     Uint32 dstR, dstG, dstB;
2946     int srcy, srcx;
2947     int posy, posx;
2948     int incy, incx;
2949
2950     srcy = 0;
2951     posy = 0;
2952     incy = (info->src_h << 16) / info->dst_h;
2953     incx = (info->src_w << 16) / info->dst_w;
2954
2955     while (info->dst_h--) {
2956         Uint32 *src = 0;
2957         Uint32 *dst = (Uint32 *)info->dst;
2958         int n = info->dst_w;
2959         srcx = -1;
2960         posx = 0x10000L;
2961         while (posy >= 0x10000L) {
2962             ++srcy;
2963             posy -= 0x10000L;
2964         }
2965         while (n--) {
2966             if (posx >= 0x10000L) {
2967                 while (posx >= 0x10000L) {
2968                     ++srcx;
2969                     posx -= 0x10000L;
2970                 }
2971                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
2972             }
2973             srcpixel = *src;
2974             srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
2975             dstpixel = *dst;
2976             dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
2977             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
2978                 /* This goes away if we ever use premultiplied alpha */
2979                 if (srcA < 255) {
2980                     srcR = (srcR * srcA) / 255;
2981                     srcG = (srcG * srcA) / 255;
2982                     srcB = (srcB * srcA) / 255;
2983                 }
2984             }
2985             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
2986             case SDL_COPY_BLEND:
2987                 dstR = srcR + ((255 - srcA) * dstR) / 255;
2988                 dstG = srcG + ((255 - srcA) * dstG) / 255;
2989                 dstB = srcB + ((255 - srcA) * dstB) / 255;
2990                 break;
2991             case SDL_COPY_ADD:
2992                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
2993                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
2994                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
2995                 break;
2996             case SDL_COPY_MOD:
2997                 dstR = (srcR * dstR) / 255;
2998                 dstG = (srcG * dstG) / 255;
2999                 dstB = (srcB * dstB) / 255;
3000                 break;
3001             }
3002             dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
3003             *dst = dstpixel;
3004             posx += incx;
3005             ++dst;
3006         }
3007         posy += incy;
3008         info->dst += info->dst_pitch;
3009     }
3010 }
3011
3012 static void SDL_Blit_ARGB8888_BGR888_Modulate(SDL_BlitInfo *info)
3013 {
3014     const int flags = info->flags;
3015     const Uint32 modulateR = info->r;
3016     const Uint32 modulateG = info->g;
3017     const Uint32 modulateB = info->b;
3018     Uint32 pixel;
3019     Uint32 R, G, B;
3020
3021     while (info->dst_h--) {
3022         Uint32 *src = (Uint32 *)info->src;
3023         Uint32 *dst = (Uint32 *)info->dst;
3024         int n = info->dst_w;
3025         while (n--) {
3026             pixel = *src;
3027             R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
3028             if (flags & SDL_COPY_MODULATE_COLOR) {
3029                 R = (R * modulateR) / 255;
3030                 G = (G * modulateG) / 255;
3031                 B = (B * modulateB) / 255;
3032             }
3033             pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
3034             *dst = pixel;
3035             ++src;
3036             ++dst;
3037         }
3038         info->src += info->src_pitch;
3039         info->dst += info->dst_pitch;
3040     }
3041 }
3042
3043 static void SDL_Blit_ARGB8888_BGR888_Modulate_Scale(SDL_BlitInfo *info)
3044 {
3045     const int flags = info->flags;
3046     const Uint32 modulateR = info->r;
3047     const Uint32 modulateG = info->g;
3048     const Uint32 modulateB = info->b;
3049     Uint32 pixel;
3050     Uint32 R, G, B;
3051     int srcy, srcx;
3052     int posy, posx;
3053     int incy, incx;
3054
3055     srcy = 0;
3056     posy = 0;
3057     incy = (info->src_h << 16) / info->dst_h;
3058     incx = (info->src_w << 16) / info->dst_w;
3059
3060     while (info->dst_h--) {
3061         Uint32 *src = 0;
3062         Uint32 *dst = (Uint32 *)info->dst;
3063         int n = info->dst_w;
3064         srcx = -1;
3065         posx = 0x10000L;
3066         while (posy >= 0x10000L) {
3067             ++srcy;
3068             posy -= 0x10000L;
3069         }
3070         while (n--) {
3071             if (posx >= 0x10000L) {
3072                 while (posx >= 0x10000L) {
3073                     ++srcx;
3074                     posx -= 0x10000L;
3075                 }
3076                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
3077             }
3078             pixel = *src;
3079             R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
3080             if (flags & SDL_COPY_MODULATE_COLOR) {
3081                 R = (R * modulateR) / 255;
3082                 G = (G * modulateG) / 255;
3083                 B = (B * modulateB) / 255;
3084             }
3085             pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
3086             *dst = pixel;
3087             posx += incx;
3088             ++dst;
3089         }
3090         posy += incy;
3091         info->dst += info->dst_pitch;
3092     }
3093 }
3094
3095 static void SDL_Blit_ARGB8888_BGR888_Modulate_Blend(SDL_BlitInfo *info)
3096 {
3097     const int flags = info->flags;
3098     const Uint32 modulateR = info->r;
3099     const Uint32 modulateG = info->g;
3100     const Uint32 modulateB = info->b;
3101     const Uint32 modulateA = info->a;
3102     Uint32 srcpixel;
3103     Uint32 srcR, srcG, srcB, srcA;
3104     Uint32 dstpixel;
3105     Uint32 dstR, dstG, dstB;
3106
3107     while (info->dst_h--) {
3108         Uint32 *src = (Uint32 *)info->src;
3109         Uint32 *dst = (Uint32 *)info->dst;
3110         int n = info->dst_w;
3111         while (n--) {
3112             srcpixel = *src;
3113             srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
3114             dstpixel = *dst;
3115             dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
3116             if (flags & SDL_COPY_MODULATE_COLOR) {
3117                 srcR = (srcR * modulateR) / 255;
3118                 srcG = (srcG * modulateG) / 255;
3119                 srcB = (srcB * modulateB) / 255;
3120             }
3121             if (flags & SDL_COPY_MODULATE_ALPHA) {
3122                 srcA = (srcA * modulateA) / 255;
3123             }
3124             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
3125                 /* This goes away if we ever use premultiplied alpha */
3126                 if (srcA < 255) {
3127                     srcR = (srcR * srcA) / 255;
3128                     srcG = (srcG * srcA) / 255;
3129                     srcB = (srcB * srcA) / 255;
3130                 }
3131             }
3132             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
3133             case SDL_COPY_BLEND:
3134                 dstR = srcR + ((255 - srcA) * dstR) / 255;
3135                 dstG = srcG + ((255 - srcA) * dstG) / 255;
3136                 dstB = srcB + ((255 - srcA) * dstB) / 255;
3137                 break;
3138             case SDL_COPY_ADD:
3139                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
3140                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
3141                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
3142                 break;
3143             case SDL_COPY_MOD:
3144                 dstR = (srcR * dstR) / 255;
3145                 dstG = (srcG * dstG) / 255;
3146                 dstB = (srcB * dstB) / 255;
3147                 break;
3148             }
3149             dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
3150             *dst = dstpixel;
3151             ++src;
3152             ++dst;
3153         }
3154         info->src += info->src_pitch;
3155         info->dst += info->dst_pitch;
3156     }
3157 }
3158
3159 static void SDL_Blit_ARGB8888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info)
3160 {
3161     const int flags = info->flags;
3162     const Uint32 modulateR = info->r;
3163     const Uint32 modulateG = info->g;
3164     const Uint32 modulateB = info->b;
3165     const Uint32 modulateA = info->a;
3166     Uint32 srcpixel;
3167     Uint32 srcR, srcG, srcB, srcA;
3168     Uint32 dstpixel;
3169     Uint32 dstR, dstG, dstB;
3170     int srcy, srcx;
3171     int posy, posx;
3172     int incy, incx;
3173
3174     srcy = 0;
3175     posy = 0;
3176     incy = (info->src_h << 16) / info->dst_h;
3177     incx = (info->src_w << 16) / info->dst_w;
3178
3179     while (info->dst_h--) {
3180         Uint32 *src = 0;
3181         Uint32 *dst = (Uint32 *)info->dst;
3182         int n = info->dst_w;
3183         srcx = -1;
3184         posx = 0x10000L;
3185         while (posy >= 0x10000L) {
3186             ++srcy;
3187             posy -= 0x10000L;
3188         }
3189         while (n--) {
3190             if (posx >= 0x10000L) {
3191                 while (posx >= 0x10000L) {
3192                     ++srcx;
3193                     posx -= 0x10000L;
3194                 }
3195                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
3196             }
3197             srcpixel = *src;
3198             srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
3199             dstpixel = *dst;
3200             dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
3201             if (flags & SDL_COPY_MODULATE_COLOR) {
3202                 srcR = (srcR * modulateR) / 255;
3203                 srcG = (srcG * modulateG) / 255;
3204                 srcB = (srcB * modulateB) / 255;
3205             }
3206             if (flags & SDL_COPY_MODULATE_ALPHA) {
3207                 srcA = (srcA * modulateA) / 255;
3208             }
3209             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
3210                 /* This goes away if we ever use premultiplied alpha */
3211                 if (srcA < 255) {
3212                     srcR = (srcR * srcA) / 255;
3213                     srcG = (srcG * srcA) / 255;
3214                     srcB = (srcB * srcA) / 255;
3215                 }
3216             }
3217             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
3218             case SDL_COPY_BLEND:
3219                 dstR = srcR + ((255 - srcA) * dstR) / 255;
3220                 dstG = srcG + ((255 - srcA) * dstG) / 255;
3221                 dstB = srcB + ((255 - srcA) * dstB) / 255;
3222                 break;
3223             case SDL_COPY_ADD:
3224                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
3225                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
3226                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
3227                 break;
3228             case SDL_COPY_MOD:
3229                 dstR = (srcR * dstR) / 255;
3230                 dstG = (srcG * dstG) / 255;
3231                 dstB = (srcB * dstB) / 255;
3232                 break;
3233             }
3234             dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
3235             *dst = dstpixel;
3236             posx += incx;
3237             ++dst;
3238         }
3239         posy += incy;
3240         info->dst += info->dst_pitch;
3241     }
3242 }
3243
3244 static void SDL_Blit_ARGB8888_ARGB8888_Scale(SDL_BlitInfo *info)
3245 {
3246     int srcy, srcx;
3247     int posy, posx;
3248     int incy, incx;
3249
3250     srcy = 0;
3251     posy = 0;
3252     incy = (info->src_h << 16) / info->dst_h;
3253     incx = (info->src_w << 16) / info->dst_w;
3254
3255     while (info->dst_h--) {
3256         Uint32 *src = 0;
3257         Uint32 *dst = (Uint32 *)info->dst;
3258         int n = info->dst_w;
3259         srcx = -1;
3260         posx = 0x10000L;
3261         while (posy >= 0x10000L) {
3262             ++srcy;
3263             posy -= 0x10000L;
3264         }
3265         while (n--) {
3266             if (posx >= 0x10000L) {
3267                 while (posx >= 0x10000L) {
3268                     ++srcx;
3269                     posx -= 0x10000L;
3270                 }
3271                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
3272             }
3273             *dst = *src;
3274             posx += incx;
3275             ++dst;
3276         }
3277         posy += incy;
3278         info->dst += info->dst_pitch;
3279     }
3280 }
3281
3282 static void SDL_Blit_ARGB8888_ARGB8888_Blend(SDL_BlitInfo *info)
3283 {
3284     const int flags = info->flags;
3285     Uint32 srcpixel;
3286     Uint32 srcR, srcG, srcB, srcA;
3287     Uint32 dstpixel;
3288     Uint32 dstR, dstG, dstB, dstA;
3289
3290     while (info->dst_h--) {
3291         Uint32 *src = (Uint32 *)info->src;
3292         Uint32 *dst = (Uint32 *)info->dst;
3293         int n = info->dst_w;
3294         while (n--) {
3295             srcpixel = *src;
3296             srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
3297             dstpixel = *dst;
3298             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
3299             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
3300                 /* This goes away if we ever use premultiplied alpha */
3301                 if (srcA < 255) {
3302                     srcR = (srcR * srcA) / 255;
3303                     srcG = (srcG * srcA) / 255;
3304                     srcB = (srcB * srcA) / 255;
3305                 }
3306             }
3307             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
3308             case SDL_COPY_BLEND:
3309                 dstR = srcR + ((255 - srcA) * dstR) / 255;
3310                 dstG = srcG + ((255 - srcA) * dstG) / 255;
3311                 dstB = srcB + ((255 - srcA) * dstB) / 255;
3312                 dstA = srcA + ((255 - srcA) * dstA) / 255;
3313                 break;
3314             case SDL_COPY_ADD:
3315                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
3316                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
3317                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
3318                 break;
3319             case SDL_COPY_MOD:
3320                 dstR = (srcR * dstR) / 255;
3321                 dstG = (srcG * dstG) / 255;
3322                 dstB = (srcB * dstB) / 255;
3323                 break;
3324             }
3325             dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
3326             *dst = dstpixel;
3327             ++src;
3328             ++dst;
3329         }
3330         info->src += info->src_pitch;
3331         info->dst += info->dst_pitch;
3332     }
3333 }
3334
3335 static void SDL_Blit_ARGB8888_ARGB8888_Blend_Scale(SDL_BlitInfo *info)
3336 {
3337     const int flags = info->flags;
3338     Uint32 srcpixel;
3339     Uint32 srcR, srcG, srcB, srcA;
3340     Uint32 dstpixel;
3341     Uint32 dstR, dstG, dstB, dstA;
3342     int srcy, srcx;
3343     int posy, posx;
3344     int incy, incx;
3345
3346     srcy = 0;
3347     posy = 0;
3348     incy = (info->src_h << 16) / info->dst_h;
3349     incx = (info->src_w << 16) / info->dst_w;
3350
3351     while (info->dst_h--) {
3352         Uint32 *src = 0;
3353         Uint32 *dst = (Uint32 *)info->dst;
3354         int n = info->dst_w;
3355         srcx = -1;
3356         posx = 0x10000L;
3357         while (posy >= 0x10000L) {
3358             ++srcy;
3359             posy -= 0x10000L;
3360         }
3361         while (n--) {
3362             if (posx >= 0x10000L) {
3363                 while (posx >= 0x10000L) {
3364                     ++srcx;
3365                     posx -= 0x10000L;
3366                 }
3367                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
3368             }
3369             srcpixel = *src;
3370             srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
3371             dstpixel = *dst;
3372             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
3373             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
3374                 /* This goes away if we ever use premultiplied alpha */
3375                 if (srcA < 255) {
3376                     srcR = (srcR * srcA) / 255;
3377                     srcG = (srcG * srcA) / 255;
3378                     srcB = (srcB * srcA) / 255;
3379                 }
3380             }
3381             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
3382             case SDL_COPY_BLEND:
3383                 dstR = srcR + ((255 - srcA) * dstR) / 255;
3384                 dstG = srcG + ((255 - srcA) * dstG) / 255;
3385                 dstB = srcB + ((255 - srcA) * dstB) / 255;
3386                 dstA = srcA + ((255 - srcA) * dstA) / 255;
3387                 break;
3388             case SDL_COPY_ADD:
3389                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
3390                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
3391                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
3392                 break;
3393             case SDL_COPY_MOD:
3394                 dstR = (srcR * dstR) / 255;
3395                 dstG = (srcG * dstG) / 255;
3396                 dstB = (srcB * dstB) / 255;
3397                 break;
3398             }
3399             dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
3400             *dst = dstpixel;
3401             posx += incx;
3402             ++dst;
3403         }
3404         posy += incy;
3405         info->dst += info->dst_pitch;
3406     }
3407 }
3408
3409 static void SDL_Blit_ARGB8888_ARGB8888_Modulate(SDL_BlitInfo *info)
3410 {
3411     const int flags = info->flags;
3412     const Uint32 modulateR = info->r;
3413     const Uint32 modulateG = info->g;
3414     const Uint32 modulateB = info->b;
3415     const Uint32 modulateA = info->a;
3416     Uint32 pixel;
3417     Uint32 R, G, B, A;
3418
3419     while (info->dst_h--) {
3420         Uint32 *src = (Uint32 *)info->src;
3421         Uint32 *dst = (Uint32 *)info->dst;
3422         int n = info->dst_w;
3423         while (n--) {
3424             pixel = *src;
3425             R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = (Uint8)(pixel >> 24);
3426             if (flags & SDL_COPY_MODULATE_COLOR) {
3427                 R = (R * modulateR) / 255;
3428                 G = (G * modulateG) / 255;
3429                 B = (B * modulateB) / 255;
3430             }
3431             if (flags & SDL_COPY_MODULATE_ALPHA) {
3432                 A = (A * modulateA) / 255;
3433             }
3434             pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
3435             *dst = pixel;
3436             ++src;
3437             ++dst;
3438         }
3439         info->src += info->src_pitch;
3440         info->dst += info->dst_pitch;
3441     }
3442 }
3443
3444 static void SDL_Blit_ARGB8888_ARGB8888_Modulate_Scale(SDL_BlitInfo *info)
3445 {
3446     const int flags = info->flags;
3447     const Uint32 modulateR = info->r;
3448     const Uint32 modulateG = info->g;
3449     const Uint32 modulateB = info->b;
3450     const Uint32 modulateA = info->a;
3451     Uint32 pixel;
3452     Uint32 R, G, B, A;
3453     int srcy, srcx;
3454     int posy, posx;
3455     int incy, incx;
3456
3457     srcy = 0;
3458     posy = 0;
3459     incy = (info->src_h << 16) / info->dst_h;
3460     incx = (info->src_w << 16) / info->dst_w;
3461
3462     while (info->dst_h--) {
3463         Uint32 *src = 0;
3464         Uint32 *dst = (Uint32 *)info->dst;
3465         int n = info->dst_w;
3466         srcx = -1;
3467         posx = 0x10000L;
3468         while (posy >= 0x10000L) {
3469             ++srcy;
3470             posy -= 0x10000L;
3471         }
3472         while (n--) {
3473             if (posx >= 0x10000L) {
3474                 while (posx >= 0x10000L) {
3475                     ++srcx;
3476                     posx -= 0x10000L;
3477                 }
3478                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
3479             }
3480             pixel = *src;
3481             R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = (Uint8)(pixel >> 24);
3482             if (flags & SDL_COPY_MODULATE_COLOR) {
3483                 R = (R * modulateR) / 255;
3484                 G = (G * modulateG) / 255;
3485                 B = (B * modulateB) / 255;
3486             }
3487             if (flags & SDL_COPY_MODULATE_ALPHA) {
3488                 A = (A * modulateA) / 255;
3489             }
3490             pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
3491             *dst = pixel;
3492             posx += incx;
3493             ++dst;
3494         }
3495         posy += incy;
3496         info->dst += info->dst_pitch;
3497     }
3498 }
3499
3500 static void SDL_Blit_ARGB8888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info)
3501 {
3502     const int flags = info->flags;
3503     const Uint32 modulateR = info->r;
3504     const Uint32 modulateG = info->g;
3505     const Uint32 modulateB = info->b;
3506     const Uint32 modulateA = info->a;
3507     Uint32 srcpixel;
3508     Uint32 srcR, srcG, srcB, srcA;
3509     Uint32 dstpixel;
3510     Uint32 dstR, dstG, dstB, dstA;
3511
3512     while (info->dst_h--) {
3513         Uint32 *src = (Uint32 *)info->src;
3514         Uint32 *dst = (Uint32 *)info->dst;
3515         int n = info->dst_w;
3516         while (n--) {
3517             srcpixel = *src;
3518             srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
3519             dstpixel = *dst;
3520             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
3521             if (flags & SDL_COPY_MODULATE_COLOR) {
3522                 srcR = (srcR * modulateR) / 255;
3523                 srcG = (srcG * modulateG) / 255;
3524                 srcB = (srcB * modulateB) / 255;
3525             }
3526             if (flags & SDL_COPY_MODULATE_ALPHA) {
3527                 srcA = (srcA * modulateA) / 255;
3528             }
3529             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
3530                 /* This goes away if we ever use premultiplied alpha */
3531                 if (srcA < 255) {
3532                     srcR = (srcR * srcA) / 255;
3533                     srcG = (srcG * srcA) / 255;
3534                     srcB = (srcB * srcA) / 255;
3535                 }
3536             }
3537             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
3538             case SDL_COPY_BLEND:
3539                 dstR = srcR + ((255 - srcA) * dstR) / 255;
3540                 dstG = srcG + ((255 - srcA) * dstG) / 255;
3541                 dstB = srcB + ((255 - srcA) * dstB) / 255;
3542                 dstA = srcA + ((255 - srcA) * dstA) / 255;
3543                 break;
3544             case SDL_COPY_ADD:
3545                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
3546                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
3547                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
3548                 break;
3549             case SDL_COPY_MOD:
3550                 dstR = (srcR * dstR) / 255;
3551                 dstG = (srcG * dstG) / 255;
3552                 dstB = (srcB * dstB) / 255;
3553                 break;
3554             }
3555             dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
3556             *dst = dstpixel;
3557             ++src;
3558             ++dst;
3559         }
3560         info->src += info->src_pitch;
3561         info->dst += info->dst_pitch;
3562     }
3563 }
3564
3565 static void SDL_Blit_ARGB8888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info)
3566 {
3567     const int flags = info->flags;
3568     const Uint32 modulateR = info->r;
3569     const Uint32 modulateG = info->g;
3570     const Uint32 modulateB = info->b;
3571     const Uint32 modulateA = info->a;
3572     Uint32 srcpixel;
3573     Uint32 srcR, srcG, srcB, srcA;
3574     Uint32 dstpixel;
3575     Uint32 dstR, dstG, dstB, dstA;
3576     int srcy, srcx;
3577     int posy, posx;
3578     int incy, incx;
3579
3580     srcy = 0;
3581     posy = 0;
3582     incy = (info->src_h << 16) / info->dst_h;
3583     incx = (info->src_w << 16) / info->dst_w;
3584
3585     while (info->dst_h--) {
3586         Uint32 *src = 0;
3587         Uint32 *dst = (Uint32 *)info->dst;
3588         int n = info->dst_w;
3589         srcx = -1;
3590         posx = 0x10000L;
3591         while (posy >= 0x10000L) {
3592             ++srcy;
3593             posy -= 0x10000L;
3594         }
3595         while (n--) {
3596             if (posx >= 0x10000L) {
3597                 while (posx >= 0x10000L) {
3598                     ++srcx;
3599                     posx -= 0x10000L;
3600                 }
3601                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
3602             }
3603             srcpixel = *src;
3604             srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
3605             dstpixel = *dst;
3606             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
3607             if (flags & SDL_COPY_MODULATE_COLOR) {
3608                 srcR = (srcR * modulateR) / 255;
3609                 srcG = (srcG * modulateG) / 255;
3610                 srcB = (srcB * modulateB) / 255;
3611             }
3612             if (flags & SDL_COPY_MODULATE_ALPHA) {
3613                 srcA = (srcA * modulateA) / 255;
3614             }
3615             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
3616                 /* This goes away if we ever use premultiplied alpha */
3617                 if (srcA < 255) {
3618                     srcR = (srcR * srcA) / 255;
3619                     srcG = (srcG * srcA) / 255;
3620                     srcB = (srcB * srcA) / 255;
3621                 }
3622             }
3623             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
3624             case SDL_COPY_BLEND:
3625                 dstR = srcR + ((255 - srcA) * dstR) / 255;
3626                 dstG = srcG + ((255 - srcA) * dstG) / 255;
3627                 dstB = srcB + ((255 - srcA) * dstB) / 255;
3628                 dstA = srcA + ((255 - srcA) * dstA) / 255;
3629                 break;
3630             case SDL_COPY_ADD:
3631                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
3632                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
3633                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
3634                 break;
3635             case SDL_COPY_MOD:
3636                 dstR = (srcR * dstR) / 255;
3637                 dstG = (srcG * dstG) / 255;
3638                 dstB = (srcB * dstB) / 255;
3639                 break;
3640             }
3641             dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
3642             *dst = dstpixel;
3643             posx += incx;
3644             ++dst;
3645         }
3646         posy += incy;
3647         info->dst += info->dst_pitch;
3648     }
3649 }
3650
3651 static void SDL_Blit_RGBA8888_RGB888_Scale(SDL_BlitInfo *info)
3652 {
3653     Uint32 pixel;
3654     Uint32 R, G, B;
3655     int srcy, srcx;
3656     int posy, posx;
3657     int incy, incx;
3658
3659     srcy = 0;
3660     posy = 0;
3661     incy = (info->src_h << 16) / info->dst_h;
3662     incx = (info->src_w << 16) / info->dst_w;
3663
3664     while (info->dst_h--) {
3665         Uint32 *src = 0;
3666         Uint32 *dst = (Uint32 *)info->dst;
3667         int n = info->dst_w;
3668         srcx = -1;
3669         posx = 0x10000L;
3670         while (posy >= 0x10000L) {
3671             ++srcy;
3672             posy -= 0x10000L;
3673         }
3674         while (n--) {
3675             if (posx >= 0x10000L) {
3676                 while (posx >= 0x10000L) {
3677                     ++srcx;
3678                     posx -= 0x10000L;
3679                 }
3680                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
3681             }
3682             pixel = *src;
3683             R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8);
3684             pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
3685             *dst = pixel;
3686             posx += incx;
3687             ++dst;
3688         }
3689         posy += incy;
3690         info->dst += info->dst_pitch;
3691     }
3692 }
3693
3694 static void SDL_Blit_RGBA8888_RGB888_Blend(SDL_BlitInfo *info)
3695 {
3696     const int flags = info->flags;
3697     Uint32 srcpixel;
3698     Uint32 srcR, srcG, srcB, srcA;
3699     Uint32 dstpixel;
3700     Uint32 dstR, dstG, dstB;
3701
3702     while (info->dst_h--) {
3703         Uint32 *src = (Uint32 *)info->src;
3704         Uint32 *dst = (Uint32 *)info->dst;
3705         int n = info->dst_w;
3706         while (n--) {
3707             srcpixel = *src;
3708             srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
3709             dstpixel = *dst;
3710             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
3711             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
3712                 /* This goes away if we ever use premultiplied alpha */
3713                 if (srcA < 255) {
3714                     srcR = (srcR * srcA) / 255;
3715                     srcG = (srcG * srcA) / 255;
3716                     srcB = (srcB * srcA) / 255;
3717                 }
3718             }
3719             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
3720             case SDL_COPY_BLEND:
3721                 dstR = srcR + ((255 - srcA) * dstR) / 255;
3722                 dstG = srcG + ((255 - srcA) * dstG) / 255;
3723                 dstB = srcB + ((255 - srcA) * dstB) / 255;
3724                 break;
3725             case SDL_COPY_ADD:
3726                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
3727                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
3728                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
3729                 break;
3730             case SDL_COPY_MOD:
3731                 dstR = (srcR * dstR) / 255;
3732                 dstG = (srcG * dstG) / 255;
3733                 dstB = (srcB * dstB) / 255;
3734                 break;
3735             }
3736             dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
3737             *dst = dstpixel;
3738             ++src;
3739             ++dst;
3740         }
3741         info->src += info->src_pitch;
3742         info->dst += info->dst_pitch;
3743     }
3744 }
3745
3746 static void SDL_Blit_RGBA8888_RGB888_Blend_Scale(SDL_BlitInfo *info)
3747 {
3748     const int flags = info->flags;
3749     Uint32 srcpixel;
3750     Uint32 srcR, srcG, srcB, srcA;
3751     Uint32 dstpixel;
3752     Uint32 dstR, dstG, dstB;
3753     int srcy, srcx;
3754     int posy, posx;
3755     int incy, incx;
3756
3757     srcy = 0;
3758     posy = 0;
3759     incy = (info->src_h << 16) / info->dst_h;
3760     incx = (info->src_w << 16) / info->dst_w;
3761
3762     while (info->dst_h--) {
3763         Uint32 *src = 0;
3764         Uint32 *dst = (Uint32 *)info->dst;
3765         int n = info->dst_w;
3766         srcx = -1;
3767         posx = 0x10000L;
3768         while (posy >= 0x10000L) {
3769             ++srcy;
3770             posy -= 0x10000L;
3771         }
3772         while (n--) {
3773             if (posx >= 0x10000L) {
3774                 while (posx >= 0x10000L) {
3775                     ++srcx;
3776                     posx -= 0x10000L;
3777                 }
3778                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
3779             }
3780             srcpixel = *src;
3781             srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
3782             dstpixel = *dst;
3783             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
3784             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
3785                 /* This goes away if we ever use premultiplied alpha */
3786                 if (srcA < 255) {
3787                     srcR = (srcR * srcA) / 255;
3788                     srcG = (srcG * srcA) / 255;
3789                     srcB = (srcB * srcA) / 255;
3790                 }
3791             }
3792             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
3793             case SDL_COPY_BLEND:
3794                 dstR = srcR + ((255 - srcA) * dstR) / 255;
3795                 dstG = srcG + ((255 - srcA) * dstG) / 255;
3796                 dstB = srcB + ((255 - srcA) * dstB) / 255;
3797                 break;
3798             case SDL_COPY_ADD:
3799                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
3800                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
3801                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
3802                 break;
3803             case SDL_COPY_MOD:
3804                 dstR = (srcR * dstR) / 255;
3805                 dstG = (srcG * dstG) / 255;
3806                 dstB = (srcB * dstB) / 255;
3807                 break;
3808             }
3809             dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
3810             *dst = dstpixel;
3811             posx += incx;
3812             ++dst;
3813         }
3814         posy += incy;
3815         info->dst += info->dst_pitch;
3816     }
3817 }
3818
3819 static void SDL_Blit_RGBA8888_RGB888_Modulate(SDL_BlitInfo *info)
3820 {
3821     const int flags = info->flags;
3822     const Uint32 modulateR = info->r;
3823     const Uint32 modulateG = info->g;
3824     const Uint32 modulateB = info->b;
3825     Uint32 pixel;
3826     Uint32 R, G, B;
3827
3828     while (info->dst_h--) {
3829         Uint32 *src = (Uint32 *)info->src;
3830         Uint32 *dst = (Uint32 *)info->dst;
3831         int n = info->dst_w;
3832         while (n--) {
3833             pixel = *src;
3834             R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8);
3835             if (flags & SDL_COPY_MODULATE_COLOR) {
3836                 R = (R * modulateR) / 255;
3837                 G = (G * modulateG) / 255;
3838                 B = (B * modulateB) / 255;
3839             }
3840             pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
3841             *dst = pixel;
3842             ++src;
3843             ++dst;
3844         }
3845         info->src += info->src_pitch;
3846         info->dst += info->dst_pitch;
3847     }
3848 }
3849
3850 static void SDL_Blit_RGBA8888_RGB888_Modulate_Scale(SDL_BlitInfo *info)
3851 {
3852     const int flags = info->flags;
3853     const Uint32 modulateR = info->r;
3854     const Uint32 modulateG = info->g;
3855     const Uint32 modulateB = info->b;
3856     Uint32 pixel;
3857     Uint32 R, G, B;
3858     int srcy, srcx;
3859     int posy, posx;
3860     int incy, incx;
3861
3862     srcy = 0;
3863     posy = 0;
3864     incy = (info->src_h << 16) / info->dst_h;
3865     incx = (info->src_w << 16) / info->dst_w;
3866
3867     while (info->dst_h--) {
3868         Uint32 *src = 0;
3869         Uint32 *dst = (Uint32 *)info->dst;
3870         int n = info->dst_w;
3871         srcx = -1;
3872         posx = 0x10000L;
3873         while (posy >= 0x10000L) {
3874             ++srcy;
3875             posy -= 0x10000L;
3876         }
3877         while (n--) {
3878             if (posx >= 0x10000L) {
3879                 while (posx >= 0x10000L) {
3880                     ++srcx;
3881                     posx -= 0x10000L;
3882                 }
3883                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
3884             }
3885             pixel = *src;
3886             R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8);
3887             if (flags & SDL_COPY_MODULATE_COLOR) {
3888                 R = (R * modulateR) / 255;
3889                 G = (G * modulateG) / 255;
3890                 B = (B * modulateB) / 255;
3891             }
3892             pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
3893             *dst = pixel;
3894             posx += incx;
3895             ++dst;
3896         }
3897         posy += incy;
3898         info->dst += info->dst_pitch;
3899     }
3900 }
3901
3902 static void SDL_Blit_RGBA8888_RGB888_Modulate_Blend(SDL_BlitInfo *info)
3903 {
3904     const int flags = info->flags;
3905     const Uint32 modulateR = info->r;
3906     const Uint32 modulateG = info->g;
3907     const Uint32 modulateB = info->b;
3908     const Uint32 modulateA = info->a;
3909     Uint32 srcpixel;
3910     Uint32 srcR, srcG, srcB, srcA;
3911     Uint32 dstpixel;
3912     Uint32 dstR, dstG, dstB;
3913
3914     while (info->dst_h--) {
3915         Uint32 *src = (Uint32 *)info->src;
3916         Uint32 *dst = (Uint32 *)info->dst;
3917         int n = info->dst_w;
3918         while (n--) {
3919             srcpixel = *src;
3920             srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
3921             dstpixel = *dst;
3922             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
3923             if (flags & SDL_COPY_MODULATE_COLOR) {
3924                 srcR = (srcR * modulateR) / 255;
3925                 srcG = (srcG * modulateG) / 255;
3926                 srcB = (srcB * modulateB) / 255;
3927             }
3928             if (flags & SDL_COPY_MODULATE_ALPHA) {
3929                 srcA = (srcA * modulateA) / 255;
3930             }
3931             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
3932                 /* This goes away if we ever use premultiplied alpha */
3933                 if (srcA < 255) {
3934                     srcR = (srcR * srcA) / 255;
3935                     srcG = (srcG * srcA) / 255;
3936                     srcB = (srcB * srcA) / 255;
3937                 }
3938             }
3939             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
3940             case SDL_COPY_BLEND:
3941                 dstR = srcR + ((255 - srcA) * dstR) / 255;
3942                 dstG = srcG + ((255 - srcA) * dstG) / 255;
3943                 dstB = srcB + ((255 - srcA) * dstB) / 255;
3944                 break;
3945             case SDL_COPY_ADD:
3946                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
3947                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
3948                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
3949                 break;
3950             case SDL_COPY_MOD:
3951                 dstR = (srcR * dstR) / 255;
3952                 dstG = (srcG * dstG) / 255;
3953                 dstB = (srcB * dstB) / 255;
3954                 break;
3955             }
3956             dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
3957             *dst = dstpixel;
3958             ++src;
3959             ++dst;
3960         }
3961         info->src += info->src_pitch;
3962         info->dst += info->dst_pitch;
3963     }
3964 }
3965
3966 static void SDL_Blit_RGBA8888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info)
3967 {
3968     const int flags = info->flags;
3969     const Uint32 modulateR = info->r;
3970     const Uint32 modulateG = info->g;
3971     const Uint32 modulateB = info->b;
3972     const Uint32 modulateA = info->a;
3973     Uint32 srcpixel;
3974     Uint32 srcR, srcG, srcB, srcA;
3975     Uint32 dstpixel;
3976     Uint32 dstR, dstG, dstB;
3977     int srcy, srcx;
3978     int posy, posx;
3979     int incy, incx;
3980
3981     srcy = 0;
3982     posy = 0;
3983     incy = (info->src_h << 16) / info->dst_h;
3984     incx = (info->src_w << 16) / info->dst_w;
3985
3986     while (info->dst_h--) {
3987         Uint32 *src = 0;
3988         Uint32 *dst = (Uint32 *)info->dst;
3989         int n = info->dst_w;
3990         srcx = -1;
3991         posx = 0x10000L;
3992         while (posy >= 0x10000L) {
3993             ++srcy;
3994             posy -= 0x10000L;
3995         }
3996         while (n--) {
3997             if (posx >= 0x10000L) {
3998                 while (posx >= 0x10000L) {
3999                     ++srcx;
4000                     posx -= 0x10000L;
4001                 }
4002                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
4003             }
4004             srcpixel = *src;
4005             srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
4006             dstpixel = *dst;
4007             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
4008             if (flags & SDL_COPY_MODULATE_COLOR) {
4009                 srcR = (srcR * modulateR) / 255;
4010                 srcG = (srcG * modulateG) / 255;
4011                 srcB = (srcB * modulateB) / 255;
4012             }
4013             if (flags & SDL_COPY_MODULATE_ALPHA) {
4014                 srcA = (srcA * modulateA) / 255;
4015             }
4016             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
4017                 /* This goes away if we ever use premultiplied alpha */
4018                 if (srcA < 255) {
4019                     srcR = (srcR * srcA) / 255;
4020                     srcG = (srcG * srcA) / 255;
4021                     srcB = (srcB * srcA) / 255;
4022                 }
4023             }
4024             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
4025             case SDL_COPY_BLEND:
4026                 dstR = srcR + ((255 - srcA) * dstR) / 255;
4027                 dstG = srcG + ((255 - srcA) * dstG) / 255;
4028                 dstB = srcB + ((255 - srcA) * dstB) / 255;
4029                 break;
4030             case SDL_COPY_ADD:
4031                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
4032                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
4033                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
4034                 break;
4035             case SDL_COPY_MOD:
4036                 dstR = (srcR * dstR) / 255;
4037                 dstG = (srcG * dstG) / 255;
4038                 dstB = (srcB * dstB) / 255;
4039                 break;
4040             }
4041             dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
4042             *dst = dstpixel;
4043             posx += incx;
4044             ++dst;
4045         }
4046         posy += incy;
4047         info->dst += info->dst_pitch;
4048     }
4049 }
4050
4051 static void SDL_Blit_RGBA8888_BGR888_Scale(SDL_BlitInfo *info)
4052 {
4053     Uint32 pixel;
4054     Uint32 R, G, B;
4055     int srcy, srcx;
4056     int posy, posx;
4057     int incy, incx;
4058
4059     srcy = 0;
4060     posy = 0;
4061     incy = (info->src_h << 16) / info->dst_h;
4062     incx = (info->src_w << 16) / info->dst_w;
4063
4064     while (info->dst_h--) {
4065         Uint32 *src = 0;
4066         Uint32 *dst = (Uint32 *)info->dst;
4067         int n = info->dst_w;
4068         srcx = -1;
4069         posx = 0x10000L;
4070         while (posy >= 0x10000L) {
4071             ++srcy;
4072             posy -= 0x10000L;
4073         }
4074         while (n--) {
4075             if (posx >= 0x10000L) {
4076                 while (posx >= 0x10000L) {
4077                     ++srcx;
4078                     posx -= 0x10000L;
4079                 }
4080                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
4081             }
4082             pixel = *src;
4083             R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8);
4084             pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
4085             *dst = pixel;
4086             posx += incx;
4087             ++dst;
4088         }
4089         posy += incy;
4090         info->dst += info->dst_pitch;
4091     }
4092 }
4093
4094 static void SDL_Blit_RGBA8888_BGR888_Blend(SDL_BlitInfo *info)
4095 {
4096     const int flags = info->flags;
4097     Uint32 srcpixel;
4098     Uint32 srcR, srcG, srcB, srcA;
4099     Uint32 dstpixel;
4100     Uint32 dstR, dstG, dstB;
4101
4102     while (info->dst_h--) {
4103         Uint32 *src = (Uint32 *)info->src;
4104         Uint32 *dst = (Uint32 *)info->dst;
4105         int n = info->dst_w;
4106         while (n--) {
4107             srcpixel = *src;
4108             srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
4109             dstpixel = *dst;
4110             dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
4111             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
4112                 /* This goes away if we ever use premultiplied alpha */
4113                 if (srcA < 255) {
4114                     srcR = (srcR * srcA) / 255;
4115                     srcG = (srcG * srcA) / 255;
4116                     srcB = (srcB * srcA) / 255;
4117                 }
4118             }
4119             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
4120             case SDL_COPY_BLEND:
4121                 dstR = srcR + ((255 - srcA) * dstR) / 255;
4122                 dstG = srcG + ((255 - srcA) * dstG) / 255;
4123                 dstB = srcB + ((255 - srcA) * dstB) / 255;
4124                 break;
4125             case SDL_COPY_ADD:
4126                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
4127                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
4128                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
4129                 break;
4130             case SDL_COPY_MOD:
4131                 dstR = (srcR * dstR) / 255;
4132                 dstG = (srcG * dstG) / 255;
4133                 dstB = (srcB * dstB) / 255;
4134                 break;
4135             }
4136             dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
4137             *dst = dstpixel;
4138             ++src;
4139             ++dst;
4140         }
4141         info->src += info->src_pitch;
4142         info->dst += info->dst_pitch;
4143     }
4144 }
4145
4146 static void SDL_Blit_RGBA8888_BGR888_Blend_Scale(SDL_BlitInfo *info)
4147 {
4148     const int flags = info->flags;
4149     Uint32 srcpixel;
4150     Uint32 srcR, srcG, srcB, srcA;
4151     Uint32 dstpixel;
4152     Uint32 dstR, dstG, dstB;
4153     int srcy, srcx;
4154     int posy, posx;
4155     int incy, incx;
4156
4157     srcy = 0;
4158     posy = 0;
4159     incy = (info->src_h << 16) / info->dst_h;
4160     incx = (info->src_w << 16) / info->dst_w;
4161
4162     while (info->dst_h--) {
4163         Uint32 *src = 0;
4164         Uint32 *dst = (Uint32 *)info->dst;
4165         int n = info->dst_w;
4166         srcx = -1;
4167         posx = 0x10000L;
4168         while (posy >= 0x10000L) {
4169             ++srcy;
4170             posy -= 0x10000L;
4171         }
4172         while (n--) {
4173             if (posx >= 0x10000L) {
4174                 while (posx >= 0x10000L) {
4175                     ++srcx;
4176                     posx -= 0x10000L;
4177                 }
4178                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
4179             }
4180             srcpixel = *src;
4181             srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
4182             dstpixel = *dst;
4183             dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
4184             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
4185                 /* This goes away if we ever use premultiplied alpha */
4186                 if (srcA < 255) {
4187                     srcR = (srcR * srcA) / 255;
4188                     srcG = (srcG * srcA) / 255;
4189                     srcB = (srcB * srcA) / 255;
4190                 }
4191             }
4192             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
4193             case SDL_COPY_BLEND:
4194                 dstR = srcR + ((255 - srcA) * dstR) / 255;
4195                 dstG = srcG + ((255 - srcA) * dstG) / 255;
4196                 dstB = srcB + ((255 - srcA) * dstB) / 255;
4197                 break;
4198             case SDL_COPY_ADD:
4199                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
4200                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
4201                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
4202                 break;
4203             case SDL_COPY_MOD:
4204                 dstR = (srcR * dstR) / 255;
4205                 dstG = (srcG * dstG) / 255;
4206                 dstB = (srcB * dstB) / 255;
4207                 break;
4208             }
4209             dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
4210             *dst = dstpixel;
4211             posx += incx;
4212             ++dst;
4213         }
4214         posy += incy;
4215         info->dst += info->dst_pitch;
4216     }
4217 }
4218
4219 static void SDL_Blit_RGBA8888_BGR888_Modulate(SDL_BlitInfo *info)
4220 {
4221     const int flags = info->flags;
4222     const Uint32 modulateR = info->r;
4223     const Uint32 modulateG = info->g;
4224     const Uint32 modulateB = info->b;
4225     Uint32 pixel;
4226     Uint32 R, G, B;
4227
4228     while (info->dst_h--) {
4229         Uint32 *src = (Uint32 *)info->src;
4230         Uint32 *dst = (Uint32 *)info->dst;
4231         int n = info->dst_w;
4232         while (n--) {
4233             pixel = *src;
4234             R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8);
4235             if (flags & SDL_COPY_MODULATE_COLOR) {
4236                 R = (R * modulateR) / 255;
4237                 G = (G * modulateG) / 255;
4238                 B = (B * modulateB) / 255;
4239             }
4240             pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
4241             *dst = pixel;
4242             ++src;
4243             ++dst;
4244         }
4245         info->src += info->src_pitch;
4246         info->dst += info->dst_pitch;
4247     }
4248 }
4249
4250 static void SDL_Blit_RGBA8888_BGR888_Modulate_Scale(SDL_BlitInfo *info)
4251 {
4252     const int flags = info->flags;
4253     const Uint32 modulateR = info->r;
4254     const Uint32 modulateG = info->g;
4255     const Uint32 modulateB = info->b;
4256     Uint32 pixel;
4257     Uint32 R, G, B;
4258     int srcy, srcx;
4259     int posy, posx;
4260     int incy, incx;
4261
4262     srcy = 0;
4263     posy = 0;
4264     incy = (info->src_h << 16) / info->dst_h;
4265     incx = (info->src_w << 16) / info->dst_w;
4266
4267     while (info->dst_h--) {
4268         Uint32 *src = 0;
4269         Uint32 *dst = (Uint32 *)info->dst;
4270         int n = info->dst_w;
4271         srcx = -1;
4272         posx = 0x10000L;
4273         while (posy >= 0x10000L) {
4274             ++srcy;
4275             posy -= 0x10000L;
4276         }
4277         while (n--) {
4278             if (posx >= 0x10000L) {
4279                 while (posx >= 0x10000L) {
4280                     ++srcx;
4281                     posx -= 0x10000L;
4282                 }
4283                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
4284             }
4285             pixel = *src;
4286             R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8);
4287             if (flags & SDL_COPY_MODULATE_COLOR) {
4288                 R = (R * modulateR) / 255;
4289                 G = (G * modulateG) / 255;
4290                 B = (B * modulateB) / 255;
4291             }
4292             pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
4293             *dst = pixel;
4294             posx += incx;
4295             ++dst;
4296         }
4297         posy += incy;
4298         info->dst += info->dst_pitch;
4299     }
4300 }
4301
4302 static void SDL_Blit_RGBA8888_BGR888_Modulate_Blend(SDL_BlitInfo *info)
4303 {
4304     const int flags = info->flags;
4305     const Uint32 modulateR = info->r;
4306     const Uint32 modulateG = info->g;
4307     const Uint32 modulateB = info->b;
4308     const Uint32 modulateA = info->a;
4309     Uint32 srcpixel;
4310     Uint32 srcR, srcG, srcB, srcA;
4311     Uint32 dstpixel;
4312     Uint32 dstR, dstG, dstB;
4313
4314     while (info->dst_h--) {
4315         Uint32 *src = (Uint32 *)info->src;
4316         Uint32 *dst = (Uint32 *)info->dst;
4317         int n = info->dst_w;
4318         while (n--) {
4319             srcpixel = *src;
4320             srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
4321             dstpixel = *dst;
4322             dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
4323             if (flags & SDL_COPY_MODULATE_COLOR) {
4324                 srcR = (srcR * modulateR) / 255;
4325                 srcG = (srcG * modulateG) / 255;
4326                 srcB = (srcB * modulateB) / 255;
4327             }
4328             if (flags & SDL_COPY_MODULATE_ALPHA) {
4329                 srcA = (srcA * modulateA) / 255;
4330             }
4331             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
4332                 /* This goes away if we ever use premultiplied alpha */
4333                 if (srcA < 255) {
4334                     srcR = (srcR * srcA) / 255;
4335                     srcG = (srcG * srcA) / 255;
4336                     srcB = (srcB * srcA) / 255;
4337                 }
4338             }
4339             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
4340             case SDL_COPY_BLEND:
4341                 dstR = srcR + ((255 - srcA) * dstR) / 255;
4342                 dstG = srcG + ((255 - srcA) * dstG) / 255;
4343                 dstB = srcB + ((255 - srcA) * dstB) / 255;
4344                 break;
4345             case SDL_COPY_ADD:
4346                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
4347                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
4348                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
4349                 break;
4350             case SDL_COPY_MOD:
4351                 dstR = (srcR * dstR) / 255;
4352                 dstG = (srcG * dstG) / 255;
4353                 dstB = (srcB * dstB) / 255;
4354                 break;
4355             }
4356             dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
4357             *dst = dstpixel;
4358             ++src;
4359             ++dst;
4360         }
4361         info->src += info->src_pitch;
4362         info->dst += info->dst_pitch;
4363     }
4364 }
4365
4366 static void SDL_Blit_RGBA8888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info)
4367 {
4368     const int flags = info->flags;
4369     const Uint32 modulateR = info->r;
4370     const Uint32 modulateG = info->g;
4371     const Uint32 modulateB = info->b;
4372     const Uint32 modulateA = info->a;
4373     Uint32 srcpixel;
4374     Uint32 srcR, srcG, srcB, srcA;
4375     Uint32 dstpixel;
4376     Uint32 dstR, dstG, dstB;
4377     int srcy, srcx;
4378     int posy, posx;
4379     int incy, incx;
4380
4381     srcy = 0;
4382     posy = 0;
4383     incy = (info->src_h << 16) / info->dst_h;
4384     incx = (info->src_w << 16) / info->dst_w;
4385
4386     while (info->dst_h--) {
4387         Uint32 *src = 0;
4388         Uint32 *dst = (Uint32 *)info->dst;
4389         int n = info->dst_w;
4390         srcx = -1;
4391         posx = 0x10000L;
4392         while (posy >= 0x10000L) {
4393             ++srcy;
4394             posy -= 0x10000L;
4395         }
4396         while (n--) {
4397             if (posx >= 0x10000L) {
4398                 while (posx >= 0x10000L) {
4399                     ++srcx;
4400                     posx -= 0x10000L;
4401                 }
4402                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
4403             }
4404             srcpixel = *src;
4405             srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
4406             dstpixel = *dst;
4407             dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
4408             if (flags & SDL_COPY_MODULATE_COLOR) {
4409                 srcR = (srcR * modulateR) / 255;
4410                 srcG = (srcG * modulateG) / 255;
4411                 srcB = (srcB * modulateB) / 255;
4412             }
4413             if (flags & SDL_COPY_MODULATE_ALPHA) {
4414                 srcA = (srcA * modulateA) / 255;
4415             }
4416             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
4417                 /* This goes away if we ever use premultiplied alpha */
4418                 if (srcA < 255) {
4419                     srcR = (srcR * srcA) / 255;
4420                     srcG = (srcG * srcA) / 255;
4421                     srcB = (srcB * srcA) / 255;
4422                 }
4423             }
4424             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
4425             case SDL_COPY_BLEND:
4426                 dstR = srcR + ((255 - srcA) * dstR) / 255;
4427                 dstG = srcG + ((255 - srcA) * dstG) / 255;
4428                 dstB = srcB + ((255 - srcA) * dstB) / 255;
4429                 break;
4430             case SDL_COPY_ADD:
4431                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
4432                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
4433                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
4434                 break;
4435             case SDL_COPY_MOD:
4436                 dstR = (srcR * dstR) / 255;
4437                 dstG = (srcG * dstG) / 255;
4438                 dstB = (srcB * dstB) / 255;
4439                 break;
4440             }
4441             dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
4442             *dst = dstpixel;
4443             posx += incx;
4444             ++dst;
4445         }
4446         posy += incy;
4447         info->dst += info->dst_pitch;
4448     }
4449 }
4450
4451 static void SDL_Blit_RGBA8888_ARGB8888_Scale(SDL_BlitInfo *info)
4452 {
4453     Uint32 pixel;
4454     Uint32 R, G, B, A;
4455     int srcy, srcx;
4456     int posy, posx;
4457     int incy, incx;
4458
4459     srcy = 0;
4460     posy = 0;
4461     incy = (info->src_h << 16) / info->dst_h;
4462     incx = (info->src_w << 16) / info->dst_w;
4463
4464     while (info->dst_h--) {
4465         Uint32 *src = 0;
4466         Uint32 *dst = (Uint32 *)info->dst;
4467         int n = info->dst_w;
4468         srcx = -1;
4469         posx = 0x10000L;
4470         while (posy >= 0x10000L) {
4471             ++srcy;
4472             posy -= 0x10000L;
4473         }
4474         while (n--) {
4475             if (posx >= 0x10000L) {
4476                 while (posx >= 0x10000L) {
4477                     ++srcx;
4478                     posx -= 0x10000L;
4479                 }
4480                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
4481             }
4482             pixel = *src;
4483             R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8); A = (Uint8)pixel;
4484             pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
4485             *dst = pixel;
4486             posx += incx;
4487             ++dst;
4488         }
4489         posy += incy;
4490         info->dst += info->dst_pitch;
4491     }
4492 }
4493
4494 static void SDL_Blit_RGBA8888_ARGB8888_Blend(SDL_BlitInfo *info)
4495 {
4496     const int flags = info->flags;
4497     Uint32 srcpixel;
4498     Uint32 srcR, srcG, srcB, srcA;
4499     Uint32 dstpixel;
4500     Uint32 dstR, dstG, dstB, dstA;
4501
4502     while (info->dst_h--) {
4503         Uint32 *src = (Uint32 *)info->src;
4504         Uint32 *dst = (Uint32 *)info->dst;
4505         int n = info->dst_w;
4506         while (n--) {
4507             srcpixel = *src;
4508             srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
4509             dstpixel = *dst;
4510             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
4511             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
4512                 /* This goes away if we ever use premultiplied alpha */
4513                 if (srcA < 255) {
4514                     srcR = (srcR * srcA) / 255;
4515                     srcG = (srcG * srcA) / 255;
4516                     srcB = (srcB * srcA) / 255;
4517                 }
4518             }
4519             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
4520             case SDL_COPY_BLEND:
4521                 dstR = srcR + ((255 - srcA) * dstR) / 255;
4522                 dstG = srcG + ((255 - srcA) * dstG) / 255;
4523                 dstB = srcB + ((255 - srcA) * dstB) / 255;
4524                 dstA = srcA + ((255 - srcA) * dstA) / 255;
4525                 break;
4526             case SDL_COPY_ADD:
4527                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
4528                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
4529                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
4530                 break;
4531             case SDL_COPY_MOD:
4532                 dstR = (srcR * dstR) / 255;
4533                 dstG = (srcG * dstG) / 255;
4534                 dstB = (srcB * dstB) / 255;
4535                 break;
4536             }
4537             dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
4538             *dst = dstpixel;
4539             ++src;
4540             ++dst;
4541         }
4542         info->src += info->src_pitch;
4543         info->dst += info->dst_pitch;
4544     }
4545 }
4546
4547 static void SDL_Blit_RGBA8888_ARGB8888_Blend_Scale(SDL_BlitInfo *info)
4548 {
4549     const int flags = info->flags;
4550     Uint32 srcpixel;
4551     Uint32 srcR, srcG, srcB, srcA;
4552     Uint32 dstpixel;
4553     Uint32 dstR, dstG, dstB, dstA;
4554     int srcy, srcx;
4555     int posy, posx;
4556     int incy, incx;
4557
4558     srcy = 0;
4559     posy = 0;
4560     incy = (info->src_h << 16) / info->dst_h;
4561     incx = (info->src_w << 16) / info->dst_w;
4562
4563     while (info->dst_h--) {
4564         Uint32 *src = 0;
4565         Uint32 *dst = (Uint32 *)info->dst;
4566         int n = info->dst_w;
4567         srcx = -1;
4568         posx = 0x10000L;
4569         while (posy >= 0x10000L) {
4570             ++srcy;
4571             posy -= 0x10000L;
4572         }
4573         while (n--) {
4574             if (posx >= 0x10000L) {
4575                 while (posx >= 0x10000L) {
4576                     ++srcx;
4577                     posx -= 0x10000L;
4578                 }
4579                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
4580             }
4581             srcpixel = *src;
4582             srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
4583             dstpixel = *dst;
4584             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
4585             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
4586                 /* This goes away if we ever use premultiplied alpha */
4587                 if (srcA < 255) {
4588                     srcR = (srcR * srcA) / 255;
4589                     srcG = (srcG * srcA) / 255;
4590                     srcB = (srcB * srcA) / 255;
4591                 }
4592             }
4593             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
4594             case SDL_COPY_BLEND:
4595                 dstR = srcR + ((255 - srcA) * dstR) / 255;
4596                 dstG = srcG + ((255 - srcA) * dstG) / 255;
4597                 dstB = srcB + ((255 - srcA) * dstB) / 255;
4598                 dstA = srcA + ((255 - srcA) * dstA) / 255;
4599                 break;
4600             case SDL_COPY_ADD:
4601                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
4602                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
4603                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
4604                 break;
4605             case SDL_COPY_MOD:
4606                 dstR = (srcR * dstR) / 255;
4607                 dstG = (srcG * dstG) / 255;
4608                 dstB = (srcB * dstB) / 255;
4609                 break;
4610             }
4611             dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
4612             *dst = dstpixel;
4613             posx += incx;
4614             ++dst;
4615         }
4616         posy += incy;
4617         info->dst += info->dst_pitch;
4618     }
4619 }
4620
4621 static void SDL_Blit_RGBA8888_ARGB8888_Modulate(SDL_BlitInfo *info)
4622 {
4623     const int flags = info->flags;
4624     const Uint32 modulateR = info->r;
4625     const Uint32 modulateG = info->g;
4626     const Uint32 modulateB = info->b;
4627     const Uint32 modulateA = info->a;
4628     Uint32 pixel;
4629     Uint32 R, G, B, A;
4630
4631     while (info->dst_h--) {
4632         Uint32 *src = (Uint32 *)info->src;
4633         Uint32 *dst = (Uint32 *)info->dst;
4634         int n = info->dst_w;
4635         while (n--) {
4636             pixel = *src;
4637             R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8); A = (Uint8)pixel;
4638             if (flags & SDL_COPY_MODULATE_COLOR) {
4639                 R = (R * modulateR) / 255;
4640                 G = (G * modulateG) / 255;
4641                 B = (B * modulateB) / 255;
4642             }
4643             if (flags & SDL_COPY_MODULATE_ALPHA) {
4644                 A = (A * modulateA) / 255;
4645             }
4646             pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
4647             *dst = pixel;
4648             ++src;
4649             ++dst;
4650         }
4651         info->src += info->src_pitch;
4652         info->dst += info->dst_pitch;
4653     }
4654 }
4655
4656 static void SDL_Blit_RGBA8888_ARGB8888_Modulate_Scale(SDL_BlitInfo *info)
4657 {
4658     const int flags = info->flags;
4659     const Uint32 modulateR = info->r;
4660     const Uint32 modulateG = info->g;
4661     const Uint32 modulateB = info->b;
4662     const Uint32 modulateA = info->a;
4663     Uint32 pixel;
4664     Uint32 R, G, B, A;
4665     int srcy, srcx;
4666     int posy, posx;
4667     int incy, incx;
4668
4669     srcy = 0;
4670     posy = 0;
4671     incy = (info->src_h << 16) / info->dst_h;
4672     incx = (info->src_w << 16) / info->dst_w;
4673
4674     while (info->dst_h--) {
4675         Uint32 *src = 0;
4676         Uint32 *dst = (Uint32 *)info->dst;
4677         int n = info->dst_w;
4678         srcx = -1;
4679         posx = 0x10000L;
4680         while (posy >= 0x10000L) {
4681             ++srcy;
4682             posy -= 0x10000L;
4683         }
4684         while (n--) {
4685             if (posx >= 0x10000L) {
4686                 while (posx >= 0x10000L) {
4687                     ++srcx;
4688                     posx -= 0x10000L;
4689                 }
4690                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
4691             }
4692             pixel = *src;
4693             R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8); A = (Uint8)pixel;
4694             if (flags & SDL_COPY_MODULATE_COLOR) {
4695                 R = (R * modulateR) / 255;
4696                 G = (G * modulateG) / 255;
4697                 B = (B * modulateB) / 255;
4698             }
4699             if (flags & SDL_COPY_MODULATE_ALPHA) {
4700                 A = (A * modulateA) / 255;
4701             }
4702             pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
4703             *dst = pixel;
4704             posx += incx;
4705             ++dst;
4706         }
4707         posy += incy;
4708         info->dst += info->dst_pitch;
4709     }
4710 }
4711
4712 static void SDL_Blit_RGBA8888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info)
4713 {
4714     const int flags = info->flags;
4715     const Uint32 modulateR = info->r;
4716     const Uint32 modulateG = info->g;
4717     const Uint32 modulateB = info->b;
4718     const Uint32 modulateA = info->a;
4719     Uint32 srcpixel;
4720     Uint32 srcR, srcG, srcB, srcA;
4721     Uint32 dstpixel;
4722     Uint32 dstR, dstG, dstB, dstA;
4723
4724     while (info->dst_h--) {
4725         Uint32 *src = (Uint32 *)info->src;
4726         Uint32 *dst = (Uint32 *)info->dst;
4727         int n = info->dst_w;
4728         while (n--) {
4729             srcpixel = *src;
4730             srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
4731             dstpixel = *dst;
4732             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
4733             if (flags & SDL_COPY_MODULATE_COLOR) {
4734                 srcR = (srcR * modulateR) / 255;
4735                 srcG = (srcG * modulateG) / 255;
4736                 srcB = (srcB * modulateB) / 255;
4737             }
4738             if (flags & SDL_COPY_MODULATE_ALPHA) {
4739                 srcA = (srcA * modulateA) / 255;
4740             }
4741             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
4742                 /* This goes away if we ever use premultiplied alpha */
4743                 if (srcA < 255) {
4744                     srcR = (srcR * srcA) / 255;
4745                     srcG = (srcG * srcA) / 255;
4746                     srcB = (srcB * srcA) / 255;
4747                 }
4748             }
4749             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
4750             case SDL_COPY_BLEND:
4751                 dstR = srcR + ((255 - srcA) * dstR) / 255;
4752                 dstG = srcG + ((255 - srcA) * dstG) / 255;
4753                 dstB = srcB + ((255 - srcA) * dstB) / 255;
4754                 dstA = srcA + ((255 - srcA) * dstA) / 255;
4755                 break;
4756             case SDL_COPY_ADD:
4757                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
4758                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
4759                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
4760                 break;
4761             case SDL_COPY_MOD:
4762                 dstR = (srcR * dstR) / 255;
4763                 dstG = (srcG * dstG) / 255;
4764                 dstB = (srcB * dstB) / 255;
4765                 break;
4766             }
4767             dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
4768             *dst = dstpixel;
4769             ++src;
4770             ++dst;
4771         }
4772         info->src += info->src_pitch;
4773         info->dst += info->dst_pitch;
4774     }
4775 }
4776
4777 static void SDL_Blit_RGBA8888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info)
4778 {
4779     const int flags = info->flags;
4780     const Uint32 modulateR = info->r;
4781     const Uint32 modulateG = info->g;
4782     const Uint32 modulateB = info->b;
4783     const Uint32 modulateA = info->a;
4784     Uint32 srcpixel;
4785     Uint32 srcR, srcG, srcB, srcA;
4786     Uint32 dstpixel;
4787     Uint32 dstR, dstG, dstB, dstA;
4788     int srcy, srcx;
4789     int posy, posx;
4790     int incy, incx;
4791
4792     srcy = 0;
4793     posy = 0;
4794     incy = (info->src_h << 16) / info->dst_h;
4795     incx = (info->src_w << 16) / info->dst_w;
4796
4797     while (info->dst_h--) {
4798         Uint32 *src = 0;
4799         Uint32 *dst = (Uint32 *)info->dst;
4800         int n = info->dst_w;
4801         srcx = -1;
4802         posx = 0x10000L;
4803         while (posy >= 0x10000L) {
4804             ++srcy;
4805             posy -= 0x10000L;
4806         }
4807         while (n--) {
4808             if (posx >= 0x10000L) {
4809                 while (posx >= 0x10000L) {
4810                     ++srcx;
4811                     posx -= 0x10000L;
4812                 }
4813                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
4814             }
4815             srcpixel = *src;
4816             srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
4817             dstpixel = *dst;
4818             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
4819             if (flags & SDL_COPY_MODULATE_COLOR) {
4820                 srcR = (srcR * modulateR) / 255;
4821                 srcG = (srcG * modulateG) / 255;
4822                 srcB = (srcB * modulateB) / 255;
4823             }
4824             if (flags & SDL_COPY_MODULATE_ALPHA) {
4825                 srcA = (srcA * modulateA) / 255;
4826             }
4827             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
4828                 /* This goes away if we ever use premultiplied alpha */
4829                 if (srcA < 255) {
4830                     srcR = (srcR * srcA) / 255;
4831                     srcG = (srcG * srcA) / 255;
4832                     srcB = (srcB * srcA) / 255;
4833                 }
4834             }
4835             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
4836             case SDL_COPY_BLEND:
4837                 dstR = srcR + ((255 - srcA) * dstR) / 255;
4838                 dstG = srcG + ((255 - srcA) * dstG) / 255;
4839                 dstB = srcB + ((255 - srcA) * dstB) / 255;
4840                 dstA = srcA + ((255 - srcA) * dstA) / 255;
4841                 break;
4842             case SDL_COPY_ADD:
4843                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
4844                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
4845                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
4846                 break;
4847             case SDL_COPY_MOD:
4848                 dstR = (srcR * dstR) / 255;
4849                 dstG = (srcG * dstG) / 255;
4850                 dstB = (srcB * dstB) / 255;
4851                 break;
4852             }
4853             dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
4854             *dst = dstpixel;
4855             posx += incx;
4856             ++dst;
4857         }
4858         posy += incy;
4859         info->dst += info->dst_pitch;
4860     }
4861 }
4862
4863 static void SDL_Blit_ABGR8888_RGB888_Scale(SDL_BlitInfo *info)
4864 {
4865     Uint32 pixel;
4866     Uint32 R, G, B;
4867     int srcy, srcx;
4868     int posy, posx;
4869     int incy, incx;
4870
4871     srcy = 0;
4872     posy = 0;
4873     incy = (info->src_h << 16) / info->dst_h;
4874     incx = (info->src_w << 16) / info->dst_w;
4875
4876     while (info->dst_h--) {
4877         Uint32 *src = 0;
4878         Uint32 *dst = (Uint32 *)info->dst;
4879         int n = info->dst_w;
4880         srcx = -1;
4881         posx = 0x10000L;
4882         while (posy >= 0x10000L) {
4883             ++srcy;
4884             posy -= 0x10000L;
4885         }
4886         while (n--) {
4887             if (posx >= 0x10000L) {
4888                 while (posx >= 0x10000L) {
4889                     ++srcx;
4890                     posx -= 0x10000L;
4891                 }
4892                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
4893             }
4894             pixel = *src;
4895             B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
4896             pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
4897             *dst = pixel;
4898             posx += incx;
4899             ++dst;
4900         }
4901         posy += incy;
4902         info->dst += info->dst_pitch;
4903     }
4904 }
4905
4906 static void SDL_Blit_ABGR8888_RGB888_Blend(SDL_BlitInfo *info)
4907 {
4908     const int flags = info->flags;
4909     Uint32 srcpixel;
4910     Uint32 srcR, srcG, srcB, srcA;
4911     Uint32 dstpixel;
4912     Uint32 dstR, dstG, dstB;
4913
4914     while (info->dst_h--) {
4915         Uint32 *src = (Uint32 *)info->src;
4916         Uint32 *dst = (Uint32 *)info->dst;
4917         int n = info->dst_w;
4918         while (n--) {
4919             srcpixel = *src;
4920             srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
4921             dstpixel = *dst;
4922             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
4923             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
4924                 /* This goes away if we ever use premultiplied alpha */
4925                 if (srcA < 255) {
4926                     srcR = (srcR * srcA) / 255;
4927                     srcG = (srcG * srcA) / 255;
4928                     srcB = (srcB * srcA) / 255;
4929                 }
4930             }
4931             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
4932             case SDL_COPY_BLEND:
4933                 dstR = srcR + ((255 - srcA) * dstR) / 255;
4934                 dstG = srcG + ((255 - srcA) * dstG) / 255;
4935                 dstB = srcB + ((255 - srcA) * dstB) / 255;
4936                 break;
4937             case SDL_COPY_ADD:
4938                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
4939                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
4940                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
4941                 break;
4942             case SDL_COPY_MOD:
4943                 dstR = (srcR * dstR) / 255;
4944                 dstG = (srcG * dstG) / 255;
4945                 dstB = (srcB * dstB) / 255;
4946                 break;
4947             }
4948             dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
4949             *dst = dstpixel;
4950             ++src;
4951             ++dst;
4952         }
4953         info->src += info->src_pitch;
4954         info->dst += info->dst_pitch;
4955     }
4956 }
4957
4958 static void SDL_Blit_ABGR8888_RGB888_Blend_Scale(SDL_BlitInfo *info)
4959 {
4960     const int flags = info->flags;
4961     Uint32 srcpixel;
4962     Uint32 srcR, srcG, srcB, srcA;
4963     Uint32 dstpixel;
4964     Uint32 dstR, dstG, dstB;
4965     int srcy, srcx;
4966     int posy, posx;
4967     int incy, incx;
4968
4969     srcy = 0;
4970     posy = 0;
4971     incy = (info->src_h << 16) / info->dst_h;
4972     incx = (info->src_w << 16) / info->dst_w;
4973
4974     while (info->dst_h--) {
4975         Uint32 *src = 0;
4976         Uint32 *dst = (Uint32 *)info->dst;
4977         int n = info->dst_w;
4978         srcx = -1;
4979         posx = 0x10000L;
4980         while (posy >= 0x10000L) {
4981             ++srcy;
4982             posy -= 0x10000L;
4983         }
4984         while (n--) {
4985             if (posx >= 0x10000L) {
4986                 while (posx >= 0x10000L) {
4987                     ++srcx;
4988                     posx -= 0x10000L;
4989                 }
4990                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
4991             }
4992             srcpixel = *src;
4993             srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
4994             dstpixel = *dst;
4995             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
4996             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
4997                 /* This goes away if we ever use premultiplied alpha */
4998                 if (srcA < 255) {
4999                     srcR = (srcR * srcA) / 255;
5000                     srcG = (srcG * srcA) / 255;
5001                     srcB = (srcB * srcA) / 255;
5002                 }
5003             }
5004             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
5005             case SDL_COPY_BLEND:
5006                 dstR = srcR + ((255 - srcA) * dstR) / 255;
5007                 dstG = srcG + ((255 - srcA) * dstG) / 255;
5008                 dstB = srcB + ((255 - srcA) * dstB) / 255;
5009                 break;
5010             case SDL_COPY_ADD:
5011                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
5012                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
5013                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
5014                 break;
5015             case SDL_COPY_MOD:
5016                 dstR = (srcR * dstR) / 255;
5017                 dstG = (srcG * dstG) / 255;
5018                 dstB = (srcB * dstB) / 255;
5019                 break;
5020             }
5021             dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
5022             *dst = dstpixel;
5023             posx += incx;
5024             ++dst;
5025         }
5026         posy += incy;
5027         info->dst += info->dst_pitch;
5028     }
5029 }
5030
5031 static void SDL_Blit_ABGR8888_RGB888_Modulate(SDL_BlitInfo *info)
5032 {
5033     const int flags = info->flags;
5034     const Uint32 modulateR = info->r;
5035     const Uint32 modulateG = info->g;
5036     const Uint32 modulateB = info->b;
5037     Uint32 pixel;
5038     Uint32 R, G, B;
5039
5040     while (info->dst_h--) {
5041         Uint32 *src = (Uint32 *)info->src;
5042         Uint32 *dst = (Uint32 *)info->dst;
5043         int n = info->dst_w;
5044         while (n--) {
5045             pixel = *src;
5046             B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
5047             if (flags & SDL_COPY_MODULATE_COLOR) {
5048                 R = (R * modulateR) / 255;
5049                 G = (G * modulateG) / 255;
5050                 B = (B * modulateB) / 255;
5051             }
5052             pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
5053             *dst = pixel;
5054             ++src;
5055             ++dst;
5056         }
5057         info->src += info->src_pitch;
5058         info->dst += info->dst_pitch;
5059     }
5060 }
5061
5062 static void SDL_Blit_ABGR8888_RGB888_Modulate_Scale(SDL_BlitInfo *info)
5063 {
5064     const int flags = info->flags;
5065     const Uint32 modulateR = info->r;
5066     const Uint32 modulateG = info->g;
5067     const Uint32 modulateB = info->b;
5068     Uint32 pixel;
5069     Uint32 R, G, B;
5070     int srcy, srcx;
5071     int posy, posx;
5072     int incy, incx;
5073
5074     srcy = 0;
5075     posy = 0;
5076     incy = (info->src_h << 16) / info->dst_h;
5077     incx = (info->src_w << 16) / info->dst_w;
5078
5079     while (info->dst_h--) {
5080         Uint32 *src = 0;
5081         Uint32 *dst = (Uint32 *)info->dst;
5082         int n = info->dst_w;
5083         srcx = -1;
5084         posx = 0x10000L;
5085         while (posy >= 0x10000L) {
5086             ++srcy;
5087             posy -= 0x10000L;
5088         }
5089         while (n--) {
5090             if (posx >= 0x10000L) {
5091                 while (posx >= 0x10000L) {
5092                     ++srcx;
5093                     posx -= 0x10000L;
5094                 }
5095                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
5096             }
5097             pixel = *src;
5098             B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
5099             if (flags & SDL_COPY_MODULATE_COLOR) {
5100                 R = (R * modulateR) / 255;
5101                 G = (G * modulateG) / 255;
5102                 B = (B * modulateB) / 255;
5103             }
5104             pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
5105             *dst = pixel;
5106             posx += incx;
5107             ++dst;
5108         }
5109         posy += incy;
5110         info->dst += info->dst_pitch;
5111     }
5112 }
5113
5114 static void SDL_Blit_ABGR8888_RGB888_Modulate_Blend(SDL_BlitInfo *info)
5115 {
5116     const int flags = info->flags;
5117     const Uint32 modulateR = info->r;
5118     const Uint32 modulateG = info->g;
5119     const Uint32 modulateB = info->b;
5120     const Uint32 modulateA = info->a;
5121     Uint32 srcpixel;
5122     Uint32 srcR, srcG, srcB, srcA;
5123     Uint32 dstpixel;
5124     Uint32 dstR, dstG, dstB;
5125
5126     while (info->dst_h--) {
5127         Uint32 *src = (Uint32 *)info->src;
5128         Uint32 *dst = (Uint32 *)info->dst;
5129         int n = info->dst_w;
5130         while (n--) {
5131             srcpixel = *src;
5132             srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
5133             dstpixel = *dst;
5134             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
5135             if (flags & SDL_COPY_MODULATE_COLOR) {
5136                 srcR = (srcR * modulateR) / 255;
5137                 srcG = (srcG * modulateG) / 255;
5138                 srcB = (srcB * modulateB) / 255;
5139             }
5140             if (flags & SDL_COPY_MODULATE_ALPHA) {
5141                 srcA = (srcA * modulateA) / 255;
5142             }
5143             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
5144                 /* This goes away if we ever use premultiplied alpha */
5145                 if (srcA < 255) {
5146                     srcR = (srcR * srcA) / 255;
5147                     srcG = (srcG * srcA) / 255;
5148                     srcB = (srcB * srcA) / 255;
5149                 }
5150             }
5151             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
5152             case SDL_COPY_BLEND:
5153                 dstR = srcR + ((255 - srcA) * dstR) / 255;
5154                 dstG = srcG + ((255 - srcA) * dstG) / 255;
5155                 dstB = srcB + ((255 - srcA) * dstB) / 255;
5156                 break;
5157             case SDL_COPY_ADD:
5158                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
5159                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
5160                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
5161                 break;
5162             case SDL_COPY_MOD:
5163                 dstR = (srcR * dstR) / 255;
5164                 dstG = (srcG * dstG) / 255;
5165                 dstB = (srcB * dstB) / 255;
5166                 break;
5167             }
5168             dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
5169             *dst = dstpixel;
5170             ++src;
5171             ++dst;
5172         }
5173         info->src += info->src_pitch;
5174         info->dst += info->dst_pitch;
5175     }
5176 }
5177
5178 static void SDL_Blit_ABGR8888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info)
5179 {
5180     const int flags = info->flags;
5181     const Uint32 modulateR = info->r;
5182     const Uint32 modulateG = info->g;
5183     const Uint32 modulateB = info->b;
5184     const Uint32 modulateA = info->a;
5185     Uint32 srcpixel;
5186     Uint32 srcR, srcG, srcB, srcA;
5187     Uint32 dstpixel;
5188     Uint32 dstR, dstG, dstB;
5189     int srcy, srcx;
5190     int posy, posx;
5191     int incy, incx;
5192
5193     srcy = 0;
5194     posy = 0;
5195     incy = (info->src_h << 16) / info->dst_h;
5196     incx = (info->src_w << 16) / info->dst_w;
5197
5198     while (info->dst_h--) {
5199         Uint32 *src = 0;
5200         Uint32 *dst = (Uint32 *)info->dst;
5201         int n = info->dst_w;
5202         srcx = -1;
5203         posx = 0x10000L;
5204         while (posy >= 0x10000L) {
5205             ++srcy;
5206             posy -= 0x10000L;
5207         }
5208         while (n--) {
5209             if (posx >= 0x10000L) {
5210                 while (posx >= 0x10000L) {
5211                     ++srcx;
5212                     posx -= 0x10000L;
5213                 }
5214                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
5215             }
5216             srcpixel = *src;
5217             srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
5218             dstpixel = *dst;
5219             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
5220             if (flags & SDL_COPY_MODULATE_COLOR) {
5221                 srcR = (srcR * modulateR) / 255;
5222                 srcG = (srcG * modulateG) / 255;
5223                 srcB = (srcB * modulateB) / 255;
5224             }
5225             if (flags & SDL_COPY_MODULATE_ALPHA) {
5226                 srcA = (srcA * modulateA) / 255;
5227             }
5228             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
5229                 /* This goes away if we ever use premultiplied alpha */
5230                 if (srcA < 255) {
5231                     srcR = (srcR * srcA) / 255;
5232                     srcG = (srcG * srcA) / 255;
5233                     srcB = (srcB * srcA) / 255;
5234                 }
5235             }
5236             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
5237             case SDL_COPY_BLEND:
5238                 dstR = srcR + ((255 - srcA) * dstR) / 255;
5239                 dstG = srcG + ((255 - srcA) * dstG) / 255;
5240                 dstB = srcB + ((255 - srcA) * dstB) / 255;
5241                 break;
5242             case SDL_COPY_ADD:
5243                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
5244                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
5245                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
5246                 break;
5247             case SDL_COPY_MOD:
5248                 dstR = (srcR * dstR) / 255;
5249                 dstG = (srcG * dstG) / 255;
5250                 dstB = (srcB * dstB) / 255;
5251                 break;
5252             }
5253             dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
5254             *dst = dstpixel;
5255             posx += incx;
5256             ++dst;
5257         }
5258         posy += incy;
5259         info->dst += info->dst_pitch;
5260     }
5261 }
5262
5263 static void SDL_Blit_ABGR8888_BGR888_Scale(SDL_BlitInfo *info)
5264 {
5265     Uint32 pixel;
5266     Uint32 R, G, B;
5267     int srcy, srcx;
5268     int posy, posx;
5269     int incy, incx;
5270
5271     srcy = 0;
5272     posy = 0;
5273     incy = (info->src_h << 16) / info->dst_h;
5274     incx = (info->src_w << 16) / info->dst_w;
5275
5276     while (info->dst_h--) {
5277         Uint32 *src = 0;
5278         Uint32 *dst = (Uint32 *)info->dst;
5279         int n = info->dst_w;
5280         srcx = -1;
5281         posx = 0x10000L;
5282         while (posy >= 0x10000L) {
5283             ++srcy;
5284             posy -= 0x10000L;
5285         }
5286         while (n--) {
5287             if (posx >= 0x10000L) {
5288                 while (posx >= 0x10000L) {
5289                     ++srcx;
5290                     posx -= 0x10000L;
5291                 }
5292                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
5293             }
5294             pixel = *src;
5295             B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
5296             pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
5297             *dst = pixel;
5298             posx += incx;
5299             ++dst;
5300         }
5301         posy += incy;
5302         info->dst += info->dst_pitch;
5303     }
5304 }
5305
5306 static void SDL_Blit_ABGR8888_BGR888_Blend(SDL_BlitInfo *info)
5307 {
5308     const int flags = info->flags;
5309     Uint32 srcpixel;
5310     Uint32 srcR, srcG, srcB, srcA;
5311     Uint32 dstpixel;
5312     Uint32 dstR, dstG, dstB;
5313
5314     while (info->dst_h--) {
5315         Uint32 *src = (Uint32 *)info->src;
5316         Uint32 *dst = (Uint32 *)info->dst;
5317         int n = info->dst_w;
5318         while (n--) {
5319             srcpixel = *src;
5320             srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
5321             dstpixel = *dst;
5322             dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
5323             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
5324                 /* This goes away if we ever use premultiplied alpha */
5325                 if (srcA < 255) {
5326                     srcR = (srcR * srcA) / 255;
5327                     srcG = (srcG * srcA) / 255;
5328                     srcB = (srcB * srcA) / 255;
5329                 }
5330             }
5331             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
5332             case SDL_COPY_BLEND:
5333                 dstR = srcR + ((255 - srcA) * dstR) / 255;
5334                 dstG = srcG + ((255 - srcA) * dstG) / 255;
5335                 dstB = srcB + ((255 - srcA) * dstB) / 255;
5336                 break;
5337             case SDL_COPY_ADD:
5338                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
5339                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
5340                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
5341                 break;
5342             case SDL_COPY_MOD:
5343                 dstR = (srcR * dstR) / 255;
5344                 dstG = (srcG * dstG) / 255;
5345                 dstB = (srcB * dstB) / 255;
5346                 break;
5347             }
5348             dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
5349             *dst = dstpixel;
5350             ++src;
5351             ++dst;
5352         }
5353         info->src += info->src_pitch;
5354         info->dst += info->dst_pitch;
5355     }
5356 }
5357
5358 static void SDL_Blit_ABGR8888_BGR888_Blend_Scale(SDL_BlitInfo *info)
5359 {
5360     const int flags = info->flags;
5361     Uint32 srcpixel;
5362     Uint32 srcR, srcG, srcB, srcA;
5363     Uint32 dstpixel;
5364     Uint32 dstR, dstG, dstB;
5365     int srcy, srcx;
5366     int posy, posx;
5367     int incy, incx;
5368
5369     srcy = 0;
5370     posy = 0;
5371     incy = (info->src_h << 16) / info->dst_h;
5372     incx = (info->src_w << 16) / info->dst_w;
5373
5374     while (info->dst_h--) {
5375         Uint32 *src = 0;
5376         Uint32 *dst = (Uint32 *)info->dst;
5377         int n = info->dst_w;
5378         srcx = -1;
5379         posx = 0x10000L;
5380         while (posy >= 0x10000L) {
5381             ++srcy;
5382             posy -= 0x10000L;
5383         }
5384         while (n--) {
5385             if (posx >= 0x10000L) {
5386                 while (posx >= 0x10000L) {
5387                     ++srcx;
5388                     posx -= 0x10000L;
5389                 }
5390                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
5391             }
5392             srcpixel = *src;
5393             srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
5394             dstpixel = *dst;
5395             dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
5396             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
5397                 /* This goes away if we ever use premultiplied alpha */
5398                 if (srcA < 255) {
5399                     srcR = (srcR * srcA) / 255;
5400                     srcG = (srcG * srcA) / 255;
5401                     srcB = (srcB * srcA) / 255;
5402                 }
5403             }
5404             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
5405             case SDL_COPY_BLEND:
5406                 dstR = srcR + ((255 - srcA) * dstR) / 255;
5407                 dstG = srcG + ((255 - srcA) * dstG) / 255;
5408                 dstB = srcB + ((255 - srcA) * dstB) / 255;
5409                 break;
5410             case SDL_COPY_ADD:
5411                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
5412                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
5413                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
5414                 break;
5415             case SDL_COPY_MOD:
5416                 dstR = (srcR * dstR) / 255;
5417                 dstG = (srcG * dstG) / 255;
5418                 dstB = (srcB * dstB) / 255;
5419                 break;
5420             }
5421             dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
5422             *dst = dstpixel;
5423             posx += incx;
5424             ++dst;
5425         }
5426         posy += incy;
5427         info->dst += info->dst_pitch;
5428     }
5429 }
5430
5431 static void SDL_Blit_ABGR8888_BGR888_Modulate(SDL_BlitInfo *info)
5432 {
5433     const int flags = info->flags;
5434     const Uint32 modulateR = info->r;
5435     const Uint32 modulateG = info->g;
5436     const Uint32 modulateB = info->b;
5437     Uint32 pixel;
5438     Uint32 R, G, B;
5439
5440     while (info->dst_h--) {
5441         Uint32 *src = (Uint32 *)info->src;
5442         Uint32 *dst = (Uint32 *)info->dst;
5443         int n = info->dst_w;
5444         while (n--) {
5445             pixel = *src;
5446             B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
5447             if (flags & SDL_COPY_MODULATE_COLOR) {
5448                 R = (R * modulateR) / 255;
5449                 G = (G * modulateG) / 255;
5450                 B = (B * modulateB) / 255;
5451             }
5452             pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
5453             *dst = pixel;
5454             ++src;
5455             ++dst;
5456         }
5457         info->src += info->src_pitch;
5458         info->dst += info->dst_pitch;
5459     }
5460 }
5461
5462 static void SDL_Blit_ABGR8888_BGR888_Modulate_Scale(SDL_BlitInfo *info)
5463 {
5464     const int flags = info->flags;
5465     const Uint32 modulateR = info->r;
5466     const Uint32 modulateG = info->g;
5467     const Uint32 modulateB = info->b;
5468     Uint32 pixel;
5469     Uint32 R, G, B;
5470     int srcy, srcx;
5471     int posy, posx;
5472     int incy, incx;
5473
5474     srcy = 0;
5475     posy = 0;
5476     incy = (info->src_h << 16) / info->dst_h;
5477     incx = (info->src_w << 16) / info->dst_w;
5478
5479     while (info->dst_h--) {
5480         Uint32 *src = 0;
5481         Uint32 *dst = (Uint32 *)info->dst;
5482         int n = info->dst_w;
5483         srcx = -1;
5484         posx = 0x10000L;
5485         while (posy >= 0x10000L) {
5486             ++srcy;
5487             posy -= 0x10000L;
5488         }
5489         while (n--) {
5490             if (posx >= 0x10000L) {
5491                 while (posx >= 0x10000L) {
5492                     ++srcx;
5493                     posx -= 0x10000L;
5494                 }
5495                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
5496             }
5497             pixel = *src;
5498             B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
5499             if (flags & SDL_COPY_MODULATE_COLOR) {
5500                 R = (R * modulateR) / 255;
5501                 G = (G * modulateG) / 255;
5502                 B = (B * modulateB) / 255;
5503             }
5504             pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
5505             *dst = pixel;
5506             posx += incx;
5507             ++dst;
5508         }
5509         posy += incy;
5510         info->dst += info->dst_pitch;
5511     }
5512 }
5513
5514 static void SDL_Blit_ABGR8888_BGR888_Modulate_Blend(SDL_BlitInfo *info)
5515 {
5516     const int flags = info->flags;
5517     const Uint32 modulateR = info->r;
5518     const Uint32 modulateG = info->g;
5519     const Uint32 modulateB = info->b;
5520     const Uint32 modulateA = info->a;
5521     Uint32 srcpixel;
5522     Uint32 srcR, srcG, srcB, srcA;
5523     Uint32 dstpixel;
5524     Uint32 dstR, dstG, dstB;
5525
5526     while (info->dst_h--) {
5527         Uint32 *src = (Uint32 *)info->src;
5528         Uint32 *dst = (Uint32 *)info->dst;
5529         int n = info->dst_w;
5530         while (n--) {
5531             srcpixel = *src;
5532             srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
5533             dstpixel = *dst;
5534             dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
5535             if (flags & SDL_COPY_MODULATE_COLOR) {
5536                 srcR = (srcR * modulateR) / 255;
5537                 srcG = (srcG * modulateG) / 255;
5538                 srcB = (srcB * modulateB) / 255;
5539             }
5540             if (flags & SDL_COPY_MODULATE_ALPHA) {
5541                 srcA = (srcA * modulateA) / 255;
5542             }
5543             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
5544                 /* This goes away if we ever use premultiplied alpha */
5545                 if (srcA < 255) {
5546                     srcR = (srcR * srcA) / 255;
5547                     srcG = (srcG * srcA) / 255;
5548                     srcB = (srcB * srcA) / 255;
5549                 }
5550             }
5551             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
5552             case SDL_COPY_BLEND:
5553                 dstR = srcR + ((255 - srcA) * dstR) / 255;
5554                 dstG = srcG + ((255 - srcA) * dstG) / 255;
5555                 dstB = srcB + ((255 - srcA) * dstB) / 255;
5556                 break;
5557             case SDL_COPY_ADD:
5558                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
5559                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
5560                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
5561                 break;
5562             case SDL_COPY_MOD:
5563                 dstR = (srcR * dstR) / 255;
5564                 dstG = (srcG * dstG) / 255;
5565                 dstB = (srcB * dstB) / 255;
5566                 break;
5567             }
5568             dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
5569             *dst = dstpixel;
5570             ++src;
5571             ++dst;
5572         }
5573         info->src += info->src_pitch;
5574         info->dst += info->dst_pitch;
5575     }
5576 }
5577
5578 static void SDL_Blit_ABGR8888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info)
5579 {
5580     const int flags = info->flags;
5581     const Uint32 modulateR = info->r;
5582     const Uint32 modulateG = info->g;
5583     const Uint32 modulateB = info->b;
5584     const Uint32 modulateA = info->a;
5585     Uint32 srcpixel;
5586     Uint32 srcR, srcG, srcB, srcA;
5587     Uint32 dstpixel;
5588     Uint32 dstR, dstG, dstB;
5589     int srcy, srcx;
5590     int posy, posx;
5591     int incy, incx;
5592
5593     srcy = 0;
5594     posy = 0;
5595     incy = (info->src_h << 16) / info->dst_h;
5596     incx = (info->src_w << 16) / info->dst_w;
5597
5598     while (info->dst_h--) {
5599         Uint32 *src = 0;
5600         Uint32 *dst = (Uint32 *)info->dst;
5601         int n = info->dst_w;
5602         srcx = -1;
5603         posx = 0x10000L;
5604         while (posy >= 0x10000L) {
5605             ++srcy;
5606             posy -= 0x10000L;
5607         }
5608         while (n--) {
5609             if (posx >= 0x10000L) {
5610                 while (posx >= 0x10000L) {
5611                     ++srcx;
5612                     posx -= 0x10000L;
5613                 }
5614                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
5615             }
5616             srcpixel = *src;
5617             srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
5618             dstpixel = *dst;
5619             dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
5620             if (flags & SDL_COPY_MODULATE_COLOR) {
5621                 srcR = (srcR * modulateR) / 255;
5622                 srcG = (srcG * modulateG) / 255;
5623                 srcB = (srcB * modulateB) / 255;
5624             }
5625             if (flags & SDL_COPY_MODULATE_ALPHA) {
5626                 srcA = (srcA * modulateA) / 255;
5627             }
5628             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
5629                 /* This goes away if we ever use premultiplied alpha */
5630                 if (srcA < 255) {
5631                     srcR = (srcR * srcA) / 255;
5632                     srcG = (srcG * srcA) / 255;
5633                     srcB = (srcB * srcA) / 255;
5634                 }
5635             }
5636             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
5637             case SDL_COPY_BLEND:
5638                 dstR = srcR + ((255 - srcA) * dstR) / 255;
5639                 dstG = srcG + ((255 - srcA) * dstG) / 255;
5640                 dstB = srcB + ((255 - srcA) * dstB) / 255;
5641                 break;
5642             case SDL_COPY_ADD:
5643                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
5644                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
5645                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
5646                 break;
5647             case SDL_COPY_MOD:
5648                 dstR = (srcR * dstR) / 255;
5649                 dstG = (srcG * dstG) / 255;
5650                 dstB = (srcB * dstB) / 255;
5651                 break;
5652             }
5653             dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
5654             *dst = dstpixel;
5655             posx += incx;
5656             ++dst;
5657         }
5658         posy += incy;
5659         info->dst += info->dst_pitch;
5660     }
5661 }
5662
5663 static void SDL_Blit_ABGR8888_ARGB8888_Scale(SDL_BlitInfo *info)
5664 {
5665     Uint32 pixel;
5666     Uint32 R, G, B, A;
5667     int srcy, srcx;
5668     int posy, posx;
5669     int incy, incx;
5670
5671     srcy = 0;
5672     posy = 0;
5673     incy = (info->src_h << 16) / info->dst_h;
5674     incx = (info->src_w << 16) / info->dst_w;
5675
5676     while (info->dst_h--) {
5677         Uint32 *src = 0;
5678         Uint32 *dst = (Uint32 *)info->dst;
5679         int n = info->dst_w;
5680         srcx = -1;
5681         posx = 0x10000L;
5682         while (posy >= 0x10000L) {
5683             ++srcy;
5684             posy -= 0x10000L;
5685         }
5686         while (n--) {
5687             if (posx >= 0x10000L) {
5688                 while (posx >= 0x10000L) {
5689                     ++srcx;
5690                     posx -= 0x10000L;
5691                 }
5692                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
5693             }
5694             pixel = *src;
5695             B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = (Uint8)(pixel >> 24);
5696             pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
5697             *dst = pixel;
5698             posx += incx;
5699             ++dst;
5700         }
5701         posy += incy;
5702         info->dst += info->dst_pitch;
5703     }
5704 }
5705
5706 static void SDL_Blit_ABGR8888_ARGB8888_Blend(SDL_BlitInfo *info)
5707 {
5708     const int flags = info->flags;
5709     Uint32 srcpixel;
5710     Uint32 srcR, srcG, srcB, srcA;
5711     Uint32 dstpixel;
5712     Uint32 dstR, dstG, dstB, dstA;
5713
5714     while (info->dst_h--) {
5715         Uint32 *src = (Uint32 *)info->src;
5716         Uint32 *dst = (Uint32 *)info->dst;
5717         int n = info->dst_w;
5718         while (n--) {
5719             srcpixel = *src;
5720             srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
5721             dstpixel = *dst;
5722             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
5723             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
5724                 /* This goes away if we ever use premultiplied alpha */
5725                 if (srcA < 255) {
5726                     srcR = (srcR * srcA) / 255;
5727                     srcG = (srcG * srcA) / 255;
5728                     srcB = (srcB * srcA) / 255;
5729                 }
5730             }
5731             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
5732             case SDL_COPY_BLEND:
5733                 dstR = srcR + ((255 - srcA) * dstR) / 255;
5734                 dstG = srcG + ((255 - srcA) * dstG) / 255;
5735                 dstB = srcB + ((255 - srcA) * dstB) / 255;
5736                 dstA = srcA + ((255 - srcA) * dstA) / 255;
5737                 break;
5738             case SDL_COPY_ADD:
5739                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
5740                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
5741                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
5742                 break;
5743             case SDL_COPY_MOD:
5744                 dstR = (srcR * dstR) / 255;
5745                 dstG = (srcG * dstG) / 255;
5746                 dstB = (srcB * dstB) / 255;
5747                 break;
5748             }
5749             dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
5750             *dst = dstpixel;
5751             ++src;
5752             ++dst;
5753         }
5754         info->src += info->src_pitch;
5755         info->dst += info->dst_pitch;
5756     }
5757 }
5758
5759 static void SDL_Blit_ABGR8888_ARGB8888_Blend_Scale(SDL_BlitInfo *info)
5760 {
5761     const int flags = info->flags;
5762     Uint32 srcpixel;
5763     Uint32 srcR, srcG, srcB, srcA;
5764     Uint32 dstpixel;
5765     Uint32 dstR, dstG, dstB, dstA;
5766     int srcy, srcx;
5767     int posy, posx;
5768     int incy, incx;
5769
5770     srcy = 0;
5771     posy = 0;
5772     incy = (info->src_h << 16) / info->dst_h;
5773     incx = (info->src_w << 16) / info->dst_w;
5774
5775     while (info->dst_h--) {
5776         Uint32 *src = 0;
5777         Uint32 *dst = (Uint32 *)info->dst;
5778         int n = info->dst_w;
5779         srcx = -1;
5780         posx = 0x10000L;
5781         while (posy >= 0x10000L) {
5782             ++srcy;
5783             posy -= 0x10000L;
5784         }
5785         while (n--) {
5786             if (posx >= 0x10000L) {
5787                 while (posx >= 0x10000L) {
5788                     ++srcx;
5789                     posx -= 0x10000L;
5790                 }
5791                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
5792             }
5793             srcpixel = *src;
5794             srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
5795             dstpixel = *dst;
5796             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
5797             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
5798                 /* This goes away if we ever use premultiplied alpha */
5799                 if (srcA < 255) {
5800                     srcR = (srcR * srcA) / 255;
5801                     srcG = (srcG * srcA) / 255;
5802                     srcB = (srcB * srcA) / 255;
5803                 }
5804             }
5805             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
5806             case SDL_COPY_BLEND:
5807                 dstR = srcR + ((255 - srcA) * dstR) / 255;
5808                 dstG = srcG + ((255 - srcA) * dstG) / 255;
5809                 dstB = srcB + ((255 - srcA) * dstB) / 255;
5810                 dstA = srcA + ((255 - srcA) * dstA) / 255;
5811                 break;
5812             case SDL_COPY_ADD:
5813                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
5814                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
5815                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
5816                 break;
5817             case SDL_COPY_MOD:
5818                 dstR = (srcR * dstR) / 255;
5819                 dstG = (srcG * dstG) / 255;
5820                 dstB = (srcB * dstB) / 255;
5821                 break;
5822             }
5823             dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
5824             *dst = dstpixel;
5825             posx += incx;
5826             ++dst;
5827         }
5828         posy += incy;
5829         info->dst += info->dst_pitch;
5830     }
5831 }
5832
5833 static void SDL_Blit_ABGR8888_ARGB8888_Modulate(SDL_BlitInfo *info)
5834 {
5835     const int flags = info->flags;
5836     const Uint32 modulateR = info->r;
5837     const Uint32 modulateG = info->g;
5838     const Uint32 modulateB = info->b;
5839     const Uint32 modulateA = info->a;
5840     Uint32 pixel;
5841     Uint32 R, G, B, A;
5842
5843     while (info->dst_h--) {
5844         Uint32 *src = (Uint32 *)info->src;
5845         Uint32 *dst = (Uint32 *)info->dst;
5846         int n = info->dst_w;
5847         while (n--) {
5848             pixel = *src;
5849             B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = (Uint8)(pixel >> 24);
5850             if (flags & SDL_COPY_MODULATE_COLOR) {
5851                 R = (R * modulateR) / 255;
5852                 G = (G * modulateG) / 255;
5853                 B = (B * modulateB) / 255;
5854             }
5855             if (flags & SDL_COPY_MODULATE_ALPHA) {
5856                 A = (A * modulateA) / 255;
5857             }
5858             pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
5859             *dst = pixel;
5860             ++src;
5861             ++dst;
5862         }
5863         info->src += info->src_pitch;
5864         info->dst += info->dst_pitch;
5865     }
5866 }
5867
5868 static void SDL_Blit_ABGR8888_ARGB8888_Modulate_Scale(SDL_BlitInfo *info)
5869 {
5870     const int flags = info->flags;
5871     const Uint32 modulateR = info->r;
5872     const Uint32 modulateG = info->g;
5873     const Uint32 modulateB = info->b;
5874     const Uint32 modulateA = info->a;
5875     Uint32 pixel;
5876     Uint32 R, G, B, A;
5877     int srcy, srcx;
5878     int posy, posx;
5879     int incy, incx;
5880
5881     srcy = 0;
5882     posy = 0;
5883     incy = (info->src_h << 16) / info->dst_h;
5884     incx = (info->src_w << 16) / info->dst_w;
5885
5886     while (info->dst_h--) {
5887         Uint32 *src = 0;
5888         Uint32 *dst = (Uint32 *)info->dst;
5889         int n = info->dst_w;
5890         srcx = -1;
5891         posx = 0x10000L;
5892         while (posy >= 0x10000L) {
5893             ++srcy;
5894             posy -= 0x10000L;
5895         }
5896         while (n--) {
5897             if (posx >= 0x10000L) {
5898                 while (posx >= 0x10000L) {
5899                     ++srcx;
5900                     posx -= 0x10000L;
5901                 }
5902                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
5903             }
5904             pixel = *src;
5905             B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = (Uint8)(pixel >> 24);
5906             if (flags & SDL_COPY_MODULATE_COLOR) {
5907                 R = (R * modulateR) / 255;
5908                 G = (G * modulateG) / 255;
5909                 B = (B * modulateB) / 255;
5910             }
5911             if (flags & SDL_COPY_MODULATE_ALPHA) {
5912                 A = (A * modulateA) / 255;
5913             }
5914             pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
5915             *dst = pixel;
5916             posx += incx;
5917             ++dst;
5918         }
5919         posy += incy;
5920         info->dst += info->dst_pitch;
5921     }
5922 }
5923
5924 static void SDL_Blit_ABGR8888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info)
5925 {
5926     const int flags = info->flags;
5927     const Uint32 modulateR = info->r;
5928     const Uint32 modulateG = info->g;
5929     const Uint32 modulateB = info->b;
5930     const Uint32 modulateA = info->a;
5931     Uint32 srcpixel;
5932     Uint32 srcR, srcG, srcB, srcA;
5933     Uint32 dstpixel;
5934     Uint32 dstR, dstG, dstB, dstA;
5935
5936     while (info->dst_h--) {
5937         Uint32 *src = (Uint32 *)info->src;
5938         Uint32 *dst = (Uint32 *)info->dst;
5939         int n = info->dst_w;
5940         while (n--) {
5941             srcpixel = *src;
5942             srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
5943             dstpixel = *dst;
5944             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
5945             if (flags & SDL_COPY_MODULATE_COLOR) {
5946                 srcR = (srcR * modulateR) / 255;
5947                 srcG = (srcG * modulateG) / 255;
5948                 srcB = (srcB * modulateB) / 255;
5949             }
5950             if (flags & SDL_COPY_MODULATE_ALPHA) {
5951                 srcA = (srcA * modulateA) / 255;
5952             }
5953             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
5954                 /* This goes away if we ever use premultiplied alpha */
5955                 if (srcA < 255) {
5956                     srcR = (srcR * srcA) / 255;
5957                     srcG = (srcG * srcA) / 255;
5958                     srcB = (srcB * srcA) / 255;
5959                 }
5960             }
5961             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
5962             case SDL_COPY_BLEND:
5963                 dstR = srcR + ((255 - srcA) * dstR) / 255;
5964                 dstG = srcG + ((255 - srcA) * dstG) / 255;
5965                 dstB = srcB + ((255 - srcA) * dstB) / 255;
5966                 dstA = srcA + ((255 - srcA) * dstA) / 255;
5967                 break;
5968             case SDL_COPY_ADD:
5969                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
5970                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
5971                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
5972                 break;
5973             case SDL_COPY_MOD:
5974                 dstR = (srcR * dstR) / 255;
5975                 dstG = (srcG * dstG) / 255;
5976                 dstB = (srcB * dstB) / 255;
5977                 break;
5978             }
5979             dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
5980             *dst = dstpixel;
5981             ++src;
5982             ++dst;
5983         }
5984         info->src += info->src_pitch;
5985         info->dst += info->dst_pitch;
5986     }
5987 }
5988
5989 static void SDL_Blit_ABGR8888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info)
5990 {
5991     const int flags = info->flags;
5992     const Uint32 modulateR = info->r;
5993     const Uint32 modulateG = info->g;
5994     const Uint32 modulateB = info->b;
5995     const Uint32 modulateA = info->a;
5996     Uint32 srcpixel;
5997     Uint32 srcR, srcG, srcB, srcA;
5998     Uint32 dstpixel;
5999     Uint32 dstR, dstG, dstB, dstA;
6000     int srcy, srcx;
6001     int posy, posx;
6002     int incy, incx;
6003
6004     srcy = 0;
6005     posy = 0;
6006     incy = (info->src_h << 16) / info->dst_h;
6007     incx = (info->src_w << 16) / info->dst_w;
6008
6009     while (info->dst_h--) {
6010         Uint32 *src = 0;
6011         Uint32 *dst = (Uint32 *)info->dst;
6012         int n = info->dst_w;
6013         srcx = -1;
6014         posx = 0x10000L;
6015         while (posy >= 0x10000L) {
6016             ++srcy;
6017             posy -= 0x10000L;
6018         }
6019         while (n--) {
6020             if (posx >= 0x10000L) {
6021                 while (posx >= 0x10000L) {
6022                     ++srcx;
6023                     posx -= 0x10000L;
6024                 }
6025                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
6026             }
6027             srcpixel = *src;
6028             srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = (Uint8)(srcpixel >> 24);
6029             dstpixel = *dst;
6030             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
6031             if (flags & SDL_COPY_MODULATE_COLOR) {
6032                 srcR = (srcR * modulateR) / 255;
6033                 srcG = (srcG * modulateG) / 255;
6034                 srcB = (srcB * modulateB) / 255;
6035             }
6036             if (flags & SDL_COPY_MODULATE_ALPHA) {
6037                 srcA = (srcA * modulateA) / 255;
6038             }
6039             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
6040                 /* This goes away if we ever use premultiplied alpha */
6041                 if (srcA < 255) {
6042                     srcR = (srcR * srcA) / 255;
6043                     srcG = (srcG * srcA) / 255;
6044                     srcB = (srcB * srcA) / 255;
6045                 }
6046             }
6047             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
6048             case SDL_COPY_BLEND:
6049                 dstR = srcR + ((255 - srcA) * dstR) / 255;
6050                 dstG = srcG + ((255 - srcA) * dstG) / 255;
6051                 dstB = srcB + ((255 - srcA) * dstB) / 255;
6052                 dstA = srcA + ((255 - srcA) * dstA) / 255;
6053                 break;
6054             case SDL_COPY_ADD:
6055                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
6056                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
6057                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
6058                 break;
6059             case SDL_COPY_MOD:
6060                 dstR = (srcR * dstR) / 255;
6061                 dstG = (srcG * dstG) / 255;
6062                 dstB = (srcB * dstB) / 255;
6063                 break;
6064             }
6065             dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
6066             *dst = dstpixel;
6067             posx += incx;
6068             ++dst;
6069         }
6070         posy += incy;
6071         info->dst += info->dst_pitch;
6072     }
6073 }
6074
6075 static void SDL_Blit_BGRA8888_RGB888_Scale(SDL_BlitInfo *info)
6076 {
6077     Uint32 pixel;
6078     Uint32 R, G, B;
6079     int srcy, srcx;
6080     int posy, posx;
6081     int incy, incx;
6082
6083     srcy = 0;
6084     posy = 0;
6085     incy = (info->src_h << 16) / info->dst_h;
6086     incx = (info->src_w << 16) / info->dst_w;
6087
6088     while (info->dst_h--) {
6089         Uint32 *src = 0;
6090         Uint32 *dst = (Uint32 *)info->dst;
6091         int n = info->dst_w;
6092         srcx = -1;
6093         posx = 0x10000L;
6094         while (posy >= 0x10000L) {
6095             ++srcy;
6096             posy -= 0x10000L;
6097         }
6098         while (n--) {
6099             if (posx >= 0x10000L) {
6100                 while (posx >= 0x10000L) {
6101                     ++srcx;
6102                     posx -= 0x10000L;
6103                 }
6104                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
6105             }
6106             pixel = *src;
6107             B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8);
6108             pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
6109             *dst = pixel;
6110             posx += incx;
6111             ++dst;
6112         }
6113         posy += incy;
6114         info->dst += info->dst_pitch;
6115     }
6116 }
6117
6118 static void SDL_Blit_BGRA8888_RGB888_Blend(SDL_BlitInfo *info)
6119 {
6120     const int flags = info->flags;
6121     Uint32 srcpixel;
6122     Uint32 srcR, srcG, srcB, srcA;
6123     Uint32 dstpixel;
6124     Uint32 dstR, dstG, dstB;
6125
6126     while (info->dst_h--) {
6127         Uint32 *src = (Uint32 *)info->src;
6128         Uint32 *dst = (Uint32 *)info->dst;
6129         int n = info->dst_w;
6130         while (n--) {
6131             srcpixel = *src;
6132             srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
6133             dstpixel = *dst;
6134             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
6135             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
6136                 /* This goes away if we ever use premultiplied alpha */
6137                 if (srcA < 255) {
6138                     srcR = (srcR * srcA) / 255;
6139                     srcG = (srcG * srcA) / 255;
6140                     srcB = (srcB * srcA) / 255;
6141                 }
6142             }
6143             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
6144             case SDL_COPY_BLEND:
6145                 dstR = srcR + ((255 - srcA) * dstR) / 255;
6146                 dstG = srcG + ((255 - srcA) * dstG) / 255;
6147                 dstB = srcB + ((255 - srcA) * dstB) / 255;
6148                 break;
6149             case SDL_COPY_ADD:
6150                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
6151                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
6152                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
6153                 break;
6154             case SDL_COPY_MOD:
6155                 dstR = (srcR * dstR) / 255;
6156                 dstG = (srcG * dstG) / 255;
6157                 dstB = (srcB * dstB) / 255;
6158                 break;
6159             }
6160             dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
6161             *dst = dstpixel;
6162             ++src;
6163             ++dst;
6164         }
6165         info->src += info->src_pitch;
6166         info->dst += info->dst_pitch;
6167     }
6168 }
6169
6170 static void SDL_Blit_BGRA8888_RGB888_Blend_Scale(SDL_BlitInfo *info)
6171 {
6172     const int flags = info->flags;
6173     Uint32 srcpixel;
6174     Uint32 srcR, srcG, srcB, srcA;
6175     Uint32 dstpixel;
6176     Uint32 dstR, dstG, dstB;
6177     int srcy, srcx;
6178     int posy, posx;
6179     int incy, incx;
6180
6181     srcy = 0;
6182     posy = 0;
6183     incy = (info->src_h << 16) / info->dst_h;
6184     incx = (info->src_w << 16) / info->dst_w;
6185
6186     while (info->dst_h--) {
6187         Uint32 *src = 0;
6188         Uint32 *dst = (Uint32 *)info->dst;
6189         int n = info->dst_w;
6190         srcx = -1;
6191         posx = 0x10000L;
6192         while (posy >= 0x10000L) {
6193             ++srcy;
6194             posy -= 0x10000L;
6195         }
6196         while (n--) {
6197             if (posx >= 0x10000L) {
6198                 while (posx >= 0x10000L) {
6199                     ++srcx;
6200                     posx -= 0x10000L;
6201                 }
6202                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
6203             }
6204             srcpixel = *src;
6205             srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
6206             dstpixel = *dst;
6207             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
6208             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
6209                 /* This goes away if we ever use premultiplied alpha */
6210                 if (srcA < 255) {
6211                     srcR = (srcR * srcA) / 255;
6212                     srcG = (srcG * srcA) / 255;
6213                     srcB = (srcB * srcA) / 255;
6214                 }
6215             }
6216             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
6217             case SDL_COPY_BLEND:
6218                 dstR = srcR + ((255 - srcA) * dstR) / 255;
6219                 dstG = srcG + ((255 - srcA) * dstG) / 255;
6220                 dstB = srcB + ((255 - srcA) * dstB) / 255;
6221                 break;
6222             case SDL_COPY_ADD:
6223                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
6224                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
6225                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
6226                 break;
6227             case SDL_COPY_MOD:
6228                 dstR = (srcR * dstR) / 255;
6229                 dstG = (srcG * dstG) / 255;
6230                 dstB = (srcB * dstB) / 255;
6231                 break;
6232             }
6233             dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
6234             *dst = dstpixel;
6235             posx += incx;
6236             ++dst;
6237         }
6238         posy += incy;
6239         info->dst += info->dst_pitch;
6240     }
6241 }
6242
6243 static void SDL_Blit_BGRA8888_RGB888_Modulate(SDL_BlitInfo *info)
6244 {
6245     const int flags = info->flags;
6246     const Uint32 modulateR = info->r;
6247     const Uint32 modulateG = info->g;
6248     const Uint32 modulateB = info->b;
6249     Uint32 pixel;
6250     Uint32 R, G, B;
6251
6252     while (info->dst_h--) {
6253         Uint32 *src = (Uint32 *)info->src;
6254         Uint32 *dst = (Uint32 *)info->dst;
6255         int n = info->dst_w;
6256         while (n--) {
6257             pixel = *src;
6258             B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8);
6259             if (flags & SDL_COPY_MODULATE_COLOR) {
6260                 R = (R * modulateR) / 255;
6261                 G = (G * modulateG) / 255;
6262                 B = (B * modulateB) / 255;
6263             }
6264             pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
6265             *dst = pixel;
6266             ++src;
6267             ++dst;
6268         }
6269         info->src += info->src_pitch;
6270         info->dst += info->dst_pitch;
6271     }
6272 }
6273
6274 static void SDL_Blit_BGRA8888_RGB888_Modulate_Scale(SDL_BlitInfo *info)
6275 {
6276     const int flags = info->flags;
6277     const Uint32 modulateR = info->r;
6278     const Uint32 modulateG = info->g;
6279     const Uint32 modulateB = info->b;
6280     Uint32 pixel;
6281     Uint32 R, G, B;
6282     int srcy, srcx;
6283     int posy, posx;
6284     int incy, incx;
6285
6286     srcy = 0;
6287     posy = 0;
6288     incy = (info->src_h << 16) / info->dst_h;
6289     incx = (info->src_w << 16) / info->dst_w;
6290
6291     while (info->dst_h--) {
6292         Uint32 *src = 0;
6293         Uint32 *dst = (Uint32 *)info->dst;
6294         int n = info->dst_w;
6295         srcx = -1;
6296         posx = 0x10000L;
6297         while (posy >= 0x10000L) {
6298             ++srcy;
6299             posy -= 0x10000L;
6300         }
6301         while (n--) {
6302             if (posx >= 0x10000L) {
6303                 while (posx >= 0x10000L) {
6304                     ++srcx;
6305                     posx -= 0x10000L;
6306                 }
6307                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
6308             }
6309             pixel = *src;
6310             B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8);
6311             if (flags & SDL_COPY_MODULATE_COLOR) {
6312                 R = (R * modulateR) / 255;
6313                 G = (G * modulateG) / 255;
6314                 B = (B * modulateB) / 255;
6315             }
6316             pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
6317             *dst = pixel;
6318             posx += incx;
6319             ++dst;
6320         }
6321         posy += incy;
6322         info->dst += info->dst_pitch;
6323     }
6324 }
6325
6326 static void SDL_Blit_BGRA8888_RGB888_Modulate_Blend(SDL_BlitInfo *info)
6327 {
6328     const int flags = info->flags;
6329     const Uint32 modulateR = info->r;
6330     const Uint32 modulateG = info->g;
6331     const Uint32 modulateB = info->b;
6332     const Uint32 modulateA = info->a;
6333     Uint32 srcpixel;
6334     Uint32 srcR, srcG, srcB, srcA;
6335     Uint32 dstpixel;
6336     Uint32 dstR, dstG, dstB;
6337
6338     while (info->dst_h--) {
6339         Uint32 *src = (Uint32 *)info->src;
6340         Uint32 *dst = (Uint32 *)info->dst;
6341         int n = info->dst_w;
6342         while (n--) {
6343             srcpixel = *src;
6344             srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
6345             dstpixel = *dst;
6346             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
6347             if (flags & SDL_COPY_MODULATE_COLOR) {
6348                 srcR = (srcR * modulateR) / 255;
6349                 srcG = (srcG * modulateG) / 255;
6350                 srcB = (srcB * modulateB) / 255;
6351             }
6352             if (flags & SDL_COPY_MODULATE_ALPHA) {
6353                 srcA = (srcA * modulateA) / 255;
6354             }
6355             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
6356                 /* This goes away if we ever use premultiplied alpha */
6357                 if (srcA < 255) {
6358                     srcR = (srcR * srcA) / 255;
6359                     srcG = (srcG * srcA) / 255;
6360                     srcB = (srcB * srcA) / 255;
6361                 }
6362             }
6363             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
6364             case SDL_COPY_BLEND:
6365                 dstR = srcR + ((255 - srcA) * dstR) / 255;
6366                 dstG = srcG + ((255 - srcA) * dstG) / 255;
6367                 dstB = srcB + ((255 - srcA) * dstB) / 255;
6368                 break;
6369             case SDL_COPY_ADD:
6370                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
6371                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
6372                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
6373                 break;
6374             case SDL_COPY_MOD:
6375                 dstR = (srcR * dstR) / 255;
6376                 dstG = (srcG * dstG) / 255;
6377                 dstB = (srcB * dstB) / 255;
6378                 break;
6379             }
6380             dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
6381             *dst = dstpixel;
6382             ++src;
6383             ++dst;
6384         }
6385         info->src += info->src_pitch;
6386         info->dst += info->dst_pitch;
6387     }
6388 }
6389
6390 static void SDL_Blit_BGRA8888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info)
6391 {
6392     const int flags = info->flags;
6393     const Uint32 modulateR = info->r;
6394     const Uint32 modulateG = info->g;
6395     const Uint32 modulateB = info->b;
6396     const Uint32 modulateA = info->a;
6397     Uint32 srcpixel;
6398     Uint32 srcR, srcG, srcB, srcA;
6399     Uint32 dstpixel;
6400     Uint32 dstR, dstG, dstB;
6401     int srcy, srcx;
6402     int posy, posx;
6403     int incy, incx;
6404
6405     srcy = 0;
6406     posy = 0;
6407     incy = (info->src_h << 16) / info->dst_h;
6408     incx = (info->src_w << 16) / info->dst_w;
6409
6410     while (info->dst_h--) {
6411         Uint32 *src = 0;
6412         Uint32 *dst = (Uint32 *)info->dst;
6413         int n = info->dst_w;
6414         srcx = -1;
6415         posx = 0x10000L;
6416         while (posy >= 0x10000L) {
6417             ++srcy;
6418             posy -= 0x10000L;
6419         }
6420         while (n--) {
6421             if (posx >= 0x10000L) {
6422                 while (posx >= 0x10000L) {
6423                     ++srcx;
6424                     posx -= 0x10000L;
6425                 }
6426                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
6427             }
6428             srcpixel = *src;
6429             srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
6430             dstpixel = *dst;
6431             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
6432             if (flags & SDL_COPY_MODULATE_COLOR) {
6433                 srcR = (srcR * modulateR) / 255;
6434                 srcG = (srcG * modulateG) / 255;
6435                 srcB = (srcB * modulateB) / 255;
6436             }
6437             if (flags & SDL_COPY_MODULATE_ALPHA) {
6438                 srcA = (srcA * modulateA) / 255;
6439             }
6440             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
6441                 /* This goes away if we ever use premultiplied alpha */
6442                 if (srcA < 255) {
6443                     srcR = (srcR * srcA) / 255;
6444                     srcG = (srcG * srcA) / 255;
6445                     srcB = (srcB * srcA) / 255;
6446                 }
6447             }
6448             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
6449             case SDL_COPY_BLEND:
6450                 dstR = srcR + ((255 - srcA) * dstR) / 255;
6451                 dstG = srcG + ((255 - srcA) * dstG) / 255;
6452                 dstB = srcB + ((255 - srcA) * dstB) / 255;
6453                 break;
6454             case SDL_COPY_ADD:
6455                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
6456                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
6457                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
6458                 break;
6459             case SDL_COPY_MOD:
6460                 dstR = (srcR * dstR) / 255;
6461                 dstG = (srcG * dstG) / 255;
6462                 dstB = (srcB * dstB) / 255;
6463                 break;
6464             }
6465             dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
6466             *dst = dstpixel;
6467             posx += incx;
6468             ++dst;
6469         }
6470         posy += incy;
6471         info->dst += info->dst_pitch;
6472     }
6473 }
6474
6475 static void SDL_Blit_BGRA8888_BGR888_Scale(SDL_BlitInfo *info)
6476 {
6477     Uint32 pixel;
6478     Uint32 R, G, B;
6479     int srcy, srcx;
6480     int posy, posx;
6481     int incy, incx;
6482
6483     srcy = 0;
6484     posy = 0;
6485     incy = (info->src_h << 16) / info->dst_h;
6486     incx = (info->src_w << 16) / info->dst_w;
6487
6488     while (info->dst_h--) {
6489         Uint32 *src = 0;
6490         Uint32 *dst = (Uint32 *)info->dst;
6491         int n = info->dst_w;
6492         srcx = -1;
6493         posx = 0x10000L;
6494         while (posy >= 0x10000L) {
6495             ++srcy;
6496             posy -= 0x10000L;
6497         }
6498         while (n--) {
6499             if (posx >= 0x10000L) {
6500                 while (posx >= 0x10000L) {
6501                     ++srcx;
6502                     posx -= 0x10000L;
6503                 }
6504                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
6505             }
6506             pixel = *src;
6507             B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8);
6508             pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
6509             *dst = pixel;
6510             posx += incx;
6511             ++dst;
6512         }
6513         posy += incy;
6514         info->dst += info->dst_pitch;
6515     }
6516 }
6517
6518 static void SDL_Blit_BGRA8888_BGR888_Blend(SDL_BlitInfo *info)
6519 {
6520     const int flags = info->flags;
6521     Uint32 srcpixel;
6522     Uint32 srcR, srcG, srcB, srcA;
6523     Uint32 dstpixel;
6524     Uint32 dstR, dstG, dstB;
6525
6526     while (info->dst_h--) {
6527         Uint32 *src = (Uint32 *)info->src;
6528         Uint32 *dst = (Uint32 *)info->dst;
6529         int n = info->dst_w;
6530         while (n--) {
6531             srcpixel = *src;
6532             srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
6533             dstpixel = *dst;
6534             dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
6535             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
6536                 /* This goes away if we ever use premultiplied alpha */
6537                 if (srcA < 255) {
6538                     srcR = (srcR * srcA) / 255;
6539                     srcG = (srcG * srcA) / 255;
6540                     srcB = (srcB * srcA) / 255;
6541                 }
6542             }
6543             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
6544             case SDL_COPY_BLEND:
6545                 dstR = srcR + ((255 - srcA) * dstR) / 255;
6546                 dstG = srcG + ((255 - srcA) * dstG) / 255;
6547                 dstB = srcB + ((255 - srcA) * dstB) / 255;
6548                 break;
6549             case SDL_COPY_ADD:
6550                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
6551                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
6552                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
6553                 break;
6554             case SDL_COPY_MOD:
6555                 dstR = (srcR * dstR) / 255;
6556                 dstG = (srcG * dstG) / 255;
6557                 dstB = (srcB * dstB) / 255;
6558                 break;
6559             }
6560             dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
6561             *dst = dstpixel;
6562             ++src;
6563             ++dst;
6564         }
6565         info->src += info->src_pitch;
6566         info->dst += info->dst_pitch;
6567     }
6568 }
6569
6570 static void SDL_Blit_BGRA8888_BGR888_Blend_Scale(SDL_BlitInfo *info)
6571 {
6572     const int flags = info->flags;
6573     Uint32 srcpixel;
6574     Uint32 srcR, srcG, srcB, srcA;
6575     Uint32 dstpixel;
6576     Uint32 dstR, dstG, dstB;
6577     int srcy, srcx;
6578     int posy, posx;
6579     int incy, incx;
6580
6581     srcy = 0;
6582     posy = 0;
6583     incy = (info->src_h << 16) / info->dst_h;
6584     incx = (info->src_w << 16) / info->dst_w;
6585
6586     while (info->dst_h--) {
6587         Uint32 *src = 0;
6588         Uint32 *dst = (Uint32 *)info->dst;
6589         int n = info->dst_w;
6590         srcx = -1;
6591         posx = 0x10000L;
6592         while (posy >= 0x10000L) {
6593             ++srcy;
6594             posy -= 0x10000L;
6595         }
6596         while (n--) {
6597             if (posx >= 0x10000L) {
6598                 while (posx >= 0x10000L) {
6599                     ++srcx;
6600                     posx -= 0x10000L;
6601                 }
6602                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
6603             }
6604             srcpixel = *src;
6605             srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
6606             dstpixel = *dst;
6607             dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
6608             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
6609                 /* This goes away if we ever use premultiplied alpha */
6610                 if (srcA < 255) {
6611                     srcR = (srcR * srcA) / 255;
6612                     srcG = (srcG * srcA) / 255;
6613                     srcB = (srcB * srcA) / 255;
6614                 }
6615             }
6616             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
6617             case SDL_COPY_BLEND:
6618                 dstR = srcR + ((255 - srcA) * dstR) / 255;
6619                 dstG = srcG + ((255 - srcA) * dstG) / 255;
6620                 dstB = srcB + ((255 - srcA) * dstB) / 255;
6621                 break;
6622             case SDL_COPY_ADD:
6623                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
6624                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
6625                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
6626                 break;
6627             case SDL_COPY_MOD:
6628                 dstR = (srcR * dstR) / 255;
6629                 dstG = (srcG * dstG) / 255;
6630                 dstB = (srcB * dstB) / 255;
6631                 break;
6632             }
6633             dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
6634             *dst = dstpixel;
6635             posx += incx;
6636             ++dst;
6637         }
6638         posy += incy;
6639         info->dst += info->dst_pitch;
6640     }
6641 }
6642
6643 static void SDL_Blit_BGRA8888_BGR888_Modulate(SDL_BlitInfo *info)
6644 {
6645     const int flags = info->flags;
6646     const Uint32 modulateR = info->r;
6647     const Uint32 modulateG = info->g;
6648     const Uint32 modulateB = info->b;
6649     Uint32 pixel;
6650     Uint32 R, G, B;
6651
6652     while (info->dst_h--) {
6653         Uint32 *src = (Uint32 *)info->src;
6654         Uint32 *dst = (Uint32 *)info->dst;
6655         int n = info->dst_w;
6656         while (n--) {
6657             pixel = *src;
6658             B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8);
6659             if (flags & SDL_COPY_MODULATE_COLOR) {
6660                 R = (R * modulateR) / 255;
6661                 G = (G * modulateG) / 255;
6662                 B = (B * modulateB) / 255;
6663             }
6664             pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
6665             *dst = pixel;
6666             ++src;
6667             ++dst;
6668         }
6669         info->src += info->src_pitch;
6670         info->dst += info->dst_pitch;
6671     }
6672 }
6673
6674 static void SDL_Blit_BGRA8888_BGR888_Modulate_Scale(SDL_BlitInfo *info)
6675 {
6676     const int flags = info->flags;
6677     const Uint32 modulateR = info->r;
6678     const Uint32 modulateG = info->g;
6679     const Uint32 modulateB = info->b;
6680     Uint32 pixel;
6681     Uint32 R, G, B;
6682     int srcy, srcx;
6683     int posy, posx;
6684     int incy, incx;
6685
6686     srcy = 0;
6687     posy = 0;
6688     incy = (info->src_h << 16) / info->dst_h;
6689     incx = (info->src_w << 16) / info->dst_w;
6690
6691     while (info->dst_h--) {
6692         Uint32 *src = 0;
6693         Uint32 *dst = (Uint32 *)info->dst;
6694         int n = info->dst_w;
6695         srcx = -1;
6696         posx = 0x10000L;
6697         while (posy >= 0x10000L) {
6698             ++srcy;
6699             posy -= 0x10000L;
6700         }
6701         while (n--) {
6702             if (posx >= 0x10000L) {
6703                 while (posx >= 0x10000L) {
6704                     ++srcx;
6705                     posx -= 0x10000L;
6706                 }
6707                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
6708             }
6709             pixel = *src;
6710             B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8);
6711             if (flags & SDL_COPY_MODULATE_COLOR) {
6712                 R = (R * modulateR) / 255;
6713                 G = (G * modulateG) / 255;
6714                 B = (B * modulateB) / 255;
6715             }
6716             pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
6717             *dst = pixel;
6718             posx += incx;
6719             ++dst;
6720         }
6721         posy += incy;
6722         info->dst += info->dst_pitch;
6723     }
6724 }
6725
6726 static void SDL_Blit_BGRA8888_BGR888_Modulate_Blend(SDL_BlitInfo *info)
6727 {
6728     const int flags = info->flags;
6729     const Uint32 modulateR = info->r;
6730     const Uint32 modulateG = info->g;
6731     const Uint32 modulateB = info->b;
6732     const Uint32 modulateA = info->a;
6733     Uint32 srcpixel;
6734     Uint32 srcR, srcG, srcB, srcA;
6735     Uint32 dstpixel;
6736     Uint32 dstR, dstG, dstB;
6737
6738     while (info->dst_h--) {
6739         Uint32 *src = (Uint32 *)info->src;
6740         Uint32 *dst = (Uint32 *)info->dst;
6741         int n = info->dst_w;
6742         while (n--) {
6743             srcpixel = *src;
6744             srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
6745             dstpixel = *dst;
6746             dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
6747             if (flags & SDL_COPY_MODULATE_COLOR) {
6748                 srcR = (srcR * modulateR) / 255;
6749                 srcG = (srcG * modulateG) / 255;
6750                 srcB = (srcB * modulateB) / 255;
6751             }
6752             if (flags & SDL_COPY_MODULATE_ALPHA) {
6753                 srcA = (srcA * modulateA) / 255;
6754             }
6755             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
6756                 /* This goes away if we ever use premultiplied alpha */
6757                 if (srcA < 255) {
6758                     srcR = (srcR * srcA) / 255;
6759                     srcG = (srcG * srcA) / 255;
6760                     srcB = (srcB * srcA) / 255;
6761                 }
6762             }
6763             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
6764             case SDL_COPY_BLEND:
6765                 dstR = srcR + ((255 - srcA) * dstR) / 255;
6766                 dstG = srcG + ((255 - srcA) * dstG) / 255;
6767                 dstB = srcB + ((255 - srcA) * dstB) / 255;
6768                 break;
6769             case SDL_COPY_ADD:
6770                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
6771                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
6772                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
6773                 break;
6774             case SDL_COPY_MOD:
6775                 dstR = (srcR * dstR) / 255;
6776                 dstG = (srcG * dstG) / 255;
6777                 dstB = (srcB * dstB) / 255;
6778                 break;
6779             }
6780             dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
6781             *dst = dstpixel;
6782             ++src;
6783             ++dst;
6784         }
6785         info->src += info->src_pitch;
6786         info->dst += info->dst_pitch;
6787     }
6788 }
6789
6790 static void SDL_Blit_BGRA8888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info)
6791 {
6792     const int flags = info->flags;
6793     const Uint32 modulateR = info->r;
6794     const Uint32 modulateG = info->g;
6795     const Uint32 modulateB = info->b;
6796     const Uint32 modulateA = info->a;
6797     Uint32 srcpixel;
6798     Uint32 srcR, srcG, srcB, srcA;
6799     Uint32 dstpixel;
6800     Uint32 dstR, dstG, dstB;
6801     int srcy, srcx;
6802     int posy, posx;
6803     int incy, incx;
6804
6805     srcy = 0;
6806     posy = 0;
6807     incy = (info->src_h << 16) / info->dst_h;
6808     incx = (info->src_w << 16) / info->dst_w;
6809
6810     while (info->dst_h--) {
6811         Uint32 *src = 0;
6812         Uint32 *dst = (Uint32 *)info->dst;
6813         int n = info->dst_w;
6814         srcx = -1;
6815         posx = 0x10000L;
6816         while (posy >= 0x10000L) {
6817             ++srcy;
6818             posy -= 0x10000L;
6819         }
6820         while (n--) {
6821             if (posx >= 0x10000L) {
6822                 while (posx >= 0x10000L) {
6823                     ++srcx;
6824                     posx -= 0x10000L;
6825                 }
6826                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
6827             }
6828             srcpixel = *src;
6829             srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
6830             dstpixel = *dst;
6831             dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel;
6832             if (flags & SDL_COPY_MODULATE_COLOR) {
6833                 srcR = (srcR * modulateR) / 255;
6834                 srcG = (srcG * modulateG) / 255;
6835                 srcB = (srcB * modulateB) / 255;
6836             }
6837             if (flags & SDL_COPY_MODULATE_ALPHA) {
6838                 srcA = (srcA * modulateA) / 255;
6839             }
6840             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
6841                 /* This goes away if we ever use premultiplied alpha */
6842                 if (srcA < 255) {
6843                     srcR = (srcR * srcA) / 255;
6844                     srcG = (srcG * srcA) / 255;
6845                     srcB = (srcB * srcA) / 255;
6846                 }
6847             }
6848             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
6849             case SDL_COPY_BLEND:
6850                 dstR = srcR + ((255 - srcA) * dstR) / 255;
6851                 dstG = srcG + ((255 - srcA) * dstG) / 255;
6852                 dstB = srcB + ((255 - srcA) * dstB) / 255;
6853                 break;
6854             case SDL_COPY_ADD:
6855                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
6856                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
6857                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
6858                 break;
6859             case SDL_COPY_MOD:
6860                 dstR = (srcR * dstR) / 255;
6861                 dstG = (srcG * dstG) / 255;
6862                 dstB = (srcB * dstB) / 255;
6863                 break;
6864             }
6865             dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
6866             *dst = dstpixel;
6867             posx += incx;
6868             ++dst;
6869         }
6870         posy += incy;
6871         info->dst += info->dst_pitch;
6872     }
6873 }
6874
6875 static void SDL_Blit_BGRA8888_ARGB8888_Scale(SDL_BlitInfo *info)
6876 {
6877     Uint32 pixel;
6878     Uint32 R, G, B, A;
6879     int srcy, srcx;
6880     int posy, posx;
6881     int incy, incx;
6882
6883     srcy = 0;
6884     posy = 0;
6885     incy = (info->src_h << 16) / info->dst_h;
6886     incx = (info->src_w << 16) / info->dst_w;
6887
6888     while (info->dst_h--) {
6889         Uint32 *src = 0;
6890         Uint32 *dst = (Uint32 *)info->dst;
6891         int n = info->dst_w;
6892         srcx = -1;
6893         posx = 0x10000L;
6894         while (posy >= 0x10000L) {
6895             ++srcy;
6896             posy -= 0x10000L;
6897         }
6898         while (n--) {
6899             if (posx >= 0x10000L) {
6900                 while (posx >= 0x10000L) {
6901                     ++srcx;
6902                     posx -= 0x10000L;
6903                 }
6904                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
6905             }
6906             pixel = *src;
6907             B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8); A = (Uint8)pixel;
6908             pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
6909             *dst = pixel;
6910             posx += incx;
6911             ++dst;
6912         }
6913         posy += incy;
6914         info->dst += info->dst_pitch;
6915     }
6916 }
6917
6918 static void SDL_Blit_BGRA8888_ARGB8888_Blend(SDL_BlitInfo *info)
6919 {
6920     const int flags = info->flags;
6921     Uint32 srcpixel;
6922     Uint32 srcR, srcG, srcB, srcA;
6923     Uint32 dstpixel;
6924     Uint32 dstR, dstG, dstB, dstA;
6925
6926     while (info->dst_h--) {
6927         Uint32 *src = (Uint32 *)info->src;
6928         Uint32 *dst = (Uint32 *)info->dst;
6929         int n = info->dst_w;
6930         while (n--) {
6931             srcpixel = *src;
6932             srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
6933             dstpixel = *dst;
6934             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
6935             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
6936                 /* This goes away if we ever use premultiplied alpha */
6937                 if (srcA < 255) {
6938                     srcR = (srcR * srcA) / 255;
6939                     srcG = (srcG * srcA) / 255;
6940                     srcB = (srcB * srcA) / 255;
6941                 }
6942             }
6943             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
6944             case SDL_COPY_BLEND:
6945                 dstR = srcR + ((255 - srcA) * dstR) / 255;
6946                 dstG = srcG + ((255 - srcA) * dstG) / 255;
6947                 dstB = srcB + ((255 - srcA) * dstB) / 255;
6948                 dstA = srcA + ((255 - srcA) * dstA) / 255;
6949                 break;
6950             case SDL_COPY_ADD:
6951                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
6952                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
6953                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
6954                 break;
6955             case SDL_COPY_MOD:
6956                 dstR = (srcR * dstR) / 255;
6957                 dstG = (srcG * dstG) / 255;
6958                 dstB = (srcB * dstB) / 255;
6959                 break;
6960             }
6961             dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
6962             *dst = dstpixel;
6963             ++src;
6964             ++dst;
6965         }
6966         info->src += info->src_pitch;
6967         info->dst += info->dst_pitch;
6968     }
6969 }
6970
6971 static void SDL_Blit_BGRA8888_ARGB8888_Blend_Scale(SDL_BlitInfo *info)
6972 {
6973     const int flags = info->flags;
6974     Uint32 srcpixel;
6975     Uint32 srcR, srcG, srcB, srcA;
6976     Uint32 dstpixel;
6977     Uint32 dstR, dstG, dstB, dstA;
6978     int srcy, srcx;
6979     int posy, posx;
6980     int incy, incx;
6981
6982     srcy = 0;
6983     posy = 0;
6984     incy = (info->src_h << 16) / info->dst_h;
6985     incx = (info->src_w << 16) / info->dst_w;
6986
6987     while (info->dst_h--) {
6988         Uint32 *src = 0;
6989         Uint32 *dst = (Uint32 *)info->dst;
6990         int n = info->dst_w;
6991         srcx = -1;
6992         posx = 0x10000L;
6993         while (posy >= 0x10000L) {
6994             ++srcy;
6995             posy -= 0x10000L;
6996         }
6997         while (n--) {
6998             if (posx >= 0x10000L) {
6999                 while (posx >= 0x10000L) {
7000                     ++srcx;
7001                     posx -= 0x10000L;
7002                 }
7003                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
7004             }
7005             srcpixel = *src;
7006             srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
7007             dstpixel = *dst;
7008             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
7009             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
7010                 /* This goes away if we ever use premultiplied alpha */
7011                 if (srcA < 255) {
7012                     srcR = (srcR * srcA) / 255;
7013                     srcG = (srcG * srcA) / 255;
7014                     srcB = (srcB * srcA) / 255;
7015                 }
7016             }
7017             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
7018             case SDL_COPY_BLEND:
7019                 dstR = srcR + ((255 - srcA) * dstR) / 255;
7020                 dstG = srcG + ((255 - srcA) * dstG) / 255;
7021                 dstB = srcB + ((255 - srcA) * dstB) / 255;
7022                 dstA = srcA + ((255 - srcA) * dstA) / 255;
7023                 break;
7024             case SDL_COPY_ADD:
7025                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
7026                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
7027                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
7028                 break;
7029             case SDL_COPY_MOD:
7030                 dstR = (srcR * dstR) / 255;
7031                 dstG = (srcG * dstG) / 255;
7032                 dstB = (srcB * dstB) / 255;
7033                 break;
7034             }
7035             dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
7036             *dst = dstpixel;
7037             posx += incx;
7038             ++dst;
7039         }
7040         posy += incy;
7041         info->dst += info->dst_pitch;
7042     }
7043 }
7044
7045 static void SDL_Blit_BGRA8888_ARGB8888_Modulate(SDL_BlitInfo *info)
7046 {
7047     const int flags = info->flags;
7048     const Uint32 modulateR = info->r;
7049     const Uint32 modulateG = info->g;
7050     const Uint32 modulateB = info->b;
7051     const Uint32 modulateA = info->a;
7052     Uint32 pixel;
7053     Uint32 R, G, B, A;
7054
7055     while (info->dst_h--) {
7056         Uint32 *src = (Uint32 *)info->src;
7057         Uint32 *dst = (Uint32 *)info->dst;
7058         int n = info->dst_w;
7059         while (n--) {
7060             pixel = *src;
7061             B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8); A = (Uint8)pixel;
7062             if (flags & SDL_COPY_MODULATE_COLOR) {
7063                 R = (R * modulateR) / 255;
7064                 G = (G * modulateG) / 255;
7065                 B = (B * modulateB) / 255;
7066             }
7067             if (flags & SDL_COPY_MODULATE_ALPHA) {
7068                 A = (A * modulateA) / 255;
7069             }
7070             pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
7071             *dst = pixel;
7072             ++src;
7073             ++dst;
7074         }
7075         info->src += info->src_pitch;
7076         info->dst += info->dst_pitch;
7077     }
7078 }
7079
7080 static void SDL_Blit_BGRA8888_ARGB8888_Modulate_Scale(SDL_BlitInfo *info)
7081 {
7082     const int flags = info->flags;
7083     const Uint32 modulateR = info->r;
7084     const Uint32 modulateG = info->g;
7085     const Uint32 modulateB = info->b;
7086     const Uint32 modulateA = info->a;
7087     Uint32 pixel;
7088     Uint32 R, G, B, A;
7089     int srcy, srcx;
7090     int posy, posx;
7091     int incy, incx;
7092
7093     srcy = 0;
7094     posy = 0;
7095     incy = (info->src_h << 16) / info->dst_h;
7096     incx = (info->src_w << 16) / info->dst_w;
7097
7098     while (info->dst_h--) {
7099         Uint32 *src = 0;
7100         Uint32 *dst = (Uint32 *)info->dst;
7101         int n = info->dst_w;
7102         srcx = -1;
7103         posx = 0x10000L;
7104         while (posy >= 0x10000L) {
7105             ++srcy;
7106             posy -= 0x10000L;
7107         }
7108         while (n--) {
7109             if (posx >= 0x10000L) {
7110                 while (posx >= 0x10000L) {
7111                     ++srcx;
7112                     posx -= 0x10000L;
7113                 }
7114                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
7115             }
7116             pixel = *src;
7117             B = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); R = (Uint8)(pixel >> 8); A = (Uint8)pixel;
7118             if (flags & SDL_COPY_MODULATE_COLOR) {
7119                 R = (R * modulateR) / 255;
7120                 G = (G * modulateG) / 255;
7121                 B = (B * modulateB) / 255;
7122             }
7123             if (flags & SDL_COPY_MODULATE_ALPHA) {
7124                 A = (A * modulateA) / 255;
7125             }
7126             pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
7127             *dst = pixel;
7128             posx += incx;
7129             ++dst;
7130         }
7131         posy += incy;
7132         info->dst += info->dst_pitch;
7133     }
7134 }
7135
7136 static void SDL_Blit_BGRA8888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info)
7137 {
7138     const int flags = info->flags;
7139     const Uint32 modulateR = info->r;
7140     const Uint32 modulateG = info->g;
7141     const Uint32 modulateB = info->b;
7142     const Uint32 modulateA = info->a;
7143     Uint32 srcpixel;
7144     Uint32 srcR, srcG, srcB, srcA;
7145     Uint32 dstpixel;
7146     Uint32 dstR, dstG, dstB, dstA;
7147
7148     while (info->dst_h--) {
7149         Uint32 *src = (Uint32 *)info->src;
7150         Uint32 *dst = (Uint32 *)info->dst;
7151         int n = info->dst_w;
7152         while (n--) {
7153             srcpixel = *src;
7154             srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
7155             dstpixel = *dst;
7156             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
7157             if (flags & SDL_COPY_MODULATE_COLOR) {
7158                 srcR = (srcR * modulateR) / 255;
7159                 srcG = (srcG * modulateG) / 255;
7160                 srcB = (srcB * modulateB) / 255;
7161             }
7162             if (flags & SDL_COPY_MODULATE_ALPHA) {
7163                 srcA = (srcA * modulateA) / 255;
7164             }
7165             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
7166                 /* This goes away if we ever use premultiplied alpha */
7167                 if (srcA < 255) {
7168                     srcR = (srcR * srcA) / 255;
7169                     srcG = (srcG * srcA) / 255;
7170                     srcB = (srcB * srcA) / 255;
7171                 }
7172             }
7173             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
7174             case SDL_COPY_BLEND:
7175                 dstR = srcR + ((255 - srcA) * dstR) / 255;
7176                 dstG = srcG + ((255 - srcA) * dstG) / 255;
7177                 dstB = srcB + ((255 - srcA) * dstB) / 255;
7178                 dstA = srcA + ((255 - srcA) * dstA) / 255;
7179                 break;
7180             case SDL_COPY_ADD:
7181                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
7182                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
7183                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
7184                 break;
7185             case SDL_COPY_MOD:
7186                 dstR = (srcR * dstR) / 255;
7187                 dstG = (srcG * dstG) / 255;
7188                 dstB = (srcB * dstB) / 255;
7189                 break;
7190             }
7191             dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
7192             *dst = dstpixel;
7193             ++src;
7194             ++dst;
7195         }
7196         info->src += info->src_pitch;
7197         info->dst += info->dst_pitch;
7198     }
7199 }
7200
7201 static void SDL_Blit_BGRA8888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info)
7202 {
7203     const int flags = info->flags;
7204     const Uint32 modulateR = info->r;
7205     const Uint32 modulateG = info->g;
7206     const Uint32 modulateB = info->b;
7207     const Uint32 modulateA = info->a;
7208     Uint32 srcpixel;
7209     Uint32 srcR, srcG, srcB, srcA;
7210     Uint32 dstpixel;
7211     Uint32 dstR, dstG, dstB, dstA;
7212     int srcy, srcx;
7213     int posy, posx;
7214     int incy, incx;
7215
7216     srcy = 0;
7217     posy = 0;
7218     incy = (info->src_h << 16) / info->dst_h;
7219     incx = (info->src_w << 16) / info->dst_w;
7220
7221     while (info->dst_h--) {
7222         Uint32 *src = 0;
7223         Uint32 *dst = (Uint32 *)info->dst;
7224         int n = info->dst_w;
7225         srcx = -1;
7226         posx = 0x10000L;
7227         while (posy >= 0x10000L) {
7228             ++srcy;
7229             posy -= 0x10000L;
7230         }
7231         while (n--) {
7232             if (posx >= 0x10000L) {
7233                 while (posx >= 0x10000L) {
7234                     ++srcx;
7235                     posx -= 0x10000L;
7236                 }
7237                 src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
7238             }
7239             srcpixel = *src;
7240             srcB = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcR = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
7241             dstpixel = *dst;
7242             dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
7243             if (flags & SDL_COPY_MODULATE_COLOR) {
7244                 srcR = (srcR * modulateR) / 255;
7245                 srcG = (srcG * modulateG) / 255;
7246                 srcB = (srcB * modulateB) / 255;
7247             }
7248             if (flags & SDL_COPY_MODULATE_ALPHA) {
7249                 srcA = (srcA * modulateA) / 255;
7250             }
7251             if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
7252                 /* This goes away if we ever use premultiplied alpha */
7253                 if (srcA < 255) {
7254                     srcR = (srcR * srcA) / 255;
7255                     srcG = (srcG * srcA) / 255;
7256                     srcB = (srcB * srcA) / 255;
7257                 }
7258             }
7259             switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
7260             case SDL_COPY_BLEND:
7261                 dstR = srcR + ((255 - srcA) * dstR) / 255;
7262                 dstG = srcG + ((255 - srcA) * dstG) / 255;
7263                 dstB = srcB + ((255 - srcA) * dstB) / 255;
7264                 dstA = srcA + ((255 - srcA) * dstA) / 255;
7265                 break;
7266             case SDL_COPY_ADD:
7267                 dstR = srcR + dstR; if (dstR > 255) dstR = 255;
7268                 dstG = srcG + dstG; if (dstG > 255) dstG = 255;
7269                 dstB = srcB + dstB; if (dstB > 255) dstB = 255;
7270                 break;
7271             case SDL_COPY_MOD:
7272                 dstR = (srcR * dstR) / 255;
7273                 dstG = (srcG * dstG) / 255;
7274                 dstB = (srcB * dstB) / 255;
7275                 break;
7276             }
7277             dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
7278             *dst = dstpixel;
7279             posx += incx;
7280             ++dst;
7281         }
7282         posy += incy;
7283         info->dst += info->dst_pitch;
7284     }
7285 }
7286
7287 SDL_BlitFuncEntry SDL_GeneratedBlitFuncTable[] = {
7288     { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_RGB888_Scale },
7289     { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGB888_RGB888_Blend },
7290     { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_RGB888_Blend_Scale },
7291     { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_RGB888_RGB888_Modulate },
7292     { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_RGB888_Modulate_Scale },
7293     { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGB888_RGB888_Modulate_Blend },
7294     { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_RGB888_Modulate_Blend_Scale },
7295     { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_BGR888_Scale },
7296     { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGB888_BGR888_Blend },
7297     { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_BGR888_Blend_Scale },
7298     { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_RGB888_BGR888_Modulate },
7299     { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_BGR888_Modulate_Scale },
7300     { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGB888_BGR888_Modulate_Blend },
7301     { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_BGR888_Modulate_Blend_Scale },
7302     { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_ARGB8888_Scale },
7303     { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGB888_ARGB8888_Blend },
7304     { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_ARGB8888_Blend_Scale },
7305     { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_RGB888_ARGB8888_Modulate },
7306     { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_ARGB8888_Modulate_Scale },
7307     { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGB888_ARGB8888_Modulate_Blend },
7308     { SDL_PIXELFORMAT_RGB888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGB888_ARGB8888_Modulate_Blend_Scale },
7309     { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_RGB888_Scale },
7310     { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGR888_RGB888_Blend },
7311     { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_RGB888_Blend_Scale },
7312     { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_BGR888_RGB888_Modulate },
7313     { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_RGB888_Modulate_Scale },
7314     { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGR888_RGB888_Modulate_Blend },
7315     { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_RGB888_Modulate_Blend_Scale },
7316     { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_BGR888_Scale },
7317     { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGR888_BGR888_Blend },
7318     { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_BGR888_Blend_Scale },
7319     { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_BGR888_BGR888_Modulate },
7320     { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_BGR888_Modulate_Scale },
7321     { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGR888_BGR888_Modulate_Blend },
7322     { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_BGR888_Modulate_Blend_Scale },
7323     { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_ARGB8888_Scale },
7324     { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGR888_ARGB8888_Blend },
7325     { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_ARGB8888_Blend_Scale },
7326     { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_BGR888_ARGB8888_Modulate },
7327     { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_ARGB8888_Modulate_Scale },
7328     { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGR888_ARGB8888_Modulate_Blend },
7329     { SDL_PIXELFORMAT_BGR888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGR888_ARGB8888_Modulate_Blend_Scale },
7330     { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_RGB888_Scale },
7331     { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ARGB8888_RGB888_Blend },
7332     { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_RGB888_Blend_Scale },
7333     { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_ARGB8888_RGB888_Modulate },
7334     { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_RGB888_Modulate_Scale },
7335     { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ARGB8888_RGB888_Modulate_Blend },
7336     { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_RGB888_Modulate_Blend_Scale },
7337     { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_BGR888_Scale },
7338     { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ARGB8888_BGR888_Blend },
7339     { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_BGR888_Blend_Scale },
7340     { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_ARGB8888_BGR888_Modulate },
7341     { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_BGR888_Modulate_Scale },
7342     { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ARGB8888_BGR888_Modulate_Blend },
7343     { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_BGR888_Modulate_Blend_Scale },
7344     { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_ARGB8888_Scale },
7345     { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ARGB8888_ARGB8888_Blend },
7346     { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_ARGB8888_Blend_Scale },
7347     { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_ARGB8888_ARGB8888_Modulate },
7348     { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_ARGB8888_Modulate_Scale },
7349     { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ARGB8888_ARGB8888_Modulate_Blend },
7350     { SDL_PIXELFORMAT_ARGB8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ARGB8888_ARGB8888_Modulate_Blend_Scale },
7351     { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_RGB888_Scale },
7352     { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGBA8888_RGB888_Blend },
7353     { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_RGB888_Blend_Scale },
7354     { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_RGBA8888_RGB888_Modulate },
7355     { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_RGB888_Modulate_Scale },
7356     { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGBA8888_RGB888_Modulate_Blend },
7357     { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_RGB888_Modulate_Blend_Scale },
7358     { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_BGR888_Scale },
7359     { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGBA8888_BGR888_Blend },
7360     { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_BGR888_Blend_Scale },
7361     { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_RGBA8888_BGR888_Modulate },
7362     { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_BGR888_Modulate_Scale },
7363     { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGBA8888_BGR888_Modulate_Blend },
7364     { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_BGR888_Modulate_Blend_Scale },
7365     { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_ARGB8888_Scale },
7366     { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGBA8888_ARGB8888_Blend },
7367     { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_ARGB8888_Blend_Scale },
7368     { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_RGBA8888_ARGB8888_Modulate },
7369     { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_ARGB8888_Modulate_Scale },
7370     { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_RGBA8888_ARGB8888_Modulate_Blend },
7371     { SDL_PIXELFORMAT_RGBA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_RGBA8888_ARGB8888_Modulate_Blend_Scale },
7372     { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_RGB888_Scale },
7373     { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ABGR8888_RGB888_Blend },
7374     { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_RGB888_Blend_Scale },
7375     { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_ABGR8888_RGB888_Modulate },
7376     { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_RGB888_Modulate_Scale },
7377     { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ABGR8888_RGB888_Modulate_Blend },
7378     { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_RGB888_Modulate_Blend_Scale },
7379     { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_BGR888_Scale },
7380     { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ABGR8888_BGR888_Blend },
7381     { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_BGR888_Blend_Scale },
7382     { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_ABGR8888_BGR888_Modulate },
7383     { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_BGR888_Modulate_Scale },
7384     { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ABGR8888_BGR888_Modulate_Blend },
7385     { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_BGR888_Modulate_Blend_Scale },
7386     { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_ARGB8888_Scale },
7387     { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ABGR8888_ARGB8888_Blend },
7388     { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_ARGB8888_Blend_Scale },
7389     { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_ABGR8888_ARGB8888_Modulate },
7390     { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_ARGB8888_Modulate_Scale },
7391     { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_ABGR8888_ARGB8888_Modulate_Blend },
7392     { SDL_PIXELFORMAT_ABGR8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_ABGR8888_ARGB8888_Modulate_Blend_Scale },
7393     { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_RGB888_Scale },
7394     { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGRA8888_RGB888_Blend },
7395     { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_RGB888_Blend_Scale },
7396     { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_BGRA8888_RGB888_Modulate },
7397     { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_RGB888_Modulate_Scale },
7398     { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGRA8888_RGB888_Modulate_Blend },
7399     { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_RGB888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_RGB888_Modulate_Blend_Scale },
7400     { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_BGR888_Scale },
7401     { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGRA8888_BGR888_Blend },
7402     { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_BGR888_Blend_Scale },
7403     { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_BGRA8888_BGR888_Modulate },
7404     { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_BGR888_Modulate_Scale },
7405     { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGRA8888_BGR888_Modulate_Blend },
7406     { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_BGR888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_BGR888_Modulate_Blend_Scale },
7407     { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_ARGB8888_Scale },
7408     { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGRA8888_ARGB8888_Blend },
7409     { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_ARGB8888_Blend_Scale },
7410     { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA), SDL_CPU_ANY, SDL_Blit_BGRA8888_ARGB8888_Modulate },
7411     { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_ARGB8888_Modulate_Scale },
7412     { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD), SDL_CPU_ANY, SDL_Blit_BGRA8888_ARGB8888_Modulate_Blend },
7413     { SDL_PIXELFORMAT_BGRA8888, SDL_PIXELFORMAT_ARGB8888, (SDL_COPY_MODULATE_COLOR | SDL_COPY_MODULATE_ALPHA | SDL_COPY_BLEND | SDL_COPY_ADD | SDL_COPY_MOD | SDL_COPY_NEAREST), SDL_CPU_ANY, SDL_Blit_BGRA8888_ARGB8888_Modulate_Blend_Scale },
7414     { 0, 0, 0, 0, NULL }
7415 };
7416
7417 /* *INDENT-ON* */
7418
7419 /* vi: set ts=4 sw=4 expandtab: */