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"
36 ColorBalanceWindow::ColorBalanceWindow(ColorBalanceMain *client)
37 : PluginClientWindow(client, 400, 210, 400, 210, 0)
39 this->client = client;
42 ColorBalanceWindow::~ColorBalanceWindow()
46 void ColorBalanceWindow::create_objects()
50 int x1 = 400 - clrBtn_w - 10; // (window_width - clrBtn_width - margin_rx)
52 add_tool(new BC_Title(x, y, _("Color Balance")));
54 add_tool(new BC_Title(x, y, _("Cyan")));
55 add_tool(cyan = new ColorBalanceSlider(client, &(client->config.cyan), x + 70, y));
56 add_tool(new BC_Title(x + 280, y, _("Red")));
57 add_subwindow(cyanClr = new ColorBalanceSliderClr(client, this, x1, y, clrBtn_w, 1));
60 add_tool(new BC_Title(x, y, _("Magenta")));
61 add_tool(magenta = new ColorBalanceSlider(client, &(client->config.magenta), x + 70, y));
62 add_tool(new BC_Title(x + 280, y, _("Green")));
63 add_subwindow(magentaClr = new ColorBalanceSliderClr(client, this, x1, y, clrBtn_w, 2));
66 add_tool(new BC_Title(x, y, _("Yellow")));
67 add_tool(yellow = new ColorBalanceSlider(client, &(client->config.yellow), x + 70, y));
68 add_tool(new BC_Title(x + 280, y, _("Blue")));
69 add_subwindow(yellowClr = new ColorBalanceSliderClr(client, this, x1, y, clrBtn_w, 3));
72 add_tool(preserve = new ColorBalancePreserve(client, x, y));
73 y += preserve->get_h() + 10;
74 add_tool(lock_params = new ColorBalanceLock(client, x, y));
76 y += lock_params->get_h() + 15;
77 add_tool(new ColorBalanceReset(client, this, x, y));
78 add_tool(new ColorBalanceWhite(client, this, int(400 / 2), y));
84 void ColorBalanceWindow::update_gui(int clear)
87 case RESET_CYAN : cyan->update((int64_t)client->config.cyan);
89 case RESET_MAGENTA : magenta->update((int64_t)client->config.magenta);
91 case RESET_YELLOW : yellow->update((int64_t)client->config.yellow);
94 case RESET_DEFAULT_SETTINGS :
96 cyan->update((int64_t)client->config.cyan);
97 magenta->update((int64_t)client->config.magenta);
98 yellow->update((int64_t)client->config.yellow);
99 preserve->update(client->config.preserve);
100 lock_params->update(client->config.lock_params);
106 ColorBalanceSlider::ColorBalanceSlider(ColorBalanceMain *client,
107 float *output, int x, int y)
108 : BC_ISlider(x, y, 0, 200, 200, -1000, 1000, (int)*output)
110 this->client = client;
111 this->output = output;
115 ColorBalanceSlider::~ColorBalanceSlider()
119 int ColorBalanceSlider::handle_event()
121 float difference = get_value() - *output;
122 *output = get_value();
123 client->synchronize_params(this, difference);
124 client->send_configure_change();
128 char* ColorBalanceSlider::get_caption()
130 float fraction = client->calculate_transfer(*output);
131 sprintf(string, "%0.4f", fraction);
138 ColorBalancePreserve::ColorBalancePreserve(ColorBalanceMain *client, int x, int y)
141 client->config.preserve,
142 _("Preserve luminosity"))
144 this->client = client;
146 ColorBalancePreserve::~ColorBalancePreserve()
150 int ColorBalancePreserve::handle_event()
152 client->config.preserve = get_value();
153 client->send_configure_change();
157 ColorBalanceLock::ColorBalanceLock(ColorBalanceMain *client, int x, int y)
160 client->config.lock_params,
161 _("Lock parameters"))
163 this->client = client;
165 ColorBalanceLock::~ColorBalanceLock()
169 int ColorBalanceLock::handle_event()
171 client->config.lock_params = get_value();
172 client->send_configure_change();
177 ColorBalanceWhite::ColorBalanceWhite(ColorBalanceMain *plugin,
178 ColorBalanceWindow *gui,
181 : BC_GenericButton(x, y, _("White balance"))
183 this->plugin = plugin;
187 int ColorBalanceWhite::handle_event()
189 // Get colorpicker value
190 float red = plugin->get_red();
191 float green = plugin->get_green();
192 float blue = plugin->get_blue();
193 // // Get maximum value
194 // float max = MAX(red, green);
195 // max = MAX(max, blue);
196 // // Get factors required to normalize other values to maximum
197 // float r_factor = max / red;
198 // float g_factor = max / green;
199 // float b_factor = max / blue;
200 // Get minimum value. Can't use maximum because the sliders run out of room.
201 float min = MIN(red, green);
202 min = MIN(min, blue);
203 // Get factors required to normalize other values to minimum
204 float r_factor = min / red;
205 float g_factor = min / green;
206 float b_factor = min / blue;
208 // Try normalizing to green like others do it
209 r_factor = green / red;
211 b_factor = green / blue;
212 // Convert factors to slider values
213 plugin->config.cyan = plugin->calculate_slider(r_factor);
214 plugin->config.magenta = plugin->calculate_slider(g_factor);
215 plugin->config.yellow = plugin->calculate_slider(b_factor);
216 gui->update_gui(RESET_DEFAULT_SETTINGS);
218 plugin->send_configure_change();
223 ColorBalanceReset::ColorBalanceReset(ColorBalanceMain *plugin,
224 ColorBalanceWindow *gui,
227 : BC_GenericButton(x, y, _("Reset"))
229 this->plugin = plugin;
233 int ColorBalanceReset::handle_event()
235 plugin->config.reset(RESET_ALL);
236 gui->update_gui(RESET_ALL);
237 plugin->send_configure_change();
242 ColorBalanceSliderClr::ColorBalanceSliderClr(ColorBalanceMain *plugin,
243 ColorBalanceWindow *gui, int x, int y, int w, int clear)
244 : BC_GenericButton(x, y, w, _("⌂"))
246 this->plugin = plugin;
250 ColorBalanceSliderClr::~ColorBalanceSliderClr()
253 int ColorBalanceSliderClr::handle_event()
255 plugin->config.reset(clear);
256 gui->update_gui(clear);
257 plugin->send_configure_change();