src/render/software/SDL_drawpoint.c
author Sam Lantinga <slouken@libsdl.org>
Thu, 03 Feb 2011 02:45:29 -0800
changeset 5163 d72793305335
parent 3697 src/video/SDL_drawpoint.c@f7b03b6838cb
child 5226 710d00cb3a6a
permissions -rw-r--r--
Making the API simpler, moved the surface drawing functions to the software renderer.
slouken@2901
     1
/*
slouken@2901
     2
    SDL - Simple DirectMedia Layer
slouken@3697
     3
    Copyright (C) 1997-2010 Sam Lantinga
slouken@2901
     4
slouken@2901
     5
    This library is free software; you can redistribute it and/or
slouken@2901
     6
    modify it under the terms of the GNU Lesser General Public
slouken@2901
     7
    License as published by the Free Software Foundation; either
slouken@2901
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@2901
     9
slouken@2901
    10
    This library is distributed in the hope that it will be useful,
slouken@2901
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@2901
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@2901
    13
    Lesser General Public License for more details.
slouken@2901
    14
slouken@2901
    15
    You should have received a copy of the GNU Lesser General Public
slouken@2901
    16
    License along with this library; if not, write to the Free Software
slouken@2901
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@2901
    18
slouken@2901
    19
    Sam Lantinga
slouken@2901
    20
    slouken@libsdl.org
slouken@2901
    21
*/
slouken@2901
    22
#include "SDL_config.h"
slouken@2901
    23
slouken@2901
    24
#include "SDL_draw.h"
slouken@5163
    25
#include "SDL_drawpoint.h"
slouken@2901
    26
slouken@2901
    27
slouken@2901
    28
int
slouken@2901
    29
SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color)
slouken@2901
    30
{
slouken@3536
    31
    if (!dst) {
slouken@3536
    32
        SDL_SetError("Passed NULL destination surface");
slouken@3536
    33
        return -1;
slouken@3536
    34
    }
slouken@3536
    35
slouken@2901
    36
    /* This function doesn't work on surfaces < 8 bpp */
slouken@2901
    37
    if (dst->format->BitsPerPixel < 8) {
slouken@3160
    38
        SDL_SetError("SDL_DrawPoint(): Unsupported surface format");
slouken@3536
    39
        return -1;
slouken@2901
    40
    }
slouken@2901
    41
slouken@2901
    42
    /* Perform clipping */
slouken@2901
    43
    if (x < dst->clip_rect.x || y < dst->clip_rect.y ||
slouken@2901
    44
        x >= (dst->clip_rect.x + dst->clip_rect.w) ||
slouken@2901
    45
        y >= (dst->clip_rect.y + dst->clip_rect.h)) {
slouken@2901
    46
        return 0;
slouken@2901
    47
    }
slouken@2901
    48
slouken@2901
    49
    switch (dst->format->BytesPerPixel) {
slouken@2901
    50
    case 1:
slouken@3596
    51
        DRAW_FASTSETPIXELXY1(x, y);
slouken@2901
    52
        break;
slouken@2901
    53
    case 2:
slouken@3596
    54
        DRAW_FASTSETPIXELXY2(x, y);
slouken@2901
    55
        break;
slouken@2901
    56
    case 3:
slouken@2901
    57
        SDL_Unsupported();
slouken@2901
    58
        return -1;
slouken@2901
    59
    case 4:
slouken@3596
    60
        DRAW_FASTSETPIXELXY4(x, y);
slouken@2901
    61
        break;
slouken@2901
    62
    }
slouken@2901
    63
    return 0;
slouken@2901
    64
}
slouken@2901
    65
slouken@3536
    66
int
slouken@3536
    67
SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count,
slouken@3536
    68
               Uint32 color)
slouken@3536
    69
{
slouken@3536
    70
    int minx, miny;
slouken@3536
    71
    int maxx, maxy;
slouken@3536
    72
    int i;
slouken@3536
    73
    int x, y;
slouken@3536
    74
slouken@3536
    75
    if (!dst) {
slouken@3536
    76
        SDL_SetError("Passed NULL destination surface");
slouken@3536
    77
        return -1;
slouken@3536
    78
    }
slouken@3536
    79
slouken@3536
    80
    /* This function doesn't work on surfaces < 8 bpp */
slouken@3536
    81
    if (dst->format->BitsPerPixel < 8) {
slouken@3536
    82
        SDL_SetError("SDL_DrawPoints(): Unsupported surface format");
slouken@3536
    83
        return -1;
slouken@3536
    84
    }
slouken@3536
    85
slouken@3536
    86
    minx = dst->clip_rect.x;
slouken@3536
    87
    maxx = dst->clip_rect.x + dst->clip_rect.w - 1;
slouken@3536
    88
    miny = dst->clip_rect.y;
slouken@3536
    89
    maxy = dst->clip_rect.y + dst->clip_rect.h - 1;
slouken@3536
    90
slouken@3536
    91
    for (i = 0; i < count; ++i) {
slouken@3536
    92
        x = points[i].x;
slouken@3536
    93
        y = points[i].y;
slouken@3536
    94
slouken@3536
    95
        if (x < minx || x > maxx || y < miny || y > maxy) {
slouken@3536
    96
            continue;
slouken@3536
    97
        }
slouken@3536
    98
slouken@3536
    99
        switch (dst->format->BytesPerPixel) {
slouken@3536
   100
        case 1:
slouken@3596
   101
            DRAW_FASTSETPIXELXY1(x, y);
slouken@3536
   102
            break;
slouken@3536
   103
        case 2:
slouken@3596
   104
            DRAW_FASTSETPIXELXY2(x, y);
slouken@3536
   105
            break;
slouken@3536
   106
        case 3:
slouken@3536
   107
            SDL_Unsupported();
slouken@3536
   108
            return -1;
slouken@3536
   109
        case 4:
slouken@3596
   110
            DRAW_FASTSETPIXELXY4(x, y);
slouken@3536
   111
            break;
slouken@3536
   112
        }
slouken@3536
   113
    }
slouken@3536
   114
    return 0;
slouken@3536
   115
}
slouken@3536
   116
slouken@2901
   117
/* vi: set ts=4 sw=4 expandtab: */