1
/* Copyright (C) 2005 Ole Andr� Vadla Ravn�s <oleavr@gmail.com>
3
* This library is free software; you can redistribute it and/or
4
* modify it under the terms of the GNU Lesser General Public
5
* License as published by the Free Software Foundation; either
6
* version 2.1 of the License, or (at your option) any later version.
8
* This library is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11
* Lesser General Public License for more details.
13
* You should have received a copy of the GNU Lesser General Public
14
* License along with this library; if not, write to the Free Software
15
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
#include "mimic-private.h"
21
extern guchar _col_zag[64];
26
* De-serialize (reconstruct) a variable length coded 8x8 block.
28
gboolean _vlc_decode_block(MimCtx *ctx, gint *block, gint num_coeffs)
32
memset(block, 0, 64 * sizeof(gint));
34
/* The DC-value is read in as is. */
35
block[0] = _read_bits(ctx, 8);
37
for (pos = 1; pos < num_coeffs; pos++) {
39
guint prev_data_index, prev_cur_chunk_len, prev_chunk;
40
guint value, num_bits;
41
gboolean prev_read_odd, found_magic;
44
prev_data_index = ctx->data_index;
45
prev_cur_chunk_len = ctx->cur_chunk_len;
46
prev_chunk = ctx->cur_chunk;
47
prev_read_odd = ctx->read_odd;
50
value = _read_bits(ctx, 16) << 16;
52
/* Restore context. */
53
ctx->data_index = prev_data_index;
54
ctx->cur_chunk_len = prev_cur_chunk_len;
55
ctx->cur_chunk = prev_chunk;
56
ctx->read_odd = prev_read_odd;
58
/* Analyze and determine number of bits to read initially. */
60
if ((value >> 30) == 0 || (value >> 30) == 1) {
62
} else if ((value & 0xE0000000) != 0x80000000) {
63
guint nibble = value >> 28;
65
if (nibble == 11 || nibble == 12) {
67
} else if (nibble == 10) {
72
if (((value << 2) & 0x8000000) == 0)
79
/* Read that number of bits. */
80
value = _read_bits(ctx, num_bits);
83
* Look up the current value against the magic ones,
84
* and continue extending it bit by bit from the input
85
* stream until the magic value is found or we have
86
* read 32 bits (in which case we give up).
89
while (!found_magic) {
95
magic = _find_magic(value);
98
pos += magic->pos_add;
99
num_bits = magic->num_bits;
104
value |= _read_bits(ctx, 1);
110
/* Read the number of bits given by magic value entry. */
111
value = _read_bits(ctx, num_bits);
114
block[_col_zag[pos]] = ctx->vlcdec_lookup[(num_bits * 255) + value];