62b5be0c5f2c1eadab95fb69b8a0a14945dd6292
[goodguy/history.git] / cinelerra-5.1 / plugins / titler / title.h.stroker
1 #ifndef TITLE_H
2 #define TITLE_H
3
4
5
6
7 // Theory:
8
9 // Stage 1:
10 // Only performed when text mask changes.
11 // Update glyph cache with every glyph used in the title.
12 // A parallel text renderer draws one character per CPU.
13 // The titler direct copies all the text currently visible onto the text mask.
14 // in integer coordinates.
15 // The text mask is in the same color space as the output but always has
16 // an alpha channel.
17
18 // Stage 2:
19 // Performed every frame.
20 // The text mask is overlayed with fractional translation and fading on the output.
21
22
23
24
25
26
27 class TitleMain;
28 class TitleEngine;
29 class GlyphEngine;
30 class TitleTranslate;
31
32 #include "defaults.h"
33 #include "loadbalance.h"
34 #include "mutex.h"
35 #include "overlayframe.h"
36 #include "pluginvclient.h"
37 #include "titlewindow.h"
38
39 #include <ft2build.h>
40 #include FT_FREETYPE_H
41 #include <sys/types.h>
42
43 // Style bitwise ORed
44 #define FONT_ITALIC    0x1
45 #define FONT_BOLD      0x2
46 #define FONT_OUTLINE   0x4
47
48 // Motion strategy
49 #define TOTAL_PATHS 5
50 #define NO_MOTION     0x0
51 #define BOTTOM_TO_TOP 0x1
52 #define TOP_TO_BOTTOM 0x2
53 #define RIGHT_TO_LEFT 0x3
54 #define LEFT_TO_RIGHT 0x4
55
56 // Horizontal justification
57 #define JUSTIFY_LEFT   0x0
58 #define JUSTIFY_CENTER 0x1
59 #define JUSTIFY_RIGHT  0x2
60
61 // Vertical justification
62 #define JUSTIFY_TOP     0x0
63 #define JUSTIFY_MID     0x1
64 #define JUSTIFY_BOTTOM  0x2
65
66
67 class TitleConfig
68 {
69 public:
70         TitleConfig();
71
72 // Only used to clear glyphs
73         int equivalent(TitleConfig &that);
74         void copy_from(TitleConfig &that);
75         void interpolate(TitleConfig &prev,
76                 TitleConfig &next,
77                 int64_t prev_frame,
78                 int64_t next_frame,
79                 int64_t current_frame);
80
81
82 // Font information
83         char font[BCTEXTLEN];
84         int64_t style;
85         int size;
86         int color;
87         int color_stroke;
88 // Motion of title across frame
89         int motion_strategy;
90 // Loop motion path
91         int loop;
92 // Speed of motion
93         float pixels_per_second;
94         int hjustification;
95         int vjustification;
96 // Number of seconds the fade in and fade out of the title take
97         double fade_in, fade_out;
98 // Position in frame relative to top left
99         float x, y;
100 // Pixels down and right of dropshadow
101         int dropshadow;
102 // Calculated during every frame for motion strategy
103         int64_t prev_keyframe_position;
104         int64_t next_keyframe_position;
105 // Stamp timecode
106         int timecode;
107
108 // Text to display
109         char text[BCTEXTLEN];
110 // Encoding to convert from
111         char encoding[BCTEXTLEN];
112 // Width of the stroke
113         double stroke_width;
114 };
115
116 class FontEntry
117 {
118 public:
119         FontEntry();
120         ~FontEntry();
121
122         void dump();
123
124         char *path;
125         char *foundary;
126         char *family;
127         char *weight;
128         char *slant;
129         char *swidth;
130         char *adstyle;
131         int pixelsize;
132         int pointsize;
133         int xres;
134         int yres;
135         char *spacing;
136         int avg_width;
137         char *registry;
138         char *encoding;
139         char *fixed_title;
140         int fixed_style;
141 };
142
143 class TitleGlyph
144 {
145 public:
146         TitleGlyph();
147         ~TitleGlyph();
148         // character in 8 bit charset
149         int c;
150         // character in UCS-4
151         FT_ULong char_code;
152         int width, height, pitch, advance_w, left, top, freetype_index;
153         VFrame *data;
154         VFrame *data_stroke;
155 };
156
157
158
159
160
161
162
163 // Draw a single character into the glyph cache
164 //
165 class GlyphPackage : public LoadPackage
166 {
167 public:
168         GlyphPackage();
169         TitleGlyph *glyph;
170 };
171
172
173 class GlyphUnit : public LoadClient
174 {
175 public:
176         GlyphUnit(TitleMain *plugin, GlyphEngine *server);
177         ~GlyphUnit();
178         void process_package(LoadPackage *package);
179
180         TitleMain *plugin;
181         FontEntry *current_font;       // Current font configured by freetype
182         FT_Library freetype_library;            // Freetype library
183         FT_Face freetype_face;
184 };
185
186 class GlyphEngine : public LoadServer
187 {
188 public:
189         GlyphEngine(TitleMain *plugin, int cpus);
190         void init_packages();
191         LoadClient* new_client();
192         LoadPackage* new_package();
193         TitleMain *plugin;
194 };
195
196
197
198
199
200
201
202 // Copy a single character to the text mask
203 class TitlePackage : public LoadPackage
204 {
205 public:
206         TitlePackage();
207         int x, y, c;
208 };
209
210
211 class TitleUnit : public LoadClient
212 {
213 public:
214         TitleUnit(TitleMain *plugin, TitleEngine *server);
215         void process_package(LoadPackage *package);
216         void draw_glyph(VFrame *output, TitleGlyph *glyph, int x, int y);
217         TitleMain *plugin;
218 };
219
220 class TitleEngine : public LoadServer
221 {
222 public:
223         TitleEngine(TitleMain *plugin, int cpus);
224         void init_packages();
225         LoadClient* new_client();
226         LoadPackage* new_package();
227         TitleMain *plugin;
228 };
229
230
231
232
233
234
235
236
237
238
239 // Overlay text mask with fractional translation
240 // We don't use OverlayFrame to enable alpha blending on non alpha
241 // output.
242 class TitleTranslatePackage : public LoadPackage
243 {
244 public:
245         TitleTranslatePackage();
246         int y1, y2;
247 };
248
249
250 class TitleTranslateUnit : public LoadClient
251 {
252 public:
253         TitleTranslateUnit(TitleMain *plugin, TitleTranslate *server);
254         void process_package(LoadPackage *package);
255         TitleMain *plugin;
256 };
257
258 class TitleTranslate : public LoadServer
259 {
260 public:
261         TitleTranslate(TitleMain *plugin, int cpus);
262         ~TitleTranslate();
263         void init_packages();
264         LoadClient* new_client();
265         LoadPackage* new_package();
266         TitleMain *plugin;
267         transfer_table_f *y_table;
268         transfer_table_f *x_table;
269         int output_w;
270         int output_h;
271 // Result of translation_array_f
272         int out_x1_int;
273         int out_x2_int;
274         int out_y1_int;
275         int out_y2_int;
276 // Values to process
277         int out_x1;
278         int out_x2;
279         int out_y1;
280         int out_y2;
281 };
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296 // Position of each character relative to total text extents
297 typedef struct
298 {
299         int x, y, w;
300 } title_char_position_t;
301
302
303
304 class TitleMain : public PluginVClient
305 {
306 public:
307         TitleMain(PluginServer *server);
308         ~TitleMain();
309
310 // required for all realtime plugins
311         int process_realtime(VFrame *input_ptr, VFrame *output_ptr);
312         int is_realtime();
313         int is_synthesis();
314         char* plugin_title();
315         int show_gui();
316         void raise_window();
317         void update_gui();
318         int set_string();
319         int load_configuration();
320         void save_data(KeyFrame *keyframe);
321         void read_data(KeyFrame *keyframe);
322         int load_defaults();
323         int save_defaults();
324
325
326
327         void build_fonts();
328         void draw_glyphs();
329         int draw_mask();
330         void overlay_mask();
331         FontEntry* get_font_entry(char *title,
332                 int style,
333                 int size);
334         FontEntry* get_font();
335         int get_char_advance(int current, int next);
336         int get_char_height();
337         void get_total_extents();
338         void clear_glyphs();
339         int load_freetype_face(FT_Library &freetype_library,
340                 FT_Face &freetype_face,
341                 char *path);
342
343
344
345
346
347         static char* motion_to_text(int motion);
348         static int text_to_motion(char *text);
349 // a thread for the GUI
350         TitleThread *thread;
351 // Current configuration
352         TitleConfig config;
353 // Size of window
354         int window_w, window_h;
355
356         static ArrayList<FontEntry*> *fonts;
357
358         Defaults *defaults;
359         ArrayList<TitleGlyph*> glyphs;
360         Mutex glyph_lock;
361
362 // Stage 1 parameters must be compared to redraw the text mask
363         VFrame *text_mask;
364         VFrame *text_mask_stroke;
365         GlyphEngine *glyph_engine;
366         TitleEngine *title_engine;
367         TitleTranslate *translate;
368
369 // Necessary to get character width
370         FT_Library freetype_library;            // Freetype library
371         FT_Face freetype_face;
372
373 // Visible area of all text present in the mask.
374 // Horizontal characters aren't clipped because column positions are
375 // proportional.
376         int visible_row1;
377         int visible_row2;
378         int visible_char1;
379         int visible_char2;
380 // relative position of all text to output
381         float text_y1;
382         float text_y2;
383         float text_x1;
384         float text_x2;
385 // relative position of visible part of text to output
386         float mask_y1;
387         float mask_y2;
388
389 // Fade value
390         int alpha;
391
392 // Must be calculated from rendering characters
393         int ascent;
394 // Relative position of mask to output is text_x1, mask_y1
395 // We can either round it to nearest ints to speed up replication while the text
396 // itself is offset fractionally
397 // or replicate with fractional offsetting.  Since fraction offsetting usually
398 // happens during motion and motion would require floating point offsetting
399 // for every frame we replicate with fractional offsetting.
400
401
402
403 // Text is always row aligned to mask boundaries.
404         int text_len;
405         int text_rows;
406         int text_w;
407         int text_h;
408 // Position of each character relative to total text extents
409         title_char_position_t *char_positions;
410 // Positions of the bottom pixels of the rows
411         int *rows_bottom;
412         VFrame *input, *output;
413
414         int need_reconfigure;
415 };
416
417
418 #endif