3 * Cinelerra :: Blue Banana - color modification plugin for Cinelerra-CV
4 * Copyright (C) 2012-2013 Monty <monty@xiph.org>
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.
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.
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
25 class BluebananaEngine;
27 class BluebananaThread;
29 #include "bluebananaconfig.h"
30 #include "bluebananawindow.h"
31 #include "loadbalance.h"
33 #include "pluginvclient.h"
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.
45 #define MIN_HISTBRACKET -100
46 #define MAX_HISTBRACKET 200
51 // valid HRGBSHIFT is 0 through 3
60 #define SELECT_THRESH .00001f
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)
67 #define CLAMP(x, y, z) ((x) < (y) ? (y) : ((x) > (z) ? (z) : (x)))
69 class BluebananaMain : public PluginVClient
72 BluebananaMain(PluginServer *server);
75 int process_buffer(VFrame *frame,
76 int64_t start_position,
79 void save_auto(KeyFrame *keyframe);
80 void save_data(KeyFrame *keyframe);
81 void read_data(KeyFrame *keyframe);
85 void enter_config_change();
86 void commit_config_change();
87 void leave_config_change();
89 void render_gui(void *data);
91 float hue_select_alpha(float hue);
92 float sat_select_alpha(float sat);
93 float val_select_alpha(float val);
95 PLUGIN_CLASS_MEMBERS(BluebananaConfig);
99 BluebananaEngine *engine;
103 friend class BluebananaEngine;
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;
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)];
125 float sat_histogram[HISTSIZE+(1<<HRGBSHIFT)];
126 float value_histogram[HISTSIZE+(1<<HRGBSHIFT)];
128 float hue_histogram_red[(HISTSIZE>>HRGBSHIFT)+1];
129 float hue_histogram_green[(HISTSIZE>>HRGBSHIFT)+1];
130 float hue_histogram_blue[(HISTSIZE>>HRGBSHIFT)+1];
132 float sat_histogram_red[(HISTSIZE>>HRGBSHIFT)+1];
133 float sat_histogram_green[(HISTSIZE>>HRGBSHIFT)+1];
134 float sat_histogram_blue[(HISTSIZE>>HRGBSHIFT)+1];
136 float value_histogram_red[(HISTSIZE>>HRGBSHIFT)+1];
137 float value_histogram_green[(HISTSIZE>>HRGBSHIFT)+1];
138 float value_histogram_blue[(HISTSIZE>>HRGBSHIFT)+1];
140 float *fill_selection(float *in, float *work,
141 int width, int height,
142 BluebananaEngine *e);
147 char select_one[FSrange*4];
148 char select_two[FSrange*4];
149 char select_three[FSrange*4];
151 BluebananaConfig lookup_cache;
152 BluebananaConfig update_cache;
154 void update_lookups(int serverside);
157 void output_nonauto(FileXML *output);
160 class BluebananaPackage : public LoadPackage
163 BluebananaPackage(BluebananaEngine *engine);
164 BluebananaEngine *engine;
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)];
173 float Hhr[HISTSIZE+1];
174 float Hhg[HISTSIZE+1];
175 float Hhb[HISTSIZE+1];
177 float Shr[HISTSIZE+1];
178 float Shg[HISTSIZE+1];
179 float Shb[HISTSIZE+1];
181 float Vhr[HISTSIZE+1];
182 float Vhg[HISTSIZE+1];
183 float Vhb[HISTSIZE+1];
186 class BluebananaUnit : public LoadClient
189 BluebananaUnit(BluebananaEngine *server, BluebananaMain *plugin);
191 void process_package(LoadPackage *package);
192 BluebananaEngine *server;
193 BluebananaMain *plugin;
196 class BluebananaEngine : public LoadServer
199 BluebananaEngine(BluebananaMain *plugin,
203 void process_packages(VFrame *data);
204 void init_packages();
205 LoadClient* new_client();
206 LoadPackage* new_package();
207 BluebananaMain *plugin;
211 void set_task(int n, const char *task);
215 friend class BluebananaUnit;
218 float *selection_workA;
219 float *selection_workB;
222 pthread_mutex_t copylock;
223 pthread_mutex_t histlock;
224 pthread_mutex_t tasklock;
225 pthread_cond_t taskcond;
227 int task_init_serial;
229 int task_finish_count;
233 extern float sel_lookup(float val, float *lookup);
234 extern float adj_lookup(float val, float *lookup, float toe_slope);