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