Visocor: Color Blind Compiz Plugin Code
Status: Beta
Brought to you by:
rafaelolg
--- a +++ b/slicer.c @@ -0,0 +1,192 @@ + +/*----------------------------------------------------------------------------*\ + | 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]; + + +} + +