src/render/software/SDL_blendline.c
author Ryan C. Gordon <icculus@icculus.org>
Mon, 20 May 2019 00:41:18 -0400
changeset 12743 c653e9fa9ca9
parent 12503 806492103856
permissions -rw-r--r--
vulkan: Swapped out a free() that should have been an SDL_free().

Fixes (for real this time!) the Visual Studio builds.
slouken@2888
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@12503
     3
  Copyright (C) 1997-2019 Sam Lantinga <slouken@libsdl.org>
slouken@2888
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@2888
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@2888
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@2888
    20
*/
icculus@8093
    21
#include "../../SDL_internal.h"
slouken@2888
    22
slouken@5226
    23
#if !SDL_RENDER_DISABLED
slouken@5226
    24
slouken@2898
    25
#include "SDL_draw.h"
slouken@5163
    26
#include "SDL_blendline.h"
slouken@5166
    27
#include "SDL_blendpoint.h"
slouken@2888
    28
slouken@3596
    29
slouken@3596
    30
static void
slouken@3596
    31
SDL_BlendLine_RGB2(SDL_Surface * dst, int x1, int y1, int x2, int y2,
slouken@4929
    32
                   SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
slouken@3596
    33
                   SDL_bool draw_end)
slouken@2898
    34
{
slouken@3596
    35
    const SDL_PixelFormat *fmt = dst->format;
slouken@3596
    36
    unsigned r, g, b, a, inva;
slouken@2896
    37
slouken@3596
    38
    if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
slouken@3596
    39
        r = DRAW_MUL(_r, _a);
slouken@3596
    40
        g = DRAW_MUL(_g, _a);
slouken@3596
    41
        b = DRAW_MUL(_b, _a);
slouken@3596
    42
        a = _a;
slouken@3596
    43
    } else {
slouken@3596
    44
        r = _r;
slouken@3596
    45
        g = _g;
slouken@3596
    46
        b = _b;
slouken@3596
    47
        a = _a;
slouken@2898
    48
    }
slouken@3596
    49
    inva = (a ^ 0xff);
slouken@2896
    50
slouken@3596
    51
    if (y1 == y2) {
slouken@2898
    52
        switch (blendMode) {
slouken@2898
    53
        case SDL_BLENDMODE_BLEND:
slouken@3596
    54
            HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end);
slouken@2898
    55
            break;
slouken@2898
    56
        case SDL_BLENDMODE_ADD:
slouken@3596
    57
            HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end);
slouken@2898
    58
            break;
slouken@5184
    59
        case SDL_BLENDMODE_MOD:
slouken@5184
    60
            HLINE(Uint16, DRAW_SETPIXEL_MOD_RGB, draw_end);
slouken@5184
    61
            break;
slouken@2898
    62
        default:
slouken@3596
    63
            HLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end);
slouken@2898
    64
            break;
slouken@2898
    65
        }
slouken@3596
    66
    } else if (x1 == x2) {
slouken@2898
    67
        switch (blendMode) {
slouken@2898
    68
        case SDL_BLENDMODE_BLEND:
slouken@3596
    69
            VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end);
slouken@2898
    70
            break;
slouken@2898
    71
        case SDL_BLENDMODE_ADD:
slouken@3596
    72
            VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end);
slouken@2898
    73
            break;
slouken@5184
    74
        case SDL_BLENDMODE_MOD:
slouken@5184
    75
            VLINE(Uint16, DRAW_SETPIXEL_MOD_RGB, draw_end);
slouken@5184
    76
            break;
slouken@2898
    77
        default:
slouken@3596
    78
            VLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end);
slouken@2898
    79
            break;
slouken@2898
    80
        }
slouken@3596
    81
    } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
slouken@3596
    82
        switch (blendMode) {
slouken@3596
    83
        case SDL_BLENDMODE_BLEND:
slouken@3596
    84
            DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end);
slouken@3596
    85
            break;
slouken@3596
    86
        case SDL_BLENDMODE_ADD:
slouken@3596
    87
            DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end);
slouken@3596
    88
            break;
slouken@5184
    89
        case SDL_BLENDMODE_MOD:
slouken@5184
    90
            DLINE(Uint16, DRAW_SETPIXEL_MOD_RGB, draw_end);
slouken@5184
    91
            break;
slouken@3596
    92
        default:
slouken@3596
    93
            DLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end);
slouken@3596
    94
            break;
slouken@3596
    95
        }
slouken@3596
    96
    } else {
slouken@3596
    97
        switch (blendMode) {
slouken@3596
    98
        case SDL_BLENDMODE_BLEND:
slouken@3596
    99
            AALINE(x1, y1, x2, y2,
slouken@3596
   100
                   DRAW_SETPIXELXY2_BLEND_RGB, DRAW_SETPIXELXY2_BLEND_RGB,
slouken@3596
   101
                   draw_end);
slouken@3596
   102
            break;
slouken@3596
   103
        case SDL_BLENDMODE_ADD:
slouken@3596
   104
            AALINE(x1, y1, x2, y2,
slouken@3596
   105
                   DRAW_SETPIXELXY2_ADD_RGB, DRAW_SETPIXELXY2_ADD_RGB,
slouken@3596
   106
                   draw_end);
slouken@3596
   107
            break;
slouken@5184
   108
        case SDL_BLENDMODE_MOD:
slouken@5184
   109
            AALINE(x1, y1, x2, y2,
slouken@5184
   110
                   DRAW_SETPIXELXY2_MOD_RGB, DRAW_SETPIXELXY2_MOD_RGB,
slouken@5184
   111
                   draw_end);
slouken@5184
   112
            break;
slouken@3596
   113
        default:
slouken@3596
   114
            AALINE(x1, y1, x2, y2,
slouken@3596
   115
                   DRAW_SETPIXELXY2_RGB, DRAW_SETPIXELXY2_BLEND_RGB,
slouken@3596
   116
                   draw_end);
slouken@3596
   117
            break;
slouken@3596
   118
        }
slouken@2898
   119
    }
slouken@2898
   120
}
slouken@2896
   121
slouken@3596
   122
static void
slouken@3596
   123
SDL_BlendLine_RGB555(SDL_Surface * dst, int x1, int y1, int x2, int y2,
slouken@4929
   124
                     SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
slouken@3596
   125
                     SDL_bool draw_end)
slouken@3596
   126
{
slouken@3596
   127
    unsigned r, g, b, a, inva;
slouken@3596
   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@3596
   139
    }
slouken@3596
   140
    inva = (a ^ 0xff);
slouken@3596
   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@3596
   210
    }
slouken@3596
   211
}
slouken@3596
   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@3596
   217
{
slouken@3596
   218
    unsigned r, g, b, a, inva;
slouken@3596
   219
slouken@3596
   220
    if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
slouken@3596
   221
        r = DRAW_MUL(_r, _a);
slouken@3596
   222
        g = DRAW_MUL(_g, _a);
slouken@3596
   223
        b = DRAW_MUL(_b, _a);
slouken@3596
   224
        a = _a;
slouken@3596
   225
    } else {
slouken@3596
   226
        r = _r;
slouken@3596
   227
        g = _g;
slouken@3596
   228
        b = _b;
slouken@3596
   229
        a = _a;
slouken@3596
   230
    }
slouken@3596
   231
    inva = (a ^ 0xff);
slouken@3596
   232
slouken@3596
   233
    if (y1 == y2) {
slouken@3596
   234
        switch (blendMode) {
slouken@3596
   235
        case SDL_BLENDMODE_BLEND:
slouken@3596
   236
            HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end);
slouken@3596
   237
            break;
slouken@3596
   238
        case SDL_BLENDMODE_ADD:
slouken@3596
   239
            HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end);
slouken@3596
   240
            break;
slouken@5184
   241
        case SDL_BLENDMODE_MOD:
slouken@5184
   242
            HLINE(Uint16, DRAW_SETPIXEL_MOD_RGB565, draw_end);
slouken@5184
   243
            break;
slouken@3596
   244
        default:
slouken@3596
   245
            HLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end);
slouken@3596
   246
            break;
slouken@3596
   247
        }
slouken@3596
   248
    } else if (x1 == x2) {
slouken@3596
   249
        switch (blendMode) {
slouken@3596
   250
        case SDL_BLENDMODE_BLEND:
slouken@3596
   251
            VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end);
slouken@3596
   252
            break;
slouken@3596
   253
        case SDL_BLENDMODE_ADD:
slouken@3596
   254
            VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end);
slouken@3596
   255
            break;
slouken@5184
   256
        case SDL_BLENDMODE_MOD:
slouken@5184
   257
            VLINE(Uint16, DRAW_SETPIXEL_MOD_RGB565, draw_end);
slouken@5184
   258
            break;
slouken@3596
   259
        default:
slouken@3596
   260
            VLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end);
slouken@3596
   261
            break;
slouken@3596
   262
        }
slouken@3596
   263
    } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
slouken@3596
   264
        switch (blendMode) {
slouken@3596
   265
        case SDL_BLENDMODE_BLEND:
slouken@3596
   266
            DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end);
slouken@3596
   267
            break;
slouken@3596
   268
        case SDL_BLENDMODE_ADD:
slouken@3596
   269
            DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end);
slouken@3596
   270
            break;
slouken@5184
   271
        case SDL_BLENDMODE_MOD:
slouken@5184
   272
            DLINE(Uint16, DRAW_SETPIXEL_MOD_RGB565, draw_end);
slouken@5184
   273
            break;
slouken@3596
   274
        default:
slouken@3596
   275
            DLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end);
slouken@3596
   276
            break;
slouken@3596
   277
        }
slouken@3596
   278
    } else {
slouken@3596
   279
        switch (blendMode) {
slouken@3596
   280
        case SDL_BLENDMODE_BLEND:
slouken@3596
   281
            AALINE(x1, y1, x2, y2,
slouken@3596
   282
                   DRAW_SETPIXELXY_BLEND_RGB565, DRAW_SETPIXELXY_BLEND_RGB565,
slouken@3596
   283
                   draw_end);
slouken@3596
   284
            break;
slouken@3596
   285
        case SDL_BLENDMODE_ADD:
slouken@3596
   286
            AALINE(x1, y1, x2, y2,
slouken@3596
   287
                   DRAW_SETPIXELXY_ADD_RGB565, DRAW_SETPIXELXY_ADD_RGB565,
slouken@3596
   288
                   draw_end);
slouken@3596
   289
            break;
slouken@5184
   290
        case SDL_BLENDMODE_MOD:
slouken@5184
   291
            AALINE(x1, y1, x2, y2,
slouken@5184
   292
                   DRAW_SETPIXELXY_MOD_RGB565, DRAW_SETPIXELXY_MOD_RGB565,
slouken@5184
   293
                   draw_end);
slouken@5184
   294
            break;
slouken@3596
   295
        default:
slouken@3596
   296
            AALINE(x1, y1, x2, y2,
slouken@3596
   297
                   DRAW_SETPIXELXY_RGB565, DRAW_SETPIXELXY_BLEND_RGB565,
slouken@3596
   298
                   draw_end);
slouken@3596
   299
            break;
slouken@3596
   300
        }
slouken@3596
   301
    }
slouken@3596
   302
}
slouken@3596
   303
slouken@3596
   304
static void
slouken@3596
   305
SDL_BlendLine_RGB4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
slouken@4929
   306
                   SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
slouken@3594
   307
                   SDL_bool draw_end)
slouken@2898
   308
{
slouken@3596
   309
    const SDL_PixelFormat *fmt = dst->format;
slouken@3596
   310
    unsigned r, g, b, a, inva;
slouken@2896
   311
slouken@3596
   312
    if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
slouken@3596
   313
        r = DRAW_MUL(_r, _a);
slouken@3596
   314
        g = DRAW_MUL(_g, _a);
slouken@3596
   315
        b = DRAW_MUL(_b, _a);
slouken@3596
   316
        a = _a;
slouken@3596
   317
    } else {
slouken@3596
   318
        r = _r;
slouken@3596
   319
        g = _g;
slouken@3596
   320
        b = _b;
slouken@3596
   321
        a = _a;
slouken@3596
   322
    }
slouken@3596
   323
    inva = (a ^ 0xff);
slouken@3596
   324
slouken@3596
   325
    if (y1 == y2) {
slouken@2898
   326
        switch (blendMode) {
slouken@2898
   327
        case SDL_BLENDMODE_BLEND:
slouken@3596
   328
            HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end);
slouken@2898
   329
            break;
slouken@2898
   330
        case SDL_BLENDMODE_ADD:
slouken@3596
   331
            HLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end);
slouken@2898
   332
            break;
slouken@5184
   333
        case SDL_BLENDMODE_MOD:
slouken@5184
   334
            HLINE(Uint32, DRAW_SETPIXEL_MOD_RGB, draw_end);
slouken@5184
   335
            break;
slouken@2898
   336
        default:
slouken@3596
   337
            HLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end);
slouken@2898
   338
            break;
slouken@2898
   339
        }
slouken@3596
   340
    } else if (x1 == x2) {
slouken@3596
   341
        switch (blendMode) {
slouken@3596
   342
        case SDL_BLENDMODE_BLEND:
slouken@3596
   343
            VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end);
slouken@3596
   344
            break;
slouken@3596
   345
        case SDL_BLENDMODE_ADD:
slouken@3596
   346
            VLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end);
slouken@3596
   347
            break;
slouken@5184
   348
        case SDL_BLENDMODE_MOD:
slouken@5184
   349
            VLINE(Uint32, DRAW_SETPIXEL_MOD_RGB, draw_end);
slouken@5184
   350
            break;
slouken@3596
   351
        default:
slouken@3596
   352
            VLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end);
slouken@3596
   353
            break;
slouken@3596
   354
        }
slouken@3596
   355
    } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
slouken@3596
   356
        switch (blendMode) {
slouken@3596
   357
        case SDL_BLENDMODE_BLEND:
slouken@3596
   358
            DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end);
slouken@3596
   359
            break;
slouken@3596
   360
        case SDL_BLENDMODE_ADD:
slouken@3596
   361
            DLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end);
slouken@3596
   362
            break;
slouken@5184
   363
        case SDL_BLENDMODE_MOD:
slouken@5184
   364
            DLINE(Uint32, DRAW_SETPIXEL_MOD_RGB, draw_end);
slouken@5184
   365
            break;
slouken@3596
   366
        default:
slouken@3596
   367
            DLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end);
slouken@3596
   368
            break;
slouken@3596
   369
        }
slouken@3596
   370
    } else {
slouken@3596
   371
        switch (blendMode) {
slouken@3596
   372
        case SDL_BLENDMODE_BLEND:
slouken@3596
   373
            AALINE(x1, y1, x2, y2,
slouken@3596
   374
                   DRAW_SETPIXELXY4_BLEND_RGB, DRAW_SETPIXELXY4_BLEND_RGB,
slouken@3596
   375
                   draw_end);
slouken@3596
   376
            break;
slouken@3596
   377
        case SDL_BLENDMODE_ADD:
slouken@3596
   378
            AALINE(x1, y1, x2, y2,
slouken@3596
   379
                   DRAW_SETPIXELXY4_ADD_RGB, DRAW_SETPIXELXY4_ADD_RGB,
slouken@3596
   380
                   draw_end);
slouken@3596
   381
            break;
slouken@5184
   382
        case SDL_BLENDMODE_MOD:
slouken@5184
   383
            AALINE(x1, y1, x2, y2,
slouken@5184
   384
                   DRAW_SETPIXELXY4_MOD_RGB, DRAW_SETPIXELXY4_MOD_RGB,
slouken@5184
   385
                   draw_end);
slouken@5184
   386
            break;
slouken@3596
   387
        default:
slouken@3596
   388
            AALINE(x1, y1, x2, y2,
slouken@3596
   389
                   DRAW_SETPIXELXY4_RGB, DRAW_SETPIXELXY4_BLEND_RGB,
slouken@3596
   390
                   draw_end);
slouken@3596
   391
            break;
slouken@3596
   392
        }
slouken@2898
   393
    }
slouken@2898
   394
}
slouken@2888
   395
slouken@3596
   396
static void
slouken@3596
   397
SDL_BlendLine_RGBA4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
slouken@4929
   398
                    SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
slouken@3596
   399
                    SDL_bool draw_end)
slouken@3596
   400
{
slouken@3596
   401
    const SDL_PixelFormat *fmt = dst->format;
slouken@3596
   402
    unsigned r, g, b, a, inva;
slouken@3596
   403
slouken@3596
   404
    if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
slouken@3596
   405
        r = DRAW_MUL(_r, _a);
slouken@3596
   406
        g = DRAW_MUL(_g, _a);
slouken@3596
   407
        b = DRAW_MUL(_b, _a);
slouken@3596
   408
        a = _a;
slouken@3596
   409
    } else {
slouken@3596
   410
        r = _r;
slouken@3596
   411
        g = _g;
slouken@3596
   412
        b = _b;
slouken@3596
   413
        a = _a;
slouken@3596
   414
    }
slouken@3596
   415
    inva = (a ^ 0xff);
slouken@3596
   416
slouken@3596
   417
    if (y1 == y2) {
slouken@3596
   418
        switch (blendMode) {
slouken@3596
   419
        case SDL_BLENDMODE_BLEND:
slouken@3596
   420
            HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end);
slouken@3596
   421
            break;
slouken@3596
   422
        case SDL_BLENDMODE_ADD:
slouken@3596
   423
            HLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end);
slouken@3596
   424
            break;
slouken@5184
   425
        case SDL_BLENDMODE_MOD:
slouken@5184
   426
            HLINE(Uint32, DRAW_SETPIXEL_MOD_RGBA, draw_end);
slouken@5184
   427
            break;
slouken@3596
   428
        default:
slouken@3596
   429
            HLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end);
slouken@3596
   430
            break;
slouken@3596
   431
        }
slouken@3596
   432
    } else if (x1 == x2) {
slouken@3596
   433
        switch (blendMode) {
slouken@3596
   434
        case SDL_BLENDMODE_BLEND:
slouken@3596
   435
            VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end);
slouken@3596
   436
            break;
slouken@3596
   437
        case SDL_BLENDMODE_ADD:
slouken@3596
   438
            VLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end);
slouken@3596
   439
            break;
slouken@5184
   440
        case SDL_BLENDMODE_MOD:
slouken@5184
   441
            VLINE(Uint32, DRAW_SETPIXEL_MOD_RGBA, draw_end);
slouken@5184
   442
            break;
slouken@3596
   443
        default:
slouken@3596
   444
            VLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end);
slouken@3596
   445
            break;
slouken@3596
   446
        }
slouken@3596
   447
    } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
slouken@3596
   448
        switch (blendMode) {
slouken@3596
   449
        case SDL_BLENDMODE_BLEND:
slouken@3596
   450
            DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end);
slouken@3596
   451
            break;
slouken@3596
   452
        case SDL_BLENDMODE_ADD:
slouken@3596
   453
            DLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end);
slouken@3596
   454
            break;
slouken@5184
   455
        case SDL_BLENDMODE_MOD:
slouken@5184
   456
            DLINE(Uint32, DRAW_SETPIXEL_MOD_RGBA, draw_end);
slouken@5184
   457
            break;
slouken@3596
   458
        default:
slouken@3596
   459
            DLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end);
slouken@3596
   460
            break;
slouken@3596
   461
        }
slouken@3596
   462
    } else {
slouken@3596
   463
        switch (blendMode) {
slouken@3596
   464
        case SDL_BLENDMODE_BLEND:
slouken@3596
   465
            AALINE(x1, y1, x2, y2,
slouken@3596
   466
                   DRAW_SETPIXELXY4_BLEND_RGBA, DRAW_SETPIXELXY4_BLEND_RGBA,
slouken@3596
   467
                   draw_end);
slouken@3596
   468
            break;
slouken@3596
   469
        case SDL_BLENDMODE_ADD:
slouken@3596
   470
            AALINE(x1, y1, x2, y2,
slouken@3596
   471
                   DRAW_SETPIXELXY4_ADD_RGBA, DRAW_SETPIXELXY4_ADD_RGBA,
slouken@3596
   472
                   draw_end);
slouken@3596
   473
            break;
slouken@5184
   474
        case SDL_BLENDMODE_MOD:
slouken@5184
   475
            AALINE(x1, y1, x2, y2,
slouken@5184
   476
                   DRAW_SETPIXELXY4_MOD_RGBA, DRAW_SETPIXELXY4_MOD_RGBA,
slouken@5184
   477
                   draw_end);
slouken@5184
   478
            break;
slouken@3596
   479
        default:
slouken@3596
   480
            AALINE(x1, y1, x2, y2,
slouken@3596
   481
                   DRAW_SETPIXELXY4_RGBA, DRAW_SETPIXELXY4_BLEND_RGBA,
slouken@3596
   482
                   draw_end);
slouken@3596
   483
            break;
slouken@3596
   484
        }
slouken@3596
   485
    }
slouken@3596
   486
}
slouken@3596
   487
slouken@3596
   488
static void
slouken@3596
   489
SDL_BlendLine_RGB888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
slouken@4929
   490
                     SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
slouken@3596
   491
                     SDL_bool draw_end)
slouken@3596
   492
{
slouken@3596
   493
    unsigned r, g, b, a, inva;
slouken@3596
   494
slouken@3596
   495
    if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
slouken@3596
   496
        r = DRAW_MUL(_r, _a);
slouken@3596
   497
        g = DRAW_MUL(_g, _a);
slouken@3596
   498
        b = DRAW_MUL(_b, _a);
slouken@3596
   499
        a = _a;
slouken@3596
   500
    } else {
slouken@3596
   501
        r = _r;
slouken@3596
   502
        g = _g;
slouken@3596
   503
        b = _b;
slouken@3596
   504
        a = _a;
slouken@3596
   505
    }
slouken@3596
   506
    inva = (a ^ 0xff);
slouken@3596
   507
slouken@3596
   508
    if (y1 == y2) {
slouken@3596
   509
        switch (blendMode) {
slouken@3596
   510
        case SDL_BLENDMODE_BLEND:
slouken@3596
   511
            HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end);
slouken@3596
   512
            break;
slouken@3596
   513
        case SDL_BLENDMODE_ADD:
slouken@3596
   514
            HLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end);
slouken@3596
   515
            break;
slouken@5184
   516
        case SDL_BLENDMODE_MOD:
slouken@5184
   517
            HLINE(Uint32, DRAW_SETPIXEL_MOD_RGB888, draw_end);
slouken@5184
   518
            break;
slouken@3596
   519
        default:
slouken@3596
   520
            HLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end);
slouken@3596
   521
            break;
slouken@3596
   522
        }
slouken@3596
   523
    } else if (x1 == x2) {
slouken@3596
   524
        switch (blendMode) {
slouken@3596
   525
        case SDL_BLENDMODE_BLEND:
slouken@3596
   526
            VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end);
slouken@3596
   527
            break;
slouken@3596
   528
        case SDL_BLENDMODE_ADD:
slouken@3596
   529
            VLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end);
slouken@3596
   530
            break;
slouken@5184
   531
        case SDL_BLENDMODE_MOD:
slouken@5184
   532
            VLINE(Uint32, DRAW_SETPIXEL_MOD_RGB888, draw_end);
slouken@5184
   533
            break;
slouken@3596
   534
        default:
slouken@3596
   535
            VLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end);
slouken@3596
   536
            break;
slouken@3596
   537
        }
slouken@3596
   538
    } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
slouken@3596
   539
        switch (blendMode) {
slouken@3596
   540
        case SDL_BLENDMODE_BLEND:
slouken@3596
   541
            DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end);
slouken@3596
   542
            break;
slouken@3596
   543
        case SDL_BLENDMODE_ADD:
slouken@3596
   544
            DLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end);
slouken@3596
   545
            break;
slouken@5184
   546
        case SDL_BLENDMODE_MOD:
slouken@5184
   547
            DLINE(Uint32, DRAW_SETPIXEL_MOD_RGB888, draw_end);
slouken@5184
   548
            break;
slouken@3596
   549
        default:
slouken@3596
   550
            DLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end);
slouken@3596
   551
            break;
slouken@3596
   552
        }
slouken@3596
   553
    } else {
slouken@3596
   554
        switch (blendMode) {
slouken@3596
   555
        case SDL_BLENDMODE_BLEND:
slouken@3596
   556
            AALINE(x1, y1, x2, y2,
slouken@3596
   557
                   DRAW_SETPIXELXY_BLEND_RGB888, DRAW_SETPIXELXY_BLEND_RGB888,
slouken@3596
   558
                   draw_end);
slouken@3596
   559
            break;
slouken@3596
   560
        case SDL_BLENDMODE_ADD:
slouken@3596
   561
            AALINE(x1, y1, x2, y2,
slouken@3596
   562
                   DRAW_SETPIXELXY_ADD_RGB888, DRAW_SETPIXELXY_ADD_RGB888,
slouken@3596
   563
                   draw_end);
slouken@3596
   564
            break;
slouken@5184
   565
        case SDL_BLENDMODE_MOD:
slouken@5184
   566
            AALINE(x1, y1, x2, y2,
slouken@5184
   567
                   DRAW_SETPIXELXY_MOD_RGB888, DRAW_SETPIXELXY_MOD_RGB888,
slouken@5184
   568
                   draw_end);
slouken@5184
   569
            break;
slouken@3596
   570
        default:
slouken@3596
   571
            AALINE(x1, y1, x2, y2,
slouken@3596
   572
                   DRAW_SETPIXELXY_RGB888, DRAW_SETPIXELXY_BLEND_RGB888,
slouken@3596
   573
                   draw_end);
slouken@3596
   574
            break;
slouken@3596
   575
        }
slouken@3596
   576
    }
slouken@3596
   577
}
slouken@3596
   578
slouken@3596
   579
static void
slouken@3596
   580
SDL_BlendLine_ARGB8888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
slouken@4929
   581
                       SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
slouken@3596
   582
                       SDL_bool draw_end)
slouken@3596
   583
{
slouken@3596
   584
    unsigned r, g, b, a, inva;
slouken@3596
   585
slouken@3596
   586
    if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
slouken@3596
   587
        r = DRAW_MUL(_r, _a);
slouken@3596
   588
        g = DRAW_MUL(_g, _a);
slouken@3596
   589
        b = DRAW_MUL(_b, _a);
slouken@3596
   590
        a = _a;
slouken@3596
   591
    } else {
slouken@3596
   592
        r = _r;
slouken@3596
   593
        g = _g;
slouken@3596
   594
        b = _b;
slouken@3596
   595
        a = _a;
slouken@3596
   596
    }
slouken@3596
   597
    inva = (a ^ 0xff);
slouken@3596
   598
slouken@3596
   599
    if (y1 == y2) {
slouken@3596
   600
        switch (blendMode) {
slouken@3596
   601
        case SDL_BLENDMODE_BLEND:
slouken@3596
   602
            HLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end);
slouken@3596
   603
            break;
slouken@3596
   604
        case SDL_BLENDMODE_ADD:
slouken@3596
   605
            HLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end);
slouken@3596
   606
            break;
slouken@5184
   607
        case SDL_BLENDMODE_MOD:
slouken@5184
   608
            HLINE(Uint32, DRAW_SETPIXEL_MOD_ARGB8888, draw_end);
slouken@5184
   609
            break;
slouken@3596
   610
        default:
slouken@3596
   611
            HLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end);
slouken@3596
   612
            break;
slouken@3596
   613
        }
slouken@3596
   614
    } else if (x1 == x2) {
slouken@3596
   615
        switch (blendMode) {
slouken@3596
   616
        case SDL_BLENDMODE_BLEND:
slouken@3596
   617
            VLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end);
slouken@3596
   618
            break;
slouken@3596
   619
        case SDL_BLENDMODE_ADD:
slouken@3596
   620
            VLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end);
slouken@3596
   621
            break;
slouken@5184
   622
        case SDL_BLENDMODE_MOD:
slouken@5184
   623
            VLINE(Uint32, DRAW_SETPIXEL_MOD_ARGB8888, draw_end);
slouken@5184
   624
            break;
slouken@3596
   625
        default:
slouken@3596
   626
            VLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end);
slouken@3596
   627
            break;
slouken@3596
   628
        }
slouken@3596
   629
    } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
slouken@3596
   630
        switch (blendMode) {
slouken@3596
   631
        case SDL_BLENDMODE_BLEND:
slouken@3596
   632
            DLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end);
slouken@3596
   633
            break;
slouken@3596
   634
        case SDL_BLENDMODE_ADD:
slouken@3596
   635
            DLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end);
slouken@3596
   636
            break;
slouken@5184
   637
        case SDL_BLENDMODE_MOD:
slouken@5184
   638
            DLINE(Uint32, DRAW_SETPIXEL_MOD_ARGB8888, draw_end);
slouken@5184
   639
            break;
slouken@3596
   640
        default:
slouken@3596
   641
            DLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end);
slouken@3596
   642
            break;
slouken@3596
   643
        }
slouken@3596
   644
    } else {
slouken@3596
   645
        switch (blendMode) {
slouken@3596
   646
        case SDL_BLENDMODE_BLEND:
slouken@3596
   647
            AALINE(x1, y1, x2, y2,
slouken@3596
   648
                   DRAW_SETPIXELXY_BLEND_ARGB8888, DRAW_SETPIXELXY_BLEND_ARGB8888,
slouken@3596
   649
                   draw_end);
slouken@3596
   650
            break;
slouken@3596
   651
        case SDL_BLENDMODE_ADD:
slouken@3596
   652
            AALINE(x1, y1, x2, y2,
slouken@3596
   653
                   DRAW_SETPIXELXY_ADD_ARGB8888, DRAW_SETPIXELXY_ADD_ARGB8888,
slouken@3596
   654
                   draw_end);
slouken@3596
   655
            break;
slouken@5184
   656
        case SDL_BLENDMODE_MOD:
slouken@5184
   657
            AALINE(x1, y1, x2, y2,
slouken@5184
   658
                   DRAW_SETPIXELXY_MOD_ARGB8888, DRAW_SETPIXELXY_MOD_ARGB8888,
slouken@5184
   659
                   draw_end);
slouken@5184
   660
            break;
slouken@3596
   661
        default:
slouken@3596
   662
            AALINE(x1, y1, x2, y2,
slouken@3596
   663
                   DRAW_SETPIXELXY_ARGB8888, DRAW_SETPIXELXY_BLEND_ARGB8888,
slouken@3596
   664
                   draw_end);
slouken@3596
   665
            break;
slouken@3596
   666
        }
slouken@3596
   667
    }
slouken@3596
   668
}
slouken@3596
   669
slouken@3596
   670
typedef void (*BlendLineFunc) (SDL_Surface * dst,
slouken@3596
   671
                               int x1, int y1, int x2, int y2,
slouken@4929
   672
                               SDL_BlendMode blendMode,
slouken@3596
   673
                               Uint8 r, Uint8 g, Uint8 b, Uint8 a,
slouken@3596
   674
                               SDL_bool draw_end);
slouken@3596
   675
slouken@3596
   676
static BlendLineFunc
slouken@3596
   677
SDL_CalculateBlendLineFunc(const SDL_PixelFormat * fmt)
slouken@3596
   678
{
slouken@3596
   679
    switch (fmt->BytesPerPixel) {
slouken@3596
   680
    case 2:
slouken@3596
   681
        if (fmt->Rmask == 0x7C00) {
slouken@3596
   682
            return SDL_BlendLine_RGB555;
slouken@3596
   683
        } else if (fmt->Rmask == 0xF800) {
slouken@3596
   684
            return SDL_BlendLine_RGB565;
slouken@3596
   685
        } else {
slouken@3596
   686
            return SDL_BlendLine_RGB2;
slouken@3596
   687
        }
slouken@10609
   688
        /* break; -Wunreachable-code-break */
slouken@3596
   689
    case 4:
slouken@3596
   690
        if (fmt->Rmask == 0x00FF0000) {
slouken@3596
   691
            if (fmt->Amask) {
slouken@3596
   692
                return SDL_BlendLine_ARGB8888;
slouken@3596
   693
            } else {
slouken@3596
   694
                return SDL_BlendLine_RGB888;
slouken@3596
   695
            }
slouken@3596
   696
        } else {
slouken@3596
   697
            if (fmt->Amask) {
slouken@3596
   698
                return SDL_BlendLine_RGBA4;
slouken@3596
   699
            } else {
slouken@3596
   700
                return SDL_BlendLine_RGB4;
slouken@3596
   701
            }
slouken@3596
   702
        }
slouken@3596
   703
    }
slouken@3596
   704
    return NULL;
slouken@3596
   705
}
slouken@3596
   706
slouken@2888
   707
int
slouken@2888
   708
SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2,
slouken@4929
   709
              SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
slouken@2888
   710
{
slouken@3596
   711
    BlendLineFunc func;
slouken@3596
   712
slouken@3596
   713
    if (!dst) {
icculus@7037
   714
        return SDL_SetError("SDL_BlendLine(): Passed NULL destination surface");
slouken@3596
   715
    }
slouken@3596
   716
slouken@3596
   717
    func = SDL_CalculateBlendLineFunc(dst->format);
slouken@3596
   718
    if (!func) {
icculus@7037
   719
        return SDL_SetError("SDL_BlendLine(): Unsupported surface format");
slouken@2888
   720
    }
slouken@2888
   721
slouken@2888
   722
    /* Perform clipping */
slouken@3596
   723
    /* FIXME: We don't actually want to clip, as it may change line slope */
slouken@2910
   724
    if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
slouken@3596
   725
        return 0;
slouken@2909
   726
    }
slouken@2909
   727
slouken@3596
   728
    func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, SDL_TRUE);
slouken@3596
   729
    return 0;
slouken@2888
   730
}
slouken@2888
   731
slouken@3536
   732
int
slouken@3536
   733
SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count,
slouken@4929
   734
               SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
slouken@3536
   735
{
slouken@3536
   736
    int i;
slouken@3536
   737
    int x1, y1;
slouken@3536
   738
    int x2, y2;
slouken@3596
   739
    SDL_bool draw_end;
slouken@3596
   740
    BlendLineFunc func;
slouken@3536
   741
slouken@3536
   742
    if (!dst) {
icculus@7037
   743
        return SDL_SetError("SDL_BlendLines(): Passed NULL destination surface");
slouken@3536
   744
    }
slouken@3536
   745
slouken@3596
   746
    func = SDL_CalculateBlendLineFunc(dst->format);
slouken@3596
   747
    if (!func) {
icculus@7037
   748
        return SDL_SetError("SDL_BlendLines(): Unsupported surface format");
slouken@3536
   749
    }
slouken@3536
   750
slouken@3536
   751
    for (i = 1; i < count; ++i) {
slouken@3536
   752
        x1 = points[i-1].x;
slouken@3536
   753
        y1 = points[i-1].y;
slouken@3536
   754
        x2 = points[i].x;
slouken@3536
   755
        y2 = points[i].y;
slouken@3536
   756
slouken@3536
   757
        /* Perform clipping */
slouken@3536
   758
        /* FIXME: We don't actually want to clip, as it may change line slope */
slouken@3536
   759
        if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
slouken@3536
   760
            continue;
slouken@3536
   761
        }
slouken@3536
   762
slouken@3596
   763
        /* Draw the end if it was clipped */
slouken@3596
   764
        draw_end = (x2 != points[i].x || y2 != points[i].y);
slouken@3596
   765
slouken@3596
   766
        func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, draw_end);
slouken@3594
   767
    }
slouken@3594
   768
    if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
slouken@3596
   769
        SDL_BlendPoint(dst, points[count-1].x, points[count-1].y,
slouken@3596
   770
                       blendMode, r, g, b, a);
slouken@3536
   771
    }
slouken@3596
   772
    return 0;
slouken@3536
   773
}
slouken@3536
   774
slouken@5226
   775
#endif /* !SDL_RENDER_DISABLED */
slouken@5226
   776
slouken@2888
   777
/* vi: set ts=4 sw=4 expandtab: */