src/video/SDL_blit_auto.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 24 Jan 2010 21:10:53 +0000
changeset 3697 f7b03b6838cb
parent 2859 99210400e8b9
child 5140 e743b9c3f6d6
permissions -rw-r--r--
Fixed bug #926

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