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