1 /*****************************************************************************
2 * bpg.c: bpg decoder module using libbpg.
3 *****************************************************************************
4 * Copyright (C) 2015 VLC authors and VideoLAN
6 * Author: Tristan Matthews <tmatth@videolan.org>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
27 #include <vlc_common.h>
28 #include <vlc_plugin.h>
29 #include <vlc_codec.h>
34 struct BPGDecoderContext
*p_bpg
;
37 static int OpenDecoder(vlc_object_t
*);
38 static void CloseDecoder(vlc_object_t
*);
40 static int DecodeBlock(decoder_t
*, block_t
*);
46 set_category( CAT_INPUT
)
47 set_subcategory( SUBCAT_INPUT_VCODEC
)
48 /* decoder main module */
49 set_description( N_("BPG image decoder") )
50 set_capability( "video decoder", 60 )
51 set_callbacks( OpenDecoder
, CloseDecoder
)
56 static int OpenDecoder(vlc_object_t
*p_this
)
58 decoder_t
*p_dec
= (decoder_t
*)p_this
;
60 if( p_dec
->fmt_in
.i_codec
!= VLC_CODEC_BPG
)
65 decoder_sys_t
*p_sys
= malloc( sizeof( decoder_sys_t
) );
73 p_sys
->p_bpg
= bpg_decoder_open();
80 p_dec
->pf_decode
= DecodeBlock
;
86 * This function must be fed with a complete compressed frame.
88 static int DecodeBlock( decoder_t
*p_dec
, block_t
*p_block
)
90 decoder_sys_t
*p_sys
= p_dec
->p_sys
;
92 BPGImageInfo img_info
;
94 if( p_block
== NULL
) /* No Drain */
95 return VLCDEC_SUCCESS
;
97 if( p_block
->i_flags
& BLOCK_FLAG_CORRUPTED
)
102 if( bpg_decoder_decode( p_sys
->p_bpg
,
104 p_block
->i_buffer
) < 0 )
106 msg_Err( p_dec
, "Could not decode block" );
110 if( bpg_decoder_get_info( p_sys
->p_bpg
, &img_info
) )
112 msg_Err( p_dec
, "Could not get info for decoder" );
116 if( bpg_decoder_start( p_sys
->p_bpg
, BPG_OUTPUT_FORMAT_RGB24
) )
118 msg_Err( p_dec
, "Could not start decoder" );
122 /* Set output properties */
123 p_dec
->fmt_out
.video
.i_chroma
=
124 p_dec
->fmt_out
.i_codec
= VLC_CODEC_RGB24
;
125 video_format_FixRgb(&p_dec
->fmt_out
.video
);
126 p_dec
->fmt_out
.video
.i_visible_width
= p_dec
->fmt_out
.video
.i_width
= img_info
.width
;
127 p_dec
->fmt_out
.video
.i_visible_height
= p_dec
->fmt_out
.video
.i_height
= img_info
.height
;
128 p_dec
->fmt_out
.video
.i_sar_num
= 1;
129 p_dec
->fmt_out
.video
.i_sar_den
= 1;
131 /* Get a new picture */
132 if( decoder_UpdateVideoFormat( p_dec
) )
136 p_pic
= decoder_NewPicture( p_dec
);
142 const int img_height
= img_info
.height
;
143 for (int i
= 0; i
< img_height
; i
++)
145 if( bpg_decoder_get_line( p_sys
->p_bpg
,
146 p_pic
->p
->p_pixels
+ p_pic
->p
->i_pitch
* i
)
149 msg_Err( p_dec
, "Could not decode line" );
154 p_pic
->date
= p_block
->i_pts
!= VLC_TICK_INVALID
? p_block
->i_pts
: p_block
->i_dts
;
156 decoder_QueueVideo( p_dec
, p_pic
);
158 block_Release( p_block
);
159 return VLCDEC_SUCCESS
;
162 static void CloseDecoder( vlc_object_t
*p_this
)
164 decoder_t
*p_dec
= (decoder_t
*)p_this
;
165 decoder_sys_t
*p_sys
= p_dec
->p_sys
;
168 bpg_decoder_close( p_sys
->p_bpg
);