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
28 #include FT_SYNTHESIS_H
30 // XXX: fix the inclusion mess so we can avoid doing this here
31 typedef struct ass_shaper ASS_Shaper
;
35 #include "ass_bitmap.h"
36 #include "ass_cache.h"
37 #include "ass_utils.h"
38 #include "ass_fontconfig.h"
39 #include "ass_library.h"
40 #include "ass_drawing.h"
42 #define GLYPH_CACHE_MAX 1000
43 #define BITMAP_CACHE_MAX_SIZE 30 * 1048576
45 #define PARSED_FADE (1<<0)
46 #define PARSED_A (1<<1)
60 typedef struct free_list
{
62 struct free_list
*next
;
68 double font_size_coeff
; // font size multiplier
69 double line_spacing
; // additional line spacing (in frame pixels)
70 int top_margin
; // height of top margin. Everything except toptitles is shifted down by top_margin.
71 int bottom_margin
; // height of bottom margin. (frame_height - top_margin - bottom_margin) is original video height.
74 int use_margins
; // 0 - place all subtitles inside original frame
75 // 1 - use margins for placing toptitles and subtitles
76 double aspect
; // frame aspect ratio, d_width / d_height.
77 double storage_aspect
; // pixel ratio of the source image
87 int top
, height
, left
, width
;
88 int detect_collisions
;
101 // GlyphInfo and TextInfo are used for text centering and word-wrapping operations
102 typedef struct glyph_info
{
104 unsigned skip
; // skip glyph when layouting text
109 ASS_Drawing
*drawing
;
112 Bitmap
*bm
; // glyph bitmap
113 Bitmap
*bm_o
; // outline bitmap
114 Bitmap
*bm_s
; // shadow bitmap
118 char linebreak
; // the first (leading) glyph of some line ?
119 uint32_t c
[4]; // colors
120 FT_Vector advance
; // 26.6
121 FT_Vector cluster_advance
;
123 int effect_timing
; // time duration of current karaoke word
124 // after process_karaoke_effects: distance in pixels from the glyph origin.
125 // part of the glyph to the left of it is displayed in a different color.
126 int effect_skip_timing
; // delay after the end of last karaoke word
127 int asc
, desc
; // font max ascender and descender
128 int be
; // blur edges
129 double blur
; // gaussian blur
132 double frx
, fry
, frz
; // rotation
133 double fax
, fay
; // text shearing
134 double scale_x
, scale_y
;
135 double border_x
, border_y
;
143 BitmapHashKey hash_key
;
145 // next glyph in this cluster
146 struct glyph_info
*next
;
165 // Values like current font face, color, screen position, clipping and so on are stored here.
173 int flags
; // decoration flags (underline/strike-through)
176 int alignment
; // alignment overrides go here; if zero, style value will be used
177 double frx
, fry
, frz
;
178 double fax
, fay
; // text shearing
180 EVENT_NORMAL
, // "normal" top-, sub- or mid- title
181 EVENT_POSITIONED
, // happens after pos(,), margins are ignored
182 EVENT_HSCROLL
, // "Banner" transition effect, text_width is unlimited
183 EVENT_VSCROLL
// "Scroll up", "Scroll down" transition effects
185 double pos_x
, pos_y
; // position
186 double org_x
, org_y
; // origin
187 char have_origin
; // origin is explicitly defined; if 0, get_base_point() is used
188 double scale_x
, scale_y
;
189 double hspacing
; // distance between letters, in pixels
190 double border_x
; // outline width
192 uint32_t c
[4]; // colors(Primary, Secondary, so on) in RGBA
193 int clip_x0
, clip_y0
, clip_x1
, clip_y1
;
194 char clip_mode
; // 1 = iclip
195 char detect_collisions
;
196 uint32_t fade
; // alpha from \fad
197 char be
; // blur edges
198 double blur
; // gaussian blur
201 int drawing_mode
; // not implemented; when != 0 text is discarded, except for style override tags
202 ASS_Drawing
*drawing
; // current drawing
203 ASS_Drawing
*clip_drawing
; // clip vector
204 int clip_drawing_mode
; // 0 = regular clip, 1 = inverse clip
208 int effect_skip_timing
;
210 // bitmap run id (used for final bitmap rendering)
214 SCROLL_LR
, // left-to-right
216 SCROLL_TB
, // top-to-bottom
218 } scroll_direction
; // for EVENT_HSCROLL, EVENT_VSCROLL
225 int treat_family_as_pattern
;
232 Cache
*outline_cache
;
234 Cache
*composite_cache
;
236 size_t bitmap_max_size
;
239 struct ass_renderer
{
240 ASS_Library
*library
;
241 FT_Library ftlibrary
;
242 FCInstance
*fontconfig_priv
;
243 ASS_Settings settings
;
245 ASS_SynthPriv
*synth_priv
;
248 ASS_Image
*images_root
; // rendering result is stored here
249 ASS_Image
*prev_images_root
;
251 EventImages
*eimg
; // temporary buffer for sorting rendered events
252 int eimg_size
; // allocated buffer size
255 int width
, height
; // screen dimensions
256 int orig_height
; // frame height ( = screen height - margins )
257 int orig_width
; // frame width ( = screen width - margins )
258 int orig_height_nocrop
; // frame height ( = screen height - margins + cropheight)
259 int orig_width_nocrop
; // frame width ( = screen width - margins + cropwidth)
261 long long time
; // frame's timestamp, ms
263 double font_scale_x
; // x scale applied to all glyphs to preserve text aspect ratio
274 typedef struct render_priv
{
275 int top
, height
, left
, width
;
287 int a
, b
; // top and height
288 int ha
, hb
; // left and width
291 void reset_render_context(ASS_Renderer
*render_priv
);
292 void ass_free_images(ASS_Image
*img
);
294 // XXX: this is actually in ass.c, includes should be fixed later on
295 void ass_lazy_track_init(ASS_Library
*lib
, ASS_Track
*track
);
297 #endif /* LIBASS_RENDER_H */