[vlc-devel] [PATCH 07/10] demux/image.c: Detect SVG Scalable Vector Graphics Images

Denis Charmet typx at dinauz.org
Tue May 13 10:31:50 CEST 2014


Hi,
Le lundi 12 mai 2014 à 12:04:27, jpsaman at videolan.org a écrit :
> From: Jean-Paul Saman <jpsaman at videolan.org>
> 
> ---
>  modules/demux/image.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 50 insertions(+)
> 
> diff --git a/modules/demux/image.c b/modules/demux/image.c
> index 672e7ba..5b56913 100644
> --- a/modules/demux/image.c
> +++ b/modules/demux/image.c
> @@ -423,6 +423,53 @@ static bool IsExif(stream_t *s)
>      return true;
>  }
>  
> +static bool FindSVGmarker(int *position, const uint8_t *data, const int size, const char *marker)
> +{
> +    for( int i = *position; i < size; i++)
> +    {
> +        if (memcmp(&data[i], marker, strlen(marker)) == 0)
> +        {
> +            *position = i;
> +            return true;
> +        }
> +    }
> +    return false;
> +}
why not strstr()?
> +
> +static bool IsSVG(stream_t *s)
> +{
> +    char *ext = strstr(s->psz_path, ".svg");
> +    if (!ext) return false;
> +
> +    const uint8_t *header;
> +    int size = stream_Peek(s, &header, 4096);
> +    int position = 0;
> +
> +    const char xml[] = "<?xml version=\"";
I don't really know xml but is it really mandatory to have a version
field and only one space?
> +    if (!FindSVGmarker(&position, header, size, xml))
> +        return false;
> +    if (position != 0)
> +        return false;
> +
> +    const char endxml[] = ">\0";
\0 is already added by ""
> +    if (!FindSVGmarker(&position, header, size, endxml))
> +        return false;
> +    if (position <= 15)
> +        return false;
> +
> +    const char svg[] = "<svg";
> +    if (!FindSVGmarker(&position, header, size, svg))
> +        return false;
> +    if (position < 19)
> +        return false;
> +
> +    /* SVG Scalable Vector Graphics image */
> +
> +    /* NOTE: some SVG images have the mimetype set in a meta data section
> +     * and some do not */
> +    return true;
> +}
> +
>  static bool IsTarga(stream_t *s)
>  {
>      /* The header is not enough to ensure proper detection, we need
> @@ -538,6 +585,9 @@ static const image_format_t formats[] = {
>      { .codec = VLC_CODEC_JPEG,
>        .detect = IsExif,
>      },
> +    { .codec = VLC_CODEC_SVG,
> +      .detect = IsSVG,
> +    },
>      { .codec = VLC_CODEC_TARGA,
>        .detect = IsTarga,
>      },
> -- 
> 1.9.0
> 
> _______________________________________________
> vlc-devel mailing list
> To unsubscribe or modify your subscription options:
> https://mailman.videolan.org/listinfo/vlc-devel

-- 
Denis Charmet - TypX
Le mauvais esprit est un art de vivre



More information about the vlc-devel mailing list