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