2 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
3 * Copyright (C) 2009 Grigori Goronzy <greg@geekmind.org>
5 * This file is part of libass.
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #ifndef LIBASS_RENDER_H
21 #define LIBASS_RENDER_H
25 #include FT_FREETYPE_H
27 #include FT_SYNTHESIS_H
28 #ifdef CONFIG_HARFBUZZ
34 #include "ass_bitmap.h"
35 #include "ass_cache.h"
36 #include "ass_utils.h"
37 #include "ass_fontselect.h"
38 #include "ass_library.h"
39 #include "ass_drawing.h"
40 #include "ass_bitmap.h"
41 #include "ass_rasterizer.h"
43 #define GLYPH_CACHE_MAX 10000
44 #define MEGABYTE (1024 * 1024)
45 #define BITMAP_CACHE_MAX_SIZE (128 * MEGABYTE)
46 #define COMPOSITE_CACHE_RATIO 2
47 #define COMPOSITE_CACHE_MAX_SIZE (BITMAP_CACHE_MAX_SIZE / COMPOSITE_CACHE_RATIO)
49 #define PARSED_FADE (1<<0)
50 #define PARSED_A (1<<1)
66 CompositeHashValue *source;
73 int storage_width; // video width before any rescaling
74 int storage_height; // video height before any rescaling
75 double font_size_coeff; // font size multiplier
76 double line_spacing; // additional line spacing (in frame pixels)
77 double line_position; // vertical position for subtitles, 0-100 (0 = no change)
78 int top_margin; // height of top margin. Everything except toptitles is shifted down by top_margin.
79 int bottom_margin; // height of bottom margin. (frame_height - top_margin - bottom_margin) is original video height.
82 int use_margins; // 0 - place all subtitles inside original frame
83 // 1 - use margins for placing toptitles and subtitles
84 double par; // user defined pixel aspect ratio (0 = unset)
86 ASS_ShapingLevel shaper;
87 int selective_style_overrides; // ASS_OVERRIDE_* flags
96 int top, height, left, width;
97 int detect_collisions;
111 int x_min, y_min, x_max, y_max;
114 // describes a combined bitmap
117 uint32_t c[4]; // colors
119 int effect_timing; // time duration of current karaoke word
120 // after process_karaoke_effects: distance in pixels from the glyph origin.
121 // part of the glyph to the left of it is displayed in a different color.
125 size_t bitmap_count, max_bitmap_count;
129 Rectangle rect, rect_o;
132 Bitmap *bm, *bm_o, *bm_s; // glyphs, outline, shadow bitmaps
133 CompositeHashValue *image;
134 } CombinedBitmapInfo;
137 // GlyphInfo and TextInfo are used for text centering and word-wrapping operations
138 typedef struct glyph_info {
140 unsigned skip; // skip glyph when layouting text
144 #ifdef CONFIG_HARFBUZZ
150 ASS_Drawing *drawing;
151 ASS_Outline *outline;
156 char linebreak; // the first (leading) glyph of some line ?
157 uint32_t c[4]; // colors
158 FT_Vector advance; // 26.6
159 FT_Vector cluster_advance;
160 char effect; // the first (leading) glyph of some effect ?
162 int effect_timing; // time duration of current karaoke word
163 // after process_karaoke_effects: distance in pixels from the glyph origin.
164 // part of the glyph to the left of it is displayed in a different color.
165 int effect_skip_timing; // delay after the end of last karaoke word
166 int asc, desc; // font max ascender and descender
167 int be; // blur edges
168 double blur; // gaussian blur
171 double frx, fry, frz; // rotation
172 double fax, fay; // text shearing
173 double scale_x, scale_y;
174 double orig_scale_x, orig_scale_y; // scale_x,y before fix_glyph_scaling
176 double border_x, border_y;
184 BitmapHashKey hash_key;
185 BitmapHashValue *image;
187 // next glyph in this cluster
188 struct glyph_info *next;
201 CombinedBitmapInfo *combined_bitmaps;
206 unsigned max_bitmaps;
210 // Values like current font face, color, screen position, clipping and so on are stored here.
218 int flags; // decoration flags (underline/strike-through)
220 int alignment; // alignment overrides go here; if zero, style value will be used
221 int justify; // justify instructions
222 double frx, fry, frz;
223 double fax, fay; // text shearing
225 EVENT_NORMAL, // "normal" top-, sub- or mid- title
226 EVENT_POSITIONED, // happens after pos(,), margins are ignored
227 EVENT_HSCROLL, // "Banner" transition effect, text_width is unlimited
228 EVENT_VSCROLL // "Scroll up", "Scroll down" transition effects
230 double pos_x, pos_y; // position
231 double org_x, org_y; // origin
232 char have_origin; // origin is explicitly defined; if 0, get_base_point() is used
233 double scale_x, scale_y;
234 double hspacing; // distance between letters, in pixels
236 double border_x; // outline width
238 uint32_t c[4]; // colors(Primary, Secondary, so on) in RGBA
239 int clip_x0, clip_y0, clip_x1, clip_y1;
240 char clip_mode; // 1 = iclip
241 char detect_collisions;
242 int fade; // alpha from \fad
243 char be; // blur edges
244 double blur; // gaussian blur
247 int drawing_scale; // currently reading: regular text if 0, drawing otherwise
248 double pbo; // drawing baseline offset
249 ASS_Drawing *clip_drawing; // clip vector
250 int clip_drawing_mode; // 0 = regular clip, 1 = inverse clip
254 int effect_skip_timing;
257 SCROLL_LR, // left-to-right
259 SCROLL_TB, // top-to-bottom
261 } scroll_direction; // for EVENT_HSCROLL, EVENT_VSCROLL
268 int treat_family_as_pattern;
272 // combination of ASS_OVERRIDE_BIT_* flags that apply right now
274 // whether to apply font_scale
275 int apply_font_scale;
276 // whether this is assumed to be explicitly positioned
279 // used to store RenderContext.style when doing selective style overrides
280 ASS_Style override_style_temp_storage;
285 Cache *outline_cache;
287 Cache *composite_cache;
289 size_t bitmap_max_size;
290 size_t composite_max_size;
293 #include "ass_shaper.h"
295 struct ass_renderer {
296 ASS_Library *library;
297 FT_Library ftlibrary;
298 ASS_FontSelector *fontselect;
299 ASS_Settings settings;
303 ASS_Image *images_root; // rendering result is stored here
304 ASS_Image *prev_images_root;
306 EventImages *eimg; // temporary buffer for sorting rendered events
307 int eimg_size; // allocated buffer size
310 int width, height; // screen dimensions
311 int orig_height; // frame height ( = screen height - margins )
312 int orig_width; // frame width ( = screen width - margins )
313 int orig_height_nocrop; // frame height ( = screen height - margins + cropheight)
314 int orig_width_nocrop; // frame width ( = screen width - margins + cropwidth)
316 long long time; // frame's timestamp, ms
318 double font_scale_x; // x scale applied to all glyphs to preserve text aspect ratio
326 const BitmapEngine *engine;
327 RasterizerData rasterizer;
329 ASS_Style user_override_style;
332 typedef struct render_priv {
333 int top, height, left, width;
345 int a, b; // top and height
346 int ha, hb; // left and width
349 void reset_render_context(ASS_Renderer *render_priv, ASS_Style *style);
350 void ass_frame_ref(ASS_Image *img);
351 void ass_frame_unref(ASS_Image *img);
353 // XXX: this is actually in ass.c, includes should be fixed later on
354 void ass_lazy_track_init(ASS_Library *lib, ASS_Track *track);
356 #endif /* LIBASS_RENDER_H */