drawAPI.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. 
  2. // zlib open source license
  3. //
  4. // Copyright (c) 2017 to 2019 David Forsgren Piuva
  5. //
  6. // This software is provided 'as-is', without any express or implied
  7. // warranty. In no event will the authors be held liable for any damages
  8. // arising from the use of this software.
  9. //
  10. // Permission is granted to anyone to use this software for any purpose,
  11. // including commercial applications, and to alter it and redistribute it
  12. // freely, subject to the following restrictions:
  13. //
  14. // 1. The origin of this software must not be misrepresented; you must not
  15. // claim that you wrote the original software. If you use this software
  16. // in a product, an acknowledgment in the product documentation would be
  17. // appreciated but is not required.
  18. //
  19. // 2. Altered source versions must be plainly marked as such, and must not be
  20. // misrepresented as being the original software.
  21. //
  22. // 3. This notice may not be removed or altered from any source
  23. // distribution.
  24. #define DFPSR_INTERNAL_ACCESS
  25. #include "imageAPI.h"
  26. #include "drawAPI.h"
  27. #include "../image/draw.h"
  28. #include "../image/PackOrder.h"
  29. #include "../image/internal/imageTemplate.h"
  30. #include "../image/internal/imageInternal.h"
  31. using namespace dsr;
  32. // -------------------------------- Drawing shapes --------------------------------
  33. void dsr::draw_rectangle(ImageU8& image, const IRect& bound, int color) {
  34. if (image) {
  35. imageImpl_draw_solidRectangle(*image, bound, color);
  36. }
  37. }
  38. void dsr::draw_rectangle(ImageF32& image, const IRect& bound, float color) {
  39. if (image) {
  40. imageImpl_draw_solidRectangle(*image, bound, color);
  41. }
  42. }
  43. void dsr::draw_rectangle(ImageRgbaU8& image, const IRect& bound, const ColorRgbaI32& color) {
  44. if (image) {
  45. imageImpl_draw_solidRectangle(*image, bound, color);
  46. }
  47. }
  48. void dsr::draw_line(ImageU8& image, int32_t x1, int32_t y1, int32_t x2, int32_t y2, int color) {
  49. if (image) {
  50. imageImpl_draw_line(*image, x1, y1, x2, y2, color);
  51. }
  52. }
  53. void dsr::draw_line(ImageF32& image, int32_t x1, int32_t y1, int32_t x2, int32_t y2, float color) {
  54. if (image) {
  55. imageImpl_draw_line(*image, x1, y1, x2, y2, color);
  56. }
  57. }
  58. void dsr::draw_line(ImageRgbaU8& image, int32_t x1, int32_t y1, int32_t x2, int32_t y2, const ColorRgbaI32& color) {
  59. if (image) {
  60. imageImpl_draw_line(*image, x1, y1, x2, y2, color);
  61. }
  62. }
  63. // -------------------------------- Drawing images --------------------------------
  64. #define DRAW_COPY_WRAPPER(TARGET_TYPE, SOURCE_TYPE) \
  65. void dsr::draw_copy(TARGET_TYPE& target, const SOURCE_TYPE& source, int32_t left, int32_t top) { \
  66. if (target && source) { \
  67. imageImpl_drawCopy(*target, *source, left, top); \
  68. } \
  69. }
  70. DRAW_COPY_WRAPPER(ImageRgbaU8, ImageRgbaU8);
  71. DRAW_COPY_WRAPPER(ImageU8, ImageU8);
  72. DRAW_COPY_WRAPPER(ImageU16, ImageU16);
  73. DRAW_COPY_WRAPPER(ImageF32, ImageF32);
  74. DRAW_COPY_WRAPPER(ImageRgbaU8, ImageU8);
  75. DRAW_COPY_WRAPPER(ImageRgbaU8, ImageU16);
  76. DRAW_COPY_WRAPPER(ImageRgbaU8, ImageF32);
  77. DRAW_COPY_WRAPPER(ImageU8, ImageU16);
  78. DRAW_COPY_WRAPPER(ImageU8, ImageF32);
  79. DRAW_COPY_WRAPPER(ImageU16, ImageU8);
  80. DRAW_COPY_WRAPPER(ImageU16, ImageF32);
  81. DRAW_COPY_WRAPPER(ImageF32, ImageU8);
  82. DRAW_COPY_WRAPPER(ImageF32, ImageU16);
  83. void dsr::draw_alphaFilter(ImageRgbaU8& target, const ImageRgbaU8& source, int32_t left, int32_t top) {
  84. if (target && source) {
  85. imageImpl_drawAlphaFilter(*target, *source, left, top);
  86. }
  87. }
  88. void dsr::draw_maxAlpha(ImageRgbaU8& target, const ImageRgbaU8& source, int32_t left, int32_t top, int32_t sourceAlphaOffset) {
  89. if (target && source) {
  90. imageImpl_drawMaxAlpha(*target, *source, left, top, sourceAlphaOffset);
  91. }
  92. }
  93. void dsr::draw_alphaClip(ImageRgbaU8& target, const ImageRgbaU8& source, int32_t left, int32_t top, int32_t threshold) {
  94. if (target && source) {
  95. imageImpl_drawAlphaClip(*target, *source, left, top, threshold);
  96. }
  97. }
  98. void dsr::draw_silhouette(ImageRgbaU8& target, const ImageU8& source, const ColorRgbaI32& color, int32_t left, int32_t top) {
  99. if (target && source) {
  100. imageImpl_drawSilhouette(*target, *source, color, left, top);
  101. }
  102. }
  103. void dsr::draw_higher(ImageU16& targetHeight, const ImageU16& sourceHeight, int32_t left, int32_t top, int32_t sourceHeightOffset) {
  104. if (targetHeight && sourceHeight) {
  105. imageImpl_drawHigher(*targetHeight, *sourceHeight, left, top, sourceHeightOffset);
  106. }
  107. }
  108. void dsr::draw_higher(ImageU16& targetHeight, const ImageU16& sourceHeight, ImageRgbaU8& targetA, const ImageRgbaU8& sourceA,
  109. int32_t left, int32_t top, int32_t sourceHeightOffset) {
  110. if (targetHeight && sourceHeight && targetA && sourceA) {
  111. imageImpl_drawHigher(*targetHeight, *sourceHeight, *targetA, *sourceA, left, top, sourceHeightOffset);
  112. }
  113. }
  114. void dsr::draw_higher(ImageU16& targetHeight, const ImageU16& sourceHeight, ImageRgbaU8& targetA, const ImageRgbaU8& sourceA,
  115. ImageRgbaU8& targetB, const ImageRgbaU8& sourceB, int32_t left, int32_t top, int32_t sourceHeightOffset) {
  116. if (targetHeight && sourceHeight && targetA && sourceA && targetB && sourceB) {
  117. imageImpl_drawHigher(*targetHeight, *sourceHeight, *targetA, *sourceA, *targetB, *sourceB, left, top, sourceHeightOffset);
  118. }
  119. }
  120. void dsr::draw_higher(ImageF32& targetHeight, const ImageF32& sourceHeight, int32_t left, int32_t top, float sourceHeightOffset) {
  121. if (targetHeight && sourceHeight) {
  122. imageImpl_drawHigher(*targetHeight, *sourceHeight, left, top, sourceHeightOffset);
  123. }
  124. }
  125. void dsr::draw_higher(ImageF32& targetHeight, const ImageF32& sourceHeight, ImageRgbaU8& targetA, const ImageRgbaU8& sourceA,
  126. int32_t left, int32_t top, float sourceHeightOffset) {
  127. if (targetHeight && sourceHeight && targetA && sourceA) {
  128. imageImpl_drawHigher(*targetHeight, *sourceHeight, *targetA, *sourceA, left, top, sourceHeightOffset);
  129. }
  130. }
  131. void dsr::draw_higher(ImageF32& targetHeight, const ImageF32& sourceHeight, ImageRgbaU8& targetA, const ImageRgbaU8& sourceA,
  132. ImageRgbaU8& targetB, const ImageRgbaU8& sourceB, int32_t left, int32_t top, float sourceHeightOffset) {
  133. if (targetHeight && sourceHeight && targetA && sourceA && targetB && sourceB) {
  134. imageImpl_drawHigher(*targetHeight, *sourceHeight, *targetA, *sourceA, *targetB, *sourceB, left, top, sourceHeightOffset);
  135. }
  136. }