remove whitespace at eol
[goodguy/history.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
26
27
28
29
30
31
32
33
34
35
36 ColorBalanceWindow::ColorBalanceWindow(ColorBalanceMain *client)
37  : PluginClientWindow(client,
38         330,
39         250,
40         330,
41         250,
42         0)
43 {
44         this->client = client;
45 }
46
47 ColorBalanceWindow::~ColorBalanceWindow()
48 {
49 }
50
51 void ColorBalanceWindow::create_objects()
52 {
53         int x = 10, y = 10;
54         add_tool(new BC_Title(x, y, _("Color Balance")));
55         y += 25;
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")));
59         y += 25;
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")));
63         y += 25;
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")));
67         y += 25;
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));
75
76         show_window();
77         flush();
78 }
79
80 void ColorBalanceWindow::update()
81 {
82         cyan->update((int64_t)client->config.cyan);
83         magenta->update((int64_t)client->config.magenta);
84         yellow->update((int64_t)client->config.yellow);
85 }
86
87
88 ColorBalanceSlider::ColorBalanceSlider(ColorBalanceMain *client,
89         float *output, int x, int y)
90  : BC_ISlider(x,
91         y,
92         0,
93         200,
94         200,
95         -1000,
96         1000,
97         (int)*output)
98 {
99         this->client = client;
100         this->output = output;
101     old_value = *output;
102 }
103
104 ColorBalanceSlider::~ColorBalanceSlider()
105 {
106 }
107
108 int ColorBalanceSlider::handle_event()
109 {
110         float difference = get_value() - *output;
111         *output = get_value();
112     client->synchronize_params(this, difference);
113         client->send_configure_change();
114         return 1;
115 }
116
117 char* ColorBalanceSlider::get_caption()
118 {
119         float fraction = client->calculate_transfer(*output);
120         sprintf(string, "%0.4f", fraction);
121         return string;
122 }
123
124
125
126
127 ColorBalancePreserve::ColorBalancePreserve(ColorBalanceMain *client, int x, int y)
128  : BC_CheckBox(x,
129         y,
130         client->config.preserve,
131         _("Preserve luminosity"))
132 {
133         this->client = client;
134 }
135 ColorBalancePreserve::~ColorBalancePreserve()
136 {
137 }
138
139 int ColorBalancePreserve::handle_event()
140 {
141         client->config.preserve = get_value();
142         client->send_configure_change();
143         return 1;
144 }
145
146 ColorBalanceLock::ColorBalanceLock(ColorBalanceMain *client, int x, int y)
147  : BC_CheckBox(x,
148         y,
149         client->config.lock_params,
150         _("Lock parameters"))
151 {
152         this->client = client;
153 }
154 ColorBalanceLock::~ColorBalanceLock()
155 {
156 }
157
158 int ColorBalanceLock::handle_event()
159 {
160         client->config.lock_params = get_value();
161         client->send_configure_change();
162         return 1;
163 }
164
165
166 ColorBalanceWhite::ColorBalanceWhite(ColorBalanceMain *plugin,
167         ColorBalanceWindow *gui,
168         int x,
169         int y)
170  : BC_GenericButton(x, y, _("White balance"))
171 {
172         this->plugin = plugin;
173         this->gui = gui;
174 }
175
176 int ColorBalanceWhite::handle_event()
177 {
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;
196
197 // Try normalizing to green like others do it
198         r_factor = green / red;
199         g_factor = 1.0;
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);
205         gui->update();
206
207         plugin->send_configure_change();
208         return 1;
209 }
210
211
212 ColorBalanceReset::ColorBalanceReset(ColorBalanceMain *plugin,
213         ColorBalanceWindow *gui,
214         int x,
215         int y)
216  : BC_GenericButton(x, y, _("Reset"))
217 {
218         this->plugin = plugin;
219         this->gui = gui;
220 }
221
222 int ColorBalanceReset::handle_event()
223 {
224         plugin->config.cyan = 0;
225         plugin->config.magenta = 0;
226         plugin->config.yellow = 0;
227         gui->update();
228         plugin->send_configure_change();
229         return 1;
230 }
231
232