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