src/render/software/SDL_drawpoint.c
changeset 5163 d72793305335
parent 3697 f7b03b6838cb
child 5226 710d00cb3a6a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/render/software/SDL_drawpoint.c	Thu Feb 03 02:45:29 2011 -0800
     1.3 @@ -0,0 +1,117 @@
     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_drawpoint.h"
    1.29 +
    1.30 +
    1.31 +int
    1.32 +SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color)
    1.33 +{
    1.34 +    if (!dst) {
    1.35 +        SDL_SetError("Passed NULL destination surface");
    1.36 +        return -1;
    1.37 +    }
    1.38 +
    1.39 +    /* This function doesn't work on surfaces < 8 bpp */
    1.40 +    if (dst->format->BitsPerPixel < 8) {
    1.41 +        SDL_SetError("SDL_DrawPoint(): Unsupported surface format");
    1.42 +        return -1;
    1.43 +    }
    1.44 +
    1.45 +    /* Perform clipping */
    1.46 +    if (x < dst->clip_rect.x || y < dst->clip_rect.y ||
    1.47 +        x >= (dst->clip_rect.x + dst->clip_rect.w) ||
    1.48 +        y >= (dst->clip_rect.y + dst->clip_rect.h)) {
    1.49 +        return 0;
    1.50 +    }
    1.51 +
    1.52 +    switch (dst->format->BytesPerPixel) {
    1.53 +    case 1:
    1.54 +        DRAW_FASTSETPIXELXY1(x, y);
    1.55 +        break;
    1.56 +    case 2:
    1.57 +        DRAW_FASTSETPIXELXY2(x, y);
    1.58 +        break;
    1.59 +    case 3:
    1.60 +        SDL_Unsupported();
    1.61 +        return -1;
    1.62 +    case 4:
    1.63 +        DRAW_FASTSETPIXELXY4(x, y);
    1.64 +        break;
    1.65 +    }
    1.66 +    return 0;
    1.67 +}
    1.68 +
    1.69 +int
    1.70 +SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count,
    1.71 +               Uint32 color)
    1.72 +{
    1.73 +    int minx, miny;
    1.74 +    int maxx, maxy;
    1.75 +    int i;
    1.76 +    int x, y;
    1.77 +
    1.78 +    if (!dst) {
    1.79 +        SDL_SetError("Passed NULL destination surface");
    1.80 +        return -1;
    1.81 +    }
    1.82 +
    1.83 +    /* This function doesn't work on surfaces < 8 bpp */
    1.84 +    if (dst->format->BitsPerPixel < 8) {
    1.85 +        SDL_SetError("SDL_DrawPoints(): Unsupported surface format");
    1.86 +        return -1;
    1.87 +    }
    1.88 +
    1.89 +    minx = dst->clip_rect.x;
    1.90 +    maxx = dst->clip_rect.x + dst->clip_rect.w - 1;
    1.91 +    miny = dst->clip_rect.y;
    1.92 +    maxy = dst->clip_rect.y + dst->clip_rect.h - 1;
    1.93 +
    1.94 +    for (i = 0; i < count; ++i) {
    1.95 +        x = points[i].x;
    1.96 +        y = points[i].y;
    1.97 +
    1.98 +        if (x < minx || x > maxx || y < miny || y > maxy) {
    1.99 +            continue;
   1.100 +        }
   1.101 +
   1.102 +        switch (dst->format->BytesPerPixel) {
   1.103 +        case 1:
   1.104 +            DRAW_FASTSETPIXELXY1(x, y);
   1.105 +            break;
   1.106 +        case 2:
   1.107 +            DRAW_FASTSETPIXELXY2(x, y);
   1.108 +            break;
   1.109 +        case 3:
   1.110 +            SDL_Unsupported();
   1.111 +            return -1;
   1.112 +        case 4:
   1.113 +            DRAW_FASTSETPIXELXY4(x, y);
   1.114 +            break;
   1.115 +        }
   1.116 +    }
   1.117 +    return 0;
   1.118 +}
   1.119 +
   1.120 +/* vi: set ts=4 sw=4 expandtab: */