diff options
Diffstat (limited to 'libass')
-rw-r--r-- | libass/ass_bitmap.h | 3 | ||||
-rw-r--r-- | libass/ass_cache.h | 4 | ||||
-rw-r--r-- | libass/ass_cache_template.h | 18 | ||||
-rw-r--r-- | libass/ass_drawing.c | 85 | ||||
-rw-r--r-- | libass/ass_drawing.h | 29 | ||||
-rw-r--r-- | libass/ass_outline.c | 164 | ||||
-rw-r--r-- | libass/ass_outline.h | 24 | ||||
-rw-r--r-- | libass/ass_parse.c | 7 | ||||
-rw-r--r-- | libass/ass_rasterizer.c | 22 | ||||
-rw-r--r-- | libass/ass_render.c | 79 | ||||
-rw-r--r-- | libass/ass_render.h | 22 |
11 files changed, 207 insertions, 250 deletions
diff --git a/libass/ass_bitmap.h b/libass/ass_bitmap.h index 8dc1b19..e919cd5 100644 --- a/libass/ass_bitmap.h +++ b/libass/ass_bitmap.h @@ -24,6 +24,7 @@ #include FT_GLYPH_H #include "ass.h" +#include "ass_outline.h" struct segment; @@ -88,8 +89,6 @@ extern const BitmapEngine ass_bitmap_engine_sse2; extern const BitmapEngine ass_bitmap_engine_avx2; -typedef struct ass_outline ASS_Outline; - typedef struct { int left, top; int w, h; // width, height diff --git a/libass/ass_cache.h b/libass/ass_cache.h index 03e58c7..278eae4 100644 --- a/libass/ass_cache.h +++ b/libass/ass_cache.h @@ -45,8 +45,8 @@ typedef struct { bool valid; ASS_Outline outline; ASS_Outline border[2]; - FT_BBox bbox_scaled; // bbox after scaling, but before rotation - FT_Vector advance; // 26.6, advance distance to the next outline in line + ASS_Rect bbox_scaled; // bbox after scaling, but before rotation + ASS_Vector advance; // 26.6, advance distance to the next outline in line int asc, desc; // ascender/descender } OutlineHashValue; diff --git a/libass/ass_cache_template.h b/libass/ass_cache_template.h index 9d81231..ba9303f 100644 --- a/libass/ass_cache_template.h +++ b/libass/ass_cache_template.h @@ -6,8 +6,8 @@ type member; #define STRING(member) \ char *member; -#define FTVECTOR(member) \ - FT_Vector member; +#define VECTOR(member) \ + ASS_Vector member; #define BITMAPHASHKEY(member) \ BitmapHashKey member; #define END(typedefnamename) \ @@ -25,7 +25,7 @@ a->member == b->member && #define STRING(member) \ strcmp(a->member, b->member) == 0 && -#define FTVECTOR(member) \ +#define VECTOR(member) \ a->member.x == b->member.x && a->member.y == b->member.y && #define BITMAPHASHKEY(member) \ bitmap_compare(&a->member, &b->member, sizeof(a->member)) && @@ -44,7 +44,7 @@ hval = fnv_32a_buf(&p->member, sizeof(p->member), hval); #define STRING(member) \ hval = fnv_32a_str(p->member, hval); -#define FTVECTOR(member) GENERIC(, member.x); GENERIC(, member.y); +#define VECTOR(member) GENERIC(, member.x); GENERIC(, member.y); #define BITMAPHASHKEY(member) { \ unsigned temp = bitmap_hash(&p->member, sizeof(p->member)); \ hval = fnv_32a_buf(&temp, sizeof(temp), hval); \ @@ -72,7 +72,7 @@ START(outline_bitmap, outline_bitmap_hash_key) // = (glyph base point) - (rotation origin), otherwise GENERIC(int, shift_x) GENERIC(int, shift_y) - FTVECTOR(advance) // subpixel shift vector + VECTOR(advance) // subpixel shift vector END(OutlineBitmapHashKey) // describe a clip mask bitmap @@ -90,7 +90,7 @@ START(glyph, glyph_hash_key) GENERIC(int, italic) GENERIC(unsigned, scale_x) // 16.16 GENERIC(unsigned, scale_y) // 16.16 - FTVECTOR(outline) // border width, 26.6 + VECTOR(outline) // border width, 26.6 GENERIC(unsigned, flags) // glyph decoration flags GENERIC(unsigned, border_style) GENERIC(int, hspacing) // 16.16 @@ -110,7 +110,7 @@ START(drawing, drawing_hash_key) GENERIC(unsigned, scale_x) GENERIC(unsigned, scale_y) GENERIC(int, pbo) - FTVECTOR(outline) + VECTOR(outline) GENERIC(unsigned, border_style) GENERIC(int, hspacing) GENERIC(int, scale) @@ -123,12 +123,12 @@ START(filter, filter_desc) GENERIC(int, flags) GENERIC(int, be) GENERIC(double, blur) - FTVECTOR(shadow) + VECTOR(shadow) END(FilterDesc) #undef START #undef GENERIC #undef STRING -#undef FTVECTOR +#undef VECTOR #undef BITMAPHASHKEY #undef END diff --git a/libass/ass_drawing.c b/libass/ass_drawing.c index 23fe8cd..d235517 100644 --- a/libass/ass_drawing.c +++ b/libass/ass_drawing.c @@ -21,7 +21,6 @@ #include <ft2build.h> #include FT_OUTLINE_H -#include FT_BBOX_H #include <math.h> #include <stdbool.h> #include <limits.h> @@ -30,7 +29,6 @@ #include "ass_drawing.h" #include "ass_font.h" -#define CURVE_ACCURACY 64.0 #define GLYPH_INITIAL_POINTS 100 #define GLYPH_INITIAL_CONTOURS 5 @@ -48,11 +46,9 @@ static void drawing_prepare(ASS_Drawing *drawing) * \brief Finish a drawing. This only sets the horizontal advance according * to the outline's bbox at the moment. */ -static void drawing_finish(ASS_Drawing *drawing, int raw_mode) +static void drawing_finish(ASS_Drawing *drawing, bool raw_mode) { - int i; - double pbo; - FT_BBox bbox = drawing->cbox; + ASS_Rect bbox = drawing->cbox; ASS_Outline *ol = &drawing->outline; if (drawing->library) @@ -63,14 +59,14 @@ static void drawing_finish(ASS_Drawing *drawing, int raw_mode) if (raw_mode) return; - drawing->advance.x = bbox.xMax - bbox.xMin; + drawing->advance.x = bbox.x_max - bbox.x_min; - pbo = drawing->pbo / (1 << (drawing->scale - 1)); + double pbo = drawing->pbo / (1 << (drawing->scale - 1)); drawing->desc = double_to_d6(pbo * drawing->scale_y); - drawing->asc = bbox.yMax - bbox.yMin - drawing->desc; + drawing->asc = bbox.y_max - bbox.y_min - drawing->desc; // Place it onto the baseline - for (i = 0; i < ol->n_points; i++) + for (size_t i = 0; i < ol->n_points; i++) ol->points[i].y += drawing->asc; } @@ -79,8 +75,7 @@ static void drawing_finish(ASS_Drawing *drawing, int raw_mode) */ static int token_check_values(ASS_DrawingToken *token, int i, int type) { - int j; - for (j = 0; j < i; j++) { + for (int j = 0; j < i; j++) { if (!token || token->type != type) return 0; token = token->next; } @@ -95,9 +90,9 @@ static int token_check_values(ASS_DrawingToken *token, int i, int type) static ASS_DrawingToken *drawing_tokenize(char *str) { char *p = str; - int i, type = -1, is_set = 0; + int type = -1, is_set = 0; double val; - FT_Vector point = {0, 0}; + ASS_Vector point = {0, 0}; ASS_DrawingToken *root = NULL, *tail = NULL, *spline_start = NULL; @@ -107,7 +102,7 @@ static ASS_DrawingToken *drawing_tokenize(char *str) // Close b-splines: add the first three points of the b-spline // back to the end if (token_check_values(spline_start->next, 2, TOKEN_B_SPLINE)) { - for (i = 0; i < 3; i++) { + for (int i = 0; i < 3; i++) { tail->next = calloc(1, sizeof(ASS_DrawingToken)); tail->next->prev = tail; tail = tail->next; @@ -181,21 +176,21 @@ static void drawing_free_tokens(ASS_DrawingToken *token) /* * \brief Update drawing cbox */ -static inline void update_cbox(ASS_Drawing *drawing, FT_Vector *point) +static inline void update_cbox(ASS_Drawing *drawing, ASS_Vector *point) { - FT_BBox *box = &drawing->cbox; + ASS_Rect *box = &drawing->cbox; - box->xMin = FFMIN(box->xMin, point->x); - box->xMax = FFMAX(box->xMax, point->x); - box->yMin = FFMIN(box->yMin, point->y); - box->yMax = FFMAX(box->yMax, point->y); + box->x_min = FFMIN(box->x_min, point->x); + box->x_max = FFMAX(box->x_max, point->x); + box->y_min = FFMIN(box->y_min, point->y); + box->y_max = FFMAX(box->y_max, point->y); } /* * \brief Translate and scale a point coordinate according to baseline * offset and scale. */ -static inline void translate_point(ASS_Drawing *drawing, FT_Vector *point) +static inline void translate_point(ASS_Drawing *drawing, ASS_Vector *point) { point->x = drawing->point_scale_x * point->x; point->y = drawing->point_scale_y * -point->y; @@ -204,15 +199,12 @@ static inline void translate_point(ASS_Drawing *drawing, FT_Vector *point) } /* - * \brief Evaluate a curve into lines - * This curve evaluator is also used in VSFilter (RTS.cpp); it's a simple - * implementation of the De Casteljau algorithm. + * \brief Add curve to drawing */ -static bool drawing_evaluate_curve(ASS_Drawing *drawing, - ASS_DrawingToken *token, char spline, - int started) +static bool drawing_add_curve(ASS_Drawing *drawing, ASS_DrawingToken *token, + bool spline, int started) { - FT_Vector p[4]; + ASS_Vector p[4]; for (int i = 0; i < 4; ++i) { p[i] = token->point; translate_point(drawing, &p[i]); @@ -247,14 +239,14 @@ static bool drawing_evaluate_curve(ASS_Drawing *drawing, /* * \brief Create and initialize a new drawing and return it */ -ASS_Drawing *ass_drawing_new(ASS_Library *lib, FT_Library ftlib) +ASS_Drawing *ass_drawing_new(ASS_Library *lib) { ASS_Drawing *drawing = calloc(1, sizeof(*drawing)); if (!drawing) return NULL; - drawing->cbox.xMin = drawing->cbox.yMin = INT_MAX; - drawing->cbox.xMax = drawing->cbox.yMax = INT_MIN; - drawing->library = lib; + drawing->cbox.x_min = drawing->cbox.y_min = INT32_MAX; + drawing->cbox.x_max = drawing->cbox.y_max = INT32_MIN; + drawing->library = lib; drawing->scale_x = 1.; drawing->scale_y = 1.; @@ -268,7 +260,7 @@ ASS_Drawing *ass_drawing_new(ASS_Library *lib, FT_Library ftlib) /* * \brief Free a drawing */ -void ass_drawing_free(ASS_Drawing* drawing) +void ass_drawing_free(ASS_Drawing *drawing) { if (drawing) { free(drawing->text); @@ -280,7 +272,7 @@ void ass_drawing_free(ASS_Drawing* drawing) /* * \brief Copy an ASCII string to the drawing text buffer */ -void ass_drawing_set_text(ASS_Drawing* drawing, char *str, size_t len) +void ass_drawing_set_text(ASS_Drawing *drawing, char *str, size_t len) { free(drawing->text); drawing->text = strndup(str, len); @@ -290,7 +282,7 @@ void ass_drawing_set_text(ASS_Drawing* drawing, char *str, size_t len) * \brief Create a hashcode for the drawing * XXX: To avoid collisions a better hash algorithm might be useful. */ -void ass_drawing_hash(ASS_Drawing* drawing) +void ass_drawing_hash(ASS_Drawing *drawing) { if (!drawing->text) return; @@ -300,11 +292,11 @@ void ass_drawing_hash(ASS_Drawing* drawing) /* * \brief Convert token list to outline. Calls the line and curve evaluators. */ -ASS_Outline *ass_drawing_parse(ASS_Drawing *drawing, int raw_mode) +ASS_Outline *ass_drawing_parse(ASS_Drawing *drawing, bool raw_mode) { - int started = 0; + bool started = false; ASS_DrawingToken *token; - FT_Vector pen = {0, 0}; + ASS_Vector pen = {0, 0}; drawing->tokens = drawing_tokenize(drawing->text); drawing_prepare(drawing); @@ -324,41 +316,40 @@ ASS_Outline *ass_drawing_parse(ASS_Drawing *drawing, int raw_mode) if (started) { if (!outline_close_contour(&drawing->outline)) goto error; - started = 0; + started = false; } token = token->next; break; case TOKEN_LINE: { - FT_Vector to; - to = token->point; + ASS_Vector to = token->point; translate_point(drawing, &to); if (!started && !outline_add_point(&drawing->outline, pen, FT_CURVE_TAG_ON)) goto error; if (!outline_add_point(&drawing->outline, to, FT_CURVE_TAG_ON)) goto error; - started = 1; + started = true; token = token->next; break; } case TOKEN_CUBIC_BEZIER: if (token_check_values(token, 3, TOKEN_CUBIC_BEZIER) && token->prev) { - if (!drawing_evaluate_curve(drawing, token->prev, 0, started)) + if (!drawing_add_curve(drawing, token->prev, false, started)) goto error; token = token->next; token = token->next; token = token->next; - started = 1; + started = true; } else token = token->next; break; case TOKEN_B_SPLINE: if (token_check_values(token, 3, TOKEN_B_SPLINE) && token->prev) { - if (!drawing_evaluate_curve(drawing, token->prev, 1, started)) + if (!drawing_add_curve(drawing, token->prev, true, started)) goto error; token = token->next; - started = 1; + started = true; } else token = token->next; break; diff --git a/libass/ass_drawing.h b/libass/ass_drawing.h index 28a7040..95e361f 100644 --- a/libass/ass_drawing.h +++ b/libass/ass_drawing.h @@ -19,9 +19,6 @@ #ifndef LIBASS_DRAWING_H #define LIBASS_DRAWING_H -#include <ft2build.h> -#include FT_OUTLINE_H - #include "ass.h" #include "ass_outline.h" #include "ass_bitmap.h" @@ -39,7 +36,7 @@ typedef enum { typedef struct ass_drawing_token { ASS_TokenType type; - FT_Vector point; + ASS_Vector point; struct ass_drawing_token *next; struct ass_drawing_token *prev; } ASS_DrawingToken; @@ -48,26 +45,26 @@ typedef struct { char *text; // drawing string int scale; // scale (1-64) for subpixel accuracy double pbo; // drawing will be shifted in y direction by this amount - double scale_x; // FontScaleX - double scale_y; // FontScaleY - int asc; // ascender - int desc; // descender + double scale_x; // FontScaleX + double scale_y; // FontScaleY + int asc; // ascender + int desc; // descender ASS_Outline outline; // target outline - FT_Vector advance; // advance (from cbox) - int hash; // hash value (for caching) + ASS_Vector advance; // advance (from cbox) + int hash; // hash value (for caching) // private ASS_Library *library; ASS_DrawingToken *tokens; // tokenized drawing double point_scale_x; double point_scale_y; - FT_BBox cbox; // bounding box, or let's say... VSFilter's idea of it + ASS_Rect cbox; // bounding box, or let's say... VSFilter's idea of it } ASS_Drawing; -ASS_Drawing *ass_drawing_new(ASS_Library *lib, FT_Library ftlib); -void ass_drawing_free(ASS_Drawing* drawing); -void ass_drawing_set_text(ASS_Drawing* drawing, char *str, size_t n); -void ass_drawing_hash(ASS_Drawing* drawing); -ASS_Outline *ass_drawing_parse(ASS_Drawing *drawing, int raw_mode); +ASS_Drawing *ass_drawing_new(ASS_Library *lib); +void ass_drawing_free(ASS_Drawing *drawing); +void ass_drawing_set_text(ASS_Drawing *drawing, char *str, size_t n); +void ass_drawing_hash(ASS_Drawing *drawing); +ASS_Outline *ass_drawing_parse(ASS_Drawing *drawing, bool raw_mode); #endif /* LIBASS_DRAWING_H */ diff --git a/libass/ass_outline.c b/libass/ass_outline.c index 8abc29f..a1dfa1e 100644 --- a/libass/ass_outline.c +++ b/libass/ass_outline.c @@ -27,7 +27,7 @@ bool outline_alloc(ASS_Outline *outline, size_t n_points, size_t n_contours) { outline->contours = malloc(sizeof(size_t) * n_contours); - outline->points = malloc(sizeof(FT_Vector) * n_points); + outline->points = malloc(sizeof(ASS_Vector) * n_points); outline->tags = malloc(n_points); if (!outline->contours || !outline->points || !outline->tags) { outline_free(outline); @@ -65,7 +65,10 @@ bool outline_convert(ASS_Outline *outline, const FT_Outline *source) size_t n = source->contours[i] - start + 1; // skip degenerate 2-point contours from broken fonts if (n >= 3) { - memcpy(outline->points + outline->n_points, source->points + start, sizeof(FT_Vector) * n); + for (size_t k = 0; k < n; k++) { + outline->points[outline->n_points + k].x = source->points[start + k].x; + outline->points[outline->n_points + k].y = source->points[start + k].y; + } memcpy(outline->tags + outline->n_points, source->tags + start, n); outline->n_points += n; @@ -87,7 +90,7 @@ bool outline_copy(ASS_Outline *outline, const ASS_Outline *source) return false; memcpy(outline->contours, source->contours, sizeof(size_t) * source->n_contours); - memcpy(outline->points, source->points, sizeof(FT_Vector) * source->n_points); + memcpy(outline->points, source->points, sizeof(ASS_Vector) * source->n_points); memcpy(outline->tags, source->tags, source->n_points); outline->n_contours = source->n_contours; outline->n_points = source->n_points; @@ -110,7 +113,7 @@ void outline_free(ASS_Outline *outline) /* * \brief Add a single point to a contour. */ -bool outline_add_point(ASS_Outline *outline, FT_Vector pt, char tag) +bool outline_add_point(ASS_Outline *outline, ASS_Vector pt, char tag) { if (outline->n_points >= outline->max_points) { size_t new_size = 2 * outline->max_points; @@ -143,7 +146,7 @@ bool outline_close_contour(ASS_Outline *outline) } -void outline_translate(const ASS_Outline *outline, FT_Pos dx, FT_Pos dy) +void outline_translate(const ASS_Outline *outline, int32_t dx, int32_t dy) { for (size_t i = 0; i < outline->n_points; i++) { outline->points[i].x += dx; @@ -154,42 +157,29 @@ void outline_translate(const ASS_Outline *outline, FT_Pos dx, FT_Pos dy) void outline_transform(const ASS_Outline *outline, const FT_Matrix *matrix) { for (size_t i = 0; i < outline->n_points; i++) { - FT_Pos x = FT_MulFix(outline->points[i].x, matrix->xx) + - FT_MulFix(outline->points[i].y, matrix->xy); - FT_Pos y = FT_MulFix(outline->points[i].x, matrix->yx) + - FT_MulFix(outline->points[i].y, matrix->yy); + int32_t x = FT_MulFix(outline->points[i].x, matrix->xx) + + FT_MulFix(outline->points[i].y, matrix->xy); + int32_t y = FT_MulFix(outline->points[i].x, matrix->yx) + + FT_MulFix(outline->points[i].y, matrix->yy); outline->points[i].x = x; outline->points[i].y = y; } } -void outline_update_cbox(const ASS_Outline *outline, FT_BBox *cbox) -{ - if (!outline) - return; - - for (size_t i = 0; i < outline->n_points; i++) { - cbox->xMin = FFMIN(cbox->xMin, outline->points[i].x); - cbox->xMax = FFMAX(cbox->xMax, outline->points[i].x); - cbox->yMin = FFMIN(cbox->yMin, outline->points[i].y); - cbox->yMax = FFMAX(cbox->yMax, outline->points[i].y); - } -} - -void outline_get_cbox(const ASS_Outline *outline, FT_BBox *cbox) +void outline_get_cbox(const ASS_Outline *outline, ASS_Rect *cbox) { if (!outline->n_points) { - cbox->xMin = cbox->xMax = 0; - cbox->yMin = cbox->yMax = 0; + cbox->x_min = cbox->x_max = 0; + cbox->y_min = cbox->y_max = 0; return; } - cbox->xMin = cbox->xMax = outline->points[0].x; - cbox->yMin = cbox->yMax = outline->points[0].y; + cbox->x_min = cbox->x_max = outline->points[0].x; + cbox->y_min = cbox->y_max = outline->points[0].y; for (size_t i = 1; i < outline->n_points; i++) { - cbox->xMin = FFMIN(cbox->xMin, outline->points[i].x); - cbox->xMax = FFMAX(cbox->xMax, outline->points[i].x); - cbox->yMin = FFMIN(cbox->yMin, outline->points[i].y); - cbox->yMax = FFMAX(cbox->yMax, outline->points[i].y); + cbox->x_min = FFMIN(cbox->x_min, outline->points[i].x); + cbox->x_max = FFMAX(cbox->x_max, outline->points[i].x); + cbox->y_min = FFMIN(cbox->y_min, outline->points[i].y); + cbox->y_max = FFMAX(cbox->y_max, outline->points[i].y); } } @@ -245,15 +235,7 @@ void outline_get_cbox(const ASS_Outline *outline, FT_BBox *cbox) typedef struct { - int32_t x, y; -} OutlinePoint; - -typedef struct { - double x, y; -} Vector; - -typedef struct { - Vector v; + ASS_DVector v; double len; } Normal; @@ -268,9 +250,9 @@ typedef struct { // skip flags for first and last point int first_skip, last_skip; // normal at first and last point - Vector first_normal, last_normal; + ASS_DVector first_normal, last_normal; // first and last point of current contour - OutlinePoint first_point, last_point; + ASS_Vector first_point, last_point; // cosinus of maximal angle that do not require cap double merge_cos; @@ -289,7 +271,7 @@ typedef struct { /** * \brief 2D vector dot product */ -static inline double vec_dot(Vector vec1, Vector vec2) +static inline double vec_dot(ASS_DVector vec1, ASS_DVector vec2) { return vec1.x * vec2.x + vec1.y * vec2.y; } @@ -297,7 +279,7 @@ static inline double vec_dot(Vector vec1, Vector vec2) /** * \brief 2D vector cross product */ -static inline double vec_crs(Vector vec1, Vector vec2) +static inline double vec_crs(ASS_DVector vec1, ASS_DVector vec2) { return vec1.x * vec2.y - vec1.y * vec2.x; } @@ -305,7 +287,7 @@ static inline double vec_crs(Vector vec1, Vector vec2) /** * \brief 2D vector length */ -static inline double vec_len(Vector vec) +static inline double vec_len(ASS_DVector vec) { return sqrt(vec.x * vec.x + vec.y * vec.y); } @@ -320,20 +302,20 @@ static inline double vec_len(Vector vec) * \param dir destination outline flags * \return false on allocation failure */ -static bool emit_point(StrokerState *str, OutlinePoint pt, - Vector offs, char tag, int dir) +static bool emit_point(StrokerState *str, ASS_Vector pt, + ASS_DVector offs, char tag, int dir) { int32_t dx = (int32_t) (str->xbord * offs.x); int32_t dy = (int32_t) (str->ybord * offs.y); if (dir & 1) { - FT_Vector res = { pt.x + dx, pt.y + dy }; + ASS_Vector res = { pt.x + dx, pt.y + dy }; res.y = -res.y; if (!outline_add_point(str->result[0], res, tag)) return false; } if (dir & 2) { - FT_Vector res = { pt.x - dx, pt.y - dy }; + ASS_Vector res = { pt.x - dx, pt.y - dy }; res.y = -res.y; if (!outline_add_point(str->result[1], res, tag)) return false; @@ -348,14 +330,14 @@ static bool emit_point(StrokerState *str, OutlinePoint pt, * \param offs offset in normal space * \param dir destination outline flags */ -static void fix_first_point(StrokerState *str, OutlinePoint pt, - Vector offs, int dir) +static void fix_first_point(StrokerState *str, ASS_Vector pt, + ASS_DVector offs, int dir) { int32_t dx = (int32_t) (str->xbord * offs.x); int32_t dy = (int32_t) (str->ybord * offs.y); if (dir & 1) { - FT_Vector res = { pt.x + dx, pt.y + dy }; + ASS_Vector res = { pt.x + dx, pt.y + dy }; res.y = -res.y; ASS_Outline *ol = str->result[0]; size_t first = ol->n_contours ? @@ -363,7 +345,7 @@ static void fix_first_point(StrokerState *str, OutlinePoint pt, ol->points[first] = res; } if (dir & 2) { - FT_Vector res = { pt.x - dx, pt.y - dy }; + ASS_Vector res = { pt.x - dx, pt.y - dy }; res.y = -res.y; ASS_Outline *ol = str->result[1]; size_t first = ol->n_contours ? @@ -383,11 +365,11 @@ static void fix_first_point(StrokerState *str, OutlinePoint pt, * \param dir destination outline flags * \return false on allocation failure */ -static bool process_arc(StrokerState *str, OutlinePoint pt, - Vector normal0, Vector normal1, +static bool process_arc(StrokerState *str, ASS_Vector pt, + ASS_DVector normal0, ASS_DVector normal1, const double *mul, int level, int dir) { - Vector center; + ASS_DVector center; center.x = (normal0.x + normal1.x) * mul[level]; center.y = (normal0.y + normal1.y) * mul[level]; if (level) @@ -407,13 +389,13 @@ static bool process_arc(StrokerState *str, OutlinePoint pt, * \param dir destination outline flags * \return false on allocation failure */ -static bool draw_arc(StrokerState *str, OutlinePoint pt, - Vector normal0, Vector normal1, double c, int dir) +static bool draw_arc(StrokerState *str, ASS_Vector pt, + ASS_DVector normal0, ASS_DVector normal1, double c, int dir) { const int max_subdiv = 15; double mul[max_subdiv + 1]; - Vector center; + ASS_DVector center; bool small_angle = true; if (c < 0) { double mul = dir & 2 ? -sqrt(0.5) : sqrt(0.5); @@ -444,7 +426,7 @@ static bool draw_arc(StrokerState *str, OutlinePoint pt, * \param dir destination outline flags * \return false on allocation failure */ -static bool draw_circle(StrokerState *str, OutlinePoint pt, int dir) +static bool draw_circle(StrokerState *str, ASS_Vector pt, int dir) { const int max_subdiv = 15; double mul[max_subdiv + 1], c = 0; @@ -457,7 +439,7 @@ static bool draw_circle(StrokerState *str, OutlinePoint pt, int dir) } mul[pos] = 1 / (1 + c); - Vector normal[4] = { + ASS_DVector normal[4] = { { 1, 0 }, { 0, 1 }, { -1, 0 }, { 0, -1 } }; return process_arc(str, pt, normal[0], normal[1], mul + pos, max_subdiv - pos, dir) && @@ -474,8 +456,8 @@ static bool draw_circle(StrokerState *str, OutlinePoint pt, int dir) * \param dir destination outline flags * \return false on allocation failure */ -static bool start_segment(StrokerState *str, OutlinePoint pt, - Vector normal, int dir) +static bool start_segment(StrokerState *str, ASS_Vector pt, + ASS_DVector normal, int dir) { if (str->contour_start) { str->contour_start = false; @@ -485,7 +467,7 @@ static bool start_segment(StrokerState *str, OutlinePoint pt, return true; } - Vector prev = str->last_normal; + ASS_DVector prev = str->last_normal; double c = vec_dot(prev, normal); if (c > str->merge_cos) { // merge without cap double mul = 1 / (1 + c); @@ -501,7 +483,7 @@ static bool start_segment(StrokerState *str, OutlinePoint pt, if (dir & skip_dir) { if (!emit_point(str, pt, prev, FT_CURVE_TAG_ON, ~str->last_skip & skip_dir)) return false; - Vector zero_normal = {0, 0}; + ASS_DVector zero_normal = {0, 0}; if (!emit_point(str, pt, zero_normal, FT_CURVE_TAG_ON, skip_dir)) return false; } @@ -514,7 +496,7 @@ static bool start_segment(StrokerState *str, OutlinePoint pt, /** * \brief Same as emit_point() but also updates skip flags */ -static bool emit_first_point(StrokerState *str, OutlinePoint pt, int dir) +static bool emit_first_point(StrokerState *str, ASS_Vector pt, int dir) { str->last_skip &= ~dir; return emit_point(str, pt, str->last_normal, FT_CURVE_TAG_ON, dir); @@ -528,7 +510,7 @@ static bool emit_first_point(StrokerState *str, OutlinePoint pt, int dir) * \param first true if the skipped part is at start of the segment * \return false on allocation failure */ -static bool prepare_skip(StrokerState *str, OutlinePoint pt, int dir, bool first) +static bool prepare_skip(StrokerState *str, ASS_Vector pt, int dir, bool first) { if (first) str->first_skip |= dir; @@ -545,16 +527,16 @@ static bool prepare_skip(StrokerState *str, OutlinePoint pt, int dir, bool first * \param dir destination outline flags * \return false on allocation failure */ -static bool add_line(StrokerState *str, OutlinePoint pt, int dir) +static bool add_line(StrokerState *str, ASS_Vector pt, int dir) { int32_t dx = pt.x - str->last_point.x; int32_t dy = pt.y - str->last_point.y; if (dx > -str->eps && dx < str->eps && dy > -str->eps && dy < str->eps) return true; - Vector deriv = { dy * str->yscale, -dx * str->xscale }; + ASS_DVector deriv = { dy * str->yscale, -dx * str->xscale }; double scale = 1 / vec_len(deriv); - Vector normal = { deriv.x * scale, deriv.y * scale }; + ASS_DVector normal = { deriv.x * scale, deriv.y * scale }; if (!start_segment(str, str->last_point, normal, dir)) return false; if (!emit_first_point(str, str->last_point, dir)) @@ -575,7 +557,7 @@ static bool add_line(StrokerState *str, OutlinePoint pt, int dir) * \return false if error is too large */ static bool estimate_quadratic_error(StrokerState *str, double c, double s, - const Normal *normal, Vector *result) + const Normal *normal, ASS_DVector *result) { // check radial error if (!((3 + c) * (3 + c) < str->err_q * (1 + c))) @@ -604,8 +586,8 @@ static bool estimate_quadratic_error(StrokerState *str, double c, double s, * \param first true if the current part is at start of the segment * \return false on allocation failure */ -static bool process_quadratic(StrokerState *str, const OutlinePoint *pt, - const Vector *deriv, const Normal *normal, +static bool process_quadratic(StrokerState *str, const ASS_Vector *pt, + const ASS_DVector *deriv, const Normal *normal, int dir, bool first) { double c = vec_dot(normal[0].v, normal[1].v); @@ -624,13 +606,13 @@ static bool process_quadratic(StrokerState *str, const OutlinePoint *pt, if (!prepare_skip(str, pt[0], skip_dir, first)) return false; if (f0 < 0 || f1 < 0) { - Vector zero_normal = {0, 0}; + ASS_DVector zero_normal = {0, 0}; if (!emit_point(str, pt[0], zero_normal, FT_CURVE_TAG_ON, skip_dir) || !emit_point(str, pt[2], zero_normal, FT_CURVE_TAG_ON, skip_dir)) return false; } else { double mul = f0 / abs_s; - Vector offs = { normal[0].v.x * mul, normal[0].v.y * mul }; + ASS_DVector offs = { normal[0].v.x * mul, normal[0].v.y * mul }; if (!emit_point(str, pt[0], offs, FT_CURVE_TAG_ON, skip_dir)) return false; } @@ -645,7 +627,7 @@ static bool process_quadratic(StrokerState *str, const OutlinePoint *pt, check_dir ^= skip_dir; } - Vector result; + ASS_DVector result; if (check_dir && estimate_quadratic_error(str, c, s, normal, &result)) { if (!emit_first_point(str, pt[0], check_dir)) return false; @@ -658,7 +640,7 @@ static bool process_quadratic(StrokerState *str, const OutlinePoint *pt, } } - OutlinePoint next[5]; + ASS_Vector next[5]; next[1].x = pt[0].x + pt[1].x; next[1].y = pt[0].y + pt[1].y; next[3].x = pt[1].x + pt[2].x; @@ -672,7 +654,7 @@ static bool process_quadratic(StrokerState *str, const OutlinePoint *pt, next[0] = pt[0]; next[4] = pt[2]; - Vector next_deriv[3]; + ASS_DVector next_deriv[3]; next_deriv[0].x = deriv[0].x / 2; next_deriv[0].y = deriv[0].y / 2; next_deriv[2].x = deriv[1].x / 2; @@ -707,7 +689,7 @@ static bool process_quadratic(StrokerState *str, const OutlinePoint *pt, * \param dir destination outline flags * \return false on allocation failure */ -static bool add_quadratic(StrokerState *str, const OutlinePoint *pt, int dir) +static bool add_quadratic(StrokerState *str, const ASS_Vector *pt, int dir) { int32_t dx0 = pt[1].x - pt[0].x; int32_t dy0 = pt[1].y - pt[0].y; @@ -719,7 +701,7 @@ static bool add_quadratic(StrokerState *str, const OutlinePoint *pt, int dir) if (dx1 > -str->eps && dx1 < str->eps && dy1 > -str->eps && dy1 < str->eps) return add_line(str, pt[2], dir); - Vector deriv[2] = { + ASS_DVector deriv[2] = { { dy0 * str->yscale, -dx0 * str->xscale }, { dy1 * str->yscale, -dx1 * str->xscale } }; @@ -770,7 +752,7 @@ enum { */ static int estimate_cubic_error(StrokerState *str, double c, double s, const double *dc, const double *ds, - const Normal *normal, Vector *result, + const Normal *normal, ASS_DVector *result, int check_flags, int dir) { double t = (ds[0] + ds[1]) / (dc[0] + dc[1]), c1 = 1 + c, ss = s * s; @@ -871,8 +853,8 @@ static int estimate_cubic_error(StrokerState *str, double c, double s, * \param first true if the current part is at start of the segment * \return false on allocation failure */ -static bool process_cubic(StrokerState *str, const OutlinePoint *pt, - const Vector *deriv, const Normal *normal, +static bool process_cubic(StrokerState *str, const ASS_Vector *pt, + const ASS_DVector *deriv, const Normal *normal, int dir, bool first) { double c = vec_dot(normal[0].v, normal[1].v); @@ -910,13 +892,13 @@ static bool process_cubic(StrokerState *str, const OutlinePoint *pt, if (!prepare_skip(str, pt[0], skip_dir, first)) return false; if (f0 < 0 || f1 < 0) { - Vector zero_normal = {0, 0}; + ASS_DVector zero_normal = {0, 0}; if (!emit_point(str, pt[0], zero_normal, FT_CURVE_TAG_ON, skip_dir) || !emit_point(str, pt[3], zero_normal, FT_CURVE_TAG_ON, skip_dir)) return false; } else { double mul = f0 / abs_s; - Vector offs = { normal[0].v.x * mul, normal[0].v.y * mul }; + ASS_DVector offs = { normal[0].v.x * mul, normal[0].v.y * mul }; if (!emit_point(str, pt[0], offs, FT_CURVE_TAG_ON, skip_dir)) return false; |