comparison src/render/software/SDL_drawpoint.c @ 5166:d72793305335

Making the API simpler, moved the surface drawing functions to the software renderer.
author Sam Lantinga <slouken@libsdl.org>
date Thu, 03 Feb 2011 02:45:29 -0800
parents src/video/SDL_drawpoint.c@f7b03b6838cb
children 710d00cb3a6a
comparison
equal deleted inserted replaced
5165:e2b3f003e085 5166:d72793305335
1 /*
2 SDL - Simple DirectMedia Layer
3 Copyright (C) 1997-2010 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 #include "SDL_draw.h"
25 #include "SDL_drawpoint.h"
26
27
28 int
29 SDL_DrawPoint(SDL_Surface * dst, int x, int y, Uint32 color)
30 {
31 if (!dst) {
32 SDL_SetError("Passed NULL destination surface");
33 return -1;
34 }
35
36 /* This function doesn't work on surfaces < 8 bpp */
37 if (dst->format->BitsPerPixel < 8) {
38 SDL_SetError("SDL_DrawPoint(): Unsupported surface format");
39 return -1;
40 }
41
42 /* Perform clipping */
43 if (x < dst->clip_rect.x || y < dst->clip_rect.y ||
44 x >= (dst->clip_rect.x + dst->clip_rect.w) ||
45 y >= (dst->clip_rect.y + dst->clip_rect.h)) {
46 return 0;
47 }
48
49 switch (dst->format->BytesPerPixel) {
50 case 1:
51 DRAW_FASTSETPIXELXY1(x, y);
52 break;
53 case 2:
54 DRAW_FASTSETPIXELXY2(x, y);
55 break;
56 case 3:
57 SDL_Unsupported();
58 return -1;
59 case 4:
60 DRAW_FASTSETPIXELXY4(x, y);
61 break;
62 }
63 return 0;
64 }
65
66 int
67 SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count,
68 Uint32 color)
69 {
70 int minx, miny;
71 int maxx, maxy;
72 int i;
73 int x, y;
74
75 if (!dst) {
76 SDL_SetError("Passed NULL destination surface");
77 return -1;
78 }
79
80 /* This function doesn't work on surfaces < 8 bpp */
81 if (dst->format->BitsPerPixel < 8) {
82 SDL_SetError("SDL_DrawPoints(): Unsupported surface format");
83 return -1;
84 }
85
86 minx = dst->clip_rect.x;
87 maxx = dst->clip_rect.x + dst->clip_rect.w - 1;
88 miny = dst->clip_rect.y;
89 maxy = dst->clip_rect.y + dst->clip_rect.h - 1;
90
91 for (i = 0; i < count; ++i) {
92 x = points[i].x;
93 y = points[i].y;
94
95 if (x < minx || x > maxx || y < miny || y > maxy) {
96 continue;
97 }
98
99 switch (dst->format->BytesPerPixel) {
100 case 1:
101 DRAW_FASTSETPIXELXY1(x, y);
102 break;
103 case 2:
104 DRAW_FASTSETPIXELXY2(x, y);
105 break;
106 case 3:
107 SDL_Unsupported();
108 return -1;
109 case 4:
110 DRAW_FASTSETPIXELXY4(x, y);
111 break;
112 }
113 }
114 return 0;
115 }
116
117 /* vi: set ts=4 sw=4 expandtab: */