SDL_drawpoint.c 3.1 KB

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