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