mirror of https://github.com/mpv-player/mpv
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. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@28834 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
e7cb3e94b6
commit
d4423f7516
|
@ -255,11 +255,38 @@ static bitmap_t* fix_outline_and_shadow(bitmap_t* bm_g, bitmap_t* bm_o)
|
||||||
return bm_s;
|
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,
|
FT_Glyph glyph, FT_Glyph outline_glyph, bitmap_t** bm_g,
|
||||||
bitmap_t** bm_o, bitmap_t** bm_s, int be, double blur_radius)
|
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;
|
blur_radius *= 2;
|
||||||
bord = (blur_radius > 0.0) ? blur_radius : bord;
|
bord = (blur_radius > 0.0) ? blur_radius : bord;
|
||||||
|
|
||||||
|
@ -279,19 +306,16 @@ int glyph_to_bitmap(ass_synth_priv_t* priv, ass_synth_priv_t* priv_blur,
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (*bm_o) {
|
if (*bm_o)
|
||||||
resize_tmp(priv, (*bm_o)->w, (*bm_o)->h);
|
|
||||||
resize_tmp(priv_blur, (*bm_o)->w, (*bm_o)->h);
|
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);
|
resize_tmp(priv_blur, (*bm_g)->w, (*bm_g)->h);
|
||||||
|
|
||||||
if (be) {
|
if (be) {
|
||||||
while (be--) {
|
while (be--) {
|
||||||
if (*bm_o)
|
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
|
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 {
|
} else {
|
||||||
if (blur_radius > 0.0) {
|
if (blur_radius > 0.0) {
|
||||||
|
|
|
@ -46,7 +46,7 @@ typedef struct bitmap_s {
|
||||||
* \param bm_g out: pointer to the bitmap of glyph shadow is returned here
|
* \param bm_g out: pointer to the bitmap of glyph shadow is returned here
|
||||||
* \param be 1 = produces blurred bitmaps, 0 = normal bitmaps
|
* \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);
|
void ass_free_bitmap(bitmap_t* bm);
|
||||||
|
|
||||||
|
|
|
@ -43,7 +43,6 @@
|
||||||
|
|
||||||
#define MAX_GLYPHS 3000
|
#define MAX_GLYPHS 3000
|
||||||
#define MAX_LINES 300
|
#define MAX_LINES 300
|
||||||
#define BE_RADIUS 1.5
|
|
||||||
#define BLUR_MAX_RADIUS 50.0
|
#define BLUR_MAX_RADIUS 50.0
|
||||||
#define ROUND(x) ((int) ((x) + .5))
|
#define ROUND(x) ((int) ((x) + .5))
|
||||||
|
|
||||||
|
@ -83,7 +82,6 @@ struct ass_renderer_s {
|
||||||
ass_settings_t settings;
|
ass_settings_t settings;
|
||||||
int render_id;
|
int render_id;
|
||||||
ass_synth_priv_t* synth_priv;
|
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* images_root; // rendering result is stored here
|
||||||
ass_image_t* prev_images_root;
|
ass_image_t* prev_images_root;
|
||||||
|
@ -270,8 +268,7 @@ ass_renderer_t* ass_renderer_init(ass_library_t* library)
|
||||||
goto ass_init_exit;
|
goto ass_init_exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
priv->synth_priv = ass_synth_init(BE_RADIUS);
|
priv->synth_priv = ass_synth_init(BLUR_MAX_RADIUS);
|
||||||
priv->synth_priv_blur = ass_synth_init(BLUR_MAX_RADIUS);
|
|
||||||
|
|
||||||
priv->library = library;
|
priv->library = library;
|
||||||
priv->ftlibrary = ft;
|
priv->ftlibrary = ft;
|
||||||
|
@ -1503,7 +1500,6 @@ static void get_bitmap_glyph(glyph_info_t* info)
|
||||||
|
|
||||||
// render glyph
|
// render glyph
|
||||||
error = glyph_to_bitmap(ass_renderer->synth_priv,
|
error = glyph_to_bitmap(ass_renderer->synth_priv,
|
||||||
ass_renderer->synth_priv_blur,
|
|
||||||
info->glyph, info->outline_glyph,
|
info->glyph, info->outline_glyph,
|
||||||
&info->bm, &info->bm_o,
|
&info->bm, &info->bm_o,
|
||||||
&info->bm_s, info->be, info->blur * frame_context.border_scale);
|
&info->bm_s, info->be, info->blur * frame_context.border_scale);
|
||||||
|
|
Loading…
Reference in New Issue