slouken@2901
|
1 |
/*
|
slouken@5535
|
2 |
Simple DirectMedia Layer
|
slouken@6885
|
3 |
Copyright (C) 1997-2013 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) {
|
icculus@7037
|
33 |
return SDL_SetError("Passed NULL destination surface");
|
slouken@3536
|
34 |
}
|
slouken@3536
|
35 |
|
slouken@2901
|
36 |
/* This function doesn't work on surfaces < 8 bpp */
|
slouken@2901
|
37 |
if (dst->format->BitsPerPixel < 8) {
|
icculus@7037
|
38 |
return SDL_SetError("SDL_DrawPoint(): Unsupported surface format");
|
slouken@2901
|
39 |
}
|
slouken@2901
|
40 |
|
slouken@2901
|
41 |
/* Perform clipping */
|
slouken@2901
|
42 |
if (x < dst->clip_rect.x || y < dst->clip_rect.y ||
|
slouken@2901
|
43 |
x >= (dst->clip_rect.x + dst->clip_rect.w) ||
|
slouken@2901
|
44 |
y >= (dst->clip_rect.y + dst->clip_rect.h)) {
|
slouken@2901
|
45 |
return 0;
|
slouken@2901
|
46 |
}
|
slouken@2901
|
47 |
|
slouken@2901
|
48 |
switch (dst->format->BytesPerPixel) {
|
slouken@2901
|
49 |
case 1:
|
slouken@3596
|
50 |
DRAW_FASTSETPIXELXY1(x, y);
|
slouken@2901
|
51 |
break;
|
slouken@2901
|
52 |
case 2:
|
slouken@3596
|
53 |
DRAW_FASTSETPIXELXY2(x, y);
|
slouken@2901
|
54 |
break;
|
slouken@2901
|
55 |
case 3:
|
icculus@7037
|
56 |
return SDL_Unsupported();
|
slouken@2901
|
57 |
case 4:
|
slouken@3596
|
58 |
DRAW_FASTSETPIXELXY4(x, y);
|
slouken@2901
|
59 |
break;
|
slouken@2901
|
60 |
}
|
slouken@2901
|
61 |
return 0;
|
slouken@2901
|
62 |
}
|
slouken@2901
|
63 |
|
slouken@3536
|
64 |
int
|
slouken@3536
|
65 |
SDL_DrawPoints(SDL_Surface * dst, const SDL_Point * points, int count,
|
slouken@3536
|
66 |
Uint32 color)
|
slouken@3536
|
67 |
{
|
slouken@3536
|
68 |
int minx, miny;
|
slouken@3536
|
69 |
int maxx, maxy;
|
slouken@3536
|
70 |
int i;
|
slouken@3536
|
71 |
int x, y;
|
slouken@3536
|
72 |
|
slouken@3536
|
73 |
if (!dst) {
|
icculus@7037
|
74 |
return SDL_SetError("Passed NULL destination surface");
|
slouken@3536
|
75 |
}
|
slouken@3536
|
76 |
|
slouken@3536
|
77 |
/* This function doesn't work on surfaces < 8 bpp */
|
slouken@3536
|
78 |
if (dst->format->BitsPerPixel < 8) {
|
icculus@7037
|
79 |
return SDL_SetError("SDL_DrawPoints(): Unsupported surface format");
|
slouken@3536
|
80 |
}
|
slouken@3536
|
81 |
|
slouken@3536
|
82 |
minx = dst->clip_rect.x;
|
slouken@3536
|
83 |
maxx = dst->clip_rect.x + dst->clip_rect.w - 1;
|
slouken@3536
|
84 |
miny = dst->clip_rect.y;
|
slouken@3536
|
85 |
maxy = dst->clip_rect.y + dst->clip_rect.h - 1;
|
slouken@3536
|
86 |
|
slouken@3536
|
87 |
for (i = 0; i < count; ++i) {
|
slouken@3536
|
88 |
x = points[i].x;
|
slouken@3536
|
89 |
y = points[i].y;
|
slouken@3536
|
90 |
|
slouken@3536
|
91 |
if (x < minx || x > maxx || y < miny || y > maxy) {
|
slouken@3536
|
92 |
continue;
|
slouken@3536
|
93 |
}
|
slouken@3536
|
94 |
|
slouken@3536
|
95 |
switch (dst->format->BytesPerPixel) {
|
slouken@3536
|
96 |
case 1:
|
slouken@3596
|
97 |
DRAW_FASTSETPIXELXY1(x, y);
|
slouken@3536
|
98 |
break;
|
slouken@3536
|
99 |
case 2:
|
slouken@3596
|
100 |
DRAW_FASTSETPIXELXY2(x, y);
|
slouken@3536
|
101 |
break;
|
slouken@3536
|
102 |
case 3:
|
icculus@7037
|
103 |
return SDL_Unsupported();
|
slouken@3536
|
104 |
case 4:
|
slouken@3596
|
105 |
DRAW_FASTSETPIXELXY4(x, y);
|
slouken@3536
|
106 |
break;
|
slouken@3536
|
107 |
}
|
slouken@3536
|
108 |
}
|
slouken@3536
|
109 |
return 0;
|
slouken@3536
|
110 |
}
|
slouken@3536
|
111 |
|
slouken@5226
|
112 |
#endif /* !SDL_RENDER_DISABLED */
|
slouken@5226
|
113 |
|
slouken@2901
|
114 |
/* vi: set ts=4 sw=4 expandtab: */
|