Audio plugin host https://kx.studio/carla
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

112 lines
4.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #ifndef JUCE_IMAGECONVOLUTIONKERNEL_H_INCLUDED
  18. #define JUCE_IMAGECONVOLUTIONKERNEL_H_INCLUDED
  19. //==============================================================================
  20. /**
  21. Represents a filter kernel to use in convoluting an image.
  22. @see Image::applyConvolution
  23. */
  24. class JUCE_API ImageConvolutionKernel
  25. {
  26. public:
  27. //==============================================================================
  28. /** Creates an empty convulution kernel.
  29. @param size the length of each dimension of the kernel, so e.g. if the size
  30. is 5, it will create a 5x5 kernel
  31. */
  32. ImageConvolutionKernel (int size);
  33. /** Destructor. */
  34. ~ImageConvolutionKernel();
  35. //==============================================================================
  36. /** Resets all values in the kernel to zero. */
  37. void clear();
  38. /** Returns one of the kernel values. */
  39. float getKernelValue (int x, int y) const noexcept;
  40. /** Sets the value of a specific cell in the kernel.
  41. The x and y parameters must be in the range 0 < x < getKernelSize().
  42. @see setOverallSum
  43. */
  44. void setKernelValue (int x, int y, float value) noexcept;
  45. /** Rescales all values in the kernel to make the total add up to a fixed value.
  46. This will multiply all values in the kernel by (desiredTotalSum / currentTotalSum).
  47. */
  48. void setOverallSum (float desiredTotalSum);
  49. /** Multiplies all values in the kernel by a value. */
  50. void rescaleAllValues (float multiplier);
  51. /** Intialises the kernel for a gaussian blur.
  52. @param blurRadius this may be larger or smaller than the kernel's actual
  53. size but this will obviously be wasteful or clip at the
  54. edges. Ideally the kernel should be just larger than
  55. (blurRadius * 2).
  56. */
  57. void createGaussianBlur (float blurRadius);
  58. //==============================================================================
  59. /** Returns the size of the kernel.
  60. E.g. if it's a 3x3 kernel, this returns 3.
  61. */
  62. int getKernelSize() const { return size; }
  63. //==============================================================================
  64. /** Applies the kernel to an image.
  65. @param destImage the image that will receive the resultant convoluted pixels.
  66. @param sourceImage the source image to read from - this can be the same image as
  67. the destination, but if different, it must be exactly the same
  68. size and format.
  69. @param destinationArea the region of the image to apply the filter to
  70. */
  71. void applyToImage (Image& destImage,
  72. const Image& sourceImage,
  73. const Rectangle<int>& destinationArea) const;
  74. private:
  75. //==============================================================================
  76. HeapBlock <float> values;
  77. const int size;
  78. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ImageConvolutionKernel)
  79. };
  80. #endif // JUCE_IMAGECONVOLUTIONKERNEL_H_INCLUDED