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