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