src/video/SDL_blit_auto.c
author Sam Lantinga <slouken@libsdl.org>
Sun, 20 Oct 2013 21:56:15 -0700
changeset 7860 2b0bcdea3a79
parent 7502 6ff02ff3cf06
child 8093 b43765095a6f
permissions -rw-r--r--
Fixed bug 2129 - fix for bug 2121 breaks linking for mingw and throws multiple warnings

Andreas Ertelt

The problem in question is caused by changeset 7771 (http://hg.libsdl.org/SDL/rev/4434498bf4b9 / https://bugzilla.libsdl.org/show_bug.cgi?id=2121)

The redefinition of __inline__ (introduced by the addition of begin_code.h:128's "|| __STRICT_ANSI__") results in mingw's gcc throwing multiple

warning: always_inline function might not be inlinable [-Wattributes]

as well as a whole bunch of redefinitions of mingw internals which break linking of projects including the SDL2 headers.
slouken@2262
     1
/* DO NOT EDIT!  This file is generated by sdlgenblit.pl */
slouken@2262
     2
/*
slouken@5535
     3
  Simple DirectMedia Layer
slouken@6885
     4
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
slouken@5535
     5
slouken@5535
     6
  This software is provided 'as-is', without any express or implied
slouken@5535
     7
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     8
  arising from the use of this software.
slouken@5535
     9
slouken@5535
    10
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    11
  including commercial applications, and to alter it and redistribute it
slouken@5535
    12
  freely, subject to the following restrictions:
slouken@5535
    13
slouken@5535
    14
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    15
     claim that you wrote the original software. If you use this software
slouken@5535
    16
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    17
     appreciated but is not required.
slouken@5535
    18
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    19
     misrepresented as being the original software.
slouken@5535
    20
  3. This notice may not be removed or altered from any source distribution.
slouken@2262
    21
*/
slouken@2262
    22
#include "SDL_config.h"
slouken@2262
    23
slouken@2262
    24
/* *INDENT-OFF* */
slouken@2262
    25
slouken@2262
    26
#include "SDL_video.h"
slouken@2262
    27
#include "SDL_blit.h"
slouken@2262
    28
#include "SDL_blit_auto.h"
slouken@2262
    29
slouken@2263
    30
static void SDL_Blit_RGB888_RGB888_Scale(SDL_BlitInfo *info)
slouken@2263
    31
{
slouken@2263
    32
    int srcy, srcx;
slouken@2263
    33
    int posy, posx;
slouken@2263
    34
    int incy, incx;
slouken@2263
    35
slouken@2263
    36
    srcy = 0;
slouken@2263
    37
    posy = 0;
slouken@2263
    38
    incy = (info->src_h << 16) / info->dst_h;
slouken@2263
    39
    incx = (info->src_w << 16) / info->dst_w;
slouken@2263
    40
slouken@2263
    41
    while (info->dst_h--) {
slouken@5426
    42
        Uint32 *src = 0;
slouken@2263
    43
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
    44
        int n = info->dst_w;
slouken@2263
    45
        srcx = -1;
slouken@2263
    46
        posx = 0x10000L;
slouken@2263
    47
        while (posy >= 0x10000L) {
slouken@2263
    48
            ++srcy;
slouken@2263
    49
            posy -= 0x10000L;
slouken@2263
    50
        }
slouken@2263
    51
        while (n--) {
slouken@2263
    52
            if (posx >= 0x10000L) {
slouken@2263
    53
                while (posx >= 0x10000L) {
slouken@2263
    54
                    ++srcx;
slouken@2263
    55
                    posx -= 0x10000L;
slouken@2263
    56
                }
slouken@2263
    57
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2263
    58
            }
slouken@2263
    59
            *dst = *src;
slouken@2263
    60
            posx += incx;
slouken@2263
    61
            ++dst;
slouken@2263
    62
        }
slouken@2263
    63
        posy += incy;
slouken@2263
    64
        info->dst += info->dst_pitch;
slouken@2263
    65
    }
slouken@2263
    66
}
slouken@2263
    67
slouken@2263
    68
static void SDL_Blit_RGB888_RGB888_Blend(SDL_BlitInfo *info)
slouken@2263
    69
{
slouken@2263
    70
    const int flags = info->flags;
slouken@2263
    71
    Uint32 srcpixel;
slouken@2263
    72
    Uint32 srcR, srcG, srcB, srcA;
slouken@2263
    73
    Uint32 dstpixel;
slouken@2263
    74
    Uint32 dstR, dstG, dstB, dstA;
slouken@2263
    75
slouken@2263
    76
    while (info->dst_h--) {
slouken@2263
    77
        Uint32 *src = (Uint32 *)info->src;
slouken@2263
    78
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
    79
        int n = info->dst_w;
slouken@2263
    80
        while (n--) {
slouken@2263
    81
            srcpixel = *src;
slouken@2263
    82
            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
slouken@2263
    83
            dstpixel = *dst;
slouken@2263
    84
            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
slouken@2263
    85
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2263
    86
                /* This goes away if we ever use premultiplied alpha */
slouken@2263
    87
                if (srcA < 255) {
slouken@2263
    88
                    srcR = (srcR * srcA) / 255;
slouken@2263
    89
                    srcG = (srcG * srcA) / 255;
slouken@2263
    90
                    srcB = (srcB * srcA) / 255;
slouken@2263
    91
                }
slouken@2263
    92
            }
slouken@5184
    93
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2263
    94
            case SDL_COPY_BLEND:
slouken@2263
    95
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2263
    96
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2263
    97
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
    98
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2263
    99
                break;
slouken@2263
   100
            case SDL_COPY_ADD:
slouken@2263
   101
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2263
   102
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2263
   103
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2263
   104
                break;
slouken@5184
   105
            case SDL_COPY_MOD:
slouken@5184
   106
                dstR = (srcR * dstR) / 255;
slouken@5184
   107
                dstG = (srcG * dstG) / 255;
slouken@5184
   108
                dstB = (srcB * dstB) / 255;
slouken@5184
   109
                break;
slouken@2263
   110
            }
slouken@2263
   111
            dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
slouken@2263
   112
            *dst = dstpixel;
slouken@2263
   113
            ++src;
slouken@2263
   114
            ++dst;
slouken@2263
   115
        }
slouken@2263
   116
        info->src += info->src_pitch;
slouken@2263
   117
        info->dst += info->dst_pitch;
slouken@2263
   118
    }
slouken@2263
   119
}
slouken@2263
   120
slouken@2263
   121
static void SDL_Blit_RGB888_RGB888_Blend_Scale(SDL_BlitInfo *info)
slouken@2263
   122
{
slouken@2263
   123
    const int flags = info->flags;
slouken@2263
   124
    Uint32 srcpixel;
slouken@2263
   125
    Uint32 srcR, srcG, srcB, srcA;
slouken@2263
   126
    Uint32 dstpixel;
slouken@2263
   127
    Uint32 dstR, dstG, dstB, dstA;
slouken@2263
   128
    int srcy, srcx;
slouken@2263
   129
    int posy, posx;
slouken@2263
   130
    int incy, incx;
slouken@2263
   131
slouken@2263
   132
    srcy = 0;
slouken@2263
   133
    posy = 0;
slouken@2263
   134
    incy = (info->src_h << 16) / info->dst_h;
slouken@2263
   135
    incx = (info->src_w << 16) / info->dst_w;
slouken@2263
   136
slouken@2263
   137
    while (info->dst_h--) {
slouken@5426
   138
        Uint32 *src = 0;
slouken@2263
   139
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
   140
        int n = info->dst_w;
slouken@2263
   141
        srcx = -1;
slouken@2263
   142
        posx = 0x10000L;
slouken@2263
   143
        while (posy >= 0x10000L) {
slouken@2263
   144
            ++srcy;
slouken@2263
   145
            posy -= 0x10000L;
slouken@2263
   146
        }
slouken@2263
   147
        while (n--) {
slouken@2263
   148
            if (posx >= 0x10000L) {
slouken@2263
   149
                while (posx >= 0x10000L) {
slouken@2263
   150
                    ++srcx;
slouken@2263
   151
                    posx -= 0x10000L;
slouken@2263
   152
                }
slouken@2263
   153
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2263
   154
            }
slouken@2263
   155
            srcpixel = *src;
slouken@2263
   156
            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
slouken@2263
   157
            dstpixel = *dst;
slouken@2263
   158
            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
slouken@2263
   159
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2263
   160
                /* This goes away if we ever use premultiplied alpha */
slouken@2263
   161
                if (srcA < 255) {
slouken@2263
   162
                    srcR = (srcR * srcA) / 255;
slouken@2263
   163
                    srcG = (srcG * srcA) / 255;
slouken@2263
   164
                    srcB = (srcB * srcA) / 255;
slouken@2263
   165
                }
slouken@2263
   166
            }
slouken@5184
   167
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2263
   168
            case SDL_COPY_BLEND:
slouken@2263
   169
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2263
   170
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2263
   171
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
   172
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2263
   173
                break;
slouken@2263
   174
            case SDL_COPY_ADD:
slouken@2263
   175
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2263
   176
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2263
   177
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2263
   178
                break;
slouken@5184
   179
            case SDL_COPY_MOD:
slouken@5184
   180
                dstR = (srcR * dstR) / 255;
slouken@5184
   181
                dstG = (srcG * dstG) / 255;
slouken@5184
   182
                dstB = (srcB * dstB) / 255;
slouken@5184
   183
                break;
slouken@2263
   184
            }
slouken@2263
   185
            dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
slouken@2263
   186
            *dst = dstpixel;
slouken@2263
   187
            posx += incx;
slouken@2263
   188
            ++dst;
slouken@2263
   189
        }
slouken@2263
   190
        posy += incy;
slouken@2263
   191
        info->dst += info->dst_pitch;
slouken@2263
   192
    }
slouken@2263
   193
}
slouken@2263
   194
slouken@2263
   195
static void SDL_Blit_RGB888_RGB888_Modulate(SDL_BlitInfo *info)
slouken@2263
   196
{
slouken@2263
   197
    const int flags = info->flags;
slouken@2263
   198
    const Uint32 modulateR = info->r;
slouken@2263
   199
    const Uint32 modulateG = info->g;
slouken@2263
   200
    const Uint32 modulateB = info->b;
slouken@2263
   201
    const Uint32 modulateA = info->a;
slouken@2263
   202
    Uint32 pixel;
slouken@2263
   203
    Uint32 R, G, B, A;
slouken@2263
   204
slouken@2263
   205
    while (info->dst_h--) {
slouken@2263
   206
        Uint32 *src = (Uint32 *)info->src;
slouken@2263
   207
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
   208
        int n = info->dst_w;
slouken@2263
   209
        while (n--) {
slouken@2263
   210
            pixel = *src;
slouken@2263
   211
            R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF;
slouken@2263
   212
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2263
   213
                R = (R * modulateR) / 255;
slouken@2263
   214
                G = (G * modulateG) / 255;
slouken@2263
   215
                B = (B * modulateB) / 255;
slouken@2263
   216
            }
slouken@2263
   217
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2263
   218
                A = (A * modulateA) / 255;
slouken@2263
   219
            }
slouken@2263
   220
            pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
slouken@2263
   221
            *dst = pixel;
slouken@2263
   222
            ++src;
slouken@2263
   223
            ++dst;
slouken@2263
   224
        }
slouken@2263
   225
        info->src += info->src_pitch;
slouken@2263
   226
        info->dst += info->dst_pitch;
slouken@2263
   227
    }
slouken@2263
   228
}
slouken@2263
   229
slouken@2263
   230
static void SDL_Blit_RGB888_RGB888_Modulate_Scale(SDL_BlitInfo *info)
slouken@2263
   231
{
slouken@2263
   232
    const int flags = info->flags;
slouken@2263
   233
    const Uint32 modulateR = info->r;
slouken@2263
   234
    const Uint32 modulateG = info->g;
slouken@2263
   235
    const Uint32 modulateB = info->b;
slouken@2263
   236
    const Uint32 modulateA = info->a;
slouken@2263
   237
    Uint32 pixel;
slouken@2263
   238
    Uint32 R, G, B, A;
slouken@2263
   239
    int srcy, srcx;
slouken@2263
   240
    int posy, posx;
slouken@2263
   241
    int incy, incx;
slouken@2263
   242
slouken@2263
   243
    srcy = 0;
slouken@2263
   244
    posy = 0;
slouken@2263
   245
    incy = (info->src_h << 16) / info->dst_h;
slouken@2263
   246
    incx = (info->src_w << 16) / info->dst_w;
slouken@2263
   247
slouken@2263
   248
    while (info->dst_h--) {
slouken@5426
   249
        Uint32 *src = 0;
slouken@2263
   250
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
   251
        int n = info->dst_w;
slouken@2263
   252
        srcx = -1;
slouken@2263
   253
        posx = 0x10000L;
slouken@2263
   254
        while (posy >= 0x10000L) {
slouken@2263
   255
            ++srcy;
slouken@2263
   256
            posy -= 0x10000L;
slouken@2263
   257
        }
slouken@2263
   258
        while (n--) {
slouken@2263
   259
            if (posx >= 0x10000L) {
slouken@2263
   260
                while (posx >= 0x10000L) {
slouken@2263
   261
                    ++srcx;
slouken@2263
   262
                    posx -= 0x10000L;
slouken@2263
   263
                }
slouken@2263
   264
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2263
   265
            }
slouken@2263
   266
            pixel = *src;
slouken@2263
   267
            R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF;
slouken@2263
   268
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2263
   269
                R = (R * modulateR) / 255;
slouken@2263
   270
                G = (G * modulateG) / 255;
slouken@2263
   271
                B = (B * modulateB) / 255;
slouken@2263
   272
            }
slouken@2263
   273
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2263
   274
                A = (A * modulateA) / 255;
slouken@2263
   275
            }
slouken@2263
   276
            pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
slouken@2263
   277
            *dst = pixel;
slouken@2263
   278
            posx += incx;
slouken@2263
   279
            ++dst;
slouken@2263
   280
        }
slouken@2263
   281
        posy += incy;
slouken@2263
   282
        info->dst += info->dst_pitch;
slouken@2263
   283
    }
slouken@2263
   284
}
slouken@2263
   285
slouken@2263
   286
static void SDL_Blit_RGB888_RGB888_Modulate_Blend(SDL_BlitInfo *info)
slouken@2263
   287
{
slouken@2263
   288
    const int flags = info->flags;
slouken@2263
   289
    const Uint32 modulateR = info->r;
slouken@2263
   290
    const Uint32 modulateG = info->g;
slouken@2263
   291
    const Uint32 modulateB = info->b;
slouken@2263
   292
    const Uint32 modulateA = info->a;
slouken@2263
   293
    Uint32 srcpixel;
slouken@2263
   294
    Uint32 srcR, srcG, srcB, srcA;
slouken@2263
   295
    Uint32 dstpixel;
slouken@2263
   296
    Uint32 dstR, dstG, dstB, dstA;
slouken@2263
   297
slouken@2263
   298
    while (info->dst_h--) {
slouken@2263
   299
        Uint32 *src = (Uint32 *)info->src;
slouken@2263
   300
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
   301
        int n = info->dst_w;
slouken@2263
   302
        while (n--) {
slouken@2263
   303
            srcpixel = *src;
slouken@2263
   304
            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
slouken@2263
   305
            dstpixel = *dst;
slouken@2263
   306
            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
slouken@2263
   307
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2263
   308
                srcR = (srcR * modulateR) / 255;
slouken@2263
   309
                srcG = (srcG * modulateG) / 255;
slouken@2263
   310
                srcB = (srcB * modulateB) / 255;
slouken@2263
   311
            }
slouken@2263
   312
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2263
   313
                srcA = (srcA * modulateA) / 255;
slouken@2263
   314
            }
slouken@2263
   315
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2263
   316
                /* This goes away if we ever use premultiplied alpha */
slouken@2263
   317
                if (srcA < 255) {
slouken@2263
   318
                    srcR = (srcR * srcA) / 255;
slouken@2263
   319
                    srcG = (srcG * srcA) / 255;
slouken@2263
   320
                    srcB = (srcB * srcA) / 255;
slouken@2263
   321
                }
slouken@2263
   322
            }
slouken@5184
   323
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2263
   324
            case SDL_COPY_BLEND:
slouken@2263
   325
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2263
   326
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2263
   327
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
   328
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2263
   329
                break;
slouken@2263
   330
            case SDL_COPY_ADD:
slouken@2263
   331
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2263
   332
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2263
   333
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2263
   334
                break;
slouken@5184
   335
            case SDL_COPY_MOD:
slouken@5184
   336
                dstR = (srcR * dstR) / 255;
slouken@5184
   337
                dstG = (srcG * dstG) / 255;
slouken@5184
   338
                dstB = (srcB * dstB) / 255;
slouken@5184
   339
                break;
slouken@2263
   340
            }
slouken@2263
   341
            dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
slouken@2263
   342
            *dst = dstpixel;
slouken@2263
   343
            ++src;
slouken@2263
   344
            ++dst;
slouken@2263
   345
        }
slouken@2263
   346
        info->src += info->src_pitch;
slouken@2263
   347
        info->dst += info->dst_pitch;
slouken@2263
   348
    }
slouken@2263
   349
}
slouken@2263
   350
slouken@2263
   351
static void SDL_Blit_RGB888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info)
slouken@2263
   352
{
slouken@2263
   353
    const int flags = info->flags;
slouken@2263
   354
    const Uint32 modulateR = info->r;
slouken@2263
   355
    const Uint32 modulateG = info->g;
slouken@2263
   356
    const Uint32 modulateB = info->b;
slouken@2263
   357
    const Uint32 modulateA = info->a;
slouken@2263
   358
    Uint32 srcpixel;
slouken@2263
   359
    Uint32 srcR, srcG, srcB, srcA;
slouken@2263
   360
    Uint32 dstpixel;
slouken@2263
   361
    Uint32 dstR, dstG, dstB, dstA;
slouken@2263
   362
    int srcy, srcx;
slouken@2263
   363
    int posy, posx;
slouken@2263
   364
    int incy, incx;
slouken@2263
   365
slouken@2263
   366
    srcy = 0;
slouken@2263
   367
    posy = 0;
slouken@2263
   368
    incy = (info->src_h << 16) / info->dst_h;
slouken@2263
   369
    incx = (info->src_w << 16) / info->dst_w;
slouken@2263
   370
slouken@2263
   371
    while (info->dst_h--) {
slouken@5426
   372
        Uint32 *src = 0;
slouken@2263
   373
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
   374
        int n = info->dst_w;
slouken@2263
   375
        srcx = -1;
slouken@2263
   376
        posx = 0x10000L;
slouken@2263
   377
        while (posy >= 0x10000L) {
slouken@2263
   378
            ++srcy;
slouken@2263
   379
            posy -= 0x10000L;
slouken@2263
   380
        }
slouken@2263
   381
        while (n--) {
slouken@2263
   382
            if (posx >= 0x10000L) {
slouken@2263
   383
                while (posx >= 0x10000L) {
slouken@2263
   384
                    ++srcx;
slouken@2263
   385
                    posx -= 0x10000L;
slouken@2263
   386
                }
slouken@2263
   387
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2263
   388
            }
slouken@2263
   389
            srcpixel = *src;
slouken@2263
   390
            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
slouken@2263
   391
            dstpixel = *dst;
slouken@2263
   392
            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
slouken@2263
   393
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2263
   394
                srcR = (srcR * modulateR) / 255;
slouken@2263
   395
                srcG = (srcG * modulateG) / 255;
slouken@2263
   396
                srcB = (srcB * modulateB) / 255;
slouken@2263
   397
            }
slouken@2263
   398
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2263
   399
                srcA = (srcA * modulateA) / 255;
slouken@2263
   400
            }
slouken@2263
   401
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2263
   402
                /* This goes away if we ever use premultiplied alpha */
slouken@2263
   403
                if (srcA < 255) {
slouken@2263
   404
                    srcR = (srcR * srcA) / 255;
slouken@2263
   405
                    srcG = (srcG * srcA) / 255;
slouken@2263
   406
                    srcB = (srcB * srcA) / 255;
slouken@2263
   407
                }
slouken@2263
   408
            }
slouken@5184
   409
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2263
   410
            case SDL_COPY_BLEND:
slouken@2263
   411
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2263
   412
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2263
   413
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
   414
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2263
   415
                break;
slouken@2263
   416
            case SDL_COPY_ADD:
slouken@2263
   417
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2263
   418
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2263
   419
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2263
   420
                break;
slouken@5184
   421
            case SDL_COPY_MOD:
slouken@5184
   422
                dstR = (srcR * dstR) / 255;
slouken@5184
   423
                dstG = (srcG * dstG) / 255;
slouken@5184
   424
                dstB = (srcB * dstB) / 255;
slouken@5184
   425
                break;
slouken@2263
   426
            }
slouken@2263
   427
            dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
slouken@2263
   428
            *dst = dstpixel;
slouken@2263
   429
            posx += incx;
slouken@2263
   430
            ++dst;
slouken@2263
   431
        }
slouken@2263
   432
        posy += incy;
slouken@2263
   433
        info->dst += info->dst_pitch;
slouken@2263
   434
    }
slouken@2263
   435
}
slouken@2263
   436
slouken@2263
   437
static void SDL_Blit_RGB888_BGR888_Scale(SDL_BlitInfo *info)
slouken@2263
   438
{
slouken@2263
   439
    Uint32 pixel;
slouken@2263
   440
    Uint32 R, G, B, A;
slouken@2263
   441
    int srcy, srcx;
slouken@2263
   442
    int posy, posx;
slouken@2263
   443
    int incy, incx;
slouken@2263
   444
slouken@2263
   445
    srcy = 0;
slouken@2263
   446
    posy = 0;
slouken@2263
   447
    incy = (info->src_h << 16) / info->dst_h;
slouken@2263
   448
    incx = (info->src_w << 16) / info->dst_w;
slouken@2263
   449
slouken@2263
   450
    while (info->dst_h--) {
slouken@5426
   451
        Uint32 *src = 0;
slouken@2263
   452
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
   453
        int n = info->dst_w;
slouken@2263
   454
        srcx = -1;
slouken@2263
   455
        posx = 0x10000L;
slouken@2263
   456
        while (posy >= 0x10000L) {
slouken@2263
   457
            ++srcy;
slouken@2263
   458
            posy -= 0x10000L;
slouken@2263
   459
        }
slouken@2263
   460
        while (n--) {
slouken@2263
   461
            if (posx >= 0x10000L) {
slouken@2263
   462
                while (posx >= 0x10000L) {
slouken@2263
   463
                    ++srcx;
slouken@2263
   464
                    posx -= 0x10000L;
slouken@2263
   465
                }
slouken@2263
   466
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2263
   467
            }
slouken@2263
   468
            pixel = *src;
slouken@2263
   469
            R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF;
slouken@2263
   470
            pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
slouken@2263
   471
            *dst = pixel;
slouken@2263
   472
            posx += incx;
slouken@2263
   473
            ++dst;
slouken@2263
   474
        }
slouken@2263
   475
        posy += incy;
slouken@2263
   476
        info->dst += info->dst_pitch;
slouken@2263
   477
    }
slouken@2263
   478
}
slouken@2263
   479
slouken@2263
   480
static void SDL_Blit_RGB888_BGR888_Blend(SDL_BlitInfo *info)
slouken@2263
   481
{
slouken@2263
   482
    const int flags = info->flags;
slouken@2263
   483
    Uint32 srcpixel;
slouken@2263
   484
    Uint32 srcR, srcG, srcB, srcA;
slouken@2263
   485
    Uint32 dstpixel;
slouken@2263
   486
    Uint32 dstR, dstG, dstB, dstA;
slouken@2263
   487
slouken@2263
   488
    while (info->dst_h--) {
slouken@2263
   489
        Uint32 *src = (Uint32 *)info->src;
slouken@2263
   490
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
   491
        int n = info->dst_w;
slouken@2263
   492
        while (n--) {
slouken@2263
   493
            srcpixel = *src;
slouken@2263
   494
            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
slouken@2263
   495
            dstpixel = *dst;
slouken@2263
   496
            dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
slouken@2263
   497
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2263
   498
                /* This goes away if we ever use premultiplied alpha */
slouken@2263
   499
                if (srcA < 255) {
slouken@2263
   500
                    srcR = (srcR * srcA) / 255;
slouken@2263
   501
                    srcG = (srcG * srcA) / 255;
slouken@2263
   502
                    srcB = (srcB * srcA) / 255;
slouken@2263
   503
                }
slouken@2263
   504
            }
slouken@5184
   505
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2263
   506
            case SDL_COPY_BLEND:
slouken@2263
   507
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2263
   508
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2263
   509
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
   510
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2263
   511
                break;
slouken@2263
   512
            case SDL_COPY_ADD:
slouken@2263
   513
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2263
   514
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2263
   515
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2263
   516
                break;
slouken@5184
   517
            case SDL_COPY_MOD:
slouken@5184
   518
                dstR = (srcR * dstR) / 255;
slouken@5184
   519
                dstG = (srcG * dstG) / 255;
slouken@5184
   520
                dstB = (srcB * dstB) / 255;
slouken@5184
   521
                break;
slouken@2263
   522
            }
slouken@2263
   523
            dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
slouken@2263
   524
            *dst = dstpixel;
slouken@2263
   525
            ++src;
slouken@2263
   526
            ++dst;
slouken@2263
   527
        }
slouken@2263
   528
        info->src += info->src_pitch;
slouken@2263
   529
        info->dst += info->dst_pitch;
slouken@2263
   530
    }
slouken@2263
   531
}
slouken@2263
   532
slouken@2263
   533
static void SDL_Blit_RGB888_BGR888_Blend_Scale(SDL_BlitInfo *info)
slouken@2263
   534
{
slouken@2263
   535
    const int flags = info->flags;
slouken@2263
   536
    Uint32 srcpixel;
slouken@2263
   537
    Uint32 srcR, srcG, srcB, srcA;
slouken@2263
   538
    Uint32 dstpixel;
slouken@2263
   539
    Uint32 dstR, dstG, dstB, dstA;
slouken@2263
   540
    int srcy, srcx;
slouken@2263
   541
    int posy, posx;
slouken@2263
   542
    int incy, incx;
slouken@2263
   543
slouken@2263
   544
    srcy = 0;
slouken@2263
   545
    posy = 0;
slouken@2263
   546
    incy = (info->src_h << 16) / info->dst_h;
slouken@2263
   547
    incx = (info->src_w << 16) / info->dst_w;
slouken@2263
   548
slouken@2263
   549
    while (info->dst_h--) {
slouken@5426
   550
        Uint32 *src = 0;
slouken@2263
   551
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
   552
        int n = info->dst_w;
slouken@2263
   553
        srcx = -1;
slouken@2263
   554
        posx = 0x10000L;
slouken@2263
   555
        while (posy >= 0x10000L) {
slouken@2263
   556
            ++srcy;
slouken@2263
   557
            posy -= 0x10000L;
slouken@2263
   558
        }
slouken@2263
   559
        while (n--) {
slouken@2263
   560
            if (posx >= 0x10000L) {
slouken@2263
   561
                while (posx >= 0x10000L) {
slouken@2263
   562
                    ++srcx;
slouken@2263
   563
                    posx -= 0x10000L;
slouken@2263
   564
                }
slouken@2263
   565
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2263
   566
            }
slouken@2263
   567
            srcpixel = *src;
slouken@2263
   568
            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
slouken@2263
   569
            dstpixel = *dst;
slouken@2263
   570
            dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
slouken@2263
   571
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2263
   572
                /* This goes away if we ever use premultiplied alpha */
slouken@2263
   573
                if (srcA < 255) {
slouken@2263
   574
                    srcR = (srcR * srcA) / 255;
slouken@2263
   575
                    srcG = (srcG * srcA) / 255;
slouken@2263
   576
                    srcB = (srcB * srcA) / 255;
slouken@2263
   577
                }
slouken@2263
   578
            }
slouken@5184
   579
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2263
   580
            case SDL_COPY_BLEND:
slouken@2263
   581
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2263
   582
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2263
   583
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
   584
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2263
   585
                break;
slouken@2263
   586
            case SDL_COPY_ADD:
slouken@2263
   587
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2263
   588
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2263
   589
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2263
   590
                break;
slouken@5184
   591
            case SDL_COPY_MOD:
slouken@5184
   592
                dstR = (srcR * dstR) / 255;
slouken@5184
   593
                dstG = (srcG * dstG) / 255;
slouken@5184
   594
                dstB = (srcB * dstB) / 255;
slouken@5184
   595
                break;
slouken@2263
   596
            }
slouken@2263
   597
            dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
slouken@2263
   598
            *dst = dstpixel;
slouken@2263
   599
            posx += incx;
slouken@2263
   600
            ++dst;
slouken@2263
   601
        }
slouken@2263
   602
        posy += incy;
slouken@2263
   603
        info->dst += info->dst_pitch;
slouken@2263
   604
    }
slouken@2263
   605
}
slouken@2263
   606
slouken@2263
   607
static void SDL_Blit_RGB888_BGR888_Modulate(SDL_BlitInfo *info)
slouken@2263
   608
{
slouken@2263
   609
    const int flags = info->flags;
slouken@2263
   610
    const Uint32 modulateR = info->r;
slouken@2263
   611
    const Uint32 modulateG = info->g;
slouken@2263
   612
    const Uint32 modulateB = info->b;
slouken@2263
   613
    const Uint32 modulateA = info->a;
slouken@2263
   614
    Uint32 pixel;
slouken@2263
   615
    Uint32 R, G, B, A;
slouken@2263
   616
slouken@2263
   617
    while (info->dst_h--) {
slouken@2263
   618
        Uint32 *src = (Uint32 *)info->src;
slouken@2263
   619
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
   620
        int n = info->dst_w;
slouken@2263
   621
        while (n--) {
slouken@2263
   622
            pixel = *src;
slouken@2263
   623
            R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF;
slouken@2263
   624
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2263
   625
                R = (R * modulateR) / 255;
slouken@2263
   626
                G = (G * modulateG) / 255;
slouken@2263
   627
                B = (B * modulateB) / 255;
slouken@2263
   628
            }
slouken@2263
   629
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2263
   630
                A = (A * modulateA) / 255;
slouken@2263
   631
            }
slouken@2263
   632
            pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
slouken@2263
   633
            *dst = pixel;
slouken@2263
   634
            ++src;
slouken@2263
   635
            ++dst;
slouken@2263
   636
        }
slouken@2263
   637
        info->src += info->src_pitch;
slouken@2263
   638
        info->dst += info->dst_pitch;
slouken@2263
   639
    }
slouken@2263
   640
}
slouken@2263
   641
slouken@2263
   642
static void SDL_Blit_RGB888_BGR888_Modulate_Scale(SDL_BlitInfo *info)
slouken@2263
   643
{
slouken@2263
   644
    const int flags = info->flags;
slouken@2263
   645
    const Uint32 modulateR = info->r;
slouken@2263
   646
    const Uint32 modulateG = info->g;
slouken@2263
   647
    const Uint32 modulateB = info->b;
slouken@2263
   648
    const Uint32 modulateA = info->a;
slouken@2263
   649
    Uint32 pixel;
slouken@2263
   650
    Uint32 R, G, B, A;
slouken@2263
   651
    int srcy, srcx;
slouken@2263
   652
    int posy, posx;
slouken@2263
   653
    int incy, incx;
slouken@2263
   654
slouken@2263
   655
    srcy = 0;
slouken@2263
   656
    posy = 0;
slouken@2263
   657
    incy = (info->src_h << 16) / info->dst_h;
slouken@2263
   658
    incx = (info->src_w << 16) / info->dst_w;
slouken@2263
   659
slouken@2263
   660
    while (info->dst_h--) {
slouken@5426
   661
        Uint32 *src = 0;
slouken@2263
   662
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
   663
        int n = info->dst_w;
slouken@2263
   664
        srcx = -1;
slouken@2263
   665
        posx = 0x10000L;
slouken@2263
   666
        while (posy >= 0x10000L) {
slouken@2263
   667
            ++srcy;
slouken@2263
   668
            posy -= 0x10000L;
slouken@2263
   669
        }
slouken@2263
   670
        while (n--) {
slouken@2263
   671
            if (posx >= 0x10000L) {
slouken@2263
   672
                while (posx >= 0x10000L) {
slouken@2263
   673
                    ++srcx;
slouken@2263
   674
                    posx -= 0x10000L;
slouken@2263
   675
                }
slouken@2263
   676
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2263
   677
            }
slouken@2263
   678
            pixel = *src;
slouken@2263
   679
            R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF;
slouken@2263
   680
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2263
   681
                R = (R * modulateR) / 255;
slouken@2263
   682
                G = (G * modulateG) / 255;
slouken@2263
   683
                B = (B * modulateB) / 255;
slouken@2263
   684
            }
slouken@2263
   685
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2263
   686
                A = (A * modulateA) / 255;
slouken@2263
   687
            }
slouken@2263
   688
            pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
slouken@2263
   689
            *dst = pixel;
slouken@2263
   690
            posx += incx;
slouken@2263
   691
            ++dst;
slouken@2263
   692
        }
slouken@2263
   693
        posy += incy;
slouken@2263
   694
        info->dst += info->dst_pitch;
slouken@2263
   695
    }
slouken@2263
   696
}
slouken@2263
   697
slouken@2263
   698
static void SDL_Blit_RGB888_BGR888_Modulate_Blend(SDL_BlitInfo *info)
slouken@2263
   699
{
slouken@2263
   700
    const int flags = info->flags;
slouken@2263
   701
    const Uint32 modulateR = info->r;
slouken@2263
   702
    const Uint32 modulateG = info->g;
slouken@2263
   703
    const Uint32 modulateB = info->b;
slouken@2263
   704
    const Uint32 modulateA = info->a;
slouken@2263
   705
    Uint32 srcpixel;
slouken@2263
   706
    Uint32 srcR, srcG, srcB, srcA;
slouken@2263
   707
    Uint32 dstpixel;
slouken@2263
   708
    Uint32 dstR, dstG, dstB, dstA;
slouken@2263
   709
slouken@2263
   710
    while (info->dst_h--) {
slouken@2263
   711
        Uint32 *src = (Uint32 *)info->src;
slouken@2263
   712
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
   713
        int n = info->dst_w;
slouken@2263
   714
        while (n--) {
slouken@2263
   715
            srcpixel = *src;
slouken@2263
   716
            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
slouken@2263
   717
            dstpixel = *dst;
slouken@2263
   718
            dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
slouken@2263
   719
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2263
   720
                srcR = (srcR * modulateR) / 255;
slouken@2263
   721
                srcG = (srcG * modulateG) / 255;
slouken@2263
   722
                srcB = (srcB * modulateB) / 255;
slouken@2263
   723
            }
slouken@2263
   724
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2263
   725
                srcA = (srcA * modulateA) / 255;
slouken@2263
   726
            }
slouken@2263
   727
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2263
   728
                /* This goes away if we ever use premultiplied alpha */
slouken@2263
   729
                if (srcA < 255) {
slouken@2263
   730
                    srcR = (srcR * srcA) / 255;
slouken@2263
   731
                    srcG = (srcG * srcA) / 255;
slouken@2263
   732
                    srcB = (srcB * srcA) / 255;
slouken@2263
   733
                }
slouken@2263
   734
            }
slouken@5184
   735
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2263
   736
            case SDL_COPY_BLEND:
slouken@2263
   737
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2263
   738
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2263
   739
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
   740
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2263
   741
                break;
slouken@2263
   742
            case SDL_COPY_ADD:
slouken@2263
   743
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2263
   744
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2263
   745
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2263
   746
                break;
slouken@5184
   747
            case SDL_COPY_MOD:
slouken@5184
   748
                dstR = (srcR * dstR) / 255;
slouken@5184
   749
                dstG = (srcG * dstG) / 255;
slouken@5184
   750
                dstB = (srcB * dstB) / 255;
slouken@5184
   751
                break;
slouken@2263
   752
            }
slouken@2263
   753
            dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
slouken@2263
   754
            *dst = dstpixel;
slouken@2263
   755
            ++src;
slouken@2263
   756
            ++dst;
slouken@2263
   757
        }
slouken@2263
   758
        info->src += info->src_pitch;
slouken@2263
   759
        info->dst += info->dst_pitch;
slouken@2263
   760
    }
slouken@2263
   761
}
slouken@2263
   762
slouken@2263
   763
static void SDL_Blit_RGB888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info)
slouken@2263
   764
{
slouken@2263
   765
    const int flags = info->flags;
slouken@2263
   766
    const Uint32 modulateR = info->r;
slouken@2263
   767
    const Uint32 modulateG = info->g;
slouken@2263
   768
    const Uint32 modulateB = info->b;
slouken@2263
   769
    const Uint32 modulateA = info->a;
slouken@2263
   770
    Uint32 srcpixel;
slouken@2263
   771
    Uint32 srcR, srcG, srcB, srcA;
slouken@2263
   772
    Uint32 dstpixel;
slouken@2263
   773
    Uint32 dstR, dstG, dstB, dstA;
slouken@2263
   774
    int srcy, srcx;
slouken@2263
   775
    int posy, posx;
slouken@2263
   776
    int incy, incx;
slouken@2263
   777
slouken@2263
   778
    srcy = 0;
slouken@2263
   779
    posy = 0;
slouken@2263
   780
    incy = (info->src_h << 16) / info->dst_h;
slouken@2263
   781
    incx = (info->src_w << 16) / info->dst_w;
slouken@2263
   782
slouken@2263
   783
    while (info->dst_h--) {
slouken@5426
   784
        Uint32 *src = 0;
slouken@2263
   785
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
   786
        int n = info->dst_w;
slouken@2263
   787
        srcx = -1;
slouken@2263
   788
        posx = 0x10000L;
slouken@2263
   789
        while (posy >= 0x10000L) {
slouken@2263
   790
            ++srcy;
slouken@2263
   791
            posy -= 0x10000L;
slouken@2263
   792
        }
slouken@2263
   793
        while (n--) {
slouken@2263
   794
            if (posx >= 0x10000L) {
slouken@2263
   795
                while (posx >= 0x10000L) {
slouken@2263
   796
                    ++srcx;
slouken@2263
   797
                    posx -= 0x10000L;
slouken@2263
   798
                }
slouken@2263
   799
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2263
   800
            }
slouken@2263
   801
            srcpixel = *src;
slouken@2263
   802
            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
slouken@2263
   803
            dstpixel = *dst;
slouken@2263
   804
            dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
slouken@2263
   805
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2263
   806
                srcR = (srcR * modulateR) / 255;
slouken@2263
   807
                srcG = (srcG * modulateG) / 255;
slouken@2263
   808
                srcB = (srcB * modulateB) / 255;
slouken@2263
   809
            }
slouken@2263
   810
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2263
   811
                srcA = (srcA * modulateA) / 255;
slouken@2263
   812
            }
slouken@2263
   813
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2263
   814
                /* This goes away if we ever use premultiplied alpha */
slouken@2263
   815
                if (srcA < 255) {
slouken@2263
   816
                    srcR = (srcR * srcA) / 255;
slouken@2263
   817
                    srcG = (srcG * srcA) / 255;
slouken@2263
   818
                    srcB = (srcB * srcA) / 255;
slouken@2263
   819
                }
slouken@2263
   820
            }
slouken@5184
   821
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2263
   822
            case SDL_COPY_BLEND:
slouken@2263
   823
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2263
   824
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2263
   825
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
   826
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2263
   827
                break;
slouken@2263
   828
            case SDL_COPY_ADD:
slouken@2263
   829
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2263
   830
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2263
   831
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2263
   832
                break;
slouken@5184
   833
            case SDL_COPY_MOD:
slouken@5184
   834
                dstR = (srcR * dstR) / 255;
slouken@5184
   835
                dstG = (srcG * dstG) / 255;
slouken@5184
   836
                dstB = (srcB * dstB) / 255;
slouken@5184
   837
                break;
slouken@2263
   838
            }
slouken@2263
   839
            dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
slouken@2263
   840
            *dst = dstpixel;
slouken@2263
   841
            posx += incx;
slouken@2263
   842
            ++dst;
slouken@2263
   843
        }
slouken@2263
   844
        posy += incy;
slouken@2263
   845
        info->dst += info->dst_pitch;
slouken@2263
   846
    }
slouken@2263
   847
}
slouken@2263
   848
slouken@2800
   849
static void SDL_Blit_RGB888_ARGB8888_Scale(SDL_BlitInfo *info)
slouken@2263
   850
{
slouken@2263
   851
    Uint32 pixel;
slouken@2263
   852
    Uint32 R, G, B, A;
slouken@2263
   853
    int srcy, srcx;
slouken@2263
   854
    int posy, posx;
slouken@2263
   855
    int incy, incx;
slouken@2263
   856
slouken@2263
   857
    srcy = 0;
slouken@2263
   858
    posy = 0;
slouken@2263
   859
    incy = (info->src_h << 16) / info->dst_h;
slouken@2263
   860
    incx = (info->src_w << 16) / info->dst_w;
slouken@2263
   861
slouken@2263
   862
    while (info->dst_h--) {
slouken@5426
   863
        Uint32 *src = 0;
slouken@2263
   864
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
   865
        int n = info->dst_w;
slouken@2263
   866
        srcx = -1;
slouken@2263
   867
        posx = 0x10000L;
slouken@2263
   868
        while (posy >= 0x10000L) {
slouken@2263
   869
            ++srcy;
slouken@2263
   870
            posy -= 0x10000L;
slouken@2263
   871
        }
slouken@2263
   872
        while (n--) {
slouken@2263
   873
            if (posx >= 0x10000L) {
slouken@2263
   874
                while (posx >= 0x10000L) {
slouken@2263
   875
                    ++srcx;
slouken@2263
   876
                    posx -= 0x10000L;
slouken@2263
   877
                }
slouken@2263
   878
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2263
   879
            }
slouken@2263
   880
            pixel = *src;
slouken@2800
   881
            R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF;
slouken@2800
   882
            pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
slouken@2263
   883
            *dst = pixel;
slouken@2263
   884
            posx += incx;
slouken@2263
   885
            ++dst;
slouken@2263
   886
        }
slouken@2263
   887
        posy += incy;
slouken@2263
   888
        info->dst += info->dst_pitch;
slouken@2263
   889
    }
slouken@2263
   890
}
slouken@2263
   891
slouken@2800
   892
static void SDL_Blit_RGB888_ARGB8888_Blend(SDL_BlitInfo *info)
slouken@2263
   893
{
slouken@2263
   894
    const int flags = info->flags;
slouken@2263
   895
    Uint32 srcpixel;
slouken@2263
   896
    Uint32 srcR, srcG, srcB, srcA;
slouken@2263
   897
    Uint32 dstpixel;
slouken@2263
   898
    Uint32 dstR, dstG, dstB, dstA;
slouken@2263
   899
slouken@2263
   900
    while (info->dst_h--) {
slouken@2263
   901
        Uint32 *src = (Uint32 *)info->src;
slouken@2263
   902
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
   903
        int n = info->dst_w;
slouken@2263
   904
        while (n--) {
slouken@2263
   905
            srcpixel = *src;
slouken@2800
   906
            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
slouken@2263
   907
            dstpixel = *dst;
slouken@2800
   908
            dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
slouken@2263
   909
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2263
   910
                /* This goes away if we ever use premultiplied alpha */
slouken@2263
   911
                if (srcA < 255) {
slouken@2263
   912
                    srcR = (srcR * srcA) / 255;
slouken@2263
   913
                    srcG = (srcG * srcA) / 255;
slouken@2263
   914
                    srcB = (srcB * srcA) / 255;
slouken@2263
   915
                }
slouken@2263
   916
            }
slouken@5184
   917
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2263
   918
            case SDL_COPY_BLEND:
slouken@2263
   919
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2263
   920
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2263
   921
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
   922
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2263
   923
                break;
slouken@2263
   924
            case SDL_COPY_ADD:
slouken@2263
   925
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2263
   926
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2263
   927
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2263
   928
                break;
slouken@5184
   929
            case SDL_COPY_MOD:
slouken@5184
   930
                dstR = (srcR * dstR) / 255;
slouken@5184
   931
                dstG = (srcG * dstG) / 255;
slouken@5184
   932
                dstB = (srcB * dstB) / 255;
slouken@5184
   933
                break;
slouken@2263
   934
            }
slouken@2800
   935
            dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
slouken@2263
   936
            *dst = dstpixel;
slouken@2263
   937
            ++src;
slouken@2263
   938
            ++dst;
slouken@2263
   939
        }
slouken@2263
   940
        info->src += info->src_pitch;
slouken@2263
   941
        info->dst += info->dst_pitch;
slouken@2263
   942
    }
slouken@2263
   943
}
slouken@2263
   944
slouken@2800
   945
static void SDL_Blit_RGB888_ARGB8888_Blend_Scale(SDL_BlitInfo *info)
slouken@2263
   946
{
slouken@2263
   947
    const int flags = info->flags;
slouken@2263
   948
    Uint32 srcpixel;
slouken@2263
   949
    Uint32 srcR, srcG, srcB, srcA;
slouken@2263
   950
    Uint32 dstpixel;
slouken@2263
   951
    Uint32 dstR, dstG, dstB, dstA;
slouken@2263
   952
    int srcy, srcx;
slouken@2263
   953
    int posy, posx;
slouken@2263
   954
    int incy, incx;
slouken@2263
   955
slouken@2263
   956
    srcy = 0;
slouken@2263
   957
    posy = 0;
slouken@2263
   958
    incy = (info->src_h << 16) / info->dst_h;
slouken@2263
   959
    incx = (info->src_w << 16) / info->dst_w;
slouken@2263
   960
slouken@2263
   961
    while (info->dst_h--) {
slouken@5426
   962
        Uint32 *src = 0;
slouken@2263
   963
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
   964
        int n = info->dst_w;
slouken@2263
   965
        srcx = -1;
slouken@2263
   966
        posx = 0x10000L;
slouken@2263
   967
        while (posy >= 0x10000L) {
slouken@2263
   968
            ++srcy;
slouken@2263
   969
            posy -= 0x10000L;
slouken@2263
   970
        }
slouken@2263
   971
        while (n--) {
slouken@2263
   972
            if (posx >= 0x10000L) {
slouken@2263
   973
                while (posx >= 0x10000L) {
slouken@2263
   974
                    ++srcx;
slouken@2263
   975
                    posx -= 0x10000L;
slouken@2263
   976
                }
slouken@2263
   977
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2263
   978
            }
slouken@2263
   979
            srcpixel = *src;
slouken@2800
   980
            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
slouken@2263
   981
            dstpixel = *dst;
slouken@2800
   982
            dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
slouken@2263
   983
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2263
   984
                /* This goes away if we ever use premultiplied alpha */
slouken@2263
   985
                if (srcA < 255) {
slouken@2263
   986
                    srcR = (srcR * srcA) / 255;
slouken@2263
   987
                    srcG = (srcG * srcA) / 255;
slouken@2263
   988
                    srcB = (srcB * srcA) / 255;
slouken@2263
   989
                }
slouken@2263
   990
            }
slouken@5184
   991
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2263
   992
            case SDL_COPY_BLEND:
slouken@2263
   993
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2263
   994
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2263
   995
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
   996
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2263
   997
                break;
slouken@2263
   998
            case SDL_COPY_ADD:
slouken@2263
   999
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2263
  1000
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2263
  1001
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2263
  1002
                break;
slouken@5184
  1003
            case SDL_COPY_MOD:
slouken@5184
  1004
                dstR = (srcR * dstR) / 255;
slouken@5184
  1005
                dstG = (srcG * dstG) / 255;
slouken@5184
  1006
                dstB = (srcB * dstB) / 255;
slouken@5184
  1007
                break;
slouken@2263
  1008
            }
slouken@2800
  1009
            dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
slouken@2263
  1010
            *dst = dstpixel;
slouken@2263
  1011
            posx += incx;
slouken@2263
  1012
            ++dst;
slouken@2263
  1013
        }
slouken@2263
  1014
        posy += incy;
slouken@2263
  1015
        info->dst += info->dst_pitch;
slouken@2263
  1016
    }
slouken@2263
  1017
}
slouken@2263
  1018
slouken@2800
  1019
static void SDL_Blit_RGB888_ARGB8888_Modulate(SDL_BlitInfo *info)
slouken@2263
  1020
{
slouken@2263
  1021
    const int flags = info->flags;
slouken@2263
  1022
    const Uint32 modulateR = info->r;
slouken@2263
  1023
    const Uint32 modulateG = info->g;
slouken@2263
  1024
    const Uint32 modulateB = info->b;
slouken@2263
  1025
    const Uint32 modulateA = info->a;
slouken@2263
  1026
    Uint32 pixel;
slouken@2263
  1027
    Uint32 R, G, B, A;
slouken@2263
  1028
slouken@2263
  1029
    while (info->dst_h--) {
slouken@2263
  1030
        Uint32 *src = (Uint32 *)info->src;
slouken@2263
  1031
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
  1032
        int n = info->dst_w;
slouken@2263
  1033
        while (n--) {
slouken@2263
  1034
            pixel = *src;
slouken@2800
  1035
            R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF;
slouken@2263
  1036
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2263
  1037
                R = (R * modulateR) / 255;
slouken@2263
  1038
                G = (G * modulateG) / 255;
slouken@2263
  1039
                B = (B * modulateB) / 255;
slouken@2263
  1040
            }
slouken@2263
  1041
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2263
  1042
                A = (A * modulateA) / 255;
slouken@2263
  1043
            }
slouken@2800
  1044
            pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
slouken@2263
  1045
            *dst = pixel;
slouken@2263
  1046
            ++src;
slouken@2263
  1047
            ++dst;
slouken@2263
  1048
        }
slouken@2263
  1049
        info->src += info->src_pitch;
slouken@2263
  1050
        info->dst += info->dst_pitch;
slouken@2263
  1051
    }
slouken@2263
  1052
}
slouken@2263
  1053
slouken@2800
  1054
static void SDL_Blit_RGB888_ARGB8888_Modulate_Scale(SDL_BlitInfo *info)
slouken@2263
  1055
{
slouken@2263
  1056
    const int flags = info->flags;
slouken@2263
  1057
    const Uint32 modulateR = info->r;
slouken@2263
  1058
    const Uint32 modulateG = info->g;
slouken@2263
  1059
    const Uint32 modulateB = info->b;
slouken@2263
  1060
    const Uint32 modulateA = info->a;
slouken@2263
  1061
    Uint32 pixel;
slouken@2263
  1062
    Uint32 R, G, B, A;
slouken@2263
  1063
    int srcy, srcx;
slouken@2263
  1064
    int posy, posx;
slouken@2263
  1065
    int incy, incx;
slouken@2263
  1066
slouken@2263
  1067
    srcy = 0;
slouken@2263
  1068
    posy = 0;
slouken@2263
  1069
    incy = (info->src_h << 16) / info->dst_h;
slouken@2263
  1070
    incx = (info->src_w << 16) / info->dst_w;
slouken@2263
  1071
slouken@2263
  1072
    while (info->dst_h--) {
slouken@5426
  1073
        Uint32 *src = 0;
slouken@2263
  1074
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
  1075
        int n = info->dst_w;
slouken@2263
  1076
        srcx = -1;
slouken@2263
  1077
        posx = 0x10000L;
slouken@2263
  1078
        while (posy >= 0x10000L) {
slouken@2263
  1079
            ++srcy;
slouken@2263
  1080
            posy -= 0x10000L;
slouken@2263
  1081
        }
slouken@2263
  1082
        while (n--) {
slouken@2263
  1083
            if (posx >= 0x10000L) {
slouken@2263
  1084
                while (posx >= 0x10000L) {
slouken@2263
  1085
                    ++srcx;
slouken@2263
  1086
                    posx -= 0x10000L;
slouken@2263
  1087
                }
slouken@2263
  1088
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2263
  1089
            }
slouken@2263
  1090
            pixel = *src;
slouken@2800
  1091
            R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF;
slouken@2263
  1092
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2263
  1093
                R = (R * modulateR) / 255;
slouken@2263
  1094
                G = (G * modulateG) / 255;
slouken@2263
  1095
                B = (B * modulateB) / 255;
slouken@2263
  1096
            }
slouken@2263
  1097
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2263
  1098
                A = (A * modulateA) / 255;
slouken@2263
  1099
            }
slouken@2800
  1100
            pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
slouken@2263
  1101
            *dst = pixel;
slouken@2263
  1102
            posx += incx;
slouken@2263
  1103
            ++dst;
slouken@2263
  1104
        }
slouken@2263
  1105
        posy += incy;
slouken@2263
  1106
        info->dst += info->dst_pitch;
slouken@2263
  1107
    }
slouken@2263
  1108
}
slouken@2263
  1109
slouken@2800
  1110
static void SDL_Blit_RGB888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info)
slouken@2263
  1111
{
slouken@2263
  1112
    const int flags = info->flags;
slouken@2263
  1113
    const Uint32 modulateR = info->r;
slouken@2263
  1114
    const Uint32 modulateG = info->g;
slouken@2263
  1115
    const Uint32 modulateB = info->b;
slouken@2263
  1116
    const Uint32 modulateA = info->a;
slouken@2263
  1117
    Uint32 srcpixel;
slouken@2263
  1118
    Uint32 srcR, srcG, srcB, srcA;
slouken@2263
  1119
    Uint32 dstpixel;
slouken@2263
  1120
    Uint32 dstR, dstG, dstB, dstA;
slouken@2263
  1121
slouken@2263
  1122
    while (info->dst_h--) {
slouken@2263
  1123
        Uint32 *src = (Uint32 *)info->src;
slouken@2263
  1124
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
  1125
        int n = info->dst_w;
slouken@2263
  1126
        while (n--) {
slouken@2263
  1127
            srcpixel = *src;
slouken@2800
  1128
            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
slouken@2263
  1129
            dstpixel = *dst;
slouken@2800
  1130
            dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
slouken@2263
  1131
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2263
  1132
                srcR = (srcR * modulateR) / 255;
slouken@2263
  1133
                srcG = (srcG * modulateG) / 255;
slouken@2263
  1134
                srcB = (srcB * modulateB) / 255;
slouken@2263
  1135
            }
slouken@2263
  1136
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2263
  1137
                srcA = (srcA * modulateA) / 255;
slouken@2263
  1138
            }
slouken@2263
  1139
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2263
  1140
                /* This goes away if we ever use premultiplied alpha */
slouken@2263
  1141
                if (srcA < 255) {
slouken@2263
  1142
                    srcR = (srcR * srcA) / 255;
slouken@2263
  1143
                    srcG = (srcG * srcA) / 255;
slouken@2263
  1144
                    srcB = (srcB * srcA) / 255;
slouken@2263
  1145
                }
slouken@2263
  1146
            }
slouken@5184
  1147
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2263
  1148
            case SDL_COPY_BLEND:
slouken@2263
  1149
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2263
  1150
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2263
  1151
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
  1152
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2263
  1153
                break;
slouken@2263
  1154
            case SDL_COPY_ADD:
slouken@2263
  1155
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2263
  1156
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2263
  1157
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2263
  1158
                break;
slouken@5184
  1159
            case SDL_COPY_MOD:
slouken@5184
  1160
                dstR = (srcR * dstR) / 255;
slouken@5184
  1161
                dstG = (srcG * dstG) / 255;
slouken@5184
  1162
                dstB = (srcB * dstB) / 255;
slouken@5184
  1163
                break;
slouken@2263
  1164
            }
slouken@2800
  1165
            dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
slouken@2263
  1166
            *dst = dstpixel;
slouken@2263
  1167
            ++src;
slouken@2263
  1168
            ++dst;
slouken@2263
  1169
        }
slouken@2263
  1170
        info->src += info->src_pitch;
slouken@2263
  1171
        info->dst += info->dst_pitch;
slouken@2263
  1172
    }
slouken@2263
  1173
}
slouken@2263
  1174
slouken@2800
  1175
static void SDL_Blit_RGB888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info)
slouken@2263
  1176
{
slouken@2263
  1177
    const int flags = info->flags;
slouken@2263
  1178
    const Uint32 modulateR = info->r;
slouken@2263
  1179
    const Uint32 modulateG = info->g;
slouken@2263
  1180
    const Uint32 modulateB = info->b;
slouken@2263
  1181
    const Uint32 modulateA = info->a;
slouken@2263
  1182
    Uint32 srcpixel;
slouken@2263
  1183
    Uint32 srcR, srcG, srcB, srcA;
slouken@2263
  1184
    Uint32 dstpixel;
slouken@2263
  1185
    Uint32 dstR, dstG, dstB, dstA;
slouken@2263
  1186
    int srcy, srcx;
slouken@2263
  1187
    int posy, posx;
slouken@2263
  1188
    int incy, incx;
slouken@2263
  1189
slouken@2263
  1190
    srcy = 0;
slouken@2263
  1191
    posy = 0;
slouken@2263
  1192
    incy = (info->src_h << 16) / info->dst_h;
slouken@2263
  1193
    incx = (info->src_w << 16) / info->dst_w;
slouken@2263
  1194
slouken@2263
  1195
    while (info->dst_h--) {
slouken@5426
  1196
        Uint32 *src = 0;
slouken@2263
  1197
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
  1198
        int n = info->dst_w;
slouken@2263
  1199
        srcx = -1;
slouken@2263
  1200
        posx = 0x10000L;
slouken@2263
  1201
        while (posy >= 0x10000L) {
slouken@2263
  1202
            ++srcy;
slouken@2263
  1203
            posy -= 0x10000L;
slouken@2263
  1204
        }
slouken@2263
  1205
        while (n--) {
slouken@2263
  1206
            if (posx >= 0x10000L) {
slouken@2263
  1207
                while (posx >= 0x10000L) {
slouken@2263
  1208
                    ++srcx;
slouken@2263
  1209
                    posx -= 0x10000L;
slouken@2263
  1210
                }
slouken@2263
  1211
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2263
  1212
            }
slouken@2263
  1213
            srcpixel = *src;
slouken@2800
  1214
            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
slouken@2263
  1215
            dstpixel = *dst;
slouken@2800
  1216
            dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
slouken@2263
  1217
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2263
  1218
                srcR = (srcR * modulateR) / 255;
slouken@2263
  1219
                srcG = (srcG * modulateG) / 255;
slouken@2263
  1220
                srcB = (srcB * modulateB) / 255;
slouken@2263
  1221
            }
slouken@2263
  1222
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2263
  1223
                srcA = (srcA * modulateA) / 255;
slouken@2263
  1224
            }
slouken@2263
  1225
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2263
  1226
                /* This goes away if we ever use premultiplied alpha */
slouken@2263
  1227
                if (srcA < 255) {
slouken@2263
  1228
                    srcR = (srcR * srcA) / 255;
slouken@2263
  1229
                    srcG = (srcG * srcA) / 255;
slouken@2263
  1230
                    srcB = (srcB * srcA) / 255;
slouken@2263
  1231
                }
slouken@2263
  1232
            }
slouken@5184
  1233
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2263
  1234
            case SDL_COPY_BLEND:
slouken@2263
  1235
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2263
  1236
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2263
  1237
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
  1238
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2263
  1239
                break;
slouken@2263
  1240
            case SDL_COPY_ADD:
slouken@2263
  1241
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2263
  1242
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2263
  1243
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2263
  1244
                break;
slouken@5184
  1245
            case SDL_COPY_MOD:
slouken@5184
  1246
                dstR = (srcR * dstR) / 255;
slouken@5184
  1247
                dstG = (srcG * dstG) / 255;
slouken@5184
  1248
                dstB = (srcB * dstB) / 255;
slouken@5184
  1249
                break;
slouken@2263
  1250
            }
slouken@2800
  1251
            dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
slouken@2263
  1252
            *dst = dstpixel;
slouken@2263
  1253
            posx += incx;
slouken@2263
  1254
            ++dst;
slouken@2263
  1255
        }
slouken@2263
  1256
        posy += incy;
slouken@2263
  1257
        info->dst += info->dst_pitch;
slouken@2263
  1258
    }
slouken@2263
  1259
}
slouken@2263
  1260
slouken@2800
  1261
static void SDL_Blit_BGR888_RGB888_Scale(SDL_BlitInfo *info)
slouken@2800
  1262
{
slouken@2800
  1263
    Uint32 pixel;
slouken@2800
  1264
    Uint32 R, G, B, A;
slouken@2263
  1265
    int srcy, srcx;
slouken@2263
  1266
    int posy, posx;
slouken@2263
  1267
    int incy, incx;
slouken@2263
  1268
slouken@2263
  1269
    srcy = 0;
slouken@2263
  1270
    posy = 0;
slouken@2263
  1271
    incy = (info->src_h << 16) / info->dst_h;
slouken@2263
  1272
    incx = (info->src_w << 16) / info->dst_w;
slouken@2263
  1273
slouken@2263
  1274
    while (info->dst_h--) {
slouken@5426
  1275
        Uint32 *src = 0;
slouken@2263
  1276
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
  1277
        int n = info->dst_w;
slouken@2263
  1278
        srcx = -1;
slouken@2263
  1279
        posx = 0x10000L;
slouken@2263
  1280
        while (posy >= 0x10000L) {
slouken@2263
  1281
            ++srcy;
slouken@2263
  1282
            posy -= 0x10000L;
slouken@2263
  1283
        }
slouken@2263
  1284
        while (n--) {
slouken@2263
  1285
            if (posx >= 0x10000L) {
slouken@2263
  1286
                while (posx >= 0x10000L) {
slouken@2263
  1287
                    ++srcx;
slouken@2263
  1288
                    posx -= 0x10000L;
slouken@2263
  1289
                }
slouken@2263
  1290
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2263
  1291
            }
slouken@2800
  1292
            pixel = *src;
slouken@2800
  1293
            B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF;
slouken@2800
  1294
            pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
slouken@2800
  1295
            *dst = pixel;
slouken@2263
  1296
            posx += incx;
slouken@2263
  1297
            ++dst;
slouken@2263
  1298
        }
slouken@2263
  1299
        posy += incy;
slouken@2263
  1300
        info->dst += info->dst_pitch;
slouken@2263
  1301
    }
slouken@2263
  1302
}
slouken@2263
  1303
slouken@2800
  1304
static void SDL_Blit_BGR888_RGB888_Blend(SDL_BlitInfo *info)
slouken@2263
  1305
{
slouken@2263
  1306
    const int flags = info->flags;
slouken@2263
  1307
    Uint32 srcpixel;
slouken@2263
  1308
    Uint32 srcR, srcG, srcB, srcA;
slouken@2263
  1309
    Uint32 dstpixel;
slouken@2263
  1310
    Uint32 dstR, dstG, dstB, dstA;
slouken@2263
  1311
slouken@2263
  1312
    while (info->dst_h--) {
slouken@2263
  1313
        Uint32 *src = (Uint32 *)info->src;
slouken@2263
  1314
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
  1315
        int n = info->dst_w;
slouken@2263
  1316
        while (n--) {
slouken@2263
  1317
            srcpixel = *src;
slouken@2263
  1318
            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
slouken@2263
  1319
            dstpixel = *dst;
slouken@2800
  1320
            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
slouken@2263
  1321
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2263
  1322
                /* This goes away if we ever use premultiplied alpha */
slouken@2263
  1323
                if (srcA < 255) {
slouken@2263
  1324
                    srcR = (srcR * srcA) / 255;
slouken@2263
  1325
                    srcG = (srcG * srcA) / 255;
slouken@2263
  1326
                    srcB = (srcB * srcA) / 255;
slouken@2263
  1327
                }
slouken@2263
  1328
            }
slouken@5184
  1329
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2263
  1330
            case SDL_COPY_BLEND:
slouken@2263
  1331
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2263
  1332
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2263
  1333
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
  1334
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2263
  1335
                break;
slouken@2263
  1336
            case SDL_COPY_ADD:
slouken@2263
  1337
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2263
  1338
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2263
  1339
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2263
  1340
                break;
slouken@5184
  1341
            case SDL_COPY_MOD:
slouken@5184
  1342
                dstR = (srcR * dstR) / 255;
slouken@5184
  1343
                dstG = (srcG * dstG) / 255;
slouken@5184
  1344
                dstB = (srcB * dstB) / 255;
slouken@5184
  1345
                break;
slouken@2263
  1346
            }
slouken@2800
  1347
            dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
slouken@2263
  1348
            *dst = dstpixel;
slouken@2263
  1349
            ++src;
slouken@2263
  1350
            ++dst;
slouken@2263
  1351
        }
slouken@2263
  1352
        info->src += info->src_pitch;
slouken@2263
  1353
        info->dst += info->dst_pitch;
slouken@2263
  1354
    }
slouken@2263
  1355
}
slouken@2263
  1356
slouken@2800
  1357
static void SDL_Blit_BGR888_RGB888_Blend_Scale(SDL_BlitInfo *info)
slouken@2263
  1358
{
slouken@2263
  1359
    const int flags = info->flags;
slouken@2263
  1360
    Uint32 srcpixel;
slouken@2263
  1361
    Uint32 srcR, srcG, srcB, srcA;
slouken@2263
  1362
    Uint32 dstpixel;
slouken@2263
  1363
    Uint32 dstR, dstG, dstB, dstA;
slouken@2263
  1364
    int srcy, srcx;
slouken@2263
  1365
    int posy, posx;
slouken@2263
  1366
    int incy, incx;
slouken@2263
  1367
slouken@2263
  1368
    srcy = 0;
slouken@2263
  1369
    posy = 0;
slouken@2263
  1370
    incy = (info->src_h << 16) / info->dst_h;
slouken@2263
  1371
    incx = (info->src_w << 16) / info->dst_w;
slouken@2263
  1372
slouken@2263
  1373
    while (info->dst_h--) {
slouken@5426
  1374
        Uint32 *src = 0;
slouken@2263
  1375
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
  1376
        int n = info->dst_w;
slouken@2263
  1377
        srcx = -1;
slouken@2263
  1378
        posx = 0x10000L;
slouken@2263
  1379
        while (posy >= 0x10000L) {
slouken@2263
  1380
            ++srcy;
slouken@2263
  1381
            posy -= 0x10000L;
slouken@2263
  1382
        }
slouken@2263
  1383
        while (n--) {
slouken@2263
  1384
            if (posx >= 0x10000L) {
slouken@2263
  1385
                while (posx >= 0x10000L) {
slouken@2263
  1386
                    ++srcx;
slouken@2263
  1387
                    posx -= 0x10000L;
slouken@2263
  1388
                }
slouken@2263
  1389
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2263
  1390
            }
slouken@2263
  1391
            srcpixel = *src;
slouken@2263
  1392
            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
slouken@2263
  1393
            dstpixel = *dst;
slouken@2800
  1394
            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
slouken@2263
  1395
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2263
  1396
                /* This goes away if we ever use premultiplied alpha */
slouken@2263
  1397
                if (srcA < 255) {
slouken@2263
  1398
                    srcR = (srcR * srcA) / 255;
slouken@2263
  1399
                    srcG = (srcG * srcA) / 255;
slouken@2263
  1400
                    srcB = (srcB * srcA) / 255;
slouken@2263
  1401
                }
slouken@2263
  1402
            }
slouken@5184
  1403
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2263
  1404
            case SDL_COPY_BLEND:
slouken@2263
  1405
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2263
  1406
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2263
  1407
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
  1408
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2263
  1409
                break;
slouken@2263
  1410
            case SDL_COPY_ADD:
slouken@2263
  1411
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2263
  1412
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2263
  1413
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2263
  1414
                break;
slouken@5184
  1415
            case SDL_COPY_MOD:
slouken@5184
  1416
                dstR = (srcR * dstR) / 255;
slouken@5184
  1417
                dstG = (srcG * dstG) / 255;
slouken@5184
  1418
                dstB = (srcB * dstB) / 255;
slouken@5184
  1419
                break;
slouken@2263
  1420
            }
slouken@2800
  1421
            dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
slouken@2263
  1422
            *dst = dstpixel;
slouken@2263
  1423
            posx += incx;
slouken@2263
  1424
            ++dst;
slouken@2263
  1425
        }
slouken@2263
  1426
        posy += incy;
slouken@2263
  1427
        info->dst += info->dst_pitch;
slouken@2263
  1428
    }
slouken@2263
  1429
}
slouken@2263
  1430
slouken@2800
  1431
static void SDL_Blit_BGR888_RGB888_Modulate(SDL_BlitInfo *info)
slouken@2263
  1432
{
slouken@2263
  1433
    const int flags = info->flags;
slouken@2263
  1434
    const Uint32 modulateR = info->r;
slouken@2263
  1435
    const Uint32 modulateG = info->g;
slouken@2263
  1436
    const Uint32 modulateB = info->b;
slouken@2263
  1437
    const Uint32 modulateA = info->a;
slouken@2263
  1438
    Uint32 pixel;
slouken@2263
  1439
    Uint32 R, G, B, A;
slouken@2263
  1440
slouken@2263
  1441
    while (info->dst_h--) {
slouken@2263
  1442
        Uint32 *src = (Uint32 *)info->src;
slouken@2263
  1443
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
  1444
        int n = info->dst_w;
slouken@2263
  1445
        while (n--) {
slouken@2263
  1446
            pixel = *src;
slouken@2263
  1447
            B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF;
slouken@2263
  1448
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2263
  1449
                R = (R * modulateR) / 255;
slouken@2263
  1450
                G = (G * modulateG) / 255;
slouken@2263
  1451
                B = (B * modulateB) / 255;
slouken@2263
  1452
            }
slouken@2263
  1453
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2263
  1454
                A = (A * modulateA) / 255;
slouken@2263
  1455
            }
slouken@2800
  1456
            pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
slouken@2263
  1457
            *dst = pixel;
slouken@2263
  1458
            ++src;
slouken@2263
  1459
            ++dst;
slouken@2263
  1460
        }
slouken@2263
  1461
        info->src += info->src_pitch;
slouken@2263
  1462
        info->dst += info->dst_pitch;
slouken@2263
  1463
    }
slouken@2263
  1464
}
slouken@2263
  1465
slouken@2800
  1466
static void SDL_Blit_BGR888_RGB888_Modulate_Scale(SDL_BlitInfo *info)
slouken@2263
  1467
{
slouken@2263
  1468
    const int flags = info->flags;
slouken@2263
  1469
    const Uint32 modulateR = info->r;
slouken@2263
  1470
    const Uint32 modulateG = info->g;
slouken@2263
  1471
    const Uint32 modulateB = info->b;
slouken@2263
  1472
    const Uint32 modulateA = info->a;
slouken@2263
  1473
    Uint32 pixel;
slouken@2263
  1474
    Uint32 R, G, B, A;
slouken@2263
  1475
    int srcy, srcx;
slouken@2263
  1476
    int posy, posx;
slouken@2263
  1477
    int incy, incx;
slouken@2263
  1478
slouken@2263
  1479
    srcy = 0;
slouken@2263
  1480
    posy = 0;
slouken@2263
  1481
    incy = (info->src_h << 16) / info->dst_h;
slouken@2263
  1482
    incx = (info->src_w << 16) / info->dst_w;
slouken@2263
  1483
slouken@2263
  1484
    while (info->dst_h--) {
slouken@5426
  1485
        Uint32 *src = 0;
slouken@2263
  1486
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
  1487
        int n = info->dst_w;
slouken@2263
  1488
        srcx = -1;
slouken@2263
  1489
        posx = 0x10000L;
slouken@2263
  1490
        while (posy >= 0x10000L) {
slouken@2263
  1491
            ++srcy;
slouken@2263
  1492
            posy -= 0x10000L;
slouken@2263
  1493
        }
slouken@2263
  1494
        while (n--) {
slouken@2263
  1495
            if (posx >= 0x10000L) {
slouken@2263
  1496
                while (posx >= 0x10000L) {
slouken@2263
  1497
                    ++srcx;
slouken@2263
  1498
                    posx -= 0x10000L;
slouken@2263
  1499
                }
slouken@2263
  1500
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2263
  1501
            }
slouken@2263
  1502
            pixel = *src;
slouken@2263
  1503
            B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF;
slouken@2263
  1504
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2263
  1505
                R = (R * modulateR) / 255;
slouken@2263
  1506
                G = (G * modulateG) / 255;
slouken@2263
  1507
                B = (B * modulateB) / 255;
slouken@2263
  1508
            }
slouken@2263
  1509
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2263
  1510
                A = (A * modulateA) / 255;
slouken@2263
  1511
            }
slouken@2800
  1512
            pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
slouken@2263
  1513
            *dst = pixel;
slouken@2263
  1514
            posx += incx;
slouken@2263
  1515
            ++dst;
slouken@2263
  1516
        }
slouken@2263
  1517
        posy += incy;
slouken@2263
  1518
        info->dst += info->dst_pitch;
slouken@2263
  1519
    }
slouken@2263
  1520
}
slouken@2263
  1521
slouken@2800
  1522
static void SDL_Blit_BGR888_RGB888_Modulate_Blend(SDL_BlitInfo *info)
slouken@2263
  1523
{
slouken@2263
  1524
    const int flags = info->flags;
slouken@2263
  1525
    const Uint32 modulateR = info->r;
slouken@2263
  1526
    const Uint32 modulateG = info->g;
slouken@2263
  1527
    const Uint32 modulateB = info->b;
slouken@2263
  1528
    const Uint32 modulateA = info->a;
slouken@2263
  1529
    Uint32 srcpixel;
slouken@2263
  1530
    Uint32 srcR, srcG, srcB, srcA;
slouken@2263
  1531
    Uint32 dstpixel;
slouken@2263
  1532
    Uint32 dstR, dstG, dstB, dstA;
slouken@2263
  1533
slouken@2263
  1534
    while (info->dst_h--) {
slouken@2263
  1535
        Uint32 *src = (Uint32 *)info->src;
slouken@2263
  1536
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
  1537
        int n = info->dst_w;
slouken@2263
  1538
        while (n--) {
slouken@2263
  1539
            srcpixel = *src;
slouken@2263
  1540
            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
slouken@2263
  1541
            dstpixel = *dst;
slouken@2800
  1542
            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
slouken@2263
  1543
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2263
  1544
                srcR = (srcR * modulateR) / 255;
slouken@2263
  1545
                srcG = (srcG * modulateG) / 255;
slouken@2263
  1546
                srcB = (srcB * modulateB) / 255;
slouken@2263
  1547
            }
slouken@2263
  1548
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2263
  1549
                srcA = (srcA * modulateA) / 255;
slouken@2263
  1550
            }
slouken@2263
  1551
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2263
  1552
                /* This goes away if we ever use premultiplied alpha */
slouken@2263
  1553
                if (srcA < 255) {
slouken@2263
  1554
                    srcR = (srcR * srcA) / 255;
slouken@2263
  1555
                    srcG = (srcG * srcA) / 255;
slouken@2263
  1556
                    srcB = (srcB * srcA) / 255;
slouken@2263
  1557
                }
slouken@2263
  1558
            }
slouken@5184
  1559
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2263
  1560
            case SDL_COPY_BLEND:
slouken@2263
  1561
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2263
  1562
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2263
  1563
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
  1564
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2263
  1565
                break;
slouken@2263
  1566
            case SDL_COPY_ADD:
slouken@2263
  1567
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2263
  1568
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2263
  1569
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2263
  1570
                break;
slouken@5184
  1571
            case SDL_COPY_MOD:
slouken@5184
  1572
                dstR = (srcR * dstR) / 255;
slouken@5184
  1573
                dstG = (srcG * dstG) / 255;
slouken@5184
  1574
                dstB = (srcB * dstB) / 255;
slouken@5184
  1575
                break;
slouken@2263
  1576
            }
slouken@2800
  1577
            dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
slouken@2263
  1578
            *dst = dstpixel;
slouken@2263
  1579
            ++src;
slouken@2263
  1580
            ++dst;
slouken@2263
  1581
        }
slouken@2263
  1582
        info->src += info->src_pitch;
slouken@2263
  1583
        info->dst += info->dst_pitch;
slouken@2263
  1584
    }
slouken@2263
  1585
}
slouken@2263
  1586
slouken@2800
  1587
static void SDL_Blit_BGR888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info)
slouken@2263
  1588
{
slouken@2263
  1589
    const int flags = info->flags;
slouken@2263
  1590
    const Uint32 modulateR = info->r;
slouken@2263
  1591
    const Uint32 modulateG = info->g;
slouken@2263
  1592
    const Uint32 modulateB = info->b;
slouken@2263
  1593
    const Uint32 modulateA = info->a;
slouken@2263
  1594
    Uint32 srcpixel;
slouken@2263
  1595
    Uint32 srcR, srcG, srcB, srcA;
slouken@2263
  1596
    Uint32 dstpixel;
slouken@2263
  1597
    Uint32 dstR, dstG, dstB, dstA;
slouken@2263
  1598
    int srcy, srcx;
slouken@2263
  1599
    int posy, posx;
slouken@2263
  1600
    int incy, incx;
slouken@2263
  1601
slouken@2263
  1602
    srcy = 0;
slouken@2263
  1603
    posy = 0;
slouken@2263
  1604
    incy = (info->src_h << 16) / info->dst_h;
slouken@2263
  1605
    incx = (info->src_w << 16) / info->dst_w;
slouken@2263
  1606
slouken@2263
  1607
    while (info->dst_h--) {
slouken@5426
  1608
        Uint32 *src = 0;
slouken@2263
  1609
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
  1610
        int n = info->dst_w;
slouken@2263
  1611
        srcx = -1;
slouken@2263
  1612
        posx = 0x10000L;
slouken@2263
  1613
        while (posy >= 0x10000L) {
slouken@2263
  1614
            ++srcy;
slouken@2263
  1615
            posy -= 0x10000L;
slouken@2263
  1616
        }
slouken@2263
  1617
        while (n--) {
slouken@2263
  1618
            if (posx >= 0x10000L) {
slouken@2263
  1619
                while (posx >= 0x10000L) {
slouken@2263
  1620
                    ++srcx;
slouken@2263
  1621
                    posx -= 0x10000L;
slouken@2263
  1622
                }
slouken@2263
  1623
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2263
  1624
            }
slouken@2263
  1625
            srcpixel = *src;
slouken@2263
  1626
            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
slouken@2263
  1627
            dstpixel = *dst;
slouken@2800
  1628
            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
slouken@2263
  1629
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2263
  1630
                srcR = (srcR * modulateR) / 255;
slouken@2263
  1631
                srcG = (srcG * modulateG) / 255;
slouken@2263
  1632
                srcB = (srcB * modulateB) / 255;
slouken@2263
  1633
            }
slouken@2263
  1634
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2263
  1635
                srcA = (srcA * modulateA) / 255;
slouken@2263
  1636
            }
slouken@2263
  1637
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2263
  1638
                /* This goes away if we ever use premultiplied alpha */
slouken@2263
  1639
                if (srcA < 255) {
slouken@2263
  1640
                    srcR = (srcR * srcA) / 255;
slouken@2263
  1641
                    srcG = (srcG * srcA) / 255;
slouken@2263
  1642
                    srcB = (srcB * srcA) / 255;
slouken@2263
  1643
                }
slouken@2263
  1644
            }
slouken@5184
  1645
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2263
  1646
            case SDL_COPY_BLEND:
slouken@2263
  1647
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2263
  1648
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2263
  1649
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
  1650
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2263
  1651
                break;
slouken@2263
  1652
            case SDL_COPY_ADD:
slouken@2263
  1653
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2263
  1654
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2263
  1655
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2263
  1656
                break;
slouken@5184
  1657
            case SDL_COPY_MOD:
slouken@5184
  1658
                dstR = (srcR * dstR) / 255;
slouken@5184
  1659
                dstG = (srcG * dstG) / 255;
slouken@5184
  1660
                dstB = (srcB * dstB) / 255;
slouken@5184
  1661
                break;
slouken@2263
  1662
            }
slouken@2800
  1663
            dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
slouken@2263
  1664
            *dst = dstpixel;
slouken@2263
  1665
            posx += incx;
slouken@2263
  1666
            ++dst;
slouken@2263
  1667
        }
slouken@2263
  1668
        posy += incy;
slouken@2263
  1669
        info->dst += info->dst_pitch;
slouken@2263
  1670
    }
slouken@2263
  1671
}
slouken@2263
  1672
slouken@2800
  1673
static void SDL_Blit_BGR888_BGR888_Scale(SDL_BlitInfo *info)
slouken@2800
  1674
{
slouken@2263
  1675
    int srcy, srcx;
slouken@2263
  1676
    int posy, posx;
slouken@2263
  1677
    int incy, incx;
slouken@2263
  1678
slouken@2263
  1679
    srcy = 0;
slouken@2263
  1680
    posy = 0;
slouken@2263
  1681
    incy = (info->src_h << 16) / info->dst_h;
slouken@2263
  1682
    incx = (info->src_w << 16) / info->dst_w;
slouken@2263
  1683
slouken@2263
  1684
    while (info->dst_h--) {
slouken@5426
  1685
        Uint32 *src = 0;
slouken@2263
  1686
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
  1687
        int n = info->dst_w;
slouken@2263
  1688
        srcx = -1;
slouken@2263
  1689
        posx = 0x10000L;
slouken@2263
  1690
        while (posy >= 0x10000L) {
slouken@2263
  1691
            ++srcy;
slouken@2263
  1692
            posy -= 0x10000L;
slouken@2263
  1693
        }
slouken@2263
  1694
        while (n--) {
slouken@2263
  1695
            if (posx >= 0x10000L) {
slouken@2263
  1696
                while (posx >= 0x10000L) {
slouken@2263
  1697
                    ++srcx;
slouken@2263
  1698
                    posx -= 0x10000L;
slouken@2263
  1699
                }
slouken@2263
  1700
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2263
  1701
            }
slouken@2800
  1702
            *dst = *src;
slouken@2263
  1703
            posx += incx;
slouken@2263
  1704
            ++dst;
slouken@2263
  1705
        }
slouken@2263
  1706
        posy += incy;
slouken@2263
  1707
        info->dst += info->dst_pitch;
slouken@2263
  1708
    }
slouken@2263
  1709
}
slouken@2263
  1710
slouken@2800
  1711
static void SDL_Blit_BGR888_BGR888_Blend(SDL_BlitInfo *info)
slouken@2263
  1712
{
slouken@2263
  1713
    const int flags = info->flags;
slouken@2263
  1714
    Uint32 srcpixel;
slouken@2263
  1715
    Uint32 srcR, srcG, srcB, srcA;
slouken@2263
  1716
    Uint32 dstpixel;
slouken@2263
  1717
    Uint32 dstR, dstG, dstB, dstA;
slouken@2263
  1718
slouken@2263
  1719
    while (info->dst_h--) {
slouken@2263
  1720
        Uint32 *src = (Uint32 *)info->src;
slouken@2263
  1721
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
  1722
        int n = info->dst_w;
slouken@2263
  1723
        while (n--) {
slouken@2263
  1724
            srcpixel = *src;
slouken@2800
  1725
            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
slouken@2263
  1726
            dstpixel = *dst;
slouken@2800
  1727
            dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
slouken@2263
  1728
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2263
  1729
                /* This goes away if we ever use premultiplied alpha */
slouken@2263
  1730
                if (srcA < 255) {
slouken@2263
  1731
                    srcR = (srcR * srcA) / 255;
slouken@2263
  1732
                    srcG = (srcG * srcA) / 255;
slouken@2263
  1733
                    srcB = (srcB * srcA) / 255;
slouken@2263
  1734
                }
slouken@2263
  1735
            }
slouken@5184
  1736
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2263
  1737
            case SDL_COPY_BLEND:
slouken@2263
  1738
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2263
  1739
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2263
  1740
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
  1741
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2263
  1742
                break;
slouken@2263
  1743
            case SDL_COPY_ADD:
slouken@2263
  1744
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2263
  1745
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2263
  1746
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2263
  1747
                break;
slouken@5184
  1748
            case SDL_COPY_MOD:
slouken@5184
  1749
                dstR = (srcR * dstR) / 255;
slouken@5184
  1750
                dstG = (srcG * dstG) / 255;
slouken@5184
  1751
                dstB = (srcB * dstB) / 255;
slouken@5184
  1752
                break;
slouken@2263
  1753
            }
slouken@2800
  1754
            dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
slouken@2263
  1755
            *dst = dstpixel;
slouken@2263
  1756
            ++src;
slouken@2263
  1757
            ++dst;
slouken@2263
  1758
        }
slouken@2263
  1759
        info->src += info->src_pitch;
slouken@2263
  1760
        info->dst += info->dst_pitch;
slouken@2263
  1761
    }
slouken@2263
  1762
}
slouken@2263
  1763
slouken@2800
  1764
static void SDL_Blit_BGR888_BGR888_Blend_Scale(SDL_BlitInfo *info)
slouken@2263
  1765
{
slouken@2263
  1766
    const int flags = info->flags;
slouken@2263
  1767
    Uint32 srcpixel;
slouken@2263
  1768
    Uint32 srcR, srcG, srcB, srcA;
slouken@2263
  1769
    Uint32 dstpixel;
slouken@2263
  1770
    Uint32 dstR, dstG, dstB, dstA;
slouken@2263
  1771
    int srcy, srcx;
slouken@2263
  1772
    int posy, posx;
slouken@2263
  1773
    int incy, incx;
slouken@2263
  1774
slouken@2263
  1775
    srcy = 0;
slouken@2263
  1776
    posy = 0;
slouken@2263
  1777
    incy = (info->src_h << 16) / info->dst_h;
slouken@2263
  1778
    incx = (info->src_w << 16) / info->dst_w;
slouken@2263
  1779
slouken@2263
  1780
    while (info->dst_h--) {
slouken@5426
  1781
        Uint32 *src = 0;
slouken@2263
  1782
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
  1783
        int n = info->dst_w;
slouken@2263
  1784
        srcx = -1;
slouken@2263
  1785
        posx = 0x10000L;
slouken@2263
  1786
        while (posy >= 0x10000L) {
slouken@2263
  1787
            ++srcy;
slouken@2263
  1788
            posy -= 0x10000L;
slouken@2263
  1789
        }
slouken@2263
  1790
        while (n--) {
slouken@2263
  1791
            if (posx >= 0x10000L) {
slouken@2263
  1792
                while (posx >= 0x10000L) {
slouken@2263
  1793
                    ++srcx;
slouken@2263
  1794
                    posx -= 0x10000L;
slouken@2263
  1795
                }
slouken@2263
  1796
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2263
  1797
            }
slouken@2263
  1798
            srcpixel = *src;
slouken@2800
  1799
            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
slouken@2263
  1800
            dstpixel = *dst;
slouken@2800
  1801
            dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
slouken@2263
  1802
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2263
  1803
                /* This goes away if we ever use premultiplied alpha */
slouken@2263
  1804
                if (srcA < 255) {
slouken@2263
  1805
                    srcR = (srcR * srcA) / 255;
slouken@2263
  1806
                    srcG = (srcG * srcA) / 255;
slouken@2263
  1807
                    srcB = (srcB * srcA) / 255;
slouken@2263
  1808
                }
slouken@2263
  1809
            }
slouken@5184
  1810
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2263
  1811
            case SDL_COPY_BLEND:
slouken@2263
  1812
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2263
  1813
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2263
  1814
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
  1815
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2263
  1816
                break;
slouken@2263
  1817
            case SDL_COPY_ADD:
slouken@2263
  1818
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2263
  1819
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2263
  1820
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2263
  1821
                break;
slouken@5184
  1822
            case SDL_COPY_MOD:
slouken@5184
  1823
                dstR = (srcR * dstR) / 255;
slouken@5184
  1824
                dstG = (srcG * dstG) / 255;
slouken@5184
  1825
                dstB = (srcB * dstB) / 255;
slouken@5184
  1826
                break;
slouken@2263
  1827
            }
slouken@2800
  1828
            dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
slouken@2263
  1829
            *dst = dstpixel;
slouken@2263
  1830
            posx += incx;
slouken@2263
  1831
            ++dst;
slouken@2263
  1832
        }
slouken@2263
  1833
        posy += incy;
slouken@2263
  1834
        info->dst += info->dst_pitch;
slouken@2263
  1835
    }
slouken@2263
  1836
}
slouken@2263
  1837
slouken@2800
  1838
static void SDL_Blit_BGR888_BGR888_Modulate(SDL_BlitInfo *info)
slouken@2263
  1839
{
slouken@2263
  1840
    const int flags = info->flags;
slouken@2263
  1841
    const Uint32 modulateR = info->r;
slouken@2263
  1842
    const Uint32 modulateG = info->g;
slouken@2263
  1843
    const Uint32 modulateB = info->b;
slouken@2263
  1844
    const Uint32 modulateA = info->a;
slouken@2263
  1845
    Uint32 pixel;
slouken@2263
  1846
    Uint32 R, G, B, A;
slouken@2263
  1847
slouken@2263
  1848
    while (info->dst_h--) {
slouken@2263
  1849
        Uint32 *src = (Uint32 *)info->src;
slouken@2263
  1850
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
  1851
        int n = info->dst_w;
slouken@2263
  1852
        while (n--) {
slouken@2263
  1853
            pixel = *src;
slouken@2800
  1854
            B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF;
slouken@2263
  1855
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2263
  1856
                R = (R * modulateR) / 255;
slouken@2263
  1857
                G = (G * modulateG) / 255;
slouken@2263
  1858
                B = (B * modulateB) / 255;
slouken@2263
  1859
            }
slouken@2263
  1860
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2263
  1861
                A = (A * modulateA) / 255;
slouken@2263
  1862
            }
slouken@2800
  1863
            pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
slouken@2263
  1864
            *dst = pixel;
slouken@2263
  1865
            ++src;
slouken@2263
  1866
            ++dst;
slouken@2263
  1867
        }
slouken@2263
  1868
        info->src += info->src_pitch;
slouken@2263
  1869
        info->dst += info->dst_pitch;
slouken@2263
  1870
    }
slouken@2263
  1871
}
slouken@2263
  1872
slouken@2800
  1873
static void SDL_Blit_BGR888_BGR888_Modulate_Scale(SDL_BlitInfo *info)
slouken@2263
  1874
{
slouken@2263
  1875
    const int flags = info->flags;
slouken@2263
  1876
    const Uint32 modulateR = info->r;
slouken@2263
  1877
    const Uint32 modulateG = info->g;
slouken@2263
  1878
    const Uint32 modulateB = info->b;
slouken@2263
  1879
    const Uint32 modulateA = info->a;
slouken@2263
  1880
    Uint32 pixel;
slouken@2263
  1881
    Uint32 R, G, B, A;
slouken@2263
  1882
    int srcy, srcx;
slouken@2263
  1883
    int posy, posx;
slouken@2263
  1884
    int incy, incx;
slouken@2263
  1885
slouken@2263
  1886
    srcy = 0;
slouken@2263
  1887
    posy = 0;
slouken@2263
  1888
    incy = (info->src_h << 16) / info->dst_h;
slouken@2263
  1889
    incx = (info->src_w << 16) / info->dst_w;
slouken@2263
  1890
slouken@2263
  1891
    while (info->dst_h--) {
slouken@5426
  1892
        Uint32 *src = 0;
slouken@2263
  1893
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
  1894
        int n = info->dst_w;
slouken@2263
  1895
        srcx = -1;
slouken@2263
  1896
        posx = 0x10000L;
slouken@2263
  1897
        while (posy >= 0x10000L) {
slouken@2263
  1898
            ++srcy;
slouken@2263
  1899
            posy -= 0x10000L;
slouken@2263
  1900
        }
slouken@2263
  1901
        while (n--) {
slouken@2263
  1902
            if (posx >= 0x10000L) {
slouken@2263
  1903
                while (posx >= 0x10000L) {
slouken@2263
  1904
                    ++srcx;
slouken@2263
  1905
                    posx -= 0x10000L;
slouken@2263
  1906
                }
slouken@2263
  1907
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2263
  1908
            }
slouken@2263
  1909
            pixel = *src;
slouken@2800
  1910
            B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF;
slouken@2263
  1911
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2263
  1912
                R = (R * modulateR) / 255;
slouken@2263
  1913
                G = (G * modulateG) / 255;
slouken@2263
  1914
                B = (B * modulateB) / 255;
slouken@2263
  1915
            }
slouken@2263
  1916
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2263
  1917
                A = (A * modulateA) / 255;
slouken@2263
  1918
            }
slouken@2800
  1919
            pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
slouken@2263
  1920
            *dst = pixel;
slouken@2263
  1921
            posx += incx;
slouken@2263
  1922
            ++dst;
slouken@2263
  1923
        }
slouken@2263
  1924
        posy += incy;
slouken@2263
  1925
        info->dst += info->dst_pitch;
slouken@2263
  1926
    }
slouken@2263
  1927
}
slouken@2263
  1928
slouken@2800
  1929
static void SDL_Blit_BGR888_BGR888_Modulate_Blend(SDL_BlitInfo *info)
slouken@2263
  1930
{
slouken@2263
  1931
    const int flags = info->flags;
slouken@2263
  1932
    const Uint32 modulateR = info->r;
slouken@2263
  1933
    const Uint32 modulateG = info->g;
slouken@2263
  1934
    const Uint32 modulateB = info->b;
slouken@2263
  1935
    const Uint32 modulateA = info->a;
slouken@2263
  1936
    Uint32 srcpixel;
slouken@2263
  1937
    Uint32 srcR, srcG, srcB, srcA;
slouken@2263
  1938
    Uint32 dstpixel;
slouken@2263
  1939
    Uint32 dstR, dstG, dstB, dstA;
slouken@2263
  1940
slouken@2263
  1941
    while (info->dst_h--) {
slouken@2263
  1942
        Uint32 *src = (Uint32 *)info->src;
slouken@2263
  1943
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
  1944
        int n = info->dst_w;
slouken@2263
  1945
        while (n--) {
slouken@2263
  1946
            srcpixel = *src;
slouken@2800
  1947
            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
slouken@2263
  1948
            dstpixel = *dst;
slouken@2800
  1949
            dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
slouken@2263
  1950
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2263
  1951
                srcR = (srcR * modulateR) / 255;
slouken@2263
  1952
                srcG = (srcG * modulateG) / 255;
slouken@2263
  1953
                srcB = (srcB * modulateB) / 255;
slouken@2263
  1954
            }
slouken@2263
  1955
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2263
  1956
                srcA = (srcA * modulateA) / 255;
slouken@2263
  1957
            }
slouken@2263
  1958
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2263
  1959
                /* This goes away if we ever use premultiplied alpha */
slouken@2263
  1960
                if (srcA < 255) {
slouken@2263
  1961
                    srcR = (srcR * srcA) / 255;
slouken@2263
  1962
                    srcG = (srcG * srcA) / 255;
slouken@2263
  1963
                    srcB = (srcB * srcA) / 255;
slouken@2263
  1964
                }
slouken@2263
  1965
            }
slouken@5184
  1966
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2263
  1967
            case SDL_COPY_BLEND:
slouken@2263
  1968
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2263
  1969
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2263
  1970
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
  1971
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2263
  1972
                break;
slouken@2263
  1973
            case SDL_COPY_ADD:
slouken@2263
  1974
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2263
  1975
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2263
  1976
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2263
  1977
                break;
slouken@5184
  1978
            case SDL_COPY_MOD:
slouken@5184
  1979
                dstR = (srcR * dstR) / 255;
slouken@5184
  1980
                dstG = (srcG * dstG) / 255;
slouken@5184
  1981
                dstB = (srcB * dstB) / 255;
slouken@5184
  1982
                break;
slouken@2263
  1983
            }
slouken@2800
  1984
            dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
slouken@2263
  1985
            *dst = dstpixel;
slouken@2263
  1986
            ++src;
slouken@2263
  1987
            ++dst;
slouken@2263
  1988
        }
slouken@2263
  1989
        info->src += info->src_pitch;
slouken@2263
  1990
        info->dst += info->dst_pitch;
slouken@2263
  1991
    }
slouken@2263
  1992
}
slouken@2263
  1993
slouken@2800
  1994
static void SDL_Blit_BGR888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info)
slouken@2263
  1995
{
slouken@2263
  1996
    const int flags = info->flags;
slouken@2263
  1997
    const Uint32 modulateR = info->r;
slouken@2263
  1998
    const Uint32 modulateG = info->g;
slouken@2263
  1999
    const Uint32 modulateB = info->b;
slouken@2263
  2000
    const Uint32 modulateA = info->a;
slouken@2263
  2001
    Uint32 srcpixel;
slouken@2263
  2002
    Uint32 srcR, srcG, srcB, srcA;
slouken@2263
  2003
    Uint32 dstpixel;
slouken@2263
  2004
    Uint32 dstR, dstG, dstB, dstA;
slouken@2263
  2005
    int srcy, srcx;
slouken@2263
  2006
    int posy, posx;
slouken@2263
  2007
    int incy, incx;
slouken@2263
  2008
slouken@2263
  2009
    srcy = 0;
slouken@2263
  2010
    posy = 0;
slouken@2263
  2011
    incy = (info->src_h << 16) / info->dst_h;
slouken@2263
  2012
    incx = (info->src_w << 16) / info->dst_w;
slouken@2263
  2013
slouken@2263
  2014
    while (info->dst_h--) {
slouken@5426
  2015
        Uint32 *src = 0;
slouken@2263
  2016
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
  2017
        int n = info->dst_w;
slouken@2263
  2018
        srcx = -1;
slouken@2263
  2019
        posx = 0x10000L;
slouken@2263
  2020
        while (posy >= 0x10000L) {
slouken@2263
  2021
            ++srcy;
slouken@2263
  2022
            posy -= 0x10000L;
slouken@2263
  2023
        }
slouken@2263
  2024
        while (n--) {
slouken@2263
  2025
            if (posx >= 0x10000L) {
slouken@2263
  2026
                while (posx >= 0x10000L) {
slouken@2263
  2027
                    ++srcx;
slouken@2263
  2028
                    posx -= 0x10000L;
slouken@2263
  2029
                }
slouken@2263
  2030
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2263
  2031
            }
slouken@2263
  2032
            srcpixel = *src;
slouken@2800
  2033
            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
slouken@2263
  2034
            dstpixel = *dst;
slouken@2800
  2035
            dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
slouken@2263
  2036
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2263
  2037
                srcR = (srcR * modulateR) / 255;
slouken@2263
  2038
                srcG = (srcG * modulateG) / 255;
slouken@2263
  2039
                srcB = (srcB * modulateB) / 255;
slouken@2263
  2040
            }
slouken@2263
  2041
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2263
  2042
                srcA = (srcA * modulateA) / 255;
slouken@2263
  2043
            }
slouken@2263
  2044
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2263
  2045
                /* This goes away if we ever use premultiplied alpha */
slouken@2263
  2046
                if (srcA < 255) {
slouken@2263
  2047
                    srcR = (srcR * srcA) / 255;
slouken@2263
  2048
                    srcG = (srcG * srcA) / 255;
slouken@2263
  2049
                    srcB = (srcB * srcA) / 255;
slouken@2263
  2050
                }
slouken@2263
  2051
            }
slouken@5184
  2052
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2263
  2053
            case SDL_COPY_BLEND:
slouken@2263
  2054
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2263
  2055
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2263
  2056
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
  2057
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2263
  2058
                break;
slouken@2263
  2059
            case SDL_COPY_ADD:
slouken@2263
  2060
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2263
  2061
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2263
  2062
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2263
  2063
                break;
slouken@5184
  2064
            case SDL_COPY_MOD:
slouken@5184
  2065
                dstR = (srcR * dstR) / 255;
slouken@5184
  2066
                dstG = (srcG * dstG) / 255;
slouken@5184
  2067
                dstB = (srcB * dstB) / 255;
slouken@5184
  2068
                break;
slouken@2263
  2069
            }
slouken@2800
  2070
            dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
slouken@2263
  2071
            *dst = dstpixel;
slouken@2263
  2072
            posx += incx;
slouken@2263
  2073
            ++dst;
slouken@2263
  2074
        }
slouken@2263
  2075
        posy += incy;
slouken@2263
  2076
        info->dst += info->dst_pitch;
slouken@2263
  2077
    }
slouken@2263
  2078
}
slouken@2263
  2079
slouken@2800
  2080
static void SDL_Blit_BGR888_ARGB8888_Scale(SDL_BlitInfo *info)
slouken@2263
  2081
{
slouken@2263
  2082
    Uint32 pixel;
slouken@2263
  2083
    Uint32 R, G, B, A;
slouken@2263
  2084
    int srcy, srcx;
slouken@2263
  2085
    int posy, posx;
slouken@2263
  2086
    int incy, incx;
slouken@2263
  2087
slouken@2263
  2088
    srcy = 0;
slouken@2263
  2089
    posy = 0;
slouken@2263
  2090
    incy = (info->src_h << 16) / info->dst_h;
slouken@2263
  2091
    incx = (info->src_w << 16) / info->dst_w;
slouken@2263
  2092
slouken@2263
  2093
    while (info->dst_h--) {
slouken@5426
  2094
        Uint32 *src = 0;
slouken@2263
  2095
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
  2096
        int n = info->dst_w;
slouken@2263
  2097
        srcx = -1;
slouken@2263
  2098
        posx = 0x10000L;
slouken@2263
  2099
        while (posy >= 0x10000L) {
slouken@2263
  2100
            ++srcy;
slouken@2263
  2101
            posy -= 0x10000L;
slouken@2263
  2102
        }
slouken@2263
  2103
        while (n--) {
slouken@2263
  2104
            if (posx >= 0x10000L) {
slouken@2263
  2105
                while (posx >= 0x10000L) {
slouken@2263
  2106
                    ++srcx;
slouken@2263
  2107
                    posx -= 0x10000L;
slouken@2263
  2108
                }
slouken@2263
  2109
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2263
  2110
            }
slouken@2263
  2111
            pixel = *src;
slouken@2800
  2112
            B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF;
slouken@2800
  2113
            pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
slouken@2263
  2114
            *dst = pixel;
slouken@2263
  2115
            posx += incx;
slouken@2263
  2116
            ++dst;
slouken@2263
  2117
        }
slouken@2263
  2118
        posy += incy;
slouken@2263
  2119
        info->dst += info->dst_pitch;
slouken@2263
  2120
    }
slouken@2263
  2121
}
slouken@2263
  2122
slouken@2800
  2123
static void SDL_Blit_BGR888_ARGB8888_Blend(SDL_BlitInfo *info)
slouken@2263
  2124
{
slouken@2263
  2125
    const int flags = info->flags;
slouken@2263
  2126
    Uint32 srcpixel;
slouken@2263
  2127
    Uint32 srcR, srcG, srcB, srcA;
slouken@2263
  2128
    Uint32 dstpixel;
slouken@2263
  2129
    Uint32 dstR, dstG, dstB, dstA;
slouken@2263
  2130
slouken@2263
  2131
    while (info->dst_h--) {
slouken@2263
  2132
        Uint32 *src = (Uint32 *)info->src;
slouken@2263
  2133
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
  2134
        int n = info->dst_w;
slouken@2263
  2135
        while (n--) {
slouken@2263
  2136
            srcpixel = *src;
slouken@2800
  2137
            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
slouken@2263
  2138
            dstpixel = *dst;
slouken@2800
  2139
            dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
slouken@2263
  2140
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2263
  2141
                /* This goes away if we ever use premultiplied alpha */
slouken@2263
  2142
                if (srcA < 255) {
slouken@2263
  2143
                    srcR = (srcR * srcA) / 255;
slouken@2263
  2144
                    srcG = (srcG * srcA) / 255;
slouken@2263
  2145
                    srcB = (srcB * srcA) / 255;
slouken@2263
  2146
                }
slouken@2263
  2147
            }
slouken@5184
  2148
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2263
  2149
            case SDL_COPY_BLEND:
slouken@2263
  2150
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2263
  2151
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2263
  2152
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
  2153
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2263
  2154
                break;
slouken@2263
  2155
            case SDL_COPY_ADD:
slouken@2263
  2156
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2263
  2157
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2263
  2158
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2263
  2159
                break;
slouken@5184
  2160
            case SDL_COPY_MOD:
slouken@5184
  2161
                dstR = (srcR * dstR) / 255;
slouken@5184
  2162
                dstG = (srcG * dstG) / 255;
slouken@5184
  2163
                dstB = (srcB * dstB) / 255;
slouken@5184
  2164
                break;
slouken@2263
  2165
            }
slouken@2800
  2166
            dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
slouken@2263
  2167
            *dst = dstpixel;
slouken@2263
  2168
            ++src;
slouken@2263
  2169
            ++dst;
slouken@2263
  2170
        }
slouken@2263
  2171
        info->src += info->src_pitch;
slouken@2263
  2172
        info->dst += info->dst_pitch;
slouken@2263
  2173
    }
slouken@2263
  2174
}
slouken@2263
  2175
slouken@2800
  2176
static void SDL_Blit_BGR888_ARGB8888_Blend_Scale(SDL_BlitInfo *info)
slouken@2263
  2177
{
slouken@2263
  2178
    const int flags = info->flags;
slouken@2263
  2179
    Uint32 srcpixel;
slouken@2263
  2180
    Uint32 srcR, srcG, srcB, srcA;
slouken@2263
  2181
    Uint32 dstpixel;
slouken@2263
  2182
    Uint32 dstR, dstG, dstB, dstA;
slouken@2263
  2183
    int srcy, srcx;
slouken@2263
  2184
    int posy, posx;
slouken@2263
  2185
    int incy, incx;
slouken@2263
  2186
slouken@2263
  2187
    srcy = 0;
slouken@2263
  2188
    posy = 0;
slouken@2263
  2189
    incy = (info->src_h << 16) / info->dst_h;
slouken@2263
  2190
    incx = (info->src_w << 16) / info->dst_w;
slouken@2263
  2191
slouken@2263
  2192
    while (info->dst_h--) {
slouken@5426
  2193
        Uint32 *src = 0;
slouken@2263
  2194
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
  2195
        int n = info->dst_w;
slouken@2263
  2196
        srcx = -1;
slouken@2263
  2197
        posx = 0x10000L;
slouken@2263
  2198
        while (posy >= 0x10000L) {
slouken@2263
  2199
            ++srcy;
slouken@2263
  2200
            posy -= 0x10000L;
slouken@2263
  2201
        }
slouken@2263
  2202
        while (n--) {
slouken@2263
  2203
            if (posx >= 0x10000L) {
slouken@2263
  2204
                while (posx >= 0x10000L) {
slouken@2263
  2205
                    ++srcx;
slouken@2263
  2206
                    posx -= 0x10000L;
slouken@2263
  2207
                }
slouken@2263
  2208
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2263
  2209
            }
slouken@2263
  2210
            srcpixel = *src;
slouken@2800
  2211
            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
slouken@2263
  2212
            dstpixel = *dst;
slouken@2800
  2213
            dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
slouken@2263
  2214
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2263
  2215
                /* This goes away if we ever use premultiplied alpha */
slouken@2263
  2216
                if (srcA < 255) {
slouken@2263
  2217
                    srcR = (srcR * srcA) / 255;
slouken@2263
  2218
                    srcG = (srcG * srcA) / 255;
slouken@2263
  2219
                    srcB = (srcB * srcA) / 255;
slouken@2263
  2220
                }
slouken@2263
  2221
            }
slouken@5184
  2222
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2263
  2223
            case SDL_COPY_BLEND:
slouken@2263
  2224
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2263
  2225
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2263
  2226
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
  2227
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2263
  2228
                break;
slouken@2263
  2229
            case SDL_COPY_ADD:
slouken@2263
  2230
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2263
  2231
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2263
  2232
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2263
  2233
                break;
slouken@5184
  2234
            case SDL_COPY_MOD:
slouken@5184
  2235
                dstR = (srcR * dstR) / 255;
slouken@5184
  2236
                dstG = (srcG * dstG) / 255;
slouken@5184
  2237
                dstB = (srcB * dstB) / 255;
slouken@5184
  2238
                break;
slouken@2263
  2239
            }
slouken@2800
  2240
            dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
slouken@2263
  2241
            *dst = dstpixel;
slouken@2263
  2242
            posx += incx;
slouken@2263
  2243
            ++dst;
slouken@2263
  2244
        }
slouken@2263
  2245
        posy += incy;
slouken@2263
  2246
        info->dst += info->dst_pitch;
slouken@2263
  2247
    }
slouken@2263
  2248
}
slouken@2263
  2249
slouken@2800
  2250
static void SDL_Blit_BGR888_ARGB8888_Modulate(SDL_BlitInfo *info)
slouken@2263
  2251
{
slouken@2263
  2252
    const int flags = info->flags;
slouken@2263
  2253
    const Uint32 modulateR = info->r;
slouken@2263
  2254
    const Uint32 modulateG = info->g;
slouken@2263
  2255
    const Uint32 modulateB = info->b;
slouken@2263
  2256
    const Uint32 modulateA = info->a;
slouken@2263
  2257
    Uint32 pixel;
slouken@2263
  2258
    Uint32 R, G, B, A;
slouken@2263
  2259
slouken@2263
  2260
    while (info->dst_h--) {
slouken@2263
  2261
        Uint32 *src = (Uint32 *)info->src;
slouken@2263
  2262
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
  2263
        int n = info->dst_w;
slouken@2263
  2264
        while (n--) {
slouken@2263
  2265
            pixel = *src;
slouken@2800
  2266
            B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF;
slouken@2263
  2267
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2263
  2268
                R = (R * modulateR) / 255;
slouken@2263
  2269
                G = (G * modulateG) / 255;
slouken@2263
  2270
                B = (B * modulateB) / 255;
slouken@2263
  2271
            }
slouken@2263
  2272
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2263
  2273
                A = (A * modulateA) / 255;
slouken@2263
  2274
            }
slouken@2800
  2275
            pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
slouken@2263
  2276
            *dst = pixel;
slouken@2263
  2277
            ++src;
slouken@2263
  2278
            ++dst;
slouken@2263
  2279
        }
slouken@2263
  2280
        info->src += info->src_pitch;
slouken@2263
  2281
        info->dst += info->dst_pitch;
slouken@2263
  2282
    }
slouken@2263
  2283
}
slouken@2263
  2284
slouken@2800
  2285
static void SDL_Blit_BGR888_ARGB8888_Modulate_Scale(SDL_BlitInfo *info)
slouken@2263
  2286
{
slouken@2263
  2287
    const int flags = info->flags;
slouken@2263
  2288
    const Uint32 modulateR = info->r;
slouken@2263
  2289
    const Uint32 modulateG = info->g;
slouken@2263
  2290
    const Uint32 modulateB = info->b;
slouken@2263
  2291
    const Uint32 modulateA = info->a;
slouken@2263
  2292
    Uint32 pixel;
slouken@2263
  2293
    Uint32 R, G, B, A;
slouken@2263
  2294
    int srcy, srcx;
slouken@2263
  2295
    int posy, posx;
slouken@2263
  2296
    int incy, incx;
slouken@2263
  2297
slouken@2263
  2298
    srcy = 0;
slouken@2263
  2299
    posy = 0;
slouken@2263
  2300
    incy = (info->src_h << 16) / info->dst_h;
slouken@2263
  2301
    incx = (info->src_w << 16) / info->dst_w;
slouken@2263
  2302
slouken@2263
  2303
    while (info->dst_h--) {
slouken@5426
  2304
        Uint32 *src = 0;
slouken@2263
  2305
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
  2306
        int n = info->dst_w;
slouken@2263
  2307
        srcx = -1;
slouken@2263
  2308
        posx = 0x10000L;
slouken@2263
  2309
        while (posy >= 0x10000L) {
slouken@2263
  2310
            ++srcy;
slouken@2263
  2311
            posy -= 0x10000L;
slouken@2263
  2312
        }
slouken@2263
  2313
        while (n--) {
slouken@2263
  2314
            if (posx >= 0x10000L) {
slouken@2263
  2315
                while (posx >= 0x10000L) {
slouken@2263
  2316
                    ++srcx;
slouken@2263
  2317
                    posx -= 0x10000L;
slouken@2263
  2318
                }
slouken@2263
  2319
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2263
  2320
            }
slouken@2263
  2321
            pixel = *src;
slouken@2800
  2322
            B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF;
slouken@2263
  2323
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2263
  2324
                R = (R * modulateR) / 255;
slouken@2263
  2325
                G = (G * modulateG) / 255;
slouken@2263
  2326
                B = (B * modulateB) / 255;
slouken@2263
  2327
            }
slouken@2263
  2328
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2263
  2329
                A = (A * modulateA) / 255;
slouken@2263
  2330
            }
slouken@2800
  2331
            pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
slouken@2263
  2332
            *dst = pixel;
slouken@2263
  2333
            posx += incx;
slouken@2263
  2334
            ++dst;
slouken@2263
  2335
        }
slouken@2263
  2336
        posy += incy;
slouken@2263
  2337
        info->dst += info->dst_pitch;
slouken@2263
  2338
    }
slouken@2263
  2339
}
slouken@2263
  2340
slouken@2800
  2341
static void SDL_Blit_BGR888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info)
slouken@2263
  2342
{
slouken@2263
  2343
    const int flags = info->flags;
slouken@2263
  2344
    const Uint32 modulateR = info->r;
slouken@2263
  2345
    const Uint32 modulateG = info->g;
slouken@2263
  2346
    const Uint32 modulateB = info->b;
slouken@2263
  2347
    const Uint32 modulateA = info->a;
slouken@2263
  2348
    Uint32 srcpixel;
slouken@2263
  2349
    Uint32 srcR, srcG, srcB, srcA;
slouken@2263
  2350
    Uint32 dstpixel;
slouken@2263
  2351
    Uint32 dstR, dstG, dstB, dstA;
slouken@2263
  2352
slouken@2263
  2353
    while (info->dst_h--) {
slouken@2263
  2354
        Uint32 *src = (Uint32 *)info->src;
slouken@2263
  2355
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
  2356
        int n = info->dst_w;
slouken@2263
  2357
        while (n--) {
slouken@2263
  2358
            srcpixel = *src;
slouken@2800
  2359
            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
slouken@2263
  2360
            dstpixel = *dst;
slouken@2800
  2361
            dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
slouken@2263
  2362
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2263
  2363
                srcR = (srcR * modulateR) / 255;
slouken@2263
  2364
                srcG = (srcG * modulateG) / 255;
slouken@2263
  2365
                srcB = (srcB * modulateB) / 255;
slouken@2263
  2366
            }
slouken@2263
  2367
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2263
  2368
                srcA = (srcA * modulateA) / 255;
slouken@2263
  2369
            }
slouken@2263
  2370
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2263
  2371
                /* This goes away if we ever use premultiplied alpha */
slouken@2263
  2372
                if (srcA < 255) {
slouken@2263
  2373
                    srcR = (srcR * srcA) / 255;
slouken@2263
  2374
                    srcG = (srcG * srcA) / 255;
slouken@2263
  2375
                    srcB = (srcB * srcA) / 255;
slouken@2263
  2376
                }
slouken@2263
  2377
            }
slouken@5184
  2378
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2263
  2379
            case SDL_COPY_BLEND:
slouken@2263
  2380
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2263
  2381
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2263
  2382
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
  2383
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2263
  2384
                break;
slouken@2263
  2385
            case SDL_COPY_ADD:
slouken@2263
  2386
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2263
  2387
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2263
  2388
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2263
  2389
                break;
slouken@5184
  2390
            case SDL_COPY_MOD:
slouken@5184
  2391
                dstR = (srcR * dstR) / 255;
slouken@5184
  2392
                dstG = (srcG * dstG) / 255;
slouken@5184
  2393
                dstB = (srcB * dstB) / 255;
slouken@5184
  2394
                break;
slouken@2263
  2395
            }
slouken@2800
  2396
            dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
slouken@2263
  2397
            *dst = dstpixel;
slouken@2263
  2398
            ++src;
slouken@2263
  2399
            ++dst;
slouken@2263
  2400
        }
slouken@2263
  2401
        info->src += info->src_pitch;
slouken@2263
  2402
        info->dst += info->dst_pitch;
slouken@2263
  2403
    }
slouken@2263
  2404
}
slouken@2263
  2405
slouken@2800
  2406
static void SDL_Blit_BGR888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info)
slouken@2263
  2407
{
slouken@2263
  2408
    const int flags = info->flags;
slouken@2263
  2409
    const Uint32 modulateR = info->r;
slouken@2263
  2410
    const Uint32 modulateG = info->g;
slouken@2263
  2411
    const Uint32 modulateB = info->b;
slouken@2263
  2412
    const Uint32 modulateA = info->a;
slouken@2263
  2413
    Uint32 srcpixel;
slouken@2263
  2414
    Uint32 srcR, srcG, srcB, srcA;
slouken@2263
  2415
    Uint32 dstpixel;
slouken@2263
  2416
    Uint32 dstR, dstG, dstB, dstA;
slouken@2263
  2417
    int srcy, srcx;
slouken@2263
  2418
    int posy, posx;
slouken@2263
  2419
    int incy, incx;
slouken@2263
  2420
slouken@2263
  2421
    srcy = 0;
slouken@2263
  2422
    posy = 0;
slouken@2263
  2423
    incy = (info->src_h << 16) / info->dst_h;
slouken@2263
  2424
    incx = (info->src_w << 16) / info->dst_w;
slouken@2263
  2425
slouken@2263
  2426
    while (info->dst_h--) {
slouken@5426
  2427
        Uint32 *src = 0;
slouken@2263
  2428
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
  2429
        int n = info->dst_w;
slouken@2263
  2430
        srcx = -1;
slouken@2263
  2431
        posx = 0x10000L;
slouken@2263
  2432
        while (posy >= 0x10000L) {
slouken@2263
  2433
            ++srcy;
slouken@2263
  2434
            posy -= 0x10000L;
slouken@2263
  2435
        }
slouken@2263
  2436
        while (n--) {
slouken@2263
  2437
            if (posx >= 0x10000L) {
slouken@2263
  2438
                while (posx >= 0x10000L) {
slouken@2263
  2439
                    ++srcx;
slouken@2263
  2440
                    posx -= 0x10000L;
slouken@2263
  2441
                }
slouken@2263
  2442
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2263
  2443
            }
slouken@2263
  2444
            srcpixel = *src;
slouken@2800
  2445
            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
slouken@2263
  2446
            dstpixel = *dst;
slouken@2800
  2447
            dstA = (Uint8)(dstpixel >> 24); dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel;
slouken@2263
  2448
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2263
  2449
                srcR = (srcR * modulateR) / 255;
slouken@2263
  2450
                srcG = (srcG * modulateG) / 255;
slouken@2263
  2451
                srcB = (srcB * modulateB) / 255;
slouken@2263
  2452
            }
slouken@2263
  2453
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2263
  2454
                srcA = (srcA * modulateA) / 255;
slouken@2263
  2455
            }
slouken@2263
  2456
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2263
  2457
                /* This goes away if we ever use premultiplied alpha */
slouken@2263
  2458
                if (srcA < 255) {
slouken@2263
  2459
                    srcR = (srcR * srcA) / 255;
slouken@2263
  2460
                    srcG = (srcG * srcA) / 255;
slouken@2263
  2461
                    srcB = (srcB * srcA) / 255;
slouken@2263
  2462
                }
slouken@2263
  2463
            }
slouken@5184
  2464
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2263
  2465
            case SDL_COPY_BLEND:
slouken@2263
  2466
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2263
  2467
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2263
  2468
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
  2469
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2263
  2470
                break;
slouken@2263
  2471
            case SDL_COPY_ADD:
slouken@2263
  2472
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2263
  2473
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2263
  2474
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2263
  2475
                break;
slouken@5184
  2476
            case SDL_COPY_MOD:
slouken@5184
  2477
                dstR = (srcR * dstR) / 255;
slouken@5184
  2478
                dstG = (srcG * dstG) / 255;
slouken@5184
  2479
                dstB = (srcB * dstB) / 255;
slouken@5184
  2480
                break;
slouken@2263
  2481
            }
slouken@2800
  2482
            dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
slouken@2263
  2483
            *dst = dstpixel;
slouken@2263
  2484
            posx += incx;
slouken@2263
  2485
            ++dst;
slouken@2263
  2486
        }
slouken@2263
  2487
        posy += incy;
slouken@2263
  2488
        info->dst += info->dst_pitch;
slouken@2263
  2489
    }
slouken@2263
  2490
}
slouken@2263
  2491
slouken@2800
  2492
static void SDL_Blit_ARGB8888_RGB888_Scale(SDL_BlitInfo *info)
slouken@2263
  2493
{
slouken@2263
  2494
    Uint32 pixel;
slouken@2263
  2495
    Uint32 R, G, B, A;
slouken@2263
  2496
    int srcy, srcx;
slouken@2263
  2497
    int posy, posx;
slouken@2263
  2498
    int incy, incx;
slouken@2263
  2499
slouken@2263
  2500
    srcy = 0;
slouken@2263
  2501
    posy = 0;
slouken@2263
  2502
    incy = (info->src_h << 16) / info->dst_h;
slouken@2263
  2503
    incx = (info->src_w << 16) / info->dst_w;
slouken@2263
  2504
slouken@2263
  2505
    while (info->dst_h--) {
slouken@5426
  2506
        Uint32 *src = 0;
slouken@2263
  2507
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
  2508
        int n = info->dst_w;
slouken@2263
  2509
        srcx = -1;
slouken@2263
  2510
        posx = 0x10000L;
slouken@2263
  2511
        while (posy >= 0x10000L) {
slouken@2263
  2512
            ++srcy;
slouken@2263
  2513
            posy -= 0x10000L;
slouken@2263
  2514
        }
slouken@2263
  2515
        while (n--) {
slouken@2263
  2516
            if (posx >= 0x10000L) {
slouken@2263
  2517
                while (posx >= 0x10000L) {
slouken@2263
  2518
                    ++srcx;
slouken@2263
  2519
                    posx -= 0x10000L;
slouken@2263
  2520
                }
slouken@2263
  2521
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2263
  2522
            }
slouken@2263
  2523
            pixel = *src;
slouken@2800
  2524
            A = (Uint8)(pixel >> 24); R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
slouken@2263
  2525
            pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
slouken@2263
  2526
            *dst = pixel;
slouken@2263
  2527
            posx += incx;
slouken@2263
  2528
            ++dst;
slouken@2263
  2529
        }
slouken@2263
  2530
        posy += incy;
slouken@2263
  2531
        info->dst += info->dst_pitch;
slouken@2263
  2532
    }
slouken@2263
  2533
}
slouken@2263
  2534
slouken@2800
  2535
static void SDL_Blit_ARGB8888_RGB888_Blend(SDL_BlitInfo *info)
slouken@2263
  2536
{
slouken@2263
  2537
    const int flags = info->flags;
slouken@2263
  2538
    Uint32 srcpixel;
slouken@2263
  2539
    Uint32 srcR, srcG, srcB, srcA;
slouken@2263
  2540
    Uint32 dstpixel;
slouken@2263
  2541
    Uint32 dstR, dstG, dstB, dstA;
slouken@2263
  2542
slouken@2263
  2543
    while (info->dst_h--) {
slouken@2263
  2544
        Uint32 *src = (Uint32 *)info->src;
slouken@2263
  2545
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
  2546
        int n = info->dst_w;
slouken@2263
  2547
        while (n--) {
slouken@2263
  2548
            srcpixel = *src;
slouken@2800
  2549
            srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel;
slouken@2263
  2550
            dstpixel = *dst;
slouken@2263
  2551
            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
slouken@2263
  2552
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2263
  2553
                /* This goes away if we ever use premultiplied alpha */
slouken@2263
  2554
                if (srcA < 255) {
slouken@2263
  2555
                    srcR = (srcR * srcA) / 255;
slouken@2263
  2556
                    srcG = (srcG * srcA) / 255;
slouken@2263
  2557
                    srcB = (srcB * srcA) / 255;
slouken@2263
  2558
                }
slouken@2263
  2559
            }
slouken@5184
  2560
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2263
  2561
            case SDL_COPY_BLEND:
slouken@2263
  2562
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2263
  2563
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2263
  2564
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
  2565
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2263
  2566
                break;
slouken@2263
  2567
            case SDL_COPY_ADD:
slouken@2263
  2568
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2263
  2569
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2263
  2570
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2263
  2571
                break;
slouken@5184
  2572
            case SDL_COPY_MOD:
slouken@5184
  2573
                dstR = (srcR * dstR) / 255;
slouken@5184
  2574
                dstG = (srcG * dstG) / 255;
slouken@5184
  2575
                dstB = (srcB * dstB) / 255;
slouken@5184
  2576
                break;
slouken@2263
  2577
            }
slouken@2263
  2578
            dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
slouken@2263
  2579
            *dst = dstpixel;
slouken@2263
  2580
            ++src;
slouken@2263
  2581
            ++dst;
slouken@2263
  2582
        }
slouken@2263
  2583
        info->src += info->src_pitch;
slouken@2263
  2584
        info->dst += info->dst_pitch;
slouken@2263
  2585
    }
slouken@2263
  2586
}
slouken@2263
  2587
slouken@2800
  2588
static void SDL_Blit_ARGB8888_RGB888_Blend_Scale(SDL_BlitInfo *info)
slouken@2263
  2589
{
slouken@2263
  2590
    const int flags = info->flags;
slouken@2263
  2591
    Uint32 srcpixel;
slouken@2263
  2592
    Uint32 srcR, srcG, srcB, srcA;
slouken@2263
  2593
    Uint32 dstpixel;
slouken@2263
  2594
    Uint32 dstR, dstG, dstB, dstA;
slouken@2263
  2595
    int srcy, srcx;
slouken@2263
  2596
    int posy, posx;
slouken@2263
  2597
    int incy, incx;
slouken@2263
  2598
slouken@2263
  2599
    srcy = 0;
slouken@2263
  2600
    posy = 0;
slouken@2263
  2601
    incy = (info->src_h << 16) / info->dst_h;
slouken@2263
  2602
    incx = (info->src_w << 16) / info->dst_w;
slouken@2263
  2603
slouken@2263
  2604
    while (info->dst_h--) {
slouken@5426
  2605
        Uint32 *src = 0;
slouken@2263
  2606
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2263
  2607
        int n = info->dst_w;
slouken@2263
  2608
        srcx = -1;
slouken@2263
  2609
        posx = 0x10000L;
slouken@2263
  2610
        while (posy >= 0x10000L) {
slouken@2263
  2611
            ++srcy;
slouken@2263
  2612
            posy -= 0x10000L;
slouken@2263
  2613
        }
slouken@2263
  2614
        while (n--) {
slouken@2263
  2615
            if (posx >= 0x10000L) {
slouken@2263
  2616
                while (posx >= 0x10000L) {
slouken@2263
  2617
                    ++srcx;
slouken@2263
  2618
                    posx -= 0x10000L;
slouken@2263
  2619
                }
slouken@2263
  2620
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2263
  2621
            }
slouken@2263
  2622
            srcpixel = *src;
slouken@2800
  2623
            srcA = (Uint8)(srcpixel >> 24); srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel;
slouken@2263
  2624
            dstpixel = *dst;
slouken@2263
  2625
            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
slouken@2263
  2626
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2263
  2627
                /* This goes away if we ever use premultiplied alpha */
slouken@2263
  2628
                if (srcA < 255) {
slouken@2263
  2629
                    srcR = (srcR * srcA) / 255;
slouken@2263
  2630
                    srcG = (srcG * srcA) / 255;
slouken@2263
  2631
                    srcB = (srcB * srcA) / 255;
slouken@2263
  2632
                }
slouken@2263
  2633
            }
slouken@5184
  2634
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2263
  2635
            case SDL_COPY_BLEND:
slouken@2263
  2636
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2263
  2637
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2263
  2638
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
  2639
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2263
  2640
                break;
slouken@2263
  2641
            case SDL_COPY_ADD:
slouken@2263