src/render/software/SDL_blendline.c
changeset 5163 d72793305335
parent 5140 e743b9c3f6d6
child 5166 4d39eeaad00b
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/render/software/SDL_blendline.c	Thu Feb 03 02:45:29 2011 -0800
     1.3 @@ -0,0 +1,683 @@
     1.4 +/*
     1.5 +    SDL - Simple DirectMedia Layer
     1.6 +    Copyright (C) 1997-2010 Sam Lantinga
     1.7 +
     1.8 +    This library is free software; you can redistribute it and/or
     1.9 +    modify it under the terms of the GNU Lesser General Public
    1.10 +    License as published by the Free Software Foundation; either
    1.11 +    version 2.1 of the License, or (at your option) any later version.
    1.12 +
    1.13 +    This library is distributed in the hope that it will be useful,
    1.14 +    but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.15 +    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    1.16 +    Lesser General Public License for more details.
    1.17 +
    1.18 +    You should have received a copy of the GNU Lesser General Public
    1.19 +    License along with this library; if not, write to the Free Software
    1.20 +    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    1.21 +
    1.22 +    Sam Lantinga
    1.23 +    slouken@libsdl.org
    1.24 +*/
    1.25 +#include "SDL_config.h"
    1.26 +
    1.27 +#include "SDL_draw.h"
    1.28 +#include "SDL_blendline.h"
    1.29 +
    1.30 +
    1.31 +static void
    1.32 +SDL_BlendLine_RGB2(SDL_Surface * dst, int x1, int y1, int x2, int y2,
    1.33 +                   SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
    1.34 +                   SDL_bool draw_end)
    1.35 +{
    1.36 +    const SDL_PixelFormat *fmt = dst->format;
    1.37 +    unsigned r, g, b, a, inva;
    1.38 +
    1.39 +    if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
    1.40 +        r = DRAW_MUL(_r, _a);
    1.41 +        g = DRAW_MUL(_g, _a);
    1.42 +        b = DRAW_MUL(_b, _a);
    1.43 +        a = _a;
    1.44 +    } else {
    1.45 +        r = _r;
    1.46 +        g = _g;
    1.47 +        b = _b;
    1.48 +        a = _a;
    1.49 +    }
    1.50 +    inva = (a ^ 0xff);
    1.51 +
    1.52 +    if (y1 == y2) {
    1.53 +        switch (blendMode) {
    1.54 +        case SDL_BLENDMODE_BLEND:
    1.55 +            HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end);
    1.56 +            break;
    1.57 +        case SDL_BLENDMODE_ADD:
    1.58 +            HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end);
    1.59 +            break;
    1.60 +        default:
    1.61 +            HLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end);
    1.62 +            break;
    1.63 +        }
    1.64 +    } else if (x1 == x2) {
    1.65 +        switch (blendMode) {
    1.66 +        case SDL_BLENDMODE_BLEND:
    1.67 +            VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end);
    1.68 +            break;
    1.69 +        case SDL_BLENDMODE_ADD:
    1.70 +            VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end);
    1.71 +            break;
    1.72 +        default:
    1.73 +            VLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end);
    1.74 +            break;
    1.75 +        }
    1.76 +    } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
    1.77 +        switch (blendMode) {
    1.78 +        case SDL_BLENDMODE_BLEND:
    1.79 +            DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB, draw_end);
    1.80 +            break;
    1.81 +        case SDL_BLENDMODE_ADD:
    1.82 +            DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB, draw_end);
    1.83 +            break;
    1.84 +        default:
    1.85 +            DLINE(Uint16, DRAW_SETPIXEL_RGB, draw_end);
    1.86 +            break;
    1.87 +        }
    1.88 +    } else {
    1.89 +        switch (blendMode) {
    1.90 +        case SDL_BLENDMODE_BLEND:
    1.91 +            AALINE(x1, y1, x2, y2,
    1.92 +                   DRAW_SETPIXELXY2_BLEND_RGB, DRAW_SETPIXELXY2_BLEND_RGB,
    1.93 +                   draw_end);
    1.94 +            break;
    1.95 +        case SDL_BLENDMODE_ADD:
    1.96 +            AALINE(x1, y1, x2, y2,
    1.97 +                   DRAW_SETPIXELXY2_ADD_RGB, DRAW_SETPIXELXY2_ADD_RGB,
    1.98 +                   draw_end);
    1.99 +            break;
   1.100 +        default:
   1.101 +            AALINE(x1, y1, x2, y2,
   1.102 +                   DRAW_SETPIXELXY2_RGB, DRAW_SETPIXELXY2_BLEND_RGB,
   1.103 +                   draw_end);
   1.104 +            break;
   1.105 +        }
   1.106 +    }
   1.107 +}
   1.108 +
   1.109 +static void
   1.110 +SDL_BlendLine_RGB555(SDL_Surface * dst, int x1, int y1, int x2, int y2,
   1.111 +                     SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
   1.112 +                     SDL_bool draw_end)
   1.113 +{
   1.114 +    const SDL_PixelFormat *fmt = dst->format;
   1.115 +    unsigned r, g, b, a, inva;
   1.116 +
   1.117 +    if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
   1.118 +        r = DRAW_MUL(_r, _a);
   1.119 +        g = DRAW_MUL(_g, _a);
   1.120 +        b = DRAW_MUL(_b, _a);
   1.121 +        a = _a;
   1.122 +    } else {
   1.123 +        r = _r;
   1.124 +        g = _g;
   1.125 +        b = _b;
   1.126 +        a = _a;
   1.127 +    }
   1.128 +    inva = (a ^ 0xff);
   1.129 +
   1.130 +    if (y1 == y2) {
   1.131 +        switch (blendMode) {
   1.132 +        case SDL_BLENDMODE_BLEND:
   1.133 +            HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end);
   1.134 +            break;
   1.135 +        case SDL_BLENDMODE_ADD:
   1.136 +            HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end);
   1.137 +            break;
   1.138 +        default:
   1.139 +            HLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end);
   1.140 +            break;
   1.141 +        }
   1.142 +    } else if (x1 == x2) {
   1.143 +        switch (blendMode) {
   1.144 +        case SDL_BLENDMODE_BLEND:
   1.145 +            VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end);
   1.146 +            break;
   1.147 +        case SDL_BLENDMODE_ADD:
   1.148 +            VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end);
   1.149 +            break;
   1.150 +        default:
   1.151 +            VLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end);
   1.152 +            break;
   1.153 +        }
   1.154 +    } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
   1.155 +        switch (blendMode) {
   1.156 +        case SDL_BLENDMODE_BLEND:
   1.157 +            DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB555, draw_end);
   1.158 +            break;
   1.159 +        case SDL_BLENDMODE_ADD:
   1.160 +            DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB555, draw_end);
   1.161 +            break;
   1.162 +        default:
   1.163 +            DLINE(Uint16, DRAW_SETPIXEL_RGB555, draw_end);
   1.164 +            break;
   1.165 +        }
   1.166 +    } else {
   1.167 +        switch (blendMode) {
   1.168 +        case SDL_BLENDMODE_BLEND:
   1.169 +            AALINE(x1, y1, x2, y2,
   1.170 +                   DRAW_SETPIXELXY_BLEND_RGB555, DRAW_SETPIXELXY_BLEND_RGB555,
   1.171 +                   draw_end);
   1.172 +            break;
   1.173 +        case SDL_BLENDMODE_ADD:
   1.174 +            AALINE(x1, y1, x2, y2,
   1.175 +                   DRAW_SETPIXELXY_ADD_RGB555, DRAW_SETPIXELXY_ADD_RGB555,
   1.176 +                   draw_end);
   1.177 +            break;
   1.178 +        default:
   1.179 +            AALINE(x1, y1, x2, y2,
   1.180 +                   DRAW_SETPIXELXY_RGB555, DRAW_SETPIXELXY_BLEND_RGB555,
   1.181 +                   draw_end);
   1.182 +            break;
   1.183 +        }
   1.184 +    }
   1.185 +}
   1.186 +
   1.187 +static void
   1.188 +SDL_BlendLine_RGB565(SDL_Surface * dst, int x1, int y1, int x2, int y2,
   1.189 +                     SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
   1.190 +                     SDL_bool draw_end)
   1.191 +{
   1.192 +    const SDL_PixelFormat *fmt = dst->format;
   1.193 +    unsigned r, g, b, a, inva;
   1.194 +
   1.195 +    if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
   1.196 +        r = DRAW_MUL(_r, _a);
   1.197 +        g = DRAW_MUL(_g, _a);
   1.198 +        b = DRAW_MUL(_b, _a);
   1.199 +        a = _a;
   1.200 +    } else {
   1.201 +        r = _r;
   1.202 +        g = _g;
   1.203 +        b = _b;
   1.204 +        a = _a;
   1.205 +    }
   1.206 +    inva = (a ^ 0xff);
   1.207 +
   1.208 +    if (y1 == y2) {
   1.209 +        switch (blendMode) {
   1.210 +        case SDL_BLENDMODE_BLEND:
   1.211 +            HLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end);
   1.212 +            break;
   1.213 +        case SDL_BLENDMODE_ADD:
   1.214 +            HLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end);
   1.215 +            break;
   1.216 +        default:
   1.217 +            HLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end);
   1.218 +            break;
   1.219 +        }
   1.220 +    } else if (x1 == x2) {
   1.221 +        switch (blendMode) {
   1.222 +        case SDL_BLENDMODE_BLEND:
   1.223 +            VLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end);
   1.224 +            break;
   1.225 +        case SDL_BLENDMODE_ADD:
   1.226 +            VLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end);
   1.227 +            break;
   1.228 +        default:
   1.229 +            VLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end);
   1.230 +            break;
   1.231 +        }
   1.232 +    } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
   1.233 +        switch (blendMode) {
   1.234 +        case SDL_BLENDMODE_BLEND:
   1.235 +            DLINE(Uint16, DRAW_SETPIXEL_BLEND_RGB565, draw_end);
   1.236 +            break;
   1.237 +        case SDL_BLENDMODE_ADD:
   1.238 +            DLINE(Uint16, DRAW_SETPIXEL_ADD_RGB565, draw_end);
   1.239 +            break;
   1.240 +        default:
   1.241 +            DLINE(Uint16, DRAW_SETPIXEL_RGB565, draw_end);
   1.242 +            break;
   1.243 +        }
   1.244 +    } else {
   1.245 +        switch (blendMode) {
   1.246 +        case SDL_BLENDMODE_BLEND:
   1.247 +            AALINE(x1, y1, x2, y2,
   1.248 +                   DRAW_SETPIXELXY_BLEND_RGB565, DRAW_SETPIXELXY_BLEND_RGB565,
   1.249 +                   draw_end);
   1.250 +            break;
   1.251 +        case SDL_BLENDMODE_ADD:
   1.252 +            AALINE(x1, y1, x2, y2,
   1.253 +                   DRAW_SETPIXELXY_ADD_RGB565, DRAW_SETPIXELXY_ADD_RGB565,
   1.254 +                   draw_end);
   1.255 +            break;
   1.256 +        default:
   1.257 +            AALINE(x1, y1, x2, y2,
   1.258 +                   DRAW_SETPIXELXY_RGB565, DRAW_SETPIXELXY_BLEND_RGB565,
   1.259 +                   draw_end);
   1.260 +            break;
   1.261 +        }
   1.262 +    }
   1.263 +}
   1.264 +
   1.265 +static void
   1.266 +SDL_BlendLine_RGB4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
   1.267 +                   SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
   1.268 +                   SDL_bool draw_end)
   1.269 +{
   1.270 +    const SDL_PixelFormat *fmt = dst->format;
   1.271 +    unsigned r, g, b, a, inva;
   1.272 +
   1.273 +    if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
   1.274 +        r = DRAW_MUL(_r, _a);
   1.275 +        g = DRAW_MUL(_g, _a);
   1.276 +        b = DRAW_MUL(_b, _a);
   1.277 +        a = _a;
   1.278 +    } else {
   1.279 +        r = _r;
   1.280 +        g = _g;
   1.281 +        b = _b;
   1.282 +        a = _a;
   1.283 +    }
   1.284 +    inva = (a ^ 0xff);
   1.285 +
   1.286 +    if (y1 == y2) {
   1.287 +        switch (blendMode) {
   1.288 +        case SDL_BLENDMODE_BLEND:
   1.289 +            HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end);
   1.290 +            break;
   1.291 +        case SDL_BLENDMODE_ADD:
   1.292 +            HLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end);
   1.293 +            break;
   1.294 +        default:
   1.295 +            HLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end);
   1.296 +            break;
   1.297 +        }
   1.298 +    } else if (x1 == x2) {
   1.299 +        switch (blendMode) {
   1.300 +        case SDL_BLENDMODE_BLEND:
   1.301 +            VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end);
   1.302 +            break;
   1.303 +        case SDL_BLENDMODE_ADD:
   1.304 +            VLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end);
   1.305 +            break;
   1.306 +        default:
   1.307 +            VLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end);
   1.308 +            break;
   1.309 +        }
   1.310 +    } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
   1.311 +        switch (blendMode) {
   1.312 +        case SDL_BLENDMODE_BLEND:
   1.313 +            DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB, draw_end);
   1.314 +            break;
   1.315 +        case SDL_BLENDMODE_ADD:
   1.316 +            DLINE(Uint32, DRAW_SETPIXEL_ADD_RGB, draw_end);
   1.317 +            break;
   1.318 +        default:
   1.319 +            DLINE(Uint32, DRAW_SETPIXEL_RGB, draw_end);
   1.320 +            break;
   1.321 +        }
   1.322 +    } else {
   1.323 +        switch (blendMode) {
   1.324 +        case SDL_BLENDMODE_BLEND:
   1.325 +            AALINE(x1, y1, x2, y2,
   1.326 +                   DRAW_SETPIXELXY4_BLEND_RGB, DRAW_SETPIXELXY4_BLEND_RGB,
   1.327 +                   draw_end);
   1.328 +            break;
   1.329 +        case SDL_BLENDMODE_ADD:
   1.330 +            AALINE(x1, y1, x2, y2,
   1.331 +                   DRAW_SETPIXELXY4_ADD_RGB, DRAW_SETPIXELXY4_ADD_RGB,
   1.332 +                   draw_end);
   1.333 +            break;
   1.334 +        default:
   1.335 +            AALINE(x1, y1, x2, y2,
   1.336 +                   DRAW_SETPIXELXY4_RGB, DRAW_SETPIXELXY4_BLEND_RGB,
   1.337 +                   draw_end);
   1.338 +            break;
   1.339 +        }
   1.340 +    }
   1.341 +}
   1.342 +
   1.343 +static void
   1.344 +SDL_BlendLine_RGBA4(SDL_Surface * dst, int x1, int y1, int x2, int y2,
   1.345 +                    SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
   1.346 +                    SDL_bool draw_end)
   1.347 +{
   1.348 +    const SDL_PixelFormat *fmt = dst->format;
   1.349 +    unsigned r, g, b, a, inva;
   1.350 +
   1.351 +    if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
   1.352 +        r = DRAW_MUL(_r, _a);
   1.353 +        g = DRAW_MUL(_g, _a);
   1.354 +        b = DRAW_MUL(_b, _a);
   1.355 +        a = _a;
   1.356 +    } else {
   1.357 +        r = _r;
   1.358 +        g = _g;
   1.359 +        b = _b;
   1.360 +        a = _a;
   1.361 +    }
   1.362 +    inva = (a ^ 0xff);
   1.363 +
   1.364 +    if (y1 == y2) {
   1.365 +        switch (blendMode) {
   1.366 +        case SDL_BLENDMODE_BLEND:
   1.367 +            HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end);
   1.368 +            break;
   1.369 +        case SDL_BLENDMODE_ADD:
   1.370 +            HLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end);
   1.371 +            break;
   1.372 +        default:
   1.373 +            HLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end);
   1.374 +            break;
   1.375 +        }
   1.376 +    } else if (x1 == x2) {
   1.377 +        switch (blendMode) {
   1.378 +        case SDL_BLENDMODE_BLEND:
   1.379 +            VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end);
   1.380 +            break;
   1.381 +        case SDL_BLENDMODE_ADD:
   1.382 +            VLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end);
   1.383 +            break;
   1.384 +        default:
   1.385 +            VLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end);
   1.386 +            break;
   1.387 +        }
   1.388 +    } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
   1.389 +        switch (blendMode) {
   1.390 +        case SDL_BLENDMODE_BLEND:
   1.391 +            DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGBA, draw_end);
   1.392 +            break;
   1.393 +        case SDL_BLENDMODE_ADD:
   1.394 +            DLINE(Uint32, DRAW_SETPIXEL_ADD_RGBA, draw_end);
   1.395 +            break;
   1.396 +        default:
   1.397 +            DLINE(Uint32, DRAW_SETPIXEL_RGBA, draw_end);
   1.398 +            break;
   1.399 +        }
   1.400 +    } else {
   1.401 +        switch (blendMode) {
   1.402 +        case SDL_BLENDMODE_BLEND:
   1.403 +            AALINE(x1, y1, x2, y2,
   1.404 +                   DRAW_SETPIXELXY4_BLEND_RGBA, DRAW_SETPIXELXY4_BLEND_RGBA,
   1.405 +                   draw_end);
   1.406 +            break;
   1.407 +        case SDL_BLENDMODE_ADD:
   1.408 +            AALINE(x1, y1, x2, y2,
   1.409 +                   DRAW_SETPIXELXY4_ADD_RGBA, DRAW_SETPIXELXY4_ADD_RGBA,
   1.410 +                   draw_end);
   1.411 +            break;
   1.412 +        default:
   1.413 +            AALINE(x1, y1, x2, y2,
   1.414 +                   DRAW_SETPIXELXY4_RGBA, DRAW_SETPIXELXY4_BLEND_RGBA,
   1.415 +                   draw_end);
   1.416 +            break;
   1.417 +        }
   1.418 +    }
   1.419 +}
   1.420 +
   1.421 +static void
   1.422 +SDL_BlendLine_RGB888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
   1.423 +                     SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
   1.424 +                     SDL_bool draw_end)
   1.425 +{
   1.426 +    const SDL_PixelFormat *fmt = dst->format;
   1.427 +    unsigned r, g, b, a, inva;
   1.428 +
   1.429 +    if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
   1.430 +        r = DRAW_MUL(_r, _a);
   1.431 +        g = DRAW_MUL(_g, _a);
   1.432 +        b = DRAW_MUL(_b, _a);
   1.433 +        a = _a;
   1.434 +    } else {
   1.435 +        r = _r;
   1.436 +        g = _g;
   1.437 +        b = _b;
   1.438 +        a = _a;
   1.439 +    }
   1.440 +    inva = (a ^ 0xff);
   1.441 +
   1.442 +    if (y1 == y2) {
   1.443 +        switch (blendMode) {
   1.444 +        case SDL_BLENDMODE_BLEND:
   1.445 +            HLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end);
   1.446 +            break;
   1.447 +        case SDL_BLENDMODE_ADD:
   1.448 +            HLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end);
   1.449 +            break;
   1.450 +        default:
   1.451 +            HLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end);
   1.452 +            break;
   1.453 +        }
   1.454 +    } else if (x1 == x2) {
   1.455 +        switch (blendMode) {
   1.456 +        case SDL_BLENDMODE_BLEND:
   1.457 +            VLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end);
   1.458 +            break;
   1.459 +        case SDL_BLENDMODE_ADD:
   1.460 +            VLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end);
   1.461 +            break;
   1.462 +        default:
   1.463 +            VLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end);
   1.464 +            break;
   1.465 +        }
   1.466 +    } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
   1.467 +        switch (blendMode) {
   1.468 +        case SDL_BLENDMODE_BLEND:
   1.469 +            DLINE(Uint32, DRAW_SETPIXEL_BLEND_RGB888, draw_end);
   1.470 +            break;
   1.471 +        case SDL_BLENDMODE_ADD:
   1.472 +            DLINE(Uint32, DRAW_SETPIXEL_ADD_RGB888, draw_end);
   1.473 +            break;
   1.474 +        default:
   1.475 +            DLINE(Uint32, DRAW_SETPIXEL_RGB888, draw_end);
   1.476 +            break;
   1.477 +        }
   1.478 +    } else {
   1.479 +        switch (blendMode) {
   1.480 +        case SDL_BLENDMODE_BLEND:
   1.481 +            AALINE(x1, y1, x2, y2,
   1.482 +                   DRAW_SETPIXELXY_BLEND_RGB888, DRAW_SETPIXELXY_BLEND_RGB888,
   1.483 +                   draw_end);
   1.484 +            break;
   1.485 +        case SDL_BLENDMODE_ADD:
   1.486 +            AALINE(x1, y1, x2, y2,
   1.487 +                   DRAW_SETPIXELXY_ADD_RGB888, DRAW_SETPIXELXY_ADD_RGB888,
   1.488 +                   draw_end);
   1.489 +            break;
   1.490 +        default:
   1.491 +            AALINE(x1, y1, x2, y2,
   1.492 +                   DRAW_SETPIXELXY_RGB888, DRAW_SETPIXELXY_BLEND_RGB888,
   1.493 +                   draw_end);
   1.494 +            break;
   1.495 +        }
   1.496 +    }
   1.497 +}
   1.498 +
   1.499 +static void
   1.500 +SDL_BlendLine_ARGB8888(SDL_Surface * dst, int x1, int y1, int x2, int y2,
   1.501 +                       SDL_BlendMode blendMode, Uint8 _r, Uint8 _g, Uint8 _b, Uint8 _a,
   1.502 +                       SDL_bool draw_end)
   1.503 +{
   1.504 +    const SDL_PixelFormat *fmt = dst->format;
   1.505 +    unsigned r, g, b, a, inva;
   1.506 +
   1.507 +    if (blendMode == SDL_BLENDMODE_BLEND || blendMode == SDL_BLENDMODE_ADD) {
   1.508 +        r = DRAW_MUL(_r, _a);
   1.509 +        g = DRAW_MUL(_g, _a);
   1.510 +        b = DRAW_MUL(_b, _a);
   1.511 +        a = _a;
   1.512 +    } else {
   1.513 +        r = _r;
   1.514 +        g = _g;
   1.515 +        b = _b;
   1.516 +        a = _a;
   1.517 +    }
   1.518 +    inva = (a ^ 0xff);
   1.519 +
   1.520 +    if (y1 == y2) {
   1.521 +        switch (blendMode) {
   1.522 +        case SDL_BLENDMODE_BLEND:
   1.523 +            HLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end);
   1.524 +            break;
   1.525 +        case SDL_BLENDMODE_ADD:
   1.526 +            HLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end);
   1.527 +            break;
   1.528 +        default:
   1.529 +            HLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end);
   1.530 +            break;
   1.531 +        }
   1.532 +    } else if (x1 == x2) {
   1.533 +        switch (blendMode) {
   1.534 +        case SDL_BLENDMODE_BLEND:
   1.535 +            VLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end);
   1.536 +            break;
   1.537 +        case SDL_BLENDMODE_ADD:
   1.538 +            VLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end);
   1.539 +            break;
   1.540 +        default:
   1.541 +            VLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end);
   1.542 +            break;
   1.543 +        }
   1.544 +    } else if (ABS(x1 - x2) == ABS(y1 - y2)) {
   1.545 +        switch (blendMode) {
   1.546 +        case SDL_BLENDMODE_BLEND:
   1.547 +            DLINE(Uint32, DRAW_SETPIXEL_BLEND_ARGB8888, draw_end);
   1.548 +            break;
   1.549 +        case SDL_BLENDMODE_ADD:
   1.550 +            DLINE(Uint32, DRAW_SETPIXEL_ADD_ARGB8888, draw_end);
   1.551 +            break;
   1.552 +        default:
   1.553 +            DLINE(Uint32, DRAW_SETPIXEL_ARGB8888, draw_end);
   1.554 +            break;
   1.555 +        }
   1.556 +    } else {
   1.557 +        switch (blendMode) {
   1.558 +        case SDL_BLENDMODE_BLEND:
   1.559 +            AALINE(x1, y1, x2, y2,
   1.560 +                   DRAW_SETPIXELXY_BLEND_ARGB8888, DRAW_SETPIXELXY_BLEND_ARGB8888,
   1.561 +                   draw_end);
   1.562 +            break;
   1.563 +        case SDL_BLENDMODE_ADD:
   1.564 +            AALINE(x1, y1, x2, y2,
   1.565 +                   DRAW_SETPIXELXY_ADD_ARGB8888, DRAW_SETPIXELXY_ADD_ARGB8888,
   1.566 +                   draw_end);
   1.567 +            break;
   1.568 +        default:
   1.569 +            AALINE(x1, y1, x2, y2,
   1.570 +                   DRAW_SETPIXELXY_ARGB8888, DRAW_SETPIXELXY_BLEND_ARGB8888,
   1.571 +                   draw_end);
   1.572 +            break;
   1.573 +        }
   1.574 +    }
   1.575 +}
   1.576 +
   1.577 +typedef void (*BlendLineFunc) (SDL_Surface * dst,
   1.578 +                               int x1, int y1, int x2, int y2,
   1.579 +                               SDL_BlendMode blendMode,
   1.580 +                               Uint8 r, Uint8 g, Uint8 b, Uint8 a,
   1.581 +                               SDL_bool draw_end);
   1.582 +
   1.583 +static BlendLineFunc
   1.584 +SDL_CalculateBlendLineFunc(const SDL_PixelFormat * fmt)
   1.585 +{
   1.586 +    switch (fmt->BytesPerPixel) {
   1.587 +    case 2:
   1.588 +        if (fmt->Rmask == 0x7C00) {
   1.589 +            return SDL_BlendLine_RGB555;
   1.590 +        } else if (fmt->Rmask == 0xF800) {
   1.591 +            return SDL_BlendLine_RGB565;
   1.592 +        } else {
   1.593 +            return SDL_BlendLine_RGB2;
   1.594 +        }
   1.595 +        break;
   1.596 +    case 4:
   1.597 +        if (fmt->Rmask == 0x00FF0000) {
   1.598 +            if (fmt->Amask) {
   1.599 +                return SDL_BlendLine_ARGB8888;
   1.600 +            } else {
   1.601 +                return SDL_BlendLine_RGB888;
   1.602 +            }
   1.603 +        } else {
   1.604 +            if (fmt->Amask) {
   1.605 +                return SDL_BlendLine_RGBA4;
   1.606 +            } else {
   1.607 +                return SDL_BlendLine_RGB4;
   1.608 +            }
   1.609 +        }
   1.610 +    }
   1.611 +    return NULL;
   1.612 +}
   1.613 +
   1.614 +int
   1.615 +SDL_BlendLine(SDL_Surface * dst, int x1, int y1, int x2, int y2,
   1.616 +              SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
   1.617 +{
   1.618 +    BlendLineFunc func;
   1.619 +
   1.620 +    if (!dst) {
   1.621 +        SDL_SetError("SDL_BlendLine(): Passed NULL destination surface");
   1.622 +        return -1;
   1.623 +    }
   1.624 +
   1.625 +    func = SDL_CalculateBlendLineFunc(dst->format);
   1.626 +    if (!func) {
   1.627 +        SDL_SetError("SDL_BlendLine(): Unsupported surface format");
   1.628 +        return -1;
   1.629 +    }
   1.630 +
   1.631 +    /* Perform clipping */
   1.632 +    /* FIXME: We don't actually want to clip, as it may change line slope */
   1.633 +    if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
   1.634 +        return 0;
   1.635 +    }
   1.636 +
   1.637 +    func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, SDL_TRUE);
   1.638 +    return 0;
   1.639 +}
   1.640 +
   1.641 +int
   1.642 +SDL_BlendLines(SDL_Surface * dst, const SDL_Point * points, int count,
   1.643 +               SDL_BlendMode blendMode, Uint8 r, Uint8 g, Uint8 b, Uint8 a)
   1.644 +{
   1.645 +    int i;
   1.646 +    int x1, y1;
   1.647 +    int x2, y2;
   1.648 +    SDL_bool draw_end;
   1.649 +    BlendLineFunc func;
   1.650 +
   1.651 +    if (!dst) {
   1.652 +        SDL_SetError("SDL_BlendLines(): Passed NULL destination surface");
   1.653 +        return -1;
   1.654 +    }
   1.655 +
   1.656 +    func = SDL_CalculateBlendLineFunc(dst->format);
   1.657 +    if (!func) {
   1.658 +        SDL_SetError("SDL_BlendLines(): Unsupported surface format");
   1.659 +        return -1;
   1.660 +    }
   1.661 +
   1.662 +    for (i = 1; i < count; ++i) {
   1.663 +        x1 = points[i-1].x;
   1.664 +        y1 = points[i-1].y;
   1.665 +        x2 = points[i].x;
   1.666 +        y2 = points[i].y;
   1.667 +
   1.668 +        /* Perform clipping */
   1.669 +        /* FIXME: We don't actually want to clip, as it may change line slope */
   1.670 +        if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
   1.671 +            continue;
   1.672 +        }
   1.673 +
   1.674 +        /* Draw the end if it was clipped */
   1.675 +        draw_end = (x2 != points[i].x || y2 != points[i].y);
   1.676 +
   1.677 +        func(dst, x1, y1, x2, y2, blendMode, r, g, b, a, draw_end);
   1.678 +    }
   1.679 +    if (points[0].x != points[count-1].x || points[0].y != points[count-1].y) {
   1.680 +        SDL_BlendPoint(dst, points[count-1].x, points[count-1].y,
   1.681 +                       blendMode, r, g, b, a);
   1.682 +    }
   1.683 +    return 0;
   1.684 +}
   1.685 +
   1.686 +/* vi: set ts=4 sw=4 expandtab: */