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