r932: When playing update clocks only, not all zoombar widgets
[cinelerra_cv/mob.git] / plugins / gamma / gammawindow.C
blobc99dcd8a100f128e39c85f85acae2e5551c5efd0
1 #include "bcdisplayinfo.h"
2 #include "gammawindow.h"
3 #include "language.h"
9 PLUGIN_THREAD_OBJECT(GammaMain, GammaThread, GammaWindow)
16 GammaWindow::GammaWindow(GammaMain *client, int x, int y)
17  : BC_Window(client->gui_string, x,
18         y,
19         400, 
20         350, 
21         400, 
22         350, 
23         0, 
24         0)
25
26         this->client = client; 
29 int GammaWindow::create_objects()
31         int x = 10, y = 10;
32         add_subwindow(histogram = new BC_SubWindow(x, 
33                 y, 
34                 get_w() - x * 2, 
35                 get_h() - 150, 
36                 WHITE));
37         y += histogram->get_h() + 10;
39         BC_Title *title;
40         add_tool(title = new BC_Title(x, y, _("Maximum:")));
41         x += title->get_w() + 10;
42         add_tool(max_slider = new MaxSlider(client, 
43                 this, 
44                 x, 
45                 y, 
46                 190));
47         x += max_slider->get_w() + 10;
48         add_tool(max_text = new MaxText(client,
49                 this,
50                 x,
51                 y,
52                 100));
53         y += max_text->get_h() + 10;
54         x = 10;
55         add_tool(automatic = new GammaAuto(client, x, y));
57         y += automatic->get_h() + 10;
58         add_tool(title = new BC_Title(x, y, _("Gamma:")));
59         x += title->get_w() + 10;
60         add_tool(gamma_slider = new GammaSlider(client, 
61                 this, 
62                 x, 
63                 y, 
64                 190));
65         x += gamma_slider->get_w() + 10;
66         add_tool(gamma_text = new GammaText(client,
67                 this,
68                 x,
69                 y,
70                 100));
71         y += gamma_text->get_h() + 10;
72         x = 10;
74         add_tool(plot = new GammaPlot(client, x, y));
75         y += plot->get_h() + 10;
77         add_tool(new GammaColorPicker(client, this, x, y));
79         show_window();
80         flush();
81         return 0;
84 void GammaWindow::update()
86         max_slider->update(client->config.max);
87         max_text->update(client->config.max);
88         gamma_slider->update(client->config.gamma);
89         gamma_text->update(client->config.gamma);
90         automatic->update(client->config.automatic);
91         plot->update(client->config.plot);
92         update_histogram();
95 void GammaWindow::update_histogram()
97         histogram->clear_box(0, 0, histogram->get_w(), histogram->get_h());
98         if(client->engine)
99         {
100                 int max = 0;
101                 histogram->set_color(MEGREY);
102                 for(int i = 0; i < histogram->get_w(); i++)
103                 {
104                         int x1 = (int64_t)i * HISTOGRAM_SIZE / histogram->get_w();
105                         int x2 = (int64_t)(i + 1) * HISTOGRAM_SIZE / histogram->get_w();
106                         if(x2 == x1) x2++;
107                         int accum = 0;
108                         for(int x = x1; x < x2; x++)
109                         {
110                                 accum += client->engine->accum[x];
111                         }
112                         if(accum > max) max = accum;
113                 }
114                 for(int i = 0; i < histogram->get_w(); i++)
115                 {
116                         int x1 = (int64_t)i * HISTOGRAM_SIZE / histogram->get_w();
117                         int x2 = (int64_t)(i + 1) * HISTOGRAM_SIZE / histogram->get_w();
118                         if(x2 == x1) x2++;
119                         int accum = 0;
120                         for(int x = x1; x < x2; x++)
121                         {
122                                 accum += client->engine->accum[x];
123                         }
125                         int h = (int)(log(accum) / log(max) * histogram->get_h());
126                         histogram->draw_line(i, 
127                                 histogram->get_h(), 
128                                 i, 
129                                 histogram->get_h() - h);
130                 }
131         }
133         histogram->set_color(GREEN);
134         int y1 = histogram->get_h();
135         float scale = 1.0 / client->config.max;
136         float gamma = client->config.gamma - 1.0;
137         float max = client->config.max;
138         for(int i = 1; i < histogram->get_w(); i++)
139         {
140                 float in = (float)i / histogram->get_w();
141                 float out = in * (scale * pow(in * 2 / max, gamma));
142                 int y2 = (int)(histogram->get_h() - out * histogram->get_h());
143                 histogram->draw_line(i - 1, y1, i, y2);
144                 y1 = y2;
145         }
146         histogram->flash();
149 WINDOW_CLOSE_EVENT(GammaWindow)
151 MaxSlider::MaxSlider(GammaMain *client, 
152         GammaWindow *gui, 
153         int x, 
154         int y,
155         int w)
156  : BC_FSlider(x, 
157         y, 
158         0, 
159         w, 
160         w,
161         0.0, 
162         1.0, 
163         client->config.max)
165         this->client = client;
166         this->gui = gui;
167         set_precision(0.01);
170 int MaxSlider::handle_event()
172         client->config.max = get_value();
173         gui->max_text->update(client->config.max);
174         gui->update_histogram();
175         client->send_configure_change();
176         return 1;
179 MaxText::MaxText(GammaMain *client,
180         GammaWindow *gui,
181         int x,
182         int y,
183         int w)
184  : BC_TextBox(x, y, w, 1, client->config.max)
186         this->client = client;
187         this->gui = gui;
190 int MaxText::handle_event()
192         client->config.max = atof(get_text());
193         gui->max_slider->update(client->config.max);
194         client->send_configure_change();
195         return 1;
198 GammaSlider::GammaSlider(GammaMain *client, 
199         GammaWindow *gui, 
200         int x, 
201         int y,
202         int w)
203  : BC_FSlider(x, 
204         y, 
205         0, 
206         w, 
207         w,
208         0.0, 
209         1.0, 
210         client->config.gamma)
212         this->client = client;
213         this->gui = gui;
214         set_precision(0.01);
217 int GammaSlider::handle_event()
219         client->config.gamma = get_value();
220         gui->gamma_text->update(client->config.gamma);
221         gui->update_histogram();
222         client->send_configure_change();
223         return 1;
226 GammaText::GammaText(GammaMain *client,
227         GammaWindow *gui,
228         int x,
229         int y,
230         int w)
231  : BC_TextBox(x, y, w, 1, client->config.gamma)
233         this->client = client;
234         this->gui = gui;
237 int GammaText::handle_event()
239         client->config.gamma = atof(get_text());
240         gui->gamma_slider->update(client->config.gamma);
241         client->send_configure_change();
242         return 1;
245 GammaAuto::GammaAuto(GammaMain *client, int x, int y)
246  : BC_CheckBox(x, 
247         y, 
248         client->config.automatic, 
249         _("Automatic"))
251         this->plugin = client;
254 int GammaAuto::handle_event()
256         plugin->config.automatic = get_value();
257         plugin->send_configure_change();
258         return 1;
262 GammaPlot::GammaPlot(GammaMain *plugin, int x, int y)
263  : BC_CheckBox(x, y, plugin->config.plot, _("Plot histogram"))
265         this->plugin = plugin;
267 int GammaPlot::handle_event()
269         plugin->config.plot = get_value();
270         plugin->send_configure_change();
271         return 1;
275 GammaColorPicker::GammaColorPicker(GammaMain *plugin, 
276         GammaWindow *gui, 
277         int x, 
278         int y)
279  : BC_GenericButton(x, y, _("Use Color Picker"))
281         this->plugin = plugin;
282         this->gui = gui;
285 int GammaColorPicker::handle_event()
287 // Get colorpicker value
288         float red = plugin->get_red();
289         float green = plugin->get_green();
290         float blue = plugin->get_blue();
291 // Get maximum value
292         plugin->config.max = MAX(red, green);
293         plugin->config.max = MAX(plugin->config.max, blue);
294         gui->max_text->update(plugin->config.max);
295         gui->max_slider->update(plugin->config.max);
296         plugin->send_configure_change();
297         return 1;