1 #include "bcdisplayinfo.h"
2 #include "gammawindow.h"
9 PLUGIN_THREAD_OBJECT(GammaMain, GammaThread, GammaWindow)
16 GammaWindow::GammaWindow(GammaMain *client, int x, int y)
17 : BC_Window(client->gui_string, x,
26 this->client = client;
29 int GammaWindow::create_objects()
32 add_subwindow(histogram = new BC_SubWindow(x,
37 y += histogram->get_h() + 10;
40 add_tool(title = new BC_Title(x, y, _("Maximum:")));
41 x += title->get_w() + 10;
42 add_tool(max_slider = new MaxSlider(client,
47 x += max_slider->get_w() + 10;
48 add_tool(max_text = new MaxText(client,
53 y += max_text->get_h() + 10;
55 add_tool(automatic = new GammaAuto(client, x, y));
57 y += automatic->get_h() + 10;
58 add_tool(title = new BC_Title(x, y, _("Gamma:")));
59 x += title->get_w() + 10;
60 add_tool(gamma_slider = new GammaSlider(client,
65 x += gamma_slider->get_w() + 10;
66 add_tool(gamma_text = new GammaText(client,
71 y += gamma_text->get_h() + 10;
74 add_tool(plot = new GammaPlot(client, x, y));
75 y += plot->get_h() + 10;
77 add_tool(new GammaColorPicker(client, this, x, y));
84 void GammaWindow::update()
86 max_slider->update(client->config.max);
87 max_text->update(client->config.max);
88 gamma_slider->update(client->config.gamma);
89 gamma_text->update(client->config.gamma);
90 automatic->update(client->config.automatic);
91 plot->update(client->config.plot);
95 void GammaWindow::update_histogram()
97 histogram->clear_box(0, 0, histogram->get_w(), histogram->get_h());
101 histogram->set_color(MEGREY);
102 for(int i = 0; i < histogram->get_w(); i++)
104 int x1 = (int64_t)i * HISTOGRAM_SIZE / histogram->get_w();
105 int x2 = (int64_t)(i + 1) * HISTOGRAM_SIZE / histogram->get_w();
108 for(int x = x1; x < x2; x++)
110 accum += client->engine->accum[x];
112 if(accum > max) max = accum;
114 for(int i = 0; i < histogram->get_w(); i++)
116 int x1 = (int64_t)i * HISTOGRAM_SIZE / histogram->get_w();
117 int x2 = (int64_t)(i + 1) * HISTOGRAM_SIZE / histogram->get_w();
120 for(int x = x1; x < x2; x++)
122 accum += client->engine->accum[x];
125 int h = (int)(log(accum) / log(max) * histogram->get_h());
126 histogram->draw_line(i,
129 histogram->get_h() - h);
133 histogram->set_color(GREEN);
134 int y1 = histogram->get_h();
135 float scale = 1.0 / client->config.max;
136 float gamma = client->config.gamma - 1.0;
137 float max = client->config.max;
138 for(int i = 1; i < histogram->get_w(); i++)
140 float in = (float)i / histogram->get_w();
141 float out = in * (scale * pow(in * 2 / max, gamma));
142 int y2 = (int)(histogram->get_h() - out * histogram->get_h());
143 histogram->draw_line(i - 1, y1, i, y2);
149 WINDOW_CLOSE_EVENT(GammaWindow)
151 MaxSlider::MaxSlider(GammaMain *client,
165 this->client = client;
170 int MaxSlider::handle_event()
172 client->config.max = get_value();
173 gui->max_text->update(client->config.max);
174 gui->update_histogram();
175 client->send_configure_change();
179 MaxText::MaxText(GammaMain *client,
184 : BC_TextBox(x, y, w, 1, client->config.max)
186 this->client = client;
190 int MaxText::handle_event()
192 client->config.max = atof(get_text());
193 gui->max_slider->update(client->config.max);
194 client->send_configure_change();
198 GammaSlider::GammaSlider(GammaMain *client,
210 client->config.gamma)
212 this->client = client;
217 int GammaSlider::handle_event()
219 client->config.gamma = get_value();
220 gui->gamma_text->update(client->config.gamma);
221 gui->update_histogram();
222 client->send_configure_change();
226 GammaText::GammaText(GammaMain *client,
231 : BC_TextBox(x, y, w, 1, client->config.gamma)
233 this->client = client;
237 int GammaText::handle_event()
239 client->config.gamma = atof(get_text());
240 gui->gamma_slider->update(client->config.gamma);
241 client->send_configure_change();
245 GammaAuto::GammaAuto(GammaMain *client, int x, int y)
248 client->config.automatic,
251 this->plugin = client;
254 int GammaAuto::handle_event()
256 plugin->config.automatic = get_value();
257 plugin->send_configure_change();
262 GammaPlot::GammaPlot(GammaMain *plugin, int x, int y)
263 : BC_CheckBox(x, y, plugin->config.plot, _("Plot histogram"))
265 this->plugin = plugin;
267 int GammaPlot::handle_event()
269 plugin->config.plot = get_value();
270 plugin->send_configure_change();
275 GammaColorPicker::GammaColorPicker(GammaMain *plugin,
279 : BC_GenericButton(x, y, _("Use Color Picker"))
281 this->plugin = plugin;
285 int GammaColorPicker::handle_event()
287 // Get colorpicker value
288 float red = plugin->get_red();
289 float green = plugin->get_green();
290 float blue = plugin->get_blue();
292 plugin->config.max = MAX(red, green);
293 plugin->config.max = MAX(plugin->config.max, blue);
294 gui->max_text->update(plugin->config.max);
295 gui->max_slider->update(plugin->config.max);
296 plugin->send_configure_change();