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