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