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