mediaFilters.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // zlib open source license
  2. //
  3. // Copyright (c) 2019 to 2022 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. #ifndef DFPSR_MEDIA_FILTERS
  24. #define DFPSR_MEDIA_FILTERS
  25. #include "../api/imageAPI.h"
  26. #include "../math/FixedPoint.h"
  27. namespace dsr {
  28. // No float nor double allowed in Media Filters.
  29. // Every bit has to be 100% deterministic across different computers if they use the same version of the library.
  30. // How a specific version works may however change how rounding is done in order to improve speed and precision.
  31. void media_filter_add(AlignedImageU8& targetImage, AlignedImageU8 imageA, AlignedImageU8 imageB);
  32. void media_filter_add(AlignedImageU8& targetImage, AlignedImageU8 image, FixedPoint luma);
  33. void media_filter_add(AlignedImageU8& targetImage, AlignedImageU8 image, int32_t luma);
  34. void media_filter_sub(AlignedImageU8& targetImage, AlignedImageU8 imageA, AlignedImageU8 imageB);
  35. void media_filter_sub(AlignedImageU8& targetImage, AlignedImageU8 image, FixedPoint luma);
  36. void media_filter_sub(AlignedImageU8& targetImage, FixedPoint luma, AlignedImageU8 image);
  37. void media_filter_sub(AlignedImageU8& targetImage, AlignedImageU8 image, int32_t luma);
  38. void media_filter_sub(AlignedImageU8& targetImage, int32_t luma, AlignedImageU8 image);
  39. void media_filter_mul(AlignedImageU8& targetImage, AlignedImageU8 image, FixedPoint scalar);
  40. void media_filter_mul(AlignedImageU8& targetImage, AlignedImageU8 imageA, AlignedImageU8 imageB, FixedPoint scalar);
  41. // Fill a region of the image with a linear fade, so that the pixel at (x1, y1) becomes roughly luma1, and the pixel at (x2, y2) becomes roughly luma2.
  42. // Fills entirely with luma1 if x1 == x2 and y1 == y2 (the line has no direction).
  43. // Safely crops the viewport to targetImage if too big.
  44. void media_fade_region_linear(ImageU8& targetImage, const IRect& viewport, FixedPoint x1, FixedPoint y1, FixedPoint luma1, FixedPoint x2, FixedPoint y2, FixedPoint luma2);
  45. // Fill the whole image with a linear fade.
  46. void media_fade_linear(ImageU8& targetImage, FixedPoint x1, FixedPoint y1, FixedPoint luma1, FixedPoint x2, FixedPoint y2, FixedPoint luma2);
  47. // Fill a region of the image with a radial fade.
  48. // Safely crops the viewport to targetImage if too big.
  49. // Pre-condition: innerRadius < outerRadius.
  50. // outerRadius will silently be reassigned to innerRadius + epsilon if the criteria isn't met.
  51. void media_fade_region_radial(ImageU8& targetImage, const IRect& viewport, FixedPoint centerX, FixedPoint centerY, FixedPoint innerRadius, FixedPoint innerLuma, FixedPoint outerRadius, FixedPoint outerLuma);
  52. // Fill the whole image with a radial fade.
  53. void media_fade_radial(ImageU8& targetImage, FixedPoint centerX, FixedPoint centerY, FixedPoint innerRadius, FixedPoint innerLuma, FixedPoint outerRadius, FixedPoint outerLuma);
  54. }
  55. #endif