]> git.sesse.net Git - mlt/commitdiff
refactor field order correction into new filter
authorDan Dennedy <dan@dennedy.org>
Fri, 9 Dec 2011 04:12:57 +0000 (20:12 -0800)
committerDan Dennedy <dan@dennedy.org>
Fri, 9 Dec 2011 04:12:57 +0000 (20:12 -0800)
src/modules/core/Makefile
src/modules/core/factory.c
src/modules/core/filter_fieldorder.c [new file with mode: 0644]
src/modules/core/filter_fieldorder.yml [new file with mode: 0644]
src/modules/core/filter_resize.c
src/modules/core/filter_resize.yml
src/modules/core/loader.ini

index 31edacd94d6c6b7965a2f67b3851c2ba71702689..b86c7f1c611427caeef9331d61cb1b97fc209faa 100644 (file)
@@ -22,6 +22,7 @@ OBJS = factory.o \
           filter_crop.o \
           filter_data_feed.o \
           filter_data_show.o \
+          filter_fieldorder.o \
           filter_gamma.o \
           filter_greyscale.o \
           filter_imageconvert.o \
index 2396562591154c56c7431400a8a9f6ee39f210d1..34246ed2be79cab250452de876aa06837afbbfb4 100644 (file)
@@ -32,6 +32,7 @@ extern mlt_filter filter_channelcopy_init( mlt_profile profile, mlt_service_type
 extern mlt_filter filter_crop_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg );
 extern mlt_filter filter_data_feed_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg );
 extern mlt_filter filter_data_show_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg );
+extern mlt_filter filter_fieldorder_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg );
 extern mlt_filter filter_gamma_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg );
 extern mlt_filter filter_greyscale_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg );
 extern mlt_filter filter_imageconvert_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg );
@@ -78,6 +79,7 @@ MLT_REPOSITORY
     MLT_REGISTER( filter_type, "crop", filter_crop_init );
        MLT_REGISTER( filter_type, "data_feed", filter_data_feed_init );
        MLT_REGISTER( filter_type, "data_show", filter_data_show_init );
+       MLT_REGISTER( filter_type, "fieldorder", filter_fieldorder_init );
        MLT_REGISTER( filter_type, "gamma", filter_gamma_init );
        MLT_REGISTER( filter_type, "greyscale", filter_greyscale_init );
        MLT_REGISTER( filter_type, "grayscale", filter_greyscale_init );
@@ -114,6 +116,7 @@ MLT_REPOSITORY
        MLT_REGISTER_METADATA( filter_type, "channelswap", metadata, "filter_channelcopy.yml" );
        MLT_REGISTER_METADATA( filter_type, "crop", metadata, "filter_crop.yml" );
        MLT_REGISTER_METADATA( filter_type, "data_show", metadata, "filter_data_show.yml" );
+       MLT_REGISTER_METADATA( filter_type, "fieldorder", metadata, "filter_fieldorder.yml" );
        MLT_REGISTER_METADATA( filter_type, "gamma", metadata, "filter_gamma.yml" );
        MLT_REGISTER_METADATA( filter_type, "greyscale", metadata, "filter_greyscale.yml" );
        MLT_REGISTER_METADATA( filter_type, "grayscale", metadata, "filter_greyscale.yml" );
diff --git a/src/modules/core/filter_fieldorder.c b/src/modules/core/filter_fieldorder.c
new file mode 100644 (file)
index 0000000..5da82d8
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * filter_fieldorder.c -- change field dominance
+ * Copyright (C) 2011 Ushodaya Enterprises Limited
+ * Author: Dan Dennedy <dan@dennedy.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include <framework/mlt.h>
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <math.h>
+
+static int get_image( mlt_frame frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
+{
+       // Get the properties from the frame
+       mlt_properties properties = MLT_FRAME_PROPERTIES( frame );
+
+       int error = mlt_frame_get_image( frame, image, format, width, height, writable );
+
+       if ( !error && *image )
+       {
+               int bpp;
+               int size = mlt_image_format_size( *format, *width, *height, &bpp );
+               int tff = mlt_properties_get_int( properties, "consumer_tff" );
+
+               // Provides a manual override for misreported field order
+               if ( mlt_properties_get( properties, "meta.top_field_first" ) )
+                       mlt_properties_set_int( properties, "top_field_first", mlt_properties_get_int( properties, "meta.top_field_first" ) );
+
+               // Correct field order if needed
+               if ( mlt_properties_get_int( properties, "top_field_first" ) != tff &&
+                    mlt_properties_get( properties, "progressive" ) &&
+                    mlt_properties_get_int( properties, "progressive" ) == 0 )
+               {
+                       // Get the input image, width and height
+                       uint8_t *new_image = mlt_pool_alloc( size );
+                       uint8_t *ptr = new_image + *width * bpp;
+                       memcpy( new_image, *image, *width * bpp );
+                       memcpy( ptr, *image, *width * ( *height - 1 ) * bpp );
+                       mlt_frame_set_image( frame, new_image, size, mlt_pool_release );
+                       *image = new_image;
+
+                       // Set the normalised field order
+                       mlt_properties_set_int( properties, "top_field_first", tff );
+                       mlt_properties_set_int( properties, "meta.top_field_first", tff );
+               }
+       }
+
+       return error;
+}
+
+static mlt_frame process( mlt_filter filter, mlt_frame frame )
+{
+       mlt_frame_push_get_image( frame, get_image );
+       return frame;
+}
+
+mlt_filter filter_fieldorder_init( mlt_profile profile, mlt_service_type type, const char *id, char *arg )
+{
+       mlt_filter filter = calloc( 1, sizeof( *filter ) );
+       if ( mlt_filter_init( filter, NULL ) == 0 )
+       {
+               filter->process = process;
+       }
+       return filter;
+}
diff --git a/src/modules/core/filter_fieldorder.yml b/src/modules/core/filter_fieldorder.yml
new file mode 100644 (file)
index 0000000..75971d5
--- /dev/null
@@ -0,0 +1,23 @@
+schema_version: 0.1
+type: filter
+identifier: fieldorder
+title: Field order
+description: Correct the field order of interlaced video.
+version: 1
+copyright: Ushodaya Enterprises Limited
+creator: Dan Dennedy <dan@dennedy.org>
+license: LGPLv2.1
+language: en
+tags:
+  - Video
+  - Hidden
+notes: >
+  This filter is automatically invoked by the loader as part of image
+  normalisation.
+parameters:
+  - identifier: argument
+    title: Scale
+    type: string
+    description: The scaling method.
+    required: no
+    readonly: no
index 0c5d64ec7e8690f65c1734228a3a8ff47e5dd7fb..af7a0254f55d16315edb58088b46cabb2e084ea9 100644 (file)
 #include <stdlib.h>
 #include <math.h>
 
-/** Swapbytes inline.
-*/
-
-static inline void swap_bytes( uint8_t *upper, uint8_t *lower )
-{
-       uint8_t t = *lower;
-       *lower = *upper;
-       *upper = t;
-}
-
 static uint8_t *resize_alpha( uint8_t *input, int owidth, int oheight, int iwidth, int iheight, uint8_t alpha_value )
 {
        uint8_t *output = NULL;
@@ -268,48 +258,9 @@ static int filter_get_image( mlt_frame this, uint8_t **image, mlt_image_format *
 
        if ( error == 0 && *image )
        {
-               // Get the requested scale operation
-               char *op = mlt_properties_get( MLT_FILTER_PROPERTIES( filter ), "scale" );
                int bpp;
-               int size = mlt_image_format_size( *format, owidth, oheight, &bpp );
-               int tff = mlt_properties_get_int( properties, "consumer_tff" );
-
-               // Provides a manual override for misreported field order
-               if ( mlt_properties_get( properties, "meta.top_field_first" ) )
-                       mlt_properties_set_int( properties, "top_field_first", mlt_properties_get_int( properties, "meta.top_field_first" ) );
-
-               // Correct field order if needed
-               if ( mlt_properties_get_int( properties, "top_field_first" ) != tff &&
-                    mlt_properties_get( properties, "progressive" ) &&
-                    mlt_properties_get_int( properties, "progressive" ) == 0 )
-               {
-                       // Get the input image, width and height
-                       uint8_t *new_image = mlt_pool_alloc( size );
-                       uint8_t *ptr = new_image + owidth * bpp;
-                       memcpy( new_image, *image, owidth * bpp );
-                       memcpy( ptr, *image, owidth * ( oheight - 1 ) * bpp );
-                       mlt_frame_set_image( this, new_image, size, mlt_pool_release );
-                       *image = new_image;
-                       
-                       // Set the normalised field order
-                       mlt_properties_set_int( properties, "top_field_first", tff );
-                       mlt_properties_set_int( properties, "meta.top_field_first", tff );
-               }
-
-               if ( !strcmp( op, "affine" ) )
-               {
-                       // TODO: Determine where this is needed and find a different way
-                       // *image = mlt_frame_rescale_image( this, *width, *height, bpp );
-               }
-               else if ( strcmp( op, "none" ) != 0 )
-               {
-                       *image = frame_resize_image( this, *width, *height, bpp );
-               }
-               else
-               {
-                       *width = owidth;
-                       *height = oheight;
-               }
+               mlt_image_format_size( *format, owidth, oheight, &bpp );
+               *image = frame_resize_image( this, *width, *height, bpp );
        }
 
        return error;
@@ -341,7 +292,6 @@ mlt_filter filter_resize_init( mlt_profile profile, mlt_service_type type, const
        if ( mlt_filter_init( this, this ) == 0 )
        {
                this->process = filter_process;
-               mlt_properties_set( MLT_FILTER_PROPERTIES( this ), "scale", arg == NULL ? "off" : arg );
        }
        return this;
 }
index a99444e693086f7182e3ca83714d39aae5b90d45..18cb8ffad45f10cdee4465df88dc3699850bd9d6 100644 (file)
@@ -1,8 +1,8 @@
 schema_version: 0.1
 type: filter
 identifier: resize
-title: Resize
-version: 1
+title: Pad
+version: 2
 copyright: Ushodaya Enterprises Limited
 creator: Charles Yates <charles.yates@pandora.be>
 license: LGPLv2.1
@@ -10,24 +10,9 @@ language: en
 tags:
   - Video
   - Hidden
-description: >
-  Image scaling and padding and field order adjustment.
+description: Pad an image with black to fulfill the requested image size.
 notes: >
   Normally resize is used to pad the producer's output to what the consumer has 
   requested after an upstream rescale filter first scales the image to maximise 
-  usage of the image area. This filter also adjusts the field order to lower 
-  field first if the frame property "top_field_first" has been set to 1. 
-  Therefore, when done, it sets the top_field_first to 0. This filter is 
-  automatically invoked by the loader as part of image sample aspect ratio 
-  normalisation.
-bugs:
-  - Assumes lower field first output.
-parameters:
-  - identifier: argument
-    title: Scale
-    type: string
-    description: The scaling method.
-    values:
-      - affine
-    required: no
-    readonly: no
+  usage of the image area. This filter is automatically invoked by the loader
+  as part of image normalisation.
index 484a4376ca8a5cad1ad8103c8de2409873b82c3b..d7967eddb238dfdb48ef2b62acabc848008de82a 100644 (file)
@@ -10,6 +10,7 @@
 crop=crop:1
 deinterlace=deinterlace,avdeinterlace
 rescaler=swscale,gtkrescale,rescale
+fieldorder=fieldorder
 resizer=resize
 
 # audio filters