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)
90 : BC_ISlider(x, y, 0, 200, 200, -1000, 1000, (int)*output)
92 this->client = client;
93 this->output = output;
97 ColorBalanceSlider::~ColorBalanceSlider()
101 int ColorBalanceSlider::handle_event()
103 float difference = get_value() - *output;
104 *output = get_value();
105 client->synchronize_params(this, difference);
106 client->send_configure_change();
110 char* ColorBalanceSlider::get_caption()
112 float fraction = client->calculate_transfer(*output);
113 sprintf(string, "%0.4f", fraction);
120 ColorBalancePreserve::ColorBalancePreserve(ColorBalanceMain *client, int x, int y)
123 client->config.preserve,
124 _("Preserve luminosity"))
126 this->client = client;
128 ColorBalancePreserve::~ColorBalancePreserve()
132 int ColorBalancePreserve::handle_event()
134 client->config.preserve = get_value();
135 client->send_configure_change();
139 ColorBalanceLock::ColorBalanceLock(ColorBalanceMain *client, int x, int y)
142 client->config.lock_params,
143 _("Lock parameters"))
145 this->client = client;
147 ColorBalanceLock::~ColorBalanceLock()
151 int ColorBalanceLock::handle_event()
153 client->config.lock_params = get_value();
154 client->send_configure_change();
159 ColorBalanceWhite::ColorBalanceWhite(ColorBalanceMain *plugin,
160 ColorBalanceWindow *gui,
163 : BC_GenericButton(x, y, _("White balance"))
165 this->plugin = plugin;
169 int ColorBalanceWhite::handle_event()
171 // Get colorpicker value
172 float red = plugin->get_red();
173 float green = plugin->get_green();
174 float blue = plugin->get_blue();
175 // // Get maximum value
176 // float max = MAX(red, green);
177 // max = MAX(max, blue);
178 // // Get factors required to normalize other values to maximum
179 // float r_factor = max / red;
180 // float g_factor = max / green;
181 // float b_factor = max / blue;
182 // Get minimum value. Can't use maximum because the sliders run out of room.
183 float min = MIN(red, green);
184 min = MIN(min, blue);
185 // Get factors required to normalize other values to minimum
186 float r_factor = min / red;
187 float g_factor = min / green;
188 float b_factor = min / blue;
190 // Try normalizing to green like others do it
191 r_factor = green / red;
193 b_factor = green / blue;
194 // Convert factors to slider values
195 plugin->config.cyan = plugin->calculate_slider(r_factor);
196 plugin->config.magenta = plugin->calculate_slider(g_factor);
197 plugin->config.yellow = plugin->calculate_slider(b_factor);
200 plugin->send_configure_change();
205 ColorBalanceReset::ColorBalanceReset(ColorBalanceMain *plugin,
206 ColorBalanceWindow *gui,
209 : BC_GenericButton(x, y, _("Reset"))
211 this->plugin = plugin;
215 int ColorBalanceReset::handle_event()
217 plugin->config.cyan = 0;
218 plugin->config.magenta = 0;
219 plugin->config.yellow = 0;
221 plugin->send_configure_change();