src/render/software/SDL_drawpoint.c
author Sam Lantinga <slouken@libsdl.org>
Tue, 08 Feb 2011 10:04:09 -0800
changeset 5226 710d00cb3a6a
parent 5163 d72793305335
child 5262 b530ef003506
permissions -rw-r--r--
Made it possible to disable the rendering subsystem with configure --disable-render
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@5226
    24
#if !SDL_RENDER_DISABLED
slouken@5226
    25
slouken@2901
    26
#include "SDL_draw.h"
slouken@5163
    27
#include "SDL_drawpoint.h"
slouken@2901
    28
slouken@2901
    29
slouken@2901
    30
int
slouken@2901
    31
SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color)
slouken@2901
    32
{
slouken@3536
    33
    if (!dst) {
slouken@3536
    34
        SDL_SetError("Passed NULL destination surface");
slouken@3536
    35
        return -1;
slouken@3536
    36
    }
slouken@3536
    37
slouken@2901
    38
    /* This function doesn't work on surfaces < 8 bpp */
slouken@2901
    39
    if (dst->format->BitsPerPixel < 8) {
slouken@3160
    40
        SDL_SetError("SDL_DrawPoint(): Unsupported surface format");
slouken@3536
    41
        return -1;
slouken@2901
    42
    }
slouken@2901
    43
slouken@2901
    44
    /* Perform clipping */
slouken@2901
    45
    if (x < dst->clip_rect.x || y < dst->clip_rect.y ||
slouken@2901
    46
        x >= (dst->clip_rect.x + dst->clip_rect.w) ||
slouken@2901
    47
        y >= (dst->clip_rect.y + dst->clip_rect.h)) {
slouken@2901
    48
        return 0;
slouken@2901
    49
    }
slouken@2901
    50
slouken@2901
    51
    switch (dst->format->BytesPerPixel) {
slouken@2901
    52
    case 1:
slouken@3596
    53
        DRAW_FASTSETPIXELXY1(x, y);
slouken@2901
    54
        break;
slouken@2901
    55
    case 2:
slouken@3596
    56
        DRAW_FASTSETPIXELXY2(x, y);
slouken@2901
    57
        break;
slouken@2901
    58
    case 3:
slouken@2901
    59
        SDL_Unsupported();
slouken@2901
    60
        return -1;
slouken@2901
    61
    case 4:
slouken@3596
    62
        DRAW_FASTSETPIXELXY4(x, y);
slouken@2901
    63
        break;
slouken@2901
    64
    }
slouken@2901
    65
    return 0;
slouken@2901
    66
}
slouken@2901
    67
slouken@3536
    68
int
slouken@3536
    69
SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count,
slouken@3536
    70
               Uint32 color)
slouken@3536
    71
{
slouken@3536
    72
    int minx, miny;
slouken@3536
    73
    int maxx, maxy;
slouken@3536
    74
    int i;
slouken@3536
    75
    int x, y;
slouken@3536
    76
slouken@3536
    77
    if (!dst) {
slouken@3536
    78
        SDL_SetError("Passed NULL destination surface");
slouken@3536
    79
        return -1;
slouken@3536
    80
    }
slouken@3536
    81
slouken@3536
    82
    /* This function doesn't work on surfaces < 8 bpp */
slouken@3536
    83
    if (dst->format->BitsPerPixel < 8) {
slouken@3536
    84
        SDL_SetError("SDL_DrawPoints(): Unsupported surface format");
slouken@3536
    85
        return -1;
slouken@3536
    86
    }
slouken@3536
    87
slouken@3536
    88
    minx = dst->clip_rect.x;
slouken@3536
    89
    maxx = dst->clip_rect.x + dst->clip_rect.w - 1;
slouken@3536
    90
    miny = dst->clip_rect.y;
slouken@3536
    91
    maxy = dst->clip_rect.y + dst->clip_rect.h - 1;
slouken@3536
    92
slouken@3536
    93
    for (i = 0; i < count; ++i) {
slouken@3536
    94
        x = points[i].x;
slouken@3536
    95
        y = points[i].y;
slouken@3536
    96
slouken@3536
    97
        if (x < minx || x > maxx || y < miny || y > maxy) {
slouken@3536
    98
            continue;
slouken@3536
    99
        }
slouken@3536
   100
slouken@3536
   101
        switch (dst->format->BytesPerPixel) {
slouken@3536
   102
        case 1:
slouken@3596
   103
            DRAW_FASTSETPIXELXY1(x, y);
slouken@3536
   104
            break;
slouken@3536
   105
        case 2:
slouken@3596
   106
            DRAW_FASTSETPIXELXY2(x, y);
slouken@3536
   107
            break;
slouken@3536
   108
        case 3:
slouken@3536
   109
            SDL_Unsupported();
slouken@3536
   110
            return -1;
slouken@3536
   111
        case 4:
slouken@3596
   112
            DRAW_FASTSETPIXELXY4(x, y);
slouken@3536
   113
            break;
slouken@3536
   114
        }
slouken@3536
   115
    }
slouken@3536
   116
    return 0;
slouken@3536
   117
}
slouken@3536
   118
slouken@5226
   119
#endif /* !SDL_RENDER_DISABLED */
slouken@5226
   120
slouken@2901
   121
/* vi: set ts=4 sw=4 expandtab: */