PageRenderTime 157ms CodeModel.GetById 15ms app.highlight 128ms RepoModel.GetById 1ms 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

Large files files are truncated, but you can click here to view the full 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 = 

Large files files are truncated, but you can click here to view the full file