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