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