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
27 #define BITSTREAM_READER_LE
28
34
38
40 uint8_t *
val;
///< This array first holds the lengths of vlc symbols and then their value.
42
44 {
45 int i;
46 int allbits = 0;
47 static const uint8_t LUT[256] = {
48 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,
49 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,
50 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,
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 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,
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 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,
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 };
57
58 /* Read all the lengths in first */
59 for (i = 0; i < ctx->
size; i++) {
60 /* At most we need to read 9 bits total to get indices up to 8 */
62
63 // read reverse unary
64 if (val) {
68 } else {
71 return -1;
73 }
74 allbits += ctx->
val[i];
75 }
76
77 /* Check we have enough bits left */
79 return -1;
80 return 0;
81 }
82
86 {
90 int i, j, left, left_top;
91
92 for (i = 0; i <
height; i++) {
93 for (j = 0; j <
width; j++) {
94 /* get_bits can't take a length of 0 */
95 if (val[j]) {
96 int v = (1 << val[j]) +
get_bits(gb, val[j]) - 1;
97 val[j] = (v >> 1) ^ -(v & 1);
98 }
99 }
100 if (i) {
101 left = 0;
102 left_top = dst[-stride];
104 width, &left, &left_top);
105 } else {
106 dst[0] = val[0];
107 for (j = 1; j <
width; j++)
108 dst[j] = val[j] + dst[j - 1];
109 }
110 dst += stride;
112 }
113 }
114
117 {
124 int width_uv = avctx->
width / 2, height_uv = avctx->
height / 2;
126
127 if (avpkt->
size < 4 || avpkt->
size - 4 > INT_MAX/8) {
130 }
131
132 /* Allocate buffer */
135
136 /* Set flags */
139
140 /* Version should always be 1 */
142
143 if (version != 1)
145
147
148 /* Unpack */
152 }
153
154 /* Restore planes. Should be almost identical to Huffyuv's. */
156
157 /* Chroma */
161
162 offset += width_uv * height_uv;
164 }
165
166 *got_frame = 1;
167
169 }
170
172 {
175
176 return 0;
177 }
178
180 {
182
183 /* Stash for later use */
186
189
192
194
199 }
200
201 return 0;
202 }
203
214 };