]> granicus.if.org Git - libass/blob - libass/ass_rasterizer.h
Consolidate bounding box operations
[libass] / libass / ass_rasterizer.h
1 /*
2  * Copyright (C) 2014 Vabishchevich Nikolay <vabnick@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_RASTERIZER_H
20 #define LIBASS_RASTERIZER_H
21
22 #include <stddef.h>
23 #include <stdint.h>
24 #include <stdbool.h>
25
26 #include "ass_bitmap.h"
27
28
29 enum {
30     SEGFLAG_DN           =  1,
31     SEGFLAG_UL_DR        =  2,
32     SEGFLAG_EXACT_LEFT   =  4,
33     SEGFLAG_EXACT_RIGHT  =  8,
34     SEGFLAG_EXACT_TOP    = 16,
35     SEGFLAG_EXACT_BOTTOM = 32,
36 };
37
38 // Polyline segment struct
39 struct segment {
40     int64_t c;
41     int32_t a, b, scale, flags;
42     int32_t x_min, x_max, y_min, y_max;
43 };
44
45 typedef struct {
46     int outline_error;  // acceptable error (in 1/64 pixel units)
47
48     // usable after rasterizer_set_outline
49     ASS_Rect bbox;
50
51     // internal buffers
52     struct segment *linebuf[2];
53     size_t size[2], capacity[2];
54     size_t n_first;
55
56     uint8_t *tile;
57 } RasterizerData;
58
59 bool rasterizer_init(RasterizerData *rst, int tile_order, int outline_error);
60 void rasterizer_done(RasterizerData *rst);
61
62 /**
63  * \brief Convert outline to polyline and calculate exact bounds
64  * \param path in: source outline
65  * \param extra in: true if path is second border outline
66  * \return false on error
67  */
68 bool rasterizer_set_outline(RasterizerData *rst,
69                             const ASS_Outline *path, bool extra);
70
71 /**
72  * \brief Polyline rasterization function
73  * \param x0, y0, width, height in: source window (full pixel units)
74  * \param buf out: aligned output buffer (size = stride * height)
75  * \param stride output buffer stride (aligned)
76  * \return false on error
77  * Deletes preprocessed polyline after work.
78  */
79 bool rasterizer_fill(const BitmapEngine *engine, RasterizerData *rst,
80                      uint8_t *buf, int x0, int y0,
81                      int width, int height, ptrdiff_t stride);
82
83
84 #endif /* LIBASS_RASTERIZER_H */