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, xS(400), yS(210), xS(400), yS(210), 0)
40 this->client = client;
43 ColorBalanceWindow::~ColorBalanceWindow()
47 void ColorBalanceWindow::create_objects()
49 int xs10 = xS(10), xs70 = xS(70), xs280 = xS(280), xs400 = xS(400);
50 int ys10 = yS(10), ys15 = yS(15), ys25 = yS(25);
51 int x = xs10, y = ys10;
52 int clrBtn_w = xS(50);
53 int x1 = xs400 - clrBtn_w - xs10; // (window_width - clrBtn_width - margin_rx)
55 add_tool(new BC_Title(x, y, _("Color Balance")));
57 add_tool(new BC_Title(x, y, _("Cyan")));
58 add_tool(cyan = new ColorBalanceSlider(client, &(client->config.cyan), x + xs70, y));
59 add_tool(new BC_Title(x + xs280, y, _("Red")));
60 add_subwindow(cyanClr = new ColorBalanceSliderClr(client, this, x1, y, clrBtn_w, 1));
63 add_tool(new BC_Title(x, y, _("Magenta")));
64 add_tool(magenta = new ColorBalanceSlider(client, &(client->config.magenta), x + xs70, y));
65 add_tool(new BC_Title(x + xs280, y, _("Green")));
66 add_subwindow(magentaClr = new ColorBalanceSliderClr(client, this, x1, y, clrBtn_w, 2));
69 add_tool(new BC_Title(x, y, _("Yellow")));
70 add_tool(yellow = new ColorBalanceSlider(client, &(client->config.yellow), x + xs70, y));
71 add_tool(new BC_Title(x + xs280, y, _("Blue")));
72 add_subwindow(yellowClr = new ColorBalanceSliderClr(client, this, x1, y, clrBtn_w, 3));
75 add_tool(preserve = new ColorBalancePreserve(client, x, y));
76 y += preserve->get_h() + ys10;
77 add_tool(lock_params = new ColorBalanceLock(client, x, y));
79 y += lock_params->get_h() + ys15;
80 add_tool(new ColorBalanceReset(client, this, x, y));
81 add_tool(new ColorBalanceWhite(client, this, int(xS(400) / 2), y));
87 void ColorBalanceWindow::update_gui(int clear)
90 case RESET_CYAN : cyan->update((int64_t)client->config.cyan);
92 case RESET_MAGENTA : magenta->update((int64_t)client->config.magenta);
94 case RESET_YELLOW : yellow->update((int64_t)client->config.yellow);
97 case RESET_DEFAULT_SETTINGS :
99 cyan->update((int64_t)client->config.cyan);
100 magenta->update((int64_t)client->config.magenta);
101 yellow->update((int64_t)client->config.yellow);
102 preserve->update(client->config.preserve);
103 lock_params->update(client->config.lock_params);
109 ColorBalanceSlider::ColorBalanceSlider(ColorBalanceMain *client,
110 float *output, int x, int y)
111 : BC_ISlider(x, y, 0, xS(200), yS(200), -1000, 1000, (int)*output)
113 this->client = client;
114 this->output = output;
118 ColorBalanceSlider::~ColorBalanceSlider()
122 int ColorBalanceSlider::handle_event()
124 float difference = get_value() - *output;
125 *output = get_value();
126 client->synchronize_params(this, difference);
127 client->send_configure_change();
131 char* ColorBalanceSlider::get_caption()
133 float fraction = client->calculate_transfer(*output);
134 sprintf(string, "%0.4f", fraction);
141 ColorBalancePreserve::ColorBalancePreserve(ColorBalanceMain *client, int x, int y)
144 client->config.preserve,
145 _("Preserve luminosity"))
147 this->client = client;
149 ColorBalancePreserve::~ColorBalancePreserve()
153 int ColorBalancePreserve::handle_event()
155 client->config.preserve = get_value();
156 client->send_configure_change();
160 ColorBalanceLock::ColorBalanceLock(ColorBalanceMain *client, int x, int y)
163 client->config.lock_params,
164 _("Lock parameters"))
166 this->client = client;
168 ColorBalanceLock::~ColorBalanceLock()
172 int ColorBalanceLock::handle_event()
174 client->config.lock_params = get_value();
175 client->send_configure_change();
180 ColorBalanceWhite::ColorBalanceWhite(ColorBalanceMain *plugin,
181 ColorBalanceWindow *gui,
184 : BC_GenericButton(x, y, _("White balance"))
186 this->plugin = plugin;
190 int ColorBalanceWhite::handle_event()
192 // Get colorpicker value
193 float red = plugin->get_red();
194 float green = plugin->get_green();
195 float blue = plugin->get_blue();
196 // // Get maximum value
197 // float max = MAX(red, green);
198 // max = MAX(max, blue);
199 // // Get factors required to normalize other values to maximum
200 // float r_factor = max / red;
201 // float g_factor = max / green;
202 // float b_factor = max / blue;
203 // Get minimum value. Can't use maximum because the sliders run out of room.
204 float min = MIN(red, green);
205 min = MIN(min, blue);
206 // Get factors required to normalize other values to minimum
207 float r_factor = min / red;
208 float g_factor = min / green;
209 float b_factor = min / blue;
211 // Try normalizing to green like others do it
212 r_factor = green / red;
214 b_factor = green / blue;
215 // Convert factors to slider values
216 plugin->config.cyan = plugin->calculate_slider(r_factor);
217 plugin->config.magenta = plugin->calculate_slider(g_factor);
218 plugin->config.yellow = plugin->calculate_slider(b_factor);
219 gui->update_gui(RESET_DEFAULT_SETTINGS);
221 plugin->send_configure_change();
226 ColorBalanceReset::ColorBalanceReset(ColorBalanceMain *plugin,
227 ColorBalanceWindow *gui,
230 : BC_GenericButton(x, y, _("Reset"))
232 this->plugin = plugin;
236 int ColorBalanceReset::handle_event()
238 plugin->config.reset(RESET_ALL);
239 gui->update_gui(RESET_ALL);
240 plugin->send_configure_change();
245 ColorBalanceSliderClr::ColorBalanceSliderClr(ColorBalanceMain *plugin,
246 ColorBalanceWindow *gui, int x, int y, int w, int clear)
247 : BC_Button(x, y, w, plugin->get_theme()->get_image_set("reset_button"))
249 this->plugin = plugin;
253 ColorBalanceSliderClr::~ColorBalanceSliderClr()
256 int ColorBalanceSliderClr::handle_event()
258 plugin->config.reset(clear);
259 gui->update_gui(clear);
260 plugin->send_configure_change();