merged hv7 mod
[goodguy/history.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         YUV yuv;
98         VFrame *frame;
99         BluebananaEngine *engine;
100         int ants_counter;
101         int colormodel;
102
103         friend class BluebananaEngine;
104
105         float hue_select_alpha_lookup[SELECT_LOOKUP_SIZE+2];
106         float sat_select_alpha_lookup[SELECT_LOOKUP_SIZE+2];
107         float val_select_alpha_lookup[SELECT_LOOKUP_SIZE+2];
108         float sat_adj_lookup[ADJUST_LOOKUP_SIZE+2];
109         float sat_adj_toe_slope;
110         float val_adj_lookup[ADJUST_LOOKUP_SIZE+2];
111         float val_adj_toe_slope;
112         float red_adj_lookup[ADJUST_LOOKUP_SIZE+2];
113         float red_adj_toe_slope;
114         float green_adj_lookup[ADJUST_LOOKUP_SIZE+2];
115         float green_adj_toe_slope;
116         float blue_adj_lookup[ADJUST_LOOKUP_SIZE+2];
117         float blue_adj_toe_slope;
118
119         float red_histogram[HISTSIZE+(1<<HRGBSHIFT)];
120         float green_histogram[HISTSIZE+(1<<HRGBSHIFT)];
121         float blue_histogram[HISTSIZE+(1<<HRGBSHIFT)];
122         float hue_histogram[HISTSIZE+(1<<HRGBSHIFT)];
123         float hue_total;
124         float hue_weight;
125         float sat_histogram[HISTSIZE+(1<<HRGBSHIFT)];
126         float value_histogram[HISTSIZE+(1<<HRGBSHIFT)];
127
128         float hue_histogram_red[(HISTSIZE>>HRGBSHIFT)+1];
129         float hue_histogram_green[(HISTSIZE>>HRGBSHIFT)+1];
130         float hue_histogram_blue[(HISTSIZE>>HRGBSHIFT)+1];
131
132         float sat_histogram_red[(HISTSIZE>>HRGBSHIFT)+1];
133         float sat_histogram_green[(HISTSIZE>>HRGBSHIFT)+1];
134         float sat_histogram_blue[(HISTSIZE>>HRGBSHIFT)+1];
135
136         float value_histogram_red[(HISTSIZE>>HRGBSHIFT)+1];
137         float value_histogram_green[(HISTSIZE>>HRGBSHIFT)+1];
138         float value_histogram_blue[(HISTSIZE>>HRGBSHIFT)+1];
139
140         float *fill_selection(float *in, float *work,
141                                  int width, int height,
142                                  BluebananaEngine *e);
143
144         int select_one_n;
145         int select_two_n;
146         int select_three_n;
147         char select_one[FSrange*4];
148         char select_two[FSrange*4];
149         char select_three[FSrange*4];
150
151         BluebananaConfig lookup_cache;
152         BluebananaConfig update_cache;
153
154         void update_lookups(int serverside);
155
156  private:
157         void output_nonauto(FileXML *output);
158 };
159
160 class BluebananaPackage : public LoadPackage
161 {
162  public:
163         BluebananaPackage(BluebananaEngine *engine);
164         BluebananaEngine *engine;
165
166         float Rhist[HISTSIZE+(1<<HRGBSHIFT)];
167         float Ghist[HISTSIZE+(1<<HRGBSHIFT)];
168         float Bhist[HISTSIZE+(1<<HRGBSHIFT)];
169         float Hhist[HISTSIZE+(1<<HRGBSHIFT)];
170         float Shist[HISTSIZE+(1<<HRGBSHIFT)];
171         float Vhist[HISTSIZE+(1<<HRGBSHIFT)];
172
173         float Hhr[HISTSIZE+1];
174         float Hhg[HISTSIZE+1];
175         float Hhb[HISTSIZE+1];
176
177         float Shr[HISTSIZE+1];
178         float Shg[HISTSIZE+1];
179         float Shb[HISTSIZE+1];
180
181         float Vhr[HISTSIZE+1];
182         float Vhg[HISTSIZE+1];
183         float Vhb[HISTSIZE+1];
184 };
185
186 class BluebananaUnit : public LoadClient
187 {
188 public:
189         BluebananaUnit(BluebananaEngine *server, BluebananaMain *plugin);
190         ~BluebananaUnit();
191         void process_package(LoadPackage *package);
192         BluebananaEngine *server;
193         BluebananaMain *plugin;
194 };
195
196 class BluebananaEngine : public LoadServer
197 {
198 public:
199         BluebananaEngine(BluebananaMain *plugin,
200                 int total_clients,
201                 int total_packages);
202         ~BluebananaEngine();
203         void process_packages(VFrame *data);
204         void init_packages();
205         LoadClient* new_client();
206         LoadPackage* new_package();
207         BluebananaMain *plugin;
208         int total_size;
209         VFrame *data;
210
211         void set_task(int n, const char *task);
212         int next_task();
213         void wait_task();
214
215         friend class BluebananaUnit;
216
217  protected:
218         float *selection_workA;
219         float *selection_workB;
220
221  private:
222         pthread_mutex_t copylock;
223         pthread_mutex_t histlock;
224         pthread_mutex_t tasklock;
225         pthread_cond_t taskcond;
226         int task_init_state;
227         int task_init_serial;
228         int task_n;
229         int task_finish_count;
230
231 };
232
233 extern float sel_lookup(float val, float *lookup);
234 extern float adj_lookup(float val, float *lookup, float toe_slope);
235
236 #endif