summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorOneric <oneric@oneric.stub>2022-10-21 00:29:19 +0200
committerOneric <oneric@oneric.stub>2022-10-22 03:42:27 +0200
commitf6e1987c08e25d88b6dfa12dafaffc42f5499011 (patch)
tree39f9a80b0da5ffec6b9b99dba3dc93e23bfd6cab
parent536f6dddd901f7ce9562ce39c83b4fb8775c0bf2 (diff)
downloadlibass-f6e1987c08e25d88b6dfa12dafaffc42f5499011.tar.bz2
libass-f6e1987c08e25d88b6dfa12dafaffc42f5499011.tar.xz
refactor: move and static'fy some internal functions
Although declared and defined in ass_utils.{h,c}, those functions are only used in one other file and aren't useful at other places.
-rw-r--r--libass/ass.c127
-rw-r--r--libass/ass_bitmap.c27
-rw-r--r--libass/ass_bitmap.h1
-rw-r--r--libass/ass_parse.c44
-rw-r--r--libass/ass_render.c28
-rw-r--r--libass/ass_utils.c174
-rw-r--r--libass/ass_utils.h7
7 files changed, 200 insertions, 208 deletions
diff --git a/libass/ass.c b/libass/ass.c
index ef3b471..08cbf16 100644
--- a/libass/ass.c
+++ b/libass/ass.c
@@ -239,6 +239,133 @@ static long long string2timecode(ASS_Library *library, char *p)
return tm;
}
+static int read_digits(char **str, unsigned base, uint32_t *res)
+{
+ char *p = *str;
+ char *start = p;
+ uint32_t val = 0;
+
+ while (1) {
+ unsigned digit;
+ if (*p >= '0' && *p < FFMIN(base, 10) + '0')
+ digit = *p - '0';
+ else if (*p >= 'a' && *p < base - 10 + 'a')
+ digit = *p - 'a' + 10;
+ else if (*p >= 'A' && *p < base - 10 + 'A')
+ digit = *p - 'A' + 10;
+ else
+ break;
+ val = val * base + digit;
+ ++p;
+ }
+
+ *res = val;
+ *str = p;
+ return p != start;
+}
+
+/**
+ * \brief Convert a string to an integer reduced modulo 2**32
+ * Follows the rules for strtoul but reduces the number modulo 2**32
+ * instead of saturating it to 2**32 - 1.
+ */
+static int mystrtou32_modulo(char **p, unsigned base, uint32_t *res)
+{
+ // This emulates scanf with %d or %x format as it works on
+ // Windows, because that's what is used by VSFilter. In practice,
+ // scanf works the same way on other platforms too, but
+ // the standard leaves its behavior on overflow undefined.
+
+ // Unlike scanf and like strtoul, produce 0 for invalid inputs.
+
+ char *start = *p;
+ int sign = 1;
+
+ skip_spaces(p);
+
+ if (**p == '+')
+ ++*p;
+ else if (**p == '-')
+ sign = -1, ++*p;
+
+ if (base == 16 && !ass_strncasecmp(*p, "0x", 2))
+ *p += 2;
+
+ if (read_digits(p, base, res)) {
+ *res *= sign;
+ return 1;
+ } else {
+ *p = start;
+ return 0;
+ }
+}
+
+static int32_t parse_int_header(char *str)
+{
+ uint32_t val = 0;
+ unsigned base;
+
+ if (!ass_strncasecmp(str, "&h", 2) || !ass_strncasecmp(str, "0x", 2)) {
+ str += 2;
+ base = 16;
+ } else
+ base = 10;
+
+ mystrtou32_modulo(&str, base, &val);
+ return val;
+}
+
+static uint32_t parse_color_header(char *str)
+{
+ uint32_t color = parse_int_header(str);
+ return ass_bswap32(color);
+}
+
+// Return a boolean value for a string
+static char parse_bool(char *str)
+{
+ skip_spaces(&str);
+ return !ass_strncasecmp(str, "yes", 3) || strtol(str, NULL, 10) > 0;
+}
+
+static int parse_ycbcr_matrix(char *str)
+{
+ skip_spaces(&str);
+ if (*str == '\0')
+ return YCBCR_DEFAULT;
+
+ char *end = str + strlen(str);
+ rskip_spaces(&end, str);
+
+ // Trim a local copy of the input that we know is safe to
+ // modify. The buffer is larger than any valid string + NUL,
+ // so we can simply chop off the rest of the input.
+ char buffer[16];
+ size_t n = FFMIN(end - str, sizeof buffer - 1);
+ memcpy(buffer, str, n);
+ buffer[n] = '\0';
+
+ if (!ass_strcasecmp(buffer, "none"))
+ return YCBCR_NONE;
+ if (!ass_strcasecmp(buffer, "tv.601"))
+ return YCBCR_BT601_TV;
+ if (!ass_strcasecmp(buffer, "pc.601"))
+ return YCBCR_BT601_PC;
+ if (!ass_strcasecmp(buffer, "tv.709"))
+ return YCBCR_BT709_TV;
+ if (!ass_strcasecmp(buffer, "pc.709"))
+ return YCBCR_BT709_PC;
+ if (!ass_strcasecmp(buffer, "tv.240m"))
+ return YCBCR_SMPTE240M_TV;
+ if (!ass_strcasecmp(buffer, "pc.240m"))
+ return YCBCR_SMPTE240M_PC;
+ if (!ass_strcasecmp(buffer, "tv.fcc"))
+ return YCBCR_FCC_TV;
+ if (!ass_strcasecmp(buffer, "pc.fcc"))
+ return YCBCR_FCC_PC;
+ return YCBCR_UNKNOWN;
+}
+
#define NEXT(str,token) \
token = next_token(&str); \
if (!token) break;
diff --git a/libass/ass_bitmap.c b/libass/ass_bitmap.c
index 191eeaa..805f549 100644
--- a/libass/ass_bitmap.c
+++ b/libass/ass_bitmap.c
@@ -347,33 +347,6 @@ void ass_be_blur_c(uint8_t *buf, intptr_t stride,
}
}
-/*
- * To find these values, simulate blur on the border between two
- * half-planes, one zero-filled (background) and the other filled
- * with the maximum supported value (foreground). Keep incrementing
- * the \be argument. The necessary padding is the distance by which
- * the blurred foreground image extends beyond the original border
- * and into the background. Initially it increases along with \be,
- * but very soon it grinds to a halt. At some point, the blurred
- * image actually reaches a stationary point and stays unchanged
- * forever after, simply _shifting_ by one pixel for each \be
- * step--moving in the direction of the non-zero half-plane and
- * thus decreasing the necessary padding (although the large
- * padding is still needed for intermediate results). In practice,
- * images are finite rather than infinite like half-planes, but
- * this can only decrease the required padding. Half-planes filled
- * with extreme values are the theoretical limit of the worst case.
- * Make sure to use the right pixel value range in the simulation!
- */
-int be_padding(int be)
-{
- if (be <= 3)
- return be;
- if (be <= 7)
- return 4;
- return 5;
-}
-
/**
* \brief Add two bitmaps together at a given position
* Uses additive blending, clipped to [0,255]. Pure C implementation.
diff --git a/libass/ass_bitmap.h b/libass/ass_bitmap.h
index 37da2bc..3909b59 100644
--- a/libass/ass_bitmap.h
+++ b/libass/ass_bitmap.h
@@ -108,7 +108,6 @@ bool outline_to_bitmap(ASS_Renderer *render_priv, Bitmap *bm,
void ass_synth_blur(const BitmapEngine *engine, Bitmap *bm,
int be, double blur_r2);
-int be_padding(int be);
bool ass_gaussian_blur(const BitmapEngine *engine, Bitmap *bm, double r2);
void shift_bitmap(Bitmap *bm, int shift_x, int shift_y);
void fix_outline(Bitmap *bm_g, Bitmap *bm_o);
diff --git a/libass/ass_parse.c b/libass/ass_parse.c
index b7ff24b..db25879 100644
--- a/libass/ass_parse.c
+++ b/libass/ass_parse.c
@@ -222,6 +222,50 @@ static bool parse_vector_clip(ASS_Renderer *render_priv,
return true;
}
+static int32_t parse_alpha_tag(char *str)
+{
+ int32_t alpha = 0;
+
+ while (*str == '&' || *str == 'H')
+ ++str;
+
+ mystrtoi32(&str, 16, &alpha);
+ return alpha;
+}
+
+static uint32_t parse_color_tag(char *str)
+{
+ int32_t color = 0;
+
+ while (*str == '&' || *str == 'H')
+ ++str;
+
+ mystrtoi32(&str, 16, &color);
+ return ass_bswap32((uint32_t) color);
+}
+
+/**
+ * \brief find style by name as in \r
+ * \param track track
+ * \param name style name
+ * \param len style name length
+ * \return style in track->styles
+ * Returns NULL if no style has the given name.
+ */
+static ASS_Style *lookup_style_strict(ASS_Track *track, char *name, size_t len)
+{
+ int i;
+ for (i = track->n_styles - 1; i >= 0; --i) {
+ if (strncmp(track->styles[i].Name, name, len) == 0 &&
+ track->styles[i].Name[len] == '\0')
+ return track->styles + i;
+ }
+ ass_msg(track->library, MSGL_WARN,
+ "[%p]: Warning: no style named '%.*s' found",
+ track, (int) len, name);
+ return NULL;
+}
+
/**
* \brief Parse style override tags.
* \param p string to parse
diff --git a/libass/ass_render.c b/libass/ass_render.c
index 4f3f20d..dedd2a7 100644
--- a/libass/ass_render.c
+++ b/libass/ass_render.c
@@ -2598,6 +2598,34 @@ static inline void rectangle_combine(ASS_Rect *rect, const Bitmap *bm, ASS_Vecto
rectangle_update(rect, pos.x, pos.y, pos.x + bm->w, pos.y + bm->h);
}
+/*
+ * To find these values, simulate blur on the border between two
+ * half-planes, one zero-filled (background) and the other filled
+ * with the maximum supported value (foreground). Keep incrementing
+ * the \be argument. The necessary padding is the distance by which
+ * the blurred foreground image extends beyond the original border
+ * and into the background. Initially it increases along with \be,
+ * but very soon it grinds to a halt. At some point, the blurred
+ * image actually reaches a stationary point and stays unchanged
+ * forever after, simply _shifting_ by one pixel for each \be
+ * step--moving in the direction of the non-zero half-plane and
+ * thus decreasing the necessary padding (although the large
+ * padding is still needed for intermediate results). In practice,
+ * images are finite rather than infinite like half-planes, but
+ * this can only decrease the required padding. Half-planes filled
+ * with extreme values are the theoretical limit of the worst case.
+ * Make sure to use the right pixel value range in the simulation!
+ */
+int be_padding(int be)
+{
+ if (be <= 3)
+ return be;
+ if (be <= 7)
+ return 4;
+ return 5;
+}
+
+
size_t ass_composite_construct(void *key, void *value, void *priv)
{
ASS_Renderer *render_priv = priv;
diff --git a/libass/ass_utils.c b/libass/ass_utils.c
index af44704..11864b2 100644
--- a/libass/ass_utils.c
+++ b/libass/ass_utils.c
@@ -173,155 +173,6 @@ void rskip_spaces(char **str, char *limit)
*str = p;
}
-static int read_digits(char **str, unsigned base, uint32_t *res)
-{
- char *p = *str;
- char *start = p;
- uint32_t val = 0;
-
- while (1) {
- unsigned digit;
- if (*p >= '0' && *p < FFMIN(base, 10) + '0')
- digit = *p - '0';
- else if (*p >= 'a' && *p < base - 10 + 'a')
- digit = *p - 'a' + 10;
- else if (*p >= 'A' && *p < base - 10 + 'A')
- digit = *p - 'A' + 10;
- else
- break;
- val = val * base + digit;
- ++p;
- }
-
- *res = val;
- *str = p;
- return p != start;
-}
-
-/**
- * \brief Convert a string to an integer reduced modulo 2**32
- * Follows the rules for strtoul but reduces the number modulo 2**32
- * instead of saturating it to 2**32 - 1.
- */
-static int mystrtou32_modulo(char **p, unsigned base, uint32_t *res)
-{
- // This emulates scanf with %d or %x format as it works on
- // Windows, because that's what is used by VSFilter. In practice,
- // scanf works the same way on other platforms too, but
- // the standard leaves its behavior on overflow undefined.
-
- // Unlike scanf and like strtoul, produce 0 for invalid inputs.
-
- char *start = *p;
- int sign = 1;
-
- skip_spaces(p);
-
- if (**p == '+')
- ++*p;
- else if (**p == '-')
- sign = -1, ++*p;
-
- if (base == 16 && !ass_strncasecmp(*p, "0x", 2))
- *p += 2;
-
- if (read_digits(p, base, res)) {
- *res *= sign;
- return 1;
- } else {
- *p = start;
- return 0;
- }
-}
-
-int32_t parse_alpha_tag(char *str)
-{
- int32_t alpha = 0;
-
- while (*str == '&' || *str == 'H')
- ++str;
-
- mystrtoi32(&str, 16, &alpha);
- return alpha;
-}
-
-uint32_t parse_color_tag(char *str)
-{
- int32_t color = 0;
-
- while (*str == '&' || *str == 'H')
- ++str;
-
- mystrtoi32(&str, 16, &color);
- return ass_bswap32((uint32_t) color);
-}
-
-int32_t parse_int_header(char *str)
-{
- uint32_t val = 0;
- unsigned base;
-
- if (!ass_strncasecmp(str, "&h", 2) || !ass_strncasecmp(str, "0x", 2)) {
- str += 2;
- base = 16;
- } else
- base = 10;
-
- mystrtou32_modulo(&str, base, &val);
- return val;
-}
-
-uint32_t parse_color_header(char *str)
-{
- uint32_t color = parse_int_header(str);
- return ass_bswap32(color);
-}
-
-// Return a boolean value for a string
-char parse_bool(char *str)
-{
- skip_spaces(&str);
- return !ass_strncasecmp(str, "yes", 3) || strtol(str, NULL, 10) > 0;
-}
-
-int parse_ycbcr_matrix(char *str)
-{
- skip_spaces(&str);
- if (*str == '\0')
- return YCBCR_DEFAULT;
-
- char *end = str + strlen(str);
- rskip_spaces(&end, str);
-
- // Trim a local copy of the input that we know is safe to
- // modify. The buffer is larger than any valid string + NUL,
- // so we can simply chop off the rest of the input.
- char buffer[16];
- size_t n = FFMIN(end - str, sizeof buffer - 1);
- memcpy(buffer, str, n);
- buffer[n] = '\0';
-
- if (!ass_strcasecmp(buffer, "none"))
- return YCBCR_NONE;
- if (!ass_strcasecmp(buffer, "tv.601"))
- return YCBCR_BT601_TV;
- if (!ass_strcasecmp(buffer, "pc.601"))
- return YCBCR_BT601_PC;
- if (!ass_strcasecmp(buffer, "tv.709"))
- return YCBCR_BT709_TV;
- if (!ass_strcasecmp(buffer, "pc.709"))
- return YCBCR_BT709_PC;
- if (!ass_strcasecmp(buffer, "tv.240m"))
- return YCBCR_SMPTE240M_TV;
- if (!ass_strcasecmp(buffer, "pc.240m"))
- return YCBCR_SMPTE240M_PC;
- if (!ass_strcasecmp(buffer, "tv.fcc"))
- return YCBCR_FCC_TV;
- if (!ass_strcasecmp(buffer, "pc.fcc"))
- return YCBCR_FCC_PC;
- return YCBCR_UNKNOWN;
-}
-
/**
* \brief converts numpad-style align to align.
*/
@@ -473,7 +324,7 @@ void ass_utf16be_to_utf8(char *dst, size_t dst_size, uint8_t *src, size_t src_si
}
/**
- * \brief find style by name
+ * \brief find style by name the common way (\r matches differently)
* \param track track
* \param name style name
* \return index in track->styles
@@ -501,26 +352,3 @@ int lookup_style(ASS_Track *track, char *name)
track, name, track->styles[i].Name);
return i;
}
-
-/**
- * \brief find style by name as in \r
- * \param track track
- * \param name style name
- * \param len style name length
- * \return style in track->styles
- * Returns NULL if no style has the given name.
- */
-ASS_Style *lookup_style_strict(ASS_Track *track, char *name, size_t len)
-{
- int i;
- for (i = track->n_styles - 1; i >= 0; --i) {
- if (strncmp(track->styles[i].Name, name, len) == 0 &&
- track->styles[i].Name[len] == '\0')
- return track->styles + i;
- }
- ass_msg(track->library, MSGL_WARN,
- "[%p]: Warning: no style named '%.*s' found",
- track, (int) len, name);
- return NULL;
-}
-
diff --git a/libass/ass_utils.h b/libass/ass_utils.h
index b4f570a..b685f3e 100644
--- a/libass/ass_utils.h
+++ b/libass/ass_utils.h
@@ -95,12 +95,6 @@ void *ass_try_realloc_array(void *ptr, size_t nmemb, size_t size);
void skip_spaces(char **str);
void rskip_spaces(char **str, char *limit);
-int32_t parse_alpha_tag(char *str);
-uint32_t parse_color_tag(char *str);
-int32_t parse_int_header(char *str);
-uint32_t parse_color_header(char *str);
-char parse_bool(char *str);
-int parse_ycbcr_matrix(char *str);
int numpad2align(int val);
unsigned ass_utf8_get_char(char **str);
unsigned ass_utf8_put_char(char *dest, uint32_t ch);
@@ -112,7 +106,6 @@ void ass_utf16be_to_utf8(char *dst, size_t dst_size, uint8_t *src, size_t src_si
#endif
void ass_msg(ASS_Library *priv, int lvl, const char *fmt, ...);
int lookup_style(ASS_Track *track, char *name);
-ASS_Style *lookup_style_strict(ASS_Track *track, char *name, size_t len);
/* defined in ass_strtod.c */
double ass_strtod(const char *string, char **endPtr);