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