]> granicus.if.org Git - libass/commitdiff
outline: rearrange allocations
authorDr.Smile <vabnick@gmail.com>
Sun, 19 May 2019 22:09:08 +0000 (01:09 +0300)
committerDr.Smile <vabnick@gmail.com>
Sun, 19 May 2019 22:09:08 +0000 (01:09 +0300)
libass/ass_drawing.c
libass/ass_outline.c
libass/ass_render.c

index fb71e151bf3c144b4f20e32fd519eb099ae825f6..1af250d1b28493309f7ef6e533b26a88ffbe29b6 100644 (file)
@@ -181,7 +181,6 @@ bool ass_drawing_parse(ASS_Outline *outline, ASS_Rect *cbox,
 {
     if (!outline_alloc(outline, DRAWING_INITIAL_POINTS, DRAWING_INITIAL_SEGMENTS))
         return false;
-    outline->n_points = outline->n_segments = 0;
     rectangle_reset(cbox);
 
     ASS_DrawingToken *tokens = drawing_tokenize(text);
index fd7e4ed70093b6ecb397aa746eb395cb5b28770a..26bd4244c5f1b43ab028beec06b6d61199616495 100644 (file)
@@ -35,6 +35,7 @@ bool outline_alloc(ASS_Outline *outline, size_t n_points, size_t n_segments)
 
     outline->max_points = n_points;
     outline->max_segments = n_segments;
+    outline->n_points = outline->n_segments = 0;
     return true;
 }
 
@@ -61,7 +62,6 @@ bool outline_convert(ASS_Outline *outline, const FT_Outline *source)
         S_ON, S_Q, S_C1, S_C2
     };
 
-    outline->n_points = outline->n_segments = 0;
     for (size_t i = 0, j = 0; i < source->n_contours; i++) {
         ASS_Vector pt;
         bool skip_last = false;
@@ -1344,13 +1344,15 @@ static bool close_contour(StrokerState *str, int dir)
 bool outline_stroke(ASS_Outline *result, ASS_Outline *result1,
                     const ASS_Outline *path, int xbord, int ybord, int eps)
 {
+    outline_alloc(result,  2 * path->n_points, 2 * path->n_segments);
+    outline_alloc(result1, 2 * path->n_points, 2 * path->n_segments);
+    if (!result->max_points || !result1->max_points)
+        return false;
+
     const int dir = 3;
     int rad = FFMAX(xbord, ybord);
     assert(rad >= eps);
 
-    result->n_points = result->n_segments = 0;
-    result1->n_points = result1->n_segments = 0;
-
     StrokerState str;
     str.result[0] = result;
     str.result[1] = result1;
index eb0a407818843ca7e073b9e0823d21f79cef2390..fc66569b958aa45e11bb2e21e9c8372c0a1d0602 100644 (file)
@@ -1190,14 +1190,10 @@ size_t ass_outline_construct(void *key, void *value, void *priv)
             if (!outline_scale_pow2(&src, &k->outline->outline[0],
                                     k->scale_ord_x, k->scale_ord_y))
                 return 1;
-
-            outline_alloc(&v->outline[0], 2 * src.n_points, 2 * src.n_segments);
-            outline_alloc(&v->outline[1], 2 * src.n_points, 2 * src.n_segments);
-            if (!v->outline[0].max_points || !v->outline[1].max_points ||
-                    !outline_stroke(&v->outline[0], &v->outline[1], &src,
-                                    k->border.x * STROKER_PRECISION,
-                                    k->border.y * STROKER_PRECISION,
-                                    STROKER_PRECISION)) {
+            if (!outline_stroke(&v->outline[0], &v->outline[1], &src,
+                                k->border.x * STROKER_PRECISION,
+                                k->border.y * STROKER_PRECISION,
+                                STROKER_PRECISION)) {
                 ass_msg(render_priv->library, MSGL_WARN, "Cannot stroke outline");
                 outline_free(&v->outline[0]);
                 outline_free(&v->outline[1]);