2 * filter_brightness.c -- gamma filter
3 * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
4 * Author: Charles Yates <charles.yates@pandora.be>
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.
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.
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
21 #include <framework/mlt_filter.h>
22 #include <framework/mlt_frame.h>
29 #define CLAMP( x, min, max ) (x) < (min) ? (min) : (x) > (max) ? (max) : (x)
35 static int filter_get_image( mlt_frame frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
37 mlt_filter filter = (mlt_filter) mlt_frame_pop_service( frame );
38 mlt_properties properties = MLT_FILTER_PROPERTIES( filter );
39 mlt_position position = mlt_filter_get_position( filter, frame );
40 mlt_position length = mlt_filter_get_length2( filter, frame );
43 *format = mlt_image_yuv422;
44 int error = mlt_frame_get_image( frame, image, format, width, height, 1 );
46 // Only process if we have no error and a valid colour space
51 // Use animated "level" property only if it has been set since init
52 char* level_property = mlt_properties_get( MLT_FILTER_PROPERTIES( filter ), "level" );
53 if ( strcmp( level_property, UNSET ) != 0 )
55 level = mlt_properties_anim_get_double( properties, "level", position, length );
59 // Get level using old "start,"end" mechanics
60 // Get the starting brightness level
61 level = fabs( mlt_properties_get_double( MLT_FILTER_PROPERTIES( filter ), "start" ) );
63 // If there is an end adjust gain to the range
64 if ( mlt_properties_get( MLT_FILTER_PROPERTIES( filter ), "end" ) != NULL )
66 // Determine the time position of this frame in the transition duration
67 double end = fabs( mlt_properties_get_double( MLT_FILTER_PROPERTIES( filter ), "end" ) );
68 level += ( end - level ) * mlt_filter_get_progress( filter, frame );
72 // Only process if level is something other than 1
75 int i = *width * *height + 1;
77 int32_t m = level * ( 1 << 16 );
78 int32_t n = 128 * ( ( 1 << 16 ) - m );
82 p[0] = CLAMP( (p[0] * m) >> 16, 16, 235 );
83 p[1] = CLAMP( (p[1] * m + n) >> 16, 16, 240 );
92 /** Filter processing.
95 static mlt_frame filter_process( mlt_filter filter, mlt_frame frame )
97 mlt_frame_push_service( frame, filter );
98 mlt_frame_push_get_image( frame, filter_get_image );
103 /** Constructor for the filter.
106 mlt_filter filter_brightness_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
108 mlt_filter filter = mlt_filter_new( );
109 if ( filter != NULL )
111 filter->process = filter_process;
112 mlt_properties_set( MLT_FILTER_PROPERTIES( filter ), "start", arg == NULL ? "1" : arg );
113 mlt_properties_set( MLT_FILTER_PROPERTIES( filter ), "level", UNSET );