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