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