no longer need ffmpeg patch0 which was for Termux
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / C41 / c41.h
1 /*
2  * C41 plugin for Cinelerra
3  * Copyright (C) 2011 Florent Delannoy <florent at plui dot es>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * 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,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18  *
19  */
20 #ifndef __C41_H__
21 #define __C41_H__
22
23 #include "guicast.h"
24 #include "pluginvclient.h"
25 #include "vframe.inc"
26
27 // C41_FAST_POW increases processing speed more than 10 times
28 // Depending on gcc version, used optimizations and cpu C41_FAST_POW may not work
29 // With gcc versiion >= 4.4 it seems safe to enable C41_FAST_POW
30 // Test some samples after you have enabled it
31 #define C41_FAST_POW
32
33 #ifdef C41_FAST_POW
34 #define POWF myPow
35 #else
36 #define POWF powf
37 #endif
38
39 // Shave the image in order to avoid black borders
40 // The min max pixel value difference must be at least 0.05
41 #define C41_SHAVE_TOLERANCE 0.05
42 #define C41_SHAVE_MARGIN 0.1
43
44 #include <stdint.h>
45 #include <string.h>
46
47 class C41Effect;
48 class C41Window;
49 class C41Config;
50 class C41Enable;
51 class C41TextBox;
52 class C41Button;
53 class C41BoxButton;
54 class C41Slider;
55
56 struct magic
57 {
58         float min_r, max_r;
59         float min_g, max_g;
60         float min_b, max_b;
61         float light;
62         float gamma_g, gamma_b;
63         float coef1, coef2;
64         int shave_min_row, shave_max_row;
65         int shave_min_col, shave_max_col;
66 };
67
68 class C41Config
69 {
70 public:
71         C41Config();
72
73         void copy_from(C41Config &src);
74         int equivalent(C41Config &src);
75         void interpolate(C41Config &prev, C41Config &next,
76                 long prev_frame, long next_frame, long current_frame);
77
78         int active, compute_magic;
79         int postproc, show_box;
80         float fix_min_r, fix_min_g, fix_min_b;
81         float fix_light, fix_gamma_g, fix_gamma_b;
82         float fix_coef1, fix_coef2;
83         int min_col, max_col, min_row, max_row;
84         int window_w, window_h;
85 };
86
87 class C41Enable : public BC_CheckBox
88 {
89 public:
90         C41Enable(C41Effect *plugin, int *output, int x, int y, const char *text);
91         int handle_event();
92
93         C41Effect *plugin;
94         int *output;
95 };
96
97 class C41TextBox : public BC_TextBox
98 {
99 public:
100         C41TextBox(C41Effect *plugin, float *value, int x, int y);
101         int handle_event();
102
103         C41Effect *plugin;
104         float *boxValue;
105 };
106
107 class C41Button : public BC_GenericButton
108 {
109 public:
110         C41Button(C41Effect *plugin, C41Window *window, int x, int y);
111         int handle_event();
112
113         C41Effect *plugin;
114         C41Window *window;
115 };
116
117 class C41BoxButton : public BC_GenericButton
118 {
119 public:
120         C41BoxButton(C41Effect *plugin, C41Window *window, int x, int y);
121         int handle_event();
122
123         C41Effect *plugin;
124         C41Window *window;
125 };
126
127 class C41Slider : public BC_ISlider
128 {
129 public:
130         C41Slider(C41Effect *plugin, int *output, int x, int y, int is_row);
131
132         int handle_event();
133         int update(int v);
134
135         C41Effect *plugin;
136         int is_row, max;
137         int *output;
138 };
139
140 class C41Window : public PluginClientWindow
141 {
142 public:
143         C41Window(C41Effect *client);
144         void create_objects();
145
146         void update();
147         void update_magic();
148
149         C41Enable *active;
150         C41Enable *compute_magic;
151         C41Enable *postproc;
152         C41Enable *show_box;
153         BC_Title *min_r;
154         BC_Title *min_g;
155         BC_Title *min_b;
156         BC_Title *light;
157         BC_Title *gamma_g;
158         BC_Title *gamma_b;
159         BC_Title *coef1;
160         BC_Title *coef2;
161         BC_Title *box_col_min;
162         BC_Title *box_col_max;
163         BC_Title *box_row_min;
164         BC_Title *box_row_max;
165         C41TextBox *fix_min_r;
166         C41TextBox *fix_min_g;
167         C41TextBox *fix_min_b;
168         C41TextBox *fix_light;
169         C41TextBox *fix_gamma_g;
170         C41TextBox *fix_gamma_b;
171         C41TextBox *fix_coef1;
172         C41TextBox *fix_coef2;
173         C41Button *lock;
174         C41BoxButton *boxlock;
175         C41Slider *min_row;
176         C41Slider *max_row;
177         C41Slider *min_col;
178         C41Slider *max_col;
179
180         int slider_max_col;
181         int slider_max_row;
182 };
183
184 class C41Effect : public PluginVClient
185 {
186 public:
187         C41Effect(PluginServer *server);
188         ~C41Effect();
189
190         PLUGIN_CLASS_MEMBERS(C41Config);
191         int is_realtime();
192         int is_synthesis();
193
194         int process_realtime(VFrame *input_ptr, VFrame *output_ptr);
195         void save_data(KeyFrame *keyframe);
196         void read_data(KeyFrame *keyframe);
197         void render_gui(void* data);
198 #if defined(C41_FAST_POW)
199         float myLog2(float i) __attribute__ ((optimize(0)));
200         float myPow2(float i) __attribute__ ((optimize(0)));
201         float myPow(float a, float b);
202 #endif
203         void pix_fix(float &pix, float min, float gamma);
204         VFrame *frame, *tmp_frame, *blurry_frame;
205         struct magic values;
206
207         int shave_min_row, shave_max_row, shave_min_col, shave_max_col;
208         int min_col, max_col, min_row, max_row;
209         float pix_max;
210         int pix_len;
211 };
212
213
214 #endif