]> git.sesse.net Git - mlt/blobdiff - src/modules/opengl/filter_movit_opacity.cpp
Hide the movit.parms properties from serialization.
[mlt] / src / modules / opengl / filter_movit_opacity.cpp
index 8586182a9a0f2c2c3913597463506d821dd5a040..5c14465b97859c192448a6d933b24701126b293f 100644 (file)
 #include <string.h>
 #include <assert.h>
 
-#include "glsl_manager.h"
-#include <movit/mix_effect.h>
+#include "filter_glsl_manager.h"
+#include <movit/multiply_effect.h>
+
+using namespace movit;
 
 static int get_image( mlt_frame frame, uint8_t **image, mlt_image_format *format, int *width, int *height, int writable )
 {
        mlt_filter filter = (mlt_filter) mlt_frame_pop_service( frame );
        mlt_properties properties = MLT_FILTER_PROPERTIES( filter );
        GlslManager::get_instance()->lock_service( frame );
-       Effect* effect = GlslManager::get_effect( filter, frame );
-       if ( effect ) {
-               bool ok = effect->set_float( "strength_first", mlt_properties_get_double( properties, "opacity" ) );
-               assert(ok);
-       }
+       mlt_position position = mlt_filter_get_position( filter, frame );
+       mlt_position length = mlt_filter_get_length2( filter, frame );
+       double opacity = mlt_properties_anim_get_double( properties, "opacity", position, length );
+       double alpha = mlt_properties_anim_get_double( properties, "alpha", position, length );
+       mlt_properties_set_double( properties, "_movit.parms.vec4.factor[0]", opacity );
+       mlt_properties_set_double( properties, "_movit.parms.vec4.factor[1]", opacity );
+       mlt_properties_set_double( properties, "_movit.parms.vec4.factor[2]", opacity );
+       mlt_properties_set_double( properties, "_movit.parms.vec4.factor[3]", alpha >= 0 ? alpha : opacity );
        GlslManager::get_instance()->unlock_service( frame );
        *format = mlt_image_glsl;
-       return mlt_frame_get_image( frame, image, format, width, height, writable );
+       int error = mlt_frame_get_image( frame, image, format, width, height, writable );
+       GlslManager::set_effect_input( MLT_FILTER_SERVICE( filter ), frame, (mlt_service) *image );
+       GlslManager::set_effect( MLT_FILTER_SERVICE( filter ), frame, new MultiplyEffect );
+       *image = (uint8_t *) MLT_FILTER_SERVICE( filter );
+       return error;
 }
 
 static mlt_frame process( mlt_filter filter, mlt_frame frame )
 {
-       if ( !mlt_frame_is_test_card( frame ) ) {
-               Effect* effect = GlslManager::get_effect( filter, frame );
-               if ( !effect ) {
-                       effect = GlslManager::add_effect( filter, frame, new MixEffect, 0 );
-                       assert(effect);
-                       bool ok = effect->set_float( "strength_first", 1.0f );
-                       ok |= effect->set_float( "strength_second", 0.0f );
-                       assert(ok);
-               }
-       }
        mlt_frame_push_service( frame, filter );
        mlt_frame_push_get_image( frame, get_image );
        return frame;
@@ -64,7 +63,9 @@ mlt_filter filter_movit_opacity_init( mlt_profile profile, mlt_service_type type
 
        if ( glsl && ( filter = mlt_filter_new() ) ) {
                mlt_properties properties = MLT_FILTER_PROPERTIES( filter );
+               glsl->add_ref( properties );
                mlt_properties_set( properties, "opacity", arg? arg : "1" );
+               mlt_properties_set_double( properties, "alpha", -1.0 );
                filter->process = process;
        }
        return filter;