Credit Andrew - fix vorbis audio which was scratchy and ensure aging plugin does...
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / colorbalance / colorbalancewindow.C
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 Adam Williams <broadcast at earthling dot net>
5  *
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.
10  *
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.
15  *
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
19  *
20  */
21
22 #include "bcdisplayinfo.h"
23 #include "colorbalancewindow.h"
24 #include "language.h"
25 #include "theme.h"
26
27
28
29
30
31
32
33
34
35
36
37 ColorBalanceWindow::ColorBalanceWindow(ColorBalanceMain *client)
38  : PluginClientWindow(client, xS(400), yS(210), xS(400), yS(210), 0)
39 {
40         this->client = client;
41 }
42
43 ColorBalanceWindow::~ColorBalanceWindow()
44 {
45 }
46
47 void ColorBalanceWindow::create_objects()
48 {
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)
54
55         add_tool(new BC_Title(x, y, _("Color Balance")));
56         y += ys25;
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));
61
62         y += ys25;
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));
67
68         y += ys25;
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));
73
74         y += ys25;
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));
78
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));
82
83         show_window();
84         flush();
85 }
86
87 void ColorBalanceWindow::update_gui(int clear)
88 {
89         switch(clear) {
90                 case RESET_CYAN : cyan->update((int64_t)client->config.cyan);
91                         break;
92                 case RESET_MAGENTA : magenta->update((int64_t)client->config.magenta);
93                         break;
94                 case RESET_YELLOW : yellow->update((int64_t)client->config.yellow);
95                         break;
96                 case RESET_ALL :
97                 case RESET_DEFAULT_SETTINGS :
98                 default:
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);
104                         break;
105         }
106 }
107
108
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)
112 {
113         this->client = client;
114         this->output = output;
115         old_value = *output;
116 }
117
118 ColorBalanceSlider::~ColorBalanceSlider()
119 {
120 }
121
122 int ColorBalanceSlider::handle_event()
123 {
124         float difference = get_value() - *output;
125         *output = get_value();
126         client->synchronize_params(this, difference);
127         client->send_configure_change();
128         return 1;
129 }
130
131 char* ColorBalanceSlider::get_caption()
132 {
133         float fraction = client->calculate_transfer(*output);
134         sprintf(string, "%0.4f", fraction);
135         return string;
136 }
137
138
139
140
141 ColorBalancePreserve::ColorBalancePreserve(ColorBalanceMain *client, int x, int y)
142  : BC_CheckBox(x,
143         y,
144         client->config.preserve,
145         _("Preserve luminosity"))
146 {
147         this->client = client;
148 }
149 ColorBalancePreserve::~ColorBalancePreserve()
150 {
151 }
152
153 int ColorBalancePreserve::handle_event()
154 {
155         client->config.preserve = get_value();
156         client->send_configure_change();
157         return 1;
158 }
159
160 ColorBalanceLock::ColorBalanceLock(ColorBalanceMain *client, int x, int y)
161  : BC_CheckBox(x,
162         y,
163         client->config.lock_params,
164         _("Lock parameters"))
165 {
166         this->client = client;
167 }
168 ColorBalanceLock::~ColorBalanceLock()
169 {
170 }
171
172 int ColorBalanceLock::handle_event()
173 {
174         client->config.lock_params = get_value();
175         client->send_configure_change();
176         return 1;
177 }
178
179
180 ColorBalanceWhite::ColorBalanceWhite(ColorBalanceMain *plugin,
181         ColorBalanceWindow *gui,
182         int x,
183         int y)
184  : BC_GenericButton(x, y, _("White balance"))
185 {
186         this->plugin = plugin;
187         this->gui = gui;
188 }
189
190 int ColorBalanceWhite::handle_event()
191 {
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;
210
211 // Try normalizing to green like others do it
212         r_factor = green / red;
213         g_factor = 1.0;
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);
220
221         plugin->send_configure_change();
222         return 1;
223 }
224
225
226 ColorBalanceReset::ColorBalanceReset(ColorBalanceMain *plugin,
227         ColorBalanceWindow *gui,
228         int x,
229         int y)
230  : BC_GenericButton(x, y, _("Reset"))
231 {
232         this->plugin = plugin;
233         this->gui = gui;
234 }
235
236 int ColorBalanceReset::handle_event()
237 {
238         plugin->config.reset(RESET_ALL);
239         gui->update_gui(RESET_ALL);
240         plugin->send_configure_change();
241         return 1;
242 }
243
244
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"))
248 {
249         this->plugin = plugin;
250         this->gui = gui;
251         this->clear = clear;
252 }
253 ColorBalanceSliderClr::~ColorBalanceSliderClr()
254 {
255 }
256 int ColorBalanceSliderClr::handle_event()
257 {
258         plugin->config.reset(clear);
259         gui->update_gui(clear);
260         plugin->send_configure_change();
261         return 1;
262 }
263