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"
35 GammaWindow::GammaWindow(GammaMain *client)
36 : PluginClientWindow(client,
43 this->client = client;
46 void GammaWindow::create_objects()
49 add_subwindow(histogram = new BC_SubWindow(x,
54 y += histogram->get_h() + 10;
57 add_tool(title = new BC_Title(x, y, _("Maximum:")));
58 x += title->get_w() + 10;
59 add_tool(max_slider = new MaxSlider(client,
64 x += max_slider->get_w() + 10;
65 add_tool(max_text = new MaxText(client,
70 y += max_text->get_h() + 10;
72 add_tool(automatic = new GammaAuto(client, x, y));
74 y += automatic->get_h() + 10;
75 add_tool(title = new BC_Title(x, y, _("Gamma:")));
76 x += title->get_w() + 10;
77 add_tool(gamma_slider = new GammaSlider(client,
82 x += gamma_slider->get_w() + 10;
83 add_tool(gamma_text = new GammaText(client,
88 y += gamma_text->get_h() + 10;
91 add_tool(plot = new GammaPlot(client, x, y));
92 y += plot->get_h() + 10;
94 add_tool(new GammaColorPicker(client, this, x, y));
100 void GammaWindow::update()
102 max_slider->update(client->config.max);
103 max_text->update(client->config.max);
104 gamma_slider->update(client->config.gamma);
105 gamma_text->update(client->config.gamma);
106 automatic->update(client->config.automatic);
107 plot->update(client->config.plot);
111 void GammaWindow::update_histogram()
113 histogram->clear_box(0, 0, histogram->get_w(), histogram->get_h());
117 histogram->set_color(MEGREY);
118 for(int i = 0; i < histogram->get_w(); i++)
120 int x1 = (int64_t)i * HISTOGRAM_SIZE / histogram->get_w();
121 int x2 = (int64_t)(i + 1) * HISTOGRAM_SIZE / histogram->get_w();
124 for(int x = x1; x < x2; x++)
126 accum += client->engine->accum[x];
128 if(accum > max) max = accum;
130 for(int i = 0; i < histogram->get_w(); i++)
132 int x1 = (int64_t)i * HISTOGRAM_SIZE / histogram->get_w();
133 int x2 = (int64_t)(i + 1) * HISTOGRAM_SIZE / histogram->get_w();
136 for(int x = x1; x < x2; x++)
138 accum += client->engine->accum[x];
141 int h = (int)(log(accum) / log(max) * histogram->get_h());
142 histogram->draw_line(i,
145 histogram->get_h() - h);
149 histogram->set_color(GREEN);
150 int y1 = histogram->get_h();
151 float max = client->config.max * client->config.gamma;
152 float scale = 1.0 / max;
153 float gamma = client->config.gamma - 1.0;
154 for(int i = 1; i < histogram->get_w(); i++)
156 float in = (float)i / histogram->get_w();
157 float out = in * (scale * pow(in * 2 / max, gamma));
158 int y2 = (int)(histogram->get_h() - out * histogram->get_h());
159 histogram->draw_line(i - 1, y1, i, y2);
168 MaxSlider::MaxSlider(GammaMain *client,
182 this->client = client;
187 int MaxSlider::handle_event()
189 client->config.max = get_value();
190 gui->max_text->update(client->config.max);
191 gui->update_histogram();
192 client->send_configure_change();
196 MaxText::MaxText(GammaMain *client,
201 : BC_TextBox(x, y, w, 1, client->config.max)
203 this->client = client;
207 int MaxText::handle_event()
209 client->config.max = atof(get_text());
210 gui->max_slider->update(client->config.max);
211 client->send_configure_change();
215 GammaSlider::GammaSlider(GammaMain *client,
227 client->config.gamma)
229 this->client = client;
234 int GammaSlider::handle_event()
236 client->config.gamma = get_value();
237 gui->gamma_text->update(client->config.gamma);
238 gui->update_histogram();
239 client->send_configure_change();
243 GammaText::GammaText(GammaMain *client,
248 : BC_TextBox(x, y, w, 1, client->config.gamma)
250 this->client = client;
254 int GammaText::handle_event()
256 client->config.gamma = atof(get_text());
257 gui->gamma_slider->update(client->config.gamma);
258 client->send_configure_change();
262 GammaAuto::GammaAuto(GammaMain *client, int x, int y)
265 client->config.automatic,
268 this->plugin = client;
271 int GammaAuto::handle_event()
273 plugin->config.automatic = get_value();
274 plugin->send_configure_change();
279 GammaPlot::GammaPlot(GammaMain *plugin, int x, int y)
280 : BC_CheckBox(x, y, plugin->config.plot, _("Plot histogram"))
282 this->plugin = plugin;
284 int GammaPlot::handle_event()
286 plugin->config.plot = get_value();
287 plugin->send_configure_change();
292 GammaColorPicker::GammaColorPicker(GammaMain *plugin,
296 : BC_GenericButton(x, y, _("Use Color Picker"))
298 this->plugin = plugin;
302 int GammaColorPicker::handle_event()
304 // Get colorpicker value
305 float red = plugin->get_red();
306 float green = plugin->get_green();
307 float blue = plugin->get_blue();
309 plugin->config.max = MAX(red, green);
310 plugin->config.max = MAX(plugin->config.max, blue);
311 gui->max_text->update(plugin->config.max);
312 gui->max_slider->update(plugin->config.max);
313 plugin->send_configure_change();