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