4 * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "bcdisplayinfo.h"
23 #include "gammawindow.h"
28 GammaWindow::GammaWindow(GammaMain *client)
29 : PluginClientWindow(client,
36 this->client = client;
39 void GammaWindow::create_objects()
41 int x = 10, y = 10, x1 = x;
42 add_subwindow(histogram = new BC_SubWindow(x,
47 y += histogram->get_h() + 10;
50 add_tool(title = new BC_Title(x, y, _("Maximum:")));
51 x += title->get_w() + 10;
52 x1 = x; // save x to align the two sliders
53 add_tool(max_slider = new MaxSlider(client,
58 x += max_slider->get_w() + 10;
59 add_tool(max_text = new MaxText(client,
64 y += max_text->get_h() + 10;
66 add_tool(automatic = new GammaAuto(client, x, y));
67 y += automatic->get_h() + 10;
68 add_tool(title = new BC_Title(x, y, _("Gamma:")));
69 x += title->get_w() + 10;
70 x = x1; // recover x of the "MaxSlider" to align the "GammaSlider"
71 add_tool(gamma_slider = new GammaSlider(client,
76 x += gamma_slider->get_w() + 10;
77 add_tool(gamma_text = new GammaText(client,
82 y += gamma_text->get_h() + 10;
85 add_tool(plot = new GammaPlot(client, x, y));
86 y += plot->get_h() + 10;
88 add_tool(new GammaColorPicker(client, this, x, y));
90 add_tool(reset = new GammaReset(client, this, get_w()-110, y));
96 void GammaWindow::update()
98 max_slider->update(client->config.max);
99 max_text->update(client->config.max);
100 gamma_slider->update(client->config.gamma);
101 gamma_text->update(client->config.gamma);
102 automatic->update(client->config.automatic);
103 plot->update(client->config.plot);
107 void GammaWindow::update_histogram()
109 histogram->clear_box(0, 0, histogram->get_w(), histogram->get_h());
113 histogram->set_color(MEGREY);
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];
124 if(accum > max) max = accum;
126 for(int i = 0; i < histogram->get_w(); i++)
128 int x1 = (int64_t)i * HISTOGRAM_SIZE / histogram->get_w();
129 int x2 = (int64_t)(i + 1) * HISTOGRAM_SIZE / histogram->get_w();
132 for(int x = x1; x < x2; x++)
134 accum += client->engine->accum[x];
137 int h = (int)(log(accum) / log(max) * histogram->get_h());
138 histogram->draw_line(i,
141 histogram->get_h() - h);
145 histogram->set_color(GREEN);
146 int y1 = histogram->get_h();
147 float max = client->config.max * client->config.gamma;
148 float scale = 1.0 / max;
149 float gamma = client->config.gamma - 1.0;
150 for(int i = 1; i < histogram->get_w(); i++)
152 float in = (float)i / histogram->get_w();
153 float out = in * (scale * pow(in * 2 / max, gamma));
154 int y2 = (int)(histogram->get_h() - out * histogram->get_h());
155 histogram->draw_line(i - 1, y1, i, y2);
164 MaxSlider::MaxSlider(GammaMain *client,
178 this->client = client;
183 int MaxSlider::handle_event()
185 client->config.max = get_value();
186 gui->max_text->update(client->config.max);
187 gui->update_histogram();
188 client->send_configure_change();
192 MaxText::MaxText(GammaMain *client,
197 : BC_TextBox(x, y, w, 1, client->config.max)
199 this->client = client;
203 int MaxText::handle_event()
205 client->config.max = atof(get_text());
206 gui->max_slider->update(client->config.max);
207 client->send_configure_change();
211 GammaSlider::GammaSlider(GammaMain *client,
223 client->config.gamma)
225 this->client = client;
230 int GammaSlider::handle_event()
232 client->config.gamma = get_value();
233 gui->gamma_text->update(client->config.gamma);
234 gui->update_histogram();
235 client->send_configure_change();
239 GammaText::GammaText(GammaMain *client,
244 : BC_TextBox(x, y, w, 1, client->config.gamma)
246 this->client = client;
250 int GammaText::handle_event()
252 client->config.gamma = atof(get_text());
253 gui->gamma_slider->update(client->config.gamma);
254 client->send_configure_change();
258 GammaAuto::GammaAuto(GammaMain *client, int x, int y)
261 client->config.automatic,
264 this->plugin = client;
267 int GammaAuto::handle_event()
269 plugin->config.automatic = get_value();
270 plugin->send_configure_change();
275 GammaPlot::GammaPlot(GammaMain *plugin, int x, int y)
276 : BC_CheckBox(x, y, plugin->config.plot, _("Plot histogram"))
278 this->plugin = plugin;
280 int GammaPlot::handle_event()
282 plugin->config.plot = get_value();
283 plugin->send_configure_change();
288 GammaColorPicker::GammaColorPicker(GammaMain *plugin,
292 : BC_GenericButton(x, y, _("Use Color Picker"))
294 this->plugin = plugin;
298 int GammaColorPicker::handle_event()
300 // Get colorpicker value
301 float red = plugin->get_red();
302 float green = plugin->get_green();
303 float blue = plugin->get_blue();
305 plugin->config.max = MAX(red, green);
306 plugin->config.max = MAX(plugin->config.max, blue);
307 gui->max_text->update(plugin->config.max);
308 gui->max_slider->update(plugin->config.max);
309 plugin->send_configure_change();
314 GammaReset::GammaReset(GammaMain *plugin, GammaWindow *gui, int x, int y)
315 : BC_GenericButton(x, y, _("Reset"))
317 this->plugin = plugin;
321 int GammaReset::handle_event()
323 plugin->config.reset();
325 plugin->send_configure_change();