PageRenderTime 595ms CodeModel.GetById 26ms app.highlight 528ms RepoModel.GetById 2ms app.codeStats 2ms

/project/jni/sdl-1.3/src/video/SDL_blit_auto.c

https://github.com/aichunyu/FFPlayer
C | 7491 lines | 7066 code | 329 blank | 96 comment | 1044 complexity | 3ae07b461596b922a17cf29366324a9e MD5 | raw file
   1/* DO NOT EDIT!  This file is generated by sdlgenblit.pl */
   2/*
   3  Simple DirectMedia Layer
   4  Copyright (C) 1997-2012 Sam Lantinga <slouken@libsdl.org>
   5
   6  This software is provided 'as-is', without any express or implied
   7  warranty.  In no event will the authors be held liable for any damages
   8  arising from the use of this software.
   9
  10  Permission is granted to anyone to use this software for any purpose,
  11  including commercial applications, and to alter it and redistribute it
  12  freely, subject to the following restrictions:
  13
  14  1. The origin of this software must not be misrepresented; you must not
  15     claim that you wrote the original software. If you use this software
  16     in a product, an acknowledgment in the product documentation would be
  17     appreciated but is not required.
  18  2. Altered source versions must be plainly marked as such, and must not be
  19     misrepresented as being the original software.
  20  3. This notice may not be removed or altered from any source distribution.
  21*/
  22#include "SDL_config.h"
  23
  24/* *INDENT-OFF* */
  25
  26#include "SDL_video.h"
  27#include "SDL_blit.h"
  28#include "SDL_blit_auto.h"
  29
  30static void SDL_Blit_RGB888_RGB888_Scale(SDL_BlitInfo *info)
  31{
  32    int srcy, srcx;
  33    int posy, posx;
  34    int incy, incx;
  35
  36    srcy = 0;
  37    posy = 0;
  38    incy = (info->src_h << 16) / info->dst_h;
  39    incx = (info->src_w << 16) / info->dst_w;
  40
  41    while (info->dst_h--) {
  42        Uint32 *src = 0;
  43        Uint32 *dst = (Uint32 *)info->dst;
  44        int n = info->dst_w;
  45        srcx = -1;
  46        posx = 0x10000L;
  47        while (posy >= 0x10000L) {
  48            ++srcy;
  49            posy -= 0x10000L;
  50        }
  51        while (n--) {
  52            if (posx >= 0x10000L) {
  53                while (posx >= 0x10000L) {
  54                    ++srcx;
  55                    posx -= 0x10000L;
  56                }
  57                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
  58            }
  59            *dst = *src;
  60            posx += incx;
  61            ++dst;
  62        }
  63        posy += incy;
  64        info->dst += info->dst_pitch;
  65    }
  66}
  67
  68static void SDL_Blit_RGB888_RGB888_Blend(SDL_BlitInfo *info)
  69{
  70    const int flags = info->flags;
  71    Uint32 srcpixel;
  72    Uint32 srcR, srcG, srcB, srcA;
  73    Uint32 dstpixel;
  74    Uint32 dstR, dstG, dstB, dstA;
  75
  76    while (info->dst_h--) {
  77        Uint32 *src = (Uint32 *)info->src;
  78        Uint32 *dst = (Uint32 *)info->dst;
  79        int n = info->dst_w;
  80        while (n--) {
  81            srcpixel = *src;
  82            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
  83            dstpixel = *dst;
  84            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
  85            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
  86                /* This goes away if we ever use premultiplied alpha */
  87                if (srcA < 255) {
  88                    srcR = (srcR * srcA) / 255;
  89                    srcG = (srcG * srcA) / 255;
  90                    srcB = (srcB * srcA) / 255;
  91                }
  92            }
  93            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
  94            case SDL_COPY_BLEND:
  95                dstR = srcR + ((255 - srcA) * dstR) / 255;
  96                dstG = srcG + ((255 - srcA) * dstG) / 255;
  97                dstB = srcB + ((255 - srcA) * dstB) / 255;
  98                break;
  99            case SDL_COPY_ADD:
 100                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
 101                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
 102                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
 103                break;
 104            case SDL_COPY_MOD:
 105                dstR = (srcR * dstR) / 255;
 106                dstG = (srcG * dstG) / 255;
 107                dstB = (srcB * dstB) / 255;
 108                break;
 109            }
 110            dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
 111            *dst = dstpixel;
 112            ++src;
 113            ++dst;
 114        }
 115        info->src += info->src_pitch;
 116        info->dst += info->dst_pitch;
 117    }
 118}
 119
 120static void SDL_Blit_RGB888_RGB888_Blend_Scale(SDL_BlitInfo *info)
 121{
 122    const int flags = info->flags;
 123    Uint32 srcpixel;
 124    Uint32 srcR, srcG, srcB, srcA;
 125    Uint32 dstpixel;
 126    Uint32 dstR, dstG, dstB, dstA;
 127    int srcy, srcx;
 128    int posy, posx;
 129    int incy, incx;
 130
 131    srcy = 0;
 132    posy = 0;
 133    incy = (info->src_h << 16) / info->dst_h;
 134    incx = (info->src_w << 16) / info->dst_w;
 135
 136    while (info->dst_h--) {
 137        Uint32 *src = 0;
 138        Uint32 *dst = (Uint32 *)info->dst;
 139        int n = info->dst_w;
 140        srcx = -1;
 141        posx = 0x10000L;
 142        while (posy >= 0x10000L) {
 143            ++srcy;
 144            posy -= 0x10000L;
 145        }
 146        while (n--) {
 147            if (posx >= 0x10000L) {
 148                while (posx >= 0x10000L) {
 149                    ++srcx;
 150                    posx -= 0x10000L;
 151                }
 152                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
 153            }
 154            srcpixel = *src;
 155            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
 156            dstpixel = *dst;
 157            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
 158            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
 159                /* This goes away if we ever use premultiplied alpha */
 160                if (srcA < 255) {
 161                    srcR = (srcR * srcA) / 255;
 162                    srcG = (srcG * srcA) / 255;
 163                    srcB = (srcB * srcA) / 255;
 164                }
 165            }
 166            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
 167            case SDL_COPY_BLEND:
 168                dstR = srcR + ((255 - srcA) * dstR) / 255;
 169                dstG = srcG + ((255 - srcA) * dstG) / 255;
 170                dstB = srcB + ((255 - srcA) * dstB) / 255;
 171                break;
 172            case SDL_COPY_ADD:
 173                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
 174                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
 175                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
 176                break;
 177            case SDL_COPY_MOD:
 178                dstR = (srcR * dstR) / 255;
 179                dstG = (srcG * dstG) / 255;
 180                dstB = (srcB * dstB) / 255;
 181                break;
 182            }
 183            dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
 184            *dst = dstpixel;
 185            posx += incx;
 186            ++dst;
 187        }
 188        posy += incy;
 189        info->dst += info->dst_pitch;
 190    }
 191}
 192
 193static void SDL_Blit_RGB888_RGB888_Modulate(SDL_BlitInfo *info)
 194{
 195    const int flags = info->flags;
 196    const Uint32 modulateR = info->r;
 197    const Uint32 modulateG = info->g;
 198    const Uint32 modulateB = info->b;
 199    const Uint32 modulateA = info->a;
 200    Uint32 pixel;
 201    Uint32 R, G, B, A;
 202
 203    while (info->dst_h--) {
 204        Uint32 *src = (Uint32 *)info->src;
 205        Uint32 *dst = (Uint32 *)info->dst;
 206        int n = info->dst_w;
 207        while (n--) {
 208            pixel = *src;
 209            R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF;
 210            if (flags & SDL_COPY_MODULATE_COLOR) {
 211                R = (R * modulateR) / 255;
 212                G = (G * modulateG) / 255;
 213                B = (B * modulateB) / 255;
 214            }
 215            if (flags & SDL_COPY_MODULATE_ALPHA) {
 216                A = (A * modulateA) / 255;
 217            }
 218            pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
 219            *dst = pixel;
 220            ++src;
 221            ++dst;
 222        }
 223        info->src += info->src_pitch;
 224        info->dst += info->dst_pitch;
 225    }
 226}
 227
 228static void SDL_Blit_RGB888_RGB888_Modulate_Scale(SDL_BlitInfo *info)
 229{
 230    const int flags = info->flags;
 231    const Uint32 modulateR = info->r;
 232    const Uint32 modulateG = info->g;
 233    const Uint32 modulateB = info->b;
 234    const Uint32 modulateA = info->a;
 235    Uint32 pixel;
 236    Uint32 R, G, B, A;
 237    int srcy, srcx;
 238    int posy, posx;
 239    int incy, incx;
 240
 241    srcy = 0;
 242    posy = 0;
 243    incy = (info->src_h << 16) / info->dst_h;
 244    incx = (info->src_w << 16) / info->dst_w;
 245
 246    while (info->dst_h--) {
 247        Uint32 *src = 0;
 248        Uint32 *dst = (Uint32 *)info->dst;
 249        int n = info->dst_w;
 250        srcx = -1;
 251        posx = 0x10000L;
 252        while (posy >= 0x10000L) {
 253            ++srcy;
 254            posy -= 0x10000L;
 255        }
 256        while (n--) {
 257            if (posx >= 0x10000L) {
 258                while (posx >= 0x10000L) {
 259                    ++srcx;
 260                    posx -= 0x10000L;
 261                }
 262                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
 263            }
 264            pixel = *src;
 265            R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF;
 266            if (flags & SDL_COPY_MODULATE_COLOR) {
 267                R = (R * modulateR) / 255;
 268                G = (G * modulateG) / 255;
 269                B = (B * modulateB) / 255;
 270            }
 271            if (flags & SDL_COPY_MODULATE_ALPHA) {
 272                A = (A * modulateA) / 255;
 273            }
 274            pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
 275            *dst = pixel;
 276            posx += incx;
 277            ++dst;
 278        }
 279        posy += incy;
 280        info->dst += info->dst_pitch;
 281    }
 282}
 283
 284static void SDL_Blit_RGB888_RGB888_Modulate_Blend(SDL_BlitInfo *info)
 285{
 286    const int flags = info->flags;
 287    const Uint32 modulateR = info->r;
 288    const Uint32 modulateG = info->g;
 289    const Uint32 modulateB = info->b;
 290    const Uint32 modulateA = info->a;
 291    Uint32 srcpixel;
 292    Uint32 srcR, srcG, srcB, srcA;
 293    Uint32 dstpixel;
 294    Uint32 dstR, dstG, dstB, dstA;
 295
 296    while (info->dst_h--) {
 297        Uint32 *src = (Uint32 *)info->src;
 298        Uint32 *dst = (Uint32 *)info->dst;
 299        int n = info->dst_w;
 300        while (n--) {
 301            srcpixel = *src;
 302            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
 303            dstpixel = *dst;
 304            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
 305            if (flags & SDL_COPY_MODULATE_COLOR) {
 306                srcR = (srcR * modulateR) / 255;
 307                srcG = (srcG * modulateG) / 255;
 308                srcB = (srcB * modulateB) / 255;
 309            }
 310            if (flags & SDL_COPY_MODULATE_ALPHA) {
 311                srcA = (srcA * modulateA) / 255;
 312            }
 313            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
 314                /* This goes away if we ever use premultiplied alpha */
 315                if (srcA < 255) {
 316                    srcR = (srcR * srcA) / 255;
 317                    srcG = (srcG * srcA) / 255;
 318                    srcB = (srcB * srcA) / 255;
 319                }
 320            }
 321            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
 322            case SDL_COPY_BLEND:
 323                dstR = srcR + ((255 - srcA) * dstR) / 255;
 324                dstG = srcG + ((255 - srcA) * dstG) / 255;
 325                dstB = srcB + ((255 - srcA) * dstB) / 255;
 326                break;
 327            case SDL_COPY_ADD:
 328                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
 329                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
 330                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
 331                break;
 332            case SDL_COPY_MOD:
 333                dstR = (srcR * dstR) / 255;
 334                dstG = (srcG * dstG) / 255;
 335                dstB = (srcB * dstB) / 255;
 336                break;
 337            }
 338            dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
 339            *dst = dstpixel;
 340            ++src;
 341            ++dst;
 342        }
 343        info->src += info->src_pitch;
 344        info->dst += info->dst_pitch;
 345    }
 346}
 347
 348static void SDL_Blit_RGB888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info)
 349{
 350    const int flags = info->flags;
 351    const Uint32 modulateR = info->r;
 352    const Uint32 modulateG = info->g;
 353    const Uint32 modulateB = info->b;
 354    const Uint32 modulateA = info->a;
 355    Uint32 srcpixel;
 356    Uint32 srcR, srcG, srcB, srcA;
 357    Uint32 dstpixel;
 358    Uint32 dstR, dstG, dstB, dstA;
 359    int srcy, srcx;
 360    int posy, posx;
 361    int incy, incx;
 362
 363    srcy = 0;
 364    posy = 0;
 365    incy = (info->src_h << 16) / info->dst_h;
 366    incx = (info->src_w << 16) / info->dst_w;
 367
 368    while (info->dst_h--) {
 369        Uint32 *src = 0;
 370        Uint32 *dst = (Uint32 *)info->dst;
 371        int n = info->dst_w;
 372        srcx = -1;
 373        posx = 0x10000L;
 374        while (posy >= 0x10000L) {
 375            ++srcy;
 376            posy -= 0x10000L;
 377        }
 378        while (n--) {
 379            if (posx >= 0x10000L) {
 380                while (posx >= 0x10000L) {
 381                    ++srcx;
 382                    posx -= 0x10000L;
 383                }
 384                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
 385            }
 386            srcpixel = *src;
 387            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
 388            dstpixel = *dst;
 389            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
 390            if (flags & SDL_COPY_MODULATE_COLOR) {
 391                srcR = (srcR * modulateR) / 255;
 392                srcG = (srcG * modulateG) / 255;
 393                srcB = (srcB * modulateB) / 255;
 394            }
 395            if (flags & SDL_COPY_MODULATE_ALPHA) {
 396                srcA = (srcA * modulateA) / 255;
 397            }
 398            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
 399                /* This goes away if we ever use premultiplied alpha */
 400                if (srcA < 255) {
 401                    srcR = (srcR * srcA) / 255;
 402                    srcG = (srcG * srcA) / 255;
 403                    srcB = (srcB * srcA) / 255;
 404                }
 405            }
 406            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
 407            case SDL_COPY_BLEND:
 408                dstR = srcR + ((255 - srcA) * dstR) / 255;
 409                dstG = srcG + ((255 - srcA) * dstG) / 255;
 410                dstB = srcB + ((255 - srcA) * dstB) / 255;
 411                break;
 412            case SDL_COPY_ADD:
 413                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
 414                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
 415                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
 416                break;
 417            case SDL_COPY_MOD:
 418                dstR = (srcR * dstR) / 255;
 419                dstG = (srcG * dstG) / 255;
 420                dstB = (srcB * dstB) / 255;
 421                break;
 422            }
 423            dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
 424            *dst = dstpixel;
 425            posx += incx;
 426            ++dst;
 427        }
 428        posy += incy;
 429        info->dst += info->dst_pitch;
 430    }
 431}
 432
 433static void SDL_Blit_RGB888_BGR888_Scale(SDL_BlitInfo *info)
 434{
 435    Uint32 pixel;
 436    Uint32 R, G, B, A;
 437    int srcy, srcx;
 438    int posy, posx;
 439    int incy, incx;
 440
 441    srcy = 0;
 442    posy = 0;
 443    incy = (info->src_h << 16) / info->dst_h;
 444    incx = (info->src_w << 16) / info->dst_w;
 445
 446    while (info->dst_h--) {
 447        Uint32 *src = 0;
 448        Uint32 *dst = (Uint32 *)info->dst;
 449        int n = info->dst_w;
 450        srcx = -1;
 451        posx = 0x10000L;
 452        while (posy >= 0x10000L) {
 453            ++srcy;
 454            posy -= 0x10000L;
 455        }
 456        while (n--) {
 457            if (posx >= 0x10000L) {
 458                while (posx >= 0x10000L) {
 459                    ++srcx;
 460                    posx -= 0x10000L;
 461                }
 462                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
 463            }
 464            pixel = *src;
 465            R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF;
 466            pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
 467            *dst = pixel;
 468            posx += incx;
 469            ++dst;
 470        }
 471        posy += incy;
 472        info->dst += info->dst_pitch;
 473    }
 474}
 475
 476static void SDL_Blit_RGB888_BGR888_Blend(SDL_BlitInfo *info)
 477{
 478    const int flags = info->flags;
 479    Uint32 srcpixel;
 480    Uint32 srcR, srcG, srcB, srcA;
 481    Uint32 dstpixel;
 482    Uint32 dstR, dstG, dstB, dstA;
 483
 484    while (info->dst_h--) {
 485        Uint32 *src = (Uint32 *)info->src;
 486        Uint32 *dst = (Uint32 *)info->dst;
 487        int n = info->dst_w;
 488        while (n--) {
 489            srcpixel = *src;
 490            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
 491            dstpixel = *dst;
 492            dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
 493            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
 494                /* This goes away if we ever use premultiplied alpha */
 495                if (srcA < 255) {
 496                    srcR = (srcR * srcA) / 255;
 497                    srcG = (srcG * srcA) / 255;
 498                    srcB = (srcB * srcA) / 255;
 499                }
 500            }
 501            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
 502            case SDL_COPY_BLEND:
 503                dstR = srcR + ((255 - srcA) * dstR) / 255;
 504                dstG = srcG + ((255 - srcA) * dstG) / 255;
 505                dstB = srcB + ((255 - srcA) * dstB) / 255;
 506                break;
 507            case SDL_COPY_ADD:
 508                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
 509                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
 510                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
 511                break;
 512            case SDL_COPY_MOD:
 513                dstR = (srcR * dstR) / 255;
 514                dstG = (srcG * dstG) / 255;
 515                dstB = (srcB * dstB) / 255;
 516                break;
 517            }
 518            dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
 519            *dst = dstpixel;
 520            ++src;
 521            ++dst;
 522        }
 523        info->src += info->src_pitch;
 524        info->dst += info->dst_pitch;
 525    }
 526}
 527
 528static void SDL_Blit_RGB888_BGR888_Blend_Scale(SDL_BlitInfo *info)
 529{
 530    const int flags = info->flags;
 531    Uint32 srcpixel;
 532    Uint32 srcR, srcG, srcB, srcA;
 533    Uint32 dstpixel;
 534    Uint32 dstR, dstG, dstB, dstA;
 535    int srcy, srcx;
 536    int posy, posx;
 537    int incy, incx;
 538
 539    srcy = 0;
 540    posy = 0;
 541    incy = (info->src_h << 16) / info->dst_h;
 542    incx = (info->src_w << 16) / info->dst_w;
 543
 544    while (info->dst_h--) {
 545        Uint32 *src = 0;
 546        Uint32 *dst = (Uint32 *)info->dst;
 547        int n = info->dst_w;
 548        srcx = -1;
 549        posx = 0x10000L;
 550        while (posy >= 0x10000L) {
 551            ++srcy;
 552            posy -= 0x10000L;
 553        }
 554        while (n--) {
 555            if (posx >= 0x10000L) {
 556                while (posx >= 0x10000L) {
 557                    ++srcx;
 558                    posx -= 0x10000L;
 559                }
 560                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
 561            }
 562            srcpixel = *src;
 563            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
 564            dstpixel = *dst;
 565            dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
 566            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
 567                /* This goes away if we ever use premultiplied alpha */
 568                if (srcA < 255) {
 569                    srcR = (srcR * srcA) / 255;
 570                    srcG = (srcG * srcA) / 255;
 571                    srcB = (srcB * srcA) / 255;
 572                }
 573            }
 574            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
 575            case SDL_COPY_BLEND:
 576                dstR = srcR + ((255 - srcA) * dstR) / 255;
 577                dstG = srcG + ((255 - srcA) * dstG) / 255;
 578                dstB = srcB + ((255 - srcA) * dstB) / 255;
 579                break;
 580            case SDL_COPY_ADD:
 581                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
 582                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
 583                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
 584                break;
 585            case SDL_COPY_MOD:
 586                dstR = (srcR * dstR) / 255;
 587                dstG = (srcG * dstG) / 255;
 588                dstB = (srcB * dstB) / 255;
 589                break;
 590            }
 591            dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
 592            *dst = dstpixel;
 593            posx += incx;
 594            ++dst;
 595        }
 596        posy += incy;
 597        info->dst += info->dst_pitch;
 598    }
 599}
 600
 601static void SDL_Blit_RGB888_BGR888_Modulate(SDL_BlitInfo *info)
 602{
 603    const int flags = info->flags;
 604    const Uint32 modulateR = info->r;
 605    const Uint32 modulateG = info->g;
 606    const Uint32 modulateB = info->b;
 607    const Uint32 modulateA = info->a;
 608    Uint32 pixel;
 609    Uint32 R, G, B, A;
 610
 611    while (info->dst_h--) {
 612        Uint32 *src = (Uint32 *)info->src;
 613        Uint32 *dst = (Uint32 *)info->dst;
 614        int n = info->dst_w;
 615        while (n--) {
 616            pixel = *src;
 617            R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF;
 618            if (flags & SDL_COPY_MODULATE_COLOR) {
 619                R = (R * modulateR) / 255;
 620                G = (G * modulateG) / 255;
 621                B = (B * modulateB) / 255;
 622            }
 623            if (flags & SDL_COPY_MODULATE_ALPHA) {
 624                A = (A * modulateA) / 255;
 625            }
 626            pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
 627            *dst = pixel;
 628            ++src;
 629            ++dst;
 630        }
 631        info->src += info->src_pitch;
 632        info->dst += info->dst_pitch;
 633    }
 634}
 635
 636static void SDL_Blit_RGB888_BGR888_Modulate_Scale(SDL_BlitInfo *info)
 637{
 638    const int flags = info->flags;
 639    const Uint32 modulateR = info->r;
 640    const Uint32 modulateG = info->g;
 641    const Uint32 modulateB = info->b;
 642    const Uint32 modulateA = info->a;
 643    Uint32 pixel;
 644    Uint32 R, G, B, A;
 645    int srcy, srcx;
 646    int posy, posx;
 647    int incy, incx;
 648
 649    srcy = 0;
 650    posy = 0;
 651    incy = (info->src_h << 16) / info->dst_h;
 652    incx = (info->src_w << 16) / info->dst_w;
 653
 654    while (info->dst_h--) {
 655        Uint32 *src = 0;
 656        Uint32 *dst = (Uint32 *)info->dst;
 657        int n = info->dst_w;
 658        srcx = -1;
 659        posx = 0x10000L;
 660        while (posy >= 0x10000L) {
 661            ++srcy;
 662            posy -= 0x10000L;
 663        }
 664        while (n--) {
 665            if (posx >= 0x10000L) {
 666                while (posx >= 0x10000L) {
 667                    ++srcx;
 668                    posx -= 0x10000L;
 669                }
 670                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
 671            }
 672            pixel = *src;
 673            R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF;
 674            if (flags & SDL_COPY_MODULATE_COLOR) {
 675                R = (R * modulateR) / 255;
 676                G = (G * modulateG) / 255;
 677                B = (B * modulateB) / 255;
 678            }
 679            if (flags & SDL_COPY_MODULATE_ALPHA) {
 680                A = (A * modulateA) / 255;
 681            }
 682            pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
 683            *dst = pixel;
 684            posx += incx;
 685            ++dst;
 686        }
 687        posy += incy;
 688        info->dst += info->dst_pitch;
 689    }
 690}
 691
 692static void SDL_Blit_RGB888_BGR888_Modulate_Blend(SDL_BlitInfo *info)
 693{
 694    const int flags = info->flags;
 695    const Uint32 modulateR = info->r;
 696    const Uint32 modulateG = info->g;
 697    const Uint32 modulateB = info->b;
 698    const Uint32 modulateA = info->a;
 699    Uint32 srcpixel;
 700    Uint32 srcR, srcG, srcB, srcA;
 701    Uint32 dstpixel;
 702    Uint32 dstR, dstG, dstB, dstA;
 703
 704    while (info->dst_h--) {
 705        Uint32 *src = (Uint32 *)info->src;
 706        Uint32 *dst = (Uint32 *)info->dst;
 707        int n = info->dst_w;
 708        while (n--) {
 709            srcpixel = *src;
 710            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
 711            dstpixel = *dst;
 712            dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
 713            if (flags & SDL_COPY_MODULATE_COLOR) {
 714                srcR = (srcR * modulateR) / 255;
 715                srcG = (srcG * modulateG) / 255;
 716                srcB = (srcB * modulateB) / 255;
 717            }
 718            if (flags & SDL_COPY_MODULATE_ALPHA) {
 719                srcA = (srcA * modulateA) / 255;
 720            }
 721            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
 722                /* This goes away if we ever use premultiplied alpha */
 723                if (srcA < 255) {
 724                    srcR = (srcR * srcA) / 255;
 725                    srcG = (srcG * srcA) / 255;
 726                    srcB = (srcB * srcA) / 255;
 727                }
 728            }
 729            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
 730            case SDL_COPY_BLEND:
 731                dstR = srcR + ((255 - srcA) * dstR) / 255;
 732                dstG = srcG + ((255 - srcA) * dstG) / 255;
 733                dstB = srcB + ((255 - srcA) * dstB) / 255;
 734                break;
 735            case SDL_COPY_ADD:
 736                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
 737                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
 738                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
 739                break;
 740            case SDL_COPY_MOD:
 741                dstR = (srcR * dstR) / 255;
 742                dstG = (srcG * dstG) / 255;
 743                dstB = (srcB * dstB) / 255;
 744                break;
 745            }
 746            dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
 747            *dst = dstpixel;
 748            ++src;
 749            ++dst;
 750        }
 751        info->src += info->src_pitch;
 752        info->dst += info->dst_pitch;
 753    }
 754}
 755
 756static void SDL_Blit_RGB888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info)
 757{
 758    const int flags = info->flags;
 759    const Uint32 modulateR = info->r;
 760    const Uint32 modulateG = info->g;
 761    const Uint32 modulateB = info->b;
 762    const Uint32 modulateA = info->a;
 763    Uint32 srcpixel;
 764    Uint32 srcR, srcG, srcB, srcA;
 765    Uint32 dstpixel;
 766    Uint32 dstR, dstG, dstB, dstA;
 767    int srcy, srcx;
 768    int posy, posx;
 769    int incy, incx;
 770
 771    srcy = 0;
 772    posy = 0;
 773    incy = (info->src_h << 16) / info->dst_h;
 774    incx = (info->src_w << 16) / info->dst_w;
 775
 776    while (info->dst_h--) {
 777        Uint32 *src = 0;
 778        Uint32 *dst = (Uint32 *)info->dst;
 779        int n = info->dst_w;
 780        srcx = -1;
 781        posx = 0x10000L;
 782        while (posy >= 0x10000L) {
 783            ++srcy;
 784            posy -= 0x10000L;
 785        }
 786        while (n--) {
 787            if (posx >= 0x10000L) {
 788                while (posx >= 0x10000L) {
 789                    ++srcx;
 790                    posx -= 0x10000L;
 791                }
 792                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
 793            }
 794            srcpixel = *src;
 795            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
 796            dstpixel = *dst;
 797            dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
 798            if (flags & SDL_COPY_MODULATE_COLOR) {
 799                srcR = (srcR * modulateR) / 255;
 800                srcG = (srcG * modulateG) / 255;
 801                srcB = (srcB * modulateB) / 255;
 802            }
 803            if (flags & SDL_COPY_MODULATE_ALPHA) {
 804                srcA = (srcA * modulateA) / 255;
 805            }
 806            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
 807                /* This goes away if we ever use premultiplied alpha */
 808                if (srcA < 255) {
 809                    srcR = (srcR * srcA) / 255;
 810                    srcG = (srcG * srcA) / 255;
 811                    srcB = (srcB * srcA) / 255;
 812                }
 813            }
 814            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
 815            case SDL_COPY_BLEND:
 816                dstR = srcR + ((255 - srcA) * dstR) / 255;
 817                dstG = srcG + ((255 - srcA) * dstG) / 255;
 818                dstB = srcB + ((255 - srcA) * dstB) / 255;
 819                break;
 820            case SDL_COPY_ADD:
 821                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
 822                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
 823                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
 824                break;
 825            case SDL_COPY_MOD:
 826                dstR = (srcR * dstR) / 255;
 827                dstG = (srcG * dstG) / 255;
 828                dstB = (srcB * dstB) / 255;
 829                break;
 830            }
 831            dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
 832            *dst = dstpixel;
 833            posx += incx;
 834            ++dst;
 835        }
 836        posy += incy;
 837        info->dst += info->dst_pitch;
 838    }
 839}
 840
 841static void SDL_Blit_RGB888_ARGB8888_Scale(SDL_BlitInfo *info)
 842{
 843    Uint32 pixel;
 844    Uint32 R, G, B, A;
 845    int srcy, srcx;
 846    int posy, posx;
 847    int incy, incx;
 848
 849    srcy = 0;
 850    posy = 0;
 851    incy = (info->src_h << 16) / info->dst_h;
 852    incx = (info->src_w << 16) / info->dst_w;
 853
 854    while (info->dst_h--) {
 855        Uint32 *src = 0;
 856        Uint32 *dst = (Uint32 *)info->dst;
 857        int n = info->dst_w;
 858        srcx = -1;
 859        posx = 0x10000L;
 860        while (posy >= 0x10000L) {
 861            ++srcy;
 862            posy -= 0x10000L;
 863        }
 864        while (n--) {
 865            if (posx >= 0x10000L) {
 866                while (posx >= 0x10000L) {
 867                    ++srcx;
 868                    posx -= 0x10000L;
 869                }
 870                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
 871            }
 872            pixel = *src;
 873            R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF;
 874            pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
 875            *dst = pixel;
 876            posx += incx;
 877            ++dst;
 878        }
 879        posy += incy;
 880        info->dst += info->dst_pitch;
 881    }
 882}
 883
 884static void SDL_Blit_RGB888_ARGB8888_Blend(SDL_BlitInfo *info)
 885{
 886    const int flags = info->flags;
 887    Uint32 srcpixel;
 888    Uint32 srcR, srcG, srcB, srcA;
 889    Uint32 dstpixel;
 890    Uint32 dstR, dstG, dstB, dstA;
 891
 892    while (info->dst_h--) {
 893        Uint32 *src = (Uint32 *)info->src;
 894        Uint32 *dst = (Uint32 *)info->dst;
 895        int n = info->dst_w;
 896        while (n--) {
 897            srcpixel = *src;
 898            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
 899            dstpixel = *dst;
 900            dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
 901            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
 902                /* This goes away if we ever use premultiplied alpha */
 903                if (srcA < 255) {
 904                    srcR = (srcR * srcA) / 255;
 905                    srcG = (srcG * srcA) / 255;
 906                    srcB = (srcB * srcA) / 255;
 907                }
 908            }
 909            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
 910            case SDL_COPY_BLEND:
 911                dstR = srcR + ((255 - srcA) * dstR) / 255;
 912                dstG = srcG + ((255 - srcA) * dstG) / 255;
 913                dstB = srcB + ((255 - srcA) * dstB) / 255;
 914                break;
 915            case SDL_COPY_ADD:
 916                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
 917                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
 918                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
 919                break;
 920            case SDL_COPY_MOD:
 921                dstR = (srcR * dstR) / 255;
 922                dstG = (srcG * dstG) / 255;
 923                dstB = (srcB * dstB) / 255;
 924                break;
 925            }
 926            dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
 927            *dst = dstpixel;
 928            ++src;
 929            ++dst;
 930        }
 931        info->src += info->src_pitch;
 932        info->dst += info->dst_pitch;
 933    }
 934}
 935
 936static void SDL_Blit_RGB888_ARGB8888_Blend_Scale(SDL_BlitInfo *info)
 937{
 938    const int flags = info->flags;
 939    Uint32 srcpixel;
 940    Uint32 srcR, srcG, srcB, srcA;
 941    Uint32 dstpixel;
 942    Uint32 dstR, dstG, dstB, dstA;
 943    int srcy, srcx;
 944    int posy, posx;
 945    int incy, incx;
 946
 947    srcy = 0;
 948    posy = 0;
 949    incy = (info->src_h << 16) / info->dst_h;
 950    incx = (info->src_w << 16) / info->dst_w;
 951
 952    while (info->dst_h--) {
 953        Uint32 *src = 0;
 954        Uint32 *dst = (Uint32 *)info->dst;
 955        int n = info->dst_w;
 956        srcx = -1;
 957        posx = 0x10000L;
 958        while (posy >= 0x10000L) {
 959            ++srcy;
 960            posy -= 0x10000L;
 961        }
 962        while (n--) {
 963            if (posx >= 0x10000L) {
 964                while (posx >= 0x10000L) {
 965                    ++srcx;
 966                    posx -= 0x10000L;
 967                }
 968                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
 969            }
 970            srcpixel = *src;
 971            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
 972            dstpixel = *dst;
 973            dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
 974            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
 975                /* This goes away if we ever use premultiplied alpha */
 976                if (srcA < 255) {
 977                    srcR = (srcR * srcA) / 255;
 978                    srcG = (srcG * srcA) / 255;
 979                    srcB = (srcB * srcA) / 255;
 980                }
 981            }
 982            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
 983            case SDL_COPY_BLEND:
 984                dstR = srcR + ((255 - srcA) * dstR) / 255;
 985                dstG = srcG + ((255 - srcA) * dstG) / 255;
 986                dstB = srcB + ((255 - srcA) * dstB) / 255;
 987                break;
 988            case SDL_COPY_ADD:
 989                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
 990                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
 991                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
 992                break;
 993            case SDL_COPY_MOD:
 994                dstR = (srcR * dstR) / 255;
 995                dstG = (srcG * dstG) / 255;
 996                dstB = (srcB * dstB) / 255;
 997                break;
 998            }
 999            dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
1000            *dst = dstpixel;
1001            posx += incx;
1002            ++dst;
1003        }
1004        posy += incy;
1005        info->dst += info->dst_pitch;
1006    }
1007}
1008
1009static void SDL_Blit_RGB888_ARGB8888_Modulate(SDL_BlitInfo *info)
1010{
1011    const int flags = info->flags;
1012    const Uint32 modulateR = info->r;
1013    const Uint32 modulateG = info->g;
1014    const Uint32 modulateB = info->b;
1015    const Uint32 modulateA = info->a;
1016    Uint32 pixel;
1017    Uint32 R, G, B, A;
1018
1019    while (info->dst_h--) {
1020        Uint32 *src = (Uint32 *)info->src;
1021        Uint32 *dst = (Uint32 *)info->dst;
1022        int n = info->dst_w;
1023        while (n--) {
1024            pixel = *src;
1025            R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF;
1026            if (flags & SDL_COPY_MODULATE_COLOR) {
1027                R = (R * modulateR) / 255;
1028                G = (G * modulateG) / 255;
1029                B = (B * modulateB) / 255;
1030            }
1031            if (flags & SDL_COPY_MODULATE_ALPHA) {
1032                A = (A * modulateA) / 255;
1033            }
1034            pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
1035            *dst = pixel;
1036            ++src;
1037            ++dst;
1038        }
1039        info->src += info->src_pitch;
1040        info->dst += info->dst_pitch;
1041    }
1042}
1043
1044static void SDL_Blit_RGB888_ARGB8888_Modulate_Scale(SDL_BlitInfo *info)
1045{
1046    const int flags = info->flags;
1047    const Uint32 modulateR = info->r;
1048    const Uint32 modulateG = info->g;
1049    const Uint32 modulateB = info->b;
1050    const Uint32 modulateA = info->a;
1051    Uint32 pixel;
1052    Uint32 R, G, B, A;
1053    int srcy, srcx;
1054    int posy, posx;
1055    int incy, incx;
1056
1057    srcy = 0;
1058    posy = 0;
1059    incy = (info->src_h << 16) / info->dst_h;
1060    incx = (info->src_w << 16) / info->dst_w;
1061
1062    while (info->dst_h--) {
1063        Uint32 *src = 0;
1064        Uint32 *dst = (Uint32 *)info->dst;
1065        int n = info->dst_w;
1066        srcx = -1;
1067        posx = 0x10000L;
1068        while (posy >= 0x10000L) {
1069            ++srcy;
1070            posy -= 0x10000L;
1071        }
1072        while (n--) {
1073            if (posx >= 0x10000L) {
1074                while (posx >= 0x10000L) {
1075                    ++srcx;
1076                    posx -= 0x10000L;
1077                }
1078                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
1079            }
1080            pixel = *src;
1081            R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF;
1082            if (flags & SDL_COPY_MODULATE_COLOR) {
1083                R = (R * modulateR) / 255;
1084                G = (G * modulateG) / 255;
1085                B = (B * modulateB) / 255;
1086            }
1087            if (flags & SDL_COPY_MODULATE_ALPHA) {
1088                A = (A * modulateA) / 255;
1089            }
1090            pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
1091            *dst = pixel;
1092            posx += incx;
1093            ++dst;
1094        }
1095        posy += incy;
1096        info->dst += info->dst_pitch;
1097    }
1098}
1099
1100static void SDL_Blit_RGB888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info)
1101{
1102    const int flags = info->flags;
1103    const Uint32 modulateR = info->r;
1104    const Uint32 modulateG = info->g;
1105    const Uint32 modulateB = info->b;
1106    const Uint32 modulateA = info->a;
1107    Uint32 srcpixel;
1108    Uint32 srcR, srcG, srcB, srcA;
1109    Uint32 dstpixel;
1110    Uint32 dstR, dstG, dstB, dstA;
1111
1112    while (info->dst_h--) {
1113        Uint32 *src = (Uint32 *)info->src;
1114        Uint32 *dst = (Uint32 *)info->dst;
1115        int n = info->dst_w;
1116        while (n--) {
1117            srcpixel = *src;
1118            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
1119            dstpixel = *dst;
1120            dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
1121            if (flags & SDL_COPY_MODULATE_COLOR) {
1122                srcR = (srcR * modulateR) / 255;
1123                srcG = (srcG * modulateG) / 255;
1124                srcB = (srcB * modulateB) / 255;
1125            }
1126            if (flags & SDL_COPY_MODULATE_ALPHA) {
1127                srcA = (srcA * modulateA) / 255;
1128            }
1129            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
1130                /* This goes away if we ever use premultiplied alpha */
1131                if (srcA < 255) {
1132                    srcR = (srcR * srcA) / 255;
1133                    srcG = (srcG * srcA) / 255;
1134                    srcB = (srcB * srcA) / 255;
1135                }
1136            }
1137            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
1138            case SDL_COPY_BLEND:
1139                dstR = srcR + ((255 - srcA) * dstR) / 255;
1140                dstG = srcG + ((255 - srcA) * dstG) / 255;
1141                dstB = srcB + ((255 - srcA) * dstB) / 255;
1142                break;
1143            case SDL_COPY_ADD:
1144                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
1145                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
1146                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
1147                break;
1148            case SDL_COPY_MOD:
1149                dstR = (srcR * dstR) / 255;
1150                dstG = (srcG * dstG) / 255;
1151                dstB = (srcB * dstB) / 255;
1152                break;
1153            }
1154            dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
1155            *dst = dstpixel;
1156            ++src;
1157            ++dst;
1158        }
1159        info->src += info->src_pitch;
1160        info->dst += info->dst_pitch;
1161    }
1162}
1163
1164static void SDL_Blit_RGB888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info)
1165{
1166    const int flags = info->flags;
1167    const Uint32 modulateR = info->r;
1168    const Uint32 modulateG = info->g;
1169    const Uint32 modulateB = info->b;
1170    const Uint32 modulateA = info->a;
1171    Uint32 srcpixel;
1172    Uint32 srcR, srcG, srcB, srcA;
1173    Uint32 dstpixel;
1174    Uint32 dstR, dstG, dstB, dstA;
1175    int srcy, srcx;
1176    int posy, posx;
1177    int incy, incx;
1178
1179    srcy = 0;
1180    posy = 0;
1181    incy = (info->src_h << 16) / info->dst_h;
1182    incx = (info->src_w << 16) / info->dst_w;
1183
1184    while (info->dst_h--) {
1185        Uint32 *src = 0;
1186        Uint32 *dst = (Uint32 *)info->dst;
1187        int n = info->dst_w;
1188        srcx = -1;
1189        posx = 0x10000L;
1190        while (posy >= 0x10000L) {
1191            ++srcy;
1192            posy -= 0x10000L;
1193        }
1194        while (n--) {
1195            if (posx >= 0x10000L) {
1196                while (posx >= 0x10000L) {
1197                    ++srcx;
1198                    posx -= 0x10000L;
1199                }
1200                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
1201            }
1202            srcpixel = *src;
1203            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
1204            dstpixel = *dst;
1205            dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
1206            if (flags & SDL_COPY_MODULATE_COLOR) {
1207                srcR = (srcR * modulateR) / 255;
1208                srcG = (srcG * modulateG) / 255;
1209                srcB = (srcB * modulateB) / 255;
1210            }
1211            if (flags & SDL_COPY_MODULATE_ALPHA) {
1212                srcA = (srcA * modulateA) / 255;
1213            }
1214            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
1215                /* This goes away if we ever use premultiplied alpha */
1216                if (srcA < 255) {
1217                    srcR = (srcR * srcA) / 255;
1218                    srcG = (srcG * srcA) / 255;
1219                    srcB = (srcB * srcA) / 255;
1220                }
1221            }
1222            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
1223            case SDL_COPY_BLEND:
1224                dstR = srcR + ((255 - srcA) * dstR) / 255;
1225                dstG = srcG + ((255 - srcA) * dstG) / 255;
1226                dstB = srcB + ((255 - srcA) * dstB) / 255;
1227                break;
1228            case SDL_COPY_ADD:
1229                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
1230                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
1231                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
1232                break;
1233            case SDL_COPY_MOD:
1234                dstR = (srcR * dstR) / 255;
1235                dstG = (srcG * dstG) / 255;
1236                dstB = (srcB * dstB) / 255;
1237                break;
1238            }
1239            dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
1240            *dst = dstpixel;
1241            posx += incx;
1242            ++dst;
1243        }
1244        posy += incy;
1245        info->dst += info->dst_pitch;
1246    }
1247}
1248
1249static void SDL_Blit_BGR888_RGB888_Scale(SDL_BlitInfo *info)
1250{
1251    Uint32 pixel;
1252    Uint32 R, G, B, A;
1253    int srcy, srcx;
1254    int posy, posx;
1255    int incy, incx;
1256
1257    srcy = 0;
1258    posy = 0;
1259    incy = (info->src_h << 16) / info->dst_h;
1260    incx = (info->src_w << 16) / info->dst_w;
1261
1262    while (info->dst_h--) {
1263        Uint32 *src = 0;
1264        Uint32 *dst = (Uint32 *)info->dst;
1265        int n = info->dst_w;
1266        srcx = -1;
1267        posx = 0x10000L;
1268        while (posy >= 0x10000L) {
1269            ++srcy;
1270            posy -= 0x10000L;
1271        }
1272        while (n--) {
1273            if (posx >= 0x10000L) {
1274                while (posx >= 0x10000L) {
1275                    ++srcx;
1276                    posx -= 0x10000L;
1277                }
1278                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
1279            }
1280            pixel = *src;
1281            B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF;
1282            pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
1283            *dst = pixel;
1284            posx += incx;
1285            ++dst;
1286        }
1287        posy += incy;
1288        info->dst += info->dst_pitch;
1289    }
1290}
1291
1292static void SDL_Blit_BGR888_RGB888_Blend(SDL_BlitInfo *info)
1293{
1294    const int flags = info->flags;
1295    Uint32 srcpixel;
1296    Uint32 srcR, srcG, srcB, srcA;
1297    Uint32 dstpixel;
1298    Uint32 dstR, dstG, dstB, dstA;
1299
1300    while (info->dst_h--) {
1301        Uint32 *src = (Uint32 *)info->src;
1302        Uint32 *dst = (Uint32 *)info->dst;
1303        int n = info->dst_w;
1304        while (n--) {
1305            srcpixel = *src;
1306            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
1307            dstpixel = *dst;
1308            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
1309            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
1310                /* This goes away if we ever use premultiplied alpha */
1311                if (srcA < 255) {
1312                    srcR = (srcR * srcA) / 255;
1313                    srcG = (srcG * srcA) / 255;
1314                    srcB = (srcB * srcA) / 255;
1315                }
1316            }
1317            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
1318            case SDL_COPY_BLEND:
1319                dstR = srcR + ((255 - srcA) * dstR) / 255;
1320                dstG = srcG + ((255 - srcA) * dstG) / 255;
1321                dstB = srcB + ((255 - srcA) * dstB) / 255;
1322                break;
1323            case SDL_COPY_ADD:
1324                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
1325                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
1326                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
1327                break;
1328            case SDL_COPY_MOD:
1329                dstR = (srcR * dstR) / 255;
1330                dstG = (srcG * dstG) / 255;
1331                dstB = (srcB * dstB) / 255;
1332                break;
1333            }
1334            dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
1335            *dst = dstpixel;
1336            ++src;
1337            ++dst;
1338        }
1339        info->src += info->src_pitch;
1340        info->dst += info->dst_pitch;
1341    }
1342}
1343
1344static void SDL_Blit_BGR888_RGB888_Blend_Scale(SDL_BlitInfo *info)
1345{
1346    const int flags = info->flags;
1347    Uint32 srcpixel;
1348    Uint32 srcR, srcG, srcB, srcA;
1349    Uint32 dstpixel;
1350    Uint32 dstR, dstG, dstB, dstA;
1351    int srcy, srcx;
1352    int posy, posx;
1353    int incy, incx;
1354
1355    srcy = 0;
1356    posy = 0;
1357    incy = (info->src_h << 16) / info->dst_h;
1358    incx = (info->src_w << 16) / info->dst_w;
1359
1360    while (info->dst_h--) {
1361        Uint32 *src = 0;
1362        Uint32 *dst = (Uint32 *)info->dst;
1363        int n = info->dst_w;
1364        srcx = -1;
1365        posx = 0x10000L;
1366        while (posy >= 0x10000L) {
1367            ++srcy;
1368            posy -= 0x10000L;
1369        }
1370        while (n--) {
1371            if (posx >= 0x10000L) {
1372                while (posx >= 0x10000L) {
1373                    ++srcx;
1374                    posx -= 0x10000L;
1375                }
1376                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
1377            }
1378            srcpixel = *src;
1379            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
1380            dstpixel = *dst;
1381            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
1382            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
1383                /* This goes away if we ever use premultiplied alpha */
1384                if (srcA < 255) {
1385                    srcR = (srcR * srcA) / 255;
1386                    srcG = (srcG * srcA) / 255;
1387                    srcB = (srcB * srcA) / 255;
1388                }
1389            }
1390            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
1391            case SDL_COPY_BLEND:
1392                dstR = srcR + ((255 - srcA) * dstR) / 255;
1393                dstG = srcG + ((255 - srcA) * dstG) / 255;
1394                dstB = srcB + ((255 - srcA) * dstB) / 255;
1395                break;
1396            case SDL_COPY_ADD:
1397                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
1398                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
1399                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
1400                break;
1401            case SDL_COPY_MOD:
1402                dstR = (srcR * dstR) / 255;
1403                dstG = (srcG * dstG) / 255;
1404                dstB = (srcB * dstB) / 255;
1405                break;
1406            }
1407            dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
1408            *dst = dstpixel;
1409            posx += incx;
1410            ++dst;
1411        }
1412        posy += incy;
1413        info->dst += info->dst_pitch;
1414    }
1415}
1416
1417static void SDL_Blit_BGR888_RGB888_Modulate(SDL_BlitInfo *info)
1418{
1419    const int flags = info->flags;
1420    const Uint32 modulateR = info->r;
1421    const Uint32 modulateG = info->g;
1422    const Uint32 modulateB = info->b;
1423    const Uint32 modulateA = info->a;
1424    Uint32 pixel;
1425    Uint32 R, G, B, A;
1426
1427    while (info->dst_h--) {
1428        Uint32 *src = (Uint32 *)info->src;
1429        Uint32 *dst = (Uint32 *)info->dst;
1430        int n = info->dst_w;
1431        while (n--) {
1432            pixel = *src;
1433            B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF;
1434            if (flags & SDL_COPY_MODULATE_COLOR) {
1435                R = (R * modulateR) / 255;
1436                G = (G * modulateG) / 255;
1437                B = (B * modulateB) / 255;
1438            }
1439            if (flags & SDL_COPY_MODULATE_ALPHA) {
1440                A = (A * modulateA) / 255;
1441            }
1442            pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
1443            *dst = pixel;
1444            ++src;
1445            ++dst;
1446        }
1447        info->src += info->src_pitch;
1448        info->dst += info->dst_pitch;
1449    }
1450}
1451
1452static void SDL_Blit_BGR888_RGB888_Modulate_Scale(SDL_BlitInfo *info)
1453{
1454    const int flags = info->flags;
1455    const Uint32 modulateR = info->r;
1456    const Uint32 modulateG = info->g;
1457    const Uint32 modulateB = info->b;
1458    const Uint32 modulateA = info->a;
1459    Uint32 pixel;
1460    Uint32 R, G, B, A;
1461    int srcy, srcx;
1462    int posy, posx;
1463    int incy, incx;
1464
1465    srcy = 0;
1466    posy = 0;
1467    incy = (info->src_h << 16) / info->dst_h;
1468    incx = (info->src_w << 16) / info->dst_w;
1469
1470    while (info->dst_h--) {
1471        Uint32 *src = 0;
1472        Uint32 *dst = (Uint32 *)info->dst;
1473        int n = info->dst_w;
1474        srcx = -1;
1475        posx = 0x10000L;
1476        while (posy >= 0x10000L) {
1477            ++srcy;
1478            posy -= 0x10000L;
1479        }
1480        while (n--) {
1481            if (posx >= 0x10000L) {
1482                while (posx >= 0x10000L) {
1483                    ++srcx;
1484                    posx -= 0x10000L;
1485                }
1486                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
1487            }
1488            pixel = *src;
1489            B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF;
1490            if (flags & SDL_COPY_MODULATE_COLOR) {
1491                R = (R * modulateR) / 255;
1492                G = (G * modulateG) / 255;
1493                B = (B * modulateB) / 255;
1494            }
1495            if (flags & SDL_COPY_MODULATE_ALPHA) {
1496                A = (A * modulateA) / 255;
1497            }
1498            pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
1499            *dst = pixel;
1500            posx += incx;
1501            ++dst;
1502        }
1503        posy += incy;
1504        info->dst += info->dst_pitch;
1505    }
1506}
1507
1508static void SDL_Blit_BGR888_RGB888_Modulate_Blend(SDL_BlitInfo *info)
1509{
1510    const int flags = info->flags;
1511    const Uint32 modulateR = info->r;
1512    const Uint32 modulateG = info->g;
1513    const Uint32 modulateB = info->b;
1514    const Uint32 modulateA = info->a;
1515    Uint32 srcpixel;
1516    Uint32 srcR, srcG, srcB, srcA;
1517    Uint32 dstpixel;
1518    Uint32 dstR, dstG, dstB, dstA;
1519
1520    while (info->dst_h--) {
1521        Uint32 *src = (Uint32 *)info->src;
1522        Uint32 *dst = (Uint32 *)info->dst;
1523        int n = info->dst_w;
1524        while (n--) {
1525            srcpixel = *src;
1526            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
1527            dstpixel = *dst;
1528            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
1529            if (flags & SDL_COPY_MODULATE_COLOR) {
1530                srcR = (srcR * modulateR) / 255;
1531                srcG = (srcG * modulateG) / 255;
1532                srcB = (srcB * modulateB) / 255;
1533            }
1534            if (flags & SDL_COPY_MODULATE_ALPHA) {
1535                srcA = (srcA * modulateA) / 255;
1536            }
1537            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
1538                /* This goes away if we ever use premultiplied alpha */
1539                if (srcA < 255) {
1540                    srcR = (srcR * srcA) / 255;
1541                    srcG = (srcG * srcA) / 255;
1542                    srcB = (srcB * srcA) / 255;
1543                }
1544            }
1545            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
1546            case SDL_COPY_BLEND:
1547                dstR = srcR + ((255 - srcA) * dstR) / 255;
1548                dstG = srcG + ((255 - srcA) * dstG) / 255;
1549                dstB = srcB + ((255 - srcA) * dstB) / 255;
1550                break;
1551            case SDL_COPY_ADD:
1552                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
1553                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
1554                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
1555                break;
1556            case SDL_COPY_MOD:
1557                dstR = (srcR * dstR) / 255;
1558                dstG = (srcG * dstG) / 255;
1559                dstB = (srcB * dstB) / 255;
1560                break;
1561            }
1562            dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
1563            *dst = dstpixel;
1564            ++src;
1565            ++dst;
1566        }
1567        info->src += info->src_pitch;
1568        info->dst += info->dst_pitch;
1569    }
1570}
1571
1572static void SDL_Blit_BGR888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info)
1573{
1574    const int flags = info->flags;
1575    const Uint32 modulateR = info->r;
1576    const Uint32 modulateG = info->g;
1577    const Uint32 modulateB = info->b;
1578    const Uint32 modulateA = info->a;
1579    Uint32 srcpixel;
1580    Uint32 srcR, srcG, srcB, srcA;
1581    Uint32 dstpixel;
1582    Uint32 dstR, dstG, dstB, dstA;
1583    int srcy, srcx;
1584    int posy, posx;
1585    int incy, incx;
1586
1587    srcy = 0;
1588    posy = 0;
1589    incy = (info->src_h << 16) / info->dst_h;
1590    incx = (info->src_w << 16) / info->dst_w;
1591
1592    while (info->dst_h--) {
1593        Uint32 *src = 0;
1594        Uint32 *dst = (Uint32 *)info->dst;
1595        int n = info->dst_w;
1596        srcx = -1;
1597        posx = 0x10000L;
1598        while (posy >= 0x10000L) {
1599            ++srcy;
1600            posy -= 0x10000L;
1601        }
1602        while (n--) {
1603            if (posx >= 0x10000L) {
1604                while (posx >= 0x10000L) {
1605                    ++srcx;
1606                    posx -= 0x10000L;
1607                }
1608                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
1609            }
1610            srcpixel = *src;
1611            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
1612            dstpixel = *dst;
1613            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
1614            if (flags & SDL_COPY_MODULATE_COLOR) {
1615                srcR = (srcR * modulateR) / 255;
1616                srcG = (srcG * modulateG) / 255;
1617                srcB = (srcB * modulateB) / 255;
1618            }
1619            if (flags & SDL_COPY_MODULATE_ALPHA) {
1620                srcA = (srcA * modulateA) / 255;
1621            }
1622            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
1623                /* This goes away if we ever use premultiplied alpha */
1624                if (srcA < 255) {
1625                    srcR = (srcR * srcA) / 255;
1626                    srcG = (srcG * srcA) / 255;
1627                    srcB = (srcB * srcA) / 255;
1628                }
1629            }
1630            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
1631            case SDL_COPY_BLEND:
1632                dstR = srcR + ((255 - srcA) * dstR) / 255;
1633                dstG = srcG + ((255 - srcA) * dstG) / 255;
1634                dstB = srcB + ((255 - srcA) * dstB) / 255;
1635                break;
1636            case SDL_COPY_ADD:
1637                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
1638                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
1639                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
1640                break;
1641            case SDL_COPY_MOD:
1642                dstR = (srcR * dstR) / 255;
1643                dstG = (srcG * dstG) / 255;
1644                dstB = (srcB * dstB) / 255;
1645                break;
1646            }
1647            dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
1648            *dst = dstpixel;
1649            posx += incx;
1650            ++dst;
1651        }
1652        posy += incy;
1653        info->dst += info->dst_pitch;
1654    }
1655}
1656
1657static void SDL_Blit_BGR888_BGR888_Scale(SDL_BlitInfo *info)
1658{
1659    int srcy, srcx;
1660    int posy, posx;
1661    int incy, incx;
1662
1663    srcy = 0;
1664    posy = 0;
1665    incy = (info->src_h << 16) / info->dst_h;
1666    incx = (info->src_w << 16) / info->dst_w;
1667
1668    while (info->dst_h--) {
1669        Uint32 *src = 0;
1670        Uint32 *dst = (Uint32 *)info->dst;
1671        int n = info->dst_w;
1672        srcx = -1;
1673        posx = 0x10000L;
1674        while (posy >= 0x10000L) {
1675            ++srcy;
1676            posy -= 0x10000L;
1677        }
1678        while (n--) {
1679            if (posx >= 0x10000L) {
1680                while (posx >= 0x10000L) {
1681                    ++srcx;
1682                    posx -= 0x10000L;
1683                }
1684                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
1685            }
1686            *dst = *src;
1687            posx += incx;
1688            ++dst;
1689        }
1690        posy += incy;
1691        info->dst += info->dst_pitch;
1692    }
1693}
1694
1695static void SDL_Blit_BGR888_BGR888_Blend(SDL_BlitInfo *info)
1696{
1697    const int flags = info->flags;
1698    Uint32 srcpixel;
1699    Uint32 srcR, srcG, srcB, srcA;
1700    Uint32 dstpixel;
1701    Uint32 dstR, dstG, dstB, dstA;
1702
1703    while (info->dst_h--) {
1704        Uint32 *src = (Uint32 *)info->src;
1705        Uint32 *dst = (Uint32 *)info->dst;
1706        int n = info->dst_w;
1707        while (n--) {
1708            srcpixel = *src;
1709            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
1710            dstpixel = *dst;
1711            dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
1712            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
1713                /* This goes away if we ever use premultiplied alpha */
1714                if (srcA < 255) {
1715                    srcR = (srcR * srcA) / 255;
1716                    srcG = (srcG * srcA) / 255;
1717                    srcB = (srcB * srcA) / 255;
1718                }
1719            }
1720            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
1721            case SDL_COPY_BLEND:
1722                dstR = srcR + ((255 - srcA) * dstR) / 255;
1723                dstG = srcG + ((255 - srcA) * dstG) / 255;
1724                dstB = srcB + ((255 - srcA) * dstB) / 255;
1725                break;
1726            case SDL_COPY_ADD:
1727                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
1728                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
1729                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
1730                break;
1731            case SDL_COPY_MOD:
1732                dstR = (srcR * dstR) / 255;
1733                dstG = (srcG * dstG) / 255;
1734                dstB = (srcB * dstB) / 255;
1735                break;
1736            }
1737            dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
1738            *dst = dstpixel;
1739            ++src;
1740            ++dst;
1741        }
1742        info->src += info->src_pitch;
1743        info->dst += info->dst_pitch;
1744    }
1745}
1746
1747static void SDL_Blit_BGR888_BGR888_Blend_Scale(SDL_BlitInfo *info)
1748{
1749    const int flags = info->flags;
1750    Uint32 srcpixel;
1751    Uint32 srcR, srcG, srcB, srcA;
1752    Uint32 dstpixel;
1753    Uint32 dstR, dstG, dstB, dstA;
1754    int srcy, srcx;
1755    int posy, posx;
1756    int incy, incx;
1757
1758    srcy = 0;
1759    posy = 0;
1760    incy = (info->src_h << 16) / info->dst_h;
1761    incx = (info->src_w << 16) / info->dst_w;
1762
1763    while (info->dst_h--) {
1764        Uint32 *src = 0;
1765        Uint32 *dst = (Uint32 *)info->dst;
1766        int n = info->dst_w;
1767        srcx = -1;
1768        posx = 0x10000L;
1769        while (posy >= 0x10000L) {
1770            ++srcy;
1771            posy -= 0x10000L;
1772        }
1773        while (n--) {
1774            if (posx >= 0x10000L) {
1775                while (posx >= 0x10000L) {
1776                    ++srcx;
1777                    posx -= 0x10000L;
1778                }
1779                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
1780            }
1781            srcpixel = *src;
1782            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
1783            dstpixel = *dst;
1784            dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
1785            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
1786                /* This goes away if we ever use premultiplied alpha */
1787                if (srcA < 255) {
1788                    srcR = (srcR * srcA) / 255;
1789                    srcG = (srcG * srcA) / 255;
1790                    srcB = (srcB * srcA) / 255;
1791                }
1792            }
1793            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
1794            case SDL_COPY_BLEND:
1795                dstR = srcR + ((255 - srcA) * dstR) / 255;
1796                dstG = srcG + ((255 - srcA) * dstG) / 255;
1797                dstB = srcB + ((255 - srcA) * dstB) / 255;
1798                break;
1799            case SDL_COPY_ADD:
1800                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
1801                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
1802                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
1803                break;
1804            case SDL_COPY_MOD:
1805                dstR = (srcR * dstR) / 255;
1806                dstG = (srcG * dstG) / 255;
1807                dstB = (srcB * dstB) / 255;
1808                break;
1809            }
1810            dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
1811            *dst = dstpixel;
1812            posx += incx;
1813            ++dst;
1814        }
1815        posy += incy;
1816        info->dst += info->dst_pitch;
1817    }
1818}
1819
1820static void SDL_Blit_BGR888_BGR888_Modulate(SDL_BlitInfo *info)
1821{
1822    const int flags = info->flags;
1823    const Uint32 modulateR = info->r;
1824    const Uint32 modulateG = info->g;
1825    const Uint32 modulateB = info->b;
1826    const Uint32 modulateA = info->a;
1827    Uint32 pixel;
1828    Uint32 R, G, B, A;
1829
1830    while (info->dst_h--) {
1831        Uint32 *src = (Uint32 *)info->src;
1832        Uint32 *dst = (Uint32 *)info->dst;
1833        int n = info->dst_w;
1834        while (n--) {
1835            pixel = *src;
1836            B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF;
1837            if (flags & SDL_COPY_MODULATE_COLOR) {
1838                R = (R * modulateR) / 255;
1839                G = (G * modulateG) / 255;
1840                B = (B * modulateB) / 255;
1841            }
1842            if (flags & SDL_COPY_MODULATE_ALPHA) {
1843                A = (A * modulateA) / 255;
1844            }
1845            pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
1846            *dst = pixel;
1847            ++src;
1848            ++dst;
1849        }
1850        info->src += info->src_pitch;
1851        info->dst += info->dst_pitch;
1852    }
1853}
1854
1855static void SDL_Blit_BGR888_BGR888_Modulate_Scale(SDL_BlitInfo *info)
1856{
1857    const int flags = info->flags;
1858    const Uint32 modulateR = info->r;
1859    const Uint32 modulateG = info->g;
1860    const Uint32 modulateB = info->b;
1861    const Uint32 modulateA = info->a;
1862    Uint32 pixel;
1863    Uint32 R, G, B, A;
1864    int srcy, srcx;
1865    int posy, posx;
1866    int incy, incx;
1867
1868    srcy = 0;
1869    posy = 0;
1870    incy = (info->src_h << 16) / info->dst_h;
1871    incx = (info->src_w << 16) / info->dst_w;
1872
1873    while (info->dst_h--) {
1874        Uint32 *src = 0;
1875        Uint32 *dst = (Uint32 *)info->dst;
1876        int n = info->dst_w;
1877        srcx = -1;
1878        posx = 0x10000L;
1879        while (posy >= 0x10000L) {
1880            ++srcy;
1881            posy -= 0x10000L;
1882        }
1883        while (n--) {
1884            if (posx >= 0x10000L) {
1885                while (posx >= 0x10000L) {
1886                    ++srcx;
1887                    posx -= 0x10000L;
1888                }
1889                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
1890            }
1891            pixel = *src;
1892            B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF;
1893            if (flags & SDL_COPY_MODULATE_COLOR) {
1894                R = (R * modulateR) / 255;
1895                G = (G * modulateG) / 255;
1896                B = (B * modulateB) / 255;
1897            }
1898            if (flags & SDL_COPY_MODULATE_ALPHA) {
1899                A = (A * modulateA) / 255;
1900            }
1901            pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
1902            *dst = pixel;
1903            posx += incx;
1904            ++dst;
1905        }
1906        posy += incy;
1907        info->dst += info->dst_pitch;
1908    }
1909}
1910
1911static void SDL_Blit_BGR888_BGR888_Modulate_Blend(SDL_BlitInfo *info)
1912{
1913    const int flags = info->flags;
1914    const Uint32 modulateR = info->r;
1915    const Uint32 modulateG = info->g;
1916    const Uint32 modulateB = info->b;
1917    const Uint32 modulateA = info->a;
1918    Uint32 srcpixel;
1919    Uint32 srcR, srcG, srcB, srcA;
1920    Uint32 dstpixel;
1921    Uint32 dstR, dstG, dstB, dstA;
1922
1923    while (info->dst_h--) {
1924        Uint32 *src = (Uint32 *)info->src;
1925        Uint32 *dst = (Uint32 *)info->dst;
1926        int n = info->dst_w;
1927        while (n--) {
1928            srcpixel = *src;
1929            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
1930            dstpixel = *dst;
1931            dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
1932            if (flags & SDL_COPY_MODULATE_COLOR) {
1933                srcR = (srcR * modulateR) / 255;
1934                srcG = (srcG * modulateG) / 255;
1935                srcB = (srcB * modulateB) / 255;
1936            }
1937            if (flags & SDL_COPY_MODULATE_ALPHA) {
1938                srcA = (srcA * modulateA) / 255;
1939            }
1940            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
1941                /* This goes away if we ever use premultiplied alpha */
1942                if (srcA < 255) {
1943                    srcR = (srcR * srcA) / 255;
1944                    srcG = (srcG * srcA) / 255;
1945                    srcB = (srcB * srcA) / 255;
1946                }
1947            }
1948            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
1949            case SDL_COPY_BLEND:
1950                dstR = srcR + ((255 - srcA) * dstR) / 255;
1951                dstG = srcG + ((255 - srcA) * dstG) / 255;
1952                dstB = srcB + ((255 - srcA) * dstB) / 255;
1953                break;
1954            case SDL_COPY_ADD:
1955                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
1956                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
1957                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
1958                break;
1959            case SDL_COPY_MOD:
1960                dstR = (srcR * dstR) / 255;
1961                dstG = (srcG * dstG) / 255;
1962                dstB = (srcB * dstB) / 255;
1963                break;
1964            }
1965            dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
1966            *dst = dstpixel;
1967            ++src;
1968            ++dst;
1969        }
1970        info->src += info->src_pitch;
1971        info->dst += info->dst_pitch;
1972    }
1973}
1974
1975static void SDL_Blit_BGR888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info)
1976{
1977    const int flags = info->flags;
1978    const Uint32 modulateR = info->r;
1979    const Uint32 modulateG = info->g;
1980    const Uint32 modulateB = info->b;
1981    const Uint32 modulateA = info->a;
1982    Uint32 srcpixel;
1983    Uint32 srcR, srcG, srcB, srcA;
1984    Uint32 dstpixel;
1985    Uint32 dstR, dstG, dstB, dstA;
1986    int srcy, srcx;
1987    int posy, posx;
1988    int incy, incx;
1989
1990    srcy = 0;
1991    posy = 0;
1992    incy = (info->src_h << 16) / info->dst_h;
1993    incx = (info->src_w << 16) / info->dst_w;
1994
1995    while (info->dst_h--) {
1996        Uint32 *src = 0;
1997        Uint32 *dst = (Uint32 *)info->dst;
1998        int n = info->dst_w;
1999        srcx = -1;
2000        posx = 0x10000L;
2001        while (posy >= 0x10000L) {
2002            ++srcy;
2003            posy -= 0x10000L;
2004        }
2005        while (n--) {
2006            if (posx >= 0x10000L) {
2007                while (posx >= 0x10000L) {
2008                    ++srcx;
2009                    posx -= 0x10000L;
2010                }
2011                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
2012            }
2013            srcpixel = *src;
2014            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
2015            dstpixel = *dst;
2016            dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
2017            if (flags & SDL_COPY_MODULATE_COLOR) {
2018                srcR = (srcR * modulateR) / 255;
2019                srcG = (srcG * modulateG) / 255;
2020                srcB = (srcB * modulateB) / 255;
2021            }
2022            if (flags & SDL_COPY_MODULATE_ALPHA) {
2023                srcA = (srcA * modulateA) / 255;
2024            }
2025            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
2026                /* This goes away if we ever use premultiplied alpha */
2027                if (srcA < 255) {
2028                    srcR = (srcR * srcA) / 255;
2029                    srcG = (srcG * srcA) / 255;
2030                    srcB = (srcB * srcA) / 255;
2031                }
2032            }
2033            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
2034            case SDL_COPY_BLEND:
2035                dstR = srcR + ((255 - srcA) * dstR) / 255;
2036                dstG = srcG + ((255 - srcA) * dstG) / 255;
2037                dstB = srcB + ((255 - srcA) * dstB) / 255;
2038                break;
2039            case SDL_COPY_ADD:
2040                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
2041                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
2042                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
2043                break;
2044            case SDL_COPY_MOD:
2045                dstR = (srcR * dstR) / 255;
2046                dstG = (srcG * dstG) / 255;
2047                dstB = (srcB * dstB) / 255;
2048                break;
2049            }
2050            dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
2051            *dst = dstpixel;
2052            posx += incx;
2053            ++dst;
2054        }
2055        posy += incy;
2056        info->dst += info->dst_pitch;
2057    }
2058}
2059
2060static void SDL_Blit_BGR888_ARGB8888_Scale(SDL_BlitInfo *info)
2061{
2062    Uint32 pixel;
2063    Uint32 R, G, B, A;
2064    int srcy, srcx;
2065    int posy, posx;
2066    int incy, incx;
2067
2068    srcy = 0;
2069    posy = 0;
2070    incy = (info->src_h << 16) / info->dst_h;
2071    incx = (info->src_w << 16) / info->dst_w;
2072
2073    while (info->dst_h--) {
2074        Uint32 *src = 0;
2075        Uint32 *dst = (Uint32 *)info->dst;
2076        int n = info->dst_w;
2077        srcx = -1;
2078        posx = 0x10000L;
2079        while (posy >= 0x10000L) {
2080            ++srcy;
2081            posy -= 0x10000L;
2082        }
2083        while (n--) {
2084            if (posx >= 0x10000L) {
2085                while (posx >= 0x10000L) {
2086                    ++srcx;
2087                    posx -= 0x10000L;
2088                }
2089                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
2090            }
2091            pixel = *src;
2092            B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF;
2093            pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
2094            *dst = pixel;
2095            posx += incx;
2096            ++dst;
2097        }
2098        posy += incy;
2099        info->dst += info->dst_pitch;
2100    }
2101}
2102
2103static void SDL_Blit_BGR888_ARGB8888_Blend(SDL_BlitInfo *info)
2104{
2105    const int flags = info->flags;
2106    Uint32 srcpixel;
2107    Uint32 srcR, srcG, srcB, srcA;
2108    Uint32 dstpixel;
2109    Uint32 dstR, dstG, dstB, dstA;
2110
2111    while (info->dst_h--) {
2112        Uint32 *src = (Uint32 *)info->src;
2113        Uint32 *dst = (Uint32 *)info->dst;
2114        int n = info->dst_w;
2115        while (n--) {
2116            srcpixel = *src;
2117            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
2118            dstpixel = *dst;
2119            dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
2120            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
2121                /* This goes away if we ever use premultiplied alpha */
2122                if (srcA < 255) {
2123                    srcR = (srcR * srcA) / 255;
2124                    srcG = (srcG * srcA) / 255;
2125                    srcB = (srcB * srcA) / 255;
2126                }
2127            }
2128            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
2129            case SDL_COPY_BLEND:
2130                dstR = srcR + ((255 - srcA) * dstR) / 255;
2131                dstG = srcG + ((255 - srcA) * dstG) / 255;
2132                dstB = srcB + ((255 - srcA) * dstB) / 255;
2133                break;
2134            case SDL_COPY_ADD:
2135                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
2136                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
2137                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
2138                break;
2139            case SDL_COPY_MOD:
2140                dstR = (srcR * dstR) / 255;
2141                dstG = (srcG * dstG) / 255;
2142                dstB = (srcB * dstB) / 255;
2143                break;
2144            }
2145            dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
2146            *dst = dstpixel;
2147            ++src;
2148            ++dst;
2149        }
2150        info->src += info->src_pitch;
2151        info->dst += info->dst_pitch;
2152    }
2153}
2154
2155static void SDL_Blit_BGR888_ARGB8888_Blend_Scale(SDL_BlitInfo *info)
2156{
2157    const int flags = info->flags;
2158    Uint32 srcpixel;
2159    Uint32 srcR, srcG, srcB, srcA;
2160    Uint32 dstpixel;
2161    Uint32 dstR, dstG, dstB, dstA;
2162    int srcy, srcx;
2163    int posy, posx;
2164    int incy, incx;
2165
2166    srcy = 0;
2167    posy = 0;
2168    incy = (info->src_h << 16) / info->dst_h;
2169    incx = (info->src_w << 16) / info->dst_w;
2170
2171    while (info->dst_h--) {
2172        Uint32 *src = 0;
2173        Uint32 *dst = (Uint32 *)info->dst;
2174        int n = info->dst_w;
2175        srcx = -1;
2176        posx = 0x10000L;
2177        while (posy >= 0x10000L) {
2178            ++srcy;
2179            posy -= 0x10000L;
2180        }
2181        while (n--) {
2182            if (posx >= 0x10000L) {
2183                while (posx >= 0x10000L) {
2184                    ++srcx;
2185                    posx -= 0x10000L;
2186                }
2187                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
2188            }
2189            srcpixel = *src;
2190            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
2191            dstpixel = *dst;
2192            dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
2193            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
2194                /* This goes away if we ever use premultiplied alpha */
2195                if (srcA < 255) {
2196                    srcR = (srcR * srcA) / 255;
2197                    srcG = (srcG * srcA) / 255;
2198                    srcB = (srcB * srcA) / 255;
2199                }
2200            }
2201            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
2202            case SDL_COPY_BLEND:
2203                dstR = srcR + ((255 - srcA) * dstR) / 255;
2204                dstG = srcG + ((255 - srcA) * dstG) / 255;
2205                dstB = srcB + ((255 - srcA) * dstB) / 255;
2206                break;
2207            case SDL_COPY_ADD:
2208                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
2209                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
2210                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
2211                break;
2212            case SDL_COPY_MOD:
2213                dstR = (srcR * dstR) / 255;
2214                dstG = (srcG * dstG) / 255;
2215                dstB = (srcB * dstB) / 255;
2216                break;
2217            }
2218            dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
2219            *dst = dstpixel;
2220            posx += incx;
2221            ++dst;
2222        }
2223        posy += incy;
2224        info->dst += info->dst_pitch;
2225    }
2226}
2227
2228static void SDL_Blit_BGR888_ARGB8888_Modulate(SDL_BlitInfo *info)
2229{
2230    const int flags = info->flags;
2231    const Uint32 modulateR = info->r;
2232    const Uint32 modulateG = info->g;
2233    const Uint32 modulateB = info->b;
2234    const Uint32 modulateA = info->a;
2235    Uint32 pixel;
2236    Uint32 R, G, B, A;
2237
2238    while (info->dst_h--) {
2239        Uint32 *src = (Uint32 *)info->src;
2240        Uint32 *dst = (Uint32 *)info->dst;
2241        int n = info->dst_w;
2242        while (n--) {
2243            pixel = *src;
2244            B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF;
2245            if (flags & SDL_COPY_MODULATE_COLOR) {
2246                R = (R * modulateR) / 255;
2247                G = (G * modulateG) / 255;
2248                B = (B * modulateB) / 255;
2249            }
2250            if (flags & SDL_COPY_MODULATE_ALPHA) {
2251                A = (A * modulateA) / 255;
2252            }
2253            pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
2254            *dst = pixel;
2255            ++src;
2256            ++dst;
2257        }
2258        info->src += info->src_pitch;
2259        info->dst += info->dst_pitch;
2260    }
2261}
2262
2263static void SDL_Blit_BGR888_ARGB8888_Modulate_Scale(SDL_BlitInfo *info)
2264{
2265    const int flags = info->flags;
2266    const Uint32 modulateR = info->r;
2267    const Uint32 modulateG = info->g;
2268    const Uint32 modulateB = info->b;
2269    const Uint32 modulateA = info->a;
2270    Uint32 pixel;
2271    Uint32 R, G, B, A;
2272    int srcy, srcx;
2273    int posy, posx;
2274    int incy, incx;
2275
2276    srcy = 0;
2277    posy = 0;
2278    incy = (info->src_h << 16) / info->dst_h;
2279    incx = (info->src_w << 16) / info->dst_w;
2280
2281    while (info->dst_h--) {
2282        Uint32 *src = 0;
2283        Uint32 *dst = (Uint32 *)info->dst;
2284        int n = info->dst_w;
2285        srcx = -1;
2286        posx = 0x10000L;
2287        while (posy >= 0x10000L) {
2288            ++srcy;
2289            posy -= 0x10000L;
2290        }
2291        while (n--) {
2292            if (posx >= 0x10000L) {
2293                while (posx >= 0x10000L) {
2294                    ++srcx;
2295                    posx -= 0x10000L;
2296                }
2297                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
2298            }
2299            pixel = *src;
2300            B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF;
2301            if (flags & SDL_COPY_MODULATE_COLOR) {
2302                R = (R * modulateR) / 255;
2303                G = (G * modulateG) / 255;
2304                B = (B * modulateB) / 255;
2305            }
2306            if (flags & SDL_COPY_MODULATE_ALPHA) {
2307                A = (A * modulateA) / 255;
2308            }
2309            pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
2310            *dst = pixel;
2311            posx += incx;
2312            ++dst;
2313        }
2314        posy += incy;
2315        info->dst += info->dst_pitch;
2316    }
2317}
2318
2319static void SDL_Blit_BGR888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info)
2320{
2321    const int flags = info->flags;
2322    const Uint32 modulateR = info->r;
2323    const Uint32 modulateG = info->g;
2324    const Uint32 modulateB = info->b;
2325    const Uint32 modulateA = info->a;
2326    Uint32 srcpixel;
2327    Uint32 srcR, srcG, srcB, srcA;
2328    Uint32 dstpixel;
2329    Uint32 dstR, dstG, dstB, dstA;
2330
2331    while (info->dst_h--) {
2332        Uint32 *src = (Uint32 *)info->src;
2333        Uint32 *dst = (Uint32 *)info->dst;
2334        int n = info->dst_w;
2335        while (n--) {
2336            srcpixel = *src;
2337            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
2338            dstpixel = *dst;
2339            dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
2340            if (flags & SDL_COPY_MODULATE_COLOR) {
2341                srcR = (srcR * modulateR) / 255;
2342                srcG = (srcG * modulateG) / 255;
2343                srcB = (srcB * modulateB) / 255;
2344            }
2345            if (flags & SDL_COPY_MODULATE_ALPHA) {
2346                srcA = (srcA * modulateA) / 255;
2347            }
2348            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
2349                /* This goes away if we ever use premultiplied alpha */
2350                if (srcA < 255) {
2351                    srcR = (srcR * srcA) / 255;
2352                    srcG = (srcG * srcA) / 255;
2353                    srcB = (srcB * srcA) / 255;
2354                }
2355            }
2356            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
2357            case SDL_COPY_BLEND:
2358                dstR = srcR + ((255 - srcA) * dstR) / 255;
2359                dstG = srcG + ((255 - srcA) * dstG) / 255;
2360                dstB = srcB + ((255 - srcA) * dstB) / 255;
2361                break;
2362            case SDL_COPY_ADD:
2363                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
2364                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
2365                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
2366                break;
2367            case SDL_COPY_MOD:
2368                dstR = (srcR * dstR) / 255;
2369                dstG = (srcG * dstG) / 255;
2370                dstB = (srcB * dstB) / 255;
2371                break;
2372            }
2373            dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
2374            *dst = dstpixel;
2375            ++src;
2376            ++dst;
2377        }
2378        info->src += info->src_pitch;
2379        info->dst += info->dst_pitch;
2380    }
2381}
2382
2383static void SDL_Blit_BGR888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info)
2384{
2385    const int flags = info->flags;
2386    const Uint32 modulateR = info->r;
2387    const Uint32 modulateG = info->g;
2388    const Uint32 modulateB = info->b;
2389    const Uint32 modulateA = info->a;
2390    Uint32 srcpixel;
2391    Uint32 srcR, srcG, srcB, srcA;
2392    Uint32 dstpixel;
2393    Uint32 dstR, dstG, dstB, dstA;
2394    int srcy, srcx;
2395    int posy, posx;
2396    int incy, incx;
2397
2398    srcy = 0;
2399    posy = 0;
2400    incy = (info->src_h << 16) / info->dst_h;
2401    incx = (info->src_w << 16) / info->dst_w;
2402
2403    while (info->dst_h--) {
2404        Uint32 *src = 0;
2405        Uint32 *dst = (Uint32 *)info->dst;
2406        int n = info->dst_w;
2407        srcx = -1;
2408        posx = 0x10000L;
2409        while (posy >= 0x10000L) {
2410            ++srcy;
2411            posy -= 0x10000L;
2412        }
2413        while (n--) {
2414            if (posx >= 0x10000L) {
2415                while (posx >= 0x10000L) {
2416                    ++srcx;
2417                    posx -= 0x10000L;
2418                }
2419                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
2420            }
2421            srcpixel = *src;
2422            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
2423            dstpixel = *dst;
2424            dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
2425            if (flags & SDL_COPY_MODULATE_COLOR) {
2426                srcR = (srcR * modulateR) / 255;
2427                srcG = (srcG * modulateG) / 255;
2428                srcB = (srcB * modulateB) / 255;
2429            }
2430            if (flags & SDL_COPY_MODULATE_ALPHA) {
2431                srcA = (srcA * modulateA) / 255;
2432            }
2433            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
2434                /* This goes away if we ever use premultiplied alpha */
2435                if (srcA < 255) {
2436                    srcR = (srcR * srcA) / 255;
2437                    srcG = (srcG * srcA) / 255;
2438                    srcB = (srcB * srcA) / 255;
2439                }
2440            }
2441            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
2442            case SDL_COPY_BLEND:
2443                dstR = srcR + ((255 - srcA) * dstR) / 255;
2444                dstG = srcG + ((255 - srcA) * dstG) / 255;
2445                dstB = srcB + ((255 - srcA) * dstB) / 255;
2446                break;
2447            case SDL_COPY_ADD:
2448                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
2449                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
2450                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
2451                break;
2452            case SDL_COPY_MOD:
2453                dstR = (srcR * dstR) / 255;
2454                dstG = (srcG * dstG) / 255;
2455                dstB = (srcB * dstB) / 255;
2456                break;
2457            }
2458            dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
2459            *dst = dstpixel;
2460            posx += incx;
2461            ++dst;
2462        }
2463        posy += incy;
2464        info->dst += info->dst_pitch;
2465    }
2466}
2467
2468static void SDL_Blit_ARGB8888_RGB888_Scale(SDL_BlitInfo *info)
2469{
2470    Uint32 pixel;
2471    Uint32 R, G, B, A;
2472    int srcy, srcx;
2473    int posy, posx;
2474    int incy, incx;
2475
2476    srcy = 0;
2477    posy = 0;
2478    incy = (info->src_h << 16) / info->dst_h;
2479    incx = (info->src_w << 16) / info->dst_w;
2480
2481    while (info->dst_h--) {
2482        Uint32 *src = 0;
2483        Uint32 *dst = (Uint32 *)info->dst;
2484        int n = info->dst_w;
2485        srcx = -1;
2486        posx = 0x10000L;
2487        while (posy >= 0x10000L) {
2488            ++srcy;
2489            posy -= 0x10000L;
2490        }
2491        while (n--) {
2492            if (posx >= 0x10000L) {
2493                while (posx >= 0x10000L) {
2494                    ++srcx;
2495                    posx -= 0x10000L;
2496                }
2497                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
2498            }
2499            pixel = *src;
2500            A = (Uint8)(pixel >> 24); R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
2501            pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
2502            *dst = pixel;
2503            posx += incx;
2504            ++dst;
2505        }
2506        posy += incy;
2507        info->dst += info->dst_pitch;
2508    }
2509}
2510
2511static void SDL_Blit_ARGB8888_RGB888_Blend(SDL_BlitInfo *info)
2512{
2513    const int flags = info->flags;
2514    Uint32 srcpixel;
2515    Uint32 srcR, srcG, srcB, srcA;
2516    Uint32 dstpixel;
2517    Uint32 dstR, dstG, dstB, dstA;
2518
2519    while (info->dst_h--) {
2520        Uint32 *src = (Uint32 *)info->src;
2521        Uint32 *dst = (Uint32 *)info->dst;
2522        int n = info->dst_w;
2523        while (n--) {
2524            srcpixel = *src;
2525            srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel;
2526            dstpixel = *dst;
2527            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
2528            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
2529                /* This goes away if we ever use premultiplied alpha */
2530                if (srcA < 255) {
2531                    srcR = (srcR * srcA) / 255;
2532                    srcG = (srcG * srcA) / 255;
2533                    srcB = (srcB * srcA) / 255;
2534                }
2535            }
2536            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
2537            case SDL_COPY_BLEND:
2538                dstR = srcR + ((255 - srcA) * dstR) / 255;
2539                dstG = srcG + ((255 - srcA) * dstG) / 255;
2540                dstB = srcB + ((255 - srcA) * dstB) / 255;
2541                break;
2542            case SDL_COPY_ADD:
2543                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
2544                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
2545                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
2546                break;
2547            case SDL_COPY_MOD:
2548                dstR = (srcR * dstR) / 255;
2549                dstG = (srcG * dstG) / 255;
2550                dstB = (srcB * dstB) / 255;
2551                break;
2552            }
2553            dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
2554            *dst = dstpixel;
2555            ++src;
2556            ++dst;
2557        }
2558        info->src += info->src_pitch;
2559        info->dst += info->dst_pitch;
2560    }
2561}
2562
2563static void SDL_Blit_ARGB8888_RGB888_Blend_Scale(SDL_BlitInfo *info)
2564{
2565    const int flags = info->flags;
2566    Uint32 srcpixel;
2567    Uint32 srcR, srcG, srcB, srcA;
2568    Uint32 dstpixel;
2569    Uint32 dstR, dstG, dstB, dstA;
2570    int srcy, srcx;
2571    int posy, posx;
2572    int incy, incx;
2573
2574    srcy = 0;
2575    posy = 0;
2576    incy = (info->src_h << 16) / info->dst_h;
2577    incx = (info->src_w << 16) / info->dst_w;
2578
2579    while (info->dst_h--) {
2580        Uint32 *src = 0;
2581        Uint32 *dst = (Uint32 *)info->dst;
2582        int n = info->dst_w;
2583        srcx = -1;
2584        posx = 0x10000L;
2585        while (posy >= 0x10000L) {
2586            ++srcy;
2587            posy -= 0x10000L;
2588        }
2589        while (n--) {
2590            if (posx >= 0x10000L) {
2591                while (posx >= 0x10000L) {
2592                    ++srcx;
2593                    posx -= 0x10000L;
2594                }
2595                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
2596            }
2597            srcpixel = *src;
2598            srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel;
2599            dstpixel = *dst;
2600            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
2601            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
2602                /* This goes away if we ever use premultiplied alpha */
2603                if (srcA < 255) {
2604                    srcR = (srcR * srcA) / 255;
2605                    srcG = (srcG * srcA) / 255;
2606                    srcB = (srcB * srcA) / 255;
2607                }
2608            }
2609            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
2610            case SDL_COPY_BLEND:
2611                dstR = srcR + ((255 - srcA) * dstR) / 255;
2612                dstG = srcG + ((255 - srcA) * dstG) / 255;
2613                dstB = srcB + ((255 - srcA) * dstB) / 255;
2614                break;
2615            case SDL_COPY_ADD:
2616                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
2617                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
2618                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
2619                break;
2620            case SDL_COPY_MOD:
2621                dstR = (srcR * dstR) / 255;
2622                dstG = (srcG * dstG) / 255;
2623                dstB = (srcB * dstB) / 255;
2624                break;
2625            }
2626            dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
2627            *dst = dstpixel;
2628            posx += incx;
2629            ++dst;
2630        }
2631        posy += incy;
2632        info->dst += info->dst_pitch;
2633    }
2634}
2635
2636static void SDL_Blit_ARGB8888_RGB888_Modulate(SDL_BlitInfo *info)
2637{
2638    const int flags = info->flags;
2639    const Uint32 modulateR = info->r;
2640    const Uint32 modulateG = info->g;
2641    const Uint32 modulateB = info->b;
2642    const Uint32 modulateA = info->a;
2643    Uint32 pixel;
2644    Uint32 R, G, B, A;
2645
2646    while (info->dst_h--) {
2647        Uint32 *src = (Uint32 *)info->src;
2648        Uint32 *dst = (Uint32 *)info->dst;
2649        int n = info->dst_w;
2650        while (n--) {
2651            pixel = *src;
2652            A = (Uint8)(pixel >> 24); R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
2653            if (flags & SDL_COPY_MODULATE_COLOR) {
2654                R = (R * modulateR) / 255;
2655                G = (G * modulateG) / 255;
2656                B = (B * modulateB) / 255;
2657            }
2658            if (flags & SDL_COPY_MODULATE_ALPHA) {
2659                A = (A * modulateA) / 255;
2660            }
2661            pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
2662            *dst = pixel;
2663            ++src;
2664            ++dst;
2665        }
2666        info->src += info->src_pitch;
2667        info->dst += info->dst_pitch;
2668    }
2669}
2670
2671static void SDL_Blit_ARGB8888_RGB888_Modulate_Scale(SDL_BlitInfo *info)
2672{
2673    const int flags = info->flags;
2674    const Uint32 modulateR = info->r;
2675    const Uint32 modulateG = info->g;
2676    const Uint32 modulateB = info->b;
2677    const Uint32 modulateA = info->a;
2678    Uint32 pixel;
2679    Uint32 R, G, B, A;
2680    int srcy, srcx;
2681    int posy, posx;
2682    int incy, incx;
2683
2684    srcy = 0;
2685    posy = 0;
2686    incy = (info->src_h << 16) / info->dst_h;
2687    incx = (info->src_w << 16) / info->dst_w;
2688
2689    while (info->dst_h--) {
2690        Uint32 *src = 0;
2691        Uint32 *dst = (Uint32 *)info->dst;
2692        int n = info->dst_w;
2693        srcx = -1;
2694        posx = 0x10000L;
2695        while (posy >= 0x10000L) {
2696            ++srcy;
2697            posy -= 0x10000L;
2698        }
2699        while (n--) {
2700            if (posx >= 0x10000L) {
2701                while (posx >= 0x10000L) {
2702                    ++srcx;
2703                    posx -= 0x10000L;
2704                }
2705                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
2706            }
2707            pixel = *src;
2708            A = (Uint8)(pixel >> 24); R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
2709            if (flags & SDL_COPY_MODULATE_COLOR) {
2710                R = (R * modulateR) / 255;
2711                G = (G * modulateG) / 255;
2712                B = (B * modulateB) / 255;
2713            }
2714            if (flags & SDL_COPY_MODULATE_ALPHA) {
2715                A = (A * modulateA) / 255;
2716            }
2717            pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
2718            *dst = pixel;
2719            posx += incx;
2720            ++dst;
2721        }
2722        posy += incy;
2723        info->dst += info->dst_pitch;
2724    }
2725}
2726
2727static void SDL_Blit_ARGB8888_RGB888_Modulate_Blend(SDL_BlitInfo *info)
2728{
2729    const int flags = info->flags;
2730    const Uint32 modulateR = info->r;
2731    const Uint32 modulateG = info->g;
2732    const Uint32 modulateB = info->b;
2733    const Uint32 modulateA = info->a;
2734    Uint32 srcpixel;
2735    Uint32 srcR, srcG, srcB, srcA;
2736    Uint32 dstpixel;
2737    Uint32 dstR, dstG, dstB, dstA;
2738
2739    while (info->dst_h--) {
2740        Uint32 *src = (Uint32 *)info->src;
2741        Uint32 *dst = (Uint32 *)info->dst;
2742        int n = info->dst_w;
2743        while (n--) {
2744            srcpixel = *src;
2745            srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel;
2746            dstpixel = *dst;
2747            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
2748            if (flags & SDL_COPY_MODULATE_COLOR) {
2749                srcR = (srcR * modulateR) / 255;
2750                srcG = (srcG * modulateG) / 255;
2751                srcB = (srcB * modulateB) / 255;
2752            }
2753            if (flags & SDL_COPY_MODULATE_ALPHA) {
2754                srcA = (srcA * modulateA) / 255;
2755            }
2756            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
2757                /* This goes away if we ever use premultiplied alpha */
2758                if (srcA < 255) {
2759                    srcR = (srcR * srcA) / 255;
2760                    srcG = (srcG * srcA) / 255;
2761                    srcB = (srcB * srcA) / 255;
2762                }
2763            }
2764            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
2765            case SDL_COPY_BLEND:
2766                dstR = srcR + ((255 - srcA) * dstR) / 255;
2767                dstG = srcG + ((255 - srcA) * dstG) / 255;
2768                dstB = srcB + ((255 - srcA) * dstB) / 255;
2769                break;
2770            case SDL_COPY_ADD:
2771                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
2772                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
2773                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
2774                break;
2775            case SDL_COPY_MOD:
2776                dstR = (srcR * dstR) / 255;
2777                dstG = (srcG * dstG) / 255;
2778                dstB = (srcB * dstB) / 255;
2779                break;
2780            }
2781            dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
2782            *dst = dstpixel;
2783            ++src;
2784            ++dst;
2785        }
2786        info->src += info->src_pitch;
2787        info->dst += info->dst_pitch;
2788    }
2789}
2790
2791static void SDL_Blit_ARGB8888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info)
2792{
2793    const int flags = info->flags;
2794    const Uint32 modulateR = info->r;
2795    const Uint32 modulateG = info->g;
2796    const Uint32 modulateB = info->b;
2797    const Uint32 modulateA = info->a;
2798    Uint32 srcpixel;
2799    Uint32 srcR, srcG, srcB, srcA;
2800    Uint32 dstpixel;
2801    Uint32 dstR, dstG, dstB, dstA;
2802    int srcy, srcx;
2803    int posy, posx;
2804    int incy, incx;
2805
2806    srcy = 0;
2807    posy = 0;
2808    incy = (info->src_h << 16) / info->dst_h;
2809    incx = (info->src_w << 16) / info->dst_w;
2810
2811    while (info->dst_h--) {
2812        Uint32 *src = 0;
2813        Uint32 *dst = (Uint32 *)info->dst;
2814        int n = info->dst_w;
2815        srcx = -1;
2816        posx = 0x10000L;
2817        while (posy >= 0x10000L) {
2818            ++srcy;
2819            posy -= 0x10000L;
2820        }
2821        while (n--) {
2822            if (posx >= 0x10000L) {
2823                while (posx >= 0x10000L) {
2824                    ++srcx;
2825                    posx -= 0x10000L;
2826                }
2827                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
2828            }
2829            srcpixel = *src;
2830            srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel;
2831            dstpixel = *dst;
2832            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
2833            if (flags & SDL_COPY_MODULATE_COLOR) {
2834                srcR = (srcR * modulateR) / 255;
2835                srcG = (srcG * modulateG) / 255;
2836                srcB = (srcB * modulateB) / 255;
2837            }
2838            if (flags & SDL_COPY_MODULATE_ALPHA) {
2839                srcA = (srcA * modulateA) / 255;
2840            }
2841            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
2842                /* This goes away if we ever use premultiplied alpha */
2843                if (srcA < 255) {
2844                    srcR = (srcR * srcA) / 255;
2845                    srcG = (srcG * srcA) / 255;
2846                    srcB = (srcB * srcA) / 255;
2847                }
2848            }
2849            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
2850            case SDL_COPY_BLEND:
2851                dstR = srcR + ((255 - srcA) * dstR) / 255;
2852                dstG = srcG + ((255 - srcA) * dstG) / 255;
2853                dstB = srcB + ((255 - srcA) * dstB) / 255;
2854                break;
2855            case SDL_COPY_ADD:
2856                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
2857                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
2858                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
2859                break;
2860            case SDL_COPY_MOD:
2861                dstR = (srcR * dstR) / 255;
2862                dstG = (srcG * dstG) / 255;
2863                dstB = (srcB * dstB) / 255;
2864                break;
2865            }
2866            dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
2867            *dst = dstpixel;
2868            posx += incx;
2869            ++dst;
2870        }
2871        posy += incy;
2872        info->dst += info->dst_pitch;
2873    }
2874}
2875
2876static void SDL_Blit_ARGB8888_BGR888_Scale(SDL_BlitInfo *info)
2877{
2878    Uint32 pixel;
2879    Uint32 R, G, B, A;
2880    int srcy, srcx;
2881    int posy, posx;
2882    int incy, incx;
2883
2884    srcy = 0;
2885    posy = 0;
2886    incy = (info->src_h << 16) / info->dst_h;
2887    incx = (info->src_w << 16) / info->dst_w;
2888
2889    while (info->dst_h--) {
2890        Uint32 *src = 0;
2891        Uint32 *dst = (Uint32 *)info->dst;
2892        int n = info->dst_w;
2893        srcx = -1;
2894        posx = 0x10000L;
2895        while (posy >= 0x10000L) {
2896            ++srcy;
2897            posy -= 0x10000L;
2898        }
2899        while (n--) {
2900            if (posx >= 0x10000L) {
2901                while (posx >= 0x10000L) {
2902                    ++srcx;
2903                    posx -= 0x10000L;
2904                }
2905                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
2906            }
2907            pixel = *src;
2908            A = (Uint8)(pixel >> 24); R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
2909            pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
2910            *dst = pixel;
2911            posx += incx;
2912            ++dst;
2913        }
2914        posy += incy;
2915        info->dst += info->dst_pitch;
2916    }
2917}
2918
2919static void SDL_Blit_ARGB8888_BGR888_Blend(SDL_BlitInfo *info)
2920{
2921    const int flags = info->flags;
2922    Uint32 srcpixel;
2923    Uint32 srcR, srcG, srcB, srcA;
2924    Uint32 dstpixel;
2925    Uint32 dstR, dstG, dstB, dstA;
2926
2927    while (info->dst_h--) {
2928        Uint32 *src = (Uint32 *)info->src;
2929        Uint32 *dst = (Uint32 *)info->dst;
2930        int n = info->dst_w;
2931        while (n--) {
2932            srcpixel = *src;
2933            srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel;
2934            dstpixel = *dst;
2935            dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
2936            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
2937                /* This goes away if we ever use premultiplied alpha */
2938                if (srcA < 255) {
2939                    srcR = (srcR * srcA) / 255;
2940                    srcG = (srcG * srcA) / 255;
2941                    srcB = (srcB * srcA) / 255;
2942                }
2943            }
2944            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
2945            case SDL_COPY_BLEND:
2946                dstR = srcR + ((255 - srcA) * dstR) / 255;
2947                dstG = srcG + ((255 - srcA) * dstG) / 255;
2948                dstB = srcB + ((255 - srcA) * dstB) / 255;
2949                break;
2950            case SDL_COPY_ADD:
2951                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
2952                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
2953                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
2954                break;
2955            case SDL_COPY_MOD:
2956                dstR = (srcR * dstR) / 255;
2957                dstG = (srcG * dstG) / 255;
2958                dstB = (srcB * dstB) / 255;
2959                break;
2960            }
2961            dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
2962            *dst = dstpixel;
2963            ++src;
2964            ++dst;
2965        }
2966        info->src += info->src_pitch;
2967        info->dst += info->dst_pitch;
2968    }
2969}
2970
2971static void SDL_Blit_ARGB8888_BGR888_Blend_Scale(SDL_BlitInfo *info)
2972{
2973    const int flags = info->flags;
2974    Uint32 srcpixel;
2975    Uint32 srcR, srcG, srcB, srcA;
2976    Uint32 dstpixel;
2977    Uint32 dstR, dstG, dstB, dstA;
2978    int srcy, srcx;
2979    int posy, posx;
2980    int incy, incx;
2981
2982    srcy = 0;
2983    posy = 0;
2984    incy = (info->src_h << 16) / info->dst_h;
2985    incx = (info->src_w << 16) / info->dst_w;
2986
2987    while (info->dst_h--) {
2988        Uint32 *src = 0;
2989        Uint32 *dst = (Uint32 *)info->dst;
2990        int n = info->dst_w;
2991        srcx = -1;
2992        posx = 0x10000L;
2993        while (posy >= 0x10000L) {
2994            ++srcy;
2995            posy -= 0x10000L;
2996        }
2997        while (n--) {
2998            if (posx >= 0x10000L) {
2999                while (posx >= 0x10000L) {
3000                    ++srcx;
3001                    posx -= 0x10000L;
3002                }
3003                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
3004            }
3005            srcpixel = *src;
3006            srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel;
3007            dstpixel = *dst;
3008            dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
3009            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
3010                /* This goes away if we ever use premultiplied alpha */
3011                if (srcA < 255) {
3012                    srcR = (srcR * srcA) / 255;
3013                    srcG = (srcG * srcA) / 255;
3014                    srcB = (srcB * srcA) / 255;
3015                }
3016            }
3017            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
3018            case SDL_COPY_BLEND:
3019                dstR = srcR + ((255 - srcA) * dstR) / 255;
3020                dstG = srcG + ((255 - srcA) * dstG) / 255;
3021                dstB = srcB + ((255 - srcA) * dstB) / 255;
3022                break;
3023            case SDL_COPY_ADD:
3024                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
3025                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
3026                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
3027                break;
3028            case SDL_COPY_MOD:
3029                dstR = (srcR * dstR) / 255;
3030                dstG = (srcG * dstG) / 255;
3031                dstB = (srcB * dstB) / 255;
3032                break;
3033            }
3034            dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
3035            *dst = dstpixel;
3036            posx += incx;
3037            ++dst;
3038        }
3039        posy += incy;
3040        info->dst += info->dst_pitch;
3041    }
3042}
3043
3044static void SDL_Blit_ARGB8888_BGR888_Modulate(SDL_BlitInfo *info)
3045{
3046    const int flags = info->flags;
3047    const Uint32 modulateR = info->r;
3048    const Uint32 modulateG = info->g;
3049    const Uint32 modulateB = info->b;
3050    const Uint32 modulateA = info->a;
3051    Uint32 pixel;
3052    Uint32 R, G, B, A;
3053
3054    while (info->dst_h--) {
3055        Uint32 *src = (Uint32 *)info->src;
3056        Uint32 *dst = (Uint32 *)info->dst;
3057        int n = info->dst_w;
3058        while (n--) {
3059            pixel = *src;
3060            A = (Uint8)(pixel >> 24); R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
3061            if (flags & SDL_COPY_MODULATE_COLOR) {
3062                R = (R * modulateR) / 255;
3063                G = (G * modulateG) / 255;
3064                B = (B * modulateB) / 255;
3065            }
3066            if (flags & SDL_COPY_MODULATE_ALPHA) {
3067                A = (A * modulateA) / 255;
3068            }
3069            pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
3070            *dst = pixel;
3071            ++src;
3072            ++dst;
3073        }
3074        info->src += info->src_pitch;
3075        info->dst += info->dst_pitch;
3076    }
3077}
3078
3079static void SDL_Blit_ARGB8888_BGR888_Modulate_Scale(SDL_BlitInfo *info)
3080{
3081    const int flags = info->flags;
3082    const Uint32 modulateR = info->r;
3083    const Uint32 modulateG = info->g;
3084    const Uint32 modulateB = info->b;
3085    const Uint32 modulateA = info->a;
3086    Uint32 pixel;
3087    Uint32 R, G, B, A;
3088    int srcy, srcx;
3089    int posy, posx;
3090    int incy, incx;
3091
3092    srcy = 0;
3093    posy = 0;
3094    incy = (info->src_h << 16) / info->dst_h;
3095    incx = (info->src_w << 16) / info->dst_w;
3096
3097    while (info->dst_h--) {
3098        Uint32 *src = 0;
3099        Uint32 *dst = (Uint32 *)info->dst;
3100        int n = info->dst_w;
3101        srcx = -1;
3102        posx = 0x10000L;
3103        while (posy >= 0x10000L) {
3104            ++srcy;
3105            posy -= 0x10000L;
3106        }
3107        while (n--) {
3108            if (posx >= 0x10000L) {
3109                while (posx >= 0x10000L) {
3110                    ++srcx;
3111                    posx -= 0x10000L;
3112                }
3113                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
3114            }
3115            pixel = *src;
3116            A = (Uint8)(pixel >> 24); R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
3117            if (flags & SDL_COPY_MODULATE_COLOR) {
3118                R = (R * modulateR) / 255;
3119                G = (G * modulateG) / 255;
3120                B = (B * modulateB) / 255;
3121            }
3122            if (flags & SDL_COPY_MODULATE_ALPHA) {
3123                A = (A * modulateA) / 255;
3124            }
3125            pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
3126            *dst = pixel;
3127            posx += incx;
3128            ++dst;
3129        }
3130        posy += incy;
3131        info->dst += info->dst_pitch;
3132    }
3133}
3134
3135static void SDL_Blit_ARGB8888_BGR888_Modulate_Blend(SDL_BlitInfo *info)
3136{
3137    const int flags = info->flags;
3138    const Uint32 modulateR = info->r;
3139    const Uint32 modulateG = info->g;
3140    const Uint32 modulateB = info->b;
3141    const Uint32 modulateA = info->a;
3142    Uint32 srcpixel;
3143    Uint32 srcR, srcG, srcB, srcA;
3144    Uint32 dstpixel;
3145    Uint32 dstR, dstG, dstB, dstA;
3146
3147    while (info->dst_h--) {
3148        Uint32 *src = (Uint32 *)info->src;
3149        Uint32 *dst = (Uint32 *)info->dst;
3150        int n = info->dst_w;
3151        while (n--) {
3152            srcpixel = *src;
3153            srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel;
3154            dstpixel = *dst;
3155            dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
3156            if (flags & SDL_COPY_MODULATE_COLOR) {
3157                srcR = (srcR * modulateR) / 255;
3158                srcG = (srcG * modulateG) / 255;
3159                srcB = (srcB * modulateB) / 255;
3160            }
3161            if (flags & SDL_COPY_MODULATE_ALPHA) {
3162                srcA = (srcA * modulateA) / 255;
3163            }
3164            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
3165                /* This goes away if we ever use premultiplied alpha */
3166                if (srcA < 255) {
3167                    srcR = (srcR * srcA) / 255;
3168                    srcG = (srcG * srcA) / 255;
3169                    srcB = (srcB * srcA) / 255;
3170                }
3171            }
3172            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
3173            case SDL_COPY_BLEND:
3174                dstR = srcR + ((255 - srcA) * dstR) / 255;
3175                dstG = srcG + ((255 - srcA) * dstG) / 255;
3176                dstB = srcB + ((255 - srcA) * dstB) / 255;
3177                break;
3178            case SDL_COPY_ADD:
3179                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
3180                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
3181                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
3182                break;
3183            case SDL_COPY_MOD:
3184                dstR = (srcR * dstR) / 255;
3185                dstG = (srcG * dstG) / 255;
3186                dstB = (srcB * dstB) / 255;
3187                break;
3188            }
3189            dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
3190            *dst = dstpixel;
3191            ++src;
3192            ++dst;
3193        }
3194        info->src += info->src_pitch;
3195        info->dst += info->dst_pitch;
3196    }
3197}
3198
3199static void SDL_Blit_ARGB8888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info)
3200{
3201    const int flags = info->flags;
3202    const Uint32 modulateR = info->r;
3203    const Uint32 modulateG = info->g;
3204    const Uint32 modulateB = info->b;
3205    const Uint32 modulateA = info->a;
3206    Uint32 srcpixel;
3207    Uint32 srcR, srcG, srcB, srcA;
3208    Uint32 dstpixel;
3209    Uint32 dstR, dstG, dstB, dstA;
3210    int srcy, srcx;
3211    int posy, posx;
3212    int incy, incx;
3213
3214    srcy = 0;
3215    posy = 0;
3216    incy = (info->src_h << 16) / info->dst_h;
3217    incx = (info->src_w << 16) / info->dst_w;
3218
3219    while (info->dst_h--) {
3220        Uint32 *src = 0;
3221        Uint32 *dst = (Uint32 *)info->dst;
3222        int n = info->dst_w;
3223        srcx = -1;
3224        posx = 0x10000L;
3225        while (posy >= 0x10000L) {
3226            ++srcy;
3227            posy -= 0x10000L;
3228        }
3229        while (n--) {
3230            if (posx >= 0x10000L) {
3231                while (posx >= 0x10000L) {
3232                    ++srcx;
3233                    posx -= 0x10000L;
3234                }
3235                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
3236            }
3237            srcpixel = *src;
3238            srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel;
3239            dstpixel = *dst;
3240            dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
3241            if (flags & SDL_COPY_MODULATE_COLOR) {
3242                srcR = (srcR * modulateR) / 255;
3243                srcG = (srcG * modulateG) / 255;
3244                srcB = (srcB * modulateB) / 255;
3245            }
3246            if (flags & SDL_COPY_MODULATE_ALPHA) {
3247                srcA = (srcA * modulateA) / 255;
3248            }
3249            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
3250                /* This goes away if we ever use premultiplied alpha */
3251                if (srcA < 255) {
3252                    srcR = (srcR * srcA) / 255;
3253                    srcG = (srcG * srcA) / 255;
3254                    srcB = (srcB * srcA) / 255;
3255                }
3256            }
3257            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
3258            case SDL_COPY_BLEND:
3259                dstR = srcR + ((255 - srcA) * dstR) / 255;
3260                dstG = srcG + ((255 - srcA) * dstG) / 255;
3261                dstB = srcB + ((255 - srcA) * dstB) / 255;
3262                break;
3263            case SDL_COPY_ADD:
3264                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
3265                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
3266                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
3267                break;
3268            case SDL_COPY_MOD:
3269                dstR = (srcR * dstR) / 255;
3270                dstG = (srcG * dstG) / 255;
3271                dstB = (srcB * dstB) / 255;
3272                break;
3273            }
3274            dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
3275            *dst = dstpixel;
3276            posx += incx;
3277            ++dst;
3278        }
3279        posy += incy;
3280        info->dst += info->dst_pitch;
3281    }
3282}
3283
3284static void SDL_Blit_ARGB8888_ARGB8888_Scale(SDL_BlitInfo *info)
3285{
3286    int srcy, srcx;
3287    int posy, posx;
3288    int incy, incx;
3289
3290    srcy = 0;
3291    posy = 0;
3292    incy = (info->src_h << 16) / info->dst_h;
3293    incx = (info->src_w << 16) / info->dst_w;
3294
3295    while (info->dst_h--) {
3296        Uint32 *src = 0;
3297        Uint32 *dst = (Uint32 *)info->dst;
3298        int n = info->dst_w;
3299        srcx = -1;
3300        posx = 0x10000L;
3301        while (posy >= 0x10000L) {
3302            ++srcy;
3303            posy -= 0x10000L;
3304        }
3305        while (n--) {
3306            if (posx >= 0x10000L) {
3307                while (posx >= 0x10000L) {
3308                    ++srcx;
3309                    posx -= 0x10000L;
3310                }
3311                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
3312            }
3313            *dst = *src;
3314            posx += incx;
3315            ++dst;
3316        }
3317        posy += incy;
3318        info->dst += info->dst_pitch;
3319    }
3320}
3321
3322static void SDL_Blit_ARGB8888_ARGB8888_Blend(SDL_BlitInfo *info)
3323{
3324    const int flags = info->flags;
3325    Uint32 srcpixel;
3326    Uint32 srcR, srcG, srcB, srcA;
3327    Uint32 dstpixel;
3328    Uint32 dstR, dstG, dstB, dstA;
3329
3330    while (info->dst_h--) {
3331        Uint32 *src = (Uint32 *)info->src;
3332        Uint32 *dst = (Uint32 *)info->dst;
3333        int n = info->dst_w;
3334        while (n--) {
3335            srcpixel = *src;
3336            srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel;
3337            dstpixel = *dst;
3338            dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
3339            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
3340                /* This goes away if we ever use premultiplied alpha */
3341                if (srcA < 255) {
3342                    srcR = (srcR * srcA) / 255;
3343                    srcG = (srcG * srcA) / 255;
3344                    srcB = (srcB * srcA) / 255;
3345                }
3346            }
3347            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
3348            case SDL_COPY_BLEND:
3349                dstR = srcR + ((255 - srcA) * dstR) / 255;
3350                dstG = srcG + ((255 - srcA) * dstG) / 255;
3351                dstB = srcB + ((255 - srcA) * dstB) / 255;
3352                break;
3353            case SDL_COPY_ADD:
3354                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
3355                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
3356                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
3357                break;
3358            case SDL_COPY_MOD:
3359                dstR = (srcR * dstR) / 255;
3360                dstG = (srcG * dstG) / 255;
3361                dstB = (srcB * dstB) / 255;
3362                break;
3363            }
3364            dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
3365            *dst = dstpixel;
3366            ++src;
3367            ++dst;
3368        }
3369        info->src += info->src_pitch;
3370        info->dst += info->dst_pitch;
3371    }
3372}
3373
3374static void SDL_Blit_ARGB8888_ARGB8888_Blend_Scale(SDL_BlitInfo *info)
3375{
3376    const int flags = info->flags;
3377    Uint32 srcpixel;
3378    Uint32 srcR, srcG, srcB, srcA;
3379    Uint32 dstpixel;
3380    Uint32 dstR, dstG, dstB, dstA;
3381    int srcy, srcx;
3382    int posy, posx;
3383    int incy, incx;
3384
3385    srcy = 0;
3386    posy = 0;
3387    incy = (info->src_h << 16) / info->dst_h;
3388    incx = (info->src_w << 16) / info->dst_w;
3389
3390    while (info->dst_h--) {
3391        Uint32 *src = 0;
3392        Uint32 *dst = (Uint32 *)info->dst;
3393        int n = info->dst_w;
3394        srcx = -1;
3395        posx = 0x10000L;
3396        while (posy >= 0x10000L) {
3397            ++srcy;
3398            posy -= 0x10000L;
3399        }
3400        while (n--) {
3401            if (posx >= 0x10000L) {
3402                while (posx >= 0x10000L) {
3403                    ++srcx;
3404                    posx -= 0x10000L;
3405                }
3406                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
3407            }
3408            srcpixel = *src;
3409            srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel;
3410            dstpixel = *dst;
3411            dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
3412            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
3413                /* This goes away if we ever use premultiplied alpha */
3414                if (srcA < 255) {
3415                    srcR = (srcR * srcA) / 255;
3416                    srcG = (srcG * srcA) / 255;
3417                    srcB = (srcB * srcA) / 255;
3418                }
3419            }
3420            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
3421            case SDL_COPY_BLEND:
3422                dstR = srcR + ((255 - srcA) * dstR) / 255;
3423                dstG = srcG + ((255 - srcA) * dstG) / 255;
3424                dstB = srcB + ((255 - srcA) * dstB) / 255;
3425                break;
3426            case SDL_COPY_ADD:
3427                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
3428                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
3429                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
3430                break;
3431            case SDL_COPY_MOD:
3432                dstR = (srcR * dstR) / 255;
3433                dstG = (srcG * dstG) / 255;
3434                dstB = (srcB * dstB) / 255;
3435                break;
3436            }
3437            dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
3438            *dst = dstpixel;
3439            posx += incx;
3440            ++dst;
3441        }
3442        posy += incy;
3443        info->dst += info->dst_pitch;
3444    }
3445}
3446
3447static void SDL_Blit_ARGB8888_ARGB8888_Modulate(SDL_BlitInfo *info)
3448{
3449    const int flags = info->flags;
3450    const Uint32 modulateR = info->r;
3451    const Uint32 modulateG = info->g;
3452    const Uint32 modulateB = info->b;
3453    const Uint32 modulateA = info->a;
3454    Uint32 pixel;
3455    Uint32 R, G, B, A;
3456
3457    while (info->dst_h--) {
3458        Uint32 *src = (Uint32 *)info->src;
3459        Uint32 *dst = (Uint32 *)info->dst;
3460        int n = info->dst_w;
3461        while (n--) {
3462            pixel = *src;
3463            A = (Uint8)(pixel >> 24); R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
3464            if (flags & SDL_COPY_MODULATE_COLOR) {
3465                R = (R * modulateR) / 255;
3466                G = (G * modulateG) / 255;
3467                B = (B * modulateB) / 255;
3468            }
3469            if (flags & SDL_COPY_MODULATE_ALPHA) {
3470                A = (A * modulateA) / 255;
3471            }
3472            pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
3473            *dst = pixel;
3474            ++src;
3475            ++dst;
3476        }
3477        info->src += info->src_pitch;
3478        info->dst += info->dst_pitch;
3479    }
3480}
3481
3482static void SDL_Blit_ARGB8888_ARGB8888_Modulate_Scale(SDL_BlitInfo *info)
3483{
3484    const int flags = info->flags;
3485    const Uint32 modulateR = info->r;
3486    const Uint32 modulateG = info->g;
3487    const Uint32 modulateB = info->b;
3488    const Uint32 modulateA = info->a;
3489    Uint32 pixel;
3490    Uint32 R, G, B, A;
3491    int srcy, srcx;
3492    int posy, posx;
3493    int incy, incx;
3494
3495    srcy = 0;
3496    posy = 0;
3497    incy = (info->src_h << 16) / info->dst_h;
3498    incx = (info->src_w << 16) / info->dst_w;
3499
3500    while (info->dst_h--) {
3501        Uint32 *src = 0;
3502        Uint32 *dst = (Uint32 *)info->dst;
3503        int n = info->dst_w;
3504        srcx = -1;
3505        posx = 0x10000L;
3506        while (posy >= 0x10000L) {
3507            ++srcy;
3508            posy -= 0x10000L;
3509        }
3510        while (n--) {
3511            if (posx >= 0x10000L) {
3512                while (posx >= 0x10000L) {
3513                    ++srcx;
3514                    posx -= 0x10000L;
3515                }
3516                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
3517            }
3518            pixel = *src;
3519            A = (Uint8)(pixel >> 24); R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
3520            if (flags & SDL_COPY_MODULATE_COLOR) {
3521                R = (R * modulateR) / 255;
3522                G = (G * modulateG) / 255;
3523                B = (B * modulateB) / 255;
3524            }
3525            if (flags & SDL_COPY_MODULATE_ALPHA) {
3526                A = (A * modulateA) / 255;
3527            }
3528            pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
3529            *dst = pixel;
3530            posx += incx;
3531            ++dst;
3532        }
3533        posy += incy;
3534        info->dst += info->dst_pitch;
3535    }
3536}
3537
3538static void SDL_Blit_ARGB8888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info)
3539{
3540    const int flags = info->flags;
3541    const Uint32 modulateR = info->r;
3542    const Uint32 modulateG = info->g;
3543    const Uint32 modulateB = info->b;
3544    const Uint32 modulateA = info->a;
3545    Uint32 srcpixel;
3546    Uint32 srcR, srcG, srcB, srcA;
3547    Uint32 dstpixel;
3548    Uint32 dstR, dstG, dstB, dstA;
3549
3550    while (info->dst_h--) {
3551        Uint32 *src = (Uint32 *)info->src;
3552        Uint32 *dst = (Uint32 *)info->dst;
3553        int n = info->dst_w;
3554        while (n--) {
3555            srcpixel = *src;
3556            srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel;
3557            dstpixel = *dst;
3558            dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
3559            if (flags & SDL_COPY_MODULATE_COLOR) {
3560                srcR = (srcR * modulateR) / 255;
3561                srcG = (srcG * modulateG) / 255;
3562                srcB = (srcB * modulateB) / 255;
3563            }
3564            if (flags & SDL_COPY_MODULATE_ALPHA) {
3565                srcA = (srcA * modulateA) / 255;
3566            }
3567            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
3568                /* This goes away if we ever use premultiplied alpha */
3569                if (srcA < 255) {
3570                    srcR = (srcR * srcA) / 255;
3571                    srcG = (srcG * srcA) / 255;
3572                    srcB = (srcB * srcA) / 255;
3573                }
3574            }
3575            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
3576            case SDL_COPY_BLEND:
3577                dstR = srcR + ((255 - srcA) * dstR) / 255;
3578                dstG = srcG + ((255 - srcA) * dstG) / 255;
3579                dstB = srcB + ((255 - srcA) * dstB) / 255;
3580                break;
3581            case SDL_COPY_ADD:
3582                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
3583                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
3584                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
3585                break;
3586            case SDL_COPY_MOD:
3587                dstR = (srcR * dstR) / 255;
3588                dstG = (srcG * dstG) / 255;
3589                dstB = (srcB * dstB) / 255;
3590                break;
3591            }
3592            dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
3593            *dst = dstpixel;
3594            ++src;
3595            ++dst;
3596        }
3597        info->src += info->src_pitch;
3598        info->dst += info->dst_pitch;
3599    }
3600}
3601
3602static void SDL_Blit_ARGB8888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info)
3603{
3604    const int flags = info->flags;
3605    const Uint32 modulateR = info->r;
3606    const Uint32 modulateG = info->g;
3607    const Uint32 modulateB = info->b;
3608    const Uint32 modulateA = info->a;
3609    Uint32 srcpixel;
3610    Uint32 srcR, srcG, srcB, srcA;
3611    Uint32 dstpixel;
3612    Uint32 dstR, dstG, dstB, dstA;
3613    int srcy, srcx;
3614    int posy, posx;
3615    int incy, incx;
3616
3617    srcy = 0;
3618    posy = 0;
3619    incy = (info->src_h << 16) / info->dst_h;
3620    incx = (info->src_w << 16) / info->dst_w;
3621
3622    while (info->dst_h--) {
3623        Uint32 *src = 0;
3624        Uint32 *dst = (Uint32 *)info->dst;
3625        int n = info->dst_w;
3626        srcx = -1;
3627        posx = 0x10000L;
3628        while (posy >= 0x10000L) {
3629            ++srcy;
3630            posy -= 0x10000L;
3631        }
3632        while (n--) {
3633            if (posx >= 0x10000L) {
3634                while (posx >= 0x10000L) {
3635                    ++srcx;
3636                    posx -= 0x10000L;
3637                }
3638                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
3639            }
3640            srcpixel = *src;
3641            srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel;
3642            dstpixel = *dst;
3643            dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
3644            if (flags & SDL_COPY_MODULATE_COLOR) {
3645                srcR = (srcR * modulateR) / 255;
3646                srcG = (srcG * modulateG) / 255;
3647                srcB = (srcB * modulateB) / 255;
3648            }
3649            if (flags & SDL_COPY_MODULATE_ALPHA) {
3650                srcA = (srcA * modulateA) / 255;
3651            }
3652            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
3653                /* This goes away if we ever use premultiplied alpha */
3654                if (srcA < 255) {
3655                    srcR = (srcR * srcA) / 255;
3656                    srcG = (srcG * srcA) / 255;
3657                    srcB = (srcB * srcA) / 255;
3658                }
3659            }
3660            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
3661            case SDL_COPY_BLEND:
3662                dstR = srcR + ((255 - srcA) * dstR) / 255;
3663                dstG = srcG + ((255 - srcA) * dstG) / 255;
3664                dstB = srcB + ((255 - srcA) * dstB) / 255;
3665                break;
3666            case SDL_COPY_ADD:
3667                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
3668                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
3669                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
3670                break;
3671            case SDL_COPY_MOD:
3672                dstR = (srcR * dstR) / 255;
3673                dstG = (srcG * dstG) / 255;
3674                dstB = (srcB * dstB) / 255;
3675                break;
3676            }
3677            dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
3678            *dst = dstpixel;
3679            posx += incx;
3680            ++dst;
3681        }
3682        posy += incy;
3683        info->dst += info->dst_pitch;
3684    }
3685}
3686
3687static void SDL_Blit_RGBA8888_RGB888_Scale(SDL_BlitInfo *info)
3688{
3689    Uint32 pixel;
3690    Uint32 R, G, B, A;
3691    int srcy, srcx;
3692    int posy, posx;
3693    int incy, incx;
3694
3695    srcy = 0;
3696    posy = 0;
3697    incy = (info->src_h << 16) / info->dst_h;
3698    incx = (info->src_w << 16) / info->dst_w;
3699
3700    while (info->dst_h--) {
3701        Uint32 *src = 0;
3702        Uint32 *dst = (Uint32 *)info->dst;
3703        int n = info->dst_w;
3704        srcx = -1;
3705        posx = 0x10000L;
3706        while (posy >= 0x10000L) {
3707            ++srcy;
3708            posy -= 0x10000L;
3709        }
3710        while (n--) {
3711            if (posx >= 0x10000L) {
3712                while (posx >= 0x10000L) {
3713                    ++srcx;
3714                    posx -= 0x10000L;
3715                }
3716                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
3717            }
3718            pixel = *src;
3719            R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8); A = (Uint8)pixel;
3720            pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
3721            *dst = pixel;
3722            posx += incx;
3723            ++dst;
3724        }
3725        posy += incy;
3726        info->dst += info->dst_pitch;
3727    }
3728}
3729
3730static void SDL_Blit_RGBA8888_RGB888_Blend(SDL_BlitInfo *info)
3731{
3732    const int flags = info->flags;
3733    Uint32 srcpixel;
3734    Uint32 srcR, srcG, srcB, srcA;
3735    Uint32 dstpixel;
3736    Uint32 dstR, dstG, dstB, dstA;
3737
3738    while (info->dst_h--) {
3739        Uint32 *src = (Uint32 *)info->src;
3740        Uint32 *dst = (Uint32 *)info->dst;
3741        int n = info->dst_w;
3742        while (n--) {
3743            srcpixel = *src;
3744            srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
3745            dstpixel = *dst;
3746            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
3747            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
3748                /* This goes away if we ever use premultiplied alpha */
3749                if (srcA < 255) {
3750                    srcR = (srcR * srcA) / 255;
3751                    srcG = (srcG * srcA) / 255;
3752                    srcB = (srcB * srcA) / 255;
3753                }
3754            }
3755            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
3756            case SDL_COPY_BLEND:
3757                dstR = srcR + ((255 - srcA) * dstR) / 255;
3758                dstG = srcG + ((255 - srcA) * dstG) / 255;
3759                dstB = srcB + ((255 - srcA) * dstB) / 255;
3760                break;
3761            case SDL_COPY_ADD:
3762                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
3763                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
3764                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
3765                break;
3766            case SDL_COPY_MOD:
3767                dstR = (srcR * dstR) / 255;
3768                dstG = (srcG * dstG) / 255;
3769                dstB = (srcB * dstB) / 255;
3770                break;
3771            }
3772            dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
3773            *dst = dstpixel;
3774            ++src;
3775            ++dst;
3776        }
3777        info->src += info->src_pitch;
3778        info->dst += info->dst_pitch;
3779    }
3780}
3781
3782static void SDL_Blit_RGBA8888_RGB888_Blend_Scale(SDL_BlitInfo *info)
3783{
3784    const int flags = info->flags;
3785    Uint32 srcpixel;
3786    Uint32 srcR, srcG, srcB, srcA;
3787    Uint32 dstpixel;
3788    Uint32 dstR, dstG, dstB, dstA;
3789    int srcy, srcx;
3790    int posy, posx;
3791    int incy, incx;
3792
3793    srcy = 0;
3794    posy = 0;
3795    incy = (info->src_h << 16) / info->dst_h;
3796    incx = (info->src_w << 16) / info->dst_w;
3797
3798    while (info->dst_h--) {
3799        Uint32 *src = 0;
3800        Uint32 *dst = (Uint32 *)info->dst;
3801        int n = info->dst_w;
3802        srcx = -1;
3803        posx = 0x10000L;
3804        while (posy >= 0x10000L) {
3805            ++srcy;
3806            posy -= 0x10000L;
3807        }
3808        while (n--) {
3809            if (posx >= 0x10000L) {
3810                while (posx >= 0x10000L) {
3811                    ++srcx;
3812                    posx -= 0x10000L;
3813                }
3814                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
3815            }
3816            srcpixel = *src;
3817            srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
3818            dstpixel = *dst;
3819            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
3820            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
3821                /* This goes away if we ever use premultiplied alpha */
3822                if (srcA < 255) {
3823                    srcR = (srcR * srcA) / 255;
3824                    srcG = (srcG * srcA) / 255;
3825                    srcB = (srcB * srcA) / 255;
3826                }
3827            }
3828            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
3829            case SDL_COPY_BLEND:
3830                dstR = srcR + ((255 - srcA) * dstR) / 255;
3831                dstG = srcG + ((255 - srcA) * dstG) / 255;
3832                dstB = srcB + ((255 - srcA) * dstB) / 255;
3833                break;
3834            case SDL_COPY_ADD:
3835                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
3836                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
3837                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
3838                break;
3839            case SDL_COPY_MOD:
3840                dstR = (srcR * dstR) / 255;
3841                dstG = (srcG * dstG) / 255;
3842                dstB = (srcB * dstB) / 255;
3843                break;
3844            }
3845            dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
3846            *dst = dstpixel;
3847            posx += incx;
3848            ++dst;
3849        }
3850        posy += incy;
3851        info->dst += info->dst_pitch;
3852    }
3853}
3854
3855static void SDL_Blit_RGBA8888_RGB888_Modulate(SDL_BlitInfo *info)
3856{
3857    const int flags = info->flags;
3858    const Uint32 modulateR = info->r;
3859    const Uint32 modulateG = info->g;
3860    const Uint32 modulateB = info->b;
3861    const Uint32 modulateA = info->a;
3862    Uint32 pixel;
3863    Uint32 R, G, B, A;
3864
3865    while (info->dst_h--) {
3866        Uint32 *src = (Uint32 *)info->src;
3867        Uint32 *dst = (Uint32 *)info->dst;
3868        int n = info->dst_w;
3869        while (n--) {
3870            pixel = *src;
3871            R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8); A = (Uint8)pixel;
3872            if (flags & SDL_COPY_MODULATE_COLOR) {
3873                R = (R * modulateR) / 255;
3874                G = (G * modulateG) / 255;
3875                B = (B * modulateB) / 255;
3876            }
3877            if (flags & SDL_COPY_MODULATE_ALPHA) {
3878                A = (A * modulateA) / 255;
3879            }
3880            pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
3881            *dst = pixel;
3882            ++src;
3883            ++dst;
3884        }
3885        info->src += info->src_pitch;
3886        info->dst += info->dst_pitch;
3887    }
3888}
3889
3890static void SDL_Blit_RGBA8888_RGB888_Modulate_Scale(SDL_BlitInfo *info)
3891{
3892    const int flags = info->flags;
3893    const Uint32 modulateR = info->r;
3894    const Uint32 modulateG = info->g;
3895    const Uint32 modulateB = info->b;
3896    const Uint32 modulateA = info->a;
3897    Uint32 pixel;
3898    Uint32 R, G, B, A;
3899    int srcy, srcx;
3900    int posy, posx;
3901    int incy, incx;
3902
3903    srcy = 0;
3904    posy = 0;
3905    incy = (info->src_h << 16) / info->dst_h;
3906    incx = (info->src_w << 16) / info->dst_w;
3907
3908    while (info->dst_h--) {
3909        Uint32 *src = 0;
3910        Uint32 *dst = (Uint32 *)info->dst;
3911        int n = info->dst_w;
3912        srcx = -1;
3913        posx = 0x10000L;
3914        while (posy >= 0x10000L) {
3915            ++srcy;
3916            posy -= 0x10000L;
3917        }
3918        while (n--) {
3919            if (posx >= 0x10000L) {
3920                while (posx >= 0x10000L) {
3921                    ++srcx;
3922                    posx -= 0x10000L;
3923                }
3924                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
3925            }
3926            pixel = *src;
3927            R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8); A = (Uint8)pixel;
3928            if (flags & SDL_COPY_MODULATE_COLOR) {
3929                R = (R * modulateR) / 255;
3930                G = (G * modulateG) / 255;
3931                B = (B * modulateB) / 255;
3932            }
3933            if (flags & SDL_COPY_MODULATE_ALPHA) {
3934                A = (A * modulateA) / 255;
3935            }
3936            pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
3937            *dst = pixel;
3938            posx += incx;
3939            ++dst;
3940        }
3941        posy += incy;
3942        info->dst += info->dst_pitch;
3943    }
3944}
3945
3946static void SDL_Blit_RGBA8888_RGB888_Modulate_Blend(SDL_BlitInfo *info)
3947{
3948    const int flags = info->flags;
3949    const Uint32 modulateR = info->r;
3950    const Uint32 modulateG = info->g;
3951    const Uint32 modulateB = info->b;
3952    const Uint32 modulateA = info->a;
3953    Uint32 srcpixel;
3954    Uint32 srcR, srcG, srcB, srcA;
3955    Uint32 dstpixel;
3956    Uint32 dstR, dstG, dstB, dstA;
3957
3958    while (info->dst_h--) {
3959        Uint32 *src = (Uint32 *)info->src;
3960        Uint32 *dst = (Uint32 *)info->dst;
3961        int n = info->dst_w;
3962        while (n--) {
3963            srcpixel = *src;
3964            srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
3965            dstpixel = *dst;
3966            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
3967            if (flags & SDL_COPY_MODULATE_COLOR) {
3968                srcR = (srcR * modulateR) / 255;
3969                srcG = (srcG * modulateG) / 255;
3970                srcB = (srcB * modulateB) / 255;
3971            }
3972            if (flags & SDL_COPY_MODULATE_ALPHA) {
3973                srcA = (srcA * modulateA) / 255;
3974            }
3975            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
3976                /* This goes away if we ever use premultiplied alpha */
3977                if (srcA < 255) {
3978                    srcR = (srcR * srcA) / 255;
3979                    srcG = (srcG * srcA) / 255;
3980                    srcB = (srcB * srcA) / 255;
3981                }
3982            }
3983            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
3984            case SDL_COPY_BLEND:
3985                dstR = srcR + ((255 - srcA) * dstR) / 255;
3986                dstG = srcG + ((255 - srcA) * dstG) / 255;
3987                dstB = srcB + ((255 - srcA) * dstB) / 255;
3988                break;
3989            case SDL_COPY_ADD:
3990                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
3991                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
3992                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
3993                break;
3994            case SDL_COPY_MOD:
3995                dstR = (srcR * dstR) / 255;
3996                dstG = (srcG * dstG) / 255;
3997                dstB = (srcB * dstB) / 255;
3998                break;
3999            }
4000            dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
4001            *dst = dstpixel;
4002            ++src;
4003            ++dst;
4004        }
4005        info->src += info->src_pitch;
4006        info->dst += info->dst_pitch;
4007    }
4008}
4009
4010static void SDL_Blit_RGBA8888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info)
4011{
4012    const int flags = info->flags;
4013    const Uint32 modulateR = info->r;
4014    const Uint32 modulateG = info->g;
4015    const Uint32 modulateB = info->b;
4016    const Uint32 modulateA = info->a;
4017    Uint32 srcpixel;
4018    Uint32 srcR, srcG, srcB, srcA;
4019    Uint32 dstpixel;
4020    Uint32 dstR, dstG, dstB, dstA;
4021    int srcy, srcx;
4022    int posy, posx;
4023    int incy, incx;
4024
4025    srcy = 0;
4026    posy = 0;
4027    incy = (info->src_h << 16) / info->dst_h;
4028    incx = (info->src_w << 16) / info->dst_w;
4029
4030    while (info->dst_h--) {
4031        Uint32 *src = 0;
4032        Uint32 *dst = (Uint32 *)info->dst;
4033        int n = info->dst_w;
4034        srcx = -1;
4035        posx = 0x10000L;
4036        while (posy >= 0x10000L) {
4037            ++srcy;
4038            posy -= 0x10000L;
4039        }
4040        while (n--) {
4041            if (posx >= 0x10000L) {
4042                while (posx >= 0x10000L) {
4043                    ++srcx;
4044                    posx -= 0x10000L;
4045                }
4046                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
4047            }
4048            srcpixel = *src;
4049            srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
4050            dstpixel = *dst;
4051            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
4052            if (flags & SDL_COPY_MODULATE_COLOR) {
4053                srcR = (srcR * modulateR) / 255;
4054                srcG = (srcG * modulateG) / 255;
4055                srcB = (srcB * modulateB) / 255;
4056            }
4057            if (flags & SDL_COPY_MODULATE_ALPHA) {
4058                srcA = (srcA * modulateA) / 255;
4059            }
4060            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
4061                /* This goes away if we ever use premultiplied alpha */
4062                if (srcA < 255) {
4063                    srcR = (srcR * srcA) / 255;
4064                    srcG = (srcG * srcA) / 255;
4065                    srcB = (srcB * srcA) / 255;
4066                }
4067            }
4068            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
4069            case SDL_COPY_BLEND:
4070                dstR = srcR + ((255 - srcA) * dstR) / 255;
4071                dstG = srcG + ((255 - srcA) * dstG) / 255;
4072                dstB = srcB + ((255 - srcA) * dstB) / 255;
4073                break;
4074            case SDL_COPY_ADD:
4075                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
4076                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
4077                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
4078                break;
4079            case SDL_COPY_MOD:
4080                dstR = (srcR * dstR) / 255;
4081                dstG = (srcG * dstG) / 255;
4082                dstB = (srcB * dstB) / 255;
4083                break;
4084            }
4085            dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
4086            *dst = dstpixel;
4087            posx += incx;
4088            ++dst;
4089        }
4090        posy += incy;
4091        info->dst += info->dst_pitch;
4092    }
4093}
4094
4095static void SDL_Blit_RGBA8888_BGR888_Scale(SDL_BlitInfo *info)
4096{
4097    Uint32 pixel;
4098    Uint32 R, G, B, A;
4099    int srcy, srcx;
4100    int posy, posx;
4101    int incy, incx;
4102
4103    srcy = 0;
4104    posy = 0;
4105    incy = (info->src_h << 16) / info->dst_h;
4106    incx = (info->src_w << 16) / info->dst_w;
4107
4108    while (info->dst_h--) {
4109        Uint32 *src = 0;
4110        Uint32 *dst = (Uint32 *)info->dst;
4111        int n = info->dst_w;
4112        srcx = -1;
4113        posx = 0x10000L;
4114        while (posy >= 0x10000L) {
4115            ++srcy;
4116            posy -= 0x10000L;
4117        }
4118        while (n--) {
4119            if (posx >= 0x10000L) {
4120                while (posx >= 0x10000L) {
4121                    ++srcx;
4122                    posx -= 0x10000L;
4123                }
4124                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
4125            }
4126            pixel = *src;
4127            R = (Uint8)(pixel >> 24); G = (Uint8)(pixel >> 16); B = (Uint8)(pixel >> 8); A = (Uint8)pixel;
4128            pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
4129            *dst = pixel;
4130            posx += incx;
4131            ++dst;
4132        }
4133        posy += incy;
4134        info->dst += info->dst_pitch;
4135    }
4136}
4137
4138static void SDL_Blit_RGBA8888_BGR888_Blend(SDL_BlitInfo *info)
4139{
4140    const int flags = info->flags;
4141    Uint32 srcpixel;
4142    Uint32 srcR, srcG, srcB, srcA;
4143    Uint32 dstpixel;
4144    Uint32 dstR, dstG, dstB, dstA;
4145
4146    while (info->dst_h--) {
4147        Uint32 *src = (Uint32 *)info->src;
4148        Uint32 *dst = (Uint32 *)info->dst;
4149        int n = info->dst_w;
4150        while (n--) {
4151            srcpixel = *src;
4152            srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
4153            dstpixel = *dst;
4154            dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
4155            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
4156                /* This goes away if we ever use premultiplied alpha */
4157                if (srcA < 255) {
4158                    srcR = (srcR * srcA) / 255;
4159                    srcG = (srcG * srcA) / 255;
4160                    srcB = (srcB * srcA) / 255;
4161                }
4162            }
4163            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
4164            case SDL_COPY_BLEND:
4165                dstR = srcR + ((255 - srcA) * dstR) / 255;
4166                dstG = srcG + ((255 - srcA) * dstG) / 255;
4167                dstB = srcB + ((255 - srcA) * dstB) / 255;
4168                break;
4169            case SDL_COPY_ADD:
4170                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
4171                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
4172                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
4173                break;
4174            case SDL_COPY_MOD:
4175                dstR = (srcR * dstR) / 255;
4176                dstG = (srcG * dstG) / 255;
4177                dstB = (srcB * dstB) / 255;
4178                break;
4179            }
4180            dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
4181            *dst = dstpixel;
4182            ++src;
4183            ++dst;
4184        }
4185        info->src += info->src_pitch;
4186        info->dst += info->dst_pitch;
4187    }
4188}
4189
4190static void SDL_Blit_RGBA8888_BGR888_Blend_Scale(SDL_BlitInfo *info)
4191{
4192    const int flags = info->flags;
4193    Uint32 srcpixel;
4194    Uint32 srcR, srcG, srcB, srcA;
4195    Uint32 dstpixel;
4196    Uint32 dstR, dstG, dstB, dstA;
4197    int srcy, srcx;
4198    int posy, posx;
4199    int incy, incx;
4200
4201    srcy = 0;
4202    posy = 0;
4203    incy = (info->src_h << 16) / info->dst_h;
4204    incx = (info->src_w << 16) / info->dst_w;
4205
4206    while (info->dst_h--) {
4207        Uint32 *src = 0;
4208        Uint32 *dst = (Uint32 *)info->dst;
4209        int n = info->dst_w;
4210        srcx = -1;
4211        posx = 0x10000L;
4212        while (posy >= 0x10000L) {
4213            ++srcy;
4214            posy -= 0x10000L;
4215        }
4216        while (n--) {
4217            if (posx >= 0x10000L) {
4218                while (posx >= 0x10000L) {
4219                    ++srcx;
4220                    posx -= 0x10000L;
4221                }
4222                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
4223            }
4224            srcpixel = *src;
4225            srcR = (Uint8)(srcpixel >> 24); srcG = (Uint8)(srcpixel >> 16); srcB = (Uint8)(srcpixel >> 8); srcA = (Uint8)srcpixel;
4226            dstpixel = *dst;
4227            dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
4228            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
4229                /* This goes away if we ever use premultiplied alpha */
4230                if (srcA < 255) {
4231                    srcR = (srcR * srcA) / 255;
4232                    srcG = (srcG * srcA) / 255;
4233                    srcB = (srcB * srcA) / 255;
4234                }
4235            }
4236            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
4237            case SDL_COPY_BLEND:
4238                dstR = srcR + ((255 - srcA) * dstR) / 255;
4239                dstG = srcG + ((255 - srcA) * dstG) / 255;
4240                dstB = srcB + ((255 - srcA) * dstB) / 255;
4241                break;
4242            case SDL_COPY_ADD:
4243                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
4244                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
4245                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
4246                break;
4247            case SDL_COPY_MOD:
4248                dstR = (srcR * dstR) / 255;
4249                dstG = (srcG * dstG) / 255;
4250                dstB = (srcB * dstB) / 255;
4251                break;
4252            }
4253            dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
4254            *dst = dstpixel;
4255            posx += incx;
4256            ++dst;
4257        }
4258        posy += incy;
4259        info->dst += info->dst_pitch<