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
;
42 if ( p
->valid
== 1 ) {
43 //draw_rectangle_outline(image, x-1, y-1, mb_w+1, mb_h+1,100);
46 //draw_rectangle_outline(image, x + p->dx, y + p->dy, mb_w, mb_h,100);
49 draw_arrow(image
, x
, y
, x
+ p
->dx
, y
+ p
->dy
, 100);
50 //draw_rectangle_fill(image, x + p->dx, y + p->dy, mb_w, mb_h, 100);
52 else if ( p
->valid
== 2 ) {
53 draw_rectangle_outline(image
, x
+1, y
+1, mb_w
-2, mb_h
-2,100);
55 else if ( p
->valid
== 3 ) {
56 draw_rectangle_fill(image
, x
-p
->dx
, y
-p
->dy
, mb_w
, mb_h
,0);
58 else if ( p
->valid
== 4 ) {
59 draw_line(image
, x
, y
, x
+ 4, y
, 100);
60 draw_line(image
, x
, y
, x
, y
+ 4, 100);
61 draw_line(image
, x
+ 4, y
, x
, y
+ 4, 100);
63 draw_line(image
, x
+mb_w
-1, y
+mb_h
-1, x
+mb_w
-5, y
+mb_h
-1, 100);
64 draw_line(image
, x
+mb_w
-1, y
+mb_h
-1, x
+mb_w
-1, y
+mb_h
-5, 100);
65 draw_line(image
, x
+mb_w
-5, y
+mb_h
-1, x
+mb_w
-1, y
+mb_h
-5, 100);
71 // Image stack(able) method
72 static int filter_get_image( mlt_frame frame
, uint8_t **image
, mlt_image_format
*format
, int *width
, int *height
, int writable
)
74 // Get the frame properties
75 mlt_properties properties
= MLT_FRAME_PROPERTIES(frame
);
78 int error
= mlt_frame_get_image( frame
, image
, format
, width
, height
, 1 );
81 mlt_properties_debug( MLT_FRAME_PROPERTIES(frame
), "error after mlt_frame_get_image()", stderr
);
84 // Get the size of macroblocks in pixel units
85 int macroblock_height
= mlt_properties_get_int( properties
, "motion_est.macroblock_height" );
86 int macroblock_width
= mlt_properties_get_int( properties
, "motion_est.macroblock_width" );
88 // Get the motion vectors
89 struct motion_vectors_s
*current_vectors
= mlt_properties_get_data( properties
, "motion_est.vectors", NULL
);
91 init_arrows( format
, *width
, *height
);
93 if ( mlt_properties_get_int( properties
, "shot_change" ) == 1 )
95 draw_line(*image
, 0, 0, *width
, *height
, 100);
96 draw_line(*image
, 0, *height
, *width
, 0, 100);
98 if( current_vectors
!= NULL
) {
99 paint_arrows( *image
, current_vectors
, *width
, *height
, macroblock_width
, macroblock_height
);
107 /** Filter processing.
110 static mlt_frame
filter_process( mlt_filter
this, mlt_frame frame
)
112 // Push the frame filter
113 mlt_frame_push_get_image( frame
, filter_get_image
);
119 /** Constructor for the filter.
123 mlt_filter
filter_vismv_init( char *arg
)
125 mlt_filter
this = mlt_filter_new( );
128 this->process
= filter_process
;
135 /** This source code will self destruct in 5...4...3...