Commit f68056f1 authored by Jean-Paul Saman's avatar Jean-Paul Saman Committed by Jean-Paul Saman

SVG decoder: various fixes

Various fixes:
- general cleanup
- fix wrong colors
- fix memleaks
- improve rsvg API usage
parent 96888e87
...@@ -4,6 +4,7 @@ ...@@ -4,6 +4,7 @@
* Copyright (C) 2014 VLC authors and VideoLAN * Copyright (C) 2014 VLC authors and VideoLAN
* *
* Authors: Adam Leggett <adamvleggett@gmail.com> * Authors: Adam Leggett <adamvleggett@gmail.com>
* Jean-Paul Saman <jpsaman@videolan.org>
* *
* This program is free software; you can redistribute it and/or modify it * This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by * under the terms of the GNU Lesser General Public License as published by
...@@ -38,13 +39,6 @@ ...@@ -38,13 +39,6 @@
#include <librsvg/rsvg.h> #include <librsvg/rsvg.h>
#include <cairo/cairo.h> #include <cairo/cairo.h>
/*****************************************************************************
* decoder_sys_t : svg decoder descriptor
*****************************************************************************/
struct decoder_sys_t
{
};
/***************************************************************************** /*****************************************************************************
* Local prototypes * Local prototypes
*****************************************************************************/ *****************************************************************************/
...@@ -73,17 +67,14 @@ static int OpenDecoder( vlc_object_t *p_this ) ...@@ -73,17 +67,14 @@ static int OpenDecoder( vlc_object_t *p_this )
decoder_t *p_dec = (decoder_t*)p_this; decoder_t *p_dec = (decoder_t*)p_this;
if( p_dec->fmt_in.i_codec != VLC_CODEC_SVG ) if( p_dec->fmt_in.i_codec != VLC_CODEC_SVG )
{
return VLC_EGENERIC; return VLC_EGENERIC;
}
/* Initialize library */ /* Initialize library */
rsvg_init(); rsvg_init();
/* Set output properties */ /* Set output properties */
p_dec->fmt_out.i_cat = VIDEO_ES; p_dec->fmt_out.i_cat = VIDEO_ES;
p_dec->fmt_out.i_codec = VLC_CODEC_RGBA; p_dec->fmt_out.i_codec = VLC_CODEC_RGB32;
/* Set callbacks */ /* Set callbacks */
p_dec->pf_decode_video = DecodeBlock; p_dec->pf_decode_video = DecodeBlock;
...@@ -91,13 +82,6 @@ static int OpenDecoder( vlc_object_t *p_this ) ...@@ -91,13 +82,6 @@ static int OpenDecoder( vlc_object_t *p_this )
return VLC_SUCCESS; return VLC_SUCCESS;
} }
static void rsvg_cairo_size_callback(int *width, int *height, gpointer data)
{
RsvgDimensionData *dim = data;
*width = dim->width;
*height = dim->height;
}
/**************************************************************************** /****************************************************************************
* DecodeBlock: the whole thing * DecodeBlock: the whole thing
**************************************************************************** ****************************************************************************
...@@ -111,7 +95,6 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block ) ...@@ -111,7 +95,6 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
RsvgHandle *rsvg = NULL; RsvgHandle *rsvg = NULL;
cairo_surface_t *surface = NULL; cairo_surface_t *surface = NULL;
cairo_t *cr = NULL; cairo_t *cr = NULL;
int stride = 0;
if( !pp_block || !*pp_block ) return NULL; if( !pp_block || !*pp_block ) return NULL;
...@@ -124,48 +107,60 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block ) ...@@ -124,48 +107,60 @@ static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
return NULL; return NULL;
} }
rsvg = rsvg_handle_new_from_data(p_block->p_buffer, p_block->i_buffer, NULL); rsvg = rsvg_handle_new_from_data( p_block->p_buffer, p_block->i_buffer, NULL );
if( !rsvg ) if( !rsvg )
goto done; goto done;
RsvgDimensionData dim; RsvgDimensionData dim;
rsvg_handle_get_dimensions(rsvg, &dim); rsvg_handle_get_dimensions( rsvg, &dim );
rsvg_handle_set_size_callback(rsvg, rsvg_cairo_size_callback, &dim, NULL);
p_dec->fmt_out.i_codec = VLC_CODEC_RGBA; p_dec->fmt_out.video.i_chroma = VLC_CODEC_RGB32;
p_dec->fmt_out.video.i_width = dim.width; p_dec->fmt_out.video.i_width = dim.width;
p_dec->fmt_out.video.i_height = dim.height; p_dec->fmt_out.video.i_height = dim.height;
p_dec->fmt_out.video.i_visible_width = dim.width;
p_dec->fmt_out.video.i_visible_height = dim.height;
p_dec->fmt_out.video.i_sar_num = 1; p_dec->fmt_out.video.i_sar_num = 1;
p_dec->fmt_out.video.i_sar_den = 1; p_dec->fmt_out.video.i_sar_den = 1;
p_dec->fmt_out.video.i_rmask = 0x000000ff; p_dec->fmt_out.video.i_rmask = 0x80800000; /* Since librsvg v1.0 */
p_dec->fmt_out.video.i_gmask = 0x0000ff00; p_dec->fmt_out.video.i_gmask = 0x0000ff00;
p_dec->fmt_out.video.i_bmask = 0x00ff0000; p_dec->fmt_out.video.i_bmask = 0x000000ff;
video_format_FixRgb(&p_dec->fmt_out.video);
/* Get a new picture */ /* Get a new picture */
p_pic = decoder_NewPicture( p_dec ); p_pic = decoder_NewPicture( p_dec );
if( !p_pic ) if( !p_pic )
goto done; goto done;
stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, dim.width); /* NOTE: Do not use the stride calculation from cairo, because it is wrong:
surface = cairo_image_surface_create_for_data(p_pic->p->p_pixels, * stride = cairo_format_stride_for_width(CAIRO_FORMAT_ARGB32, dim.width);
CAIRO_FORMAT_ARGB32, * Use the stride from VLC its picture_t::p[0].i_pitch, which is correct.
dim.width, dim.height, */
stride); surface = cairo_image_surface_create_for_data( p_pic->p->p_pixels,
CAIRO_FORMAT_ARGB32,
dim.width, dim.height,
p_pic->p[0].i_pitch );
if( !surface ) if( !surface )
{ {
picture_Release( p_pic );
p_pic = NULL; p_pic = NULL;
goto done; goto done;
} }
/* Decode picture */ /* Decode picture */
cr = cairo_create(surface); cr = cairo_create( surface );
if( !cr ) if( !cr )
{ {
picture_Release( p_pic );
p_pic = NULL; p_pic = NULL;
goto done; goto done;
} }
rsvg_handle_render_cairo(rsvg, cr); if( !rsvg_handle_render_cairo( rsvg, cr ) )
{
picture_Release( p_pic );
p_pic = NULL;
goto done;
}
p_pic->date = p_block->i_pts > VLC_TS_INVALID ? p_block->i_pts : p_block->i_dts; p_pic->date = p_block->i_pts > VLC_TS_INVALID ? p_block->i_pts : p_block->i_dts;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment