[vlc-devel] [PATCH 05/10] codec/svg.c: add --svg-scale=<float> option.
jpsaman at videolan.org
jpsaman at videolan.org
Mon May 12 12:04:25 CEST 2014
From: Jean-Paul Saman <jpsaman at videolan.org>
The scaling value overrides the --svg-width and --svg-height for the image.
---
modules/codec/svg.c | 63 +++++++++++++++++++++++++++++++++++++----------------
1 file changed, 44 insertions(+), 19 deletions(-)
diff --git a/modules/codec/svg.c b/modules/codec/svg.c
index 44f51bd..ce215a2 100644
--- a/modules/codec/svg.c
+++ b/modules/codec/svg.c
@@ -51,6 +51,8 @@ static picture_t *DecodeBlock ( decoder_t *, block_t ** );
#define LONG_TEXT_WIDTH N_("Specify the width to decode the image too")
#define TEXT_HEIGHT N_("Image height")
#define LONG_TEXT_HEIGHT N_("Specify the height to decode the image too")
+#define TEXT_SCALE N_("Scale factor")
+#define LONG_TEXT_SCALE N_("Scale factor to apply to image")
/*****************************************************************************
* Module descriptor
@@ -70,12 +72,15 @@ vlc_module_begin ()
add_integer_with_range( "svg-height", -1, 1, 65535,
TEXT_HEIGHT, LONG_TEXT_HEIGHT, false )
change_safe()
+
+ add_float( "svg-scale", -1.0, TEXT_SCALE, LONG_TEXT_SCALE, false )
vlc_module_end ()
struct decoder_sys_t
{
int32_t i_width;
int32_t i_height;
+ double f_scale;
};
/*****************************************************************************
@@ -95,6 +100,7 @@ static int OpenDecoder( vlc_object_t *p_this )
p_sys->i_width = var_InheritInteger( p_this, "svg-width" );
p_sys->i_height = var_InheritInteger( p_this, "svg-height" );
+ p_sys->f_scale = var_InheritFloat( p_this, "svg-scale" );
/* Initialize library */
rsvg_init();
@@ -143,25 +149,39 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
RsvgDimensionData dim;
rsvg_handle_get_dimensions( rsvg, &dim );
- i_width = p_sys->i_width > 0 ? p_sys->i_width : dim.width;
- i_height = p_sys->i_height > 0 ? p_sys->i_height : dim.height;
-
- /* Keep aspect */
- if( p_sys->i_width < 0 || p_sys->i_height > 0 )
+ if( p_sys->f_scale > 0.0 )
{
- i_width = dim.width * p_sys->i_height / dim.height;
- i_height = p_sys->i_height;
+ i_width = (int32_t)(p_sys->f_scale * dim.width);
+ i_height = (int32_t)(p_sys->f_scale * dim.height);
}
- else if( p_sys->i_width > 0 || p_sys->i_height < 0 )
+ else
{
- i_width = p_sys->i_height;
- i_height = dim.height * p_sys->i_width / dim.height;
+ /* Keep aspect */
+ if( p_sys->i_width < 0 && p_sys->i_height > 0 )
+ {
+ i_width = dim.width * p_sys->i_height / dim.height;
+ i_height = p_sys->i_height;
+ }
+ else if( p_sys->i_width > 0 && p_sys->i_height < 0 )
+ {
+ i_width = p_sys->i_width;
+ i_height = dim.height * p_sys->i_width / dim.height;
+ }
+ else if( p_sys->i_width > 0 && p_sys->i_height > 0 )
+ {
+ i_width = dim.width * p_sys->i_height / dim.height;
+ i_height = p_sys->i_height;
+ }
+ else
+ {
+ i_width = dim.width;
+ i_height = dim.height;
+ }
}
-
p_dec->fmt_out.video.i_chroma = VLC_CODEC_RGB32;
- p_dec->fmt_out.video.i_width = p_sys->i_width;
- p_dec->fmt_out.video.i_height = p_sys->i_height;
+ p_dec->fmt_out.video.i_width = i_width;
+ p_dec->fmt_out.video.i_height = i_height;
p_dec->fmt_out.video.i_visible_width = i_width;
p_dec->fmt_out.video.i_visible_height = i_height;
p_dec->fmt_out.video.i_sar_num = 1;
@@ -200,13 +220,18 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
goto done;
}
- if ( i_width != dim.width || i_height != dim.height )
+ if ( i_width != dim.width || i_height != dim.height )
{
- double aspect = (double) (dim.width * p_dec->fmt_out.video.i_sar_num) /
- (dim.height * p_dec->fmt_out.video.i_sar_den);
- double sw = aspect * i_width / dim.width;
- double sh = aspect * i_height / dim.height;
-
+ double sw, sh;
+ if ( p_sys->f_scale > 0.0 && !(p_sys->i_width > 0 || p_sys->i_height > 0) )
+ sw = sh = p_sys->f_scale;
+ else
+ {
+ double aspect = (double) (dim.width * p_dec->fmt_out.video.i_sar_num) /
+ (dim.height * p_dec->fmt_out.video.i_sar_den);
+ sw = aspect * i_width / dim.width;
+ sh = aspect * i_height / dim.height;
+ }
cairo_scale(cr, sw, sh);
}
--
1.9.0
More information about the vlc-devel
mailing list