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.

106 lines
3.7KB

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