1 #include "bcdisplayinfo.h"
2 #include "colorbalancewindow.h"
9 PLUGIN_THREAD_OBJECT(ColorBalanceMain, ColorBalanceThread, ColorBalanceWindow)
16 ColorBalanceWindow::ColorBalanceWindow(ColorBalanceMain *client, int x, int y)
17 : BC_Window(client->gui_string, x,
26 this->client = client;
29 ColorBalanceWindow::~ColorBalanceWindow()
33 int ColorBalanceWindow::create_objects()
36 add_tool(new BC_Title(x, y, _("Color Balance")));
38 add_tool(new BC_Title(x, y, _("Cyan")));
39 add_tool(cyan = new ColorBalanceSlider(client, &(client->config.cyan), x + 70, y));
40 add_tool(new BC_Title(x + 270, y, _("Red")));
42 add_tool(new BC_Title(x, y, _("Magenta")));
43 add_tool(magenta = new ColorBalanceSlider(client, &(client->config.magenta), x + 70, y));
44 add_tool(new BC_Title(x + 270, y, _("Green")));
46 add_tool(new BC_Title(x, y, _("Yellow")));
47 add_tool(yellow = new ColorBalanceSlider(client, &(client->config.yellow), x + 70, y));
48 add_tool(new BC_Title(x + 270, y, _("Blue")));
50 add_tool(preserve = new ColorBalancePreserve(client, x + 70, y));
51 y += preserve->get_h() + 10;
52 add_tool(lock_params = new ColorBalanceLock(client, x + 70, y));
53 y += lock_params->get_h() + 10;
54 add_tool(new ColorBalanceWhite(client, this, x, y));
55 y += lock_params->get_h() + 10;
56 add_tool(new ColorBalanceReset(client, this, x, y));
63 void ColorBalanceWindow::update()
65 cyan->update((int64_t)client->config.cyan);
66 magenta->update((int64_t)client->config.magenta);
67 yellow->update((int64_t)client->config.yellow);
70 WINDOW_CLOSE_EVENT(ColorBalanceWindow)
72 ColorBalanceSlider::ColorBalanceSlider(ColorBalanceMain *client,
73 float *output, int x, int y)
83 this->client = client;
84 this->output = output;
88 ColorBalanceSlider::~ColorBalanceSlider()
92 int ColorBalanceSlider::handle_event()
94 float difference = get_value() - *output;
95 *output = get_value();
96 client->synchronize_params(this, difference);
97 client->send_configure_change();
101 char* ColorBalanceSlider::get_caption()
103 float fraction = client->calculate_transfer(*output);
104 sprintf(string, "%0.4f", fraction);
111 ColorBalancePreserve::ColorBalancePreserve(ColorBalanceMain *client, int x, int y)
114 client->config.preserve,
115 _("Preserve luminosity"))
117 this->client = client;
119 ColorBalancePreserve::~ColorBalancePreserve()
123 int ColorBalancePreserve::handle_event()
125 client->config.preserve = get_value();
126 client->send_configure_change();
130 ColorBalanceLock::ColorBalanceLock(ColorBalanceMain *client, int x, int y)
133 client->config.lock_params,
134 _("Lock parameters"))
136 this->client = client;
138 ColorBalanceLock::~ColorBalanceLock()
142 int ColorBalanceLock::handle_event()
144 client->config.lock_params = get_value();
145 client->send_configure_change();
150 ColorBalanceWhite::ColorBalanceWhite(ColorBalanceMain *plugin,
151 ColorBalanceWindow *gui,
154 : BC_GenericButton(x, y, _("White balance"))
156 this->plugin = plugin;
160 int ColorBalanceWhite::handle_event()
162 // Get colorpicker value
163 float red = plugin->get_red();
164 float green = plugin->get_green();
165 float blue = plugin->get_blue();
166 // // Get maximum value
167 // float max = MAX(red, green);
168 // max = MAX(max, blue);
169 // // Get factors required to normalize other values to maximum
170 // float r_factor = max / red;
171 // float g_factor = max / green;
172 // float b_factor = max / blue;
173 // Get minimum value. Can't use maximum because the sliders run out of room.
174 float min = MIN(red, green);
175 min = MIN(min, blue);
176 // Get factors required to normalize other values to minimum
177 float r_factor = min / red;
178 float g_factor = min / green;
179 float b_factor = min / blue;
181 // Try normalizing to green like others do it
182 r_factor = green / red;
184 b_factor = green / blue;
185 // Convert factors to slider values
186 plugin->config.cyan = plugin->calculate_slider(r_factor);
187 plugin->config.magenta = plugin->calculate_slider(g_factor);
188 plugin->config.yellow = plugin->calculate_slider(b_factor);
191 plugin->send_configure_change();
196 ColorBalanceReset::ColorBalanceReset(ColorBalanceMain *plugin,
197 ColorBalanceWindow *gui,
200 : BC_GenericButton(x, y, _("Reset"))
202 this->plugin = plugin;
206 int ColorBalanceReset::handle_event()
208 plugin->config.cyan = 0;
209 plugin->config.magenta = 0;
210 plugin->config.yellow = 0;
212 plugin->send_configure_change();