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