src/render/software/SDL_drawpoint.c
author Sam Lantinga <slouken@libsdl.org>
Fri, 08 Apr 2011 13:03:26 -0700
changeset 5535 96594ac5fd1a
parent 5262 b530ef003506
child 6138 4c64952a58fb
permissions -rw-r--r--
SDL 1.3 is now under the zlib license.
slouken@2901
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@5535
     3
  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
slouken@2901
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@2901
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@2901
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@2901
    20
*/
slouken@2901
    21
#include "SDL_config.h"
slouken@2901
    22
slouken@5226
    23
#if !SDL_RENDER_DISABLED
slouken@5226
    24
slouken@2901
    25
#include "SDL_draw.h"
slouken@5163
    26
#include "SDL_drawpoint.h"
slouken@2901
    27
slouken@2901
    28
slouken@2901
    29
int
slouken@2901
    30
SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color)
slouken@2901
    31
{
slouken@3536
    32
    if (!dst) {
slouken@3536
    33
        SDL_SetError("Passed NULL destination surface");
slouken@3536
    34
        return -1;
slouken@3536
    35
    }
slouken@3536
    36
slouken@2901
    37
    /* This function doesn't work on surfaces < 8 bpp */
slouken@2901
    38
    if (dst->format->BitsPerPixel < 8) {
slouken@3160
    39
        SDL_SetError("SDL_DrawPoint(): Unsupported surface format");
slouken@3536
    40
        return -1;
slouken@2901
    41
    }
slouken@2901
    42
slouken@2901
    43
    /* Perform clipping */
slouken@2901
    44
    if (x < dst->clip_rect.x || y < dst->clip_rect.y ||
slouken@2901
    45
        x >= (dst->clip_rect.x + dst->clip_rect.w) ||
slouken@2901
    46
        y >= (dst->clip_rect.y + dst->clip_rect.h)) {
slouken@2901
    47
        return 0;
slouken@2901
    48
    }
slouken@2901
    49
slouken@2901
    50
    switch (dst->format->BytesPerPixel) {
slouken@2901
    51
    case 1:
slouken@3596
    52
        DRAW_FASTSETPIXELXY1(x, y);
slouken@2901
    53
        break;
slouken@2901
    54
    case 2:
slouken@3596
    55
        DRAW_FASTSETPIXELXY2(x, y);
slouken@2901
    56
        break;
slouken@2901
    57
    case 3:
slouken@2901
    58
        SDL_Unsupported();
slouken@2901
    59
        return -1;
slouken@2901
    60
    case 4:
slouken@3596
    61
        DRAW_FASTSETPIXELXY4(x, y);
slouken@2901
    62
        break;
slouken@2901
    63
    }
slouken@2901
    64
    return 0;
slouken@2901
    65
}
slouken@2901
    66
slouken@3536
    67
int
slouken@3536
    68
SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count,
slouken@3536
    69
               Uint32 color)
slouken@3536
    70
{
slouken@3536
    71
    int minx, miny;
slouken@3536
    72
    int maxx, maxy;
slouken@3536
    73
    int i;
slouken@3536
    74
    int x, y;
slouken@3536
    75
slouken@3536
    76
    if (!dst) {
slouken@3536
    77
        SDL_SetError("Passed NULL destination surface");
slouken@3536
    78
        return -1;
slouken@3536
    79
    }
slouken@3536
    80
slouken@3536
    81
    /* This function doesn't work on surfaces < 8 bpp */
slouken@3536
    82
    if (dst->format->BitsPerPixel < 8) {
slouken@3536
    83
        SDL_SetError("SDL_DrawPoints(): Unsupported surface format");
slouken@3536
    84
        return -1;
slouken@3536
    85
    }
slouken@3536
    86
slouken@3536
    87
    minx = dst->clip_rect.x;
slouken@3536
    88
    maxx = dst->clip_rect.x + dst->clip_rect.w - 1;
slouken@3536
    89
    miny = dst->clip_rect.y;
slouken@3536
    90
    maxy = dst->clip_rect.y + dst->clip_rect.h - 1;
slouken@3536
    91
slouken@3536
    92
    for (i = 0; i < count; ++i) {
slouken@3536
    93
        x = points[i].x;
slouken@3536
    94
        y = points[i].y;
slouken@3536
    95
slouken@3536
    96
        if (x < minx || x > maxx || y < miny || y > maxy) {
slouken@3536
    97
            continue;
slouken@3536
    98
        }
slouken@3536
    99
slouken@3536
   100
        switch (dst->format->BytesPerPixel) {
slouken@3536
   101
        case 1:
slouken@3596
   102
            DRAW_FASTSETPIXELXY1(x, y);
slouken@3536
   103
            break;
slouken@3536
   104
        case 2:
slouken@3596
   105
            DRAW_FASTSETPIXELXY2(x, y);
slouken@3536
   106
            break;
slouken@3536
   107
        case 3:
slouken@3536
   108
            SDL_Unsupported();
slouken@3536
   109
            return -1;
slouken@3536
   110
        case 4:
slouken@3596
   111
            DRAW_FASTSETPIXELXY4(x, y);
slouken@3536
   112
            break;
slouken@3536
   113
        }
slouken@3536
   114
    }
slouken@3536
   115
    return 0;
slouken@3536
   116
}
slouken@3536
   117
slouken@5226
   118
#endif /* !SDL_RENDER_DISABLED */
slouken@5226
   119
slouken@2901
   120
/* vi: set ts=4 sw=4 expandtab: */