2 ==============================================================================
4 This file is part of the JUCE library - "Jules' Utility Class Extensions"
5 Copyright 2004-11 by Raw Material Software Ltd.
7 ------------------------------------------------------------------------------
9 JUCE can be redistributed and/or modified under the terms of the GNU General
10 Public License (Version 2), as published by the Free Software Foundation.
11 A copy of the license is included in the JUCE distribution, or can be found
12 online at www.gnu.org/licenses.
14 JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
16 A PARTICULAR PURPOSE. See the GNU General Public License for more details.
18 ------------------------------------------------------------------------------
20 To release a closed-source product which uses JUCE, commercial licenses are
21 available: visit www.rawmaterialsoftware.com/juce for more information.
23 ==============================================================================
26 #ifndef __JUCE_IMAGECONVOLUTIONKERNEL_JUCEHEADER__
27 #define __JUCE_IMAGECONVOLUTIONKERNEL_JUCEHEADER__
29 #include "juce_Image.h"
32 //==============================================================================
34 Represents a filter kernel to use in convoluting an image.
36 @see Image::applyConvolution
38 class JUCE_API ImageConvolutionKernel
41 //==============================================================================
42 /** Creates an empty convulution kernel.
44 @param size the length of each dimension of the kernel, so e.g. if the size
45 is 5, it will create a 5x5 kernel
47 ImageConvolutionKernel (int size
);
50 ~ImageConvolutionKernel();
52 //==============================================================================
53 /** Resets all values in the kernel to zero. */
56 /** Returns one of the kernel values. */
57 float getKernelValue (int x
, int y
) const noexcept
;
59 /** Sets the value of a specific cell in the kernel.
61 The x and y parameters must be in the range 0 < x < getKernelSize().
65 void setKernelValue (int x
, int y
, float value
) noexcept
;
67 /** Rescales all values in the kernel to make the total add up to a fixed value.
69 This will multiply all values in the kernel by (desiredTotalSum / currentTotalSum).
71 void setOverallSum (float desiredTotalSum
);
73 /** Multiplies all values in the kernel by a value. */
74 void rescaleAllValues (float multiplier
);
76 /** Intialises the kernel for a gaussian blur.
78 @param blurRadius this may be larger or smaller than the kernel's actual
79 size but this will obviously be wasteful or clip at the
80 edges. Ideally the kernel should be just larger than
83 void createGaussianBlur (float blurRadius
);
85 //==============================================================================
86 /** Returns the size of the kernel.
88 E.g. if it's a 3x3 kernel, this returns 3.
90 int getKernelSize() const { return size
; }
92 //==============================================================================
93 /** Applies the kernel to an image.
95 @param destImage the image that will receive the resultant convoluted pixels.
96 @param sourceImage the source image to read from - this can be the same image as
97 the destination, but if different, it must be exactly the same
99 @param destinationArea the region of the image to apply the filter to
101 void applyToImage (Image
& destImage
,
102 const Image
& sourceImage
,
103 const Rectangle
<int>& destinationArea
) const;
106 //==============================================================================
107 HeapBlock
<float> values
;
110 JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ImageConvolutionKernel
);
114 #endif // __JUCE_IMAGECONVOLUTIONKERNEL_JUCEHEADER__