1 /*
2 * VBLE Decoder
3 * Copyright (c) 2011 Derek Buitenhuis
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
23 * @file
24 * VBLE Decoder
25 */
26
28
29 #define BITSTREAM_READER_LE
36
40
42 uint8_t *
val;
///< This array first holds the lengths of vlc symbols and then their value.
44
46 {
47 int i;
48 int allbits = 0;
49 static const uint8_t LUT[256] = {
50 8,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
51 5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
52 6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
53 5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
54 7,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
55 5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
56 6,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
57 5,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,4,0,1,0,2,0,1,0,3,0,1,0,2,0,1,0,
58 };
59
60 /* Read all the lengths in first */
61 for (i = 0; i < ctx->
size; i++) {
62 /* At most we need to read 9 bits total to get indices up to 8 */
64
65 // read reverse unary
66 if (val) {
70 } else {
73 return -1;
75 }
76 allbits += ctx->
val[i];
77 }
78
79 /* Check we have enough bits left */
81 return -1;
82 return 0;
83 }
84
88 {
92 int i, j, left, left_top;
93
94 for (i = 0; i <
height; i++) {
95 for (j = 0; j <
width; j++) {
96 /* get_bits can't take a length of 0 */
97 if (val[j]) {
98 int v = (1 << val[j]) +
get_bits(gb, val[j]) - 1;
99 val[j] = (v >> 1) ^ -(v & 1);
100 }
101 }
102 if (i) {
103 left = 0;
106 width, &left, &left_top);
107 } else {
108 dst[0] = val[0];
109 for (j = 1; j <
width; j++)
110 dst[j] = val[j] + dst[j - 1];
111 }
114 }
115 }
116
119 {
126 int width_uv = avctx->
width / 2, height_uv = avctx->
height / 2;
127 int ret;
129
130 if (avpkt->
size < 4 || avpkt->
size - 4 > INT_MAX/8) {
133 }
134
135 /* Allocate buffer */
137 return ret;
138
139 /* Set flags */
142
143 /* Version should always be 1 */
145
146 if (version != 1)
148
150
151 /* Unpack */
155 }
156
157 /* Restore planes. Should be almost identical to Huffyuv's. */
159
160 /* Chroma */
164
165 offset += width_uv * height_uv;
167 }
168
169 *got_frame = 1;
170
172 }
173
175 {
178
179 return 0;
180 }
181
183 {
185
186 /* Stash for later use */
189
192
195
197
202 }
203
204 return 0;
205 }
206
219 };
const char const char void * val
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
This structure describes decoded (raw) audio or video data.
ptrdiff_t const GLvoid * data
static unsigned int get_bits(GetBitContext *s, int n)
Read 1-25 bits.
#define AV_LOG_WARNING
Something somehow does not look correct.
static int init_thread_copy(AVCodecContext *avctx)
static av_cold int init(AVCodecContext *avctx)
static int vble_decode_frame(AVCodecContext *avctx, void *data, int *got_frame, AVPacket *avpkt)
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
static void decode(AVCodecContext *dec_ctx, AVPacket *pkt, AVFrame *frame, FILE *outfile)
#define FF_CODEC_CAP_INIT_THREADSAFE
The codec does not modify any global variables in the init function, allowing to call the init functi...
Multithreading support functions.
static int vble_unpack(VBLEContext *ctx, GetBitContext *gb)
bitstream reader API header.
#define AV_CODEC_FLAG_GRAY
Only decode/encode grayscale.
static int get_bits_left(GetBitContext *gb)
int av_image_get_buffer_size(enum AVPixelFormat pix_fmt, int width, int height, int align)
Return the size in bytes of the amount of data required to store an image with the given parameters...
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
int flags
AV_CODEC_FLAG_*.
const char * name
Name of the codec implementation.
static const uint8_t offset[127][2]
#define AV_CODEC_CAP_FRAME_THREADS
Codec supports frame-level multithreading.
#define ONLY_IF_THREADS_ENABLED(x)
Define a function with only the non-default version specified.
enum AVPictureType pict_type
Picture type of the frame.
int width
picture width / height.
static unsigned int show_bits(GetBitContext *s, int n)
Show 1-25 bits.
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
int ff_thread_get_buffer(AVCodecContext *avctx, ThreadFrame *f, int flags)
Wrapper around get_buffer() for frame-multithreaded codecs.
main external API structure.
static av_cold int vble_decode_close(AVCodecContext *avctx)
void ff_llviddsp_init(LLVidDSPContext *c)
static unsigned int get_bits1(GetBitContext *s)
static void skip_bits(GetBitContext *s, int n)
uint8_t * val
This array first holds the lengths of vlc symbols and then their value.
static int init_get_bits(GetBitContext *s, const uint8_t *buffer, int bit_size)
Initialize GetBitContext.
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
GLint GLenum GLboolean GLsizei stride
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
common internal api header.
static void vble_restore_plane(VBLEContext *ctx, AVFrame *pic, GetBitContext *gb, int plane, int offset, int width, int height)
int key_frame
1 -> keyframe, 0-> not
static av_cold int vble_decode_init(AVCodecContext *avctx)
#define av_malloc_array(a, b)
uint64_t_TMPL AV_WL64 unsigned int_TMPL AV_RL32
This structure stores compressed data.
#define AV_CODEC_CAP_DR1
Codec uses get_buffer() for allocating buffers and supports custom allocators.
void(* add_median_pred)(uint8_t *dst, const uint8_t *top, const uint8_t *diff, ptrdiff_t w, int *left, int *left_top)