1 #include "bcdisplayinfo.h"
2 #include "histogramengine.h"
5 #include "thresholdwindow.h"
11 ThresholdMin::ThresholdMin(ThresholdMain *plugin,
16 : BC_TumbleTextBox(gui,
24 this->plugin = plugin;
29 int ThresholdMin::handle_event()
31 plugin->config.min = atof(get_text());
33 plugin->send_configure_change();
45 ThresholdMax::ThresholdMax(ThresholdMain *plugin,
50 : BC_TumbleTextBox(gui,
58 this->plugin = plugin;
62 int ThresholdMax::handle_event()
64 plugin->config.max = atof(get_text());
66 plugin->send_configure_change();
76 ThresholdPlot::ThresholdPlot(ThresholdMain *plugin,
79 : BC_CheckBox(x, y, plugin->config.plot, _("Plot histogram"))
81 this->plugin = plugin;
84 int ThresholdPlot::handle_event()
86 plugin->config.plot = get_value();
88 plugin->send_configure_change();
97 ThresholdCanvas::ThresholdCanvas(ThresholdMain *plugin,
103 : BC_SubWindow(x, y, w, h)
105 this->plugin = plugin;
107 state = NO_OPERATION;
110 int ThresholdCanvas::button_press_event()
112 if(is_event_win() && cursor_inside())
115 state = DRAG_SELECTION;
118 x1 = (int)((plugin->config.min - HISTOGRAM_MIN) /
119 (HISTOGRAM_MAX - HISTOGRAM_MIN) *
121 x2 = (int)((plugin->config.max - HISTOGRAM_MIN) /
122 (HISTOGRAM_MAX - HISTOGRAM_MIN) *
124 center_x = (x2 + x1) / 2;
125 if(abs(get_cursor_x() - x1) < abs(get_cursor_x() - x2))
138 x1 = x2 = center_x = get_cursor_x();
141 plugin->config.min = x1 *
142 (HISTOGRAM_MAX - HISTOGRAM_MIN) /
145 plugin->config.max = x2 *
146 (HISTOGRAM_MAX - HISTOGRAM_MIN) /
156 int ThresholdCanvas::button_release_event()
158 if(state == DRAG_SELECTION)
160 state = NO_OPERATION;
166 int ThresholdCanvas::cursor_motion_event()
168 if(state == DRAG_SELECTION)
170 if(get_cursor_x() > center_x)
181 plugin->config.min = x1 *
182 (HISTOGRAM_MAX - HISTOGRAM_MIN) /
186 plugin->config.max = x2 *
187 (HISTOGRAM_MAX - HISTOGRAM_MIN) /
191 gui->min->update(plugin->config.min);
192 gui->max->update(plugin->config.max);
194 plugin->send_configure_change();
200 void ThresholdCanvas::draw()
204 draw_box(0, 0, get_w(), get_h());
205 int border_x1 = (int)((0 - HISTOGRAM_MIN) /
206 (HISTOGRAM_MAX - HISTOGRAM_MIN) *
208 int border_x2 = (int)((1.0 - HISTOGRAM_MIN) /
209 (HISTOGRAM_MAX - HISTOGRAM_MIN) *
212 int x1 = (int)((plugin->config.min - HISTOGRAM_MIN) /
213 (HISTOGRAM_MAX - HISTOGRAM_MIN) *
215 int x2 = (int)((plugin->config.max - HISTOGRAM_MIN) /
216 (HISTOGRAM_MAX - HISTOGRAM_MIN) *
221 int64_t *array = plugin->engine->accum[HISTOGRAM_VALUE];
224 // Get normalizing factor
225 for(int i = 0; i < get_w(); i++)
227 int division1 = i * HISTOGRAM_RANGE / get_w();
228 int division2 = (i + 1) * HISTOGRAM_RANGE / get_w();
230 for(int j = division1; j < division2; j++)
234 if(total > max) max = total;
237 for(int i = 0; i < get_w(); i++)
239 int division1 = i * HISTOGRAM_RANGE / get_w();
240 int division2 = (i + 1) * HISTOGRAM_RANGE / get_w();
242 for(int j = division1; j < division2; j++)
249 pixels = total * get_h() / max;
252 if(i >= x1 && i < x2)
255 draw_line(i, 0, i, get_h() - pixels);
257 draw_line(i, get_h(), i, get_h() - pixels);
262 draw_line(i, get_h(), i, get_h() - pixels);
271 draw_box(x1, 0, x2 - x1, get_h());
275 draw_line(border_x1, 0, border_x1, get_h());
276 draw_line(border_x2, 0, border_x2, get_h());
293 ThresholdWindow::ThresholdWindow(ThresholdMain *plugin, int x, int y)
294 : BC_Window(plugin->gui_string, x, y, 440, 350, 440, 350, 0, 1)
296 this->plugin = plugin;
299 ThresholdWindow::~ThresholdWindow()
303 int ThresholdWindow::create_objects()
307 add_subwindow(canvas = new ThresholdCanvas(plugin,
314 y += canvas->get_h() + 10;
316 add_subwindow(new BC_Title(x, y, _("Min:")));
318 min = new ThresholdMin(plugin,
323 min->create_objects();
324 min->set_increment(0.1);
327 add_subwindow(new BC_Title(x, y, _("Max:")));
329 max = new ThresholdMax(plugin,
334 max->create_objects();
335 max->set_increment(0.1);
340 add_subwindow(plot = new ThresholdPlot(plugin, x, y));
345 WINDOW_CLOSE_EVENT(ThresholdWindow)
351 PLUGIN_THREAD_OBJECT(ThresholdMain, ThresholdThread, ThresholdWindow)