1 #include "bcdisplayinfo.h"
2 #include "linearizewindow.h"
9 PLUGIN_THREAD_OBJECT(LinearizeMain, LinearizeThread, LinearizeWindow)
16 LinearizeWindow::LinearizeWindow(LinearizeMain *client, int x, int y)
17 : BC_Window(client->gui_string, x,
26 this->client = client;
29 int LinearizeWindow::create_objects()
32 add_subwindow(histogram = new BC_SubWindow(x,
37 y += histogram->get_h() + 10;
40 add_tool(title = new BC_Title(x, y, _("Maximum:")));
41 x += title->get_w() + 10;
42 add_tool(max_slider = new MaxSlider(client,
47 x += max_slider->get_w() + 10;
48 add_tool(max_text = new MaxText(client,
53 y += max_text->get_h() + 10;
55 add_tool(automatic = new LinearizeAuto(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,
65 x += gamma_slider->get_w() + 10;
66 add_tool(gamma_text = new GammaText(client,
71 y += gamma_text->get_h() + 10;
75 add_tool(new LinearizeColorPicker(client, this, x, y));
82 void LinearizeWindow::update()
84 max_slider->update(client->config.max);
85 max_text->update(client->config.max);
86 gamma_slider->update(client->config.gamma);
87 gamma_text->update(client->config.gamma);
88 automatic->update(client->config.automatic);
92 void LinearizeWindow::update_histogram()
94 histogram->clear_box(0, 0, histogram->get_w(), histogram->get_h());
98 histogram->set_color(MEGREY);
99 for(int i = 0; i < histogram->get_w(); i++)
101 int x1 = (int64_t)i * HISTOGRAM_SIZE / histogram->get_w();
102 int x2 = (int64_t)(i + 1) * HISTOGRAM_SIZE / histogram->get_w();
105 for(int x = x1; x < x2; x++)
107 accum += client->engine->accum[x];
109 if(accum > max) max = accum;
111 for(int i = 0; i < histogram->get_w(); i++)
113 int x1 = (int64_t)i * HISTOGRAM_SIZE / histogram->get_w();
114 int x2 = (int64_t)(i + 1) * HISTOGRAM_SIZE / histogram->get_w();
117 for(int x = x1; x < x2; x++)
119 accum += client->engine->accum[x];
122 int h = (int)(log(accum) / log(max) * histogram->get_h());
123 histogram->draw_line(i,
126 histogram->get_h() - h);
130 histogram->set_color(GREEN);
131 int y1 = histogram->get_h();
132 float scale = 1.0 / client->config.max;
133 float gamma = client->config.gamma - 1.0;
134 float max = client->config.max;
135 for(int i = 1; i < histogram->get_w(); i++)
137 float in = (float)i / histogram->get_w();
138 float out = in * (scale * pow(in * 2 / max, gamma));
139 int y2 = (int)(histogram->get_h() - out * histogram->get_h());
140 histogram->draw_line(i - 1, y1, i, y2);
146 WINDOW_CLOSE_EVENT(LinearizeWindow)
148 MaxSlider::MaxSlider(LinearizeMain *client,
149 LinearizeWindow *gui,
162 this->client = client;
167 int MaxSlider::handle_event()
169 client->config.max = get_value();
170 gui->max_text->update(client->config.max);
171 gui->update_histogram();
172 client->send_configure_change();
176 MaxText::MaxText(LinearizeMain *client,
177 LinearizeWindow *gui,
181 : BC_TextBox(x, y, w, 1, client->config.max)
183 this->client = client;
187 int MaxText::handle_event()
189 client->config.max = atof(get_text());
190 gui->max_slider->update(client->config.max);
191 client->send_configure_change();
195 GammaSlider::GammaSlider(LinearizeMain *client,
196 LinearizeWindow *gui,
207 client->config.gamma)
209 this->client = client;
214 int GammaSlider::handle_event()
216 client->config.gamma = get_value();
217 gui->gamma_text->update(client->config.gamma);
218 gui->update_histogram();
219 client->send_configure_change();
223 GammaText::GammaText(LinearizeMain *client,
224 LinearizeWindow *gui,
228 : BC_TextBox(x, y, w, 1, client->config.gamma)
230 this->client = client;
234 int GammaText::handle_event()
236 client->config.gamma = atof(get_text());
237 gui->gamma_slider->update(client->config.gamma);
238 client->send_configure_change();
242 LinearizeAuto::LinearizeAuto(LinearizeMain *client, int x, int y)
245 client->config.automatic,
248 this->plugin = client;
251 int LinearizeAuto::handle_event()
253 plugin->config.automatic = get_value();
254 plugin->send_configure_change();
258 LinearizeColorPicker::LinearizeColorPicker(LinearizeMain *plugin,
259 LinearizeWindow *gui,
262 : BC_GenericButton(x, y, _("Use Color Picker"))
264 this->plugin = plugin;
268 int LinearizeColorPicker::handle_event()
270 // Get colorpicker value
271 float red = plugin->get_red();
272 float green = plugin->get_green();
273 float blue = plugin->get_blue();
275 plugin->config.max = MAX(red, green);
276 plugin->config.max = MAX(plugin->config.max, blue);
277 gui->max_text->update(plugin->config.max);
278 gui->max_slider->update(plugin->config.max);
279 plugin->send_configure_change();