33 Eigen::Matrix<qreal, Eigen::Dynamic, Eigen::Dynamic> matrix(kernelSize, kernelSize);
36 const int center = kernelSize / 2;
39 for (
int x = 0; x < kernelSize; x++) {
40 for (
int y=0; y<kernelSize; y++) {
43 xDistance = x - center;
45 xDistance = center - x;
47 matrix(x, y) = xDistance;
51 matrix.resize(kernelSize, 1);
52 for (
int x = 0; x < kernelSize; x++) {
55 xDistance = x - center;
57 xDistance = center - x;
62 matrix(x, 0) = (1/xDistance);
66 for (
int x = 0; x < kernelSize; x++) {
67 for (
int y=0; y<kernelSize; y++) {
68 if (x==center && y==center) {
79 matrix(x, y) = xD / (xD*xD + yD*yD);
93 Eigen::Matrix<qreal, Eigen::Dynamic, Eigen::Dynamic> matrix(kernelSize, kernelSize);
95 const int center = kernelSize / 2;
98 for (
int y = 0; y < kernelSize; y++) {
99 for (
int x=0; x<kernelSize; x++) {
102 yDistance = y - center;
104 yDistance = center - y;
106 matrix(x, y) = yDistance;
110 matrix.resize(1, kernelSize);
111 for (
int y = 0; y < kernelSize; y++) {
114 yDistance = y - center;
116 yDistance = center - y;
121 matrix(0, y) = (1/yDistance);
125 for (
int y = 0; y < kernelSize; y++) {
126 for (
int x=0; x<kernelSize; x++) {
127 if (x==center && y==center) {
138 matrix(x, y) = yD / (xD*xD + yD*yD);
151 Eigen::Matrix<qreal, Eigen::Dynamic, Eigen::Dynamic> matrix =
createHorizontalMatrix(radius, type, reverse);
164 Eigen::Matrix<qreal, Eigen::Dynamic, Eigen::Dynamic> matrix =
createVerticalMatrix(radius, type, reverse);
179 return 0.3 * radius + 0.3;
187 const QBitArray &channelFlags,
192 QPoint srcTopLeft =
rect.topLeft();
210 horizPainterLR.
applyMatrix(kernelHorizLeftRight, device,
219 verticalPainterTB.
applyMatrix(kernelVerticalTopBottom, device,
242 for (
int c = 0; c<channels; c++) {
243 finalNorm[c] = 2 * sqrt( ((xNormalised[c]-0.5)*(xNormalised[c]-0.5)) + ((yNormalised[c]-0.5)*(yNormalised[c]-0.5)));
246 for (
int c = 0; c<channels; c++) {
247 finalNorm[c] = atan2(xNormalised[c]-0.5, yNormalised[c]-0.5);
255 for (
int c = 0; c<(channels-1); c++) {
256 alpha = alpha+finalNorm[c];
259 alpha = qMin(alpha/(channels-1), col.
opacityF());
264 finalNorm[alphaPos] = 1.0;
266 memcpy(finalIt.
rawData(), f, pixelSize);
272 bool denormalize = !writeToAlpha;
275 }
else if (output ==
xFall) {
277 }
else if (output ==
yGrowth) {
291 srcTopLeft, srcTopLeft,
302 for (
int c = 0; c<channels; c++) {
303 alpha = alpha+normalised[c];
305 alpha = qMin(alpha/channels, col.
opacityF());
316 srcTopLeft, srcTopLeft,
334 int channelToConvert,
337 const QBitArray &channelFlags,
339 boost::optional<bool> useFftw)
343 QPoint srcTopLeft =
rect.topLeft();
363 horizPainterLR.
applyMatrix(kernelHorizLeftRight, device,
364 srcTopLeft, srcTopLeft,
376 verticalPainterTB.
applyMatrix(kernelVerticalTopBottom, device,
400 if (channelFlip[2]==
true){
403 QVector3D normal = QVector3D((xNormalised[channelToConvert]-0.5)*2, (yNormalised[channelToConvert]-0.5)*2, z);
406 for (
int c = 0; c < 3; c++) {
407 finalNorm[channelInfo.at(channelOrder[c])->displayPosition()] = (normal[channelOrder[c]]/2)+0.5;
410 finalNorm[alphaPos]= 1.0;
412 quint8* pixel = finalIt.
rawData();
414 memcpy(finalIt.
rawData(), pixel, pixelSize);
The KisConvolutionPainter class applies a convolution kernel to a paint device.
void applyMatrix(const KisConvolutionKernelSP kernel, const KisPaintDeviceSP src, QPoint srcPos, QPoint dstPos, QSize areaSize, KisConvolutionBorderOp borderOp=BORDER_REPEAT)
void setEnginePreference(EnginePreference value)
static int kernelSizeFromRadius(qreal radius)
static void applyEdgeDetection(KisPaintDeviceSP device, const QRect &rect, qreal xRadius, qreal yRadius, FilterType type, const QBitArray &channelFlags, KoUpdater *progressUpdater, FilterOutput output=pythagorean, bool writeToAlpha=false)
applyEdgeDetection This applies the edge detection filter to the device.
static void convertToNormalMap(KisPaintDeviceSP device, const QRect &rect, qreal xRadius, qreal yRadius, FilterType type, int channelToConvert, QVector< int > channelOrder, QVector< bool > channelFlip, const QBitArray &channelFlags, KoUpdater *progressUpdater, boost::optional< bool > useFftw=boost::none)
convertToNormalMap Convert a channel of the device to a normal map. The channel will be interpreted a...
static KisConvolutionKernelSP createHorizontalKernel(qreal radius, FilterType type, bool denormalize=true, bool reverse=false)
static Eigen::Matrix< qreal, Eigen::Dynamic, Eigen::Dynamic > createVerticalMatrix(qreal radius, FilterType type, bool reverse=false)
createVerticalMatrix
static Eigen::Matrix< qreal, Eigen::Dynamic, Eigen::Dynamic > createHorizontalMatrix(qreal radius, FilterType type, bool reverse=false)
createHorizontalMatrix
static KisConvolutionKernelSP createVerticalKernel(qreal radius, FilterType type, bool denormalize=true, bool reverse=false)
static qreal sigmaFromRadius(qreal radius)
const KoColorSpace * colorSpace() const
void prepareClone(KisPaintDeviceSP src)
void setProgress(KoUpdater *progressUpdater)
void setChannelFlags(QBitArray channelFlags)
bool nextPixels(int numPixels)
ALWAYS_INLINE quint8 * rawData()
int nConseqPixels() const
virtual quint32 alphaPos() const =0
virtual quint32 pixelSize() const =0
virtual void setOpacity(quint8 *pixels, quint8 alpha, qint32 nPixels) const =0
QList< KoChannelInfo * > channels
virtual quint32 channelCount() const =0
virtual void normalisedChannelsValue(const quint8 *pixel, QVector< float > &channels) const =0
virtual void fromNormalisedChannelsValue(quint8 *pixel, const QVector< float > &values) const =0
virtual quint32 colorChannelCount() const =0
void setOpacity(quint8 alpha)
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
#define KIS_ASSERT_RECOVER_RETURN(cond)
#define KIS_ASSERT_RECOVER_NOOP(cond)
static KisConvolutionKernelSP fromMatrix(Eigen::Matrix< qreal, Eigen::Dynamic, Eigen::Dynamic > matrix, qreal offset, qreal factor)