drawAPI.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. // zlib open source license
  2. //
  3. // Copyright (c) 2017 to 2019 David Forsgren Piuva
  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. //
  18. // 2. Altered source versions must be plainly marked as such, and must not be
  19. // misrepresented as being the original software.
  20. //
  21. // 3. This notice may not be removed or altered from any source
  22. // distribution.
  23. #define DFPSR_INTERNAL_ACCESS
  24. #include "imageAPI.h"
  25. #include "drawAPI.h"
  26. #include "../image/draw.h"
  27. #include "../image/PackOrder.h"
  28. #include "../image/internal/imageTemplate.h"
  29. #include "../image/internal/imageInternal.h"
  30. using namespace dsr;
  31. // -------------------------------- Drawing shapes --------------------------------
  32. void dsr::draw_rectangle(ImageU8& image, const IRect& bound, int color) {
  33. if (image) {
  34. imageImpl_draw_solidRectangle(*image, bound, color);
  35. }
  36. }
  37. void dsr::draw_rectangle(ImageF32& image, const IRect& bound, float color) {
  38. if (image) {
  39. imageImpl_draw_solidRectangle(*image, bound, color);
  40. }
  41. }
  42. void dsr::draw_rectangle(ImageRgbaU8& image, const IRect& bound, const ColorRgbaI32& color) {
  43. if (image) {
  44. imageImpl_draw_solidRectangle(*image, bound, color);
  45. }
  46. }
  47. void dsr::draw_line(ImageU8& image, int32_t x1, int32_t y1, int32_t x2, int32_t y2, int color) {
  48. if (image) {
  49. imageImpl_draw_line(*image, x1, y1, x2, y2, color);
  50. }
  51. }
  52. void dsr::draw_line(ImageF32& image, int32_t x1, int32_t y1, int32_t x2, int32_t y2, float color) {
  53. if (image) {
  54. imageImpl_draw_line(*image, x1, y1, x2, y2, color);
  55. }
  56. }
  57. void dsr::draw_line(ImageRgbaU8& image, int32_t x1, int32_t y1, int32_t x2, int32_t y2, const ColorRgbaI32& color) {
  58. if (image) {
  59. imageImpl_draw_line(*image, x1, y1, x2, y2, color);
  60. }
  61. }
  62. // -------------------------------- Drawing images --------------------------------
  63. #define DRAW_COPY_WRAPPER(TARGET_TYPE, SOURCE_TYPE) \
  64. void dsr::draw_copy(TARGET_TYPE& target, const SOURCE_TYPE& source, int32_t left, int32_t top) { \
  65. if (target && source) { \
  66. imageImpl_drawCopy(*target, *source, left, top); \
  67. } \
  68. }
  69. DRAW_COPY_WRAPPER(ImageRgbaU8, ImageRgbaU8);
  70. DRAW_COPY_WRAPPER(ImageU8, ImageU8);
  71. DRAW_COPY_WRAPPER(ImageU16, ImageU16);
  72. DRAW_COPY_WRAPPER(ImageF32, ImageF32);
  73. DRAW_COPY_WRAPPER(ImageRgbaU8, ImageU8);
  74. DRAW_COPY_WRAPPER(ImageRgbaU8, ImageU16);
  75. DRAW_COPY_WRAPPER(ImageRgbaU8, ImageF32);
  76. DRAW_COPY_WRAPPER(ImageU8, ImageU16);
  77. DRAW_COPY_WRAPPER(ImageU8, ImageF32);
  78. DRAW_COPY_WRAPPER(ImageU16, ImageU8);
  79. DRAW_COPY_WRAPPER(ImageU16, ImageF32);
  80. DRAW_COPY_WRAPPER(ImageF32, ImageU8);
  81. DRAW_COPY_WRAPPER(ImageF32, ImageU16);
  82. void dsr::draw_alphaFilter(ImageRgbaU8& target, const ImageRgbaU8& source, int32_t left, int32_t top) {
  83. if (target && source) {
  84. imageImpl_drawAlphaFilter(*target, *source, left, top);
  85. }
  86. }
  87. void dsr::draw_maxAlpha(ImageRgbaU8& target, const ImageRgbaU8& source, int32_t left, int32_t top, int32_t sourceAlphaOffset) {
  88. if (target && source) {
  89. imageImpl_drawMaxAlpha(*target, *source, left, top, sourceAlphaOffset);
  90. }
  91. }
  92. void dsr::draw_alphaClip(ImageRgbaU8& target, const ImageRgbaU8& source, int32_t left, int32_t top, int32_t threshold) {
  93. if (target && source) {
  94. imageImpl_drawAlphaClip(*target, *source, left, top, threshold);
  95. }
  96. }
  97. void dsr::draw_silhouette(ImageRgbaU8& target, const ImageU8& source, const ColorRgbaI32& color, int32_t left, int32_t top) {
  98. if (target && source) {
  99. imageImpl_drawSilhouette(*target, *source, color, left, top);
  100. }
  101. }
  102. void dsr::draw_higher(ImageU16& targetHeight, const ImageU16& sourceHeight, int32_t left, int32_t top, int32_t sourceHeightOffset) {
  103. if (targetHeight && sourceHeight) {
  104. imageImpl_drawHigher(*targetHeight, *sourceHeight, left, top, sourceHeightOffset);
  105. }
  106. }
  107. void dsr::draw_higher(ImageU16& targetHeight, const ImageU16& sourceHeight, ImageRgbaU8& targetA, const ImageRgbaU8& sourceA,
  108. int32_t left, int32_t top, int32_t sourceHeightOffset) {
  109. if (targetHeight && sourceHeight && targetA && sourceA) {
  110. imageImpl_drawHigher(*targetHeight, *sourceHeight, *targetA, *sourceA, left, top, sourceHeightOffset);
  111. }
  112. }
  113. void dsr::draw_higher(ImageU16& targetHeight, const ImageU16& sourceHeight, ImageRgbaU8& targetA, const ImageRgbaU8& sourceA,
  114. ImageRgbaU8& targetB, const ImageRgbaU8& sourceB, int32_t left, int32_t top, int32_t sourceHeightOffset) {
  115. if (targetHeight && sourceHeight && targetA && sourceA && targetB && sourceB) {
  116. imageImpl_drawHigher(*targetHeight, *sourceHeight, *targetA, *sourceA, *targetB, *sourceB, left, top, sourceHeightOffset);
  117. }
  118. }
  119. void dsr::draw_higher(ImageF32& targetHeight, const ImageF32& sourceHeight, int32_t left, int32_t top, float sourceHeightOffset) {
  120. if (targetHeight && sourceHeight) {
  121. imageImpl_drawHigher(*targetHeight, *sourceHeight, left, top, sourceHeightOffset);
  122. }
  123. }
  124. void dsr::draw_higher(ImageF32& targetHeight, const ImageF32& sourceHeight, ImageRgbaU8& targetA, const ImageRgbaU8& sourceA,
  125. int32_t left, int32_t top, float sourceHeightOffset) {
  126. if (targetHeight && sourceHeight && targetA && sourceA) {
  127. imageImpl_drawHigher(*targetHeight, *sourceHeight, *targetA, *sourceA, left, top, sourceHeightOffset);
  128. }
  129. }
  130. void dsr::draw_higher(ImageF32& targetHeight, const ImageF32& sourceHeight, ImageRgbaU8& targetA, const ImageRgbaU8& sourceA,
  131. ImageRgbaU8& targetB, const ImageRgbaU8& sourceB, int32_t left, int32_t top, float sourceHeightOffset) {
  132. if (targetHeight && sourceHeight && targetA && sourceA && targetB && sourceB) {
  133. imageImpl_drawHigher(*targetHeight, *sourceHeight, *targetA, *sourceA, *targetB, *sourceB, left, top, sourceHeightOffset);
  134. }
  135. }