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