]> granicus.if.org Git - libass/blob - libass/ass_bitmap.h
renderer: switch to using two border outlines instead of one
[libass] / libass / ass_bitmap.h
1 /*
2  * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
3  *
4  * This file is part of libass.
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18
19 #ifndef LIBASS_BITMAP_H
20 #define LIBASS_BITMAP_H
21
22 #include <stdbool.h>
23 #include <ft2build.h>
24 #include FT_GLYPH_H
25
26 #include "ass.h"
27
28
29 struct segment;
30 typedef void (*FillSolidTileFunc)(uint8_t *buf, ptrdiff_t stride, int set);
31 typedef void (*FillHalfplaneTileFunc)(uint8_t *buf, ptrdiff_t stride,
32                                       int32_t a, int32_t b, int64_t c, int32_t scale);
33 typedef void (*FillGenericTileFunc)(uint8_t *buf, ptrdiff_t stride,
34                                     const struct segment *line, size_t n_lines,
35                                     int winding);
36
37 typedef void (*BitmapBlendFunc)(uint8_t *dst, intptr_t dst_stride,
38                                 uint8_t *src, intptr_t src_stride,
39                                 intptr_t height, intptr_t width);
40 typedef void (*BitmapMulFunc)(uint8_t *dst, intptr_t dst_stride,
41                               uint8_t *src1, intptr_t src1_stride,
42                               uint8_t *src2, intptr_t src2_stride,
43                               intptr_t width, intptr_t height);
44
45 typedef void (*BeBlurFunc)(uint8_t *buf, intptr_t w, intptr_t h,
46                            intptr_t stride, uint16_t *tmp);
47
48 // intermediate bitmaps represented as sets of verical stripes of int16_t[alignment / 2]
49 typedef void (*Convert8to16Func)(int16_t *dst, const uint8_t *src, ptrdiff_t src_stride,
50                                  uintptr_t width, uintptr_t height);
51 typedef void (*Convert16to8Func)(uint8_t *dst, ptrdiff_t dst_stride, const int16_t *src,
52                                  uintptr_t width, uintptr_t height);
53 typedef void (*FilterFunc)(int16_t *dst, const int16_t *src,
54                            uintptr_t src_width, uintptr_t src_height);
55 typedef void (*ParamFilterFunc)(int16_t *dst, const int16_t *src,
56                                 uintptr_t src_width, uintptr_t src_height,
57                                 const int16_t *param);
58
59 #define C_ALIGN_ORDER 5
60
61 typedef struct {
62     int align_order;  // log2(alignment)
63
64     // rasterizer functions
65     int tile_order;  // log2(tile_size)
66     FillSolidTileFunc fill_solid;
67     FillHalfplaneTileFunc fill_halfplane;
68     FillGenericTileFunc fill_generic;
69
70     // blend functions
71     BitmapBlendFunc add_bitmaps, sub_bitmaps;
72     BitmapMulFunc mul_bitmaps;
73
74     // be blur function
75     BeBlurFunc be_blur;
76
77     // gaussian blur functions
78     Convert8to16Func stripe_unpack;
79     Convert16to8Func stripe_pack;
80     FilterFunc shrink_horz, shrink_vert;
81     FilterFunc expand_horz, expand_vert;
82     FilterFunc pre_blur_horz[3], pre_blur_vert[3];
83     ParamFilterFunc main_blur_horz[3], main_blur_vert[3];
84 } BitmapEngine;
85
86 extern const BitmapEngine ass_bitmap_engine_c;
87 extern const BitmapEngine ass_bitmap_engine_sse2;
88 extern const BitmapEngine ass_bitmap_engine_avx2;
89
90
91 typedef struct ass_outline ASS_Outline;
92
93 typedef struct {
94     int left, top;
95     int w, h;                   // width, height
96     int stride;
97     unsigned char *buffer;      // h * stride buffer
98 } Bitmap;
99
100 Bitmap *alloc_bitmap(const BitmapEngine *engine, int w, int h, bool zero);
101 bool realloc_bitmap(const BitmapEngine *engine, Bitmap *bm, int w, int h);
102 Bitmap *copy_bitmap(const BitmapEngine *engine, const Bitmap *src);
103 void ass_free_bitmap(Bitmap *bm);
104
105 Bitmap *outline_to_bitmap(ASS_Renderer *render_priv,
106                           ASS_Outline *outline1, ASS_Outline *outline2,
107                           int bord);
108
109 void ass_synth_blur(const BitmapEngine *engine, int opaque_box, int be,
110                     double blur_radius, Bitmap *bm_g, Bitmap *bm_o);
111
112 /**
113  * \brief perform glyph rendering
114  * \param outline original glyph
115  * \param border1 inside "border" outline, produced by stroker
116  * \param border2 outside "border" outline, produced by stroker
117  * \param bm_g out: pointer to the bitmap of original glyph is returned here
118  * \param bm_o out: pointer to the bitmap of border glyph is returned here
119  */
120 int outline_to_bitmap2(ASS_Renderer *render_priv, ASS_Outline *outline,
121                        ASS_Outline *border1, ASS_Outline *border2,
122                        Bitmap **bm_g, Bitmap **bm_o);
123
124 int be_padding(int be);
125 void be_blur_pre(uint8_t *buf, intptr_t w,
126                  intptr_t h, intptr_t stride);
127 void be_blur_post(uint8_t *buf, intptr_t w,
128                   intptr_t h, intptr_t stride);
129 bool ass_gaussian_blur(const BitmapEngine *engine, Bitmap *bm, double r2);
130 void shift_bitmap(Bitmap *bm, int shift_x, int shift_y);
131 void fix_outline(Bitmap *bm_g, Bitmap *bm_o);
132
133 #endif                          /* LIBASS_BITMAP_H */