Welcome to mirror list, hosted at ThFree Co, Russian Federation.

COM_ConvolutionEdgeFilterOperation.cpp « operations « compositor « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6505e1be83ecfd988580bc61b75215a33b4543e5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/*
 * Copyright 2011, Blender Foundation.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 *
 * Contributor: 
 *		Jeroen Bakker 
 *		Monique Dewanchand
 */

#include "COM_ConvolutionEdgeFilterOperation.h"
#include "BLI_math.h"

ConvolutionEdgeFilterOperation::ConvolutionEdgeFilterOperation() : ConvolutionFilterOperation() {
}
inline void addFilter(float* result, float*input, float value) {
	result[0] += input[0] * value;
	result[1] += input[1] * value;
	result[2] += input[2] * value;
}

void ConvolutionEdgeFilterOperation::executePixel(float *color,int x, int y, MemoryBuffer *inputBuffers[], void* data) {
	float in1[4],in2[4], res1[4], res2[4];
	
	float value[4];
	this->inputValueOperation->read(value, x, y, inputBuffers, NULL);
	float mval = 1.0f - value[0];
	
	res1[0] = 0.0f;
	res1[1] = 0.0f;
	res1[2] = 0.0f;
	res1[3] = 0.0f;
	res2[0] = 0.0f;
	res2[1] = 0.0f;
	res2[2] = 0.0f;
	res2[3] = 0.0f;
	
	this->inputOperation->read(in1, x-1, y-1, inputBuffers, NULL);
	addFilter(res1, in1, this->filter[0]);
	addFilter(res2, in1, this->filter[0]);
	
	this->inputOperation->read(in1, x, y-1, inputBuffers, NULL);
	addFilter(res1, in1, this->filter[1]);
	addFilter(res2, in1, this->filter[3]);
	
	this->inputOperation->read(in1, x+1, y-1, inputBuffers, NULL);
	addFilter(res1, in1, this->filter[2]);
	addFilter(res2, in1, this->filter[6]);
	
	this->inputOperation->read(in1, x-1, y, inputBuffers, NULL);
	addFilter(res1, in1, this->filter[3]);
	addFilter(res2, in1, this->filter[1]);
	
	this->inputOperation->read(in2, x, y, inputBuffers, NULL);
	addFilter(res1, in2, this->filter[4]);
	addFilter(res2, in2, this->filter[4]);
	
	this->inputOperation->read(in1, x+1, y, inputBuffers, NULL);
	addFilter(res1, in1, this->filter[5]);
	addFilter(res2, in1, this->filter[7]);
	
	this->inputOperation->read(in1, x-1, y+1, inputBuffers, NULL);
	addFilter(res1, in1, this->filter[6]);
	addFilter(res2, in1, this->filter[2]);
	
	this->inputOperation->read(in1, x, y+1, inputBuffers, NULL);
	addFilter(res1, in1, this->filter[7]);
	addFilter(res2, in1, this->filter[5]);
	
	this->inputOperation->read(in1, x+1, y+1, inputBuffers, NULL);
	addFilter(res1, in1, this->filter[8]);
	addFilter(res2, in1, this->filter[8]);
	
	color[0] = sqrt(res1[0]*res1[0]+res2[0]*res2[0]);
	color[1] = sqrt(res1[1]*res1[1]+res2[1]*res2[1]);
	color[2] = sqrt(res1[2]*res1[2]+res2[2]*res2[2]);
	
	color[0] = color[0]*value[0] + in2[0] * mval;
	color[1] = color[1]*value[0] + in2[1] * mval;
	color[2] = color[2]*value[0] + in2[2] * mval;
	
	color[3] = in2[3];
}