]> git.sesse.net Git - mlt/commitdiff
affine with alpha and a broken sepia
authorlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Sun, 20 Jun 2004 09:24:55 +0000 (09:24 +0000)
committerlilo_booter <lilo_booter@d19143bc-622f-0410-bfdd-b5b2a6649095>
Sun, 20 Jun 2004 09:24:55 +0000 (09:24 +0000)
git-svn-id: https://mlt.svn.sourceforge.net/svnroot/mlt/trunk/mlt@331 d19143bc-622f-0410-bfdd-b5b2a6649095

src/modules/plus/Makefile
src/modules/plus/configure
src/modules/plus/factory.c
src/modules/plus/filter_sepia.c [new file with mode: 0644]
src/modules/plus/filter_sepia.h [new file with mode: 0644]
src/modules/plus/transition_affine.c

index 0131198a7ee73b531e6bd1304e6ecb9447f956b3..fc90e24552b62fcd3bd670957c2e1653dfc1534e 100644 (file)
@@ -5,6 +5,7 @@ TARGET = ../libmltplus.so
 OBJS = factory.o \
           filter_charcoal.o \
           filter_invert.o \
+          filter_sepia.o \
           transition_affine.o
 
 CFLAGS += -I../..
index e3a797eb64162f359f015b54bdf0d85300157d81..cd026690e05bd625b3c8b0ddec6a811c559edc00 100755 (executable)
@@ -9,6 +9,7 @@ EOF
 cat << EOF >> ../filters.dat
 charcoal               libmltplus.so
 invert                 libmltplus.so
+sepia                  libmltplus.so
 EOF
 
 cat << EOF >> ../transitions.dat
index 956f42db17de0987acdebaa61fe371f173f76f71..39fba3a6640a487a93eb3d9a80124e568667aad0 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "filter_charcoal.h"
 #include "filter_invert.h"
+#include "filter_sepia.h"
 #include "transition_affine.h"
 
 void *mlt_create_producer( char *id, void *arg )
@@ -35,6 +36,8 @@ void *mlt_create_filter( char *id, void *arg )
                return filter_charcoal_init( arg );
        if ( !strcmp( id, "invert" ) )
                return filter_invert_init( arg );
+       if ( !strcmp( id, "sepia" ) )
+               return filter_sepia_init( arg );
        return NULL;
 }
 
diff --git a/src/modules/plus/filter_sepia.c b/src/modules/plus/filter_sepia.c
new file mode 100644 (file)
index 0000000..56fe4ec
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * filter_sepia.c -- sepia filter
+ * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
+ * Author: Charles Yates <charles.yates@pandora.be>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#include "filter_sepia.h"
+
+#include <framework/mlt_frame.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+
+/** Do it :-).
+*/
+
+static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
+{
+       // Get the filter
+       mlt_filter filter = mlt_frame_pop_service( this );
+
+       // Get the image
+       int error = mlt_frame_get_image( this, image, format, width, height, 1 );
+
+       // Only process if we have no error and a valid colour space
+       if ( error == 0 && *format == mlt_image_yuv422 )
+       {
+               // We modify the whole image
+               uint8_t *p = *image;
+               uint8_t *q = *image + *height * *width * 2;
+
+               // Get u and v values
+               int u = mlt_properties_get_int( mlt_filter_properties( filter ), "u" );
+               int v = mlt_properties_get_int( mlt_filter_properties( filter ), "v" );
+
+               // Loop through image
+               while ( p != q )
+               {
+                       p ++;
+                       *p ++ = u;
+                       p ++;
+                       *p ++ = v;
+               }
+       }
+
+       return error;
+}
+
+/** Filter processing.
+*/
+
+static mlt_frame filter_process( mlt_filter this, mlt_frame frame )
+{
+       // Push the frame filter
+       mlt_frame_push_service( frame, this );
+       mlt_frame_push_get_image( frame, filter_get_image );
+       return frame;
+}
+
+/** Constructor for the filter.
+*/
+
+mlt_filter filter_sepia_init( char *arg )
+{
+       mlt_filter this = mlt_filter_new( );
+       if ( this != NULL )
+       {
+               this->process = filter_process;
+               mlt_properties_set( mlt_filter_properties( this ), "u", "50" );
+               mlt_properties_set( mlt_filter_properties( this ), "v", "50" );
+       }
+       return this;
+}
+
diff --git a/src/modules/plus/filter_sepia.h b/src/modules/plus/filter_sepia.h
new file mode 100644 (file)
index 0000000..b4d75eb
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * filter_sepia.h -- sepia filter
+ * Copyright (C) 2003-2004 Ushodaya Enterprises Limited
+ * Author: Charles Yates <charles.yates@pandora.be>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef _FILTER_SEPIA_H_
+#define _FILTER_SEPIA_H_
+
+#include <framework/mlt_filter.h>
+
+extern mlt_filter filter_sepia_init( char *arg );
+
+#endif
index 7e0252d97c469f152fcf2dcc9c353cc1ca782e49..e04f9ff690d4dcd68726887459fd86d3a2fbba4d 100644 (file)
@@ -385,7 +385,7 @@ static void affine_scale( float this[3][3], float sx, float sy )
 }
 
 // Shear by a given value
-static void affine_shear( float this[3][3], float shear_x, float shear_y )
+static void affine_shear( float this[3][3], float shear_x, float shear_y, float shear_z )
 {
        float affine[3][3];
        affine[0][0] = 1;
@@ -393,7 +393,7 @@ static void affine_shear( float this[3][3], float shear_x, float shear_y )
        affine[0][2] = 0;
        affine[1][0] = tan( shear_y * M_PI / 180 );
        affine[1][1] = 1;
-       affine[1][2] = 0;
+       affine[1][2] = tan( shear_z * M_PI / 180 );
        affine[2][0] = 0;
        affine[2][1] = 0;
        affine[2][2] = 1;
@@ -540,6 +540,7 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
                mlt_properties_set_double( b_props, "consumer_aspect_ratio", mlt_properties_get_double( a_props, "consumer_aspect_ratio" ) );
        }
 
+       mlt_properties_set( b_props, "distort", mlt_properties_get( properties, "distort" ) );
        mlt_frame_get_image( b_frame, &b_image, &b_format, &b_width, &b_height, 0 );
        result.w = b_width;
        result.h = b_height;
@@ -557,8 +558,10 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
                float rotate_z = mlt_properties_get_double( properties, "rotate_z" );
                float fix_shear_x = mlt_properties_get_double( properties, "fix_shear_x" );
                float fix_shear_y = mlt_properties_get_double( properties, "fix_shear_y" );
+               float fix_shear_z = mlt_properties_get_double( properties, "fix_shear_z" );
                float shear_x = mlt_properties_get_double( properties, "shear_x" );
                float shear_y = mlt_properties_get_double( properties, "shear_y" );
+               float shear_z = mlt_properties_get_double( properties, "shear_z" );
                float ox = mlt_properties_get_double( properties, "ox" );
                float oy = mlt_properties_get_double( properties, "oy" );
                int scale = mlt_properties_get_int( properties, "scale" );
@@ -579,18 +582,25 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
                int x_offset = ( int )result.w >> 1;
                int y_offset = ( int )result.h >> 1;
 
+               uint8_t *alpha = mlt_frame_get_alpha_mask( b_frame );
+               float mix;
+
                affine_t affine;
                affine_init( affine.matrix );
                affine_rotate( affine.matrix, rotate_x * ( position - in ) );
                affine_rotate_y( affine.matrix, rotate_y * ( position - in ) );
                affine_rotate_z( affine.matrix, rotate_z * ( position - in ) );
-               affine_shear( affine.matrix, fix_shear_x + shear_x * ( position - in ), fix_shear_y + shear_y * ( position - in ) );
+               affine_shear( affine.matrix, 
+                                         fix_shear_x + shear_x * ( position - in ), 
+                                         fix_shear_y + shear_y * ( position - in ),
+                                         fix_shear_z + shear_z * ( position - in ) );
                affine_offset( affine.matrix, ox, oy );
 
-               affine_max_output( affine.matrix, &sw, &sh );
-
                if ( scale )
+               {
+                       affine_max_output( affine.matrix, &sw, &sh );
                        affine_scale( affine.matrix, sw, sh );
+               }
        
                lower_x -= ( lower_x & 1 );
                upper_x -= ( upper_x & 1 );
@@ -608,9 +618,19 @@ static int transition_get_image( mlt_frame a_frame, uint8_t **image, mlt_image_f
 
                                if ( dx >= 0 && dx < b_width && dy >=0 && dy < b_height )
                                {
-                                       dx -= dx & 1;
-                                       *p ++ = *( b_image + dy * b_stride + ( dx << 1 ) );
-                                       *p ++ = *( b_image + dy * b_stride + ( dx << 1 ) + ( ( x & 1 ) << 1 ) + 1 );
+                                       if ( alpha == NULL )
+                                       {
+                                               dx -= dx & 1;
+                                               *p ++ = *( b_image + dy * b_stride + ( dx << 1 ) );
+                                               *p ++ = *( b_image + dy * b_stride + ( dx << 1 ) + ( ( x & 1 ) << 1 ) + 1 );
+                                       }
+                                       else
+                                       {
+                                               dx -= dx & 1;
+                                               mix = ( float )*( alpha + dy * b_width + dx ) / 255.0;
+                                               *p ++ = *p * ( 1 - mix ) + mix * *( b_image + dy * b_stride + ( dx << 1 ) );
+                                               *p ++ = *p * ( 1 - mix ) + mix * *( b_image + dy * b_stride + ( dx << 1 ) + ( ( x & 1 ) << 1 ) + 1 );
+                                       }
                                }
                                else
                                {
@@ -660,6 +680,7 @@ mlt_transition transition_affine_init( char *arg )
        {
                mlt_properties_set_int( mlt_transition_properties( transition ), "sx", 1 );
                mlt_properties_set_int( mlt_transition_properties( transition ), "sy", 1 );
+               mlt_properties_set( mlt_transition_properties( transition ), "distort", NULL );
                mlt_properties_set( mlt_transition_properties( transition ), "start", "0,0:100%x100%" );
                transition->process = transition_process;
        }