videoscope tweaks, add scope overlay grid (andrea), hw probe fix for sw fallback
authorGood Guy <[email protected]>
Tue, 14 Apr 2020 03:23:08 +0000 (21:23 -0600)
committerGood Guy <[email protected]>
Tue, 14 Apr 2020 03:23:08 +0000 (21:23 -0600)
cinelerra-5.1/cinelerra/editpanel.C
cinelerra-5.1/cinelerra/ffmpeg.C
cinelerra-5.1/cinelerra/mainsession.C
cinelerra-5.1/cinelerra/mainsession.h
cinelerra-5.1/cinelerra/recordscopes.C
cinelerra-5.1/cinelerra/scopewindow.C
cinelerra-5.1/cinelerra/scopewindow.h
cinelerra-5.1/plugins/scopes/grid.png [new file with mode: 0644]
cinelerra-5.1/plugins/videoscope/videoscope.C

index 33dcded589afab15b4f9c58868f82557976c4fb9..03eb9e483e5b2d3f925037d7f1bf2b721da39f15 100644 (file)
@@ -1224,6 +1224,7 @@ void EditPanelScopeGUI::create_objects()
        use_wave_gain = session->use_wave_gain;
        use_vect_gain = session->use_vect_gain;
        use_smooth = session->use_smooth;
+       use_graticule = session->use_graticule;
        ScopeGUI::create_objects();
 }
 
@@ -1238,6 +1239,7 @@ void EditPanelScopeGUI::toggle_event()
        session->use_wave_gain = use_wave_gain;
        session->use_vect_gain = use_vect_gain;
        session->use_smooth = use_smooth;
+       session->use_graticule = use_graticule;
 }
 
 int EditPanelScopeGUI::translation_event()
index a6f67d85eb3d54fcb804e28b85eb49ea73f18846..bf6a6fe61786c8f104434d525240ae2ce15c9a8b 100644 (file)
@@ -421,7 +421,6 @@ int FFStream::decode_activate()
                        }
                        if( ret >= 0 && hw_type != AV_HWDEVICE_TYPE_NONE ) {
                                ret = decode_hw_format(decoder, hw_type);
-                               if( !ret ) hw_type = AV_HWDEVICE_TYPE_NONE;
                        }
                        if( ret >= 0 ) {
                                avcodec_parameters_to_context(avctx, st->codecpar);
@@ -437,28 +436,27 @@ int FFStream::decode_activate()
                                }
                                if( ret >= 0 )
                                        ret = decode(frame);
-                               if( ret < 0 || hw_pix_fmt == AV_PIX_FMT_NONE ) {
-                                       ff_err(ret, "HW device init failed, using SW decode.\nfile:%s\n",
-                                               ffmpeg->fmt_ctx->url);
-                                       avcodec_close(avctx);
-                                       avcodec_free_context(&avctx);
-                                       av_buffer_unref(&hw_device_ctx);
-                                       hw_device_ctx = 0;
-                                       av_frame_free(&frame);
-                                       hw_type = AV_HWDEVICE_TYPE_NONE;
-                                       int flags = AVSEEK_FLAG_BACKWARD | AVSEEK_FLAG_ANY;
-                                       int idx = st->index;
-                                       av_seek_frame(fmt_ctx, idx, INT64_MIN, flags);
-                                       need_packet = 1;  flushed = 0;
-                                       seeked = 1;  st_eof(0);
-                                       ret = 0;
-                                       continue;
-                               }
-                               probe_frame = frame;
                        }
-                       if( ret >= 0 ) {
-                               reading = 1;
+                       if( ret < 0 && hw_type != AV_HWDEVICE_TYPE_NONE ) {
+                               ff_err(ret, "HW device init failed, using SW decode.\nfile:%s\n",
+                                       ffmpeg->fmt_ctx->url);
+                               avcodec_close(avctx);
+                               avcodec_free_context(&avctx);
+                               av_buffer_unref(&hw_device_ctx);
+                               hw_device_ctx = 0;
+                               av_frame_free(&frame);
+                               hw_type = AV_HWDEVICE_TYPE_NONE;
+                               int flags = AVSEEK_FLAG_BACKWARD | AVSEEK_FLAG_ANY;
+                               int idx = st->index;
+                               av_seek_frame(fmt_ctx, idx, INT64_MIN, flags);
+                               need_packet = 1;  flushed = 0;
+                               seeked = 1;  st_eof(0);
+                               ret = 0;
+                               continue;
                        }
+                       probe_frame = frame;
+                       if( ret >= 0 )
+                               reading = 1;
                        else
                                eprintf(_("open decoder failed\n"));
                }
@@ -1104,9 +1102,11 @@ int FFVideoStream::decode_hw_format(AVCodec *decoder, AVHWDeviceType type)
                        avctx->hw_device_ctx = av_buffer_ref(hw_device_ctx);
                        ret = 1;
                }
-               else
+               else {
                        ff_err(ret, "Failed HW device create.\ndev:%s\n",
                                av_hwdevice_get_type_name(type));
+                       ret = -1;
+               }
        }
        return ret;
 }
index 66978fef4c32c355044270f6c66921d24cc8b0f0..58ff172479581598d1a40bf0777e6d32532e3ecc 100644 (file)
@@ -109,6 +109,7 @@ MainSession::MainSession(MWindow *mwindow)
        use_wave_gain = 5;
        use_vect_gain = 5;
        use_smooth = 0;
+       use_graticule = 0;
        afolders_w = 0;
        show_vwindow = show_awindow = show_cwindow = show_gwindow = show_lwindow = 0;
        plugindialog_w = plugindialog_h = 0;
@@ -327,6 +328,7 @@ void MainSession::default_window_positions(int window_config)
        use_wave_gain = 5;
        use_vect_gain = 5;
        use_smooth = 1;
+       use_graticule = 0;
 
        if(mwindow->edl)
                lwindow_w = MeterPanel::get_meters_width(mwindow->theme,
@@ -444,6 +446,7 @@ int MainSession::load_defaults(BC_Hash *defaults)
        use_wave_gain = defaults->get("USE_WAVE_GAIN", use_wave_gain);
        use_vect_gain = defaults->get("USE_VECT_GAIN", use_vect_gain);
        use_smooth = defaults->get("USE_SMOOTH", use_smooth);
+       use_graticule = defaults->get("USE_GRATICULE", use_graticule);
 
 //printf("MainSession::load_defaults 1\n");
 
@@ -572,6 +575,7 @@ int MainSession::save_defaults(BC_Hash *defaults)
        defaults->update("USE_WAVE_GAIN", use_wave_gain);
        defaults->update("USE_VECT_GAIN", use_vect_gain);
        defaults->update("USE_SMOOTH", use_smooth);
+       defaults->update("USE_GRATICULE", use_graticule);
 
        defaults->update("ABINS_W", afolders_w);
 
index 2757f7e0421c076e8851c87aeacd8cdbdc0e74dd..64796f8bff060b368096e99949b6358ea8ee7a8d 100644 (file)
@@ -175,6 +175,7 @@ public:
        int use_wave_gain;
        int use_vect_gain;
        int use_smooth;
+       int use_graticule;
 
        int afolders_w;
        int show_vwindow, show_awindow, show_cwindow, show_gwindow, show_lwindow;
index c7dfd53d30ff37d81a9335f62b5a5c4d67bd8c83..3de960bae841198f0092e7352c05e30ecc80a724 100644 (file)
@@ -120,6 +120,7 @@ void RecordScopeGUI::create_objects()
        use_wave_gain = mwindow->session->use_wave_gain;
        use_vect_gain = mwindow->session->use_vect_gain;
        use_smooth = mwindow->session->use_smooth;
+       use_graticule = mwindow->session->use_graticule;
        ScopeGUI::create_objects();
 }
 
@@ -134,6 +135,7 @@ void RecordScopeGUI::toggle_event()
        mwindow->session->use_wave_gain = use_wave_gain;
        mwindow->session->use_vect_gain = use_vect_gain;
        mwindow->session->use_smooth = use_smooth;
+       mwindow->session->use_graticule = use_graticule;
 }
 
 int RecordScopeGUI::translation_event()
index 2b21ff0d34df071e5ee4c3e0d7eec6c5dcf65d35..37e22d1794cb989756f51872f499b394deb0197a 100644 (file)
@@ -445,7 +445,6 @@ void ScopeGUI::reset()
        vect_slider = 0;
        grad_image = 0;
        grad_pixmap = 0;
-       vector_gradical = 0;
        grad_idx = 0;
        vect_grads = 0;
 
@@ -460,6 +459,7 @@ void ScopeGUI::reset()
        use_vector = 1;
        use_hist_parade = 0;
        use_wave_parade = 0;
+       use_graticule = 0;
        waveform = 0;
        vectorscope = 0;
        histogram = 0;
@@ -481,17 +481,20 @@ void ScopeGUI::create_objects()
        if( use_wave && use_wave_parade )
                use_wave = 0;
        if( !engine ) engine = new ScopeEngine(this, cpus);
+       grad_idx = use_graticule; // last graticule
+       use_graticule = 0;
 
        lock_window("ScopeGUI::create_objects");
-       int x = theme->widget_border;
-       int y = theme->widget_border;
+       int margin = theme->widget_border;
+       int x = margin;
+       int y = margin;
        add_subwindow(smooth = new ScopeSmooth(this, x, y));
-       y += smooth->get_h() + theme->widget_border;
+       y += smooth->get_h() + margin;
        add_subwindow(scope_menu = new ScopeMenu(this, x, y));
        scope_menu->create_objects();
-       x += scope_menu->get_w() + theme->widget_border;
+       x += scope_menu->get_w() + margin;
        add_subwindow(value_text = new BC_Title(x, y, ""));
-       y += scope_menu->get_h() + theme->widget_border;
+       y += scope_menu->get_h() + margin;
 
        create_panels();
        update_toggles();
@@ -504,6 +507,7 @@ void ScopeGUI::create_panels()
 {
        calculate_sizes(get_w(), get_h());
        int slider_w = xS(100);
+       int margin = theme->widget_border;
        if( (use_wave || use_wave_parade) ) {
                int px = wave_x + wave_w - slider_w - xS(5);
                int py = wave_y - ScopeGain::calculate_h() - yS(5);
@@ -536,7 +540,8 @@ void ScopeGUI::create_panels()
                        vect_slider = new ScopeVectSlider(this, vx, vy, slider_w);
                        vect_slider->create_objects();
                        if( use_vector < 0 ) {
-                               add_subwindow(vect_grads = new ScopeVectGrads(this, vector_x, vy));
+                               vect_grads = new ScopeVectGrads(this, vector_x, 2*margin);
+                               add_subwindow(vect_grads);
                                vect_grads->create_objects();
                        }
                }
@@ -549,11 +554,12 @@ void ScopeGUI::create_panels()
                                delete vect_grads;  vect_grads = 0;
                        }
                        else if( !vect_grads ) {
-                               add_subwindow(vect_grads = new ScopeVectGrads(this, vector_x, vy));
+                               vect_grads = new ScopeVectGrads(this, vector_x, 2*margin);
+                               add_subwindow(vect_grads);
                                vect_grads->create_objects();
                        }
                        else
-                               vect_grads->reposition_window(vector_x, vy);
+                               vect_grads->reposition_window(vector_x, 2*margin);
                }
        }
        else if( !use_vector && vectorscope ) {
@@ -627,7 +633,7 @@ void ScopeGUI::calculate_sizes(int w, int h)
 
                if( vector_w > vector_h ) {
                        vector_w = vector_h;
-                       vector_x = w - theme->widget_border - vector_w;
+                       vector_x = w - margin - vector_w;
                }
                --total_panels;
                if(total_panels > 0)
@@ -706,7 +712,7 @@ int ScopeGUI::resize_event(int w, int h)
                int vy = vector_y - vect_slider->get_h() - margin;
                vect_slider->reposition_window(vx, vy);
                if( vect_grads )
-                       vect_grads->reposition_window(vector_x, vy);
+                       vect_grads->reposition_window(vector_x, 2*margin);
        }
 
        allocate_vframes();
@@ -727,6 +733,7 @@ int ScopeGUI::translation_event()
 
 void ScopeGUI::draw_overlays(int overlays, int borders, int flush)
 {
+       int margin = theme->widget_border;
        if( overlays && borders ) {
                clear_box(0, 0, get_w(), get_h());
        }
@@ -756,7 +763,7 @@ void ScopeGUI::draw_overlays(int overlays, int borders, int flush)
                                char string[BCTEXTLEN];
                                sprintf(string, "%d", (int)lround((FLOAT_MAX -
                                        i * (FLOAT_MAX - FLOAT_MIN) / WAVEFORM_DIVISIONS) * 100));
-                               int text_x = wave_x - get_text_width(SMALLFONT, string) - theme->widget_border;
+                               int text_x = wave_x - get_text_width(SMALLFONT, string) - margin;
                                set_color(text_color);
                                draw_text(text_x, text_y, string);
                                CLAMP(y, 0, waveform->get_h() - 1);
@@ -771,7 +778,7 @@ void ScopeGUI::draw_overlays(int overlays, int borders, int flush)
                }
 // Vectorscope overlay
                if( vectorscope && use_vector ) {
-                       draw_gradical();
+                       draw_graticule();
                        set_color(text_color);
                        vectorscope->draw_point();
                        vectorscope->flash(0);
@@ -801,7 +808,7 @@ void ScopeGUI::draw_overlays(int overlays, int borders, int flush)
        if(flush) this->flush();
 }
 
-void ScopeGUI::draw_gradical()
+void ScopeGUI::draw_graticule()
 {
        if( use_vector > 0 ) {
                int margin = theme->widget_border;
@@ -827,24 +834,24 @@ void ScopeGUI::draw_gradical()
                vectorscope->draw_radient(th, 0.1f, .75f, dark_color);
        }
        else if( use_vector < 0 ) {
-               if( grad_image && grad_idx != vector_gradical ) {
+               if( grad_image && grad_idx != use_graticule ) {
                        delete grad_image;   grad_image = 0;
-                       vector_gradical = 0;
+                       use_graticule = 0;
                }
                if( !grad_image && grad_idx > 0 ) {
                        grad_image = VFramePng::vframe_png(grad_paths[grad_idx]);
                }
                int rr = 2*radius;
-               if( grad_pixmap && (!vector_gradical ||
+               if( grad_pixmap && (!use_graticule ||
                      rr != grad_pixmap->get_w() || rr != grad_pixmap->get_h()) ) {
                        delete grad_pixmap;  grad_pixmap = 0;
-                       vector_gradical = 0;
+                       use_graticule = 0;
                }
                if( !grad_pixmap && grad_image ) {
                        VFrame grad(rr, rr, BC_RGBA8888);
                        grad.transfer_from(grad_image);
                        grad_pixmap = new BC_Pixmap(this, &grad, PIXMAP_ALPHA);
-                       vector_gradical = grad_idx;
+                       use_graticule = grad_idx;
                }
                if( grad_pixmap ) {
                        int px = vector_cx - radius, py = vector_cy - radius;
@@ -855,15 +862,17 @@ void ScopeGUI::draw_gradical()
 }
 
 
-void ScopeGUI::update_gradical(int idx)
+void ScopeGUI::update_graticule(int idx)
 {
        grad_idx = idx;
        update_scope();
+       toggle_event();
 }
 
 void ScopeGUI::draw_colorwheel(VFrame *dst, int bg_color)
 {
-       float cx = vector_cx, cy = vector_cy, rad = radius;
+// downfactor radius to prevent extreme edge from showing behind graticule
+       float cx = vector_cx, cy = vector_cy, rad = radius * 0.99;
         int color_model = dst->get_color_model();
         int bpp = BC_CModels::calculate_pixelsize(color_model);
        int bg_r = (bg_color>>16) & 0xff;
@@ -1298,7 +1307,7 @@ void ScopeMenu::update_toggles()
 
 
 ScopeVectGrads::ScopeVectGrads(ScopeGUI *gui, int x, int y)
- : BC_PopupMenu(x, y, xS(40), "", 1, 0, 0)
+ : BC_PopupMenu(x, y, _("Overlay"))
 {
        this->gui = gui;
 }
@@ -1309,10 +1318,10 @@ void ScopeVectGrads::create_objects()
        gui->grad_paths.remove_all_objects();
        ScopeGradItem *item;
        add_item(item = new ScopeGradItem(this, _("none"), 0));
-       if( item->idx == gui->vector_gradical ) item->set_checked(1);
+       if( item->idx == gui->grad_idx ) item->set_checked(1);
        gui->grad_paths.append(0);
        FileSystem fs;
-       fs.set_filter("[*.png][*.jpg]");
+       fs.set_filter("[*.png]");
        char scope_path[BCTEXTLEN];
        sprintf(scope_path, "%s%s", File::get_plugin_path(), SCOPE_SEARCHPATH);
        fs.update(scope_path);
@@ -1323,7 +1332,7 @@ void ScopeVectGrads::create_objects()
                char *cp = strrchr(scope_path, '.');
                if( cp ) *cp = 0;
                add_item(item = new ScopeGradItem(this, scope_path, gui->grad_paths.size()));
-               if( item->idx == gui->vector_gradical ) item->set_checked(1);
+               if( item->idx == gui->grad_idx ) item->set_checked(1);
                gui->grad_paths.append(cstrdup(file_item->get_path()));
        }
 }
@@ -1339,9 +1348,9 @@ int ScopeGradItem::handle_event()
 {
        for( int i=0,n=vect_grads->total_items(); i<n; ++i ) {
                ScopeGradItem *item = (ScopeGradItem *)vect_grads->get_item(i);
-               item->set_checked(item == this);
+               item->set_checked(item->idx == idx);
        }       
-       vect_grads->gui->update_gradical(idx);
+       vect_grads->gui->update_graticule(idx);
        return 1;
 }
 
index 44b2f8fd80503b803480384d3cc7ceb014a15638..5ecd4ef1a7fc1f66f6ac5eb9d7c83e23b3366b8f 100644 (file)
@@ -279,9 +279,9 @@ public:
        void calculate_sizes(int w, int h);
        void allocate_vframes();
        void draw_overlays(int overlays, int borders, int flush);
-       void update_gradical(int idx);
+       void update_graticule(int idx);
        void draw_colorwheel(VFrame *dst, int bg_color);
-       void draw_gradical();
+       void draw_graticule();
        void process(VFrame *output_frame);
        void draw(int flash, int flush);
        void clear_points(int flash);
@@ -314,7 +314,7 @@ public:
        int text_color, dark_color;
 
        ScopeGradPaths grad_paths;
-       int grad_idx, vector_gradical;
+       int grad_idx, use_graticule;
 
        int cpus;
        int use_hist, use_wave, use_vector;
diff --git a/cinelerra-5.1/plugins/scopes/grid.png b/cinelerra-5.1/plugins/scopes/grid.png
new file mode 100644 (file)
index 0000000..a50ffde
Binary files /dev/null and b/cinelerra-5.1/plugins/scopes/grid.png differ
index e662dacbf65518e4ff5d947f2f3840122b334940..f831a80919fb1110f48854c9bcb178815657ee51 100644 (file)
@@ -77,7 +77,8 @@ public:
 
        int use_hist, use_wave, use_vector;
        int use_hist_parade, use_wave_parade;
-       int use_wave_gain, use_vect_gain, use_smooth;
+       int use_wave_gain, use_vect_gain;
+       int use_smooth, use_graticule;
 
        int w, h;
        VFrame *input;
@@ -108,6 +109,7 @@ void VideoScopeWindow::create_objects()
        use_wave_gain = plugin->use_wave_gain;
        use_vect_gain = plugin->use_vect_gain;
        use_smooth = plugin->use_smooth;
+       use_graticule = plugin->use_graticule;
 
        ScopeGUI::create_objects();
 }
@@ -122,6 +124,7 @@ void VideoScopeWindow::toggle_event()
        plugin->use_wave_gain = use_wave_gain;
        plugin->use_vect_gain = use_vect_gain;
        plugin->use_smooth = use_smooth;
+       plugin->use_graticule = use_graticule;
 // Make it reprocess
        plugin->send_configure_change();
 }
@@ -152,6 +155,7 @@ VideoScopeEffect::VideoScopeEffect(PluginServer *server)
        use_wave_gain = 5;
        use_vect_gain = 5;
        use_smooth = 1;
+       use_graticule = 0;
 }
 
 VideoScopeEffect::~VideoScopeEffect()
@@ -184,6 +188,7 @@ void VideoScopeEffect::save_data(KeyFrame *keyframe)
                output.tag.set_property("USE_WAVE_GAIN", use_wave_gain);
                output.tag.set_property("USE_VECT_GAIN", use_vect_gain);
                output.tag.set_property("USE_SMOOTH", use_smooth);
+               output.tag.set_property("USE_GRATICULE", use_graticule);
 
        }
        output.append_tag();
@@ -212,6 +217,7 @@ void VideoScopeEffect::read_data(KeyFrame *keyframe)
                                use_wave_gain = input.tag.get_property("USE_WAVE_GAIN", use_wave_gain);
                                use_vect_gain = input.tag.get_property("USE_VECT_GAIN", use_vect_gain);
                                use_smooth = input.tag.get_property("USE_SMOOTH", use_smooth);
+                               use_graticule = input.tag.get_property("USE_GRATICULE", use_graticule);
                        }
                }
        }