3cac11f450ca0acb16f73a6e3a98002084ca53f9
[goodguy/history.git] / cinelerra-5.0 / plugins / lof / lof.C
1
2 #include "lofwindow.h"
3
4 // repeat last output frame on read_frame error
5 //   uses vframe.status as read status
6
7 REGISTER_PLUGIN(LofEffect)
8
9 LofConfig::LofConfig()
10 {
11         errs = 0;
12         miss = 1;
13         mark = 1;
14 }
15
16 void LofConfig::copy_from(LofConfig &src)
17 {
18         errs = src.errs;
19         miss = src.miss;
20         mark = src.mark;
21 }
22
23 int LofConfig::equivalent(LofConfig &src)
24 {
25         if( errs != src.errs ) return 0;
26         if( miss != src.miss ) return 0;
27         if( mark != src.mark ) return 0;
28         return 1;
29 }
30
31 void LofConfig::interpolate(LofConfig &prev, LofConfig &next, 
32         long prev_frame, long next_frame, long current_frame)
33 {
34         copy_from(prev);
35 }
36
37 LofEffect::LofEffect(PluginServer *server)
38  : PluginVClient(server)
39 {
40         frm = 0;
41 }
42 LofEffect::~LofEffect()
43 {
44         delete frm;
45 }
46
47 const char* LofEffect::plugin_title() { return _("Last Frame"); }
48 int LofEffect::is_realtime() { return 1; }
49
50 NEW_WINDOW_MACRO(LofEffect, LofWindow)
51 LOAD_CONFIGURATION_MACRO(LofEffect, LofConfig)
52
53 void LofEffect::update_gui()
54 {
55         if(thread) {
56                 thread->window->lock_window();
57                 load_configuration();
58                 ((LofWindow*)thread->window)->update();
59                 thread->window->unlock_window();
60         }
61 }
62
63
64 void LofEffect::save_data(KeyFrame *keyframe)
65 {
66         FileXML output;
67         output.set_shared_output(keyframe->get_data(), MESSAGESIZE);
68         output.tag.set_title("LOF");
69         output.tag.set_property("ERRS", config.errs);
70         output.tag.set_property("MISS", config.miss);
71         output.tag.set_property("MARK", config.mark);
72         output.append_tag();
73         output.terminate_string();
74 }
75
76 void LofEffect::read_data(KeyFrame *keyframe)
77 {
78         FileXML input;
79         input.set_shared_input(keyframe->get_data(), strlen(keyframe->get_data()));
80         while(!input.read_tag()) {
81                 if(input.tag.title_is("LOF")) {
82                         config.errs = input.tag.get_property("ERRS", config.errs);
83                         config.miss = input.tag.get_property("MISS", config.miss);
84                         config.mark = input.tag.get_property("MARK", config.mark);
85                 }
86         }
87 }
88
89
90 int LofEffect::process_buffer(VFrame *frame, int64_t start_position, double frame_rate)
91 {
92         load_configuration();
93         int w = frame->get_w(), h = frame->get_h();
94         int colormodel = frame->get_color_model();
95         if( frm && (frm->get_w() != w || frm->get_h() != h ||
96             frm->get_color_model() != colormodel ) ) {
97                 delete frm;  frm = 0;
98         }
99         int ret = read_frame(frame, 0, start_position, frame_rate, get_use_opengl());
100         if( ret >= 0 ) ret = frame->get_status();
101         if( ret > 0 ) {
102                 if( !frm )
103                         frm = new VFrame(w, h, colormodel, -1);
104                 frm->copy_from(frame);
105         }
106         else if( !frm )
107                 frame->clear_frame();
108         else if( (ret < 0 && config.errs) || (!ret && config.miss) ) {
109                 frame->copy_from(frm);
110                 if( config.mark ) {
111                         VFrame dot(1, 1, BC_RGBA8888, -1);
112                         *(uint32_t*)dot.get_rows()[0] = 0xff0000ff;
113                         int scl = 48, sz = 3, ww = w/scl, hh = h/scl;
114                         if( ww < sz ) ww = w > sz ? sz : w;
115                         if( hh < sz ) hh = h > sz ? sz : h;
116                         BC_CModels::transfer(
117                                 frame->get_rows(), dot.get_rows(),
118                                 frame->get_y(), frame->get_u(), frame->get_v(),
119                                 dot.get_y(), dot.get_u(), dot.get_v(),
120                                 0, 0, 1, 1, 0, 0, ww, hh,
121                                 dot.get_color_model(), frame->get_color_model(),
122                                 0, dot.get_w(), frame->get_w()); 
123                 }
124         }
125         return 0;
126 }
127
128