fix Sample ref constructor for segv in resamplert
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / yuv411 / yuv411win.C
1 #include "bcdisplayinfo.h"
2 #include "edl.h"
3 #include "edlsession.h"
4 #include "yuv411win.h"
5 #include "language.h"
6
7 yuv411Window::yuv411Window(yuv411Main *client)
8  : PluginClientWindow(client, xS(260), yS(250), xS(260), yS(250), 0)
9 {
10         this->client = client;
11         colormodel = -1;
12 }
13
14 yuv411Window::~yuv411Window()
15 {
16 }
17
18 void yuv411Window::create_objects()
19 {
20         int xs10 = xS(10), xs90 = xS(90);
21         int ys10 = yS(10), ys30 = yS(30);
22         int x = xs10, y = ys10, x1=xs90;
23         add_tool(avg_vertical = new yuv411Toggle(client,
24                 &(client->config.avg_vertical),
25                 _("Vertical average"),
26                 x,
27                 y));
28         y += ys30;
29         add_tool(int_horizontal = new yuv411Toggle(client,
30                 &(client->config.int_horizontal),
31                 _("Horizontal interpolate"),
32                 x,
33                 y));
34         y += ys30;
35         add_tool(inpainting = new yuv411Toggle(client,
36                 &(client->config.inpainting),
37                 _("Inpainting method"),
38                 x,
39                 y));
40         y += ys30;
41         add_subwindow(new BC_Title(x, y, _("Offset:")));
42         add_subwindow(offset=new yuv411Offset(client,x1,y));
43         y += ys30;
44         add_subwindow(new BC_Title(x, y, _("Threshold:")));
45         add_subwindow(thresh=new yuv411Thresh(client,x1,y));
46         y += ys30;
47         add_subwindow(new BC_Title(x, y, _("Bias:")));
48         add_subwindow(bias=new yuv411Bias(client,x1,y));
49         y += ys30;
50         int y1 = get_h() - yuv411Reset::calculate_h() - yS(20);
51         add_subwindow(reset = new yuv411Reset(client, this, x, y1+ys10));
52         show_window();
53         flush();
54
55         yuv_warning = new BC_Title(x, y, _("Warning: colormodel not YUV"),MEDIUMFONT,RED);
56         add_subwindow(yuv_warning);
57         EDL *edl = client->get_edl();
58         colormodel = edl->session->color_model;
59         switch( colormodel ) {
60         case BC_YUV888:
61         case BC_YUVA8888:
62                 yuv_warning->hide_window();
63                 break;
64         }
65 }
66
67 void yuv411Window::update()
68 {
69         avg_vertical->update(client->config.avg_vertical);
70         int_horizontal->update(client->config.int_horizontal);
71         inpainting->update(client->config.inpainting);
72         offset->update(client->config.offset);
73         thresh->update(client->config.thresh);
74         bias->update(client->config.bias);
75 }
76
77 int yuv411Window::close_event()
78 {
79         set_done(1);
80         return 1;
81 }
82
83 yuv411Toggle::yuv411Toggle(yuv411Main *client, int *output, char *string, int x, int y)
84  : BC_CheckBox(x, y, *output, string)
85 {
86         this->client = client;
87         this->output = output;
88 }
89 yuv411Toggle::~yuv411Toggle()
90 {
91 }
92 int yuv411Toggle::handle_event()
93 {
94         *output = get_value();
95         ((yuv411Window*)client->thread->window)->update_enables();
96         client->send_configure_change();
97         return 1;
98 }
99
100 yuv411Offset::yuv411Offset(yuv411Main *client, int x, int y)
101  :  BC_FSlider(x+xS(60), y, 0, xS(100), yS(100), (float)0, (float)2,
102             (float)client->config.offset)
103 {
104         this->client = client;
105         set_precision(1.0);
106 }
107 int yuv411Offset::handle_event()
108 {
109         client->config.offset = get_value();
110         client->send_configure_change();
111         return 1;
112 }
113
114 yuv411Thresh::yuv411Thresh(yuv411Main *client, int x, int y)
115  :  BC_FSlider(x+xS(60), y, 0, xS(100), yS(100), (float)1, (float)100,
116             (float)client->config.thresh)
117 {
118         this->client = client;
119         set_precision(1.0);
120 }
121 int yuv411Thresh::handle_event()
122 {
123         client->config.thresh = get_value();
124         client->send_configure_change();
125         return 1;
126 }
127
128 yuv411Bias::yuv411Bias(yuv411Main *client, int x, int y)
129  :  BC_FSlider(x+xS(60), y, 0, xS(100), yS(100), (float)0, (float)25,
130             (float)client->config.bias)
131 {
132         this->client = client;
133         set_precision(1.0);
134 }
135
136 int yuv411Bias::handle_event()
137 {
138         client->config.bias = get_value();
139         client->send_configure_change();
140         return 1;
141 }
142
143 yuv411Reset::yuv411Reset(yuv411Main *client, yuv411Window *window, int x, int y)
144  : BC_GenericButton(x, y, _("Reset"))
145 {
146         this->client = client;
147         this->window = window;
148 }
149 yuv411Reset::~yuv411Reset()
150 {
151 }
152 int yuv411Reset::handle_event()
153 {
154         client->config.reset();
155         window->update();
156         window->update_enables();
157         client->send_configure_change();
158         return 1;
159 }
160
161
162 void yuv411Window::update_enables()
163 {
164         yuv411Config &config = client->config;
165         if( !config.int_horizontal && config.inpainting ) {
166                 config.inpainting = 0;
167                 inpainting->set_value(0);
168         }
169         if( config.int_horizontal ) {
170                 inpainting->enable();
171                 offset->show_window();
172         }
173         else {
174                 inpainting->disable();
175                 offset->hide_window();
176         }
177         if( config.int_horizontal && config.inpainting ) {
178                 thresh->show_window();
179                 bias->show_window();
180         }
181         else {
182                 thresh->hide_window();
183                 bias->hide_window();
184         }
185 }
186
187 void yuv411Window::show_warning(int warn)
188 {
189         if( warn )
190                 yuv_warning->show_window();
191         else
192                 yuv_warning->hide_window();
193 }
194