src/video/SDL_drawline.c
author Sam Lantinga
Sat, 19 Sep 2009 13:29:40 +0000
changeset 3280 00cace2d9080
parent 2910 27d8b12e0e8e
child 3536 0267b8b1595c
permissions -rw-r--r--
Merged a cleaned up version of Jiang's code changes from Google Summer of Code 2009
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2009 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 #include "SDL_draw.h"
    25 
    26 
    27 int
    28 SDL_DrawLine(SDL_Surface * dst, int x1, int y1, int x2, int y2, Uint32 color)
    29 {
    30     /* This function doesn't work on surfaces < 8 bpp */
    31     if (dst->format->BitsPerPixel < 8) {
    32         SDL_SetError("SDL_DrawLine(): Unsupported surface format");
    33         return (-1);
    34     }
    35 
    36     /* Perform clipping */
    37     if (!SDL_IntersectRectAndLine(&dst->clip_rect, &x1, &y1, &x2, &y2)) {
    38         return (0);
    39     }
    40 
    41     switch (dst->format->BytesPerPixel) {
    42     case 1:
    43         DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL1);
    44         break;
    45     case 2:
    46         DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL2);
    47         break;
    48     case 3:
    49         SDL_Unsupported();
    50         return -1;
    51     case 4:
    52         DRAWLINE(x1, y1, x2, y2, DRAW_FASTSETPIXEL4);
    53         break;
    54     }
    55     return 0;
    56 }
    57 
    58 /* vi: set ts=4 sw=4 expandtab: */