2 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
4 * This file is part of libass.
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.
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.
19 #ifndef LIBASS_BITMAP_H
20 #define LIBASS_BITMAP_H
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,
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);
45 typedef void (*BeBlurFunc)(uint8_t *buf, intptr_t w, intptr_t h,
46 intptr_t stride, uint16_t *tmp);
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);
59 #define C_ALIGN_ORDER 5
62 int align_order; // log2(alignment)
64 // rasterizer functions
65 int tile_order; // log2(tile_size)
66 FillSolidTileFunc fill_solid;
67 FillHalfplaneTileFunc fill_halfplane;
68 FillGenericTileFunc fill_generic;
71 BitmapBlendFunc add_bitmaps, sub_bitmaps;
72 BitmapMulFunc mul_bitmaps;
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];
86 extern const BitmapEngine ass_bitmap_engine_c;
87 extern const BitmapEngine ass_bitmap_engine_sse2;
88 extern const BitmapEngine ass_bitmap_engine_avx2;
91 typedef struct ass_outline ASS_Outline;
95 int w, h; // width, height
97 unsigned char *buffer; // h * stride buffer
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);
105 Bitmap *outline_to_bitmap(ASS_Renderer *render_priv,
106 ASS_Outline *outline1, ASS_Outline *outline2,
109 void ass_synth_blur(const BitmapEngine *engine, int opaque_box, int be,
110 double blur_radius, Bitmap *bm_g, Bitmap *bm_o);
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
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);
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);
133 #endif /* LIBASS_BITMAP_H */