From 1f004d22ca7bd7a98a3bf02b12ec5b1adece92f2 Mon Sep 17 00:00:00 2001 From: Good Guy Date: Fri, 14 Sep 2018 17:59:56 -0600 Subject: [PATCH] motion draw_vectors using VFrame draw_pixel brush --- cinelerra-5.1/plugins/motion-cv/motion-cv.C | 90 ++++---------- cinelerra-5.1/plugins/motion-cv/motion-cv.h | 8 ++ cinelerra-5.1/plugins/motion-hv/motion-hv.C | 125 ++++---------------- cinelerra-5.1/plugins/motion-hv/motion-hv.h | 8 ++ cinelerra-5.1/plugins/motion/motion.C | 87 ++++---------- cinelerra-5.1/plugins/motion/motion.h | 8 ++ cinelerra-5.1/plugins/motion2point/motion.C | 125 ++++---------------- cinelerra-5.1/plugins/motion2point/motion.h | 9 ++ cinelerra-5.1/plugins/motion51/motion51.C | 14 ++- 9 files changed, 131 insertions(+), 343 deletions(-) diff --git a/cinelerra-5.1/plugins/motion-cv/motion-cv.C b/cinelerra-5.1/plugins/motion-cv/motion-cv.C index 923a183d..e8249bb0 100644 --- a/cinelerra-5.1/plugins/motion-cv/motion-cv.C +++ b/cinelerra-5.1/plugins/motion-cv/motion-cv.C @@ -1039,79 +1039,37 @@ void MotionCVMain::draw_vectors(VFrame *frame) } } -void MotionCVMain::draw_pixel(VFrame *frame, 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 +MotionCvVVFrame::MotionCvVVFrame(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; +} - 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); +int MotionCvVVFrame::draw_pixel(int x, int y) +{ + VFrame::draw_pixel(x+0, y+0); + for( int i=1; i 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("MotionCVMain::draw_line 2\n"); + int iw = frame->get_w(), ih = frame->get_h(); + int mx = iw > ih ? iw : ih; + int n = mx/800 + 1; + MotionCvVVFrame 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 diff --git a/cinelerra-5.1/plugins/motion-cv/motion-cv.h b/cinelerra-5.1/plugins/motion-cv/motion-cv.h index 823ce860..99de4b25 100644 --- a/cinelerra-5.1/plugins/motion-cv/motion-cv.h +++ b/cinelerra-5.1/plugins/motion-cv/motion-cv.h @@ -270,6 +270,14 @@ public: +class MotionCvVVFrame : public VFrame +{ +public: + MotionCvVVFrame(VFrame *vfrm, int n); + int draw_pixel(int x, int y); + int n; +}; + diff --git a/cinelerra-5.1/plugins/motion-hv/motion-hv.C b/cinelerra-5.1/plugins/motion-hv/motion-hv.C index ba5b5d19..c6f008cd 100644 --- a/cinelerra-5.1/plugins/motion-hv/motion-hv.C +++ b/cinelerra-5.1/plugins/motion-hv/motion-hv.C @@ -1281,118 +1281,35 @@ void MotionHVMain::draw_vectors(VFrame *frame) } - -void MotionHVMain::draw_pixel(VFrame *frame, int x, int y) +MotionHvVVFrame::MotionHvVVFrame(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()) { - if(!(x >= 0 && y >= 0 && x < frame->get_w() && y < frame->get_h())) return; - -#define DRAW_PIXEL(x, y, components, do_yuv, max, type) \ -{ \ - 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; \ + this->n = n; } - - switch(frame->get_color_model()) - { - case BC_RGB888: - DRAW_PIXEL(x, y, 3, 0, 0xff, unsigned char); - break; - case BC_RGBA8888: - DRAW_PIXEL(x, y, 4, 0, 0xff, unsigned char); - break; - case BC_RGB_FLOAT: - DRAW_PIXEL(x, y, 3, 0, 1.0, float); - break; - case BC_RGBA_FLOAT: - DRAW_PIXEL(x, y, 4, 0, 1.0, float); - break; - case BC_YUV888: - DRAW_PIXEL(x, y, 3, 1, 0xff, unsigned char); - break; - case BC_YUVA8888: - DRAW_PIXEL(x, y, 4, 1, 0xff, unsigned char); - break; - case BC_RGB161616: - DRAW_PIXEL(x, y, 3, 0, 0xffff, uint16_t); - break; - case BC_YUV161616: - DRAW_PIXEL(x, y, 3, 1, 0xffff, uint16_t); - break; - case BC_RGBA16161616: - DRAW_PIXEL(x, y, 4, 0, 0xffff, uint16_t); - break; - case BC_YUVA16161616: - DRAW_PIXEL(x, y, 4, 1, 0xffff, uint16_t); - break; +int MotionHvVVFrame::draw_pixel(int x, int y) +{ + VFrame::draw_pixel(x+0, y+0); + for( int i=1; i 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("MotionHVMain::draw_line 2\n"); + int iw = frame->get_w(), ih = frame->get_h(); + int mx = iw > ih ? iw : ih; + int n = mx/800 + 1; + MotionHvVVFrame 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 diff --git a/cinelerra-5.1/plugins/motion-hv/motion-hv.h b/cinelerra-5.1/plugins/motion-hv/motion-hv.h index f375fb43..320d2dbe 100644 --- a/cinelerra-5.1/plugins/motion-hv/motion-hv.h +++ b/cinelerra-5.1/plugins/motion-hv/motion-hv.h @@ -234,6 +234,14 @@ public: }; +class MotionHvVVFrame : public VFrame +{ +public: + MotionHvVVFrame(VFrame *vfrm, int n); + int draw_pixel(int x, int y); + int n; +}; + diff --git a/cinelerra-5.1/plugins/motion/motion.C b/cinelerra-5.1/plugins/motion/motion.C index 21468bde..8b437b86 100644 --- a/cinelerra-5.1/plugins/motion/motion.C +++ b/cinelerra-5.1/plugins/motion/motion.C @@ -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 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 diff --git a/cinelerra-5.1/plugins/motion/motion.h b/cinelerra-5.1/plugins/motion/motion.h index 493aeeef..1ce29e50 100644 --- a/cinelerra-5.1/plugins/motion/motion.h +++ b/cinelerra-5.1/plugins/motion/motion.h @@ -313,4 +313,12 @@ private: Mutex *cache_lock; }; +class MotionVVFrame : public VFrame +{ +public: + MotionVVFrame(VFrame *vfrm, int n); + int draw_pixel(int x, int y); + int n; +}; + #endif diff --git a/cinelerra-5.1/plugins/motion2point/motion.C b/cinelerra-5.1/plugins/motion2point/motion.C index 103afb07..8bcd81d6 100644 --- a/cinelerra-5.1/plugins/motion2point/motion.C +++ b/cinelerra-5.1/plugins/motion2point/motion.C @@ -1233,120 +1233,39 @@ void MotionMain2::draw_vectors(VFrame *frame, int point) } - -void MotionMain2::draw_pixel(VFrame *frame, int x, int y) +Motion2VVFrame::Motion2VVFrame(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()) { - if(!(x >= 0 && y >= 0 && x < frame->get_w() && y < frame->get_h())) return; - -#define DRAW_PIXEL(x, y, components, do_yuv, max, type) \ -{ \ - 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; \ + this->n = n; } - - switch(frame->get_color_model()) - { - case BC_RGB888: - DRAW_PIXEL(x, y, 3, 0, 0xff, unsigned char); - break; - case BC_RGBA8888: - DRAW_PIXEL(x, y, 4, 0, 0xff, unsigned char); - break; - case BC_RGB_FLOAT: - DRAW_PIXEL(x, y, 3, 0, 1.0, float); - break; - case BC_RGBA_FLOAT: - DRAW_PIXEL(x, y, 4, 0, 1.0, float); - break; - case BC_YUV888: - DRAW_PIXEL(x, y, 3, 1, 0xff, unsigned char); - break; - case BC_YUVA8888: - DRAW_PIXEL(x, y, 4, 1, 0xff, unsigned char); - break; - case BC_RGB161616: - DRAW_PIXEL(x, y, 3, 0, 0xffff, uint16_t); - break; - case BC_YUV161616: - DRAW_PIXEL(x, y, 3, 1, 0xffff, uint16_t); - break; - case BC_RGBA16161616: - DRAW_PIXEL(x, y, 4, 0, 0xffff, uint16_t); - break; - case BC_YUVA16161616: - DRAW_PIXEL(x, y, 4, 1, 0xffff, uint16_t); - break; +int Motion2VVFrame::draw_pixel(int x, int y) +{ + VFrame::draw_pixel(x+0, y+0); + for( int i=1; i 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("MotionMain2::draw_line 2\n"); + int iw = frame->get_w(), ih = frame->get_h(); + int mx = iw > ih ? iw : ih; + int n = mx/800 + 1; + Motion2VVFrame 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 void MotionMain2::draw_arrow(VFrame *frame, int x1, int y1, int x2, int y2) { diff --git a/cinelerra-5.1/plugins/motion2point/motion.h b/cinelerra-5.1/plugins/motion2point/motion.h index 19d1fa65..82290375 100644 --- a/cinelerra-5.1/plugins/motion2point/motion.h +++ b/cinelerra-5.1/plugins/motion2point/motion.h @@ -228,6 +228,15 @@ public: +class Motion2VVFrame : public VFrame +{ +public: + Motion2VVFrame(VFrame *vfrm, int n); + int draw_pixel(int x, int y); + int n; +}; + + diff --git a/cinelerra-5.1/plugins/motion51/motion51.C b/cinelerra-5.1/plugins/motion51/motion51.C index b16cdbc9..f29ea0bb 100644 --- a/cinelerra-5.1/plugins/motion51/motion51.C +++ b/cinelerra-5.1/plugins/motion51/motion51.C @@ -578,10 +578,10 @@ int Motion51VVFrame::draw_pixel(int x, int y) { VFrame::draw_pixel(x+0, y+0); for( int i=1; iget_w(), ih = img->get_h(); int mx = iw > ih ? iw : ih; - Motion51VVFrame vfrm(img, mx/800+1); + int n = mx/800 + 1; + Motion51VVFrame vfrm(img, n); + vfrm.set_pixel_color(WHITE); + int m = 2; while( m < n ) m <<= 1; + vfrm.set_stiple(2*m); vfrm.draw_arrow(rx, ry, rx+current_dx, ry+current_dy); // vfrm.draw_smooth(rx-rr,ry, rx-rr,ry+rr, rx,ry+rr); -- 2.26.2