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