summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--libass/ass.c21
1 files changed, 15 insertions, 6 deletions
diff --git a/libass/ass.c b/libass/ass.c
index e8cefc5..3a94290 100644
--- a/libass/ass.c
+++ b/libass/ass.c
@@ -24,6 +24,7 @@
#include <string.h>
#include <assert.h>
#include <errno.h>
+#include <limits.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <inttypes.h>
@@ -241,12 +242,20 @@ static long long string2timecode(ASS_Library *library, char *p)
*/
static int numpad2align(int val)
{
- int res, v;
- v = (val - 1) / 3; // 0, 1 or 2 for vertical alignment
- if (v != 0)
- v = 3 - v;
- res = ((val - 1) % 3) + 1; // horizontal alignment
- res += v * 4;
+ if (val < -INT_MAX)
+ // Pick an alignment somewhat arbitrarily. VSFilter handles
+ // INT32_MIN as a mix of 1, 2 and 3, so prefer one of those values.
+ val = 2;
+ else if (val < 0)
+ val = -val;
+
+ int res = ((val - 1) % 3) + 1; // horizontal alignment
+ if (val <= 3)
+ res |= VALIGN_SUB;
+ else if (val <= 6)
+ res |= VALIGN_CENTER;
+ else
+ res |= VALIGN_TOP;
return res;
}