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