fade in / out in titler fix from freelancer
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / titler / titler.C
index 0fc66692f9c4d3667b5a6a6963feab52be32237c..37582050c4146dc447e451de2895aca71a9e32f3 100644 (file)
@@ -76,7 +76,7 @@ REGISTER_PLUGIN(TitleMain)
 #else
 #define DEFAULT_ENCODING "ISO8859-1"
 #endif
-#define DEFAULT_TIMECODEFORMAT TIME_HMS
+#define DEFAULT_TIMECODEFORMAT TIME_HMSF
 
 static inline int kw_strcmp(const char *ap, const char *bp) {
        return !strcmp(ap, bp) ? 0 : strcmp(ap,_(bp));
@@ -87,11 +87,11 @@ TitleConfig::TitleConfig()
        strcpy(font, "fixed");
        strcpy(encoding, DEFAULT_ENCODING);
        style = FONT_ALIAS;
-       size = 24;
-       color = BLACK;
+       size = 48;
+       color = WHITE;
        alpha = 0xff;
        outline_size = 0.;
-       outline_color = WHITE;
+       outline_color = RED;
        outline_alpha = 0xff;
        color_stroke = 0xff0000;
        stroke_width = 0.0;
@@ -110,11 +110,10 @@ TitleConfig::TitleConfig()
        next_keyframe_position = 0;
        prev_keyframe_position = 0;
        timecode = 0;
-       dropshadow = 2;
+       dropshadow = 0;
        background = 0;
        strcpy(background_path, "");
        timecode_format = DEFAULT_TIMECODEFORMAT;
-       drag = 0;
        loop_playback = 0;
 }
 
@@ -146,7 +145,7 @@ int TitleConfig::equivalent(TitleConfig &that)
 //             EQUIV(pixels_per_second, that.pixels_per_second) &&
                wlen == that.wlen &&
                !memcmp(wtext, that.wtext, wlen * sizeof(wchr_t)) &&
-               title_x == that.title_x && title_y == that.title_y &&
+               EQUIV(title_x, that.title_x) && EQUIV(title_y, that.title_y) &&
                title_w == that.title_w && title_h == that.title_h &&
 //             window_w == that.window_w && window_h == that.window_h &&
                timecode == that.timecode &&
@@ -154,7 +153,6 @@ int TitleConfig::equivalent(TitleConfig &that)
                background == that.background &&
                !strcmp(background_path, that.background_path) &&
                timecode_format == that.timecode_format &&
-//             drag == that.drag &&
                loop_playback == that.loop_playback;
 }
 
@@ -189,7 +187,6 @@ void TitleConfig::copy_from(TitleConfig &that)
        background = that.background;
        strcpy(background_path, that.background_path);
        timecode_format = that.timecode_format;
-       drag = that.drag;
        loop_playback = that.loop_playback;
 }
 
@@ -236,7 +233,6 @@ void TitleConfig::interpolate(TitleConfig &prev, TitleConfig &next,
        background = prev.background;
        strcpy(background_path, prev.background_path);
        timecode_format = prev.timecode_format;
-       drag = prev.drag;
        loop_playback = prev.loop_playback;
 }
 
@@ -598,7 +594,6 @@ void TitleUnit::draw_frame(int mode, VFrame *dst, VFrame *src, int x, int y)
        int color = chr->color, max = 0xff;
        int alpha = chr->alpha * chr->fade;
        int ofs = BC_CModels::is_yuv(dst->get_color_model()) ? 0x80 : 0x00;
-
        switch( mode ) {
        case DRAW_ALPHA: {
                while( y_inp < inp_h && y_out < out_h ) {
@@ -935,6 +930,7 @@ TitleMain::TitleMain(PluginServer *server)
        if( cpus > 8 ) cpus = 8;
        last_position = -1;
        need_reconfigure = 1;
+       drag = 0;
 }
 
 TitleMain::~TitleMain()
@@ -944,7 +940,8 @@ TitleMain::~TitleMain()
                background = 0;
        }
        delete render_engine;
-       delete video_cache;
+       if( video_cache )
+               video_cache->remove_user(); 
        delete overlay_frame;
        delete bg_file;
        delete bg_frame;
@@ -967,6 +964,18 @@ int TitleMain::is_synthesis() { return 1; }
 
 NEW_WINDOW_MACRO(TitleMain, TitleWindow);
 
+void TitleMain::render_gui(void *data)
+{
+       TitleMain *tilter = (TitleMain *)data;
+       tilter->drag = drag;
+}
+
+int TitleMain::is_dragging()
+{
+       drag = 0;
+       send_render_gui(this);
+       return drag;
+}
 
 void TitleMain::build_previews(TitleWindow *gui)
 {
@@ -1186,7 +1195,7 @@ int TitleMain::load_font(BC_FontEntry *font)
 Indexable *TitleMain::open_background(const char *filename)
 {
        delete render_engine;  render_engine = 0;
-       delete video_cache;    video_cache = 0;
+       if( video_cache ) { video_cache->remove_user();  video_cache = 0; }
        delete bg_file;        bg_file = new File;
 
        Asset *asset = new Asset(filename);
@@ -1203,7 +1212,7 @@ Indexable *TitleMain::open_background(const char *filename)
        nested_edl->create_objects();
        nested_edl->set_path(filename);
        nested_edl->load_xml(&xml_file, LOAD_ALL);
-       TransportCommand command;
+       TransportCommand command(server->preferences);
        //command.command = audio_tracks ? NORMAL_FWD : CURRENT_FRAME;
        command.command = CURRENT_FRAME;
        command.get_edl()->copy_all(nested_edl);
@@ -2145,7 +2154,6 @@ int TitleMain::draw_underline(VFrame *mask, int alpha)
 
 void TitleMain::draw_overlay()
 {
-//printf("TitleMain::draw_overlay 1\n");
         fade = 1;
         if( !EQUIV(config.fade_in, 0) ) {
                int64_t plugin_start = get_startproject();
@@ -2265,11 +2273,16 @@ TitleTranslateUnit::TitleTranslateUnit(TitleMain *plugin, TitleTranslate *server
                        type in_r = (cp00[0]*a00 + cp01[0]*a01 + cp10[0]*a10 + cp11[0]*a11)*s + r; \
                        type in_g = (cp00[1]*a00 + cp01[1]*a01 + cp10[1]*a10 + cp11[1]*a11)*s + r; \
                        type in_b = (cp00[2]*a00 + cp01[2]*a01 + cp10[2]*a10 + cp11[2]*a11)*s + r; \
-                       type a = in_a*plugin->fade, b = max - a, px; \
-                       /*if( comps == 4 ) { b = (b * op[3]) / max; }*/ \
-                       px = *op;  *op++ = (a*in_r + b*px) / max; \
-                       px = *op;  *op++ = (a*(in_g-ofs) + b*(px-ofs)) / max + ofs; \
-                       px = *op;  *op++ = (a*(in_b-ofs) + b*(px-ofs)) / max + ofs; \
+                       type a = in_a*plugin->fade, px; \
+                       type b ; \
+                       double total_alpha, double_b; \
+                       if ( comps == 4 ) { b = *(op+3); } \
+                       else b = max - a; \
+                       double_b = (1.0 * b * (max - a)/(max*1.0)); \
+                       total_alpha = a + double_b; \
+                       px = *op;  *op++ = (a*in_r + double_b*px) / total_alpha; \
+                       px = *op;  *op++ = (a*(in_g-ofs) + double_b*(px-ofs)) / total_alpha + ofs; \
+                       px = *op;  *op++ = (a*(in_b-ofs) + double_b*(px-ofs)) / total_alpha + ofs; \
                        if( comps == 4 ) { b = *op;  *op++ = a + b - a*b / max; } \
                } \
        } \
@@ -2451,7 +2464,7 @@ int TitleMain::process_realtime(VFrame *input_ptr, VFrame *output_ptr)
        if( !result )
                draw_overlay();
 
-       if( config.drag )
+       if( is_dragging() )
                draw_boundry();
 
        return 0;
@@ -2544,7 +2557,6 @@ void TitleMain::save_data(KeyFrame *keyframe)
        output.tag.set_property("TIMECODEFORMAT", config.timecode_format);
        output.tag.set_property("WINDOW_W", config.window_w);
        output.tag.set_property("WINDOW_H", config.window_h);
-       output.tag.set_property("DRAG", config.drag);
        output.tag.set_property("BACKGROUND", config.background);
        output.tag.set_property("BACKGROUND_PATH", config.background_path);
        output.tag.set_property("LOOP_PLAYBACK", config.loop_playback);
@@ -2608,7 +2620,6 @@ void TitleMain::read_data(KeyFrame *keyframe)
                        config.timecode_format = input.tag.get_property("TIMECODEFORMAT", config.timecode_format);
                        config.window_w = input.tag.get_property("WINDOW_W", config.window_w);
                        config.window_h = input.tag.get_property("WINDOW_H", config.window_h);
-                       config.drag = input.tag.get_property("DRAG", config.drag);
                        config.background = input.tag.get_property("BACKGROUND", config.background);
                        input.tag.get_property("BACKGROUND_PATH", config.background_path);
                        config.loop_playback = input.tag.get_property("LOOP_PLAYBACK", config.loop_playback);