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.

132 lines
5.1KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-9 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 (const int size) throw();
  35. /** Destructor. */
  36. ~ImageConvolutionKernel() throw();
  37. //==============================================================================
  38. /** Resets all values in the kernel to zero.
  39. */
  40. void clear() throw();
  41. /** Sets the value of a specific cell in the kernel.
  42. The x and y parameters must be in the range 0 < x < getKernelSize().
  43. @see setOverallSum
  44. */
  45. void setKernelValue (const int x,
  46. const int y,
  47. const float value) throw();
  48. /** Rescales all values in the kernel to make the total add up to a fixed value.
  49. This will multiply all values in the kernel by (desiredTotalSum / currentTotalSum).
  50. */
  51. void setOverallSum (const float desiredTotalSum) throw();
  52. /** Multiplies all values in the kernel by a value. */
  53. void rescaleAllValues (const float multiplier) throw();
  54. /** Intialises the kernel for a gaussian blur.
  55. @param blurRadius this may be larger or smaller than the kernel's actual
  56. size but this will obviously be wasteful or clip at the
  57. edges. Ideally the kernel should be just larger than
  58. (blurRadius * 2).
  59. */
  60. void createGaussianBlur (const float blurRadius) throw();
  61. //==============================================================================
  62. /** Returns the size of the kernel.
  63. E.g. if it's a 3x3 kernel, this returns 3.
  64. */
  65. int getKernelSize() const throw() { return size; }
  66. /** Returns a 2-dimensional array of the kernel's values.
  67. The size of each dimension of the array will be getKernelSize().
  68. */
  69. float** getValues() const throw() { return values; }
  70. //==============================================================================
  71. /** Applies the kernel to an image.
  72. @param destImage the image that will receive the resultant convoluted pixels.
  73. @param sourceImage an optional source image to read from - if this is 0, then the
  74. destination image will be used as the source. If an image is
  75. specified, it must be exactly the same size and type as the destination
  76. image.
  77. @param x the region of the image to apply the filter to
  78. @param y the region of the image to apply the filter to
  79. @param width the region of the image to apply the filter to
  80. @param height the region of the image to apply the filter to
  81. */
  82. void applyToImage (Image& destImage,
  83. const Image* sourceImage,
  84. int x,
  85. int y,
  86. int width,
  87. int height) const;
  88. //==============================================================================
  89. juce_UseDebuggingNewOperator
  90. private:
  91. HeapBlock <float> values;
  92. const int size;
  93. // no reason not to implement these one day..
  94. ImageConvolutionKernel (const ImageConvolutionKernel&);
  95. const ImageConvolutionKernel& operator= (const ImageConvolutionKernel&);
  96. };
  97. #endif // __JUCE_IMAGECONVOLUTIONKERNEL_JUCEHEADER__