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.

113 lines
3.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2022 - Raw Material Software Limited
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 7 End-User License
  8. Agreement and JUCE Privacy Policy.
  9. End User License Agreement: www.juce.com/juce-7-licence
  10. Privacy Policy: www.juce.com/juce-privacy-policy
  11. Or: You may also use this code under the terms of the GPL v3 (see
  12. www.gnu.org/licenses).
  13. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  14. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  15. DISCLAIMED.
  16. ==============================================================================
  17. */
  18. namespace juce
  19. {
  20. //==============================================================================
  21. /**
  22. Represents a filter kernel to use in convoluting an image.
  23. @see Image::applyConvolution
  24. @tags{Graphics}
  25. */
  26. class JUCE_API ImageConvolutionKernel
  27. {
  28. public:
  29. //==============================================================================
  30. /** Creates an empty convolution kernel.
  31. @param size the length of each dimension of the kernel, so e.g. if the size
  32. is 5, it will create a 5x5 kernel
  33. */
  34. ImageConvolutionKernel (int size);
  35. /** Destructor. */
  36. ~ImageConvolutionKernel();
  37. //==============================================================================
  38. /** Resets all values in the kernel to zero. */
  39. void clear();
  40. /** Returns one of the kernel values. */
  41. float getKernelValue (int x, int y) const noexcept;
  42. /** Sets the value of a specific cell in the kernel.
  43. The x and y parameters must be in the range 0 < x < getKernelSize().
  44. @see setOverallSum
  45. */
  46. void setKernelValue (int x, int y, float value) noexcept;
  47. /** Rescales all values in the kernel to make the total add up to a fixed value.
  48. This will multiply all values in the kernel by (desiredTotalSum / currentTotalSum).
  49. */
  50. void setOverallSum (float desiredTotalSum);
  51. /** Multiplies all values in the kernel by a value. */
  52. void rescaleAllValues (float multiplier);
  53. /** Initialises the kernel for a gaussian blur.
  54. @param blurRadius this may be larger or smaller than the kernel's actual
  55. size but this will obviously be wasteful or clip at the
  56. edges. Ideally the kernel should be just larger than
  57. (blurRadius * 2).
  58. */
  59. void createGaussianBlur (float blurRadius);
  60. //==============================================================================
  61. /** Returns the size of the kernel.
  62. E.g. if it's a 3x3 kernel, this returns 3.
  63. */
  64. int getKernelSize() const { return size; }
  65. //==============================================================================
  66. /** Applies the kernel to an image.
  67. @param destImage the image that will receive the resultant convoluted pixels.
  68. @param sourceImage the source image to read from - this can be the same image as
  69. the destination, but if different, it must be exactly the same
  70. size and format.
  71. @param destinationArea the region of the image to apply the filter to
  72. */
  73. void applyToImage (Image& destImage,
  74. const Image& sourceImage,
  75. const Rectangle<int>& destinationArea) const;
  76. private:
  77. //==============================================================================
  78. HeapBlock<float> values;
  79. const int size;
  80. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ImageConvolutionKernel)
  81. };
  82. } // namespace juce