]> git.sesse.net Git - mlt/blob - src/modules/motion_est/filter_vismv.c
framework: remove global profile, rather share one mlt_profile across a service netwo...
[mlt] / src / modules / motion_est / filter_vismv.c
1 /*
2  *      /brief Draw motion vectors
3  *      /author Zachary Drew, Copyright 2004
4  *
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.
9  *
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.
14  *
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.
18  */
19
20 #include "filter_motion_est.h"
21 #include "arrow_code.h"
22
23 #include <framework/mlt_frame.h>
24
25 #include <stdio.h>
26 #include <stdlib.h>
27 #include <math.h>
28 #include <string.h>
29
30 #define ABS(a) ((a) >= 0 ? (a) : (-(a)))
31
32 static void paint_arrows( uint8_t *image, struct motion_vector_s *vectors, int w, int h, int mb_w, int mb_h )
33 {
34         int i, j, x, y;
35         struct motion_vector_s *p;
36         for( i = 0; i < w/mb_w; i++ ){
37                 for( j = 0; j < h/mb_h; j++ ){
38                         x = i*mb_w;
39                         y = j*mb_h;
40                         p = vectors + (w/mb_w)*j + i;
41
42                         if ( p->valid == 1 ) {
43                                 //draw_rectangle_outline(image, x-1, y-1, mb_w+1, mb_h+1,100);
44                                 //x += mb_w/4;
45                                 //y += mb_h/4;
46                                 //draw_rectangle_outline(image, x + p->dx, y + p->dy, mb_w, mb_h,100);
47                                 x += mb_w/2;
48                                 y += mb_h/2;
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);
51                         }
52                         else if ( p->valid == 2 ) {
53                                 draw_rectangle_outline(image, x+1, y+1, mb_w-2, mb_h-2,100);
54                         }
55                         else if ( p->valid == 3 ) {
56                                 draw_rectangle_fill(image, x-p->dx, y-p->dy, mb_w, mb_h,0);
57                         }
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);
62
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);
66                         }
67                 }
68         }
69 }
70
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 )
73 {
74         // Get the frame properties
75         mlt_properties properties = MLT_FRAME_PROPERTIES(frame);
76
77         // Get the new image
78         int error = mlt_frame_get_image( frame, image, format, width, height, 1 );
79
80         if( error != 0 )
81                 mlt_properties_debug( MLT_FRAME_PROPERTIES(frame), "error after mlt_frame_get_image()", stderr );
82
83
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" );
87
88         // Get the motion vectors
89         struct motion_vector_s *current_vectors = mlt_properties_get_data( properties, "motion_est.vectors", NULL );
90
91         init_arrows( format, *width, *height );
92
93         if ( mlt_properties_get_int( properties, "shot_change" ) == 1 )
94         {
95                 draw_line(*image, 0, 0, *width, *height, 100);
96                 draw_line(*image, 0, *height, *width, 0, 100);
97         }
98         if( current_vectors != NULL ) {
99                 paint_arrows( *image, current_vectors, *width, *height, macroblock_width, macroblock_height);
100         }
101
102         return error;
103 }
104
105
106
107 /** Filter processing.
108 */
109
110 static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
111 {
112         // Push the frame filter
113         mlt_frame_push_get_image( frame, filter_get_image );
114
115
116         return frame;
117 }
118
119 /** Constructor for the filter.
120 */
121
122
123 mlt_filter filter_vismv_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
124 {
125         mlt_filter this = mlt_filter_new( );
126         if ( this != NULL )
127         {
128                 this->process = filter_process;
129
130         }
131
132         return this;
133 }
134
135 /** This source code will self destruct in 5...4...3...
136 */
137
138
139
140
141
142
143
144