[go: up one dir, main page]

Menu

[r1]: / filter.c  Maximize  Restore  History

Download this file

166 lines (130 with data), 4.7 kB

  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
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*----------------------------------------------------------------------------*\
| Copyright (C) 2009 - Rafael de O. Lopes Gonçalves and André Shoji Asato |
| 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 3 |
| of the License. |
| |
| 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.|
\*----------------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include "visocor.h"
static const int LAST_FILTER = N_FILTER_VARIATIONS - 1;
static const int FIRST_FILTER = 0;
static const int FILTER_STEP = 1;
static void recalculateColorFilter(CompScreen * s) {
VISOCOR_SCREEN(s);
int middle;
middle = (LAST_FILTER + FIRST_FILTER) / 2;
if (vs->filterIntensity > middle) {
vs->ir = ((float) vs->filterIntensity - middle)
/ (LAST_FILTER - middle);
vs->ig = 0;
} else {
vs->ig = ((float) middle - vs->filterIntensity) / (middle
- FIRST_FILTER);
vs->ir = 0;
}
vs->ib = 1.0 - vs->ig - vs->ir;
visocorPrintf(CompLogLevelDebug, "ir = %f\tig = %f\tib = %f", vs->ir,
vs->ig, vs->ib);
}
void visocorResetFilter(VISOCORScreen * vs) {
int middle;
middle = (LAST_FILTER + FIRST_FILTER) / 2;
vs->filterIntensity = middle;
vs->ig = 0;
vs->ir = 0;
vs->ib = 1;
}
Bool visocorToggleFilter(CompDisplay * d, CompAction * action,
CompActionState state, CompOption * option, int nOption) {
CompWindow *w;
w = visocorFindWindow(d, option, nOption);
if (w) {
VISOCOR_WINDOW(w);
if (vw->currentState != FILTER) {
visocorToggleWindowToState(w, FILTER);
} else {
visocorToggleWindowToState(w, vw->lastState);
}
}
return TRUE;
}
Bool visocorDecreaseFilter(CompDisplay * d, CompAction * action,
CompActionState state, CompOption * option, int nOption) {
int value;
CompScreen *s;
s = visocorFindScreen(d, option, nOption);
if (s) {
VISOCOR_SCREEN(s);
value = MAX(FIRST_FILTER, vs->filterIntensity - FILTER_STEP);
vs->filterIntensity = value;
recalculateColorFilter(s);
visocorDamageAllWindows(s);
return TRUE;
}
return FALSE;
}
Bool visocorIncreaseFilter(CompDisplay * d, CompAction * action,
CompActionState state, CompOption * option, int nOption) {
CompScreen *s;
int value;
s = visocorFindScreen(d, option, nOption);
if (s) {
VISOCOR_SCREEN(s);
value = MIN(LAST_FILTER, vs->filterIntensity + FILTER_STEP);
vs->filterIntensity = value;
recalculateColorFilter(s);
visocorDamageAllWindows(s);
return TRUE;
}
return FALSE;
}
int getVisocorFilterFragmentFunction(CompScreen * s, CompTexture * texture,
int param) {
VISOCOR_SCREEN(s);
if (vs->visocorFunctions[FILTER][param] == 0) {
CompFunctionData *data;
int target;
char filter_operation[1024];
Bool ok = TRUE;
visocorPrintf(CompLogLevelDebug, "criando um FILTER com a variavel %d",
param);
if (texture->target == GL_TEXTURE_2D)
target = COMP_FETCH_TARGET_2D;
else
target = COMP_FETCH_TARGET_RECT;
data = createFunctionData();
if (data) {
ok &= addTempHeaderOpToFunctionData(data, "tex");
ok &= addTempHeaderOpToFunctionData(data, "temp");
ok &= addFetchOpToFunctionData(data, "tex", NULL, target);
char * format = "DP3 temp.r, tex, {1 , 0 , 0 , 0};\n"
"DP3 temp.g, tex, {0 , 1 , 0 , 0};\n"
"DP3 temp.b, tex, program.env[%d].xyzw;\n"
"MOV temp.a, tex.a;";
sprintf(filter_operation, format, param);
}
ok &= addDataOpToFunctionData(data, filter_operation);
ok &= addColorOpToFunctionData(data, "output", "temp");
if (!ok) {
destroyFunctionData(data);
return 0;
}
vs->visocorFunctions[FILTER][param] = createFragmentFunction(s,
"visocor", data);
;
}
(*s->programEnvParameter4f)(GL_FRAGMENT_PROGRAM_ARB, param, vs->ir, vs->ig,
vs->ib, 1.0f);
return vs->visocorFunctions[FILTER][param];
}