-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIPManager.cpp
More file actions
141 lines (122 loc) · 4.1 KB
/
IPManager.cpp
File metadata and controls
141 lines (122 loc) · 4.1 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
#include "IPManager.h"
#include "PtOpenGL.h"
#include "GLUtils.h"
IPManager::IPManager(GLPresenter& presenter) : activeFilters(NONE),
localContrastGather(NULL), localContrastApply(NULL),
localContrastBuffers(NULL),
contrastIncrease(0.15f), gamma(1.05f),
localContrastRange(5),
presenter(presenter)
{
localContrastGather = new GLFragmentProgram("shaders/local_contrast_gather.glsl", presenter.getShaderPrependString());
localContrastApply = new GLFragmentProgram("shaders/local_contrast_apply.glsl", presenter.getShaderPrependString());
localContrastApply->setParameter("original", 0);
localContrastApply->setParameter("gathered", 1);
localContrastApply->setParameter("contrastIncrease", contrastIncrease);
gammaCorrection = new GLFragmentProgram("shaders/gamma.glsl", presenter.getShaderPrependString());
gammaCorrection->setParameter("gamma", gamma);
localContrastBuffers = new GLRenderTexture*[localContrastRange];
for(unsigned i=0; i<localContrastRange; ++i) {
localContrastBuffers[i] = new GLRenderTexture(presenter.getW()/(2<<i), presenter.getH()/(2<<i), GL_RGBA8, GL_RGBA, GL_UNSIGNED_BYTE);
}
RT_GL_ASSERT("Error during IPManager initialization.");
}
IPManager::~IPManager()
{
if(localContrastGather) delete localContrastGather;
if(localContrastApply) delete localContrastApply;
if(gammaCorrection) delete gammaCorrection;
for(unsigned i=0; i<localContrastRange; ++i) {
delete localContrastBuffers[i];
}
delete [] localContrastBuffers;
}
void IPManager::applyIP(GLRenderTexture *source, GLRenderTexture *target)
{
NONRELEASE(
glFinish();
static SlidingAverage avg(60);
Timer time;
);
if(activeFilters == NONE) {
target->makeCurrent();
source->bindTexture();
glutil::drawQuad();
target->releaseCurrent();
}
else {
GLRenderTexture *c_src = source, *c_trg = target, *tmp;
if(activeFilters & LOCAL_CONTRAST) {
localContrastGather->use();
for(unsigned i=0; i<localContrastRange; ++i) {
localContrastBuffers[i]->makeCurrent();
if(i==0) c_src->bindTexture();
else localContrastBuffers[i-1]->bindTexture();
glutil::drawQuad();
localContrastBuffers[i]->releaseCurrent();
}
localContrastGather->stopUsing();
c_trg->makeCurrent();
localContrastApply->use();
c_src->bindTexture(0);
localContrastBuffers[localContrastRange-1]->bindTexture(1);
glutil::drawQuad();
localContrastApply->stopUsing();
c_trg->releaseCurrent();
tmp = c_src; c_src = c_trg; c_trg = c_src;
}
if(activeFilters & GAMMA_CORRECTION) {
c_trg->makeCurrent();
gammaCorrection->use();
c_src->bindTexture();
glutil::drawQuad();
gammaCorrection->stopUsing();
c_trg->releaseCurrent();
tmp = c_src; c_src = c_trg; c_trg = c_src;
}
// if last target isn't real target, copy
if(c_trg != target) {
target->makeCurrent();
c_trg->bindTexture();
glutil::drawQuad();
target->releaseCurrent();
}
}
NONRELEASE(
glFinish();
avg.add(time.elapsed());
if(avg.justFilled()) printf("(2) IP step average time: %6.2lf microseconds\n", avg.get());
);
}
IPManager::ipFilters IPManager::getActiveFilters()
{
return activeFilters;
}
void IPManager::toggleFilter( ipFilters filter )
{
activeFilters = (ipFilters)(activeFilters ^ filter);
Console::get().add(format("Active image processing filters: %s", getActiveFilterString().c_str()));
}
std::string IPManager::getActiveFilterString()
{
string ret = "";
if(activeFilters == NONE) ret = "None, ";
if(activeFilters & LOCAL_CONTRAST) ret += "Local Contrast Enhancement, ";
if(activeFilters & GAMMA_CORRECTION) ret += "Gamma Correction, ";
ret = ret.substr(0, ret.length()-2);
return ret;
}
void IPManager::adjustContrastIncrease( GLfloat adjustment )
{
contrastIncrease += adjustment;
localContrastApply->setParameter("contrastIncrease", contrastIncrease);
Console::get().add(format("Adjusted local contrast enhancement to: %3.2f", contrastIncrease));
}
void IPManager::adjustGamma( GLfloat adjustment )
{
gamma += adjustment;
if(gamma < 0.1f) gamma = 0.1f;
if(gamma > 10.0f) gamma = 10.0f;
gammaCorrection->setParameter("gamma", gamma);
Console::get().add(format("Adjusted gamma correction to: %4.2f", gamma));
}