2 * /brief Draw motion vectors
3 * /author Zachary Drew, Copyright 2004
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software Foundation,
17 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 #include "filter_motion_est.h"
21 #include "arrow_code.h"
23 #include <framework/mlt_frame.h>
30 #define ABS(a) ((a) >= 0 ? (a) : (-(a)))
32 static void paint_arrows( uint8_t *image, struct motion_vector_s *vectors, int w, int h, int mb_w, int mb_h )
35 struct motion_vector_s *p;
36 for( i = 0; i < w/mb_w; i++ ){
37 for( j = 0; j < h/mb_h; j++ ){
40 p = vectors + (w/mb_w)*j + i;
44 if( p->quality > 10 ){
45 draw_line(image, x, y, x + mb_w, y, 100);
46 draw_line(image, x, y, x, y + mb_h, 100);
47 draw_line(image, x + mb_w, y, x + mb_w, y + mb_h, 100);
48 draw_line(image, x + mb_w, y + mb_h, x, y + mb_w, 100);
50 else if ( p->color == 18 ) {
51 draw_line(image, x, y, x + mb_w, y + mb_h, 100);
52 draw_line(image, x, y + mb_h, x + mb_w, y, 100);
55 else if( p->vert_dev < 150 ){
57 draw_line(image, x, y, x, y + mb_h, 100);
60 else if( p->horiz_dev < 150 ){
62 draw_line(image, x, y, x+mb_w, y, 100);
67 /*if ( p->valid == 1 ){
70 draw_arrow(image, x + p->dx, y + p->dy, x, y, 100);
72 if ( p->valid == 3 ) {
73 draw_rectangle_fill(image, x, y, mb_w, mb_h,0);
75 if ( p->valid == 1 ) {
76 //draw_rectangle_outline(image, x, y, mb_w, mb_h,100);
79 //draw_rectangle_outline(image, x + p->dx, y + p->dy, mb_w, mb_h,100);
82 draw_arrow(image, x, y, x + p->dx, y + p->dy, 100);
83 //draw_rectangle_fill(image, x + p->dx, y + p->dy, mb_w, mb_h, 100);
88 // fprintf(stderr, "%d mbs above %d\n", count, mb_w * mb_h * 12);
92 static void paint_mbs( uint8_t *image, struct motion_vector_s *vectors, int w, int h, int mb_w, int mb_h, int xstep, int ystep )
95 struct motion_vector_s *p;
96 for( i = 0; i < w/mb_w; i++ ){
97 for( j = 0; j < h/mb_h; j++ ){
100 p = vectors + (w/mb_w)*j + i;
103 draw_line(image, x, y, x + mb_w, y, 100);
104 draw_line(image, x, y, x, y + mb_h, 100);
105 draw_line(image, x + mb_w, y, x + mb_w, y + mb_h, 100);
106 draw_line(image, x + mb_w, y + mb_h, x, y + mb_w, 100);
112 // Image stack(able) method
113 static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
115 // Get the frame properties
116 mlt_properties properties = MLT_FRAME_PROPERTIES(frame);
119 int error = mlt_frame_get_image( frame, image, format, width, height, 1 );
122 mlt_properties_debug( MLT_FRAME_PROPERTIES(frame), "error after mlt_frame_get_image()", stderr );
125 // Get the size of macroblocks in pixel units
126 int macroblock_height = mlt_properties_get_int( properties, "motion_est.macroblock_height" );
127 int macroblock_width = mlt_properties_get_int( properties, "motion_est.macroblock_width" );
129 // Get the motion vectors
130 struct motion_vectors_s *current_vectors = mlt_properties_get_data( properties, "motion_est.vectors", NULL );
132 init_arrows( format, *width, *height );
134 if ( mlt_properties_get_int( properties, "shot_change" ) == 1 )
136 draw_line(*image, 0, 0, *width, *height, 100);
137 draw_line(*image, 0, *height, *width, 0, 100);
139 if( current_vectors != NULL ) {
140 paint_arrows( *image, current_vectors, *width, *height, macroblock_width, macroblock_height);
141 //paint_mbs( *image, current_vectors, *width, *height, macroblock_width, macroblock_height, xstep, ystep);
149 /** Filter processing.
152 static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
154 // Push the frame filter
155 mlt_frame_push_get_image( frame, filter_get_image );
161 /** Constructor for the filter.
165 mlt_filter filter_vismv_init( char *arg )
167 mlt_filter this = mlt_filter_new( );
170 this->process = filter_process;
177 /** This source code will self destruct in 5...4...3...