no longer need ffmpeg patch0 which was for Termux
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / histogram / histogramwindow.C
index cb50652d838964734b669611c5fe0dae68592af5..b36c7b0b8999b6d8b43dcdb26800e342e6b6d3ff 100644 (file)
@@ -60,63 +60,34 @@ void HistogramWindow::create_objects()
        int margin = plugin->get_theme()->widget_border;
        int x = margin, y = margin, x1 = margin;
 
-       add_subwindow(mode_v = new HistogramMode(plugin,
-               x,
-               y,
-               HISTOGRAM_VALUE,
-               _("Value")));
+       add_subwindow(mode_v = new HistogramMode(plugin, x, y,
+               HISTOGRAM_VALUE, _("Value")));
        x += mode_v->get_w() + margin;
-       add_subwindow(mode_r = new HistogramMode(plugin,
-               x,
-               y,
-               HISTOGRAM_RED,
-               _("Red")));
+       add_subwindow(mode_r = new HistogramMode(plugin, x, y,
+               HISTOGRAM_RED, _("Red")));
        x += mode_r->get_w() + margin;
-       add_subwindow(mode_g = new HistogramMode(plugin,
-               x,
-               y,
-               HISTOGRAM_GREEN,
-               _("Green")));
+       add_subwindow(mode_g = new HistogramMode(plugin, x, y,
+               HISTOGRAM_GREEN, _("Green")));
        x += mode_g->get_w() + margin;
-       add_subwindow(mode_b = new HistogramMode(plugin,
-               x,
-               y,
-               HISTOGRAM_BLUE,
-               _("Blue")));
-
-
+       add_subwindow(mode_b = new HistogramMode(plugin, x, y,
+               HISTOGRAM_BLUE, _("Blue")));
        x = get_w() - margin - plugin->get_theme()->get_image_set("histogram_rgb_toggle")[0]->get_w();
-       add_subwindow(parade_on = new HistogramParade(plugin,
-               this,
-               x,
-               y,
-               1));
+       add_subwindow(parade_on = new HistogramParade(plugin, this,
+               x, y, 1));
        x -= parade_on->get_w() + margin;
-       add_subwindow(parade_off = new HistogramParade(plugin,
-               this,
-               x,
-               y,
-               0));
-
+       add_subwindow(parade_off = new HistogramParade(plugin, this, x, y, 0));
 
        x = x1;
        y += parade_on->get_h() + margin;
-       add_subwindow(canvas_title1 = new BC_Title(margin,
-               y,
-               "-10%"));
-       add_subwindow(canvas_title2 = new BC_Title(get_w() - get_text_width(MEDIUMFONT, "110%") - margin,
-               y,
-               "110%"));
+       add_subwindow(canvas_title1 = new BC_Title(margin, y, "-10%"));
+       x = get_w() - get_text_width(MEDIUMFONT, "110%") - margin;
+       add_subwindow(canvas_title2 = new BC_Title(x, y, "110%"));
 
        y += canvas_title2->get_h() + margin;
        x = x1;
        canvas_h = get_h() - y - yS(210);
 
-
-       add_subwindow(low_input_carrot = new HistogramCarrot(plugin,
-               this,
-               x,
-               y + canvas_h));
+       add_subwindow(low_input_carrot = new HistogramCarrot(plugin, this, x, y + canvas_h));
 
        x = low_input_carrot->get_w() / 2 + x;
        canvas_w = get_w() - x - x;
@@ -126,48 +97,27 @@ void HistogramWindow::create_objects()
        title3_x = x + (int)(canvas_w * (1.0 - HIST_MIN_INPUT) / FLOAT_RANGE);
        title4_x = x + (int)(canvas_w);
 
-
-
-
-
-       add_subwindow(canvas = new HistogramCanvas(plugin,
-               this,
-               x,
-               y,
-               canvas_w,
-               canvas_h));
+       add_subwindow(canvas = new HistogramCanvas(plugin, this,
+                       x, y, canvas_w, canvas_h));
 
 // Canvas border
-       draw_3d_border(x - 2,
-               y - 2,
-               canvas_w + 4,
-               canvas_h + 4,
-               get_bg_color(),
-               BLACK,
-               MDGREY,
-               get_bg_color());
+       draw_3d_border(x - 2, y - 2, canvas_w + 4, canvas_h + 4,
+               get_bg_color(), BLACK, MDGREY, get_bg_color());
 
 // Calculate output curve with no value function
-       plugin->tabulate_curve(plugin->mode, 0);
+       plugin->tabulate_curve(plugin->preview_lookup, plugin->mode, 0x10000, 0);
 
        y += canvas->get_h();
        x = margin;
 
-       add_subwindow(gamma_carrot = new HistogramCarrot(plugin,
-               this,
-               canvas->get_x() +
-                       canvas->get_w() / 2 -
-                       low_input_carrot->get_w() / 2 ,
-               y));
-
-       add_subwindow(high_input_carrot = new HistogramCarrot(plugin,
-               this,
-               canvas->get_x() +
-                       canvas->get_w() -
-                       low_input_carrot->get_w() / 2,
-               y));
-       y += low_input_carrot->get_h() + margin;
+       add_subwindow(gamma_carrot = new HistogramCarrot(plugin, this,
+               canvas->get_x() + canvas->get_w() / 2 -
+                       low_input_carrot->get_w() / 2 , y));
 
+       add_subwindow(high_input_carrot = new HistogramCarrot(plugin, this,
+               canvas->get_x() + canvas->get_w() -
+                       low_input_carrot->get_w() / 2, y));
+       y += low_input_carrot->get_h() + margin;
 
 //     add_subwindow(title = new BC_Title(x, y, _("Input:")));
 //     x += title->get_w() + margin;
@@ -235,12 +185,8 @@ void HistogramWindow::create_objects()
        threshold->create_objects();
        y += automatic->get_h() + margin;
 
-       add_subwindow(plot = new HistogramPlot(plugin, x1, y));
-       add_subwindow(select = new HistogramSelect(plugin, this, x2, y));
-       frames = new HistogramFrames(plugin, this, x3, y);
-       frames->create_objects();
-       x = x3 + frames->get_w() + margin;
-       add_subwindow(clear_frames = new HistogramClearFrames(plugin, this, x, y));
+       add_subwindow(plot= new HistogramPlot(plugin, x, y));
+       add_subwindow(sum_frames = new HistogramSumFrames(plugin, x2, y));
        y += plot->get_h() + margin;
 
        x = x1;
@@ -271,20 +217,13 @@ int HistogramWindow::resize_event(int w, int h)
 // Canvas follows window size
        canvas_w = canvas_w + xdiff;
        canvas_h = canvas_h + ydiff;
-       canvas->reposition_window(canvas->get_x(),
-               canvas->get_y(),
-               canvas_w,
-               canvas_h);
+       canvas->reposition_window(canvas->get_x(), canvas->get_y(),
+               canvas_w, canvas_h);
 
 // Canvas border
-       draw_3d_border(canvas->get_x() - 2,
-               canvas->get_y() - 2,
-               canvas_w + 4,
-               canvas_h + 4,
-               get_bg_color(),
-               BLACK,
-               MDGREY,
-               get_bg_color());
+       draw_3d_border(canvas->get_x() - 2, canvas->get_y() - 2,
+               canvas_w + 4, canvas_h + 4,
+               get_bg_color(), BLACK, MDGREY, get_bg_color());
 
        low_input_carrot->reposition_window(low_input_carrot->get_x(),
                low_input_carrot->get_y() + ydiff);
@@ -307,14 +246,9 @@ int HistogramWindow::resize_event(int w, int h)
        output->update();
 
 // Output border
-       draw_3d_border(output->get_x() - 2,
-               output->get_y() - 2,
-               output->get_w() + 4,
-               output->get_h() + 4,
-               get_bg_color(),
-               BLACK,
-               MDGREY,
-               get_bg_color());
+       draw_3d_border(output->get_x() - 2, output->get_y() - 2,
+               output->get_w() + 4, output->get_h() + 4,
+               get_bg_color(), BLACK, MDGREY, get_bg_color());
 
        low_output_carrot->reposition_window(low_output_carrot->get_x(),
                low_output_carrot->get_y() + ydiff);
@@ -323,7 +257,7 @@ int HistogramWindow::resize_event(int w, int h)
 
        low_output->reposition_window(low_output->get_x(),
                low_output->get_y() + ydiff);
-       int xs = (get_w() - log_slider->get_w()) / 2;
+       int xs = (w - log_slider->get_w()) / 2;
        int margin = plugin->get_theme()->widget_border;
        log_title1->reposition_window(xs - log_title1->get_w() - margin,
                log_title1->get_y() + ydiff);
@@ -346,19 +280,14 @@ int HistogramWindow::resize_event(int w, int h)
                threshold->get_y() + ydiff);
        plot->reposition_window(plot->get_x(),
                plot->get_y() + ydiff);
+       sum_frames->reposition_window(sum_frames->get_x(),
+               sum_frames->get_y() + ydiff);
 
        split->reposition_window(split->get_x(),
                split->get_y() + ydiff);
        reset->reposition_window(reset->get_x(),
                reset->get_y() + ydiff);
 
-       frames->reposition_window(frames->get_x(),
-               frames->get_y() + ydiff);
-       select->reposition_window(select->get_x(),
-               select->get_y() + ydiff);
-       clear_frames->reposition_window(clear_frames->get_x(),
-               clear_frames->get_y() + ydiff);
-
        update(1, 1, 1, 1);
 
        plugin->w = w;
@@ -401,37 +330,34 @@ int HistogramWindow::keypress_event()
                }
        }
 
+       if (! result)
+               result = context_help_check_and_show();
+
        return result;
 }
 
-void HistogramWindow::update(int do_canvases,
-       int do_carrots,
-       int do_text,
-       int do_toggles)
+void HistogramWindow::update(int do_canvases, int do_carrots, int do_text, int do_toggles)
 {
-       if(do_toggles)
-       {
+       if(do_toggles) {
                automatic->update(plugin->config.automatic);
                mode_v->update(plugin->mode == HISTOGRAM_VALUE ? 1 : 0);
                mode_r->update(plugin->mode == HISTOGRAM_RED ? 1 : 0);
                mode_g->update(plugin->mode == HISTOGRAM_GREEN ? 1 : 0);
                mode_b->update(plugin->mode == HISTOGRAM_BLUE ? 1 : 0);
                plot->update(plugin->config.plot);
+               sum_frames->update(plugin->config.sum_frames);
                split->update(plugin->config.split);
-               frames->update(plugin->config.frames);
                parade_on->update(plugin->parade ? 1 : 0);
                parade_off->update(plugin->parade ? 0 : 1);
                log_slider->update(plugin->config.log_slider);
                output->update();
        }
 
-       if(do_canvases)
-       {
+       if(do_canvases) {
                update_canvas();
        }
 
-       if(do_carrots)
-       {
+       if(do_carrots) {
                low_input_carrot->update();
                high_input_carrot->update();
                gamma_carrot->update();
@@ -439,8 +365,7 @@ void HistogramWindow::update(int do_canvases,
                high_output_carrot->update();
        }
 
-       if(do_text)
-       {
+       if(do_text) {
                low_input->update();
                gamma->update();
                high_input->update();
@@ -448,40 +373,45 @@ void HistogramWindow::update(int do_canvases,
                high_output->update();
                threshold->update();
        }
-
-
 }
 
 
 void HistogramWindow::draw_canvas_mode(int mode, int color, int y, int h)
 {
 // Draw histogram
-       int max = 0, *accum = plugin->accum[mode];
-       if( accum ) {
-               for( int i=0; i<HISTOGRAM_SLOTS; ++i ) {
-                       int v = accum[i];
-                       if( max < v ) max = v;
+       int64_t max = 0;
+       int64_t *accum = plugin->accum[mode];
+       for( int k0=0,x=0; x<canvas_w; ++x ) {
+               int k1 = (HISTOGRAM_SLOTS * (x+1)) / canvas_w;
+               if( k0 == k1 ) continue;
+               int64_t m = accum[k0];
+               for( int k=k0; ++k<k1; ) {
+                       if( m < accum[k] ) m = accum[k];
                }
+               if( max < m ) max = m;
+               k0 = k1;
        }
-
        if( max > 0 ) {
                double log_slider = plugin->config.log_slider;
                double lin_slider = 1. - log_slider;
-               double lin_scale = (lin_slider * h) / max;
-               double log_scale = (log_slider * h) / log(max);
-               for( int i=0,x=0; x<canvas_w; ++x ) {
-                       int m = 0;
-                       int i1 = (HISTOGRAM_SLOTS * (x+1)) / canvas_w;
-                       while( i < i1 ) {
-                               int v = accum[i++];
-                               if( m < v ) m = v;
+               double lin_max = (lin_slider * h) / max;
+               double log_max = (log_slider * h) / log(max);
+               for( int k0=0,x=0; x<canvas_w; ++x ) {
+                       int k1 = (HISTOGRAM_SLOTS * (x+1)) / canvas_w;
+                       if( k0 == k1 ) continue;
+                       int64_t m = accum[k0];
+                       for( int k=k0; ++k<k1; ) {
+                               if( m < accum[k] ) m = accum[k];
                        }
-                       m = m*lin_scale + log(m)*log_scale;
-
+                       int y1 = y+h;
+                       double vv = m > 0 ? (double)m : 0;
+                       m = vv > 0 ? vv*lin_max + log(vv)*log_max : 0;
                        canvas->set_color(BLACK);
-                       canvas->draw_line(x, y, x, y+h - m);
+                       int y0 = y1 - m;
+                       canvas->draw_line(x, y, x, y0);
                        canvas->set_color(color);
-                       canvas->draw_line(x, y+h - m, x, y+h);
+                       canvas->draw_line(x, y0, x, y1);
+                       k0 = k1;
                }
        }
        else {
@@ -525,28 +455,16 @@ void HistogramWindow::update_canvas()
 // Draw 0 and 100% lines.
        canvas->set_color(RED);
        int x = (int)(canvas_w * -HIST_MIN_INPUT / FLOAT_RANGE);
-       canvas->draw_line(x,
-               0,
-               x,
-               canvas_h);
+       canvas->draw_line(x, 0, x, canvas_h);
        x = (int)(canvas_w * (1.0 - HIST_MIN_INPUT) / FLOAT_RANGE);
-       canvas->draw_line(x,
-               0,
-               x,
-               canvas_h);
+       canvas->draw_line(x, 0, x, canvas_h);
        canvas->flash();
 }
 
 
-
-
-HistogramParade::HistogramParade(HistogramMain *plugin,
-       HistogramWindow *gui,
-       int x,
-       int y,
-       int value)
- : BC_Toggle(x,
-       y,
+HistogramParade::HistogramParade(HistogramMain *plugin, HistogramWindow *gui,
+               int x, int y, int value)
+ : BC_Toggle(x, y,
        value ? plugin->get_theme()->get_image_set("histogram_rgb_toggle") :
                plugin->get_theme()->get_image_set("histogram_toggle"),
        0)
@@ -564,30 +482,13 @@ int HistogramParade::handle_event()
 {
        update(1);
        plugin->parade = value;
-       gui->update(1,
-               0,
-               0,
-               1);
+       gui->update(1, 0, 0, 1);
        return 1;
 }
 
-
-
-
-
-
-
-HistogramCanvas::HistogramCanvas(HistogramMain *plugin,
-       HistogramWindow *gui,
-       int x,
-       int y,
-       int w,
-       int h)
- : BC_SubWindow(x,
-       y,
-       w,
-       h,
-       BLACK)
+HistogramCanvas::HistogramCanvas(HistogramMain *plugin, HistogramWindow *gui,
+               int x, int y, int w, int h)
+ : BC_SubWindow(x, y, w, h, BLACK)
 {
        this->plugin = plugin;
        this->gui = gui;
@@ -635,48 +536,6 @@ int HistogramReset::handle_event()
 }
 
 
-HistogramSelect::HistogramSelect(HistogramMain *plugin, HistogramWindow *gui,
-               int x, int y)
- : BC_GenericButton(x, y, xS(100), _("Frames"))
-{
-       this->plugin = plugin;
-       this->gui = gui;
-       set_tooltip(_("Set frames to selection duration"));
-}
-int HistogramSelect::handle_event()
-{
-       MWindow *mwindow = plugin->server->mwindow;
-       if( mwindow ) {
-               EDL *edl = mwindow->edl;
-               double start = edl->local_session->get_selectionstart();
-               int64_t start_pos = edl->get_frame_rate() * start;
-               double end = edl->local_session->get_selectionend();
-               int64_t end_pos = edl->get_frame_rate() * end;
-               int64_t frames = end_pos - start_pos;
-               gui->frames->update(frames);
-               plugin->config.frames = frames;
-               plugin->send_configure_change();
-       }
-       return 1;
-}
-
-HistogramClearFrames::HistogramClearFrames(HistogramMain *plugin, HistogramWindow *gui,
-               int x, int y)
- : BC_Button(x, y, plugin->get_theme()->get_image_set("reset_button"))
-{
-       this->plugin = plugin;
-       this->gui = gui;
-       set_tooltip(_("Clear frames"));
-}
-
-int HistogramClearFrames::handle_event()
-{
-       plugin->config.frames = 0;
-       gui->frames->update(0);
-       plugin->send_configure_change();
-       return 1;
-}
-
 HistogramLogSlider::HistogramLogSlider(HistogramMain *plugin, HistogramWindow *gui,
                int x, int y)
 : BC_FSlider(x, y, 0, xS(100), xS(100), 0., 1., plugin->config.log_slider)
@@ -844,18 +703,8 @@ int HistogramCarrot::cursor_motion_event()
 
 
 
-
-
-
-
-
-HistogramSlider::HistogramSlider(HistogramMain *plugin,
-       HistogramWindow *gui,
-       int x,
-       int y,
-       int w,
-       int h,
-       int is_input)
+HistogramSlider::HistogramSlider(HistogramMain *plugin, HistogramWindow *gui,
+               int x, int y, int w, int h, int is_input)
  : BC_SubWindow(x, y, w, h)
 {
        this->plugin = plugin;
@@ -882,44 +731,30 @@ void HistogramSlider::update()
 
        clear_box(0, 0, w, h);
 
-       switch(mode)
-       {
-               case HISTOGRAM_RED:
-                       g = b = 0x00;
-                       break;
-               case HISTOGRAM_GREEN:
-                       r = b = 0x00;
-                       break;
-               case HISTOGRAM_BLUE:
-                       r = g = 0x00;
-                       break;
+       switch(mode) {
+       case HISTOGRAM_RED:
+               g = b = 0x00;
+               break;
+       case HISTOGRAM_GREEN:
+               r = b = 0x00;
+               break;
+       case HISTOGRAM_BLUE:
+               r = g = 0x00;
+               break;
        }
 
-       for(int i = 0; i < w; i++)
-       {
+       for( int i = 0; i < w; i++ ) {
                int color = (int)(i * 0xff / w);
                set_color(((r * color / 0xff) << 16) |
                        ((g * color / 0xff) << 8) |
                        (b * color / 0xff));
-
                draw_line(i, 0, i, h);
        }
-
-
        flash();
 }
 
 
-
-
-
-
-
-
-
-HistogramAuto::HistogramAuto(HistogramMain *plugin,
-       int x,
-       int y)
+HistogramAuto::HistogramAuto(HistogramMain *plugin, int x, int y)
  : BC_CheckBox(x, y, plugin->config.automatic, _("Automatic"))
 {
        this->plugin = plugin;
@@ -933,11 +768,7 @@ int HistogramAuto::handle_event()
 }
 
 
-
-
-HistogramPlot::HistogramPlot(HistogramMain *plugin,
-       int x,
-       int y)
+HistogramPlot::HistogramPlot(HistogramMain *plugin, int x, int y)
  : BC_CheckBox(x, y, plugin->config.plot, _("Plot histogram"))
 {
        this->plugin = plugin;
@@ -951,11 +782,21 @@ int HistogramPlot::handle_event()
 }
 
 
+HistogramSumFrames::HistogramSumFrames(HistogramMain *plugin, int x, int y)
+ : BC_CheckBox(x, y, plugin->config.sum_frames, _("Sum frames"))
+{
+       this->plugin = plugin;
+}
+
+int HistogramSumFrames::handle_event()
+{
+       plugin->config.sum_frames = get_value();
+       plugin->send_configure_change();
+       return 1;
+}
 
 
-HistogramSplit::HistogramSplit(HistogramMain *plugin,
-       int x,
-       int y)
+HistogramSplit::HistogramSplit(HistogramMain *plugin, int x, int y)
  : BC_CheckBox(x, y, plugin->config.split, _("Split output"))
 {
        this->plugin = plugin;
@@ -970,10 +811,7 @@ int HistogramSplit::handle_event()
 
 
 HistogramMode::HistogramMode(HistogramMain *plugin,
-       int x,
-       int y,
-       int value,
-       char *text)
+               int x, int y, int value, char *text)
  : BC_Radial(x, y, plugin->mode == value, text)
 {
        this->plugin = plugin;
@@ -996,27 +834,6 @@ int HistogramMode::handle_event()
 }
 
 
-HistogramFrames::HistogramFrames(HistogramMain *plugin, HistogramWindow *gui,
-               int x, int y)
- : BC_TumbleTextBox(gui, 0, 0, 65535, x, y, xS(80))
-{
-       this->plugin = plugin;
-       this->gui = gui;
-}
-
-int HistogramFrames::handle_event()
-{
-       plugin->config.frames = atoi(get_text());
-       plugin->send_configure_change();
-       return 1;
-}
-
-void HistogramFrames::update(int frames)
-{
-       BC_TumbleTextBox::update((int64_t)frames);
-}
-
-
 HistogramText::HistogramText(HistogramMain *plugin,
        HistogramWindow *gui, int x, int y, float hist_min, float hist_max)
  : BC_TumbleTextBox(gui, 0.0, hist_min, hist_max, x, y, xS(80))