[vlc-commits] bpg: add libbpg decoder

Tristan Matthews git at videolan.org
Thu Jan 8 17:57:49 CET 2015


vlc | branch: master | Tristan Matthews <tmatth at videolan.org> | Tue Jan  6 00:51:58 2015 +0000| [0451f9715206bdf593fcff9dd7732ee9a4f870ad] | committer: Tristan Matthews

bpg: add libbpg decoder

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=0451f9715206bdf593fcff9dd7732ee9a4f870ad
---

 NEWS                      |    1 +
 configure.ac              |   11 +++
 include/vlc_fourcc.h      |    1 +
 modules/MODULES_LIST      |    1 +
 modules/codec/Makefile.am |    6 ++
 modules/codec/bpg.c       |  187 +++++++++++++++++++++++++++++++++++++++++++++
 modules/demux/image.c     |    4 +
 po/POTFILES.in            |    1 +
 src/misc/fourcc.c         |    3 +
 src/misc/image.c          |    2 +
 10 files changed, 217 insertions(+)

diff --git a/NEWS b/NEWS
index 2af3171..c120613 100644
--- a/NEWS
+++ b/NEWS
@@ -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)
diff --git a/configure.ac b/configure.ac
index 55a64ba..bca8081 100644
--- a/configure.ac
+++ b/configure.ac
@@ -2715,6 +2715,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
 AC_ARG_ENABLE(x262,
diff --git a/include/vlc_fourcc.h b/include/vlc_fourcc.h
index 70b35d6..5f4f8f9 100644
--- a/include/vlc_fourcc.h
+++ b/include/vlc_fourcc.h
@@ -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')
diff --git a/modules/MODULES_LIST b/modules/MODULES_LIST
index 0f5adc9..a67b4a7 100644
--- a/modules/MODULES_LIST
+++ b/modules/MODULES_LIST
@@ -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
diff --git a/modules/codec/Makefile.am b/modules/codec/Makefile.am
index e26114b..ebdbf78 100644
--- a/modules/codec/Makefile.am
+++ b/modules/codec/Makefile.am
@@ -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)
diff --git a/modules/codec/bpg.c b/modules/codec/bpg.c
new file mode 100644
index 0000000..6ec49c7
--- /dev/null
+++ b/modules/codec/bpg.c
@@ -0,0 +1,187 @@
+/*****************************************************************************
+ * bpg.c: bpg decoder module using libbpg.
+ *****************************************************************************
+ * Copyright (C) 2015 VLC authors and VideoLAN
+ *
+ * Author: Tristan Matthews <tmatth at 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 );
+}
diff --git a/modules/demux/image.c b/modules/demux/image.c
index 5b56913..d91791f 100644
--- a/modules/demux/image.c
+++ b/modules/demux/image.c
@@ -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,
     },
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 4d861d5..008df4a 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -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
diff --git a/src/misc/fourcc.c b/src/misc/fourcc.c
index 1682870..13e9b40 100644
--- a/src/misc/fourcc.c
+++ b/src/misc/fourcc.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 "),
 
diff --git a/src/misc/image.c b/src/misc/image.c
index 906470a..02db3cb 100644
--- a/src/misc/image.c
+++ b/src/misc/image.c
@@ -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" },



More information about the vlc-commits mailing list