]> git.sesse.net Git - mlt/blob - src/modules/core/filter_region.c
Fix reading binary files on Windows.
[mlt] / src / modules / core / filter_region.c
1 /*
2  * filter_region.c -- region filter
3  * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4  * Author: Charles Yates <charles.yates@pandora.be>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include "transition_region.h"
22
23 #include <framework/mlt_filter.h>
24 #include <framework/mlt.h>
25
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29
30 /** Filter processing.
31 */
32
33 static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
34 {
35         // Get the filter
36         mlt_filter filter = mlt_frame_pop_service( frame );
37
38         // Get the properties of the filter
39         mlt_properties properties = MLT_FILTER_PROPERTIES( filter );
40
41         mlt_service_lock( MLT_FILTER_SERVICE( filter ) );
42
43         // Get the region transition
44         mlt_transition transition = mlt_properties_get_data( properties, "_transition", NULL );
45
46         // Create the transition if not available
47         if ( transition == NULL )
48         {
49                 // Create the transition
50                 mlt_profile profile = mlt_service_profile( MLT_FILTER_SERVICE( filter ) );
51                 transition = mlt_factory_transition( profile, "region", NULL );
52
53                 // Register with the filter
54                 mlt_properties_set_data( properties, "_transition", transition, 0, ( mlt_destructor )mlt_transition_close, NULL );
55
56                 // Pass a reference to this filter down
57                 mlt_properties_set_data( MLT_TRANSITION_PROPERTIES( transition ), "_region_filter", filter, 0, NULL, NULL );
58         }
59
60         mlt_service_unlock( MLT_FILTER_SERVICE( filter ) );
61
62         // Pass all properties down
63         mlt_properties_inherit( MLT_TRANSITION_PROPERTIES( transition ), properties );
64
65         // Make the frame's position relative to this filter's in point
66         mlt_frame_set_position( frame, mlt_filter_get_position( filter, frame ) );
67
68         // Process the frame
69         mlt_transition_process( transition, frame, NULL );
70
71         return mlt_frame_get_image( frame, image, format, width, height, writable );
72 }
73
74 static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
75 {
76         mlt_frame_push_service( frame, this );
77         mlt_frame_push_get_image( frame, filter_get_image );
78
79         return frame;
80 }
81
82 /** Constructor for the filter.
83 */
84
85 mlt_filter filter_region_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
86 {
87         // Create a new filter
88         mlt_filter this = mlt_filter_new( );
89
90         // Further initialisation
91         if ( this != NULL )
92         {
93                 // Get the properties from the filter
94                 mlt_properties properties = MLT_FILTER_PROPERTIES( this );
95
96                 // Assign the filter process method
97                 this->process = filter_process;
98
99                 // Resource defines the shape of the region
100                 mlt_properties_set( properties, "resource", arg == NULL ? "rectangle" : arg );
101
102                 // Ensure that attached filters are handled privately
103                 mlt_properties_set_int( properties, "_filter_private", 1 );
104         }
105
106         // Return the filter
107         return this;
108 }