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);
98 BluebananaEngine *engine;
102 friend class BluebananaEngine;
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;
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)];
124 float sat_histogram[HISTSIZE+(1<<HRGBSHIFT)];
125 float value_histogram[HISTSIZE+(1<<HRGBSHIFT)];
127 float hue_histogram_red[(HISTSIZE>>HRGBSHIFT)+1];
128 float hue_histogram_green[(HISTSIZE>>HRGBSHIFT)+1];
129 float hue_histogram_blue[(HISTSIZE>>HRGBSHIFT)+1];
131 float sat_histogram_red[(HISTSIZE>>HRGBSHIFT)+1];
132 float sat_histogram_green[(HISTSIZE>>HRGBSHIFT)+1];
133 float sat_histogram_blue[(HISTSIZE>>HRGBSHIFT)+1];
135 float value_histogram_red[(HISTSIZE>>HRGBSHIFT)+1];
136 float value_histogram_green[(HISTSIZE>>HRGBSHIFT)+1];
137 float value_histogram_blue[(HISTSIZE>>HRGBSHIFT)+1];
139 float *fill_selection(float *in, float *work,
140 int width, int height,
141 BluebananaEngine *e);
146 char select_one[FSrange*4];
147 char select_two[FSrange*4];
148 char select_three[FSrange*4];
150 BluebananaConfig lookup_cache;
151 BluebananaConfig update_cache;
153 void update_lookups(int serverside);
156 void output_nonauto(FileXML *output);
159 class BluebananaPackage : public LoadPackage
162 BluebananaPackage(BluebananaEngine *engine);
163 BluebananaEngine *engine;
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)];
172 float Hhr[HISTSIZE+1];
173 float Hhg[HISTSIZE+1];
174 float Hhb[HISTSIZE+1];
176 float Shr[HISTSIZE+1];
177 float Shg[HISTSIZE+1];
178 float Shb[HISTSIZE+1];
180 float Vhr[HISTSIZE+1];
181 float Vhg[HISTSIZE+1];
182 float Vhb[HISTSIZE+1];
185 class BluebananaUnit : public LoadClient
188 BluebananaUnit(BluebananaEngine *server, BluebananaMain *plugin);
190 void process_package(LoadPackage *package);
191 BluebananaEngine *server;
192 BluebananaMain *plugin;
195 class BluebananaEngine : public LoadServer
198 BluebananaEngine(BluebananaMain *plugin,
202 void process_packages(VFrame *data);
203 void init_packages();
204 LoadClient* new_client();
205 LoadPackage* new_package();
206 BluebananaMain *plugin;
210 void set_task(int n, const char *task);
214 friend class BluebananaUnit;
217 float *selection_workA;
218 float *selection_workB;
221 pthread_mutex_t copylock;
222 pthread_mutex_t histlock;
223 pthread_mutex_t tasklock;
224 pthread_cond_t taskcond;
226 int task_init_serial;
228 int task_finish_count;
232 extern float sel_lookup(float val, float *lookup);
233 extern float adj_lookup(float val, float *lookup, float toe_slope);