Merge branch 'ct' of git.pipapo.org:cinelerra-ct into ct
[cinelerra_cv/ct.git] / cinelerra / playback3d.h
blobb92af2b873ed7b67e0c3805602b48b3af0a29137
1 #ifndef PLAYBACK3D_H
2 #define PLAYBACK3D_H
4 #include "arraylist.h"
5 #include "bcpixmap.inc"
6 #include "bcsynchronous.h"
7 #include "bcwindowbase.inc"
8 #include "canvas.inc"
9 #include "condition.inc"
10 #include "maskauto.inc"
11 #include "maskautos.inc"
12 #include "mutex.inc"
13 #include "mwindow.inc"
14 #include "pluginclient.inc"
15 #include "thread.h"
16 #include "vframe.inc"
22 // Macros for useful fragment shaders
23 #define YUV_TO_RGB_FRAG(PIXEL) \
24 PIXEL ".gb -= vec2(0.5, 0.5);\n" \
25 PIXEL ".rgb = mat3(\n" \
26 " 1, 1, 1, \n" \
27 " 0, -0.34414, 1.77200, \n" \
28 " 1.40200, -0.71414, 0) * " PIXEL ".rgb;\n"
30 #define RGB_TO_YUV_FRAG(PIXEL) \
31 PIXEL ".rgb = mat3(\n" \
32 " 0.29900, -0.16874, 0.50000, \n" \
33 " 0.58700, -0.33126, -0.41869, \n" \
34 " 0.11400, 0.50000, -0.08131) * " PIXEL ".rgb;\n" \
35 PIXEL ".gb += vec2(0.5, 0.5);\n"
37 #define RGB_TO_HSV_FRAG(PIXEL) \
38 "{\n" \
39 "float r, g, b;\n" \
40 "float h, s, v;\n" \
41 "float min, max, delta;\n" \
42 "float f, p, q, t;\n" \
43 "r = " PIXEL ".r;\n" \
44 "g = " PIXEL ".g;\n" \
45 "b = " PIXEL ".b;\n" \
46 "min = ((r < g) ? r : g) < b ? ((r < g) ? r : g) : b;\n" \
47 "max = ((r > g) ? r : g) > b ? ((r > g) ? r : g) : b;\n" \
48 "v = max;\n" \
49 "delta = max - min;\n" \
50 "if(max != 0.0 && delta != 0.0)\n" \
51 "{\n" \
52 " s = delta / max;\n" \
53 " if(r == max)\n" \
54 " h = (g - b) / delta;\n" \
55 " else \n" \
56 " if(g == max)\n" \
57 " h = 2.0 + (b - r) / delta;\n" \
58 " else\n" \
59 " h = 4.0 + (r - g) / delta;\n" \
60 "\n" \
61 " h *= 60.0;\n" \
62 " if(h < 0.0)\n" \
63 " h += 360.0;\n" \
64 "}\n" \
65 "else\n" \
66 "{\n" \
67 " s = 0.0;\n" \
68 " h = -1.0;\n" \
69 "}\n" \
70 "" PIXEL ".r = h;\n" \
71 "" PIXEL ".g = s;\n" \
72 "" PIXEL ".b = v;\n" \
73 "}\n"
75 #define HSV_TO_RGB_FRAG(PIXEL) \
76 "{\n" \
77 "int i;\n" \
78 "float r, g, b;\n" \
79 "float h, s, v;\n" \
80 "float min, max, delta;\n" \
81 "float f, p, q, t;\n" \
82 "h = " PIXEL ".r;\n" \
83 "s = " PIXEL ".g;\n" \
84 "v = " PIXEL ".b;\n" \
85 "if(s == 0.0) \n" \
86 "{\n" \
87 " r = g = b = v;\n" \
88 "}\n" \
89 "else\n" \
90 "{\n" \
91 " h /= 60.0;\n" \
92 " i = int(h);\n" \
93 " f = h - float(i);\n" \
94 " p = v * (1.0 - s);\n" \
95 " q = v * (1.0 - s * f);\n" \
96 " t = v * (1.0 - s * (1.0 - f));\n" \
97 "\n" \
98 " if(i == 0)\n" \
99 " {\n" \
100 " r = v;\n" \
101 " g = t;\n" \
102 " b = p;\n" \
103 " }\n" \
104 " else\n" \
105 " if(i == 1)\n" \
106 " {\n" \
107 " r = q;\n" \
108 " g = v;\n" \
109 " b = p;\n" \
110 " }\n" \
111 " else\n" \
112 " if(i == 2)\n" \
113 " {\n" \
114 " r = p;\n" \
115 " g = v;\n" \
116 " b = t;\n" \
117 " }\n" \
118 " else\n" \
119 " if(i == 3)\n" \
120 " {\n" \
121 " r = p;\n" \
122 " g = q;\n" \
123 " b = v;\n" \
124 " }\n" \
125 " else\n" \
126 " if(i == 4)\n" \
127 " {\n" \
128 " r = t;\n" \
129 " g = p;\n" \
130 " b = v;\n" \
131 " }\n" \
132 " else\n" \
133 " if(i == 5)\n" \
134 " {\n" \
135 " r = v;\n" \
136 " g = p;\n" \
137 " b = q;\n" \
138 " }\n" \
139 "}\n" \
140 "" PIXEL ".r = r;\n" \
141 "" PIXEL ".g = g;\n" \
142 "" PIXEL ".b = b;\n" \
143 "}\n"
147 class Playback3DCommand : public BC_SynchronousCommand
149 public:
150 Playback3DCommand();
151 void copy_from(BC_SynchronousCommand *command);
153 // Extra commands
154 enum
156 // 5
157 WRITE_BUFFER = LAST_COMMAND,
158 CLEAR_OUTPUT,
159 OVERLAY,
160 DO_FADE,
161 DO_MASK,
162 PLUGIN,
163 CLEAR_INPUT,
164 DO_CAMERA,
165 COPY_FROM
168 Canvas *canvas;
169 int is_cleared;
171 // Parameters for overlay command
172 float in_x1;
173 float in_y1;
174 float in_x2;
175 float in_y2;
176 float out_x1;
177 float out_y1;
178 float out_x2;
179 float out_y2;
180 // 0 - 1
181 float alpha;
182 int mode;
183 int interpolation_type;
184 VFrame *input;
185 int want_texture;
187 int64_t start_position_project;
188 MaskAutos *keyframe_set;
189 MaskAuto *keyframe;
190 MaskAuto *default_auto;
191 PluginClient *plugin_client;
195 class Playback3D : public BC_Synchronous
197 public:
198 Playback3D(MWindow *mwindow);
199 ~Playback3D();
201 BC_SynchronousCommand* new_command();
202 void handle_command(BC_SynchronousCommand *command);
204 // Called by VDeviceX11::write_buffer during video playback
205 void write_buffer(Canvas *canvas,
206 VFrame *frame,
207 float in_x1,
208 float in_y1,
209 float in_x2,
210 float in_y2,
211 float out_x1,
212 float out_y1,
213 float out_x2,
214 float out_y2,
215 int is_cleared);
217 // Reads from pbuffer to either RAM or texture and updates the dst state
218 // want_texture - causes read into texture if 1
219 void copy_from(Canvas *canvas,
220 VFrame *dst,
221 VFrame *src,
222 int want_texture = 0);
224 // Clear framebuffer before composing virtual console
225 // output - passed when rendering refresh frame. If 0, the canvas is cleared.
226 void clear_output(Canvas *canvas, VFrame *output);
228 void do_fade(Canvas *canvas, VFrame *fade, float fade);
230 void do_mask(Canvas *canvas,
231 VFrame *output,
232 int64_t start_position_project,
233 MaskAutos *keyframe_set,
234 MaskAuto *keyframe,
235 MaskAuto *default_auto);
238 // Overlay a virtual node on the framebuffer
239 void overlay(Canvas *canvas,
240 VFrame *input,
241 float in_x1,
242 float in_y1,
243 float in_x2,
244 float in_y2,
245 float out_x1,
246 float out_y1,
247 float out_x2,
248 float out_y2,
249 float alpha, // 0 - 1
250 int mode,
251 int interpolation_type,
252 // supplied if rendering single frame to PBuffer.
253 VFrame *output = 0);
256 int run_plugin(Canvas *canvas, PluginClient *client);
258 void clear_input(Canvas *canvas, VFrame *frame);
259 void do_camera(Canvas *canvas,
260 VFrame *output,
261 VFrame *input,
262 float in_x1,
263 float in_y1,
264 float in_x2,
265 float in_y2,
266 float out_x1,
267 float out_y1,
268 float out_x2,
269 float out_y2);
271 private:
272 // Called by write_buffer and clear_frame to initialize OpenGL flags
273 void init_frame(Playback3DCommand *command);
274 void write_buffer_sync(Playback3DCommand *command);
275 void draw_output(Playback3DCommand *command);
276 void clear_output_sync(Playback3DCommand *command);
277 void clear_input_sync(Playback3DCommand *command);
278 void overlay_sync(Playback3DCommand *command);
279 // Read frame buffer back into texture for overlay operation
280 void enable_overlay_texture(Playback3DCommand *command);
281 void do_fade_sync(Playback3DCommand *command);
282 void do_mask_sync(Playback3DCommand *command);
283 void run_plugin_sync(Playback3DCommand *command);
284 void do_camera_sync(Playback3DCommand *command);
285 // void draw_refresh_sync(Playback3DCommand *command);
286 void copy_from_sync(Playback3DCommand *command);
288 // Print errors from shader compilation
289 void print_error(unsigned int object, int is_program);
291 // This quits the program when it's 1.
292 MWindow *mwindow;
293 // Temporaries for render to texture
294 BC_Texture *temp_texture;
295 // This is set by clear_output and used in compositing directly
296 // to the output framebuffer.
297 int canvas_w;
298 int canvas_h;
304 #endif
306 // Local Variables:
307 // mode: C++
308 // c-file-style: "linux"
309 // End: