]> granicus.if.org Git - libass/commitdiff
Clamp clip rectangle to frame size
authorGrigori Goronzy <greg@blackbox>
Tue, 21 Jul 2009 00:39:52 +0000 (02:39 +0200)
committerGrigori Goronzy <greg@blackbox>
Tue, 21 Jul 2009 00:39:52 +0000 (02:39 +0200)
Make sure the clip rectangle is inside the screen boundaries.
Idea by Evgeniy Stepanov.

libass/ass_render.c
libass/ass_utils.h

index f2c137d4ecc1e33894b5fa54eef6bacb978b098c..f6234828b310ef68ef12a5a95b61e123bbac5e9a 100644 (file)
@@ -556,10 +556,10 @@ static ass_image_t **render_glyph(ass_renderer_t *render_priv,
     brk -= bm->left;
 
     // clipping
-    clip_x0 = render_priv->state.clip_x0;
-    clip_y0 = render_priv->state.clip_y0;
-    clip_x1 = render_priv->state.clip_x1;
-    clip_y1 = render_priv->state.clip_y1;
+    clip_x0 = FFMINMAX(render_priv->state.clip_x0, 0, render_priv->width);
+    clip_y0 = FFMINMAX(render_priv->state.clip_y0, 0, render_priv->height);
+    clip_x1 = FFMINMAX(render_priv->state.clip_x1, 0, render_priv->width);
+    clip_y1 = FFMINMAX(render_priv->state.clip_y1, 0, render_priv->height);
     b_x0 = 0;
     b_y0 = 0;
     b_x1 = bm->w;
index a906ca57ae7eb38e01bc46cd87852030c2e27c2b..39132903e31ad3dbb21681b4a522470346f9f923 100644 (file)
@@ -43,6 +43,7 @@
 
 #define FFMAX(a,b) ((a) > (b) ? (a) : (b))
 #define FFMIN(a,b) ((a) > (b) ? (b) : (a))
+#define FFMINMAX(c,a,b) FFMIN(FFMAX(c, a), b)
 
 int mystrtoi(char **p, int *res);
 int mystrtoll(char **p, long long *res);