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 25 #include "ass_bitmap.h" 26 #include "ass_font.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 int32_t x_min, x_max, y_min, y_max; 50 51 // internal buffers 52 struct segment *linebuf[2]; 53 size_t size[2], capacity[2]; 54 } RasterizerData; 55 56 void rasterizer_init(RasterizerData *rst, int outline_error); 57 void rasterizer_done(RasterizerData *rst); 58 59 /** 60 * \brief Convert FreeType outline to polyline and calculate exact bounds 61 */ 62 int rasterizer_set_outline(RasterizerData *rst, const ASS_Outline *path); 63 64 /** 65 * \brief Polyline rasterization function 66 * \param x0, y0, width, height in: source window (full pixel units) 67 * \param buf out: aligned output buffer (size = stride * height) 68 * \param stride output buffer stride (aligned) 69 * \return zero on error 70 * Deletes preprocessed polyline after work. 71 */ 72 int rasterizer_fill(const BitmapEngine *engine, RasterizerData *rst, 73 uint8_t *buf, int x0, int y0, 74 int width, int height, ptrdiff_t stride); 75 76 77 #endif /* LIBASS_RASTERIZER_H */ 78