src/video/SDL_blit_auto.c
author Ryan C. Gordon
Thu, 20 Mar 2014 17:55:24 -0400
changeset 8659 d3a9836732ea
parent 8149 681eb46b8ac4
child 8661 e9e62c8fffb6
permissions -rw-r--r--
Static analysis fix: clean up unused variables and dead stores in blitters.
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;
slouken@2262
    75
slouken@2262
    76
    while (info->dst_h--) {
slouken@2262
    77
        Uint32 *src = (Uint32 *)info->src;
slouken@2262
    78
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2262
    79
        int n = info->dst_w;
slouken@2262
    80
        while (n--) {
slouken@2262
    81
            srcpixel = *src;
slouken@2262
    82
            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
slouken@2262
    83
            dstpixel = *dst;
slouken@2262
    84
            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
slouken@2262
    85
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2262
    86
                /* This goes away if we ever use premultiplied alpha */
slouken@2262
    87
                if (srcA < 255) {
slouken@2262
    88
                    srcR = (srcR * srcA) / 255;
slouken@2262
    89
                    srcG = (srcG * srcA) / 255;
slouken@2262
    90
                    srcB = (srcB * srcA) / 255;
slouken@2262
    91
                }
slouken@2262
    92
            }
slouken@5184
    93
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2262
    94
            case SDL_COPY_BLEND:
slouken@2262
    95
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2262
    96
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2262
    97
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
    98
                dstA = srcA + ((255 - srcA) * dstA) / 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;
slouken@2262
   131
slouken@2262
   132
    srcy = 0;
slouken@2262
   133
    posy = 0;
slouken@2262
   134
    incy = (info->src_h << 16) / info->dst_h;
slouken@2262
   135
    incx = (info->src_w << 16) / info->dst_w;
slouken@2262
   136
slouken@2262
   137
    while (info->dst_h--) {
slouken@5426
   138
        Uint32 *src = 0;
slouken@2262
   139
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2262
   140
        int n = info->dst_w;
slouken@2262
   141
        srcx = -1;
slouken@2262
   142
        posx = 0x10000L;
slouken@2262
   143
        while (posy >= 0x10000L) {
slouken@2262
   144
            ++srcy;
slouken@2262
   145
            posy -= 0x10000L;
slouken@2262
   146
        }
slouken@2262
   147
        while (n--) {
slouken@2262
   148
            if (posx >= 0x10000L) {
slouken@2262
   149
                while (posx >= 0x10000L) {
slouken@2262
   150
                    ++srcx;
slouken@2262
   151
                    posx -= 0x10000L;
slouken@2262
   152
                }
slouken@2262
   153
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2262
   154
            }
slouken@2262
   155
            srcpixel = *src;
slouken@2262
   156
            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
slouken@2262
   157
            dstpixel = *dst;
slouken@2262
   158
            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
slouken@2262
   159
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2262
   160
                /* This goes away if we ever use premultiplied alpha */
slouken@2262
   161
                if (srcA < 255) {
slouken@2262
   162
                    srcR = (srcR * srcA) / 255;
slouken@2262
   163
                    srcG = (srcG * srcA) / 255;
slouken@2262
   164
                    srcB = (srcB * srcA) / 255;
slouken@2262
   165
                }
slouken@2262
   166
            }
slouken@5184
   167
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2262
   168
            case SDL_COPY_BLEND:
slouken@2262
   169
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2262
   170
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2262
   171
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
   172
                dstA = srcA + ((255 - srcA) * dstA) / 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. */
slouken@2262
   296
slouken@2262
   297
    while (info->dst_h--) {
slouken@2262
   298
        Uint32 *src = (Uint32 *)info->src;
slouken@2262
   299
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2262
   300
        int n = info->dst_w;
slouken@2262
   301
        while (n--) {
slouken@2262
   302
            srcpixel = *src;
slouken@2262
   303
            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
slouken@2262
   304
            dstpixel = *dst;
slouken@2262
   305
            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
slouken@2262
   306
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2262
   307
                srcR = (srcR * modulateR) / 255;
slouken@2262
   308
                srcG = (srcG * modulateG) / 255;
slouken@2262
   309
                srcB = (srcB * modulateB) / 255;
slouken@2262
   310
            }
slouken@2262
   311
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2262
   312
                srcA = (srcA * modulateA) / 255;
slouken@2262
   313
            }
slouken@2262
   314
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2262
   315
                /* This goes away if we ever use premultiplied alpha */
slouken@2262
   316
                if (srcA < 255) {
slouken@2262
   317
                    srcR = (srcR * srcA) / 255;
slouken@2262
   318
                    srcG = (srcG * srcA) / 255;
slouken@2262
   319
                    srcB = (srcB * srcA) / 255;
slouken@2262
   320
                }
slouken@2262
   321
            }
slouken@5184
   322
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2262
   323
            case SDL_COPY_BLEND:
slouken@2262
   324
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2262
   325
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2262
   326
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
   327
                dstA = srcA + ((255 - srcA) * dstA) / 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. */
slouken@2262
   365
slouken@2262
   366
    srcy = 0;
slouken@2262
   367
    posy = 0;
slouken@2262
   368
    incy = (info->src_h << 16) / info->dst_h;
slouken@2262
   369
    incx = (info->src_w << 16) / info->dst_w;
slouken@2262
   370
slouken@2262
   371
    while (info->dst_h--) {
slouken@5426
   372
        Uint32 *src = 0;
slouken@2262
   373
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2262
   374
        int n = info->dst_w;
slouken@2262
   375
        srcx = -1;
slouken@2262
   376
        posx = 0x10000L;
slouken@2262
   377
        while (posy >= 0x10000L) {
slouken@2262
   378
            ++srcy;
slouken@2262
   379
            posy -= 0x10000L;
slouken@2262
   380
        }
slouken@2262
   381
        while (n--) {
slouken@2262
   382
            if (posx >= 0x10000L) {
slouken@2262
   383
                while (posx >= 0x10000L) {
slouken@2262
   384
                    ++srcx;
slouken@2262
   385
                    posx -= 0x10000L;
slouken@2262
   386
                }
slouken@2262
   387
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2262
   388
            }
slouken@2262
   389
            srcpixel = *src;
slouken@2262
   390
            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
slouken@2262
   391
            dstpixel = *dst;
slouken@2262
   392
            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
slouken@2262
   393
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2262
   394
                srcR = (srcR * modulateR) / 255;
slouken@2262
   395
                srcG = (srcG * modulateG) / 255;
slouken@2262
   396
                srcB = (srcB * modulateB) / 255;
slouken@2262
   397
            }
slouken@2262
   398
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2262
   399
                srcA = (srcA * modulateA) / 255;
slouken@2262
   400
            }
slouken@2262
   401
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2262
   402
                /* This goes away if we ever use premultiplied alpha */
slouken@2262
   403
                if (srcA < 255) {
slouken@2262
   404
                    srcR = (srcR * srcA) / 255;
slouken@2262
   405
                    srcG = (srcG * srcA) / 255;
slouken@2262
   406
                    srcB = (srcB * srcA) / 255;
slouken@2262
   407
                }
slouken@2262
   408
            }
slouken@5184
   409
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2262
   410
            case SDL_COPY_BLEND:
slouken@2262
   411
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2262
   412
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2262
   413
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
   414
                dstA = srcA + ((255 - srcA) * dstA) / 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;
slouken@2262
   488
slouken@2262
   489
    while (info->dst_h--) {
slouken@2262
   490
        Uint32 *src = (Uint32 *)info->src;
slouken@2262
   491
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2262
   492
        int n = info->dst_w;
slouken@2262
   493
        while (n--) {
slouken@2262
   494
            srcpixel = *src;
slouken@2262
   495
            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
slouken@2262
   496
            dstpixel = *dst;
slouken@2262
   497
            dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
slouken@2262
   498
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2262
   499
                /* This goes away if we ever use premultiplied alpha */
slouken@2262
   500
                if (srcA < 255) {
slouken@2262
   501
                    srcR = (srcR * srcA) / 255;
slouken@2262
   502
                    srcG = (srcG * srcA) / 255;
slouken@2262
   503
                    srcB = (srcB * srcA) / 255;
slouken@2262
   504
                }
slouken@2262
   505
            }
slouken@5184
   506
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2262
   507
            case SDL_COPY_BLEND:
slouken@2262
   508
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2262
   509
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2262
   510
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
   511
                dstA = srcA + ((255 - srcA) * dstA) / 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;
slouken@2262
   544
slouken@2262
   545
    srcy = 0;
slouken@2262
   546
    posy = 0;
slouken@2262
   547
    incy = (info->src_h << 16) / info->dst_h;
slouken@2262
   548
    incx = (info->src_w << 16) / info->dst_w;
slouken@2262
   549
slouken@2262
   550
    while (info->dst_h--) {
slouken@5426
   551
        Uint32 *src = 0;
slouken@2262
   552
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2262
   553
        int n = info->dst_w;
slouken@2262
   554
        srcx = -1;
slouken@2262
   555
        posx = 0x10000L;
slouken@2262
   556
        while (posy >= 0x10000L) {
slouken@2262
   557
            ++srcy;
slouken@2262
   558
            posy -= 0x10000L;
slouken@2262
   559
        }
slouken@2262
   560
        while (n--) {
slouken@2262
   561
            if (posx >= 0x10000L) {
slouken@2262
   562
                while (posx >= 0x10000L) {
slouken@2262
   563
                    ++srcx;
slouken@2262
   564
                    posx -= 0x10000L;
slouken@2262
   565
                }
slouken@2262
   566
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2262
   567
            }
slouken@2262
   568
            srcpixel = *src;
slouken@2262
   569
            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
slouken@2262
   570
            dstpixel = *dst;
slouken@2262
   571
            dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
slouken@2262
   572
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2262
   573
                /* This goes away if we ever use premultiplied alpha */
slouken@2262
   574
                if (srcA < 255) {
slouken@2262
   575
                    srcR = (srcR * srcA) / 255;
slouken@2262
   576
                    srcG = (srcG * srcA) / 255;
slouken@2262
   577
                    srcB = (srcB * srcA) / 255;
slouken@2262
   578
                }
slouken@2262
   579
            }
slouken@5184
   580
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2262
   581
            case SDL_COPY_BLEND:
slouken@2262
   582
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2262
   583
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2262
   584
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
   585
                dstA = srcA + ((255 - srcA) * dstA) / 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. */
slouken@2262
   709
slouken@2262
   710
    while (info->dst_h--) {
slouken@2262
   711
        Uint32 *src = (Uint32 *)info->src;
slouken@2262
   712
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2262
   713
        int n = info->dst_w;
slouken@2262
   714
        while (n--) {
slouken@2262
   715
            srcpixel = *src;
slouken@2262
   716
            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
slouken@2262
   717
            dstpixel = *dst;
slouken@2262
   718
            dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
slouken@2262
   719
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2262
   720
                srcR = (srcR * modulateR) / 255;
slouken@2262
   721
                srcG = (srcG * modulateG) / 255;
slouken@2262
   722
                srcB = (srcB * modulateB) / 255;
slouken@2262
   723
            }
slouken@2262
   724
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2262
   725
                srcA = (srcA * modulateA) / 255;
slouken@2262
   726
            }
slouken@2262
   727
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2262
   728
                /* This goes away if we ever use premultiplied alpha */
slouken@2262
   729
                if (srcA < 255) {
slouken@2262
   730
                    srcR = (srcR * srcA) / 255;
slouken@2262
   731
                    srcG = (srcG * srcA) / 255;
slouken@2262
   732
                    srcB = (srcB * srcA) / 255;
slouken@2262
   733
                }
slouken@2262
   734
            }
slouken@5184
   735
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2262
   736
            case SDL_COPY_BLEND:
slouken@2262
   737
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2262
   738
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2262
   739
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
   740
                dstA = srcA + ((255 - srcA) * dstA) / 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. */
slouken@2262
   778
slouken@2262
   779
    srcy = 0;
slouken@2262
   780
    posy = 0;
slouken@2262
   781
    incy = (info->src_h << 16) / info->dst_h;
slouken@2262
   782
    incx = (info->src_w << 16) / info->dst_w;
slouken@2262
   783
slouken@2262
   784
    while (info->dst_h--) {
slouken@5426
   785
        Uint32 *src = 0;
slouken@2262
   786
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2262
   787
        int n = info->dst_w;
slouken@2262
   788
        srcx = -1;
slouken@2262
   789
        posx = 0x10000L;
slouken@2262
   790
        while (posy >= 0x10000L) {
slouken@2262
   791
            ++srcy;
slouken@2262
   792
            posy -= 0x10000L;
slouken@2262
   793
        }
slouken@2262
   794
        while (n--) {
slouken@2262
   795
            if (posx >= 0x10000L) {
slouken@2262
   796
                while (posx >= 0x10000L) {
slouken@2262
   797
                    ++srcx;
slouken@2262
   798
                    posx -= 0x10000L;
slouken@2262
   799
                }
slouken@2262
   800
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2262
   801
            }
slouken@2262
   802
            srcpixel = *src;
slouken@2262
   803
            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
slouken@2262
   804
            dstpixel = *dst;
slouken@2262
   805
            dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
slouken@2262
   806
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2262
   807
                srcR = (srcR * modulateR) / 255;
slouken@2262
   808
                srcG = (srcG * modulateG) / 255;
slouken@2262
   809
                srcB = (srcB * modulateB) / 255;
slouken@2262
   810
            }
slouken@2262
   811
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2262
   812
                srcA = (srcA * modulateA) / 255;
slouken@2262
   813
            }
slouken@2262
   814
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2262
   815
                /* This goes away if we ever use premultiplied alpha */
slouken@2262
   816
                if (srcA < 255) {
slouken@2262
   817
                    srcR = (srcR * srcA) / 255;
slouken@2262
   818
                    srcG = (srcG * srcA) / 255;
slouken@2262
   819
                    srcB = (srcB * srcA) / 255;
slouken@2262
   820
                }
slouken@2262
   821
            }
slouken@5184
   822
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2262
   823
            case SDL_COPY_BLEND:
slouken@2262
   824
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2262
   825
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2262
   826
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
   827
                dstA = srcA + ((255 - srcA) * dstA) / 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;
slouken@2800
   901
slouken@2800
   902
    while (info->dst_h--) {
slouken@2800
   903
        Uint32 *src = (Uint32 *)info->src;
slouken@2800
   904
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2800
   905
        int n = info->dst_w;
slouken@2800
   906
        while (n--) {
slouken@2800
   907
            srcpixel = *src;
slouken@2800
   908
            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
slouken@2800
   909
            dstpixel = *dst;
icculus@8659
   910
            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
slouken@2800
   911
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2800
   912
                /* This goes away if we ever use premultiplied alpha */
slouken@2800
   913
                if (srcA < 255) {
slouken@2800
   914
                    srcR = (srcR * srcA) / 255;
slouken@2800
   915
                    srcG = (srcG * srcA) / 255;
slouken@2800
   916
                    srcB = (srcB * srcA) / 255;
slouken@2800
   917
                }
slouken@2800
   918
            }
slouken@5184
   919
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2800
   920
            case SDL_COPY_BLEND:
slouken@2800
   921
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2800
   922
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2800
   923
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
   924
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2800
   925
                break;
slouken@2800
   926
            case SDL_COPY_ADD:
slouken@2800
   927
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2800
   928
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2800
   929
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2800
   930
                break;
slouken@5184
   931
            case SDL_COPY_MOD:
slouken@5184
   932
                dstR = (srcR * dstR) / 255;
slouken@5184
   933
                dstG = (srcG * dstG) / 255;
slouken@5184
   934
                dstB = (srcB * dstB) / 255;
slouken@5184
   935
                break;
slouken@2800
   936
            }
slouken@2800
   937
            dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
slouken@2800
   938
            *dst = dstpixel;
slouken@2800
   939
            ++src;
slouken@2800
   940
            ++dst;
slouken@2800
   941
        }
slouken@2800
   942
        info->src += info->src_pitch;
slouken@2800
   943
        info->dst += info->dst_pitch;
slouken@2800
   944
    }
slouken@2800
   945
}
slouken@2800
   946
slouken@2800
   947
static void SDL_Blit_RGB888_ARGB8888_Blend_Scale(SDL_BlitInfo *info)
slouken@2800
   948
{
slouken@2800
   949
    const int flags = info->flags;
slouken@2800
   950
    Uint32 srcpixel;
slouken@2800
   951
    Uint32 srcR, srcG, srcB, srcA;
slouken@2800
   952
    Uint32 dstpixel;
slouken@2800
   953
    Uint32 dstR, dstG, dstB, dstA;
slouken@2800
   954
    int srcy, srcx;
slouken@2800
   955
    int posy, posx;
slouken@2800
   956
    int incy, incx;
slouken@2800
   957
slouken@2800
   958
    srcy = 0;
slouken@2800
   959
    posy = 0;
slouken@2800
   960
    incy = (info->src_h << 16) / info->dst_h;
slouken@2800
   961
    incx = (info->src_w << 16) / info->dst_w;
slouken@2800
   962
slouken@2800
   963
    while (info->dst_h--) {
slouken@5426
   964
        Uint32 *src = 0;
slouken@2800
   965
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2800
   966
        int n = info->dst_w;
slouken@2800
   967
        srcx = -1;
slouken@2800
   968
        posx = 0x10000L;
slouken@2800
   969
        while (posy >= 0x10000L) {
slouken@2800
   970
            ++srcy;
slouken@2800
   971
            posy -= 0x10000L;
slouken@2800
   972
        }
slouken@2800
   973
        while (n--) {
slouken@2800
   974
            if (posx >= 0x10000L) {
slouken@2800
   975
                while (posx >= 0x10000L) {
slouken@2800
   976
                    ++srcx;
slouken@2800
   977
                    posx -= 0x10000L;
slouken@2800
   978
                }
slouken@2800
   979
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2800
   980
            }
slouken@2800
   981
            srcpixel = *src;
slouken@2800
   982
            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
slouken@2800
   983
            dstpixel = *dst;
icculus@8659
   984
            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
slouken@2800
   985
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2800
   986
                /* This goes away if we ever use premultiplied alpha */
slouken@2800
   987
                if (srcA < 255) {
slouken@2800
   988
                    srcR = (srcR * srcA) / 255;
slouken@2800
   989
                    srcG = (srcG * srcA) / 255;
slouken@2800
   990
                    srcB = (srcB * srcA) / 255;
slouken@2800
   991
                }
slouken@2800
   992
            }
slouken@5184
   993
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2800
   994
            case SDL_COPY_BLEND:
slouken@2800
   995
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2800
   996
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2800
   997
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
   998
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2800
   999
                break;
slouken@2800
  1000
            case SDL_COPY_ADD:
slouken@2800
  1001
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2800
  1002
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2800
  1003
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2800
  1004
                break;
slouken@5184
  1005
            case SDL_COPY_MOD:
slouken@5184
  1006
                dstR = (srcR * dstR) / 255;
slouken@5184
  1007
                dstG = (srcG * dstG) / 255;
slouken@5184
  1008
                dstB = (srcB * dstB) / 255;
slouken@5184
  1009
                break;
slouken@2800
  1010
            }
slouken@2800
  1011
            dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
slouken@2800
  1012
            *dst = dstpixel;
slouken@2800
  1013
            posx += incx;
slouken@2800
  1014
            ++dst;
slouken@2800
  1015
        }
slouken@2800
  1016
        posy += incy;
slouken@2800
  1017
        info->dst += info->dst_pitch;
slouken@2800
  1018
    }
slouken@2800
  1019
}
slouken@2800
  1020
slouken@2800
  1021
static void SDL_Blit_RGB888_ARGB8888_Modulate(SDL_BlitInfo *info)
slouken@2800
  1022
{
slouken@2800
  1023
    const int flags = info->flags;
slouken@2800
  1024
    const Uint32 modulateR = info->r;
slouken@2800
  1025
    const Uint32 modulateG = info->g;
slouken@2800
  1026
    const Uint32 modulateB = info->b;
slouken@2800
  1027
    const Uint32 modulateA = info->a;
slouken@2800
  1028
    Uint32 pixel;
slouken@2800
  1029
    Uint32 R, G, B, A;
icculus@8659
  1030
    (void) A;  /* not all formats use alpha. */
icculus@8659
  1031
    (void) modulateA;  /* not all formats use alpha. */
slouken@2800
  1032
slouken@2800
  1033
    while (info->dst_h--) {
slouken@2800
  1034
        Uint32 *src = (Uint32 *)info->src;
slouken@2800
  1035
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2800
  1036
        int n = info->dst_w;
slouken@2800
  1037
        while (n--) {
slouken@2800
  1038
            pixel = *src;
slouken@2800
  1039
            R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF;
slouken@2800
  1040
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2800
  1041
                R = (R * modulateR) / 255;
slouken@2800
  1042
                G = (G * modulateG) / 255;
slouken@2800
  1043
                B = (B * modulateB) / 255;
slouken@2800
  1044
            }
slouken@2800
  1045
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2800
  1046
                A = (A * modulateA) / 255;
slouken@2800
  1047
            }
slouken@2800
  1048
            pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
slouken@2800
  1049
            *dst = pixel;
slouken@2800
  1050
            ++src;
slouken@2800
  1051
            ++dst;
slouken@2800
  1052
        }
slouken@2800
  1053
        info->src += info->src_pitch;
slouken@2800
  1054
        info->dst += info->dst_pitch;
slouken@2800
  1055
    }
slouken@2800
  1056
}
slouken@2800
  1057
slouken@2800
  1058
static void SDL_Blit_RGB888_ARGB8888_Modulate_Scale(SDL_BlitInfo *info)
slouken@2800
  1059
{
slouken@2800
  1060
    const int flags = info->flags;
slouken@2800
  1061
    const Uint32 modulateR = info->r;
slouken@2800
  1062
    const Uint32 modulateG = info->g;
slouken@2800
  1063
    const Uint32 modulateB = info->b;
slouken@2800
  1064
    const Uint32 modulateA = info->a;
slouken@2800
  1065
    Uint32 pixel;
slouken@2800
  1066
    Uint32 R, G, B, A;
slouken@2800
  1067
    int srcy, srcx;
slouken@2800
  1068
    int posy, posx;
slouken@2800
  1069
    int incy, incx;
icculus@8659
  1070
    (void) A;  /* not all formats use alpha. */
icculus@8659
  1071
    (void) modulateA;  /* not all formats use alpha. */
slouken@2800
  1072
slouken@2800
  1073
    srcy = 0;
slouken@2800
  1074
    posy = 0;
slouken@2800
  1075
    incy = (info->src_h << 16) / info->dst_h;
slouken@2800
  1076
    incx = (info->src_w << 16) / info->dst_w;
slouken@2800
  1077
slouken@2800
  1078
    while (info->dst_h--) {
slouken@5426
  1079
        Uint32 *src = 0;
slouken@2800
  1080
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2800
  1081
        int n = info->dst_w;
slouken@2800
  1082
        srcx = -1;
slouken@2800
  1083
        posx = 0x10000L;
slouken@2800
  1084
        while (posy >= 0x10000L) {
slouken@2800
  1085
            ++srcy;
slouken@2800
  1086
            posy -= 0x10000L;
slouken@2800
  1087
        }
slouken@2800
  1088
        while (n--) {
slouken@2800
  1089
            if (posx >= 0x10000L) {
slouken@2800
  1090
                while (posx >= 0x10000L) {
slouken@2800
  1091
                    ++srcx;
slouken@2800
  1092
                    posx -= 0x10000L;
slouken@2800
  1093
                }
slouken@2800
  1094
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2800
  1095
            }
slouken@2800
  1096
            pixel = *src;
slouken@2800
  1097
            R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel; A = 0xFF;
slouken@2800
  1098
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2800
  1099
                R = (R * modulateR) / 255;
slouken@2800
  1100
                G = (G * modulateG) / 255;
slouken@2800
  1101
                B = (B * modulateB) / 255;
slouken@2800
  1102
            }
slouken@2800
  1103
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2800
  1104
                A = (A * modulateA) / 255;
slouken@2800
  1105
            }
slouken@2800
  1106
            pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
slouken@2800
  1107
            *dst = pixel;
slouken@2800
  1108
            posx += incx;
slouken@2800
  1109
            ++dst;
slouken@2800
  1110
        }
slouken@2800
  1111
        posy += incy;
slouken@2800
  1112
        info->dst += info->dst_pitch;
slouken@2800
  1113
    }
slouken@2800
  1114
}
slouken@2800
  1115
slouken@2800
  1116
static void SDL_Blit_RGB888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info)
slouken@2800
  1117
{
slouken@2800
  1118
    const int flags = info->flags;
slouken@2800
  1119
    const Uint32 modulateR = info->r;
slouken@2800
  1120
    const Uint32 modulateG = info->g;
slouken@2800
  1121
    const Uint32 modulateB = info->b;
slouken@2800
  1122
    const Uint32 modulateA = info->a;
slouken@2800
  1123
    Uint32 srcpixel;
slouken@2800
  1124
    Uint32 srcR, srcG, srcB, srcA;
slouken@2800
  1125
    Uint32 dstpixel;
slouken@2800
  1126
    Uint32 dstR, dstG, dstB, dstA;
icculus@8659
  1127
    (void) modulateA;  /* not all formats use alpha. */
slouken@2800
  1128
slouken@2800
  1129
    while (info->dst_h--) {
slouken@2800
  1130
        Uint32 *src = (Uint32 *)info->src;
slouken@2800
  1131
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2800
  1132
        int n = info->dst_w;
slouken@2800
  1133
        while (n--) {
slouken@2800
  1134
            srcpixel = *src;
slouken@2800
  1135
            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
slouken@2800
  1136
            dstpixel = *dst;
icculus@8659
  1137
            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
slouken@2800
  1138
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2800
  1139
                srcR = (srcR * modulateR) / 255;
slouken@2800
  1140
                srcG = (srcG * modulateG) / 255;
slouken@2800
  1141
                srcB = (srcB * modulateB) / 255;
slouken@2800
  1142
            }
slouken@2800
  1143
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2800
  1144
                srcA = (srcA * modulateA) / 255;
slouken@2800
  1145
            }
slouken@2800
  1146
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2800
  1147
                /* This goes away if we ever use premultiplied alpha */
slouken@2800
  1148
                if (srcA < 255) {
slouken@2800
  1149
                    srcR = (srcR * srcA) / 255;
slouken@2800
  1150
                    srcG = (srcG * srcA) / 255;
slouken@2800
  1151
                    srcB = (srcB * srcA) / 255;
slouken@2800
  1152
                }
slouken@2800
  1153
            }
slouken@5184
  1154
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2800
  1155
            case SDL_COPY_BLEND:
slouken@2800
  1156
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2800
  1157
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2800
  1158
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
  1159
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2800
  1160
                break;
slouken@2800
  1161
            case SDL_COPY_ADD:
slouken@2800
  1162
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2800
  1163
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2800
  1164
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2800
  1165
                break;
slouken@5184
  1166
            case SDL_COPY_MOD:
slouken@5184
  1167
                dstR = (srcR * dstR) / 255;
slouken@5184
  1168
                dstG = (srcG * dstG) / 255;
slouken@5184
  1169
                dstB = (srcB * dstB) / 255;
slouken@5184
  1170
                break;
slouken@2800
  1171
            }
slouken@2800
  1172
            dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
slouken@2800
  1173
            *dst = dstpixel;
slouken@2800
  1174
            ++src;
slouken@2800
  1175
            ++dst;
slouken@2800
  1176
        }
slouken@2800
  1177
        info->src += info->src_pitch;
slouken@2800
  1178
        info->dst += info->dst_pitch;
slouken@2800
  1179
    }
slouken@2800
  1180
}
slouken@2800
  1181
slouken@2800
  1182
static void SDL_Blit_RGB888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info)
slouken@2800
  1183
{
slouken@2800
  1184
    const int flags = info->flags;
slouken@2800
  1185
    const Uint32 modulateR = info->r;
slouken@2800
  1186
    const Uint32 modulateG = info->g;
slouken@2800
  1187
    const Uint32 modulateB = info->b;
slouken@2800
  1188
    const Uint32 modulateA = info->a;
slouken@2800
  1189
    Uint32 srcpixel;
slouken@2800
  1190
    Uint32 srcR, srcG, srcB, srcA;
slouken@2800
  1191
    Uint32 dstpixel;
slouken@2800
  1192
    Uint32 dstR, dstG, dstB, dstA;
slouken@2800
  1193
    int srcy, srcx;
slouken@2800
  1194
    int posy, posx;
slouken@2800
  1195
    int incy, incx;
icculus@8659
  1196
    (void) modulateA;  /* not all formats use alpha. */
slouken@2800
  1197
slouken@2800
  1198
    srcy = 0;
slouken@2800
  1199
    posy = 0;
slouken@2800
  1200
    incy = (info->src_h << 16) / info->dst_h;
slouken@2800
  1201
    incx = (info->src_w << 16) / info->dst_w;
slouken@2800
  1202
slouken@2800
  1203
    while (info->dst_h--) {
slouken@5426
  1204
        Uint32 *src = 0;
slouken@2800
  1205
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2800
  1206
        int n = info->dst_w;
slouken@2800
  1207
        srcx = -1;
slouken@2800
  1208
        posx = 0x10000L;
slouken@2800
  1209
        while (posy >= 0x10000L) {
slouken@2800
  1210
            ++srcy;
slouken@2800
  1211
            posy -= 0x10000L;
slouken@2800
  1212
        }
slouken@2800
  1213
        while (n--) {
slouken@2800
  1214
            if (posx >= 0x10000L) {
slouken@2800
  1215
                while (posx >= 0x10000L) {
slouken@2800
  1216
                    ++srcx;
slouken@2800
  1217
                    posx -= 0x10000L;
slouken@2800
  1218
                }
slouken@2800
  1219
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2800
  1220
            }
slouken@2800
  1221
            srcpixel = *src;
slouken@2800
  1222
            srcR = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcB = (Uint8)srcpixel; srcA = 0xFF;
slouken@2800
  1223
            dstpixel = *dst;
icculus@8659
  1224
            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
slouken@2800
  1225
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2800
  1226
                srcR = (srcR * modulateR) / 255;
slouken@2800
  1227
                srcG = (srcG * modulateG) / 255;
slouken@2800
  1228
                srcB = (srcB * modulateB) / 255;
slouken@2800
  1229
            }
slouken@2800
  1230
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2800
  1231
                srcA = (srcA * modulateA) / 255;
slouken@2800
  1232
            }
slouken@2800
  1233
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2800
  1234
                /* This goes away if we ever use premultiplied alpha */
slouken@2800
  1235
                if (srcA < 255) {
slouken@2800
  1236
                    srcR = (srcR * srcA) / 255;
slouken@2800
  1237
                    srcG = (srcG * srcA) / 255;
slouken@2800
  1238
                    srcB = (srcB * srcA) / 255;
slouken@2800
  1239
                }
slouken@2800
  1240
            }
slouken@5184
  1241
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2800
  1242
            case SDL_COPY_BLEND:
slouken@2800
  1243
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2800
  1244
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2800
  1245
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
  1246
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2800
  1247
                break;
slouken@2800
  1248
            case SDL_COPY_ADD:
slouken@2800
  1249
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2800
  1250
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2800
  1251
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2800
  1252
                break;
slouken@5184
  1253
            case SDL_COPY_MOD:
slouken@5184
  1254
                dstR = (srcR * dstR) / 255;
slouken@5184
  1255
                dstG = (srcG * dstG) / 255;
slouken@5184
  1256
                dstB = (srcB * dstB) / 255;
slouken@5184
  1257
                break;
slouken@2800
  1258
            }
slouken@2800
  1259
            dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
slouken@2800
  1260
            *dst = dstpixel;
slouken@2800
  1261
            posx += incx;
slouken@2800
  1262
            ++dst;
slouken@2800
  1263
        }
slouken@2800
  1264
        posy += incy;
slouken@2800
  1265
        info->dst += info->dst_pitch;
slouken@2800
  1266
    }
slouken@2800
  1267
}
slouken@2800
  1268
slouken@2263
  1269
static void SDL_Blit_BGR888_RGB888_Scale(SDL_BlitInfo *info)
slouken@2262
  1270
{
slouken@2262
  1271
    Uint32 pixel;
slouken@2262
  1272
    Uint32 R, G, B, A;
slouken@2262
  1273
    int srcy, srcx;
slouken@2262
  1274
    int posy, posx;
slouken@2262
  1275
    int incy, incx;
icculus@8659
  1276
    (void) A;  /* not all formats use alpha. */
slouken@2262
  1277
slouken@2262
  1278
    srcy = 0;
slouken@2262
  1279
    posy = 0;
slouken@2262
  1280
    incy = (info->src_h << 16) / info->dst_h;
slouken@2262
  1281
    incx = (info->src_w << 16) / info->dst_w;
slouken@2262
  1282
slouken@2262
  1283
    while (info->dst_h--) {
slouken@5426
  1284
        Uint32 *src = 0;
slouken@2262
  1285
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2262
  1286
        int n = info->dst_w;
slouken@2262
  1287
        srcx = -1;
slouken@2262
  1288
        posx = 0x10000L;
slouken@2262
  1289
        while (posy >= 0x10000L) {
slouken@2262
  1290
            ++srcy;
slouken@2262
  1291
            posy -= 0x10000L;
slouken@2262
  1292
        }
slouken@2262
  1293
        while (n--) {
slouken@2262
  1294
            if (posx >= 0x10000L) {
slouken@2262
  1295
                while (posx >= 0x10000L) {
slouken@2262
  1296
                    ++srcx;
slouken@2262
  1297
                    posx -= 0x10000L;
slouken@2262
  1298
                }
slouken@2262
  1299
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2262
  1300
            }
slouken@2262
  1301
            pixel = *src;
icculus@8659
  1302
            B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
slouken@2262
  1303
            pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
slouken@2262
  1304
            *dst = pixel;
slouken@2262
  1305
            posx += incx;
slouken@2262
  1306
            ++dst;
slouken@2262
  1307
        }
slouken@2262
  1308
        posy += incy;
slouken@2262
  1309
        info->dst += info->dst_pitch;
slouken@2262
  1310
    }
slouken@2262
  1311
}
slouken@2262
  1312
slouken@2263
  1313
static void SDL_Blit_BGR888_RGB888_Blend(SDL_BlitInfo *info)
slouken@2262
  1314
{
slouken@2262
  1315
    const int flags = info->flags;
slouken@2262
  1316
    Uint32 srcpixel;
slouken@2262
  1317
    Uint32 srcR, srcG, srcB, srcA;
slouken@2262
  1318
    Uint32 dstpixel;
slouken@2262
  1319
    Uint32 dstR, dstG, dstB, dstA;
slouken@2262
  1320
slouken@2262
  1321
    while (info->dst_h--) {
slouken@2262
  1322
        Uint32 *src = (Uint32 *)info->src;
slouken@2262
  1323
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2262
  1324
        int n = info->dst_w;
slouken@2262
  1325
        while (n--) {
slouken@2262
  1326
            srcpixel = *src;
slouken@2262
  1327
            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
slouken@2262
  1328
            dstpixel = *dst;
slouken@2262
  1329
            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
slouken@2262
  1330
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2262
  1331
                /* This goes away if we ever use premultiplied alpha */
slouken@2262
  1332
                if (srcA < 255) {
slouken@2262
  1333
                    srcR = (srcR * srcA) / 255;
slouken@2262
  1334
                    srcG = (srcG * srcA) / 255;
slouken@2262
  1335
                    srcB = (srcB * srcA) / 255;
slouken@2262
  1336
                }
slouken@2262
  1337
            }
slouken@5184
  1338
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2262
  1339
            case SDL_COPY_BLEND:
slouken@2262
  1340
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2262
  1341
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2262
  1342
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
  1343
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2262
  1344
                break;
slouken@2262
  1345
            case SDL_COPY_ADD:
slouken@2262
  1346
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2262
  1347
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2262
  1348
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2262
  1349
                break;
slouken@5184
  1350
            case SDL_COPY_MOD:
slouken@5184
  1351
                dstR = (srcR * dstR) / 255;
slouken@5184
  1352
                dstG = (srcG * dstG) / 255;
slouken@5184
  1353
                dstB = (srcB * dstB) / 255;
slouken@5184
  1354
                break;
slouken@2262
  1355
            }
slouken@2262
  1356
            dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
slouken@2262
  1357
            *dst = dstpixel;
slouken@2262
  1358
            ++src;
slouken@2262
  1359
            ++dst;
slouken@2262
  1360
        }
slouken@2262
  1361
        info->src += info->src_pitch;
slouken@2262
  1362
        info->dst += info->dst_pitch;
slouken@2262
  1363
    }
slouken@2262
  1364
}
slouken@2262
  1365
slouken@2263
  1366
static void SDL_Blit_BGR888_RGB888_Blend_Scale(SDL_BlitInfo *info)
slouken@2262
  1367
{
slouken@2262
  1368
    const int flags = info->flags;
slouken@2262
  1369
    Uint32 srcpixel;
slouken@2262
  1370
    Uint32 srcR, srcG, srcB, srcA;
slouken@2262
  1371
    Uint32 dstpixel;
slouken@2262
  1372
    Uint32 dstR, dstG, dstB, dstA;
slouken@2262
  1373
    int srcy, srcx;
slouken@2262
  1374
    int posy, posx;
slouken@2262
  1375
    int incy, incx;
slouken@2262
  1376
slouken@2262
  1377
    srcy = 0;
slouken@2262
  1378
    posy = 0;
slouken@2262
  1379
    incy = (info->src_h << 16) / info->dst_h;
slouken@2262
  1380
    incx = (info->src_w << 16) / info->dst_w;
slouken@2262
  1381
slouken@2262
  1382
    while (info->dst_h--) {
slouken@5426
  1383
        Uint32 *src = 0;
slouken@2262
  1384
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2262
  1385
        int n = info->dst_w;
slouken@2262
  1386
        srcx = -1;
slouken@2262
  1387
        posx = 0x10000L;
slouken@2262
  1388
        while (posy >= 0x10000L) {
slouken@2262
  1389
            ++srcy;
slouken@2262
  1390
            posy -= 0x10000L;
slouken@2262
  1391
        }
slouken@2262
  1392
        while (n--) {
slouken@2262
  1393
            if (posx >= 0x10000L) {
slouken@2262
  1394
                while (posx >= 0x10000L) {
slouken@2262
  1395
                    ++srcx;
slouken@2262
  1396
                    posx -= 0x10000L;
slouken@2262
  1397
                }
slouken@2262
  1398
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2262
  1399
            }
slouken@2262
  1400
            srcpixel = *src;
slouken@2262
  1401
            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
slouken@2262
  1402
            dstpixel = *dst;
slouken@2262
  1403
            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
slouken@2262
  1404
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2262
  1405
                /* This goes away if we ever use premultiplied alpha */
slouken@2262
  1406
                if (srcA < 255) {
slouken@2262
  1407
                    srcR = (srcR * srcA) / 255;
slouken@2262
  1408
                    srcG = (srcG * srcA) / 255;
slouken@2262
  1409
                    srcB = (srcB * srcA) / 255;
slouken@2262
  1410
                }
slouken@2262
  1411
            }
slouken@5184
  1412
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2262
  1413
            case SDL_COPY_BLEND:
slouken@2262
  1414
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2262
  1415
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2262
  1416
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
  1417
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2262
  1418
                break;
slouken@2262
  1419
            case SDL_COPY_ADD:
slouken@2262
  1420
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2262
  1421
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2262
  1422
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2262
  1423
                break;
slouken@5184
  1424
            case SDL_COPY_MOD:
slouken@5184
  1425
                dstR = (srcR * dstR) / 255;
slouken@5184
  1426
                dstG = (srcG * dstG) / 255;
slouken@5184
  1427
                dstB = (srcB * dstB) / 255;
slouken@5184
  1428
                break;
slouken@2262
  1429
            }
slouken@2262
  1430
            dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
slouken@2262
  1431
            *dst = dstpixel;
slouken@2262
  1432
            posx += incx;
slouken@2262
  1433
            ++dst;
slouken@2262
  1434
        }
slouken@2262
  1435
        posy += incy;
slouken@2262
  1436
        info->dst += info->dst_pitch;
slouken@2262
  1437
    }
slouken@2262
  1438
}
slouken@2262
  1439
slouken@2263
  1440
static void SDL_Blit_BGR888_RGB888_Modulate(SDL_BlitInfo *info)
slouken@2262
  1441
{
slouken@2262
  1442
    const int flags = info->flags;
slouken@2262
  1443
    const Uint32 modulateR = info->r;
slouken@2262
  1444
    const Uint32 modulateG = info->g;
slouken@2262
  1445
    const Uint32 modulateB = info->b;
slouken@2262
  1446
    const Uint32 modulateA = info->a;
slouken@2262
  1447
    Uint32 pixel;
slouken@2262
  1448
    Uint32 R, G, B, A;
icculus@8659
  1449
    (void) A;  /* not all formats use alpha. */
icculus@8659
  1450
    (void) modulateA;  /* not all formats use alpha. */
slouken@2262
  1451
slouken@2262
  1452
    while (info->dst_h--) {
slouken@2262
  1453
        Uint32 *src = (Uint32 *)info->src;
slouken@2262
  1454
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2262
  1455
        int n = info->dst_w;
slouken@2262
  1456
        while (n--) {
slouken@2262
  1457
            pixel = *src;
icculus@8659
  1458
            B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
slouken@2262
  1459
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2262
  1460
                R = (R * modulateR) / 255;
slouken@2262
  1461
                G = (G * modulateG) / 255;
slouken@2262
  1462
                B = (B * modulateB) / 255;
slouken@2262
  1463
            }
slouken@2262
  1464
            pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
slouken@2262
  1465
            *dst = pixel;
slouken@2262
  1466
            ++src;
slouken@2262
  1467
            ++dst;
slouken@2262
  1468
        }
slouken@2262
  1469
        info->src += info->src_pitch;
slouken@2262
  1470
        info->dst += info->dst_pitch;
slouken@2262
  1471
    }
slouken@2262
  1472
}
slouken@2262
  1473
slouken@2263
  1474
static void SDL_Blit_BGR888_RGB888_Modulate_Scale(SDL_BlitInfo *info)
slouken@2262
  1475
{
slouken@2262
  1476
    const int flags = info->flags;
slouken@2262
  1477
    const Uint32 modulateR = info->r;
slouken@2262
  1478
    const Uint32 modulateG = info->g;
slouken@2262
  1479
    const Uint32 modulateB = info->b;
slouken@2262
  1480
    const Uint32 modulateA = info->a;
slouken@2262
  1481
    Uint32 pixel;
slouken@2262
  1482
    Uint32 R, G, B, A;
slouken@2262
  1483
    int srcy, srcx;
slouken@2262
  1484
    int posy, posx;
slouken@2262
  1485
    int incy, incx;
icculus@8659
  1486
    (void) A;  /* not all formats use alpha. */
icculus@8659
  1487
    (void) modulateA;  /* not all formats use alpha. */
slouken@2262
  1488
slouken@2262
  1489
    srcy = 0;
slouken@2262
  1490
    posy = 0;
slouken@2262
  1491
    incy = (info->src_h << 16) / info->dst_h;
slouken@2262
  1492
    incx = (info->src_w << 16) / info->dst_w;
slouken@2262
  1493
slouken@2262
  1494
    while (info->dst_h--) {
slouken@5426
  1495
        Uint32 *src = 0;
slouken@2262
  1496
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2262
  1497
        int n = info->dst_w;
slouken@2262
  1498
        srcx = -1;
slouken@2262
  1499
        posx = 0x10000L;
slouken@2262
  1500
        while (posy >= 0x10000L) {
slouken@2262
  1501
            ++srcy;
slouken@2262
  1502
            posy -= 0x10000L;
slouken@2262
  1503
        }
slouken@2262
  1504
        while (n--) {
slouken@2262
  1505
            if (posx >= 0x10000L) {
slouken@2262
  1506
                while (posx >= 0x10000L) {
slouken@2262
  1507
                    ++srcx;
slouken@2262
  1508
                    posx -= 0x10000L;
slouken@2262
  1509
                }
slouken@2262
  1510
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2262
  1511
            }
slouken@2262
  1512
            pixel = *src;
icculus@8659
  1513
            B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
slouken@2262
  1514
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2262
  1515
                R = (R * modulateR) / 255;
slouken@2262
  1516
                G = (G * modulateG) / 255;
slouken@2262
  1517
                B = (B * modulateB) / 255;
slouken@2262
  1518
            }
slouken@2262
  1519
            pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
slouken@2262
  1520
            *dst = pixel;
slouken@2262
  1521
            posx += incx;
slouken@2262
  1522
            ++dst;
slouken@2262
  1523
        }
slouken@2262
  1524
        posy += incy;
slouken@2262
  1525
        info->dst += info->dst_pitch;
slouken@2262
  1526
    }
slouken@2262
  1527
}
slouken@2262
  1528
slouken@2263
  1529
static void SDL_Blit_BGR888_RGB888_Modulate_Blend(SDL_BlitInfo *info)
slouken@2262
  1530
{
slouken@2262
  1531
    const int flags = info->flags;
slouken@2262
  1532
    const Uint32 modulateR = info->r;
slouken@2262
  1533
    const Uint32 modulateG = info->g;
slouken@2262
  1534
    const Uint32 modulateB = info->b;
slouken@2262
  1535
    const Uint32 modulateA = info->a;
slouken@2262
  1536
    Uint32 srcpixel;
slouken@2262
  1537
    Uint32 srcR, srcG, srcB, srcA;
slouken@2262
  1538
    Uint32 dstpixel;
slouken@2262
  1539
    Uint32 dstR, dstG, dstB, dstA;
icculus@8659
  1540
    (void) modulateA;  /* not all formats use alpha. */
slouken@2262
  1541
slouken@2262
  1542
    while (info->dst_h--) {
slouken@2262
  1543
        Uint32 *src = (Uint32 *)info->src;
slouken@2262
  1544
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2262
  1545
        int n = info->dst_w;
slouken@2262
  1546
        while (n--) {
slouken@2262
  1547
            srcpixel = *src;
slouken@2262
  1548
            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
slouken@2262
  1549
            dstpixel = *dst;
slouken@2262
  1550
            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
slouken@2262
  1551
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2262
  1552
                srcR = (srcR * modulateR) / 255;
slouken@2262
  1553
                srcG = (srcG * modulateG) / 255;
slouken@2262
  1554
                srcB = (srcB * modulateB) / 255;
slouken@2262
  1555
            }
slouken@2262
  1556
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2262
  1557
                srcA = (srcA * modulateA) / 255;
slouken@2262
  1558
            }
slouken@2262
  1559
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2262
  1560
                /* This goes away if we ever use premultiplied alpha */
slouken@2262
  1561
                if (srcA < 255) {
slouken@2262
  1562
                    srcR = (srcR * srcA) / 255;
slouken@2262
  1563
                    srcG = (srcG * srcA) / 255;
slouken@2262
  1564
                    srcB = (srcB * srcA) / 255;
slouken@2262
  1565
                }
slouken@2262
  1566
            }
slouken@5184
  1567
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2262
  1568
            case SDL_COPY_BLEND:
slouken@2262
  1569
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2262
  1570
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2262
  1571
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
  1572
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2262
  1573
                break;
slouken@2262
  1574
            case SDL_COPY_ADD:
slouken@2262
  1575
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2262
  1576
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2262
  1577
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2262
  1578
                break;
slouken@5184
  1579
            case SDL_COPY_MOD:
slouken@5184
  1580
                dstR = (srcR * dstR) / 255;
slouken@5184
  1581
                dstG = (srcG * dstG) / 255;
slouken@5184
  1582
                dstB = (srcB * dstB) / 255;
slouken@5184
  1583
                break;
slouken@2262
  1584
            }
slouken@2262
  1585
            dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
slouken@2262
  1586
            *dst = dstpixel;
slouken@2262
  1587
            ++src;
slouken@2262
  1588
            ++dst;
slouken@2262
  1589
        }
slouken@2262
  1590
        info->src += info->src_pitch;
slouken@2262
  1591
        info->dst += info->dst_pitch;
slouken@2262
  1592
    }
slouken@2262
  1593
}
slouken@2262
  1594
slouken@2263
  1595
static void SDL_Blit_BGR888_RGB888_Modulate_Blend_Scale(SDL_BlitInfo *info)
slouken@2262
  1596
{
slouken@2262
  1597
    const int flags = info->flags;
slouken@2262
  1598
    const Uint32 modulateR = info->r;
slouken@2262
  1599
    const Uint32 modulateG = info->g;
slouken@2262
  1600
    const Uint32 modulateB = info->b;
slouken@2262
  1601
    const Uint32 modulateA = info->a;
slouken@2262
  1602
    Uint32 srcpixel;
slouken@2262
  1603
    Uint32 srcR, srcG, srcB, srcA;
slouken@2262
  1604
    Uint32 dstpixel;
slouken@2262
  1605
    Uint32 dstR, dstG, dstB, dstA;
slouken@2262
  1606
    int srcy, srcx;
slouken@2262
  1607
    int posy, posx;
slouken@2262
  1608
    int incy, incx;
icculus@8659
  1609
    (void) modulateA;  /* not all formats use alpha. */
slouken@2262
  1610
slouken@2262
  1611
    srcy = 0;
slouken@2262
  1612
    posy = 0;
slouken@2262
  1613
    incy = (info->src_h << 16) / info->dst_h;
slouken@2262
  1614
    incx = (info->src_w << 16) / info->dst_w;
slouken@2262
  1615
slouken@2262
  1616
    while (info->dst_h--) {
slouken@5426
  1617
        Uint32 *src = 0;
slouken@2262
  1618
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2262
  1619
        int n = info->dst_w;
slouken@2262
  1620
        srcx = -1;
slouken@2262
  1621
        posx = 0x10000L;
slouken@2262
  1622
        while (posy >= 0x10000L) {
slouken@2262
  1623
            ++srcy;
slouken@2262
  1624
            posy -= 0x10000L;
slouken@2262
  1625
        }
slouken@2262
  1626
        while (n--) {
slouken@2262
  1627
            if (posx >= 0x10000L) {
slouken@2262
  1628
                while (posx >= 0x10000L) {
slouken@2262
  1629
                    ++srcx;
slouken@2262
  1630
                    posx -= 0x10000L;
slouken@2262
  1631
                }
slouken@2262
  1632
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2262
  1633
            }
slouken@2262
  1634
            srcpixel = *src;
slouken@2262
  1635
            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
slouken@2262
  1636
            dstpixel = *dst;
slouken@2262
  1637
            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = 0xFF;
slouken@2262
  1638
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2262
  1639
                srcR = (srcR * modulateR) / 255;
slouken@2262
  1640
                srcG = (srcG * modulateG) / 255;
slouken@2262
  1641
                srcB = (srcB * modulateB) / 255;
slouken@2262
  1642
            }
slouken@2262
  1643
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2262
  1644
                srcA = (srcA * modulateA) / 255;
slouken@2262
  1645
            }
slouken@2262
  1646
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2262
  1647
                /* This goes away if we ever use premultiplied alpha */
slouken@2262
  1648
                if (srcA < 255) {
slouken@2262
  1649
                    srcR = (srcR * srcA) / 255;
slouken@2262
  1650
                    srcG = (srcG * srcA) / 255;
slouken@2262
  1651
                    srcB = (srcB * srcA) / 255;
slouken@2262
  1652
                }
slouken@2262
  1653
            }
slouken@5184
  1654
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2262
  1655
            case SDL_COPY_BLEND:
slouken@2262
  1656
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2262
  1657
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2262
  1658
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
  1659
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2262
  1660
                break;
slouken@2262
  1661
            case SDL_COPY_ADD:
slouken@2262
  1662
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2262
  1663
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2262
  1664
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2262
  1665
                break;
slouken@5184
  1666
            case SDL_COPY_MOD:
slouken@5184
  1667
                dstR = (srcR * dstR) / 255;
slouken@5184
  1668
                dstG = (srcG * dstG) / 255;
slouken@5184
  1669
                dstB = (srcB * dstB) / 255;
slouken@5184
  1670
                break;
slouken@2262
  1671
            }
slouken@2262
  1672
            dstpixel = ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
slouken@2262
  1673
            *dst = dstpixel;
slouken@2262
  1674
            posx += incx;
slouken@2262
  1675
            ++dst;
slouken@2262
  1676
        }
slouken@2262
  1677
        posy += incy;
slouken@2262
  1678
        info->dst += info->dst_pitch;
slouken@2262
  1679
    }
slouken@2262
  1680
}
slouken@2262
  1681
slouken@2263
  1682
static void SDL_Blit_BGR888_BGR888_Scale(SDL_BlitInfo *info)
slouken@2262
  1683
{
slouken@2262
  1684
    int srcy, srcx;
slouken@2262
  1685
    int posy, posx;
slouken@2262
  1686
    int incy, incx;
slouken@2262
  1687
slouken@2262
  1688
    srcy = 0;
slouken@2262
  1689
    posy = 0;
slouken@2262
  1690
    incy = (info->src_h << 16) / info->dst_h;
slouken@2262
  1691
    incx = (info->src_w << 16) / info->dst_w;
slouken@2262
  1692
slouken@2262
  1693
    while (info->dst_h--) {
slouken@5426
  1694
        Uint32 *src = 0;
slouken@2262
  1695
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2262
  1696
        int n = info->dst_w;
slouken@2262
  1697
        srcx = -1;
slouken@2262
  1698
        posx = 0x10000L;
slouken@2262
  1699
        while (posy >= 0x10000L) {
slouken@2262
  1700
            ++srcy;
slouken@2262
  1701
            posy -= 0x10000L;
slouken@2262
  1702
        }
slouken@2262
  1703
        while (n--) {
slouken@2262
  1704
            if (posx >= 0x10000L) {
slouken@2262
  1705
                while (posx >= 0x10000L) {
slouken@2262
  1706
                    ++srcx;
slouken@2262
  1707
                    posx -= 0x10000L;
slouken@2262
  1708
                }
slouken@2262
  1709
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2262
  1710
            }
slouken@2262
  1711
            *dst = *src;
slouken@2262
  1712
            posx += incx;
slouken@2262
  1713
            ++dst;
slouken@2262
  1714
        }
slouken@2262
  1715
        posy += incy;
slouken@2262
  1716
        info->dst += info->dst_pitch;
slouken@2262
  1717
    }
slouken@2262
  1718
}
slouken@2262
  1719
slouken@2263
  1720
static void SDL_Blit_BGR888_BGR888_Blend(SDL_BlitInfo *info)
slouken@2262
  1721
{
slouken@2262
  1722
    const int flags = info->flags;
slouken@2262
  1723
    Uint32 srcpixel;
slouken@2262
  1724
    Uint32 srcR, srcG, srcB, srcA;
slouken@2262
  1725
    Uint32 dstpixel;
slouken@2262
  1726
    Uint32 dstR, dstG, dstB, dstA;
slouken@2262
  1727
slouken@2262
  1728
    while (info->dst_h--) {
slouken@2262
  1729
        Uint32 *src = (Uint32 *)info->src;
slouken@2262
  1730
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2262
  1731
        int n = info->dst_w;
slouken@2262
  1732
        while (n--) {
slouken@2262
  1733
            srcpixel = *src;
slouken@2262
  1734
            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
slouken@2262
  1735
            dstpixel = *dst;
slouken@2262
  1736
            dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
slouken@2262
  1737
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2262
  1738
                /* This goes away if we ever use premultiplied alpha */
slouken@2262
  1739
                if (srcA < 255) {
slouken@2262
  1740
                    srcR = (srcR * srcA) / 255;
slouken@2262
  1741
                    srcG = (srcG * srcA) / 255;
slouken@2262
  1742
                    srcB = (srcB * srcA) / 255;
slouken@2262
  1743
                }
slouken@2262
  1744
            }
slouken@5184
  1745
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2262
  1746
            case SDL_COPY_BLEND:
slouken@2262
  1747
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2262
  1748
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2262
  1749
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
  1750
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2262
  1751
                break;
slouken@2262
  1752
            case SDL_COPY_ADD:
slouken@2262
  1753
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2262
  1754
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2262
  1755
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2262
  1756
                break;
slouken@5184
  1757
            case SDL_COPY_MOD:
slouken@5184
  1758
                dstR = (srcR * dstR) / 255;
slouken@5184
  1759
                dstG = (srcG * dstG) / 255;
slouken@5184
  1760
                dstB = (srcB * dstB) / 255;
slouken@5184
  1761
                break;
slouken@2262
  1762
            }
slouken@2262
  1763
            dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
slouken@2262
  1764
            *dst = dstpixel;
slouken@2262
  1765
            ++src;
slouken@2262
  1766
            ++dst;
slouken@2262
  1767
        }
slouken@2262
  1768
        info->src += info->src_pitch;
slouken@2262
  1769
        info->dst += info->dst_pitch;
slouken@2262
  1770
    }
slouken@2262
  1771
}
slouken@2262
  1772
slouken@2263
  1773
static void SDL_Blit_BGR888_BGR888_Blend_Scale(SDL_BlitInfo *info)
slouken@2262
  1774
{
slouken@2262
  1775
    const int flags = info->flags;
slouken@2262
  1776
    Uint32 srcpixel;
slouken@2262
  1777
    Uint32 srcR, srcG, srcB, srcA;
slouken@2262
  1778
    Uint32 dstpixel;
slouken@2262
  1779
    Uint32 dstR, dstG, dstB, dstA;
slouken@2262
  1780
    int srcy, srcx;
slouken@2262
  1781
    int posy, posx;
slouken@2262
  1782
    int incy, incx;
slouken@2262
  1783
slouken@2262
  1784
    srcy = 0;
slouken@2262
  1785
    posy = 0;
slouken@2262
  1786
    incy = (info->src_h << 16) / info->dst_h;
slouken@2262
  1787
    incx = (info->src_w << 16) / info->dst_w;
slouken@2262
  1788
slouken@2262
  1789
    while (info->dst_h--) {
slouken@5426
  1790
        Uint32 *src = 0;
slouken@2262
  1791
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2262
  1792
        int n = info->dst_w;
slouken@2262
  1793
        srcx = -1;
slouken@2262
  1794
        posx = 0x10000L;
slouken@2262
  1795
        while (posy >= 0x10000L) {
slouken@2262
  1796
            ++srcy;
slouken@2262
  1797
            posy -= 0x10000L;
slouken@2262
  1798
        }
slouken@2262
  1799
        while (n--) {
slouken@2262
  1800
            if (posx >= 0x10000L) {
slouken@2262
  1801
                while (posx >= 0x10000L) {
slouken@2262
  1802
                    ++srcx;
slouken@2262
  1803
                    posx -= 0x10000L;
slouken@2262
  1804
                }
slouken@2262
  1805
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2262
  1806
            }
slouken@2262
  1807
            srcpixel = *src;
slouken@2262
  1808
            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
slouken@2262
  1809
            dstpixel = *dst;
slouken@2262
  1810
            dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
slouken@2262
  1811
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2262
  1812
                /* This goes away if we ever use premultiplied alpha */
slouken@2262
  1813
                if (srcA < 255) {
slouken@2262
  1814
                    srcR = (srcR * srcA) / 255;
slouken@2262
  1815
                    srcG = (srcG * srcA) / 255;
slouken@2262
  1816
                    srcB = (srcB * srcA) / 255;
slouken@2262
  1817
                }
slouken@2262
  1818
            }
slouken@5184
  1819
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2262
  1820
            case SDL_COPY_BLEND:
slouken@2262
  1821
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2262
  1822
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2262
  1823
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
  1824
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2262
  1825
                break;
slouken@2262
  1826
            case SDL_COPY_ADD:
slouken@2262
  1827
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2262
  1828
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2262
  1829
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2262
  1830
                break;
slouken@5184
  1831
            case SDL_COPY_MOD:
slouken@5184
  1832
                dstR = (srcR * dstR) / 255;
slouken@5184
  1833
                dstG = (srcG * dstG) / 255;
slouken@5184
  1834
                dstB = (srcB * dstB) / 255;
slouken@5184
  1835
                break;
slouken@2262
  1836
            }
slouken@2262
  1837
            dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
slouken@2262
  1838
            *dst = dstpixel;
slouken@2262
  1839
            posx += incx;
slouken@2262
  1840
            ++dst;
slouken@2262
  1841
        }
slouken@2262
  1842
        posy += incy;
slouken@2262
  1843
        info->dst += info->dst_pitch;
slouken@2262
  1844
    }
slouken@2262
  1845
}
slouken@2262
  1846
slouken@2263
  1847
static void SDL_Blit_BGR888_BGR888_Modulate(SDL_BlitInfo *info)
slouken@2262
  1848
{
slouken@2262
  1849
    const int flags = info->flags;
slouken@2262
  1850
    const Uint32 modulateR = info->r;
slouken@2262
  1851
    const Uint32 modulateG = info->g;
slouken@2262
  1852
    const Uint32 modulateB = info->b;
slouken@2262
  1853
    const Uint32 modulateA = info->a;
slouken@2262
  1854
    Uint32 pixel;
slouken@2262
  1855
    Uint32 R, G, B, A;
icculus@8659
  1856
    (void) A;  /* not all formats use alpha. */
icculus@8659
  1857
    (void) modulateA;  /* not all formats use alpha. */
slouken@2262
  1858
slouken@2262
  1859
    while (info->dst_h--) {
slouken@2262
  1860
        Uint32 *src = (Uint32 *)info->src;
slouken@2262
  1861
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2262
  1862
        int n = info->dst_w;
slouken@2262
  1863
        while (n--) {
slouken@2262
  1864
            pixel = *src;
icculus@8659
  1865
            B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
slouken@2262
  1866
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2262
  1867
                R = (R * modulateR) / 255;
slouken@2262
  1868
                G = (G * modulateG) / 255;
slouken@2262
  1869
                B = (B * modulateB) / 255;
slouken@2262
  1870
            }
slouken@2262
  1871
            pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
slouken@2262
  1872
            *dst = pixel;
slouken@2262
  1873
            ++src;
slouken@2262
  1874
            ++dst;
slouken@2262
  1875
        }
slouken@2262
  1876
        info->src += info->src_pitch;
slouken@2262
  1877
        info->dst += info->dst_pitch;
slouken@2262
  1878
    }
slouken@2262
  1879
}
slouken@2262
  1880
slouken@2263
  1881
static void SDL_Blit_BGR888_BGR888_Modulate_Scale(SDL_BlitInfo *info)
slouken@2262
  1882
{
slouken@2262
  1883
    const int flags = info->flags;
slouken@2262
  1884
    const Uint32 modulateR = info->r;
slouken@2262
  1885
    const Uint32 modulateG = info->g;
slouken@2262
  1886
    const Uint32 modulateB = info->b;
slouken@2262
  1887
    const Uint32 modulateA = info->a;
slouken@2262
  1888
    Uint32 pixel;
slouken@2262
  1889
    Uint32 R, G, B, A;
slouken@2262
  1890
    int srcy, srcx;
slouken@2262
  1891
    int posy, posx;
slouken@2262
  1892
    int incy, incx;
icculus@8659
  1893
    (void) A;  /* not all formats use alpha. */
icculus@8659
  1894
    (void) modulateA;  /* not all formats use alpha. */
slouken@2262
  1895
slouken@2262
  1896
    srcy = 0;
slouken@2262
  1897
    posy = 0;
slouken@2262
  1898
    incy = (info->src_h << 16) / info->dst_h;
slouken@2262
  1899
    incx = (info->src_w << 16) / info->dst_w;
slouken@2262
  1900
slouken@2262
  1901
    while (info->dst_h--) {
slouken@5426
  1902
        Uint32 *src = 0;
slouken@2262
  1903
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2262
  1904
        int n = info->dst_w;
slouken@2262
  1905
        srcx = -1;
slouken@2262
  1906
        posx = 0x10000L;
slouken@2262
  1907
        while (posy >= 0x10000L) {
slouken@2262
  1908
            ++srcy;
slouken@2262
  1909
            posy -= 0x10000L;
slouken@2262
  1910
        }
slouken@2262
  1911
        while (n--) {
slouken@2262
  1912
            if (posx >= 0x10000L) {
slouken@2262
  1913
                while (posx >= 0x10000L) {
slouken@2262
  1914
                    ++srcx;
slouken@2262
  1915
                    posx -= 0x10000L;
slouken@2262
  1916
                }
slouken@2262
  1917
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2262
  1918
            }
slouken@2262
  1919
            pixel = *src;
icculus@8659
  1920
            B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel;
slouken@2262
  1921
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2262
  1922
                R = (R * modulateR) / 255;
slouken@2262
  1923
                G = (G * modulateG) / 255;
slouken@2262
  1924
                B = (B * modulateB) / 255;
slouken@2262
  1925
            }
slouken@2262
  1926
            pixel = ((Uint32)B << 16) | ((Uint32)G << 8) | R;
slouken@2262
  1927
            *dst = pixel;
slouken@2262
  1928
            posx += incx;
slouken@2262
  1929
            ++dst;
slouken@2262
  1930
        }
slouken@2262
  1931
        posy += incy;
slouken@2262
  1932
        info->dst += info->dst_pitch;
slouken@2262
  1933
    }
slouken@2262
  1934
}
slouken@2262
  1935
slouken@2263
  1936
static void SDL_Blit_BGR888_BGR888_Modulate_Blend(SDL_BlitInfo *info)
slouken@2262
  1937
{
slouken@2262
  1938
    const int flags = info->flags;
slouken@2262
  1939
    const Uint32 modulateR = info->r;
slouken@2262
  1940
    const Uint32 modulateG = info->g;
slouken@2262
  1941
    const Uint32 modulateB = info->b;
slouken@2262
  1942
    const Uint32 modulateA = info->a;
slouken@2262
  1943
    Uint32 srcpixel;
slouken@2262
  1944
    Uint32 srcR, srcG, srcB, srcA;
slouken@2262
  1945
    Uint32 dstpixel;
slouken@2262
  1946
    Uint32 dstR, dstG, dstB, dstA;
icculus@8659
  1947
    (void) modulateA;  /* not all formats use alpha. */
slouken@2262
  1948
slouken@2262
  1949
    while (info->dst_h--) {
slouken@2262
  1950
        Uint32 *src = (Uint32 *)info->src;
slouken@2262
  1951
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2262
  1952
        int n = info->dst_w;
slouken@2262
  1953
        while (n--) {
slouken@2262
  1954
            srcpixel = *src;
slouken@2262
  1955
            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
slouken@2262
  1956
            dstpixel = *dst;
slouken@2262
  1957
            dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
slouken@2262
  1958
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2262
  1959
                srcR = (srcR * modulateR) / 255;
slouken@2262
  1960
                srcG = (srcG * modulateG) / 255;
slouken@2262
  1961
                srcB = (srcB * modulateB) / 255;
slouken@2262
  1962
            }
slouken@2262
  1963
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2262
  1964
                srcA = (srcA * modulateA) / 255;
slouken@2262
  1965
            }
slouken@2262
  1966
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2262
  1967
                /* This goes away if we ever use premultiplied alpha */
slouken@2262
  1968
                if (srcA < 255) {
slouken@2262
  1969
                    srcR = (srcR * srcA) / 255;
slouken@2262
  1970
                    srcG = (srcG * srcA) / 255;
slouken@2262
  1971
                    srcB = (srcB * srcA) / 255;
slouken@2262
  1972
                }
slouken@2262
  1973
            }
slouken@5184
  1974
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2262
  1975
            case SDL_COPY_BLEND:
slouken@2262
  1976
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2262
  1977
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2262
  1978
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
  1979
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2262
  1980
                break;
slouken@2262
  1981
            case SDL_COPY_ADD:
slouken@2262
  1982
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2262
  1983
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2262
  1984
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2262
  1985
                break;
slouken@5184
  1986
            case SDL_COPY_MOD:
slouken@5184
  1987
                dstR = (srcR * dstR) / 255;
slouken@5184
  1988
                dstG = (srcG * dstG) / 255;
slouken@5184
  1989
                dstB = (srcB * dstB) / 255;
slouken@5184
  1990
                break;
slouken@2262
  1991
            }
slouken@2262
  1992
            dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
slouken@2262
  1993
            *dst = dstpixel;
slouken@2262
  1994
            ++src;
slouken@2262
  1995
            ++dst;
slouken@2262
  1996
        }
slouken@2262
  1997
        info->src += info->src_pitch;
slouken@2262
  1998
        info->dst += info->dst_pitch;
slouken@2262
  1999
    }
slouken@2262
  2000
}
slouken@2262
  2001
slouken@2263
  2002
static void SDL_Blit_BGR888_BGR888_Modulate_Blend_Scale(SDL_BlitInfo *info)
slouken@2262
  2003
{
slouken@2262
  2004
    const int flags = info->flags;
slouken@2262
  2005
    const Uint32 modulateR = info->r;
slouken@2262
  2006
    const Uint32 modulateG = info->g;
slouken@2262
  2007
    const Uint32 modulateB = info->b;
slouken@2262
  2008
    const Uint32 modulateA = info->a;
slouken@2262
  2009
    Uint32 srcpixel;
slouken@2262
  2010
    Uint32 srcR, srcG, srcB, srcA;
slouken@2262
  2011
    Uint32 dstpixel;
slouken@2262
  2012
    Uint32 dstR, dstG, dstB, dstA;
slouken@2262
  2013
    int srcy, srcx;
slouken@2262
  2014
    int posy, posx;
slouken@2262
  2015
    int incy, incx;
icculus@8659
  2016
    (void) modulateA;  /* not all formats use alpha. */
slouken@2262
  2017
slouken@2262
  2018
    srcy = 0;
slouken@2262
  2019
    posy = 0;
slouken@2262
  2020
    incy = (info->src_h << 16) / info->dst_h;
slouken@2262
  2021
    incx = (info->src_w << 16) / info->dst_w;
slouken@2262
  2022
slouken@2262
  2023
    while (info->dst_h--) {
slouken@5426
  2024
        Uint32 *src = 0;
slouken@2262
  2025
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2262
  2026
        int n = info->dst_w;
slouken@2262
  2027
        srcx = -1;
slouken@2262
  2028
        posx = 0x10000L;
slouken@2262
  2029
        while (posy >= 0x10000L) {
slouken@2262
  2030
            ++srcy;
slouken@2262
  2031
            posy -= 0x10000L;
slouken@2262
  2032
        }
slouken@2262
  2033
        while (n--) {
slouken@2262
  2034
            if (posx >= 0x10000L) {
slouken@2262
  2035
                while (posx >= 0x10000L) {
slouken@2262
  2036
                    ++srcx;
slouken@2262
  2037
                    posx -= 0x10000L;
slouken@2262
  2038
                }
slouken@2262
  2039
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2262
  2040
            }
slouken@2262
  2041
            srcpixel = *src;
slouken@2262
  2042
            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
slouken@2262
  2043
            dstpixel = *dst;
slouken@2262
  2044
            dstB = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstR = (Uint8)dstpixel; dstA = 0xFF;
slouken@2262
  2045
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2262
  2046
                srcR = (srcR * modulateR) / 255;
slouken@2262
  2047
                srcG = (srcG * modulateG) / 255;
slouken@2262
  2048
                srcB = (srcB * modulateB) / 255;
slouken@2262
  2049
            }
slouken@2262
  2050
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2262
  2051
                srcA = (srcA * modulateA) / 255;
slouken@2262
  2052
            }
slouken@2262
  2053
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2262
  2054
                /* This goes away if we ever use premultiplied alpha */
slouken@2262
  2055
                if (srcA < 255) {
slouken@2262
  2056
                    srcR = (srcR * srcA) / 255;
slouken@2262
  2057
                    srcG = (srcG * srcA) / 255;
slouken@2262
  2058
                    srcB = (srcB * srcA) / 255;
slouken@2262
  2059
                }
slouken@2262
  2060
            }
slouken@5184
  2061
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2262
  2062
            case SDL_COPY_BLEND:
slouken@2262
  2063
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2262
  2064
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2262
  2065
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
  2066
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2262
  2067
                break;
slouken@2262
  2068
            case SDL_COPY_ADD:
slouken@2262
  2069
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2262
  2070
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2262
  2071
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2262
  2072
                break;
slouken@5184
  2073
            case SDL_COPY_MOD:
slouken@5184
  2074
                dstR = (srcR * dstR) / 255;
slouken@5184
  2075
                dstG = (srcG * dstG) / 255;
slouken@5184
  2076
                dstB = (srcB * dstB) / 255;
slouken@5184
  2077
                break;
slouken@2262
  2078
            }
slouken@2262
  2079
            dstpixel = ((Uint32)dstB << 16) | ((Uint32)dstG << 8) | dstR;
slouken@2262
  2080
            *dst = dstpixel;
slouken@2262
  2081
            posx += incx;
slouken@2262
  2082
            ++dst;
slouken@2262
  2083
        }
slouken@2262
  2084
        posy += incy;
slouken@2262
  2085
        info->dst += info->dst_pitch;
slouken@2262
  2086
    }
slouken@2262
  2087
}
slouken@2262
  2088
slouken@2800
  2089
static void SDL_Blit_BGR888_ARGB8888_Scale(SDL_BlitInfo *info)
slouken@2800
  2090
{
slouken@2800
  2091
    Uint32 pixel;
slouken@2800
  2092
    Uint32 R, G, B, A;
slouken@2800
  2093
    int srcy, srcx;
slouken@2800
  2094
    int posy, posx;
slouken@2800
  2095
    int incy, incx;
icculus@8659
  2096
    (void) A;  /* not all formats use alpha. */
slouken@2800
  2097
slouken@2800
  2098
    srcy = 0;
slouken@2800
  2099
    posy = 0;
slouken@2800
  2100
    incy = (info->src_h << 16) / info->dst_h;
slouken@2800
  2101
    incx = (info->src_w << 16) / info->dst_w;
slouken@2800
  2102
slouken@2800
  2103
    while (info->dst_h--) {
slouken@5426
  2104
        Uint32 *src = 0;
slouken@2800
  2105
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2800
  2106
        int n = info->dst_w;
slouken@2800
  2107
        srcx = -1;
slouken@2800
  2108
        posx = 0x10000L;
slouken@2800
  2109
        while (posy >= 0x10000L) {
slouken@2800
  2110
            ++srcy;
slouken@2800
  2111
            posy -= 0x10000L;
slouken@2800
  2112
        }
slouken@2800
  2113
        while (n--) {
slouken@2800
  2114
            if (posx >= 0x10000L) {
slouken@2800
  2115
                while (posx >= 0x10000L) {
slouken@2800
  2116
                    ++srcx;
slouken@2800
  2117
                    posx -= 0x10000L;
slouken@2800
  2118
                }
slouken@2800
  2119
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2800
  2120
            }
slouken@2800
  2121
            pixel = *src;
slouken@2800
  2122
            B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF;
slouken@2800
  2123
            pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
slouken@2800
  2124
            *dst = pixel;
slouken@2800
  2125
            posx += incx;
slouken@2800
  2126
            ++dst;
slouken@2800
  2127
        }
slouken@2800
  2128
        posy += incy;
slouken@2800
  2129
        info->dst += info->dst_pitch;
slouken@2800
  2130
    }
slouken@2800
  2131
}
slouken@2800
  2132
slouken@2800
  2133
static void SDL_Blit_BGR888_ARGB8888_Blend(SDL_BlitInfo *info)
slouken@2800
  2134
{
slouken@2800
  2135
    const int flags = info->flags;
slouken@2800
  2136
    Uint32 srcpixel;
slouken@2800
  2137
    Uint32 srcR, srcG, srcB, srcA;
slouken@2800
  2138
    Uint32 dstpixel;
slouken@2800
  2139
    Uint32 dstR, dstG, dstB, dstA;
slouken@2800
  2140
slouken@2800
  2141
    while (info->dst_h--) {
slouken@2800
  2142
        Uint32 *src = (Uint32 *)info->src;
slouken@2800
  2143
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2800
  2144
        int n = info->dst_w;
slouken@2800
  2145
        while (n--) {
slouken@2800
  2146
            srcpixel = *src;
slouken@2800
  2147
            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
slouken@2800
  2148
            dstpixel = *dst;
icculus@8659
  2149
            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
slouken@2800
  2150
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2800
  2151
                /* This goes away if we ever use premultiplied alpha */
slouken@2800
  2152
                if (srcA < 255) {
slouken@2800
  2153
                    srcR = (srcR * srcA) / 255;
slouken@2800
  2154
                    srcG = (srcG * srcA) / 255;
slouken@2800
  2155
                    srcB = (srcB * srcA) / 255;
slouken@2800
  2156
                }
slouken@2800
  2157
            }
slouken@5184
  2158
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2800
  2159
            case SDL_COPY_BLEND:
slouken@2800
  2160
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2800
  2161
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2800
  2162
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
  2163
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2800
  2164
                break;
slouken@2800
  2165
            case SDL_COPY_ADD:
slouken@2800
  2166
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2800
  2167
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2800
  2168
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2800
  2169
                break;
slouken@5184
  2170
            case SDL_COPY_MOD:
slouken@5184
  2171
                dstR = (srcR * dstR) / 255;
slouken@5184
  2172
                dstG = (srcG * dstG) / 255;
slouken@5184
  2173
                dstB = (srcB * dstB) / 255;
slouken@5184
  2174
                break;
slouken@2800
  2175
            }
slouken@2800
  2176
            dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
slouken@2800
  2177
            *dst = dstpixel;
slouken@2800
  2178
            ++src;
slouken@2800
  2179
            ++dst;
slouken@2800
  2180
        }
slouken@2800
  2181
        info->src += info->src_pitch;
slouken@2800
  2182
        info->dst += info->dst_pitch;
slouken@2800
  2183
    }
slouken@2800
  2184
}
slouken@2800
  2185
slouken@2800
  2186
static void SDL_Blit_BGR888_ARGB8888_Blend_Scale(SDL_BlitInfo *info)
slouken@2800
  2187
{
slouken@2800
  2188
    const int flags = info->flags;
slouken@2800
  2189
    Uint32 srcpixel;
slouken@2800
  2190
    Uint32 srcR, srcG, srcB, srcA;
slouken@2800
  2191
    Uint32 dstpixel;
slouken@2800
  2192
    Uint32 dstR, dstG, dstB, dstA;
slouken@2800
  2193
    int srcy, srcx;
slouken@2800
  2194
    int posy, posx;
slouken@2800
  2195
    int incy, incx;
slouken@2800
  2196
slouken@2800
  2197
    srcy = 0;
slouken@2800
  2198
    posy = 0;
slouken@2800
  2199
    incy = (info->src_h << 16) / info->dst_h;
slouken@2800
  2200
    incx = (info->src_w << 16) / info->dst_w;
slouken@2800
  2201
slouken@2800
  2202
    while (info->dst_h--) {
slouken@5426
  2203
        Uint32 *src = 0;
slouken@2800
  2204
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2800
  2205
        int n = info->dst_w;
slouken@2800
  2206
        srcx = -1;
slouken@2800
  2207
        posx = 0x10000L;
slouken@2800
  2208
        while (posy >= 0x10000L) {
slouken@2800
  2209
            ++srcy;
slouken@2800
  2210
            posy -= 0x10000L;
slouken@2800
  2211
        }
slouken@2800
  2212
        while (n--) {
slouken@2800
  2213
            if (posx >= 0x10000L) {
slouken@2800
  2214
                while (posx >= 0x10000L) {
slouken@2800
  2215
                    ++srcx;
slouken@2800
  2216
                    posx -= 0x10000L;
slouken@2800
  2217
                }
slouken@2800
  2218
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2800
  2219
            }
slouken@2800
  2220
            srcpixel = *src;
slouken@2800
  2221
            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
slouken@2800
  2222
            dstpixel = *dst;
icculus@8659
  2223
            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
slouken@2800
  2224
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2800
  2225
                /* This goes away if we ever use premultiplied alpha */
slouken@2800
  2226
                if (srcA < 255) {
slouken@2800
  2227
                    srcR = (srcR * srcA) / 255;
slouken@2800
  2228
                    srcG = (srcG * srcA) / 255;
slouken@2800
  2229
                    srcB = (srcB * srcA) / 255;
slouken@2800
  2230
                }
slouken@2800
  2231
            }
slouken@5184
  2232
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2800
  2233
            case SDL_COPY_BLEND:
slouken@2800
  2234
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2800
  2235
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2800
  2236
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
  2237
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2800
  2238
                break;
slouken@2800
  2239
            case SDL_COPY_ADD:
slouken@2800
  2240
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2800
  2241
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2800
  2242
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2800
  2243
                break;
slouken@5184
  2244
            case SDL_COPY_MOD:
slouken@5184
  2245
                dstR = (srcR * dstR) / 255;
slouken@5184
  2246
                dstG = (srcG * dstG) / 255;
slouken@5184
  2247
                dstB = (srcB * dstB) / 255;
slouken@5184
  2248
                break;
slouken@2800
  2249
            }
slouken@2800
  2250
            dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
slouken@2800
  2251
            *dst = dstpixel;
slouken@2800
  2252
            posx += incx;
slouken@2800
  2253
            ++dst;
slouken@2800
  2254
        }
slouken@2800
  2255
        posy += incy;
slouken@2800
  2256
        info->dst += info->dst_pitch;
slouken@2800
  2257
    }
slouken@2800
  2258
}
slouken@2800
  2259
slouken@2800
  2260
static void SDL_Blit_BGR888_ARGB8888_Modulate(SDL_BlitInfo *info)
slouken@2800
  2261
{
slouken@2800
  2262
    const int flags = info->flags;
slouken@2800
  2263
    const Uint32 modulateR = info->r;
slouken@2800
  2264
    const Uint32 modulateG = info->g;
slouken@2800
  2265
    const Uint32 modulateB = info->b;
slouken@2800
  2266
    const Uint32 modulateA = info->a;
slouken@2800
  2267
    Uint32 pixel;
slouken@2800
  2268
    Uint32 R, G, B, A;
icculus@8659
  2269
    (void) A;  /* not all formats use alpha. */
icculus@8659
  2270
    (void) modulateA;  /* not all formats use alpha. */
slouken@2800
  2271
slouken@2800
  2272
    while (info->dst_h--) {
slouken@2800
  2273
        Uint32 *src = (Uint32 *)info->src;
slouken@2800
  2274
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2800
  2275
        int n = info->dst_w;
slouken@2800
  2276
        while (n--) {
slouken@2800
  2277
            pixel = *src;
slouken@2800
  2278
            B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF;
slouken@2800
  2279
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2800
  2280
                R = (R * modulateR) / 255;
slouken@2800
  2281
                G = (G * modulateG) / 255;
slouken@2800
  2282
                B = (B * modulateB) / 255;
slouken@2800
  2283
            }
slouken@2800
  2284
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2800
  2285
                A = (A * modulateA) / 255;
slouken@2800
  2286
            }
slouken@2800
  2287
            pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
slouken@2800
  2288
            *dst = pixel;
slouken@2800
  2289
            ++src;
slouken@2800
  2290
            ++dst;
slouken@2800
  2291
        }
slouken@2800
  2292
        info->src += info->src_pitch;
slouken@2800
  2293
        info->dst += info->dst_pitch;
slouken@2800
  2294
    }
slouken@2800
  2295
}
slouken@2800
  2296
slouken@2800
  2297
static void SDL_Blit_BGR888_ARGB8888_Modulate_Scale(SDL_BlitInfo *info)
slouken@2800
  2298
{
slouken@2800
  2299
    const int flags = info->flags;
slouken@2800
  2300
    const Uint32 modulateR = info->r;
slouken@2800
  2301
    const Uint32 modulateG = info->g;
slouken@2800
  2302
    const Uint32 modulateB = info->b;
slouken@2800
  2303
    const Uint32 modulateA = info->a;
slouken@2800
  2304
    Uint32 pixel;
slouken@2800
  2305
    Uint32 R, G, B, A;
slouken@2800
  2306
    int srcy, srcx;
slouken@2800
  2307
    int posy, posx;
slouken@2800
  2308
    int incy, incx;
icculus@8659
  2309
    (void) A;  /* not all formats use alpha. */
icculus@8659
  2310
    (void) modulateA;  /* not all formats use alpha. */
slouken@2800
  2311
slouken@2800
  2312
    srcy = 0;
slouken@2800
  2313
    posy = 0;
slouken@2800
  2314
    incy = (info->src_h << 16) / info->dst_h;
slouken@2800
  2315
    incx = (info->src_w << 16) / info->dst_w;
slouken@2800
  2316
slouken@2800
  2317
    while (info->dst_h--) {
slouken@5426
  2318
        Uint32 *src = 0;
slouken@2800
  2319
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2800
  2320
        int n = info->dst_w;
slouken@2800
  2321
        srcx = -1;
slouken@2800
  2322
        posx = 0x10000L;
slouken@2800
  2323
        while (posy >= 0x10000L) {
slouken@2800
  2324
            ++srcy;
slouken@2800
  2325
            posy -= 0x10000L;
slouken@2800
  2326
        }
slouken@2800
  2327
        while (n--) {
slouken@2800
  2328
            if (posx >= 0x10000L) {
slouken@2800
  2329
                while (posx >= 0x10000L) {
slouken@2800
  2330
                    ++srcx;
slouken@2800
  2331
                    posx -= 0x10000L;
slouken@2800
  2332
                }
slouken@2800
  2333
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2800
  2334
            }
slouken@2800
  2335
            pixel = *src;
slouken@2800
  2336
            B = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); R = (Uint8)pixel; A = 0xFF;
slouken@2800
  2337
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2800
  2338
                R = (R * modulateR) / 255;
slouken@2800
  2339
                G = (G * modulateG) / 255;
slouken@2800
  2340
                B = (B * modulateB) / 255;
slouken@2800
  2341
            }
slouken@2800
  2342
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2800
  2343
                A = (A * modulateA) / 255;
slouken@2800
  2344
            }
slouken@2800
  2345
            pixel = ((Uint32)A << 24) | ((Uint32)R << 16) | ((Uint32)G << 8) | B;
slouken@2800
  2346
            *dst = pixel;
slouken@2800
  2347
            posx += incx;
slouken@2800
  2348
            ++dst;
slouken@2800
  2349
        }
slouken@2800
  2350
        posy += incy;
slouken@2800
  2351
        info->dst += info->dst_pitch;
slouken@2800
  2352
    }
slouken@2800
  2353
}
slouken@2800
  2354
slouken@2800
  2355
static void SDL_Blit_BGR888_ARGB8888_Modulate_Blend(SDL_BlitInfo *info)
slouken@2800
  2356
{
slouken@2800
  2357
    const int flags = info->flags;
slouken@2800
  2358
    const Uint32 modulateR = info->r;
slouken@2800
  2359
    const Uint32 modulateG = info->g;
slouken@2800
  2360
    const Uint32 modulateB = info->b;
slouken@2800
  2361
    const Uint32 modulateA = info->a;
slouken@2800
  2362
    Uint32 srcpixel;
slouken@2800
  2363
    Uint32 srcR, srcG, srcB, srcA;
slouken@2800
  2364
    Uint32 dstpixel;
slouken@2800
  2365
    Uint32 dstR, dstG, dstB, dstA;
icculus@8659
  2366
    (void) modulateA;  /* not all formats use alpha. */
slouken@2800
  2367
slouken@2800
  2368
    while (info->dst_h--) {
slouken@2800
  2369
        Uint32 *src = (Uint32 *)info->src;
slouken@2800
  2370
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2800
  2371
        int n = info->dst_w;
slouken@2800
  2372
        while (n--) {
slouken@2800
  2373
            srcpixel = *src;
slouken@2800
  2374
            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
slouken@2800
  2375
            dstpixel = *dst;
icculus@8659
  2376
            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
slouken@2800
  2377
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2800
  2378
                srcR = (srcR * modulateR) / 255;
slouken@2800
  2379
                srcG = (srcG * modulateG) / 255;
slouken@2800
  2380
                srcB = (srcB * modulateB) / 255;
slouken@2800
  2381
            }
slouken@2800
  2382
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2800
  2383
                srcA = (srcA * modulateA) / 255;
slouken@2800
  2384
            }
slouken@2800
  2385
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2800
  2386
                /* This goes away if we ever use premultiplied alpha */
slouken@2800
  2387
                if (srcA < 255) {
slouken@2800
  2388
                    srcR = (srcR * srcA) / 255;
slouken@2800
  2389
                    srcG = (srcG * srcA) / 255;
slouken@2800
  2390
                    srcB = (srcB * srcA) / 255;
slouken@2800
  2391
                }
slouken@2800
  2392
            }
slouken@5184
  2393
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2800
  2394
            case SDL_COPY_BLEND:
slouken@2800
  2395
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2800
  2396
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2800
  2397
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
  2398
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2800
  2399
                break;
slouken@2800
  2400
            case SDL_COPY_ADD:
slouken@2800
  2401
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2800
  2402
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2800
  2403
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2800
  2404
                break;
slouken@5184
  2405
            case SDL_COPY_MOD:
slouken@5184
  2406
                dstR = (srcR * dstR) / 255;
slouken@5184
  2407
                dstG = (srcG * dstG) / 255;
slouken@5184
  2408
                dstB = (srcB * dstB) / 255;
slouken@5184
  2409
                break;
slouken@2800
  2410
            }
slouken@2800
  2411
            dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
slouken@2800
  2412
            *dst = dstpixel;
slouken@2800
  2413
            ++src;
slouken@2800
  2414
            ++dst;
slouken@2800
  2415
        }
slouken@2800
  2416
        info->src += info->src_pitch;
slouken@2800
  2417
        info->dst += info->dst_pitch;
slouken@2800
  2418
    }
slouken@2800
  2419
}
slouken@2800
  2420
slouken@2800
  2421
static void SDL_Blit_BGR888_ARGB8888_Modulate_Blend_Scale(SDL_BlitInfo *info)
slouken@2800
  2422
{
slouken@2800
  2423
    const int flags = info->flags;
slouken@2800
  2424
    const Uint32 modulateR = info->r;
slouken@2800
  2425
    const Uint32 modulateG = info->g;
slouken@2800
  2426
    const Uint32 modulateB = info->b;
slouken@2800
  2427
    const Uint32 modulateA = info->a;
slouken@2800
  2428
    Uint32 srcpixel;
slouken@2800
  2429
    Uint32 srcR, srcG, srcB, srcA;
slouken@2800
  2430
    Uint32 dstpixel;
slouken@2800
  2431
    Uint32 dstR, dstG, dstB, dstA;
slouken@2800
  2432
    int srcy, srcx;
slouken@2800
  2433
    int posy, posx;
slouken@2800
  2434
    int incy, incx;
icculus@8659
  2435
    (void) modulateA;  /* not all formats use alpha. */
slouken@2800
  2436
slouken@2800
  2437
    srcy = 0;
slouken@2800
  2438
    posy = 0;
slouken@2800
  2439
    incy = (info->src_h << 16) / info->dst_h;
slouken@2800
  2440
    incx = (info->src_w << 16) / info->dst_w;
slouken@2800
  2441
slouken@2800
  2442
    while (info->dst_h--) {
slouken@5426
  2443
        Uint32 *src = 0;
slouken@2800
  2444
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2800
  2445
        int n = info->dst_w;
slouken@2800
  2446
        srcx = -1;
slouken@2800
  2447
        posx = 0x10000L;
slouken@2800
  2448
        while (posy >= 0x10000L) {
slouken@2800
  2449
            ++srcy;
slouken@2800
  2450
            posy -= 0x10000L;
slouken@2800
  2451
        }
slouken@2800
  2452
        while (n--) {
slouken@2800
  2453
            if (posx >= 0x10000L) {
slouken@2800
  2454
                while (posx >= 0x10000L) {
slouken@2800
  2455
                    ++srcx;
slouken@2800
  2456
                    posx -= 0x10000L;
slouken@2800
  2457
                }
slouken@2800
  2458
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2800
  2459
            }
slouken@2800
  2460
            srcpixel = *src;
slouken@2800
  2461
            srcB = (Uint8)(srcpixel >> 16); srcG = (Uint8)(srcpixel >> 8); srcR = (Uint8)srcpixel; srcA = 0xFF;
slouken@2800
  2462
            dstpixel = *dst;
icculus@8659
  2463
            dstR = (Uint8)(dstpixel >> 16); dstG = (Uint8)(dstpixel >> 8); dstB = (Uint8)dstpixel; dstA = (Uint8)(dstpixel >> 24);
slouken@2800
  2464
            if (flags & SDL_COPY_MODULATE_COLOR) {
slouken@2800
  2465
                srcR = (srcR * modulateR) / 255;
slouken@2800
  2466
                srcG = (srcG * modulateG) / 255;
slouken@2800
  2467
                srcB = (srcB * modulateB) / 255;
slouken@2800
  2468
            }
slouken@2800
  2469
            if (flags & SDL_COPY_MODULATE_ALPHA) {
slouken@2800
  2470
                srcA = (srcA * modulateA) / 255;
slouken@2800
  2471
            }
slouken@2800
  2472
            if (flags & (SDL_COPY_BLEND|SDL_COPY_ADD)) {
slouken@2800
  2473
                /* This goes away if we ever use premultiplied alpha */
slouken@2800
  2474
                if (srcA < 255) {
slouken@2800
  2475
                    srcR = (srcR * srcA) / 255;
slouken@2800
  2476
                    srcG = (srcG * srcA) / 255;
slouken@2800
  2477
                    srcB = (srcB * srcA) / 255;
slouken@2800
  2478
                }
slouken@2800
  2479
            }
slouken@5184
  2480
            switch (flags & (SDL_COPY_BLEND|SDL_COPY_ADD|SDL_COPY_MOD)) {
slouken@2800
  2481
            case SDL_COPY_BLEND:
slouken@2800
  2482
                dstR = srcR + ((255 - srcA) * dstR) / 255;
slouken@2800
  2483
                dstG = srcG + ((255 - srcA) * dstG) / 255;
slouken@2800
  2484
                dstB = srcB + ((255 - srcA) * dstB) / 255;
slouken@7502
  2485
                dstA = srcA + ((255 - srcA) * dstA) / 255;
slouken@2800
  2486
                break;
slouken@2800
  2487
            case SDL_COPY_ADD:
slouken@2800
  2488
                dstR = srcR + dstR; if (dstR > 255) dstR = 255;
slouken@2800
  2489
                dstG = srcG + dstG; if (dstG > 255) dstG = 255;
slouken@2800
  2490
                dstB = srcB + dstB; if (dstB > 255) dstB = 255;
slouken@2800
  2491
                break;
slouken@5184
  2492
            case SDL_COPY_MOD:
slouken@5184
  2493
                dstR = (srcR * dstR) / 255;
slouken@5184
  2494
                dstG = (srcG * dstG) / 255;
slouken@5184
  2495
                dstB = (srcB * dstB) / 255;
slouken@5184
  2496
                break;
slouken@2800
  2497
            }
slouken@2800
  2498
            dstpixel = ((Uint32)dstA << 24) | ((Uint32)dstR << 16) | ((Uint32)dstG << 8) | dstB;
slouken@2800
  2499
            *dst = dstpixel;
slouken@2800
  2500
            posx += incx;
slouken@2800
  2501
            ++dst;
slouken@2800
  2502
        }
slouken@2800
  2503
        posy += incy;
slouken@2800
  2504
        info->dst += info->dst_pitch;
slouken@2800
  2505
    }
slouken@2800
  2506
}
slouken@2800
  2507
slouken@2263
  2508
static void SDL_Blit_ARGB8888_RGB888_Scale(SDL_BlitInfo *info)
slouken@2262
  2509
{
slouken@2262
  2510
    Uint32 pixel;
slouken@2262
  2511
    Uint32 R, G, B, A;
slouken@2262
  2512
    int srcy, srcx;
slouken@2262
  2513
    int posy, posx;
slouken@2262
  2514
    int incy, incx;
icculus@8659
  2515
    (void) A;  /* not all formats use alpha. */
slouken@2262
  2516
slouken@2262
  2517
    srcy = 0;
slouken@2262
  2518
    posy = 0;
slouken@2262
  2519
    incy = (info->src_h << 16) / info->dst_h;
slouken@2262
  2520
    incx = (info->src_w << 16) / info->dst_w;
slouken@2262
  2521
slouken@2262
  2522
    while (info->dst_h--) {
slouken@5426
  2523
        Uint32 *src = 0;
slouken@2262
  2524
        Uint32 *dst = (Uint32 *)info->dst;
slouken@2262
  2525
        int n = info->dst_w;
slouken@2262
  2526
        srcx = -1;
slouken@2262
  2527
        posx = 0x10000L;
slouken@2262
  2528
        while (posy >= 0x10000L) {
slouken@2262
  2529
            ++srcy;
slouken@2262
  2530
            posy -= 0x10000L;
slouken@2262
  2531
        }
slouken@2262
  2532
        while (n--) {
slouken@2262
  2533
            if (posx >= 0x10000L) {
slouken@2262
  2534
                while (posx >= 0x10000L) {
slouken@2262
  2535
                    ++srcx;
slouken@2262
  2536
                    posx -= 0x10000L;
slouken@2262
  2537
                }
slouken@2262
  2538
                src = (Uint32 *)(info->src + (srcy * info->src_pitch) + (srcx * 4));
slouken@2262
  2539
            }
slouken@2262
  2540
            pixel = *src;
icculus@8659
  2541
            R = (Uint8)(pixel >> 16); G = (Uint8)(pixel >> 8); B = (Uint8)pixel;
slouken@2262
  2542
            pixel = ((Uint32)R << 16) | ((Uint32)G << 8) | B;
slouken@2262
  2543
            *dst = pixel;
slouken@2262
  2544
            posx += incx;
slouken@2262
  2545
            ++dst;
slouken@2262
  2546
        }
slouken@2262
  2547
        posy += incy;
slouken@2262
  2548
        info->dst += info->dst_pitch;
slouken@2262
  2549
    }
slouken@2262
  2550
}
slouken@2262
  2551
slouken@2263
  2552
static void SDL_Blit_ARGB8888_RGB888_Blend(SDL_BlitInfo *info)
slouken@2262
  2553
{
slouken@2262
  2554
    const int flags = info->flags;
slouken@2262
  2555
    Uint32 srcpixel;