diff options
Diffstat (limited to 'contrib/SDL-3.2.8/src/render/software/SDL_drawpoint.c')
| -rw-r--r-- | contrib/SDL-3.2.8/src/render/software/SDL_drawpoint.c | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/contrib/SDL-3.2.8/src/render/software/SDL_drawpoint.c b/contrib/SDL-3.2.8/src/render/software/SDL_drawpoint.c new file mode 100644 index 0000000..5aa28b3 --- /dev/null +++ b/contrib/SDL-3.2.8/src/render/software/SDL_drawpoint.c | |||
| @@ -0,0 +1,108 @@ | |||
| 1 | /* | ||
| 2 | Simple DirectMedia Layer | ||
| 3 | Copyright (C) 1997-2025 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_internal.h" | ||
| 22 | |||
| 23 | #ifdef SDL_VIDEO_RENDER_SW | ||
| 24 | |||
| 25 | #include "SDL_draw.h" | ||
| 26 | #include "SDL_drawpoint.h" | ||
| 27 | |||
| 28 | bool SDL_DrawPoint(SDL_Surface *dst, int x, int y, Uint32 color) | ||
| 29 | { | ||
| 30 | if (!SDL_SurfaceValid(dst)) { | ||
| 31 | return SDL_InvalidParamError("SDL_DrawPoint(): dst"); | ||
| 32 | } | ||
| 33 | |||
| 34 | // This function doesn't work on surfaces < 8 bpp | ||
| 35 | if (dst->fmt->bits_per_pixel < 8) { | ||
| 36 | return SDL_SetError("SDL_DrawPoint(): Unsupported surface format"); | ||
| 37 | } | ||
| 38 | |||
| 39 | // Perform clipping | ||
| 40 | if (x < dst->clip_rect.x || y < dst->clip_rect.y || | ||
| 41 | x >= (dst->clip_rect.x + dst->clip_rect.w) || | ||
| 42 | y >= (dst->clip_rect.y + dst->clip_rect.h)) { | ||
| 43 | return true; | ||
| 44 | } | ||
| 45 | |||
| 46 | switch (dst->fmt->bytes_per_pixel) { | ||
| 47 | case 1: | ||
| 48 | DRAW_FASTSETPIXELXY1(x, y); | ||
| 49 | break; | ||
| 50 | case 2: | ||
| 51 | DRAW_FASTSETPIXELXY2(x, y); | ||
| 52 | break; | ||
| 53 | case 3: | ||
| 54 | return SDL_Unsupported(); | ||
| 55 | case 4: | ||
| 56 | DRAW_FASTSETPIXELXY4(x, y); | ||
| 57 | break; | ||
| 58 | } | ||
| 59 | return true; | ||
| 60 | } | ||
| 61 | |||
| 62 | bool SDL_DrawPoints(SDL_Surface *dst, const SDL_Point *points, int count, Uint32 color) | ||
| 63 | { | ||
| 64 | int minx, miny; | ||
| 65 | int maxx, maxy; | ||
| 66 | int i; | ||
| 67 | int x, y; | ||
| 68 | |||
| 69 | if (!SDL_SurfaceValid(dst)) { | ||
| 70 | return SDL_InvalidParamError("SDL_DrawPoints(): dst"); | ||
| 71 | } | ||
| 72 | |||
| 73 | // This function doesn't work on surfaces < 8 bpp | ||
| 74 | if (dst->fmt->bits_per_pixel < 8) { | ||
| 75 | return SDL_SetError("SDL_DrawPoints(): Unsupported surface format"); | ||
| 76 | } | ||
| 77 | |||
| 78 | minx = dst->clip_rect.x; | ||
| 79 | maxx = dst->clip_rect.x + dst->clip_rect.w - 1; | ||
| 80 | miny = dst->clip_rect.y; | ||
| 81 | maxy = dst->clip_rect.y + dst->clip_rect.h - 1; | ||
| 82 | |||
| 83 | for (i = 0; i < count; ++i) { | ||
| 84 | x = points[i].x; | ||
| 85 | y = points[i].y; | ||
| 86 | |||
| 87 | if (x < minx || x > maxx || y < miny || y > maxy) { | ||
| 88 | continue; | ||
| 89 | } | ||
| 90 | |||
| 91 | switch (dst->fmt->bytes_per_pixel) { | ||
| 92 | case 1: | ||
| 93 | DRAW_FASTSETPIXELXY1(x, y); | ||
| 94 | break; | ||
| 95 | case 2: | ||
| 96 | DRAW_FASTSETPIXELXY2(x, y); | ||
| 97 | break; | ||
| 98 | case 3: | ||
| 99 | return SDL_Unsupported(); | ||
| 100 | case 4: | ||
| 101 | DRAW_FASTSETPIXELXY4(x, y); | ||
| 102 | break; | ||
| 103 | } | ||
| 104 | } | ||
| 105 | return true; | ||
| 106 | } | ||
| 107 | |||
| 108 | #endif // SDL_VIDEO_RENDER_SW | ||
