From: Good Guy Date: Tue, 3 Apr 2018 00:56:01 +0000 (-0600) Subject: compositor f1-f10/j/p shortcuts, opencv upgrade, new stylize,puzzle opencv plugins X-Git-Url: https://git.cinelerra-gg.org/git/?a=commitdiff_plain;h=9d8694b7d2e0f4202e025eaf78d096340184b4e6;p=goodguy%2Fhistory.git compositor f1-f10/j/p shortcuts, opencv upgrade, new stylize,puzzle opencv plugins --- diff --git a/cinelerra-5.1/cinelerra/cwindowgui.C b/cinelerra-5.1/cinelerra/cwindowgui.C index 37dd35bf..d7bcf789 100644 --- a/cinelerra-5.1/cinelerra/cwindowgui.C +++ b/cinelerra-5.1/cinelerra/cwindowgui.C @@ -219,14 +219,7 @@ void CWindowGUI::create_objects() tool_panel = new CWindowTool(mwindow, this); tool_panel->Thread::start(); - set_operation(mwindow->edl->session->cwindow_operation); - - - - canvas->draw_refresh(0); - - draw_status(0); unlock_window(); } @@ -425,15 +418,26 @@ void CWindowGUI::zoom_canvas(double value, int update_menu) canvas->draw_refresh(); } - - void CWindowGUI::set_operation(int value) { - mwindow->edl->session->cwindow_operation = value; + switch( value ) { + case CWINDOW_TOOL_WINDOW: + mwindow->edl->session->tool_window = !mwindow->edl->session->tool_window; + composite_panel->operation[CWINDOW_TOOL_WINDOW]->update(mwindow->edl->session->tool_window); + tool_panel->update_show_window(); + return; + case CWINDOW_TITLESAFE: + mwindow->edl->session->safe_regions = !mwindow->edl->session->safe_regions; + composite_panel->operation[CWINDOW_TITLESAFE]->update(mwindow->edl->session->safe_regions); + value = mwindow->edl->session->cwindow_operation; + break; + default: + mwindow->edl->session->cwindow_operation = value; + composite_panel->set_operation(value); + break; + } - composite_panel->set_operation(value); edit_panel->update(); - tool_panel->start_tool(value); canvas->draw_refresh(); } @@ -453,6 +457,7 @@ int CWindowGUI::close_event() int CWindowGUI::keypress_event() { int result = 0; + int cwindow_operation = CWINDOW_NONE; switch(get_keypress()) { @@ -556,6 +561,21 @@ int CWindowGUI::keypress_event() } break; + case KEY_F1: cwindow_operation = CWINDOW_PROTECT; break; + case KEY_F2: cwindow_operation = CWINDOW_ZOOM; break; + case KEY_F3: cwindow_operation = CWINDOW_MASK; break; + case KEY_F4: cwindow_operation = CWINDOW_RULER; break; + case KEY_F5: cwindow_operation = CWINDOW_CAMERA; break; + case KEY_F6: cwindow_operation = CWINDOW_PROJECTOR; break; + case KEY_F7: cwindow_operation = CWINDOW_CROP; break; + case KEY_F8: cwindow_operation = CWINDOW_EYEDROP; break; + case KEY_F9: cwindow_operation = CWINDOW_TOOL_WINDOW; break; + case KEY_F10: cwindow_operation = CWINDOW_TITLESAFE; break; + } + + if( cwindow_operation >= 0 ) { + set_operation(cwindow_operation); + result = 1; } if(!result) result = transport->keypress_event(); diff --git a/cinelerra-5.1/cinelerra/cwindowtool.C b/cinelerra-5.1/cinelerra/cwindowtool.C index f3fda9a4..cb3a1d7e 100644 --- a/cinelerra-5.1/cinelerra/cwindowtool.C +++ b/cinelerra-5.1/cinelerra/cwindowtool.C @@ -289,9 +289,28 @@ int CWindowToolGUI::close_event() int CWindowToolGUI::keypress_event() { - if(get_keypress() == 'w' || get_keypress() == 'W') + int result = 0; + int cwindow_operation = CWINDOW_NONE; + + switch( get_keypress() ) { + case 'w': + case 'W': return close_event(); - return 0; + case KEY_F1: + case KEY_F2: + case KEY_F3: + case KEY_F4: + case KEY_F5: + case KEY_F6: + case KEY_F7: + case KEY_F8: + case KEY_F9: + case KEY_F10: + resend_event(thread->gui); + result = 1; + } + + return result; } int CWindowToolGUI::translation_event() diff --git a/cinelerra-5.1/cinelerra/editpanel.C b/cinelerra-5.1/cinelerra/editpanel.C index 75ee8d42..32b2e848 100644 --- a/cinelerra-5.1/cinelerra/editpanel.C +++ b/cinelerra-5.1/cinelerra/editpanel.C @@ -979,7 +979,7 @@ EditClick2Play::EditClick2Play(MWindow *mwindow, EditPanel *panel, int x, int y) { this->mwindow = mwindow; this->panel = panel; - set_tooltip(_("Click to play")); + set_tooltip(_("Click to play (p)")); } int EditClick2Play::handle_event() { @@ -990,6 +990,21 @@ int EditClick2Play::handle_event() mwindow->edl->session->vwindow_click2play = value; return 1; } +int EditClick2Play::keypress_event() +{ + int key = get_keypress(); + if( key == 'p' && !ctrl_down() && !shift_down() && !alt_down() ) { + int value = get_value() ? 0 : 1; + update(value); + if( !panel->is_vwindow() ) + mwindow->edl->session->cwindow_click2play = value; + else + mwindow->edl->session->vwindow_click2play = value; + return 1; + } + return 0; +} + EditCommercial::EditCommercial(MWindow *mwindow, EditPanel *panel, int x, int y) : BC_Button(x, y, mwindow->theme->get_image_set("commercial")) @@ -1353,7 +1368,7 @@ KeyFrameButton::KeyFrameButton(MWindow *mwindow, EditPanel *panel, int x, int y) { this->mwindow = mwindow; this->panel = panel; - set_tooltip(_("Generate keyframes while tweeking")); + set_tooltip(_("Generate keyframes while tweeking (j)")); } int KeyFrameButton::handle_event() @@ -1363,6 +1378,18 @@ int KeyFrameButton::handle_event() return 1; } +int KeyFrameButton::keypress_event() +{ + int key = get_keypress(); + if( key == 'j' && !ctrl_down() && !shift_down() && !alt_down() ) { + int value = get_value() ? 0 : 1; + update(value); + mwindow->set_auto_keyframes(value, + !panel->is_mwindow(), panel->is_mwindow()); + return 1; + } + return 0; +} LockLabelsButton::LockLabelsButton(MWindow *mwindow, int x, int y) : BC_Toggle(x, y, diff --git a/cinelerra-5.1/cinelerra/editpanel.h b/cinelerra-5.1/cinelerra/editpanel.h index 47b703be..67ce8a1e 100644 --- a/cinelerra-5.1/cinelerra/editpanel.h +++ b/cinelerra-5.1/cinelerra/editpanel.h @@ -173,6 +173,7 @@ public: EditClick2Play(); int handle_event(); + int keypress_event(); MWindow *mwindow; EditPanel *panel; @@ -380,6 +381,7 @@ class KeyFrameButton : public BC_Toggle public: KeyFrameButton(MWindow *mwindow, EditPanel *panel, int x, int y); int handle_event(); + int keypress_event(); MWindow *mwindow; EditPanel *panel; }; diff --git a/cinelerra-5.1/cinelerra/mwindowgui.C b/cinelerra-5.1/cinelerra/mwindowgui.C index d1aea0fc..f7cd97cd 100644 --- a/cinelerra-5.1/cinelerra/mwindowgui.C +++ b/cinelerra-5.1/cinelerra/mwindowgui.C @@ -1039,7 +1039,7 @@ int MWindowGUI::drag_stop() } -//printf("TrackCanvas::drag_stop %d %d\n", redraw, mwindow->session->current_operation); +//printf("MWindowGUI::drag_stop %d %d\n", redraw, mwindow->session->current_operation); if(redraw) { mwindow->edl->tracks->update_y_pixels(mwindow->theme); @@ -1162,6 +1162,8 @@ int MWindowGUI::keypress_event() int result = mbuttons->keypress_event(); if( result ) return result; + Track *this_track = 0; + switch(get_keypress()) { case 'e': mwindow->toggle_editing_mode(); @@ -1263,7 +1265,6 @@ int MWindowGUI::keypress_event() case TAB: case LEFTTAB: - Track *this_track = 0; for( int i=0; iover_track()) != 0 ) break; @@ -1287,10 +1288,23 @@ int MWindowGUI::keypress_event() update(0, 1, 0, 0, 1, 0, 1); unlock_window(); mwindow->cwindow->update(0, 1, 1); - lock_window("TrackCanvas::keypress_event 3"); + lock_window("MWindowGUI::keypress_event 3"); result = 1; break; + + case KEY_F1: + case KEY_F2: + case KEY_F3: + case KEY_F4: + case KEY_F5: + case KEY_F6: + case KEY_F7: + case KEY_F8: + case KEY_F9: + case KEY_F10: + resend_event(mwindow->cwindow->gui); + return 1; } // since things under cursor have changed... diff --git a/cinelerra-5.1/cinelerra/setformat.C b/cinelerra-5.1/cinelerra/setformat.C index b70f6882..bf22103f 100644 --- a/cinelerra-5.1/cinelerra/setformat.C +++ b/cinelerra-5.1/cinelerra/setformat.C @@ -279,22 +279,18 @@ void SetFormatThread::update_aspect() SetFormatWindow::SetFormatWindow(MWindow *mwindow, - SetFormatThread *thread, - int x, - int y) - : BC_Window(_(PROGRAM_NAME ": Set Format"), - x, - y, - mwindow->theme->setformat_w, - mwindow->theme->setformat_h, - -1, - -1, - 0, - 0, - 1) + SetFormatThread *thread, int x, int y) + : BC_Window(_(PROGRAM_NAME ": Set Format"), x, y, + mwindow->theme->setformat_w, mwindow->theme->setformat_h, + -1, -1, 0, 0, 1) { this->mwindow = mwindow; this->thread = thread; + presets = 0; +} +SetFormatWindow::~SetFormatWindow() +{ + delete presets; } void SetFormatWindow::create_objects() diff --git a/cinelerra-5.1/cinelerra/setformat.h b/cinelerra-5.1/cinelerra/setformat.h index 89ede118..b85fce17 100644 --- a/cinelerra-5.1/cinelerra/setformat.h +++ b/cinelerra-5.1/cinelerra/setformat.h @@ -202,11 +202,8 @@ public: class FormatSwapExtents : public BC_Button { public: - FormatSwapExtents(MWindow *mwindow, - SetFormatThread *thread, - SetFormatWindow *gui, - int x, - int y); + FormatSwapExtents(MWindow *mwindow, SetFormatThread *thread, + SetFormatWindow *gui, int x, int y); int handle_event(); MWindow *mwindow; SetFormatThread *thread; @@ -217,9 +214,8 @@ class SetFormatWindow : public BC_Window { public: SetFormatWindow(MWindow *mwindow, - SetFormatThread *thread, - int x, - int y); + SetFormatThread *thread, int x, int y); + ~SetFormatWindow(); void create_objects(); const char* get_preset_text(); diff --git a/cinelerra-5.1/guicast/bcwindowbase.C b/cinelerra-5.1/guicast/bcwindowbase.C index f9eb98f2..5b133106 100644 --- a/cinelerra-5.1/guicast/bcwindowbase.C +++ b/cinelerra-5.1/guicast/bcwindowbase.C @@ -255,6 +255,7 @@ int BC_WindowBase::initialize() keys_return[0] = 0; is_deleting = 0; window_lock = 0; + resend_event_window = 0; x = 0; y = 0; w = 0; @@ -1254,6 +1255,18 @@ locking_message = event->xclient.message_type; case XK_KP_Insert: key_pressed = KPINS; break; case XK_KP_Decimal: case XK_KP_Delete: key_pressed = KPDEL; break; + + case XK_F1: key_pressed = KEY_F1; break; + case XK_F2: key_pressed = KEY_F2; break; + case XK_F3: key_pressed = KEY_F3; break; + case XK_F4: key_pressed = KEY_F4; break; + case XK_F5: key_pressed = KEY_F5; break; + case XK_F6: key_pressed = KEY_F6; break; + case XK_F7: key_pressed = KEY_F7; break; + case XK_F8: key_pressed = KEY_F8; break; + case XK_F9: key_pressed = KEY_F9; break; + case XK_F10: key_pressed = KEY_F10; break; + case XK_Menu: key_pressed = KPMENU; break; /* menu */ // remote control // above case XK_KP_Enter: key_pressed = KPENTER; break; /* check */ @@ -1351,7 +1364,14 @@ locking_message = event->xclient.message_type; #ifndef SINGLE_THREAD unlock_window(); - if(event) delete event; + if(event) { + if( resend_event_window ) { + resend_event_window->put_event(event); + resend_event_window = 0; + } + else + delete event; + } #else // if(done) completion_lock->unlock(); #endif @@ -4473,6 +4493,20 @@ void BC_WindowBase::dequeue_events(Window win) event_lock->unlock(); } +int BC_WindowBase::resend_event(BC_WindowBase *window) +{ + if( resend_event_window ) return 1; + resend_event_window = window; + return 0; +} + +#else + +int BC_WindowBase::resend_event(BC_WindowBase *window) +{ + return 1; +} + #endif // SINGLE_THREAD int BC_WindowBase::get_id() diff --git a/cinelerra-5.1/guicast/bcwindowbase.h b/cinelerra-5.1/guicast/bcwindowbase.h index 82e6d57c..5d17e5ee 100644 --- a/cinelerra-5.1/guicast/bcwindowbase.h +++ b/cinelerra-5.1/guicast/bcwindowbase.h @@ -224,7 +224,6 @@ public: int get_deleting(); - //============================= OpenGL functions =============================== // OpenGL functions must be called from inside a BC_Synchronous command. // Create openGL context and bind it to the current window. @@ -269,6 +268,7 @@ public: virtual int keyboard_listener(BC_WindowBase *wp) { return 0; } void add_keyboard_listener(int(BC_WindowBase::*handler)(BC_WindowBase *)); void del_keyboard_listener(int(BC_WindowBase::*handler)(BC_WindowBase *)); + int resend_event(BC_WindowBase *window); // Dimensions virtual int get_w() { return w; } virtual int get_h() { return h; } @@ -658,6 +658,8 @@ private: BC_PopupMenu* active_popup_menu; // pointer to the active subwindow BC_WindowBase* active_subwindow; +// pointer to the window to which to put the current event + BC_WindowBase* resend_event_window; // thread id of display locker pthread_t display_lock_owner; diff --git a/cinelerra-5.1/guicast/keys.h b/cinelerra-5.1/guicast/keys.h index d15c1241..c48ee590 100644 --- a/cinelerra-5.1/guicast/keys.h +++ b/cinelerra-5.1/guicast/keys.h @@ -34,7 +34,6 @@ #define BACKSPACE 262 #define ESC 263 #define TAB 264 - // Number pad keys #define KPPLUS 265 #define KPMINUS 266 @@ -115,6 +114,17 @@ #define KPRECD 297 #define KPSTOP 298 #define KPAUSE 299 +// function keys +#define KEY_F1 301 +#define KEY_F2 302 +#define KEY_F3 303 +#define KEY_F4 304 +#define KEY_F5 305 +#define KEY_F6 306 +#define KEY_F7 307 +#define KEY_F8 308 +#define KEY_F9 309 +#define KEY_F10 310 #define RETURN 13 #define NEWLINE 13 diff --git a/cinelerra-5.1/opencv_build b/cinelerra-5.1/opencv_build index 86d96d1c..097e97f5 100644 --- a/cinelerra-5.1/opencv_build +++ b/cinelerra-5.1/opencv_build @@ -80,8 +80,8 @@ $(opencv)/build: $(opencv).src -DOPENCV_EXTRA_MODULES_PATH="$(opencv)_contrib/modules/" LFLAGS += -Wl,--start-group -LFLAGS += $(shell ls -1 $(opencv_prefix)/lib/libopencv_*.a 2> /dev/null) -LFLAGS += $(shell ls -1 $(opencv_prefix)/share/OpenCV/3rdparty/lib/lib*.a 2> /dev/null) +LFLAGS += $(shell ls -1 $(opencv_prefix)/lib*/libopencv_*.a 2> /dev/null) +LFLAGS += $(shell ls -1 $(opencv_prefix)/share/OpenCV/3rdparty/lib*/lib*.a 2> /dev/null) LFLAGS += -Wl,--end-group else ifeq ($(bld),dyn) $(opencv)/build: $(opencv).src diff --git a/cinelerra-5.1/plugin_defs b/cinelerra-5.1/plugin_defs index ecf3dc9b..8f6e6c4c 100644 --- a/cinelerra-5.1/plugin_defs +++ b/cinelerra-5.1/plugin_defs @@ -23,7 +23,8 @@ colors := brightness bluebanana C41 color3way colorbalance huesaturation \ gamma gradient histeq histogram histogram_bezier threshold plugin_dirs += exotic -exotic := aging burn dot holo oil edge spherecam +exotic := aging burn dot holo oil edge spherecam \ + findobj flowobj gaborobj moveobj stylizeobj puzzleobj plugin_dirs += audio_tools audio_tools := audioscope cdripper compressor dcoffset delayaudio \ @@ -40,7 +41,7 @@ video_tools := blur decimate delayvideo denoisemjpeg denoisevideo downsample \ motion2 motionblur motion motion-cv motion-hv motion51 \ overlay radialblur reframe reframert reroute reversevideo \ rumbler seltempavg sharpen svg titler timeavg timefront \ - unsharp videoscope wave zoomblur findobject descratch + unsharp videoscope wave zoomblur descratch plugin_dirs += blending blending := crikey chromakeyhsv chromakey diffkey diff --git a/cinelerra-5.1/plugins/Makefile b/cinelerra-5.1/plugins/Makefile index e86526ab..bd7d8591 100644 --- a/cinelerra-5.1/plugins/Makefile +++ b/cinelerra-5.1/plugins/Makefile @@ -8,7 +8,7 @@ endif ifneq ($(WANT_OPENCV), no) want_var:=$(WANT_OPENCV) include $(TOPDIR)/opencv_build -OPENCV_OBJS := findobj flowobj gaborobj moveobj +OPENCV_OBJS := findobj flowobj gaborobj moveobj stylizeobj puzzleobj $(OPENCV_OBJS): opencv endif diff --git a/cinelerra-5.1/plugins/flowobj/flowobj.C b/cinelerra-5.1/plugins/flowobj/flowobj.C index 9ebeb4f9..1f991e6c 100644 --- a/cinelerra-5.1/plugins/flowobj/flowobj.C +++ b/cinelerra-5.1/plugins/flowobj/flowobj.C @@ -272,7 +272,7 @@ int FlowObj::process_buffer(VFrame *frame, int64_t start_position, double frame_ goodFeaturesToTrack(next_mat, *next_corners, corner_count, 0.01, // quality_level min_distance, noArray(), block_size, - 0, // use_harris + false, // use_harris 0.04); // k if( !next_mat.empty() && next_corners->size() > 3 ) { diff --git a/cinelerra-5.1/plugins/moveobj/moveobj.C b/cinelerra-5.1/plugins/moveobj/moveobj.C index 4f5fd0fd..e6457555 100644 --- a/cinelerra-5.1/plugins/moveobj/moveobj.C +++ b/cinelerra-5.1/plugins/moveobj/moveobj.C @@ -255,7 +255,7 @@ int MoveObj::process_buffer(VFrame *frame, int64_t start_position, double frame_ goodFeaturesToTrack(next_mat, *next_corners, corner_count, 0.01, // quality_level min_distance, noArray(), block_size, - 0, // use_harris + false, // use_harris 0.04); // k ptV pt1, pt2; diff --git a/cinelerra-5.1/plugins/puzzleobj/Makefile b/cinelerra-5.1/plugins/puzzleobj/Makefile new file mode 100644 index 00000000..65484d95 --- /dev/null +++ b/cinelerra-5.1/plugins/puzzleobj/Makefile @@ -0,0 +1,21 @@ +default: all + +TOPDIR?=../.. +include $(TOPDIR)/plugin_defs + +PLUGIN = puzzleobj + +OBJS := \ + $(OBJDIR)/puzzleobj.o \ + $(OBJDIR)/puzzleobjwindow.o \ + +want_var:=$(WANT_OPENCV) +include $(TOPDIR)/opencv_build +include $(TOPDIR)/plugin_config + +all: opencv + +make $(OUTPUT) + +$(OBJDIR)/puzzleobj.o: puzzleobj.C puzzleobj.h puzzleobjwindow.h +$(OBJDIR)/puzzleobjwindow.o: puzzleobjwindow.C puzzleobj.h puzzleobjwindow.h + diff --git a/cinelerra-5.1/plugins/puzzleobj/puzzleobj.C b/cinelerra-5.1/plugins/puzzleobj/puzzleobj.C new file mode 100644 index 00000000..6861becb --- /dev/null +++ b/cinelerra-5.1/plugins/puzzleobj/puzzleobj.C @@ -0,0 +1,222 @@ +/* + * CINELERRA + * Copyright (C) 1997-2014 Adam Williams + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "clip.h" +#include "filexml.h" +#include "puzzleobj.h" +#include "puzzleobjwindow.h" +#include "language.h" +#include "mutex.h" + +REGISTER_PLUGIN(PuzzleObj) + + +PuzzleObjConfig::PuzzleObjConfig() +{ + pixels = 400; + iterations = 10; +} + +int PuzzleObjConfig::equivalent(PuzzleObjConfig &that) +{ + return 1; +} + +void PuzzleObjConfig::copy_from(PuzzleObjConfig &that) +{ +} + +void PuzzleObjConfig::interpolate( PuzzleObjConfig &prev, PuzzleObjConfig &next, + long prev_frame, long next_frame, long current_frame) +{ + copy_from(next); +} + +void PuzzleObjConfig::limits() +{ +} + + +PuzzleObj::PuzzleObj(PluginServer *server) + : PluginVClient(server) +{ + ss_width = 0; ss_height = 0; ss_channels = 0; + ss_pixels = 0; ss_levels = 0; ss_prior = 0; + ss_hist_bins = 0; +} + +PuzzleObj::~PuzzleObj() +{ +} + +const char* PuzzleObj::plugin_title() { return N_("PuzzleObj"); } +int PuzzleObj::is_realtime() { return 1; } + +NEW_WINDOW_MACRO(PuzzleObj, PuzzleObjWindow); +LOAD_CONFIGURATION_MACRO(PuzzleObj, PuzzleObjConfig) + +void PuzzleObj::save_data(KeyFrame *keyframe) +{ + FileXML output; + +// cause data to be stored directly in text + output.set_shared_output(keyframe->get_data(), MESSAGESIZE); + output.tag.set_title("PUZZLEOBJ"); + output.tag.set_property("PIXELS", config.pixels); + output.tag.set_property("ITERATIONS", config.iterations); + output.append_tag(); + output.append_newline(); + output.tag.set_title("/PUZZLEOBJ"); + output.append_tag(); + output.append_newline(); + output.terminate_string(); +} + +void PuzzleObj::read_data(KeyFrame *keyframe) +{ + FileXML input; + input.set_shared_input(keyframe->get_data(), strlen(keyframe->get_data())); + + int result = 0; + while( !(result = input.read_tag()) ) { + if( input.tag.title_is("PUZZLEOBJ") ) { + config.pixels = input.tag.get_property("PIXELS", config.pixels); + config.iterations = input.tag.get_property("ITERATIONS", config.iterations); + config.limits(); + } + else if( input.tag.title_is("/PUZZLEOBJ") ) + result = 1; + } +} + +void PuzzleObj::update_gui() +{ + if( !thread ) return; + if( !load_configuration() ) return; + thread->window->lock_window("PuzzleObj::update_gui"); + PuzzleObjWindow *window = (PuzzleObjWindow*)thread->window; + window->unlock_window(); +} + +void PuzzleObj::to_mat(Mat &mat, int mcols, int mrows, + VFrame *inp, int ix,int iy, int mcolor_model) +{ + int mcomp = BC_CModels::components(mcolor_model); + int mbpp = BC_CModels::calculate_pixelsize(mcolor_model); + int psz = mbpp / mcomp; + int mdepth = psz < 2 ? CV_8U : psz < 4 ? CV_16U : CV_32F; + if( mat.dims != 2 || mat.depth() != mdepth || mat.channels() != mcomp || + mat.cols != mcols || mat.rows != mrows ) { + mat.release(); + } + if( mat.empty() ) { + int type = CV_MAKETYPE(mdepth, mcomp); + mat.create(mrows, mcols, type); + } + uint8_t *mat_rows[mrows]; + for( int y=0; yget_rows(); + int ibpl = inp->get_bytes_per_line(), mbpl = mcols * mbpp; + int icolor_model = inp->get_color_model(); + BC_CModels::transfer(mat_rows, mcolor_model, 0,0, mcols,mrows, mbpl, + inp_rows, icolor_model, ix,iy, mcols,mrows, ibpl, 0); +// VFrame vfrm(mat_rows[0], -1, mcols,mrows, mcolor_model, mat_rows[1]-mat_rows[0]); +// static int vfrm_no = 0; char vfn[64]; sprintf(vfn,"/tmp/idat/%06d.png", vfrm_no++); +// vfrm.write_png(vfn); +} + +int PuzzleObj::process_buffer(VFrame *frame, int64_t start_position, double frame_rate) +{ + + //int need_reconfigure = + load_configuration(); + input = get_input(0); + output = get_output(0); + width = input->get_w(); + height = input->get_h(); + color_model = input->get_color_model(); + VFrame *iframe = input; + read_frame(iframe, 0, start_position, frame_rate, 0); + int cv_color_model = BC_RGB888; + if( color_model != cv_color_model ) { + iframe = new_temp(width,height, cv_color_model); + iframe->transfer_from(input); + } + int prior = 2; + int levels = 4; + int hist_bins = 5; + int channels = BC_CModels::components(cv_color_model); + +// load next image + to_mat(next_img, width,height, iframe, 0,0, cv_color_model); + Mat img; //, img1; + cvtColor(next_img, img, COLOR_RGB2HSV); + if( !sseeds.empty() && + ( ss_width != width || ss_height != height || ss_channels != channels || + ss_pixels != config.pixels || ss_levels != levels || ss_prior != prior || + ss_hist_bins != hist_bins ) ) + sseeds.release(); + if( sseeds.empty() ) + sseeds = ximgproc::createSuperpixelSEEDS( + ss_width=width, ss_height=height, ss_channels=channels, + ss_pixels=config.pixels, ss_levels=levels, ss_prior=prior, + ss_hist_bins=hist_bins, false); + sseeds->iterate(img, config.iterations); +// sseeds->getLabels(img1); + sseeds->getLabelContourMask(img, false); + uint8_t **irows = input->get_rows(); + int ibpp = BC_CModels::calculate_pixelsize(color_model); + uint8_t **orows = output->get_rows(); + int obpp = BC_CModels::calculate_pixelsize(color_model); + if( BC_CModels::is_float(color_model) ) { + for( int y=0; y + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef PUZZLEOBJ_H +#define PUZZLEOBJ_H + +#include "pluginvclient.h" +#include "loadbalance.h" +#include "mutex.inc" + +#include "opencv2/core/types.hpp" +#include "opencv2/core/mat.hpp" +#include "opencv2/calib3d.hpp" +#include "opencv2/photo.hpp" +#include "opencv2/ximgproc.hpp" +#include "opencv2/video/video.hpp" + +#include + + +using namespace std; +using namespace cv; +using namespace cv::ximgproc; + +class PuzzleObjConfig; +class PuzzleObj; + + +class PuzzleObjConfig +{ +public: + PuzzleObjConfig(); + int pixels; + int iterations; + + int equivalent(PuzzleObjConfig &that); + void copy_from(PuzzleObjConfig &that); + void interpolate(PuzzleObjConfig &prev, PuzzleObjConfig &next, + long prev_frame, long next_frame, long current_frame); + void limits(); +}; + +class PuzzleObj : public PluginVClient +{ +public: + PuzzleObj(PluginServer *server); + ~PuzzleObj(); + PLUGIN_CLASS_MEMBERS2(PuzzleObjConfig) + int is_realtime(); + void update_gui(); + void save_data(KeyFrame *keyframe); + void read_data(KeyFrame *keyframe); + int process_buffer(VFrame *frame, int64_t start_position, double frame_rate); + void to_mat(Mat &mat, int mcols, int mrows, + VFrame *inp, int ix,int iy, int mcolor_model); + + int width, height, color_model; + VFrame *input, *output; + + int ss_width, ss_height, ss_channels; + int ss_pixels, ss_levels, ss_prior, ss_hist_bins; + + Ptr sseeds; + Mat next_img; +}; + +#endif diff --git a/cinelerra-5.1/plugins/puzzleobj/puzzleobjwindow.C b/cinelerra-5.1/plugins/puzzleobj/puzzleobjwindow.C new file mode 100644 index 00000000..da3d1470 --- /dev/null +++ b/cinelerra-5.1/plugins/puzzleobj/puzzleobjwindow.C @@ -0,0 +1,76 @@ +/* + * CINELERRA + * Copyright (C) 2014 Adam Williams + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "bcdisplayinfo.h" +#include "clip.h" +#include "language.h" +#include "puzzleobj.h" +#include "puzzleobjwindow.h" +#include "theme.h" + +PuzzleObjWindow::PuzzleObjWindow(PuzzleObj *plugin) + : PluginClientWindow(plugin, 320, 100, 320, 100, 0) +{ + this->plugin = plugin; + pixels = 0; + iterations = 0; + pixels_title = 0; + iterations_title = 0; +} + +PuzzleObjWindow::~PuzzleObjWindow() +{ +} + +void PuzzleObjWindow::create_objects() +{ + int x = 10, y = 10; + BC_Title *title = new BC_Title(x, y, _("PuzzleObj")); + add_subwindow(title); + y += title->get_h() + 10; + int x1 = x + 80; + add_subwindow(pixels_title = new BC_Title(x,y,_("Pixels:"))); + add_subwindow(pixels = new PuzzleObjISlider(this, + x1,y,180, 1,1000, &plugin->config.pixels)); + y += pixels->get_h() + 10; + add_subwindow(iterations_title = new BC_Title(x,y,_("Iterations:"))); + add_subwindow(iterations = new PuzzleObjISlider(this, + x1,y,180, 0,50, &plugin->config.iterations)); + show_window(1); +} + +PuzzleObjISlider::PuzzleObjISlider(PuzzleObjWindow *win, + int x, int y, int w, int min, int max, int *output) + : BC_ISlider(x, y, 0,w,w, min,max, *output) +{ + this->win = win; + this->output = output; +} +PuzzleObjISlider::~PuzzleObjISlider() +{ +} + +int PuzzleObjISlider::handle_event() +{ + *output = get_value(); + win->plugin->send_configure_change(); + return 1; +} + diff --git a/cinelerra-5.1/plugins/puzzleobj/puzzleobjwindow.h b/cinelerra-5.1/plugins/puzzleobj/puzzleobjwindow.h new file mode 100644 index 00000000..d71cdc88 --- /dev/null +++ b/cinelerra-5.1/plugins/puzzleobj/puzzleobjwindow.h @@ -0,0 +1,58 @@ +/* + * CINELERRA + * Copyright (C) 2008-2014 Adam Williams + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef PUZZLEOBJWINDOW_H +#define PUZZLEOBJWINDOW_H + + +#include "guicast.h" + +class PuzzleObj; +class PuzzleObjWindow; +class PuzzleObjISlider; + +class PuzzleObjISlider : public BC_ISlider +{ +public: + PuzzleObjISlider(PuzzleObjWindow *win, + int x, int y, int w, int min, int max, int *output); + ~PuzzleObjISlider(); + int handle_event(); + + PuzzleObjWindow *win; + int *output; +}; + +class PuzzleObjWindow : public PluginClientWindow +{ +public: + PuzzleObjWindow(PuzzleObj *plugin); + ~PuzzleObjWindow(); + + void create_objects(); + + PuzzleObj *plugin; + BC_Title *pixels_title; + BC_Title *iterations_title; + PuzzleObjISlider *pixels; + PuzzleObjISlider *iterations; +}; + +#endif diff --git a/cinelerra-5.1/plugins/stylizeobj/Makefile b/cinelerra-5.1/plugins/stylizeobj/Makefile new file mode 100644 index 00000000..9e804ac6 --- /dev/null +++ b/cinelerra-5.1/plugins/stylizeobj/Makefile @@ -0,0 +1,21 @@ +default: all + +TOPDIR?=../.. +include $(TOPDIR)/plugin_defs + +PLUGIN = stylizeobj + +OBJS := \ + $(OBJDIR)/stylizeobj.o \ + $(OBJDIR)/stylizeobjwindow.o \ + +want_var:=$(WANT_OPENCV) +include $(TOPDIR)/opencv_build +include $(TOPDIR)/plugin_config + +all: opencv + +make $(OUTPUT) + +$(OBJDIR)/stylizeobj.o: stylizeobj.C stylizeobj.h stylizeobjwindow.h +$(OBJDIR)/stylizeobjwindow.o: stylizeobjwindow.C stylizeobj.h stylizeobjwindow.h + diff --git a/cinelerra-5.1/plugins/stylizeobj/stylizeobj.C b/cinelerra-5.1/plugins/stylizeobj/stylizeobj.C new file mode 100644 index 00000000..2d8b515c --- /dev/null +++ b/cinelerra-5.1/plugins/stylizeobj/stylizeobj.C @@ -0,0 +1,216 @@ +/* + * CINELERRA + * Copyright (C) 1997-2014 Adam Williams + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "clip.h" +#include "filexml.h" +#include "stylizeobj.h" +#include "stylizeobjwindow.h" +#include "language.h" +#include "mutex.h" + +REGISTER_PLUGIN(StylizeObj) + + +StylizeObjConfig::StylizeObjConfig() +{ + mode = MODE_EDGE_SMOOTH; + smoothing = 10; + edge_strength = 25; + shade_factor = 40; +} + +int StylizeObjConfig::equivalent(StylizeObjConfig &that) +{ + return 1; +} + +void StylizeObjConfig::copy_from(StylizeObjConfig &that) +{ +} + +void StylizeObjConfig::interpolate( StylizeObjConfig &prev, StylizeObjConfig &next, + long prev_frame, long next_frame, long current_frame) +{ + copy_from(next); +} + +void StylizeObjConfig::limits() +{ +} + + +StylizeObj::StylizeObj(PluginServer *server) + : PluginVClient(server) +{ +} + +StylizeObj::~StylizeObj() +{ +} + +const char* StylizeObj::plugin_title() { return N_("StylizeObj"); } +int StylizeObj::is_realtime() { return 1; } + +NEW_WINDOW_MACRO(StylizeObj, StylizeObjWindow); +LOAD_CONFIGURATION_MACRO(StylizeObj, StylizeObjConfig) + +void StylizeObj::save_data(KeyFrame *keyframe) +{ + FileXML output; + +// cause data to be stored directly in text + output.set_shared_output(keyframe->get_data(), MESSAGESIZE); + output.tag.set_title("STYLIZEOBJ"); + output.tag.set_property("MODE", config.mode); + output.tag.set_property("SMOOTHING", config.smoothing); + output.tag.set_property("EDGE_STRENGTH", config.edge_strength); + output.tag.set_property("SHADE_FACTOR", config.shade_factor); + output.append_tag(); + output.append_newline(); + output.tag.set_title("/STYLIZEOBJ"); + output.append_tag(); + output.append_newline(); + output.terminate_string(); +} + +void StylizeObj::read_data(KeyFrame *keyframe) +{ + FileXML input; + input.set_shared_input(keyframe->get_data(), strlen(keyframe->get_data())); + + int result = 0; + while( !(result = input.read_tag()) ) { + if( input.tag.title_is("STYLIZEOBJ") ) { + config.mode = input.tag.get_property("MODE", config.mode); + config.smoothing = input.tag.get_property("SMOOTHING", config.smoothing); + config.edge_strength = input.tag.get_property("EDGE_STRENGTH", config.edge_strength); + config.shade_factor = input.tag.get_property("SHADE_FACTOR", config.shade_factor); + config.limits(); + } + else if( input.tag.title_is("/STYLIZEOBJ") ) + result = 1; + } +} + +void StylizeObj::update_gui() +{ + if( !thread ) return; + if( !load_configuration() ) return; + thread->window->lock_window("StylizeObj::update_gui"); + StylizeObjWindow *window = (StylizeObjWindow*)thread->window; + window->unlock_window(); +} + +void StylizeObj::to_mat(Mat &mat, int mcols, int mrows, + VFrame *inp, int ix,int iy, int mcolor_model) +{ + int mcomp = BC_CModels::components(mcolor_model); + int mbpp = BC_CModels::calculate_pixelsize(mcolor_model); + int psz = mbpp / mcomp; + int mdepth = psz < 2 ? CV_8U : psz < 4 ? CV_16U : CV_32F; + if( mat.dims != 2 || mat.depth() != mdepth || mat.channels() != mcomp || + mat.cols != mcols || mat.rows != mrows ) { + mat.release(); + } + if( mat.empty() ) { + int type = CV_MAKETYPE(mdepth, mcomp); + mat.create(mrows, mcols, type); + } + uint8_t *mat_rows[mrows]; + for( int y=0; yget_rows(); + int ibpl = inp->get_bytes_per_line(), mbpl = mcols * mbpp; + int icolor_model = inp->get_color_model(); + BC_CModels::transfer(mat_rows, mcolor_model, 0,0, mcols,mrows, mbpl, + inp_rows, icolor_model, ix,iy, mcols,mrows, ibpl, 0); +// VFrame vfrm(mat_rows[0], -1, mcols,mrows, mcolor_model, mat_rows[1]-mat_rows[0]); +// static int vfrm_no = 0; char vfn[64]; sprintf(vfn,"/tmp/idat/%06d.png", vfrm_no++); +// vfrm.write_png(vfn); +} + +void StylizeObj::from_mat(VFrame *out, int ox, int oy, int ow, int oh, Mat &mat, int mcolor_model) +{ + int mbpp = BC_CModels::calculate_pixelsize(mcolor_model); + int mrows = mat.rows, mcols = mat.cols; + uint8_t *mat_rows[mrows]; + for( int y=0; yget_rows(); + int obpl = out->get_bytes_per_line(), mbpl = mcols * mbpp; + int ocolor_model = out->get_color_model(); + BC_CModels::transfer(out_rows, ocolor_model, ox,oy, ow,oh, obpl, + mat_rows, mcolor_model, 0,0, mcols,mrows, mbpl, 0); +// static int vfrm_no = 0; char vfn[64]; sprintf(vfn,"/tmp/odat/%06d.png", vfrm_no++); +// out->write_png(vfn); +} + + +int StylizeObj::process_buffer(VFrame *frame, int64_t start_position, double frame_rate) +{ + + //int need_reconfigure = + load_configuration(); + input = get_input(0); + output = get_output(0); + width = input->get_w(); + height = input->get_h(); + color_model = input->get_color_model(); + VFrame *iframe = input; + read_frame(iframe, 0, start_position, frame_rate, 0); + int cv_color_model = BC_RGB888; + if( color_model != cv_color_model ) { + iframe = new_temp(width,height, cv_color_model); + iframe->transfer_from(input); + } + +// load next image + to_mat(next_img, width,height, iframe, 0,0, cv_color_model); + output->clear_frame(); + Mat img, img1; + switch( config.mode ) { + case MODE_EDGE_SMOOTH: + edgePreservingFilter(next_img,img,1); // normalized conv filter + break; + case MODE_EDGE_RECURSIVE: + edgePreservingFilter(next_img,img,2); // recursive filter + break; + case MODE_DETAIL_ENHANCE: + detailEnhance(next_img,img); + break; + case MODE_PENCIL_SKETCH: { + float s = config.smoothing / 100; s = s * s * 200; + float r = config.edge_strength / 100; r = r * r; + float f = config.shade_factor / 100; f = f * 0.1; + pencilSketch(next_img,img, img1, s, r, f); + cv_color_model = BC_GREY8; + break; } + case MODE_COLOR_SKETCH: { + float s = config.smoothing / 100; s = s * s * 200; + float r = config.edge_strength / 100; r = r * r; + float f = config.shade_factor / 100; f = f * 0.1; + pencilSketch(next_img,img1, img, s, r, f); + break; } + case MODE_STYLIZATION: + stylization(next_img,img); + break; + } + from_mat(output, 0,0,width,height, img, cv_color_model); + return 0; +} + diff --git a/cinelerra-5.1/plugins/stylizeobj/stylizeobj.h b/cinelerra-5.1/plugins/stylizeobj/stylizeobj.h new file mode 100644 index 00000000..8f721932 --- /dev/null +++ b/cinelerra-5.1/plugins/stylizeobj/stylizeobj.h @@ -0,0 +1,87 @@ +/* + * CINELERRA + * Copyright (C) 1997-2014 Adam Williams + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef STYLIZEOBJ_H +#define STYLIZEOBJ_H + +#include "pluginvclient.h" +#include "loadbalance.h" +#include "mutex.inc" + +#include "opencv2/core/types.hpp" +#include "opencv2/core/mat.hpp" +#include "opencv2/calib3d.hpp" +#include "opencv2/photo.hpp" +#include "opencv2/video/video.hpp" + +#include + +using namespace std; +using namespace cv; + +enum { + MODE_EDGE_SMOOTH, + MODE_EDGE_RECURSIVE, + MODE_DETAIL_ENHANCE, + MODE_PENCIL_SKETCH, + MODE_COLOR_SKETCH, + MODE_STYLIZATION, +}; + +class StylizeObjConfig; +class StylizeObj; + + +class StylizeObjConfig +{ +public: + StylizeObjConfig(); + int mode; + float smoothing, edge_strength, shade_factor; + + int equivalent(StylizeObjConfig &that); + void copy_from(StylizeObjConfig &that); + void interpolate(StylizeObjConfig &prev, StylizeObjConfig &next, + long prev_frame, long next_frame, long current_frame); + void limits(); +}; + +class StylizeObj : public PluginVClient +{ +public: + StylizeObj(PluginServer *server); + ~StylizeObj(); + PLUGIN_CLASS_MEMBERS2(StylizeObjConfig) + int is_realtime(); + void update_gui(); + void save_data(KeyFrame *keyframe); + void read_data(KeyFrame *keyframe); + int process_buffer(VFrame *frame, int64_t start_position, double frame_rate); + void to_mat(Mat &mat, int mcols, int mrows, + VFrame *inp, int ix,int iy, int mcolor_model); + void from_mat(VFrame *out, int ox, int oy, int ow, int oh, + Mat &mat, int mcolor_model); + + int width, height, color_model; + VFrame *input, *output; + + Mat next_img; +}; + +#endif diff --git a/cinelerra-5.1/plugins/stylizeobj/stylizeobjwindow.C b/cinelerra-5.1/plugins/stylizeobj/stylizeobjwindow.C new file mode 100644 index 00000000..9b68d965 --- /dev/null +++ b/cinelerra-5.1/plugins/stylizeobj/stylizeobjwindow.C @@ -0,0 +1,171 @@ +/* + * CINELERRA + * Copyright (C) 2014 Adam Williams + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "bcdisplayinfo.h" +#include "clip.h" +#include "language.h" +#include "stylizeobj.h" +#include "stylizeobjwindow.h" +#include "theme.h" + +StylizeObjWindow::StylizeObjWindow(StylizeObj *plugin) + : PluginClientWindow(plugin, 320, 160, 320, 160, 0) +{ + this->plugin = plugin; + smoothing = 0; + edge_strength = 0; + shade_factor = 0; + smooth_title = 0; + edge_title = 0; + shade_title = 0; +} + +StylizeObjWindow::~StylizeObjWindow() +{ +} + +void StylizeObjWindow::create_objects() +{ + int x = 10, y = 10; + BC_Title *title = new BC_Title(x, y, _("StylizeObj")); + add_subwindow(title); + y += title->get_h() + 10; + int x1 = x; + add_subwindow(title = new BC_Title(x1, y, _("Mode: "))); + x1 += title->get_w() + 15; + add_subwindow(mode = new StylizeObjMode(this, x1, y, &plugin->config.mode)); + mode->create_objects(); + y += mode->get_h() + 10; + x0 = x; y0 = y; + update_params(); + show_window(1); +} + +void StylizeObjWindow::update_params() +{ + int x = x0, y = y0; + if( plugin->config.mode == MODE_PENCIL_SKETCH || + plugin->config.mode == MODE_COLOR_SKETCH ) { + int x1 = x + 80; + if( !smooth_title ) + add_subwindow(smooth_title = new BC_Title(x,y,_("Smooth:"))); + if( !smoothing ) + add_subwindow(smoothing = new StylizeObjFSlider(this, + x1,y,180, 0,100, &plugin->config.smoothing)); + y += smoothing->get_h() + 10; + if( !edge_title ) + add_subwindow(edge_title = new BC_Title(x,y,_("Edges:"))); + if( !edge_strength ) + add_subwindow(edge_strength = new StylizeObjFSlider(this, + x1,y,180, 0,100, &plugin->config.edge_strength)); + y += edge_strength->get_h() + 10; + if( !shade_title ) + add_subwindow(shade_title = new BC_Title(x,y,_("Shade:"))); + if( !shade_factor ) + add_subwindow(shade_factor = new StylizeObjFSlider(this, + x1,y,180, 0,100, &plugin->config.shade_factor)); + //y += shade_factor->get_h() + 10; + } + else { + delete smooth_title; smooth_title = 0; + delete smoothing; smoothing = 0; + delete edge_title; edge_title = 0; + delete edge_strength; edge_strength = 0; + delete shade_title; shade_title = 0; + delete shade_factor; shade_factor = 0; + } +} + +StylizeObjModeItem::StylizeObjModeItem(StylizeObjMode *popup, int type, const char *text) + : BC_MenuItem(text) +{ + this->popup = popup; + this->type = type; +} + +StylizeObjModeItem::~StylizeObjModeItem() +{ +} + +int StylizeObjModeItem::handle_event() +{ + popup->update(type); + popup->win->update_params(); + return popup->handle_event(); +} + +StylizeObjMode::StylizeObjMode(StylizeObjWindow *win, int x, int y, int *value) + : BC_PopupMenu(x, y, 150, "", 1) +{ + this->win = win; + this->value = value; +} + +StylizeObjMode::~StylizeObjMode() +{ +} + +void StylizeObjMode::create_objects() +{ + add_item(new StylizeObjModeItem(this, MODE_EDGE_SMOOTH, _("Edge smooth"))); + add_item(new StylizeObjModeItem(this, MODE_EDGE_RECURSIVE, _("Edge recursive"))); + add_item(new StylizeObjModeItem(this, MODE_DETAIL_ENHANCE, _("Detail Enhance"))); + add_item(new StylizeObjModeItem(this, MODE_PENCIL_SKETCH, _("Pencil Sketch"))); + add_item(new StylizeObjModeItem(this, MODE_COLOR_SKETCH, _("Color Sketch"))); + add_item(new StylizeObjModeItem(this, MODE_STYLIZATION, _("Stylization"))); + set_value(*value); +} + +int StylizeObjMode::handle_event() +{ + win->plugin->send_configure_change(); + return 1; +} + +void StylizeObjMode::update(int v) +{ + set_value(*value = v); +} + +void StylizeObjMode::set_value(int v) +{ + int i = total_items(); + while( --i >= 0 && ((StylizeObjModeItem*)get_item(i))->type != v ); + if( i >= 0 ) set_text(get_item(i)->get_text()); +} + +StylizeObjFSlider::StylizeObjFSlider(StylizeObjWindow *win, + int x, int y, int w, float min, float max, float *output) + : BC_FSlider(x, y, 0,w,w, min,max, *output) +{ + this->win = win; + this->output = output; +} +StylizeObjFSlider::~StylizeObjFSlider() +{ +} + +int StylizeObjFSlider::handle_event() +{ + *output = get_value(); + win->plugin->send_configure_change(); + return 1; +} + diff --git a/cinelerra-5.1/plugins/stylizeobj/stylizeobjwindow.h b/cinelerra-5.1/plugins/stylizeobj/stylizeobjwindow.h new file mode 100644 index 00000000..dab84d2f --- /dev/null +++ b/cinelerra-5.1/plugins/stylizeobj/stylizeobjwindow.h @@ -0,0 +1,90 @@ +/* + * CINELERRA + * Copyright (C) 2008-2014 Adam Williams + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#ifndef STYLIZEOBJWINDOW_H +#define STYLIZEOBJWINDOW_H + + +#include "guicast.h" + +class StylizeObj; +class StylizeObjWindow; +class StylizeObjModeItem; +class StylizeObjMode; +class StylizeObjFSlider; + +class StylizeObjModeItem : public BC_MenuItem +{ +public: + StylizeObjModeItem(StylizeObjMode *popup, int type, const char *text); + ~StylizeObjModeItem(); + int handle_event(); + + StylizeObjMode *popup; + int type; +}; + +class StylizeObjMode : public BC_PopupMenu +{ +public: + StylizeObjMode(StylizeObjWindow *win, int x, int y, int *value); + ~StylizeObjMode(); + void create_objects(); + int handle_event(); + void update(int v); + void set_value(int v); + + StylizeObjWindow *win; + int *value; +}; + +class StylizeObjFSlider : public BC_FSlider +{ +public: + StylizeObjFSlider(StylizeObjWindow *win, + int x, int y, int w, float min, float max, float *output); + ~StylizeObjFSlider(); + int handle_event(); + + StylizeObjWindow *win; + float *output; +}; + +class StylizeObjWindow : public PluginClientWindow +{ +public: + StylizeObjWindow(StylizeObj *plugin); + ~StylizeObjWindow(); + + void create_objects(); + void update_params(); + int x0, y0; + + StylizeObj *plugin; + StylizeObjMode *mode; + BC_Title *smooth_title; + BC_Title *edge_title; + BC_Title *shade_title; + StylizeObjFSlider *smoothing; + StylizeObjFSlider *edge_strength; + StylizeObjFSlider *shade_factor; +}; + +#endif