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 "colorbalancewindow.h"
37 ColorBalanceWindow::ColorBalanceWindow(ColorBalanceMain *client)
38 : PluginClientWindow(client, 400, 210, 400, 210, 0)
40 this->client = client;
43 ColorBalanceWindow::~ColorBalanceWindow()
47 void ColorBalanceWindow::create_objects()
51 int x1 = 400 - clrBtn_w - 10; // (window_width - clrBtn_width - margin_rx)
53 add_tool(new BC_Title(x, y, _("Color Balance")));
55 add_tool(new BC_Title(x, y, _("Cyan")));
56 add_tool(cyan = new ColorBalanceSlider(client, &(client->config.cyan), x + 70, y));
57 add_tool(new BC_Title(x + 280, y, _("Red")));
58 add_subwindow(cyanClr = new ColorBalanceSliderClr(client, this, x1, y, clrBtn_w, 1));
61 add_tool(new BC_Title(x, y, _("Magenta")));
62 add_tool(magenta = new ColorBalanceSlider(client, &(client->config.magenta), x + 70, y));
63 add_tool(new BC_Title(x + 280, y, _("Green")));
64 add_subwindow(magentaClr = new ColorBalanceSliderClr(client, this, x1, y, clrBtn_w, 2));
67 add_tool(new BC_Title(x, y, _("Yellow")));
68 add_tool(yellow = new ColorBalanceSlider(client, &(client->config.yellow), x + 70, y));
69 add_tool(new BC_Title(x + 280, y, _("Blue")));
70 add_subwindow(yellowClr = new ColorBalanceSliderClr(client, this, x1, y, clrBtn_w, 3));
73 add_tool(preserve = new ColorBalancePreserve(client, x, y));
74 y += preserve->get_h() + 10;
75 add_tool(lock_params = new ColorBalanceLock(client, x, y));
77 y += lock_params->get_h() + 15;
78 add_tool(new ColorBalanceReset(client, this, x, y));
79 add_tool(new ColorBalanceWhite(client, this, int(400 / 2), y));
85 void ColorBalanceWindow::update_gui(int clear)
88 case RESET_CYAN : cyan->update((int64_t)client->config.cyan);
90 case RESET_MAGENTA : magenta->update((int64_t)client->config.magenta);
92 case RESET_YELLOW : yellow->update((int64_t)client->config.yellow);
95 case RESET_DEFAULT_SETTINGS :
97 cyan->update((int64_t)client->config.cyan);
98 magenta->update((int64_t)client->config.magenta);
99 yellow->update((int64_t)client->config.yellow);
100 preserve->update(client->config.preserve);
101 lock_params->update(client->config.lock_params);
107 ColorBalanceSlider::ColorBalanceSlider(ColorBalanceMain *client,
108 float *output, int x, int y)
109 : BC_ISlider(x, y, 0, 200, 200, -1000, 1000, (int)*output)
111 this->client = client;
112 this->output = output;
116 ColorBalanceSlider::~ColorBalanceSlider()
120 int ColorBalanceSlider::handle_event()
122 float difference = get_value() - *output;
123 *output = get_value();
124 client->synchronize_params(this, difference);
125 client->send_configure_change();
129 char* ColorBalanceSlider::get_caption()
131 float fraction = client->calculate_transfer(*output);
132 sprintf(string, "%0.4f", fraction);
139 ColorBalancePreserve::ColorBalancePreserve(ColorBalanceMain *client, int x, int y)
142 client->config.preserve,
143 _("Preserve luminosity"))
145 this->client = client;
147 ColorBalancePreserve::~ColorBalancePreserve()
151 int ColorBalancePreserve::handle_event()
153 client->config.preserve = get_value();
154 client->send_configure_change();
158 ColorBalanceLock::ColorBalanceLock(ColorBalanceMain *client, int x, int y)
161 client->config.lock_params,
162 _("Lock parameters"))
164 this->client = client;
166 ColorBalanceLock::~ColorBalanceLock()
170 int ColorBalanceLock::handle_event()
172 client->config.lock_params = get_value();
173 client->send_configure_change();
178 ColorBalanceWhite::ColorBalanceWhite(ColorBalanceMain *plugin,
179 ColorBalanceWindow *gui,
182 : BC_GenericButton(x, y, _("White balance"))
184 this->plugin = plugin;
188 int ColorBalanceWhite::handle_event()
190 // Get colorpicker value
191 float red = plugin->get_red();
192 float green = plugin->get_green();
193 float blue = plugin->get_blue();
194 // // Get maximum value
195 // float max = MAX(red, green);
196 // max = MAX(max, blue);
197 // // Get factors required to normalize other values to maximum
198 // float r_factor = max / red;
199 // float g_factor = max / green;
200 // float b_factor = max / blue;
201 // Get minimum value. Can't use maximum because the sliders run out of room.
202 float min = MIN(red, green);
203 min = MIN(min, blue);
204 // Get factors required to normalize other values to minimum
205 float r_factor = min / red;
206 float g_factor = min / green;
207 float b_factor = min / blue;
209 // Try normalizing to green like others do it
210 r_factor = green / red;
212 b_factor = green / blue;
213 // Convert factors to slider values
214 plugin->config.cyan = plugin->calculate_slider(r_factor);
215 plugin->config.magenta = plugin->calculate_slider(g_factor);
216 plugin->config.yellow = plugin->calculate_slider(b_factor);
217 gui->update_gui(RESET_DEFAULT_SETTINGS);
219 plugin->send_configure_change();
224 ColorBalanceReset::ColorBalanceReset(ColorBalanceMain *plugin,
225 ColorBalanceWindow *gui,
228 : BC_GenericButton(x, y, _("Reset"))
230 this->plugin = plugin;
234 int ColorBalanceReset::handle_event()
236 plugin->config.reset(RESET_ALL);
237 gui->update_gui(RESET_ALL);
238 plugin->send_configure_change();
243 ColorBalanceSliderClr::ColorBalanceSliderClr(ColorBalanceMain *plugin,
244 ColorBalanceWindow *gui, int x, int y, int w, int clear)
245 : BC_Button(x, y, w, plugin->get_theme()->get_image_set("reset_button"))
247 this->plugin = plugin;
251 ColorBalanceSliderClr::~ColorBalanceSliderClr()
254 int ColorBalanceSliderClr::handle_event()
256 plugin->config.reset(clear);
257 gui->update_gui(clear);
258 plugin->send_configure_change();