r1009: Move the dependencies to newer package names
[cinelerra_cv/mob.git] / plugins / colorbalance / colorbalancewindow.C
blob23cde55b6823518e791a0d9e3f4e39ff48a5f458
1 #include "bcdisplayinfo.h"
2 #include "colorbalancewindow.h"
3 #include "language.h"
9 PLUGIN_THREAD_OBJECT(ColorBalanceMain, ColorBalanceThread, ColorBalanceWindow)
16 ColorBalanceWindow::ColorBalanceWindow(ColorBalanceMain *client, int x, int y)
17  : BC_Window(client->gui_string, x,
18         y,
19         330, 
20         250, 
21         330, 
22         250, 
23         0, 
24         0)
25
26         this->client = client; 
29 ColorBalanceWindow::~ColorBalanceWindow()
33 int ColorBalanceWindow::create_objects()
35         int x = 10, y = 10;
36         add_tool(new BC_Title(x, y, _("Color Balance")));
37         y += 25;
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")));
41         y += 25;
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")));
45         y += 25;
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")));
49         y += 25;
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));
58         show_window();
59         flush();
60         return 0;
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)
74  : BC_ISlider(x, 
75         y, 
76         0, 
77         200, 
78         200,
79         -1000, 
80         1000, 
81         (int)*output)
83         this->client = client;
84         this->output = output;
85     old_value = *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();
98         return 1;
101 char* ColorBalanceSlider::get_caption()
103         float fraction = client->calculate_transfer(*output);
104         sprintf(string, "%0.4f", fraction);
105         return string;
111 ColorBalancePreserve::ColorBalancePreserve(ColorBalanceMain *client, int x, int y)
112  : BC_CheckBox(x, 
113         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();
127         return 1;
130 ColorBalanceLock::ColorBalanceLock(ColorBalanceMain *client, int x, int y)
131  : BC_CheckBox(x, 
132         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();
146         return 1;
150 ColorBalanceWhite::ColorBalanceWhite(ColorBalanceMain *plugin, 
151         ColorBalanceWindow *gui,
152         int x, 
153         int y)
154  : BC_GenericButton(x, y, _("White balance"))
156         this->plugin = plugin;
157         this->gui = gui;
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;
183         g_factor = 1.0;
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);
189         gui->update();
191         plugin->send_configure_change();
192         return 1;
196 ColorBalanceReset::ColorBalanceReset(ColorBalanceMain *plugin, 
197         ColorBalanceWindow *gui, 
198         int x, 
199         int y)
200  : BC_GenericButton(x, y, _("Reset"))
202         this->plugin = plugin;
203         this->gui = gui;
206 int ColorBalanceReset::handle_event()
208         plugin->config.cyan = 0;
209         plugin->config.magenta = 0;
210         plugin->config.yellow = 0;
211         gui->update();
212         plugin->send_configure_change();
213         return 1;