src/render/software/SDL_blendline.c
author Sam Lantinga <slouken@libsdl.org>
Fri, 04 Feb 2011 19:50:56 -0800
changeset 5184 d976b67150c5
parent 5166 4d39eeaad00b
child 5226 710d00cb3a6a
permissions -rwxr-xr-x
Restored SDL_BLENDMODE_MOD for MAME
slouken@2888
     1
/*
slouken@2888
     2
    SDL - Simple DirectMedia Layer
slouken@3697
     3
    Copyright (C) 1997-2010 Sam Lantinga
slouken@2888
     4
slouken@2888
     5
    This library is free software; you can redistribute it and/or
slouken@2888
     6
    modify it under the terms of the GNU Lesser General Public
slouken@2888
     7
    License as published by the Free Software Foundation; either
slouken@2888
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@2888
     9
slouken@2888
    10
    This library is distributed in the hope that it will be useful,
slouken@2888
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@2888
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@2888
    13
    Lesser General Public License for more details.
slouken@2888
    14
slouken@2888
    15
    You should have received a copy of the GNU Lesser General Public
slouken@2888
    16
    License along with this library; if not, write to the Free Software
slouken@2888
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@2888
    18
slouken@2888
    19
    Sam Lantinga
slouken@2888
    20
    slouken@libsdl.org
slouken@2888
    21
*/
slouken@2888
    22
#include "SDL_config.h"
slouken@2888
    23
slouken@2898
    24
#include "SDL_draw.h"
slouken@5163
    25
#include "SDL_blendline.h"
slouken@5166
    26
#include "SDL_blendpoint.h"
slouken@2898
    27
slouken@3596
    28
slouken@3596
    29
static void
slouken@3596
    30
SDL_BlendLine_RGB2(SDL_Surface * dst, int x1, int y1, int x2, int y2,
slouken@4929
    31
                   SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
slouken@3596
    32
                   SDL_bool draw_end)
slouken@2898
    33
{
slouken@3596
    34
    const SDL_PixelFormat *fmt = dst->format;
slouken@3596
    35
    unsigned r, g, b, a, inva;
slouken@3596
    36
slouken@3596
    37
    if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
slouken@3596
    38
        r = DRAW_MUL(_r, _a);
slouken@3596
    39
        g = DRAW_MUL(_g, _a);
slouken@3596
    40
        b = DRAW_MUL(_b, _a);
slouken@3596
    41
        a = _a;
slouken@3596
    42
    } else {
slouken@3596
    43
        r = _r;
slouken@3596
    44
        g = _g;
slouken@3596
    45
        b = _b;
slouken@3596
    46
        a = _a;
slouken@3596
    47
    }
slouken@3596
    48
    inva = (a ^ 0xff);
slouken@2888
    49
slouken@3596
    50
    if (y1 == y2) {
slouken@3596
    51
        switch (blendMode) {
slouken@3596
    52
        case SDL_BLENDMODE_BLEND:
slouken@3596
    53
            HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end);
slouken@3596
    54
            break;
slouken@3596
    55
        case SDL_BLENDMODE_ADD:
slouken@3596
    56
            HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end);
slouken@3596
    57
            break;
slouken@5184
    58
        case SDL_BLENDMODE_MOD:
slouken@5184
    59
            HLINE(Uint16, DRAW_SETPIXEL_MOD_RGB, draw_end);
slouken@5184
    60
            break;
slouken@3596
    61
        default:
slouken@3596
    62
            HLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end);
slouken@3596
    63
            break;
slouken@3596
    64
        }
slouken@3596
    65
    } else if (x1 == x2) {
slouken@3596
    66
        switch (blendMode) {
slouken@3596
    67
        case SDL_BLENDMODE_BLEND:
slouken@3596
    68
            VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end);
slouken@3596
    69
            break;
slouken@3596
    70
        case SDL_BLENDMODE_ADD:
slouken@3596
    71
            VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end);
slouken@3596
    72
            break;
slouken@5184
    73
        case SDL_BLENDMODE_MOD:
slouken@5184
    74
            VLINE(Uint16, DRAW_SETPIXEL_MOD_RGB, draw_end);
slouken@5184
    75
            break;
slouken@3596
    76
        default:
slouken@3596
    77
            VLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end);
slouken@3596
    78
            break;
slouken@3596
    79
        }
slouken@3596
    80
    } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
slouken@3596
    81
        switch (blendMode) {
slouken@3596
    82
        case SDL_BLENDMODE_BLEND:
slouken@3596
    83
            DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end);
slouken@3596
    84
            break;
slouken@3596
    85
        case SDL_BLENDMODE_ADD:
slouken@3596
    86
            DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end);
slouken@3596
    87
            break;
slouken@5184
    88
        case SDL_BLENDMODE_MOD:
slouken@5184
    89
            DLINE(Uint16, DRAW_SETPIXEL_MOD_RGB, draw_end);
slouken@5184
    90
            break;
slouken@3596
    91
        default:
slouken@3596
    92
            DLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end);
slouken@3596
    93
            break;
slouken@3596
    94
        }
slouken@3596
    95
    } else {
slouken@3596
    96
        switch (blendMode) {
slouken@3596
    97
        case SDL_BLENDMODE_BLEND:
slouken@3596
    98
            AALINE(x1, y1, x2, y2,
slouken@3596
    99
                   DRAW_SETPIXELXY2_BLEND_RGB, DRAW_SETPIXELXY2_BLEND_RGB,
slouken@3596
   100
                   draw_end);
slouken@3596
   101
            break;
slouken@3596
   102
        case SDL_BLENDMODE_ADD:
slouken@3596
   103
            AALINE(x1, y1, x2, y2,
slouken@3596
   104
                   DRAW_SETPIXELXY2_ADD_RGB, DRAW_SETPIXELXY2_ADD_RGB,
slouken@3596
   105
                   draw_end);
slouken@3596
   106
            break;
slouken@5184
   107
        case SDL_BLENDMODE_MOD:
slouken@5184
   108
            AALINE(x1, y1, x2, y2,
slouken@5184
   109
                   DRAW_SETPIXELXY2_MOD_RGB, DRAW_SETPIXELXY2_MOD_RGB,
slouken@5184
   110
                   draw_end);
slouken@5184
   111
            break;
slouken@3596
   112
        default:
slouken@3596
   113
            AALINE(x1, y1, x2, y2,
slouken@3596
   114
                   DRAW_SETPIXELXY2_RGB, DRAW_SETPIXELXY2_BLEND_RGB,
slouken@3596
   115
                   draw_end);
slouken@3596
   116
            break;
slouken@3596
   117
        }
slouken@2898
   118
    }
slouken@2898
   119
}
slouken@2896
   120
slouken@3596
   121
static void
slouken@3596
   122
SDL_BlendLine_RGB555(SDL_Surface * dst, int x1, int y1, int x2, int y2,
slouken@4929
   123
                     SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
slouken@3594
   124
                     SDL_bool draw_end)
slouken@2898
   125
{
slouken@3596
   126
    const SDL_PixelFormat *fmt = dst->format;
slouken@3596
   127
    unsigned r, g, b, a, inva;
slouken@2898
   128
slouken@3596
   129
    if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
slouken@3596
   130
        r = DRAW_MUL(_r, _a);
slouken@3596
   131
        g = DRAW_MUL(_g, _a);
slouken@3596
   132
        b = DRAW_MUL(_b, _a);
slouken@3596
   133
        a = _a;
slouken@3596
   134
    } else {
slouken@3596
   135
        r = _r;
slouken@3596
   136
        g = _g;
slouken@3596
   137
        b = _b;
slouken@3596
   138
        a = _a;
slouken@2898
   139
    }
slouken@3596
   140
    inva = (a ^ 0xff);
slouken@2896
   141
slouken@3596
   142
    if (y1 == y2) {
slouken@3596
   143
        switch (blendMode) {
slouken@3596
   144
        case SDL_BLENDMODE_BLEND:
slouken@3596
   145
            HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end);
slouken@3596
   146
            break;
slouken@3596
   147
        case SDL_BLENDMODE_ADD:
slouken@3596
   148
            HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end);
slouken@3596
   149
            break;
slouken@5184
   150
        case SDL_BLENDMODE_MOD:
slouken@5184
   151
            HLINE(Uint16, DRAW_SETPIXEL_MOD_RGB555, draw_end);
slouken@5184
   152
            break;
slouken@3596
   153
        default:
slouken@3596
   154
            HLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end);
slouken@3596
   155
            break;
slouken@3596
   156
        }
slouken@3596
   157
    } else if (x1 == x2) {
slouken@3596
   158
        switch (blendMode) {
slouken@3596
   159
        case SDL_BLENDMODE_BLEND:
slouken@3596
   160
            VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end);
slouken@3596
   161
            break;
slouken@3596
   162
        case SDL_BLENDMODE_ADD:
slouken@3596
   163
            VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end);
slouken@3596
   164
            break;
slouken@5184
   165
        case SDL_BLENDMODE_MOD:
slouken@5184
   166
            VLINE(Uint16, DRAW_SETPIXEL_MOD_RGB555, draw_end);
slouken@5184
   167
            break;
slouken@3596
   168
        default:
slouken@3596
   169
            VLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end);
slouken@3596
   170
            break;
slouken@3596
   171
        }
slouken@3596
   172
    } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
slouken@3596
   173
        switch (blendMode) {
slouken@3596
   174
        case SDL_BLENDMODE_BLEND:
slouken@3596
   175
            DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end);
slouken@3596
   176
            break;
slouken@3596
   177
        case SDL_BLENDMODE_ADD:
slouken@3596
   178
            DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end);
slouken@3596
   179
            break;
slouken@5184
   180
        case SDL_BLENDMODE_MOD:
slouken@5184
   181
            DLINE(Uint16, DRAW_SETPIXEL_MOD_RGB555, draw_end);
slouken@5184
   182
            break;
slouken@3596
   183
        default:
slouken@3596
   184
            DLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end);
slouken@3596
   185
            break;
slouken@3596
   186
        }
slouken@3596
   187
    } else {
slouken@3596
   188
        switch (blendMode) {
slouken@3596
   189
        case SDL_BLENDMODE_BLEND:
slouken@3596
   190
            AALINE(x1, y1, x2, y2,
slouken@3596
   191
                   DRAW_SETPIXELXY_BLEND_RGB555, DRAW_SETPIXELXY_BLEND_RGB555,
slouken@3596
   192
                   draw_end);
slouken@3596
   193
            break;
slouken@3596
   194
        case SDL_BLENDMODE_ADD:
slouken@3596
   195
            AALINE(x1, y1, x2, y2,
slouken@3596
   196
                   DRAW_SETPIXELXY_ADD_RGB555, DRAW_SETPIXELXY_ADD_RGB555,
slouken@3596
   197
                   draw_end);
slouken@3596
   198
            break;
slouken@5184
   199
        case SDL_BLENDMODE_MOD:
slouken@5184
   200
            AALINE(x1, y1, x2, y2,
slouken@5184
   201
                   DRAW_SETPIXELXY_MOD_RGB555, DRAW_SETPIXELXY_MOD_RGB555,
slouken@5184
   202
                   draw_end);
slouken@5184
   203
            break;
slouken@3596
   204
        default:
slouken@3596
   205
            AALINE(x1, y1, x2, y2,
slouken@3596
   206
                   DRAW_SETPIXELXY_RGB555, DRAW_SETPIXELXY_BLEND_RGB555,
slouken@3596
   207
                   draw_end);
slouken@3596
   208
            break;
slouken@3596
   209
        }
slouken@2899
   210
    }
slouken@2899
   211
}
slouken@2899
   212
slouken@3596
   213
static void
slouken@3596
   214
SDL_BlendLine_RGB565(SDL_Surface * dst, int x1, int y1, int x2, int y2,
slouken@4929
   215
                     SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
slouken@3596
   216
                     SDL_bool draw_end)
slouken@2898
   217
{
slouken@3596
   218
    const SDL_PixelFormat *fmt = dst->format;
slouken@3596
   219
    unsigned r, g, b, a, inva;
slouken@2896
   220
slouken@3596
   221
    if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
slouken@3596
   222
        r = DRAW_MUL(_r, _a);
slouken@3596
   223
        g = DRAW_MUL(_g, _a);
slouken@3596
   224
        b = DRAW_MUL(_b, _a);
slouken@3596
   225
        a = _a;
slouken@3596
   226
    } else {
slouken@3596
   227
        r = _r;
slouken@3596
   228
        g = _g;
slouken@3596
   229
        b = _b;
slouken@3596
   230
        a = _a;
slouken@3596
   231
    }
slouken@3596
   232
    inva = (a ^ 0xff);
slouken@3596
   233
slouken@3596
   234
    if (y1 == y2) {
slouken@2898
   235
        switch (blendMode) {
slouken@2898
   236
        case SDL_BLENDMODE_BLEND:
slouken@3596
   237
            HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end);
slouken@2898
   238
            break;
slouken@2898
   239
        case SDL_BLENDMODE_ADD:
slouken@3596
   240
            HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end);
slouken@2898
   241
            break;
slouken@5184
   242
        case SDL_BLENDMODE_MOD:
slouken@5184
   243
            HLINE(Uint16, DRAW_SETPIXEL_MOD_RGB565, draw_end);
slouken@5184
   244
            break;
slouken@2898
   245
        default:
slouken@3596
   246
            HLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end);
slouken@2898
   247
            break;
slouken@2898
   248
        }
slouken@3596
   249
    } else if (x1 == x2) {
slouken@2898
   250
        switch (blendMode) {
slouken@2898
   251
        case SDL_BLENDMODE_BLEND:
slouken@3596
   252
            VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end);
slouken@3596
   253
            break;
slouken@3596
   254
        case SDL_BLENDMODE_ADD:
slouken@3596
   255
            VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end);
slouken@3596
   256
            break;
slouken@5184
   257
        case SDL_BLENDMODE_MOD:
slouken@5184
   258
            VLINE(Uint16, DRAW_SETPIXEL_MOD_RGB565, draw_end);
slouken@5184
   259
            break;
slouken@3596
   260
        default:
slouken@3596
   261
            VLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end);
slouken@3596
   262
            break;
slouken@3596
   263
        }
slouken@3596
   264
    } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
slouken@3596
   265
        switch (blendMode) {
slouken@3596
   266
        case SDL_BLENDMODE_BLEND:
slouken@3596
   267
            DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end);
slouken@2898
   268
            break;
slouken@2898
   269
        case SDL_BLENDMODE_ADD:
slouken@3596
   270
            DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end);
slouken@2898
   271
            break;
slouken@5184
   272
        case SDL_BLENDMODE_MOD:
slouken@5184
   273
            DLINE(Uint16, DRAW_SETPIXEL_MOD_RGB565, draw_end);
slouken@5184
   274
            break;
slouken@2898
   275
        default:
slouken@3596
   276
            DLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end);
slouken@2898
   277
            break;
slouken@2898
   278
        }
slouken@3596
   279
    } else {
slouken@3596
   280
        switch (blendMode) {
slouken@3596
   281
        case SDL_BLENDMODE_BLEND:
slouken@3596
   282
            AALINE(x1, y1, x2, y2,
slouken@3596
   283
                   DRAW_SETPIXELXY_BLEND_RGB565, DRAW_SETPIXELXY_BLEND_RGB565,
slouken@3596
   284
                   draw_end);
slouken@3596
   285
            break;
slouken@3596
   286
        case SDL_BLENDMODE_ADD:
slouken@3596
   287
            AALINE(x1, y1, x2, y2,
slouken@3596
   288
                   DRAW_SETPIXELXY_ADD_RGB565, DRAW_SETPIXELXY_ADD_RGB565,
slouken@3596
   289
                   draw_end);
slouken@3596
   290
            break;
slouken@5184
   291
        case SDL_BLENDMODE_MOD:
slouken@5184
   292
            AALINE(x1, y1, x2, y2,
slouken@5184
   293
                   DRAW_SETPIXELXY_MOD_RGB565, DRAW_SETPIXELXY_MOD_RGB565,
slouken@5184
   294
                   draw_end);
slouken@5184
   295
            break;
slouken@3596
   296
        default:
slouken@3596
   297
            AALINE(x1, y1, x2, y2,
slouken@3596
   298
                   DRAW_SETPIXELXY_RGB565, DRAW_SETPIXELXY_BLEND_RGB565,
slouken@3596
   299
                   draw_end);
slouken@3596
   300
            break;
slouken@3596
   301
        }
slouken@2898
   302
    }
slouken@2898
   303
}
slouken@2896
   304
slouken@3596
   305
static void
slouken@3596
   306
SDL_BlendLine_RGB4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
slouken@4929
   307
                   SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
slouken@3594
   308
                   SDL_bool draw_end)
slouken@2898
   309
{
slouken@3596
   310
    const SDL_PixelFormat *fmt = dst->format;
slouken@3596
   311
    unsigned r, g, b, a, inva;
slouken@3596
   312
slouken@3596
   313
    if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
slouken@3596
   314
        r = DRAW_MUL(_r, _a);
slouken@3596
   315
        g = DRAW_MUL(_g, _a);
slouken@3596
   316
        b = DRAW_MUL(_b, _a);
slouken@3596
   317
        a = _a;
slouken@3596
   318
    } else {
slouken@3596
   319
        r = _r;
slouken@3596
   320
        g = _g;
slouken@3596
   321
        b = _b;
slouken@3596
   322
        a = _a;
slouken@3596
   323
    }
slouken@3596
   324
    inva = (a ^ 0xff);
slouken@2896
   325
slouken@3596
   326
    if (y1 == y2) {
slouken@3596
   327
        switch (blendMode) {
slouken@3596
   328
        case SDL_BLENDMODE_BLEND:
slouken@3596
   329
            HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end);
slouken@3596
   330
            break;
slouken@3596
   331
        case SDL_BLENDMODE_ADD:
slouken@3596
   332
            HLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end);
slouken@3596
   333
            break;
slouken@5184
   334
        case SDL_BLENDMODE_MOD:
slouken@5184
   335
            HLINE(Uint32, DRAW_SETPIXEL_MOD_RGB, draw_end);
slouken@5184
   336
            break;
slouken@3596
   337
        default:
slouken@3596
   338
            HLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end);
slouken@3596
   339
            break;
slouken@3596
   340
        }
slouken@3596
   341
    } else if (x1 == x2) {
slouken@3596
   342
        switch (blendMode) {
slouken@3596
   343
        case SDL_BLENDMODE_BLEND:
slouken@3596
   344
            VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end);
slouken@3596
   345
            break;
slouken@3596
   346
        case SDL_BLENDMODE_ADD:
slouken@3596
   347
            VLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end);
slouken@3596
   348
            break;
slouken@5184
   349
        case SDL_BLENDMODE_MOD:
slouken@5184
   350
            VLINE(Uint32, DRAW_SETPIXEL_MOD_RGB, draw_end);
slouken@5184
   351
            break;
slouken@3596
   352
        default:
slouken@3596
   353
            VLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end);
slouken@3596
   354
            break;
slouken@3596
   355
        }
slouken@3596
   356
    } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
slouken@3596
   357
        switch (blendMode) {
slouken@3596
   358
        case SDL_BLENDMODE_BLEND:
slouken@3596
   359
            DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end);
slouken@3596
   360
            break;
slouken@3596
   361
        case SDL_BLENDMODE_ADD:
slouken@3596
   362
            DLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end);
slouken@3596
   363
            break;
slouken@5184
   364
        case SDL_BLENDMODE_MOD:
slouken@5184
   365
            DLINE(Uint32, DRAW_SETPIXEL_MOD_RGB, draw_end);
slouken@5184
   366
            break;
slouken@3596
   367
        default:
slouken@3596
   368
            DLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end);
slouken@3596
   369
            break;
slouken@3596
   370
        }
slouken@3596
   371
    } else {
slouken@2898
   372
        switch (blendMode) {
slouken@2898
   373
        case SDL_BLENDMODE_BLEND:
slouken@3596
   374
            AALINE(x1, y1, x2, y2,
slouken@3596
   375
                   DRAW_SETPIXELXY4_BLEND_RGB, DRAW_SETPIXELXY4_BLEND_RGB,
slouken@3596
   376
                   draw_end);
slouken@3596
   377
            break;
slouken@3596
   378
        case SDL_BLENDMODE_ADD:
slouken@3596
   379
            AALINE(x1, y1, x2, y2,
slouken@3596
   380
                   DRAW_SETPIXELXY4_ADD_RGB, DRAW_SETPIXELXY4_ADD_RGB,
slouken@3596
   381
                   draw_end);
slouken@3596
   382
            break;
slouken@5184
   383
        case SDL_BLENDMODE_MOD:
slouken@5184
   384
            AALINE(x1, y1, x2, y2,
slouken@5184
   385
                   DRAW_SETPIXELXY4_MOD_RGB, DRAW_SETPIXELXY4_MOD_RGB,
slouken@5184
   386
                   draw_end);
slouken@5184
   387
            break;
slouken@3596
   388
        default:
slouken@3596
   389
            AALINE(x1, y1, x2, y2,
slouken@3596
   390
                   DRAW_SETPIXELXY4_RGB, DRAW_SETPIXELXY4_BLEND_RGB,
slouken@3596
   391
                   draw_end);
slouken@3596
   392
            break;
slouken@3596
   393
        }
slouken@3596
   394
    }
slouken@3596
   395
}
slouken@3596
   396
slouken@3596
   397
static void
slouken@3596
   398
SDL_BlendLine_RGBA4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
slouken@4929
   399
                    SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
slouken@3596
   400
                    SDL_bool draw_end)
slouken@3596
   401
{
slouken@3596
   402
    const SDL_PixelFormat *fmt = dst->format;
slouken@3596
   403
    unsigned r, g, b, a, inva;
slouken@3596
   404
slouken@3596
   405
    if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
slouken@3596
   406
        r = DRAW_MUL(_r, _a);
slouken@3596
   407
        g = DRAW_MUL(_g, _a);
slouken@3596
   408
        b = DRAW_MUL(_b, _a);
slouken@3596
   409
        a = _a;
slouken@3596
   410
    } else {
slouken@3596
   411
        r = _r;
slouken@3596
   412
        g = _g;
slouken@3596
   413
        b = _b;
slouken@3596
   414
        a = _a;
slouken@3596
   415
    }
slouken@3596
   416
    inva = (a ^ 0xff);
slouken@3596
   417
slouken@3596
   418
    if (y1 == y2) {
slouken@3596
   419
        switch (blendMode) {
slouken@3596
   420
        case SDL_BLENDMODE_BLEND:
slouken@3596
   421
            HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end);
slouken@3596
   422
            break;
slouken@3596
   423
        case SDL_BLENDMODE_ADD:
slouken@3596
   424
            HLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end);
slouken@3596
   425
            break;
slouken@5184
   426
        case SDL_BLENDMODE_MOD:
slouken@5184
   427
            HLINE(Uint32, DRAW_SETPIXEL_MOD_RGBA, draw_end);
slouken@5184
   428
            break;
slouken@3596
   429
        default:
slouken@3596
   430
            HLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end);
slouken@3596
   431
            break;
slouken@3596
   432
        }
slouken@3596
   433
    } else if (x1 == x2) {
slouken@3596
   434
        switch (blendMode) {
slouken@3596
   435
        case SDL_BLENDMODE_BLEND:
slouken@3596
   436
            VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end);
slouken@3596
   437
            break;
slouken@3596
   438
        case SDL_BLENDMODE_ADD:
slouken@3596
   439
            VLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end);
slouken@3596
   440
            break;
slouken@5184
   441
        case SDL_BLENDMODE_MOD:
slouken@5184
   442
            VLINE(Uint32, DRAW_SETPIXEL_MOD_RGBA, draw_end);
slouken@5184
   443
            break;
slouken@3596
   444
        default:
slouken@3596
   445
            VLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end);
slouken@3596
   446
            break;
slouken@3596
   447
        }
slouken@3596
   448
    } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
slouken@3596
   449
        switch (blendMode) {
slouken@3596
   450
        case SDL_BLENDMODE_BLEND:
slouken@3596
   451
            DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end);
slouken@3596
   452
            break;
slouken@3596
   453
        case SDL_BLENDMODE_ADD:
slouken@3596
   454
            DLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end);
slouken@3596
   455
            break;
slouken@5184
   456
        case SDL_BLENDMODE_MOD:
slouken@5184
   457
            DLINE(Uint32, DRAW_SETPIXEL_MOD_RGBA, draw_end);
slouken@5184
   458
            break;
slouken@3596
   459
        default:
slouken@3596
   460
            DLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end);
slouken@3596
   461
            break;
slouken@3596
   462
        }
slouken@3596
   463
    } else {
slouken@3596
   464
        switch (blendMode) {
slouken@3596
   465
        case SDL_BLENDMODE_BLEND:
slouken@3596
   466
            AALINE(x1, y1, x2, y2,
slouken@3596
   467
                   DRAW_SETPIXELXY4_BLEND_RGBA, DRAW_SETPIXELXY4_BLEND_RGBA,
slouken@3596
   468
                   draw_end);
slouken@2898
   469
            break;
slouken@2898
   470
        case SDL_BLENDMODE_ADD:
slouken@3596
   471
            AALINE(x1, y1, x2, y2,
slouken@3596
   472
                   DRAW_SETPIXELXY4_ADD_RGBA, DRAW_SETPIXELXY4_ADD_RGBA,
slouken@3596
   473
                   draw_end);
slouken@3596
   474
            break;
slouken@5184
   475
        case SDL_BLENDMODE_MOD:
slouken@5184
   476
            AALINE(x1, y1, x2, y2,
slouken@5184
   477
                   DRAW_SETPIXELXY4_MOD_RGBA, DRAW_SETPIXELXY4_MOD_RGBA,
slouken@5184
   478
                   draw_end);
slouken@5184
   479
            break;
slouken@3596
   480
        default:
slouken@3596
   481
            AALINE(x1, y1, x2, y2,
slouken@3596
   482
                   DRAW_SETPIXELXY4_RGBA, DRAW_SETPIXELXY4_BLEND_RGBA,
slouken@3596
   483
                   draw_end);
slouken@3596
   484
            break;
slouken@3596
   485
        }
slouken@3596
   486
    }
slouken@3596
   487
}
slouken@3596
   488
slouken@3596
   489
static void
slouken@3596
   490
SDL_BlendLine_RGB888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
slouken@4929
   491
                     SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
slouken@3596
   492
                     SDL_bool draw_end)
slouken@3596
   493
{
slouken@3596
   494
    const SDL_PixelFormat *fmt = dst->format;
slouken@3596
   495
    unsigned r, g, b, a, inva;
slouken@3596
   496
slouken@3596
   497
    if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
slouken@3596
   498
        r = DRAW_MUL(_r, _a);
slouken@3596
   499
        g = DRAW_MUL(_g, _a);
slouken@3596
   500
        b = DRAW_MUL(_b, _a);
slouken@3596
   501
        a = _a;
slouken@3596
   502
    } else {
slouken@3596
   503
        r = _r;
slouken@3596
   504
        g = _g;
slouken@3596
   505
        b = _b;
slouken@3596
   506
        a = _a;
slouken@3596
   507
    }
slouken@3596
   508
    inva = (a ^ 0xff);
slouken@3596
   509
slouken@3596
   510
    if (y1 == y2) {
slouken@3596
   511
        switch (blendMode) {
slouken@3596
   512
        case SDL_BLENDMODE_BLEND:
slouken@3596
   513
            HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end);
slouken@3596
   514
            break;
slouken@3596
   515
        case SDL_BLENDMODE_ADD:
slouken@3596
   516
            HLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end);
slouken@2898
   517
            break;
slouken@5184
   518
        case SDL_BLENDMODE_MOD:
slouken@5184
   519
            HLINE(Uint32, DRAW_SETPIXEL_MOD_RGB888, draw_end);
slouken@5184
   520
            break;
slouken@3596
   521
        default:
slouken@3596
   522
            HLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end);
slouken@3596
   523
            break;
slouken@3596
   524
        }
slouken@3596
   525
    } else if (x1 == x2) {
slouken@3596
   526
        switch (blendMode) {
slouken@3596
   527
        case SDL_BLENDMODE_BLEND:
slouken@3596
   528
            VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end);
slouken@3596
   529
            break;
slouken@3596
   530
        case SDL_BLENDMODE_ADD:
slouken@3596
   531
            VLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end);
slouken@3596
   532
            break;
slouken@5184
   533
        case SDL_BLENDMODE_MOD:
slouken@5184
   534
            VLINE(Uint32, DRAW_SETPIXEL_MOD_RGB888, draw_end);
slouken@5184
   535
            break;
slouken@3596
   536
        default:
slouken@3596
   537
            VLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end);
slouken@3596
   538
            break;
slouken@3596
   539
        }
slouken@3596
   540
    } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
slouken@3596
   541
        switch (blendMode) {
slouken@3596
   542
        case SDL_BLENDMODE_BLEND:
slouken@3596
   543
            DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end);
slouken@3596
   544
            break;
slouken@3596
   545
        case SDL_BLENDMODE_ADD:
slouken@3596
   546
            DLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end);
slouken@3596
   547
            break;
slouken@5184
   548
        case SDL_BLENDMODE_MOD:
slouken@5184
   549
            DLINE(Uint32, DRAW_SETPIXEL_MOD_RGB888, draw_end);
slouken@5184
   550
            break;
slouken@3596
   551
        default:
slouken@3596
   552
            DLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end);
slouken@3596
   553
            break;
slouken@3596
   554
        }
slouken@3596
   555
    } else {
slouken@3596
   556
        switch (blendMode) {
slouken@3596
   557
        case SDL_BLENDMODE_BLEND:
slouken@3596
   558
            AALINE(x1, y1, x2, y2,
slouken@3596
   559
                   DRAW_SETPIXELXY_BLEND_RGB888, DRAW_SETPIXELXY_BLEND_RGB888,
slouken@3596
   560
                   draw_end);
slouken@3596
   561
            break;
slouken@3596
   562
        case SDL_BLENDMODE_ADD:
slouken@3596
   563
            AALINE(x1, y1, x2, y2,
slouken@3596
   564
                   DRAW_SETPIXELXY_ADD_RGB888, DRAW_SETPIXELXY_ADD_RGB888,
slouken@3596
   565
                   draw_end);
slouken@3596
   566
            break;
slouken@5184
   567
        case SDL_BLENDMODE_MOD:
slouken@5184
   568
            AALINE(x1, y1, x2, y2,
slouken@5184
   569
                   DRAW_SETPIXELXY_MOD_RGB888, DRAW_SETPIXELXY_MOD_RGB888,
slouken@5184
   570
                   draw_end);
slouken@5184
   571
            break;
slouken@2898
   572
        default:
slouken@3596
   573
            AALINE(x1, y1, x2, y2,
slouken@3596
   574
                   DRAW_SETPIXELXY_RGB888, DRAW_SETPIXELXY_BLEND_RGB888,
slouken@3596
   575
                   draw_end);
slouken@3596
   576
            break;
slouken@3596
   577
        }
slouken@3596
   578
    }
slouken@3596
   579
}
slouken@3596
   580
slouken@3596
   581
static void
slouken@3596
   582
SDL_BlendLine_ARGB8888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
slouken@4929
   583
                       SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
slouken@3596
   584
                       SDL_bool draw_end)
slouken@3596
   585
{
slouken@3596
   586
    const SDL_PixelFormat *fmt = dst->format;
slouken@3596
   587
    unsigned r, g, b, a, inva;
slouken@3596
   588
slouken@3596
   589
    if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
slouken@3596
   590
        r = DRAW_MUL(_r, _a);
slouken@3596
   591
        g = DRAW_MUL(_g, _a);
slouken@3596
   592
        b = DRAW_MUL(_b, _a);
slouken@3596
   593
        a = _a;
slouken@3596
   594
    } else {
slouken@3596
   595
        r = _r;
slouken@3596
   596
        g = _g;
slouken@3596
   597
        b = _b;
slouken@3596
   598
        a = _a;
slouken@3596
   599
    }
slouken@3596
   600
    inva = (a ^ 0xff);
slouken@3596
   601
slouken@3596
   602
    if (y1 == y2) {
slouken@3596
   603
        switch (blendMode) {
slouken@3596
   604
        case SDL_BLENDMODE_BLEND:
slouken@3596
   605
            HLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end);
slouken@3596
   606
            break;
slouken@3596
   607
        case SDL_BLENDMODE_ADD:
slouken@3596
   608
            HLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end);
slouken@3596
   609
            break;
slouken@5184
   610
        case SDL_BLENDMODE_MOD:
slouken@5184
   611
            HLINE(Uint32, DRAW_SETPIXEL_MOD_ARGB8888, draw_end);
slouken@5184
   612
            break;
slouken@3596
   613
        default:
slouken@3596
   614
            HLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end);
slouken@3596
   615
            break;
slouken@3596
   616
        }
slouken@3596
   617
    } else if (x1 == x2) {
slouken@3596
   618
        switch (blendMode) {
slouken@3596
   619
        case SDL_BLENDMODE_BLEND:
slouken@3596
   620
            VLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end);
slouken@3596
   621
            break;
slouken@3596
   622
        case SDL_BLENDMODE_ADD:
slouken@3596
   623
            VLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end);
slouken@3596
   624
            break;
slouken@5184
   625
        case SDL_BLENDMODE_MOD:
slouken@5184
   626
            VLINE(Uint32, DRAW_SETPIXEL_MOD_ARGB8888, draw_end);
slouken@5184
   627
            break;
slouken@3596
   628
        default:
slouken@3596
   629
            VLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end);
slouken@2898
   630
            break;
slouken@2898
   631
        }
slouken@3596
   632
    } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
slouken@3596
   633
        switch (blendMode) {
slouken@3596
   634
        case SDL_BLENDMODE_BLEND:
slouken@3596
   635
            DLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end);
slouken@3596
   636
            break;
slouken@3596
   637
        case SDL_BLENDMODE_ADD:
slouken@3596
   638
            DLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end);
slouken@3596
   639
            break;
slouken@5184
   640
        case SDL_BLENDMODE_MOD:
slouken@5184
   641
            DLINE(Uint32, DRAW_SETPIXEL_MOD_ARGB8888, draw_end);
slouken@5184
   642
            break;
slouken@3596
   643
        default:
slouken@3596
   644
            DLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end);
slouken@3596
   645
            break;
slouken@3596
   646
        }
slouken@3596
   647
    } else {
slouken@3596
   648
        switch (blendMode) {
slouken@3596
   649
        case SDL_BLENDMODE_BLEND:
slouken@3596
   650
            AALINE(x1, y1, x2, y2,
slouken@3596
   651
                   DRAW_SETPIXELXY_BLEND_ARGB8888, DRAW_SETPIXELXY_BLEND_ARGB8888,
slouken@3596
   652
                   draw_end);
slouken@3596
   653
            break;
slouken@3596
   654
        case SDL_BLENDMODE_ADD:
slouken@3596
   655
            AALINE(x1, y1, x2, y2,
slouken@3596
   656
                   DRAW_SETPIXELXY_ADD_ARGB8888, DRAW_SETPIXELXY_ADD_ARGB8888,
slouken@3596
   657
                   draw_end);
slouken@3596
   658
            break;
slouken@5184
   659
        case SDL_BLENDMODE_MOD:
slouken@5184
   660
            AALINE(x1, y1, x2, y2,
slouken@5184
   661
                   DRAW_SETPIXELXY_MOD_ARGB8888, DRAW_SETPIXELXY_MOD_ARGB8888,
slouken@5184
   662
                   draw_end);
slouken@5184
   663
            break;
slouken@3596
   664
        default:
slouken@3596
   665
            AALINE(x1, y1, x2, y2,
slouken@3596
   666
                   DRAW_SETPIXELXY_ARGB8888, DRAW_SETPIXELXY_BLEND_ARGB8888,
slouken@3596
   667
                   draw_end);
slouken@3596
   668
            break;
slouken@3596
   669
        }
slouken@2898
   670
    }
slouken@2898
   671
}
slouken@2888
   672
slouken@3596
   673
typedef void (*BlendLineFunc) (SDL_Surface * dst,
slouken@3596
   674
                               int x1, int y1, int x2, int y2,
slouken@4929
   675
                               SDL_BlendMode blendMode,
slouken@3596
   676
                               Uint8 r, Uint8 g, Uint8 b, Uint8 a,
slouken@3596
   677
                               SDL_bool draw_end);
slouken@3596
   678
slouken@3596
   679
static BlendLineFunc
slouken@3596
   680
SDL_CalculateBlendLineFunc(const SDL_PixelFormat * fmt)
slouken@3596
   681
{
slouken@3596
   682
    switch (fmt->BytesPerPixel) {
slouken@3596
   683
    case 2:
slouken@3596
   684
        if (fmt->Rmask == 0x7C00) {
slouken@3596
   685
            return SDL_BlendLine_RGB555;
slouken@3596
   686
        } else if (fmt->Rmask == 0xF800) {
slouken@3596
   687
            return SDL_BlendLine_RGB565;
slouken@3596
   688
        } else {
slouken@3596
   689
            return SDL_BlendLine_RGB2;
slouken@3596
   690
        }
slouken@3596
   691
        break;
slouken@3596
   692
    case 4:
slouken@3596
   693
        if (fmt->Rmask == 0x00FF0000) {
slouken@3596
   694
            if (fmt->Amask) {
slouken@3596
   695
                return SDL_BlendLine_ARGB8888;
slouken@3596
   696
            } else {
slouken@3596
   697
                return SDL_BlendLine_RGB888;
slouken@3596
   698
            }
slouken@3596
   699
        } else {
slouken@3596
   700
            if (fmt->Amask) {
slouken@3596
   701
                return SDL_BlendLine_RGBA4;
slouken@3596
   702
            } else {
slouken@3596
   703
                return SDL_BlendLine_RGB4;
slouken@3596
   704
            }
slouken@3596
   705
        }
slouken@3596
   706
    }
slouken@3596
   707
    return NULL;
slouken@3596
   708
}
slouken@3596
   709
slouken@2888
   710
int
slouken@2888
   711
SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2,
slouken@4929
   712
              SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
slouken@2888
   713
{
slouken@3596
   714
    BlendLineFunc func;
slouken@3596
   715
slouken@3596
   716
    if (!dst) {
slouken@3596
   717
        SDL_SetError("SDL_BlendLine(): Passed NULL destination surface");
slouken@3596
   718
        return -1;
slouken@3596
   719
    }
slouken@3596
   720
slouken@3596
   721
    func = SDL_CalculateBlendLineFunc(dst->format);
slouken@3596
   722
    if (!func) {
slouken@2888
   723
        SDL_SetError("SDL_BlendLine(): Unsupported surface format");
slouken@3596
   724
        return -1;
slouken@2888
   725
    }
slouken@2888
   726
slouken@2888
   727
    /* Perform clipping */
slouken@3596
   728
    /* FIXME: We don't actually want to clip, as it may change line slope */
slouken@2910
   729
    if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
slouken@3596
   730
        return 0;
slouken@2896
   731
    }
slouken@2898
   732
slouken@3596
   733
    func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, SDL_TRUE);
slouken@3596
   734
    return 0;
slouken@2888
   735
}
slouken@2888
   736
slouken@3536
   737
int
slouken@3536
   738
SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count,
slouken@4929
   739
               SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
slouken@3536
   740
{
slouken@3536
   741
    int i;
slouken@3536
   742
    int x1, y1;
slouken@3536
   743
    int x2, y2;
slouken@3596
   744
    SDL_bool draw_end;
slouken@3596
   745
    BlendLineFunc func;
slouken@3536
   746
slouken@3536
   747
    if (!dst) {
slouken@3596
   748
        SDL_SetError("SDL_BlendLines(): Passed NULL destination surface");
slouken@3536
   749
        return -1;
slouken@3536
   750
    }
slouken@3536
   751
slouken@3596
   752
    func = SDL_CalculateBlendLineFunc(dst->format);
slouken@3536
   753
    if (!func) {
slouken@3596
   754
        SDL_SetError("SDL_BlendLines(): Unsupported surface format");
slouken@3596
   755
        return -1;
slouken@3536
   756
    }
slouken@3536
   757
slouken@3536
   758
    for (i = 1; i < count; ++i) {
slouken@3536
   759
        x1 = points[i-1].x;
slouken@3536
   760
        y1 = points[i-1].y;
slouken@3536
   761
        x2 = points[i].x;
slouken@3536
   762
        y2 = points[i].y;
slouken@3536
   763
slouken@3536
   764
        /* Perform clipping */
slouken@3536
   765
        /* FIXME: We don't actually want to clip, as it may change line slope */
slouken@3536
   766
        if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
slouken@3536
   767
            continue;
slouken@3536
   768
        }
slouken@3536
   769
slouken@3596
   770
        /* Draw the end if it was clipped */
slouken@3596
   771
        draw_end = (x2 != points[i].x || y2 != points[i].y);
slouken@3596
   772
slouken@3596
   773
        func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, draw_end);
slouken@3594
   774
    }
slouken@3594
   775
    if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
slouken@3596
   776
        SDL_BlendPoint(dst, points[count-1].x, points[count-1].y,
slouken@3596
   777
                       blendMode, r, g, b, a);
slouken@3536
   778
    }
slouken@3596
   779
    return 0;
slouken@3536
   780
}
slouken@3536
   781
slouken@2888
   782
/* vi: set ts=4 sw=4 expandtab: */