Fourth set of 50 GPL attribution for CV-Contributors added +
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / yuv411 / yuv411win.C
1 /*
2  * CINELERRA
3  * Copyright (C) 2016 Eric Olson
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU General Public License as published
7  * by the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
18  * USA
19  */
20
21 #include "bcdisplayinfo.h"
22 #include "edl.h"
23 #include "edlsession.h"
24 #include "yuv411win.h"
25 #include "language.h"
26
27 yuv411Window::yuv411Window(yuv411Main *client)
28  : PluginClientWindow(client, xS(260), yS(250), xS(260), yS(250), 0)
29 {
30         this->client = client;
31         colormodel = -1;
32 }
33
34 yuv411Window::~yuv411Window()
35 {
36 }
37
38 void yuv411Window::create_objects()
39 {
40         int xs10 = xS(10), xs90 = xS(90);
41         int ys10 = yS(10), ys30 = yS(30);
42         int x = xs10, y = ys10, x1=xs90;
43         add_tool(avg_vertical = new yuv411Toggle(client,
44                 &(client->config.avg_vertical),
45                 _("Vertical average"),
46                 x,
47                 y));
48         y += ys30;
49         add_tool(int_horizontal = new yuv411Toggle(client,
50                 &(client->config.int_horizontal),
51                 _("Horizontal interpolate"),
52                 x,
53                 y));
54         y += ys30;
55         add_tool(inpainting = new yuv411Toggle(client,
56                 &(client->config.inpainting),
57                 _("Inpainting method"),
58                 x,
59                 y));
60         y += ys30;
61         add_subwindow(new BC_Title(x, y, _("Offset:")));
62         add_subwindow(offset=new yuv411Offset(client,x1,y));
63         y += ys30;
64         add_subwindow(new BC_Title(x, y, _("Threshold:")));
65         add_subwindow(thresh=new yuv411Thresh(client,x1,y));
66         y += ys30;
67         add_subwindow(new BC_Title(x, y, _("Bias:")));
68         add_subwindow(bias=new yuv411Bias(client,x1,y));
69         y += ys30;
70         int y1 = get_h() - yuv411Reset::calculate_h() - yS(20);
71         add_subwindow(reset = new yuv411Reset(client, this, x, y1+ys10));
72         show_window();
73         flush();
74
75         yuv_warning = new BC_Title(x, y, _("Warning: colormodel not YUV"),MEDIUMFONT,RED);
76         add_subwindow(yuv_warning);
77         EDL *edl = client->get_edl();
78         colormodel = edl->session->color_model;
79         switch( colormodel ) {
80         case BC_YUV888:
81         case BC_YUVA8888:
82                 yuv_warning->hide_window();
83                 break;
84         }
85 }
86
87 void yuv411Window::update()
88 {
89         avg_vertical->update(client->config.avg_vertical);
90         int_horizontal->update(client->config.int_horizontal);
91         inpainting->update(client->config.inpainting);
92         offset->update(client->config.offset);
93         thresh->update(client->config.thresh);
94         bias->update(client->config.bias);
95 }
96
97 int yuv411Window::close_event()
98 {
99         set_done(1);
100         return 1;
101 }
102
103 yuv411Toggle::yuv411Toggle(yuv411Main *client, int *output, char *string, int x, int y)
104  : BC_CheckBox(x, y, *output, string)
105 {
106         this->client = client;
107         this->output = output;
108 }
109 yuv411Toggle::~yuv411Toggle()
110 {
111 }
112 int yuv411Toggle::handle_event()
113 {
114         *output = get_value();
115         ((yuv411Window*)client->thread->window)->update_enables();
116         client->send_configure_change();
117         return 1;
118 }
119
120 yuv411Offset::yuv411Offset(yuv411Main *client, int x, int y)
121  :  BC_FSlider(x+xS(60), y, 0, xS(100), yS(100), (float)0, (float)2,
122             (float)client->config.offset)
123 {
124         this->client = client;
125         set_precision(1.0);
126 }
127 int yuv411Offset::handle_event()
128 {
129         client->config.offset = get_value();
130         client->send_configure_change();
131         return 1;
132 }
133
134 yuv411Thresh::yuv411Thresh(yuv411Main *client, int x, int y)
135  :  BC_FSlider(x+xS(60), y, 0, xS(100), yS(100), (float)1, (float)100,
136             (float)client->config.thresh)
137 {
138         this->client = client;
139         set_precision(1.0);
140 }
141 int yuv411Thresh::handle_event()
142 {
143         client->config.thresh = get_value();
144         client->send_configure_change();
145         return 1;
146 }
147
148 yuv411Bias::yuv411Bias(yuv411Main *client, int x, int y)
149  :  BC_FSlider(x+xS(60), y, 0, xS(100), yS(100), (float)0, (float)25,
150             (float)client->config.bias)
151 {
152         this->client = client;
153         set_precision(1.0);
154 }
155
156 int yuv411Bias::handle_event()
157 {
158         client->config.bias = get_value();
159         client->send_configure_change();
160         return 1;
161 }
162
163 yuv411Reset::yuv411Reset(yuv411Main *client, yuv411Window *window, int x, int y)
164  : BC_GenericButton(x, y, _("Reset"))
165 {
166         this->client = client;
167         this->window = window;
168 }
169 yuv411Reset::~yuv411Reset()
170 {
171 }
172 int yuv411Reset::handle_event()
173 {
174         client->config.reset();
175         window->update();
176         window->update_enables();
177         client->send_configure_change();
178         return 1;
179 }
180
181
182 void yuv411Window::update_enables()
183 {
184         yuv411Config &config = client->config;
185         if( !config.int_horizontal && config.inpainting ) {
186                 config.inpainting = 0;
187                 inpainting->set_value(0);
188         }
189         if( config.int_horizontal ) {
190                 inpainting->enable();
191                 offset->show_window();
192         }
193         else {
194                 inpainting->disable();
195                 offset->hide_window();
196         }
197         if( config.int_horizontal && config.inpainting ) {
198                 thresh->show_window();
199                 bias->show_window();
200         }
201         else {
202                 thresh->hide_window();
203                 bias->hide_window();
204         }
205 }
206
207 void yuv411Window::show_warning(int warn)
208 {
209         if( warn )
210                 yuv_warning->show_window();
211         else
212                 yuv_warning->hide_window();
213 }
214