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