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