[MPlayer-cvslog] r28834 - in trunk/libass: ass_bitmap.c ass_bitmap.h ass_render.c

greg subversion at mplayerhq.hu
Fri Mar 6 02:17:06 CET 2009


Author: greg
Date: Fri Mar  6 02:17:05 2009
New Revision: 28834

Log:
Use blur with kernel [[1,2,1], [2,4,2], [1,2,1]] for \be.
This is faster than gaussian blur and similar to vsfilter.

Modified:
   trunk/libass/ass_bitmap.c
   trunk/libass/ass_bitmap.h
   trunk/libass/ass_render.c

Modified: trunk/libass/ass_bitmap.c
==============================================================================
--- trunk/libass/ass_bitmap.c	Fri Mar  6 01:47:03 2009	(r28833)
+++ trunk/libass/ass_bitmap.c	Fri Mar  6 02:17:05 2009	(r28834)
@@ -255,11 +255,38 @@ static bitmap_t* fix_outline_and_shadow(
 	return bm_s;
 }
 
-int glyph_to_bitmap(ass_synth_priv_t* priv, ass_synth_priv_t* priv_blur,
+/**
+ * \brief Blur with [[1,2,1]. [2,4,2], [1,2,1]] kernel
+ * This blur is the same as the one employed by vsfilter.
+ */
+static void be_blur(unsigned char *buf, int w, int h) {
+	unsigned int x, y;
+	unsigned int old_sum, new_sum;
+
+	for (y=0; y<h; y++) {
+		old_sum = 2 * buf[0];
+		for (x=0; x<w-1; x++) {
+			new_sum = buf[y*w+x] + buf[y*w+x+1];
+			buf[y*w+x] = (old_sum + new_sum) >> 2;
+			old_sum = new_sum;
+		}
+	}
+
+	for (x=0; x<w; x++) {
+		old_sum = 2 * buf[0];
+		for (y=0; y<h-1; y++) {
+			new_sum = buf[y*w+x] + buf[(y+1)*w+x];
+			buf[y*w+x] = (old_sum + new_sum) >> 2;
+			old_sum = new_sum;
+		}
+	}
+}
+
+int glyph_to_bitmap(ass_synth_priv_t* priv_blur,
 		FT_Glyph glyph, FT_Glyph outline_glyph, bitmap_t** bm_g,
 		bitmap_t** bm_o, bitmap_t** bm_s, int be, double blur_radius)
 {
-	int bord = be ? (be+1) : 0;
+	int bord = be ? (be/4+1) : 0;
 	blur_radius *= 2;
 	bord = (blur_radius > 0.0) ? blur_radius : bord;
 
@@ -279,19 +306,16 @@ int glyph_to_bitmap(ass_synth_priv_t* pr
 			return 1;
 		}
 	}
-	if (*bm_o) {
-		resize_tmp(priv, (*bm_o)->w, (*bm_o)->h);
+	if (*bm_o)
 		resize_tmp(priv_blur, (*bm_o)->w, (*bm_o)->h);
-	}
-	resize_tmp(priv, (*bm_g)->w, (*bm_g)->h);
 	resize_tmp(priv_blur, (*bm_g)->w, (*bm_g)->h);
 	
 	if (be) {
 		while (be--) {
 			if (*bm_o)
-				blur((*bm_o)->buffer, priv->tmp, (*bm_o)->w, (*bm_o)->h, (*bm_o)->w, (int*)priv->gt2, priv->g_r, priv->g_w);
+				be_blur((*bm_o)->buffer, (*bm_o)->w, (*bm_o)->h);
 			else
-				blur((*bm_g)->buffer, priv->tmp, (*bm_g)->w, (*bm_g)->h, (*bm_g)->w, (int*)priv->gt2, priv->g_r, priv->g_w);
+				be_blur((*bm_g)->buffer, (*bm_g)->w, (*bm_g)->h);
 		}
 	} else {
 		if (blur_radius > 0.0) {

Modified: trunk/libass/ass_bitmap.h
==============================================================================
--- trunk/libass/ass_bitmap.h	Fri Mar  6 01:47:03 2009	(r28833)
+++ trunk/libass/ass_bitmap.h	Fri Mar  6 02:17:05 2009	(r28834)
@@ -46,7 +46,7 @@ typedef struct bitmap_s {
  * \param bm_g out: pointer to the bitmap of glyph shadow is returned here
  * \param be 1 = produces blurred bitmaps, 0 = normal bitmaps
  */
-int glyph_to_bitmap(ass_synth_priv_t* priv, ass_synth_priv_t* priv_blur, FT_Glyph glyph, FT_Glyph outline_glyph, bitmap_t** bm_g, bitmap_t** bm_o, bitmap_t** bm_s, int be, double blur_radius);
+int glyph_to_bitmap(ass_synth_priv_t* priv_blur, FT_Glyph glyph, FT_Glyph outline_glyph, bitmap_t** bm_g, bitmap_t** bm_o, bitmap_t** bm_s, int be, double blur_radius);
 
 void ass_free_bitmap(bitmap_t* bm);
 

Modified: trunk/libass/ass_render.c
==============================================================================
--- trunk/libass/ass_render.c	Fri Mar  6 01:47:03 2009	(r28833)
+++ trunk/libass/ass_render.c	Fri Mar  6 02:17:05 2009	(r28834)
@@ -43,7 +43,6 @@
 
 #define MAX_GLYPHS 3000
 #define MAX_LINES 300
-#define BE_RADIUS 1.5
 #define BLUR_MAX_RADIUS 50.0
 #define ROUND(x) ((int) ((x) + .5))
 
@@ -83,7 +82,6 @@ struct ass_renderer_s {
 	ass_settings_t settings;
 	int render_id;
 	ass_synth_priv_t* synth_priv;
-	ass_synth_priv_t* synth_priv_blur;
 
 	ass_image_t* images_root; // rendering result is stored here
 	ass_image_t* prev_images_root;
@@ -270,8 +268,7 @@ ass_renderer_t* ass_renderer_init(ass_li
 		goto ass_init_exit;
 	}
 
-	priv->synth_priv = ass_synth_init(BE_RADIUS);
-	priv->synth_priv_blur = ass_synth_init(BLUR_MAX_RADIUS);
+	priv->synth_priv = ass_synth_init(BLUR_MAX_RADIUS);
 
 	priv->library = library;
 	priv->ftlibrary = ft;
@@ -1503,7 +1500,6 @@ static void get_bitmap_glyph(glyph_info_
 
 			// render glyph
 			error = glyph_to_bitmap(ass_renderer->synth_priv,
-					ass_renderer->synth_priv_blur,
 					info->glyph, info->outline_glyph,
 					&info->bm, &info->bm_o,
 					&info->bm_s, info->be, info->blur * frame_context.border_scale);



More information about the MPlayer-cvslog mailing list