add mask smooth boundary
authorGood Guy <[email protected]>
Fri, 5 Jul 2019 00:14:27 +0000 (18:14 -0600)
committerGood Guy <[email protected]>
Fri, 5 Jul 2019 00:14:27 +0000 (18:14 -0600)
cinelerra-5.1/cinelerra/cwindowtool.C
cinelerra-5.1/cinelerra/cwindowtool.h
cinelerra-5.1/cinelerra/cwindowtool.inc

index 10aab69c21591c23dde5eee3eba2e9f5568941f2..1c715f9d248886404b57013a44a76d4af01d470e 100644 (file)
@@ -2316,6 +2316,33 @@ int CWindowMaskGangFocus::handle_event()
        return 1;
 }
 
+
+CWindowMaskSmooth::CWindowMaskSmooth(MWindow *mwindow,
+               CWindowMaskGUI *gui, int x, int y)
+ : BC_GenericButton(x, y, _("Smooth"))
+{
+       this->mwindow = mwindow;
+       this->gui = gui;
+       set_tooltip(_("Smooth boundary"));
+}
+int CWindowMaskSmooth::handle_event()
+{
+       return gui->smooth_mask(0);
+}
+
+CWindowMaskGangSmooth::CWindowMaskGangSmooth(MWindow *mwindow,
+               CWindowMaskGUI *gui, int x, int y)
+ : BC_Button(x, y, mwindow->theme->get_image_set("gangpatch_data"))
+{
+       this->mwindow = mwindow;
+       this->gui = gui;
+       set_tooltip(_("Smooth All"));
+}
+int CWindowMaskGangSmooth::handle_event()
+{
+       return gui->smooth_mask(1);
+}
+
 CWindowMaskBeforePlugins::CWindowMaskBeforePlugins(CWindowMaskGUI *gui, int x, int y)
  : BC_CheckBox(x,
        y,
@@ -2579,6 +2606,8 @@ void CWindowMaskGUI::create_objects()
        float cy = mwindow->edl->session->output_h / 2.f;
        focus_y = new CWindowCoord(this, x1, y, cy);
        focus_y->create_objects();
+       add_subwindow(smooth = new CWindowMaskSmooth(mwindow, this, del_x, y));
+       add_subwindow(gang_smooth = new CWindowMaskGangSmooth(mwindow, this, clr_x, y));
        y += focus_x->get_h() + 2*margin;
        BC_Bar *bar;
        add_subwindow(bar = new BC_Bar(x, y, get_w()-2*x));
@@ -2595,11 +2624,11 @@ void CWindowMaskGUI::create_objects()
                "Shift+LMB: move an end point\n"
                "Ctrl+LMB: move a control point\n"
                "Alt+LMB: to drag translate the mask\n"
-               "Shift+Key Delete to delete the point\n"
+               "Shift+Key Delete: to delete the point\n"
                "Shift+MMB: Set Pivot Point at pointer\n"
                "Wheel: rotate around Pivot Point\n"
                "Shift+Wheel: scale around Pivot Point\n"
-               "Ctrl Wheel: rotate/scale around pointer")));
+               "Ctrl+Wheel: rotate/scale around pointer")));
        help_h = y + title->get_h() + 2*margin;
        update();
        resize_window(get_w(), help_y);
@@ -2768,6 +2797,59 @@ void CWindowMaskGUI::update_buttons(MaskAuto *keyframe, int k)
        }
 }
 
+int CWindowMaskGUI::smooth_mask(int gang)
+{
+       MaskAutos *autos;
+       MaskAuto *keyframe;
+       Track *track;
+       MaskPoint *point;
+       SubMask *mask;
+#ifdef USE_KEYFRAME_SPANNING
+       int create_it = 0;
+#else
+       int create_it = 1;
+#endif
+
+       mwindow->undo->update_undo_before(_("mask smooth"), this);
+
+// Get existing keyframe
+       get_keyframe(track, autos, keyframe,
+                       mask, point, create_it);
+       if( track ) {
+#ifdef USE_KEYFRAME_SPANNING
+               MaskAuto temp_keyframe(mwindow->edl, autos);
+               temp_keyframe.copy_data(keyframe);
+               keyframe = &temp_keyframe;
+#endif
+               int k = mwindow->edl->session->cwindow_mask;
+               int n = gang ? keyframe->masks.size() : k+1;
+               for( int j=gang? 0 : k; j<n; ++j ) {
+                       SubMask *sub_mask = keyframe->get_submask(j);
+                       ArrayList<MaskPoint*> &points = sub_mask->points;
+                       int psz = points.size();
+                       if( psz < 3 ) continue;
+                       for( int i=0; i<psz; ++i ) {
+                               int i0 = i-1, i1 = i+1;
+                               if( i0 < 0 ) i0 = psz-1;
+                               if( i1 >= psz ) i1 = 0;
+                               MaskPoint *p0 = points[i0];
+                               MaskPoint *p  = points[i];
+                               MaskPoint *p1 = points[i1];
+                               float dx = p1->x - p0->x, dy = p1->y - p0->y;
+                               p->control_x1 = -dx/4;  p->control_y1 = -dy/4;
+                               p->control_x2 =  dx/4;  p->control_y2 =  dy/4;
+                       }
+               }
+#ifdef USE_KEYFRAME_SPANNING
+               autos->update_parameter(keyframe);
+#endif
+               update_preview();
+       }
+
+       mwindow->undo->update_undo_after(_("mask smooth"), LOAD_AUTOMATION);
+       return 1;
+}
+
 CWindowRulerGUI::CWindowRulerGUI(MWindow *mwindow, CWindowTool *thread)
  : CWindowToolGUI(mwindow, thread, _(PROGRAM_NAME ": Ruler"), 320, 240)
 {
index 951d30e4d36c6c5c61ca2ebe430a92323f8b3c57..5654e8825cd7b181f2c76bbdb0a546800780b02d 100644 (file)
@@ -323,6 +323,26 @@ public:
        CWindowMaskGUI *gui;
 };
 
+class CWindowMaskSmooth : public BC_GenericButton
+{
+public:
+       CWindowMaskSmooth(MWindow *mwindow, CWindowMaskGUI *gui,
+                       int x, int y);
+       int handle_event();
+       MWindow *mwindow;
+       CWindowMaskGUI *gui;
+};
+
+class CWindowMaskGangSmooth : public BC_Button
+{
+public:
+       CWindowMaskGangSmooth(MWindow *mwindow, CWindowMaskGUI *gui,
+                       int x, int y);
+       int handle_event();
+       MWindow *mwindow;
+       CWindowMaskGUI *gui;
+};
+
 class CWindowMaskAffectedPoint : public BC_TumbleTextBox
 {
 public:
@@ -456,9 +476,10 @@ public:
        void update();
        int close_event();
        void done_event();
+       void handle_event();
        void set_focused(int v, float cx, float cy);
        void update_buttons(MaskAuto *keyframe, int k);
-       void handle_event();
+       int smooth_mask(int gang);
        void get_keyframe(Track* &track, MaskAutos* &autos, MaskAuto* &keyframe,
                SubMask* &mask, MaskPoint* &point, int create_it);
 
@@ -482,6 +503,8 @@ public:
        CWindowMaskFocus *focus;
        int focused;
        CWindowMaskGangFocus *gang_focus;
+       CWindowMaskSmooth *smooth;
+       CWindowMaskGangSmooth *gang_smooth;
        CWindowMaskHelp *help;
        int helped, help_y, help_h;
        CWindowMaskDrawMarkers *draw_markers;
index 444460e67098104dbae8e7a945536ffb164e90a7..c1a2107c7cc3cb68aa1ed68f56aa054921a0d0a5 100644 (file)
@@ -43,8 +43,11 @@ class CWindowMaskFade;
 class CWindowMaskFadeSlider;
 class CWindowMaskGangFader;
 class CWindowMaskGangFocus;
+class CWindowMaskSmooth;
+class CWindowMaskGangSmooth;
 class CWindowMaskAffectedPoint;
 class CWindowMaskFocus;
+class CWindowMaskHelp;
 class CWindowMaskDrawMarkers;
 class CWindowMaskDrawBoundary;
 class CWindowMaskDelPoint;