X-Git-Url: http://git.cinelerra-gg.org/git/?a=blobdiff_plain;f=cinelerra-5.1%2Fplugins%2Frotate%2Frotate.C;h=cc78511f4158bd25d3e494801653eb9d444ae89c;hb=7efb497e185234700abe3abeaa430471c4e34f58;hp=db30ad6ed76508c2ee2dd240da45c670c0bdf703;hpb=7fd85fb66168f6b518c5f2d73e04036e87faa0e1;p=goodguy%2Fcinelerra.git diff --git a/cinelerra-5.1/plugins/rotate/rotate.C b/cinelerra-5.1/plugins/rotate/rotate.C index db30ad6e..cc78511f 100644 --- a/cinelerra-5.1/plugins/rotate/rotate.C +++ b/cinelerra-5.1/plugins/rotate/rotate.C @@ -19,190 +19,13 @@ * */ -#include "affine.h" -#include "bcdisplayinfo.h" -#include "clip.h" -#include "bchash.h" -#include "filexml.h" -#include "guicast.h" -#include "language.h" -#include "pluginvclient.h" -#include "rotateframe.h" -#include "vframe.h" - - -#include - - - -#define MAXANGLE 360 - - -class RotateEffect; -class RotateWindow; - - -class RotateConfig -{ -public: - RotateConfig(); - - int equivalent(RotateConfig &that); - void copy_from(RotateConfig &that); - void interpolate(RotateConfig &prev, - RotateConfig &next, - long prev_frame, - long next_frame, - long current_frame); - - float angle; - float pivot_x; - float pivot_y; - int draw_pivot; -// int bilinear; -}; - -class RotateToggle : public BC_Radial -{ -public: - RotateToggle(RotateWindow *window, - RotateEffect *plugin, - int init_value, - int x, - int y, - int value, - const char *string); - int handle_event(); - - RotateEffect *plugin; - RotateWindow *window; - int value; -}; - -class RotateDrawPivot : public BC_CheckBox -{ -public: - RotateDrawPivot(RotateWindow *window, - RotateEffect *plugin, - int x, - int y); - int handle_event(); - RotateEffect *plugin; - RotateWindow *window; - int value; -}; - -class RotateInterpolate : public BC_CheckBox -{ -public: - RotateInterpolate(RotateEffect *plugin, int x, int y); - int handle_event(); - RotateEffect *plugin; -}; - -class RotateFine : public BC_FPot -{ -public: - RotateFine(RotateWindow *window, - RotateEffect *plugin, - int x, - int y); - int handle_event(); - - RotateEffect *plugin; - RotateWindow *window; -}; - -class RotateX : public BC_FPot -{ -public: - RotateX(RotateWindow *window, - RotateEffect *plugin, - int x, - int y); - int handle_event(); - RotateEffect *plugin; - RotateWindow *window; -}; - -class RotateY : public BC_FPot -{ -public: - RotateY(RotateWindow *window, - RotateEffect *plugin, - int x, - int y); - int handle_event(); - RotateEffect *plugin; - RotateWindow *window; -}; - - -class RotateText : public BC_TextBox -{ -public: - RotateText(RotateWindow *window, - RotateEffect *plugin, - int x, - int y); - int handle_event(); - - RotateEffect *plugin; - RotateWindow *window; -}; - -class RotateWindow : public PluginClientWindow -{ -public: - RotateWindow(RotateEffect *plugin); - - void create_objects(); - - int update(); - int update_fine(); - int update_text(); - int update_toggles(); - - RotateEffect *plugin; - RotateToggle *toggle0; - RotateToggle *toggle90; - RotateToggle *toggle180; - RotateToggle *toggle270; - RotateDrawPivot *draw_pivot; - RotateFine *fine; - RotateText *text; - RotateX *x; - RotateY *y; -// RotateInterpolate *bilinear; -}; - - - - -class RotateEffect : public PluginVClient -{ -public: - RotateEffect(PluginServer *server); - ~RotateEffect(); - - PLUGIN_CLASS_MEMBERS(RotateConfig) - int process_buffer(VFrame *frame, - int64_t start_position, - double frame_rate); - int is_realtime(); - void update_gui(); - void save_data(KeyFrame *keyframe); - void read_data(KeyFrame *keyframe); - int handle_opengl(); - - AffineEngine *engine; - int need_reconfigure; -}; - - - +#include "rotate.h" +#include "theme.h" +#define MAXANGLE 360.00 +#define MINPIVOT 0.00 +#define MAXPIVOT 100.00 REGISTER_PLUGIN(RotateEffect) @@ -210,26 +33,32 @@ REGISTER_PLUGIN(RotateEffect) - - - - - - - - - - - - - - RotateConfig::RotateConfig() { - angle = 0; - pivot_x = 50; - pivot_y = 50; - draw_pivot = 0; + reset(RESET_DEFAULT_SETTINGS); +} + +void RotateConfig::reset(int clear) +{ + switch(clear) { + case RESET_ANGLE : + angle = 0.0; + break; + case RESET_PIVOT_X : + pivot_x = 50.0; + break; + case RESET_PIVOT_Y : + pivot_y = 50.0; + break; + case RESET_ALL : + case RESET_DEFAULT_SETTINGS : + default: + angle = 0.0; + pivot_x = 50.0; + pivot_y = 50.0; + draw_pivot = 0; + break; + } } int RotateConfig::equivalent(RotateConfig &that) @@ -286,13 +115,13 @@ RotateToggle::RotateToggle(RotateWindow *window, { this->value = value; this->plugin = plugin; - this->window = window; + this->window = window; } int RotateToggle::handle_event() { plugin->config.angle = (float)value; - window->update(); + window->update(); plugin->send_configure_change(); return 1; } @@ -310,7 +139,7 @@ RotateDrawPivot::RotateDrawPivot(RotateWindow *window, : BC_CheckBox(x, y, plugin->config.draw_pivot, _("Draw pivot")) { this->plugin = plugin; - this->window = window; + this->window = window; } int RotateDrawPivot::handle_event() @@ -339,221 +168,272 @@ int RotateDrawPivot::handle_event() -RotateFine::RotateFine(RotateWindow *window, RotateEffect *plugin, int x, int y) - : BC_FPot(x, - y, - (float)plugin->config.angle, - (float)-360, - (float)360) +RotateAngleText::RotateAngleText(RotateWindow *window, RotateEffect *plugin, int x, int y) + : BC_TumbleTextBox(window, (float)plugin->config.angle, + (float)-MAXANGLE, (float)MAXANGLE, x, y, xS(60), 2) { this->window = window; this->plugin = plugin; - set_precision(0.01); - set_use_caption(0); } -int RotateFine::handle_event() +int RotateAngleText::handle_event() { - plugin->config.angle = get_value(); + plugin->config.angle = atof(get_text()); window->update_toggles(); - window->update_text(); + window->update_sliders(); plugin->send_configure_change(); return 1; } - -RotateText::RotateText(RotateWindow *window, - RotateEffect *plugin, - int x, - int y) - : BC_TextBox(x, - y, - 100, - 1, - (float)plugin->config.angle) +RotateAngleSlider::RotateAngleSlider(RotateWindow *window, RotateEffect *plugin, int x, int y, int w) + : BC_FSlider(x, y, 0, w, w, (float)-MAXANGLE, (float)MAXANGLE, (float)plugin->config.angle) { this->window = window; this->plugin = plugin; - set_precision(4); + enable_show_value(0); // Hide caption + set_precision(0.1); } -int RotateText::handle_event() +int RotateAngleSlider::handle_event() { - plugin->config.angle = atof(get_text()); + plugin->config.angle = get_value(); window->update_toggles(); - window->update_fine(); + window->update_texts(); plugin->send_configure_change(); return 1; } -RotateX::RotateX(RotateWindow *window, RotateEffect *plugin, int x, int y) - : BC_FPot(x, - y, - (float)plugin->config.pivot_x, - (float)0, - (float)100) +RotatePivotXText::RotatePivotXText(RotateWindow *window, RotateEffect *plugin, int x, int y) + : BC_TumbleTextBox(window, (float)plugin->config.pivot_x, + (float)MINPIVOT, (float)MAXPIVOT, x, y, xS(60), 2) { this->window = window; this->plugin = plugin; - set_precision(0.01); - set_use_caption(1); } -int RotateX::handle_event() +int RotatePivotXText::handle_event() +{ + plugin->config.pivot_x = atof(get_text()); + window->update_sliders(); + plugin->send_configure_change(); + return 1; +} + + +RotatePivotXSlider::RotatePivotXSlider(RotateWindow *window, RotateEffect *plugin, int x, int y, int w) + : BC_FSlider(x, y, 0, w, w, (float)MINPIVOT, (float)MAXPIVOT, (float)plugin->config.pivot_x) +{ + this->window = window; + this->plugin = plugin; + enable_show_value(0); // Hide caption + set_precision(0.1); +} + +int RotatePivotXSlider::handle_event() { plugin->config.pivot_x = get_value(); + window->update_toggles(); + window->update_texts(); + plugin->send_configure_change(); + return 1; +} + + +RotatePivotYText::RotatePivotYText(RotateWindow *window, RotateEffect *plugin, int x, int y) + : BC_TumbleTextBox(window, (float)plugin->config.pivot_y, + (float)MINPIVOT, (float)MAXPIVOT, x, y, xS(60), 2) +{ + this->window = window; + this->plugin = plugin; +} + +int RotatePivotYText::handle_event() +{ + plugin->config.pivot_y = atof(get_text()); plugin->send_configure_change(); return 1; } -RotateY::RotateY(RotateWindow *window, RotateEffect *plugin, int x, int y) - : BC_FPot(x, - y, - (float)plugin->config.pivot_y, - (float)0, - (float)100) + +RotatePivotYSlider::RotatePivotYSlider(RotateWindow *window, RotateEffect *plugin, int x, int y, int w) + : BC_FSlider(x, y, 0, w, w, (float)MINPIVOT, (float)MAXPIVOT, (float)plugin->config.pivot_y) { this->window = window; this->plugin = plugin; - set_precision(0.01); - set_use_caption(1); + enable_show_value(0); // Hide caption + set_precision(0.1); } -int RotateY::handle_event() +int RotatePivotYSlider::handle_event() { plugin->config.pivot_y = get_value(); + window->update_toggles(); + window->update_texts(); plugin->send_configure_change(); return 1; } +RotateClr::RotateClr(RotateWindow *window, RotateEffect *plugin, int x, int y, int clear) + : BC_Button(x, y, plugin->get_theme()->get_image_set("reset_button")) +{ + this->window = window; + this->plugin = plugin; + this->clear = clear; +} +RotateClr::~RotateClr() +{ +} +int RotateClr::handle_event() +{ + plugin->config.reset(clear); + window->update(); + plugin->send_configure_change(); + return 1; +} -RotateWindow::RotateWindow(RotateEffect *plugin) - : PluginClientWindow(plugin, - 250, - 230, - 250, - 230, - 0) +RotateReset::RotateReset(RotateEffect *plugin, RotateWindow *window, int x, int y) + : BC_GenericButton(x, y, _("Reset")) { this->plugin = plugin; + this->window = window; +} +RotateReset::~RotateReset() +{ +} +int RotateReset::handle_event() +{ + plugin->config.reset(RESET_ALL); + window->update(); + plugin->send_configure_change(); + return 1; } -#define RADIUS 30 -void RotateWindow::create_objects() -{ - int x = 10, y = 10; - BC_Title *title; - add_tool(new BC_Title(x, y, _("Rotate"))); - x += 50; - y += 20; - add_tool(toggle0 = new RotateToggle(this, - plugin, - plugin->config.angle == 0, - x, - y, - 0, - "0")); - x += RADIUS; - y += RADIUS; - add_tool(toggle90 = new RotateToggle(this, - plugin, - plugin->config.angle == 90, - x, - y, - 90, - "90")); - x -= RADIUS; - y += RADIUS; - add_tool(toggle180 = new RotateToggle(this, - plugin, - plugin->config.angle == 180, - x, - y, - 180, - "180")); - x -= RADIUS; - y -= RADIUS; - add_tool(toggle270 = new RotateToggle(this, - plugin, - plugin->config.angle == 270, - x, - y, - 270, - "270")); -// add_subwindow(bilinear = new RotateInterpolate(plugin, 10, y + 60)); - x += 120; - y -= 50; - add_tool(fine = new RotateFine(this, plugin, x, y)); - y += fine->get_h() + 10; - add_tool(text = new RotateText(this, plugin, x, y)); - y += 30; - add_tool(new BC_Title(x, y, _("Degrees"))); - - - - - - y += text->get_h() + 10; - add_subwindow(title = new BC_Title(x, y, _("Pivot (x,y):"))); - y += title->get_h() + 10; - add_subwindow(this->x = new RotateX(this, plugin, x, y)); - x += this->x->get_w() + 10; - add_subwindow(this->y = new RotateY(this, plugin, x, y)); - - x = 10; - y += this->y->get_h() + 10; - add_subwindow(draw_pivot = new RotateDrawPivot(this, plugin, x, y)); - show_window(); +RotateWindow::RotateWindow(RotateEffect *plugin) + : PluginClientWindow(plugin, xS(420), yS(260), xS(420), yS(260), 0) +{ + this->plugin = plugin; +} +#define RADIUS xS(30) +void RotateWindow::create_objects() +{ + int xs10 = xS(10), xs20 = xS(20), xs64 = xS(64), xs200 = xS(200); + int ys10 = yS(10), ys20 = yS(20), ys30 = yS(30), ys40 = yS(40); + int x2 = xS(80), x3 = xS(180); + int x = xs10, y = ys10; + int clr_x = get_w()-x - xS(22); // note: clrBtn_w = 22 + + BC_TitleBar *title_bar; + BC_Bar *bar; + +// Angle section + add_subwindow(title_bar = new BC_TitleBar(x, y, get_w()-2*x, xs20, xs10, _("Rotation"))); + x = xs10; y += ys20; + add_tool(new BC_Title(x, y, _("Preset:"))); + x = x + x2; + add_tool(toggle180neg = new RotateToggle(this, plugin, + plugin->config.angle == -180, x, y, -180, "-180°")); + x += xs64; + add_tool(toggle90neg = new RotateToggle(this, plugin, + plugin->config.angle == -90, x, y, -90, "-90°")); + x += xs64; + add_tool(toggle0 = new RotateToggle(this, plugin, + plugin->config.angle == 0, x, y, 0, "0°")); + x += xs64; + add_tool(toggle90 = new RotateToggle(this, plugin, + plugin->config.angle == 90, x, y, 90, "+90°")); + x += xs64; + add_tool(toggle180 = new RotateToggle(this, plugin, + plugin->config.angle == 180, x, y, 180, "+180°")); +// add_subwindow(bilinear = new RotateInterpolate(plugin, xs10, y + ys60)); + x = xs10; y += ys30; + add_tool(new BC_Title(x, y, _("Angle:"))); + rotate_angle_text = new RotateAngleText(this, plugin, (x + x2), y); + rotate_angle_text->create_objects(); + add_tool(rotate_angle_slider = new RotateAngleSlider(this, plugin, x3, y, xs200)); + add_tool(rotate_angle_clr = new RotateClr(this, plugin, + clr_x, y, RESET_ANGLE)); + y += ys40; + +// Pivot section + add_subwindow(title_bar = new BC_TitleBar(x, y, get_w()-2*x, xs20, xs10, _("Pivot"))); + y += ys20; + add_subwindow(draw_pivot = new RotateDrawPivot(this, plugin, x, y)); + y += ys30; + add_tool(new BC_Title(x, y, _("X:"))); + add_tool(new BC_Title((x2-x), y, _("%"))); + rotate_pivot_x_text = new RotatePivotXText(this, plugin, (x + x2), y); + rotate_pivot_x_text->create_objects(); + add_tool(rotate_pivot_x_slider = new RotatePivotXSlider(this, plugin, x3, y, xs200)); + add_tool(rotate_pivot_x_clr = new RotateClr(this, plugin, + clr_x, y, RESET_PIVOT_X)); + y += ys30; + add_tool(new BC_Title(x, y, _("Y:"))); + add_tool(new BC_Title((x2-x), y, _("%"))); + rotate_pivot_y_text = new RotatePivotYText(this, plugin, (x + x2), y); + rotate_pivot_y_text->create_objects(); + add_tool(rotate_pivot_y_slider = new RotatePivotYSlider(this, plugin, x3, y, xs200)); + add_tool(rotate_pivot_y_clr = new RotateClr(this, plugin, + clr_x, y, RESET_PIVOT_Y)); + y += ys40; + +// Reset section + add_subwindow(bar = new BC_Bar(x, y, get_w()-2*x)); + y += ys10; + add_subwindow(reset = new RotateReset(plugin, this, x, y)); + show_window(); } int RotateWindow::update() { - update_fine(); + update_sliders(); update_toggles(); - update_text(); + update_texts(); // bilinear->update(plugin->config.bilinear); return 0; } -int RotateWindow::update_fine() +int RotateWindow::update_sliders() { - fine->update(plugin->config.angle); - x->update(plugin->config.pivot_x); - y->update(plugin->config.pivot_y); + rotate_angle_slider->update(plugin->config.angle); + rotate_pivot_x_slider->update(plugin->config.pivot_x); + rotate_pivot_y_slider->update(plugin->config.pivot_y); return 0; } -int RotateWindow::update_text() +int RotateWindow::update_texts() { - text->update(plugin->config.angle); + rotate_angle_text->update(plugin->config.angle); + rotate_pivot_x_text->update(plugin->config.pivot_x); + rotate_pivot_y_text->update(plugin->config.pivot_y); return 0; } int RotateWindow::update_toggles() { + toggle180neg->update(EQUIV(plugin->config.angle, -180)); + toggle90neg->update(EQUIV(plugin->config.angle, -90)); toggle0->update(EQUIV(plugin->config.angle, 0)); toggle90->update(EQUIV(plugin->config.angle, 90)); toggle180->update(EQUIV(plugin->config.angle, 180)); - toggle270->update(EQUIV(plugin->config.angle, 270)); draw_pivot->update(plugin->config.draw_pivot); return 0; } @@ -681,12 +561,10 @@ int RotateEffect::process_buffer(VFrame *frame, double frame_rate) { load_configuration(); - int w = frame->get_w(); - int h = frame->get_h(); //printf("RotateEffect::process_buffer %d\n", __LINE__); - if(config.angle == 0) + if(config.angle == 0 && !config.draw_pivot) { read_frame(frame, 0, @@ -744,65 +622,27 @@ int RotateEffect::process_buffer(VFrame *frame, //printf("RotateEffect::process_buffer %d draw_pivot=%d\n", __LINE__, config.draw_pivot); // Draw center -#define CENTER_H 20 -#define CENTER_W 20 -#define DRAW_CENTER(components, type, max) \ -{ \ - type **rows = (type**)get_output()->get_rows(); \ - if( (center_x >= 0 && center_x < w) || (center_y >= 0 && center_y < h) ) \ - { \ - type *hrow = rows[center_y] + components * (center_x - CENTER_W / 2); \ - for(int i = center_x - CENTER_W / 2; i <= center_x + CENTER_W / 2; i++) \ - { \ - if(i >= 0 && i < w) \ - { \ - hrow[0] = max - hrow[0]; \ - hrow[1] = max - hrow[1]; \ - hrow[2] = max - hrow[2]; \ - hrow += components; \ - } \ - } \ - \ - for(int i = center_y - CENTER_W / 2; i <= center_y + CENTER_W / 2; i++) \ - { \ - if(i >= 0 && i < h) \ - { \ - type *vrow = rows[i] + center_x * components; \ - vrow[0] = max - vrow[0]; \ - vrow[1] = max - vrow[1]; \ - vrow[2] = max - vrow[2]; \ - } \ - } \ - } \ -} - - if(config.draw_pivot) - { - int center_x = (int)(config.pivot_x * w / 100); \ - int center_y = (int)(config.pivot_y * h / 100); \ - -//printf("RotateEffect::process_buffer %d %d %d\n", __LINE__, center_x, center_y); - switch(get_output()->get_color_model()) - { - case BC_RGB_FLOAT: - DRAW_CENTER(3, float, 1.0) - break; - case BC_RGBA_FLOAT: - DRAW_CENTER(4, float, 1.0) - break; - case BC_RGB888: - DRAW_CENTER(3, unsigned char, 0xff) - break; - case BC_RGBA8888: - DRAW_CENTER(4, unsigned char, 0xff) - break; - case BC_YUV888: - DRAW_CENTER(3, unsigned char, 0xff) - break; - case BC_YUVA8888: - DRAW_CENTER(4, unsigned char, 0xff) - break; - } + if(config.draw_pivot) { + VFrame *vframe = get_output(); + int w = vframe->get_w(), h = vframe->get_h(); + int mx = w > h ? w : h; + int lw = mx/400 + 1, cxy = mx/80; + int center_x = (int)(config.pivot_x * w/100); + int center_y = (int)(config.pivot_y * h/100); + int x1 = center_x - cxy, x2 = center_x + cxy; + int y1 = center_y - cxy, y2 = center_y + cxy; + vframe->set_pixel_color(WHITE); + for( int i=0; idraw_line(x1-i,center_y-i, x2-i,center_y-i); + vframe->set_pixel_color(BLACK); + for( int i=1; i<=lw; ++i ) + frame->draw_line(x1+i,center_y+i, x2+i,center_y+i); + vframe->set_pixel_color(WHITE); + for( int i=0; idraw_line(center_x-i,y1-i, center_x-i,y2-i); + vframe->set_pixel_color(BLACK); + for( int i=1; i<=lw; ++i ) + frame->draw_line(center_x+i,y1+i, center_x+i,y2+i); } // Conserve memory by deleting large frames @@ -828,29 +668,41 @@ int RotateEffect::handle_opengl() if(config.draw_pivot) { - int w = get_output()->get_w(); - int h = get_output()->get_h(); - int center_x = (int)(config.pivot_x * w / 100); - int center_y = (int)(config.pivot_y * h / 100); - + VFrame *vframe = get_output(); + int w = vframe->get_w(), h = vframe->get_h(); + int mx = w > h ? w : h; + int lw = mx/400 + 1, cxy = mx/80; + int center_x = (int)(config.pivot_x * w/100); + int center_y = (int)(config.pivot_y * h/100); + int x1 = center_x - cxy, x2 = center_x + cxy; + int y1 = center_y - cxy, y2 = center_y + cxy; glDisable(GL_TEXTURE_2D); - glColor4f(0.0, 0.0, 0.0, 1.0); + int is_yuv = BC_CModels::is_yuv(vframe->get_color_model()); + float rwt = 1, gwt = is_yuv? 0.5 : 1, bwt = is_yuv? 0.5 : 1; + float rbk = 0, gbk = is_yuv? 0.5 : 0, bbk = is_yuv? 0.5 : 0; glBegin(GL_LINES); - glVertex3f(center_x, -h + center_y - CENTER_H / 2, 0.0); - glVertex3f(center_x, -h + center_y + CENTER_H / 2, 0.0); - glEnd(); - glBegin(GL_LINES); - glVertex3f(center_x - CENTER_W / 2, -h + center_y, 0.0); - glVertex3f(center_x + CENTER_W / 2, -h + center_y, 0.0); - glEnd(); - glColor4f(1.0, 1.0, 1.0, 1.0); - glBegin(GL_LINES); - glVertex3f(center_x - 1, -h + center_y - CENTER_H / 2 - 1, 0.0); - glVertex3f(center_x - 1, -h + center_y + CENTER_H / 2 - 1, 0.0); + glColor4f(rwt, gwt, bwt, 1.0); + for( int i=0; i