[go: up one dir, main page]

Menu

[r1]: / slicer.c  Maximize  Restore  History

Download this file

193 lines (148 with data), 5.8 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*----------------------------------------------------------------------------*\
| 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 2 |
| 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"
void visocorMousepollPositionUpdate(CompScreen *s, int x, int y) {
VISOCOR_SCREEN(s);
vs->mousePosX = x;
vs->mousePosY = y;
}
Bool visocorMousepollClickKeyInitiateSlice(CompDisplay *d,
CompAction *action, CompActionState state, CompOption *option,
int nOption) {
CompScreen *s;
Window xid;
xid = getIntOptionNamed(option, nOption, "root", 0);
s = findScreenAtDisplay(d, xid);
if (s) {
VISOCOR_SCREEN (s);
VISOCOR_DISPLAY (s->display);
if (otherScreenGrabExist(s, 0))
return FALSE;
if (state & CompActionStateInitButton)
action->state |= CompActionStateTermButton;
if (state & CompActionStateInitKey)
action->state |= CompActionStateTermKey;
if (visocorGetMousepollToggleBool(s->display) && !vs->pollHandle) {
(*vd->mousepollFunc->getCurrentPosition)(s, &vs->mousePosX,
&vs->mousePosY);
vs->pollHandle = (*vd->mousepollFunc->addPositionPolling)(s,
visocorMousepollPositionUpdate);
}
}
return TRUE;
}
Bool visocorMousepollClickKeyTerminateSlice(CompDisplay *d,
CompAction *action, CompActionState state, CompOption *option,
int nOption) {
CompScreen *s;
Window xid;
CompWindow * w;
xid = getIntOptionNamed(option, nOption, "root", 0);
for (s = d->screens; s; s = s->next) {
int i;
GLint viewport[4];
GLubyte color[3];
VISOCOR_SCREEN (s);
VISOCOR_DISPLAY (s->display);
if (xid && s->root != xid)
continue;
if (vs->pollHandle) {
(*vd->mousepollFunc->removePositionPolling)(s, vs->pollHandle);
vs->pollHandle = 0;
}
glGetIntegerv(GL_VIEWPORT, viewport);
glReadPixels(vs->mousePosX, viewport[3] - vs->mousePosY, 1, 1, GL_RGB,
GL_UNSIGNED_BYTE, (void *) color);
visocorPrintf(CompLogLevelDebug,
"pegou info da posicao:(%4d, %3d); (%f, %f, %f)",
vs->mousePosX, vs->mousePosY, vs->mouse_pixel[0],
vs->mouse_pixel[1], vs->mouse_pixel[2]);
for (i = 0; i < 3; i++) {
vs->mouse_pixel[i] = ((float) color[i]) / 255;
}
}
w = visocorFindWindow(d,option, nOption);
if (w) {
VISOCOR_WINDOW(w);
if(vw->currentState != SLICE) {
visocorToggleWindowToState(w, SLICE);
}else {
visocorToggleWindowToState(w, vw->lastState);
}
visocorPrintf(CompLogLevelDebug, "vw->state = %d\n", vw->currentState);
}
action->state &= ~(CompActionStateTermKey | CompActionStateTermButton);
return FALSE;
}
int getVisocorSlicerFragmentFunction(CompScreen * s, CompTexture * texture,
int param) {
float r_precision;
float g_precision;
float b_precision;
VISOCOR_SCREEN(s);
if (vs->visocorFunctions[SLICE][param] == 0) {
CompFunctionData *data;
int target;
char filter_operation[1024];
Bool ok = TRUE;
visocorPrintf(CompLogLevelDebug, "criando um SLICER 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);
ok &= addTempHeaderOpToFunctionData(data, "test");
ok &= addTempHeaderOpToFunctionData(data, "dist");
ok &= addTempHeaderOpToFunctionData(data, "bw");
char * format = "SUB dist, tex, program.env[%d];\n"
"MUL dist, dist, program.env[%d];\n"
"DP3 dist, dist, dist;\n"
"SUB test, 1.0 ,dist;\n"
/*cria o negativo*/
"DP3_SAT bw, tex, {0.2, 0.2, 0.2, 0};\n"
"SUB bw, 1, bw;\n"
/*testa onde substituir*/
"CMP temp, test, bw, tex;\n"
"MOV temp.a, tex.a;\n";
sprintf(filter_operation, format, param, param + 1);
visocorPrintf(CompLogLevelDebug, "%s\n", filter_operation);
ok &= addDataOpToFunctionData(data, filter_operation);
}
ok &= addColorOpToFunctionData(data, "output", "temp");
if (!ok) {
destroyFunctionData(data);
return 0;
}
vs->visocorFunctions[SLICE][param] = createFragmentFunction(s, "visocor", data);;
}
r_precision = visocorGetMaxdistancered(s);
g_precision = visocorGetMaxdistancegreen(s);
b_precision = visocorGetMaxdistanceblue(s);
(*s->programEnvParameter4f)(
GL_FRAGMENT_PROGRAM_ARB, param, vs->mouse_pixel[0],
vs->mouse_pixel[1], vs->mouse_pixel[2], 1.0f);
(*s->programEnvParameter4f)(
GL_FRAGMENT_PROGRAM_ARB, param + 1, r_precision, g_precision, b_precision, 0.0f);
visocorPrintf(CompLogLevelDebug, "slicer: r = %f\tg = %f\tb = %f", r_precision, g_precision, b_precision);
return vs->visocorFunctions[SLICE][param];
}