bg/clr color tweaks, clear borders rework, fc31 depends
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / bluebanana / bluebanana.h
1
2 /*
3  * Cinelerra :: Blue Banana - color modification plugin for Cinelerra-CV
4  * Copyright (C) 2012-2013 Monty <monty@xiph.org>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #ifndef BLUEBANANA_H
23 #define BLUEBANANA_H
24
25 class BluebananaEngine;
26 class BluebananaMain;
27 class BluebananaThread;
28
29 #include "bluebananaconfig.h"
30 #include "bluebananawindow.h"
31 #include "loadbalance.h"
32 #include "bccolors.h"
33 #include "pluginvclient.h"
34
35 #define SELECT_LOOKUP_SIZE 1024
36 #define ADJUST_LOOKUP_SIZE 4096
37 #define SELECT_LOOKUP_SCALE 1024.f
38 #define ADJUST_LOOKUP_SCALE 1024.f
39 // adjust lookups clamp lookup range / intermediate results above this value
40 #define MAX_ADJ_HEADROOM 4.
41
42 #define MIN_GAMMA .2f
43 #define MAX_GAMMA 5.f
44
45 #define MIN_HISTBRACKET -100
46 #define MAX_HISTBRACKET 200
47 #define HISTSIZE 1536
48 #define HISTSCALE 512
49 #define HUESCALE  256
50
51 // valid HRGBSHIFT is 0 through 3
52 #define HRGBSHIFT 1
53 #define HISTOFF 1.f
54 #define FRAC0   .2f
55 #define FRAC100 .8f
56
57 #define FSrange 15
58 #define FSovermax 50
59
60 #define SELECT_THRESH .00001f
61
62 #define HSpV_SATURATION_BIAS (32.f/255.f)
63 #define HSpV_SATURATION_SCALE (1.f+HSpV_SATURATION_BIAS)
64 #define HSpV_SATURATION_ISCALE (1.f/HSpV_SATURATION_SCALE)
65
66 #undef CLAMP
67 #define CLAMP(x, y, z) ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x)))
68
69 class BluebananaMain : public PluginVClient
70 {
71 public:
72         BluebananaMain(PluginServer *server);
73         ~BluebananaMain();
74
75         int process_buffer(VFrame *frame,
76                 int64_t start_position,
77                 double frame_rate);
78         int is_realtime();
79         void save_auto(KeyFrame *keyframe);
80         void save_data(KeyFrame *keyframe);
81         void read_data(KeyFrame *keyframe);
82         void load_nonauto();
83         void save_nonauto();
84         void push_nonauto();
85         void enter_config_change();
86         void commit_config_change();
87         void leave_config_change();
88         void update_gui();
89         void render_gui(void *data);
90
91         float hue_select_alpha(float hue);
92         float sat_select_alpha(float sat);
93         float val_select_alpha(float val);
94
95         PLUGIN_CLASS_MEMBERS(BluebananaConfig);
96
97         VFrame *frame;
98         BluebananaEngine *engine;
99         int ants_counter;
100         int colormodel;
101
102         friend class BluebananaEngine;
103
104         float hue_select_alpha_lookup[SELECT_LOOKUP_SIZE+2];
105         float sat_select_alpha_lookup[SELECT_LOOKUP_SIZE+2];
106         float val_select_alpha_lookup[SELECT_LOOKUP_SIZE+2];
107         float sat_adj_lookup[ADJUST_LOOKUP_SIZE+2];
108         float sat_adj_toe_slope;
109         float val_adj_lookup[ADJUST_LOOKUP_SIZE+2];
110         float val_adj_toe_slope;
111         float red_adj_lookup[ADJUST_LOOKUP_SIZE+2];
112         float red_adj_toe_slope;
113         float green_adj_lookup[ADJUST_LOOKUP_SIZE+2];
114         float green_adj_toe_slope;
115         float blue_adj_lookup[ADJUST_LOOKUP_SIZE+2];
116         float blue_adj_toe_slope;
117
118         float red_histogram[HISTSIZE+(1<<HRGBSHIFT)];
119         float green_histogram[HISTSIZE+(1<<HRGBSHIFT)];
120         float blue_histogram[HISTSIZE+(1<<HRGBSHIFT)];
121         float hue_histogram[HISTSIZE+(1<<HRGBSHIFT)];
122         float hue_total;
123         float hue_weight;
124         float sat_histogram[HISTSIZE+(1<<HRGBSHIFT)];
125         float value_histogram[HISTSIZE+(1<<HRGBSHIFT)];
126
127         float hue_histogram_red[(HISTSIZE>>HRGBSHIFT)+1];
128         float hue_histogram_green[(HISTSIZE>>HRGBSHIFT)+1];
129         float hue_histogram_blue[(HISTSIZE>>HRGBSHIFT)+1];
130
131         float sat_histogram_red[(HISTSIZE>>HRGBSHIFT)+1];
132         float sat_histogram_green[(HISTSIZE>>HRGBSHIFT)+1];
133         float sat_histogram_blue[(HISTSIZE>>HRGBSHIFT)+1];
134
135         float value_histogram_red[(HISTSIZE>>HRGBSHIFT)+1];
136         float value_histogram_green[(HISTSIZE>>HRGBSHIFT)+1];
137         float value_histogram_blue[(HISTSIZE>>HRGBSHIFT)+1];
138
139         float *fill_selection(float *in, float *work,
140                                  int width, int height,
141                                  BluebananaEngine *e);
142
143         int select_one_n;
144         int select_two_n;
145         int select_three_n;
146         char select_one[FSrange*4];
147         char select_two[FSrange*4];
148         char select_three[FSrange*4];
149
150         BluebananaConfig lookup_cache;
151         BluebananaConfig update_cache;
152
153         void update_lookups(int serverside);
154
155  private:
156         void output_nonauto(FileXML *output);
157 };
158
159 class BluebananaPackage : public LoadPackage
160 {
161  public:
162         BluebananaPackage(BluebananaEngine *engine);
163         BluebananaEngine *engine;
164
165         float Rhist[HISTSIZE+(1<<HRGBSHIFT)];
166         float Ghist[HISTSIZE+(1<<HRGBSHIFT)];
167         float Bhist[HISTSIZE+(1<<HRGBSHIFT)];
168         float Hhist[HISTSIZE+(1<<HRGBSHIFT)];
169         float Shist[HISTSIZE+(1<<HRGBSHIFT)];
170         float Vhist[HISTSIZE+(1<<HRGBSHIFT)];
171
172         float Hhr[HISTSIZE+1];
173         float Hhg[HISTSIZE+1];
174         float Hhb[HISTSIZE+1];
175
176         float Shr[HISTSIZE+1];
177         float Shg[HISTSIZE+1];
178         float Shb[HISTSIZE+1];
179
180         float Vhr[HISTSIZE+1];
181         float Vhg[HISTSIZE+1];
182         float Vhb[HISTSIZE+1];
183 };
184
185 class BluebananaUnit : public LoadClient
186 {
187 public:
188         BluebananaUnit(BluebananaEngine *server, BluebananaMain *plugin);
189         ~BluebananaUnit();
190         void process_package(LoadPackage *package);
191         BluebananaEngine *server;
192         BluebananaMain *plugin;
193 };
194
195 class BluebananaEngine : public LoadServer
196 {
197 public:
198         BluebananaEngine(BluebananaMain *plugin,
199                 int total_clients,
200                 int total_packages);
201         ~BluebananaEngine();
202         void process_packages(VFrame *data);
203         void init_packages();
204         LoadClient* new_client();
205         LoadPackage* new_package();
206         BluebananaMain *plugin;
207         int total_size;
208         VFrame *data;
209
210         void set_task(int n, const char *task);
211         int next_task();
212         void wait_task();
213
214         friend class BluebananaUnit;
215
216  protected:
217         float *selection_workA;
218         float *selection_workB;
219
220  private:
221         pthread_mutex_t copylock;
222         pthread_mutex_t histlock;
223         pthread_mutex_t tasklock;
224         pthread_cond_t taskcond;
225         int task_init_state;
226         int task_init_serial;
227         int task_n;
228         int task_finish_count;
229
230 };
231
232 extern float sel_lookup(float val, float *lookup);
233 extern float adj_lookup(float val, float *lookup, float toe_slope);
234
235 #endif