Commit 0451f971 authored by Tristan Matthews's avatar Tristan Matthews

bpg: add libbpg decoder

parent afbb16c0
......@@ -26,6 +26,7 @@ Decoder:
* Support HEVC hardware decoding using OMX and MediaCodec
* Support VP9 and WMV3 decoding using OMX and performance improvements
* New MPEG-1 & 2 audio layer I, II, III + MPEG 2.5 decoder based on libmpg123
* New BPG decoder based on libbpg
Demuxers:
* Support HD-DVD .evo (H.264, VC-1, MPEG-2, PCM, AC-3, E-AC3, MLP, DTS)
......
......@@ -2714,6 +2714,17 @@ AC_CHECK_HEADERS(jpeglib.h, [
])
])
dnl
dnl BPG decoder module
dnl
AC_ARG_ENABLE(bpg,
[ --enable-bpg BPG support (default disabled)])
AS_IF([test "${enable_bpg}" != "no"], [
AC_CHECK_HEADERS(libbpg.h, [
VLC_ADD_PLUGIN([bpg])
])
])
dnl
dnl H262 encoder plugin (lib262)
dnl
......
......@@ -334,6 +334,7 @@
#define VLC_CODEC_PGMYUV VLC_FOURCC('p','g','m','y')
#define VLC_CODEC_PAM VLC_FOURCC('p','a','m',' ')
#define VLC_CODEC_JPEG VLC_FOURCC('j','p','e','g')
#define VLC_CODEC_BPG VLC_FOURCC('B','P','G',0xFB)
#define VLC_CODEC_JPEGLS VLC_FOURCC('M','J','L','S')
#define VLC_CODEC_BMP VLC_FOURCC('b','m','p',' ')
#define VLC_CODEC_TIFF VLC_FOURCC('t','i','f','f')
......
......@@ -61,6 +61,7 @@ $Id$
* blendbench: a picture filter that test performance of blending routines
* bluescreen: Bluescreen (weather channel like) video filter
* bonjour: Zeroconf services discovery
* bpg: BPG image decoder using libbpg
* caca: color ASCII art video output using libcaca
* caf: CAF demuxer
* canvas: Automatically resize and padd a video
......
......@@ -121,6 +121,12 @@ libjpeg_plugin_la_LIBADD = -ljpeg
EXTRA_LTLIBRARIES += libjpeg_plugin.la
codec_LTLIBRARIES += $(LTLIBjpeg)
libbpg_plugin_la_SOURCES = codec/bpg.c
libbpg_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(codecdir)'
libbpg_plugin_la_LIBADD = -lbpg
EXTRA_LTLIBRARIES += libbpg_plugin.la
codec_LTLIBRARIES += $(LTLIBbpg)
libsvgdec_plugin_la_SOURCES = codec/svg.c
libsvgdec_plugin_la_CFLAGS = $(AM_CLAGS) $(CFLAGS_svgdec)
libsvgdec_plugin_la_LDFLAGS = $(AM_LDFLAGS) -rpath '$(codecdir)' $(LDFLAGS_svg)
......
/*****************************************************************************
* bpg.c: bpg decoder module using libbpg.
*****************************************************************************
* Copyright (C) 2015 VLC authors and VideoLAN
*
* Author: Tristan Matthews <tmatth@videolan.org>
*
* 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
* the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; if not, write to the Free Software Foundation,
* Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <vlc_common.h>
#include <vlc_plugin.h>
#include <vlc_codec.h>
#include <libbpg.h>
struct decoder_sys_t
{
struct BPGDecoderContext *p_bpg;
};
static int OpenDecoder(vlc_object_t *);
static void CloseDecoder(vlc_object_t *);
static picture_t *DecodeBlock(decoder_t *, block_t **);
/*
* Module descriptor
*/
vlc_module_begin()
set_category( CAT_INPUT )
set_subcategory( SUBCAT_INPUT_VCODEC )
/* decoder main module */
set_description( N_("BPG image decoder") )
set_capability( "decoder", 60 )
set_callbacks( OpenDecoder, CloseDecoder )
add_shortcut( "bpg" )
vlc_module_end()
static int OpenDecoder(vlc_object_t *p_this)
{
decoder_t *p_dec = (decoder_t *)p_this;
if( p_dec->fmt_in.i_codec != VLC_CODEC_BPG )
{
return VLC_EGENERIC;
}
decoder_sys_t *p_sys = malloc( sizeof( decoder_sys_t ) );
if( p_sys == NULL )
{
return VLC_ENOMEM;
}
p_dec->p_sys = p_sys;
p_sys->p_bpg = bpg_decoder_open();
if( !p_sys->p_bpg )
{
return VLC_EGENERIC;
}
/* Set output properties */
p_dec->fmt_out.i_cat = VIDEO_ES;
/* Set callbacks */
p_dec->pf_decode_video = DecodeBlock;
return VLC_SUCCESS;
}
/*
* This function must be fed with a complete compressed frame.
*/
static picture_t *DecodeBlock( decoder_t *p_dec, block_t **pp_block )
{
decoder_sys_t *p_sys = p_dec->p_sys;
block_t *p_block;
picture_t *p_pic = 0;
BPGImageInfo img_info;
if( !pp_block || !*pp_block )
{
return NULL;
}
p_block = *pp_block;
if( p_block->i_flags & BLOCK_FLAG_DISCONTINUITY )
{
block_Release(p_block);
*pp_block = NULL;
return NULL;
}
/* Decode picture */
if( bpg_decoder_decode( p_sys->p_bpg,
p_block->p_buffer,
p_block->i_buffer ) < 0 )
{
msg_Err( p_dec, "Could not decode block" );
goto error;
}
if( bpg_decoder_get_info( p_sys->p_bpg, &img_info ) )
{
msg_Err( p_dec, "Could not get info for decoder" );
goto error;
}
if( bpg_decoder_start( p_sys->p_bpg, BPG_OUTPUT_FORMAT_RGB24 ) )
{
msg_Err( p_dec, "Could not start decoder" );
goto error;
}
/* Set output properties */
p_dec->fmt_out.i_codec = VLC_CODEC_RGB24;
p_dec->fmt_out.video.i_visible_width = p_dec->fmt_out.video.i_width = img_info.width;
p_dec->fmt_out.video.i_visible_height = p_dec->fmt_out.video.i_height = img_info.height;
p_dec->fmt_out.video.i_sar_num = 1;
p_dec->fmt_out.video.i_sar_den = 1;
p_dec->fmt_out.video.i_rmask = 0x000000ff;
p_dec->fmt_out.video.i_gmask = 0x0000ff00;
p_dec->fmt_out.video.i_bmask = 0x00ff0000;
/* Get a new picture */
p_pic = decoder_NewPicture( p_dec );
if( !p_pic )
{
goto error;
}
const int img_height = img_info.height;
for (int i = 0; i < img_height; i++)
{
if( bpg_decoder_get_line( p_sys->p_bpg,
p_pic->p->p_pixels + p_pic->p->i_pitch * i )
< 0 )
{
msg_Err( p_dec, "Could not decode line" );
goto error;
}
}
p_pic->date = p_block->i_pts > VLC_TS_INVALID ? p_block->i_pts : p_block->i_dts;
block_Release( p_block );
*pp_block = NULL;
return p_pic;
error:
block_Release( p_block );
*pp_block = NULL;
return NULL;
}
static void CloseDecoder( vlc_object_t *p_this )
{
decoder_t *p_dec = (decoder_t *)p_this;
decoder_sys_t *p_sys = p_dec->p_sys;
if( p_sys->p_bpg )
bpg_decoder_close( p_sys->p_bpg );
free( p_sys );
}
......@@ -585,6 +585,10 @@ static const image_format_t formats[] = {
{ .codec = VLC_CODEC_JPEG,
.detect = IsExif,
},
{ .codec = VLC_CODEC_BPG,
.marker_size = 4,
.marker = { 'B', 'P', 'G', 0xFB },
},
{ .codec = VLC_CODEC_SVG,
.detect = IsSVG,
},
......
......@@ -357,6 +357,7 @@ modules/codec/avcodec/fourcc.c
modules/codec/avcodec/vaapi.c
modules/codec/avcodec/vda.c
modules/codec/avcodec/video.c
modules/codec/bpg.c
modules/codec/cc.c
modules/codec/cc.h
modules/codec/cdg.c
......
......@@ -958,6 +958,9 @@ static const staticentry_t p_list_video[] = {
A("jpeg"),
A("JPEG"),
B(VLC_CODEC_BPG, "BPG Image"),
A("BPG "),
B(VLC_CODEC_BMP, "BMP Image"),
A("bmp "),
......
......@@ -503,6 +503,7 @@ static const struct
{ VLC_CODEC_JPEG, "jpeg" },
{ VLC_CODEC_JPEG, "jpg" },
{ VLC_CODEC_JPEGLS, "ljpg" },
{ VLC_CODEC_BPG, "bpg" },
{ VLC_CODEC_PNG, "png" },
{ VLC_CODEC_PGM, "pgm" },
{ VLC_CODEC_PGMYUV, "pgmyuv" },
......@@ -567,6 +568,7 @@ static const struct
{ VLC_CODEC_PNM, "image/x-portable-pixmap" },
{ VLC_CODEC_GIF, "image/gif" },
{ VLC_CODEC_JPEG, "image/jpeg" },
{ VLC_CODEC_BPG, "image/bpg" },
{ VLC_CODEC_PCX, "image/pcx" },
{ VLC_CODEC_PNG, "image/png" },
{ VLC_CODEC_SVG, "image/svg+xml" },
......
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