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)
54 CompositeHashValue *source;
61 int storage_width; // video width before any rescaling
62 int storage_height; // video height before any rescaling
63 double font_size_coeff; // font size multiplier
64 double line_spacing; // additional line spacing (in frame pixels)
65 double line_position; // vertical position for subtitles, 0-100 (0 = no change)
66 int top_margin; // height of top margin. Everything except toptitles is shifted down by top_margin.
67 int bottom_margin; // height of bottom margin. (frame_height - top_margin - bottom_margin) is original video height.
70 int use_margins; // 0 - place all subtitles inside original frame
71 // 1 - use margins for placing toptitles and subtitles
72 double par; // user defined pixel aspect ratio (0 = unset)
74 ASS_ShapingLevel shaper;
75 int selective_style_overrides; // ASS_OVERRIDE_* flags
84 int top, height, left, width;
85 int detect_collisions;
97 // describes a combined bitmap
100 uint32_t c[4]; // colors
102 int effect_timing; // time duration of current karaoke word
103 // after process_karaoke_effects: distance in pixels from the glyph origin.
104 // part of the glyph to the left of it is displayed in a different color.
108 size_t bitmap_count, max_bitmap_count;
112 Bitmap *bm, *bm_o, *bm_s; // glyphs, outline, shadow bitmaps
113 CompositeHashValue *image;
114 } CombinedBitmapInfo;
117 ASS_DVector scale, offset;
121 // GlyphInfo and TextInfo are used for text centering and word-wrapping operations
122 typedef struct glyph_info {
124 unsigned skip; // skip glyph when layouting text
128 #ifdef CONFIG_HARFBUZZ
137 OutlineHashValue *outline;
138 ASS_Transform transform;
142 char linebreak; // the first (leading) glyph of some line ?
143 uint32_t c[4]; // colors
144 ASS_Vector advance; // 26.6
145 ASS_Vector cluster_advance;
146 char effect; // the first (leading) glyph of some effect ?
148 int effect_timing; // time duration of current karaoke word
149 // after process_karaoke_effects: distance in pixels from the glyph origin.
150 // part of the glyph to the left of it is displayed in a different color.
151 int effect_skip_timing; // delay after the end of last karaoke word
152 int asc, desc; // font max ascender and descender
153 int be; // blur edges
154 double blur; // gaussian blur
157 double frx, fry, frz; // rotation
158 double fax, fay; // text shearing
159 double scale_x, scale_y;
160 // amount of scale_x,y change due to fix_glyph_scaling
161 // scale_fix = before / after
164 double border_x, border_y;
166 int hspacing_scaled; // 26.6
174 ASS_Vector bitmap_advance;
175 BitmapHashValue *image, *image_o;
177 // next glyph in this cluster
178 struct glyph_info *next;
191 CombinedBitmapInfo *combined_bitmaps;
196 unsigned max_bitmaps;
200 // Values like current font face, color, screen position, clipping and so on are stored here.
208 int flags; // decoration flags (underline/strike-through)
210 int alignment; // alignment overrides go here; if zero, style value will be used
211 int justify; // justify instructions
212 double frx, fry, frz;
213 double fax, fay; // text shearing
215 EVENT_NORMAL, // "normal" top-, sub- or mid- title
216 EVENT_POSITIONED, // happens after pos(,), margins are ignored
217 EVENT_HSCROLL, // "Banner" transition effect, text_width is unlimited
218 EVENT_VSCROLL // "Scroll up", "Scroll down" transition effects
220 double pos_x, pos_y; // position
221 double org_x, org_y; // origin
222 char have_origin; // origin is explicitly defined; if 0, get_base_point() is used
223 double scale_x, scale_y;
224 double hspacing; // distance between letters, in pixels
226 double border_x; // outline width
228 uint32_t c[4]; // colors(Primary, Secondary, so on) in RGBA
229 int clip_x0, clip_y0, clip_x1, clip_y1;
230 char clip_mode; // 1 = iclip
231 char detect_collisions;
232 int fade; // alpha from \fad
233 char be; // blur edges
234 double blur; // gaussian blur
237 int drawing_scale; // currently reading: regular text if 0, drawing otherwise
238 double pbo; // drawing baseline offset
239 char *clip_drawing_text;
240 int clip_drawing_scale;
241 int clip_drawing_mode; // 0 = regular clip, 1 = inverse clip
245 int effect_skip_timing;
248 SCROLL_LR, // left-to-right
250 SCROLL_TB, // top-to-bottom
252 } scroll_direction; // for EVENT_HSCROLL, EVENT_VSCROLL
259 int treat_family_as_pattern;
263 // combination of ASS_OVERRIDE_BIT_* flags that apply right now
265 // whether to apply font_scale
266 int apply_font_scale;
267 // whether this is assumed to be explicitly positioned
270 // used to store RenderContext.style when doing selective style overrides
271 ASS_Style override_style_temp_storage;
276 Cache *outline_cache;
278 Cache *composite_cache;
280 size_t bitmap_max_size;
281 size_t composite_max_size;
284 #include "ass_shaper.h"
286 struct ass_renderer {
287 ASS_Library *library;
288 FT_Library ftlibrary;
289 ASS_FontSelector *fontselect;
290 ASS_Settings settings;
294 ASS_Image *images_root; // rendering result is stored here
295 ASS_Image *prev_images_root;
297 EventImages *eimg; // temporary buffer for sorting rendered events
298 int eimg_size; // allocated buffer size
301 int width, height; // screen dimensions
302 int orig_height; // frame height ( = screen height - margins )
303 int orig_width; // frame width ( = screen width - margins )
304 int orig_height_nocrop; // frame height ( = screen height - margins + cropheight)
305 int orig_width_nocrop; // frame width ( = screen width - margins + cropwidth)
307 long long time; // frame's timestamp, ms
309 double font_scale_x; // x scale applied to all glyphs to preserve text aspect ratio
317 const BitmapEngine *engine;
318 RasterizerData rasterizer;
320 ASS_Style user_override_style;
323 typedef struct render_priv {
324 int top, height, left, width;
336 int a, b; // top and height
337 int ha, hb; // left and width
340 void reset_render_context(ASS_Renderer *render_priv, ASS_Style *style);
341 void ass_frame_ref(ASS_Image *img);
342 void ass_frame_unref(ASS_Image *img);
344 // XXX: this is actually in ass.c, includes should be fixed later on
345 void ass_lazy_track_init(ASS_Library *lib, ASS_Track *track);
347 #endif /* LIBASS_RENDER_H */