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