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