]> granicus.if.org Git - libass/commitdiff
Improve rotation cache accuracy
authorGrigori Goronzy <greg@blackbox>
Wed, 6 Jan 2010 22:51:01 +0000 (23:51 +0100)
committerGrigori Goronzy <greg@blackbox>
Thu, 7 Jan 2010 08:05:15 +0000 (09:05 +0100)
In some cases 16.16 precision is not good enough. Instead use 10.22 and
use modulo 360.0 on the angles to make overflows impossible and improve
cache hit ratio sometimes.

libass/ass_render.c
libass/ass_utils.h

index 1dc347f69de07da8bc57d815aa2e39109683195a..22edce81bfdce23bb3046310de8bd85b92b739dc 100644 (file)
@@ -1915,11 +1915,11 @@ ass_render_event(ASS_Renderer *render_priv, ASS_Event *event,
         text_info->glyphs[text_info->length].hash_key.scale_y =
             render_priv->state.scale_y * 0xFFFF;
         text_info->glyphs[text_info->length].hash_key.frx =
-            render_priv->state.frx * 0xFFFF;
+            rot_key(render_priv->state.frx);
         text_info->glyphs[text_info->length].hash_key.fry =
-            render_priv->state.fry * 0xFFFF;
+            rot_key(render_priv->state.fry);
         text_info->glyphs[text_info->length].hash_key.frz =
-            render_priv->state.frz * 0xFFFF;
+            rot_key(render_priv->state.frz);
         text_info->glyphs[text_info->length].hash_key.fax =
             render_priv->state.fax * 0xFFFF;
         text_info->glyphs[text_info->length].hash_key.fay =
index f5c68e96cf634b10405cd6b0d84936dba551f8a7..ad8574c1d69e838053b4595245cd742cfd606e51 100644 (file)
@@ -102,6 +102,21 @@ static inline int double_to_d16(double x)
 {
     return (int) (x * 0x10000);
 }
+static inline double d22_to_double(int x)
+{
+    return ((double) x) / 0x400000;
+}
+static inline int double_to_d22(double x)
+{
+    return (int) (x * 0x400000);
+}
+
+// Calculate cache key for a rotational angle in degrees
+static inline int rot_key(double a)
+{
+    const int m = double_to_d22(360.0);
+    return double_to_d22(a) % m;
+}
 
 #define FNV1_32A_INIT (unsigned)0x811c9dc5