The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
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.

115 lines
4.3KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-11 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #ifndef __JUCE_IMAGECONVOLUTIONKERNEL_JUCEHEADER__
  19. #define __JUCE_IMAGECONVOLUTIONKERNEL_JUCEHEADER__
  20. #include "juce_Image.h"
  21. //==============================================================================
  22. /**
  23. Represents a filter kernel to use in convoluting an image.
  24. @see Image::applyConvolution
  25. */
  26. class JUCE_API ImageConvolutionKernel
  27. {
  28. public:
  29. //==============================================================================
  30. /** Creates an empty convulution 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. /** Intialises 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. #endif // __JUCE_IMAGECONVOLUTIONKERNEL_JUCEHEADER__