rework histogram_bezier, init wm icon set_icon(gg), update de.po+msg/txt
[goodguy/history.git] / cinelerra-5.1 / plugins / motion / motion.C
index db9235eccb4ecf2ddf6a973ca90b3e33fb1cf438..b8da2dca0b9ab7a527f9a24c0ddc1ead23e6c92a 100644 (file)
@@ -212,7 +212,7 @@ MotionMain::~MotionMain()
        delete rotate_target_dst;
 }
 
-const char* MotionMain::plugin_title() { return _("Motion"); }
+const char* MotionMain::plugin_title() { return N_("Motion"); }
 int MotionMain::is_realtime() { return 1; }
 int MotionMain::is_multichannel() { return 1; }
 
@@ -280,7 +280,7 @@ void MotionMain::save_data(KeyFrame *keyframe)
        FileXML output;
 
 // cause data to be stored directly in text
-       output.set_shared_output(keyframe->get_data(), MESSAGESIZE);
+       output.set_shared_output(keyframe->xbuf);
        output.tag.set_title("MOTION");
 
        output.tag.set_property("BLOCK_COUNT", config.block_count);
@@ -319,7 +319,7 @@ void MotionMain::save_data(KeyFrame *keyframe)
 void MotionMain::read_data(KeyFrame *keyframe)
 {
        FileXML input;
-       input.set_shared_input(keyframe->get_data(), strlen(keyframe->get_data()));
+       input.set_shared_input(keyframe->xbuf);
        int result = 0;
 
        while( !(result = input.read_tag()) ) {
@@ -364,7 +364,7 @@ void MotionMain::allocate_temp(int w, int h, int color_model)
                temp_frame = 0;
        }
        if( !temp_frame )
-               temp_frame = new VFrame(w, h, color_model);
+               temp_frame = new VFrame(w, h, color_model, 0);
 }
 
 void MotionMain::process_global()
@@ -733,16 +733,16 @@ printf("MotionMain::process_buffer 2 rename tracking file: %s to %s\n",
 // The center of the search area is fixed in compensate mode or
 // the user value + the accumulation vector in track mode.
                if( !prev_global_ref )
-                       prev_global_ref = new VFrame(w, h, color_model);
+                       prev_global_ref = new VFrame(w, h, color_model, 0);
                if( !current_global_ref )
-                       current_global_ref = new VFrame(w, h, color_model);
+                       current_global_ref = new VFrame(w, h, color_model, 0);
 
 // Global loads the current target frame into the src and
 // writes it to the dst frame with desired translation.
                if( !global_target_src )
-                       global_target_src = new VFrame(w, h, color_model);
+                       global_target_src = new VFrame(w, h, color_model, 0);
                if( !global_target_dst )
-                       global_target_dst = new VFrame(w, h, color_model);
+                       global_target_dst = new VFrame(w, h, color_model, 0);
 
 // Load the global frames
                if( need_reload ) {
@@ -762,10 +762,10 @@ printf("MotionMain::process_buffer 2 rename tracking file: %s to %s\n",
 // The center of the search area is always the user value + the accumulation
 // vector.
                        if( !prev_rotate_ref )
-                               prev_rotate_ref = new VFrame(w, h, color_model);
+                               prev_rotate_ref = new VFrame(w, h, color_model, 0);
 // The current global reference is the current rotation reference.
                        if( !current_rotate_ref )
-                               current_rotate_ref = new VFrame(w, h, color_model);
+                               current_rotate_ref = new VFrame(w, h, color_model, 0);
                        current_rotate_ref->copy_from(current_global_ref);
 
 // The global target destination is copied to the rotation target source
@@ -774,9 +774,9 @@ printf("MotionMain::process_buffer 2 rename tracking file: %s to %s\n",
 // if we're tracking.
 // The pivot is fixed to the user position if we're compensating.
                        if( !rotate_target_src )
-                               rotate_target_src = new VFrame(w, h, color_model);
+                               rotate_target_src = new VFrame(w, h, color_model, 0);
                        if( !rotate_target_dst )
-                               rotate_target_dst = new VFrame(w, h, color_model);
+                               rotate_target_dst = new VFrame(w, h, color_model, 0);
                }
        }
 // Rotation only
@@ -784,16 +784,16 @@ printf("MotionMain::process_buffer 2 rename tracking file: %s to %s\n",
 // Rotation reads the previous reference frame and compares it with current
 // reference frame.
                if( !prev_rotate_ref )
-                       prev_rotate_ref = new VFrame(w, h, color_model);
+                       prev_rotate_ref = new VFrame(w, h, color_model, 0);
                if( !current_rotate_ref )
-                       current_rotate_ref = new VFrame(w, h, color_model);
+                       current_rotate_ref = new VFrame(w, h, color_model, 0);
 
 // Rotation loads target frame to temporary, rotates it, and writes it to the
 // target frame.  The pivot is always fixed.
                if( !rotate_target_src )
-                       rotate_target_src = new VFrame(w, h, color_model);
+                       rotate_target_src = new VFrame(w, h, color_model, 0);
                if( !rotate_target_dst )
-                       rotate_target_dst = new VFrame(w, h, color_model);
+                       rotate_target_dst = new VFrame(w, h, color_model, 0);
 
 
 // Load the rotate frames
@@ -1009,78 +1009,35 @@ void MotionMain::draw_vectors(VFrame *frame)
        }
 }
 
+MotionVVFrame::MotionVVFrame(VFrame *vfrm, int n)
+ : VFrame(vfrm->get_data(), -1, vfrm->get_y()-vfrm->get_data(),
+       vfrm->get_u()-vfrm->get_data(), vfrm->get_v()-vfrm->get_data(),
+       vfrm->get_w(), vfrm->get_h(), vfrm->get_color_model(),
+       vfrm->get_bytes_per_line())
+{
+       this->n = n;
+}
 
-void MotionMain::draw_pixel(VFrame *frame, int x, int y)
+int MotionVVFrame::draw_pixel(int x, int y)
 {
-       if( !(x >= 0 && y >= 0 && x < frame->get_w() && y < frame->get_h()) ) return;
-
-#define DRAW_PIXEL(model, x, y, components, do_yuv, max, type) \
- case model: { \
-       type **rows = (type**)frame->get_rows(); \
-       rows[y][x * components] = max - rows[y][x * components]; \
-       if( !do_yuv ) { \
-               rows[y][x * components + 1] = max - rows[y][x * components + 1]; \
-               rows[y][x * components + 2] = max - rows[y][x * components + 2]; \
-       } \
-       else { \
-               rows[y][x * components + 1] = (max / 2 + 1) - rows[y][x * components + 1]; \
-               rows[y][x * components + 2] = (max / 2 + 1) - rows[y][x * components + 2]; \
-       } \
-       if( components == 4 ) \
-               rows[y][x * components + 3] = max; \
-} break
-
-       switch(frame->get_color_model()) {
-       DRAW_PIXEL(BC_RGB888, x, y, 3, 0, 0xff, unsigned char);
-       DRAW_PIXEL(BC_RGBA8888, x, y, 4, 0, 0xff, unsigned char);
-       DRAW_PIXEL(BC_RGB_FLOAT, x, y, 3, 0, 1.0, float);
-       DRAW_PIXEL(BC_RGBA_FLOAT, x, y, 4, 0, 1.0, float);
-       DRAW_PIXEL(BC_YUV888, x, y, 3, 1, 0xff, unsigned char);
-       DRAW_PIXEL(BC_YUVA8888, x, y, 4, 1, 0xff, unsigned char);
-       DRAW_PIXEL(BC_RGB161616, x, y, 3, 0, 0xffff, uint16_t);
-       DRAW_PIXEL(BC_YUV161616, x, y, 3, 1, 0xffff, uint16_t);
-       DRAW_PIXEL(BC_RGBA16161616, x, y, 4, 0, 0xffff, uint16_t);
-       DRAW_PIXEL(BC_YUVA16161616, x, y, 4, 1, 0xffff, uint16_t);
+       VFrame::draw_pixel(x+0, y+0);
+       for( int i=1; i<n; ++i ) {
+               VFrame::draw_pixel(x-i, y-i);
+               VFrame::draw_pixel(x+i, y+i);
        }
+       return 0;
 }
 
-
 void MotionMain::draw_line(VFrame *frame, int x1, int y1, int x2, int y2)
 {
-       int w = labs(x2 - x1);
-       int h = labs(y2 - y1);
-//printf("MotionMain::draw_line 1 %d %d %d %d\n", x1, y1, x2, y2);
-
-       if( !w && !h ) {
-               draw_pixel(frame, x1, y1);
-       }
-       else if( w > h ) {
-// Flip coordinates so x1 < x2
-               if( x2 < x1 ) {
-                       y2 ^= y1; y1 ^= y2; y2 ^= y1;
-                       x1 ^= x2; x2 ^= x1; x1 ^= x2;
-               }
-               int numerator = y2 - y1;
-               int denominator = x2 - x1;
-               for( int i = x1; i < x2; i++ ) {
-                       int y = y1 + (int64_t)(i - x1) * (int64_t)numerator / (int64_t)denominator;
-                       draw_pixel(frame, i, y);
-               }
-       }
-       else {
-// Flip coordinates so y1 < y2
-               if( y2 < y1 ) {
-                       y2 ^= y1; y1 ^= y2; y2 ^= y1;
-                       x1 ^= x2; x2 ^= x1; x1 ^= x2;
-               }
-               int numerator = x2 - x1;
-               int denominator = y2 - y1;
-               for( int i = y1; i < y2; i++ ) {
-                       int x = x1 + (int64_t)(i - y1) * (int64_t)numerator / (int64_t)denominator;
-                       draw_pixel(frame, x, i);
-               }
-       }
-//printf("MotionMain::draw_line 2\n");
+       int iw = frame->get_w(), ih = frame->get_h();
+       int mx = iw > ih ? iw : ih;
+       int n = mx/800 + 1;
+       MotionVVFrame vfrm(frame, n);
+       vfrm.set_pixel_color(WHITE);
+       int m = 2;  while( m < n ) m <<= 1;
+       vfrm.set_stiple(2*m);
+       vfrm.draw_line(x1,y1, x2,y2);
 }
 
 #define ARROW_SIZE 10
@@ -1255,12 +1212,11 @@ void RotateScanUnit::process_package(LoadPackage *package)
 
                if( !rotater )
                        rotater = new AffineEngine(1, 1);
-               if( !temp ) temp = new VFrame(0,
-                       -1,
-                       server->previous_frame->get_w(),
-                       server->previous_frame->get_h(),
-                       color_model,
-                       -1);
+               if( !temp )
+                       temp = new VFrame(
+                               server->previous_frame->get_w(),
+                               server->previous_frame->get_h(),
+                               color_model, 0);
 //printf("RotateScanUnit::process_package %d\n", __LINE__);