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,
44 this->client = client;
47 ColorBalanceWindow::~ColorBalanceWindow()
51 void ColorBalanceWindow::create_objects()
54 add_tool(new BC_Title(x, y, _("Color Balance")));
56 add_tool(new BC_Title(x, y, _("Cyan")));
57 add_tool(cyan = new ColorBalanceSlider(client, &(client->config.cyan), x + 70, y));
58 add_tool(new BC_Title(x + 270, y, _("Red")));
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 + 270, y, _("Green")));
64 add_tool(new BC_Title(x, y, _("Yellow")));
65 add_tool(yellow = new ColorBalanceSlider(client, &(client->config.yellow), x + 70, y));
66 add_tool(new BC_Title(x + 270, y, _("Blue")));
68 add_tool(preserve = new ColorBalancePreserve(client, x + 70, y));
69 y += preserve->get_h() + 10;
70 add_tool(lock_params = new ColorBalanceLock(client, x + 70, y));
71 y += lock_params->get_h() + 10;
72 add_tool(new ColorBalanceWhite(client, this, x, y));
73 y += lock_params->get_h() + 10;
74 add_tool(new ColorBalanceReset(client, this, x, y));
80 void ColorBalanceWindow::update()
82 cyan->update((int64_t)client->config.cyan);
83 magenta->update((int64_t)client->config.magenta);
84 yellow->update((int64_t)client->config.yellow);
88 ColorBalanceSlider::ColorBalanceSlider(ColorBalanceMain *client,
89 float *output, int x, int y)
99 this->client = client;
100 this->output = output;
104 ColorBalanceSlider::~ColorBalanceSlider()
108 int ColorBalanceSlider::handle_event()
110 float difference = get_value() - *output;
111 *output = get_value();
112 client->synchronize_params(this, difference);
113 client->send_configure_change();
117 char* ColorBalanceSlider::get_caption()
119 float fraction = client->calculate_transfer(*output);
120 sprintf(string, "%0.4f", fraction);
127 ColorBalancePreserve::ColorBalancePreserve(ColorBalanceMain *client, int x, int y)
130 client->config.preserve,
131 _("Preserve luminosity"))
133 this->client = client;
135 ColorBalancePreserve::~ColorBalancePreserve()
139 int ColorBalancePreserve::handle_event()
141 client->config.preserve = get_value();
142 client->send_configure_change();
146 ColorBalanceLock::ColorBalanceLock(ColorBalanceMain *client, int x, int y)
149 client->config.lock_params,
150 _("Lock parameters"))
152 this->client = client;
154 ColorBalanceLock::~ColorBalanceLock()
158 int ColorBalanceLock::handle_event()
160 client->config.lock_params = get_value();
161 client->send_configure_change();
166 ColorBalanceWhite::ColorBalanceWhite(ColorBalanceMain *plugin,
167 ColorBalanceWindow *gui,
170 : BC_GenericButton(x, y, _("White balance"))
172 this->plugin = plugin;
176 int ColorBalanceWhite::handle_event()
178 // Get colorpicker value
179 float red = plugin->get_red();
180 float green = plugin->get_green();
181 float blue = plugin->get_blue();
182 // // Get maximum value
183 // float max = MAX(red, green);
184 // max = MAX(max, blue);
185 // // Get factors required to normalize other values to maximum
186 // float r_factor = max / red;
187 // float g_factor = max / green;
188 // float b_factor = max / blue;
189 // Get minimum value. Can't use maximum because the sliders run out of room.
190 float min = MIN(red, green);
191 min = MIN(min, blue);
192 // Get factors required to normalize other values to minimum
193 float r_factor = min / red;
194 float g_factor = min / green;
195 float b_factor = min / blue;
197 // Try normalizing to green like others do it
198 r_factor = green / red;
200 b_factor = green / blue;
201 // Convert factors to slider values
202 plugin->config.cyan = plugin->calculate_slider(r_factor);
203 plugin->config.magenta = plugin->calculate_slider(g_factor);
204 plugin->config.yellow = plugin->calculate_slider(b_factor);
207 plugin->send_configure_change();
212 ColorBalanceReset::ColorBalanceReset(ColorBalanceMain *plugin,
213 ColorBalanceWindow *gui,
216 : BC_GenericButton(x, y, _("Reset"))
218 this->plugin = plugin;
222 int ColorBalanceReset::handle_event()
224 plugin->config.cyan = 0;
225 plugin->config.magenta = 0;
226 plugin->config.yellow = 0;
228 plugin->send_configure_change();