263f15ea39e50dfd44326b012a11581502682854
[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
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, y, 0, 200, 200, -1000, 1000, (int)*output)
91 {
92         this->client = client;
93         this->output = output;
94         old_value = *output;
95 }
96
97 ColorBalanceSlider::~ColorBalanceSlider()
98 {
99 }
100
101 int ColorBalanceSlider::handle_event()
102 {
103         float difference = get_value() - *output;
104         *output = get_value();
105         client->synchronize_params(this, difference);
106         client->send_configure_change();
107         return 1;
108 }
109
110 char* ColorBalanceSlider::get_caption()
111 {
112         float fraction = client->calculate_transfer(*output);
113         sprintf(string, "%0.4f", fraction);
114         return string;
115 }
116
117
118
119
120 ColorBalancePreserve::ColorBalancePreserve(ColorBalanceMain *client, int x, int y)
121  : BC_CheckBox(x,
122         y,
123         client->config.preserve,
124         _("Preserve luminosity"))
125 {
126         this->client = client;
127 }
128 ColorBalancePreserve::~ColorBalancePreserve()
129 {
130 }
131
132 int ColorBalancePreserve::handle_event()
133 {
134         client->config.preserve = get_value();
135         client->send_configure_change();
136         return 1;
137 }
138
139 ColorBalanceLock::ColorBalanceLock(ColorBalanceMain *client, int x, int y)
140  : BC_CheckBox(x,
141         y,
142         client->config.lock_params,
143         _("Lock parameters"))
144 {
145         this->client = client;
146 }
147 ColorBalanceLock::~ColorBalanceLock()
148 {
149 }
150
151 int ColorBalanceLock::handle_event()
152 {
153         client->config.lock_params = get_value();
154         client->send_configure_change();
155         return 1;
156 }
157
158
159 ColorBalanceWhite::ColorBalanceWhite(ColorBalanceMain *plugin,
160         ColorBalanceWindow *gui,
161         int x,
162         int y)
163  : BC_GenericButton(x, y, _("White balance"))
164 {
165         this->plugin = plugin;
166         this->gui = gui;
167 }
168
169 int ColorBalanceWhite::handle_event()
170 {
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;
189
190 // Try normalizing to green like others do it
191         r_factor = green / red;
192         g_factor = 1.0;
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);
198         gui->update();
199
200         plugin->send_configure_change();
201         return 1;
202 }
203
204
205 ColorBalanceReset::ColorBalanceReset(ColorBalanceMain *plugin,
206         ColorBalanceWindow *gui,
207         int x,
208         int y)
209  : BC_GenericButton(x, y, _("Reset"))
210 {
211         this->plugin = plugin;
212         this->gui = gui;
213 }
214
215 int ColorBalanceReset::handle_event()
216 {
217         plugin->config.cyan = 0;
218         plugin->config.magenta = 0;
219         plugin->config.yellow = 0;
220         gui->update();
221         plugin->send_configure_change();
222         return 1;
223 }
224
225