diff options
author | Miguel Freitas <miguelfreitas@users.sourceforge.net> | 2002-07-15 19:42:40 +0000 |
---|---|---|
committer | Miguel Freitas <miguelfreitas@users.sourceforge.net> | 2002-07-15 19:42:40 +0000 |
commit | 01ef70db6c2a280d96ddce6e6272a4813e047c9b (patch) | |
tree | 38a5cf0a9b7500f5b06dbe5de93548985dcb0185 | |
parent | c6b394300792eb277b16b25bfca864c8bcbed7db (diff) | |
download | xine-lib-01ef70db6c2a280d96ddce6e6272a4813e047c9b.tar.gz xine-lib-01ef70db6c2a280d96ddce6e6272a4813e047c9b.tar.bz2 |
update to ffmpeg cvs
CVS patchset: 2277
CVS date: 2002/07/15 19:42:40
22 files changed, 4528 insertions, 1093 deletions
diff --git a/src/libffmpeg/libavcodec/Makefile.am b/src/libffmpeg/libavcodec/Makefile.am index 3a8764eaf..06bfb162d 100644 --- a/src/libffmpeg/libavcodec/Makefile.am +++ b/src/libffmpeg/libavcodec/Makefile.am @@ -16,10 +16,10 @@ LIBTOOL = $(SHELL) $(top_builddir)/libtool-nofpic noinst_LTLIBRARIES = libavcodec.la libavcodec_la_SOURCES = common.c utils.c mpegvideo.c h263.c jrevdct.c jfdctfst.c \ - mjpeg.c dsputil.c \ + mjpeg.c dsputil.c svq1.c \ motion_est.c imgconvert.c msmpeg4.c \ mpeg12.c h263dec.c rv10.c simple_idct.c \ - ratecontrol.c mem.c + ratecontrol.c mem.c #imgresample.c libavcodec_la_LDFLAGS = \ diff --git a/src/libffmpeg/libavcodec/alpha/dsputil_alpha.c b/src/libffmpeg/libavcodec/alpha/dsputil_alpha.c index 5e1aa2093..9a3fb1eac 100644 --- a/src/libffmpeg/libavcodec/alpha/dsputil_alpha.c +++ b/src/libffmpeg/libavcodec/alpha/dsputil_alpha.c @@ -22,6 +22,8 @@ void simple_idct_axp(DCTELEM *block); +void put_pixels_axp_asm(uint8_t *block, const uint8_t *pixels, + int line_size, int h); void put_pixels_clamped_mvi_asm(const DCTELEM *block, uint8_t *pixels, int line_size); void add_pixels_clamped_mvi_asm(const DCTELEM *block, uint8_t *pixels, @@ -103,145 +105,183 @@ void add_pixels_clamped_mvi(const DCTELEM *block, uint8_t *pixels, } #endif -/* Average 8 unsigned bytes in parallel: (b1 + b2) >> 1 - Since the immediate result could be greater than 255, we do the - shift first. The result is too low by one if the bytes were both - odd, so we need to add (l1 & l2) & BYTE_VEC(0x01). */ -static inline UINT64 avg2_no_rnd(UINT64 l1, UINT64 l2) -{ - UINT64 correction = (l1 & l2) & BYTE_VEC(0x01); - l1 = (l1 & ~BYTE_VEC(0x01)) >> 1; - l2 = (l2 & ~BYTE_VEC(0x01)) >> 1; - return l1 + l2 + correction; +static void clear_blocks_axp(DCTELEM *blocks) { + uint64_t *p = (uint64_t *) blocks; + int n = sizeof(DCTELEM) * 6 * 64; + + do { + p[0] = 0; + p[1] = 0; + p[2] = 0; + p[3] = 0; + p[4] = 0; + p[5] = 0; + p[6] = 0; + p[7] = 0; + p += 8; + n -= 8 * 8; + } while (n); } -/* Average 8 bytes with rounding: (b1 + b2 + 1) >> 1 - The '1' only has an effect when one byte is even and the other odd, - i. e. we also need to add (l1 ^ l2) & BYTE_VEC(0x01). - Incidentally, that is equivalent to (l1 | l2) & BYTE_VEC(0x01). */ -static inline UINT64 avg2(UINT64 l1, UINT64 l2) +static inline uint64_t avg2_no_rnd(uint64_t a, uint64_t b) { - UINT64 correction = (l1 | l2) & BYTE_VEC(0x01); - l1 = (l1 & ~BYTE_VEC(0x01)) >> 1; - l2 = (l2 & ~BYTE_VEC(0x01)) >> 1; - return l1 + l2 + correction; + return (a & b) + (((a ^ b) & BYTE_VEC(0xfe)) >> 1); } -static inline UINT64 avg4(UINT64 l1, UINT64 l2, UINT64 l3, UINT64 l4) +static inline uint64_t avg2(uint64_t a, uint64_t b) { - UINT64 r1 = ((l1 & ~BYTE_VEC(0x03)) >> 2) - + ((l2 & ~BYTE_VEC(0x03)) >> 2) - + ((l3 & ~BYTE_VEC(0x03)) >> 2) - + ((l4 & ~BYTE_VEC(0x03)) >> 2); - UINT64 r2 = (( (l1 & BYTE_VEC(0x03)) - + (l2 & BYTE_VEC(0x03)) - + (l3 & BYTE_VEC(0x03)) - + (l4 & BYTE_VEC(0x03)) - + BYTE_VEC(0x02)) >> 2) & BYTE_VEC(0x03); - return r1 + r2; + return (a | b) - (((a ^ b) & BYTE_VEC(0xfe)) >> 1); } -static inline UINT64 avg4_no_rnd(UINT64 l1, UINT64 l2, UINT64 l3, UINT64 l4) +#if 0 +/* The XY2 routines basically utilize this scheme, but reuse parts in + each iteration. */ +static inline uint64_t avg4(uint64_t l1, uint64_t l2, uint64_t l3, uint64_t l4) { - UINT64 r1 = ((l1 & ~BYTE_VEC(0x03)) >> 2) - + ((l2 & ~BYTE_VEC(0x03)) >> 2) - + ((l3 & ~BYTE_VEC(0x03)) >> 2) - + ((l4 & ~BYTE_VEC(0x03)) >> 2); - UINT64 r2 = (( (l1 & BYTE_VEC(0x03)) - + (l2 & BYTE_VEC(0x03)) - + (l3 & BYTE_VEC(0x03)) - + (l4 & BYTE_VEC(0x03)) - + BYTE_VEC(0x01)) >> 2) & BYTE_VEC(0x03); + uint64_t r1 = ((l1 & ~BYTE_VEC(0x03)) >> 2) + + ((l2 & ~BYTE_VEC(0x03)) >> 2) + + ((l3 & ~BYTE_VEC(0x03)) >> 2) + + ((l4 & ~BYTE_VEC(0x03)) >> 2); + uint64_t r2 = (( (l1 & BYTE_VEC(0x03)) + + (l2 & BYTE_VEC(0x03)) + + (l3 & BYTE_VEC(0x03)) + + (l4 & BYTE_VEC(0x03)) + + BYTE_VEC(0x02)) >> 2) & BYTE_VEC(0x03); return r1 + r2; } +#endif -#define PIXOPNAME(suffix) put ## suffix -#define BTYPE UINT8 -#define AVG2 avg2 -#define AVG4 avg4 -#define STORE(l, b) stq(l, b) -#include "pixops.h" -#undef PIXOPNAME -#undef BTYPE -#undef AVG2 -#undef AVG4 -#undef STORE +#define OP(LOAD, STORE) \ + do { \ + STORE(LOAD(pixels), block); \ + pixels += line_size; \ + block += line_size; \ + } while (--h) -#define PIXOPNAME(suffix) put_no_rnd ## suffix -#define BTYPE UINT8 -#define AVG2 avg2_no_rnd -#define AVG4 avg4_no_rnd -#define STORE(l, b) stq(l, b) -#include "pixops.h" -#undef PIXOPNAME -#undef BTYPE -#undef AVG2 -#undef AVG4 -#undef STORE +#define OP_X2(LOAD, STORE) \ + do { \ + uint64_t pix1, pix2; \ + \ + pix1 = LOAD(pixels); \ + pix2 = pix1 >> 8 | ((uint64_t) pixels[8] << 56); \ + STORE(AVG2(pix1, pix2), block); \ + pixels += line_size; \ + block += line_size; \ + } while (--h) -/* The following functions are untested. */ -#if 0 +#define OP_Y2(LOAD, STORE) \ + do { \ + uint64_t pix = LOAD(pixels); \ + do { \ + uint64_t next_pix; \ + \ + pixels += line_size; \ + next_pix = LOAD(pixels); \ + STORE(AVG2(pix, next_pix), block); \ + block += line_size; \ + pix = next_pix; \ + } while (--h); \ + } while (0) + +#define OP_XY2(LOAD, STORE) \ + do { \ + uint64_t pix1 = LOAD(pixels); \ + uint64_t pix2 = pix1 >> 8 | ((uint64_t) pixels[8] << 56); \ + uint64_t pix_l = (pix1 & BYTE_VEC(0x03)) \ + + (pix2 & BYTE_VEC(0x03)); \ + uint64_t pix_h = ((pix1 & ~BYTE_VEC(0x03)) >> 2) \ + + ((pix2 & ~BYTE_VEC(0x03)) >> 2); \ + \ + do { \ + uint64_t npix1, npix2; \ + uint64_t npix_l, npix_h; \ + uint64_t avg; \ + \ + pixels += line_size; \ + npix1 = LOAD(pixels); \ + npix2 = npix1 >> 8 | ((uint64_t) pixels[8] << 56); \ + npix_l = (npix1 & BYTE_VEC(0x03)) \ + + (npix2 & BYTE_VEC(0x03)); \ + npix_h = ((npix1 & ~BYTE_VEC(0x03)) >> 2) \ + + ((npix2 & ~BYTE_VEC(0x03)) >> 2); \ + avg = (((pix_l + npix_l + AVG4_ROUNDER) >> 2) & BYTE_VEC(0x03)) \ + + pix_h + npix_h; \ + STORE(avg, block); \ + \ + block += line_size; \ + pix_l = npix_l; \ + pix_h = npix_h; \ + } while (--h); \ + } while (0) + +#define MAKE_OP(OPNAME, SUFF, OPKIND, STORE) \ +static void OPNAME ## _pixels ## SUFF ## _axp \ + (uint8_t *restrict block, const uint8_t *restrict pixels, \ + int line_size, int h) \ +{ \ + if ((size_t) pixels & 0x7) { \ + OPKIND(uldq, STORE); \ + } else { \ + OPKIND(ldq, STORE); \ + } \ +} -#define PIXOPNAME(suffix) avg ## suffix -#define BTYPE UINT8 +#define PIXOP(OPNAME, STORE) \ + MAKE_OP(OPNAME, , OP, STORE) \ + MAKE_OP(OPNAME, _x2, OP_X2, STORE) \ + MAKE_OP(OPNAME, _y2, OP_Y2, STORE) \ + MAKE_OP(OPNAME, _xy2, OP_XY2, STORE) + +/* Rounding primitives. */ #define AVG2 avg2 #define AVG4 avg4 +#define AVG4_ROUNDER BYTE_VEC(0x02) +#define STORE(l, b) stq(l, b) +PIXOP(put, STORE); + +#undef STORE #define STORE(l, b) stq(AVG2(l, ldq(b)), b); -#include "pixops.h" -#undef PIXOPNAME -#undef BTYPE +PIXOP(avg, STORE); + +/* Not rounding primitives. */ #undef AVG2 #undef AVG4 +#undef AVG4_ROUNDER #undef STORE - -#define PIXOPNAME(suffix) avg_no_rnd ## suffix -#define BTYPE UINT8 #define AVG2 avg2_no_rnd #define AVG4 avg4_no_rnd -#define STORE(l, b) stq(AVG2(l, ldq(b)), b); -#include "pixops.h" -#undef PIXOPNAME -#undef BTYPE -#undef AVG2 -#undef AVG4 -#undef STORE +#define AVG4_ROUNDER BYTE_VEC(0x01) +#define STORE(l, b) stq(l, b) +PIXOP(put_no_rnd, STORE); -#define PIXOPNAME(suffix) sub ## suffix -#define BTYPE DCTELEM -#define AVG2 avg2 -#define AVG4 avg4 -#define STORE(l, block) do { \ - UINT64 xxx = l; \ - (block)[0] -= (xxx >> 0) & 0xff; \ - (block)[1] -= (xxx >> 8) & 0xff; \ - (block)[2] -= (xxx >> 16) & 0xff; \ - (block)[3] -= (xxx >> 24) & 0xff; \ - (block)[4] -= (xxx >> 32) & 0xff; \ - (block)[5] -= (xxx >> 40) & 0xff; \ - (block)[6] -= (xxx >> 48) & 0xff; \ - (block)[7] -= (xxx >> 56) & 0xff; \ -} while (0) -#include "pixops.h" -#undef PIXOPNAME -#undef BTYPE -#undef AVG2 -#undef AVG4 #undef STORE - -#endif +#define STORE(l, b) stq(AVG2(l, ldq(b)), b); +PIXOP(avg_no_rnd, STORE); void dsputil_init_alpha(void) { - put_pixels_tab[0] = put_pixels_axp; + put_pixels_tab[0] = put_pixels_axp_asm; put_pixels_tab[1] = put_pixels_x2_axp; put_pixels_tab[2] = put_pixels_y2_axp; put_pixels_tab[3] = put_pixels_xy2_axp; - put_no_rnd_pixels_tab[0] = put_pixels_axp; + put_no_rnd_pixels_tab[0] = put_pixels_axp_asm; put_no_rnd_pixels_tab[1] = put_no_rnd_pixels_x2_axp; put_no_rnd_pixels_tab[2] = put_no_rnd_pixels_y2_axp; put_no_rnd_pixels_tab[3] = put_no_rnd_pixels_xy2_axp; + avg_pixels_tab[0] = avg_pixels_axp; + avg_pixels_tab[1] = avg_pixels_x2_axp; + avg_pixels_tab[2] = avg_pixels_y2_axp; + avg_pixels_tab[3] = avg_pixels_xy2_axp; + + avg_no_rnd_pixels_tab[0] = avg_no_rnd_pixels_axp; + avg_no_rnd_pixels_tab[1] = avg_no_rnd_pixels_x2_axp; + avg_no_rnd_pixels_tab[2] = avg_no_rnd_pixels_y2_axp; + avg_no_rnd_pixels_tab[3] = avg_no_rnd_pixels_xy2_axp; + + clear_blocks = clear_blocks_axp; + /* amask clears all bits that correspond to present features. */ if (amask(AMASK_MVI) == 0) { put_pixels_clamped = put_pixels_clamped_mvi_asm; diff --git a/src/libffmpeg/libavcodec/alpha/dsputil_alpha_asm.S b/src/libffmpeg/libavcodec/alpha/dsputil_alpha_asm.S new file mode 100644 index 000000000..5349e443c --- /dev/null +++ b/src/libffmpeg/libavcodec/alpha/dsputil_alpha_asm.S @@ -0,0 +1,306 @@ +/* + * Alpha optimized DSP utils + * Copyright (c) 2002 Falk Hueffner <falk@debian.org> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +/* + * These functions are scheduled for pca56. They should work + * reasonably on ev6, though. + */ + +#include "regdef.h" +#ifdef HAVE_AV_CONFIG_H +#include "config.h" +#endif + +/* Some nicer register names. */ +#define ta t10 +#define tb t11 +#define tc t12 +#define td AT +/* Danger: these overlap with the argument list and the return value */ +#define te a5 +#define tf a4 +#define tg a3 +#define th v0 + + .set noat + .set noreorder + .arch pca56 + .text + +/************************************************************************ + * void put_pixels_axp_asm(uint8_t *block, const uint8_t *pixels, + * int line_size, int h) + */ + .align 6 + .globl put_pixels_axp_asm + .ent put_pixels_axp_asm +put_pixels_axp_asm: + .frame sp, 0, ra + .prologue 0 + +#ifdef HAVE_GPROF + lda AT, _mcount + jsr AT, (AT), _mcount +#endif + + and a1, 7, t0 + beq t0, $aligned + + .align 4 +$unaligned: + ldq_u t0, 0(a1) + ldq_u t1, 8(a1) + addq a1, a2, a1 + nop + + ldq_u t2, 0(a1) + ldq_u t3, 8(a1) + addq a1, a2, a1 + nop + + ldq_u t4, 0(a1) + ldq_u t5, 8(a1) + addq a1, a2, a1 + nop + + ldq_u t6, 0(a1) + ldq_u t7, 8(a1) + extql t0, a1, t0 + addq a1, a2, a1 + + extqh t1, a1, t1 + addq a0, a2, t8 + extql t2, a1, t2 + addq t8, a2, t9 + + extqh t3, a1, t3 + addq t9, a2, ta + extql t4, a1, t4 + or t0, t1, t0 + + extqh t5, a1, t5 + or t2, t3, t2 + extql t6, a1, t6 + or t4, t5, t4 + + extqh t7, a1, t7 + or t6, t7, t6 + stq t0, 0(a0) + stq t2, 0(t8) + + stq t4, 0(t9) + subq a3, 4, a3 + stq t6, 0(ta) + addq ta, a2, a0 + + bne a3, $unaligned + ret + + .align 4 +$aligned: + ldq t0, 0(a1) + addq a1, a2, a1 + ldq t1, 0(a1) + addq a1, a2, a1 + + ldq t2, 0(a1) + addq a1, a2, a1 + ldq t3, 0(a1) + addq a1, a2, a1 + + ldq t4, 0(a1) + addq a1, a2, a1 + ldq t5, 0(a1) + addq a1, a2, a1 + + ldq t6, 0(a1) + addq a1, a2, a1 + ldq t7, 0(a1) + addq a1, a2, a1 + + addq a0, a2, t8 + stq t0, 0(a0) + addq t8, a2, t9 + stq t1, 0(t8) + + addq t9, a2, ta + stq t2, 0(t9) + addq ta, a2, tb + stq t3, 0(ta) + + addq tb, a2, tc + stq t4, 0(tb) + addq tc, a2, td + stq t5, 0(tc) + + addq td, a2, te + stq t6, 0(td) + addq te, a2, a0 + stq t7, 0(te) + + subq a3, 8, a3 + bne a3, $aligned + + ret + .end put_pixels_axp_asm + +/************************************************************************ + * void put_pixels_clamped_mvi_asm(const DCTELEM *block, uint8_t *pixels, + * int line_size) + */ + .align 6 + .globl put_pixels_clamped_mvi_asm + .ent put_pixels_clamped_mvi_asm +put_pixels_clamped_mvi_asm: + .frame sp, 0, ra + .prologue 0 + +#ifdef HAVE_GPROF + lda AT, _mcount + jsr AT, (AT), _mcount +#endif + + lda t8, -1 + lda t9, 8 # loop counter + zap t8, 0xaa, t8 # 00ff00ff00ff00ff + + .align 4 +1: ldq t0, 0(a0) + ldq t1, 8(a0) + ldq t2, 16(a0) + ldq t3, 24(a0) + + maxsw4 t0, zero, t0 + subq t9, 2, t9 + maxsw4 t1, zero, t1 + lda a0, 32(a0) + + maxsw4 t2, zero, t2 + addq a1, a2, ta + maxsw4 t3, zero, t3 + minsw4 t0, t8, t0 + + minsw4 t1, t8, t1 + minsw4 t2, t8, t2 + minsw4 t3, t8, t3 + pkwb t0, t0 + + pkwb t1, t1 + pkwb t2, t2 + pkwb t3, t3 + stl t0, 0(a1) + + stl t1, 4(a1) + addq ta, a2, a1 + stl t2, 0(ta) + stl t3, 4(ta) + + bne t9, 1b + ret + .end put_pixels_clamped_mvi_asm + +/************************************************************************ + * void add_pixels_clamped_mvi_asm(const DCTELEM *block, uint8_t *pixels, + * int line_size) + */ + .align 6 + .globl add_pixels_clamped_mvi_asm + .ent add_pixels_clamped_mvi_asm +add_pixels_clamped_mvi_asm: + .frame sp, 0, ra + .prologue 0 + +#ifdef HAVE_GPROF + lda AT, _mcount + jsr AT, (AT), _mcount +#endif + + lda t1, -1 + lda th, 8 + zap t1, 0x33, tg + nop + + srl tg, 1, t0 + xor tg, t0, tg # 0x8000800080008000 + zap t1, 0xaa, tf # 0x00ff00ff00ff00ff + + .align 4 +1: ldl t1, 0(a1) # pix0 (try to hit cache line soon) + ldl t4, 4(a1) # pix1 + addq a1, a2, te # pixels += line_size + ldq t0, 0(a0) # shorts0 + + ldl t7, 0(te) # pix2 (try to hit cache line soon) + ldl ta, 4(te) # pix3 + ldq t3, 8(a0) # shorts1 + ldq t6, 16(a0) # shorts2 + + ldq t9, 24(a0) # shorts3 + unpkbw t1, t1 # 0 0 (quarter/op no.) + and t0, tg, t2 # 0 1 + unpkbw t4, t4 # 1 0 + + bic t0, tg, t0 # 0 2 + unpkbw t7, t7 # 2 0 + and t3, tg, t5 # 1 1 + addq t0, t1, t0 # 0 3 + + xor t0, t2, t0 # 0 4 + unpkbw ta, ta # 3 0 + and t6, tg, t8 # 2 1 + maxsw4 t0, zero, t0 # 0 5 + + bic t3, tg, t3 # 1 2 + bic t6, tg, t6 # 2 2 + minsw4 t0, tf, t0 # 0 6 + addq t3, t4, t3 # 1 3 + + pkwb t0, t0 # 0 7 + xor t3, t5, t3 # 1 4 + maxsw4 t3, zero, t3 # 1 5 + addq t6, t7, t6 # 2 3 + + xor t6, t8, t6 # 2 4 + and t9, tg, tb # 3 1 + minsw4 t3, tf, t3 # 1 6 + bic t9, tg, t9 # 3 2 + + maxsw4 t6, zero, t6 # 2 5 + addq t9, ta, t9 # 3 3 + stl t0, 0(a1) # 0 8 + minsw4 t6, tf, t6 # 2 6 + + xor t9, tb, t9 # 3 4 + maxsw4 t9, zero, t9 # 3 5 + lda a0, 32(a0) # block += 16; + pkwb t3, t3 # 1 7 + + minsw4 t9, tf, t9 # 3 6 + subq th, 2, th + pkwb t6, t6 # 2 7 + pkwb t9, t9 # 3 7 + + stl t3, 4(a1) # 1 8 + addq te, a2, a1 # pixels += line_size + stl t6, 0(te) # 2 8 + stl t9, 4(te) # 3 8 + + bne th, 1b + ret + .end add_pixels_clamped_mvi_asm diff --git a/src/libffmpeg/libavcodec/alpha/mpegvideo_alpha.c b/src/libffmpeg/libavcodec/alpha/mpegvideo_alpha.c index eb1997eee..0be327079 100644 --- a/src/libffmpeg/libavcodec/alpha/mpegvideo_alpha.c +++ b/src/libffmpeg/libavcodec/alpha/mpegvideo_alpha.c @@ -23,69 +23,75 @@ extern UINT8 zigzag_end[64]; -static void dct_unquantize_h263_axp(MpegEncContext *s, - DCTELEM *block, int n, int qscale) +static void dct_unquantize_h263_axp(MpegEncContext *s, DCTELEM *block, + int n, int qscale) { - int i, level; - UINT64 qmul, qadd; + int i, n_coeffs; + uint64_t qmul, qadd; + uint64_t correction; + DCTELEM *orig_block = block; + DCTELEM block0; - ASM_ACCEPT_MVI; - if (s->mb_intra) { - if (n < 4) - block[0] = block[0] * s->y_dc_scale; - else - block[0] = block[0] * s->c_dc_scale; - /* Catch up to aligned point. */ - qmul = s->qscale << 1; - qadd = (s->qscale - 1) | 1; - for (i = 1; i < 4; ++i) { - level = block[i]; - if (level) { - if (level < 0) { - level = level * qmul - qadd; - } else { - level = level * qmul + qadd; - } - block[i] = level; - } - } - block += 4; - i = 60 / 4; + if (!s->h263_aic) { + if (n < 4) + block0 = block[0] * s->y_dc_scale; + else + block0 = block[0] * s->c_dc_scale; + } + n_coeffs = 64; // does not always use zigzag table } else { - i = zigzag_end[s->block_last_index[n]] / 4; + n_coeffs = zigzag_end[s->block_last_index[n]]; } - qmul = s->qscale << 1; + + qmul = qscale << 1; qadd = WORD_VEC((qscale - 1) | 1); - do { - UINT64 levels, negmask, zeromask, corr; - levels = ldq(block); - if (levels == 0) - continue; - zeromask = cmpbge(0, levels); - zeromask &= zeromask >> 1; - /* Negate all negative words. */ - negmask = maxsw4(levels, WORD_VEC(0xffff)); /* negative -> ffff (-1) */ - negmask = minsw4(negmask, 0); /* positive -> 0000 (0) */ - corr = negmask & WORD_VEC(0x0001); /* twos-complement correction */ - levels ^= negmask; - levels += corr; + /* This mask kills spill from negative subwords to the next subword. */ + correction = WORD_VEC((qmul - 1) + 1); /* multiplication / addition */ + + for(i = 0; i < n_coeffs; block += 4, i += 4) { + uint64_t levels, negmask, zeros, add; + + levels = ldq(block); + if (levels == 0) + continue; + +#ifdef __alpha_max__ + /* I don't think the speed difference justifies runtime + detection. */ + ASM_ACCEPT_MVI; + negmask = maxsw4(levels, -1); /* negative -> ffff (-1) */ + negmask = minsw4(negmask, 0); /* positive -> 0000 (0) */ +#else + negmask = cmpbge(WORD_VEC(0x7fff), levels); + negmask &= (negmask >> 1) | (1 << 7); + negmask = zap(-1, negmask); +#endif + + zeros = cmpbge(0, levels); + zeros &= zeros >> 1; + /* zeros |= zeros << 1 is not needed since qadd <= 255, so + zapping the lower byte suffices. */ - levels = levels * qmul; - levels += zap(qadd, zeromask); + levels *= qmul; + levels -= correction & (negmask << 16); - /* Re-negate negative words. */ - levels -= corr; - levels ^= negmask; + /* Negate qadd for negative levels. */ + add = qadd ^ negmask; + add += WORD_VEC(0x0001) & negmask; + /* Set qadd to 0 for levels == 0. */ + add = zap(add, zeros); - stq(levels, block); - } while (block += 4, --i); + levels += add; + + stq(levels, block); + } + + if (s->mb_intra && !s->h263_aic) + orig_block[0] = block0; } void MPV_common_init_axp(MpegEncContext *s) { - if (amask(AMASK_MVI) == 0) { - if (s->out_format == FMT_H263) - s->dct_unquantize = dct_unquantize_h263_axp; - } + s->dct_unquantize_h263 = dct_unquantize_h263_axp; } diff --git a/src/libffmpeg/libavcodec/alpha/regdef.h b/src/libffmpeg/libavcodec/alpha/regdef.h new file mode 100644 index 000000000..7e7fc06b2 --- /dev/null +++ b/src/libffmpeg/libavcodec/alpha/regdef.h @@ -0,0 +1,45 @@ +/* Some BSDs don't seem to have regdef.h... sigh */ +#ifndef alpha_regdef_h +#define alpha_regdef_h + +#define v0 $0 /* function return value */ + +#define t0 $1 /* temporary registers (caller-saved) */ +#define t1 $2 +#define t2 $3 +#define t3 $4 +#define t4 $5 +#define t5 $6 +#define t6 $7 +#define t7 $8 + +#define s0 $9 /* saved-registers (callee-saved registers) */ +#define s1 $10 +#define s2 $11 +#define s3 $12 +#define s4 $13 +#define s5 $14 +#define s6 $15 +#define fp s6 /* frame-pointer (s6 in frame-less procedures) */ + +#define a0 $16 /* argument registers (caller-saved) */ +#define a1 $17 +#define a2 $18 +#define a3 $19 +#define a4 $20 +#define a5 $21 + +#define t8 $22 /* more temps (caller-saved) */ +#define t9 $23 +#define t10 $24 +#define t11 $25 +#define ra $26 /* return address register */ +#define t12 $27 + +#define pv t12 /* procedure-variable register */ +#define AT $at /* assembler temporary */ +#define gp $29 /* global pointer */ +#define sp $30 /* stack pointer */ +#define zero $31 /* reads as zero, writes are noops */ + +#endif /* alpha_regdef_h */ diff --git a/src/libffmpeg/libavcodec/avcodec.h b/src/libffmpeg/libavcodec/avcodec.h index d9775db52..ceb38dba4 100644 --- a/src/libffmpeg/libavcodec/avcodec.h +++ b/src/libffmpeg/libavcodec/avcodec.h @@ -5,8 +5,8 @@ #define LIBAVCODEC_VERSION_INT 0x000406 #define LIBAVCODEC_VERSION "0.4.6" -#define LIBAVCODEC_BUILD 4614 -#define LIBAVCODEC_BUILD_STR "4614" +#define LIBAVCODEC_BUILD 4617 +#define LIBAVCODEC_BUILD_STR "4617" enum CodecID { CODEC_ID_NONE, @@ -26,6 +26,7 @@ enum CodecID { CODEC_ID_WMV2, CODEC_ID_H263P, CODEC_ID_H263I, + CODEC_ID_SVQ1, /* various pcm "codecs" */ CODEC_ID_PCM_S16LE, @@ -53,6 +54,7 @@ enum PixelFormat { PIX_FMT_BGR24, PIX_FMT_YUV422P, PIX_FMT_YUV444P, + PIX_FMT_YUV410P }; /* currently unused, may be used if 24/32 bits samples ever supported */ @@ -98,12 +100,14 @@ static const int Motion_Est_QTab[] = { ME_ZERO, ME_PHODS, ME_LOG, #define CODEC_FLAG_PASS1 0x0200 /* use internal 2pass ratecontrol in first pass mode */ #define CODEC_FLAG_PASS2 0x0400 /* use internal 2pass ratecontrol in second pass mode */ #define CODEC_FLAG_EXTERN_HUFF 0x1000 /* use external huffman table (for mjpeg) */ -#define CODEC_FLAG_GRAY 0x2000 /* only decode/encode grayscale */ - +#define CODEC_FLAG_GRAY 0x2000 /* only decode/encode grayscale */ +#define CODEC_FLAG_EMU_EDGE 0x4000/* dont draw edges */ +#define CODEC_FLAG_DR1 0x8000 /* dr1 */ /* codec capabilities */ /* decoder can use draw_horiz_band callback */ #define CODEC_CAP_DRAW_HORIZ_BAND 0x0001 +#define CODEC_CAP_DR1 0x0002 /* direct rendering method 1 */ #define FRAME_RATE_BASE 10000 @@ -246,8 +250,20 @@ typedef struct AVCodecContext { #define MBC 128 #define MBR 96 #endif - int *quant_store; /* field for communicating with external postprocessing */ +#define QP_TYPE int //FIXME note xxx this might be changed to int8_t + + QP_TYPE *quant_store; /* field for communicating with external postprocessing */ unsigned qstride; + + uint8_t *dr_buffer[3]; + int dr_stride; + void *dr_opaque_frame; + void (*get_buffer_callback)(struct AVCodecContext *c, int width, int height, int pict_type); + + int has_b_frames; // is 1 if the decoded stream contains b frames + int dr_uvstride; + int dr_ip_buffer_count; + //FIXME this should be reordered after kabis API is finished ... /* Note: Below are located reserved fields for further usage @@ -265,19 +281,18 @@ typedef struct AVCodecContext { flt_res6,flt_res7,flt_res8,flt_res9,flt_res10,flt_res11; void *ptr_res0,*ptr_res1,*ptr_res2,*ptr_res3,*ptr_res4,*ptr_res5, - *ptr_res6,*ptr_res7,*ptr_res8,*ptr_res9,*ptr_res10,*ptr_res11; + *ptr_res6; unsigned long int ul_res0,ul_res1,ul_res2,ul_res3,ul_res4,ul_res5, ul_res6,ul_res7,ul_res8,ul_res9,ul_res10,ul_res11,ul_res12; unsigned int - ui_res0,ui_res1,ui_res2,ui_res3,ui_res4,ui_res5, - ui_res6; + ui_res0,ui_res1,ui_res2; unsigned short int us_res0,us_res1,us_res2,us_res3,us_res4,us_res5, us_res6,us_res7,us_res8,us_res9,us_res10,us_res11,us_res12; unsigned char uc_res0,uc_res1,uc_res2,uc_res3,uc_res4,uc_res5, - uc_res6,uc_res7,uc_res8,uc_res9,uc_res10,uc_res11,uc_res12; + uc_res6,uc_res7,uc_res8,uc_res9,uc_res10,uc_res11,uc_res12; } AVCodecContext; typedef struct AVCodec { @@ -288,7 +303,7 @@ typedef struct AVCodec { int (*init)(AVCodecContext *); int (*encode)(AVCodecContext *, UINT8 *buf, int buf_size, void *data); int (*close)(AVCodecContext *); - int (*decode)(AVCodecContext *, void *outdata, int *outdata_size, + int (*decode)(AVCodecContext *, void *outdata, int *outdata_size, UINT8 *buf, int buf_size); int capabilities; struct AVCodec *next; @@ -342,6 +357,7 @@ extern AVCodec wmv2_decoder; extern AVCodec mpeg_decoder; extern AVCodec h263i_decoder; extern AVCodec rv10_decoder; +extern AVCodec svq1_decoder; extern AVCodec mjpeg_decoder; extern AVCodec mp2_decoder; extern AVCodec mp3_decoder; diff --git a/src/libffmpeg/libavcodec/common.c b/src/libffmpeg/libavcodec/common.c index 571de1afc..63d17b6c2 100644 --- a/src/libffmpeg/libavcodec/common.c +++ b/src/libffmpeg/libavcodec/common.c @@ -18,7 +18,7 @@ * * alternative bitstream reader & writer by Michael Niedermayer <michaelni@gmx.at> */ -#include "common.h" +#include "avcodec.h" void init_put_bits(PutBitContext *s, UINT8 *buffer, int buffer_size, @@ -118,101 +118,39 @@ void put_string(PutBitContext * pbc, char *s) /* bit input functions */ -void init_get_bits(GetBitContext *s, +void init_get_bits(GetBitContext *s, UINT8 *buffer, int buffer_size) { -#ifdef ALT_BITSTREAM_READER - s->index=0; s->buffer= buffer; -#else - s->buf = buffer; - s->buf_ptr = buffer; - s->buf_end = buffer + buffer_size; - s->bit_cnt = 0; - s->bit_buf = 0; - while (s->buf_ptr < s->buf_end && - s->bit_cnt < 32) { - s->bit_buf |= (*s->buf_ptr++ << (24 - s->bit_cnt)); - s->bit_cnt += 8; - } -#endif s->size= buffer_size; -} - -#ifndef ALT_BITSTREAM_READER -/* n must be >= 1 and <= 32 */ -/* also true: n > s->bit_cnt */ -unsigned int get_bits_long(GetBitContext *s, int n) -{ - unsigned int val; - int bit_cnt; - unsigned int bit_buf; - -#ifdef STATS - st_bit_counts[st_current_index] += n; + s->buffer_end= buffer + buffer_size; +#ifdef ALT_BITSTREAM_READER + s->index=0; +#elif defined LIBMPEG2_BITSTREAM_READER + s->buffer_ptr = buffer; + s->bit_count = 16; + s->cache = 0; +#elif defined A32_BITSTREAM_READER + s->buffer_ptr = (uint32_t*)buffer; + s->bit_count = 32; + s->cache0 = 0; + s->cache1 = 0; #endif - - bit_buf = s->bit_buf; - bit_cnt = s->bit_cnt - n; - -// if (bit_cnt >= 0) { -// val = bit_buf >> (32 - n); -// bit_buf <<= n; -// } else { - UINT8 *buf_ptr; - val = bit_buf >> (32 - n); - buf_ptr = s->buf_ptr; - buf_ptr += 4; - /* handle common case: we can read everything */ - if (buf_ptr <= s->buf_end) { -#ifdef ARCH_X86 - bit_buf = bswap_32(*((unsigned long*)(&buf_ptr[-4]))); -#else - bit_buf = (buf_ptr[-4] << 24) | - (buf_ptr[-3] << 16) | - (buf_ptr[-2] << 8) | - (buf_ptr[-1]); -#endif - val |= bit_buf >> (32 + bit_cnt); - bit_buf <<= - bit_cnt; - bit_cnt += 32; - } else { - buf_ptr -= 4; - bit_buf = 0; - if (buf_ptr < s->buf_end) - bit_buf |= *buf_ptr++ << 24; - if (buf_ptr < s->buf_end) - bit_buf |= *buf_ptr++ << 16; - if (buf_ptr < s->buf_end) - bit_buf |= *buf_ptr++ << 8; - if (buf_ptr < s->buf_end) - bit_buf |= *buf_ptr++; - - val |= bit_buf >> (32 + bit_cnt); - bit_buf <<= - bit_cnt; - bit_cnt += 8*(buf_ptr - s->buf_ptr); - if(bit_cnt<0) bit_cnt=0; - } - s->buf_ptr = buf_ptr; + OPEN_READER(re, s) + UPDATE_CACHE(re, s) +// UPDATE_CACHE(re, s) + CLOSE_READER(re, s) } - s->bit_buf = bit_buf; - s->bit_cnt = bit_cnt; - return val; -} +#ifdef A32_BITSTREAM_READER + s->cache1 = 0; #endif +} void align_get_bits(GetBitContext *s) { -#ifdef ALT_BITSTREAM_READER - s->index= (s->index + 7) & (~7); -#else - int n; - n = s->bit_cnt & 7; - if (n > 0) { - get_bits(s, n); - } -#endif + int n= (-get_bits_count(s)) & 7; + if(n) skip_bits(s, n); } int check_marker(GetBitContext *s, char *msg) @@ -223,55 +161,6 @@ int check_marker(GetBitContext *s, char *msg) return bit; } -#ifndef ALT_BITSTREAM_READER -/* This function is identical to get_bits_long(), the */ -/* only diference is that it doesn't touch the buffer */ -/* it is usefull to see the buffer. */ - -unsigned int show_bits_long(GetBitContext *s, int n) -{ - unsigned int val; - int bit_cnt; - unsigned int bit_buf; - UINT8 *buf_ptr; - - bit_buf = s->bit_buf; - bit_cnt = s->bit_cnt - n; - - val = bit_buf >> (32 - n); - buf_ptr = s->buf_ptr; - buf_ptr += 4; - - /* handle common case: we can read everything */ - if (buf_ptr <= s->buf_end) { -#ifdef ARCH_X86 - bit_buf = bswap_32(*((unsigned long*)(&buf_ptr[-4]))); -#else - bit_buf = (buf_ptr[-4] << 24) | - (buf_ptr[-3] << 16) | - (buf_ptr[-2] << 8) | - (buf_ptr[-1]); -#endif - } else { - buf_ptr -= 4; - bit_buf = 0; - if (buf_ptr < s->buf_end) - bit_buf |= *buf_ptr++ << 24; - if (buf_ptr < s->buf_end) - bit_buf |= *buf_ptr++ << 16; - if (buf_ptr < s->buf_end) - bit_buf |= *buf_ptr++ << 8; - if (buf_ptr < s->buf_end) - bit_buf |= *buf_ptr++; - } - val |= bit_buf >> (32 + bit_cnt); - bit_buf <<= - bit_cnt; - bit_cnt += 32; - - return val; -} -#endif - /* VLC decoding */ //#define DEBUG_VLC @@ -300,18 +189,15 @@ static int alloc_table(VLC *vlc, int size) vlc->table_size += size; if (vlc->table_size > vlc->table_allocated) { vlc->table_allocated += (1 << vlc->bits); - vlc->table_bits = realloc(vlc->table_bits, - sizeof(INT8) * vlc->table_allocated); - vlc->table_codes = realloc(vlc->table_codes, - sizeof(INT16) * vlc->table_allocated); - if (!vlc->table_bits || - !vlc->table_codes) + vlc->table = realloc(vlc->table, + sizeof(VLC_TYPE) * 2 * vlc->table_allocated); + if (!vlc->table) return -1; } return index; } -static int build_table(VLC *vlc, int table_nb_bits, +static int build_table(VLC *vlc, int table_nb_bits, int nb_codes, const void *bits, int bits_wrap, int bits_size, const void *codes, int codes_wrap, int codes_size, @@ -319,23 +205,21 @@ static int build_table(VLC *vlc, int table_nb_bits, { int i, j, k, n, table_size, table_index, nb, n1, index; UINT32 code; - INT8 *table_bits; - INT16 *table_codes; + VLC_TYPE (*table)[2]; table_size = 1 << table_nb_bits; table_index = alloc_table(vlc, table_size); #ifdef DEBUG_VLC - printf("new table index=%d size=%d code_prefix=%x n=%d\n", + printf("new table index=%d size=%d code_prefix=%x n=%d\n", table_index, table_size, code_prefix, n_prefix); #endif if (table_index < 0) return -1; - table_bits = &vlc->table_bits[table_index]; - table_codes = &vlc->table_codes[table_index]; + table = &vlc->table[table_index]; for(i=0;i<table_size;i++) { - table_bits[i] = 0; - table_codes[i] = -1; + table[i][1] = 0; //bits + table[i][0] = -1; //codes } /* first pass: map codes and compute auxillary table sizes */ @@ -360,12 +244,12 @@ static int build_table(VLC *vlc, int table_nb_bits, printf("%4x: code=%d n=%d\n", j, i, n); #endif - if (table_bits[j] != 0) { + if (table[j][1] /*bits*/ != 0) { fprintf(stderr, "incorrect codes\n"); exit(1); } - table_bits[j] = n; - table_codes[j] = i; + table[j][1] = n; //bits + table[j][0] = i; //code j++; } } else { @@ -376,22 +260,22 @@ static int build_table(VLC *vlc, int table_nb_bits, j, n); #endif /* compute table size */ - n1 = -table_bits[j]; + n1 = -table[j][1]; //bits if (n > n1) n1 = n; - table_bits[j] = -n1; + table[j][1] = -n1; //bits } } } /* second pass : fill auxillary tables recursively */ for(i=0;i<table_size;i++) { - n = table_bits[i]; + n = table[i][1]; //bits if (n < 0) { n = -n; if (n > table_nb_bits) { n = table_nb_bits; - table_bits[i] = -n; + table[i][1] = -n; //bits } index = build_table(vlc, n, nb_codes, bits, bits_wrap, bits_size, @@ -401,9 +285,8 @@ static int build_table(VLC *vlc, int table_nb_bits, if (index < 0) return -1; /* note: realloc has been done, so reload tables */ - table_bits = &vlc->table_bits[table_index]; - table_codes = &vlc->table_codes[table_index]; - table_codes[i] = index; + table = &vlc->table[table_index]; + table[i][0] = index; //code } } return table_index; @@ -436,8 +319,7 @@ int init_vlc(VLC *vlc, int nb_bits, int nb_codes, const void *codes, int codes_wrap, int codes_size) { vlc->bits = nb_bits; - vlc->table_bits = NULL; - vlc->table_codes = NULL; + vlc->table = NULL; vlc->table_allocated = 0; vlc->table_size = 0; #ifdef DEBUG_VLC @@ -448,8 +330,7 @@ int init_vlc(VLC *vlc, int nb_bits, int nb_codes, bits, bits_wrap, bits_size, codes, codes_wrap, codes_size, 0, 0) < 0) { - av_free(vlc->table_bits); - av_free(vlc->table_codes); + av_free(vlc->table); return -1; } return 0; @@ -458,8 +339,7 @@ int init_vlc(VLC *vlc, int nb_bits, int nb_codes, void free_vlc(VLC *vlc) { - av_free(vlc->table_bits); - av_free(vlc->table_codes); + av_free(vlc->table); } int ff_gcd(int a, int b){ diff --git a/src/libffmpeg/libavcodec/common.h b/src/libffmpeg/libavcodec/common.h index a6e7fbe1d..93b91d3e8 100644 --- a/src/libffmpeg/libavcodec/common.h +++ b/src/libffmpeg/libavcodec/common.h @@ -10,10 +10,10 @@ //#define ALT_BITSTREAM_WRITER //#define ALIGNED_BITSTREAM_WRITER -//#define ALT_BITSTREAM_READER -//#define ALIGNED_BITSTREAM -#define FAST_GET_FIRST_VLC -//#define DUMP_STREAM // only works with the ALT_BITSTREAM_READER + +#define ALT_BITSTREAM_READER +//#define LIBMPEG2_BITSTREAM_READER +//#define A32_BITSTREAM_READER #ifdef HAVE_AV_CONFIG_H /* only include the following when compiling package */ @@ -31,6 +31,17 @@ #endif /* HAVE_AV_CONFIG_H */ +/* Suppress restrict if it was not defined in config.h. */ +#ifndef restrict +#define restrict +#endif + +#if defined(__GNUC__) && (__GNUC__ > 3 || __GNUC__ == 3 && __GNUC_MINOR__ > 0) +#define always_inline __attribute__((always_inline)) inline +#else +#define always_inline inline +#endif + #ifdef CONFIG_WIN32 /* windows */ @@ -160,6 +171,27 @@ inline void dprintf(const char* fmt,...) {} #define MAX(a,b) ((a) > (b) ? (a) : (b)) #define MIN(a,b) ((a) > (b) ? (b) : (a)) +#ifdef ARCH_X86 +// avoid +32 for shift optimization (gcc should do that ...) +static inline int32_t NEG_SSR32( int32_t a, int8_t s){ + asm ("sarl %1, %0\n\t" + : "+r" (a) + : "ic" ((uint8_t)(-s)) + ); + return a; +} +static inline uint32_t NEG_USR32(uint32_t a, int8_t s){ + asm ("shrl %1, %0\n\t" + : "+r" (a) + : "ic" ((uint8_t)(-s)) + ); + return a; +} +#else +#define NEG_SSR32(a,s) ((( int32_t)(a))>>(32-(s))) +#define NEG_USR32(a,s) (((uint32_t)(a))>>(32-(s))) +#endif + /* bit output */ struct PutBitContext; @@ -194,26 +226,38 @@ void jflush_put_bits(PutBitContext *s); /* bit input */ typedef struct GetBitContext { + UINT8 *buffer, *buffer_end; #ifdef ALT_BITSTREAM_READER int index; - UINT8 *buffer; -#else - UINT32 bit_buf; - int bit_cnt; - UINT8 *buf, *buf_ptr, *buf_end; +#elif defined LIBMPEG2_BITSTREAM_READER + UINT8 *buffer_ptr; + UINT32 cache; + int bit_count; +#elif defined A32_BITSTREAM_READER + UINT32 *buffer_ptr; + UINT32 cache0; + UINT32 cache1; + int bit_count; #endif int size; } GetBitContext; static inline int get_bits_count(GetBitContext *s); +#define VLC_TYPE INT16 + typedef struct VLC { int bits; - INT16 *table_codes; - INT8 *table_bits; + VLC_TYPE (*table)[2]; // code, bits int table_size, table_allocated; } VLC; +typedef struct RL_VLC_ELEM { + int16_t level; + int8_t len; + uint8_t run; +} RL_VLC_ELEM; + /* used to avoid missaligned exceptions on some archs (alpha, ...) */ #ifdef ARCH_X86 #define unaligned32(a) (*(UINT32*)(a)) @@ -437,227 +481,262 @@ static inline uint8_t* pbBufPtr(PutBitContext *s) #endif } -void init_get_bits(GetBitContext *s, - UINT8 *buffer, int buffer_size); +/* Bitstream reader API docs: +name + abritary name which is used as prefix for the internal variables -#ifndef ALT_BITSTREAM_READER -unsigned int get_bits_long(GetBitContext *s, int n); -unsigned int show_bits_long(GetBitContext *s, int n); -#endif +gb + getbitcontext + +OPEN_READER(name, gb) + loads gb into local variables + +CLOSE_READER(name, gb) + stores local vars in gb + +UPDATE_CACHE(name, gb) + refills the internal cache from the bitstream + after this call at least MIN_CACHE_BITS will be available, + +GET_CACHE(name, gb) + will output the contents of the internal cache, next bit is MSB of 32 or 64 bit (FIXME 64bit) + +SHOW_UBITS(name, gb, num) + will return the nest num bits + +SHOW_SBITS(name, gb, num) + will return the nest num bits and do sign extension + +SKIP_BITS(name, gb, num) + will skip over the next num bits + note, this is equinvalent to SKIP_CACHE; SKIP_COUNTER + +SKIP_CACHE(name, gb, num) + will remove the next num bits from the cache (note SKIP_COUNTER MUST be called before UPDATE_CACHE / CLOSE_READER) + +SKIP_COUNTER(name, gb, num) + will increment the internal bit counter (see SKIP_CACHE & SKIP_BITS) + +LAST_SKIP_CACHE(name, gb, num) + will remove the next num bits from the cache if it is needed for UPDATE_CACHE otherwise it will do nothing + +LAST_SKIP_BITS(name, gb, num) + is equinvalent to SKIP_LAST_CACHE; SKIP_COUNTER + +for examples see get_bits, show_bits, skip_bits, get_vlc +*/ -static inline unsigned int get_bits(GetBitContext *s, int n){ #ifdef ALT_BITSTREAM_READER -#ifdef ALIGNED_BITSTREAM - int index= s->index; - uint32_t result1= be2me_32( ((uint32_t *)s->buffer)[index>>5] ); - uint32_t result2= be2me_32( ((uint32_t *)s->buffer)[(index>>5) + 1] ); -#ifdef ARCH_X86 - asm ("shldl %%cl, %2, %0\n\t" - : "=r" (result1) - : "0" (result1), "r" (result2), "c" (index)); -#else - result1<<= (index&0x1F); - result2= (result2>>1) >> (31-(index&0x1F)); - result1|= result2; -#endif - result1>>= 32 - n; - index+= n; - s->index= index; - - return result1; -#else //ALIGNED_BITSTREAM - int index= s->index; - uint32_t result= be2me_32( unaligned32( ((uint8_t *)s->buffer)+(index>>3) ) ); +# define MIN_CACHE_BITS 25 - result<<= (index&0x07); - result>>= 32 - n; - index+= n; - s->index= index; -#ifdef DUMP_STREAM - while(n){ - printf("%d", (result>>(n-1))&1); - n--; - } - printf(" "); -#endif - return result; -#endif //!ALIGNED_BITSTREAM -#else //ALT_BITSTREAM_READER - if(s->bit_cnt>=n){ - /* most common case here */ - unsigned int val = s->bit_buf >> (32 - n); - s->bit_buf <<= n; - s->bit_cnt -= n; -#ifdef STATS - st_bit_counts[st_current_index] += n; -#endif - return val; - } - return get_bits_long(s,n); -#endif //!ALT_BITSTREAM_READER +# define OPEN_READER(name, gb)\ + int name##_index= (gb)->index;\ + int name##_cache= 0;\ + +# define CLOSE_READER(name, gb)\ + (gb)->index= name##_index;\ + +# define UPDATE_CACHE(name, gb)\ + name##_cache= be2me_32( unaligned32( ((uint8_t *)(gb)->buffer)+(name##_index>>3) ) ) << (name##_index&0x07);\ + +# define SKIP_CACHE(name, gb, num)\ + name##_cache <<= (num);\ + +// FIXME name? +# define SKIP_COUNTER(name, gb, num)\ + name##_index += (num);\ + +# define SKIP_BITS(name, gb, num)\ + {\ + SKIP_CACHE(name, gb, num)\ + SKIP_COUNTER(name, gb, num)\ + }\ + +# define LAST_SKIP_BITS(name, gb, num) SKIP_COUNTER(name, gb, num) +# define LAST_SKIP_CACHE(name, gb, num) ; + +# define SHOW_UBITS(name, gb, num)\ + NEG_USR32(name##_cache, num) + +# define SHOW_SBITS(name, gb, num)\ + NEG_SSR32(name##_cache, num) + +# define GET_CACHE(name, gb)\ + ((uint32_t)name##_cache) + +static inline int get_bits_count(GetBitContext *s){ + return s->index; } +#elif defined LIBMPEG2_BITSTREAM_READER +//libmpeg2 like reader + +# define MIN_CACHE_BITS 16 + +# define OPEN_READER(name, gb)\ + int name##_bit_count=(gb)->bit_count;\ + int name##_cache= (gb)->cache;\ + uint8_t * name##_buffer_ptr=(gb)->buffer_ptr;\ + +# define CLOSE_READER(name, gb)\ + (gb)->bit_count= name##_bit_count;\ + (gb)->cache= name##_cache;\ + (gb)->buffer_ptr= name##_buffer_ptr;\ + +# define UPDATE_CACHE(name, gb)\ + if(name##_bit_count > 0){\ + name##_cache+= ((name##_buffer_ptr[0]<<8) + name##_buffer_ptr[1]) << name##_bit_count;\ + name##_buffer_ptr+=2;\ + name##_bit_count-= 16;\ + }\ -static inline unsigned int get_bits1(GetBitContext *s){ -#ifdef ALT_BITSTREAM_READER - int index= s->index; - uint8_t result= s->buffer[ index>>3 ]; - result<<= (index&0x07); - result>>= 8 - 1; - index++; - s->index= index; - -#ifdef DUMP_STREAM - printf("%d ", result); -#endif - return result; -#else - if(s->bit_cnt>0){ - /* most common case here */ - unsigned int val = s->bit_buf >> 31; - s->bit_buf <<= 1; - s->bit_cnt--; -#ifdef STATS - st_bit_counts[st_current_index]++; -#endif - return val; - } - return get_bits_long(s,1); -#endif +# define SKIP_CACHE(name, gb, num)\ + name##_cache <<= (num);\ + +# define SKIP_COUNTER(name, gb, num)\ + name##_bit_count += (num);\ + +# define SKIP_BITS(name, gb, num)\ + {\ + SKIP_CACHE(name, gb, num)\ + SKIP_COUNTER(name, gb, num)\ + }\ + +# define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num) +# define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num) + +# define SHOW_UBITS(name, gb, num)\ + NEG_USR32(name##_cache, num) + +# define SHOW_SBITS(name, gb, num)\ + NEG_SSR32(name##_cache, num) + +# define GET_CACHE(name, gb)\ + ((uint32_t)name##_cache) + +static inline int get_bits_count(GetBitContext *s){ + return (s->buffer_ptr - s->buffer)*8 - 16 + s->bit_count; } -/* This function is identical to get_bits(), the only */ -/* diference is that it doesn't touch the buffer */ -/* it is usefull to see the buffer. */ -static inline unsigned int show_bits(GetBitContext *s, int n) -{ -#ifdef ALT_BITSTREAM_READER -#ifdef ALIGNED_BITSTREAM - int index= s->index; - uint32_t result1= be2me_32( ((uint32_t *)s->buffer)[index>>5] ); - uint32_t result2= be2me_32( ((uint32_t *)s->buffer)[(index>>5) + 1] ); +#elif defined A32_BITSTREAM_READER + +# define MIN_CACHE_BITS 32 + +# define OPEN_READER(name, gb)\ + int name##_bit_count=(gb)->bit_count;\ + uint32_t name##_cache0= (gb)->cache0;\ + uint32_t name##_cache1= (gb)->cache1;\ + uint32_t * name##_buffer_ptr=(gb)->buffer_ptr;\ + +# define CLOSE_READER(name, gb)\ + (gb)->bit_count= name##_bit_count;\ + (gb)->cache0= name##_cache0;\ + (gb)->cache1= name##_cache1;\ + (gb)->buffer_ptr= name##_buffer_ptr;\ + +# define UPDATE_CACHE(name, gb)\ + if(name##_bit_count > 0){\ + const uint32_t next= be2me_32( *name##_buffer_ptr );\ + name##_cache0 |= NEG_USR32(next,name##_bit_count);\ + name##_cache1 |= next<<name##_bit_count;\ + name##_buffer_ptr++;\ + name##_bit_count-= 32;\ + }\ + #ifdef ARCH_X86 - asm ("shldl %%cl, %2, %0\n\t" - : "=r" (result1) - : "0" (result1), "r" (result2), "c" (index)); +# define SKIP_CACHE(name, gb, num)\ + asm(\ + "shldl %2, %1, %0 \n\t"\ + "shll %2, %1 \n\t"\ + : "+r" (name##_cache0), "+r" (name##_cache1)\ + : "Ic" ((uint8_t)num)\ + ); #else - result1<<= (index&0x1F); - result2= (result2>>1) >> (31-(index&0x1F)); - result1|= result2; +# define SKIP_CACHE(name, gb, num)\ + name##_cache0 <<= (num);\ + name##_cache0 |= NEG_USR32(name##_cache1,num);\ + name##_cache1 <<= (num); #endif - result1>>= 32 - n; - - return result1; -#else //ALIGNED_BITSTREAM - int index= s->index; - uint32_t result= be2me_32( unaligned32( ((uint8_t *)s->buffer)+(index>>3) ) ); - result<<= (index&0x07); - result>>= 32 - n; - - return result; -#endif //!ALIGNED_BITSTREAM -#else //ALT_BITSTREAM_READER - if(s->bit_cnt>=n) { - /* most common case here */ - unsigned int val = s->bit_buf >> (32 - n); - return val; - } - return show_bits_long(s,n); -#endif //!ALT_BITSTREAM_READER +# define SKIP_COUNTER(name, gb, num)\ + name##_bit_count += (num);\ + +# define SKIP_BITS(name, gb, num)\ + {\ + SKIP_CACHE(name, gb, num)\ + SKIP_COUNTER(name, gb, num)\ + }\ + +# define LAST_SKIP_BITS(name, gb, num) SKIP_BITS(name, gb, num) +# define LAST_SKIP_CACHE(name, gb, num) SKIP_CACHE(name, gb, num) + +# define SHOW_UBITS(name, gb, num)\ + NEG_USR32(name##_cache0, num) + +# define SHOW_SBITS(name, gb, num)\ + NEG_SSR32(name##_cache0, num) + +# define GET_CACHE(name, gb)\ + (name##_cache0) + +static inline int get_bits_count(GetBitContext *s){ + return ((uint8_t*)s->buffer_ptr - s->buffer)*8 - 32 + s->bit_count; } -static inline int show_aligned_bits(GetBitContext *s, int offset, int n) -{ -#ifdef ALT_BITSTREAM_READER -#ifdef ALIGNED_BITSTREAM - int index= (s->index + offset + 7)&(~7); - uint32_t result1= be2me_32( ((uint32_t *)s->buffer)[index>>5] ); - uint32_t result2= be2me_32( ((uint32_t *)s->buffer)[(index>>5) + 1] ); -#ifdef ARCH_X86 - asm ("shldl %%cl, %2, %0\n\t" - : "=r" (result1) - : "0" (result1), "r" (result2), "c" (index)); -#else - result1<<= (index&0x1F); - result2= (result2>>1) >> (31-(index&0x1F)); - result1|= result2; #endif - result1>>= 32 - n; - - return result1; -#else //ALIGNED_BITSTREAM - int index= (s->index + offset + 7)>>3; - uint32_t result= be2me_32( unaligned32( ((uint8_t *)s->buffer)+index ) ); - result>>= 32 - n; - - return result; -#endif //!ALIGNED_BITSTREAM -#else //ALT_BITSTREAM_READER - int index= (get_bits_count(s) + offset + 7)>>3; - uint32_t result= be2me_32( unaligned32( ((uint8_t *)s->buf)+index ) ); +static inline unsigned int get_bits(GetBitContext *s, int n){ + register int tmp; + OPEN_READER(re, s) + UPDATE_CACHE(re, s) + tmp= SHOW_UBITS(re, s, n); + LAST_SKIP_BITS(re, s, n) + CLOSE_READER(re, s) + return tmp; +} - result>>= 32 - n; -//printf(" %X %X %d \n", (int)(((uint8_t *)s->buf)+index ), (int)s->buf_ptr, s->bit_cnt); - return result; -#endif //!ALT_BITSTREAM_READER +static inline unsigned int show_bits(GetBitContext *s, int n){ + register int tmp; + OPEN_READER(re, s) + UPDATE_CACHE(re, s) + tmp= SHOW_UBITS(re, s, n); +// CLOSE_READER(re, s) + return tmp; } static inline void skip_bits(GetBitContext *s, int n){ + //Note gcc seems to optimize this to s->index+=n for the ALT_READER :)) + OPEN_READER(re, s) + UPDATE_CACHE(re, s) + LAST_SKIP_BITS(re, s, n) + CLOSE_READER(re, s) +} + +static inline unsigned int get_bits1(GetBitContext *s){ #ifdef ALT_BITSTREAM_READER - s->index+= n; -#ifdef DUMP_STREAM - { - int result; - s->index-= n; - result= get_bits(s, n); - } -#endif + int index= s->index; + uint8_t result= s->buffer[ index>>3 ]; + result<<= (index&0x07); + result>>= 8 - 1; + index++; + s->index= index; + return result; #else - if(s->bit_cnt>=n){ - /* most common case here */ - s->bit_buf <<= n; - s->bit_cnt -= n; -#ifdef STATS - st_bit_counts[st_current_index] += n; -#endif - } else { - get_bits_long(s,n); - } + return get_bits(s, 1); #endif } -static inline void skip_bits1(GetBitContext *s){ -#ifdef ALT_BITSTREAM_READER - s->index++; -#ifdef DUMP_STREAM - s->index--; - printf("%d ", get_bits1(s)); -#endif -#else - if(s->bit_cnt>0){ - /* most common case here */ - s->bit_buf <<= 1; - s->bit_cnt--; -#ifdef STATS - st_bit_counts[st_current_index]++; -#endif - } else { - get_bits_long(s,1); - } -#endif +static inline unsigned int show_bits1(GetBitContext *s){ + return show_bits(s, 1); } -static inline int get_bits_count(GetBitContext *s) -{ -#ifdef ALT_BITSTREAM_READER - return s->index; -#else - return (s->buf_ptr - s->buf) * 8 - s->bit_cnt; -#endif +static inline void skip_bits1(GetBitContext *s){ + skip_bits(s, 1); } +void init_get_bits(GetBitContext *s, + UINT8 *buffer, int buffer_size); + int check_marker(GetBitContext *s, char *msg); void align_get_bits(GetBitContext *s); int init_vlc(VLC *vlc, int nb_bits, int nb_codes, @@ -665,150 +744,85 @@ int init_vlc(VLC *vlc, int nb_bits, int nb_codes, const void *codes, int codes_wrap, int codes_size); void free_vlc(VLC *vlc); -#ifdef ALT_BITSTREAM_READER -#ifdef ALIGNED_BITSTREAM -#ifdef ARCH_X86 -#define SHOW_BITS(s, val, n) \ - val= be2me_32( ((uint32_t *)(s)->buffer)[bit_cnt>>5] );\ - {uint32_t result2= be2me_32( ((uint32_t *)(s)->buffer)[(bit_cnt>>5) + 1] );\ - asm ("shldl %%cl, %2, %0\n\t"\ - : "=r" (val)\ - : "0" (val), "r" (result2), "c" (bit_cnt));\ - ((uint32_t)val)>>= 32 - n;} -#else //ARCH_X86 -#define SHOW_BITS(s, val, n) \ - val= be2me_32( ((uint32_t *)(s)->buffer)[bit_cnt>>5] );\ - {uint32_t result2= be2me_32( ((uint32_t *)(s)->buffer)[(bit_cnt>>5) + 1] );\ - val<<= (bit_cnt&0x1F);\ - result2= (result2>>1) >> (31-(bit_cnt&0x1F));\ - val|= result2;\ - ((uint32_t)val)>>= 32 - n;} -#endif //!ARCH_X86 -#else //ALIGNED_BITSTREAM -#define SHOW_BITS(s, val, n) \ - val= be2me_32( unaligned32( ((uint8_t *)(s)->buffer)+(bit_cnt>>3) ) );\ - val<<= (bit_cnt&0x07);\ - ((uint32_t)val)>>= 32 - n; -#endif // !ALIGNED_BITSTREAM -#define FLUSH_BITS(n) bit_cnt+=n; -#define SAVE_BITS(s) bit_cnt= (s)->index; -#define RESTORE_BITS(s) (s)->index= bit_cnt; -#else - -/* macro to go faster */ -/* n must be <= 24 */ -/* XXX: optimize buffer end test */ -#define SHOW_BITS(s, val, n)\ +#define GET_VLC(code, name, gb, table, bits, max_depth)\ {\ - if (bit_cnt < n && buf_ptr < (s)->buf_end) {\ - bit_buf |= *buf_ptr++ << (24 - bit_cnt);\ - bit_cnt += 8;\ - if (bit_cnt < n && buf_ptr < (s)->buf_end) {\ - bit_buf |= *buf_ptr++ << (24 - bit_cnt);\ - bit_cnt += 8;\ - if (bit_cnt < n && buf_ptr < (s)->buf_end) {\ - bit_buf |= *buf_ptr++ << (24 - bit_cnt);\ - bit_cnt += 8;\ - }\ + int n, index, nb_bits;\ +\ + index= SHOW_UBITS(name, gb, bits);\ + code = table[index][0];\ + n = table[index][1];\ +\ + if(max_depth > 1 && n < 0){\ + LAST_SKIP_BITS(name, gb, bits)\ + UPDATE_CACHE(name, gb)\ +\ + nb_bits = -n;\ +\ + index= SHOW_UBITS(name, gb, nb_bits) + code;\ + code = table[index][0];\ + n = table[index][1];\ + if(max_depth > 2 && n < 0){\ + LAST_SKIP_BITS(name, gb, nb_bits)\ + UPDATE_CACHE(name, gb)\ +\ + nb_bits = -n;\ +\ + index= SHOW_UBITS(name, gb, nb_bits) + code;\ + code = table[index][0];\ + n = table[index][1];\ }\ }\ - val = bit_buf >> (32 - n);\ + SKIP_BITS(name, gb, n)\ } -/* SHOW_BITS with n1 >= n must be been done before */ -#define FLUSH_BITS(n)\ +#define GET_RL_VLC(level, run, name, gb, table, bits, max_depth)\ {\ - bit_buf <<= n;\ - bit_cnt -= n;\ + int n, index, nb_bits;\ +\ + index= SHOW_UBITS(name, gb, bits);\ + level = table[index].level;\ + n = table[index].len;\ +\ + if(max_depth > 1 && n < 0){\ + LAST_SKIP_BITS(name, gb, bits)\ + UPDATE_CACHE(name, gb)\ +\ + nb_bits = -n;\ +\ + index= SHOW_UBITS(name, gb, nb_bits) + level;\ + level = table[index].level;\ + n = table[index].len;\ + }\ + run= table[index].run;\ + SKIP_BITS(name, gb, n)\ } -#define SAVE_BITS(s) \ -{\ - bit_cnt = (s)->bit_cnt;\ - bit_buf = (s)->bit_buf;\ - buf_ptr = (s)->buf_ptr;\ -} +// deprecated, dont use get_vlc for new code, use get_vlc2 instead or use GET_VLC directly +static inline int get_vlc(GetBitContext *s, VLC *vlc) +{ + int code; + VLC_TYPE (*table)[2]= vlc->table; + + OPEN_READER(re, s) + UPDATE_CACHE(re, s) -#define RESTORE_BITS(s) \ -{\ - (s)->buf_ptr = buf_ptr;\ - (s)->bit_buf = bit_buf;\ - (s)->bit_cnt = bit_cnt;\ + GET_VLC(code, re, s, table, vlc->bits, 3) + + CLOSE_READER(re, s) + return code; } -#endif // !ALT_BITSTREAM_READER -static inline int get_vlc(GetBitContext *s, VLC *vlc) +static always_inline int get_vlc2(GetBitContext *s, VLC_TYPE (*table)[2], + int bits, int max_depth) { - int code, n, nb_bits, index; - INT16 *table_codes; - INT8 *table_bits; - int bit_cnt; -#ifndef ALT_BITSTREAM_READER - UINT32 bit_buf; - UINT8 *buf_ptr; -#endif + int code; + + OPEN_READER(re, s) + UPDATE_CACHE(re, s) - SAVE_BITS(s); - nb_bits = vlc->bits; - table_codes = vlc->table_codes; - table_bits = vlc->table_bits; - -#ifdef FAST_GET_FIRST_VLC - SHOW_BITS(s, index, nb_bits); - code = table_codes[index]; - n = table_bits[index]; - if (n > 0) { - /* most common case (90%)*/ - FLUSH_BITS(n); -#ifdef DUMP_STREAM - { - int n= bit_cnt - s->index; - skip_bits(s, n); - RESTORE_BITS(s); - } -#endif - RESTORE_BITS(s); - return code; - } else if (n == 0) { - return -1; - } else { - FLUSH_BITS(nb_bits); - nb_bits = -n; - table_codes = vlc->table_codes + code; - table_bits = vlc->table_bits + code; - } -#endif - for(;;) { - SHOW_BITS(s, index, nb_bits); - code = table_codes[index]; - n = table_bits[index]; - if (n > 0) { - /* most common case */ - FLUSH_BITS(n); -#ifdef STATS - st_bit_counts[st_current_index] += n; -#endif - break; - } else if (n == 0) { - return -1; - } else { - FLUSH_BITS(nb_bits); -#ifdef STATS - st_bit_counts[st_current_index] += nb_bits; -#endif - nb_bits = -n; - table_codes = vlc->table_codes + code; - table_bits = vlc->table_bits + code; - } - } -#ifdef DUMP_STREAM - { - int n= bit_cnt - s->index; - skip_bits(s, n); - RESTORE_BITS(s); - } -#endif - RESTORE_BITS(s); + GET_VLC(code, re, s, table, bits, max_depth) + + CLOSE_READER(re, s) return code; } diff --git a/src/libffmpeg/libavcodec/dsputil.c b/src/libffmpeg/libavcodec/dsputil.c index 6bc5c8b45..2d2378f3f 100644 --- a/src/libffmpeg/libavcodec/dsputil.c +++ b/src/libffmpeg/libavcodec/dsputil.c @@ -46,8 +46,8 @@ op_pixels_abs_func pix_abs8x8_xy2; UINT8 cropTbl[256 + 2 * MAX_NEG_CROP]; UINT32 squareTbl[512]; -extern INT16 default_intra_matrix[64]; -extern INT16 default_non_intra_matrix[64]; +extern INT16 ff_mpeg1_default_intra_matrix[64]; +extern INT16 ff_mpeg1_default_non_intra_matrix[64]; extern INT16 ff_mpeg4_default_intra_matrix[64]; extern INT16 ff_mpeg4_default_non_intra_matrix[64]; @@ -159,96 +159,86 @@ static void build_zigzag_end(void) } } -void get_pixels_c(DCTELEM *block, const UINT8 *pixels, int line_size) +void get_pixels_c(DCTELEM *restrict block, const UINT8 *pixels, int line_size) { - DCTELEM *p; - const UINT8 *pix; int i; /* read the pixels */ - p = block; - pix = pixels; for(i=0;i<8;i++) { - p[0] = pix[0]; - p[1] = pix[1]; - p[2] = pix[2]; - p[3] = pix[3]; - p[4] = pix[4]; - p[5] = pix[5]; - p[6] = pix[6]; - p[7] = pix[7]; - pix += line_size; - p += 8; + block[0] = pixels[0]; + block[1] = pixels[1]; + block[2] = pixels[2]; + block[3] = pixels[3]; + block[4] = pixels[4]; + block[5] = pixels[5]; + block[6] = pixels[6]; + block[7] = pixels[7]; + pixels += line_size; + block += 8; } } -void diff_pixels_c(DCTELEM *block, const UINT8 *s1, const UINT8 *s2, int stride){ - DCTELEM *p; +void diff_pixels_c(DCTELEM *restrict block, const UINT8 *s1, const UINT8 *s2, + int stride){ int i; /* read the pixels */ - p = block; for(i=0;i<8;i++) { - p[0] = s1[0] - s2[0]; - p[1] = s1[1] - s2[1]; - p[2] = s1[2] - s2[2]; - p[3] = s1[3] - s2[3]; - p[4] = s1[4] - s2[4]; - p[5] = s1[5] - s2[5]; - p[6] = s1[6] - s2[6]; - p[7] = s1[7] - s2[7]; + block[0] = s1[0] - s2[0]; + block[1] = s1[1] - s2[1]; + block[2] = s1[2] - s2[2]; + block[3] = s1[3] - s2[3]; + block[4] = s1[4] - s2[4]; + block[5] = s1[5] - s2[5]; + block[6] = s1[6] - s2[6]; + block[7] = s1[7] - s2[7]; s1 += stride; s2 += stride; - p += 8; + block += 8; } } -void put_pixels_clamped_c(const DCTELEM *block, UINT8 *pixels, int line_size) +void put_pixels_clamped_c(const DCTELEM *block, UINT8 *restrict pixels, + int line_size) { - const DCTELEM *p; - UINT8 *pix; int i; UINT8 *cm = cropTbl + MAX_NEG_CROP; /* read the pixels */ - p = block; - pix = pixels; for(i=0;i<8;i++) { - pix[0] = cm[p[0]]; - pix[1] = cm[p[1]]; - pix[2] = cm[p[2]]; - pix[3] = cm[p[3]]; - pix[4] = cm[p[4]]; - pix[5] = cm[p[5]]; - pix[6] = cm[p[6]]; - pix[7] = cm[p[7]]; - pix += line_size; - p += 8; + pixels[0] = cm[block[0]]; + pixels[1] = cm[block[1]]; + pixels[2] = cm[block[2]]; + pixels[3] = cm[block[3]]; + pixels[4] = cm[block[4]]; + pixels[5] = cm[block[5]]; + pixels[6] = cm[block[6]]; + pixels[7] = cm[block[7]]; + + pixels += line_size; + block += 8; } } -void add_pixels_clamped_c(const DCTELEM *block, UINT8 *pixels, int line_size) +void add_pixels_clamped_c(const DCTELEM *block, UINT8 *restrict pixels, + int line_size) { - const DCTELEM *p; - UINT8 *pix; int i; UINT8 *cm = cropTbl + MAX_NEG_CROP; /* read the pixels */ - p = block; - pix = pixels; for(i=0;i<8;i++) { - pix[0] = cm[pix[0] + p[0]]; - pix[1] = cm[pix[1] + p[1]]; - pix[2] = cm[pix[2] + p[2]]; - pix[3] = cm[pix[3] + p[3]]; - pix[4] = cm[pix[4] + p[4]]; - pix[5] = cm[pix[5] + p[5]]; - pix[6] = cm[pix[6] + p[6]]; - pix[7] = cm[pix[7] + p[7]]; - pix += line_size; - p += 8; + pixels[0] = cm[pixels[0] + block[0]]; + pixels[1] = cm[pixels[1] + block[1]]; + pixels[2] = cm[pixels[2] + block[2]]; + pixels[3] = cm[pixels[3] + block[3]]; + pixels[4] = cm[pixels[4] + block[4]]; + pixels[5] = cm[pixels[5] + block[5]]; + pixels[6] = cm[pixels[6] + block[6]]; + pixels[7] = cm[pixels[7] + block[7]]; + pixels += line_size; + block += 8; } } @@ -1332,8 +1322,8 @@ void dsputil_init(void) j = ff_alternate_vertical_scan[i]; ff_alternate_vertical_scan[i] = block_permute_op(j); } - block_permute(default_intra_matrix); - block_permute(default_non_intra_matrix); + block_permute(ff_mpeg1_default_intra_matrix); + block_permute(ff_mpeg1_default_non_intra_matrix); block_permute(ff_mpeg4_default_intra_matrix); block_permute(ff_mpeg4_default_non_intra_matrix); } diff --git a/src/libffmpeg/libavcodec/h263.c b/src/libffmpeg/libavcodec/h263.c index ae1eea7d7..d016f1972 100644 --- a/src/libffmpeg/libavcodec/h263.c +++ b/src/libffmpeg/libavcodec/h263.c @@ -32,8 +32,17 @@ //rounded divison & shift #define RSHIFT(a,b) ((a) > 0 ? ((a) + (1<<((b)-1)))>>(b) : ((a) + (1<<((b)-1))-1)>>(b)) -#define PRINT_MB_TYPE(a) ; -//#define PRINT_MB_TYPE(a) printf(a); +#define PRINT_MB_TYPE(a) {} +//#define PRINT_MB_TYPE(a) printf(a) + +#define INTRA_MCBPC_VLC_BITS 6 +#define INTER_MCBPC_VLC_BITS 6 +#define CBPY_VLC_BITS 6 +#define MV_VLC_BITS 9 +#define DC_VLC_BITS 9 +#define SPRITE_TRAJ_VLC_BITS 6 +#define MB_TYPE_B_VLC_BITS 4 +#define TEX_VLC_BITS 9 static void h263_encode_block(MpegEncContext * s, DCTELEM * block, int n); @@ -1622,9 +1631,49 @@ void init_rl(RLTable *rl) void init_vlc_rl(RLTable *rl) { + int i, q; + init_vlc(&rl->vlc, 9, rl->n + 1, &rl->table_vlc[0][1], 4, 2, &rl->table_vlc[0][0], 4, 2); + + + for(q=0; q<32; q++){ + int qmul= q*2; + int qadd= (q-1)|1; + + if(q==0){ + qmul=1; + qadd=0; + } + + rl->rl_vlc[q]= av_malloc(rl->vlc.table_size*sizeof(RL_VLC_ELEM)); + for(i=0; i<rl->vlc.table_size; i++){ + int code= rl->vlc.table[i][0]; + int len = rl->vlc.table[i][1]; + int level, run; + + if(len==0){ // illegal code + run= 65; + level= MAX_LEVEL; + }else if(len<0){ //more bits needed + run= 0; + level= code; + }else{ + if(code==rl->n){ //esc + run= 65; + level= 0; + }else{ + run= rl->table_run [code] + 1; + level= rl->table_level[code] * qmul + qadd; + if(code >= rl->last) run+=192; + } + } + rl->rl_vlc[q][i].len= len; + rl->rl_vlc[q][i].level= level; + rl->rl_vlc[q][i].run= run; + } + } } /* init vlcs */ @@ -1637,16 +1686,16 @@ void h263_decode_init_vlc(MpegEncContext *s) if (!done) { done = 1; - init_vlc(&intra_MCBPC_vlc, 6, 8, + init_vlc(&intra_MCBPC_vlc, INTRA_MCBPC_VLC_BITS, 8, intra_MCBPC_bits, 1, 1, intra_MCBPC_code, 1, 1); - init_vlc(&inter_MCBPC_vlc, 9, 25, + init_vlc(&inter_MCBPC_vlc, INTER_MCBPC_VLC_BITS, 25, inter_MCBPC_bits, 1, 1, inter_MCBPC_code, 1, 1); - init_vlc(&cbpy_vlc, 6, 16, + init_vlc(&cbpy_vlc, CBPY_VLC_BITS, 16, &cbpy_tab[0][1], 2, 1, &cbpy_tab[0][0], 2, 1); - init_vlc(&mv_vlc, 9, 33, + init_vlc(&mv_vlc, MV_VLC_BITS, 33, &mvtab[0][1], 2, 1, &mvtab[0][0], 2, 1); init_rl(&rl_inter); @@ -1655,16 +1704,16 @@ void h263_decode_init_vlc(MpegEncContext *s) init_vlc_rl(&rl_inter); init_vlc_rl(&rl_intra); init_vlc_rl(&rl_intra_aic); - init_vlc(&dc_lum, 9, 13, + init_vlc(&dc_lum, DC_VLC_BITS, 10 /* 13 */, &DCtab_lum[0][1], 2, 1, &DCtab_lum[0][0], 2, 1); - init_vlc(&dc_chrom, 9, 13, + init_vlc(&dc_chrom, DC_VLC_BITS, 10 /* 13 */, &DCtab_chrom[0][1], 2, 1, &DCtab_chrom[0][0], 2, 1); - init_vlc(&sprite_trajectory, 9, 15, + init_vlc(&sprite_trajectory, SPRITE_TRAJ_VLC_BITS, 15, &sprite_trajectory_tab[0][1], 4, 2, &sprite_trajectory_tab[0][0], 4, 2); - init_vlc(&mb_type_b_vlc, 4, 4, + init_vlc(&mb_type_b_vlc, MB_TYPE_B_VLC_BITS, 4, &mb_type_b_tab[0][1], 2, 1, &mb_type_b_tab[0][0], 2, 1); } @@ -1984,7 +2033,7 @@ int ff_mpeg4_decode_partitions(MpegEncContext *s) int i; PRINT_MB_TYPE("I"); - cbpc = get_vlc(&s->gb, &intra_MCBPC_vlc); + cbpc = get_vlc2(&s->gb, intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 1); if (cbpc < 0){ fprintf(stderr, "cbpc corrupted at %d %d\n", s->mb_x, s->mb_y); return DECODING_DESYNC; @@ -2049,7 +2098,7 @@ int ff_mpeg4_decode_partitions(MpegEncContext *s) continue; } - cbpc = get_vlc(&s->gb, &inter_MCBPC_vlc); + cbpc = get_vlc2(&s->gb, inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2); if (cbpc < 0){ fprintf(stderr, "cbpc corrupted at %d %d\n", s->mb_x, s->mb_y); return DECODING_DESYNC; @@ -2156,7 +2205,7 @@ int ff_mpeg4_decode_partitions(MpegEncContext *s) if(s->pict_type==I_TYPE){ int ac_pred= get_bits1(&s->gb); - int cbpy = get_vlc(&s->gb, &cbpy_vlc); + int cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); if(cbpy<0){ fprintf(stderr, "cbpy corrupted at %d %d\n", s->mb_x, s->mb_y); return DECODING_AC_LOST; @@ -2168,7 +2217,7 @@ int ff_mpeg4_decode_partitions(MpegEncContext *s) if(s->mb_type[xy]&MB_TYPE_INTRA){ int dir=0,i; int ac_pred = get_bits1(&s->gb); - int cbpy = get_vlc(&s->gb, &cbpy_vlc); + int cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); if(cbpy<0){ fprintf(stderr, "I cbpy corrupted at %d %d\n", s->mb_x, s->mb_y); @@ -2202,7 +2251,7 @@ int ff_mpeg4_decode_partitions(MpegEncContext *s) s->qscale_table[xy]= s->qscale; s->cbp_table[xy]= 0; }else{ - int cbpy = get_vlc(&s->gb, &cbpy_vlc); + int cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); if(cbpy<0){ fprintf(stderr, "P cbpy corrupted at %d %d\n", s->mb_x, s->mb_y); @@ -2357,7 +2406,7 @@ int h263_decode_mb(MpegEncContext *s, INT16 *mot_val; static INT8 quant_tab[4] = { -1, -2, 1, 2 }; - if(s->mb_x==0) PRINT_MB_TYPE("\n") + if(s->mb_x==0) PRINT_MB_TYPE("\n"); if(s->resync_marker){ if(s->resync_mb_x == s->mb_x && s->resync_mb_y+1 == s->mb_y){ @@ -2403,7 +2452,7 @@ int h263_decode_mb(MpegEncContext *s, } return 0; } - cbpc = get_vlc(&s->gb, &inter_MCBPC_vlc); + cbpc = get_vlc2(&s->gb, inter_MCBPC_vlc.table, INTER_MCBPC_VLC_BITS, 2); //fprintf(stderr, "\tCBPC: %d", cbpc); if (cbpc < 0) return -1; @@ -2419,7 +2468,7 @@ int h263_decode_mb(MpegEncContext *s, if(s->pict_type==S_TYPE && s->vol_sprite_usage==GMC_SPRITE && (cbpc & 16) == 0) s->mcsel= get_bits1(&s->gb); else s->mcsel= 0; - cbpy = get_vlc(&s->gb, &cbpy_vlc); + cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); cbp = (cbpc & 3) | ((cbpy ^ 0xf) << 2); if (dquant) { s->qscale += quant_tab[get_bits(&s->gb, 2)]; @@ -2539,14 +2588,14 @@ int h263_decode_mb(MpegEncContext *s, //FIXME is this correct? /* s->last_mv[0][0][0]= s->last_mv[0][0][1]=0;*/ - PRINT_MB_TYPE("s") + PRINT_MB_TYPE("s"); return 0; } modb1= get_bits1(&s->gb); if(modb1==0){ modb2= get_bits1(&s->gb); - mb_type= get_vlc(&s->gb, &mb_type_b_vlc); + mb_type= get_vlc2(&s->gb, mb_type_b_vlc.table, MB_TYPE_B_VLC_BITS, 1); if(modb2==0) cbp= get_bits(&s->gb, 6); else cbp=0; if (mb_type && cbp) { @@ -2624,7 +2673,7 @@ int h263_decode_mb(MpegEncContext *s, return -1; } } else { /* I-Frame */ - cbpc = get_vlc(&s->gb, &intra_MCBPC_vlc); + cbpc = get_vlc2(&s->gb, intra_MCBPC_vlc.table, INTRA_MCBPC_VLC_BITS, 1); if (cbpc < 0) return -1; dquant = cbpc & 4; @@ -2637,7 +2686,7 @@ intra: if (s->ac_pred && s->h263_aic) s->h263_aic_dir = get_bits1(&s->gb); } - cbpy = get_vlc(&s->gb, &cbpy_vlc); + cbpy = get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); if(cbpy<0) return -1; cbp = (cbpc & 3) | (cbpy << 2); if (dquant) { @@ -2669,7 +2718,7 @@ static int h263_decode_motion(MpegEncContext * s, int pred, int f_code) { int code, val, sign, shift, l, m; - code = get_vlc(&s->gb, &mv_vlc); + code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2); if (code < 0) return 0xffff; @@ -2782,7 +2831,7 @@ static int h263_decode_block(MpegEncContext * s, DCTELEM * block, } for(;;) { - code = get_vlc(&s->gb, &rl->vlc); + code = get_vlc2(&s->gb, rl->vlc.table, TEX_VLC_BITS, 2); if (code < 0) return -1; if (code == rl->n) { @@ -2826,9 +2875,9 @@ static inline int mpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr) UINT16 *dc_val; if (n < 4) - code = get_vlc(&s->gb, &dc_lum); + code = get_vlc2(&s->gb, dc_lum.table, DC_VLC_BITS, 1); else - code = get_vlc(&s->gb, &dc_chrom); + code = get_vlc2(&s->gb, dc_chrom.table, DC_VLC_BITS, 1); if (code < 0 || code > 9 /* && s->nbit<9 */){ fprintf(stderr, "illegal dc vlc\n"); return -1; @@ -2868,10 +2917,12 @@ static inline int mpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr) static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, int n, int coded) { - int code, level, i, j, last, run; + int level, i, last, run; int dc_pred_dir; RLTable *rl; + RL_VLC_ELEM *rl_vlc; const UINT8 *scan_table; + int qmul, qadd; if (s->mb_intra) { /* DC coef */ @@ -2886,10 +2937,11 @@ static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, return DECODING_ACDC_LOST; } block[0] = level; - i = 1; + i = 0; if (!coded) goto not_coded; rl = &rl_intra; + rl_vlc = rl_intra.rl_vlc[0]; if (s->ac_pred) { if (dc_pred_dir == 0) scan_table = ff_alternate_vertical_scan; /* left */ @@ -2898,37 +2950,52 @@ static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, } else { scan_table = zigzag_direct; } + qmul=1; + qadd=0; } else { - i = 0; + i = -1; if (!coded) { - s->block_last_index[n] = i - 1; + s->block_last_index[n] = i; return 0; } rl = &rl_inter; + rl_vlc = rl_inter.rl_vlc[s->qscale]; scan_table = zigzag_direct; + qmul = s->qscale << 1; + qadd = (s->qscale - 1) | 1; } - + { + OPEN_READER(re, &s->gb); for(;;) { - code = get_vlc(&s->gb, &rl->vlc); - if (code < 0) - return DECODING_AC_LOST; - if (code == rl->n) { + UPDATE_CACHE(re, &s->gb); + GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2); + if (level==0) { + int cache; + cache= GET_CACHE(re, &s->gb); /* escape */ - if (get_bits1(&s->gb) != 0) { - if (get_bits1(&s->gb) != 0) { + if (cache&0x80000000) { + if (cache&0x40000000) { /* third escape */ - last = get_bits1(&s->gb); - run = get_bits(&s->gb, 6); - if(get_bits1(&s->gb)==0){ + SKIP_CACHE(re, &s->gb, 2); + last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1); + run= SHOW_UBITS(re, &s->gb, 6); LAST_SKIP_CACHE(re, &s->gb, 6); + SKIP_COUNTER(re, &s->gb, 2+1+6); + UPDATE_CACHE(re, &s->gb); + + if(SHOW_UBITS(re, &s->gb, 1)==0){ fprintf(stderr, "1. marker bit missing in 3. esc\n"); return DECODING_AC_LOST; - } - level = get_bits(&s->gb, 12); - level = (level << 20) >> 20; /* sign extend */ - if(get_bits1(&s->gb)==0){ + }; SKIP_CACHE(re, &s->gb, 1); + + level= SHOW_SBITS(re, &s->gb, 12); SKIP_CACHE(re, &s->gb, 12); + + if(SHOW_UBITS(re, &s->gb, 1)==0){ fprintf(stderr, "2. marker bit missing in 3. esc\n"); return DECODING_AC_LOST; - } + }; LAST_SKIP_CACHE(re, &s->gb, 1); + + SKIP_COUNTER(re, &s->gb, 1+12+1); + if(level>512 || level<-512){ //FIXME check that QP=1 is ok with this too fprintf(stderr, "|level| overflow in 3. esc\n"); return DECODING_AC_LOST; @@ -2953,54 +3020,66 @@ static inline int mpeg4_decode_block(MpegEncContext * s, DCTELEM * block, } } #endif + if (level>0) level= level * qmul + qadd; + else level= level * qmul - qadd; + + i+= run + 1; + if(last) i+=192; } else { /* second escape */ - code = get_vlc(&s->gb, &rl->vlc); - if (code < 0 || code >= rl->n) - return DECODING_AC_LOST; - run = rl->table_run[code]; - level = rl->table_level[code]; - last = code >= rl->last; - run += rl->max_run[last][level] + 1; - if (get_bits1(&s->gb)) - level = -level; +#if MIN_CACHE_BITS < 20 + LAST_SKIP_BITS(re, &s->gb, 2); + UPDATE_CACHE(re, &s->gb); +#else + SKIP_BITS(re, &s->gb, 2); +#endif + GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2); + i+= run + rl->max_run[run>>7][level/qmul] +1; //FIXME opt indexing + level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); + LAST_SKIP_BITS(re, &s->gb, 1); } } else { /* first escape */ - code = get_vlc(&s->gb, &rl->vlc); - if (code < 0 || code >= rl->n) - return DECODING_AC_LOST; - run = rl->table_run[code]; - level = rl->table_level[code]; - last = code >= rl->last; - level += rl->max_level[last][run]; - if (get_bits1(&s->gb)) - level = -level; +#if MIN_CACHE_BITS < 19 + LAST_SKIP_BITS(re, &s->gb, 1); + UPDATE_CACHE(re, &s->gb); +#else + SKIP_BITS(re, &s->gb, 1); +#endif + GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2); + i+= run; + level = level + rl->max_level[run>>7][(run-1)&63] * qmul;//FIXME opt indexing + level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); + LAST_SKIP_BITS(re, &s->gb, 1); } } else { - run = rl->table_run[code]; - level = rl->table_level[code]; - last = code >= rl->last; - if (get_bits1(&s->gb)) - level = -level; + i+= run; + level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); + LAST_SKIP_BITS(re, &s->gb, 1); } - i += run; - if (i >= 64) - return DECODING_AC_LOST; - j = scan_table[i]; - block[j] = level; - i++; - if (last) + if (i > 62){ + i-= 192; + if(i&(~63)){ + fprintf(stderr, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); + return DECODING_AC_LOST; + } + + block[scan_table[i]] = level; break; + } + + block[scan_table[i]] = level; } + CLOSE_READER(re, &s->gb); + } not_coded: if (s->mb_intra) { mpeg4_pred_ac(s, block, n, dc_pred_dir); if (s->ac_pred) { - i = 64; /* XXX: not optimal */ + i = 63; /* XXX: not optimal */ } } - s->block_last_index[n] = i - 1; + s->block_last_index[n] = i; return 0; } diff --git a/src/libffmpeg/libavcodec/h263dec.c b/src/libffmpeg/libavcodec/h263dec.c index 83b76dbe9..d03b9ccf5 100644 --- a/src/libffmpeg/libavcodec/h263dec.c +++ b/src/libffmpeg/libavcodec/h263dec.c @@ -89,7 +89,7 @@ static int h263_decode_init(AVCodecContext *avctx) } s->codec_id= avctx->codec->id; avctx->mbskip_table= s->mbskip_table; - + /* for h263, we allocate the images after having read the header */ if (avctx->codec->id != CODEC_ID_H263 && avctx->codec->id != CODEC_ID_MPEG4) if (MPV_common_init(s) < 0) @@ -154,43 +154,45 @@ uint64_t time= rdtsc(); } else { ret = h263_decode_picture_header(s); } + avctx->has_b_frames= s->has_b_frames; + /* After H263 & mpeg4 header decode we have the height, width,*/ /* and other parameters. So then we could init the picture */ /* FIXME: By the way H263 decoder is evolving it should have */ /* an H263EncContext */ + if (s->width != avctx->width || s->height != avctx->height) { + /* H.263 could change picture size any time */ + MPV_common_end(s); + s->context_initialized=0; + } if (!s->context_initialized) { avctx->width = s->width; avctx->height = s->height; avctx->aspect_ratio_info= s->aspect_ratio_info; if (MPV_common_init(s) < 0) return -1; - } else if (s->width != avctx->width || s->height != avctx->height) { - /* H.263 could change picture size any time */ - MPV_common_end(s); - if (MPV_common_init(s) < 0) - return -1; } - if(ret==FRAME_SKIPED) return 0; + if(ret==FRAME_SKIPED) return buf_size; /* skip if the header was thrashed */ if (ret < 0){ fprintf(stderr, "header damaged\n"); return -1; } /* skip b frames if we dont have reference frames */ - if(s->num_available_buffers<2 && s->pict_type==B_TYPE) return 0; + if(s->num_available_buffers<2 && s->pict_type==B_TYPE) return buf_size; /* skip b frames if we are in a hurry */ - if(s->hurry_up && s->pict_type==B_TYPE) return 0; + if(s->hurry_up && s->pict_type==B_TYPE) return buf_size; if(s->next_p_frame_damaged){ if(s->pict_type==B_TYPE) - return 0; + return buf_size; else s->next_p_frame_damaged=0; } - MPV_frame_start(s); + MPV_frame_start(s, avctx); #ifdef DEBUG printf("qscale=%d\n", s->qscale); @@ -431,8 +433,8 @@ uint64_t time= rdtsc(); pict->data[2] = s->last_picture[2]; } pict->linesize[0] = s->linesize; - pict->linesize[1] = s->linesize / 2; - pict->linesize[2] = s->linesize / 2; + pict->linesize[1] = s->uvlinesize; + pict->linesize[2] = s->uvlinesize; avctx->quality = s->qscale; @@ -459,7 +461,7 @@ AVCodec mpeg4_decoder = { NULL, h263_decode_end, h263_decode_frame, - CODEC_CAP_DRAW_HORIZ_BAND, + CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, }; AVCodec h263_decoder = { @@ -471,7 +473,7 @@ AVCodec h263_decoder = { NULL, h263_decode_end, h263_decode_frame, - CODEC_CAP_DRAW_HORIZ_BAND, + CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, }; AVCodec msmpeg4v1_decoder = { @@ -483,7 +485,7 @@ AVCodec msmpeg4v1_decoder = { NULL, h263_decode_end, h263_decode_frame, - CODEC_CAP_DRAW_HORIZ_BAND, + CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, }; AVCodec msmpeg4v2_decoder = { @@ -495,7 +497,7 @@ AVCodec msmpeg4v2_decoder = { NULL, h263_decode_end, h263_decode_frame, - CODEC_CAP_DRAW_HORIZ_BAND, + CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, }; AVCodec msmpeg4v3_decoder = { @@ -507,7 +509,7 @@ AVCodec msmpeg4v3_decoder = { NULL, h263_decode_end, h263_decode_frame, - CODEC_CAP_DRAW_HORIZ_BAND, + CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, }; AVCodec wmv1_decoder = { @@ -519,7 +521,7 @@ AVCodec wmv1_decoder = { NULL, h263_decode_end, h263_decode_frame, - CODEC_CAP_DRAW_HORIZ_BAND, + CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, }; AVCodec wmv2_decoder = { @@ -531,7 +533,7 @@ AVCodec wmv2_decoder = { NULL, h263_decode_end, h263_decode_frame, - CODEC_CAP_DRAW_HORIZ_BAND, + CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, }; AVCodec h263i_decoder = { @@ -543,6 +545,6 @@ AVCodec h263i_decoder = { NULL, h263_decode_end, h263_decode_frame, - CODEC_CAP_DRAW_HORIZ_BAND, + CODEC_CAP_DRAW_HORIZ_BAND | CODEC_CAP_DR1, }; diff --git a/src/libffmpeg/libavcodec/mjpeg.c b/src/libffmpeg/libavcodec/mjpeg.c index ccaf37e38..5beb47e17 100644 --- a/src/libffmpeg/libavcodec/mjpeg.c +++ b/src/libffmpeg/libavcodec/mjpeg.c @@ -372,10 +372,10 @@ static void jpeg_put_comments(MpegEncContext *s) flush_put_bits(p); ptr = pbBufPtr(p); put_bits(p, 16, 0); /* patched later */ -#define VERSION "FFmpeg" LIBAVCODEC_VERSION "b" LIBAVCODEC_BUILD_STR - put_string(p, VERSION); - size = strlen(VERSION)+3; -#undef VERSION +#define MJPEG_VERSION "FFmpeg" LIBAVCODEC_VERSION "b" LIBAVCODEC_BUILD_STR + put_string(p, MJPEG_VERSION); + size = strlen(MJPEG_VERSION)+3; +#undef MJPEG_VERSION ptr[0] = size >> 8; ptr[1] = size; } @@ -1247,7 +1247,7 @@ static int mjpeg_decode_frame(AVCodecContext *avctx, s->bottom_field ^= 1; /* if not bottom field, do not output image yet */ if (s->bottom_field) - goto the_end; + goto not_the_end; } for(i=0;i<3;i++) { picture->data[i] = s->current_picture[i]; @@ -1313,6 +1313,8 @@ static int mjpeg_decode_frame(AVCodecContext *avctx, #endif } } + not_the_end: + ; } the_end: return buf_ptr - buf; diff --git a/src/libffmpeg/libavcodec/mpeg12.c b/src/libffmpeg/libavcodec/mpeg12.c index 9b917ce27..fab6d1aef 100644 --- a/src/libffmpeg/libavcodec/mpeg12.c +++ b/src/libffmpeg/libavcodec/mpeg12.c @@ -33,6 +33,14 @@ #define EXT_START_CODE 0x000001b5 #define USER_START_CODE 0x000001b2 +#define DC_VLC_BITS 9 +#define MV_VLC_BITS 9 +#define MBINCR_VLC_BITS 9 +#define MB_PAT_VLC_BITS 9 +#define MB_PTYPE_VLC_BITS 6 +#define MB_BTYPE_VLC_BITS 6 +#define TEX_VLC_BITS 9 + static void mpeg1_encode_block(MpegEncContext *s, DCTELEM *block, int component); @@ -52,6 +60,46 @@ static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred); static UINT16 mv_penalty[MAX_FCODE+1][MAX_MV*2+1]; static UINT8 fcode_tab[MAX_MV*2+1]; +static void init_2d_vlc_rl(RLTable *rl) +{ + int i, q; + + init_vlc(&rl->vlc, TEX_VLC_BITS, rl->n + 2, + &rl->table_vlc[0][1], 4, 2, + &rl->table_vlc[0][0], 4, 2); + + + rl->rl_vlc[0]= av_malloc(rl->vlc.table_size*sizeof(RL_VLC_ELEM)); + for(i=0; i<rl->vlc.table_size; i++){ + int code= rl->vlc.table[i][0]; + int len = rl->vlc.table[i][1]; + int level, run; + + if(len==0){ // illegal code + run= 65; + level= MAX_LEVEL; + }else if(len<0){ //more bits needed + run= 0; + level= code; + }else{ + if(code==rl->n){ //esc + run= 65; + level= 0; + }else if(code==rl->n+1){ //eob + run= 192; + level= 1; + }else{ + run= rl->table_run [code] + 1; + level= rl->table_level[code]; + } + } + rl->rl_vlc[0][i].len= len; + rl->rl_vlc[0][i].level= level; + rl->rl_vlc[0][i].run= run; + } +} + + static void put_header(MpegEncContext *s, int header) { align_put_bits(&s->pb); @@ -540,37 +588,33 @@ void mpeg1_init_vlc(MpegEncContext *s) if (!done) { done = 1; - init_vlc(&dc_lum_vlc, 9, 12, + init_vlc(&dc_lum_vlc, DC_VLC_BITS, 10/*12*/, vlc_dc_lum_bits, 1, 1, vlc_dc_lum_code, 2, 2); - init_vlc(&dc_chroma_vlc, 9, 12, + init_vlc(&dc_chroma_vlc, DC_VLC_BITS, 10/*12*/, vlc_dc_chroma_bits, 1, 1, vlc_dc_chroma_code, 2, 2); - init_vlc(&mv_vlc, 9, 17, + init_vlc(&mv_vlc, MV_VLC_BITS, 17, &mbMotionVectorTable[0][1], 2, 1, &mbMotionVectorTable[0][0], 2, 1); - init_vlc(&mbincr_vlc, 9, 35, + init_vlc(&mbincr_vlc, MBINCR_VLC_BITS, 35, &mbAddrIncrTable[0][1], 2, 1, &mbAddrIncrTable[0][0], 2, 1); - init_vlc(&mb_pat_vlc, 9, 63, + init_vlc(&mb_pat_vlc, MB_PAT_VLC_BITS, 63, &mbPatTable[0][1], 2, 1, &mbPatTable[0][0], 2, 1); - init_vlc(&mb_ptype_vlc, 6, 32, + init_vlc(&mb_ptype_vlc, MB_PTYPE_VLC_BITS, 32, &table_mb_ptype[0][1], 2, 1, &table_mb_ptype[0][0], 2, 1); - init_vlc(&mb_btype_vlc, 6, 32, + init_vlc(&mb_btype_vlc, MB_BTYPE_VLC_BITS, 32, &table_mb_btype[0][1], 2, 1, &table_mb_btype[0][0], 2, 1); init_rl(&rl_mpeg1); init_rl(&rl_mpeg2); - /* cannot use generic init because we must add the EOB code */ - init_vlc(&rl_mpeg1.vlc, 9, rl_mpeg1.n + 2, - &rl_mpeg1.table_vlc[0][1], 4, 2, - &rl_mpeg1.table_vlc[0][0], 4, 2); - init_vlc(&rl_mpeg2.vlc, 9, rl_mpeg2.n + 2, - &rl_mpeg2.table_vlc[0][1], 4, 2, - &rl_mpeg2.table_vlc[0][0], 4, 2); + + init_2d_vlc_rl(&rl_mpeg1); + init_2d_vlc_rl(&rl_mpeg2); } } @@ -614,7 +658,7 @@ static int mpeg_decode_mb(MpegEncContext *s, /* read again increment */ s->mb_incr = 1; for(;;) { - code = get_vlc(&s->gb, &mbincr_vlc); + code = get_vlc2(&s->gb, mbincr_vlc.table, MBINCR_VLC_BITS, 2); if (code < 0) return 1; /* error = end of slice */ if (code >= 33) { @@ -671,12 +715,12 @@ static int mpeg_decode_mb(MpegEncContext *s, } break; case P_TYPE: - mb_type = get_vlc(&s->gb, &mb_ptype_vlc); + mb_type = get_vlc2(&s->gb, mb_ptype_vlc.table, MB_PTYPE_VLC_BITS, 1); if (mb_type < 0) return -1; break; case B_TYPE: - mb_type = get_vlc(&s->gb, &mb_btype_vlc); + mb_type = get_vlc2(&s->gb, mb_btype_vlc.table, MB_BTYPE_VLC_BITS, 1); if (mb_type < 0) return -1; break; @@ -846,7 +890,7 @@ static int mpeg_decode_mb(MpegEncContext *s, } if (mb_type & MB_PAT) { - cbp = get_vlc(&s->gb, &mb_pat_vlc); + cbp = get_vlc2(&s->gb, mb_pat_vlc.table, MB_PAT_VLC_BITS, 1); if (cbp < 0) return -1; cbp++; @@ -891,7 +935,7 @@ static int mpeg_decode_motion(MpegEncContext *s, int fcode, int pred) { int code, sign, val, m, l, shift; - code = get_vlc(&s->gb, &mv_vlc); + code = get_vlc2(&s->gb, mv_vlc.table, MV_VLC_BITS, 2); if (code < 0) { return 0xffff; } @@ -924,9 +968,9 @@ static inline int decode_dc(MpegEncContext *s, int component) int code, diff; if (component == 0) { - code = get_vlc(&s->gb, &dc_lum_vlc); + code = get_vlc2(&s->gb, dc_lum_vlc.table, DC_VLC_BITS, 1); } else { - code = get_vlc(&s->gb, &dc_chroma_vlc); + code = get_vlc2(&s->gb, dc_chroma_vlc.table, DC_VLC_BITS, 1); } if (code < 0) return 0xffff; @@ -961,26 +1005,25 @@ static int mpeg1_decode_block(MpegEncContext *s, dprintf("dc=%d diff=%d\n", dc, diff); i = 1; } else { - int bit_cnt, v; - UINT32 bit_buf; - UINT8 *buf_ptr; + int v; + OPEN_READER(re, &s->gb); i = 0; /* special case for the first coef. no need to add a second vlc table */ - SAVE_BITS(&s->gb); - SHOW_BITS(&s->gb, v, 2); + UPDATE_CACHE(re, &s->gb); + v= SHOW_UBITS(re, &s->gb, 2); if (v & 2) { run = 0; level = 1 - ((v & 1) << 1); - FLUSH_BITS(2); - RESTORE_BITS(&s->gb); + SKIP_BITS(re, &s->gb, 2); + CLOSE_READER(re, &s->gb); goto add_coef; } - RESTORE_BITS(&s->gb); + CLOSE_READER(re, &s->gb); } /* now quantify & encode AC coefs */ for(;;) { - code = get_vlc(&s->gb, &rl->vlc); + code = get_vlc2(&s->gb, rl->vlc.table, TEX_VLC_BITS, 2); if (code < 0) { return -1; } @@ -1035,31 +1078,30 @@ static int mpeg2_decode_block_non_intra(MpegEncContext *s, mismatch = 1; { - int bit_cnt, v; - UINT32 bit_buf; - UINT8 *buf_ptr; + int v; + OPEN_READER(re, &s->gb); i = 0; - if (n < 4) + if (n < 4) matrix = s->inter_matrix; else matrix = s->chroma_inter_matrix; - + /* special case for the first coef. no need to add a second vlc table */ - SAVE_BITS(&s->gb); - SHOW_BITS(&s->gb, v, 2); + UPDATE_CACHE(re, &s->gb); + v= SHOW_UBITS(re, &s->gb, 2); if (v & 2) { run = 0; level = 1 - ((v & 1) << 1); - FLUSH_BITS(2); - RESTORE_BITS(&s->gb); + SKIP_BITS(re, &s->gb, 2); + CLOSE_READER(re, &s->gb); goto add_coef; } - RESTORE_BITS(&s->gb); + CLOSE_READER(re, &s->gb); } /* now quantify & encode AC coefs */ for(;;) { - code = get_vlc(&s->gb, &rl->vlc); + code = get_vlc2(&s->gb, rl->vlc.table, TEX_VLC_BITS, 2); if (code < 0) return -1; if (code == 112) { @@ -1138,7 +1180,7 @@ static int mpeg2_decode_block_intra(MpegEncContext *s, /* now quantify & encode AC coefs */ for(;;) { - code = get_vlc(&s->gb, &rl->vlc); + code = get_vlc2(&s->gb, rl->vlc.table, TEX_VLC_BITS, 2); if (code < 0) return -1; if (code == 112) { @@ -1410,7 +1452,7 @@ static int mpeg_decode_slice(AVCodecContext *avctx, /* start frame decoding */ if (s->first_slice) { s->first_slice = 0; - MPV_frame_start(s); + MPV_frame_start(s, avctx); } init_get_bits(&s->gb, buf, buf_size); @@ -1463,8 +1505,8 @@ static int mpeg_decode_slice(AVCodecContext *avctx, pict->data[1] = picture[1]; pict->data[2] = picture[2]; pict->linesize[0] = s->linesize; - pict->linesize[1] = s->linesize / 2; - pict->linesize[2] = s->linesize / 2; + pict->linesize[1] = s->uvlinesize; + pict->linesize[2] = s->uvlinesize; return 1; } else { return 0; @@ -1504,7 +1546,7 @@ static int mpeg1_decode_sequence(AVCodecContext *avctx, } s->width = width; s->height = height; - s->has_b_frames = 1; + avctx->has_b_frames= s->has_b_frames = 1; s->avctx = avctx; avctx->width = width; avctx->height = height; @@ -1542,7 +1584,7 @@ static int mpeg1_decode_sequence(AVCodecContext *avctx, #endif } else { for(i=0;i<64;i++) { - v = default_intra_matrix[i]; + v = ff_mpeg1_default_intra_matrix[i]; s->intra_matrix[i] = v; s->chroma_intra_matrix[i] = v; } @@ -1562,7 +1604,7 @@ static int mpeg1_decode_sequence(AVCodecContext *avctx, #endif } else { for(i=0;i<64;i++) { - v = default_non_intra_matrix[i]; + v = ff_mpeg1_default_non_intra_matrix[i]; s->inter_matrix[i] = v; s->chroma_inter_matrix[i] = v; } @@ -1600,8 +1642,8 @@ static int mpeg_decode_frame(AVCodecContext *avctx, picture->data[1] = s2->next_picture[1]; picture->data[2] = s2->next_picture[2]; picture->linesize[0] = s2->linesize; - picture->linesize[1] = s2->linesize / 2; - picture->linesize[2] = s2->linesize / 2; + picture->linesize[1] = s2->uvlinesize; + picture->linesize[2] = s2->uvlinesize; *data_size = sizeof(AVPicture); } return 0; diff --git a/src/libffmpeg/libavcodec/mpeg12data.h b/src/libffmpeg/libavcodec/mpeg12data.h index cfb6e1d0f..041708fd1 100644 --- a/src/libffmpeg/libavcodec/mpeg12data.h +++ b/src/libffmpeg/libavcodec/mpeg12data.h @@ -2,7 +2,7 @@ * MPEG1/2 tables */ -INT16 default_intra_matrix[64] = { +INT16 ff_mpeg1_default_intra_matrix[64] = { 8, 16, 19, 22, 26, 27, 29, 34, 16, 16, 22, 24, 27, 29, 34, 37, 19, 22, 26, 27, 29, 34, 34, 38, @@ -13,7 +13,7 @@ INT16 default_intra_matrix[64] = { 27, 29, 35, 38, 46, 56, 69, 83 }; -INT16 default_non_intra_matrix[64] = { +INT16 ff_mpeg1_default_non_intra_matrix[64] = { 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, 16, diff --git a/src/libffmpeg/libavcodec/mpegvideo.c b/src/libffmpeg/libavcodec/mpegvideo.c index fc15b98c1..6528ee9a3 100644 --- a/src/libffmpeg/libavcodec/mpegvideo.c +++ b/src/libffmpeg/libavcodec/mpegvideo.c @@ -132,6 +132,9 @@ int MPV_common_init(MpegEncContext *s) #ifdef HAVE_MMX MPV_common_init_mmx(s); #endif +#ifdef ARCH_ALPHA + MPV_common_init_axp(s); +#endif //setup default unquantizers (mpeg4 might change it later) if(s->out_format == FMT_H263) s->dct_unquantize = s->dct_unquantize_h263; @@ -141,16 +144,18 @@ int MPV_common_init(MpegEncContext *s) s->mb_width = (s->width + 15) / 16; s->mb_height = (s->height + 15) / 16; s->mb_num = s->mb_width * s->mb_height; - s->linesize = s->mb_width * 16 + 2 * EDGE_WIDTH; + if(!(s->flags&CODEC_FLAG_DR1)){ + s->linesize = s->mb_width * 16 + 2 * EDGE_WIDTH; + s->uvlinesize = s->mb_width * 8 + EDGE_WIDTH; - for(i=0;i<3;i++) { + for(i=0;i<3;i++) { int w, h, shift, pict_start; w = s->linesize; h = s->mb_height * 16 + 2 * EDGE_WIDTH; shift = (i == 0) ? 0 : 1; - c_size = (w >> shift) * (h >> shift); - pict_start = (w >> shift) * (EDGE_WIDTH >> shift) + (EDGE_WIDTH >> shift); + c_size = (s->linesize>>shift) * (h >> shift); + pict_start = (s->linesize>>shift) * (EDGE_WIDTH >> shift) + (EDGE_WIDTH >> shift); CHECKED_ALLOCZ(pict, c_size) s->last_picture_base[i] = pict; @@ -170,8 +175,12 @@ int MPV_common_init(MpegEncContext *s) s->aux_picture[i] = pict + pict_start; if(i>0) memset(s->aux_picture_base[i], 128, c_size); } + } + s->ip_buffer_count= 2; } + CHECKED_ALLOCZ(s->edge_emu_buffer, (s->width+32)*2*17); + if (s->encoding) { int j; int mv_table_size= (s->mb_width+2)*(s->mb_height+2); @@ -264,7 +273,7 @@ int MPV_common_init(MpegEncContext *s) } /* default structure is frame */ s->picture_structure = PICT_FRAME; - + /* init macroblock skip table */ CHECKED_ALLOCZ(s->mbskip_table, s->mb_num); @@ -312,11 +321,22 @@ void MPV_common_end(MpegEncContext *s) av_freep(&s->bitstream_buffer); av_freep(&s->tex_pb_buffer); av_freep(&s->pb2_buffer); + av_freep(&s->edge_emu_buffer); + for(i=0;i<3;i++) { int j; - av_freep(&s->last_picture_base[i]); - av_freep(&s->next_picture_base[i]); - av_freep(&s->aux_picture_base[i]); + if(!(s->flags&CODEC_FLAG_DR1)){ + av_freep(&s->last_picture_base[i]); + av_freep(&s->next_picture_base[i]); + av_freep(&s->aux_picture_base[i]); + } + s->last_picture_base[i]= + s->next_picture_base[i]= + s->aux_picture_base [i] = NULL; + s->last_picture[i]= + s->next_picture[i]= + s->aux_picture [i] = NULL; + for(j=0; j<REORDER_BUFFER_SIZE; j++){ av_freep(&s->picture_buffer[j][i]); } @@ -517,11 +537,11 @@ int MPV_encode_init(AVCodecContext *avctx) /* init default q matrix */ for(i=0;i<64;i++) { if(s->out_format == FMT_H263) - s->intra_matrix[i] = default_non_intra_matrix[i]; + s->intra_matrix[i] = ff_mpeg1_default_non_intra_matrix[i]; else - s->intra_matrix[i] = default_intra_matrix[i]; + s->intra_matrix[i] = ff_mpeg1_default_intra_matrix[i]; - s->inter_matrix[i] = default_non_intra_matrix[i]; + s->inter_matrix[i] = ff_mpeg1_default_non_intra_matrix[i]; } /* precompute matrix */ @@ -592,7 +612,7 @@ static void draw_edges_c(UINT8 *buf, int wrap, int width, int height, int w) } /* generic function for encode/decode called before a frame is coded/decoded */ -void MPV_frame_start(MpegEncContext *s) +void MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx) { int i; UINT8 *tmp; @@ -600,17 +620,41 @@ void MPV_frame_start(MpegEncContext *s) s->mb_skiped = 0; s->decoding_error=0; + if(avctx->flags&CODEC_FLAG_DR1){ + int i; + avctx->get_buffer_callback(avctx, s->width, s->height, s->pict_type); + + s->linesize = avctx->dr_stride; + s->uvlinesize= avctx->dr_uvstride; + s->ip_buffer_count= avctx->dr_ip_buffer_count; + } + if (s->pict_type == B_TYPE) { for(i=0;i<3;i++) { + if(avctx->flags&CODEC_FLAG_DR1) + s->aux_picture[i]= avctx->dr_buffer[i]; + s->current_picture[i] = s->aux_picture[i]; } } else { for(i=0;i<3;i++) { /* swap next and last */ - tmp = s->last_picture[i]; + if(avctx->flags&CODEC_FLAG_DR1) + tmp= avctx->dr_buffer[i]; + else + tmp = s->last_picture[i]; + s->last_picture[i] = s->next_picture[i]; s->next_picture[i] = tmp; s->current_picture[i] = tmp; + + s->last_dr_opaque= s->next_dr_opaque; + s->next_dr_opaque= avctx->dr_opaque_frame; + + if(s->has_b_frames && s->last_dr_opaque) + avctx->dr_opaque_frame= s->last_dr_opaque; + else + avctx->dr_opaque_frame= s->next_dr_opaque; } } } @@ -621,16 +665,16 @@ void MPV_frame_end(MpegEncContext *s) // if((s->picture_number%100)==0 && s->encoding) printf("sads:%d //\n", sads); /* draw edge for correct motion prediction if outside */ - if (s->pict_type != B_TYPE && !s->intra_only) { + if (s->pict_type != B_TYPE && !s->intra_only && !(s->flags&CODEC_FLAG_EMU_EDGE)) { if(s->avctx==NULL || s->avctx->codec->id!=CODEC_ID_MPEG4 || s->divx_version>=500){ draw_edges(s->current_picture[0], s->linesize, s->mb_width*16, s->mb_height*16, EDGE_WIDTH); - draw_edges(s->current_picture[1], s->linesize/2, s->mb_width*8, s->mb_height*8, EDGE_WIDTH/2); - draw_edges(s->current_picture[2], s->linesize/2, s->mb_width*8, s->mb_height*8, EDGE_WIDTH/2); + draw_edges(s->current_picture[1], s->uvlinesize, s->mb_width*8, s->mb_height*8, EDGE_WIDTH/2); + draw_edges(s->current_picture[2], s->uvlinesize, s->mb_width*8, s->mb_height*8, EDGE_WIDTH/2); }else{ /* mpeg4? / opendivx / xvid */ draw_edges(s->current_picture[0], s->linesize, s->width, s->height, EDGE_WIDTH); - draw_edges(s->current_picture[1], s->linesize/2, s->width/2, s->height/2, EDGE_WIDTH/2); - draw_edges(s->current_picture[2], s->linesize/2, s->width/2, s->height/2, EDGE_WIDTH/2); + draw_edges(s->current_picture[1], s->uvlinesize, s->width/2, s->height/2, EDGE_WIDTH/2); + draw_edges(s->current_picture[2], s->uvlinesize, s->width/2, s->height/2, EDGE_WIDTH/2); } } emms_c(); @@ -675,8 +719,8 @@ void reorder_input(MpegEncContext *s, AVPicture *pict) //printf("index:%d type:%d strides: %d %d\n", index, s->input_pict_type, pict->linesize[0], s->linesize); if( (index==0 || (s->flags&CODEC_FLAG_INPUT_PRESERVED)) && pict->linesize[0] == s->linesize - && pict->linesize[1] == s->linesize>>1 - && pict->linesize[2] == s->linesize>>1){ + && pict->linesize[1] == s->uvlinesize + && pict->linesize[2] == s->uvlinesize){ //printf("ptr\n"); for(i=0; i<3; i++){ s->coded_order[index].picture[i]= pict->data[i]; @@ -773,7 +817,7 @@ int MPV_encode_picture(AVCodecContext *avctx, s->picture_in_gop_number= s->coded_order[0].picture_in_gop_number; s->picture_number= s->coded_order[0].picture_number; - MPV_frame_start(s); + MPV_frame_start(s, avctx); encode_picture(s, s->picture_number); avctx->key_frame = (s->pict_type == I_TYPE); @@ -830,7 +874,7 @@ static inline void gmc1_motion(MpegEncContext *s, int h) { UINT8 *ptr; - int offset, src_x, src_y, linesize; + int offset, src_x, src_y, linesize, uvlinesize; int motion_x, motion_y; if(s->real_sprite_warping_points>1) printf("more than 1 warp point isnt supported\n"); @@ -848,6 +892,7 @@ static inline void gmc1_motion(MpegEncContext *s, motion_y =0; linesize = s->linesize; + uvlinesize = s->uvlinesize; ptr = ref_picture[0] + (src_y * linesize) + src_x + src_offset; dest_y+=dest_offset; @@ -867,15 +912,75 @@ static inline void gmc1_motion(MpegEncContext *s, if (src_y == s->height>>1) motion_y =0; - offset = (src_y * linesize>>1) + src_x + (src_offset>>1); + offset = (src_y * uvlinesize) + src_x + (src_offset>>1); ptr = ref_picture[1] + offset; - gmc1(dest_cb + (dest_offset>>1), ptr, linesize>>1, h>>1, motion_x&15, motion_y&15, s->no_rounding); + gmc1(dest_cb + (dest_offset>>1), ptr, uvlinesize, h>>1, motion_x&15, motion_y&15, s->no_rounding); ptr = ref_picture[2] + offset; - gmc1(dest_cr + (dest_offset>>1), ptr, linesize>>1, h>>1, motion_x&15, motion_y&15, s->no_rounding); + gmc1(dest_cr + (dest_offset>>1), ptr, uvlinesize, h>>1, motion_x&15, motion_y&15, s->no_rounding); return; } +static void emulated_edge_mc(UINT8 *buf, UINT8 *src, int linesize, int block_w, int block_h, + int src_x, int src_y, int w, int h){ + int x, y; + int start_y, start_x, end_y, end_x; + + if(src_y>= h){ + src+= (h-1-src_y)*linesize; + src_y=h-1; + }else if(src_y<=-block_h){ + src+= (1-block_h-src_y)*linesize; + src_y=1-block_h; + } + if(src_x>= w){ + src+= (w-1-src_x); + src_x=w-1; + }else if(src_x<=-block_w){ + src+= (1-block_w-src_x); + src_x=1-block_w; + } + + start_y= MAX(0, -src_y); + start_x= MAX(0, -src_x); + end_y= MIN(block_h, h-src_y); + end_x= MIN(block_w, w-src_x); + + // copy existing part + for(y=start_y; y<end_y; y++){ + for(x=start_x; x<end_x; x++){ + buf[x + y*linesize]= src[x + y*linesize]; + } + } + + //top + for(y=0; y<start_y; y++){ + for(x=start_x; x<end_x; x++){ + buf[x + y*linesize]= buf[x + start_y*linesize]; + } + } + + //bottom + for(y=end_y; y<block_h; y++){ + for(x=start_x; x<end_x; x++){ + buf[x + y*linesize]= buf[x + (end_y-1)*linesize]; + } + } + + for(y=0; y<block_h; y++){ + //left + for(x=0; x<start_x; x++){ + buf[x + y*linesize]= buf[start_x + y*linesize]; + } + + //right + for(x=end_x; x<block_w; x++){ + buf[x + y*linesize]= buf[end_x - 1 + y*linesize]; + } + } +} + + /* apply one mpeg motion vector to the three components */ static inline void mpeg_motion(MpegEncContext *s, UINT8 *dest_y, UINT8 *dest_cb, UINT8 *dest_cr, @@ -886,6 +991,8 @@ static inline void mpeg_motion(MpegEncContext *s, { UINT8 *ptr; int dxy, offset, mx, my, src_x, src_y, height, linesize; + int emu=0; + if(s->quarter_sample) { motion_x>>=1; @@ -906,6 +1013,15 @@ if(s->quarter_sample) linesize = s->linesize << field_based; ptr = ref_picture[0] + (src_y * linesize) + (src_x) + src_offset; dest_y += dest_offset; + + if(s->flags&CODEC_FLAG_EMU_EDGE){ + if(src_x<0 || src_y<0 || src_x + (motion_x&1) + 16 > s->width + || src_y + (motion_y&1) + h > height){ + emulated_edge_mc(s->edge_emu_buffer, ptr, linesize, 17, h+1, src_x, src_y, s->width, height); + ptr= s->edge_emu_buffer; + emu=1; + } + } pix_op[dxy](dest_y, ptr, linesize, h); pix_op[dxy](dest_y + 8, ptr + 8, linesize, h); @@ -936,11 +1052,20 @@ if(s->quarter_sample) if (src_y == (height >> 1)) dxy &= ~2; - offset = (src_y * (linesize >> 1)) + src_x + (src_offset >> 1); + offset = (src_y * s->uvlinesize) + src_x + (src_offset >> 1); ptr = ref_picture[1] + offset; - pix_op[dxy](dest_cb + (dest_offset >> 1), ptr, linesize >> 1, h >> 1); + if(emu){ + emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, (h>>1)+1, src_x, src_y, s->width>>1, height>>1); + ptr= s->edge_emu_buffer; + } + pix_op[dxy](dest_cb + (dest_offset >> 1), ptr, s->uvlinesize, h >> 1); + ptr = ref_picture[2] + offset; - pix_op[dxy](dest_cr + (dest_offset >> 1), ptr, linesize >> 1, h >> 1); + if(emu){ + emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, (h>>1)+1, src_x, src_y, s->width>>1, height>>1); + ptr= s->edge_emu_buffer; + } + pix_op[dxy](dest_cr + (dest_offset >> 1), ptr, s->uvlinesize, h >> 1); } static inline void qpel_motion(MpegEncContext *s, @@ -953,6 +1078,7 @@ static inline void qpel_motion(MpegEncContext *s, { UINT8 *ptr; int dxy, offset, mx, my, src_x, src_y, height, linesize; + int emu=0; dxy = ((motion_y & 3) << 2) | (motion_x & 3); src_x = s->mb_x * 16 + (motion_x >> 2); @@ -969,6 +1095,15 @@ static inline void qpel_motion(MpegEncContext *s, ptr = ref_picture[0] + (src_y * linesize) + src_x + src_offset; dest_y += dest_offset; //printf("%d %d %d\n", src_x, src_y, dxy); + + if(s->flags&CODEC_FLAG_EMU_EDGE){ + if(src_x<0 || src_y<0 || src_x + (motion_x&3) + 16 > s->width + || src_y + (motion_y&3) + h > height){ + emulated_edge_mc(s->edge_emu_buffer, ptr, linesize, 17, h+1, src_x, src_y, s->width, height); + ptr= s->edge_emu_buffer; + emu=1; + } + } qpix_op[dxy](dest_y , ptr , linesize, linesize, motion_x&3, motion_y&3); qpix_op[dxy](dest_y + 8, ptr + 8, linesize, linesize, motion_x&3, motion_y&3); qpix_op[dxy](dest_y + linesize*8 , ptr + linesize*8 , linesize, linesize, motion_x&3, motion_y&3); @@ -996,11 +1131,20 @@ static inline void qpel_motion(MpegEncContext *s, if (src_y == (height >> 1)) dxy &= ~2; - offset = (src_y * (linesize >> 1)) + src_x + (src_offset >> 1); + offset = (src_y * s->uvlinesize) + src_x + (src_offset >> 1); ptr = ref_picture[1] + offset; - pix_op[dxy](dest_cb + (dest_offset >> 1), ptr, linesize >> 1, h >> 1); + if(emu){ + emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, (h>>1)+1, src_x, src_y, s->width>>1, height>>1); + ptr= s->edge_emu_buffer; + } + pix_op[dxy](dest_cb + (dest_offset >> 1), ptr, s->uvlinesize, h >> 1); + ptr = ref_picture[2] + offset; - pix_op[dxy](dest_cr + (dest_offset >> 1), ptr, linesize >> 1, h >> 1); + if(emu){ + emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, (h>>1)+1, src_x, src_y, s->width>>1, height>>1); + ptr= s->edge_emu_buffer; + } + pix_op[dxy](dest_cr + (dest_offset >> 1), ptr, s->uvlinesize, h >> 1); } @@ -1012,6 +1156,7 @@ static inline void MPV_motion(MpegEncContext *s, int dxy, offset, mx, my, src_x, src_y, motion_x, motion_y; int mb_x, mb_y, i; UINT8 *ptr, *dest; + int emu=0; mb_x = s->mb_x; mb_y = s->mb_y; @@ -1061,6 +1206,13 @@ static inline void MPV_motion(MpegEncContext *s, dxy &= ~2; ptr = ref_picture[0] + (src_y * s->linesize) + (src_x); + if(s->flags&CODEC_FLAG_EMU_EDGE){ + if(src_x<0 || src_y<0 || src_x + (motion_x&1) + 8 > s->width + || src_y + (motion_y&1) + 8 > s->height){ + emulated_edge_mc(s->edge_emu_buffer, ptr, s->linesize, 9, 9, src_x, src_y, s->width, s->height); + ptr= s->edge_emu_buffer; + } + } dest = dest_y + ((i & 1) * 8) + (i >> 1) * 8 * s->linesize; pix_op[dxy](dest, ptr, s->linesize, 8); } @@ -1099,11 +1251,24 @@ static inline void MPV_motion(MpegEncContext *s, if (src_y == s->height/2) dxy &= ~2; - offset = (src_y * (s->linesize >> 1)) + src_x; + offset = (src_y * (s->uvlinesize)) + src_x; ptr = ref_picture[1] + offset; - pix_op[dxy](dest_cb, ptr, s->linesize >> 1, 8); + if(s->flags&CODEC_FLAG_EMU_EDGE){ + if(src_x<0 || src_y<0 || src_x + (dxy &1) + 8 > s->width >>1 + || src_y + (dxy>>1) + 8 > s->height>>1){ + emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->width>>1, s->height>>1); + ptr= s->edge_emu_buffer; + emu=1; + } + } + pix_op[dxy](dest_cb, ptr, s->uvlinesize, 8); + ptr = ref_picture[2] + offset; - pix_op[dxy](dest_cr, ptr, s->linesize >> 1, 8); + if(emu){ + emulated_edge_mc(s->edge_emu_buffer, ptr, s->uvlinesize, 9, 9, src_x, src_y, s->width>>1, s->height>>1); + ptr= s->edge_emu_buffer; + } + pix_op[dxy](dest_cr, ptr, s->uvlinesize, 8); break; case MV_TYPE_FIELD: if (s->picture_structure == PICT_FRAME) { @@ -1265,19 +1430,22 @@ void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) UINT8 *mbskip_ptr = &s->mbskip_table[mb_xy]; if (s->mb_skiped) { s->mb_skiped = 0; + + (*mbskip_ptr) ++; /* indicate that this time we skiped it */ + if(*mbskip_ptr >99) *mbskip_ptr= 99; + /* if previous was skipped too, then nothing to do ! skip only during decoding as we might trash the buffers during encoding a bit */ - if (*mbskip_ptr != 0 && !s->encoding) + if (*mbskip_ptr >= s->ip_buffer_count && !s->encoding) goto the_end; - *mbskip_ptr = 1; /* indicate that this time we skiped it */ } else { *mbskip_ptr = 0; /* not skipped */ } } dest_y = s->current_picture[0] + (mb_y * 16 * s->linesize) + mb_x * 16; - dest_cb = s->current_picture[1] + (mb_y * 8 * (s->linesize >> 1)) + mb_x * 8; - dest_cr = s->current_picture[2] + (mb_y * 8 * (s->linesize >> 1)) + mb_x * 8; + dest_cb = s->current_picture[1] + (mb_y * 8 * (s->uvlinesize)) + mb_x * 8; + dest_cr = s->current_picture[2] + (mb_y * 8 * (s->uvlinesize)) + mb_x * 8; if (s->interlaced_dct) { dct_linesize = s->linesize * 2; @@ -1315,15 +1483,15 @@ void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) if(s->hurry_up>1) goto the_end; /* add dct residue */ - if(!s->mpeg2 && (s->encoding || (!s->h263_msmpeg4))){ + if(s->encoding || !(s->mpeg2 || s->h263_msmpeg4 || s->codec_id==CODEC_ID_MPEG4)){ add_dequant_dct(s, block[0], 0, dest_y, dct_linesize); add_dequant_dct(s, block[1], 1, dest_y + 8, dct_linesize); add_dequant_dct(s, block[2], 2, dest_y + dct_offset, dct_linesize); add_dequant_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize); if(!(s->flags&CODEC_FLAG_GRAY)){ - add_dequant_dct(s, block[4], 4, dest_cb, s->linesize >> 1); - add_dequant_dct(s, block[5], 5, dest_cr, s->linesize >> 1); + add_dequant_dct(s, block[4], 4, dest_cb, s->uvlinesize); + add_dequant_dct(s, block[5], 5, dest_cr, s->uvlinesize); } } else { add_dct(s, block[0], 0, dest_y, dct_linesize); @@ -1332,8 +1500,8 @@ void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) add_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize); if(!(s->flags&CODEC_FLAG_GRAY)){ - add_dct(s, block[4], 4, dest_cb, s->linesize >> 1); - add_dct(s, block[5], 5, dest_cr, s->linesize >> 1); + add_dct(s, block[4], 4, dest_cb, s->uvlinesize); + add_dct(s, block[5], 5, dest_cr, s->uvlinesize); } } } else { @@ -1344,8 +1512,8 @@ void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64]) put_dct(s, block[3], 3, dest_y + dct_offset + 8, dct_linesize); if(!(s->flags&CODEC_FLAG_GRAY)){ - put_dct(s, block[4], 4, dest_cb, s->linesize >> 1); - put_dct(s, block[5], 5, dest_cr, s->linesize >> 1); + put_dct(s, block[4], 4, dest_cb, s->uvlinesize); + put_dct(s, block[5], 5, dest_cr, s->uvlinesize); } } } @@ -1460,8 +1628,8 @@ static void encode_mb(MpegEncContext *s, int motion_x, int motion_y) int wrap_y, wrap_c; dest_y = s->current_picture[0] + (mb_y * 16 * s->linesize ) + mb_x * 16; - dest_cb = s->current_picture[1] + (mb_y * 8 * (s->linesize >> 1)) + mb_x * 8; - dest_cr = s->current_picture[2] + (mb_y * 8 * (s->linesize >> 1)) + mb_x * 8; + dest_cb = s->current_picture[1] + (mb_y * 8 * (s->uvlinesize)) + mb_x * 8; + dest_cr = s->current_picture[2] + (mb_y * 8 * (s->uvlinesize)) + mb_x * 8; wrap_y = s->linesize; wrap_c = wrap_y>>1; ptr_y = s->new_picture[0] + (mb_y * 16 * wrap_y) + mb_x * 16; @@ -1793,9 +1961,9 @@ static void encode_picture(MpegEncContext *s, int picture_number) if (s->out_format == FMT_MJPEG) { /* for mjpeg, we do include qscale in the matrix */ - s->intra_matrix[0] = default_intra_matrix[0]; + s->intra_matrix[0] = ff_mpeg1_default_intra_matrix[0]; for(i=1;i<64;i++) - s->intra_matrix[i] = CLAMP_TO_8BIT((default_intra_matrix[i] * s->qscale) >> 3); + s->intra_matrix[i] = CLAMP_TO_8BIT((ff_mpeg1_default_intra_matrix[i] * s->qscale) >> 3); convert_matrix(s->q_intra_matrix, s->q_intra_matrix16, s->q_intra_matrix16_bias, s->intra_matrix, s->intra_quant_bias); } @@ -2406,8 +2574,8 @@ static void remove_ac(MpegEncContext *s, uint8_t *dest_y, uint8_t *dest_cb, uint for(y=0; y<8; y++){ int x; for(x=0; x<8; x++){ - dest_cb[x + y*(s->linesize>>1)]= dcb/8; - dest_cr[x + y*(s->linesize>>1)]= dcr/8; + dest_cb[x + y*(s->uvlinesize)]= dcb/8; + dest_cr[x + y*(s->uvlinesize)]= dcr/8; } } } @@ -2462,8 +2630,8 @@ void ff_conceal_past_errors(MpegEncContext *s, int unknown_pos) for(; mb_y>=0 && mb_y>=s->resync_mb_y; mb_y--){ for(; mb_x>=0; mb_x--){ uint8_t *dest_y = s->current_picture[0] + (mb_y * 16* s->linesize ) + mb_x * 16; - uint8_t *dest_cb = s->current_picture[1] + (mb_y * 8 * (s->linesize >> 1)) + mb_x * 8; - uint8_t *dest_cr = s->current_picture[2] + (mb_y * 8 * (s->linesize >> 1)) + mb_x * 8; + uint8_t *dest_cb = s->current_picture[1] + (mb_y * 8 * (s->uvlinesize)) + mb_x * 8; + uint8_t *dest_cr = s->current_picture[2] + (mb_y * 8 * (s->uvlinesize)) + mb_x * 8; int mb_x_backup= s->mb_x; //FIXME pass xy to mpeg_motion int mb_y_backup= s->mb_y; s->mb_x=mb_x; diff --git a/src/libffmpeg/libavcodec/mpegvideo.h b/src/libffmpeg/libavcodec/mpegvideo.h index f25f5dcb3..b04d4f74c 100644 --- a/src/libffmpeg/libavcodec/mpegvideo.h +++ b/src/libffmpeg/libavcodec/mpegvideo.h @@ -132,6 +132,7 @@ typedef struct MpegEncContext { int mb_width, mb_height; /* number of MBs horizontally & vertically */ int mb_num; /* number of MBs of a picture */ int linesize; /* line size, in bytes, may be different from width */ + int uvlinesize; /* line size, for chroma in bytes, may be different from width */ UINT8 *new_picture[3]; /* picture to be compressed */ UINT8 *picture_buffer[REORDER_BUFFER_SIZE][3]; /* internal buffers used for reordering of input pictures */ int picture_buffer_index; @@ -143,6 +144,9 @@ typedef struct MpegEncContext { UINT8 *aux_picture[3]; /* aux picture (for B frames only) */ UINT8 *aux_picture_base[3]; /* real start of the picture */ UINT8 *current_picture[3]; /* buffer to store the decompressed current picture */ + void *last_dr_opaque; + void *next_dr_opaque; + int ip_buffer_count; /* number of buffers, currently only >2 if dr1 is used */ int num_available_buffers; /* is 0 at the start & after seeking, after the first I frame its 1 after next I/P 2 */ int last_dc[3]; /* last DC values for MPEG1 */ INT16 *dc_val[3]; /* used for mpeg4 DC prediction, all 3 arrays must be continuous */ @@ -159,6 +163,7 @@ typedef struct MpegEncContext { UINT8 *cbp_table; /* used to store cbp, ac_pred for partitioned decoding */ UINT8 *pred_dir_table; /* used to store pred_dir for partitioned decoding */ INT8 *qscale_table; /* used to store qscale for partitioned decoding (& postprocessing FIXME export) */ + UINT8 *edge_emu_buffer; int input_qscale; /* qscale prior to reordering of frames */ int input_pict_type; /* pict_type prior to reordering of frames */ @@ -337,6 +342,8 @@ typedef struct MpegEncContext { int quant_precision; int quarter_sample; /* 1->qpel, 0->half pel ME/MC */ int scalability; + int hierachy_type; + int enhancement_type; int new_pred; int reduced_res_vop; int aspect_ratio_info; @@ -392,6 +399,7 @@ typedef struct MpegEncContext { UINT8 *intra_h_scantable; /* [mb_intra][isChroma][level][run][last] */ int ac_stats[2][2][MAX_LEVEL+1][MAX_RUN+1][2]; + int inter_intra_pred; /* decompression specific */ @@ -446,11 +454,14 @@ typedef struct MpegEncContext { int MPV_common_init(MpegEncContext *s); void MPV_common_end(MpegEncContext *s); void MPV_decode_mb(MpegEncContext *s, DCTELEM block[6][64]); -void MPV_frame_start(MpegEncContext *s); +void MPV_frame_start(MpegEncContext *s, AVCodecContext *avctx); void MPV_frame_end(MpegEncContext *s); #ifdef HAVE_MMX void MPV_common_init_mmx(MpegEncContext *s); #endif +#ifdef ARCH_ALPHA +void MPV_common_init_axp(MpegEncContext *s); +#endif extern int (*dct_quantize)(MpegEncContext *s, DCTELEM *block, int n, int qscale, int *overflow); extern void (*draw_edges)(UINT8 *buf, int wrap, int width, int height, int w); void ff_conceal_past_errors(MpegEncContext *s, int conceal_all); @@ -467,8 +478,8 @@ void ff_fix_long_p_mvs(MpegEncContext * s); void ff_fix_long_b_mvs(MpegEncContext * s, int16_t (*mv_table)[2], int f_code, int type); /* mpeg12.c */ -extern INT16 default_intra_matrix[64]; -extern INT16 default_non_intra_matrix[64]; +extern INT16 ff_mpeg1_default_intra_matrix[64]; +extern INT16 ff_mpeg1_default_non_intra_matrix[64]; extern UINT8 ff_mpeg1_dc_scale_table[128]; void mpeg1_encode_picture_header(MpegEncContext *s, int picture_number); @@ -478,7 +489,6 @@ void mpeg1_encode_mb(MpegEncContext *s, void ff_mpeg1_encode_init(MpegEncContext *s); /* h263enc.c */ - typedef struct RLTable { int n; /* number of entries of table_vlc minus 1 */ int last; /* number of values for last = 0 */ @@ -488,7 +498,8 @@ typedef struct RLTable { UINT8 *index_run[2]; /* encoding only */ INT8 *max_level[2]; /* encoding & decoding */ INT8 *max_run[2]; /* encoding & decoding */ - VLC vlc; /* decoding only */ + VLC vlc; /* decoding only deprected FIXME remove*/ + RL_VLC_ELEM *rl_vlc[32]; /* decoding only */ } RLTable; void init_rl(RLTable *rl); diff --git a/src/libffmpeg/libavcodec/msmpeg4.c b/src/libffmpeg/libavcodec/msmpeg4.c index 0cac44457..34dc3569d 100644 --- a/src/libffmpeg/libavcodec/msmpeg4.c +++ b/src/libffmpeg/libavcodec/msmpeg4.c @@ -32,6 +32,19 @@ */ //#define DEBUG +#define DC_VLC_BITS 9 +#define CBPY_VLC_BITS 6 +#define INTER_INTRA_VLC_BITS 3 +#define V1_INTRA_CBPC_VLC_BITS 6 +#define V1_INTER_CBPC_VLC_BITS 6 +#define V2_INTRA_CBPC_VLC_BITS 3 +#define V2_MB_TYPE_VLC_BITS 7 +#define MV_VLC_BITS 9 +#define V2_MV_VLC_BITS 9 +#define TEX_VLC_BITS 9 +#define MB_NON_INTRA_VLC_BITS 9 +#define MB_INTRA_VLC_BITS 9 + static UINT32 v2_dc_lum_table[512][2]; static UINT32 v2_dc_chroma_table[512][2]; @@ -43,6 +56,8 @@ static int msmpeg4_decode_motion(MpegEncContext * s, int *mx_ptr, int *my_ptr); static void msmpeg4v2_encode_motion(MpegEncContext * s, int val); static void init_h263_dc_for_msmpeg4(void); +static inline void msmpeg4_memsetw(short *tab, int val, int n); + extern UINT32 inverse[256]; @@ -345,14 +360,17 @@ void msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number) s->mv_table_index = 1; /* only if P frame */ s->use_skip_mb_code = 1; /* only if P frame */ s->per_mb_rl_table = 0; + s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=128 && s->pict_type==P_TYPE); if (s->pict_type == I_TYPE) { s->no_rounding = 1; - put_bits(&s->pb, 5, 0x17); /* indicate only one "slice" */ + s->slice_height= s->mb_height/1; + put_bits(&s->pb, 5, 0x16 + s->mb_height/s->slice_height); if(s->msmpeg4_version==4){ msmpeg4_encode_ext_header(s); - put_bits(&s->pb, 1, s->per_mb_rl_table); + if(s->bit_rate>50) + put_bits(&s->pb, 1, s->per_mb_rl_table); } if(s->msmpeg4_version>2){ @@ -366,7 +384,7 @@ void msmpeg4_encode_picture_header(MpegEncContext * s, int picture_number) } else { put_bits(&s->pb, 1, s->use_skip_mb_code); - if(s->msmpeg4_version==4) + if(s->msmpeg4_version==4 && s->bit_rate>50) put_bits(&s->pb, 1, s->per_mb_rl_table); if(s->msmpeg4_version>2){ @@ -398,7 +416,7 @@ void msmpeg4_encode_ext_header(MpegEncContext * s) { put_bits(&s->pb, 5, s->frame_rate / FRAME_RATE_BASE); //yes 29.97 -> 29 - put_bits(&s->pb, 11, MIN(s->bit_rate, 2047)); + put_bits(&s->pb, 11, MIN(s->bit_rate, 2047)); if(s->msmpeg4_version<3) s->flipflop_rounding=0; @@ -474,6 +492,38 @@ static void msmpeg4_encode_motion(MpegEncContext * s, } } +static inline void handle_slices(MpegEncContext *s){ + if (s->mb_x == 0) { + if (s->slice_height && (s->mb_y % s->slice_height) == 0) { + if(s->msmpeg4_version != 4){ + int wrap; + /* reset DC pred (set previous line to 1024) */ + wrap = 2 * s->mb_width + 2; + msmpeg4_memsetw(&s->dc_val[0][(1) + (2 * s->mb_y) * wrap], + 1024, 2 * s->mb_width); + wrap = s->mb_width + 2; + msmpeg4_memsetw(&s->dc_val[1][(1) + (s->mb_y) * wrap], + 1024, s->mb_width); + msmpeg4_memsetw(&s->dc_val[2][(1) + (s->mb_y) * wrap], + 1024, s->mb_width); + + /* reset AC pred (set previous line to 0) */ + wrap = s->mb_width * 2 + 2; + msmpeg4_memsetw(s->ac_val[0][0] + (1 + (2 * s->mb_y) * wrap)*16, + 0, 2 * s->mb_width*16); + wrap = s->mb_width + 2; + msmpeg4_memsetw(s->ac_val[1][0] + (1 + (s->mb_y) * wrap)*16, + 0, s->mb_width*16); + msmpeg4_memsetw(s->ac_val[2][0] + (1 + (s->mb_y) * wrap)*16, + 0, s->mb_width*16); + } + s->first_slice_line = 1; + } else { + s->first_slice_line = 0; + } + } +} + void msmpeg4_encode_mb(MpegEncContext * s, DCTELEM block[6][64], int motion_x, int motion_y) @@ -482,6 +532,8 @@ void msmpeg4_encode_mb(MpegEncContext * s, int pred_x, pred_y; UINT8 *coded_block; + handle_slices(s); + if (!s->mb_intra) { /* compute cbp */ set_stat(ST_INTER_MB); @@ -610,6 +662,19 @@ static inline int msmpeg4v1_pred_dc(MpegEncContext * s, int n, return s->last_dc[i]; } +static int get_dc(uint8_t *src, int stride, int scale) +{ + int y; + int sum=0; + for(y=0; y<8; y++){ + int x; + for(x=0; x<8; x++){ + sum+=src[x + y*stride]; + } + } + return (sum + (scale>>1))/scale; +} + /* dir = 0: left, dir = 1: top prediction */ static inline int msmpeg4_pred_dc(MpegEncContext * s, int n, UINT16 **dc_val_ptr, int *dir_ptr) @@ -675,12 +740,69 @@ static inline int msmpeg4_pred_dc(MpegEncContext * s, int n, /* XXX: WARNING: they did not choose the same test as MPEG4. This is very important ! */ if(s->msmpeg4_version>3){ - if (abs(a - b) < abs(b - c)) { - pred = c; - *dir_ptr = 1; - } else { - pred = a; - *dir_ptr = 0; + if(s->inter_intra_pred){ + uint8_t *dest; + int wrap; + + if(n==1){ + pred=a; + *dir_ptr = 0; + }else if(n==2){ + pred=c; + *dir_ptr = 1; + }else if(n==3){ + if (abs(a - b) < abs(b - c)) { + pred = c; + *dir_ptr = 1; + } else { + pred = a; + *dir_ptr = 0; + } + }else{ + if(n<4){ + wrap= s->linesize; + dest= s->current_picture[0] + (((n>>1) + 2*s->mb_y) * 8* wrap ) + ((n&1) + 2*s->mb_x) * 8; + }else{ + wrap= s->uvlinesize; + dest= s->current_picture[n-3] + (s->mb_y * 8 * wrap) + s->mb_x * 8; + } + if(s->mb_x==0) a= (1024 + (scale>>1))/scale; + else a= get_dc(dest-8, wrap, scale*8); + if(s->mb_y==0) c= (1024 + (scale>>1))/scale; + else c= get_dc(dest-8*wrap, wrap, scale*8); + + if (s->h263_aic_dir==0) { + pred= a; + *dir_ptr = 0; + }else if (s->h263_aic_dir==1) { + if(n==0){ + pred= c; + *dir_ptr = 1; + }else{ + pred= a; + *dir_ptr = 0; + } + }else if (s->h263_aic_dir==2) { + if(n==0){ + pred= a; + *dir_ptr = 0; + }else{ + pred= c; + *dir_ptr = 1; + } + } else { + pred= c; + *dir_ptr = 1; + } + } + }else{ + if (abs(a - b) < abs(b - c)) { + pred = c; + *dir_ptr = 1; + } else { + pred = a; + *dir_ptr = 0; + } } }else{ if (abs(a - b) <= abs(b - c)) { @@ -904,6 +1026,7 @@ static VLC v2_mb_type_vlc; static VLC v2_mv_vlc; static VLC v1_intra_cbpc_vlc; static VLC v1_inter_cbpc_vlc; +static VLC inter_intra_vlc; /* this table is practically identical to the one from h263 except that its inverted */ static void init_h263_dc_for_msmpeg4(void) @@ -978,57 +1101,61 @@ int ff_msmpeg4_decode_init(MpegEncContext *s) } for(i=0;i<2;i++) { mv = &mv_tables[i]; - init_vlc(&mv->vlc, 9, mv->n + 1, + init_vlc(&mv->vlc, MV_VLC_BITS, mv->n + 1, mv->table_mv_bits, 1, 1, mv->table_mv_code, 2, 2); } - init_vlc(&dc_lum_vlc[0], 9, 120, + init_vlc(&dc_lum_vlc[0], DC_VLC_BITS, 120, &table0_dc_lum[0][1], 8, 4, &table0_dc_lum[0][0], 8, 4); - init_vlc(&dc_chroma_vlc[0], 9, 120, + init_vlc(&dc_chroma_vlc[0], DC_VLC_BITS, 120, &table0_dc_chroma[0][1], 8, 4, &table0_dc_chroma[0][0], 8, 4); - init_vlc(&dc_lum_vlc[1], 9, 120, + init_vlc(&dc_lum_vlc[1], DC_VLC_BITS, 120, &table1_dc_lum[0][1], 8, 4, &table1_dc_lum[0][0], 8, 4); - init_vlc(&dc_chroma_vlc[1], 9, 120, + init_vlc(&dc_chroma_vlc[1], DC_VLC_BITS, 120, &table1_dc_chroma[0][1], 8, 4, &table1_dc_chroma[0][0], 8, 4); - init_vlc(&v2_dc_lum_vlc, 9, 512, + init_vlc(&v2_dc_lum_vlc, DC_VLC_BITS, 512, &v2_dc_lum_table[0][1], 8, 4, &v2_dc_lum_table[0][0], 8, 4); - init_vlc(&v2_dc_chroma_vlc, 9, 512, + init_vlc(&v2_dc_chroma_vlc, DC_VLC_BITS, 512, &v2_dc_chroma_table[0][1], 8, 4, &v2_dc_chroma_table[0][0], 8, 4); - init_vlc(&cbpy_vlc, 6, 16, + init_vlc(&cbpy_vlc, CBPY_VLC_BITS, 16, &cbpy_tab[0][1], 2, 1, &cbpy_tab[0][0], 2, 1); - init_vlc(&v2_intra_cbpc_vlc, 3, 4, + init_vlc(&v2_intra_cbpc_vlc, V2_INTRA_CBPC_VLC_BITS, 4, &v2_intra_cbpc[0][1], 2, 1, &v2_intra_cbpc[0][0], 2, 1); - init_vlc(&v2_mb_type_vlc, 5, 8, + init_vlc(&v2_mb_type_vlc, V2_MB_TYPE_VLC_BITS, 8, &v2_mb_type[0][1], 2, 1, &v2_mb_type[0][0], 2, 1); - init_vlc(&v2_mv_vlc, 9, 33, + init_vlc(&v2_mv_vlc, V2_MV_VLC_BITS, 33, &mvtab[0][1], 2, 1, &mvtab[0][0], 2, 1); - init_vlc(&mb_non_intra_vlc, 9, 128, + init_vlc(&mb_non_intra_vlc, MB_NON_INTRA_VLC_BITS, 128, &table_mb_non_intra[0][1], 8, 4, &table_mb_non_intra[0][0], 8, 4); - init_vlc(&mb_intra_vlc, 9, 64, + init_vlc(&mb_intra_vlc, MB_INTRA_VLC_BITS, 64, &table_mb_intra[0][1], 4, 2, &table_mb_intra[0][0], 4, 2); - init_vlc(&v1_intra_cbpc_vlc, 6, 8, + init_vlc(&v1_intra_cbpc_vlc, V1_INTRA_CBPC_VLC_BITS, 8, intra_MCBPC_bits, 1, 1, intra_MCBPC_code, 1, 1); - init_vlc(&v1_inter_cbpc_vlc, 6, 25, + init_vlc(&v1_inter_cbpc_vlc, V1_INTER_CBPC_VLC_BITS, 25, inter_MCBPC_bits, 1, 1, inter_MCBPC_code, 1, 1); + + init_vlc(&inter_intra_vlc, INTER_INTRA_VLC_BITS, 4, + &table_inter_intra[0][1], 2, 1, + &table_inter_intra[0][0], 2, 1); } return 0; } @@ -1075,7 +1202,13 @@ return -1; fprintf(stderr, "invalid picture type\n"); return -1; } - +#if 0 +{ + static int had_i=0; + if(s->pict_type == I_TYPE) had_i=1; + if(!had_i) return -1; +} +#endif s->qscale = get_bits(&s->gb, 5); if (s->pict_type == I_TYPE) { @@ -1089,8 +1222,10 @@ return -1; s->slice_height = code; }else{ /* 0x17: one slice, 0x18: two slices, ... */ - if (code < 0x17) + if (code < 0x17){ + fprintf(stderr, "error, slice code was %X\n", code); return -1; + } s->slice_height = s->mb_height / (code - 0x16); } @@ -1112,24 +1247,27 @@ return -1; case 4: msmpeg4_decode_ext_header(s, (2+5+5+17+7)/8); - s->per_mb_rl_table= get_bits1(&s->gb); + if(s->bit_rate > 50) s->per_mb_rl_table= get_bits1(&s->gb); + else s->per_mb_rl_table= 0; + if(!s->per_mb_rl_table){ s->rl_chroma_table_index = decode012(&s->gb); s->rl_table_index = decode012(&s->gb); } s->dc_table_index = get_bits1(&s->gb); + s->inter_intra_pred= 0; break; } s->no_rounding = 1; -/* printf(" %d %d %d %d %d \n", +/* printf("qscale:%d rlc:%d rl:%d dc:%d mbrl:%d slice:%d \n", s->qscale, s->rl_chroma_table_index, s->rl_table_index, s->dc_table_index, - s->per_mb_rl_table);*/ + s->per_mb_rl_table, + s->slice_height);*/ } else { - switch(s->msmpeg4_version){ case 1: case 2: @@ -1153,7 +1291,10 @@ return -1; break; case 4: s->use_skip_mb_code = get_bits1(&s->gb); - s->per_mb_rl_table= get_bits1(&s->gb); + + if(s->bit_rate > 50) s->per_mb_rl_table= get_bits1(&s->gb); + else s->per_mb_rl_table= 0; + if(!s->per_mb_rl_table){ s->rl_table_index = decode012(&s->gb); s->rl_chroma_table_index = s->rl_table_index; @@ -1162,15 +1303,17 @@ return -1; s->dc_table_index = get_bits1(&s->gb); s->mv_table_index = get_bits1(&s->gb); + s->inter_intra_pred= (s->width*s->height < 320*240 && s->bit_rate<=128); break; } -/* printf(" %d %d %d %d %d %d \n", +/* printf("skip:%d rl:%d rlc:%d dc:%d mv:%d mbrl:%d qp:%d \n", s->use_skip_mb_code, s->rl_table_index, s->rl_chroma_table_index, s->dc_table_index, s->mv_table_index, - s->per_mb_rl_table);*/ + s->per_mb_rl_table, + s->qscale);*/ if(s->flipflop_rounding){ s->no_rounding ^= 1; }else{ @@ -1263,7 +1406,7 @@ static int msmpeg4v2_decode_motion(MpegEncContext * s, int pred, int f_code) { int code, val, sign, shift; - code = get_vlc(&s->gb, &v2_mv_vlc); + code = get_vlc2(&s->gb, v2_mv_vlc.table, V2_MV_VLC_BITS, 2); // printf("MV code %d at %d %d pred: %d\n", code, s->mb_x,s->mb_y, pred); if (code < 0) return 0xffff; @@ -1310,9 +1453,9 @@ static int msmpeg4v12_decode_mb(MpegEncContext *s, } if(s->msmpeg4_version==2) - code = get_vlc(&s->gb, &v2_mb_type_vlc); + code = get_vlc2(&s->gb, v2_mb_type_vlc.table, V2_MB_TYPE_VLC_BITS, 1); else - code = get_vlc(&s->gb, &v1_inter_cbpc_vlc); + code = get_vlc2(&s->gb, v1_inter_cbpc_vlc.table, V1_INTER_CBPC_VLC_BITS, 3); if(code<0 || code>7){ fprintf(stderr, "cbpc %d invalid at %d %d\n", code, s->mb_x, s->mb_y); return -1; @@ -1324,9 +1467,9 @@ static int msmpeg4v12_decode_mb(MpegEncContext *s, } else { s->mb_intra = 1; if(s->msmpeg4_version==2) - cbp= get_vlc(&s->gb, &v2_intra_cbpc_vlc); + cbp= get_vlc2(&s->gb, v2_intra_cbpc_vlc.table, V2_INTRA_CBPC_VLC_BITS, 1); else - cbp= get_vlc(&s->gb, &v1_intra_cbpc_vlc); + cbp= get_vlc2(&s->gb, v1_intra_cbpc_vlc.table, V1_INTRA_CBPC_VLC_BITS, 1); if(cbp<0 || cbp>3){ fprintf(stderr, "cbpc %d invalid at %d %d\n", cbp, s->mb_x, s->mb_y); return -1; @@ -1336,7 +1479,7 @@ static int msmpeg4v12_decode_mb(MpegEncContext *s, if (!s->mb_intra) { int mx, my, cbpy; - cbpy= get_vlc(&s->gb, &cbpy_vlc); + cbpy= get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1); if(cbpy<0){ fprintf(stderr, "cbpy %d invalid at %d %d\n", cbp, s->mb_x, s->mb_y); return -1; @@ -1356,10 +1499,10 @@ static int msmpeg4v12_decode_mb(MpegEncContext *s, } else { if(s->msmpeg4_version==2){ s->ac_pred = get_bits1(&s->gb); - cbp|= get_vlc(&s->gb, &cbpy_vlc)<<2; //FIXME check errors + cbp|= get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1)<<2; //FIXME check errors } else{ s->ac_pred = 0; - cbp|= get_vlc(&s->gb, &cbpy_vlc)<<2; //FIXME check errors + cbp|= get_vlc2(&s->gb, cbpy_vlc.table, CBPY_VLC_BITS, 1)<<2; //FIXME check errors if(s->pict_type==P_TYPE) cbp^=0x3C; } } @@ -1387,34 +1530,7 @@ if(s->mb_x==0){ } #endif /* special slice handling */ - if (s->mb_x == 0) { - if (s->slice_height && (s->mb_y % s->slice_height) == 0) { - int wrap; - /* reset DC pred (set previous line to 1024) */ - wrap = 2 * s->mb_width + 2; - msmpeg4_memsetw(&s->dc_val[0][(1) + (2 * s->mb_y) * wrap], - 1024, 2 * s->mb_width); - wrap = s->mb_width + 2; - msmpeg4_memsetw(&s->dc_val[1][(1) + (s->mb_y) * wrap], - 1024, s->mb_width); - msmpeg4_memsetw(&s->dc_val[2][(1) + (s->mb_y) * wrap], - 1024, s->mb_width); - - /* reset AC pred (set previous line to 0) */ - wrap = s->mb_width * 2 + 2; - msmpeg4_memsetw(s->ac_val[0][0] + (1 + (2 * s->mb_y) * wrap)*16, - 0, 2 * s->mb_width*16); - wrap = s->mb_width + 2; - msmpeg4_memsetw(s->ac_val[1][0] + (1 + (s->mb_y) * wrap)*16, - 0, s->mb_width*16); - msmpeg4_memsetw(s->ac_val[2][0] + (1 + (s->mb_y) * wrap)*16, - 0, s->mb_width*16); - - s->first_slice_line = 1; - } else { - s->first_slice_line = 0; - } - } + handle_slices(s); if(s->msmpeg4_version<=2) return msmpeg4v12_decode_mb(s, block); //FIXME export function & call from outside perhaps @@ -1438,7 +1554,7 @@ printf("S "); } } - code = get_vlc(&s->gb, &mb_non_intra_vlc); + code = get_vlc2(&s->gb, mb_non_intra_vlc.table, MB_NON_INTRA_VLC_BITS, 3); if (code < 0) return -1; //s->mb_intra = (code & 0x40) ? 0 : 1; @@ -1448,7 +1564,7 @@ printf("S "); } else { set_stat(ST_INTRA_MB); s->mb_intra = 1; - code = get_vlc(&s->gb, &mb_intra_vlc); + code = get_vlc2(&s->gb, mb_intra_vlc.table, MB_INTRA_VLC_BITS, 2); if (code < 0) return -1; /* predict coded block pattern */ @@ -1489,6 +1605,10 @@ printf("P "); #ifdef PRINT_MB printf("%c", s->ac_pred ? 'A' : 'I'); #endif + if(s->inter_intra_pred){ + s->h263_aic_dir= get_vlc2(&s->gb, inter_intra_vlc.table, INTER_INTRA_VLC_BITS, 1); +// printf("%d%d %d %d/", s->ac_pred, s->h263_aic_dir, s->mb_x, s->mb_y); + } if(s->per_mb_rl_table && cbp){ s->rl_table_index = decode012(&s->gb); s->rl_chroma_table_index = s->rl_table_index; @@ -1509,9 +1629,10 @@ printf("%c", s->ac_pred ? 'A' : 'I'); static inline int msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block, int n, int coded) { - int code, level, i, j, last, run, run_diff; + int level, i, last, run, run_diff; int dc_pred_dir; RLTable *rl; + RL_VLC_ELEM *rl_vlc; const UINT8 *scan_table; int qmul, qadd; @@ -1532,25 +1653,26 @@ static inline int msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block, #endif if (level < 0){ fprintf(stderr, "dc overflow- block: %d qscale: %d//\n", n, s->qscale); - return -1; + if(s->inter_intra_pred) level=0; + else return -1; } if (n < 4) { rl = &rl_table[s->rl_table_index]; if(level > 256*s->y_dc_scale){ fprintf(stderr, "dc overflow+ L qscale: %d//\n", s->qscale); - return -1; + if(!s->inter_intra_pred) return -1; } } else { rl = &rl_table[3 + s->rl_chroma_table_index]; if(level > 256*s->c_dc_scale){ fprintf(stderr, "dc overflow+ C qscale: %d//\n", s->qscale); - return -1; + if(!s->inter_intra_pred) return -1; } } block[0] = level; run_diff = 0; - i = 1; + i = 0; if (!coded) { goto not_coded; } @@ -1563,10 +1685,11 @@ static inline int msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block, scan_table = s->intra_scantable; } set_stat(ST_INTRA_AC); + rl_vlc= rl->rl_vlc[0]; } else { qmul = s->qscale << 1; qadd = (s->qscale - 1) | 1; - i = 0; + i = -1; rl = &rl_table[3 + s->rl_table_index]; if(s->msmpeg4_version==2) @@ -1575,53 +1698,66 @@ static inline int msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block, run_diff = 1; if (!coded) { - s->block_last_index[n] = i - 1; + s->block_last_index[n] = i; return 0; } scan_table = s->inter_scantable; set_stat(ST_INTER_AC); + rl_vlc= rl->rl_vlc[s->qscale]; } - + { + OPEN_READER(re, &s->gb); for(;;) { - code = get_vlc(&s->gb, &rl->vlc); - if (code < 0){ - fprintf(stderr, "illegal AC-VLC code at %d %d\n", s->mb_x, s->mb_y); - return -1; - } - if (code == rl->n) { + UPDATE_CACHE(re, &s->gb); + GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2); + if (level==0) { + int cache; + cache= GET_CACHE(re, &s->gb); /* escape */ - if (s->msmpeg4_version==1 || get_bits1(&s->gb) == 0) { - if (s->msmpeg4_version==1 || get_bits1(&s->gb) == 0) { + if (s->msmpeg4_version==1 || (cache&0x80000000)==0) { + if (s->msmpeg4_version==1 || (cache&0x40000000)==0) { /* third escape */ + if(s->msmpeg4_version!=1) LAST_SKIP_BITS(re, &s->gb, 2); + UPDATE_CACHE(re, &s->gb); if(s->msmpeg4_version<=3){ - last= get_bits1(&s->gb); - run= get_bits(&s->gb, 6); - level= get_bits(&s->gb, 8); - level= ((int8_t)level); - }else{ + last= SHOW_UBITS(re, &s->gb, 1); SKIP_CACHE(re, &s->gb, 1); + run= SHOW_UBITS(re, &s->gb, 6); SKIP_CACHE(re, &s->gb, 6); + level= SHOW_SBITS(re, &s->gb, 8); LAST_SKIP_CACHE(re, &s->gb, 8); + SKIP_COUNTER(re, &s->gb, 1+6+8); + }else{ int sign; - last= get_bits1(&s->gb); + last= SHOW_UBITS(re, &s->gb, 1); SKIP_BITS(re, &s->gb, 1); if(!s->esc3_level_length){ int ll; //printf("ESC-3 %X at %d %d\n", show_bits(&s->gb, 24), s->mb_x, s->mb_y); if(s->qscale<8){ - ll= get_bits(&s->gb, 3); + ll= SHOW_UBITS(re, &s->gb, 3); SKIP_BITS(re, &s->gb, 3); if(ll==0){ - if(get_bits1(&s->gb)) printf("cool a new vlc code ,contact the ffmpeg developers and upload the file\n"); + if(SHOW_UBITS(re, &s->gb, 1)) printf("cool a new vlc code ,contact the ffmpeg developers and upload the file\n"); + SKIP_BITS(re, &s->gb, 1); ll=8; } }else{ ll=2; - while(ll<8 && get_bits1(&s->gb)==0) ll++; + while(ll<8 && SHOW_UBITS(re, &s->gb, 1)==0){ + ll++; + SKIP_BITS(re, &s->gb, 1); + } + SKIP_BITS(re, &s->gb, 1); } s->esc3_level_length= ll; - s->esc3_run_length= get_bits(&s->gb, 2) + 3; + s->esc3_run_length= SHOW_UBITS(re, &s->gb, 2) + 3; SKIP_BITS(re, &s->gb, 2); //printf("level length:%d, run length: %d\n", ll, s->esc3_run_length); } - run= get_bits(&s->gb, s->esc3_run_length); - sign= get_bits1(&s->gb); - level= get_bits(&s->gb, s->esc3_level_length); + run= SHOW_UBITS(re, &s->gb, s->esc3_run_length); + SKIP_BITS(re, &s->gb, s->esc3_run_length); + + sign= SHOW_UBITS(re, &s->gb, 1); + SKIP_BITS(re, &s->gb, 1); + + level= SHOW_UBITS(re, &s->gb, s->esc3_level_length); + SKIP_BITS(re, &s->gb, s->esc3_level_length); if(sign) level= -level; } //printf("level: %d, run: %d at %d %d\n", level, run, s->mb_x, s->mb_y); @@ -1654,64 +1790,64 @@ static inline int msmpeg4_decode_block(MpegEncContext * s, DCTELEM * block, return DECODING_AC_LOST; } #endif + i+= run + 1; + if(last) i+=192; } else { /* second escape */ - code = get_vlc(&s->gb, &rl->vlc); - if (code < 0 || code >= rl->n){ - fprintf(stderr, "illegal ESC2-VLC code %d at %d %d\n", code, s->mb_x, s->mb_y); - return -1; - } - run = rl->table_run[code]; - level = rl->table_level[code]; - last = code >= rl->last; - run += rl->max_run[last][level] + run_diff; - level= level * qmul + qadd; - if (get_bits1(&s->gb)) - level = -level; +#if MIN_CACHE_BITS < 23 + LAST_SKIP_BITS(re, &s->gb, 2); + UPDATE_CACHE(re, &s->gb); +#else + SKIP_BITS(re, &s->gb, 2); +#endif + GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2); + i+= run + rl->max_run[run>>7][level/qmul] + run_diff; //FIXME opt indexing + level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); + LAST_SKIP_BITS(re, &s->gb, 1); } } else { /* first escape */ - code = get_vlc(&s->gb, &rl->vlc); - if (code < 0 || code >= rl->n){ - fprintf(stderr, "illegal ESC2-VLC code %d at %d %d\n", code, s->mb_x, s->mb_y); - return -1; - } - run = rl->table_run[code]; - level = rl->table_level[code]; - last = code >= rl->last; - level += rl->max_level[last][run]; - level= level * qmul + qadd; - if (get_bits1(&s->gb)) - level = -level; +#if MIN_CACHE_BITS < 22 + LAST_SKIP_BITS(re, &s->gb, 1); + UPDATE_CACHE(re, &s->gb); +#else + SKIP_BITS(re, &s->gb, 1); +#endif + GET_RL_VLC(level, run, re, &s->gb, rl_vlc, TEX_VLC_BITS, 2); + i+= run; + level = level + rl->max_level[run>>7][(run-1)&63] * qmul;//FIXME opt indexing + level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); + LAST_SKIP_BITS(re, &s->gb, 1); } } else { - run = rl->table_run[code]; - level = rl->table_level[code] * qmul + qadd; - last = code >= rl->last; - if (get_bits1(&s->gb)) - level = -level; - } - i += run; - if (i >= 64){ - fprintf(stderr, "run too long at %d %d\n", s->mb_x, s->mb_y); - return -1; + i+= run; + level = (level ^ SHOW_SBITS(re, &s->gb, 1)) - SHOW_SBITS(re, &s->gb, 1); + LAST_SKIP_BITS(re, &s->gb, 1); } + if (i > 62){ + i-= 192; + if(i&(~63)){ + fprintf(stderr, "ac-tex damaged at %d %d\n", s->mb_x, s->mb_y); + return -1; + } - j = scan_table[i]; - block[j] = level; - i++; - if (last) + block[scan_table[i]] = level; break; + } + + block[scan_table[i]] = level; } + CLOSE_READER(re, &s->gb); + } not_coded: if (s->mb_intra) { mpeg4_pred_ac(s, block, n, dc_pred_dir); if (s->ac_pred) { - i = 64; /* XXX: not optimal */ + i = 63; /* XXX: not optimal */ } } - if(s->msmpeg4_version==4 && i>1) i=64; //FIXME/XXX optimize - s->block_last_index[n] = i - 1; + if(s->msmpeg4_version==4 && i>0) i=63; //FIXME/XXX optimize + s->block_last_index[n] = i; return 0; } @@ -1722,18 +1858,18 @@ static int msmpeg4_decode_dc(MpegEncContext * s, int n, int *dir_ptr) if(s->msmpeg4_version<=2){ if (n < 4) { - level = get_vlc(&s->gb, &v2_dc_lum_vlc); + level = get_vlc2(&s->gb, v2_dc_lum_vlc.table, DC_VLC_BITS, 3); } else { - level = get_vlc(&s->gb, &v2_dc_chroma_vlc); + level = get_vlc2(&s->gb, v2_dc_chroma_vlc.table, DC_VLC_BITS, 3); } if (level < 0) return -1; level-=256; }else{ //FIXME optimize use unified tables & index if (n < 4) { - level = get_vlc(&s->gb, &dc_lum_vlc[s->dc_table_index]); + level = get_vlc2(&s->gb, dc_lum_vlc[s->dc_table_index].table, DC_VLC_BITS, 3); } else { - level = get_vlc(&s->gb, &dc_chroma_vlc[s->dc_table_index]); + level = get_vlc2(&s->gb, dc_chroma_vlc[s->dc_table_index].table, DC_VLC_BITS, 3); } if (level < 0){ fprintf(stderr, "illegal dc vlc\n"); @@ -1781,7 +1917,7 @@ static int msmpeg4_decode_motion(MpegEncContext * s, mv = &mv_tables[s->mv_table_index]; - code = get_vlc(&s->gb, &mv->vlc); + code = get_vlc2(&s->gb, mv->vlc.table, MV_VLC_BITS, 2); if (code < 0){ fprintf(stderr, "illegal MV code at %d %d\n", s->mb_x, s->mb_y); return -1; diff --git a/src/libffmpeg/libavcodec/msmpeg4data.h b/src/libffmpeg/libavcodec/msmpeg4data.h index 9d728ef2e..cab8f04dd 100644 --- a/src/libffmpeg/libavcodec/msmpeg4data.h +++ b/src/libffmpeg/libavcodec/msmpeg4data.h @@ -1867,3 +1867,7 @@ static UINT8 *wmv1_scantable[WMV1_SCANTABLE_COUNT+1]={ wmv1_scantable03, }; +static UINT8 table_inter_intra[4][2]={ + {0,1},{2,2},{6,3},{7,3} +}; + diff --git a/src/libffmpeg/libavcodec/rv10.c b/src/libffmpeg/libavcodec/rv10.c index 261c889de..438d0dd38 100644 --- a/src/libffmpeg/libavcodec/rv10.c +++ b/src/libffmpeg/libavcodec/rv10.c @@ -22,6 +22,8 @@ //#define DEBUG +#define DC_VLC_BITS 9 + static const UINT16 rv_lum_code[256] = { 0x3e7f, 0x0f00, 0x0f01, 0x0f02, 0x0f03, 0x0f04, 0x0f05, 0x0f06, @@ -173,7 +175,7 @@ int rv_decode_dc(MpegEncContext *s, int n) int code; if (n < 4) { - code = get_vlc(&s->gb, &rv_dc_lum); + code = get_vlc2(&s->gb, rv_dc_lum.table, DC_VLC_BITS, 2); if (code < 0) { /* XXX: I don't understand why they use LONGER codes than necessary. The following code would be completely useless @@ -196,7 +198,7 @@ int rv_decode_dc(MpegEncContext *s, int n) code -= 128; } } else { - code = get_vlc(&s->gb, &rv_dc_chrom); + code = get_vlc2(&s->gb, rv_dc_chrom.table, DC_VLC_BITS, 2); /* same remark */ if (code < 0) { code = get_bits(&s->gb, 9); @@ -351,10 +353,10 @@ static int rv10_decode_init(AVCodecContext *avctx) /* init rv vlc */ if (!done) { - init_vlc(&rv_dc_lum, 9, 256, + init_vlc(&rv_dc_lum, DC_VLC_BITS, 256, rv_lum_bits, 1, 1, rv_lum_code, 2, 2); - init_vlc(&rv_dc_chrom, 9, 256, + init_vlc(&rv_dc_chrom, DC_VLC_BITS, 256, rv_chrom_bits, 1, 1, rv_chrom_code, 2, 2); done = 1; @@ -417,7 +419,7 @@ static int rv10_decode_frame(AVCodecContext *avctx, } if (s->mb_x == 0 && s->mb_y == 0) { - MPV_frame_start(s); + MPV_frame_start(s, avctx); } #ifdef DEBUG @@ -485,8 +487,8 @@ static int rv10_decode_frame(AVCodecContext *avctx, pict->data[1] = s->current_picture[1]; pict->data[2] = s->current_picture[2]; pict->linesize[0] = s->linesize; - pict->linesize[1] = s->linesize / 2; - pict->linesize[2] = s->linesize / 2; + pict->linesize[1] = s->uvlinesize; + pict->linesize[2] = s->uvlinesize; avctx->quality = s->qscale; *data_size = sizeof(AVPicture); diff --git a/src/libffmpeg/libavcodec/svq1.c b/src/libffmpeg/libavcodec/svq1.c new file mode 100644 index 000000000..6922614fd --- /dev/null +++ b/src/libffmpeg/libavcodec/svq1.c @@ -0,0 +1,2685 @@ +/* + * + * Copyright (C) 2002 the xine project + * Copyright (C) 2002 the ffmpeg project + * + * This library 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 of the License, or (at your option) any later version. + * + * This library 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 library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * Ported to mplayer by Arpi <arpi@thot.banki.hu> + * Ported to libavcodec by Nick Kurshev <nickols_k@mail.ru> + * + */ +//#define DEBUG_SVQ1 +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +#include "common.h" +#include "avcodec.h" +#include "dsputil.h" +#include "mpegvideo.h" +#include "bswap.h" +#define bit_buffer_t GetBitContext + +static inline unsigned int get_bit_cache(GetBitContext *s){ + OPEN_READER(re, s) + UPDATE_CACHE(re, s) + return GET_CACHE(re, s); +// CLOSE_READER(re, s) +} + +/* variable length (bit) code */ +typedef struct vlc_code_s { + int16_t value :10, + length :6; +} vlc_code_t; + +#define MEDIAN(a,b,c) (((a < b) != (b >= c)) ? b : (((a < c) != (c > b)) ? c : a)) + +#define SVQ1_BLOCK_SKIP 0 +#define SVQ1_BLOCK_INTER 1 +#define SVQ1_BLOCK_INTER_4V 2 +#define SVQ1_BLOCK_INTRA 3 + +#define SVQ1_FRAME_INTRA 0 +#define SVQ1_FRAME_INTER 1 +#define SVQ1_FRAME_DROPPABLE 2 + +/* motion vector (prediction) */ +typedef struct svq1_pmv_s { + int x; + int y; +} svq1_pmv_t; + +/* 6x16-entry codebook for inter-coded 4x2 vectors */ +static int8_t svq1_inter_codebook_4x2[768] = { + 7, 2, -6, -7, 7, 3, -3, -4, -7, -2, 7, 8, -8, -4, 3, 4, + 19, 17, 9, 3,-14,-16,-12, -8,-18,-16, -8, -3, 11, 14, 12, 8, + 7,-16,-10, 20, 7,-17,-10, 20, -6, 18, 8,-21, -7, 18, 9,-20, + 25, 3,-20,-14, 29, 7,-18,-13,-29, -4, 21, 14,-31, -6, 20, 14, + -19,-26,-28,-24, 31, 32, 22, 10, 15, 24, 31, 28,-32,-32,-22,-13, + 2, -8,-23,-26, -9, 3, 27, 35, 3, 11, 21, 21, 8, -4,-27,-34, + -30,-31, 12, 47,-29,-30, 13, 47, 38, 30,-17,-46, 34, 26,-19,-46, + -42,-50,-51,-43, 34, 48, 55, 48, 48, 54, 51, 42,-44,-52,-53,-47, + 4, 5, 0, -6, -2, -2, 0, 1,-11, -6, -1, -2, 1, 8, 9, 1, + 0, 1, -6, 5, 8, 1,-12, 2, 7,-14, -7, 8, 5, -8, 0, 8, + 1, 4, 11, 8,-12, -8, 0, -5, -1, 1, 0, 4,-15, -8, 3, 16, + 17, 8, -4, -6, 9, -4,-13, -8, 2, 6, 1,-18, -1, 11, 11,-12, + 6, 0, 2, 0, 14, 6, -7,-21, 1, -1,-13,-20, 1, 1, 10, 21, + -22, -5, 7, 13,-11, -1, 4, 12, -7, 0, 14, 19, -4, 3, -5,-19, + -26,-14, 10, 15, 18, 4, -6, -2, 25, 19, -5,-18,-20, -7, 4, 2, + -13, -6, -1, -4, 25, 37, -2,-35, 5, 4, 1, 1,-21,-36, 2, 43, + 2, -2, -1, 3, 8, -2, -6, -1, -2, -3, 2, 12, -5, -2, -2, -1, + -3, -1, -1, -5, -1, 7, 8, -2, 2, 7, 5, -3, 1, 1, -3, -8, + -3, -1, -3, -2, -2, -3, 2, 13, 15, 0,-11, -6, 3, 0, 0, 0, + -6, -9, -5, -4, 18, 4, 1, 3, 12, 3, 0, 4,-16, -3, 3, -3, + -17, 3, 18, 2, -1, -3, -1, -1, -6, 16, -8, 0, -9, 14, -7, 0, + 3,-13, 14, -5, 3,-13, 14, -4, -7, 20, 14,-23, 8, -7, -8, 4, + 8,-15,-19, 16,-10, 13, 11, -3, 9, -1, 1, 26, 5,-15,-27, 2, + -20, 7, 16, -4,-40, 9, 31, 1, 26,-12,-30, -7, 40, -2,-19, 4, + 6, 0, 0, 0, -6, -2, 1, 2, 0, -1, 0, -6, 9, 0, -2, -1, + -7, 8, 2, -3, -1, 2, -3, 2, 7, -4, -2, 4, 2, 0, 0, -6, + -3, -2, 9, 2, -2, -1, 0, -4, -3, -3, 0, -3, -6, 2, 10, 4, + 3, 0,-10, 8, 0, 0, -4, 4, -1, 1, 4, 2, 3, -7, -9, 7, + 2, 1, -9, -4, -1, 12, 0, 0, 3, -1, 7, -4, 3,-14, 4, 2, + -12, -9, 1, 11, 2, 5, 1, 0, 3, 1, 0, 2, 0, 8, 6,-19, + -6,-10, -7, -4, 9, 7, 5, 7, 6, 21, 3, -3,-11, -9, -5, -2, + -4, -9,-16, -1, -2, -5, 1, 36, 8, 11, 19, 0, 2, 5, -4,-41, + -1, -1, -2, -1, -2, -2, 1, 6, 0, 4, 1, -8, 1, 1, 1, 0, + -2, -3, 4, 0, 2, -1, 3, -3, 1, 3, -4, 1, -1, 3, 0, -5, + 3, 4, 2, 3, -2, -3, -6, -1, -2, -3, -2, 2, -4, 8, 1, 0, + -7, 4, 2, 6, -7, -1, 1, 0, -2, 2, -4, 1, 8, -6, 2, -1, + -6, 2, 0, 2, 5, 4, -8, -1, -1,-11, 0, 9, 0, -2, 2, 2, + 17, -5, -4, -1, -1, -4, -2, -2, 0,-13, 9, -3, -1, 12, -7, 2, + 0, -2, -5, 2, -7, -5, 20, -3, 7, 7, -1,-30, 3, 5, 8, 1, + -6, 3, -1, -4, 2, -2,-11, 18, 0, -7, 3, 14, 20, -3,-18, -9, + 7, -2, 0, -1, -2, 0, 0, -1, -4, -1, 1, 0, -2, 2, 0, 4, + 1, -3, 2, 1, 3, 1, -5, 1, -3, 0, -1, -2, 7, 1, 0, -3, + 2, 5, 0, -2, 2, -5, -1, 1, -1, -2, 4, -1, 0, -3, 5, 0, + 0, 3, -1, -2, -4, 1, 5, -1, -1, 0, -1, 9, -1, -2, -1, -1, + -2, 5, 5, -1, -2, 2, -3, -2, 1, 2,-11, 1, 2, 1, 3, 2, + 2,-10, -1, -2, 4, 2, 4, 1, 4, 5, -5, 1, 0, 6,-11, 1, + 1, 0, 6, 6, 0, 2, 1,-15, 7, 3, 5, 9,-30, 2, 2, 2, + -34, 1, 9, 2, 5, 8, 8, 2, 7, 2, 6, 6, 2,-27, 1, 4 +}; + +/* 6x16-entry codebook for inter-coded 4x4 vectors */ +static int8_t svq1_inter_codebook_4x4[1536] = { + 4, 0, -6, -7, -4, -8,-13, -9, -8, -8, -1, 6, -2, 5, 22, 27, + -16, -7, 11, 10,-18, -7, 13, 10,-15, -4, 12, 8, -9, -1, 9, 5, + -2, 2, 15,-16, -3, 2, 19,-19, -3, 2, 19,-19, -2, 3, 15,-14, + 17, 22, 22, 16, -6, -7, -5, -2,-12,-16,-16,-12, 1, 1, -1, -3, + 11,-17, 0, 8, 14,-21, -1, 9, 14,-21, -2, 8, 11,-16, -2, 6, + 7, -2,-16, 11, 9, -2,-21, 14, 10, -1,-22, 14, 8, -1,-18, 10, + -10, 16, 3, -9,-13, 20, 4,-11,-14, 21, 4,-10,-11, 16, 3, -8, + 11, 4, -9, -9, 15, 6,-12,-14, 17, 8,-12,-14, 16, 10, -7,-11, + 4, 10, 14, 13, -1, 7, 15, 16,-12, -7, 3, 8,-20,-23,-18,-10, + -10,-18,-26,-25, 4, 1, -6,-11, 13, 15, 11, 3, 12, 15, 13, 8, + -16,-19,-16,-11, 7, 12, 15, 11, 11, 16, 16, 11, -6, -9,-11,-10, + 18, 19, 12, 5, 18, 16, 5, -4, 6, 0,-10,-15, -9,-17,-23,-22, + -10,-14, -1, 21,-11,-17, 0, 29,-11,-16, 1, 30,-10,-14, 0, 23, + -16,-17,-12, -6,-19,-19,-14, -7, -3, -1, 1, 2, 27, 35, 29, 19, + -37, -8, 23, 23,-42, -9, 28, 29,-43,-10, 26, 28,-38,-11, 19, 22, + 32, 16,-16,-33, 39, 20,-18,-37, 38, 19,-19,-38, 32, 15,-17,-34, + 24, 9, -6, -4, -1,-10, -6, 3, -8, -9, -1, 3, 3, 7, 2, -6, + -1, -3, -1, 0, -1, 4, 2, -7, -3, 11, 3,-16, 1, 20, 9,-18, + -3, -8, 6, 12, -5,-10, 7, 13, -6, -9, 5, 7, -5, -5, 2, -1, + -8, 12, -3, -1,-10, 15, -3, 1,-11, 13, -4, 1,-11, 8, -3, 2, + 9, 6, -5,-12, 3, 0, -8,-13, -4, -4, -1, -1, -4, 1, 15, 18, + 9, 13, 14, 12, 4, 3, -1, -2, -2, -5, -8, -5, -7,-11, -9, -4, + 7, -5, -7, -4, 14, -2, -7, -4, 17, 0, -8, -5, 15, 1, -7, -5, + -10, -1, 6, 4,-15, -9, 2, 4, 2, -1, -3, 0, 25, 13, -8,-10, + 7, 11, -3,-16, 7, 11, -3,-15, 6, 7, -2, -9, 4, 2, -3, -5, + -7, -1, -1, 0, -9, -2, 2, 6,-12, -4, 6, 14,-13, -6, 8, 19, + -18,-18,-11, -5, -3, 0, 3, 4, 6, 8, 6, 6, 6, 6, 6, 6, + -5, 3, 13,-10, -6, 1, 15, -9, -6, -3, 15, -6, -6, -6, 10, -3, + 9, 1, -9, -9, 11, 9, 6, 5, 0, 3, 8, 7,-15,-14, -6, -5, + -11, -6, 11, 19, -2, -5, -9, -8, 6, 2, -9,-10, 6, 5, 4, 5, + -7, -3, 8, 15, -1, 3, 10, 15, 5, 5, -1, -2, 4, -2,-21,-25, + 6, -6, -6, 5, 8, -9, -7, 9, 8,-12, -7, 13, 4,-14, -7, 14, + -4, -3, 1, 1, -3, -5, -2, -3, 7, 0, -2, -4, 20, 7, -4, -4, + -3,-20, -6, 10, 6, 0, 0, 1, 5, 8, 5, -1, -3, 0, 0, -2, + 13, 6, -1, 2, 5, 3, 2, 3, -3, 0, 3, 0,-16, -8, -2, -5, + -2, -7, -6, 0, -3, -6, -3, 1, -5, -1, 2, -1, -1, 12, 16, 5, + -7, 1, 9, 8,-10, -2, 5, 3, -6, 2, 7, 3, -4, 0, -1, -7, + 3, 4, -9,-24, 0, 2, 6, 3, -1, -1, 4, 7, 5, 3, -1, -2, + 3, 6, -9, 2, 1, 6,-13, 1, 1, 8,-10, 2, 1, 8, -7, 1, + -3, -3, 2, 22, -2, -3, -5, 12, -2, -3,-10, 2, -3, -1, -4, 2, + 11, 12, 8, 2, -5, -5, -5, -8, -6, -4, 0, -3, -2, -1, 3, 3, + 12, -6, -2, -1, 12, -8, -2, -2, 9, -7, 0, -3, 4, -6, 2, -2, + -19, 1, 12, -3, -4, 4, 5, -4, 6, 1, -2, -1, 4, -4, -2, 7, + -3, -4, -7, -8, -4, -4, -2, 0, -1, 2, 14, 16, -4, -2, 4, 4, + -1, 7, 2, -5, -2, 0, -1, 1, 4, -3, -1, 13, 6,-12,-14, 8, + -1, 5, 4, -5, -2, 5, 3, -9, -2, 7, 4,-12, -1, 7, 4, -9, + -6, -3, 1, 1, 11, 11, 0, -6, 6, 4, -2, -7,-12,-10, 3, 10, + -2, -3, -3, -2, 6, 11, 14, 10, -9,-11,-10,-10, 2, 2, 3, 2, + -7, -5, -7, -1, -1, 2, 0, 7, -1, 1, 0, 9, 3, 4, -5, -1, + 10, -1,-15, -1, 4, 1, -5, 2, -3, 1, -1, 1, -3, 1, 4, 4, + 2, -1, 4, 10, 6, 2, -1, 0, 2, 2, -7,-12, -4, 2, 0, -3, + -1, -4, -1, -8, 3, -1, 2, -9, 4, 0, 5, -5, 2, 0, 8, 3, + 3, 2, 1, 1, 4, -2, 0, 3, 2, -1, 4, 1, 0, 6, -1,-25, + -1, -2, -2, -4, -3, 0, -1, -4, -1, -1, -4, 2, 0, -6, 2, 25, + -11, -1, 5, 0, 7, 0, -2, 2, 10, -1, -3, 4, -5, -5, -2, -1, + 0, 6, 3, -1, -2, -1, -1, 1, -1, -7,-12, -5, 8, 6, 2, 4, + 2, 6, -1, -6, 9, 10, -1, -4, 1, 0, -4, 0, 3, -2, -9, -5, + -4, 3, 4, 0, -4, 3, 3, 0,-11, 0, 3, 2,-11, 3, 7, 2, + 2, -4, 7, 3, 1, -8, 7, 1, -1,-12, 4, 1, 3, -9, 2, 2, + 2, -2, -2, 9,-17, -3, 3, 1, -4, 7, 1, -6, 5, 4, -1, 3, + -1, 2, 0, -4, -7, 8, 12, -1, -2, 5, 4, -5, 3, -5, -8, -2, + 0, 0, -5, -2, -2, -8, 3, 27, -1, -4, -3, 6, -3, 1, -2, -7, + 4, 4, 1, -1, -7,-10, -7, -3, 10, 10, 5, 3, -2, -2, -4, -3, + 0, 1, 5, 7, 4, -2,-16,-20, 0, 4, 7, 8, 2, 0, -2, -1, + -2, 1, 3, 17, -3, 1, -2, -1, -1, -2, -1, -2, -1, -5, -1, 0, + 5, -3, 1, 0, 6, -2, 0, 0, -1, -2, 0, -3,-11, 1, 8, -1, + 3, 0, 0, 0, 0, 2, 4, 1, 2, 0, 6, 1, -2,-18, -3, 2, + -14, 0, 6, 1, -5, -2, -1, 1, -1, 1, 0, 1, 1, 7, 4, 0, + -1, 0, 1, -4, 1, 8, 3, -4, -3, 4, 1, 3, -6, 1, -4, 1, + 1,-12, 3, 3, -1,-10, 0, -1, 2, 0, 2, 1, 3, 2, 2, 4, + 3, 0, 0, 3, 2, 0, -2, 1, 5, 2, -5, 0, 6, -1,-14, -1, + -2, -6, -3, -3, 2, -1, 4, 5, 6, -1, -2, 0, 4, 4, -1, -5, + -4, 1,-11, 0, -1, 2, -4, 1, 2, -3, 3, -1, 1, -2, 15, 0, + 1, -1, 0, -2, 1, -4, -7, 1, -2, -6, -1, 21, -2, 2, -1, 1, + 21, -1, -2, 0, -1, -3, 1, -2, -9, -2, 2, -1, 2, 1, -4, -1, + 1, 8, 2, -6,-10, -1, 4, 0, -4, -3, 3, 3, 5, 0, -1, -1, + 3, 2, 1, -2, -2, -2, 4, 3, 5, 2, -4,-17, 0, -2, 4, 3, + -7, -4, 0, 3, 9, 9, 2, -1,-11, -6, 0, -1, 5, 1, 0, 1, + 0, 17, 5,-11, 3, -2, -6, 0, 2, -2, -4, 1, -4, 1, 2, -1, + -5, -1, -5, -3, -3, 5, -3, -2, 4, 16, 2, -5, -2, 5, -1, -1, + 0, 0, -4, 1, -1, 2, 5, 11, -1, -1, -2, 1, -4, -2, -3, -1, + -5, -1, 10, 0, 6, 1, 0, -3, 0, -4, 1, 0, -2, -4, 3, -1, + 6, 9, 3, 0, -2, 1, -2, 0, -2, -3, -2, -2, 1, 0, 1, -6, + 1, 0, 2, 1, -1, 3, -2, 1, 0, -1,-15, 0, -1, 5, 2, 6, + 2, 0, 2, 2, 0,-12, -4, 6, 0, 1, 4, -1, 1, 2, 1, -4, + 1, -2, -7, 0, 0, 0, 0, -1, -5, 2, 11, 3, 1, 3, 0, -6, + 0, -3, -9, -4, 1, 3, -1, 0, 4, 1, -2, 0, 7, -3, -1, 6, + 1, -2, 6, 2, 0, -1, 3, -2, -2, 4, 0, 2, -1, 2,-14, 2, + 2, 2, 0, -1, -2, 3, -3,-14, 0, 2, 3, -3, 5, 1, 3, 2, + 1, -3, 4,-14, 1, -2, 11, -1, 0, -1, 3, 0, -1, 1, 0, 2, + -2, 3, -3, 2, -4, -1, -4, 3, -1, 2, 1, 3, -6, -2, 2, 7, + -2, 1, 2, 0, -2, 0, 0, -1, 12, 5, -1, 2, -8, -1, 1, -7, + 2, -2, -4, 2, 11, 0,-11, -2, 3, 1, -3, -1, 0, 3, 1, -1, + 0, 3, 0, -2, 0, -6, -1, -3, 12, -7, -2, 0, 7, -2, 1, 1, + 1, 2, 2, 2, -1, 2, 0, 2,-23, 0, 4, 0, 3, 2, 1, 3, + -4, -5, -1, 5, -3, 5, 10, -1, 0, 0, 3, -4, 1, -1, 2, -5 +}; + +/* 6x16-entry codebook for inter-coded 8x4 vectors */ +static int8_t svq1_inter_codebook_8x4[3072] = { + 9, 8, 4, 0, -3, -4, -4, -3, 9, 8, 4, -1, -4, -5, -5, -3, + 8, 7, 3, -2, -5, -5, -5, -4, 6, 4, 1, -2, -4, -5, -4, -3, + -12,-14,-11, -4, 1, 5, 6, 6, -8,-10, -7, -5, -2, 1, 1, 1, + 5, 4, 3, 1, 0, 0, -1, -1, 13, 13, 9, 6, 3, 0, -1, -2, + -4, -4, -3, -1, 1, 4, 8, 11, -5, -6, -4, -2, 0, 3, 8, 12, + -7, -7, -6, -4, -2, 2, 7, 10, -7, -7, -5, -4, -2, 1, 5, 8, + -3, -2, -1, 1, 3, 6, 7, 6, 2, 3, 5, 7, 8, 8, 6, 4, + 4, 5, 4, 3, 1, -2, -6, -7, 1, 0, -2, -7,-10,-14,-17,-16, + -5, -4, 1, 8, 9, 3, -3, -7, -7, -6, 1, 11, 12, 5, -3, -8, + -8, -7, 0, 9, 11, 5, -3, -7, -8, -6, -1, 5, 8, 4, -2, -6, + -4, -5, -7, -8, -9, -9, -8, -6, -4, -5, -6, -7, -7, -6, -4, -2, + 0, 1, 2, 3, 5, 8, 10, 9, 1, 2, 3, 6, 9, 12, 14, 13, + 5, 6, 6, 5, 4, 3, 2, 1, 5, 6, 7, 7, 6, 6, 6, 4, + -1, 0, 1, 1, 3, 5, 5, 5,-13,-16,-17,-17,-14,-10, -6, -4, + 9, 11, 13, 16, 15, 13, 12, 10, -4, -5, -6, -7, -7, -7, -6, -5, + -6, -6, -7, -7, -7, -7, -6, -5, -2, -1, 0, 0, 0, 0, 0, -1, + -11,-13,-15,-16,-16,-14,-12,-10, 2, 3, 4, 5, 4, 3, 3, 3, + 6, 7, 8, 8, 8, 7, 6, 5, 3, 4, 3, 3, 3, 3, 3, 3, + 3, 4, 4, 1, -2, -7,-13,-17, 5, 7, 7, 5, 1, -5,-13,-19, + 6, 8, 9, 8, 5, -1, -9,-16, 6, 8, 10, 10, 7, 2, -4,-11, + 18, 9, -1,-10,-13, -9, -4, 0, 22, 12, -1,-12,-15,-10, -4, 2, + 23, 13, 0,-10,-13, -9, -3, 2, 20, 12, 2, -6, -9, -6, -2, 2, + -6, -6, -6, -7, -7, -7, -7, -6, -6, -7, -8, -8, -9, -9, -9, -8, + -3, -3, -3, -3, -3, -3, -3, -3, 12, 15, 18, 21, 21, 19, 17, 14, + 14, 16, 18, 18, 18, 16, 15, 13, 5, 6, 6, 5, 5, 4, 4, 3, + -6, -7, -9,-10,-10,-10, -9, -7,-10,-11,-13,-14,-14,-13,-12,-10, + -27,-17, -4, 5, 9, 10, 10, 7,-32,-19, -3, 7, 11, 12, 11, 8, + -30,-16, -2, 8, 12, 12, 10, 7,-23,-12, 0, 7, 10, 11, 9, 6, + 16, 17, 16, 12, 6, -1, -8,-12, 17, 18, 15, 10, 1, -8,-15,-18, + 15, 14, 10, 4, -5,-14,-20,-23, 10, 8, 4, -1, -9,-16,-21,-22, + -10,-12,-12,-11, -5, 4, 14, 20,-11,-13,-15,-12, -4, 7, 19, 27, + -11,-13,-14,-11, -3, 8, 21, 28,-10,-11,-12, -9, -2, 8, 18, 25, + -1, -1, -1, 1, 4, 6, 6, 5, 0, 0, 0, 2, 4, 3, 1, -2, + 0, 0, 2, 4, 4, -1, -7,-10, 0, 0, 3, 5, 3, -3,-11,-15, + -14,-13, -8, -1, 3, 3, -1, -4, -5, -4, -1, 4, 8, 8, 3, 0, + 3, 2, 2, 3, 4, 5, 3, 1, 5, 3, 0, -2, -2, -1, -1, -1, + 9, 1, -6, -6, -5, -3, -2, -1, 12, 1, -6, -6, -4, -2, -1, 0, + 14, 4, -4, -4, -2, -2, -1, -1, 14, 6, -1, -1, -1, -1, -1, -1, + 4, 6, 8, 10, 11, 9, 7, 5, -1, -1, -1, 0, 0, -1, -1, -2, + -2, -4, -4, -5, -5, -5, -5, -4, -2, -3, -3, -4, -4, -3, -2, -1, + 2, 3, 4, 4, 3, 1, 0, 0, -1, 1, 4, 5, 6, 5, 4, 3, + -8, -6, -2, 2, 3, 4, 4, 3,-14,-13, -9, -5, -2, -1, 0, 0, + -3, -4, -5, -4, 0, 7, 12, 13, -3, -4, -5, -5, -2, 4, 9, 10, + -2, -3, -4, -5, -4, -1, 3, 4, -1, -1, -2, -3, -3, -2, 0, 1, + 9, 5, -2, -8,-11,-10, -7, -4, 12, 10, 6, 2, 0, -1, 0, 0, + 2, 2, 3, 4, 3, 1, 1, 1, -9, -8, -4, 0, 1, 2, 1, 0, + 6, 8, 8, 5, 1, -5,-11,-13, 0, 1, 2, 2, -1, -4, -8,-11, + -3, -2, 1, 3, 3, 1, -1, -4, -2, -1, 2, 5, 6, 6, 4, 1, + 3, 4, 5, 5, 4, 1, -3, -6, 5, 6, 4, 2, 2, 2, 0, -3, + 6, 5, 0, -5, -5, -2, -1, -2, 7, 4, -3,-11,-12, -7, -3, -2, + 1, 0, -1, -1, -1, 0, 0, 0, 2, 3, 4, 4, 5, 5, 4, 3, + -7, -9, -9,-10,-10, -9, -7, -6, 3, 4, 5, 6, 5, 5, 5, 5, + -7, -7, -7, -7, -6, -6, -5, -4, -5, -4, -3, -1, -1, -1, 0, 0, + -3, -2, 1, 4, 5, 5, 5, 5, -2, -1, 3, 6, 9, 10, 10, 9, + -14, 1, 10, 3, -2, 0, 1, 1,-16, 2, 13, 3, -3, -1, 1, 0, + -15, 2, 12, 3, -4, -2, 1, 1,-10, 3, 10, 2, -3, -1, 1, 1, + 0, 1, 4, 2, -5,-10, -3, 11, -1, 1, 4, 2, -6,-13, -2, 15, + -1, 0, 3, 1, -6,-12, -1, 15, -1, 1, 2, 1, -4, -8, 0, 11, + 10, 5, -2, -2, 2, 5, 1, -4, 7, 0, -8, -6, 1, 5, 2, -4, + 2, -5,-12, -7, 2, 7, 4, -1, -1, -7,-10, -4, 4, 9, 7, 2, + -5, -5, -4, -6, -6, -5, -5, -3, -1, -2, -2, -4, -5, -6, -5, -4, + 6, 7, 7, 4, 0, -2, -3, -3, 13, 14, 13, 10, 5, 1, -1, -2, + 1, 1, 2, 2, 2, 2, 2, 2, -5, -6, -8, -9, -9, -8, -7, -6, + 7, 9, 10, 11, 11, 9, 7, 5, -1, -2, -3, -3, -4, -4, -4, -3, + -1, -1, 0, 0, 0, 0, -1, -1, -3, -3, -4, -5, -4, -3, -3, -2, + 2, 1, -1, -3, -3, -2, -1, 0, 12, 12, 8, 3, 1, 0, 0, 1, + -6, -8, -8, -6, -2, 2, 6, 8, 1, 1, -1, -2, 0, 3, 5, 7, + 3, 3, 1, -1, -1, 0, 0, 2, 0, 1, 0, -1, -1, -1, -2, -1, + 1, 0, 0, 0, 0, 0, 2, 4, 2, 1, 3, 4, 3, 1, 0, 2, + 2, 1, 0, 0, -1, -1, 0, 3, 5, 1, -6,-12,-13, -8, -1, 4, + -2, 0, -1, -2, -1, 0, 2, 3, -6, -3, -2, 0, 1, 1, 1, 1, + -9, -5, 0, 4, 5, 3, 1, 0, -8, -3, 3, 7, 8, 4, 1, 0, + 1, 2, 2, 3, 3, 1, -1, -3, 4, 5, 5, 6, 6, 5, 2, 0, + 0, 0, 0, 0, 1, 0, -2, -4, -3, -3, -4, -3, -3, -4, -7, -8, + 14, 12, 6, -1, -3, -3, 0, 0, 7, 5, 1, -3, -5, -4, -2, -1, + -2, -2, -2, -2, -2, -2, -1, -1, -6, -4, -1, 1, 1, 1, 0, -1, + 2, 2, 1, -3, -6, -7, -6, -3, 1, 0, -1, -3, -2, 1, 4, 6, + 0, 0, 1, 2, 4, 7, 8, 7, 0, 0, 0, 0, -1, -4, -7, -8, + 0, 2, 1, -2, -3, -3, -2, -1, -1, 1, 0, -3, -5, -2, 0, 2, + -2, -1, -2, -5, -4, 1, 6, 9, -3, -2, -3, -4, -2, 5, 11, 13, + -4, -2, 2, 6, 4, -3,-10,-14, -2, -1, 1, 4, 4, 1, -1, -2, + 0, 0, -1, -2, -2, 0, 4, 6, 2, 2, 0, -3, -3, 0, 5, 9, + -4, -4, -2, 1, 6, 9, 3, -7, -2, -2, -2, -1, 4, 8, 0,-11, + 1, 1, 0, 0, 2, 6, -1,-10, 2, 2, 1, 0, 2, 4, 0, -7, + -1, -2, -3, -6, -7, -8, -8, -8, 2, 3, 3, 1, -1, -2, -3, -4, + 5, 5, 5, 4, 3, 2, 0, -1, 3, 3, 3, 3, 2, 2, 1, 1, + 3, 3, 2, -2, -3, 0, 7, 10, 1, 2, 2, -2, -5, -4, 0, 3, + 0, 3, 4, 2, -3, -5, -6, -4, 0, 2, 4, 4, 1, -4, -7, -7, + 2, 4, 5, 5, 5, 5, 6, 6, -4, -4, -3, -5, -5, -3, -3, -2, + -3, -4, -4, -5, -4, -2, -2, -2, 1, 1, 0, 0, 2, 4, 5, 4, + -2, 0, 3, 4, 4, 3, 2, 2, -9, -7, -4, 0, 3, 6, 6, 6, + -5, -5, -3, -2, 0, 1, 3, 4, 5, 5, 2, -2, -4, -6, -5, -3, + 1, -6, -4, 7, 5, -2, -2, 1, 5, -5, -4, 6, 4, -5, -4, 1, + 5, -5, -4, 6, 4, -5, -3, 1, 1, -7, -3, 8, 7, -1, -3, 1, + -8, -7, -4, 0, 2, 4, 5, 5, 5, 6, 5, 2, -1, -5, -7, -7, + 5, 6, 4, 1, -3, -5, -6, -5, -7, -7, -5, -2, 1, 6, 9, 10, + 6, 3, 0, 1, 3, 0, -8,-14, 3, 0, -1, 1, 4, 3, 0, -4, + 1, 0, 0, 1, 2, 1, 1, 1, -1, -1, 1, 2, 1, -1, -1, 0, + 1, 1, 1, 1, 0, -2, -3, 0, 1, 2, 1, 0, -2, -8, -9, -4, + 1, 3, 3, 2, 1, -3, -3, 1, 0, 1, 1, 1, 1, 1, 4, 8, + 2, 5, 9, 7, 2, -1, -1, 1, -4, -1, 1, 0, -3, -4, -1, 2, + -3, 0, 3, 3, 0, -1, 0, 2, -4, -1, 1, 1, -2, -4, -5, -4, + 1, -1, -2, -2, -1, 2, 4, 5, 2, 1, 1, 0, -1, -1, 0, 0, + 2, 3, 4, 5, 4, 2, 1, 0, -9, -9, -6, -3, -1, -1, -1, -1, + -6, -6, 4, 7, 0, -2, -1, -2, -1, -2, 5, 6, -1, -2, 0, -1, + 4, -1, 1, 0, -4, -2, 0, -2, 7, 1, -1, -2, -3, 1, 3, 1, + 4, 2, 1, 3, 3, 1, 1, 2, 2, -2, -4, 0, 3, 1, 0, 0, + 1, -4, -8, -4, 1, 2, 1, 0, 2, -3, -9, -6, 0, 3, 3, 2, + -1, -1, 0, -1, -1, 0, 1, 2, 3, 1, -4, -8, -7, -3, 1, 2, + 2, -1, -3, -2, -1, 0, 1, 0, -1, 0, 5, 11, 9, 3, -1, -3, + -1, -2, -2, -1, 1, 1, 1, 1, 0, -1, 0, 3, 6, 6, 5, 5, + 2, 1, -1, -1, -2, -5, -6, -4, 2, 2, 2, 1, -1, -4, -5, -5, + -1, -3, -6, -7, -6, -4, -1, 1, 5, 5, 3, 4, 4, 3, 4, 5, + -1, -2, -3, -2, -2, -2, 0, 1, 0, 0, 0, 0, 0, 1, 2, 3, + -6, -6, -4, -1, 2, 2, 2, 2, -6, -7, -5, -2, 0, -1, -1, 0, + 2, 2, 2, 4, 4, 3, 3, 4, 2, 1, 0, -1, 0, 0, 2, 4, + 12, 5, -5, -8, -5, 0, 2, 2, 2, -3, -6, -3, 0, 0, -1, -2, + -2, -3, -1, 3, 4, 1, -2, -3, 2, 2, 3, 4, 3, 1, -1, -1, + 3, 2, 1, 0, 1, 4, 3, 0, 4, 3, 0, -5, -6, 0, 3, 3, + 2, 3, 1, -7,-12, -6, 1, 3, 1, 3, 4, -1, -6, -4, 0, 1, + -9, -4, 2, 6, 7, 4, 1, 0, -7, -1, 4, 6, 4, 0, -3, -3, + -6, 0, 4, 4, 1, -2, -3, -2, -4, 1, 3, 2, 0, -2, -1, 0, + 0, 5, 2, -5, -3, 3, 1, -4, -2, 4, 2, -6, -3, 6, 4, -3, + -1, 5, 3, -5, -1, 7, 3, -4, -1, 2, 0, -6, -3, 5, 3, -3, + -8, -3, 3, 5, 3, 1, -2, -2, 2, 4, 4, -2, -4, -3, 1, 3, + 2, 1, -3, -5, -3, 3, 4, 3, -5, -6, -5, 3, 10, 8, -1, -5, + 0, 3, 2, -4, -9, -7, 0, 6, -5, -1, 5, 7, 4, -1, -3, -3, + -5, -5, -2, 3, 6, 5, -1, -4, 9, 6, 0, -4, -2, 1, 1, -1, + -1, -1, -1, 1, 1, 0, -1, 0, -1, 0, 0, 0, 0, -1, -1, 0, + 2, 1, -2, -1, 1, 1, 0, 0, 12, 8, 2, -1, -1, -4, -7, -7, + 2, 1, 3, 6, 7, 4, 2, 0, 1, 0, -1, 0, -1, -4, -7, -8, + 0, 0, -1, 0, 0, 0, -1, -3, 0, 0, 0, 0, 1, 1, 0, -2, + -1, 0, 1, 1, 0, 0, -1, -2, 0, 0, -1, -3, -4, -3, -1, 1, + -1, 0, 0, 0, 1, 4, 10, 12, -1, 0, -2, -2, -3, -3, -1, 1, + -3, -1, -2, -4, 2, 9, 9, 7, -3, 0, -1, -3, 0, 2, -1, 1, + -1, 1, -2, -3, 0, -1, -3, 0, 0, 0, -3, -2, 0, -1, -1, 1, + -1, -2, -1, -1, -2, -1, -1, -2, 2, -1, -2, -1, 0, 1, 0, -2, + 3, -1, -2, 2, 5, 3, -1, -3, 1, -5, -5, 1, 6, 6, 2, 0, + 1, 2, 0, -1, 0, 1, 0, -2, -5, -3, -1, 0, 1, 2, 1, -2, + -7, -5, -2, -2, -2, -2, 0, 1, -1, 0, 1, 1, 0, 3, 9, 12, + 0, 6, 5, 1, -2, -3, 0, 3, 0, 6, 5, 1, 1, 1, 2, 3, + -5, -2, -2, -3, 0, 0, 0, 0, -6, -3, -3, -2, 0, 0, -1, -2, + 4, 4, 2, 1, 0, -1, -1, 0, -2, -2, 0, 1, 2, 1, 1, 0, + 2, 2, 1, -1, -3, -5, -9,-10, 2, 1, -1, -1, 1, 4, 4, 1, + 4, 0, -2, -2, -2, -2, -1, 0, 7, 1, -4, -3, -2, 0, 1, 1, + 10, 5, -1, -2, 0, 1, 1, 0, 5, 1, -3, -4, -3, -1, -1, -2, + 2, 1, -1, -3, -3, 1, 1, -1, -2, -1, 3, 0, -1, 1, 1, 0, + -3, 1, 7, 2, -3, -2, -1, 0, -2, 4, 8, -1, -8, -5, 0, 2, + -4, -1, 1, 2, 1, -3, -4, -2, -5, -3, -2, 1, 4, 4, 4, 6, + -3, -2, -4, -3, 0, 1, 1, 2, 2, 2, 2, 1, 2, 1, -1, -1, + -4, -1, 0, -1, -3, -3, -1, -1, 1, 4, 4, 2, 0, -1, -2, -3, + 4, 6, 5, 3, 2, 1, -2, -4, 0, 1, 1, 1, 1, -1, -4, -6, + 1, 2, 2, -1, -6, -5, -1, 2, -3, -2, 1, 1, -4, -3, 2, 5, + -2, -1, 2, 2, -3, -4, 0, 3, -2, -2, 2, 6, 5, 2, 1, 2, + 2, -3, -3, 0, 0, 2, 3, 1, 3, -1, 1, 3, 1, 2, -1, -5, + -5, -7, -4, -2, 1, 8, 8, 1, -1, 0, 2, 0, -3, 0, 1, -3, + -2, -5, -5, -2, -3, -1, 0, -2, -1, -4, 0, 4, 0, 2, 4, 0, + 0, 0, 8, 10, 2, 1, 3, -1, -4, -3, 2, 3, -3, -3, 1, -1, + 1, -2, -4, 2, 7, 3, -2, -1, 6, 4, -2, -1, 2, 0, -1, 3, + 1, 1, -2, -2, -2, -5, -3, 4, -6, -2, 1, 1, -1, -4, -2, 4, + -2, -1, -2, -2, 0, 1, 0, -2, -1, 1, 0, -1, 0, 0, -1, -3, + 0, 1, -2, -4, -3, -1, 0, 0, 6, 8, 5, 0, 0, 1, 2, 3, + -2, -2, 2, 5, 2, 0, 0, 1, 2, -2, -2, -1, -1, 1, 2, 4, + 2, -1, 0, 1, 0, 0, 0, 1, -8, -7, -1, 1, -1, -1, 1, 3, + 0, 3, 6, 2, -2, 1, 2, 0,-10, -7, -1, 0, -3, -1, 2, 1, + 0, 0, 2, 2, 1, 1, 1, -1, 3, 0, -2, -2, 0, 2, 1, 0, + 8, 1, 0, 0, -2, -3, -1, 0, 2, -2, 2, 5, 1, -2, -1, 1, + -3, -6, -3, -1, -3, -3, -1, 2, 2, 0, 1, 2, 2, 1, 0, 0, + 1, -1, -1, -2, -1, 0, 1, 0, 15, 9, 2, -1, -2, -3, -3, -3, + 0, -3, -2, 0, 0, -1, -1, -1, 1, 0, 1, 0, 0, -1, -1, -1, + 0, 2, 2, -2, -3, -3, -7, -8, 0, 2, 2, 0, 1, 2, 1, 1, + 1, 2, 2, 2, 3, 1, 0, 3, 1, 0, -1, -2, -1, -2, 0, 5, + -11, -6, -1, 1, 2, 3, 1, -3, 1, 4, 3, -1, -2, 1, 2, -1, + 2, 2, 1, -1, -2, 0, 1, -1, 0, 0, -1, -1, 0, 2, 3, 2, + 1, 1, 2, 1, -1, 1, 0, -4, 0, 0, 0, -2, -2, 2, 4, -2, + -2, -3, 0, 0, -1, 2, 1, -6, 0, 2, 5, 5, 3, 2, -1, -7, + 4, 2, 0, 0, 3, 3, 1, -1, 0, -1, -1, 3, 6, 4, 1, -1, + -2, -2, 0, 2, 2, 0, -2, -2, -1, 0, -1, -5, -7, -5, -1, 1, + 5, -1, -2, 0, 2, 4, 2, -5, 0, -5, -2, 2, 1, 2, 0, -6, + 6, 1, 0, 1, -2, -1, 4, 2, 2, -3, -3, 0, -1, -2, 0, 0, + 1, -1, 0, 2, 0, 0, 6, 11, 2, -1, -1, 0, -3, -2, 3, 5, + 0, -2, -1, 0, -1, 0, 0, -3, 1, -1, -1, -1, -2, -1, -3, -7, + 1, 1, -2, -2, 1, 3, 1, -2, -1, 2, 0, -1, -1, 1, 0, 0, + -4, 2, 3, -1, -2, -2, 0, 1,-11, -2, 4, 5, 6, 2, -1, -2, + -6, -2, 1, -1, -3, -4, 1, 9, -3, 0, 3, 3, 2, -3, -3, 3, + 1, 1, 0, 0, 1, -1, -2, 3, 2, 0, -3, -3, 0, -1, -1, 3, + 1, -1, -3, 1, 2, -6, -4, 6, 0, -2, -5, -2, 0, -3, -2, 3, + 2, 2, 1, -2, -2, 1, 2, -1, -1, 1, 1, -2, -1, 6, 7, -1, + 1, 0, -4, -2, 1, -2, -3, 1, -4, 0, -3, -2, 2, 0, -3, 0, + -3, 4, 3, 1, 8, 7, 0, -1, -3, 4, 1, -4, 2, 3, -2, -3, + -3, 6, 1, -4, 1, 1, -1, -1, -2, 4, -3, -3, 3, 0, -1, -1, + 1, 2, -4, 2, 4, -3, -1, 2, 3, -1, -4, 5, 4, -6, -3, 2 +}; + +/* 6x16-entry codebook for inter-coded 8x8 vectors */ +static int8_t svq1_inter_codebook_8x8[6144] = { + -4, -3, 4, 5, 2, 1, 1, 0, -5, -3, 5, 5, 2, 1, 0, 0, + -6, -4, 5, 5, 2, 1, 0, 0, -7, -4, 4, 5, 2, 1, 0, 0, + -8, -5, 3, 4, 2, 1, 0, 0, -8, -6, 3, 4, 1, 1, 1, 0, + -8, -6, 2, 4, 2, 1, 1, 0, -8, -6, 2, 4, 1, 1, 1, 1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -2, -2, -2, -2, -2, -2, -2, + -2, -3, -3, -3, -3, -3, -3, -3, -2, -3, -3, -3, -3, -3, -4, -3, + -2, -2, -2, -2, -2, -3, -3, -2, 1, 1, 1, 1, 1, 0, -1, -1, + 4, 5, 5, 5, 4, 3, 3, 2, 7, 7, 8, 8, 8, 7, 6, 5, + 2, 1, 2, 4, 4, 0, -4, -6, 1, 1, 2, 5, 5, 1, -5, -7, + 1, 2, 1, 4, 5, 1, -5, -8, 1, 1, 1, 5, 5, 0, -6, -8, + 0, 1, 1, 5, 6, 1, -6, -9, 0, 0, 1, 4, 5, 0, -5, -8, + 0, 0, 1, 4, 5, 0, -5, -7, 0, 0, 1, 4, 4, 1, -4, -7, + 1, 2, 3, 0, -3, -4, -3, -1, 1, 3, 4, 0, -3, -4, -3, -1, + 2, 4, 5, 1, -3, -4, -3, -2, 2, 5, 6, 1, -3, -5, -4, -2, + 3, 6, 6, 1, -3, -5, -4, -2, 3, 6, 6, 1, -3, -5, -4, -2, + 3, 6, 6, 1, -3, -5, -4, -2, 3, 5, 5, 1, -3, -4, -4, -2, + 2, 2, 2, 2, 1, 0, 0, -1, 4, 4, 4, 3, 2, 1, 1, 0, + 4, 5, 4, 4, 3, 3, 2, 1, 4, 4, 4, 4, 4, 3, 2, 2, + 2, 3, 3, 3, 3, 3, 2, 1, -1, -1, -1, -1, 0, 0, 0, 0, + -5, -6, -6, -5, -5, -4, -3, -3, -7, -9, -9, -8, -7, -6, -6, -5, + 6, 6, 6, 6, 6, 5, 5, 4, 4, 4, 4, 3, 3, 3, 3, 2, + 0, -1, -1, -1, -2, -2, -1, -1, -3, -5, -6, -6, -6, -6, -5, -4, + -3, -5, -6, -7, -6, -6, -5, -4, -1, -2, -2, -2, -2, -2, -1, -1, + 0, 1, 1, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 3, 3, 3, + 2, 1, -2, -5, -4, 0, 2, 5, 2, 1, -2, -6, -5, 0, 3, 5, + 2, 1, -2, -6, -6, -1, 3, 6, 3, 2, -2, -7, -6, 0, 4, 7, + 2, 1, -2, -7, -5, 0, 5, 7, 2, 1, -2, -6, -5, 0, 4, 7, + 2, 1, -2, -6, -4, 0, 4, 6, 1, 1, -2, -5, -4, 0, 3, 6, + -10, -9, -6, -4, -1, 2, 3, 2,-10, -9, -5, -3, 0, 4, 4, 3, + -9, -7, -3, -1, 2, 5, 5, 3, -7, -5, -2, 0, 3, 5, 5, 3, + -6, -3, 0, 1, 4, 6, 5, 3, -4, -2, 1, 2, 3, 5, 4, 2, + -2, 0, 1, 2, 2, 4, 3, 1, -1, 1, 2, 2, 2, 3, 3, 1, + -4, -5, -5, -6, -6, -6, -6, -5, -3, -3, -4, -4, -4, -4, -4, -4, + 0, 0, 0, 0, -1, -1, -1, -1, 5, 5, 6, 5, 5, 4, 3, 2, + 5, 6, 7, 7, 7, 6, 5, 4, 3, 3, 4, 4, 4, 4, 3, 2, + 0, -1, 0, 0, -1, -1, 0, -1, -3, -3, -4, -4, -4, -4, -3, -3, + 1, -2, -5, 1, 5, 4, 2, 0, 1, -3, -6, 1, 6, 5, 2, 0, + 0, -4, -7, 0, 6, 6, 2, 1, -1, -5, -9, -1, 6, 6, 3, 1, + -1, -6,-10, -2, 6, 6, 3, 1, -1, -6, -9, -2, 5, 6, 3, 1, + -2, -6, -9, -2, 5, 5, 3, 1, -2, -6, -7, -2, 4, 4, 2, 1, + -5, -7, -8, -9, -9, -8, -7, -6, -5, -6, -6, -7, -7, -6, -6, -5, + -3, -3, -3, -4, -5, -5, -4, -4, -1, 0, 0, -1, -1, -1, -1, -1, + 0, 1, 2, 2, 2, 2, 2, 1, 2, 3, 4, 5, 5, 5, 5, 4, + 3, 4, 5, 6, 8, 8, 8, 7, 3, 4, 5, 6, 7, 7, 7, 6, + 5, 6, 7, 8, 9, 10, 10, 9, 3, 4, 6, 7, 8, 9, 9, 8, + 0, 1, 2, 3, 4, 5, 5, 5, -1, -2, -1, -1, 0, 1, 2, 2, + -2, -3, -3, -3, -3, -2, -1, 0, -3, -4, -5, -5, -5, -5, -5, -4, + -4, -5, -5, -6, -7, -7, -6, -5, -3, -4, -5, -6, -7, -7, -6, -6, + 13, 7, 0, -3, -3, -4, -4, -5, 14, 7, 0, -3, -3, -4, -4, -4, + 15, 8, -1, -4, -4, -4, -5, -4, 15, 8, -1, -4, -4, -5, -4, -3, + 15, 7, -1, -4, -5, -5, -5, -4, 14, 7, -1, -4, -4, -4, -4, -3, + 12, 6, -1, -4, -4, -4, -4, -3, 11, 5, -1, -4, -4, -4, -4, -3, + -17, -4, 5, 4, 4, 4, 3, 3,-18, -5, 5, 4, 4, 4, 3, 3, + -19, -5, 6, 4, 4, 4, 3, 2,-20, -5, 6, 4, 4, 4, 3, 3, + -20, -4, 6, 4, 4, 5, 3, 3,-19, -5, 6, 4, 4, 5, 3, 3, + -18, -4, 5, 4, 4, 4, 3, 2,-17, -5, 4, 3, 4, 4, 3, 3, + -6, -6, -6, -4, -2, 1, 6, 11, -6, -7, -7, -4, -2, 2, 8, 13, + -8, -8, -7, -4, -2, 3, 9, 14, -8, -8, -7, -5, -1, 4, 10, 16, + -8, -8, -7, -5, -1, 4, 10, 17, -8, -8, -7, -4, 0, 5, 10, 16, + -8, -8, -6, -3, 0, 4, 9, 15, -7, -7, -5, -3, 0, 4, 8, 12, + 8, 7, 7, 5, 2, -2, -8,-14, 8, 8, 7, 5, 2, -2, -8,-15, + 8, 8, 7, 5, 1, -3, -9,-16, 8, 8, 7, 5, 1, -3,-10,-17, + 8, 9, 8, 5, 1, -3,-10,-17, 8, 8, 7, 4, 1, -4,-10,-16, + 7, 7, 7, 4, 1, -3, -9,-14, 6, 7, 6, 3, 0, -3, -9,-13, + 5, 1, -4, -4, -3, -1, 0, 0, 7, 2, -3, -3, -2, -1, 1, 0, + 7, 1, -3, -3, -1, 0, 1, 1, 6, 1, -3, -2, -1, 1, 1, 0, + 6, 0, -4, -2, -1, 0, 1, 0, 5, 0, -4, -3, -1, 0, 0, -1, + 5, 0, -3, -1, 0, 0, 0, -2, 4, 1, -2, -1, 0, 1, 0, -1, + 2, 2, 1, 1, -2, -6, -8, -8, 1, 1, 1, 1, -2, -5, -8, -8, + 1, 1, 1, 0, -1, -3, -5, -5, 0, 0, 0, 0, -1, -1, -1, -2, + 0, -1, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 2, 3, 2, + 2, 1, 1, 1, 2, 3, 4, 3, 3, 3, 3, 3, 4, 4, 5, 4, + -4, -4, -3, -2, 0, 0, 1, 1, -4, -4, -3, -2, -1, 0, 0, 1, + -2, -2, -2, -1, -1, -1, 0, 0, 0, 1, 0, 0, 0, 0, 0, -1, + 2, 2, 2, 2, 2, 2, 1, 1, 3, 4, 4, 4, 4, 4, 4, 3, + 1, 1, 1, 3, 3, 4, 3, 3, -5, -6, -5, -4, -3, -3, -2, -2, + -4, -2, -1, -1, -1, -1, 0, 1, -4, -2, -1, -1, -1, -1, 0, 1, + -3, -2, -1, -1, -1, 0, 1, 2, -4, -3, -2, -1, -1, 1, 3, 3, + -4, -3, -3, -1, -1, 1, 4, 5, -4, -3, -2, -2, -1, 1, 4, 7, + -2, -2, -1, -1, 0, 2, 6, 8, -1, 0, 0, 1, 1, 4, 7, 8, + -3, -3, -3, -2, -2, -1, -1, 0, -1, -1, 0, 1, 2, 2, 3, 3, + 0, 1, 2, 4, 5, 6, 6, 5, -1, 0, 2, 3, 5, 6, 5, 3, + -1, -1, 0, 2, 3, 3, 2, 1, -2, -2, -1, 0, -1, -3, -4, -4, + 0, 0, -1, -1, -2, -4, -8, -7, 1, 2, 1, 0, -1, -4, -6, -7, + -2, 4, 1, -6, 0, 3, 0, 0, -2, 5, 1, -7, 0, 3, 0, 0, + -3, 5, 1, -8, 0, 3, -1, -1, -2, 6, 1, -9, 0, 3, 0, -1, + -2, 6, 2, -8, 0, 4, 0, -1, -3, 5, 1, -7, 1, 4, 0, 0, + -2, 4, 1, -7, 0, 4, 1, 0, -1, 4, 1, -6, 0, 3, 1, 0, + 0, 0, 0, 3, 4, 5, 4, 1, 1, 1, 1, 2, 3, 3, 2, 0, + 2, 2, 1, 2, 2, 1, -1, -2, 4, 3, 1, 1, 0, -1, -3, -5, + 5, 3, 1, -1, -2, -3, -4, -6, 5, 3, 0, -2, -3, -5, -6, -7, + 4, 3, 0, -2, -3, -4, -5, -5, 4, 3, 0, -1, -2, -2, -3, -3, + 0, 0, 0, 0, -1, -5, -2, 6, 0, 0, 0, 1, -1, -6, -2, 8, + 0, 0, 0, 2, 0, -6, -3, 9, 0, -1, 0, 2, 0, -7, -2, 10, + 0, -1, 0, 2, -1, -8, -3, 10, 0, -1, -1, 2, -1, -7, -3, 9, + 0, -1, 0, 1, -1, -6, -3, 8, 0, 0, 0, 1, 0, -5, -2, 7, + 2, 3, 3, 2, 1, 0, -1, -1, 3, 4, 3, 2, 1, 0, -1, -2, + 3, 4, 4, 2, 1, -1, -2, -3, 2, 3, 3, 2, 0, -1, -2, -3, + -1, 0, 1, 1, 0, -1, -2, -2, -5, -4, -3, -1, 0, 1, 1, 1, + -8, -8, -5, -1, 1, 3, 4, 3,-10, -9, -5, 0, 3, 5, 6, 5, + -5, -1, 4, 5, 3, 1, 0, 0, -6, -1, 4, 5, 2, 0, -1, -2, + -6, -1, 5, 4, 2, -1, -2, -2, -7, -1, 4, 4, 1, -2, -3, -3, + -6, -1, 5, 4, 1, -2, -3, -3, -5, 0, 4, 4, 1, -1, -2, -2, + -4, 0, 5, 4, 1, -1, -1, -2, -3, 1, 4, 3, 1, -1, -1, -2, + -2, -3, -2, 1, 4, 6, 5, 3, -3, -4, -4, 0, 3, 5, 4, 2, + -3, -5, -5, -1, 2, 4, 3, 1, -4, -6, -4, -1, 2, 4, 2, -1, + -2, -4, -3, 1, 2, 4, 2, -1, -2, -4, -2, 1, 3, 3, 1, -2, + -2, -3, -2, 1, 3, 3, 1, -2, -2, -2, -1, 1, 3, 3, 0, -2, + -4, -4, -3, -2, -1, 2, 5, 7, -4, -4, -3, -3, -2, 1, 5, 7, + -2, -3, -2, -3, -3, -1, 3, 5, -1, -1, 0, -2, -3, -2, 2, 4, + 1, 1, 1, -1, -4, -3, 1, 3, 4, 3, 2, -1, -4, -3, -1, 1, + 6, 4, 3, 0, -3, -3, -2, 0, 6, 5, 3, 1, -2, -3, -2, -1, + 12, 11, 8, 4, 0, -2, -2, -1, 10, 9, 6, 2, -1, -2, -1, 0, + 4, 3, 2, 0, -1, -1, 0, 1, -1, -1, -1, -1, -2, 0, 1, 2, + -3, -5, -4, -2, -2, 0, 2, 3, -5, -5, -4, -2, -1, 0, 1, 2, + -5, -5, -4, -2, -1, 0, 1, 1, -4, -4, -3, -2, -2, -1, 0, 0, + 3, 3, 2, -1, -3, -4, -3, -2, 3, 2, 0, -2, -4, -4, -3, -2, + 2, 2, 1, -1, -3, -5, -4, -3, 3, 3, 3, 1, -2, -3, -3, -3, + 4, 4, 4, 3, 0, -2, -2, -2, 5, 5, 5, 3, 0, -1, -2, -2, + 5, 5, 4, 2, -1, -2, -3, -2, 3, 3, 3, 0, -2, -4, -4, -4, + -1, -1, 4, -2, -2, 6, 2, -5, -1, 0, 4, -2, -3, 6, 2, -6, + -1, 0, 4, -2, -3, 7, 3, -7, -1, -1, 4, -3, -4, 8, 3, -7, + 0, -1, 4, -3, -4, 7, 3, -6, -1, -1, 4, -3, -4, 7, 3, -6, + -1, -1, 3, -3, -4, 6, 3, -6, -1, 0, 3, -2, -3, 6, 3, -5, + 1, -2, -7, 2, 5, -2, -1, 1, 1, -2, -8, 3, 6, -3, -1, 2, + 2, -2, -9, 4, 7, -4, -2, 2, 3, -1, -9, 5, 7, -4, -1, 3, + 3, -1, -9, 4, 7, -4, -2, 2, 3, -1, -7, 4, 6, -4, -2, 1, + 2, 0, -6, 4, 6, -4, -1, 1, 2, 0, -5, 3, 4, -3, -1, 1, + -2, 2, 2, 0, 0, -1, -3, -4, -2, 2, 2, 1, 1, 0, -2, -4, + -2, 2, 2, 2, 2, 1, -1, -2, -3, 2, 3, 3, 4, 2, 0, -2, + -3, 2, 3, 2, 4, 2, 0, -3, -4, 1, 2, 1, 2, 1, -1, -3, + -5, 0, 1, 0, 1, 1, -2, -3, -4, 0, 0, 0, 1, 0, -2, -3, + 0, 0, -1, -2, -2, 2, 7, 8, 0, 0, -1, -3, -2, 1, 6, 7, + 0, 1, -1, -3, -3, 0, 4, 5, 0, 1, 0, -1, -1, 0, 1, 3, + 0, 2, 1, 1, 0, -1, 0, 1, -2, 0, 1, 2, 1, 0, -1, -1, + -5, -2, 0, 1, 1, 0, -3, -3, -6, -4, -1, 1, 1, -1, -3, -4, + -4, -2, 2, 5, 6, 4, 3, 2, -5, -3, 1, 4, 4, 2, 0, 0, + -4, -2, 0, 2, 1, -1, -2, -2, -2, -1, 0, 1, 0, -2, -3, -2, + -2, 0, 0, 0, -1, -1, -2, -1, -2, -1, -1, 0, 0, 0, 1, 2, + -2, -2, -1, -1, 0, 1, 3, 4, -2, -3, -2, -1, 0, 2, 4, 5, + 2, 1, -2, -2, -1, 0, 1, 0, 1, 0, -3, -3, -1, 0, 1, 0, + 0, -1, -3, -3, -1, 1, 1, 1, 0, 0, -3, -1, 1, 2, 3, 3, + 0, -1, -3, -1, 1, 3, 3, 3, -2, -2, -4, -2, 1, 3, 4, 4, + -3, -3, -4, -2, 1, 3, 3, 4, -2, -3, -5, -2, 1, 2, 3, 3, + 4, 5, 3, 4, 4, 4, 4, 5, 3, 3, 1, 0, 0, 0, 0, 1, + 1, 1, -1, -2, -3, -4, -3, -2, 2, 2, 0, -2, -2, -4, -3, -2, + 2, 3, 1, -1, -1, -3, -3, -2, 1, 2, 0, 0, -1, -2, -2, -1, + 0, 1, 0, -1, -1, -3, -2, -1, 1, 1, 0, -1, -1, -2, -2, -2, + -2, -1, -1, 0, 1, 2, 1, 0, 1, 2, 3, 5, 6, 5, 5, 3, + 1, 2, 3, 4, 5, 5, 4, 3, -2, -2, -3, -3, -2, -1, 0, 0, + -3, -3, -4, -5, -4, -3, -2, -1, -1, -1, -2, -2, -2, -1, 0, 0, + 0, 1, 0, -1, -1, 0, 0, 1, -1, 0, -1, -2, -3, -2, -2, -1, + 7, 7, 6, 5, 4, 2, -1, -2, 3, 3, 2, 2, 1, 0, -2, -3, + 0, -1, -1, -1, 0, -1, -2, -2, -1, -3, -2, -1, 0, 0, 0, 1, + 0, -2, -2, -1, -1, 1, 2, 2, 3, 1, -1, -1, -1, 1, 2, 2, + 3, 1, -2, -3, -2, -1, 1, 2, 1, -2, -5, -6, -5, -3, -2, 0, + 0, -1, -2, -3, -1, 0, -2, -2, 0, 0, -1, -1, 0, 1, -1, -2, + 0, 0, -2, -1, 0, 0, 0, -2, -1, -2, -3, -3, -2, -1, -3, -3, + -1, -2, -3, -3, -2, -2, -3, -4, 2, 2, 0, 0, 0, 0, -1, -2, + 5, 5, 3, 2, 2, 2, 0, -1, 8, 8, 6, 5, 4, 4, 2, 1, + -7, -8, -6, -3, -1, -1, -2, -1, -5, -5, -3, 0, 2, 1, 0, 0, + -1, -1, 0, 3, 4, 3, 1, 1, 2, 1, 1, 3, 4, 3, 2, 2, + 3, 2, 0, 2, 3, 2, 1, 2, 4, 2, -1, -1, 0, 1, 1, 1, + 3, 2, -2, -3, -2, -1, 0, 1, 3, 1, -3, -4, -3, -2, 0, 1, + -4, -2, -1, 2, 3, 3, 1, 0, -7, -5, -4, -2, 0, 0, -1, -2, + -6, -5, -5, -4, -2, -2, -2, -3, -1, 0, -1, -1, 0, 0, 0, -1, + 2, 3, 2, 2, 2, 2, 1, 0, 3, 5, 4, 3, 1, 0, 1, 0, + 3, 4, 3, 2, 0, -1, -1, -1, 5, 5, 3, 1, 0, -1, -1, -1, + 1, 1, 0, -1, -3, -5, -6, -4, 1, 1, 0, 0, 0, -3, -3, -1, + 0, -1, -1, 0, 1, 0, 1, 3, -2, -2, -3, -1, 2, 2, 4, 7, + -2, -2, -2, 0, 2, 2, 3, 6, -1, 0, 0, 1, 1, 0, 0, 3, + 0, 3, 3, 3, 1, -2, -3, -1, 1, 3, 4, 3, 0, -3, -5, -4, + 0, 2, 0, -1, -3, -4, -2, -2, 1, 4, 2, 0, -2, -3, -2, -1, + 3, 6, 3, 1, -2, -2, 0, -1, 4, 7, 4, 1, -2, -3, -1, 0, + 3, 6, 3, 0, -3, -3, -1, 0, 1, 3, 0, -1, -3, -2, 1, 1, + 0, 1, -1, -2, -3, -1, 2, 2, -2, -1, -3, -3, -3, -1, 1, 2, + 3, 1, -1, 0, 1, 0, 0, 0, 2, -1, -2, -1, 1, 0, -1, -1, + 1, -1, -2, 0, 1, 0, -2, -3, 0, -2, -1, 1, 3, 1, -3, -5, + 0, -2, -1, 2, 5, 2, -3, -5, 0, -2, -1, 4, 6, 3, -2, -5, + 0, -2, 0, 4, 7, 4, -2, -4, 0, -2, 0, 4, 6, 4, -2, -4, + -2, -2, -3, -4, -3, -2, -1, 0, 1, 1, 0, -1, -1, -1, 0, 1, + 3, 3, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2, 1, 0, 0, 1, + 0, 0, 0, 0, -1, -1, -1, -1, -4, -4, -4, -4, -4, -4, -4, -3, + -3, -3, -2, -3, -2, -1, -1, 0, 3, 4, 4, 5, 5, 6, 6, 7, + -1, -2, 7, -2, -4, -1, -1, 0, -1, -2, 9, -1, -4, -1, -1, 0, + -1, -3, 10, -1, -4, -1, -1, 1, -1, -3, 10, -2, -3, -1, -1, 2, + -1, -2, 10, -2, -4, -1, -1, 2, -1, -2, 9, -2, -4, -1, -1, 2, + -1, -2, 8, -2, -4, 0, -1, 1, 0, -2, 7, -2, -3, -1, 0, 2, + 3, -4, 1, 3, -3, -2, 1, 0, 3, -5, 1, 4, -3, -2, 1, 0, + 3, -6, 2, 5, -3, -1, 3, 0, 3, -6, 2, 5, -3, -1, 2, 0, + 3, -6, 1, 5, -4, -2, 3, 0, 3, -6, 1, 5, -3, -2, 2, 0, + 2, -6, 1, 4, -3, -1, 1, 0, 2, -6, 1, 4, -2, -1, 1, 0, + 0, 0, 1, 1, 1, 0, 0, 2, 0, -1, 1, 1, 1, 0, 0, 2, + 0, -1, 0, 0, 0, 0, 0, 2, 0, -1, 0, 0, 0, 0, -1, 0, + 1, 0, 1, 0, 0, -1, -2, -1, 3, 1, 1, 0, 0, -2, -4, -3, + 5, 3, 2, 1, 0, -3, -5, -4, 5, 4, 2, 0, -1, -4, -5, -5, + 1, 0, -1, -2, -2, -3, -6, -9, 2, 0, -1, -1, 0, 0, -3, -6, + 1, 0, 0, -1, 0, 0, -2, -5, 2, 1, 1, 1, 1, 2, -1, -3, + 1, 1, 2, 1, 2, 2, 1, -1, 1, 1, 2, 1, 1, 1, 1, 1, + 0, 0, 2, 1, 0, 0, 2, 2, 0, 1, 2, 2, 0, 0, 2, 2, + -4, -3, 0, 1, 4, 6, 4, 3, -3, -2, 0, 0, 2, 4, 1, 0, + -1, -1, 0, 0, 1, 1, -2, -3, 1, 1, 1, 0, 1, 1, -3, -5, + 1, 1, 1, 0, 1, 1, -3, -5, -1, 0, 0, -1, 1, 1, -2, -4, + -1, 0, 0, -1, 1, 2, 0, -2, -1, 0, 0, 0, 2, 3, 1, 0, + -1, 0, 3, 4, 0, -4, -5, -5, 0, 0, 4, 5, 2, -2, -3, -2, + 0, -1, 2, 4, 2, -1, -1, 0, 0, -2, -1, 1, 0, -2, 0, 1, + 1, -2, -2, 0, 0, -1, -1, 1, 1, -2, -3, 0, 1, 0, -1, 0, + 1, -2, -2, 1, 3, 1, 0, 0, 1, -2, -1, 2, 4, 2, 0, 0, + 1, 2, 3, 2, 0, 2, 2, 1, -1, 0, 1, 0, -3, 1, 1, 1, + -1, 0, 0, -2, -4, 0, 2, 1, -1, 2, 2, -1, -5, 0, 2, 1, + -1, 3, 4, -1, -5, 0, 2, 1, -2, 2, 4, 0, -4, -1, 0, 0, + -4, 0, 2, 0, -4, -2, 0, 0, -5, -1, 2, 1, -2, 1, 3, 2, + 1, 0, 1, 0, 1, 2, -1, -2, 2, 0, -1, -2, 1, 3, 0, -1, + 3, 0, -2, -4, 0, 3, 1, 0, 5, 1, -3, -5, -2, 2, 1, 1, + 6, 1, -2, -5, -2, 1, 0, 1, 5, 1, -1, -5, -2, 0, -1, 0, + 3, 0, -2, -4, -2, 0, -1, 0, 1, -1, 0, -2, 0, 1, 0, 1, + 1, 1, 2, 3, 2, 1, 1, 2, -1, -1, 0, 1, 1, 0, 1, 1, + -4, -3, 0, 0, 1, 1, 1, 2, -4, -3, 0, 2, 2, 2, 3, 2, + -5, -4, 0, 1, 1, 1, 1, 2, -5, -4, -1, -1, -2, -2, -1, 0, + -3, -2, 0, 0, -2, -3, -2, -1, 2, 3, 4, 4, 2, 0, 0, 0, + -4, -2, 0, 1, 0, 0, 0, 0, -3, -1, 1, 1, 0, 0, 0, 0, + -2, 0, 2, 2, 0, 0, 0, 2, -1, 1, 2, 1, -1, 0, 3, 5, + 0, 2, 1, -1, -2, 0, 5, 6, 0, 1, 0, -3, -3, 0, 4, 6, + 1, 1, -2, -4, -4, -3, 1, 2, 1, 0, -2, -4, -5, -4, -2, 0, + -1, -3, -3, -3, -3, -2, -1, -1, 3, 2, 1, 0, 0, 1, 1, 1, + 5, 4, 3, 2, 1, 1, 2, 2, 2, 1, 0, -2, -2, -2, -1, -1, + 0, 0, 0, -1, -2, -2, -2, -2, 0, 1, 3, 3, 2, 1, -1, -1, + 0, 1, 3, 4, 3, 2, 1, -1, -4, -3, -1, 1, 0, -2, -3, -3, + -3, -4, -7, -8, -7, -4, -1, 2, 0, -1, -3, -4, -4, -2, 0, 2, + 1, 0, 0, -1, -3, -2, 0, 2, 2, 1, 1, 0, -1, -1, 0, 2, + 1, 1, 1, 1, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 1, 2, 3, 3, 2, 2, 0, 0, 1, 3, 4, 4, 3, 2, + 3, 3, 3, 0, -1, 0, 1, 2, 1, 1, 1, -1, -2, -1, -1, 1, + -2, -2, -1, -3, -3, -2, -2, 0, -4, -4, -2, -2, -2, -2, -3, 0, + -4, -4, -1, 1, 1, 0, -1, 2, -3, -1, 2, 3, 4, 3, 3, 5, + -2, 0, 2, 3, 3, 3, 3, 3, -2, -2, 0, 0, 0, 0, 0, 1, + 0, 2, 1, -1, -3, -1, 3, -2, -1, 0, -1, -1, -3, 0, 4, -2, + -2, -2, -2, -2, -2, 1, 5, -2, -3, -2, -3, -1, -2, 1, 4, -3, + -2, 0, -1, 0, -1, 0, 3, -5, 1, 2, 1, 2, 0, 0, 2, -5, + 2, 4, 2, 3, 1, 1, 3, -3, 1, 2, 1, 1, 0, 1, 4, -2, + 4, -3, -4, -1, 3, 3, 1, 3, 4, -4, -4, -1, 3, 2, 0, 2, + 4, -3, -4, 0, 2, 2, -1, 1, 4, -3, -2, 1, 2, 1, -2, 0, + 2, -4, -2, 1, 2, 0, -3, 0, 2, -3, -2, 0, 1, 0, -2, 2, + 3, -1, -1, 0, 0, 0, 0, 3, 2, -2, -2, -2, -1, -1, -1, 2, + 2, 2, 3, 4, 3, 1, 0, -1, 1, 0, 1, 2, 1, -1, -2, -2, + 2, 1, 2, 1, 1, 0, -1, -1, 4, 3, 4, 3, 2, 1, 1, 1, + 3, 2, 2, 2, 1, 1, 1, 1, -1, -2, -1, 0, -1, -1, -1, -1, + -3, -3, -2, -1, -2, -2, -2, -2, -4, -4, -3, -3, -4, -4, -3, -3, + 2, 1, -1, -3, -4, -2, 3, 4, 2, 2, 1, -1, -3, -2, 1, 2, + 1, 2, 3, 3, 0, -2, -1, -2, -1, 0, 2, 4, 2, 0, -1, -3, + -2, -2, 0, 3, 3, 2, 0, -3, 0, -2, -3, -1, 1, 2, 2, -1, + 3, -1, -4, -5, -3, 0, 2, 0, 6, 3, -2, -6, -5, 0, 3, 1, + -2, 3, -2, 0, 3, -2, -2, 1, -3, 4, -3, 0, 3, -2, -1, 2, + -3, 5, -3, 0, 4, -2, -1, 2, -2, 4, -4, -1, 3, -3, -2, 2, + -3, 4, -3, 0, 3, -3, -1, 2, -2, 5, -2, 0, 3, -3, -1, 2, + -2, 4, -3, 1, 3, -2, -1, 2, -2, 3, -2, 1, 3, -2, 0, 2, + 1, 0, 0, -1, 1, 2, -4, -1, 2, 0, 0, -1, 1, 2, -4, -2, + 1, 1, 1, -1, 2, 4, -2, 0, 0, -1, 1, -1, 2, 5, -1, 1, + 0, -1, 0, -2, 1, 5, -1, 1, 0, -1, -1, -2, 0, 3, -3, -1, + 1, 1, 0, -2, 0, 3, -3, -1, 1, 1, 0, -3, 0, 3, -2, 0, + 1, 0, -1, 1, 1, 2, 4, 5, 1, 0, -1, 1, 1, 1, 5, 7, + 0, 0, -2, -1, -1, 0, 3, 5, 0, -1, -2, -1, -1, -1, 2, 3, + 0, -1, -3, -1, -1, -1, 1, 2, -1, -2, -4, -2, -2, -2, 0, 0, + -1, -2, -2, -1, -2, -2, 0, 0, 0, -1, -1, 0, -1, -1, 0, 0, + 3, 3, 0, -1, -1, 1, 4, 4, 2, 3, 0, -2, -2, 0, 1, 1, + 2, 3, 1, -1, -1, 0, 1, 0, 1, 2, 0, -1, -1, -1, 0, -2, + 0, 1, 0, -1, -2, -1, 0, -2, 0, 1, 0, -1, -2, -1, 1, 0, + 1, 1, -1, -3, -4, -3, 1, 3, 1, 2, -1, -3, -5, -4, 1, 3, + -3, -2, 0, 1, 1, 1, 0, -2, 0, 1, 1, 1, 0, 0, -1, -3, + 1, 2, 1, 1, 0, -1, -1, -2, 0, -1, -3, -1, -1, -1, 0, -1, + 0, -3, -6, -3, -2, -1, 1, 1, 2, -1, -4, -3, -2, 0, 2, 2, + 5, 4, 1, 1, 0, 1, 3, 2, 5, 4, 2, 1, 0, -1, 0, 1, + -2, 0, -2, -5, -6, -3, 0, 0, -2, 0, 1, 0, -1, 1, 2, 2, + -2, 0, 1, 3, 2, 2, 2, 1, -2, 0, 2, 4, 3, 2, 1, 1, + -2, 0, 2, 3, 2, 0, -1, 0, -3, -1, 1, 1, 0, -1, -1, 1, + -4, -1, 1, 0, -1, -2, 0, 2, -4, -1, 0, -1, -1, -2, 1, 4, + -3, 0, 0, -1, 1, 1, 1, 0, -3, 1, 0, -1, 0, 0, -1, -1, + -1, 3, 3, 0, 1, 0, 0, 1, -3, 2, 2, -2, -1, 0, 0, 1, + -5, 0, 0, -2, -1, 1, 0, 2, -7, -2, 1, 0, 1, 2, 2, 2, + -5, 0, 3, 2, 3, 3, 2, 2, -3, 2, 4, 1, 0, 0, -2, -3, + 5, 2, -2, -2, 0, -1, -1, -1, 2, -1, -4, -3, -1, -2, -1, -1, + 0, -2, -2, 1, 2, -1, 0, 1, -1, -2, -1, 3, 3, -1, 0, 2, + 1, 0, 0, 3, 3, -2, -1, 2, 2, 1, 1, 3, 2, -2, -2, 0, + 1, 0, -1, 1, 1, -3, -3, -2, 1, 0, 1, 2, 3, 0, 0, 0, + -4, -5, -3, 0, 1, -1, -2, -1, -2, -3, -1, 1, 2, 0, 0, 0, + 1, 1, 2, 1, 2, 1, 1, 1, 3, 4, 3, 1, 0, -2, -1, -1, + 3, 3, 2, 0, -2, -3, -3, -2, 1, 1, 0, -1, -2, -4, -2, -2, + 2, 1, 0, 0, 0, -1, 0, 1, 2, 1, 1, 1, 1, 1, 1, 3, + 0, 0, 0, -1, -2, -1, 1, 0, -2, -1, -1, -2, -3, -2, 0, 0, + -1, 0, 0, -1, -2, 0, 1, 1, 1, 1, 0, -1, -1, 1, 3, 1, + 2, 2, 0, -2, -1, 2, 3, 0, 3, 1, -1, -1, 1, 4, 2, -2, + 2, 0, -3, -1, 3, 5, 0, -5, 1, -1, -2, 0, 3, 3, -1, -6, + -1, 0, 3, 4, 2, 0, 1, 2, -2, -1, 0, 1, -1, -2, 0, 1, + -2, -3, -2, -3, -6, -7, -6, -3, 2, 2, 3, 1, -1, -2, -3, -2, + 2, 2, 3, 1, 0, 0, 0, 0, 2, 1, 1, 0, 1, 1, 0, 1, + 1, 0, 0, 0, 0, 1, 1, 2, 1, 0, -1, 0, 0, 2, 2, 1, + 1, 1, 3, 1, -1, -1, -1, 1, -2, -1, 0, 0, -2, -2, -1, 2, + -2, -2, 1, 1, 1, 0, 1, 3, -2, -2, 0, -1, 0, -1, 0, 2, + 0, 0, 1, 0, -1, -1, -2, 1, 3, 2, 2, 1, 0, -2, -2, 1, + 5, 3, 3, 2, 1, 1, 1, 4, 0, -3, -4, -5, -4, -3, -1, 1, + -6, -4, -1, 2, 2, 0, 0, -1, -4, -2, 1, 3, 3, 2, 2, 0, + -3, -2, -1, 2, 3, 3, 2, 0, -3, -2, -2, 1, 2, 1, 1, -1, + -2, -2, -2, 0, 2, 2, 1, -1, -1, -1, -1, 1, 2, 3, 2, 0, + -1, -1, -2, 1, 2, 2, 2, -1, 0, -1, -2, 0, 2, 1, 0, -1, + 6, 4, 2, 1, 0, 0, 0, 1, 4, 2, -1, -2, -2, -2, -1, -1, + 2, 1, -1, -2, -2, -2, -2, -1, 2, 2, 0, -2, -2, -2, -1, 0, + 0, 0, -1, -2, -2, -1, 0, 1, -3, -3, -2, -1, -1, -2, -1, 0, + -3, -2, 2, 3, 2, 0, -1, -2, -2, 0, 4, 5, 5, 2, 0, -1, + 5, 4, 2, 0, -1, -2, -1, -1, 4, 3, 2, 1, 0, -1, 0, -1, + 1, 1, 0, 1, 1, 0, 1, -1, -2, -1, -1, 0, 0, -2, -2, -3, + -1, 0, 0, 0, -1, -3, -3, -5, 0, 1, 1, -1, -1, -2, -2, -3, + -1, -1, -1, -2, -1, 1, 3, 1, -1, -2, -2, -1, 2, 5, 6, 5, + -3, -3, -2, 1, 1, -2, -1, -1, 1, 2, 3, 4, 1, -3, -1, -3, + 3, 2, 0, 1, -1, -3, -1, -3, 1, 0, -1, 0, -1, -1, 1, 0, + 1, 1, 0, 1, 2, 2, 5, 3, 1, 1, 1, 2, 2, 2, 3, 0, + -3, -1, -2, -2, -3, -3, -1, -3, -1, 1, 1, 0, -1, -1, 0, -2, + 2, 0, -2, -2, 2, 4, 1, -2, 1, 0, -2, -1, 3, 5, 2, -1, + -1, -2, -3, -2, 1, 3, 1, -2, -1, -2, -1, -1, 0, 2, 1, -1, + 0, 0, 1, 1, 1, 2, 2, 0, 0, 1, 4, 4, 2, 2, 3, 1, + -2, -1, 2, 1, -2, -3, -2, -3, -1, 0, 1, 0, -3, -4, -4, -5, + 4, 0, -3, -4, -4, -4, -2, -1, 5, 0, -1, 0, -1, -3, -2, -1, + 4, 0, 0, 1, 1, 0, 0, 0, 0, -3, -2, -1, 0, 0, 1, 0, + 0, -2, 0, 0, 1, 1, 2, 1, 2, 0, 0, 0, 1, 1, 1, 0, + 2, 0, -1, -1, 1, 1, 1, 0, 1, -1, -2, -2, 0, 2, 2, 2, + -3, -5, -2, 0, -1, -3, -3, 0, 0, -2, 0, 2, 2, 0, 0, 3, + 2, -1, -2, 0, 0, -1, -1, 2, 5, 2, -1, -1, -1, -1, -1, 2, + 5, 2, 0, -1, -1, 0, -1, 2, 2, 1, 0, 0, 0, 1, 0, 2, + -1, -1, 1, 1, 2, 2, 1, 2, -3, -2, 0, 0, 0, 0, -2, -1, + 0, 3, 2, 0, -2, -3, -3, -3, 0, 3, 3, 1, 0, 0, 1, 2, + -1, 0, -1, -2, -1, -1, 1, 3, -1, 0, -1, -2, -1, -1, 0, 2, + -1, 0, -1, -2, 0, 0, -1, 2, -1, 0, -1, -2, -1, -1, -2, 1, + 0, 1, 0, -3, -1, -1, -1, 2, 5, 5, 2, -1, -1, -1, 1, 3, + 0, 0, 1, -1, -3, -2, 0, 2, 1, 1, 3, 0, -2, -2, 0, 1, + 1, 1, 3, 1, 0, 0, -1, -1, 0, -1, 2, 1, 1, 0, -1, -3, + -1, -2, 1, 1, 1, 0, -2, -4, -1, 0, 2, 1, 1, 0, -1, -3, + 1, 1, 3, 2, 1, 0, -2, -3, 2, 2, 4, 2, 1, -1, -2, -4, + 1, 2, 2, 2, 0, -2, 0, 2, -1, -1, -2, -3, -4, -5, -3, 1, + 0, 1, 1, 0, -1, -1, -1, 1, 0, 1, 1, 1, 0, 0, 0, 2, + 0, 1, 1, 2, 1, 1, 1, 2, -1, -1, 0, 2, 2, 2, 2, 3, + -2, -4, -4, -1, -2, -2, -2, 0, 1, 0, 0, 1, 0, 0, 0, 1, + 0, -1, -3, -2, 0, 2, 2, 1, 0, -1, -2, -3, 0, 1, 1, 2, + 1, 0, -2, -3, -1, 0, 0, 1, -1, 0, -1, -2, 0, 0, -1, 0, + -1, 1, 1, 0, 2, 2, 0, 0, 0, 2, 3, 1, 3, 5, 3, 2, + -1, 1, 1, -2, 0, 3, 1, 1, -1, 0, 0, -4, -4, -1, -1, -1, + -1, 1, 1, 0, 1, 2, 1, 2, -3, 0, 1, 0, 1, 1, 0, 2, + -5, -3, -1, -1, 0, 1, 0, 1, -4, -3, -2, -3, -2, -1, -1, 0, + 0, 0, -1, -2, -2, -2, -2, 0, 3, 4, 2, 0, 0, 0, 0, 1, + 2, 1, 0, 0, 0, 0, -1, 0, 0, 1, 2, 3, 4, 4, 3, 2, + -1, 4, 7, 4, 0, 0, 0, 0, -1, 4, 6, 3, 0, 1, 1, 1, + 0, 3, 4, 0, -1, 0, 0, 1, 0, 1, 1, -2, -1, 0, -1, -1, + -1, 0, -1, -1, -1, 0, 0, 0, -1, -1, -1, 0, 0, 0, 0, 0, + -1, -3, -3, 0, 1, -1, -2, -1, -3, -4, -4, -2, -1, -2, -2, -1, + 2, 2, 1, 0, 1, 1, 0, -3, -2, -1, 0, 0, 1, 1, 0, -3, + -2, -1, 0, 1, 2, 1, 1, -2, 1, 2, 2, 2, 3, 3, 2, -1, + 1, 2, 1, 0, 1, 1, 2, -1, 0, 1, -2, -4, -2, 0, 1, -1, + 1, 1, -1, -3, -2, 0, -1, -3, 1, 2, 0, -1, 0, 1, -1, -4, + -1, -1, -2, -2, 0, 3, 4, 3, 1, 1, -1, -3, -2, 0, 0, 0, + 2, 2, 2, 2, 2, 1, -1, -1, 1, 1, 1, 3, 3, 0, -2, -2, + 0, -1, -1, -1, 0, -2, -1, -1, -1, -3, -4, -3, -2, -2, 0, 2, + -1, -1, 0, 1, 2, 2, 3, 5, -2, -1, -1, 0, 0, 0, 0, 1, + -2, -3, 2, 0, 0, 1, 1, -1, -1, -4, 1, -2, -1, 2, 2, 0, + 1, -4, 0, -2, -2, 1, 1, -1, 2, -3, 1, -1, -1, 1, 1, -1, + 3, -2, 3, 1, 0, 1, 1, -1, 1, -3, 2, 1, 0, 1, 0, -1, + -1, -5, 1, 0, -1, 0, 1, 1, 0, -3, 3, 3, 1, 2, 3, 3, + 0, -1, -2, 1, 5, 5, 2, -1, 1, -1, -2, -1, 1, 1, -2, -5, + 1, 1, -1, -2, -1, -1, -1, -3, 1, 1, -1, -1, -1, 2, 4, 3, + -1, -1, -1, -1, -1, 0, 4, 3, -1, -1, 0, 1, -1, -3, -1, -1, + 0, 0, 0, 2, 2, 0, 0, -1, 0, -2, -3, 0, 1, 1, 3, 2, + 2, 3, 2, 1, 0, 0, -2, -2, 2, 3, 0, 1, 1, 3, 3, 2, + 0, 0, -3, -1, -1, 2, 2, 3, -2, -2, -3, 1, 1, 2, 1, 1, + -2, -1, -2, 2, 1, 1, -1, -2, 0, 1, 0, 2, 0, 0, -2, -2, + 0, 1, 0, 2, 0, 0, -2, -2, -3, -2, -2, 0, -1, -2, -2, -3, + 0, 1, -1, 3, -1, 1, 3, -1, 0, 1, -1, 3, -1, -1, 2, -3, + 1, 1, -2, 3, -1, -3, 0, -3, 2, 2, -2, 3, 0, -2, 1, -2, + 1, 1, -3, 3, -1, -2, 1, -3, 1, 1, -3, 3, 0, -1, 1, -2, + 1, 2, -1, 4, 0, -1, 1, -2, 0, 1, -1, 3, -1, -3, 0, -3, + -3, -3, -1, 1, 2, 1, -1, -2, -2, -2, 0, 2, 1, 0, -2, -2, + -3, -2, 1, 2, 1, -1, -2, -1, -3, -2, 2, 4, 0, -2, -2, 1, + -3, -1, 2, 4, 0, -2, -2, 2, -1, 1, 4, 3, -1, -3, -2, 2, + 0, 2, 4, 2, -1, -2, -1, 2, 0, 1, 2, 0, -1, 0, 1, 3, + 3, 0, -5, 1, 4, 0, 0, 1, 1, -2, -5, 2, 5, -1, -2, 1, + -1, 0, 0, 3, 3, 1, 0, -1, -2, 3, 4, -2, -3, -1, 0, -2, + -3, 3, 5, -3, -3, 0, 0, -2, -1, 3, 2, -2, -2, 2, 2, -1, + 2, 0, 0, -1, 0, 0, 0, 0, 0, -3, -2, 1, 3, 0, -2, -2 +}; + +/* list of codebooks for inter-coded vectors */ +static uint8_t *svq1_inter_codebooks[4] = { + svq1_inter_codebook_4x2, svq1_inter_codebook_4x4, + svq1_inter_codebook_8x4, svq1_inter_codebook_8x8 +}; + +/* 6x16-entry codebook for intra-coded 4x2 vectors */ +static int8_t svq1_intra_codebook_4x2[768] = { + 12, 13, 13, 11, -7,-10,-15,-17,-16,-15,-12,-10, 11, 15, 15, 12, + 2, 17, 20, 15,-45,-24, 2, 13, 21, 20, -6,-36, 12, 16, -1,-27, + -18,-21, 10, 45,-11,-20, -7, 21, 43, -8,-28, 0, 33,-16,-28, 3, + -12,-18,-18, -6,-20,-10, 28, 55, -5,-18,-21,-18, 56, 30, -6,-20, + -34, 27, 29,-22,-30, 29, 26,-25, 30, 34, 33, 26,-25,-31,-35,-33, + -31,-35,-36,-32, 29, 36, 37, 31,-71,-12, 38, 34,-63, -1, 42, 33, + 58, 37,-31,-60, 55, 34,-33,-61,-57,-57, 22, 93,-57,-58, 21, 93, + 59, 69, 70, 62,-63,-68,-68,-60,-64,-71,-71,-64, 63, 73, 72, 62, + -2, 0, 7, 15,-11,-10, -3, 5, -5, -8,-10,-10, 1, 9, 14, 9, + 15, 8, -4,-11, 12, 2,-11,-12, -8, 0, 19, 28, 4, -1,-15,-26, + -15, 27, 2,-14,-14, 22, 1, -9, -4, -6,-13,-10, -6,-14, 6, 47, + -35,-20, 6, 23, 6, 9, 6, 4, -6, 2, 23,-22, -7, 4, 28,-21, + 20,-22, -2, 6, 22,-28, -5, 8,-10,-18,-16,-12, 36, 19, 2, -1, + -3, 0, 4, 8,-45,-10, 23, 23, 40, 15,-20,-35, -4, -1, 4, 1, + 9, -5,-33, 24, 8, 3,-26, 19, -1, 4, 6, -3, 32, 25,-13,-49, + 24, 24, 15, 7,-17,-27,-19, -7,-47, 0, 39, 24,-21, -6, 7, 4, + -1, 0,-10,-13, 1, 1, 5, 16, 20, 5, -3, -9, -1, -4, -2, -6, + -17, -7, 1, 4, 12, 7, 0, 0, 3, 0, 12, 11, -3, 1, 0,-23, + 4, 17, -6, 0, 6, 3,-25, 0,-17, 10, 8, 5,-14, 4, 1, 4, + 13, 10, 4, 2,-23, -9, 1, 2, 3, -3, 1, 7, 1,-23, -7, 20, + -7,-18, 2, 12, -5, -4, 10, 9, 4, 10, 7,-24, 6, 3, 4,-10, + 22,-14,-22, 6, 0, 5, 5, -1, -4, 3,-11, -4, -7, 31, 7,-14, + -5,-16, -1, 42, -4, -2, -9, -5, 5, -8, -6, -3, 42, -4,-21, -5, + -18, 12, 20,-12, 13,-13,-10, 7, -8, -9, -2,-18,-16, 6, 40, 8, + 10, -1, 0, 4, -3, 4, -1,-13, -2, 6, 1,-15, 5, 3, 1, 2, + -4, -2, 1, 3, 15, 0, -9, -4, -3, -4, -4, -4, -3, 5, 16, -3, + 2, 13, 3, 4, -3, -8,-10, 0, -6, -2, -4, -1, -2, -3, -6, 23, + 6, -6, 7, 1, 4,-18, 5, 1, -1, 1,-15, 14, -5, 6, -4, 4, + 2, 2, 2, 6,-24, 2, 7, 3,-26, 0, 3, 3, 5, 7, 1, 6, + 14, -2,-18, -3, 7, 5, -4, 2, -6, 3, 32, 1, -6, -6, -6,-12, + 5,-36, 7, 6, 9, -1, 11, 0, 4, 4, 5, 3, 4, 15, 3,-38, + 10, 23, -5,-42, 0, 4, 4, 4, 23, 17, -6,-13,-13,-37, 1, 29, + 5,-14, -1, 1, 5, 0, 3, 1, 0, 4, -5, 2, 8, 0, 0,-10, + 4, 7, -2, -3,-10, 3, 1, 1,-12, -1, 13, 3, 0, -1, 1, -3, + 0, -1, 3, 1, -6, -9, 3, 9, -6, 1, -4, -6, 8, -1, 0, 8, + -3, -3, 0, 18, -5, -1, -4, -1, -8, -2, 3, -4, 0, 17, -1, -5, + 5, -2, 9,-10, 1, -5, 6, -5, 4, 2, 2, 3, 10,-14, -8, 1, + -1, -2,-18, -1, -1, 20, 1, 2, -1, 1, -9, 1, -1, -9, 22, -4, + 6, -4, 8, -3, -1, 7,-19, 5, -7, 31, -4, -4, -6, 0, -5, -5, + -7, -8,-19, -4, 1, 1, 4, 32, 38, -1, -8, 4, -7, -8, -6,-12, + -1, 0, -7, 1, -1, 9, -1, 0, 9, -1, -1, 0, 2, -6, 1, -3, + -12, 0, 2, 1, 1, 1, 8, 0, 9, 1, 0, 2, -2, 1,-11, 0, + 0, 8, 2,-10, -1, 2, -1, 0, -2, -4, 0, -5, -2, -1, -1, 14, + -3, 7, -1, 5, 0,-10, 1, 1, -1, -5, 14, -1, -2, 1, -3, -2, + -6, 0, 0, 6, 2, 3, -9, 4, 4, -5, -1, -1, -7, 3, 8, -1, + 2, -4, -1,-11, 11, 2, 1, 0, -1, 2, 3, 9, 0, 2, 0,-15, + 3, 5,-20, 3, 3, -1, 3, 3, 1, -1, 16, 1, 2,-29, 9, 2, + -13, -6, -1, -3, 36, -1, -8, -3, 2, 5, 4, 2,-37, 9, 11, 3 +}; + +/* 6x16-entry codebook for intra-coded 4x4 vectors */ +static int8_t svq1_intra_codebook_4x4[1536] = { + -11, -3, 3, 6,-10, -1, 5, 7, -9, -1, 6, 7, -9, -1, 4, 6, + 5, 7, 0,-14, 6, 9, 2,-15, 6, 9, 2,-15, 4, 6, 0,-14, + 16, 3, -5, -6, 16, 1, -8, -8, 14, -1, -9, -9, 12, 0, -8, -8, + 8, 12, 16, 17, -2, 2, 6, 9,-10, -8, -4, 0,-15,-14,-11, -7, + -7,-10, -2, 16, -7,-11, -3, 18, -7,-11, -1, 20, -6, -8, 1, 19, + -9,-13,-16,-17, 2, -2, -7, -9, 11, 8, 4, -1, 16, 15, 11, 7, + -22, -2, 13, 15,-24, -2, 14, 16,-25, -4, 13, 15,-25, -6, 10, 13, + 26, 26, 22, 16, 17, 15, 9, 3, -2, -6,-11,-14,-20,-25,-28,-28, + -27,-27,-25,-21,-16,-15,-11, -7, 3, 8, 12, 13, 23, 28, 31, 30, + 20, 16, -7,-33, 22, 19, -6,-35, 22, 19, -6,-34, 20, 17, -6,-32, + -20,-20, 2, 38,-21,-22, 2, 40,-21,-22, 2, 40,-20,-20, 3, 38, + -47, -4, 24, 26,-50, -3, 26, 27,-50, -3, 26, 27,-47, -4, 24, 26, + 45, 6,-23,-27, 48, 5,-25,-28, 48, 5,-26,-28, 44, 6,-24,-27, + -30,-36,-10, 76,-31,-37,-11, 78,-31,-37,-11, 78,-31,-36,-10, 77, + -53,-32, 35, 52,-54,-34, 36, 52,-54,-34, 36, 52,-53,-33, 34, 51, + -93,-34, 62, 65,-93,-34, 62, 66,-93,-34, 62, 65,-93,-34, 60, 64, + -7, 0, 2, 2, -8, -1, 3, 3, -8, 0, 4, 5, -6, 1, 5, 5, + 3, 7, 11, 11, 2, 2, 3, 3, 1, -2, -6, -7, 1, -5,-11,-13, + 3, -2, -4, -3, 7, 0, -5, -5, 12, 4, -5, -7, 14, 6, -4, -7, + 18, 14, 3, -2, 6, 4, 0, -3, -8, -5, -2, 0,-16,-11, -2, 2, + -8, -6, 7, 18, -7, -8, 2, 13, -4, -6, -2, 6, 0, -4, -3, 1, + 1, -3,-13,-18, 0, -1, -5, -7, -1, 1, 6, 7, -2, 4, 15, 17, + -15,-14, -7, -2, -6, -5, -1, 0, 6, 6, 3, 1, 15, 13, 6, 1, + 2, -2,-11, 10, 2, -1,-12, 11, 3, -1,-12, 11, 2, -2,-11, 11, + -9, 14, -1, -5, -9, 15, -2, -5, -8, 16, -2, -5, -7, 15, -1, -4, + 2, 6, 8, 8, -2, 3, 9, 12,-11, -5, 4, 10,-19,-16, -8, 0, + 14, 8, -7,-15, 12, 7, -7,-14, 8, 5, -4, -9, 5, 3, -1, -4, + 12,-14, -2, 2, 13,-15, -1, 3, 14,-15, -1, 3, 13,-14, -1, 3, + 0, 6, 10,-13, 0, 6, 10,-15, 0, 7, 9,-17, 1, 6, 8,-16, + -8, -5, 15, -2, -8, -6, 17, -2, -8, -6, 16, -3, -8, -5, 15, -2, + -9,-11,-11,-10, 9, 10, 9, 8, 8, 10, 10, 9, -8, -9, -8, -7, + 9, 10, 9, 7, -8,-10,-10,-10, -7,-10,-11,-11, 11, 12, 11, 8, + 0, 10, 7, 0, 0, 7, 0, -6, 0, 2, -5, -6, -2, -1, -4, -1, + 5, 0, -6, -9, 2, 2, 2, 1, -2, 0, 5, 7, -6, -5, 1, 4, + 3, -8, 2, -1, 4, -9, 3, 0, 5, -7, 3, 0, 7, -5, 3, 0, + -5, -3, 2, 9, -6, -3, 1, 8, -6, -3, 1, 7, -5, -2, 0, 4, + 13, 8, 3, 1, -3, -5, -4, -1, -8, -7, -3, 0, -1, 1, 3, 2, + 3, 2, -5,-12, 4, 3, -2, -9, 3, 4, 1, -4, 3, 5, 4, -1, + -9, -8, -4, 0, 8, 6, 2, 0, 10, 8, 3, 0, -6, -5, -3, -1, + -3, -9,-12, -5, 0, -3, -5, 0, 2, 3, 2, 4, 5, 8, 7, 6, + -1, -2, 5, 12, -1, -1, 5, 9, 2, 1, -1, -2, 2, -1,-11,-17, + -7, 3, 3, -1, -9, 3, 4, -1,-10, 4, 6, -1, -9, 5, 7, 0, + -18, -7, 2, 2, -8, 1, 5, 3, 3, 4, 1, 0, 9, 5, -2, -3, + -2, 0, 6, 8, -4, -5, -5, -3, 1, -2, -6, -8, 10, 9, 3, -1, + 0, -2, -2, 0, 0, -4, -5, 0, -2, -8, -4, 8, -5, -7, 6, 24, + 9, 1, -7, 1, 9, 1, -8, 1, 8, 0,-10, 1, 8, -1,-11, -1, + 8, 8, 6, 3, 5, 4, 3, 2, -2, -3, -1, 0,-10,-13, -8, -4, + 0, 4, 2, -3, 0, 6, 3, -5, 3, 10, 2,-12, 5, 10, -4,-22, + 0, -4, -1, 3, 1, -4, -1, 5, 1, -5, 0, 8, -1, -6, -2, 7, + -1, -1, -2, -4, -1, -2, -4, -6, -1, -1, -1, -2, 1, 5, 10, 9, + 10, 3, 0, -2, 6, -1, -2, -5, 3, -1, -2, -6, 2, 0, 0, -5, + 6, 3, 0, 0, 6, 3, 1, 1, 4, -2, -2, 1, 0, -9, -9, -2, + -11, -3, 1, 2, -6, 2, 4, 5, -3, 2, 3, 4, -2, 1, 1, 2, + -6, -4, -1, -2, 2, -1, -1, -2, 10, 2, -2, -2, 11, 2, -4, -1, + 6, 0, -2, 2, 3, 3, 0, 0, -6, 3, 3, 0,-17, -1, 5, 0, + -1, 4, 10, 11, -3, -2, 0, 1, -3, -4, -5, -3, -1, -2, -2, -1, + 2, -3, -9,-12, 3, 3, 3, 2, 2, 2, 4, 4, 2, 1, -1, -2, + -2, 9, 5,-10, -3, 5, 5, -5, -2, 1, 2, 0, -1, -2, -2, 1, + -2, -3, 7, -2, -1, -3, 7, -3, -1, -2, 8, -4, -2, -2, 7, -3, + 1, -8, -3, 12, 2, -2, -2, 4, 1, 3, 0, -5, -1, 5, 2, -7, + -1, 3, 1, -5, -7, -2, 3, 1, -2, -7, -2, 2, 20, 3, -5, -1, + 5, 0, -3, -2, -7, -7, 0, 6, -6, 0, 7, 6, 2, 6, 0, -7, + -2, 6, -7, 1, -2, 7, -8, 3, -2, 7, -7, 3, -1, 7, -6, 2, + -5, -2, 5, 7, 4, 1, -4, -8, 6, 3, -2, -5, -7, -5, 3, 7, + -1, -1, 6, 5, 0, -1, 1, -4, 2, 1, 0, -7, 1, 0, 0, -4, + -8, 0, 3, 1, -2, 1, -1, -1, 1, -1, -3, 1, 1, -2, 1, 9, + 5, 2, -3, -4, -1, 0, -1, -3, -3, 1, 3, 1, -4, 0, 4, 2, + 2, -2, -2, 12, 0, -2, -5, 3, -1, 0, -3, 1, -3, -1, -2, 1, + 1, 5, 3, 0, -6, -4, -2, 1, 0, -2, -2, 2, 6, 1, -4, -1, + -3, -5, -5, -1, 3, 5, 5, 4, 0, 3, 1, -1, -2, 1, -2, -3, + 2, -4, -5, -3, 4, -2, -3, -2, 6, 0, -1, -1, 7, 1, 0, 0, + -3, -2, -2, 0, -2, -3, -5, -1, -2, 2, 0, -1, -1, 11, 9, -1, + 0, 1, -1,-10, -1, 1, 0, -6, 1, 0, 1, 4, 2, -5, -1, 13, + -2, 4, 5, 0, -5, 1, 6, 3, -6, -2, 3, 2, -5, -2, 0, -2, + -1, 1, 1, -2, -1, -2, 0, 2, 5, 5, 5, 7, 0, -4, -8, -7, + 0, 2, -1, -5, -1, 2, 2, -3, 0, 5, 3, -5, 3, 8, 2,-12, + 8, 4, 0, -2, 10, -1, -4, -1, 3, -6, -3, 0, -4, -5, 0, 0, + 0,-10, -4, 2, -1, -6, 3, 5, -1, -3, 6, 4, 0, -2, 4, 2, + 0, 8, 1, -1, 0, 11, 1, -3, -1, 6, -2, -4, -3, -2, -7, -4, + 0, -1, -1, -1, 4, 5, 6, 5, -5, -9, -8, -5, 2, 2, 3, 2, + 0, 2, 6, 1, 2, 0, 3, 0, 1, -2, -1, -2, 0, -1, -3, -6, + 0, 0, 2, 0, 4, 0, 2, 1, 5, -2, 0, 0, -2, -9, -1, 2, + 0, 1, 0,-10, -1, 1, 8, 0, -1, -2, 4, 0, 1, -1, 2, -1, + -3, -2, 2, -1, -3, -1, 2, -3, 0, -1, 1, 0, 8, 1, -1, 3, + 0, 1, 1, 2, 0, -4, -2, 0, -1, -5, 1, -1, -2, -1, 11, 2, + 1, 5, -2, -2, 0, 2, -4, 0, -2, 1, -5, 1, 0, 5, 0, 1, + -5, -3, 0, 6, -4, 2, 0, 0, -3, 5, 1, 0, -3, 3, 0, 0, + 3, -2, -3, 1, 1, -4, 0, 8, -2, -3, -2, 3, 1, 2, -1, -1, + 1, 1, 0, 2, 2, 0, 1, 6, 1, -1, 2, 1, 0, 3, 0,-19, + 1, -3, -2, 2, 6, 5, -2, -7, -3, 1, 3, 1, -1, -1, 0, 2, + -8, -1, -1, -4, 1, 1, -1, 2, 4, 3, 2, 3, -5, 1, 3, 0, + 0, 2, -1, 1, -3, 0, 0, 5, -5, -2, 0, 8, -4, -4, -4, 6, + 1, 2, 1, 2, 2, 2, -3, 2, 4, 0, -9, 0, 7, 0,-11, 1, + 0, 0, 0, -2, 3, 3, -1, -6, 4, 3, -3,-10, -1, 2, 6, 2, + 7, -2, -3, 5, -4, 0, 3, -1, -4, 2, 1, -7, 2, -1, -1, 3, + 3, 2, 2, 2, -5, -7, -7, -5, 5, 6, 4, 2, -2, -1, 0, 1 +}; + +/* 6x16-entry codebook for intra-coded 8x4 vectors */ +static int8_t svq1_intra_codebook_8x4[3072] = { + 5, 6, 6, 6, 7, 7, 8, 8, 0, 0, 0, 0, 0, 1, 2, 3, + -3, -4, -4, -5, -5, -4, -3, -2, -4, -4, -4, -5, -4, -4, -3, -3, + 1, 2, 2, 2, 2, 3, 3, 3, 2, 3, 3, 4, 4, 5, 5, 5, + -1, 0, 1, 1, 2, 3, 4, 4, -9,-10, -9, -9, -8, -7, -6, -5, + -4, -4, -5, -6, -6, -7, -7, -7, 0, -1, -2, -2, -3, -3, -4, -4, + 4, 4, 3, 3, 2, 1, 1, 0, 7, 7, 7, 6, 6, 5, 4, 4, + 2, 4, 5, 6, 4, 1, -3, -6, 3, 4, 5, 5, 4, 0, -5, -8, + 2, 3, 4, 4, 2, -2, -7,-10, 2, 2, 2, 1, 0, -4, -9,-12, + -9, -7, -3, 1, 4, 4, 3, 3,-10, -7, -2, 3, 5, 5, 3, 3, + -9, -6, -2, 3, 6, 5, 4, 3, -8, -6, -1, 3, 4, 4, 3, 2, + -5, -5, -5, -5, -3, 1, 4, 7, -5, -5, -5, -4, -2, 1, 6, 8, + -4, -5, -4, -3, -1, 3, 8, 10, -3, -4, -3, -2, 1, 5, 9, 11, + -2, -2, -2, -2, -2, -2, -2, -2, -4, -5, -5, -5, -5, -5, -5, -4, + -3, -4, -4, -4, -4, -4, -4, -3, 9, 10, 10, 11, 11, 11, 10, 10, + 7, 4, 1, -2, -4, -6, -9,-10, 9, 7, 3, 0, -2, -4, -8, -9, + 11, 8, 4, 2, 0, -3, -6, -8, 11, 9, 5, 3, 1, -2, -5, -7, + -13,-13,-13,-12,-11,-10, -8, -8, 0, 1, 2, 3, 4, 4, 4, 3, + 3, 4, 5, 6, 6, 6, 5, 4, 3, 4, 4, 4, 3, 3, 3, 2, + 10, 10, 11, 10, 9, 9, 8, 7, 6, 6, 6, 6, 5, 4, 3, 2, + 0, 0, 0, -1, -2, -3, -4, -4,-10,-10,-11,-12,-13,-14,-14,-14, + 16, 16, 17, 16, 15, 13, 12, 11, -1, -2, -3, -4, -4, -4, -4, -3, + -4, -5, -6, -6, -6, -6, -6, -6, -5, -6, -6, -6, -6, -6, -5, -5, + -13,-13,-13,-12,-11,-10, -8, -6, -9, -8, -7, -6, -4, -2, 0, 1, + -2, -1, 1, 3, 5, 7, 8, 9, 5, 7, 9, 11, 13, 14, 15, 15, + 16, 14, 11, 7, 2, -3, -7, -9, 14, 12, 8, 3, -1, -6, -9,-11, + 11, 9, 4, 0, -4, -8,-11,-13, 8, 5, 1, -3, -6,-10,-12,-14, + -18,-15, -9, -3, 1, 6, 9, 11,-17,-13, -7, -1, 3, 7, 11, 12, + -15,-11, -5, 1, 5, 9, 12, 13,-13, -9, -3, 2, 5, 9, 11, 13, + 22, 21, 19, 15, 10, 3, -4, -9, 20, 18, 15, 9, 2, -5,-12,-17, + 16, 13, 8, 1, -7,-14,-20,-24, 10, 6, -1, -8,-15,-21,-25,-27, + -25,-23,-20,-14, -7, 1, 9, 14,-23,-21,-16, -9, 0, 9, 16, 21, + -20,-16,-10, -1, 8, 16, 22, 25,-15,-11, -3, 6, 14, 20, 25, 27, + -4, -2, 0, 1, 2, 2, 2, 2, -5, -2, 0, 2, 3, 3, 3, 3, + -6, -4, -1, 1, 2, 3, 3, 3, -7, -5, -2, 0, 1, 1, 2, 2, + 2, 1, 1, 1, 1, 0, -2, -3, 3, 3, 2, 1, 0, -1, -3, -4, + 4, 3, 2, 1, 0, -2, -4, -6, 5, 4, 3, 1, -1, -3, -5, -6, + 5, 6, 6, 4, 2, 0, -2, -3, 3, 4, 4, 4, 3, 1, 0, -1, + -2, -2, -1, -1, -1, -1, -2, -2, -5, -4, -3, -2, -2, -2, -3, -3, + -1, -1, -1, -1, -1, -1, -1, -1, -3, -4, -4, -4, -3, -3, -3, -3, + -1, -1, -1, -1, -1, -1, -1, -2, 5, 6, 6, 6, 6, 5, 4, 3, + 4, 4, 4, 4, 4, 5, 6, 7, 0, -1, -1, -1, -1, 0, 1, 2, + -2, -3, -3, -3, -3, -2, -1, 0, -3, -3, -4, -4, -4, -3, -2, -1, + 0, -2, -4, -4, -2, 0, 2, 3, 0, -2, -3, -3, -1, 2, 4, 5, + -1, -2, -4, -3, 0, 3, 5, 6, -2, -3, -4, -3, -1, 2, 4, 5, + 9, 4, 0, -3, -3, -1, 0, 1, 8, 4, -1, -4, -3, -1, 1, 2, + 6, 2, -3, -5, -4, -2, 0, 1, 5, 1, -3, -4, -4, -2, 0, 1, + 5, 3, 1, -1, -4, -8,-10,-10, 3, 3, 2, 1, 0, -2, -3, -4, + 1, 1, 1, 2, 3, 2, 1, 0, -1, 0, 1, 2, 3, 4, 3, 2, + 0, 1, 2, 2, 1, -1, -3, -3, 0, 1, 1, 1, -1, -2, -4, -3, + -3, -3, -3, -3, -3, -3, -1, 2, -4, -4, -3, 0, 3, 7, 12, 14, + -5, -5, -6, -6, -6, -6, -6, -5, 2, 2, 2, 1, 0, 0, 0, 0, + 4, 4, 3, 2, 1, 0, 0, 0, 6, 6, 5, 4, 2, 2, 1, 1, + -7, -7, -6, -3, 0, 4, 7, 8, -1, -2, -3, -3, -2, -1, 1, 2, + 3, 3, 1, -1, -2, -2, -2, -1, 6, 6, 4, 2, 0, -2, -2, -2, + -6, -5, -2, 2, 5, 9, 11, 12, -4, -4, -2, 0, 2, 4, 5, 6, + -3, -2, -2, -2, -2, -1, 0, 1, -2, -2, -2, -3, -3, -3, -3, -2, + -7, -3, 1, 3, 3, 0, -3, -5, -6, -2, 3, 5, 4, 1, -3, -5, + -5, -1, 4, 6, 5, 2, -3, -4, -4, 0, 5, 7, 6, 3, -1, -3, + 0, 0, 0, 0, 0, 0, 0, 0, -2, -2, -3, -3, -3, -3, -2, -1, + 6, 7, 8, 9, 9, 8, 7, 6, -4, -4, -5, -5, -6, -6, -5, -4, + -9, -8, -6, -4, 0, 3, 6, 6, -5, -4, -1, 3, 5, 6, 5, 3, + 1, 3, 6, 6, 4, 1, -2, -5, 6, 7, 5, 1, -3, -7,-10,-11, + 10, 9, 5, 1, -3, -6, -6, -4, 5, 3, -1, -5, -6, -5, -2, 2, + -2, -4, -6, -6, -4, 1, 6, 10, -6, -7, -7, -4, 1, 7, 11, 12, + 6, 5, 3, 2, 0, 0, 0, 0, 2, 1, -1, -2, -3, -2, -1, -1, + 0, -1, -2, -4, -4, -2, -1, 1, 0, 0, -1, -2, -1, 0, 2, 3, + 0, -1, -2, -2, -2, -2, -1, -1, 5, 4, 2, 1, 0, 0, 0, 0, + 6, 5, 3, 1, 0, 0, 0, 0, 2, 0, -2, -4, -4, -3, -2, -2, + -7, -4, 0, 2, 2, 2, 2, 1, -7, -3, 0, 0, 0, 0, 0, 0, + -4, -1, 1, 1, 0, 0, 0, 1, -1, 1, 2, 2, 2, 2, 3, 3, + -2, 0, 2, 2, 1, 1, 1, 1, -1, 1, 2, 2, 1, 0, 0, -1, + 0, 2, 4, 2, 0, -1, -2, -3, 1, 2, 3, 1, -2, -4, -6, -6, + 1, 2, 2, 4, 5, 6, 4, 1, 0, -1, -1, -1, 0, 0, -2, -4, + 0, 0, -1, -2, -2, -2, -4, -6, 2, 1, 0, 0, 1, 1, -1, -3, + 1, 1, 1, 1, 1, 2, 3, 3, 0, 0, 1, 0, 1, 2, 4, 4, + -1, -1, -1, -1, 0, 1, 2, 3, -4, -4, -5, -5, -5, -3, -1, 0, + -6, -5, -5, -4, -3, -2, -1, -1, -1, 0, 0, 1, 1, 2, 3, 3, + 0, 1, 1, 1, 2, 2, 3, 4, 0, 0, -1, -1, 0, 1, 2, 3, + 0, 1, 1, 1, 0, 0, -1, -1, 1, 3, 3, 2, 1, -1, -2, -2, + -2, 0, 2, 2, 2, 2, 1, 1, -9, -8, -4, -2, 1, 3, 3, 3, + -1, -1, -1, -2, -3, -3, -3, -4, 0, 0, 0, -1, -2, -2, -3, -3, + 2, 2, 2, 0, -1, -1, -1, -1, 5, 5, 4, 3, 2, 2, 2, 2, + 6, 3, -1, -4, -3, -1, 1, 1, 2, -1, -3, -4, -1, 2, 2, 0, + -1, -2, -2, 1, 4, 4, 1, -3, -2, -1, 1, 4, 6, 3, -3, -8, + 3, 3, 2, 1, -1, -2, -2, -2, -4, -4, -2, -1, 1, 3, 4, 4, + -4, -5, -5, -4, -2, 0, 2, 2, 7, 7, 4, 1, -1, -2, -3, -2, + -1, 1, 3, 0, -4, -6, 0, 6, -2, 1, 4, 1, -4, -6, -1, 7, + -3, 1, 4, 2, -3, -6, -1, 6, -2, 0, 3, 2, -2, -5, -1, 4, + 1, -1, -2, 1, 4, 4, -1, -7, 1, -1, -4, -1, 5, 6, 0, -6, + 3, 0, -4, -3, 3, 6, 2, -4, 3, 0, -5, -4, 1, 4, 1, -3, + 2, 2, 3, 3, 3, 3, 2, 2, -4, -5, -6, -7, -7, -7, -7, -6, + 1, 2, 3, 3, 3, 3, 2, 2, 0, 0, 1, 1, 1, 2, 2, 1, + 3, -3, -3, 3, 4, -2, -2, 2, 3, -4, -4, 4, 4, -4, -4, 2, + 4, -4, -4, 4, 4, -4, -3, 3, 3, -3, -4, 3, 3, -3, -3, 3, + -2, -2, -2, -2, -2, -2, -1, -1, 6, 7, 8, 8, 8, 7, 6, 5, + -5, -6, -7, -7, -8, -7, -6, -5, 1, 1, 2, 2, 2, 2, 1, 1, + 0, 0, 0, 0, 0, -1, 0, 0, -1, 0, 0, 0, 0, -1, 0, 0, + -2, -3, -2, -2, -2, -3, -3, -3, 2, 3, 5, 6, 4, 2, 1, 0, + 8, 6, 2, 0, 0, 0, 0, 0, 4, 1, 0, 0, 0, -1, -1, -1, + 1, -1, 0, 0, 0, -1, -2, -3, -2, -2, -1, 0, 0, -2, -4, -5, + 3, 1, -1, -2, -3, -4, -5, -5, 2, 1, 0, 0, 1, 1, 0, 0, + 0, -1, -1, 0, 2, 2, 2, 2, -1, -2, -1, 1, 2, 2, 2, 2, + 0, -1, -2, -1, -1, -1, -1, 0, -1, -2, -2, -1, -1, 0, 0, 1, + 2, 1, 1, 2, 2, 1, 1, 0, 6, 5, 3, 1, 0, -2, -4, -4, + -3, -2, -1, 0, 1, 1, 0, -1, 0, 1, 3, 4, 5, 5, 3, 1, + -1, -1, -1, 0, 1, 0, -1, -2, -2, -2, -2, -1, 0, -1, -2, -3, + 0, -1, -2, -2, -1, -1, 0, 2, 1, -1, -2, -1, -1, -1, 0, 2, + 1, 0, -2, -2, -2, -2, 1, 5, 1, -1, -2, -2, -2, 0, 5, 10, + 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, 0, 0, 0, 1, 2, + 1, 2, 2, 3, 4, 4, 6, 5, -3, -3, -3, -2, -2, -3, -3, -3, + 1, -1, -2, -2, 0, 3, 5, 7, 2, 0, -2, -3, -2, 0, 2, 3, + 3, 1, -2, -3, -3, -2, -1, -1, 3, 1, 0, -1, -1, -1, -1, -1, + 1, 3, 5, 4, 2, -1, -3, -4, -3, -2, 1, 2, 1, 0, -1, -2, + -5, -3, 0, 2, 2, 1, 0, 0, -3, -1, 1, 2, 2, 1, 0, 0, + 0, -1, -1, -1, 1, 2, 3, 4, -3, -4, -4, -3, -1, 0, 0, 1, + -2, -3, -2, -1, 1, 1, 1, 1, -2, -2, 0, 3, 4, 4, 3, 2, + -4, -4, -3, -2, -1, 1, 2, 3, 0, 1, 1, 1, -1, -2, -3, -3, + 3, 4, 5, 4, 2, -1, -3, -3, -2, -2, 0, 2, 2, 2, 1, 0, + -4, 0, 5, 7, 4, -1, -4, -4, -1, 2, 4, 3, 0, -3, -3, -2, + 2, 1, 0, -1, -2, -2, 0, 1, 0, 0, -1, -2, -2, -1, 1, 2, + -4, -3, -2, -1, 0, 1, 2, 2, 10, 9, 5, 0, -3, -4, -3, -2, + 1, -1, -2, -2, -1, 0, 0, 0, -2, -2, -1, 1, 1, 1, 0, -1, + -5, -3, 0, 3, 4, 2, 0, -2, -2, -1, 0, 1, 1, 0, -1, -1, + 3, 2, -1, -2, -2, -1, 1, 1, 7, 5, -1, -5, -6, -2, 2, 4, + -2, 3, 3, -3, -4, 1, 2, -2, -3, 3, 4, -3, -4, 2, 3, -2, + -3, 3, 4, -3, -4, 2, 3, -2, -4, 2, 4, -2, -3, 1, 2, -1, + 4, 3, -1, -3, -3, -1, 1, 2, -4, -6, -4, 0, 4, 5, 4, 1, + 0, 2, 5, 6, 2, -3, -5, -4, 1, 1, -1, -3, -5, -2, 2, 4, + -1, 0, 1, 2, 2, 3, 3, 4, -1, 0, 1, 1, 0, -1, -1, -1, + -1, 0, 1, 2, 2, 1, -1, -2, -3, -2, -1, 0, 0, -1, -2, -3, + 1, 1, 1, 1, 0, 0, 1, 2, 1, 0, -1, 0, 0, 1, 1, 0, + 1, -2, -4, -1, 1, 2, 1, 0, 1, -4, -7, -3, 1, 3, 2, 1, + 1, 1, 1, 1, 1, 1, 0, -1, 1, 1, 1, 0, 1, 2, 2, 0, + 1, 1, 0, 0, 0, 2, 0, -3, 3, 2, 0, -1, -1, -2, -6, -9, + 0, 0, 0, 1, 0, 0, 1, 2, 1, 0, 0, 0, -1, -1, 0, 2, + 0, 1, 1, 1, -1, -3, -2, 0, -7, -5, 1, 6, 6, 2, -1, -1, + 3, 1, -1, -3, -4, -2, 1, 4, 2, 0, -2, -3, -4, -3, -1, 2, + 2, 2, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 0, 0, 1, + -1, 1, 1, -2, -5, -6, -4, -1, -1, 1, 4, 3, 2, 0, 1, 2, + -1, 0, 2, 3, 1, 0, 0, 1, -1, 0, 1, 0, 0, -1, -1, 0, + 0, 1, 2, 2, 0, -2, -1, 1, -2, -1, -1, -2, -1, 2, 6, 8, + -1, -1, -2, -3, -2, 0, 1, 2, -1, 0, 0, -1, -1, 0, -1, -1, + 2, 1, 1, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, -1, -1, 1, + -1, 0, 2, 2, -1, -3, -2, 3, 0, 2, 3, 0, -5, -7, -2, 4, + -1, 0, 0, 0, -1, -2, -3, -3, -1, 0, -1, -2, -2, -2, -2, -2, + 1, 1, 0, 0, 1, 2, 0, -1, 1, 2, 1, 2, 5, 6, 2, 0, + -2, -4, -3, 0, 2, 2, 0, -3, 3, 1, 0, 1, 2, 1, -2, -3, + 3, 1, 0, 0, 0, 0, 0, -1, 1, -1, -2, -2, -1, 1, 3, 3, + 3, 2, 1, 2, 4, 3, 1, -2, -2, -4, -4, -3, -1, 0, -2, -3, + 1, 0, -1, -1, 0, 1, 0, -1, 3, 2, 0, 0, 0, 1, 1, 0, + 1, 1, 0, 0, 0, 0, 0, 0, 2, 3, 3, 2, 2, 2, 1, 1, + 0, -1, -2, -3, -5, -5, -5, -4, 1, 1, 0, -1, 0, 1, 3, 3, + -9, -6, -2, 0, 1, 1, 2, 2, -6, -2, 1, 2, 1, 1, 0, 1, + -2, 1, 2, 2, 1, 1, 1, 1, 0, 2, 2, 1, 0, 1, 1, 1, + 1, 0, 0, 0, 0, 0, -1, 0, 0, 0, 0, 0, -1, -3, -2, 0, + -3, -3, -3, -2, -1, 3, 7, 9, 1, 2, 2, 2, 0, -2, -4, -3, + 2, 0, -2, -1, 3, 4, -1, -6, 1, 0, -2, -3, -1, 3, 3, 0, + 0, 3, 3, 0, -2, -1, 1, 1, -6, -1, 3, 2, -1, -2, 0, 1, + 5, 3, 0, -2, -3, 0, 2, 1, 1, 1, 2, 2, 0, -2, -4, -7, + -3, -2, 1, 2, 2, 1, -1, -4, 2, 2, 0, -2, -2, 0, 2, 2, + 0, 0, -2, -3, -2, -1, 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, + -2, -1, 0, 1, 0, 1, 2, 3, -4, -2, 0, 0, -1, 0, 2, 3, + -2, -2, -2, -1, -1, 0, 2, 4, 0, 0, 0, 0, -1, -1, 0, 1, + 0, -1, -1, -1, -1, -1, 0, 0, 6, 4, 2, 0, -1, -2, -1, -1, + 0, 1, 1, 1, 1, -1, -5,-10, 1, 1, 1, 1, 1, 1, 0, -4, + 1, 0, 1, 1, 1, 1, 1, -1, 2, 1, 1, 1, 0, 0, 0, 0, + -3, 1, 4, 3, 3, 1, -1, 0, -4, 0, 1, 0, -1, 0, 0, 0, + -5, 0, 2, 1, 1, 1, 0, -1, -1, 2, 1, -2, -2, -1, 0, -1, + 2, 4, 5, 3, 0, -1, 1, 2, 0, 0, 1, 0, -2, -2, -1, -1, + -2, -2, -2, -2, -3, -2, -1, 0, 0, 0, 1, 0, 0, 0, 1, 2, + 0, -2, -2, -3, -1, 2, 2, -1, 1, 0, 0, 0, 1, 5, 3, -2, + -1, -1, 0, -1, 0, 2, 0, -5, -1, 0, 1, 0, 0, 2, 2, -2, + 3, 1, -1, -1, 0, 1, 1, 2, 1, 0, 0, 1, 1, 1, 1, 1, + -10, -8, -2, 1, 2, 1, 1, 1, -1, 1, 2, 1, 0, 0, 0, 0, + -1, -1, 0, 1, 2, 2, 2, 1, -1, -1, -1, 0, -1, -3, -5, -4, + 1, 1, 2, 1, 1, 0, 0, 2, -1, -2, -1, -1, -1, 0, 2, 4, + -3, -7, -5, 0, 2, 0, 0, 0, 3, -1, -2, 1, 2, 1, 1, 2, + 1, -2, -1, 1, 2, 1, 0, 1, 0, -1, 0, 3, 2, -1, -1, -1, + 2, 1, 1, 0, 0, 0, 0, 0, -9, -7, -2, 3, 3, 2, 1, 1, + 3, 2, 0, -2, -2, -1, 1, 1, 0, -1, 0, 0, 1, 1, 0, 0, + -2, -1, 1, 1, 1, 0, 0, 0, 1, 2, 1, -2, -4, -3, 1, 2, + 1, 2, 1, -2, -3, 0, 3, 1, -1, -1, 0, 0, 1, 3, 0, -4, + 2, 0, -1, 1, 2, -2, -2, 3, 2, 0, -1, 2, 3, -2, -4, 1, + 0, 1, 1, 1, 2, -2, -6, -2, -1, 0, 0, 0, 2, 0, -2, -1, + -1, -1, 1, 2, 1, -2, -3, -2, 3, -1, -2, -1, -1, 0, 1, 2, + 10, 4, 0, 0, -1, -2, -2, -1, 3, -1, -2, -1, 0, -1, -1, 0, + -5, 2, 7, 1, -4, -2, 1, 0, -2, 2, 3, -1, -3, 0, 2, 0, + 2, 1, 0, 0, 1, 1, -1, -2, 1, -2, -2, -1, -1, -2, 0, 0, + 0, 3, -2, -7, -1, 3, 0, 0, 1, 3, -3, -5, 2, 3, -1, 0, + 0, 2, -2, -2, 4, 2, -2, 0, -1, 1, -1, 0, 2, -1, -2, 1, + 4, 0, -3, -4, -2, 1, 2, 1, 0, 0, 3, 5, 3, 1, -1, -2, + 1, 1, 1, -1, -3, -1, 1, 1, 1, -1, -2, -2, 0, 0, -1, -2 +}; + +/* 6x16-entry codebook for intra-coded 8x8 vectors */ +static int8_t svq1_intra_codebook_8x8[6144] = { + 4, 4, 3, 2, 2, 1, 0, -1, 4, 3, 3, 2, 1, 0, -1, -1, + 3, 3, 2, 2, 1, 0, -1, -2, 3, 2, 2, 1, 0, -1, -2, -3, + 2, 2, 1, 0, -1, -1, -2, -3, 2, 1, 0, 0, -1, -2, -3, -4, + 1, 0, 0, -1, -2, -3, -4, -4, 0, 0, -1, -2, -2, -3, -4, -4, + 2, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2, 2, 2, 3, 3, + 1, 2, 2, 2, 2, 2, 2, 2, 0, 1, 1, 1, 1, 1, 1, 1, + -1, 0, 0, 0, 0, 0, 1, 1, -2, -2, -1, -1, -1, -1, -1, -1, + -3, -3, -3, -3, -3, -3, -2, -2, -5, -4, -4, -4, -4, -4, -4, -3, + -4, -2, -1, 0, 1, 2, 2, 3, -4, -2, -1, 0, 1, 2, 3, 3, + -4, -3, -1, 0, 1, 2, 3, 3, -4, -3, -1, 0, 1, 2, 3, 3, + -5, -3, -1, 0, 1, 2, 3, 3, -5, -3, -1, 0, 1, 2, 3, 3, + -5, -3, -1, 0, 1, 1, 2, 3, -5, -3, -2, -1, 0, 1, 2, 3, + 4, 4, 5, 5, 6, 6, 7, 7, 2, 2, 2, 3, 3, 4, 4, 4, + 0, 0, 0, 0, 1, 1, 1, 2, -2, -2, -2, -2, -1, -1, -1, 0, + -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, + -1, -2, -2, -2, -2, -2, -2, -2, -1, -1, -1, -1, -2, -2, -2, -2, + 5, 3, 1, -1, -2, -3, -3, -3, 5, 3, 1, -1, -2, -3, -3, -3, + 5, 3, 1, -1, -2, -3, -3, -3, 5, 3, 1, -1, -2, -3, -3, -3, + 5, 4, 1, 0, -2, -3, -3, -3, 6, 4, 2, 0, -2, -2, -3, -3, + 6, 4, 2, 0, -1, -2, -2, -3, 6, 4, 2, 1, -1, -2, -2, -2, + -1, 1, 3, 3, 2, 0, -3, -6, -1, 1, 3, 4, 3, 0, -3, -6, + -1, 1, 4, 4, 3, 1, -3, -6, -1, 1, 3, 4, 3, 1, -3, -6, + -2, 1, 3, 4, 3, 1, -3, -6, -2, 1, 3, 4, 3, 1, -3, -7, + -2, 1, 3, 3, 2, 0, -3, -7, -2, 0, 2, 3, 2, 0, -3, -6, + 10, 9, 8, 6, 6, 5, 4, 4, 6, 5, 4, 3, 2, 2, 2, 1, + 2, 1, 0, -1, -2, -2, -2, -1, -1, -2, -3, -4, -4, -4, -4, -3, + -2, -3, -4, -4, -5, -4, -4, -3, -2, -2, -3, -3, -3, -3, -2, -2, + -1, -1, -1, -1, -1, -1, -1, 0, 1, 1, 1, 1, 1, 1, 1, 2, + -2, -1, 1, 2, 4, 5, 7, 8, -3, -2, 0, 1, 3, 5, 7, 8, + -4, -3, -1, 0, 2, 4, 6, 7, -5, -4, -2, -1, 1, 3, 5, 7, + -6, -5, -3, -2, 0, 2, 4, 6, -6, -5, -4, -2, -1, 1, 3, 5, + -7, -6, -5, -3, -2, 0, 2, 3, -8, -7, -5, -4, -3, -1, 1, 2, + 11, 9, 7, 5, 3, 1, -1, -1, 10, 8, 6, 3, 1, 0, -2, -2, + 9, 7, 5, 2, 0, -2, -3, -4, 8, 6, 3, 1, -1, -3, -4, -4, + 6, 4, 2, -1, -3, -4, -5, -5, 5, 3, 0, -2, -4, -5, -6, -6, + 3, 1, -1, -3, -5, -6, -7, -7, 2, 0, -2, -4, -6, -6, -7, -7, + 5, 6, 7, 7, 7, 8, 8, 8, 3, 4, 5, 5, 6, 6, 6, 6, + 0, 2, 2, 3, 4, 4, 4, 5, -2, -1, 0, 1, 2, 2, 3, 3, + -4, -3, -2, -1, 0, 1, 1, 2, -6, -5, -4, -3, -2, -2, -1, 0, + -8, -7, -6, -6, -5, -4, -3, -3,-10, -9, -8, -8, -7, -6, -6, -5, + 6, 5, 3, 1, -1, -3, -6, -8, 6, 5, 4, 2, -1, -3, -6, -8, + 6, 5, 4, 2, 0, -3, -6, -8, 6, 5, 4, 2, 0, -3, -6, -8, + 6, 6, 4, 2, 0, -3, -6, -8, 6, 5, 4, 2, 0, -3, -6, -8, + 6, 5, 4, 2, 0, -3, -6, -8, 6, 5, 4, 2, -1, -3, -5, -8, + 11, 10, 9, 8, 7, 6, 5, 4, 8, 8, 7, 6, 5, 4, 3, 2, + 6, 5, 4, 4, 2, 2, 1, 0, 3, 3, 2, 1, 0, 0, -1, -2, + 1, 1, 0, -1, -2, -2, -3, -3, -1, -1, -2, -3, -4, -4, -5, -5, + -3, -4, -4, -5, -6, -6, -7, -7, -5, -5, -6, -7, -8, -8, -8, -8, + -14,-13,-12,-11, -9, -7, -6, -4,-12,-11,-10, -9, -7, -5, -3, -1, + -10, -9, -7, -6, -3, -2, 0, 2, -8, -6, -4, -2, 0, 2, 4, 5, + -5, -3, 0, 2, 4, 5, 7, 8, -2, 0, 2, 4, 6, 8, 9, 10, + 0, 3, 5, 7, 8, 10, 11, 12, 3, 5, 7, 8, 10, 11, 12, 12, + -19,-19,-18,-18,-17,-16,-15,-14,-15,-15,-14,-13,-12,-11,-10, -9, + -11,-10, -9, -8, -6, -5, -4, -3, -6, -5, -3, -2, -1, 0, 1, 2, + -1, 0, 2, 3, 4, 5, 6, 6, 4, 6, 7, 8, 9, 10, 10, 10, + 9, 10, 11, 12, 13, 14, 14, 14, 12, 14, 14, 15, 16, 16, 16, 16, + 22, 21, 19, 17, 14, 11, 9, 5, 20, 19, 17, 14, 11, 8, 4, 1, + 17, 15, 13, 10, 6, 3, 0, -4, 13, 11, 8, 5, 1, -2, -5, -9, + 9, 6, 3, -1, -4, -7,-11,-13, 4, 0, -3, -6, -9,-12,-15,-17, + -2, -5, -8,-11,-14,-16,-18,-20, -8,-10,-13,-16,-17,-19,-21,-22, + 17, 18, 18, 18, 17, 16, 16, 14, 16, 16, 15, 15, 14, 13, 12, 11, + 12, 12, 11, 10, 9, 8, 7, 5, 7, 6, 6, 4, 3, 2, 1, -1, + 1, 0, -1, -2, -3, -4, -5, -6, -5, -6, -7, -8, -9,-10,-11,-12, + -11,-12,-13,-14,-15,-16,-16,-17,-16,-17,-17,-18,-19,-20,-20,-20, + 0, 0, 0, 0, -1, -1, -2, -3, 1, 0, 0, 0, 0, -1, -2, -3, + 1, 1, 0, 0, -1, -1, -2, -2, 1, 1, 1, 0, 0, -1, -1, -2, + 2, 1, 1, 1, 0, -1, -1, -2, 2, 2, 1, 1, 0, 0, -1, -2, + 2, 2, 1, 1, 1, 0, -1, -1, 2, 2, 1, 1, 1, 0, 0, -2, + 0, -1, -1, 0, 0, 1, 2, 3, 0, -1, -1, 0, 1, 1, 2, 2, + -1, -1, -1, -1, 0, 1, 2, 2, -1, -1, -2, -1, 0, 1, 1, 2, + -1, -2, -2, -1, 0, 0, 1, 2, -1, -2, -2, -2, -1, 0, 1, 2, + -1, -1, -2, -1, 0, 0, 1, 2, -1, -1, -1, -1, 0, 1, 1, 2, + 3, 2, 2, 2, 1, 1, 0, 0, 3, 2, 2, 2, 2, 1, 0, 0, + 2, 2, 2, 1, 1, 1, 0, 0, 2, 2, 1, 1, 1, 0, 0, -1, + 1, 1, 1, 0, 0, 0, -1, -1, 0, 0, -1, -1, -1, -1, -1, -1, + -2, -2, -2, -2, -2, -2, -2, -2, -2, -3, -3, -3, -2, -2, -2, -2, + 5, 2, 0, 0, -1, 0, 0, 0, 4, 2, 0, -1, -1, -1, 0, -1, + 4, 1, -1, -1, -2, -1, -1, -1, 4, 1, -1, -1, -2, -1, -1, -1, + 4, 1, -1, -2, -2, -1, -1, -1, 4, 1, -1, -2, -2, -1, -1, -1, + 4, 1, -1, -1, -1, -1, -1, -1, 4, 2, 0, -1, 0, 0, 0, -1, + -2, -1, 0, 1, 1, 1, 1, 1, -3, -1, 0, 1, 1, 1, 1, 1, + -3, -1, 0, 1, 1, 1, 1, 1, -3, -1, 0, 1, 1, 1, 1, 1, + -3, -2, 0, 1, 2, 2, 1, 1, -4, -2, 0, 1, 2, 2, 2, 2, + -5, -3, -1, 1, 1, 2, 1, 2, -5, -3, -2, 0, 1, 1, 1, 1, + 3, 3, 1, 0, -2, -4, -4, -5, 3, 3, 2, 0, -1, -2, -3, -4, + 2, 2, 1, 1, 0, -1, -2, -2, 1, 1, 1, 1, 1, 0, 0, 0, + 0, 0, 0, 1, 1, 1, 1, 1, -2, -1, -1, 0, 0, 1, 2, 2, + -3, -2, -2, -1, 0, 1, 2, 3, -3, -3, -2, -1, 0, 1, 2, 3, + -3, -3, -3, -3, -3, -2, -2, -2, -3, -3, -2, -2, -2, -1, -1, -1, + -2, -2, -2, -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 2, 2, 2, 2, + 1, 1, 1, 2, 2, 3, 3, 3, 2, 2, 2, 2, 3, 3, 3, 3, + -8, -7, -5, -3, -2, -1, 0, -1, -4, -3, -1, 0, 1, 2, 1, 1, + -1, 1, 2, 3, 3, 2, 2, 1, 1, 2, 3, 3, 2, 2, 1, 0, + 2, 3, 3, 2, 1, 0, 0, -1, 1, 2, 1, 0, -1, -1, -1, -1, + 1, 1, 0, -1, -1, -2, -2, -1, 1, 1, 0, 0, -1, -1, 0, -1, + -4, -3, -2, 0, 1, 2, 3, 3, -4, -3, -2, 0, 1, 2, 2, 2, + -3, -3, -2, -1, 0, 1, 1, 1, -2, -2, -2, -1, -1, 0, 0, 0, + 0, -1, -1, -1, -1, -1, -1, -1, 2, 1, 1, 0, 0, -1, -1, -2, + 3, 3, 3, 1, 0, -1, -2, -2, 5, 4, 4, 2, 1, 0, -1, -2, + 0, 0, 0, 0, 1, 2, 3, 3, 0, -1, 0, 0, 1, 2, 3, 3, + 0, -1, 0, 0, 1, 2, 3, 2, 0, 0, 0, 1, 1, 2, 2, 2, + 2, 1, 1, 1, 1, 1, 1, 0, 2, 2, 2, 1, 0, 0, -1, -2, + 2, 1, 0, 0, -2, -3, -5, -6, 0, -1, -1, -3, -5, -6, -8, -9, + -2, 0, 1, 2, 2, 1, -1, -4, -2, 0, 2, 2, 2, 1, -1, -4, + -2, 0, 2, 2, 2, 1, -1, -3, -2, 0, 2, 2, 2, 1, -1, -3, + -2, -1, 2, 2, 2, 1, -1, -3, -2, -1, 1, 2, 2, 1, -1, -3, + -3, -1, 1, 2, 2, 1, -1, -3, -2, -1, 1, 2, 2, 1, -1, -3, + -1, 1, 1, -1, -3, -3, 0, 4, -1, 1, 1, -1, -3, -3, 0, 4, + -1, 1, 1, 0, -3, -3, 0, 4, -1, 1, 2, 0, -3, -3, 0, 5, + 0, 1, 2, 0, -3, -4, 0, 4, 0, 1, 2, 0, -3, -4, 0, 5, + 0, 1, 2, 0, -3, -3, 0, 4, 0, 1, 2, -1, -2, -2, 0, 4, + 6, 6, 5, 6, 5, 5, 5, 5, 2, 2, 2, 2, 2, 2, 2, 2, + 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -2, -2, -2, -2, + -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, -2, + -1, -1, -2, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 2, 2, 2, 2, 2, 2, 2, 2, 0, 1, 1, 0, 0, 0, 0, 0, + -1, -2, -2, -2, -2, -2, -2, -1, -3, -3, -3, -3, -3, -3, -3, -2, + -3, -4, -4, -3, -3, -3, -2, -2, -2, -2, -2, -2, -1, -1, 0, 0, + 0, 1, 1, 1, 2, 2, 3, 3, 3, 4, 4, 5, 5, 6, 6, 6, + 4, 1, -2, -3, -3, -1, 1, 3, 4, 1, -2, -4, -3, -1, 1, 3, + 5, 1, -2, -4, -3, -1, 1, 4, 5, 1, -2, -3, -3, -1, 2, 4, + 5, 1, -2, -3, -3, -1, 2, 4, 4, 0, -3, -4, -3, -1, 2, 4, + 4, 0, -3, -3, -3, -1, 1, 3, 3, 0, -2, -3, -2, -1, 1, 3, + -3, -4, -4, -4, -4, -4, -4, -4, -1, -1, -1, -1, -1, -1, -2, -2, + 2, 1, 1, 2, 2, 1, 1, 1, 3, 3, 3, 4, 4, 3, 3, 3, + 3, 3, 3, 4, 4, 4, 3, 3, 1, 2, 1, 2, 2, 2, 2, 2, + -2, -2, -2, -1, -1, -1, 0, 0, -4, -4, -4, -4, -3, -3, -3, -3, + -1, -2, -3, -3, -2, -2, -1, 0, 0, -1, -2, -2, -2, -1, 0, 1, + 2, 1, -1, -1, -1, -1, 0, 1, 3, 1, 0, -1, -1, 0, 0, 1, + 3, 2, 0, -1, 0, 0, 0, 1, 3, 1, 0, -1, 0, 0, 0, 1, + 3, 1, 0, -1, 0, 0, 0, 1, 2, 1, 0, 0, 0, 0, 0, 1, + 0, 0, 0, 1, 1, 2, 3, 4, 0, 0, -1, 0, 0, 0, 2, 3, + 0, -1, -1, -1, -1, -1, 0, 1, 0, -1, -1, -1, -1, -1, -1, 0, + 0, 0, -1, -1, -1, -2, -2, -1, 1, 0, 0, -1, -1, -2, -2, -1, + 2, 2, 1, 0, -1, -1, -1, -1, 3, 3, 2, 1, 0, -1, -1, 0, + 1, 0, 1, 0, 0, -1, -2, -1, 0, 0, 0, 0, -1, -1, -2, -1, + 0, -1, 0, 0, -1, -1, -1, -1, -1, -1, -1, 0, 0, 0, 0, 0, + -1, -1, -1, 0, 0, 0, 1, 1, -1, -1, -1, 0, 1, 1, 2, 3, + -2, -2, -1, 0, 1, 2, 3, 4, -2, -2, -1, 0, 1, 2, 4, 5, + -3, -1, 1, 0, 0, -1, 0, 1, -3, 0, 1, 0, -1, -1, 0, 2, + -3, 0, 1, 0, -1, -1, 0, 2, -2, 1, 2, 0, -1, -1, 0, 2, + -2, 1, 2, 0, -1, -1, 0, 2, -2, 1, 2, 0, -1, -1, 0, 2, + -1, 2, 2, 0, -1, -1, 0, 2, -1, 1, 1, 0, -1, -1, -1, 1, + -2, -2, -1, 1, 3, 4, 3, 1, -2, -2, -1, 0, 2, 3, 2, 0, + -2, -2, -1, 0, 1, 2, 1, -1, -1, -1, -1, 0, 1, 2, 1, -1, + -1, -1, -1, 0, 1, 1, 0, -2, 0, -1, -1, 0, 1, 1, 0, -1, + 0, -1, -1, 0, 1, 1, 1, -1, 0, -1, -1, 0, 0, 1, 0, -1, + -2, -1, 0, 1, 1, 1, 1, 1, -2, -1, 0, 0, 0, 0, 0, 0, + -2, -1, -1, 0, -1, -1, -2, -2, -2, -1, -1, -1, -1, -2, -2, -3, + -1, 0, 1, 1, 0, -1, -2, -2, 1, 2, 3, 3, 2, 1, 0, 0, + 1, 2, 3, 3, 3, 2, 1, 0, 0, 0, 1, 1, 1, 1, 0, 0, + 0, -1, -1, -1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 1, 1, 1, 1, + 1, 1, 1, 1, 1, 1, 1, 1, -1, 0, 0, 1, 1, 0, 0, 0, + -3, -2, -1, -1, -1, -1, 0, -1, -5, -5, -4, -3, -2, -2, -2, -1, + 1, 1, 1, 1, 2, 1, 0, -1, 1, 1, 1, 2, 1, 1, 0, -1, + 1, 1, 1, 1, 1, 1, 0, -2, 2, 1, 1, 1, 1, 1, 0, -2, + 1, 1, 0, 0, 0, 0, -1, -3, 1, 1, 0, 0, 0, -1, -2, -3, + 1, 1, 0, 0, -1, -1, -2, -4, 1, 0, 0, -1, -2, -2, -3, -4, + 8, 7, 5, 3, 2, 1, 1, 1, 2, 1, 0, 0, -1, -1, -2, -1, + -1, -1, -1, -2, -2, -2, -2, -1, -1, -1, -1, -1, 0, -1, -1, 0, + 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 0, + -1, 0, 0, 0, 0, 0, -1, -1, -2, -2, -1, -1, -1, -2, -2, -1, + 9, 4, 0, -2, -2, -2, -1, -1, 7, 2, -1, -2, -2, -1, 0, 0, + 4, 0, -2, -2, -1, 0, 1, 1, 1, -2, -2, -2, -1, 0, 1, 1, + -1, -2, -2, -1, 0, 1, 1, 1, -1, -2, -1, 0, 1, 1, 1, 0, + -1, -1, 0, 1, 1, 1, 0, -1, 0, -1, 0, 1, 0, 0, -1, -1, + 0, 1, 1, 1, 1, 1, 0, 0, 1, 2, 2, 2, 1, 0, 0, 0, + 2, 2, 2, 2, 1, 0, -1, -1, 1, 1, 1, 0, -1, -2, -2, -2, + 0, 0, 0, -1, -2, -3, -2, -2, -1, -1, -1, -2, -2, -2, -1, 0, + -1, -1, -1, -1, 0, 0, 1, 2, -1, -1, -1, 0, 1, 2, 3, 4, + -1, -1, 0, 0, -1, -2, -3, -3, -1, -1, 0, 0, 0, -1, -1, -1, + -2, -2, -1, 0, 1, 1, 1, 1, -2, -2, -2, 0, 1, 2, 3, 3, + -1, -1, -1, 0, 1, 3, 3, 3, 1, 0, 0, 0, 1, 1, 2, 2, + 2, 2, 1, 0, 0, -1, -1, -1, 3, 2, 1, 0, -1, -2, -3, -3, + -1, -1, -1, -2, -2, -3, -4, -5, 0, 0, 0, -1, -1, -3, -3, -4, + 1, 1, 1, 0, 0, -1, -2, -3, 2, 2, 2, 1, 1, 0, -1, -1, + 2, 2, 2, 2, 1, 1, 0, -1, 2, 2, 2, 2, 2, 1, 0, 0, + 1, 1, 2, 1, 1, 1, 0, 0, 0, 0, 1, 1, 0, 0, 0, -1, + -2, 2, 3, 1, -1, 1, 1, -1, -3, 2, 3, 0, -1, 1, 1, -1, + -3, 2, 3, 0, -1, 1, 1, -1, -4, 2, 3, 0, -1, 1, 1, -2, + -4, 1, 3, 0, -1, 1, 1, -2, -4, 1, 3, -1, -2, 1, 1, -2, + -3, 1, 2, 0, -1, 1, 1, -2, -3, 1, 2, 0, -1, 1, 1, -1, + -1, -1, -1, -2, -2, -2, -2, -2, 1, 1, 1, 1, 0, 0, 0, 0, + 1, 2, 2, 2, 2, 2, 2, 2, 0, 0, 1, 1, 1, 2, 2, 2, + -2, -2, -1, -1, -1, 0, 0, 0, -3, -3, -3, -3, -3, -3, -3, -2, + -1, -1, -1, -1, -2, -2, -2, -2, 4, 4, 4, 4, 4, 3, 3, 2, + -3, -3, -2, -1, 0, 1, 2, 5, -3, -3, -3, -2, -1, 1, 3, 6, + -3, -3, -2, -2, 0, 2, 3, 5, -3, -2, -2, -2, 0, 1, 3, 5, + -2, -2, -2, -1, -1, 1, 3, 5, -2, -2, -1, -1, 0, 1, 2, 4, + -1, -1, -1, -1, 0, 1, 1, 4, -1, -1, -1, -1, 0, 1, 2, 3, + 0, -1, 0, 1, 1, 0, -1, -1, 0, 0, 0, 1, 2, 0, -1, -1, + 1, 0, -1, 0, 1, 0, 0, 0, 1, -1, -2, -1, 0, 0, 0, 0, + 1, -2, -3, -1, 0, 0, 0, 1, 1, -1, -3, -2, 0, 1, 1, 2, + 1, -1, -2, -1, 0, 1, 1, 2, 2, 0, -1, 0, 1, 1, 2, 2, + 1, 1, 1, 1, 0, 0, 1, 2, -1, 0, 0, -1, 0, 0, 0, 1, + -3, -2, -1, -1, -1, 0, 1, 1, -4, -2, -1, 0, 0, 1, 1, 1, + -3, -2, 0, 0, 1, 1, 1, 1, -3, -1, 0, 1, 1, 1, 0, 0, + -1, 0, 1, 1, 1, 0, 0, -1, 0, 1, 2, 2, 1, 0, 0, -1, + -4, -4, -4, -3, -2, -1, -1, -1, -2, -2, -2, -1, 0, 0, 0, 0, + -1, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 1, 1, + 0, 0, 1, 1, 2, 2, 1, 0, 0, 0, 1, 1, 1, 1, 1, 0, + 0, 0, 0, 1, 1, 1, 1, 0, -1, 0, 0, 1, 1, 1, 0, 0, + 1, 2, 2, 2, 1, -1, -2, -4, 1, 1, 2, 2, 1, 0, -2, -4, + 0, 1, 1, 1, 1, 0, -1, -3, -1, 0, 1, 1, 0, 0, -1, -2, + -1, 0, 1, 1, 1, 0, 0, -1, -2, -1, 0, 0, 0, 0, 0, -1, + -1, -1, 0, 1, 1, 0, 0, 0, -1, 0, 1, 1, 1, 1, 1, 0, + 2, 2, 0, -1, -2, -1, -1, -2, 1, 1, -1, -2, -2, -1, -1, -2, + 1, 1, -1, -2, -2, 0, 0, -1, 1, 1, 0, -2, -1, 1, 1, 0, + 1, 1, 0, -1, -1, 1, 2, 1, 1, 1, 0, -1, -1, 1, 2, 1, + 1, 1, 0, -1, -1, 1, 1, 1, 1, 1, 0, -1, 0, 1, 1, 1, + 0, 0, -1, -2, -4, -4, -4, -4, 3, 3, 3, 2, 1, 0, 0, 0, + 3, 3, 3, 3, 2, 2, 2, 2, 0, 0, 0, 0, 0, 0, 0, 1, + -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, 0, 0, -1, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, -1, 0, + -1, -1, 0, -1, -1, 1, 2, -1, 1, 1, 0, 0, 0, 2, 3, -1, + 1, 1, 0, -1, -1, 1, 3, -1, 1, 1, 0, -2, -2, 0, 1, -2, + 1, 0, 0, -2, -2, 0, 1, -3, 0, 0, 0, 0, -1, 1, 1, -3, + 0, 1, 1, 0, 1, 2, 1, -3, -1, 0, 1, 1, 1, 2, 1, -4, + -4, -3, 0, 1, 1, 1, 0, 0, -4, -2, 0, 1, 1, 1, 0, -1, + -3, -1, 1, 1, 1, 0, -1, -1, -1, 1, 1, 1, 1, 0, -1, 0, + 1, 2, 2, 1, 0, -1, 0, 0, 2, 2, 1, 0, -1, -1, 0, 1, + 2, 1, 0, -1, -2, -1, 0, 1, 2, 2, 0, -1, -2, -1, 1, 1, + 1, 1, 0, 0, -1, -1, -1, -1, 0, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, 0, 0, -1, -1, -1, -1, -1, -1, + 1, 0, 0, -1, -1, -1, -1, -1, 2, 1, 0, 0, -1, -1, -1, -1, + 5, 3, 2, 1, 0, 0, 0, 0, 6, 5, 3, 2, 1, 0, 0, 0, + 4, 4, 3, 1, 0, 0, 0, 1, 3, 3, 2, 1, 0, 0, 0, 1, + 2, 2, 1, 0, -1, -1, 0, 1, 0, 0, 0, -1, -1, -1, 0, 1, + 0, 0, -1, -1, -2, -1, 0, 2, 0, -1, -1, -2, -2, -2, 0, 1, + 0, -1, -1, -2, -2, -2, -1, 0, 0, 0, -1, -2, -2, -2, -1, 0, + 0, 0, -1, -1, -1, 0, 2, 3, 0, -1, -2, -2, -1, -1, 1, 2, + 1, 0, -1, -1, -1, 0, 0, 0, 1, 1, 1, 0, 0, 0, -1, -1, + 1, 2, 1, 0, 0, -1, -1, -1, -1, 0, 0, 0, -1, -1, -1, -1, + -3, -2, -1, -1, 0, 1, 1, 2, -4, -3, -1, 1, 2, 3, 5, 5, + 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, + 0, 0, 0, -1, 0, 0, 0, 1, -1, -1, -2, -2, -2, -1, -1, 0, + 0, 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 2, 2, 3, 3, 3, + 1, 1, 1, 1, 2, 2, 1, 1, -4, -3, -4, -4, -4, -4, -3, -3, + -1, 0, 1, 2, 2, 3, 3, 3, -1, -1, -1, -1, 0, 0, 0, 0, + 0, 0, -1, -2, -2, -3, -3, -2, 3, 2, 1, 0, -1, -2, -2, -2, + 4, 3, 2, 1, 1, 0, 0, 0, 2, 2, 1, 1, 0, 1, 1, 1, + 0, -1, -1, -1, -1, 0, 0, 1, -2, -2, -2, -2, -2, -1, 0, 0, + 1, -1, 0, 2, 1, -2, -1, 1, 1, -1, 0, 2, 1, -2, -2, 1, + 1, -1, 0, 3, 2, -2, -1, 1, 0, -2, 0, 3, 2, -2, -2, 1, + 0, -2, 0, 3, 2, -2, -2, 1, 0, -2, 0, 3, 1, -2, -1, 1, + 0, -2, 0, 2, 1, -2, -2, 1, 0, -1, 0, 2, 1, -2, -1, 1, + 0, 1, 2, 2, 3, 3, 2, 2, 0, 1, 1, 2, 3, 3, 2, 1, + 0, 0, 1, 2, 2, 2, 2, 1, -1, 0, 0, 1, 1, 1, 1, 1, + -1, -1, 0, 0, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, -1, + -2, -2, -2, -2, -2, -2, -2, -1, -2, -2, -2, -2, -2, -2, -2, -1, + 0, 0, -1, -2, -1, 0, 3, 5, 0, 0, -1, -1, -1, 0, 2, 4, + 1, 1, 0, 0, -1, -1, 1, 2, 1, 2, 1, 1, 0, -1, -1, 0, + 0, 1, 2, 1, 0, -1, -2, -2, -1, 0, 1, 2, 1, 0, -3, -3, + -2, -1, 1, 2, 2, 0, -2, -4, -2, -1, 0, 2, 2, 1, -1, -3, + 0, 0, 0, 0, 0, 0, -1, -1, 0, 0, -1, 0, 0, 0, 0, 0, + -1, -1, -1, -1, 0, 0, 0, 0, -1, -1, -1, -1, -1, -1, -1, 0, + -1, -1, -1, -1, -1, -1, -1, 0, -1, 0, 0, 0, 0, -1, -1, 0, + 0, 0, 1, 1, 0, 0, 0, 1, 3, 3, 3, 4, 3, 3, 3, 3, + 5, 1, -2, -2, 0, 0, 0, -1, 4, -1, -3, -1, 0, 0, 0, -1, + 3, -1, -1, 0, 1, 1, 0, -1, 2, 0, 0, 1, 1, 1, 0, -2, + 1, 0, 0, 1, 1, 1, 0, -2, 0, -1, -1, -1, 0, 0, 0, -1, + 0, -1, -1, -1, -1, 0, 0, -1, 2, 1, 0, 0, 0, 1, 0, 0, + 1, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, + 1, -1, -1, 0, 0, 0, 0, 0, 2, 0, -1, -1, -1, -1, -1, 0, + 3, 1, -1, -1, -2, -2, -2, -1, 4, 2, 1, 0, -1, -2, -2, -1, + 2, 1, 0, 0, -1, -1, 0, 0, 0, -1, -1, -1, -1, 0, 1, 1, + 0, 1, 2, 2, 2, 1, -1, -3, 0, 0, 1, 1, 1, 0, -1, -2, + 0, 0, 0, 0, 0, 0, -1, -1, 0, 0, -1, 0, 0, 1, 1, 0, + 0, 0, -1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 1, 1, 1, 0, + 0, 0, 1, 1, 2, 1, -1, -3, 0, 0, 0, 1, 1, -1, -4, -5, + -2, -2, -2, -1, 0, 2, 2, 2, 0, 0, 0, 0, 1, 1, 1, 0, + 1, 1, 1, 1, 1, 0, -2, -3, 0, 0, 1, 1, 0, -1, -3, -4, + -1, -1, 0, 1, 0, 0, -2, -3, -1, -1, 0, 1, 1, 1, 0, -1, + 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, + 0, 1, 0, 0, 1, 1, 1, 2, 1, 2, 0, 0, 0, 0, -1, 1, + 0, 2, 0, -1, 1, 0, -1, 0, 0, 1, 0, 0, 2, 1, 0, 1, + 0, 1, -1, 0, 2, 2, 0, 1, -1, 0, -1, -1, 2, 1, 1, 2, + -2, -2, -3, -2, 0, 1, 1, 1, -2, -2, -3, -3, -1, -1, -1, 0, + -3, -1, 0, 1, 2, 1, 1, 0, -3, -1, 0, 1, 2, 1, 1, 1, + -2, 0, 0, 1, 1, 1, 1, 1, -1, 0, 0, 0, 0, 0, 0, 0, + -2, 0, 0, 0, 0, -1, -1, 0, -2, 0, 0, 0, 0, 0, -1, -1, + -3, 0, 1, 1, 1, 1, 0, 1, -5, -2, 0, 1, 2, 2, 1, 2, + -2, -1, -1, 0, 0, 1, 2, 3, 0, 0, 1, 1, 0, 0, 1, 2, + 0, 0, 1, 0, -1, -1, 0, 1, -1, -1, -1, -1, -2, -2, -1, 0, + -2, -2, -2, -2, -2, -1, 0, 1, 0, 0, 0, -1, 0, 1, 2, 2, + 2, 1, 0, 0, 0, 1, 2, 2, 2, 1, 0, -1, -1, -1, 0, 0, + 0, 1, 1, 1, 1, 1, -1, -4, -1, -1, 0, 1, 1, 1, 0, -3, + -2, -1, 0, 0, 1, 2, 2, -2, -1, 0, 0, 0, 0, 2, 3, -1, + -1, 0, 0, 0, 0, 1, 2, 0, 0, 0, -1, -2, -1, 1, 1, 0, + 0, 0, -1, -2, -2, 0, 2, 1, 0, 0, -1, -2, -1, 1, 2, 2, + 1, 0, 0, 0, -2, -3, -2, -3, 0, 0, 1, 0, -2, -2, -1, -1, + 0, -1, 1, 1, -1, -1, 0, 0, 0, -1, 1, 1, -1, -1, 0, 0, + 0, 1, 2, 1, -1, -1, 0, 1, 1, 2, 3, 2, 0, 0, 1, 2, + -1, 0, 2, 1, 0, 0, 2, 3, -2, -1, 0, 0, -1, 0, 1, 2, + 1, 1, 0, -1, -2, -2, -1, 1, 1, 1, 1, -1, -2, -2, 0, 2, + 1, 1, 1, -1, -1, -1, 0, 2, 0, 0, 0, 0, 0, 0, 1, 2, + -1, -1, -1, 0, 0, 0, 1, 2, -1, -2, -1, 1, 1, 1, 0, 0, + -1, -2, -1, 1, 2, 2, 0, -1, -1, -2, -1, 2, 2, 2, 0, -1, + -1, -1, -1, -2, -1, -1, 0, 1, 0, 0, -1, -1, -1, 0, 1, 2, + 1, 0, 0, 0, 0, 1, 1, 2, 1, 1, 0, 0, 1, 1, 1, 1, + 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, -1, -1, -1, + 1, 2, 1, 0, -1, -2, -2, -3, 2, 2, 1, 0, -2, -3, -4, -4, + -4, -2, 1, 1, 1, 1, 0, 0, -2, 0, 1, 0, 0, 0, 0, 0, + 0, 1, 1, -2, -2, -1, 0, 1, 2, 2, 1, -2, -2, -1, 1, 2, + 1, 2, 1, -2, -2, -1, 1, 2, -1, 1, 1, -1, -1, -1, 0, 1, + -2, 0, 1, 1, 0, -1, -1, 0, -2, 0, 2, 2, 1, -1, -1, 0, + 1, 1, 0, 0, 0, 1, 0, 0, -2, -3, -3, -2, -2, -1, 0, 0, + -3, -4, -3, -2, -1, 0, 0, 0, -1, -1, 0, 1, 2, 3, 2, 1, + 0, 1, 2, 3, 3, 3, 2, 1, 1, 1, 1, 2, 1, 0, 0, -1, + 0, 0, 0, 0, -1, -1, -1, -1, 0, -1, -1, 0, 0, 0, 0, 0, + 1, 1, 0, 0, -1, -1, 0, 2, 0, 0, 1, 0, -1, -1, 1, 1, + -2, -1, 0, 1, 1, 1, 1, 1, -3, -3, 0, 2, 2, 1, 1, 0, + -2, -2, 0, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, -1, -1, + 3, 1, -1, -3, -2, -1, 0, 1, 4, 2, -1, -3, -3, -1, 1, 2, + 0, 0, 0, -1, -1, -1, -1, -1, 1, 2, 1, 0, 0, 0, -1, -1, + 2, 3, 3, 2, 1, 0, -1, -1, 3, 4, 4, 2, 1, 0, -1, -2, + 3, 3, 2, 1, 0, -1, -2, -2, 1, 1, 0, -1, -1, -2, -2, -3, + 0, 0, 0, -1, -1, -2, -2, -2, -1, -1, -1, -1, -1, -2, -2, -1, + 1, 2, 2, 2, 2, 1, 2, 2, 0, 1, 1, 1, 1, 0, 0, 0, + 0, 0, 0, 1, 1, 0, -1, -2, 0, 0, 0, 0, 1, 0, -1, -4, + 1, 0, 0, 0, 0, 0, -2, -5, 1, 0, 0, 0, 0, 0, -1, -4, + 1, 0, -1, 0, 0, 0, -1, -3, 0, -1, -1, 0, 1, 1, 1, -1, + -2, -1, 0, 0, -1, -1, -1, -2, -1, 0, 0, 0, -1, -1, -2, -2, + 0, 1, 1, 0, -1, -1, -1, -2, 0, 1, 1, 0, 0, 0, -1, -1, + 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 2, 2, 1, + 1, 1, 0, 0, 1, 2, 2, 1, 1, 1, 0, -1, 0, 1, 1, 0, + 4, 2, 1, 0, 0, 1, 1, 1, 4, 2, 1, 0, 0, 0, 0, 1, + 3, 1, 0, 0, -1, -1, -1, 0, 1, 0, 0, -1, -1, -2, -1, 0, + 0, 0, 0, 0, -1, -1, -1, 0, -1, -1, 0, 0, -1, -1, 0, 1, + -2, -1, 0, -1, -1, 0, 0, 1, -2, -2, -1, -2, -1, 0, 0, 1, + 0, 1, 1, 1, 2, 1, 0, -1, -1, -1, -1, 0, 0, -1, -2, -2, + -1, 0, -1, 0, 0, -1, -2, -1, 0, 0, 0, 0, 0, 0, 1, 2, + 0, 0, 0, 0, 0, 0, 2, 3, -1, 0, -1, -1, -1, -1, 0, 3, + -1, 0, 0, -1, -1, -2, 0, 3, 0, 0, 0, 0, -1, -1, 1, 4, + 2, 2, 0, 0, 0, 0, 0, 1, 1, 1, -1, -2, -1, -2, -1, 1, + -1, -1, -2, -2, -2, -3, -2, 0, -1, 0, -1, -1, -1, -2, -1, 1, + 1, 1, 0, 0, 1, 0, 0, 1, 2, 2, 0, 0, 1, 0, 0, 1, + 2, 2, 0, 0, 0, 0, -1, -1, 2, 2, 0, 0, 1, 0, -1, -1, + -1, 0, 1, 1, 0, -1, -1, -1, 1, 2, 3, 2, 1, 0, 0, 0, + 0, 1, 1, 1, 0, -1, 0, 0, -2, -2, -1, 0, 1, 0, 0, 0, + -2, -2, -1, 2, 2, 2, 1, 0, -2, -1, 0, 1, 1, 0, 0, -1, + -1, -1, 0, 0, -1, -2, -1, -2, 0, 1, 1, 1, 0, 0, 1, 1, + -3, -3, -3, -2, -1, -1, -2, -2, -1, -1, 0, 1, 2, 1, 0, 0, + 1, 1, 1, 2, 2, 1, 0, 0, 1, 1, 1, 1, 1, 0, -1, 1, + 1, 0, -1, -1, 0, 0, -1, 1, 0, -1, -1, -1, 0, -1, -1, 1, + 1, 0, -1, 0, 0, -1, 0, 2, 2, 0, -1, 0, 0, 0, 0, 2, + 1, 0, -2, -1, 0, 1, 1, 0, 2, 0, -1, -1, 0, 1, 1, 0, + 1, 0, -2, -1, 0, 1, 0, -1, 1, 0, -1, -1, 0, 1, 0, -1, + 0, 1, 1, 0, 1, 1, 0, 0, -2, 1, 2, 1, 0, 0, 0, 1, + -5, 0, 2, 1, 0, -1, 0, 1, -6, -1, 2, 1, 0, -1, 0, 0, + 5, 3, 0, -1, -2, -1, -1, -1, 1, 1, 0, -1, -1, 0, -1, -1, + -1, 0, 1, 1, 2, 2, 1, 0, -2, -1, 0, 1, 2, 1, 1, 1, + -2, -1, -1, -1, 0, -1, 0, 1, 0, 1, 0, 0, -1, -1, 0, 0, + 0, 1, 1, 1, 1, 0, 0, 0, -3, -2, 0, 1, 1, 0, 0, -1, + -1, 0, 1, 0, -1, 0, 2, 3, -1, 0, 0, -2, -4, -2, -1, 0, + 0, 1, 1, 0, -2, -1, 0, -1, 1, 2, 3, 1, 0, 1, 1, 0, + -1, 0, 1, 1, 1, 1, 1, 0, -2, -3, -2, 0, 0, 0, 1, 0, + -1, -2, -2, 0, 1, 0, 0, -1, 3, 1, 0, 0, 1, 0, -1, -1, + -2, -1, 0, 0, -1, -1, 0, 0, -1, 0, 0, 0, 0, 1, 1, 1, + -1, -1, -1, 0, 1, 1, 1, 1, 0, -2, -3, -1, 1, 0, 0, 0, + 1, -1, -3, -1, 1, 1, 0, -1, 3, 1, -1, 1, 2, 2, 0, -1, + 3, 1, 0, 1, 2, 1, 1, 0, 0, -2, -2, -1, -1, 0, 0, 0, + 1, 0, -1, -1, 1, 2, 1, 0, 0, -1, -2, -1, 1, 2, 2, 1, + -1, -1, -1, 0, 0, 1, 2, 0, -2, 0, 0, 0, 0, 0, 1, -1, + -1, 0, 1, 0, -1, -1, -1, -1, 0, 1, 1, 2, 0, -2, -1, 0, + 1, 2, 2, 2, 1, -1, -1, 0, 0, 1, 1, 1, 0, -2, -2, -1, + 0, 0, -1, -1, -1, -1, -2, -2, 0, 0, -1, 0, 1, 2, 2, 1, + 0, 0, -1, -1, 0, 1, 2, 2, 1, 1, -1, -2, -1, -1, -1, -1, + 2, 2, 1, 0, 0, -1, -2, -2, 1, 2, 2, 1, 0, 0, -2, -2, + 0, 0, 0, 0, 1, 1, 0, -1, 0, -1, -1, -1, 2, 3, 2, 1, + 0, -2, 1, 2, -1, 0, 0, 1, -1, -2, 2, 3, -1, 0, 0, 0, + 0, -2, 2, 3, -1, -1, 0, 0, 0, -1, 3, 2, -2, 0, 1, 0, + 0, -1, 3, 1, -2, 0, 1, 0, 0, -1, 2, 1, -1, 1, 0, -1, + 0, 0, 1, -1, -2, 0, 0, -1, 1, 0, 0, -2, -2, -1, -1, -1, + 1, 1, 1, 1, 1, -1, -1, -2, 0, 0, 0, 1, 1, 1, 1, 1, + 0, 0, 0, 1, 1, 1, 2, 3, 1, 0, 0, -1, 0, 0, 1, 2, + 0, -1, -1, -2, -1, 0, 1, 2, -2, -2, -2, -2, -1, 0, 1, 1, + -1, -1, -1, -1, 0, 0, 0, -1, 2, 2, 2, 0, -1, -1, -2, -4, + -1, -2, -1, -1, 0, 1, 2, 3, -1, -1, -1, -1, 0, 1, 2, 3, + 1, 0, -1, 0, -1, 0, 1, 2, 1, 0, 0, 0, -1, 0, 2, 2, + 1, 0, -1, -1, -2, 0, 1, 2, 0, -2, -2, -2, -3, -1, 0, 1, + 0, -2, -2, -2, -2, -1, 1, 1, 0, 0, 0, 0, 0, 1, 2, 2 +}; + +/* list of codebooks for intra-coded vectors */ +static uint8_t *svq1_intra_codebooks[4] = { + svq1_intra_codebook_4x2, svq1_intra_codebook_4x4, + svq1_intra_codebook_8x4, svq1_intra_codebook_8x8 +}; + +/* block type, codes 000 .. 1xx */ +static vlc_code_t svq1_block_type_table[8] = { + { SVQ1_BLOCK_INTRA, 3 }, { SVQ1_BLOCK_INTER_4V, 3 }, + { SVQ1_BLOCK_INTER, 2 }, { SVQ1_BLOCK_INTER, 2 }, + { SVQ1_BLOCK_SKIP, 1 }, { SVQ1_BLOCK_SKIP, 1 }, + { SVQ1_BLOCK_SKIP, 1 }, { SVQ1_BLOCK_SKIP, 1 } +}; + +/* motion vector, codes 0000011 .. 011xxxx */ +static vlc_code_t svq1_motion_table_0[61] = { + { 7, 8 }, { 6, 8 }, { 5, 8 }, { 4, 7 }, { 4, 7 }, + { 3, 5 }, { 3, 5 }, { 3, 5 }, { 3, 5 }, { 3, 5 }, { 3, 5 }, { 3, 5 }, { 3, 5 }, + { 2, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, + { 2, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, + { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, + { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, + { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, + { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 } +}; + +/* motion vector, codes 000000000010 ... 0000010111xx */ +static vlc_code_t svq1_motion_table_1[94] = { + {32, 13}, {31, 13}, {30, 12}, {30, 12}, {29, 12}, {29, 12}, + {28, 12}, {28, 12}, {27, 12}, {27, 12}, {26, 12}, {26, 12}, {25, 12}, {25, 12}, + {24, 11}, {24, 11}, {24, 11}, {24, 11}, {23, 11}, {23, 11}, {23, 11}, {23, 11}, + {22, 11}, {22, 11}, {22, 11}, {22, 11}, {21, 11}, {21, 11}, {21, 11}, {21, 11}, + {20, 11}, {20, 11}, {20, 11}, {20, 11}, {19, 11}, {19, 11}, {19, 11}, {19, 11}, + {18, 11}, {18, 11}, {18, 11}, {18, 11}, {17, 11}, {17, 11}, {17, 11}, {17, 11}, + {16, 11}, {16, 11}, {16, 11}, {16, 11}, {15, 11}, {15, 11}, {15, 11}, {15, 11}, + {14, 11}, {14, 11}, {14, 11}, {14, 11}, {13, 11}, {13, 11}, {13, 11}, {13, 11}, + {12, 11}, {12, 11}, {12, 11}, {12, 11}, {11, 11}, {11, 11}, {11, 11}, {11, 11}, + {10, 10}, {10, 10}, {10, 10}, {10, 10}, {10, 10}, {10, 10}, {10, 10}, {10, 10}, + { 9, 10}, { 9, 10}, { 9, 10}, { 9, 10}, { 9, 10}, { 9, 10}, { 9, 10}, { 9, 10}, + { 8, 10}, { 8, 10}, { 8, 10}, { 8, 10}, { 8, 10}, { 8, 10}, { 8, 10}, { 8, 10}, +}; + +/* inter-coded vector codebook count tables, codes 000000 ... 111111 */ +static vlc_code_t svq1_inter_vector_tables[6][64] = { + /* 4x2 vector, codes 0000xxx ... 11xxxxx */ + { { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, { 5, 4 }, { 5, 4 }, { 5, 4 }, { 5, 4 }, + { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, + { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, + { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, + { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, + { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, + {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, + {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 } }, + + /* 4x4 vector, codes 0000xxx ... 11xxxxx */ + { { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, { 5, 4 }, { 5, 4 }, { 5, 4 }, { 5, 4 }, + { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, + { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, + { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, + { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, + { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, + {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, + {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 }, {-1, 2 } }, + + /* 8x4 vector, codes 00000xx ... 1xxxxxx */ + { { 6, 5 }, { 6, 5 }, { 5, 5 }, { 5, 5 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, + { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, + { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, + { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, + {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, + {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, + {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, + {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 } }, + + /* 8x8 vector, codes 00000xx ... 1xxxxxx */ + { { 6, 5 }, { 6, 5 }, { 5, 5 }, { 5, 5 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, + { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, + { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, + { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, + {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, + {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, + {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, + {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 } }, + + /* 16x8 vector, codes 00000xx ... 1xxxxxx */ + { { 6, 5 }, { 6, 5 }, { 5, 5 }, { 5, 5 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, + { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, { 2, 4 }, + { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, + { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, { 0, 3 }, + {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, + {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, + {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, + {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 } }, + + /* 16x16 vector, codes 000000x ... 1xxxxxx */ + { { 6, 6 }, { 5, 6 }, { 4, 5 }, { 4, 5 }, { 3, 5 }, { 3, 5 }, { 2, 5 }, { 2, 5 }, + { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, + { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, + { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, + {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, + {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, + {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, + {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 }, {-1, 1 } } +}; + +/* vector codebook count tables, codes 0000000 ... 1111111 */ +static vlc_code_t svq1_intra_vector_tables[6][128] = { + /* 4x2 vector, codes 00000xx ... 1xxxxxx */ + { { 5, 5 }, { 5, 5 }, { 5, 5 }, { 5, 5 }, {-1, 5 }, {-1, 5 }, {-1, 5 }, {-1, 5 }, + { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, + { 4, 4 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, + { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, + { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, + { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, + { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, + { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 } }, + + /* 4x4 vector, codes 0000xxx ... 11xxxxx */ + { { 5, 4 }, { 5, 4 }, { 5, 4 }, { 5, 4 }, { 5, 4 }, { 5, 4 }, { 5, 4 }, { 5, 4 }, + {-1, 4 }, {-1, 4 }, {-1, 4 }, {-1, 4 }, {-1, 4 }, {-1, 4 }, {-1, 4 }, {-1, 4 }, + { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, + { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, + { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, + { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, + { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, + { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, { 3, 3 }, + { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, + { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, + { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, + { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, + { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, + { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, + { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, + { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 }, { 0, 2 } }, + + /* 8x4 vector, codes 00000xx ... 1xxxxxx */ + { { 2, 5 }, { 2, 5 }, { 2, 5 }, { 2, 5 }, {-1, 5 }, {-1, 5 }, {-1, 5 }, {-1, 5 }, + { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, + { 5, 4 }, { 5, 4 }, { 5, 4 }, { 5, 4 }, { 5, 4 }, { 5, 4 }, { 5, 4 }, { 5, 4 }, + { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, + { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, + { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, { 4, 3 }, + { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, + { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 } }, + + /* 8x8 vector, codes 000000x ... 1xxxxxx */ + { { 2, 6 }, { 2, 6 }, {-1, 6 }, {-1, 6 }, { 5, 5 }, { 5, 5 }, { 5, 5 }, { 5, 5 }, + { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, { 6, 4 }, + { 4, 4 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, { 4, 4 }, + { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, + { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, + { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, + { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, + { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 } }, + + /* 16x8 vector, codes 000000x ... 1xxxxxx */ + { { 4, 6 }, { 4, 6 }, {-1, 6 }, {-1, 6 }, { 5, 5 }, { 5, 5 }, { 5, 5 }, { 5, 5 }, + { 3, 5 }, { 3, 5 }, { 3, 5 }, { 3, 5 }, { 2, 5 }, { 2, 5 }, { 2, 5 }, { 2, 5 }, + { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, + { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, { 6, 3 }, + { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, + { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, + { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, + { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 } }, + + /* 16x16 vector, codes 0000000 ... 1xxxxxx */ + { { 5, 7 }, {-1, 7 }, { 4, 6 }, { 4, 6 }, { 6, 5 }, { 6, 5 }, { 6, 5 }, { 6, 5 }, + { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, { 3, 4 }, + { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, + { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, { 2, 3 }, + { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, + { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, + { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, + { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, { 1, 2 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 } } +}; + +/* intra mean value, codes 00100101 ... 1111xxxx */ +static vlc_code_t svq1_intra_mean_table_0[219] = { + {135, 8 }, {136, 8 }, {165, 8 }, + {134, 8 }, {129, 8 }, {164, 8 }, {163, 8 }, {133, 8 }, {162, 8 }, {174, 8 }, {175, 8 }, + {161, 8 }, {160, 8 }, {159, 8 }, {158, 8 }, {157, 8 }, {156, 8 }, {155, 8 }, {154, 8 }, + {153, 8 }, {151, 8 }, {152, 8 }, {132, 8 }, {110, 8 }, {131, 8 }, {108, 8 }, {130, 8 }, + {166, 8 }, {105, 8 }, {104, 8 }, {103, 8 }, {127, 8 }, {101, 8 }, {167, 8 }, {168, 8 }, + { 98, 8 }, {128, 8 }, { 48, 8 }, { 95, 8 }, { 62, 8 }, { 93, 8 }, { 92, 8 }, { 91, 8 }, + { 90, 8 }, { 89, 8 }, { 60, 8 }, { 87, 8 }, { 86, 8 }, { 57, 8 }, { 84, 8 }, { 83, 8 }, + { 82, 8 }, { 81, 8 }, { 80, 8 }, { 79, 8 }, { 78, 8 }, { 77, 8 }, { 76, 8 }, { 75, 8 }, + { 74, 8 }, { 73, 8 }, { 72, 8 }, { 71, 8 }, { 70, 8 }, { 69, 8 }, { 68, 8 }, { 67, 8 }, + { 66, 8 }, { 65, 8 }, { 56, 8 }, { 63, 8 }, { 23, 8 }, { 61, 8 }, { 30, 8 }, { 59, 8 }, + { 58, 8 }, { 52, 8 }, { 29, 8 }, { 55, 8 }, { 54, 8 }, { 53, 8 }, { 50, 8 }, { 51, 8 }, + { 22, 8 }, { 49, 8 }, { 85, 7 }, { 85, 7 }, { 97, 7 }, { 97, 7 }, { 88, 7 }, { 88, 7 }, + { 64, 7 }, { 64, 7 }, { 94, 7 }, { 94, 7 }, {106, 7 }, {106, 7 }, {107, 7 }, {107, 7 }, + {109, 7 }, {109, 7 }, {111, 7 }, {111, 7 }, {112, 7 }, {112, 7 }, {113, 7 }, {113, 7 }, + {114, 7 }, {114, 7 }, {115, 7 }, {115, 7 }, {116, 7 }, {116, 7 }, {117, 7 }, {117, 7 }, + {118, 7 }, {118, 7 }, {119, 7 }, {119, 7 }, {120, 7 }, {120, 7 }, { 99, 7 }, { 99, 7 }, + {102, 7 }, {102, 7 }, { 28, 7 }, { 28, 7 }, {100, 7 }, {100, 7 }, { 96, 7 }, { 96, 7 }, + {139, 7 }, {139, 7 }, { 24, 7 }, { 24, 7 }, { 1, 7 }, { 1, 7 }, {138, 7 }, {138, 7 }, + {121, 7 }, {121, 7 }, {122, 7 }, {122, 7 }, {123, 7 }, {123, 7 }, {124, 7 }, {124, 7 }, + {125, 7 }, {125, 7 }, {126, 7 }, {126, 7 }, {137, 7 }, {137, 7 }, {140, 7 }, {140, 7 }, + {150, 7 }, {150, 7 }, {144, 7 }, {144, 7 }, {141, 7 }, {141, 7 }, {142, 7 }, {142, 7 }, + {143, 7 }, {143, 7 }, {145, 7 }, {145, 7 }, {147, 7 }, {147, 7 }, {146, 7 }, {146, 7 }, + { 27, 6 }, { 27, 6 }, { 27, 6 }, { 27, 6 }, {148, 6 }, {148, 6 }, {148, 6 }, {148, 6 }, + {149, 6 }, {149, 6 }, {149, 6 }, {149, 6 }, { 0, 6 }, { 0, 6 }, { 0, 6 }, { 0, 6 }, + { 26, 4 }, { 26, 4 }, { 26, 4 }, { 26, 4 }, { 26, 4 }, { 26, 4 }, { 26, 4 }, { 26, 4 }, + { 26, 4 }, { 26, 4 }, { 26, 4 }, { 26, 4 }, { 26, 4 }, { 26, 4 }, { 26, 4 }, { 26, 4 }, + { 25, 4 }, { 25, 4 }, { 25, 4 }, { 25, 4 }, { 25, 4 }, { 25, 4 }, { 25, 4 }, { 25, 4 }, + { 25, 4 }, { 25, 4 }, { 25, 4 }, { 25, 4 }, { 25, 4 }, { 25, 4 }, { 25, 4 }, { 25, 4 } +}; + +/* intra mean value, codes 0000001101 ... 001001001x */ +static vlc_code_t svq1_intra_mean_table_1[135] = { + {218, 10}, {219, 10}, {220, 10}, + {221, 10}, {222, 10}, {217, 10}, {230, 10}, {215, 10}, {208, 10}, {207, 10}, {206, 10}, + {214, 10}, {204, 10}, {223, 10}, {224, 10}, {225, 10}, {226, 10}, {227, 10}, {228, 10}, + {229, 10}, {213, 10}, {212, 10}, {231, 10}, {232, 10}, {211, 10}, {210, 10}, {236, 10}, + {209, 10}, {216, 10}, {205, 10}, { 18, 10}, {186, 9 }, {186, 9 }, {185, 9 }, {185, 9 }, + {184, 9 }, {184, 9 }, {182, 9 }, {182, 9 }, {183, 9 }, {183, 9 }, {180, 9 }, {180, 9 }, + {181, 9 }, {181, 9 }, {178, 9 }, {178, 9 }, {187, 9 }, {187, 9 }, {176, 9 }, {176, 9 }, + {188, 9 }, {188, 9 }, {179, 9 }, {179, 9 }, {173, 9 }, {173, 9 }, {172, 9 }, {172, 9 }, + {171, 9 }, {171, 9 }, {170, 9 }, {170, 9 }, {169, 9 }, {169, 9 }, {189, 9 }, {189, 9 }, + {190, 9 }, {190, 9 }, {191, 9 }, {191, 9 }, {192, 9 }, {192, 9 }, {193, 9 }, {193, 9 }, + {194, 9 }, {194, 9 }, {195, 9 }, {195, 9 }, {196, 9 }, {196, 9 }, {197, 9 }, {197, 9 }, + {198, 9 }, {198, 9 }, {200, 9 }, {200, 9 }, {201, 9 }, {201, 9 }, {202, 9 }, {202, 9 }, + {203, 9 }, {203, 9 }, {199, 9 }, {199, 9 }, {177, 9 }, {177, 9 }, { 40, 9 }, { 40, 9 }, + { 39, 9 }, { 39, 9 }, { 38, 9 }, { 38, 9 }, { 37, 9 }, { 37, 9 }, { 36, 9 }, { 36, 9 }, + { 35, 9 }, { 35, 9 }, { 34, 9 }, { 34, 9 }, { 33, 9 }, { 33, 9 }, { 32, 9 }, { 32, 9 }, + { 31, 9 }, { 31, 9 }, { 21, 9 }, { 21, 9 }, { 11, 9 }, { 11, 9 }, { 41, 9 }, { 41, 9 }, + { 45, 9 }, { 45, 9 }, { 44, 9 }, { 44, 9 }, { 42, 9 }, { 42, 9 }, { 43, 9 }, { 43, 9 }, + { 47, 9 }, { 47, 9 }, { 46, 9 }, { 46, 9 } +}; + +/* intra mean value, codes 00000000000001 ... 00000011001xxx */ +static vlc_code_t svq1_intra_mean_table_2[207] = { + {255, 14}, { 14, 14}, { 13, 14}, { 17, 12}, { 17, 12}, { 17, 12}, { 17, 12}, + {243, 11}, {243, 11}, {243, 11}, {243, 11}, {243, 11}, {243, 11}, {243, 11}, {243, 11}, + {242, 11}, {242, 11}, {242, 11}, {242, 11}, {242, 11}, {242, 11}, {242, 11}, {242, 11}, + {241, 11}, {241, 11}, {241, 11}, {241, 11}, {241, 11}, {241, 11}, {241, 11}, {241, 11}, + {240, 11}, {240, 11}, {240, 11}, {240, 11}, {240, 11}, {240, 11}, {240, 11}, {240, 11}, + {237, 11}, {237, 11}, {237, 11}, {237, 11}, {237, 11}, {237, 11}, {237, 11}, {237, 11}, + {239, 11}, {239, 11}, {239, 11}, {239, 11}, {239, 11}, {239, 11}, {239, 11}, {239, 11}, + {235, 11}, {235, 11}, {235, 11}, {235, 11}, {235, 11}, {235, 11}, {235, 11}, {235, 11}, + {234, 11}, {234, 11}, {234, 11}, {234, 11}, {234, 11}, {234, 11}, {234, 11}, {234, 11}, + {233, 11}, {233, 11}, {233, 11}, {233, 11}, {233, 11}, {233, 11}, {233, 11}, {233, 11}, + {244, 11}, {244, 11}, {244, 11}, {244, 11}, {244, 11}, {244, 11}, {244, 11}, {244, 11}, + {238, 11}, {238, 11}, {238, 11}, {238, 11}, {238, 11}, {238, 11}, {238, 11}, {238, 11}, + { 20, 11}, { 20, 11}, { 20, 11}, { 20, 11}, { 20, 11}, { 20, 11}, { 20, 11}, { 20, 11}, + {248, 11}, {248, 11}, {248, 11}, {248, 11}, {248, 11}, {248, 11}, {248, 11}, {248, 11}, + {249, 11}, {249, 11}, {249, 11}, {249, 11}, {249, 11}, {249, 11}, {249, 11}, {249, 11}, + {250, 11}, {250, 11}, {250, 11}, {250, 11}, {250, 11}, {250, 11}, {250, 11}, {250, 11}, + {251, 11}, {251, 11}, {251, 11}, {251, 11}, {251, 11}, {251, 11}, {251, 11}, {251, 11}, + {252, 11}, {252, 11}, {252, 11}, {252, 11}, {252, 11}, {252, 11}, {252, 11}, {252, 11}, + {253, 11}, {253, 11}, {253, 11}, {253, 11}, {253, 11}, {253, 11}, {253, 11}, {253, 11}, + {254, 11}, {254, 11}, {254, 11}, {254, 11}, {254, 11}, {254, 11}, {254, 11}, {254, 11}, + { 12, 11}, { 12, 11}, { 12, 11}, { 12, 11}, { 12, 11}, { 12, 11}, { 12, 11}, { 12, 11}, + { 10, 11}, { 10, 11}, { 10, 11}, { 10, 11}, { 10, 11}, { 10, 11}, { 10, 11}, { 10, 11}, + {245, 11}, {245, 11}, {245, 11}, {245, 11}, {245, 11}, {245, 11}, {245, 11}, {245, 11}, + {247, 11}, {247, 11}, {247, 11}, {247, 11}, {247, 11}, {247, 11}, {247, 11}, {247, 11}, + { 19, 11}, { 19, 11}, { 19, 11}, { 19, 11}, { 19, 11}, { 19, 11}, { 19, 11}, { 19, 11}, + {246, 11}, {246, 11}, {246, 11}, {246, 11}, {246, 11}, {246, 11}, {246, 11}, {246, 11} +}; + +/* intra mean value, codes 00000000000000000000 ... 000000000000001xxxxx */ +static vlc_code_t svq1_intra_mean_table_3[64] = { + { 6, 20}, { 3, 20}, { 4, 20}, { 5, 20}, { 7, 20}, { 8, 20}, { 9, 19}, { 9, 19}, + { 2, 17}, { 2, 17}, { 2, 17}, { 2, 17}, { 2, 17}, { 2, 17}, { 2, 17}, { 2, 17}, + { 16, 16}, { 16, 16}, { 16, 16}, { 16, 16}, { 16, 16}, { 16, 16}, { 16, 16}, { 16, 16}, + { 16, 16}, { 16, 16}, { 16, 16}, { 16, 16}, { 16, 16}, { 16, 16}, { 16, 16}, { 16, 16}, + { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, + { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, + { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, + { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15}, { 15, 15} +}; + +/* inter mean value, codes 00001011 ... 1xxxxxxx */ +static vlc_code_t svq1_inter_mean_table_0[245] = { + { 10, 8 }, { 12, 8 }, { 11, 8 }, {-11, 8 }, {-12, 8 }, + {-10, 8 }, { -9, 8 }, { -7, 7 }, { -7, 7 }, { -6, 7 }, { -6, 7 }, { 8, 7 }, { 8, 7 }, + { -8, 7 }, { -8, 7 }, { 9, 7 }, { 9, 7 }, { 6, 7 }, { 6, 7 }, { 7, 7 }, { 7, 7 }, + { -5, 6 }, { -5, 6 }, { -5, 6 }, { -5, 6 }, { -4, 6 }, { -4, 6 }, { -4, 6 }, { -4, 6 }, + { 5, 6 }, { 5, 6 }, { 5, 6 }, { 5, 6 }, { 4, 6 }, { 4, 6 }, { 4, 6 }, { 4, 6 }, + { 3, 5 }, { 3, 5 }, { 3, 5 }, { 3, 5 }, { 3, 5 }, { 3, 5 }, { 3, 5 }, { 3, 5 }, + { 2, 5 }, { 2, 5 }, { 2, 5 }, { 2, 5 }, { 2, 5 }, { 2, 5 }, { 2, 5 }, { 2, 5 }, + { -2, 5 }, { -2, 5 }, { -2, 5 }, { -2, 5 }, { -2, 5 }, { -2, 5 }, { -2, 5 }, { -2, 5 }, + { -3, 5 }, { -3, 5 }, { -3, 5 }, { -3, 5 }, { -3, 5 }, { -3, 5 }, { -3, 5 }, { -3, 5 }, + { -1, 4 }, { -1, 4 }, { -1, 4 }, { -1, 4 }, { -1, 4 }, { -1, 4 }, { -1, 4 }, { -1, 4 }, + { -1, 4 }, { -1, 4 }, { -1, 4 }, { -1, 4 }, { -1, 4 }, { -1, 4 }, { -1, 4 }, { -1, 4 }, + { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, + { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, + { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, + { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, { 1, 3 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, + { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 }, { 0, 1 } +}; + +/* inter mean value, codes 000000010010 ... 00001011xxxx */ +static vlc_code_t svq1_inter_mean_table_1[158] = { + {-30, 12}, {-31, 12}, {-32, 12}, {-33, 12}, { 31, 12}, {-34, 12}, + {-35, 12}, { 29, 12}, { 30, 12}, { 33, 12}, { 34, 12}, { 32, 12}, {-29, 11}, {-29, 11}, + {-28, 11}, {-28, 11}, { 28, 11}, { 28, 11}, {-27, 11}, {-27, 11}, {-26, 11}, {-26, 11}, + { 27, 11}, { 27, 11}, { 26, 11}, { 26, 11}, { 25, 11}, { 25, 11}, { 24, 11}, { 24, 11}, + { 23, 11}, { 23, 11}, { 22, 11}, { 22, 11}, {-24, 11}, {-24, 11}, {-25, 11}, {-25, 11}, + {-23, 10}, {-23, 10}, {-23, 10}, {-23, 10}, {-21, 10}, {-21, 10}, {-21, 10}, {-21, 10}, + {-20, 10}, {-20, 10}, {-20, 10}, {-20, 10}, {-19, 10}, {-19, 10}, {-19, 10}, {-19, 10}, + {-18, 10}, {-18, 10}, {-18, 10}, {-18, 10}, {-22, 10}, {-22, 10}, {-22, 10}, {-22, 10}, + { 19, 10}, { 19, 10}, { 19, 10}, { 19, 10}, { 21, 10}, { 21, 10}, { 21, 10}, { 21, 10}, + { 20, 10}, { 20, 10}, { 20, 10}, { 20, 10}, { 18, 10}, { 18, 10}, { 18, 10}, { 18, 10}, + {-14, 9 }, {-14, 9 }, {-14, 9 }, {-14, 9 }, {-14, 9 }, {-14, 9 }, {-14, 9 }, {-14, 9 }, + {-17, 9 }, {-17, 9 }, {-17, 9 }, {-17, 9 }, {-17, 9 }, {-17, 9 }, {-17, 9 }, {-17, 9 }, + { 16, 9 }, { 16, 9 }, { 16, 9 }, { 16, 9 }, { 16, 9 }, { 16, 9 }, { 16, 9 }, { 16, 9 }, + { 13, 9 }, { 13, 9 }, { 13, 9 }, { 13, 9 }, { 13, 9 }, { 13, 9 }, { 13, 9 }, { 13, 9 }, + { 14, 9 }, { 14, 9 }, { 14, 9 }, { 14, 9 }, { 14, 9 }, { 14, 9 }, { 14, 9 }, { 14, 9 }, + { 15, 9 }, { 15, 9 }, { 15, 9 }, { 15, 9 }, { 15, 9 }, { 15, 9 }, { 15, 9 }, { 15, 9 }, + { 17, 9 }, { 17, 9 }, { 17, 9 }, { 17, 9 }, { 17, 9 }, { 17, 9 }, { 17, 9 }, { 17, 9 }, + {-13, 9 }, {-13, 9 }, {-13, 9 }, {-13, 9 }, {-13, 9 }, {-13, 9 }, {-13, 9 }, {-13, 9 }, + {-16, 9 }, {-16, 9 }, {-16, 9 }, {-16, 9 }, {-16, 9 }, {-16, 9 }, {-16, 9 }, {-16, 9 }, + {-15, 9 }, {-15, 9 }, {-15, 9 }, {-15, 9 }, {-15, 9 }, {-15, 9 }, {-15, 9 }, {-15, 9 } +}; + +/* inter mean value, codes 000000000010111 ... 0000000100011xx */ +static vlc_code_t svq1_inter_mean_table_2[121] = { + { 61, 15}, + { 52, 15}, { 58, 15}, {-56, 15}, {-57, 15}, { 59, 15}, {-55, 15}, { 60, 15}, {-54, 15}, + { 53, 15}, {-62, 15}, {-60, 15}, {-59, 15}, {-58, 15}, { 57, 15}, { 56, 15}, {-53, 15}, + { 55, 15}, { 54, 15}, { 50, 14}, { 50, 14}, { 45, 14}, { 45, 14}, {-52, 14}, {-52, 14}, + {-51, 14}, {-51, 14}, {-50, 14}, {-50, 14}, { 46, 14}, { 46, 14}, {-49, 14}, {-49, 14}, + {-48, 14}, {-48, 14}, { 48, 14}, { 48, 14}, {-47, 14}, {-47, 14}, { 49, 14}, { 49, 14}, + {-45, 14}, {-45, 14}, {-44, 14}, {-44, 14}, { 47, 14}, { 47, 14}, { 51, 14}, { 51, 14}, + { 44, 14}, { 44, 14}, {-46, 14}, {-46, 14}, {-43, 13}, {-43, 13}, {-43, 13}, {-43, 13}, + {-42, 13}, {-42, 13}, {-42, 13}, {-42, 13}, {-41, 13}, {-41, 13}, {-41, 13}, {-41, 13}, + {-40, 13}, {-40, 13}, {-40, 13}, {-40, 13}, {-39, 13}, {-39, 13}, {-39, 13}, {-39, 13}, + {-38, 13}, {-38, 13}, {-38, 13}, {-38, 13}, {-37, 13}, {-37, 13}, {-37, 13}, {-37, 13}, + {-36, 13}, {-36, 13}, {-36, 13}, {-36, 13}, { 42, 13}, { 42, 13}, { 42, 13}, { 42, 13}, + { 36, 13}, { 36, 13}, { 36, 13}, { 36, 13}, { 43, 13}, { 43, 13}, { 43, 13}, { 43, 13}, + { 41, 13}, { 41, 13}, { 41, 13}, { 41, 13}, { 40, 13}, { 40, 13}, { 40, 13}, { 40, 13}, + { 35, 13}, { 35, 13}, { 35, 13}, { 35, 13}, { 39, 13}, { 39, 13}, { 39, 13}, { 39, 13}, + { 38, 13}, { 38, 13}, { 38, 13}, { 38, 13}, { 37, 13}, { 37, 13}, { 37, 13}, { 37, 13} +}; + +/* inter mean value, codes 000000000000100101 ... 0000000000101101xx */ +static vlc_code_t svq1_inter_mean_table_3[147] = { + {111, 18}, {102, 18}, { 99, 18}, + {-86, 18}, { 97, 18}, {-97, 18}, { 96, 18}, {-95, 18}, {-76, 18}, {-77, 18}, {-78, 18}, + {-85, 18}, {-80, 18}, {-81, 18}, { 89, 18}, { 90, 18}, {-84, 18}, {-89, 18}, { 80, 18}, + {-90, 18}, {-88, 18}, { 92, 18}, { 93, 18}, { 95, 18}, {-109,18}, {-79, 17}, {-79, 17}, + {-83, 17}, {-83, 17}, {-75, 17}, {-75, 17}, {-74, 17}, {-74, 17}, {-73, 17}, {-73, 17}, + {-72, 17}, {-72, 17}, { 87, 17}, { 87, 17}, { 86, 17}, { 86, 17}, { 75, 17}, { 75, 17}, + { 85, 17}, { 85, 17}, { 84, 17}, { 84, 17}, { 81, 17}, { 81, 17}, { 79, 17}, { 79, 17}, + { 74, 17}, { 74, 17}, { 72, 17}, { 72, 17}, { 82, 17}, { 82, 17}, { 78, 17}, { 78, 17}, + { 83, 17}, { 83, 17}, { 76, 17}, { 76, 17}, { 73, 17}, { 73, 17}, { 77, 17}, { 77, 17}, + { 70, 16}, { 70, 16}, { 70, 16}, { 70, 16}, { 69, 16}, { 69, 16}, { 69, 16}, { 69, 16}, + { 64, 16}, { 64, 16}, { 64, 16}, { 64, 16}, {-68, 16}, {-68, 16}, {-68, 16}, {-68, 16}, + {-66, 16}, {-66, 16}, {-66, 16}, {-66, 16}, { 68, 16}, { 68, 16}, { 68, 16}, { 68, 16}, + {-69, 16}, {-69, 16}, {-69, 16}, {-69, 16}, { 65, 16}, { 65, 16}, { 65, 16}, { 65, 16}, + { 71, 16}, { 71, 16}, { 71, 16}, { 71, 16}, {-70, 16}, {-70, 16}, {-70, 16}, {-70, 16}, + {-65, 16}, {-65, 16}, {-65, 16}, {-65, 16}, {-67, 16}, {-67, 16}, {-67, 16}, {-67, 16}, + {-63, 16}, {-63, 16}, {-63, 16}, {-63, 16}, {-71, 16}, {-71, 16}, {-71, 16}, {-71, 16}, + { 67, 16}, { 67, 16}, { 67, 16}, { 67, 16}, {-61, 16}, {-61, 16}, {-61, 16}, {-61, 16}, + {-64, 16}, {-64, 16}, {-64, 16}, {-64, 16}, { 63, 16}, { 63, 16}, { 63, 16}, { 63, 16}, + { 62, 16}, { 62, 16}, { 62, 16}, { 62, 16}, { 66, 16}, { 66, 16}, { 66, 16}, { 66, 16} +}; + +/* inter mean value, codes 00000000000001001001 ... 0000000000001001001x */ +static vlc_code_t svq1_inter_mean_table_4[75] = { + {142, 20}, {135, 20}, {125, 20}, {123, 20}, {122, 20}, {119, 20}, {117, 20}, + {113, 20}, {104, 20}, {103, 20}, {-120,20}, {-114,20}, {-108,20}, {-104,20}, {-102,20}, + {-101,20}, {-93, 20}, {-91, 19}, {-91, 19}, {-96, 19}, {-96, 19}, { 88, 19}, { 88, 19}, + { 91, 19}, { 91, 19}, { 94, 19}, { 94, 19}, {121, 19}, {121, 19}, {120, 19}, {120, 19}, + {-110,19}, {-110,19}, {118, 19}, {118, 19}, {115, 19}, {115, 19}, {114, 19}, {114, 19}, + {112, 19}, {112, 19}, {107, 19}, {107, 19}, {110, 19}, {110, 19}, {109, 19}, {109, 19}, + {108, 19}, {108, 19}, {-103,19}, {-103,19}, {106, 19}, {106, 19}, {105, 19}, {105, 19}, + {-100,19}, {-100,19}, {101, 19}, {101, 19}, {100, 19}, {100, 19}, {-99, 19}, {-99, 19}, + {-82, 19}, {-82, 19}, {-87, 19}, {-87, 19}, {-94, 19}, {-94, 19}, {-98, 19}, {-98, 19}, + { 98, 19}, { 98, 19}, {-92, 19}, {-92, 19} +}; + +/* inter mean value, codes 0000000000000000000000 ... 000000000000010010001x */ +static vlc_code_t svq1_inter_mean_table_5[292] = { + {255, 22}, {254, 22}, {253, 22}, {252, 22}, {251, 22}, {250, 22}, {249, 22}, {248, 22}, + {247, 22}, {246, 22}, {245, 22}, {244, 22}, {243, 22}, {242, 22}, {241, 22}, {240, 22}, + {239, 22}, {238, 22}, {237, 22}, {236, 22}, {235, 22}, {234, 22}, {233, 22}, {232, 22}, + {231, 22}, {230, 22}, {229, 22}, {228, 22}, {227, 22}, {226, 22}, {225, 22}, {224, 22}, + {223, 22}, {222, 22}, {221, 22}, {220, 22}, {219, 22}, {218, 22}, {217, 22}, {216, 22}, + {215, 22}, {214, 22}, {213, 22}, {212, 22}, {211, 22}, {210, 22}, {209, 22}, {208, 22}, + {207, 22}, {206, 22}, {205, 22}, {204, 22}, {203, 22}, {202, 22}, {201, 22}, {200, 22}, + {199, 22}, {198, 22}, {197, 22}, {196, 22}, {195, 22}, {194, 22}, {193, 22}, {192, 22}, + {191, 22}, {190, 22}, {189, 22}, {188, 22}, {187, 22}, {186, 22}, {185, 22}, {184, 22}, + {183, 22}, {182, 22}, {181, 22}, {180, 22}, {179, 22}, {178, 22}, {177, 22}, {176, 22}, + {175, 22}, {174, 22}, {173, 22}, {172, 22}, {171, 22}, {170, 22}, {169, 22}, {168, 22}, + {167, 22}, {166, 22}, {-256,22}, {164, 22}, {-211,22}, {162, 22}, {161, 22}, {160, 22}, + {-210,22}, {-168,22}, {157, 22}, {156, 22}, {155, 22}, {154, 22}, {153, 22}, {152, 22}, + {151, 22}, {150, 22}, {149, 22}, {148, 22}, {147, 22}, {146, 22}, {145, 22}, {144, 22}, + {143, 22}, {-208,22}, {141, 22}, {140, 22}, {139, 22}, {-200,22}, {137, 22}, {136, 22}, + {-198,22}, {134, 22}, {133, 22}, {-196,22}, {-201,22}, {130, 22}, {129, 22}, {128, 22}, + {127, 22}, {126, 22}, {-195,22}, {124, 22}, {-167,22}, {-166,22}, {-165,22}, {-164,22}, + {-163,22}, {-162,22}, {-161,22}, {-180,22}, {-160,22}, {-159,22}, {-158,22}, {-157,22}, + {-156,22}, {-155,22}, {-154,22}, {-153,22}, {-152,22}, {-151,22}, {-150,22}, {-149,22}, + {-148,22}, {-147,22}, {-146,22}, {-145,22}, {-144,22}, {-143,22}, {-142,22}, {-141,22}, + {-140,22}, {-139,22}, {-138,22}, {-137,22}, {-136,22}, {-135,22}, {-134,22}, {-133,22}, + {-132,22}, {-131,22}, {-130,22}, {-129,22}, {-126,22}, {-125,22}, {-124,22}, {-123,22}, + {-122,22}, {-121,22}, {-118,22}, {-116,22}, {-115,22}, {-113,22}, {-112,22}, {-107,22}, + {-106,22}, {-169,22}, {-170,22}, {-171,22}, {-172,22}, {-173,22}, {-174,22}, {-175,22}, + {-176,22}, {-177,22}, {-178,22}, {-187,22}, {-179,22}, {-181,22}, {-182,22}, {-183,22}, + {-184,22}, {-185,22}, {-186,22}, {-235,22}, {-188,22}, {-189,22}, {-190,22}, {-191,22}, + {-192,22}, {-193,22}, {-194,22}, {-197,22}, {-255,22}, {-254,22}, {-253,22}, {-252,22}, + {-251,22}, {-250,22}, {-249,22}, {-248,22}, {-247,22}, {-246,22}, {-245,22}, {-244,22}, + {-243,22}, {-242,22}, {-241,22}, {-240,22}, {-239,22}, {-238,22}, {-237,22}, {-232,22}, + {-236,22}, {-234,22}, {-233,22}, {-217,22}, {-231,22}, {-230,22}, {-229,22}, {-228,22}, + {-227,22}, {-226,22}, {-225,22}, {-224,22}, {-223,22}, {-222,22}, {-221,22}, {-220,22}, + {-219,22}, {-216,22}, {-202,22}, {-205,22}, {-215,22}, {-214,22}, {-213,22}, {-204,22}, + {-212,22}, {-209,22}, {-218,22}, {-199,22}, {-207,22}, {-206,22}, {165, 21}, {165, 21}, + {131, 21}, {131, 21}, {163, 21}, {163, 21}, {-203,21}, {-203,21}, {116, 21}, {116, 21}, + {159, 21}, {159, 21}, {138, 21}, {138, 21}, {158, 21}, {158, 21}, {-105,21}, {-105,21}, + {-111,21}, {-111,21}, {132, 21}, {132, 21}, {128, 21}, {128, 21}, {-127,21}, {-127,21}, + {-119,21}, {-119,21}, {-117,21}, {-117,21} +}; + +#define SVQ1_PROCESS_VECTOR()\ + for (; level > 0; i++) {\ + /* process next depth */\ + if (i == m) {\ + m = n;\ + if (--level == 0)\ + break;\ + }\ + /* divide block if next bit set */\ + if (get_bits (bitbuf, 1) == 0)\ + break;\ + /* add child nodes */\ + list[n++] = list[i];\ + list[n++] = list[i] + (((level & 1) ? pitch : 1) << ((level / 2) + 1));\ + } + +#define SVQ1_ADD_CODEBOOK()\ + /* add codebook entries to vector */\ + for (j=0; j < stages; j++) {\ + n3 = codebook[entries[j]] ^ 0x80808080;\ + n1 += ((n3 & 0xFF00FF00) >> 8);\ + n2 += (n3 & 0x00FF00FF);\ + }\ +\ + /* clip to [0..255] */\ + if (n1 & 0xFF00FF00) {\ + n3 = ((( n1 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\ + n1 += 0x7F007F00;\ + n1 |= (((~n1 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\ + n1 &= (n3 & 0x00FF00FF);\ + }\ +\ + if (n2 & 0xFF00FF00) {\ + n3 = ((( n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\ + n2 += 0x7F007F00;\ + n2 |= (((~n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;\ + n2 &= (n3 & 0x00FF00FF);\ + } + +#define SVQ1_DO_CODEBOOK_INTRA()\ + for (y=0; y < height; y++) {\ + for (x=0; x < (width / 4); x++, codebook++) {\ + n1 = n4;\ + n2 = n4;\ + SVQ1_ADD_CODEBOOK()\ + /* store result */\ + dst[x] = (n1 << 8) | n2;\ + }\ + dst += (pitch / 4);\ + } + +#define SVQ1_DO_CODEBOOK_NONINTRA()\ + for (y=0; y < height; y++) {\ + for (x=0; x < (width / 4); x++, codebook++) {\ + n3 = dst[x];\ + /* add mean value to vector */\ + n1 = ((n3 & 0xFF00FF00) >> 8) + n4;\ + n2 = (n3 & 0x00FF00FF) + n4;\ + SVQ1_ADD_CODEBOOK()\ + /* store result */\ + dst[x] = (n1 << 8) | n2;\ + }\ + dst += (pitch / 4);\ + } + +#define SVQ1_CALC_CODEBOOK_ENTRIES(cbook)\ + codebook = (uint32_t *) cbook[level];\ + bit_cache = get_bits (bitbuf, 4*stages);\ + /* calculate codebook entries for this vector */\ + for (j=0; j < stages; j++) {\ + entries[j] = (((bit_cache >> (4*(stages - j - 1))) & 0xF) + 16*j) << (level + 1);\ + }\ + mean -= (stages * 128);\ + n4 = ((mean + (mean >> 31)) << 16) | (mean & 0xFFFF); + +static int svq1_decode_block_intra (bit_buffer_t *bitbuf, uint8_t *pixels, int pitch ) { + uint32_t bit_cache; + vlc_code_t *vlc; + uint8_t *list[63]; + uint32_t *dst; + uint32_t *codebook; + int entries[6]; + int i, j, m, n; + int mean, stages; + int x, y, width, height, level; + uint32_t n1, n2, n3, n4; + + /* initialize list for breadth first processing of vectors */ + list[0] = pixels; + + /* recursively process vector */ + for (i=0, m=1, n=1, level=5; i < n; i++) { + SVQ1_PROCESS_VECTOR(); + + /* destination address and vector size */ + dst = (uint32_t *) list[i]; + width = 1 << ((4 + level) /2); + height = 1 << ((3 + level) /2); + + /* get number of stages (-1 skips vector, 0 for mean only) */ + bit_cache = get_bit_cache (bitbuf); + + vlc = &svq1_intra_vector_tables[level][bit_cache >> (32 - 7)]; + + /* flush bits */ + stages = vlc->value; + skip_bits(bitbuf,vlc->length); + + if (stages == -1) { + for (y=0; y < height; y++) { + memset (&dst[y*(pitch / 4)], 0, width); + } + continue; /* skip vector */ + } + + if ((stages > 0) && (level >= 4)) { +#ifdef DEBUG_SVQ1 + printf("Error (svq1_decode_block_intra): invalid vector: stages=%i level=%i\n",stages,level); +#endif + return -1; /* invalid vector */ + } + + /* get mean value for vector */ + bit_cache = get_bit_cache (bitbuf); + + if (bit_cache >= 0x25000000) + vlc = &svq1_intra_mean_table_0[(bit_cache >> (32 - 8)) - 37]; + else if (bit_cache >= 0x03400000) + vlc = &svq1_intra_mean_table_1[(bit_cache >> (32 - 10)) - 13]; + else if (bit_cache >= 0x00040000) + vlc = &svq1_intra_mean_table_2[(bit_cache >> (32 - 14)) - 1]; + else + vlc = &svq1_intra_mean_table_3[bit_cache >> (32 - 20)]; + + /* flush bits */ + mean = vlc->value; + skip_bits(bitbuf,vlc->length); + + if (stages == 0) { + for (y=0; y < height; y++) { + memset (&dst[y*(pitch / 4)], mean, width); + } + } else { + SVQ1_CALC_CODEBOOK_ENTRIES(svq1_intra_codebooks); + SVQ1_DO_CODEBOOK_INTRA() + } + } + + return 0; +} + +static int svq1_decode_block_non_intra (bit_buffer_t *bitbuf, uint8_t *pixels, int pitch ) { + uint32_t bit_cache; + vlc_code_t *vlc; + uint8_t *list[63]; + uint32_t *dst; + uint32_t *codebook; + int entries[6]; + int i, j, m, n; + int mean, stages; + int x, y, width, height, level; + uint32_t n1, n2, n3, n4; + + /* initialize list for breadth first processing of vectors */ + list[0] = pixels; + + /* recursively process vector */ + for (i=0, m=1, n=1, level=5; i < n; i++) { + SVQ1_PROCESS_VECTOR(); + + /* destination address and vector size */ + dst = (uint32_t *) list[i]; + width = 1 << ((4 + level) /2); + height = 1 << ((3 + level) /2); + + /* get number of stages (-1 skips vector, 0 for mean only) */ + bit_cache = get_bit_cache (bitbuf); + + vlc = &svq1_inter_vector_tables[level][bit_cache >> (32 - 6)]; + + /* flush bits */ + stages = vlc->value; + skip_bits(bitbuf,vlc->length); + + if (stages == -1) continue; /* skip vector */ + + if ((stages > 0) && (level >= 4)) { +#ifdef DEBUG_SVQ1 + printf("Error (svq1_decode_block_non_intra): invalid vector: stages=%i level=%i\n",stages,level); +#endif + return -1; /* invalid vector */ + } + + /* get mean value for vector */ + bit_cache = get_bit_cache (bitbuf); + + if (bit_cache >= 0x0B000000) + vlc = &svq1_inter_mean_table_0[(bit_cache >> (32 - 8)) - 11]; + else if (bit_cache >= 0x01200000) + vlc = &svq1_inter_mean_table_1[(bit_cache >> (32 - 12)) - 18]; + else if (bit_cache >= 0x002E0000) + vlc = &svq1_inter_mean_table_2[(bit_cache >> (32 - 15)) - 23]; + else if (bit_cache >= 0x00094000) + vlc = &svq1_inter_mean_table_3[(bit_cache >> (32 - 18)) - 37]; + else if (bit_cache >= 0x00049000) + vlc = &svq1_inter_mean_table_4[(bit_cache >> (32 - 20)) - 73]; + else + vlc = &svq1_inter_mean_table_5[bit_cache >> (32 - 22)]; + + /* flush bits */ + mean = vlc->value; + skip_bits(bitbuf,vlc->length); + + SVQ1_CALC_CODEBOOK_ENTRIES(svq1_inter_codebooks); + SVQ1_DO_CODEBOOK_NONINTRA() + } + return 0; +} + +static int svq1_decode_motion_vector (bit_buffer_t *bitbuf, svq1_pmv_t *mv, svq1_pmv_t **pmv) { + uint32_t bit_cache; + vlc_code_t *vlc; + int diff, sign; + int i; + + for (i=0; i < 2; i++) { + + /* get motion code */ + bit_cache = get_bit_cache (bitbuf); + + if (!(bit_cache & 0xFFE00000)) + return -1; /* invalid vlc code */ + + if (bit_cache & 0x80000000) { + diff = 0; + + /* flush bit */ + skip_bits(bitbuf,1); + + } else { + if (bit_cache >= 0x06000000) { + vlc = &svq1_motion_table_0[(bit_cache >> (32 - 7)) - 3]; + } else { + vlc = &svq1_motion_table_1[(bit_cache >> (32 - 12)) - 2]; + } + + /* decode motion vector differential */ + sign = (int) (bit_cache << (vlc->length - 1)) >> 31; + diff = (vlc->value ^ sign) - sign; + + /* flush bits */ + skip_bits(bitbuf,vlc->length); + } + + /* add median of motion vector predictors and clip result */ + if (i == 1) + mv->y = ((diff + MEDIAN(pmv[0]->y, pmv[1]->y, pmv[2]->y)) << 26) >> 26; + else + mv->x = ((diff + MEDIAN(pmv[0]->x, pmv[1]->x, pmv[2]->x)) << 26) >> 26; + } + + return 0; +} + +static void svq1_skip_block (uint8_t *current, uint8_t *previous, int pitch, int x, int y) { + uint8_t *src; + uint8_t *dst; + int i; + + src = &previous[x + y*pitch]; + dst = current; + + for (i=0; i < 16; i++) { + memcpy (dst, src, 16); + src += pitch; + dst += pitch; + } +} + +static int svq1_motion_inter_block (bit_buffer_t *bitbuf, + uint8_t *current, uint8_t *previous, int pitch, + svq1_pmv_t *motion, int x, int y) { + uint8_t *src; + uint8_t *dst; + svq1_pmv_t mv; + svq1_pmv_t *pmv[3]; + int result; + + /* predict and decode motion vector */ + pmv[0] = &motion[0]; + if (y == 0) { + pmv[1] = + pmv[2] = pmv[0]; + } + else { + pmv[1] = &motion[(x / 8) + 2]; + pmv[2] = &motion[(x / 8) + 4]; + } + + result = svq1_decode_motion_vector (bitbuf, &mv, pmv); + + if (result != 0) + return result; + + motion[0].x = + motion[(x / 8) + 2].x = + motion[(x / 8) + 3].x = mv.x; + motion[0].y = + motion[(x / 8) + 2].y = + motion[(x / 8) + 3].y = mv.y; + + src = &previous[(x + (mv.x >> 1)) + (y + (mv.y >> 1))*pitch]; + dst = current; + + put_pixels_tab[((mv.y & 1) << 1) | (mv.x & 1)](dst,src,pitch,16); + put_pixels_tab[((mv.y & 1) << 1) | (mv.x & 1)](dst+8,src+8,pitch,16); + + return 0; +} + +static int svq1_motion_inter_4v_block (bit_buffer_t *bitbuf, + uint8_t *current, uint8_t *previous, int pitch, + svq1_pmv_t *motion,int x, int y) { + uint8_t *src; + uint8_t *dst; + svq1_pmv_t mv; + svq1_pmv_t *pmv[4]; + int i, result; + + /* predict and decode motion vector (0) */ + pmv[0] = &motion[0]; + if (y == 0) { + pmv[1] = + pmv[2] = pmv[0]; + } + else { + pmv[1] = &motion[(x / 8) + 2]; + pmv[2] = &motion[(x / 8) + 4]; + } + + result = svq1_decode_motion_vector (bitbuf, &mv, pmv); + + if (result != 0) + return result; + + /* predict and decode motion vector (1) */ + pmv[0] = &mv; + if (y == 0) { + pmv[1] = + pmv[2] = pmv[0]; + } + else { + pmv[1] = &motion[(x / 8) + 3]; + } + result = svq1_decode_motion_vector (bitbuf, &motion[0], pmv); + + if (result != 0) + return result; + + /* predict and decode motion vector (2) */ + pmv[1] = &motion[0]; + pmv[2] = &motion[(x / 8) + 1]; + + result = svq1_decode_motion_vector (bitbuf, &motion[(x / 8) + 2], pmv); + + if (result != 0) + return result; + + /* predict and decode motion vector (3) */ + pmv[2] = &motion[(x / 8) + 2]; + pmv[3] = &motion[(x / 8) + 3]; + + result = svq1_decode_motion_vector (bitbuf, pmv[3], pmv); + + if (result != 0) + return result; + + /* form predictions */ + for (i=0; i < 4; i++) { + src = &previous[(x + (pmv[i]->x >> 1)) + (y + (pmv[i]->y >> 1))*pitch]; + dst = current; + + put_pixels_tab[((pmv[i]->y & 1) << 1) | (pmv[i]->x & 1)](dst,src,pitch,8); + + /* select next block */ + if (i & 1) { + current += 8*(pitch - 1); + previous += 8*(pitch - 1); + } else { + current += 8; + previous += 8; + } + } + + return 0; +} + +static int svq1_decode_delta_block (bit_buffer_t *bitbuf, + uint8_t *current, uint8_t *previous, int pitch, + svq1_pmv_t *motion, int x, int y) { + uint32_t bit_cache; + uint32_t block_type; + int result = 0; + + /* get block type */ + bit_cache = get_bit_cache (bitbuf); + + bit_cache >>= (32 - 3); + block_type = svq1_block_type_table[bit_cache].value; + skip_bits(bitbuf,svq1_block_type_table[bit_cache].length); + + /* reset motion vectors */ + if (block_type == SVQ1_BLOCK_SKIP || block_type == SVQ1_BLOCK_INTRA) { + motion[0].x = + motion[0].y = + motion[(x / 8) + 2].x = + motion[(x / 8) + 2].y = + motion[(x / 8) + 3].x = + motion[(x / 8) + 3].y = 0; + } + + switch (block_type) { + case SVQ1_BLOCK_SKIP: + svq1_skip_block (current, previous, pitch, x, y); + break; + + case SVQ1_BLOCK_INTER: + result = svq1_motion_inter_block (bitbuf, current, previous, pitch, motion, x, y); + + if (result != 0) + { +#ifdef DEBUG_SVQ1 + printf("Error in svq1_motion_inter_block %i\n",result); +#endif + break; + } + result = svq1_decode_block_non_intra (bitbuf, current, pitch); + break; + + case SVQ1_BLOCK_INTER_4V: + result = svq1_motion_inter_4v_block (bitbuf, current, previous, pitch, motion, x, y); + + if (result != 0) + { +#ifdef DEBUG_SVQ1 + printf("Error in svq1_motion_inter_4v_block %i\n",result); +#endif + break; + } + result = svq1_decode_block_non_intra (bitbuf, current, pitch); + break; + + case SVQ1_BLOCK_INTRA: + result = svq1_decode_block_intra (bitbuf, current, pitch); + break; + } + + return result; +} + +/* standard video sizes */ +static struct { int width; int height; } svq1_frame_size_table[8] = { + { 160, 120 }, { 128, 96 }, { 176, 144 }, { 352, 288 }, + { 704, 576 }, { 240, 180 }, { 320, 240 }, { -1, -1 } +}; + +static int svq1_decode_frame_header (bit_buffer_t *bitbuf,MpegEncContext *s) { + int frame_size_code; + + /* unknown field */ + get_bits (bitbuf, 8); + + /* frame type */ + s->pict_type = get_bits (bitbuf, 2); + + if (s->pict_type == 3) + return -1; + + if (s->pict_type == SVQ1_FRAME_INTRA) { + + /* unknown fields */ + if (s->f_code == 0x50 || s->f_code == 0x60) { + get_bits (bitbuf, 16); + } + + if ((s->f_code ^ 0x10) >= 0x50) { + skip_bits(bitbuf,8*get_bits (bitbuf, 8)); + } + + get_bits (bitbuf, 2); + get_bits (bitbuf, 2); + get_bits (bitbuf, 1); + + /* load frame size */ + frame_size_code = get_bits (bitbuf, 3); + + if (frame_size_code == 7) { + /* load width, height (12 bits each) */ + s->width = get_bits (bitbuf, 12); + s->height = get_bits (bitbuf, 12); + + if (!s->width || !s->height) + return -1; + } else { + /* get width, height from table */ + s->width = svq1_frame_size_table[frame_size_code].width; + s->height = svq1_frame_size_table[frame_size_code].height; + } + } + + /* unknown fields */ + if (get_bits (bitbuf, 1) == 1) { + get_bits (bitbuf, 1); + get_bits (bitbuf, 1); + + if (get_bits (bitbuf, 2) != 0) + return -1; + } + + if (get_bits (bitbuf, 1) == 1) { + get_bits (bitbuf, 1); + get_bits (bitbuf, 4); + get_bits (bitbuf, 1); + get_bits (bitbuf, 2); + + while (get_bits (bitbuf, 1) == 1) { + get_bits (bitbuf, 8); + } + } + + return 0; +} + +static int svq1_decode_frame(AVCodecContext *avctx, + void *data, int *data_size, + UINT8 *buf, int buf_size) +{ + MpegEncContext *s=avctx->priv_data; + uint8_t *current, *previous; + int result, i, x, y, width, height; + AVPicture *pict = data; + + /* initialize bit buffer */ + init_get_bits(&s->gb,buf,buf_size); + + /* decode frame header */ + s->f_code = get_bits (&s->gb, 22); + + if ((s->f_code & ~0x70) || !(s->f_code & 0x60)) + return -1; + + /* swap some header bytes (why?) */ + if (s->f_code != 0x20) { + uint32_t *src = (uint32_t *) (buf + 4); + + for (i=0; i < 4; i++) { + src[i] = ((src[i] << 16) | (src[i] >> 16)) ^ src[7 - i]; + } + } + + result = svq1_decode_frame_header (&s->gb, s); + + if (result != 0) + { +#ifdef DEBUG_SVQ1 + printf("Error in svq1_decode_frame_header %i\n",result); +#endif + return result; + } + + /* decode y, u and v components */ + for (i=0; i < 3; i++) { + if (i == 0) { + width = (s->width+15)&~15; + height = (s->height+15)&~15; + } else { + width = (s->width/4+15)&~15; + height = (s->height/4+15)&~15; + } + + current = s->current_picture[i]; + previous = s->last_picture[i]; + + if (s->pict_type == SVQ1_FRAME_INTRA) { + /* keyframe */ + for (y=0; y < height; y+=16) { + for (x=0; x < width; x+=16) { + result = svq1_decode_block_intra (&s->gb, ¤t[x], width); + if (result != 0) + { +#ifdef DEBUG_SVQ1 + printf("Error in svq1_decode_block %i (keyframe)\n",result); +#endif + return result; + } + } + current += 16*width; + } + } else { + /* delta frame */ + memset (s->opaque, 0, ((width / 8) + 3) * sizeof(svq1_pmv_t)); + + for (y=0; y < height; y+=16) { + for (x=0; x < width; x+=16) { + result = svq1_decode_delta_block (&s->gb, ¤t[x], previous, + width, s->opaque, x, y); + if (result != 0) + { +#ifdef DEBUG_SVQ1 + printf("Error in svq1_decode_delta_block %i\n",result); +#endif + return result; + } + } + + ((svq1_pmv_t *)s->opaque)[0].x = + ((svq1_pmv_t *)s->opaque)[0].y = 0; + + current += 16*width; + } + } + + pict->data[i] = s->current_picture[i]; + pict->linesize[i] = width; + /* update backward reference frame */ + if (s->pict_type != SVQ1_FRAME_DROPPABLE) + { + uint8_t *tmp = s->last_picture[i]; + s->last_picture[i] = s->current_picture[i]; + s->current_picture[i] = tmp; + } + } + *data_size=sizeof(AVPicture); + return 0; +} + +static int svq1_decode_init(AVCodecContext *avctx) +{ + MpegEncContext *s = avctx->priv_data; + unsigned i; + s->avctx = avctx; + s->width = (avctx->width+3)&~3; + s->height = (avctx->height+3)&~3; + s->codec_id= avctx->codec->id; + avctx->mbskip_table= s->mbskip_table; + s->opaque = (svq1_pmv_t *) malloc (((s->width / 8) + 3) * sizeof(svq1_pmv_t)); + if (MPV_common_init(s) < 0) return -1; + for(i=0;i<3;i++) + s->current_picture[i] = s->next_picture[i]; + avctx->pix_fmt = PIX_FMT_YUV410P; + return 0; +} + +static int svq1_decode_end(AVCodecContext *avctx) +{ + MpegEncContext *s = avctx->priv_data; + + MPV_common_end(s); + free(s->opaque); + return 0; +} + +AVCodec svq1_decoder = { + "svq1", + CODEC_TYPE_VIDEO, + CODEC_ID_SVQ1, + sizeof(MpegEncContext), + svq1_decode_init, + NULL, + svq1_decode_end, + svq1_decode_frame +}; diff --git a/src/libffmpeg/libavcodec/utils.c b/src/libffmpeg/libavcodec/utils.c index d66988253..05fd6ab70 100644 --- a/src/libffmpeg/libavcodec/utils.c +++ b/src/libffmpeg/libavcodec/utils.c @@ -199,6 +199,7 @@ const char *pix_fmt_str[] = { "bgr24", "yuv422p", "yuv444p", + "yuv410p" }; void avcodec_string(char *buf, int buf_size, AVCodecContext *enc, int encode) diff --git a/src/libffmpeg/xine_decoder.c b/src/libffmpeg/xine_decoder.c index 90165b3b3..e53823f4c 100644 --- a/src/libffmpeg/xine_decoder.c +++ b/src/libffmpeg/xine_decoder.c @@ -17,7 +17,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA * - * $Id: xine_decoder.c,v 1.47 2002/07/05 20:54:37 miguelfreitas Exp $ + * $Id: xine_decoder.c,v 1.48 2002/07/15 19:43:16 miguelfreitas Exp $ * * xine decoder plugin using ffmpeg * @@ -80,6 +80,8 @@ static int ff_can_handle (video_decoder_t *this_gen, int buf_type) { /* buf_type == BUF_VIDEO_I263 || */ buf_type == BUF_VIDEO_H263 || buf_type == BUF_VIDEO_RV10 || + /* PIX_FMT_YUV410P must be supported to enable svq1 */ + /* buf_type == BUF_VIDEO_SORENSON_V1 || */ buf_type == BUF_VIDEO_JPEG); } @@ -149,6 +151,9 @@ static void ff_decode_data (video_decoder_t *this_gen, buf_element_t *buf) { case BUF_VIDEO_RV10: codec = avcodec_find_decoder (CODEC_ID_RV10); break; + case BUF_VIDEO_SORENSON_V1: + codec = avcodec_find_decoder (CODEC_ID_SVQ1); + break; default: printf ("ffmpeg: unknown video format (buftype: 0x%08X)\n", buf->type & 0xFFFF0000); @@ -392,6 +397,7 @@ void avcodec_register_all(void) register_avcodec(&mpeg_decoder); register_avcodec(&h263i_decoder); register_avcodec(&rv10_decoder); + register_avcodec(&svq1_decoder); register_avcodec(&mjpeg_decoder); } |