[Scummvm-cvs-logs] scummvm master -> 744528cb18ef6b79703a77804acf01864aaaf39e

digitall digitall at scummvm.org
Sun Apr 8 05:24:26 CEST 2012


This automated email contains information about 23 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
e1f9598392 GRAPHICS: Add YUV410 to RGB Conversion Functions, required for SVQ1.
c9c16cd1ee VIDEO: Add initial framework and data tables for Sorenson SVQ1 decoder.
e16270605a VIDEO: Hookup SVQ1 codec to build system and QT Decoder.
da35b9f5f6 VIDEO: Migrate SVQ1 codec WIP to Common::BitStream.
69e76182cb VIDEO: Update SVQ1 WIP with minor corrections.
9330a7c54d VIDEO: Corrected minor mistake in SVQ1 decoder.
b99565d701 VIDEO: Add remaining SVQ1 code derived from FFMPEG.
a3fb8867d0 VIDEO: Fix remaining missing code (getVlc2()) in SVQ1 Codec.
32ff1f8478 VIDEO: SVQ1 - Add table_size default setting for VLC Table setup.
c9bbe5793c VIDEO: Rewrite the SVQ1 VLC code to use Common::Huffman
97746e2281 VIDEO: Correct SVQ1 Header Decoding and Last Frame Buffering.
d15ff5a03e VIDEO: Correct delete type in SVQ1 decoder.
7109e26d04 VIDEO: Workaround for out of buffer accesses in SVQ1 codec.
1ca81ee6ec VIDEO: Rework SVQ1 codebooks so they're endian-safe
2043403207 VIDEO: Add Missing Half-Pel Motion Compensation Code to SVQ1 Codec.
7e05107256 VIDEO: Fix endian issue with SVQ1
b0646529d1 VIDEO: Fix segfaults on different sized SVQ1 frames
c917db0754 VIDEO: Change SVQ1 decoder to skip rather than decode embedded string.
95d7c012d6 VIDEO: Minor updates to SVQ1 decoder, mainly return flags to bool.
8bf8a08048 VIDEO: Fix SVQ1 plane pitch
7b6c4bb8e1 VIDEO: Minor update to SVQ1 decoder, reversing sense of return flags.
8e107f8c78 MOHAWK: Enable the SVQ1 intro for Myst ME Mac
744528cb18 VIDEO: Clean up the SVQ1 code


Commit: e1f95983923ffcb0624eef1fa6cf552eb54fe647
    https://github.com/scummvm/scummvm/commit/e1f95983923ffcb0624eef1fa6cf552eb54fe647
Author: D G Turner (digitall at scummvm.org)
Date: 2012-04-07T19:28:58-07:00

Commit Message:
GRAPHICS: Add YUV410 to RGB Conversion Functions, required for SVQ1.

Thanks to clone2727 for these.

Changed paths:
    graphics/yuv_to_rgb.cpp
    graphics/yuv_to_rgb.h



diff --git a/graphics/yuv_to_rgb.cpp b/graphics/yuv_to_rgb.cpp
index ac7f217..e0af267 100644
--- a/graphics/yuv_to_rgb.cpp
+++ b/graphics/yuv_to_rgb.cpp
@@ -300,4 +300,64 @@ void convertYUV420ToRGB(Graphics::Surface *dst, const byte *ySrc, const byte *uS
 		convertYUV420ToRGB<uint32>((byte *)dst->pixels, dst->pitch, lookup, ySrc, uSrc, vSrc, yWidth, yHeight, yPitch, uvPitch);
 }
 
+#define OUTPUT_4_PIXEL_COLUMN() \
+	PUT_PIXEL(*ySrc, dstPtr); \
+	PUT_PIXEL(*(ySrc + yPitch), dstPtr + dstPitch); \
+	PUT_PIXEL(*(ySrc + (yPitch << 1)), dstPtr + dstPitch * 2); \
+	PUT_PIXEL(*(ySrc + (yPitch * 3)), dstPtr + dstPitch * 3); \
+	ySrc++; \
+	dstPtr += sizeof(PixelInt)
+
+template<typename PixelInt>
+void convertYUV410ToRGB(byte *dstPtr, int dstPitch, const YUVToRGBLookup *lookup, const byte *ySrc, const byte *uSrc, const byte *vSrc, int yWidth, int yHeight, int yPitch, int uvPitch) {
+	int quarterHeight = yHeight >> 2;
+	int quarterWidth = yWidth >> 2;
+
+	// Keep the tables in pointers here to avoid a dereference on each pixel
+	const int16 *Cr_r_tab = lookup->_colorTab;
+	const int16 *Cr_g_tab = Cr_r_tab + 256;
+	const int16 *Cb_g_tab = Cr_g_tab + 256;
+	const int16 *Cb_b_tab = Cb_g_tab + 256;
+	const uint32 *rgbToPix = lookup->_rgbToPix;
+
+	for (int h = 0; h < quarterHeight; h++) {
+		for (int w = 0; w < quarterWidth; w++) {
+			register const uint32 *L;
+
+			int16 cr_r  = Cr_r_tab[*vSrc];
+			int16 crb_g = Cr_g_tab[*vSrc] + Cb_g_tab[*uSrc];
+			int16 cb_b  = Cb_b_tab[*uSrc];
+			++uSrc;
+			++vSrc;
+
+			OUTPUT_4_PIXEL_COLUMN();
+			OUTPUT_4_PIXEL_COLUMN();
+			OUTPUT_4_PIXEL_COLUMN();
+			OUTPUT_4_PIXEL_COLUMN();
+		}
+
+		dstPtr += dstPitch * 3;
+		ySrc += (yPitch << 2) - yWidth;
+		uSrc += uvPitch - quarterWidth;
+		vSrc += uvPitch - quarterWidth;
+	}
+}
+
+void convertYUV410ToRGB(Graphics::Surface *dst, const byte *ySrc, const byte *uSrc, const byte *vSrc, int yWidth, int yHeight, int yPitch, int uvPitch) {
+	// Sanity checks
+	assert(dst && dst->pixels);
+	assert(dst->format.bytesPerPixel == 2 || dst->format.bytesPerPixel == 4);
+	assert(ySrc && uSrc && vSrc);
+	assert((yWidth & 3) == 0);
+	assert((yHeight & 3) == 0);
+
+	const YUVToRGBLookup *lookup = YUVToRGBMan.getLookup(dst->format);
+
+	// Use a templated function to avoid an if check on every pixel
+	if (dst->format.bytesPerPixel == 2)
+		convertYUV410ToRGB<uint16>((byte *)dst->pixels, dst->pitch, lookup, ySrc, uSrc, vSrc, yWidth, yHeight, yPitch, uvPitch);
+	else
+		convertYUV410ToRGB<uint32>((byte *)dst->pixels, dst->pitch, lookup, ySrc, uSrc, vSrc, yWidth, yHeight, yPitch, uvPitch);
+}
+
 } // End of namespace Graphics
diff --git a/graphics/yuv_to_rgb.h b/graphics/yuv_to_rgb.h
index 8e02504..52ab2eb 100644
--- a/graphics/yuv_to_rgb.h
+++ b/graphics/yuv_to_rgb.h
@@ -64,6 +64,20 @@ void convertYUV444ToRGB(Graphics::Surface *dst, const byte *ySrc, const byte *uS
  */
 void convertYUV420ToRGB(Graphics::Surface *dst, const byte *ySrc, const byte *uSrc, const byte *vSrc, int yWidth, int yHeight, int yPitch, int uvPitch);
 
+/**
+ * Convert a YUV410 image to an RGB surface
+ *
+ * @param dst     the destination surface
+ * @param ySrc    the source of the y component
+ * @param uSrc    the source of the u component
+ * @param vSrc    the source of the v component
+ * @param yWidth  the width of the y surface (must be divisible by 4)
+ * @param yHeight the height of the y surface (must be divisible by 4)
+ * @param yPitch  the pitch of the y surface
+ * @param uvPitch the pitch of the u and v surfaces
+ */
+void convertYUV410ToRGB(Graphics::Surface *dst, const byte *ySrc, const byte *uSrc, const byte *vSrc, int yWidth, int yHeight, int yPitch, int uvPitch);
+
 } // End of namespace Graphics
 
 #endif


Commit: c9c16cd1ee44d089a68ec973f3b6df5a0ea17ab6
    https://github.com/scummvm/scummvm/commit/c9c16cd1ee44d089a68ec973f3b6df5a0ea17ab6
Author: D G Turner (digitall at scummvm.org)
Date: 2012-04-07T19:29:01-07:00

Commit Message:
VIDEO: Add initial framework and data tables for Sorenson SVQ1 decoder.

This is based on the SVQ1 decoder from FFMPEG.

Changed paths:
  A video/codecs/svq1.cpp
  A video/codecs/svq1.h
  A video/codecs/svq1_cb.h
  A video/codecs/svq1_vlc.h



diff --git a/video/codecs/svq1.cpp b/video/codecs/svq1.cpp
new file mode 100644
index 0000000..c63405e
--- /dev/null
+++ b/video/codecs/svq1.cpp
@@ -0,0 +1,335 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+// Sorenson Video 1 Codec
+// Based off ffmpeg's SVQ1 decoder (written by Mike Melanson)
+
+#include "video/codecs/svq1.h"
+#include "video/codecs/svq1_cb.h"
+#include "video/codecs/svq1_vlc.h"
+
+#include "common/stream.h"
+#include "common/system.h"
+#include "common/debug.h"
+#include "common/textconsole.h"
+
+#include "graphics/yuv_to_rgb.h"
+
+namespace Video {
+
+// TODO: Common could do with a good Bitstream Reader Class 
+//       capable of wrapping ReadStream and byte *buffers
+//       This would replace this, a similar class in SMK, QDM2
+//       and probably a number of other similar pieces of code.
+class SVQ1BitStream {
+public:
+	SVQ1BitStream(Common::SeekableReadStream *stream)
+		: _stream(stream), _bitCount(0) {
+	}
+
+	bool getBit();
+	byte getBitsByte(uint n);
+	uint32 getBitsUint32(uint n);
+
+private:
+	Common::SeekableReadStream *_stream;
+
+	byte _curByte;
+	byte  _bitCount;
+};
+
+bool SVQ1BitStream::getBit() {
+	if (_bitCount == 0) {
+		assert(_stream->pos() < _stream->size());
+		_curByte = _stream->readByte();
+		_bitCount = 8;
+	}
+
+	bool v = _curByte & 1;
+
+	_curByte >>= 1;
+	--_bitCount;
+
+	return v;
+}
+
+byte SVQ1BitStream::getBitsByte(uint n) {
+	assert (n <= 8);
+	byte v = 0;
+
+	for (uint i = 0; i < 8; i++) {
+		v >>= 1;
+		if (getBit() && i < n)
+			v |= 0x80;
+	}
+
+	return v;
+}
+
+uint32 SVQ1BitStream::getBitsUint32(uint n) {
+	assert (n <= 32);
+	uint32 v = 0;
+
+	for (uint i = 0; i < 32; i++) {
+		v >>= 1;
+		if (getBit() && i < n)
+			v |= 0x8000;
+	}
+
+	return v;
+}
+
+SVQ1Decoder::SVQ1Decoder(uint16 width, uint16 height) {
+	_surface = new Graphics::Surface();
+	_surface->create(width, height, g_system->getScreenFormat());
+}
+
+SVQ1Decoder::~SVQ1Decoder() {
+	_surface->free();
+	delete _surface;
+}
+
+const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *stream) {
+	debug(1, "SVQ1Decoder::decodeImage()");
+
+	// Debugging Output to compare with output of Bitstream Reader
+#if 1
+	int32 startPos = stream->pos();
+	for (uint32 i = 0; i < 6; i++) {
+		debug(1, " Stream Byte %d: 0x%02x", i, stream->readByte());
+	}
+	stream->seek(startPos, SEEK_SET);
+#endif
+
+	SVQ1BitStream *frameData = new SVQ1BitStream(stream);
+
+	uint32 frameCode = frameData->getBitsUint32(22);
+	debug(1, " frameCode: %d", frameCode);
+
+  if ((frameCode & ~0x70) || !(frameCode & 0x60)) // Invalid
+    return _surface;
+
+  // swap some header bytes (why?)
+  //if (frameCode != 0x20) {
+  //  uint32 *src = stream;
+	//
+  //  for (i = 4; i < 8; i++) {
+  //    src[i] = ((src[i] << 16) | (src[i] >> 16)) ^ src[7 - i];
+  // }
+  //}
+
+#if 0
+	static const uint16 checksum_table[256] = {
+		0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
+		0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
+		0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
+		0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
+		0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
+		0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
+		0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
+		0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
+		0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
+		0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
+		0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
+		0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
+		0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
+		0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
+		0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
+		0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
+		0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
+		0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
+		0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
+		0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
+		0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
+		0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
+		0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
+		0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
+		0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
+		0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
+		0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
+		0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
+		0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
+		0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
+		0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
+		0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0
+	};
+#endif
+
+	byte temporalReference = frameData->getBitsByte(8);
+	debug(1, " temporalReference: %d", temporalReference);
+	const char* types[4] = { "I Frame", "P Frame", "B Frame", "Invalid" };
+	byte pictureType = frameData->getBitsByte(2);
+	debug(1, " pictureType: %d (%s)", pictureType, types[pictureType]);
+	if (pictureType == 3) // Invalid
+		return _surface;
+	else if (pictureType == 0) { // I Frame
+		if (frameCode == 0x50 || frameCode == 0x60) {
+			uint32 checksum = frameData->getBitsUint32(16);
+			debug(1, " checksum:0x%02x", checksum);
+			// TODO: Validate checksum
+			//uint16 calculate_packet_checksum (const uint8 *data, const int length) {
+			//  int value;
+  		//	for (int i = 0; i < length; i++)
+    	//		value = checksum_table[data[i] ^ (value >> 8)] ^ ((value & 0xFF) << 8);
+  		//	return value;
+			//}
+		}
+	}
+
+	static const uint8 stringXORTable[256] = {
+		0x00, 0xD5, 0x7F, 0xAA, 0xFE, 0x2B, 0x81, 0x54,
+		0x29, 0xFC, 0x56, 0x83, 0xD7, 0x02, 0xA8, 0x7D,
+		0x52, 0x87, 0x2D, 0xF8, 0xAC, 0x79, 0xD3, 0x06,
+		0x7B, 0xAE, 0x04, 0xD1, 0x85, 0x50, 0xFA, 0x2F,
+		0xA4, 0x71, 0xDB, 0x0E, 0x5A, 0x8F, 0x25, 0xF0,
+		0x8D, 0x58, 0xF2, 0x27, 0x73, 0xA6, 0x0C, 0xD9,
+		0xF6, 0x23, 0x89, 0x5C, 0x08, 0xDD, 0x77, 0xA2,
+		0xDF, 0x0A, 0xA0, 0x75, 0x21, 0xF4, 0x5E, 0x8B,
+		0x9D, 0x48, 0xE2, 0x37, 0x63, 0xB6, 0x1C, 0xC9,
+		0xB4, 0x61, 0xCB, 0x1E, 0x4A, 0x9F, 0x35, 0xE0,
+		0xCF, 0x1A, 0xB0, 0x65, 0x31, 0xE4, 0x4E, 0x9B,
+		0xE6, 0x33, 0x99, 0x4C, 0x18, 0xCD, 0x67, 0xB2,
+		0x39, 0xEC, 0x46, 0x93, 0xC7, 0x12, 0xB8, 0x6D,
+		0x10, 0xC5, 0x6F, 0xBA, 0xEE, 0x3B, 0x91, 0x44,
+		0x6B, 0xBE, 0x14, 0xC1, 0x95, 0x40, 0xEA, 0x3F,
+		0x42, 0x97, 0x3D, 0xE8, 0xBC, 0x69, 0xC3, 0x16,
+		0xEF, 0x3A, 0x90, 0x45, 0x11, 0xC4, 0x6E, 0xBB,
+		0xC6, 0x13, 0xB9, 0x6C, 0x38, 0xED, 0x47, 0x92,
+		0xBD, 0x68, 0xC2, 0x17, 0x43, 0x96, 0x3C, 0xE9,
+		0x94, 0x41, 0xEB, 0x3E, 0x6A, 0xBF, 0x15, 0xC0,
+		0x4B, 0x9E, 0x34, 0xE1, 0xB5, 0x60, 0xCA, 0x1F,
+		0x62, 0xB7, 0x1D, 0xC8, 0x9C, 0x49, 0xE3, 0x36,
+		0x19, 0xCC, 0x66, 0xB3, 0xE7, 0x32, 0x98, 0x4D,
+		0x30, 0xE5, 0x4F, 0x9A, 0xCE, 0x1B, 0xB1, 0x64,
+		0x72, 0xA7, 0x0D, 0xD8, 0x8C, 0x59, 0xF3, 0x26,
+		0x5B, 0x8E, 0x24, 0xF1, 0xA5, 0x70, 0xDA, 0x0F,
+		0x20, 0xF5, 0x5F, 0x8A, 0xDE, 0x0B, 0xA1, 0x74,
+		0x09, 0xDC, 0x76, 0xA3, 0xF7, 0x22, 0x88, 0x5D,
+		0xD6, 0x03, 0xA9, 0x7C, 0x28, 0xFD, 0x57, 0x82,
+		0xFF, 0x2A, 0x80, 0x55, 0x01, 0xD4, 0x7E, 0xAB,
+		0x84, 0x51, 0xFB, 0x2E, 0x7A, 0xAF, 0x05, 0xD0,
+		0xAD, 0x78, 0xD2, 0x07, 0x53, 0x86, 0x2C, 0xF9
+	};
+
+	if ((frameCode ^ 0x10) >= 0x50) {
+		// Decode embedded string
+		Common::String str;
+		uint8 stringLen = frameData->getBitsByte(8);
+		byte xorVal = stringXORTable[stringLen];
+
+		for (uint16 i = 0; i < stringLen-1; i++) {
+			byte data = frameData->getBitsByte(8);
+			str += data ^ xorVal;
+			xorVal = stringXORTable[data];
+		}
+		debug(1, " Embedded String of %d Characters: \"%s\"", stringLen, str.c_str());
+	}
+
+	byte unk1 = frameData->getBitsByte(2); // Unknown
+	debug(1, "unk1: %d", unk1);
+	byte unk2 = frameData->getBitsByte(2); // Unknown
+	debug(1, "unk2: %d", unk2);
+	bool unk3 = frameData->getBit(); // Unknown
+	debug(1, "unk3: %d", unk3);
+
+	static const struct { uint w, h; } standardFrameSizes[7] = {
+		{ 160, 120 }, // 0
+		{ 128,  96 }, // 1
+		{ 176, 144 }, // 2
+		{ 352, 288 }, // 3
+	  { 704, 576 }, // 4
+		{ 240, 180 }, // 5
+		{ 320, 240 }  // 6
+	};
+
+	byte frameSizeCode = frameData->getBitsByte(3);
+	debug(1, " frameSizeCode: %d", frameSizeCode);
+	uint16 frameWidth, frameHeight;
+	if (frameSizeCode == 7) {
+		frameWidth = frameData->getBitsUint32(12);
+		frameHeight = frameData->getBitsUint32(12);
+	} else {
+		frameWidth = standardFrameSizes[frameSizeCode].w;
+		frameHeight = standardFrameSizes[frameSizeCode].h;
+	}
+	debug(1, " frameWidth: %d", frameWidth);
+	debug(1, " frameHeight: %d", frameHeight);
+	if (frameWidth == 0 || frameHeight == 0) // Invalid
+		return _surface;
+
+	bool checksumPresent = frameData->getBit();
+	debug(1, " checksumPresent: %d", checksumPresent);
+	if (checksumPresent) {
+		bool usePacketChecksum = frameData->getBit();
+		debug(1, " usePacketChecksum: %d", usePacketChecksum);
+		bool componentChecksumsAfterImageData = frameData->getBit();
+		debug(1, " componentChecksumsAfterImageData: %d", componentChecksumsAfterImageData);
+		byte unk4 = frameData->getBitsByte(2);
+		debug(1, " unk4: %d", unk4);
+		if (unk4 != 0)
+			warning("Invalid Frame Header in SVQ1 Frame Decode");
+	}
+
+	bool unk5 = frameData->getBit();
+	debug(1, " unk5: %d", unk5);
+	if (unk5) {
+		bool unk6 = frameData->getBit();
+		debug(1, " unk6: %d", unk6);
+		byte unk7 = frameData->getBitsByte(4);
+		debug(1, " unk7: %d", unk7);
+		bool unk8 = frameData->getBit();
+		debug(1, " unk8: %d", unk8);
+		byte unk9 = frameData->getBitsByte(2);
+		debug(1, " unk9: %d", unk9);
+		while (frameData->getBit()) {
+			byte unk10 = frameData->getBitsByte(8);
+			debug(1, " unk10: %d", unk10);
+		}
+	}
+
+	if (frameWidth <= _surface->w && frameHeight <= _surface->h) {
+		byte *yPlane = new byte[frameWidth*frameHeight];
+		byte *uPlane = new byte[(frameWidth/2)*(frameHeight/2)];
+		byte *vPlane = new byte[(frameWidth/2)*(frameHeight/2)];
+
+		// TODO: Read Plane Data
+		for (uint32 i = 0; i < frameWidth*frameHeight; i++)
+			yPlane[i] = 0;
+		for (uint32 i = 0; i < (frameWidth/2)*(frameHeight/2); i++) {
+			uPlane[i] = 0;
+			vPlane[i] = 0;
+		}
+
+		delete frameData;
+
+		convertYUV410ToRGB(_surface, yPlane, uPlane, vPlane, frameWidth, frameHeight, frameWidth, frameWidth/2);
+	
+		delete[] yPlane;
+		delete[] uPlane;
+		delete[] vPlane;
+	} else
+		warning("FrameWidth/Height Sanity Check Failed!");
+
+	return _surface;
+}
+
+} // End of namespace Video
diff --git a/video/codecs/svq1.h b/video/codecs/svq1.h
new file mode 100644
index 0000000..f2b7ddf
--- /dev/null
+++ b/video/codecs/svq1.h
@@ -0,0 +1,44 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef VIDEO_CODECS_SVQ1_H
+#define VIDEO_CODECS_SVQ1_H
+
+#include "video/codecs/codec.h"
+
+namespace Video {
+
+class SVQ1Decoder : public Codec {
+public:
+	SVQ1Decoder(uint16 width, uint16 height);
+	~SVQ1Decoder();
+
+	const Graphics::Surface *decodeImage(Common::SeekableReadStream *stream);
+	Graphics::PixelFormat getPixelFormat() const { return _surface->format; }
+
+private:
+	Graphics::Surface *_surface;
+};
+
+} // End of namespace Video
+
+#endif
diff --git a/video/codecs/svq1_cb.h b/video/codecs/svq1_cb.h
new file mode 100644
index 0000000..e34fe3a
--- /dev/null
+++ b/video/codecs/svq1_cb.h
@@ -0,0 +1,1512 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef VIDEO_CODECS_SVQ1_CB_H
+#define VIDEO_CODECS_SVQ1_CB_H
+
+// 6x16-entry codebook for inter-coded 4x2 vectors
+static const int8 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 const int8 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 const int8 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 const int8 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
+const int8_t* const ff_svq1_inter_codebooks[6] = {
+    svq1_inter_codebook_4x2, svq1_inter_codebook_4x4,
+    svq1_inter_codebook_8x4, svq1_inter_codebook_8x8,
+    NULL, NULL,
+};
+
+// 6x16-entry codebook for intra-coded 4x2 vectors
+static const int8 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 const int8 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 const int8 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 const int8 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/
+const int8* const ff_svq1_intra_codebooks[6] = {
+    svq1_intra_codebook_4x2, svq1_intra_codebook_4x4,
+    svq1_intra_codebook_8x4, svq1_intra_codebook_8x8,
+    NULL, NULL,
+};
+
+#endif
diff --git a/video/codecs/svq1_vlc.h b/video/codecs/svq1_vlc.h
new file mode 100644
index 0000000..1694ce3
--- /dev/null
+++ b/video/codecs/svq1_vlc.h
@@ -0,0 +1,283 @@
+/* ScummVM - Graphic Adventure Engine
+ *
+ * ScummVM is the legal property of its developers, whose names
+ * are too numerous to list here. Please refer to the COPYRIGHT
+ * file distributed with this source distribution.
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ */
+
+#ifndef VIDEO_CODECS_SVQ1_VLC_H
+#define VIDEO_CODECS_SVQ1_VLC_H
+
+// values in this table range from 0..3; adjust retrieved value by +0
+const uint8 ff_svq1_block_type_vlc[4][2] = {
+ // { code, length }
+    { 0x1, 1 },  { 0x1, 2 },  { 0x1, 3 },  { 0x0, 3 }
+
+};
+
+// values in this table range from -1..6; adjust retrieved value by -1
+const uint8 ff_svq1_intra_multistage_vlc[6][8][2] = {
+ // { code, length }
+{
+    { 0x1, 5 },  { 0x1, 1 },  { 0x3, 3 },  { 0x2, 3 },
+    { 0x3, 4 },  { 0x2, 4 },  { 0x0, 5 },  { 0x1, 4 }
+},{
+    { 0x1, 4 },  { 0x3, 2 },  { 0x5, 3 },  { 0x4, 3 },
+    { 0x3, 3 },  { 0x2, 3 },  { 0x0, 4 },  { 0x1, 3 }
+},{
+    { 0x1, 5 },  { 0x1, 1 },  { 0x3, 3 },  { 0x0, 5 },
+    { 0x3, 4 },  { 0x2, 3 },  { 0x2, 4 },  { 0x1, 4 }
+},{
+    { 0x1, 6 },  { 0x1, 1 },  { 0x1, 2 },  { 0x0, 6 },
+    { 0x3, 4 },  { 0x2, 4 },  { 0x1, 5 },  { 0x1, 4 }
+},{
+    { 0x1, 6 },  { 0x1, 1 },  { 0x1, 2 },  { 0x3, 5 },
+    { 0x2, 5 },  { 0x0, 6 },  { 0x1, 5 },  { 0x1, 3 }
+},{
+    { 0x1, 7 },  { 0x1, 1 },  { 0x1, 2 },  { 0x1, 3 },
+    { 0x1, 4 },  { 0x1, 6 },  { 0x0, 7 },  { 0x1, 5 }
+}
+};
+
+// values in this table range from -1..6; adjust retrieved value by -1
+const uint8 ff_svq1_inter_multistage_vlc[6][8][2] = {
+ // { code, length }
+{
+    { 0x3, 2 },  { 0x5, 3 },  { 0x4, 3 },  { 0x3, 3 },
+    { 0x2, 3 },  { 0x1, 3 },  { 0x1, 4 },  { 0x0, 4 }
+},{
+    { 0x3, 2 },  { 0x5, 3 },  { 0x4, 3 },  { 0x3, 3 },
+    { 0x2, 3 },  { 0x1, 3 },  { 0x1, 4 },  { 0x0, 4 }
+},{
+    { 0x1, 1 },  { 0x3, 3 },  { 0x2, 3 },  { 0x3, 4 },
+    { 0x2, 4 },  { 0x1, 4 },  { 0x1, 5 },  { 0x0, 5 }
+},{
+    { 0x1, 1 },  { 0x3, 3 },  { 0x2, 3 },  { 0x3, 4 },
+    { 0x2, 4 },  { 0x1, 4 },  { 0x1, 5 },  { 0x0, 5 }
+},{
+    { 0x1, 1 },  { 0x3, 3 },  { 0x2, 3 },  { 0x3, 4 },
+    { 0x2, 4 },  { 0x1, 4 },  { 0x1, 5 },  { 0x0, 5 }
+},{
+    { 0x1, 1 },  { 0x1, 2 },  { 0x1, 3 },  { 0x3, 5 },
+    { 0x2, 5 },  { 0x1, 5 },  { 0x1, 6 },  { 0x0, 6 }
+}
+};
+
+// values in this table range from 0..255; adjust retrieved value by +0
+const uint16 ff_svq1_intra_mean_vlc[256][2] = {
+ // { code, length }
+    { 0x37, 6 },  { 0x56, 7 },  { 0x1, 17 },  { 0x1, 20 },
+    { 0x2, 20 },  { 0x3, 20 },  { 0x0, 20 },  { 0x4, 20 },
+    { 0x5, 20 },  { 0x3, 19 },  { 0x15, 11 },  { 0x42, 9 },
+    { 0x14, 11 },  { 0x3, 14 },  { 0x2, 14 },  { 0x1, 15 },
+    { 0x1, 16 },  { 0x1, 12 },  { 0x2B, 10 },  { 0x18, 11 },
+    { 0xC, 11 },  { 0x41, 9 },  { 0x78, 8 },  { 0x6C, 8 },
+    { 0x55, 7 },  { 0xF, 4 },  { 0xE, 4 },  { 0x34, 6 },
+    { 0x51, 7 },  { 0x72, 8 },  { 0x6E, 8 },  { 0x40, 9 },
+    { 0x3F, 9 },  { 0x3E, 9 },  { 0x3D, 9 },  { 0x3C, 9 },
+    { 0x3B, 9 },  { 0x3A, 9 },  { 0x39, 9 },  { 0x38, 9 },
+    { 0x37, 9 },  { 0x43, 9 },  { 0x46, 9 },  { 0x47, 9 },
+    { 0x45, 9 },  { 0x44, 9 },  { 0x49, 9 },  { 0x48, 9 },
+    { 0x4A, 8 },  { 0x79, 8 },  { 0x76, 8 },  { 0x77, 8 },
+    { 0x71, 8 },  { 0x75, 8 },  { 0x74, 8 },  { 0x73, 8 },
+    { 0x6A, 8 },  { 0x55, 8 },  { 0x70, 8 },  { 0x6F, 8 },
+    { 0x52, 8 },  { 0x6D, 8 },  { 0x4C, 8 },  { 0x6B, 8 },
+    { 0x40, 7 },  { 0x69, 8 },  { 0x68, 8 },  { 0x67, 8 },
+    { 0x66, 8 },  { 0x65, 8 },  { 0x64, 8 },  { 0x63, 8 },
+    { 0x62, 8 },  { 0x61, 8 },  { 0x60, 8 },  { 0x5F, 8 },
+    { 0x5E, 8 },  { 0x5D, 8 },  { 0x5C, 8 },  { 0x5B, 8 },
+    { 0x5A, 8 },  { 0x59, 8 },  { 0x58, 8 },  { 0x57, 8 },
+    { 0x56, 8 },  { 0x3D, 7 },  { 0x54, 8 },  { 0x53, 8 },
+    { 0x3F, 7 },  { 0x51, 8 },  { 0x50, 8 },  { 0x4F, 8 },
+    { 0x4E, 8 },  { 0x4D, 8 },  { 0x41, 7 },  { 0x4B, 8 },
+    { 0x53, 7 },  { 0x3E, 7 },  { 0x48, 8 },  { 0x4F, 7 },
+    { 0x52, 7 },  { 0x45, 8 },  { 0x50, 7 },  { 0x43, 8 },
+    { 0x42, 8 },  { 0x41, 8 },  { 0x42, 7 },  { 0x43, 7 },
+    { 0x3E, 8 },  { 0x44, 7 },  { 0x3C, 8 },  { 0x45, 7 },
+    { 0x46, 7 },  { 0x47, 7 },  { 0x48, 7 },  { 0x49, 7 },
+    { 0x4A, 7 },  { 0x4B, 7 },  { 0x4C, 7 },  { 0x4D, 7 },
+    { 0x4E, 7 },  { 0x58, 7 },  { 0x59, 7 },  { 0x5A, 7 },
+    { 0x5B, 7 },  { 0x5C, 7 },  { 0x5D, 7 },  { 0x44, 8 },
+    { 0x49, 8 },  { 0x29, 8 },  { 0x3F, 8 },  { 0x3D, 8 },
+    { 0x3B, 8 },  { 0x2C, 8 },  { 0x28, 8 },  { 0x25, 8 },
+    { 0x26, 8 },  { 0x5E, 7 },  { 0x57, 7 },  { 0x54, 7 },
+    { 0x5F, 7 },  { 0x62, 7 },  { 0x63, 7 },  { 0x64, 7 },
+    { 0x61, 7 },  { 0x65, 7 },  { 0x67, 7 },  { 0x66, 7 },
+    { 0x35, 6 },  { 0x36, 6 },  { 0x60, 7 },  { 0x39, 8 },
+    { 0x3A, 8 },  { 0x38, 8 },  { 0x37, 8 },  { 0x36, 8 },
+    { 0x35, 8 },  { 0x34, 8 },  { 0x33, 8 },  { 0x32, 8 },
+    { 0x31, 8 },  { 0x30, 8 },  { 0x2D, 8 },  { 0x2B, 8 },
+    { 0x2A, 8 },  { 0x27, 8 },  { 0x40, 8 },  { 0x46, 8 },
+    { 0x47, 8 },  { 0x26, 9 },  { 0x25, 9 },  { 0x24, 9 },
+    { 0x23, 9 },  { 0x22, 9 },  { 0x2E, 8 },  { 0x2F, 8 },
+    { 0x1F, 9 },  { 0x36, 9 },  { 0x1D, 9 },  { 0x21, 9 },
+    { 0x1B, 9 },  { 0x1C, 9 },  { 0x19, 9 },  { 0x1A, 9 },
+    { 0x18, 9 },  { 0x17, 9 },  { 0x16, 9 },  { 0x1E, 9 },
+    { 0x20, 9 },  { 0x27, 9 },  { 0x28, 9 },  { 0x29, 9 },
+    { 0x2A, 9 },  { 0x2B, 9 },  { 0x2C, 9 },  { 0x2D, 9 },
+    { 0x2E, 9 },  { 0x2F, 9 },  { 0x30, 9 },  { 0x35, 9 },
+    { 0x31, 9 },  { 0x32, 9 },  { 0x33, 9 },  { 0x34, 9 },
+    { 0x19, 10 },  { 0x2A, 10 },  { 0x17, 10 },  { 0x16, 10 },
+    { 0x15, 10 },  { 0x28, 10 },  { 0x26, 10 },  { 0x25, 10 },
+    { 0x22, 10 },  { 0x21, 10 },  { 0x18, 10 },  { 0x14, 10 },
+    { 0x29, 10 },  { 0x12, 10 },  { 0xD, 10 },  { 0xE, 10 },
+    { 0xF, 10 },  { 0x10, 10 },  { 0x11, 10 },  { 0x1A, 10 },
+    { 0x1B, 10 },  { 0x1C, 10 },  { 0x1D, 10 },  { 0x1E, 10 },
+    { 0x1F, 10 },  { 0x20, 10 },  { 0x13, 10 },  { 0x23, 10 },
+    { 0x24, 10 },  { 0x9, 11 },  { 0x8, 11 },  { 0x7, 11 },
+    { 0x27, 10 },  { 0x5, 11 },  { 0xB, 11 },  { 0x6, 11 },
+    { 0x4, 11 },  { 0x3, 11 },  { 0x2, 11 },  { 0x1, 11 },
+    { 0xA, 11 },  { 0x16, 11 },  { 0x19, 11 },  { 0x17, 11 },
+    { 0xD, 11 },  { 0xE, 11 },  { 0xF, 11 },  { 0x10, 11 },
+    { 0x11, 11 },  { 0x12, 11 },  { 0x13, 11 },  { 0x1, 14 }
+};
+
+// values in this table range from -256..255; adjust retrieved value by -256
+const uint16 ff_svq1_inter_mean_vlc[512][2] = {
+ // { code, length }
+    { 0x5A, 22 },  { 0xD4, 22 },  { 0xD5, 22 },  { 0xD6, 22 },
+    { 0xD7, 22 },  { 0xD8, 22 },  { 0xD9, 22 },  { 0xDA, 22 },
+    { 0xDB, 22 },  { 0xDC, 22 },  { 0xDD, 22 },  { 0xDE, 22 },
+    { 0xDF, 22 },  { 0xE0, 22 },  { 0xE1, 22 },  { 0xE2, 22 },
+    { 0xE3, 22 },  { 0xE4, 22 },  { 0xE5, 22 },  { 0xE6, 22 },
+    { 0xE8, 22 },  { 0xCB, 22 },  { 0xE9, 22 },  { 0xEA, 22 },
+    { 0xE7, 22 },  { 0xEC, 22 },  { 0xED, 22 },  { 0xEE, 22 },
+    { 0xEF, 22 },  { 0xF0, 22 },  { 0xF1, 22 },  { 0xF2, 22 },
+    { 0xF3, 22 },  { 0xF4, 22 },  { 0xF5, 22 },  { 0xF6, 22 },
+    { 0xF7, 22 },  { 0xF8, 22 },  { 0x102, 22 },  { 0xEB, 22 },
+    { 0xF9, 22 },  { 0xFC, 22 },  { 0xFD, 22 },  { 0xFE, 22 },
+    { 0x100, 22 },  { 0x5C, 22 },  { 0x60, 22 },  { 0x101, 22 },
+    { 0x71, 22 },  { 0x104, 22 },  { 0x105, 22 },  { 0xFB, 22 },
+    { 0xFF, 22 },  { 0x86, 21 },  { 0xFA, 22 },  { 0x7C, 22 },
+    { 0x75, 22 },  { 0x103, 22 },  { 0x78, 22 },  { 0xD3, 22 },
+    { 0x7B, 22 },  { 0x82, 22 },  { 0xD2, 22 },  { 0xD1, 22 },
+    { 0xD0, 22 },  { 0xCF, 22 },  { 0xCE, 22 },  { 0xCD, 22 },
+    { 0xCC, 22 },  { 0xC3, 22 },  { 0xCA, 22 },  { 0xC9, 22 },
+    { 0xC8, 22 },  { 0xC7, 22 },  { 0xC6, 22 },  { 0xC5, 22 },
+    { 0x8B, 22 },  { 0xC4, 22 },  { 0xC2, 22 },  { 0xC1, 22 },
+    { 0xC0, 22 },  { 0xBF, 22 },  { 0xBE, 22 },  { 0xBD, 22 },
+    { 0xBC, 22 },  { 0xBB, 22 },  { 0xBA, 22 },  { 0xB9, 22 },
+    { 0x61, 22 },  { 0x84, 22 },  { 0x85, 22 },  { 0x86, 22 },
+    { 0x87, 22 },  { 0x88, 22 },  { 0x89, 22 },  { 0x8A, 22 },
+    { 0x8C, 22 },  { 0x8D, 22 },  { 0x8E, 22 },  { 0x8F, 22 },
+    { 0x90, 22 },  { 0x91, 22 },  { 0x92, 22 },  { 0x93, 22 },
+    { 0x94, 22 },  { 0x95, 22 },  { 0x96, 22 },  { 0x97, 22 },
+    { 0x98, 22 },  { 0x99, 22 },  { 0x9A, 22 },  { 0x9B, 22 },
+    { 0x9C, 22 },  { 0x9D, 22 },  { 0x9E, 22 },  { 0x9F, 22 },
+    { 0xA0, 22 },  { 0xA1, 22 },  { 0xA2, 22 },  { 0xA3, 22 },
+    { 0xA4, 22 },  { 0xA5, 22 },  { 0xA6, 22 },  { 0xA7, 22 },
+    { 0xA8, 22 },  { 0xA9, 22 },  { 0xAA, 22 },  { 0xAB, 22 },
+    { 0x7F, 22 },  { 0x8F, 21 },  { 0xAC, 22 },  { 0xAD, 22 },
+    { 0xAE, 22 },  { 0xAF, 22 },  { 0xB0, 22 },  { 0xB1, 22 },
+    { 0x53, 20 },  { 0x90, 21 },  { 0xB2, 22 },  { 0x91, 21 },
+    { 0xB3, 22 },  { 0xB4, 22 },  { 0x54, 20 },  { 0xB5, 22 },
+    { 0xB6, 22 },  { 0x8C, 21 },  { 0x34, 19 },  { 0x3D, 18 },
+    { 0x55, 20 },  { 0xB7, 22 },  { 0xB8, 22 },  { 0x8B, 21 },
+    { 0x56, 20 },  { 0x3D, 19 },  { 0x57, 20 },  { 0x58, 20 },
+    { 0x40, 19 },  { 0x43, 19 },  { 0x47, 19 },  { 0x2A, 18 },
+    { 0x2E, 19 },  { 0x2C, 18 },  { 0x46, 19 },  { 0x59, 20 },
+    { 0x49, 19 },  { 0x2D, 19 },  { 0x38, 18 },  { 0x36, 18 },
+    { 0x39, 18 },  { 0x45, 19 },  { 0x28, 18 },  { 0x30, 18 },
+    { 0x35, 18 },  { 0x20, 17 },  { 0x44, 19 },  { 0x32, 18 },
+    { 0x31, 18 },  { 0x1F, 17 },  { 0x2F, 18 },  { 0x2E, 18 },
+    { 0x2D, 18 },  { 0x21, 17 },  { 0x22, 17 },  { 0x23, 17 },
+    { 0x24, 17 },  { 0x27, 16 },  { 0x23, 16 },  { 0x20, 16 },
+    { 0x1D, 16 },  { 0x25, 16 },  { 0x1E, 16 },  { 0x24, 16 },
+    { 0x2A, 16 },  { 0x26, 16 },  { 0x21, 15 },  { 0x29, 16 },
+    { 0x22, 15 },  { 0x23, 15 },  { 0x24, 15 },  { 0x1B, 15 },
+    { 0x1A, 15 },  { 0x1D, 15 },  { 0x1F, 15 },  { 0x27, 15 },
+    { 0x17, 14 },  { 0x18, 14 },  { 0x19, 14 },  { 0x1B, 14 },
+    { 0x1C, 14 },  { 0x1E, 14 },  { 0x25, 14 },  { 0x20, 14 },
+    { 0x21, 14 },  { 0x13, 13 },  { 0x14, 13 },  { 0x15, 13 },
+    { 0x16, 13 },  { 0x17, 13 },  { 0x18, 13 },  { 0x19, 13 },
+    { 0x1A, 13 },  { 0x18, 12 },  { 0x17, 12 },  { 0x15, 12 },
+    { 0x14, 12 },  { 0x13, 12 },  { 0x12, 12 },  { 0xF, 11 },
+    { 0x10, 11 },  { 0x12, 11 },  { 0x13, 11 },  { 0x1B, 11 },
+    { 0x1A, 11 },  { 0xE, 10 },  { 0x13, 10 },  { 0xF, 10 },
+    { 0x10, 10 },  { 0x11, 10 },  { 0x12, 10 },  { 0xD, 9 },
+    { 0x14, 9 },  { 0x15, 9 },  { 0xC, 9 },  { 0x13, 9 },
+    { 0xF, 8 },  { 0xE, 8 },  { 0x10, 8 },  { 0x11, 8 },
+    { 0xC, 7 },  { 0x9, 7 },  { 0xA, 7 },  { 0x8, 6 },
+    { 0x9, 6 },  { 0x9, 5 },  { 0x8, 5 },  { 0x5, 4 },
+    { 0x1, 1 },  { 0x3, 3 },  { 0x7, 5 },  { 0x6, 5 },
+    { 0xB, 6 },  { 0xA, 6 },  { 0xE, 7 },  { 0xF, 7 },
+    { 0xB, 7 },  { 0xD, 7 },  { 0xB, 8 },  { 0xD, 8 },
+    { 0xC, 8 },  { 0xF, 9 },  { 0x10, 9 },  { 0x11, 9 },
+    { 0xE, 9 },  { 0x12, 9 },  { 0x17, 10 },  { 0x14, 10 },
+    { 0x16, 10 },  { 0x15, 10 },  { 0x19, 11 },  { 0x18, 11 },
+    { 0x17, 11 },  { 0x16, 11 },  { 0x15, 11 },  { 0x14, 11 },
+    { 0x11, 11 },  { 0x19, 12 },  { 0x1A, 12 },  { 0x16, 12 },
+    { 0x1D, 12 },  { 0x1B, 12 },  { 0x1C, 12 },  { 0x20, 13 },
+    { 0x1C, 13 },  { 0x23, 13 },  { 0x22, 13 },  { 0x21, 13 },
+    { 0x1F, 13 },  { 0x1E, 13 },  { 0x1B, 13 },  { 0x1D, 13 },
+    { 0x24, 14 },  { 0x16, 14 },  { 0x1A, 14 },  { 0x22, 14 },
+    { 0x1D, 14 },  { 0x1F, 14 },  { 0x15, 14 },  { 0x23, 14 },
+    { 0x18, 15 },  { 0x20, 15 },  { 0x29, 15 },  { 0x28, 15 },
+    { 0x26, 15 },  { 0x25, 15 },  { 0x19, 15 },  { 0x1C, 15 },
+    { 0x1E, 15 },  { 0x17, 15 },  { 0x2C, 16 },  { 0x2B, 16 },
+    { 0x1C, 16 },  { 0x21, 16 },  { 0x2D, 16 },  { 0x28, 16 },
+    { 0x1F, 16 },  { 0x1B, 16 },  { 0x1A, 16 },  { 0x22, 16 },
+    { 0x2D, 17 },  { 0x32, 17 },  { 0x2C, 17 },  { 0x27, 17 },
+    { 0x31, 17 },  { 0x33, 17 },  { 0x2F, 17 },  { 0x2B, 17 },
+    { 0x37, 18 },  { 0x2A, 17 },  { 0x2E, 17 },  { 0x30, 17 },
+    { 0x29, 17 },  { 0x28, 17 },  { 0x26, 17 },  { 0x25, 17 },
+    { 0x2F, 19 },  { 0x33, 18 },  { 0x34, 18 },  { 0x30, 19 },
+    { 0x3A, 18 },  { 0x3B, 18 },  { 0x31, 19 },  { 0x3C, 18 },
+    { 0x2B, 18 },  { 0x29, 18 },  { 0x48, 19 },  { 0x27, 18 },
+    { 0x42, 19 },  { 0x41, 19 },  { 0x26, 18 },  { 0x52, 20 },
+    { 0x51, 20 },  { 0x3F, 19 },  { 0x3E, 19 },  { 0x39, 19 },
+    { 0x3C, 19 },  { 0x3B, 19 },  { 0x3A, 19 },  { 0x25, 18 },
+    { 0x38, 19 },  { 0x50, 20 },  { 0x37, 19 },  { 0x36, 19 },
+    { 0x87, 21 },  { 0x4F, 20 },  { 0x35, 19 },  { 0x4E, 20 },
+    { 0x33, 19 },  { 0x32, 19 },  { 0x4D, 20 },  { 0x4C, 20 },
+    { 0x83, 22 },  { 0x4B, 20 },  { 0x81, 22 },  { 0x80, 22 },
+    { 0x8E, 21 },  { 0x7E, 22 },  { 0x7D, 22 },  { 0x84, 21 },
+    { 0x8D, 21 },  { 0x7A, 22 },  { 0x79, 22 },  { 0x4A, 20 },
+    { 0x77, 22 },  { 0x76, 22 },  { 0x89, 21 },  { 0x74, 22 },
+    { 0x73, 22 },  { 0x72, 22 },  { 0x49, 20 },  { 0x70, 22 },
+    { 0x6F, 22 },  { 0x6E, 22 },  { 0x6D, 22 },  { 0x6C, 22 },
+    { 0x6B, 22 },  { 0x6A, 22 },  { 0x69, 22 },  { 0x68, 22 },
+    { 0x67, 22 },  { 0x66, 22 },  { 0x65, 22 },  { 0x64, 22 },
+    { 0x63, 22 },  { 0x62, 22 },  { 0x8A, 21 },  { 0x88, 21 },
+    { 0x5F, 22 },  { 0x5E, 22 },  { 0x5D, 22 },  { 0x85, 21 },
+    { 0x5B, 22 },  { 0x83, 21 },  { 0x59, 22 },  { 0x58, 22 },
+    { 0x57, 22 },  { 0x56, 22 },  { 0x55, 22 },  { 0x54, 22 },
+    { 0x53, 22 },  { 0x52, 22 },  { 0x51, 22 },  { 0x50, 22 },
+    { 0x4F, 22 },  { 0x4E, 22 },  { 0x4D, 22 },  { 0x4C, 22 },
+    { 0x4B, 22 },  { 0x4A, 22 },  { 0x49, 22 },  { 0x48, 22 },
+    { 0x47, 22 },  { 0x46, 22 },  { 0x45, 22 },  { 0x44, 22 },
+    { 0x43, 22 },  { 0x42, 22 },  { 0x41, 22 },  { 0x40, 22 },
+    { 0x3F, 22 },  { 0x3E, 22 },  { 0x3D, 22 },  { 0x3C, 22 },
+    { 0x3B, 22 },  { 0x3A, 22 },  { 0x39, 22 },  { 0x38, 22 },
+    { 0x37, 22 },  { 0x36, 22 },  { 0x35, 22 },  { 0x34, 22 },
+    { 0x33, 22 },  { 0x32, 22 },  { 0x31, 22 },  { 0x30, 22 },
+    { 0x2F, 22 },  { 0x2E, 22 },  { 0x2D, 22 },  { 0x2C, 22 },
+    { 0x2B, 22 },  { 0x2A, 22 },  { 0x29, 22 },  { 0x28, 22 },
+    { 0x27, 22 },  { 0x26, 22 },  { 0x25, 22 },  { 0x24, 22 },
+    { 0x23, 22 },  { 0x22, 22 },  { 0x21, 22 },  { 0x20, 22 },
+    { 0x1F, 22 },  { 0x1E, 22 },  { 0x1D, 22 },  { 0x1C, 22 },
+    { 0x1B, 22 },  { 0x1A, 22 },  { 0x19, 22 },  { 0x18, 22 },
+    { 0x17, 22 },  { 0x16, 22 },  { 0x15, 22 },  { 0x14, 22 },
+    { 0x13, 22 },  { 0x12, 22 },  { 0x11, 22 },  { 0x10, 22 },
+    { 0xF, 22 },  { 0xE, 22 },  { 0xD, 22 },  { 0xC, 22 },
+    { 0xB, 22 },  { 0xA, 22 },  { 0x9, 22 },  { 0x8, 22 },
+    { 0x7, 22 },  { 0x6, 22 },  { 0x5, 22 },  { 0x4, 22 },
+    { 0x3, 22 },  { 0x2, 22 },  { 0x1, 22 },  { 0x0, 22 }
+};
+
+#endif


Commit: e16270605ac2df9a605bd035889950290b83f99d
    https://github.com/scummvm/scummvm/commit/e16270605ac2df9a605bd035889950290b83f99d
Author: D G Turner (digitall at scummvm.org)
Date: 2012-04-07T19:29:04-07:00

Commit Message:
VIDEO: Hookup SVQ1 codec to build system and QT Decoder.

Changed paths:
    video/module.mk
    video/qt_decoder.cpp



diff --git a/video/module.mk b/video/module.mk
index 900a781..cebd403 100644
--- a/video/module.mk
+++ b/video/module.mk
@@ -18,6 +18,7 @@ MODULE_OBJS := \
 	codecs/qtrle.o \
 	codecs/rpza.o \
 	codecs/smc.o \
+	codecs/svq1.o \
 	codecs/truemotion1.o
 
 ifdef USE_BINK
diff --git a/video/qt_decoder.cpp b/video/qt_decoder.cpp
index 7557222..52e1806 100644
--- a/video/qt_decoder.cpp
+++ b/video/qt_decoder.cpp
@@ -46,6 +46,7 @@
 #include "video/codecs/qtrle.h"
 #include "video/codecs/rpza.h"
 #include "video/codecs/smc.h"
+#include "video/codecs/svq1.h"
 #include "video/codecs/cdtoons.h"
 
 
@@ -471,7 +472,7 @@ void QuickTimeDecoder::VideoSampleDesc::initCodec() {
 		break;
 	case MKTAG('S','V','Q','1'):
 		// Sorenson Video 1: Used by some Myst ME videos.
-		warning("Sorenson Video 1 not yet supported");
+		_videoCodec = new SVQ1Decoder(_parentTrack->width, _parentTrack->height);
 		break;
 	case MKTAG('S','V','Q','3'):
 		// Sorenson Video 3: Used by some Myst ME videos.


Commit: da35b9f5f699e3f870b305ba2e8f311d9b72e5b7
    https://github.com/scummvm/scummvm/commit/da35b9f5f699e3f870b305ba2e8f311d9b72e5b7
Author: D G Turner (digitall at scummvm.org)
Date: 2012-04-07T19:29:06-07:00

Commit Message:
VIDEO: Migrate SVQ1 codec WIP to Common::BitStream.

Changed paths:
    video/codecs/svq1.cpp



diff --git a/video/codecs/svq1.cpp b/video/codecs/svq1.cpp
index c63405e..ea617eb 100644
--- a/video/codecs/svq1.cpp
+++ b/video/codecs/svq1.cpp
@@ -28,6 +28,7 @@
 #include "video/codecs/svq1_vlc.h"
 
 #include "common/stream.h"
+#include "common/bitstream.h"
 #include "common/system.h"
 #include "common/debug.h"
 #include "common/textconsole.h"
@@ -36,68 +37,6 @@
 
 namespace Video {
 
-// TODO: Common could do with a good Bitstream Reader Class 
-//       capable of wrapping ReadStream and byte *buffers
-//       This would replace this, a similar class in SMK, QDM2
-//       and probably a number of other similar pieces of code.
-class SVQ1BitStream {
-public:
-	SVQ1BitStream(Common::SeekableReadStream *stream)
-		: _stream(stream), _bitCount(0) {
-	}
-
-	bool getBit();
-	byte getBitsByte(uint n);
-	uint32 getBitsUint32(uint n);
-
-private:
-	Common::SeekableReadStream *_stream;
-
-	byte _curByte;
-	byte  _bitCount;
-};
-
-bool SVQ1BitStream::getBit() {
-	if (_bitCount == 0) {
-		assert(_stream->pos() < _stream->size());
-		_curByte = _stream->readByte();
-		_bitCount = 8;
-	}
-
-	bool v = _curByte & 1;
-
-	_curByte >>= 1;
-	--_bitCount;
-
-	return v;
-}
-
-byte SVQ1BitStream::getBitsByte(uint n) {
-	assert (n <= 8);
-	byte v = 0;
-
-	for (uint i = 0; i < 8; i++) {
-		v >>= 1;
-		if (getBit() && i < n)
-			v |= 0x80;
-	}
-
-	return v;
-}
-
-uint32 SVQ1BitStream::getBitsUint32(uint n) {
-	assert (n <= 32);
-	uint32 v = 0;
-
-	for (uint i = 0; i < 32; i++) {
-		v >>= 1;
-		if (getBit() && i < n)
-			v |= 0x8000;
-	}
-
-	return v;
-}
-
 SVQ1Decoder::SVQ1Decoder(uint16 width, uint16 height) {
 	_surface = new Graphics::Surface();
 	_surface->create(width, height, g_system->getScreenFormat());
@@ -120,9 +59,9 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 	stream->seek(startPos, SEEK_SET);
 #endif
 
-	SVQ1BitStream *frameData = new SVQ1BitStream(stream);
+	Common::BitStream32LELSB frameData(*stream);
 
-	uint32 frameCode = frameData->getBitsUint32(22);
+	uint32 frameCode = frameData.getBits(22);
 	debug(1, " frameCode: %d", frameCode);
 
   if ((frameCode & ~0x70) || !(frameCode & 0x60)) // Invalid
@@ -174,16 +113,16 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 	};
 #endif
 
-	byte temporalReference = frameData->getBitsByte(8);
+	byte temporalReference = frameData.getBits(8);
 	debug(1, " temporalReference: %d", temporalReference);
 	const char* types[4] = { "I Frame", "P Frame", "B Frame", "Invalid" };
-	byte pictureType = frameData->getBitsByte(2);
+	byte pictureType = frameData.getBits(2);
 	debug(1, " pictureType: %d (%s)", pictureType, types[pictureType]);
 	if (pictureType == 3) // Invalid
 		return _surface;
 	else if (pictureType == 0) { // I Frame
 		if (frameCode == 0x50 || frameCode == 0x60) {
-			uint32 checksum = frameData->getBitsUint32(16);
+			uint32 checksum = frameData.getBits(16);
 			debug(1, " checksum:0x%02x", checksum);
 			// TODO: Validate checksum
 			//uint16 calculate_packet_checksum (const uint8 *data, const int length) {
@@ -233,22 +172,22 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 	if ((frameCode ^ 0x10) >= 0x50) {
 		// Decode embedded string
 		Common::String str;
-		uint8 stringLen = frameData->getBitsByte(8);
+		uint8 stringLen = frameData.getBits(8);
 		byte xorVal = stringXORTable[stringLen];
 
 		for (uint16 i = 0; i < stringLen-1; i++) {
-			byte data = frameData->getBitsByte(8);
+			byte data = frameData.getBits(8);
 			str += data ^ xorVal;
 			xorVal = stringXORTable[data];
 		}
 		debug(1, " Embedded String of %d Characters: \"%s\"", stringLen, str.c_str());
 	}
 
-	byte unk1 = frameData->getBitsByte(2); // Unknown
+	byte unk1 = frameData.getBits(2); // Unknown
 	debug(1, "unk1: %d", unk1);
-	byte unk2 = frameData->getBitsByte(2); // Unknown
+	byte unk2 = frameData.getBits(2); // Unknown
 	debug(1, "unk2: %d", unk2);
-	bool unk3 = frameData->getBit(); // Unknown
+	bool unk3 = frameData.getBit(); // Unknown
 	debug(1, "unk3: %d", unk3);
 
 	static const struct { uint w, h; } standardFrameSizes[7] = {
@@ -261,12 +200,12 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 		{ 320, 240 }  // 6
 	};
 
-	byte frameSizeCode = frameData->getBitsByte(3);
+	byte frameSizeCode = frameData.getBits(3);
 	debug(1, " frameSizeCode: %d", frameSizeCode);
 	uint16 frameWidth, frameHeight;
 	if (frameSizeCode == 7) {
-		frameWidth = frameData->getBitsUint32(12);
-		frameHeight = frameData->getBitsUint32(12);
+		frameWidth = frameData.getBits(12);
+		frameHeight = frameData.getBits(12);
 	} else {
 		frameWidth = standardFrameSizes[frameSizeCode].w;
 		frameHeight = standardFrameSizes[frameSizeCode].h;
@@ -276,32 +215,32 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 	if (frameWidth == 0 || frameHeight == 0) // Invalid
 		return _surface;
 
-	bool checksumPresent = frameData->getBit();
+	bool checksumPresent = frameData.getBit();
 	debug(1, " checksumPresent: %d", checksumPresent);
 	if (checksumPresent) {
-		bool usePacketChecksum = frameData->getBit();
+		bool usePacketChecksum = frameData.getBit();
 		debug(1, " usePacketChecksum: %d", usePacketChecksum);
-		bool componentChecksumsAfterImageData = frameData->getBit();
+		bool componentChecksumsAfterImageData = frameData.getBit();
 		debug(1, " componentChecksumsAfterImageData: %d", componentChecksumsAfterImageData);
-		byte unk4 = frameData->getBitsByte(2);
+		byte unk4 = frameData.getBits(2);
 		debug(1, " unk4: %d", unk4);
 		if (unk4 != 0)
 			warning("Invalid Frame Header in SVQ1 Frame Decode");
 	}
 
-	bool unk5 = frameData->getBit();
+	bool unk5 = frameData.getBit();
 	debug(1, " unk5: %d", unk5);
 	if (unk5) {
-		bool unk6 = frameData->getBit();
+		bool unk6 = frameData.getBit();
 		debug(1, " unk6: %d", unk6);
-		byte unk7 = frameData->getBitsByte(4);
+		byte unk7 = frameData.getBits(4);
 		debug(1, " unk7: %d", unk7);
-		bool unk8 = frameData->getBit();
+		bool unk8 = frameData.getBit();
 		debug(1, " unk8: %d", unk8);
-		byte unk9 = frameData->getBitsByte(2);
+		byte unk9 = frameData.getBits(2);
 		debug(1, " unk9: %d", unk9);
-		while (frameData->getBit()) {
-			byte unk10 = frameData->getBitsByte(8);
+		while (frameData.getBit()) {
+			byte unk10 = frameData.getBits(8);
 			debug(1, " unk10: %d", unk10);
 		}
 	}
@@ -319,8 +258,6 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 			vPlane[i] = 0;
 		}
 
-		delete frameData;
-
 		convertYUV410ToRGB(_surface, yPlane, uPlane, vPlane, frameWidth, frameHeight, frameWidth, frameWidth/2);
 	
 		delete[] yPlane;


Commit: 69e76182cbfc33788a010e2cc48d2de39f7aae45
    https://github.com/scummvm/scummvm/commit/69e76182cbfc33788a010e2cc48d2de39f7aae45
Author: D G Turner (digitall at scummvm.org)
Date: 2012-04-07T19:29:09-07:00

Commit Message:
VIDEO: Update SVQ1 WIP with minor corrections.

This mainly fixes the Bitstream to Big Endian, MSB to LSB.

Changed paths:
    video/codecs/svq1.cpp



diff --git a/video/codecs/svq1.cpp b/video/codecs/svq1.cpp
index ea617eb..3973367 100644
--- a/video/codecs/svq1.cpp
+++ b/video/codecs/svq1.cpp
@@ -50,33 +50,26 @@ SVQ1Decoder::~SVQ1Decoder() {
 const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *stream) {
 	debug(1, "SVQ1Decoder::decodeImage()");
 
-	// Debugging Output to compare with output of Bitstream Reader
-#if 1
-	int32 startPos = stream->pos();
-	for (uint32 i = 0; i < 6; i++) {
-		debug(1, " Stream Byte %d: 0x%02x", i, stream->readByte());
-	}
-	stream->seek(startPos, SEEK_SET);
-#endif
-
-	Common::BitStream32LELSB frameData(*stream);
+	Common::BitStream32BEMSB frameData(*stream);
 
 	uint32 frameCode = frameData.getBits(22);
 	debug(1, " frameCode: %d", frameCode);
 
-  if ((frameCode & ~0x70) || !(frameCode & 0x60)) // Invalid
-    return _surface;
+	if ((frameCode & ~0x70) || !(frameCode & 0x60)) { // Invalid
+		warning("Invalid Image at frameCode");
+		return _surface;
+	}
 
-  // swap some header bytes (why?)
-  //if (frameCode != 0x20) {
-  //  uint32 *src = stream;
+	// swap some header bytes (why?)
+	//if (frameCode != 0x20) {
+	//  uint32 *src = stream;
 	//
-  //  for (i = 4; i < 8; i++) {
-  //    src[i] = ((src[i] << 16) | (src[i] >> 16)) ^ src[7 - i];
-  // }
-  //}
+	//  for (i = 4; i < 8; i++) {
+	//    src[i] = ((src[i] << 16) | (src[i] >> 16)) ^ src[7 - i];
+	// }
+	//}
 
-#if 0
+#ifdef 0
 	static const uint16 checksum_table[256] = {
 		0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
 		0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
@@ -118,8 +111,10 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 	const char* types[4] = { "I Frame", "P Frame", "B Frame", "Invalid" };
 	byte pictureType = frameData.getBits(2);
 	debug(1, " pictureType: %d (%s)", pictureType, types[pictureType]);
-	if (pictureType == 3) // Invalid
+	if (pictureType == 3) { // Invalid
+		warning("Invalid pictureType");
 		return _surface;
+	}
 	else if (pictureType == 0) { // I Frame
 		if (frameCode == 0x50 || frameCode == 0x60) {
 			uint32 checksum = frameData.getBits(16);
@@ -127,10 +122,8 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 			// TODO: Validate checksum
 			//uint16 calculate_packet_checksum (const uint8 *data, const int length) {
 			//  int value;
-  		//	for (int i = 0; i < length; i++)
-    	//		value = checksum_table[data[i] ^ (value >> 8)] ^ ((value & 0xFF) << 8);
-  		//	return value;
-			//}
+  			//for (int i = 0; i < length; i++)
+    			//	value = checksum_table[data[i] ^ (value >> 8)] ^ ((value & 0xFF) << 8);
 		}
 	}
 
@@ -184,11 +177,11 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 	}
 
 	byte unk1 = frameData.getBits(2); // Unknown
-	debug(1, "unk1: %d", unk1);
+	debug(1, " unk1: %d", unk1);
 	byte unk2 = frameData.getBits(2); // Unknown
-	debug(1, "unk2: %d", unk2);
+	debug(1, " unk2: %d", unk2);
 	bool unk3 = frameData.getBit(); // Unknown
-	debug(1, "unk3: %d", unk3);
+	debug(1, " unk3: %d", unk3);
 
 	static const struct { uint w, h; } standardFrameSizes[7] = {
 		{ 160, 120 }, // 0


Commit: 9330a7c54db8782b399f747f882d641b85122513
    https://github.com/scummvm/scummvm/commit/9330a7c54db8782b399f747f882d641b85122513
Author: D G Turner (digitall at scummvm.org)
Date: 2012-04-07T19:29:11-07:00

Commit Message:
VIDEO: Corrected minor mistake in SVQ1 decoder.

Changed paths:
    video/codecs/svq1.cpp



diff --git a/video/codecs/svq1.cpp b/video/codecs/svq1.cpp
index 3973367..056e9e0 100644
--- a/video/codecs/svq1.cpp
+++ b/video/codecs/svq1.cpp
@@ -69,7 +69,7 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 	// }
 	//}
 
-#ifdef 0
+#if 0
 	static const uint16 checksum_table[256] = {
 		0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
 		0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,


Commit: b99565d701dd2dc9b355b0d43b4d8119c2b1085e
    https://github.com/scummvm/scummvm/commit/b99565d701dd2dc9b355b0d43b4d8119c2b1085e
Author: D G Turner (digitall at scummvm.org)
Date: 2012-04-07T19:29:14-07:00

Commit Message:
VIDEO: Add remaining SVQ1 code derived from FFMPEG.

This still requires some work to make it usuable, mainly changing the
Variable Length Code reader to work with Common::BitStream input.

Changed paths:
    video/codecs/svq1.cpp
    video/codecs/svq1.h
    video/codecs/svq1_cb.h
    video/codecs/svq1_vlc.h



diff --git a/video/codecs/svq1.cpp b/video/codecs/svq1.cpp
index 056e9e0..8d3673b 100644
--- a/video/codecs/svq1.cpp
+++ b/video/codecs/svq1.cpp
@@ -29,6 +29,7 @@
 
 #include "common/stream.h"
 #include "common/bitstream.h"
+#include "common/rect.h"
 #include "common/system.h"
 #include "common/debug.h"
 #include "common/textconsole.h"
@@ -37,14 +38,771 @@
 
 namespace Video {
 
+#define SVQ1_BLOCK_SKIP     0
+#define SVQ1_BLOCK_INTER    1
+#define SVQ1_BLOCK_INTER_4V 2
+#define SVQ1_BLOCK_INTRA    3
+
+struct VLC {
+	int32 bits;
+	int16 (*table)[2]; // code, bits
+	int32 table_size;
+	int32 table_allocated;
+};
+
+/**
+ * parses a vlc code, faster then get_vlc()
+ * @param bits is the number of bits which will be read at once, must be
+ *             identical to nb_bits in init_vlc()
+ * @param max_depth is the number of times bits bits must be read to completely
+ *                  read the longest vlc code
+ *                  = (max_vlc_length + bits - 1) / bits
+ */
+static int getVlc2(Common::BitStream *s, int16 (*table)[2], int bits, int maxDepth) {
+	//FIXME - Change this code to working with BitStream...
+	//GetBitContext *s
+	//int reIndex;
+	//int reCache;
+	//int index;
+	int code = 0;
+	//int n;
+
+/* FIXME
+	reIndex = s->index;
+	reCache = READ_LE_UINT32(s->buffer + (reIndex >> 3)) >> (reIndex & 0x07);
+	index = reCache & (0xffffffff >> (32 - bits));
+	code = table[index][0];
+	n = table[index][1];
+
+	if (maxDepth > 1 && n < 0){
+		reIndex += bits;
+		reCache = READ_LE_UINT32(s->buffer + (reIndex >> 3)) >> (reIndex & 0x07);
+
+		int nbBits = -n;
+
+		index = (reCache & (0xffffffff >> (32 - nbBits))) + code;
+		code = table[index][0];
+		n = table[index][1];
+
+		if(maxDepth > 2 && n < 0) {
+			reIndex += nbBits;
+			reCache = READ_LE_UINT32(s->buffer + (reIndex >> 3)) >> (reIndex & 0x07);
+
+			nbBits = -n;
+
+			index = (reCache & (0xffffffff >> (32 - nbBits))) + code;
+			code = table[index][0];
+			n = table[index][1];
+		}
+	}
+
+	reCache >>= n;
+	s->index = reIndex + n;
+*/
+	return code;
+}
+
+static int allocTable(VLC *vlc, int size, int use_static) {
+	int index;
+	int16 (*temp)[2] = NULL;
+	index = vlc->table_size;
+	vlc->table_size += size;
+	if (vlc->table_size > vlc->table_allocated) {
+		if(use_static)
+			error("SVQ1 cant do anything, init_vlc() is used with too little memory");
+		vlc->table_allocated += (1 << vlc->bits);
+		temp = (int16 (*)[2])realloc(vlc->table, sizeof(int16 *) * 2 * vlc->table_allocated);
+		if (!temp) {
+			free(vlc->table);
+			vlc->table = NULL;
+			return -1;
+		}
+		vlc->table = temp;
+	}
+	return index;
+}
+
+static VLC svq1_block_type;
+static VLC svq1_motion_component;
+static VLC svq1_intra_multistage[6];
+static VLC svq1_inter_multistage[6];
+static VLC svq1_intra_mean;
+static VLC svq1_inter_mean;
+
+static int svq1DecodeBlockIntra(Common::BitStream *s, uint8 *pixels, int pitch) {
+	uint8 *list[63];
+	uint32 *dst;
+	int entries[6];
+	int i, j, m, n;
+	int mean, stages;
+	unsigned int x, y, width, height, level;
+	uint32 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()
+		for (; level > 0; i++) {
+			// process next depth
+			if (i == m) {
+				m = n;
+				if (--level == 0)
+					break;
+			}
+			// divide block if next bit set
+			if (s->getBit() == 0)
+				break;
+			// add child nodes
+			list[n++] = list[i];
+			list[n++] = list[i] + (((level & 1) ? pitch : 1) << ((level / 2) + 1));
+		}
+
+		// destination address and vector size
+		dst = (uint32 *) list[i];
+		width = 1 << ((4 + level) /2);
+		height = 1 << ((3 + level) /2);
+
+		// get number of stages (-1 skips vector, 0 for mean only)
+		stages = getVlc2(s, svq1_intra_multistage[level].table, 3, 3) - 1;
+
+		if (stages == -1) {
+			for (y=0; y < height; y++) {
+				memset (&dst[y*(pitch / 4)], 0, width);
+			}
+		continue; // skip vector
+		}
+
+		if ((stages > 0) && (level >= 4)) {
+			warning("Error (svq1_decode_block_intra): invalid vector: stages=%i level=%i", stages, level);
+		return -1; // invalid vector
+		}
+
+		mean = getVlc2(s, svq1_intra_mean.table, 8, 3);
+
+		if (stages == 0) {
+			for (y=0; y < height; y++) {
+				memset (&dst[y*(pitch / 4)], mean, width);
+			}
+		} else {
+			// SVQ1_CALC_CODEBOOK_ENTRIES(svq1_intra_codebooks);
+			const uint32 *codebook = (const uint32 *) svq1_intra_codebooks[level];
+			uint32 bit_cache = s->getBits(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);
+
+			// 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()
+					// 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);
+					}
+
+					// store result
+					dst[x] = (n1 << 8) | n2;
+				}
+				dst += (pitch / 4);
+			}
+		}
+	}
+
+	return 0;
+}
+
+static int svq1DecodeBlockNonIntra(Common::BitStream *s, uint8 *pixels, int pitch) {
+	uint8 *list[63];
+	uint32 *dst;
+	int entries[6];
+	int i, j, m, n;
+	int mean, stages;
+	int x, y, width, height, level;
+	uint32 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()
+		for (; level > 0; i++) {
+			// process next depth
+			if (i == m) {
+				m = n;
+				if (--level == 0)
+					break;
+			}
+			// divide block if next bit set
+			if (s->getBit() == 0)
+				break;
+			// add child nodes
+			list[n++] = list[i];
+			list[n++] = list[i] + (((level & 1) ? pitch : 1) << ((level / 2) + 1));
+		}
+
+		// destination address and vector size
+		dst = (uint32 *) list[i];
+		width = 1 << ((4 + level) /2);
+		height = 1 << ((3 + level) /2);
+
+		// get number of stages (-1 skips vector, 0 for mean only)
+		stages = getVlc2(s, svq1_inter_multistage[level].table, 3, 2) - 1;
+
+		if (stages == -1) continue; // skip vector
+
+		if ((stages > 0) && (level >= 4)) {
+			warning("Error (svq1_decode_block_non_intra): invalid vector: stages=%i level=%i", stages, level);
+			return -1;        // invalid vector
+		}
+
+		mean = getVlc2(s, svq1_inter_mean.table, 9, 3) - 256;
+
+		// SVQ1_CALC_CODEBOOK_ENTRIES(svq1_inter_codebooks);
+		const uint32 *codebook = (const uint32 *) svq1_inter_codebooks[level];
+		uint32 bit_cache = s->getBits(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);
+
+		// 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()
+				// 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);
+				}
+
+				// store result
+				dst[x] = (n1 << 8) | n2;
+			}
+			dst += (pitch / 4);
+		}
+	}
+	return 0;
+}
+
+// median of 3
+static inline int mid_pred(int a, int b, int c) {
+	if (a > b) {
+		if (c > b) {
+			if (c > a) b = a;
+			else b = c;
+		}
+	} else {
+		if (b > c) {
+			if (c > a) b = c;
+			else b = a;
+		}
+	}
+	return b;
+}
+
+static int svq1DecodeMotionVector(Common::BitStream *s, Common::Point *mv, Common::Point **pmv) {
+	for (int i=0; i < 2; i++) {
+		// get motion code
+		int diff = getVlc2(s, svq1_motion_component.table, 7, 2);
+		if (diff < 0)
+			return -1;
+		else if (diff) {
+			if (s->getBit()) diff= -diff;
+		}
+
+		// add median of motion vector predictors and clip result
+		if (i == 1)
+			mv->y = ((diff + mid_pred(pmv[0]->y, pmv[1]->y, pmv[2]->y)) << 26) >> 26;
+		else
+			mv->x = ((diff + mid_pred(pmv[0]->x, pmv[1]->x, pmv[2]->x)) << 26) >> 26;
+	}
+
+	return 0;
+}
+
+static void svq1SkipBlock(uint8 *current, uint8 *previous, int pitch, int x, int y) {
+	uint8 *src;
+	uint8 *dst;
+
+	src = &previous[x + y*pitch];
+	dst = current;
+
+	for (int i = 0; i < 16; i++) {
+		memcpy(dst, src, 16);
+		src += pitch;
+		dst += pitch;
+	}
+}
+
+static int svq1MotionInterBlock(Common::BitStream *ss,
+                                uint8 *current, uint8 *previous, int pitch,
+                                Common::Point *motion, int x, int y) {
+	uint8 *src;
+	uint8 *dst;
+	Common::Point mv;
+	Common::Point *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 = svq1DecodeMotionVector(ss, &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;
+
+	if(y + (mv.y >> 1)<0)
+		mv.y= 0;
+	if(x + (mv.x >> 1)<0)
+		mv.x= 0;
+
+#if 0
+	int w = (s->width+15)&~15;
+	int h = (s->height+15)&~15;
+	if(x + (mv.x >> 1)<0 || y + (mv.y >> 1)<0 || x + (mv.x >> 1) + 16 > w || y + (mv.y >> 1) + 16> h)
+		debug(1, "%d %d %d %d", x, y, x + (mv.x >> 1), y + (mv.y >> 1));
+#endif
+
+	src = &previous[(x + (mv.x >> 1)) + (y + (mv.y >> 1))*pitch];
+	dst = current;
+
+	// FIXME
+	//MpegEncContext *s
+	//s->dsp.put_pixels_tab[0][((mv.y & 1) << 1) | (mv.x & 1)](dst,src,pitch,16);
+
+	return 0;
+}
+
+static int svq1MotionInter4vBlock(Common::BitStream *ss,
+                                  uint8 *current, uint8 *previous, int pitch,
+                                  Common::Point *motion, int x, int y) {
+	uint8 *src;
+	uint8 *dst;
+	Common::Point mv;
+	Common::Point *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 = svq1DecodeMotionVector(ss, &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 = svq1DecodeMotionVector(ss, &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 = svq1DecodeMotionVector(ss, &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 = svq1DecodeMotionVector(ss, pmv[3], pmv);
+
+	if (result != 0)
+		return result;
+
+	// form predictions
+	for (i=0; i < 4; i++) {
+		int mvx = pmv[i]->x + (i&1)*16;
+		int mvy = pmv[i]->y + (i>>1)*16;
+
+		///XXX /FIXME clipping or padding?
+		if(y + (mvy >> 1)<0)
+			mvy = 0;
+		if(x + (mvx >> 1)<0)
+			mvx = 0;
+
+#if 0
+		int w = (s->width+15)&~15;
+		int h = (s->height+15)&~15;
+		if(x + (mvx >> 1)<0 || y + (mvy >> 1)<0 || x + (mvx >> 1) + 8 > w || y + (mvy >> 1) + 8> h)
+			debug(1, "%d %d %d %d", x, y, x + (mvx >> 1), y + (mvy >> 1));
+#endif
+		src = &previous[(x + (mvx >> 1)) + (y + (mvy >> 1))*pitch];
+		dst = current;
+
+		// FIXME
+		//MpegEncContext *s
+		//s->dsp.put_pixels_tab[1][((mvy & 1) << 1) | (mvx & 1)](dst,src,pitch,8);
+
+		// select next block
+		if (i & 1) {
+			current  += 8*(pitch - 1);
+		} else {
+			current  += 8;
+		}
+	}
+
+	return 0;
+}
+
+static int svq1DecodeDeltaBlock(Common::BitStream *ss,
+                        uint8 *current, uint8 *previous, int pitch,
+                        Common::Point *motion, int x, int y) {
+	uint32 block_type;
+	int result = 0;
+
+	// get block type
+	block_type = getVlc2(ss, svq1_block_type.table, 2, 2);
+
+	// 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:
+		svq1SkipBlock(current, previous, pitch, x, y);
+		break;
+
+	case SVQ1_BLOCK_INTER:
+		result = svq1MotionInterBlock(ss, current, previous, pitch, motion, x, y);
+		if (result != 0) {
+			warning("Error in svq1MotionInterBlock %i", result);
+			break;
+		}
+		result = svq1DecodeBlockNonIntra(ss, current, pitch);
+		break;
+
+	case SVQ1_BLOCK_INTER_4V:
+		result = svq1MotionInter4vBlock(ss, current, previous, pitch, motion, x, y);
+		if (result != 0) {
+			warning("Error in svq1MotionInter4vBlock %i", result);
+			break;
+		}
+		result = svq1DecodeBlockNonIntra(ss, current, pitch);
+		break;
+
+	case SVQ1_BLOCK_INTRA:
+		result = svq1DecodeBlockIntra(ss, current, pitch);
+		break;
+	}
+
+	return result;
+}
+
+#define GET_DATA(v, table, i, wrap, size)\
+{\
+	const uint8 *ptr = (const uint8 *)table + i * wrap;\
+	switch(size) {\
+		case 1:\
+			v = *(const uint8 *)ptr;\
+			break;\
+		case 2:\
+			v = *(const uint16 *)ptr;\
+			break;\
+		default:\
+			v = *(const uint32 *)ptr;\
+			break;\
+	}\
+}
+
+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,
+                       const void *symbols, int symbols_wrap, int symbols_size,
+                       int code_prefix, int n_prefix, int flags)
+{
+	int i, j, k, n, table_size, table_index, nb, n1, index, code_prefix2, symbol;
+	uint32 code;
+	int16 (*table)[2];
+
+	table_size = 1 << table_nb_bits;
+	table_index = allocTable(vlc, table_size, flags & 4);
+	if (table_index < 0)
+		return -1;
+	table = &vlc->table[table_index];
+
+	for(i = 0; i < table_size; i++) {
+		table[i][1] = 0; //bits
+		table[i][0] = -1; //codes
+	}
+
+	// first pass: map codes and compute auxillary table sizes
+	for(i = 0; i < nb_codes; i++) {
+		GET_DATA(n, bits, i, bits_wrap, bits_size);
+		GET_DATA(code, codes, i, codes_wrap, codes_size);
+		// we accept tables with holes
+		if (n <= 0)
+			continue;
+		if (!symbols)
+			symbol = i;
+		else
+			GET_DATA(symbol, symbols, i, symbols_wrap, symbols_size);
+		// if code matches the prefix, it is in the table
+		n -= n_prefix;
+		if(flags & 2)
+			code_prefix2= code & (n_prefix>=32 ? 0xffffffff : (1 << n_prefix)-1);
+		else
+			code_prefix2= code >> n;
+		if (n > 0 && code_prefix2 == code_prefix) {
+			if (n <= table_nb_bits) {
+				// no need to add another table
+				j = (code << (table_nb_bits - n)) & (table_size - 1);
+				nb = 1 << (table_nb_bits - n);
+				for(k = 0; k < nb; k++) {
+					if(flags & 2)
+						j = (code >> n_prefix) + (k<<n);
+					if (table[j][1] /*bits*/ != 0) {
+						error("SVQ1 incorrect codes");
+						return -1;
+					}
+					table[j][1] = n; //bits
+					table[j][0] = symbol;
+					j++;
+				}
+			} else {
+				n -= table_nb_bits;
+				j = (code >> ((flags & 2) ? n_prefix : n)) & ((1 << table_nb_bits) - 1);
+				// compute table size
+				n1 = -table[j][1]; //bits
+				if (n > n1)
+					n1 = n;
+				table[j][1] = -n1; //bits
+			}
+		}
+	}
+
+	// second pass : fill auxillary tables recursively
+	for(i = 0;i < table_size; i++) {
+		n = table[i][1]; //bits
+		if (n < 0) {
+			n = -n;
+			if (n > table_nb_bits) {
+				n = table_nb_bits;
+				table[i][1] = -n; //bits
+			}
+			index = build_table(vlc, n, nb_codes,
+			                    bits, bits_wrap, bits_size,
+			                    codes, codes_wrap, codes_size,
+			                    symbols, symbols_wrap, symbols_size,
+			                    (flags & 2) ? (code_prefix | (i << n_prefix)) : ((code_prefix << table_nb_bits) | i),
+			                    n_prefix + table_nb_bits, flags);
+ 			if (index < 0)
+				return -1;
+			// note: realloc has been done, so reload tables
+			table = &vlc->table[table_index];
+			table[i][0] = index; //code
+		}
+	}
+	return table_index;
+}
+
+/* Build VLC decoding tables suitable for use with get_vlc().
+
+   'nb_bits' set thee decoding table size (2^nb_bits) entries. The
+   bigger it is, the faster is the decoding. But it should not be too
+   big to save memory and L1 cache. '9' is a good compromise.
+
+   'nb_codes' : number of vlcs codes
+
+   'bits' : table which gives the size (in bits) of each vlc code.
+
+   'codes' : table which gives the bit pattern of of each vlc code.
+
+   'symbols' : table which gives the values to be returned from get_vlc().
+
+   'xxx_wrap' : give the number of bytes between each entry of the
+   'bits' or 'codes' tables.
+
+   'xxx_size' : gives the number of bytes of each entry of the 'bits'
+   or 'codes' tables.
+
+   'wrap' and 'size' allows to use any memory configuration and types
+   (byte/word/long) to store the 'bits', 'codes', and 'symbols' tables.
+
+   'use_static' should be set to 1 for tables, which should be freed
+   with av_free_static(), 0 if free_vlc() will be used.
+*/
+void initVlcSparse(VLC *vlc, int nb_bits, int nb_codes,
+		const void *bits, int bits_wrap, int bits_size,
+		const void *codes, int codes_wrap, int codes_size,
+		const void *symbols, int symbols_wrap, int symbols_size) {
+	vlc->bits = nb_bits;
+
+	if(vlc->table_size && vlc->table_size == vlc->table_allocated) {
+		return;
+	} else if(vlc->table_size) {
+		error("called on a partially initialized table");
+	}
+
+	if (build_table(vlc, nb_bits, nb_codes,
+	                bits, bits_wrap, bits_size,
+	                codes, codes_wrap, codes_size,
+	                symbols, symbols_wrap, symbols_size,
+	                0, 0, 4 | 2) < 0) {
+		free(&vlc->table);
+		return; // Error
+	}
+
+	if(vlc->table_size != vlc->table_allocated)
+		error("SVQ1 needed %d had %d", vlc->table_size, vlc->table_allocated);
+}
+
 SVQ1Decoder::SVQ1Decoder(uint16 width, uint16 height) {
 	_surface = new Graphics::Surface();
 	_surface->create(width, height, g_system->getScreenFormat());
+
+	_current[0] = new byte[width*height];
+	_current[1] = new byte[(width/4)*(height/4)];
+	_current[2] = new byte[(width/4)*(height/4)];
+
+	_last[0] = 0;
+	_last[1] = 0;
+	_last[2] = 0;
+
+	// Setup Variable Length Code Tables
+	static int16 tableA[6][2];
+	svq1_block_type.table = tableA;
+	svq1_block_type.table_allocated = 6;
+	initVlcSparse(&svq1_block_type, 2, 4, 
+	        &svq1_block_type_vlc[0][1], 2, 1, 
+	        &svq1_block_type_vlc[0][0], 2, 1, NULL, 0, 0);
+
+	static int16 tableB[176][2];
+	svq1_motion_component.table = tableB;
+	svq1_motion_component.table_allocated = 176;
+	initVlcSparse(&svq1_motion_component, 7, 33, 
+	        &mvtab[0][1], 2, 1, 
+	        &mvtab[0][0], 2, 1, NULL, 0, 0);
+
+	uint16 offset = 0;
+	for (uint8 i = 0; i < 6; i++) {
+		static const uint8 sizes[2][6] = {{14, 10, 14, 18, 16, 18}, {10, 10, 14, 14, 14, 16}};
+		static int16 tableC[168][2];
+
+		svq1_intra_multistage[i].table = &tableC[offset];
+		svq1_intra_multistage[i].table_allocated = sizes[0][i];
+		offset += sizes[0][i];
+		initVlcSparse(&svq1_intra_multistage[i], 3, 8, 
+		         &svq1_intra_multistage_vlc[i][0][1], 2, 1,
+		         &svq1_intra_multistage_vlc[i][0][0], 2, 1, NULL, 0, 0);
+
+		svq1_inter_multistage[i].table = &tableC[offset];
+		svq1_inter_multistage[i].table_allocated = sizes[1][i];
+		offset += sizes[1][i];
+		initVlcSparse(&svq1_inter_multistage[i], 3, 8,
+		         &svq1_inter_multistage_vlc[i][0][1], 2, 1,
+		         &svq1_inter_multistage_vlc[i][0][0], 2, 1, NULL, 0, 0);
+	}
+
+	static int16 tableD[632][2];
+	svq1_intra_mean.table = tableD;
+	svq1_intra_mean.table_allocated = 632;
+	initVlcSparse(&svq1_intra_mean, 8, 256, 
+	        &svq1_intra_mean_vlc[0][1], 4, 2, 
+	        &svq1_intra_mean_vlc[0][0], 4, 2, NULL, 0, 0);
+
+	static int16 tableE[1434][2];
+	svq1_inter_mean.table = tableE;
+	svq1_inter_mean.table_allocated = 1434;
+	initVlcSparse(&svq1_inter_mean, 9, 512, 
+	        &svq1_inter_mean_vlc[0][1], 4, 2, 
+	        &svq1_inter_mean_vlc[0][0], 4, 2, NULL, 0, 0);
 }
 
 SVQ1Decoder::~SVQ1Decoder() {
 	_surface->free();
 	delete _surface;
+
+	delete[] _current[0];
+	delete[] _current[1];
+	delete[] _current[2];
+
+	delete[] _last[0];
+	delete[] _last[1];
+	delete[] _last[2];
 }
 
 const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *stream) {
@@ -108,23 +866,25 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 
 	byte temporalReference = frameData.getBits(8);
 	debug(1, " temporalReference: %d", temporalReference);
-	const char* types[4] = { "I Frame", "P Frame", "B Frame", "Invalid" };
-	byte pictureType = frameData.getBits(2);
-	debug(1, " pictureType: %d (%s)", pictureType, types[pictureType]);
-	if (pictureType == 3) { // Invalid
-		warning("Invalid pictureType");
-		return _surface;
-	}
-	else if (pictureType == 0) { // I Frame
+	const char* types[4] = { "I (Key)", "P (Delta from Previous)", "B (Delta from Next)", "Invalid" };
+	byte frameType = frameData.getBits(2);
+	debug(1, " frameType: %d = %s Frame", frameType, types[frameType]);
+	if (frameType == 0) { // I Frame
+		// TODO: Validate checksum if present
 		if (frameCode == 0x50 || frameCode == 0x60) {
 			uint32 checksum = frameData.getBits(16);
 			debug(1, " checksum:0x%02x", checksum);
-			// TODO: Validate checksum
 			//uint16 calculate_packet_checksum (const uint8 *data, const int length) {
 			//  int value;
-  			//for (int i = 0; i < length; i++)
-    			//	value = checksum_table[data[i] ^ (value >> 8)] ^ ((value & 0xFF) << 8);
+			//for (int i = 0; i < length; i++)
+				//	value = checksum_table[data[i] ^ (value >> 8)] ^ ((value & 0xFF) << 8);
 		}
+	} else if (frameType == 2) { // B Frame
+		warning("B Frames not supported by SVQ1 decoder");
+		return _surface;
+	} else if (frameType == 3) { // Invalid
+		warning("Invalid Frame Type");
+		return _surface;
 	}
 
 	static const uint8 stringXORTable[256] = {
@@ -188,7 +948,7 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 		{ 128,  96 }, // 1
 		{ 176, 144 }, // 2
 		{ 352, 288 }, // 3
-	  { 704, 576 }, // 4
+		{ 704, 576 }, // 4
 		{ 240, 180 }, // 5
 		{ 320, 240 }  // 6
 	};
@@ -205,9 +965,10 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 	}
 	debug(1, " frameWidth: %d", frameWidth);
 	debug(1, " frameHeight: %d", frameHeight);
-	if (frameWidth == 0 || frameHeight == 0) // Invalid
+	if (frameWidth == 0 || frameHeight == 0) { // Invalid
+		warning("Invalid Frame Size");
 		return _surface;
-
+	}
 	bool checksumPresent = frameData.getBit();
 	debug(1, " checksumPresent: %d", checksumPresent);
 	if (checksumPresent) {
@@ -238,24 +999,89 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 		}
 	}
 
-	if (frameWidth <= _surface->w && frameHeight <= _surface->h) {
-		byte *yPlane = new byte[frameWidth*frameHeight];
-		byte *uPlane = new byte[(frameWidth/2)*(frameHeight/2)];
-		byte *vPlane = new byte[(frameWidth/2)*(frameHeight/2)];
-
-		// TODO: Read Plane Data
-		for (uint32 i = 0; i < frameWidth*frameHeight; i++)
-			yPlane[i] = 0;
-		for (uint32 i = 0; i < (frameWidth/2)*(frameHeight/2); i++) {
-			uPlane[i] = 0;
-			vPlane[i] = 0;
+	if (frameWidth == _surface->w && frameHeight == _surface->h) {
+		// Decode Y, U and V component planes
+		for (int i = 0; i < 3; i++) {
+			int linesize, width, height;
+			if (i == 0) {
+				// Y Size is width * height
+				width  = frameWidth;
+				if (width % 16) {
+					width /= 16;
+					width++;
+					width *= 16;
+				}
+				assert(width % 16 == 0);
+				height = frameHeight;
+				if (height % 16) {
+					height /= 16;
+					height++;
+					height *= 16;
+				}
+				assert(height % 16 == 0);
+				linesize = width;
+			} else {
+				// U and V size is width/4 * height/4
+				width  = frameWidth/4;
+				if (width % 16) {
+					width /= 16;
+					width++;
+					width *= 16;
+				}
+				assert(width % 16 == 0);
+				height = frameHeight/4;
+				if (height % 16) {
+					height /= 16;
+					height++;
+					height *= 16;
+				}
+				assert(height % 16 == 0);
+				linesize = width;
+			}
+
+			if (frameType == 0) { // I Frame
+				// Keyframe (I)
+				byte *current = _current[i];
+				for (uint16 y = 0; y < height; y += 16) {
+					for (uint16 x = 0; x < width; x += 16) {
+						if (int result = svq1DecodeBlockIntra(&frameData, &current[x], linesize) != 0) {
+							warning("Error in svq1DecodeBlock %i (keyframe)", result);
+							return _surface;
+						}
+					}
+					current += 16 * linesize;
+				}
+			} else {
+				// Delta frame (P or B)
+
+				// Prediction Motion Vector
+				Common::Point *pmv = new Common::Point[(width/8) + 3];
+
+				byte *previous;
+				if(frameType == 2) { // B Frame
+					warning("B Frame not supported currently");
+					//previous = _next[i];
+				} else
+					previous = _last[i];
+
+				byte *current = _current[i];
+				for (uint16 y = 0; y < height; y += 16) {
+					for (uint16 x = 0; x < width; x += 16) {
+						if (int result = svq1DecodeDeltaBlock(&frameData, &current[x], previous, linesize, pmv, x, y) != 0) {
+							warning("Error in svq1DecodeDeltaBlock %i", result);
+							return _surface;
+						}
+					}
+
+					pmv[0].x = pmv[0].y = 0;
+
+					current += 16*linesize;
+				}
+				delete[] pmv;
+			}
 		}
 
-		convertYUV410ToRGB(_surface, yPlane, uPlane, vPlane, frameWidth, frameHeight, frameWidth, frameWidth/2);
-	
-		delete[] yPlane;
-		delete[] uPlane;
-		delete[] vPlane;
+		convertYUV410ToRGB(_surface, _current[0], _current[1], _current[2], frameWidth, frameHeight, frameWidth, frameWidth/2);
 	} else
 		warning("FrameWidth/Height Sanity Check Failed!");
 
diff --git a/video/codecs/svq1.h b/video/codecs/svq1.h
index f2b7ddf..786a2bb 100644
--- a/video/codecs/svq1.h
+++ b/video/codecs/svq1.h
@@ -37,6 +37,9 @@ public:
 
 private:
 	Graphics::Surface *_surface;
+
+	byte *_current[3];
+	byte *_last[3];
 };
 
 } // End of namespace Video
diff --git a/video/codecs/svq1_cb.h b/video/codecs/svq1_cb.h
index e34fe3a..4eaf323 100644
--- a/video/codecs/svq1_cb.h
+++ b/video/codecs/svq1_cb.h
@@ -760,7 +760,7 @@ static const int8 svq1_inter_codebook_8x8[6144] = {
 };
 
 // list of codebooks for inter-coded vectors
-const int8_t* const ff_svq1_inter_codebooks[6] = {
+const int8_t* const svq1_inter_codebooks[6] = {
     svq1_inter_codebook_4x2, svq1_inter_codebook_4x4,
     svq1_inter_codebook_8x4, svq1_inter_codebook_8x8,
     NULL, NULL,
@@ -1503,7 +1503,7 @@ static const int8 svq1_intra_codebook_8x8[6144] = {
 };
 
 // list of codebooks for intra-coded vectors/
-const int8* const ff_svq1_intra_codebooks[6] = {
+const int8* const svq1_intra_codebooks[6] = {
     svq1_intra_codebook_4x2, svq1_intra_codebook_4x4,
     svq1_intra_codebook_8x4, svq1_intra_codebook_8x8,
     NULL, NULL,
diff --git a/video/codecs/svq1_vlc.h b/video/codecs/svq1_vlc.h
index 1694ce3..0b9477f 100644
--- a/video/codecs/svq1_vlc.h
+++ b/video/codecs/svq1_vlc.h
@@ -24,14 +24,14 @@
 #define VIDEO_CODECS_SVQ1_VLC_H
 
 // values in this table range from 0..3; adjust retrieved value by +0
-const uint8 ff_svq1_block_type_vlc[4][2] = {
+const uint8 svq1_block_type_vlc[4][2] = {
  // { code, length }
     { 0x1, 1 },  { 0x1, 2 },  { 0x1, 3 },  { 0x0, 3 }
 
 };
 
 // values in this table range from -1..6; adjust retrieved value by -1
-const uint8 ff_svq1_intra_multistage_vlc[6][8][2] = {
+const uint8 svq1_intra_multistage_vlc[6][8][2] = {
  // { code, length }
 {
     { 0x1, 5 },  { 0x1, 1 },  { 0x3, 3 },  { 0x2, 3 },
@@ -55,7 +55,7 @@ const uint8 ff_svq1_intra_multistage_vlc[6][8][2] = {
 };
 
 // values in this table range from -1..6; adjust retrieved value by -1
-const uint8 ff_svq1_inter_multistage_vlc[6][8][2] = {
+const uint8 svq1_inter_multistage_vlc[6][8][2] = {
  // { code, length }
 {
     { 0x3, 2 },  { 0x5, 3 },  { 0x4, 3 },  { 0x3, 3 },
@@ -79,7 +79,7 @@ const uint8 ff_svq1_inter_multistage_vlc[6][8][2] = {
 };
 
 // values in this table range from 0..255; adjust retrieved value by +0
-const uint16 ff_svq1_intra_mean_vlc[256][2] = {
+const uint16 svq1_intra_mean_vlc[256][2] = {
  // { code, length }
     { 0x37, 6 },  { 0x56, 7 },  { 0x1, 17 },  { 0x1, 20 },
     { 0x2, 20 },  { 0x3, 20 },  { 0x0, 20 },  { 0x4, 20 },
@@ -148,7 +148,7 @@ const uint16 ff_svq1_intra_mean_vlc[256][2] = {
 };
 
 // values in this table range from -256..255; adjust retrieved value by -256
-const uint16 ff_svq1_inter_mean_vlc[512][2] = {
+const uint16 svq1_inter_mean_vlc[512][2] = {
  // { code, length }
     { 0x5A, 22 },  { 0xD4, 22 },  { 0xD5, 22 },  { 0xD6, 22 },
     { 0xD7, 22 },  { 0xD8, 22 },  { 0xD9, 22 },  { 0xDA, 22 },
@@ -280,4 +280,15 @@ const uint16 ff_svq1_inter_mean_vlc[512][2] = {
     { 0x3, 22 },  { 0x2, 22 },  { 0x1, 22 },  { 0x0, 22 }
 };
 
+// From H263 Data Tables
+const uint8 mvtab[33][2] =
+{
+  {1,1}, {1,2}, {1,3}, {1,4}, {3,6}, {5,7}, {4,7}, {3,7},
+  {11,9}, {10,9}, {9,9}, {17,10}, {16,10}, {15,10}, {14,10}, {13,10},
+  {12,10}, {11,10}, {10,10}, {9,10}, {8,10}, {7,10}, {6,10}, {5,10},
+  {4,10}, {7,11}, {6,11}, {5,11}, {4,11}, {3,11}, {2,11}, {3,12},
+  {2,12}
+};
+
+
 #endif


Commit: a3fb8867d050561a963df122a3e2d2510fd78d54
    https://github.com/scummvm/scummvm/commit/a3fb8867d050561a963df122a3e2d2510fd78d54
Author: D G Turner (digitall at scummvm.org)
Date: 2012-04-07T19:29:17-07:00

Commit Message:
VIDEO: Fix remaining missing code (getVlc2()) in SVQ1 Codec.

Changed paths:
    video/codecs/svq1.cpp



diff --git a/video/codecs/svq1.cpp b/video/codecs/svq1.cpp
index 8d3673b..9d05a8d 100644
--- a/video/codecs/svq1.cpp
+++ b/video/codecs/svq1.cpp
@@ -59,46 +59,22 @@ struct VLC {
  *                  = (max_vlc_length + bits - 1) / bits
  */
 static int getVlc2(Common::BitStream *s, int16 (*table)[2], int bits, int maxDepth) {
-	//FIXME - Change this code to working with BitStream...
-	//GetBitContext *s
-	//int reIndex;
-	//int reCache;
-	//int index;
-	int code = 0;
-	//int n;
-
-/* FIXME
-	reIndex = s->index;
-	reCache = READ_LE_UINT32(s->buffer + (reIndex >> 3)) >> (reIndex & 0x07);
-	index = reCache & (0xffffffff >> (32 - bits));
-	code = table[index][0];
-	n = table[index][1];
-
-	if (maxDepth > 1 && n < 0){
-		reIndex += bits;
-		reCache = READ_LE_UINT32(s->buffer + (reIndex >> 3)) >> (reIndex & 0x07);
-
-		int nbBits = -n;
-
-		index = (reCache & (0xffffffff >> (32 - nbBits))) + code;
+	int index = s->getBits(bits);
+	int code = table[index][0];
+	int n = table[index][1];
+
+	if (maxDepth > 1 && n < 0) {
+		index = s->getBits(-n) + code;
 		code = table[index][0];
 		n = table[index][1];
 
 		if(maxDepth > 2 && n < 0) {
-			reIndex += nbBits;
-			reCache = READ_LE_UINT32(s->buffer + (reIndex >> 3)) >> (reIndex & 0x07);
-
-			nbBits = -n;
-
-			index = (reCache & (0xffffffff >> (32 - nbBits))) + code;
+			index = s->getBits(-n) + code;
 			code = table[index][0];
 			n = table[index][1];
 		}
 	}
 
-	reCache >>= n;
-	s->index = reIndex + n;
-*/
 	return code;
 }
 


Commit: 32ff1f8478bac4bb8b2ec8ee2a94eeb42e79ba77
    https://github.com/scummvm/scummvm/commit/32ff1f8478bac4bb8b2ec8ee2a94eeb42e79ba77
Author: D G Turner (digitall at scummvm.org)
Date: 2012-04-07T19:29:19-07:00

Commit Message:
VIDEO: SVQ1 - Add table_size default setting for VLC Table setup.

Changed paths:
    video/codecs/svq1.cpp



diff --git a/video/codecs/svq1.cpp b/video/codecs/svq1.cpp
index 9d05a8d..38abbc7 100644
--- a/video/codecs/svq1.cpp
+++ b/video/codecs/svq1.cpp
@@ -722,6 +722,7 @@ SVQ1Decoder::SVQ1Decoder(uint16 width, uint16 height) {
 	static int16 tableA[6][2];
 	svq1_block_type.table = tableA;
 	svq1_block_type.table_allocated = 6;
+	svq1_block_type.table_size = 0;
 	initVlcSparse(&svq1_block_type, 2, 4, 
 	        &svq1_block_type_vlc[0][1], 2, 1, 
 	        &svq1_block_type_vlc[0][0], 2, 1, NULL, 0, 0);
@@ -729,6 +730,7 @@ SVQ1Decoder::SVQ1Decoder(uint16 width, uint16 height) {
 	static int16 tableB[176][2];
 	svq1_motion_component.table = tableB;
 	svq1_motion_component.table_allocated = 176;
+	svq1_motion_component.table_size = 0;
 	initVlcSparse(&svq1_motion_component, 7, 33, 
 	        &mvtab[0][1], 2, 1, 
 	        &mvtab[0][0], 2, 1, NULL, 0, 0);
@@ -740,6 +742,7 @@ SVQ1Decoder::SVQ1Decoder(uint16 width, uint16 height) {
 
 		svq1_intra_multistage[i].table = &tableC[offset];
 		svq1_intra_multistage[i].table_allocated = sizes[0][i];
+		svq1_intra_multistage[i].table_size = 0;
 		offset += sizes[0][i];
 		initVlcSparse(&svq1_intra_multistage[i], 3, 8, 
 		         &svq1_intra_multistage_vlc[i][0][1], 2, 1,
@@ -747,6 +750,7 @@ SVQ1Decoder::SVQ1Decoder(uint16 width, uint16 height) {
 
 		svq1_inter_multistage[i].table = &tableC[offset];
 		svq1_inter_multistage[i].table_allocated = sizes[1][i];
+		svq1_inter_multistage[i].table_size = 0;
 		offset += sizes[1][i];
 		initVlcSparse(&svq1_inter_multistage[i], 3, 8,
 		         &svq1_inter_multistage_vlc[i][0][1], 2, 1,
@@ -756,6 +760,7 @@ SVQ1Decoder::SVQ1Decoder(uint16 width, uint16 height) {
 	static int16 tableD[632][2];
 	svq1_intra_mean.table = tableD;
 	svq1_intra_mean.table_allocated = 632;
+	svq1_intra_mean.table_size = 0;
 	initVlcSparse(&svq1_intra_mean, 8, 256, 
 	        &svq1_intra_mean_vlc[0][1], 4, 2, 
 	        &svq1_intra_mean_vlc[0][0], 4, 2, NULL, 0, 0);
@@ -763,6 +768,7 @@ SVQ1Decoder::SVQ1Decoder(uint16 width, uint16 height) {
 	static int16 tableE[1434][2];
 	svq1_inter_mean.table = tableE;
 	svq1_inter_mean.table_allocated = 1434;
+	svq1_inter_mean.table_size = 0;
 	initVlcSparse(&svq1_inter_mean, 9, 512, 
 	        &svq1_inter_mean_vlc[0][1], 4, 2, 
 	        &svq1_inter_mean_vlc[0][0], 4, 2, NULL, 0, 0);


Commit: c9bbe5793cbd34138b722c3a7414c7d8c5f3d55f
    https://github.com/scummvm/scummvm/commit/c9bbe5793cbd34138b722c3a7414c7d8c5f3d55f
Author: Matthew Hoops (clone2727 at gmail.com)
Date: 2012-04-07T19:29:22-07:00

Commit Message:
VIDEO: Rewrite the SVQ1 VLC code to use Common::Huffman

Changed paths:
    video/codecs/svq1.cpp
    video/codecs/svq1.h
    video/codecs/svq1_vlc.h



diff --git a/video/codecs/svq1.cpp b/video/codecs/svq1.cpp
index 38abbc7..0ccdc22 100644
--- a/video/codecs/svq1.cpp
+++ b/video/codecs/svq1.cpp
@@ -33,6 +33,7 @@
 #include "common/system.h"
 #include "common/debug.h"
 #include "common/textconsole.h"
+#include "common/huffman.h"
 
 #include "graphics/yuv_to_rgb.h"
 
@@ -43,195 +44,358 @@ namespace Video {
 #define SVQ1_BLOCK_INTER_4V 2
 #define SVQ1_BLOCK_INTRA    3
 
-struct VLC {
-	int32 bits;
-	int16 (*table)[2]; // code, bits
-	int32 table_size;
-	int32 table_allocated;
-};
-
-/**
- * parses a vlc code, faster then get_vlc()
- * @param bits is the number of bits which will be read at once, must be
- *             identical to nb_bits in init_vlc()
- * @param max_depth is the number of times bits bits must be read to completely
- *                  read the longest vlc code
- *                  = (max_vlc_length + bits - 1) / bits
- */
-static int getVlc2(Common::BitStream *s, int16 (*table)[2], int bits, int maxDepth) {
-	int index = s->getBits(bits);
-	int code = table[index][0];
-	int n = table[index][1];
-
-	if (maxDepth > 1 && n < 0) {
-		index = s->getBits(-n) + code;
-		code = table[index][0];
-		n = table[index][1];
-
-		if(maxDepth > 2 && n < 0) {
-			index = s->getBits(-n) + code;
-			code = table[index][0];
-			n = table[index][1];
-		}
-	}
+SVQ1Decoder::SVQ1Decoder(uint16 width, uint16 height) {
+	_surface = new Graphics::Surface();
+	_surface->create(width, height, g_system->getScreenFormat());
 
-	return code;
-}
+	_current[0] = new byte[width*height];
+	_current[1] = new byte[(width/4)*(height/4)];
+	_current[2] = new byte[(width/4)*(height/4)];
 
-static int allocTable(VLC *vlc, int size, int use_static) {
-	int index;
-	int16 (*temp)[2] = NULL;
-	index = vlc->table_size;
-	vlc->table_size += size;
-	if (vlc->table_size > vlc->table_allocated) {
-		if(use_static)
-			error("SVQ1 cant do anything, init_vlc() is used with too little memory");
-		vlc->table_allocated += (1 << vlc->bits);
-		temp = (int16 (*)[2])realloc(vlc->table, sizeof(int16 *) * 2 * vlc->table_allocated);
-		if (!temp) {
-			free(vlc->table);
-			vlc->table = NULL;
-			return -1;
-		}
-		vlc->table = temp;
-	}
-	return index;
-}
+	_last[0] = 0;
+	_last[1] = 0;
+	_last[2] = 0;
 
-static VLC svq1_block_type;
-static VLC svq1_motion_component;
-static VLC svq1_intra_multistage[6];
-static VLC svq1_inter_multistage[6];
-static VLC svq1_intra_mean;
-static VLC svq1_inter_mean;
+	// Setup Variable Length Code Tables
+	_blockType = new Common::Huffman(0, 4, s_svq1BlockTypeCodes, s_svq1BlockTypeLengths);
 
-static int svq1DecodeBlockIntra(Common::BitStream *s, uint8 *pixels, int pitch) {
-	uint8 *list[63];
-	uint32 *dst;
-	int entries[6];
-	int i, j, m, n;
-	int mean, stages;
-	unsigned int x, y, width, height, level;
-	uint32 n1, n2, n3, n4;
+	for (int i = 0; i < 6; i++) {
+		_intraMultistage[i] = new Common::Huffman(0, 8, s_svq1IntraMultistageCodes[i], s_svq1IntraMultistageLengths[i]);
+		_interMultistage[i] = new Common::Huffman(0, 8, s_svq1InterMultistageCodes[i], s_svq1InterMultistageLengths[i]);
+	}
 
-	// initialize list for breadth first processing of vectors
-	list[0] = pixels;
+	_intraMean = new Common::Huffman(0, 256, s_svq1IntraMeanCodes, s_svq1IntraMeanLengths);
+	_interMean = new Common::Huffman(0, 512, s_svq1InterMeanCodes, s_svq1InterMeanLengths);
+	_motionComponent = new Common::Huffman(0, 33, s_svq1MotionComponentCodes, s_svq1MotionComponentLengths);
+}
 
-	// recursively process vector
-	for (i=0, m=1, n=1, level=5; i < n; i++) {
-		// 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 (s->getBit() == 0)
-				break;
-			// add child nodes
-			list[n++] = list[i];
-			list[n++] = list[i] + (((level & 1) ? pitch : 1) << ((level / 2) + 1));
-		}
+SVQ1Decoder::~SVQ1Decoder() {
+	_surface->free();
+	delete _surface;
 
-		// destination address and vector size
-		dst = (uint32 *) list[i];
-		width = 1 << ((4 + level) /2);
-		height = 1 << ((3 + level) /2);
+	delete[] _current[0];
+	delete[] _current[1];
+	delete[] _current[2];
 
-		// get number of stages (-1 skips vector, 0 for mean only)
-		stages = getVlc2(s, svq1_intra_multistage[level].table, 3, 3) - 1;
+	delete[] _last[0];
+	delete[] _last[1];
+	delete[] _last[2];
 
-		if (stages == -1) {
-			for (y=0; y < height; y++) {
-				memset (&dst[y*(pitch / 4)], 0, width);
-			}
-		continue; // skip vector
-		}
+	delete _blockType;
+	delete _intraMean;
+	delete _interMean;
+	delete _motionComponent;
 
-		if ((stages > 0) && (level >= 4)) {
-			warning("Error (svq1_decode_block_intra): invalid vector: stages=%i level=%i", stages, level);
-		return -1; // invalid vector
-		}
+	for (int i = 0; i < 6; i++) {
+		delete _intraMultistage[i];
+		delete _interMultistage[i];
+	}
+}
 
-		mean = getVlc2(s, svq1_intra_mean.table, 8, 3);
+const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *stream) {
+	debug(1, "SVQ1Decoder::decodeImage()");
 
-		if (stages == 0) {
-			for (y=0; y < height; y++) {
-				memset (&dst[y*(pitch / 4)], mean, width);
-			}
-		} else {
-			// SVQ1_CALC_CODEBOOK_ENTRIES(svq1_intra_codebooks);
-			const uint32 *codebook = (const uint32 *) svq1_intra_codebooks[level];
-			uint32 bit_cache = s->getBits(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);
+	Common::BitStream32BEMSB frameData(*stream);
 
-			// 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()
-					// add codebook entries to vector
-					for (j=0; j < stages; j++) {
-						n3  = codebook[entries[j]] ^ 0x80808080;
-						n1 += ((n3 & 0xFF00FF00) >> 8);
-						n2 +=  (n3 & 0x00FF00FF);
-					}
+	uint32 frameCode = frameData.getBits(22);
+	debug(1, " frameCode: %d", frameCode);
 
-					// 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 ((frameCode & ~0x70) || !(frameCode & 0x60)) { // Invalid
+		warning("Invalid Image at frameCode");
+		return _surface;
+	}
 
-					if (n2 & 0xFF00FF00) {
-						n3  = ((( n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;
-						n2 += 0x7F007F00;
-						n2 |= (((~n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;
-						n2 &= (n3 & 0x00FF00FF);
-					}
+	// swap some header bytes (why?)
+	//if (frameCode != 0x20) {
+	//  uint32 *src = stream;
+	//
+	//  for (i = 4; i < 8; i++) {
+	//    src[i] = ((src[i] << 16) | (src[i] >> 16)) ^ src[7 - i];
+	// }
+	//}
 
-					// store result
-					dst[x] = (n1 << 8) | n2;
-				}
-				dst += (pitch / 4);
-			}
+#if 0
+	static const uint16 checksum_table[256] = {
+		0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
+		0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
+		0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
+		0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
+		0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
+		0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
+		0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
+		0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
+		0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
+		0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
+		0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
+		0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
+		0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
+		0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
+		0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
+		0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
+		0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
+		0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
+		0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
+		0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
+		0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
+		0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
+		0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
+		0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
+		0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
+		0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
+		0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
+		0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
+		0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
+		0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
+		0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
+		0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0
+	};
+#endif
+
+	byte temporalReference = frameData.getBits(8);
+	debug(1, " temporalReference: %d", temporalReference);
+	const char* types[4] = { "I (Key)", "P (Delta from Previous)", "B (Delta from Next)", "Invalid" };
+	byte frameType = frameData.getBits(2);
+	debug(1, " frameType: %d = %s Frame", frameType, types[frameType]);
+	if (frameType == 0) { // I Frame
+		// TODO: Validate checksum if present
+		if (frameCode == 0x50 || frameCode == 0x60) {
+			uint32 checksum = frameData.getBits(16);
+			debug(1, " checksum:0x%02x", checksum);
+			//uint16 calculate_packet_checksum (const uint8 *data, const int length) {
+			//  int value;
+			//for (int i = 0; i < length; i++)
+				//	value = checksum_table[data[i] ^ (value >> 8)] ^ ((value & 0xFF) << 8);
 		}
+	} else if (frameType == 2) { // B Frame
+		warning("B Frames not supported by SVQ1 decoder");
+		return _surface;
+	} else if (frameType == 3) { // Invalid
+		warning("Invalid Frame Type");
+		return _surface;
 	}
 
-	return 0;
-}
+	static const uint8 stringXORTable[256] = {
+		0x00, 0xD5, 0x7F, 0xAA, 0xFE, 0x2B, 0x81, 0x54,
+		0x29, 0xFC, 0x56, 0x83, 0xD7, 0x02, 0xA8, 0x7D,
+		0x52, 0x87, 0x2D, 0xF8, 0xAC, 0x79, 0xD3, 0x06,
+		0x7B, 0xAE, 0x04, 0xD1, 0x85, 0x50, 0xFA, 0x2F,
+		0xA4, 0x71, 0xDB, 0x0E, 0x5A, 0x8F, 0x25, 0xF0,
+		0x8D, 0x58, 0xF2, 0x27, 0x73, 0xA6, 0x0C, 0xD9,
+		0xF6, 0x23, 0x89, 0x5C, 0x08, 0xDD, 0x77, 0xA2,
+		0xDF, 0x0A, 0xA0, 0x75, 0x21, 0xF4, 0x5E, 0x8B,
+		0x9D, 0x48, 0xE2, 0x37, 0x63, 0xB6, 0x1C, 0xC9,
+		0xB4, 0x61, 0xCB, 0x1E, 0x4A, 0x9F, 0x35, 0xE0,
+		0xCF, 0x1A, 0xB0, 0x65, 0x31, 0xE4, 0x4E, 0x9B,
+		0xE6, 0x33, 0x99, 0x4C, 0x18, 0xCD, 0x67, 0xB2,
+		0x39, 0xEC, 0x46, 0x93, 0xC7, 0x12, 0xB8, 0x6D,
+		0x10, 0xC5, 0x6F, 0xBA, 0xEE, 0x3B, 0x91, 0x44,
+		0x6B, 0xBE, 0x14, 0xC1, 0x95, 0x40, 0xEA, 0x3F,
+		0x42, 0x97, 0x3D, 0xE8, 0xBC, 0x69, 0xC3, 0x16,
+		0xEF, 0x3A, 0x90, 0x45, 0x11, 0xC4, 0x6E, 0xBB,
+		0xC6, 0x13, 0xB9, 0x6C, 0x38, 0xED, 0x47, 0x92,
+		0xBD, 0x68, 0xC2, 0x17, 0x43, 0x96, 0x3C, 0xE9,
+		0x94, 0x41, 0xEB, 0x3E, 0x6A, 0xBF, 0x15, 0xC0,
+		0x4B, 0x9E, 0x34, 0xE1, 0xB5, 0x60, 0xCA, 0x1F,
+		0x62, 0xB7, 0x1D, 0xC8, 0x9C, 0x49, 0xE3, 0x36,
+		0x19, 0xCC, 0x66, 0xB3, 0xE7, 0x32, 0x98, 0x4D,
+		0x30, 0xE5, 0x4F, 0x9A, 0xCE, 0x1B, 0xB1, 0x64,
+		0x72, 0xA7, 0x0D, 0xD8, 0x8C, 0x59, 0xF3, 0x26,
+		0x5B, 0x8E, 0x24, 0xF1, 0xA5, 0x70, 0xDA, 0x0F,
+		0x20, 0xF5, 0x5F, 0x8A, 0xDE, 0x0B, 0xA1, 0x74,
+		0x09, 0xDC, 0x76, 0xA3, 0xF7, 0x22, 0x88, 0x5D,
+		0xD6, 0x03, 0xA9, 0x7C, 0x28, 0xFD, 0x57, 0x82,
+		0xFF, 0x2A, 0x80, 0x55, 0x01, 0xD4, 0x7E, 0xAB,
+		0x84, 0x51, 0xFB, 0x2E, 0x7A, 0xAF, 0x05, 0xD0,
+		0xAD, 0x78, 0xD2, 0x07, 0x53, 0x86, 0x2C, 0xF9
+	};
 
-static int svq1DecodeBlockNonIntra(Common::BitStream *s, uint8 *pixels, int pitch) {
-	uint8 *list[63];
-	uint32 *dst;
-	int entries[6];
-	int i, j, m, n;
-	int mean, stages;
-	int x, y, width, height, level;
-	uint32 n1, n2, n3, n4;
+	if ((frameCode ^ 0x10) >= 0x50) {
+		// Decode embedded string
+		Common::String str;
+		uint8 stringLen = frameData.getBits(8);
+		byte xorVal = stringXORTable[stringLen];
 
-	// initialize list for breadth first processing of vectors
-	list[0] = pixels;
+		for (uint16 i = 0; i < stringLen-1; i++) {
+			byte data = frameData.getBits(8);
+			str += data ^ xorVal;
+			xorVal = stringXORTable[data];
+		}
+		debug(1, " Embedded String of %d Characters: \"%s\"", stringLen, str.c_str());
+	}
 
-	// recursively process vector
-	for (i=0, m=1, n=1, level=5; i < n; i++) {
-		// SVQ1_PROCESS_VECTOR()
-		for (; level > 0; i++) {
-			// process next depth
-			if (i == m) {
-				m = n;
-				if (--level == 0)
-					break;
+	byte unk1 = frameData.getBits(2); // Unknown
+	debug(1, " unk1: %d", unk1);
+	byte unk2 = frameData.getBits(2); // Unknown
+	debug(1, " unk2: %d", unk2);
+	bool unk3 = frameData.getBit(); // Unknown
+	debug(1, " unk3: %d", unk3);
+
+	static const struct { uint w, h; } standardFrameSizes[7] = {
+		{ 160, 120 }, // 0
+		{ 128,  96 }, // 1
+		{ 176, 144 }, // 2
+		{ 352, 288 }, // 3
+		{ 704, 576 }, // 4
+		{ 240, 180 }, // 5
+		{ 320, 240 }  // 6
+	};
+
+	byte frameSizeCode = frameData.getBits(3);
+	debug(1, " frameSizeCode: %d", frameSizeCode);
+	uint16 frameWidth, frameHeight;
+	if (frameSizeCode == 7) {
+		frameWidth = frameData.getBits(12);
+		frameHeight = frameData.getBits(12);
+	} else {
+		frameWidth = standardFrameSizes[frameSizeCode].w;
+		frameHeight = standardFrameSizes[frameSizeCode].h;
+	}
+	debug(1, " frameWidth: %d", frameWidth);
+	debug(1, " frameHeight: %d", frameHeight);
+	if (frameWidth == 0 || frameHeight == 0) { // Invalid
+		warning("Invalid Frame Size");
+		return _surface;
+	}
+	bool checksumPresent = frameData.getBit();
+	debug(1, " checksumPresent: %d", checksumPresent);
+	if (checksumPresent) {
+		bool usePacketChecksum = frameData.getBit();
+		debug(1, " usePacketChecksum: %d", usePacketChecksum);
+		bool componentChecksumsAfterImageData = frameData.getBit();
+		debug(1, " componentChecksumsAfterImageData: %d", componentChecksumsAfterImageData);
+		byte unk4 = frameData.getBits(2);
+		debug(1, " unk4: %d", unk4);
+		if (unk4 != 0)
+			warning("Invalid Frame Header in SVQ1 Frame Decode");
+	}
+
+	bool unk5 = frameData.getBit();
+	debug(1, " unk5: %d", unk5);
+	if (unk5) {
+		bool unk6 = frameData.getBit();
+		debug(1, " unk6: %d", unk6);
+		byte unk7 = frameData.getBits(4);
+		debug(1, " unk7: %d", unk7);
+		bool unk8 = frameData.getBit();
+		debug(1, " unk8: %d", unk8);
+		byte unk9 = frameData.getBits(2);
+		debug(1, " unk9: %d", unk9);
+		while (frameData.getBit()) {
+			byte unk10 = frameData.getBits(8);
+			debug(1, " unk10: %d", unk10);
+		}
+	}
+
+	if (frameWidth == _surface->w && frameHeight == _surface->h) {
+		// Decode Y, U and V component planes
+		for (int i = 0; i < 3; i++) {
+			int linesize, width, height;
+			if (i == 0) {
+				// Y Size is width * height
+				width  = frameWidth;
+				if (width % 16) {
+					width /= 16;
+					width++;
+					width *= 16;
+				}
+				assert(width % 16 == 0);
+				height = frameHeight;
+				if (height % 16) {
+					height /= 16;
+					height++;
+					height *= 16;
+				}
+				assert(height % 16 == 0);
+				linesize = width;
+			} else {
+				// U and V size is width/4 * height/4
+				width  = frameWidth/4;
+				if (width % 16) {
+					width /= 16;
+					width++;
+					width *= 16;
+				}
+				assert(width % 16 == 0);
+				height = frameHeight/4;
+				if (height % 16) {
+					height /= 16;
+					height++;
+					height *= 16;
+				}
+				assert(height % 16 == 0);
+				linesize = width;
+			}
+
+			if (frameType == 0) { // I Frame
+				// Keyframe (I)
+				byte *current = _current[i];
+				for (uint16 y = 0; y < height; y += 16) {
+					for (uint16 x = 0; x < width; x += 16) {
+						if (int result = svq1DecodeBlockIntra(&frameData, &current[x], linesize) != 0) {
+							warning("Error in svq1DecodeBlock %i (keyframe)", result);
+							return _surface;
+						}
+					}
+					current += 16 * linesize;
+				}
+			} else {
+				// Delta frame (P or B)
+
+				// Prediction Motion Vector
+				Common::Point *pmv = new Common::Point[(width/8) + 3];
+
+				byte *previous;
+				if(frameType == 2) { // B Frame
+					warning("B Frame not supported currently");
+					//previous = _next[i];
+				} else
+					previous = _last[i];
+
+				byte *current = _current[i];
+				for (uint16 y = 0; y < height; y += 16) {
+					for (uint16 x = 0; x < width; x += 16) {
+						if (int result = svq1DecodeDeltaBlock(&frameData, &current[x], previous, linesize, pmv, x, y) != 0) {
+							warning("Error in svq1DecodeDeltaBlock %i", result);
+							return _surface;
+						}
+					}
+
+					pmv[0].x = pmv[0].y = 0;
+
+					current += 16*linesize;
+				}
+				delete[] pmv;
+			}
+		}
+
+		convertYUV410ToRGB(_surface, _current[0], _current[1], _current[2], frameWidth, frameHeight, frameWidth, frameWidth/2);
+	} else
+		warning("FrameWidth/Height Sanity Check Failed!");
+
+	return _surface;
+}
+
+int SVQ1Decoder::svq1DecodeBlockIntra(Common::BitStream *s, uint8 *pixels, int pitch) {
+	uint8 *list[63];
+	uint32 *dst;
+	int entries[6];
+	int i, j, m, n;
+	int mean, stages;
+	unsigned int x, y, width, height, level;
+	uint32 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()
+		for (; level > 0; i++) {
+			// process next depth
+			if (i == m) {
+				m = n;
+				if (--level == 0)
+					break;
 			}
 			// divide block if next bit set
 			if (s->getBit() == 0)
@@ -247,60 +411,166 @@ static int svq1DecodeBlockNonIntra(Common::BitStream *s, uint8 *pixels, int pitc
 		height = 1 << ((3 + level) /2);
 
 		// get number of stages (-1 skips vector, 0 for mean only)
-		stages = getVlc2(s, svq1_inter_multistage[level].table, 3, 2) - 1;
+		stages = _intraMultistage[level]->getSymbol(*s) - 1;
 
-		if (stages == -1) continue; // skip vector
+		if (stages == -1) {
+			for (y=0; y < height; y++) {
+				memset (&dst[y*(pitch / 4)], 0, width);
+			}
+		continue; // skip vector
+		}
 
 		if ((stages > 0) && (level >= 4)) {
-			warning("Error (svq1_decode_block_non_intra): invalid vector: stages=%i level=%i", stages, level);
-			return -1;        // invalid vector
+			warning("Error (svq1_decode_block_intra): invalid vector: stages=%i level=%i", stages, level);
+		return -1; // invalid vector
 		}
 
-		mean = getVlc2(s, svq1_inter_mean.table, 9, 3) - 256;
-
-		// SVQ1_CALC_CODEBOOK_ENTRIES(svq1_inter_codebooks);
-		const uint32 *codebook = (const uint32 *) svq1_inter_codebooks[level];
-		uint32 bit_cache = s->getBits(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);
+		mean = _intraMean->getSymbol(*s);
 
-		// 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()
-				// add codebook entries to vector
-				for (j=0; j < stages; j++) {
-					n3  = codebook[entries[j]] ^ 0x80808080;
-					n1 += ((n3 & 0xFF00FF00) >> 8);
-					n2 +=  (n3 & 0x00FF00FF);
-				}
+		if (stages == 0) {
+			for (y=0; y < height; y++) {
+				memset (&dst[y*(pitch / 4)], mean, width);
+			}
+		} else {
+			// SVQ1_CALC_CODEBOOK_ENTRIES(svq1_intra_codebooks);
+			const uint32 *codebook = (const uint32 *) svq1_intra_codebooks[level];
+			uint32 bit_cache = s->getBits(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);
 
-				// clip to [0..255]
-				if (n1 & 0xFF00FF00) {
-					n3  = ((( n1 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;
-					n1 += 0x7F007F00;
-					n1 |= (((~n1 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;
-					n1 &= (n3 & 0x00FF00FF);
-				}
+			// 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()
+					// add codebook entries to vector
+					for (j=0; j < stages; j++) {
+						n3  = codebook[entries[j]] ^ 0x80808080;
+						n1 += ((n3 & 0xFF00FF00) >> 8);
+						n2 +=  (n3 & 0x00FF00FF);
+					}
 
-				if (n2 & 0xFF00FF00) {
-					n3  = ((( n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;
-					n2 += 0x7F007F00;
-					n2 |= (((~n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;
-					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);
+					}
 
-				// store result
-				dst[x] = (n1 << 8) | n2;
-			}
+					if (n2 & 0xFF00FF00) {
+						n3  = ((( n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;
+						n2 += 0x7F007F00;
+						n2 |= (((~n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;
+						n2 &= (n3 & 0x00FF00FF);
+					}
+
+					// store result
+					dst[x] = (n1 << 8) | n2;
+				}
+				dst += (pitch / 4);
+			}
+		}
+	}
+
+	return 0;
+}
+
+int SVQ1Decoder::svq1DecodeBlockNonIntra(Common::BitStream *s, uint8 *pixels, int pitch) {
+	uint8 *list[63];
+	uint32 *dst;
+	int entries[6];
+	int i, j, m, n;
+	int mean, stages;
+	int x, y, width, height, level;
+	uint32 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()
+		for (; level > 0; i++) {
+			// process next depth
+			if (i == m) {
+				m = n;
+				if (--level == 0)
+					break;
+			}
+			// divide block if next bit set
+			if (s->getBit() == 0)
+				break;
+			// add child nodes
+			list[n++] = list[i];
+			list[n++] = list[i] + (((level & 1) ? pitch : 1) << ((level / 2) + 1));
+		}
+
+		// destination address and vector size
+		dst = (uint32 *) list[i];
+		width = 1 << ((4 + level) /2);
+		height = 1 << ((3 + level) /2);
+
+		// get number of stages (-1 skips vector, 0 for mean only)
+		stages = _interMultistage[level]->getSymbol(*s) - 1;
+
+		if (stages == -1) continue; // skip vector
+
+		if ((stages > 0) && (level >= 4)) {
+			warning("Error (svq1_decode_block_non_intra): invalid vector: stages=%i level=%i", stages, level);
+			return -1;        // invalid vector
+		}
+
+		mean = _interMean->getSymbol(*s) - 256;
+
+		// SVQ1_CALC_CODEBOOK_ENTRIES(svq1_inter_codebooks);
+		const uint32 *codebook = (const uint32 *) svq1_inter_codebooks[level];
+		uint32 bit_cache = s->getBits(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);
+
+		// 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()
+				// 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);
+				}
+
+				// store result
+				dst[x] = (n1 << 8) | n2;
+			}
 			dst += (pitch / 4);
 		}
 	}
@@ -323,10 +593,10 @@ static inline int mid_pred(int a, int b, int c) {
 	return b;
 }
 
-static int svq1DecodeMotionVector(Common::BitStream *s, Common::Point *mv, Common::Point **pmv) {
+int SVQ1Decoder::svq1DecodeMotionVector(Common::BitStream *s, Common::Point *mv, Common::Point **pmv) {
 	for (int i=0; i < 2; i++) {
 		// get motion code
-		int diff = getVlc2(s, svq1_motion_component.table, 7, 2);
+		int diff = _motionComponent->getSymbol(*s);
 		if (diff < 0)
 			return -1;
 		else if (diff) {
@@ -343,7 +613,7 @@ static int svq1DecodeMotionVector(Common::BitStream *s, Common::Point *mv, Commo
 	return 0;
 }
 
-static void svq1SkipBlock(uint8 *current, uint8 *previous, int pitch, int x, int y) {
+void SVQ1Decoder::svq1SkipBlock(uint8 *current, uint8 *previous, int pitch, int x, int y) {
 	uint8 *src;
 	uint8 *dst;
 
@@ -357,7 +627,7 @@ static void svq1SkipBlock(uint8 *current, uint8 *previous, int pitch, int x, int
 	}
 }
 
-static int svq1MotionInterBlock(Common::BitStream *ss,
+int SVQ1Decoder::svq1MotionInterBlock(Common::BitStream *ss,
                                 uint8 *current, uint8 *previous, int pitch,
                                 Common::Point *motion, int x, int y) {
 	uint8 *src;
@@ -409,7 +679,7 @@ static int svq1MotionInterBlock(Common::BitStream *ss,
 	return 0;
 }
 
-static int svq1MotionInter4vBlock(Common::BitStream *ss,
+int SVQ1Decoder::svq1MotionInter4vBlock(Common::BitStream *ss,
                                   uint8 *current, uint8 *previous, int pitch,
                                   Common::Point *motion, int x, int y) {
 	uint8 *src;
@@ -497,14 +767,14 @@ static int svq1MotionInter4vBlock(Common::BitStream *ss,
 	return 0;
 }
 
-static int svq1DecodeDeltaBlock(Common::BitStream *ss,
+int SVQ1Decoder::svq1DecodeDeltaBlock(Common::BitStream *ss,
                         uint8 *current, uint8 *previous, int pitch,
                         Common::Point *motion, int x, int y) {
 	uint32 block_type;
 	int result = 0;
 
 	// get block type
-	block_type = getVlc2(ss, svq1_block_type.table, 2, 2);
+	block_type = _blockType->getSymbol(*ss);
 
 	// reset motion vectors
 	if (block_type == SVQ1_BLOCK_SKIP || block_type == SVQ1_BLOCK_INTRA) {
@@ -547,527 +817,4 @@ static int svq1DecodeDeltaBlock(Common::BitStream *ss,
 	return result;
 }
 
-#define GET_DATA(v, table, i, wrap, size)\
-{\
-	const uint8 *ptr = (const uint8 *)table + i * wrap;\
-	switch(size) {\
-		case 1:\
-			v = *(const uint8 *)ptr;\
-			break;\
-		case 2:\
-			v = *(const uint16 *)ptr;\
-			break;\
-		default:\
-			v = *(const uint32 *)ptr;\
-			break;\
-	}\
-}
-
-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,
-                       const void *symbols, int symbols_wrap, int symbols_size,
-                       int code_prefix, int n_prefix, int flags)
-{
-	int i, j, k, n, table_size, table_index, nb, n1, index, code_prefix2, symbol;
-	uint32 code;
-	int16 (*table)[2];
-
-	table_size = 1 << table_nb_bits;
-	table_index = allocTable(vlc, table_size, flags & 4);
-	if (table_index < 0)
-		return -1;
-	table = &vlc->table[table_index];
-
-	for(i = 0; i < table_size; i++) {
-		table[i][1] = 0; //bits
-		table[i][0] = -1; //codes
-	}
-
-	// first pass: map codes and compute auxillary table sizes
-	for(i = 0; i < nb_codes; i++) {
-		GET_DATA(n, bits, i, bits_wrap, bits_size);
-		GET_DATA(code, codes, i, codes_wrap, codes_size);
-		// we accept tables with holes
-		if (n <= 0)
-			continue;
-		if (!symbols)
-			symbol = i;
-		else
-			GET_DATA(symbol, symbols, i, symbols_wrap, symbols_size);
-		// if code matches the prefix, it is in the table
-		n -= n_prefix;
-		if(flags & 2)
-			code_prefix2= code & (n_prefix>=32 ? 0xffffffff : (1 << n_prefix)-1);
-		else
-			code_prefix2= code >> n;
-		if (n > 0 && code_prefix2 == code_prefix) {
-			if (n <= table_nb_bits) {
-				// no need to add another table
-				j = (code << (table_nb_bits - n)) & (table_size - 1);
-				nb = 1 << (table_nb_bits - n);
-				for(k = 0; k < nb; k++) {
-					if(flags & 2)
-						j = (code >> n_prefix) + (k<<n);
-					if (table[j][1] /*bits*/ != 0) {
-						error("SVQ1 incorrect codes");
-						return -1;
-					}
-					table[j][1] = n; //bits
-					table[j][0] = symbol;
-					j++;
-				}
-			} else {
-				n -= table_nb_bits;
-				j = (code >> ((flags & 2) ? n_prefix : n)) & ((1 << table_nb_bits) - 1);
-				// compute table size
-				n1 = -table[j][1]; //bits
-				if (n > n1)
-					n1 = n;
-				table[j][1] = -n1; //bits
-			}
-		}
-	}
-
-	// second pass : fill auxillary tables recursively
-	for(i = 0;i < table_size; i++) {
-		n = table[i][1]; //bits
-		if (n < 0) {
-			n = -n;
-			if (n > table_nb_bits) {
-				n = table_nb_bits;
-				table[i][1] = -n; //bits
-			}
-			index = build_table(vlc, n, nb_codes,
-			                    bits, bits_wrap, bits_size,
-			                    codes, codes_wrap, codes_size,
-			                    symbols, symbols_wrap, symbols_size,
-			                    (flags & 2) ? (code_prefix | (i << n_prefix)) : ((code_prefix << table_nb_bits) | i),
-			                    n_prefix + table_nb_bits, flags);
- 			if (index < 0)
-				return -1;
-			// note: realloc has been done, so reload tables
-			table = &vlc->table[table_index];
-			table[i][0] = index; //code
-		}
-	}
-	return table_index;
-}
-
-/* Build VLC decoding tables suitable for use with get_vlc().
-
-   'nb_bits' set thee decoding table size (2^nb_bits) entries. The
-   bigger it is, the faster is the decoding. But it should not be too
-   big to save memory and L1 cache. '9' is a good compromise.
-
-   'nb_codes' : number of vlcs codes
-
-   'bits' : table which gives the size (in bits) of each vlc code.
-
-   'codes' : table which gives the bit pattern of of each vlc code.
-
-   'symbols' : table which gives the values to be returned from get_vlc().
-
-   'xxx_wrap' : give the number of bytes between each entry of the
-   'bits' or 'codes' tables.
-
-   'xxx_size' : gives the number of bytes of each entry of the 'bits'
-   or 'codes' tables.
-
-   'wrap' and 'size' allows to use any memory configuration and types
-   (byte/word/long) to store the 'bits', 'codes', and 'symbols' tables.
-
-   'use_static' should be set to 1 for tables, which should be freed
-   with av_free_static(), 0 if free_vlc() will be used.
-*/
-void initVlcSparse(VLC *vlc, int nb_bits, int nb_codes,
-		const void *bits, int bits_wrap, int bits_size,
-		const void *codes, int codes_wrap, int codes_size,
-		const void *symbols, int symbols_wrap, int symbols_size) {
-	vlc->bits = nb_bits;
-
-	if(vlc->table_size && vlc->table_size == vlc->table_allocated) {
-		return;
-	} else if(vlc->table_size) {
-		error("called on a partially initialized table");
-	}
-
-	if (build_table(vlc, nb_bits, nb_codes,
-	                bits, bits_wrap, bits_size,
-	                codes, codes_wrap, codes_size,
-	                symbols, symbols_wrap, symbols_size,
-	                0, 0, 4 | 2) < 0) {
-		free(&vlc->table);
-		return; // Error
-	}
-
-	if(vlc->table_size != vlc->table_allocated)
-		error("SVQ1 needed %d had %d", vlc->table_size, vlc->table_allocated);
-}
-
-SVQ1Decoder::SVQ1Decoder(uint16 width, uint16 height) {
-	_surface = new Graphics::Surface();
-	_surface->create(width, height, g_system->getScreenFormat());
-
-	_current[0] = new byte[width*height];
-	_current[1] = new byte[(width/4)*(height/4)];
-	_current[2] = new byte[(width/4)*(height/4)];
-
-	_last[0] = 0;
-	_last[1] = 0;
-	_last[2] = 0;
-
-	// Setup Variable Length Code Tables
-	static int16 tableA[6][2];
-	svq1_block_type.table = tableA;
-	svq1_block_type.table_allocated = 6;
-	svq1_block_type.table_size = 0;
-	initVlcSparse(&svq1_block_type, 2, 4, 
-	        &svq1_block_type_vlc[0][1], 2, 1, 
-	        &svq1_block_type_vlc[0][0], 2, 1, NULL, 0, 0);
-
-	static int16 tableB[176][2];
-	svq1_motion_component.table = tableB;
-	svq1_motion_component.table_allocated = 176;
-	svq1_motion_component.table_size = 0;
-	initVlcSparse(&svq1_motion_component, 7, 33, 
-	        &mvtab[0][1], 2, 1, 
-	        &mvtab[0][0], 2, 1, NULL, 0, 0);
-
-	uint16 offset = 0;
-	for (uint8 i = 0; i < 6; i++) {
-		static const uint8 sizes[2][6] = {{14, 10, 14, 18, 16, 18}, {10, 10, 14, 14, 14, 16}};
-		static int16 tableC[168][2];
-
-		svq1_intra_multistage[i].table = &tableC[offset];
-		svq1_intra_multistage[i].table_allocated = sizes[0][i];
-		svq1_intra_multistage[i].table_size = 0;
-		offset += sizes[0][i];
-		initVlcSparse(&svq1_intra_multistage[i], 3, 8, 
-		         &svq1_intra_multistage_vlc[i][0][1], 2, 1,
-		         &svq1_intra_multistage_vlc[i][0][0], 2, 1, NULL, 0, 0);
-
-		svq1_inter_multistage[i].table = &tableC[offset];
-		svq1_inter_multistage[i].table_allocated = sizes[1][i];
-		svq1_inter_multistage[i].table_size = 0;
-		offset += sizes[1][i];
-		initVlcSparse(&svq1_inter_multistage[i], 3, 8,
-		         &svq1_inter_multistage_vlc[i][0][1], 2, 1,
-		         &svq1_inter_multistage_vlc[i][0][0], 2, 1, NULL, 0, 0);
-	}
-
-	static int16 tableD[632][2];
-	svq1_intra_mean.table = tableD;
-	svq1_intra_mean.table_allocated = 632;
-	svq1_intra_mean.table_size = 0;
-	initVlcSparse(&svq1_intra_mean, 8, 256, 
-	        &svq1_intra_mean_vlc[0][1], 4, 2, 
-	        &svq1_intra_mean_vlc[0][0], 4, 2, NULL, 0, 0);
-
-	static int16 tableE[1434][2];
-	svq1_inter_mean.table = tableE;
-	svq1_inter_mean.table_allocated = 1434;
-	svq1_inter_mean.table_size = 0;
-	initVlcSparse(&svq1_inter_mean, 9, 512, 
-	        &svq1_inter_mean_vlc[0][1], 4, 2, 
-	        &svq1_inter_mean_vlc[0][0], 4, 2, NULL, 0, 0);
-}
-
-SVQ1Decoder::~SVQ1Decoder() {
-	_surface->free();
-	delete _surface;
-
-	delete[] _current[0];
-	delete[] _current[1];
-	delete[] _current[2];
-
-	delete[] _last[0];
-	delete[] _last[1];
-	delete[] _last[2];
-}
-
-const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *stream) {
-	debug(1, "SVQ1Decoder::decodeImage()");
-
-	Common::BitStream32BEMSB frameData(*stream);
-
-	uint32 frameCode = frameData.getBits(22);
-	debug(1, " frameCode: %d", frameCode);
-
-	if ((frameCode & ~0x70) || !(frameCode & 0x60)) { // Invalid
-		warning("Invalid Image at frameCode");
-		return _surface;
-	}
-
-	// swap some header bytes (why?)
-	//if (frameCode != 0x20) {
-	//  uint32 *src = stream;
-	//
-	//  for (i = 4; i < 8; i++) {
-	//    src[i] = ((src[i] << 16) | (src[i] >> 16)) ^ src[7 - i];
-	// }
-	//}
-
-#if 0
-	static const uint16 checksum_table[256] = {
-		0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
-		0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
-		0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
-		0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
-		0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
-		0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
-		0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
-		0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
-		0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
-		0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
-		0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
-		0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
-		0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
-		0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
-		0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
-		0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
-		0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
-		0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
-		0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
-		0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
-		0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
-		0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
-		0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
-		0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
-		0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
-		0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
-		0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
-		0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
-		0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
-		0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
-		0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
-		0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0
-	};
-#endif
-
-	byte temporalReference = frameData.getBits(8);
-	debug(1, " temporalReference: %d", temporalReference);
-	const char* types[4] = { "I (Key)", "P (Delta from Previous)", "B (Delta from Next)", "Invalid" };
-	byte frameType = frameData.getBits(2);
-	debug(1, " frameType: %d = %s Frame", frameType, types[frameType]);
-	if (frameType == 0) { // I Frame
-		// TODO: Validate checksum if present
-		if (frameCode == 0x50 || frameCode == 0x60) {
-			uint32 checksum = frameData.getBits(16);
-			debug(1, " checksum:0x%02x", checksum);
-			//uint16 calculate_packet_checksum (const uint8 *data, const int length) {
-			//  int value;
-			//for (int i = 0; i < length; i++)
-				//	value = checksum_table[data[i] ^ (value >> 8)] ^ ((value & 0xFF) << 8);
-		}
-	} else if (frameType == 2) { // B Frame
-		warning("B Frames not supported by SVQ1 decoder");
-		return _surface;
-	} else if (frameType == 3) { // Invalid
-		warning("Invalid Frame Type");
-		return _surface;
-	}
-
-	static const uint8 stringXORTable[256] = {
-		0x00, 0xD5, 0x7F, 0xAA, 0xFE, 0x2B, 0x81, 0x54,
-		0x29, 0xFC, 0x56, 0x83, 0xD7, 0x02, 0xA8, 0x7D,
-		0x52, 0x87, 0x2D, 0xF8, 0xAC, 0x79, 0xD3, 0x06,
-		0x7B, 0xAE, 0x04, 0xD1, 0x85, 0x50, 0xFA, 0x2F,
-		0xA4, 0x71, 0xDB, 0x0E, 0x5A, 0x8F, 0x25, 0xF0,
-		0x8D, 0x58, 0xF2, 0x27, 0x73, 0xA6, 0x0C, 0xD9,
-		0xF6, 0x23, 0x89, 0x5C, 0x08, 0xDD, 0x77, 0xA2,
-		0xDF, 0x0A, 0xA0, 0x75, 0x21, 0xF4, 0x5E, 0x8B,
-		0x9D, 0x48, 0xE2, 0x37, 0x63, 0xB6, 0x1C, 0xC9,
-		0xB4, 0x61, 0xCB, 0x1E, 0x4A, 0x9F, 0x35, 0xE0,
-		0xCF, 0x1A, 0xB0, 0x65, 0x31, 0xE4, 0x4E, 0x9B,
-		0xE6, 0x33, 0x99, 0x4C, 0x18, 0xCD, 0x67, 0xB2,
-		0x39, 0xEC, 0x46, 0x93, 0xC7, 0x12, 0xB8, 0x6D,
-		0x10, 0xC5, 0x6F, 0xBA, 0xEE, 0x3B, 0x91, 0x44,
-		0x6B, 0xBE, 0x14, 0xC1, 0x95, 0x40, 0xEA, 0x3F,
-		0x42, 0x97, 0x3D, 0xE8, 0xBC, 0x69, 0xC3, 0x16,
-		0xEF, 0x3A, 0x90, 0x45, 0x11, 0xC4, 0x6E, 0xBB,
-		0xC6, 0x13, 0xB9, 0x6C, 0x38, 0xED, 0x47, 0x92,
-		0xBD, 0x68, 0xC2, 0x17, 0x43, 0x96, 0x3C, 0xE9,
-		0x94, 0x41, 0xEB, 0x3E, 0x6A, 0xBF, 0x15, 0xC0,
-		0x4B, 0x9E, 0x34, 0xE1, 0xB5, 0x60, 0xCA, 0x1F,
-		0x62, 0xB7, 0x1D, 0xC8, 0x9C, 0x49, 0xE3, 0x36,
-		0x19, 0xCC, 0x66, 0xB3, 0xE7, 0x32, 0x98, 0x4D,
-		0x30, 0xE5, 0x4F, 0x9A, 0xCE, 0x1B, 0xB1, 0x64,
-		0x72, 0xA7, 0x0D, 0xD8, 0x8C, 0x59, 0xF3, 0x26,
-		0x5B, 0x8E, 0x24, 0xF1, 0xA5, 0x70, 0xDA, 0x0F,
-		0x20, 0xF5, 0x5F, 0x8A, 0xDE, 0x0B, 0xA1, 0x74,
-		0x09, 0xDC, 0x76, 0xA3, 0xF7, 0x22, 0x88, 0x5D,
-		0xD6, 0x03, 0xA9, 0x7C, 0x28, 0xFD, 0x57, 0x82,
-		0xFF, 0x2A, 0x80, 0x55, 0x01, 0xD4, 0x7E, 0xAB,
-		0x84, 0x51, 0xFB, 0x2E, 0x7A, 0xAF, 0x05, 0xD0,
-		0xAD, 0x78, 0xD2, 0x07, 0x53, 0x86, 0x2C, 0xF9
-	};
-
-	if ((frameCode ^ 0x10) >= 0x50) {
-		// Decode embedded string
-		Common::String str;
-		uint8 stringLen = frameData.getBits(8);
-		byte xorVal = stringXORTable[stringLen];
-
-		for (uint16 i = 0; i < stringLen-1; i++) {
-			byte data = frameData.getBits(8);
-			str += data ^ xorVal;
-			xorVal = stringXORTable[data];
-		}
-		debug(1, " Embedded String of %d Characters: \"%s\"", stringLen, str.c_str());
-	}
-
-	byte unk1 = frameData.getBits(2); // Unknown
-	debug(1, " unk1: %d", unk1);
-	byte unk2 = frameData.getBits(2); // Unknown
-	debug(1, " unk2: %d", unk2);
-	bool unk3 = frameData.getBit(); // Unknown
-	debug(1, " unk3: %d", unk3);
-
-	static const struct { uint w, h; } standardFrameSizes[7] = {
-		{ 160, 120 }, // 0
-		{ 128,  96 }, // 1
-		{ 176, 144 }, // 2
-		{ 352, 288 }, // 3
-		{ 704, 576 }, // 4
-		{ 240, 180 }, // 5
-		{ 320, 240 }  // 6
-	};
-
-	byte frameSizeCode = frameData.getBits(3);
-	debug(1, " frameSizeCode: %d", frameSizeCode);
-	uint16 frameWidth, frameHeight;
-	if (frameSizeCode == 7) {
-		frameWidth = frameData.getBits(12);
-		frameHeight = frameData.getBits(12);
-	} else {
-		frameWidth = standardFrameSizes[frameSizeCode].w;
-		frameHeight = standardFrameSizes[frameSizeCode].h;
-	}
-	debug(1, " frameWidth: %d", frameWidth);
-	debug(1, " frameHeight: %d", frameHeight);
-	if (frameWidth == 0 || frameHeight == 0) { // Invalid
-		warning("Invalid Frame Size");
-		return _surface;
-	}
-	bool checksumPresent = frameData.getBit();
-	debug(1, " checksumPresent: %d", checksumPresent);
-	if (checksumPresent) {
-		bool usePacketChecksum = frameData.getBit();
-		debug(1, " usePacketChecksum: %d", usePacketChecksum);
-		bool componentChecksumsAfterImageData = frameData.getBit();
-		debug(1, " componentChecksumsAfterImageData: %d", componentChecksumsAfterImageData);
-		byte unk4 = frameData.getBits(2);
-		debug(1, " unk4: %d", unk4);
-		if (unk4 != 0)
-			warning("Invalid Frame Header in SVQ1 Frame Decode");
-	}
-
-	bool unk5 = frameData.getBit();
-	debug(1, " unk5: %d", unk5);
-	if (unk5) {
-		bool unk6 = frameData.getBit();
-		debug(1, " unk6: %d", unk6);
-		byte unk7 = frameData.getBits(4);
-		debug(1, " unk7: %d", unk7);
-		bool unk8 = frameData.getBit();
-		debug(1, " unk8: %d", unk8);
-		byte unk9 = frameData.getBits(2);
-		debug(1, " unk9: %d", unk9);
-		while (frameData.getBit()) {
-			byte unk10 = frameData.getBits(8);
-			debug(1, " unk10: %d", unk10);
-		}
-	}
-
-	if (frameWidth == _surface->w && frameHeight == _surface->h) {
-		// Decode Y, U and V component planes
-		for (int i = 0; i < 3; i++) {
-			int linesize, width, height;
-			if (i == 0) {
-				// Y Size is width * height
-				width  = frameWidth;
-				if (width % 16) {
-					width /= 16;
-					width++;
-					width *= 16;
-				}
-				assert(width % 16 == 0);
-				height = frameHeight;
-				if (height % 16) {
-					height /= 16;
-					height++;
-					height *= 16;
-				}
-				assert(height % 16 == 0);
-				linesize = width;
-			} else {
-				// U and V size is width/4 * height/4
-				width  = frameWidth/4;
-				if (width % 16) {
-					width /= 16;
-					width++;
-					width *= 16;
-				}
-				assert(width % 16 == 0);
-				height = frameHeight/4;
-				if (height % 16) {
-					height /= 16;
-					height++;
-					height *= 16;
-				}
-				assert(height % 16 == 0);
-				linesize = width;
-			}
-
-			if (frameType == 0) { // I Frame
-				// Keyframe (I)
-				byte *current = _current[i];
-				for (uint16 y = 0; y < height; y += 16) {
-					for (uint16 x = 0; x < width; x += 16) {
-						if (int result = svq1DecodeBlockIntra(&frameData, &current[x], linesize) != 0) {
-							warning("Error in svq1DecodeBlock %i (keyframe)", result);
-							return _surface;
-						}
-					}
-					current += 16 * linesize;
-				}
-			} else {
-				// Delta frame (P or B)
-
-				// Prediction Motion Vector
-				Common::Point *pmv = new Common::Point[(width/8) + 3];
-
-				byte *previous;
-				if(frameType == 2) { // B Frame
-					warning("B Frame not supported currently");
-					//previous = _next[i];
-				} else
-					previous = _last[i];
-
-				byte *current = _current[i];
-				for (uint16 y = 0; y < height; y += 16) {
-					for (uint16 x = 0; x < width; x += 16) {
-						if (int result = svq1DecodeDeltaBlock(&frameData, &current[x], previous, linesize, pmv, x, y) != 0) {
-							warning("Error in svq1DecodeDeltaBlock %i", result);
-							return _surface;
-						}
-					}
-
-					pmv[0].x = pmv[0].y = 0;
-
-					current += 16*linesize;
-				}
-				delete[] pmv;
-			}
-		}
-
-		convertYUV410ToRGB(_surface, _current[0], _current[1], _current[2], frameWidth, frameHeight, frameWidth, frameWidth/2);
-	} else
-		warning("FrameWidth/Height Sanity Check Failed!");
-
-	return _surface;
-}
-
 } // End of namespace Video
diff --git a/video/codecs/svq1.h b/video/codecs/svq1.h
index 786a2bb..2271bf4 100644
--- a/video/codecs/svq1.h
+++ b/video/codecs/svq1.h
@@ -25,6 +25,12 @@
 
 #include "video/codecs/codec.h"
 
+namespace Common {
+class BitStream;
+class Huffman;
+class Point;
+}
+
 namespace Video {
 
 class SVQ1Decoder : public Codec {
@@ -40,6 +46,24 @@ private:
 
 	byte *_current[3];
 	byte *_last[3];
+
+	Common::Huffman *_blockType;
+	Common::Huffman *_intraMultistage[6];
+	Common::Huffman *_interMultistage[6];
+	Common::Huffman *_intraMean;
+	Common::Huffman *_interMean;
+	Common::Huffman *_motionComponent;
+
+	int svq1DecodeBlockIntra(Common::BitStream *s, uint8 *pixels, int pitch);
+	int svq1DecodeBlockNonIntra(Common::BitStream *s, uint8 *pixels, int pitch);
+	int svq1DecodeMotionVector(Common::BitStream *s, Common::Point *mv, Common::Point **pmv);
+	void svq1SkipBlock(uint8 *current, uint8 *previous, int pitch, int x, int y);
+	int svq1MotionInterBlock(Common::BitStream *ss, uint8 *current, uint8 *previous, int pitch,
+			Common::Point *motion, int x, int y);
+	int svq1MotionInter4vBlock(Common::BitStream *ss, uint8 *current, uint8 *previous, int pitch,
+			Common::Point *motion, int x, int y);
+	int svq1DecodeDeltaBlock(Common::BitStream *ss, uint8 *current, uint8 *previous, int pitch,
+			Common::Point *motion, int x, int y);
 };
 
 } // End of namespace Video
diff --git a/video/codecs/svq1_vlc.h b/video/codecs/svq1_vlc.h
index 0b9477f..eb70eb5 100644
--- a/video/codecs/svq1_vlc.h
+++ b/video/codecs/svq1_vlc.h
@@ -23,272 +23,316 @@
 #ifndef VIDEO_CODECS_SVQ1_VLC_H
 #define VIDEO_CODECS_SVQ1_VLC_H
 
-// values in this table range from 0..3; adjust retrieved value by +0
-const uint8 svq1_block_type_vlc[4][2] = {
- // { code, length }
-    { 0x1, 1 },  { 0x1, 2 },  { 0x1, 3 },  { 0x0, 3 }
-
-};
-
-// values in this table range from -1..6; adjust retrieved value by -1
-const uint8 svq1_intra_multistage_vlc[6][8][2] = {
- // { code, length }
-{
-    { 0x1, 5 },  { 0x1, 1 },  { 0x3, 3 },  { 0x2, 3 },
-    { 0x3, 4 },  { 0x2, 4 },  { 0x0, 5 },  { 0x1, 4 }
-},{
-    { 0x1, 4 },  { 0x3, 2 },  { 0x5, 3 },  { 0x4, 3 },
-    { 0x3, 3 },  { 0x2, 3 },  { 0x0, 4 },  { 0x1, 3 }
-},{
-    { 0x1, 5 },  { 0x1, 1 },  { 0x3, 3 },  { 0x0, 5 },
-    { 0x3, 4 },  { 0x2, 3 },  { 0x2, 4 },  { 0x1, 4 }
-},{
-    { 0x1, 6 },  { 0x1, 1 },  { 0x1, 2 },  { 0x0, 6 },
-    { 0x3, 4 },  { 0x2, 4 },  { 0x1, 5 },  { 0x1, 4 }
-},{
-    { 0x1, 6 },  { 0x1, 1 },  { 0x1, 2 },  { 0x3, 5 },
-    { 0x2, 5 },  { 0x0, 6 },  { 0x1, 5 },  { 0x1, 3 }
-},{
-    { 0x1, 7 },  { 0x1, 1 },  { 0x1, 2 },  { 0x1, 3 },
-    { 0x1, 4 },  { 0x1, 6 },  { 0x0, 7 },  { 0x1, 5 }
-}
-};
-
-// values in this table range from -1..6; adjust retrieved value by -1
-const uint8 svq1_inter_multistage_vlc[6][8][2] = {
- // { code, length }
-{
-    { 0x3, 2 },  { 0x5, 3 },  { 0x4, 3 },  { 0x3, 3 },
-    { 0x2, 3 },  { 0x1, 3 },  { 0x1, 4 },  { 0x0, 4 }
-},{
-    { 0x3, 2 },  { 0x5, 3 },  { 0x4, 3 },  { 0x3, 3 },
-    { 0x2, 3 },  { 0x1, 3 },  { 0x1, 4 },  { 0x0, 4 }
-},{
-    { 0x1, 1 },  { 0x3, 3 },  { 0x2, 3 },  { 0x3, 4 },
-    { 0x2, 4 },  { 0x1, 4 },  { 0x1, 5 },  { 0x0, 5 }
-},{
-    { 0x1, 1 },  { 0x3, 3 },  { 0x2, 3 },  { 0x3, 4 },
-    { 0x2, 4 },  { 0x1, 4 },  { 0x1, 5 },  { 0x0, 5 }
-},{
-    { 0x1, 1 },  { 0x3, 3 },  { 0x2, 3 },  { 0x3, 4 },
-    { 0x2, 4 },  { 0x1, 4 },  { 0x1, 5 },  { 0x0, 5 }
-},{
-    { 0x1, 1 },  { 0x1, 2 },  { 0x1, 3 },  { 0x3, 5 },
-    { 0x2, 5 },  { 0x1, 5 },  { 0x1, 6 },  { 0x0, 6 }
-}
-};
-
-// values in this table range from 0..255; adjust retrieved value by +0
-const uint16 svq1_intra_mean_vlc[256][2] = {
- // { code, length }
-    { 0x37, 6 },  { 0x56, 7 },  { 0x1, 17 },  { 0x1, 20 },
-    { 0x2, 20 },  { 0x3, 20 },  { 0x0, 20 },  { 0x4, 20 },
-    { 0x5, 20 },  { 0x3, 19 },  { 0x15, 11 },  { 0x42, 9 },
-    { 0x14, 11 },  { 0x3, 14 },  { 0x2, 14 },  { 0x1, 15 },
-    { 0x1, 16 },  { 0x1, 12 },  { 0x2B, 10 },  { 0x18, 11 },
-    { 0xC, 11 },  { 0x41, 9 },  { 0x78, 8 },  { 0x6C, 8 },
-    { 0x55, 7 },  { 0xF, 4 },  { 0xE, 4 },  { 0x34, 6 },
-    { 0x51, 7 },  { 0x72, 8 },  { 0x6E, 8 },  { 0x40, 9 },
-    { 0x3F, 9 },  { 0x3E, 9 },  { 0x3D, 9 },  { 0x3C, 9 },
-    { 0x3B, 9 },  { 0x3A, 9 },  { 0x39, 9 },  { 0x38, 9 },
-    { 0x37, 9 },  { 0x43, 9 },  { 0x46, 9 },  { 0x47, 9 },
-    { 0x45, 9 },  { 0x44, 9 },  { 0x49, 9 },  { 0x48, 9 },
-    { 0x4A, 8 },  { 0x79, 8 },  { 0x76, 8 },  { 0x77, 8 },
-    { 0x71, 8 },  { 0x75, 8 },  { 0x74, 8 },  { 0x73, 8 },
-    { 0x6A, 8 },  { 0x55, 8 },  { 0x70, 8 },  { 0x6F, 8 },
-    { 0x52, 8 },  { 0x6D, 8 },  { 0x4C, 8 },  { 0x6B, 8 },
-    { 0x40, 7 },  { 0x69, 8 },  { 0x68, 8 },  { 0x67, 8 },
-    { 0x66, 8 },  { 0x65, 8 },  { 0x64, 8 },  { 0x63, 8 },
-    { 0x62, 8 },  { 0x61, 8 },  { 0x60, 8 },  { 0x5F, 8 },
-    { 0x5E, 8 },  { 0x5D, 8 },  { 0x5C, 8 },  { 0x5B, 8 },
-    { 0x5A, 8 },  { 0x59, 8 },  { 0x58, 8 },  { 0x57, 8 },
-    { 0x56, 8 },  { 0x3D, 7 },  { 0x54, 8 },  { 0x53, 8 },
-    { 0x3F, 7 },  { 0x51, 8 },  { 0x50, 8 },  { 0x4F, 8 },
-    { 0x4E, 8 },  { 0x4D, 8 },  { 0x41, 7 },  { 0x4B, 8 },
-    { 0x53, 7 },  { 0x3E, 7 },  { 0x48, 8 },  { 0x4F, 7 },
-    { 0x52, 7 },  { 0x45, 8 },  { 0x50, 7 },  { 0x43, 8 },
-    { 0x42, 8 },  { 0x41, 8 },  { 0x42, 7 },  { 0x43, 7 },
-    { 0x3E, 8 },  { 0x44, 7 },  { 0x3C, 8 },  { 0x45, 7 },
-    { 0x46, 7 },  { 0x47, 7 },  { 0x48, 7 },  { 0x49, 7 },
-    { 0x4A, 7 },  { 0x4B, 7 },  { 0x4C, 7 },  { 0x4D, 7 },
-    { 0x4E, 7 },  { 0x58, 7 },  { 0x59, 7 },  { 0x5A, 7 },
-    { 0x5B, 7 },  { 0x5C, 7 },  { 0x5D, 7 },  { 0x44, 8 },
-    { 0x49, 8 },  { 0x29, 8 },  { 0x3F, 8 },  { 0x3D, 8 },
-    { 0x3B, 8 },  { 0x2C, 8 },  { 0x28, 8 },  { 0x25, 8 },
-    { 0x26, 8 },  { 0x5E, 7 },  { 0x57, 7 },  { 0x54, 7 },
-    { 0x5F, 7 },  { 0x62, 7 },  { 0x63, 7 },  { 0x64, 7 },
-    { 0x61, 7 },  { 0x65, 7 },  { 0x67, 7 },  { 0x66, 7 },
-    { 0x35, 6 },  { 0x36, 6 },  { 0x60, 7 },  { 0x39, 8 },
-    { 0x3A, 8 },  { 0x38, 8 },  { 0x37, 8 },  { 0x36, 8 },
-    { 0x35, 8 },  { 0x34, 8 },  { 0x33, 8 },  { 0x32, 8 },
-    { 0x31, 8 },  { 0x30, 8 },  { 0x2D, 8 },  { 0x2B, 8 },
-    { 0x2A, 8 },  { 0x27, 8 },  { 0x40, 8 },  { 0x46, 8 },
-    { 0x47, 8 },  { 0x26, 9 },  { 0x25, 9 },  { 0x24, 9 },
-    { 0x23, 9 },  { 0x22, 9 },  { 0x2E, 8 },  { 0x2F, 8 },
-    { 0x1F, 9 },  { 0x36, 9 },  { 0x1D, 9 },  { 0x21, 9 },
-    { 0x1B, 9 },  { 0x1C, 9 },  { 0x19, 9 },  { 0x1A, 9 },
-    { 0x18, 9 },  { 0x17, 9 },  { 0x16, 9 },  { 0x1E, 9 },
-    { 0x20, 9 },  { 0x27, 9 },  { 0x28, 9 },  { 0x29, 9 },
-    { 0x2A, 9 },  { 0x2B, 9 },  { 0x2C, 9 },  { 0x2D, 9 },
-    { 0x2E, 9 },  { 0x2F, 9 },  { 0x30, 9 },  { 0x35, 9 },
-    { 0x31, 9 },  { 0x32, 9 },  { 0x33, 9 },  { 0x34, 9 },
-    { 0x19, 10 },  { 0x2A, 10 },  { 0x17, 10 },  { 0x16, 10 },
-    { 0x15, 10 },  { 0x28, 10 },  { 0x26, 10 },  { 0x25, 10 },
-    { 0x22, 10 },  { 0x21, 10 },  { 0x18, 10 },  { 0x14, 10 },
-    { 0x29, 10 },  { 0x12, 10 },  { 0xD, 10 },  { 0xE, 10 },
-    { 0xF, 10 },  { 0x10, 10 },  { 0x11, 10 },  { 0x1A, 10 },
-    { 0x1B, 10 },  { 0x1C, 10 },  { 0x1D, 10 },  { 0x1E, 10 },
-    { 0x1F, 10 },  { 0x20, 10 },  { 0x13, 10 },  { 0x23, 10 },
-    { 0x24, 10 },  { 0x9, 11 },  { 0x8, 11 },  { 0x7, 11 },
-    { 0x27, 10 },  { 0x5, 11 },  { 0xB, 11 },  { 0x6, 11 },
-    { 0x4, 11 },  { 0x3, 11 },  { 0x2, 11 },  { 0x1, 11 },
-    { 0xA, 11 },  { 0x16, 11 },  { 0x19, 11 },  { 0x17, 11 },
-    { 0xD, 11 },  { 0xE, 11 },  { 0xF, 11 },  { 0x10, 11 },
-    { 0x11, 11 },  { 0x12, 11 },  { 0x13, 11 },  { 0x1, 14 }
-};
-
-// values in this table range from -256..255; adjust retrieved value by -256
-const uint16 svq1_inter_mean_vlc[512][2] = {
- // { code, length }
-    { 0x5A, 22 },  { 0xD4, 22 },  { 0xD5, 22 },  { 0xD6, 22 },
-    { 0xD7, 22 },  { 0xD8, 22 },  { 0xD9, 22 },  { 0xDA, 22 },
-    { 0xDB, 22 },  { 0xDC, 22 },  { 0xDD, 22 },  { 0xDE, 22 },
-    { 0xDF, 22 },  { 0xE0, 22 },  { 0xE1, 22 },  { 0xE2, 22 },
-    { 0xE3, 22 },  { 0xE4, 22 },  { 0xE5, 22 },  { 0xE6, 22 },
-    { 0xE8, 22 },  { 0xCB, 22 },  { 0xE9, 22 },  { 0xEA, 22 },
-    { 0xE7, 22 },  { 0xEC, 22 },  { 0xED, 22 },  { 0xEE, 22 },
-    { 0xEF, 22 },  { 0xF0, 22 },  { 0xF1, 22 },  { 0xF2, 22 },
-    { 0xF3, 22 },  { 0xF4, 22 },  { 0xF5, 22 },  { 0xF6, 22 },
-    { 0xF7, 22 },  { 0xF8, 22 },  { 0x102, 22 },  { 0xEB, 22 },
-    { 0xF9, 22 },  { 0xFC, 22 },  { 0xFD, 22 },  { 0xFE, 22 },
-    { 0x100, 22 },  { 0x5C, 22 },  { 0x60, 22 },  { 0x101, 22 },
-    { 0x71, 22 },  { 0x104, 22 },  { 0x105, 22 },  { 0xFB, 22 },
-    { 0xFF, 22 },  { 0x86, 21 },  { 0xFA, 22 },  { 0x7C, 22 },
-    { 0x75, 22 },  { 0x103, 22 },  { 0x78, 22 },  { 0xD3, 22 },
-    { 0x7B, 22 },  { 0x82, 22 },  { 0xD2, 22 },  { 0xD1, 22 },
-    { 0xD0, 22 },  { 0xCF, 22 },  { 0xCE, 22 },  { 0xCD, 22 },
-    { 0xCC, 22 },  { 0xC3, 22 },  { 0xCA, 22 },  { 0xC9, 22 },
-    { 0xC8, 22 },  { 0xC7, 22 },  { 0xC6, 22 },  { 0xC5, 22 },
-    { 0x8B, 22 },  { 0xC4, 22 },  { 0xC2, 22 },  { 0xC1, 22 },
-    { 0xC0, 22 },  { 0xBF, 22 },  { 0xBE, 22 },  { 0xBD, 22 },
-    { 0xBC, 22 },  { 0xBB, 22 },  { 0xBA, 22 },  { 0xB9, 22 },
-    { 0x61, 22 },  { 0x84, 22 },  { 0x85, 22 },  { 0x86, 22 },
-    { 0x87, 22 },  { 0x88, 22 },  { 0x89, 22 },  { 0x8A, 22 },
-    { 0x8C, 22 },  { 0x8D, 22 },  { 0x8E, 22 },  { 0x8F, 22 },
-    { 0x90, 22 },  { 0x91, 22 },  { 0x92, 22 },  { 0x93, 22 },
-    { 0x94, 22 },  { 0x95, 22 },  { 0x96, 22 },  { 0x97, 22 },
-    { 0x98, 22 },  { 0x99, 22 },  { 0x9A, 22 },  { 0x9B, 22 },
-    { 0x9C, 22 },  { 0x9D, 22 },  { 0x9E, 22 },  { 0x9F, 22 },
-    { 0xA0, 22 },  { 0xA1, 22 },  { 0xA2, 22 },  { 0xA3, 22 },
-    { 0xA4, 22 },  { 0xA5, 22 },  { 0xA6, 22 },  { 0xA7, 22 },
-    { 0xA8, 22 },  { 0xA9, 22 },  { 0xAA, 22 },  { 0xAB, 22 },
-    { 0x7F, 22 },  { 0x8F, 21 },  { 0xAC, 22 },  { 0xAD, 22 },
-    { 0xAE, 22 },  { 0xAF, 22 },  { 0xB0, 22 },  { 0xB1, 22 },
-    { 0x53, 20 },  { 0x90, 21 },  { 0xB2, 22 },  { 0x91, 21 },
-    { 0xB3, 22 },  { 0xB4, 22 },  { 0x54, 20 },  { 0xB5, 22 },
-    { 0xB6, 22 },  { 0x8C, 21 },  { 0x34, 19 },  { 0x3D, 18 },
-    { 0x55, 20 },  { 0xB7, 22 },  { 0xB8, 22 },  { 0x8B, 21 },
-    { 0x56, 20 },  { 0x3D, 19 },  { 0x57, 20 },  { 0x58, 20 },
-    { 0x40, 19 },  { 0x43, 19 },  { 0x47, 19 },  { 0x2A, 18 },
-    { 0x2E, 19 },  { 0x2C, 18 },  { 0x46, 19 },  { 0x59, 20 },
-    { 0x49, 19 },  { 0x2D, 19 },  { 0x38, 18 },  { 0x36, 18 },
-    { 0x39, 18 },  { 0x45, 19 },  { 0x28, 18 },  { 0x30, 18 },
-    { 0x35, 18 },  { 0x20, 17 },  { 0x44, 19 },  { 0x32, 18 },
-    { 0x31, 18 },  { 0x1F, 17 },  { 0x2F, 18 },  { 0x2E, 18 },
-    { 0x2D, 18 },  { 0x21, 17 },  { 0x22, 17 },  { 0x23, 17 },
-    { 0x24, 17 },  { 0x27, 16 },  { 0x23, 16 },  { 0x20, 16 },
-    { 0x1D, 16 },  { 0x25, 16 },  { 0x1E, 16 },  { 0x24, 16 },
-    { 0x2A, 16 },  { 0x26, 16 },  { 0x21, 15 },  { 0x29, 16 },
-    { 0x22, 15 },  { 0x23, 15 },  { 0x24, 15 },  { 0x1B, 15 },
-    { 0x1A, 15 },  { 0x1D, 15 },  { 0x1F, 15 },  { 0x27, 15 },
-    { 0x17, 14 },  { 0x18, 14 },  { 0x19, 14 },  { 0x1B, 14 },
-    { 0x1C, 14 },  { 0x1E, 14 },  { 0x25, 14 },  { 0x20, 14 },
-    { 0x21, 14 },  { 0x13, 13 },  { 0x14, 13 },  { 0x15, 13 },
-    { 0x16, 13 },  { 0x17, 13 },  { 0x18, 13 },  { 0x19, 13 },
-    { 0x1A, 13 },  { 0x18, 12 },  { 0x17, 12 },  { 0x15, 12 },
-    { 0x14, 12 },  { 0x13, 12 },  { 0x12, 12 },  { 0xF, 11 },
-    { 0x10, 11 },  { 0x12, 11 },  { 0x13, 11 },  { 0x1B, 11 },
-    { 0x1A, 11 },  { 0xE, 10 },  { 0x13, 10 },  { 0xF, 10 },
-    { 0x10, 10 },  { 0x11, 10 },  { 0x12, 10 },  { 0xD, 9 },
-    { 0x14, 9 },  { 0x15, 9 },  { 0xC, 9 },  { 0x13, 9 },
-    { 0xF, 8 },  { 0xE, 8 },  { 0x10, 8 },  { 0x11, 8 },
-    { 0xC, 7 },  { 0x9, 7 },  { 0xA, 7 },  { 0x8, 6 },
-    { 0x9, 6 },  { 0x9, 5 },  { 0x8, 5 },  { 0x5, 4 },
-    { 0x1, 1 },  { 0x3, 3 },  { 0x7, 5 },  { 0x6, 5 },
-    { 0xB, 6 },  { 0xA, 6 },  { 0xE, 7 },  { 0xF, 7 },
-    { 0xB, 7 },  { 0xD, 7 },  { 0xB, 8 },  { 0xD, 8 },
-    { 0xC, 8 },  { 0xF, 9 },  { 0x10, 9 },  { 0x11, 9 },
-    { 0xE, 9 },  { 0x12, 9 },  { 0x17, 10 },  { 0x14, 10 },
-    { 0x16, 10 },  { 0x15, 10 },  { 0x19, 11 },  { 0x18, 11 },
-    { 0x17, 11 },  { 0x16, 11 },  { 0x15, 11 },  { 0x14, 11 },
-    { 0x11, 11 },  { 0x19, 12 },  { 0x1A, 12 },  { 0x16, 12 },
-    { 0x1D, 12 },  { 0x1B, 12 },  { 0x1C, 12 },  { 0x20, 13 },
-    { 0x1C, 13 },  { 0x23, 13 },  { 0x22, 13 },  { 0x21, 13 },
-    { 0x1F, 13 },  { 0x1E, 13 },  { 0x1B, 13 },  { 0x1D, 13 },
-    { 0x24, 14 },  { 0x16, 14 },  { 0x1A, 14 },  { 0x22, 14 },
-    { 0x1D, 14 },  { 0x1F, 14 },  { 0x15, 14 },  { 0x23, 14 },
-    { 0x18, 15 },  { 0x20, 15 },  { 0x29, 15 },  { 0x28, 15 },
-    { 0x26, 15 },  { 0x25, 15 },  { 0x19, 15 },  { 0x1C, 15 },
-    { 0x1E, 15 },  { 0x17, 15 },  { 0x2C, 16 },  { 0x2B, 16 },
-    { 0x1C, 16 },  { 0x21, 16 },  { 0x2D, 16 },  { 0x28, 16 },
-    { 0x1F, 16 },  { 0x1B, 16 },  { 0x1A, 16 },  { 0x22, 16 },
-    { 0x2D, 17 },  { 0x32, 17 },  { 0x2C, 17 },  { 0x27, 17 },
-    { 0x31, 17 },  { 0x33, 17 },  { 0x2F, 17 },  { 0x2B, 17 },
-    { 0x37, 18 },  { 0x2A, 17 },  { 0x2E, 17 },  { 0x30, 17 },
-    { 0x29, 17 },  { 0x28, 17 },  { 0x26, 17 },  { 0x25, 17 },
-    { 0x2F, 19 },  { 0x33, 18 },  { 0x34, 18 },  { 0x30, 19 },
-    { 0x3A, 18 },  { 0x3B, 18 },  { 0x31, 19 },  { 0x3C, 18 },
-    { 0x2B, 18 },  { 0x29, 18 },  { 0x48, 19 },  { 0x27, 18 },
-    { 0x42, 19 },  { 0x41, 19 },  { 0x26, 18 },  { 0x52, 20 },
-    { 0x51, 20 },  { 0x3F, 19 },  { 0x3E, 19 },  { 0x39, 19 },
-    { 0x3C, 19 },  { 0x3B, 19 },  { 0x3A, 19 },  { 0x25, 18 },
-    { 0x38, 19 },  { 0x50, 20 },  { 0x37, 19 },  { 0x36, 19 },
-    { 0x87, 21 },  { 0x4F, 20 },  { 0x35, 19 },  { 0x4E, 20 },
-    { 0x33, 19 },  { 0x32, 19 },  { 0x4D, 20 },  { 0x4C, 20 },
-    { 0x83, 22 },  { 0x4B, 20 },  { 0x81, 22 },  { 0x80, 22 },
-    { 0x8E, 21 },  { 0x7E, 22 },  { 0x7D, 22 },  { 0x84, 21 },
-    { 0x8D, 21 },  { 0x7A, 22 },  { 0x79, 22 },  { 0x4A, 20 },
-    { 0x77, 22 },  { 0x76, 22 },  { 0x89, 21 },  { 0x74, 22 },
-    { 0x73, 22 },  { 0x72, 22 },  { 0x49, 20 },  { 0x70, 22 },
-    { 0x6F, 22 },  { 0x6E, 22 },  { 0x6D, 22 },  { 0x6C, 22 },
-    { 0x6B, 22 },  { 0x6A, 22 },  { 0x69, 22 },  { 0x68, 22 },
-    { 0x67, 22 },  { 0x66, 22 },  { 0x65, 22 },  { 0x64, 22 },
-    { 0x63, 22 },  { 0x62, 22 },  { 0x8A, 21 },  { 0x88, 21 },
-    { 0x5F, 22 },  { 0x5E, 22 },  { 0x5D, 22 },  { 0x85, 21 },
-    { 0x5B, 22 },  { 0x83, 21 },  { 0x59, 22 },  { 0x58, 22 },
-    { 0x57, 22 },  { 0x56, 22 },  { 0x55, 22 },  { 0x54, 22 },
-    { 0x53, 22 },  { 0x52, 22 },  { 0x51, 22 },  { 0x50, 22 },
-    { 0x4F, 22 },  { 0x4E, 22 },  { 0x4D, 22 },  { 0x4C, 22 },
-    { 0x4B, 22 },  { 0x4A, 22 },  { 0x49, 22 },  { 0x48, 22 },
-    { 0x47, 22 },  { 0x46, 22 },  { 0x45, 22 },  { 0x44, 22 },
-    { 0x43, 22 },  { 0x42, 22 },  { 0x41, 22 },  { 0x40, 22 },
-    { 0x3F, 22 },  { 0x3E, 22 },  { 0x3D, 22 },  { 0x3C, 22 },
-    { 0x3B, 22 },  { 0x3A, 22 },  { 0x39, 22 },  { 0x38, 22 },
-    { 0x37, 22 },  { 0x36, 22 },  { 0x35, 22 },  { 0x34, 22 },
-    { 0x33, 22 },  { 0x32, 22 },  { 0x31, 22 },  { 0x30, 22 },
-    { 0x2F, 22 },  { 0x2E, 22 },  { 0x2D, 22 },  { 0x2C, 22 },
-    { 0x2B, 22 },  { 0x2A, 22 },  { 0x29, 22 },  { 0x28, 22 },
-    { 0x27, 22 },  { 0x26, 22 },  { 0x25, 22 },  { 0x24, 22 },
-    { 0x23, 22 },  { 0x22, 22 },  { 0x21, 22 },  { 0x20, 22 },
-    { 0x1F, 22 },  { 0x1E, 22 },  { 0x1D, 22 },  { 0x1C, 22 },
-    { 0x1B, 22 },  { 0x1A, 22 },  { 0x19, 22 },  { 0x18, 22 },
-    { 0x17, 22 },  { 0x16, 22 },  { 0x15, 22 },  { 0x14, 22 },
-    { 0x13, 22 },  { 0x12, 22 },  { 0x11, 22 },  { 0x10, 22 },
-    { 0xF, 22 },  { 0xE, 22 },  { 0xD, 22 },  { 0xC, 22 },
-    { 0xB, 22 },  { 0xA, 22 },  { 0x9, 22 },  { 0x8, 22 },
-    { 0x7, 22 },  { 0x6, 22 },  { 0x5, 22 },  { 0x4, 22 },
-    { 0x3, 22 },  { 0x2, 22 },  { 0x1, 22 },  { 0x0, 22 }
-};
-
-// From H263 Data Tables
-const uint8 mvtab[33][2] =
-{
-  {1,1}, {1,2}, {1,3}, {1,4}, {3,6}, {5,7}, {4,7}, {3,7},
-  {11,9}, {10,9}, {9,9}, {17,10}, {16,10}, {15,10}, {14,10}, {13,10},
-  {12,10}, {11,10}, {10,10}, {9,10}, {8,10}, {7,10}, {6,10}, {5,10},
-  {4,10}, {7,11}, {6,11}, {5,11}, {4,11}, {3,11}, {2,11}, {3,12},
-  {2,12}
+#include "common/scummsys.h"
+
+namespace Video {
+
+static const byte s_svq1BlockTypeLengths[4] = {
+	1, 2, 3, 3
+};
+
+static const uint32 s_svq1BlockTypeCodes[4] = {
+	1, 1, 1, 0
+};
+
+static const byte s_svq1IntraMultistageLengths0[8] = {
+	5, 1, 3, 3, 4, 4, 5, 4
+};
+
+static const uint32 s_svq1IntraMultistageCodes0[8] = {
+	1, 1, 3, 2, 3, 2, 0, 1
+};
+
+static const byte s_svq1IntraMultistageLengths1[8] = {
+	4, 2, 3, 3, 3, 3, 4, 3
+};
+
+static const uint32 s_svq1IntraMultistageCodes1[8] = {
+	1, 3, 5, 4, 3, 2, 0, 1
+};
+
+static const byte s_svq1IntraMultistageLengths2[8] = {
+	5, 1, 3, 5, 4, 3, 4, 4
+};
+
+static const uint32 s_svq1IntraMultistageCodes2[8] = {
+	1, 1, 3, 0, 3, 2, 2, 1
+};
+
+static const byte s_svq1IntraMultistageLengths3[8] = {
+	6, 1, 2, 6, 4, 4, 5, 4
+};
+
+static const uint32 s_svq1IntraMultistageCodes3[8] = {
+	1, 1, 1, 0, 3, 2, 1, 1
+};
+
+static const byte s_svq1IntraMultistageLengths4[8] = {
+	6, 1, 2, 5, 5, 6, 5, 3
+};
+
+static const uint32 s_svq1IntraMultistageCodes4[8] = {
+	1, 1, 1, 3, 2, 0, 1, 1
+};
+
+static const byte s_svq1IntraMultistageLengths5[8] = {
+	7, 1, 2, 3, 4, 6, 7, 5
+};
+
+static const uint32 s_svq1IntraMultistageCodes5[8] = {
+	1, 1, 1, 1, 1, 1, 0, 1
+};
+
+static const byte *s_svq1IntraMultistageLengths[6] = {
+	s_svq1IntraMultistageLengths0, s_svq1IntraMultistageLengths1, s_svq1IntraMultistageLengths2,
+	s_svq1IntraMultistageLengths3, s_svq1IntraMultistageLengths4, s_svq1IntraMultistageLengths5
+};
+
+static const uint32 *s_svq1IntraMultistageCodes[6] = {
+	s_svq1IntraMultistageCodes0, s_svq1IntraMultistageCodes1, s_svq1IntraMultistageCodes2,
+	s_svq1IntraMultistageCodes3, s_svq1IntraMultistageCodes4, s_svq1IntraMultistageCodes5
+};
+
+static const byte s_svq1InterMultistageLengths0[8] = {
+	2, 3, 3, 3, 3, 3, 4, 4
+};
+
+static const uint32 s_svq1InterMultistageCodes0[8] = {
+	3, 5, 4, 3, 2, 1, 1, 0
+};
+
+static const byte s_svq1InterMultistageLengths1[8] = {
+	2, 3, 3, 3, 3, 3, 4, 4
+};
+
+static const uint32 s_svq1InterMultistageCodes1[8] = {
+	3, 5, 4, 3, 2, 1, 1, 0
+};
+
+static const byte s_svq1InterMultistageLengths2[8] = {
+	1, 3, 3, 4, 4, 4, 5, 5
+};
+
+static const uint32 s_svq1InterMultistageCodes2[8] = {
+	1, 3, 2, 3, 2, 1, 1, 0
+};
+
+static const byte s_svq1InterMultistageLengths3[8] = {
+	1, 3, 3, 4, 4, 4, 5, 5
+};
+
+static const uint32 s_svq1InterMultistageCodes3[8] = {
+	1, 3, 2, 3, 2, 1, 1, 0
+};
+
+static const byte s_svq1InterMultistageLengths4[8] = {
+	1, 3, 3, 4, 4, 4, 5, 5
+};
+
+static const uint32 s_svq1InterMultistageCodes4[8] = {
+	1, 3, 2, 3, 2, 1, 1, 0
+};
+
+static const byte s_svq1InterMultistageLengths5[8] = {
+	1, 2, 3, 5, 5, 5, 6, 6
+};
+
+static const uint32 s_svq1InterMultistageCodes5[8] = {
+	1, 1, 1, 3, 2, 1, 1, 0
+};
+
+static const byte *s_svq1InterMultistageLengths[6] = {
+	s_svq1InterMultistageLengths0, s_svq1InterMultistageLengths1, s_svq1InterMultistageLengths2,
+	s_svq1InterMultistageLengths3, s_svq1InterMultistageLengths4, s_svq1InterMultistageLengths5
+};
+
+static const uint32 *s_svq1InterMultistageCodes[6] = {
+	s_svq1InterMultistageCodes0, s_svq1InterMultistageCodes1, s_svq1InterMultistageCodes2,
+	s_svq1InterMultistageCodes3, s_svq1InterMultistageCodes4, s_svq1InterMultistageCodes5
+};
+
+static const byte s_svq1IntraMeanLengths[256] = {
+	6, 7, 17, 20, 20, 20, 20, 20, 20, 19,
+	11, 9, 11, 14, 14, 15, 16, 12, 10, 11,
+	11, 9, 8, 8, 7, 4, 4, 6, 7, 8,
+	8, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+	9, 9, 9, 9, 9, 9, 9, 9, 8, 8,
+	8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+	8, 8, 8, 8, 7, 8, 8, 8, 8, 8,
+	8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+	8, 8, 8, 8, 8, 7, 8, 8, 7, 8,
+	8, 8, 8, 8, 7, 8, 7, 7, 8, 7,
+	7, 8, 7, 8, 8, 8, 7, 7, 8, 7,
+	8, 7, 7, 7, 7, 7, 7, 7, 7, 7,
+	7, 7, 7, 7, 7, 7, 7, 8, 8, 8,
+	8, 8, 8, 8, 8, 8, 8, 7, 7, 7,
+	7, 7, 7, 7, 7, 7, 7, 7, 6, 6,
+	7, 8, 8, 8, 8, 8, 8, 8, 8, 8,
+	8, 8, 8, 8, 8, 8, 8, 8, 8, 9,
+	9, 9, 9, 9, 8, 8, 9, 9, 9, 9,
+	9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+	9, 9, 9, 9, 9, 9, 9, 9, 9, 9,
+	9, 9, 9, 9, 10, 10, 10, 10, 10, 10,
+	10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+	10, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+	10, 10, 10, 11, 11, 11, 10, 11, 11, 11,
+	11, 11, 11, 11, 11, 11, 11, 11, 11, 11,
+	11, 11, 11, 11, 11, 14
+};
+
+static const uint32 s_svq1IntraMeanCodes[256] = {
+	55, 86, 1, 1, 2, 3, 0, 4, 5, 3,
+	21, 66, 20, 3, 2, 1, 1, 1, 43, 24,
+	12, 65, 120, 108, 85, 15, 14, 52, 81, 114,
+	110, 64, 63, 62, 61, 60, 59, 58, 57, 56,
+	55, 67, 70, 71, 69, 68, 73, 72, 74, 121,
+	118, 119, 113, 117, 116, 115, 106, 85, 112, 111,
+	82, 109, 76, 107, 64, 105, 104, 103, 102, 101,
+	100, 99, 98, 97, 96, 95, 94, 93, 92, 91,
+	90, 89, 88, 87, 86, 61, 84, 83, 63, 81,
+	80, 79, 78, 77, 65, 75, 83, 62, 72, 79,
+	82, 69, 80, 67, 66, 65, 66, 67, 62, 68,
+	60, 69, 70, 71, 72, 73, 74, 75, 76, 77,
+	78, 88, 89, 90, 91, 92, 93, 68, 73, 41,
+	63, 61, 59, 44, 40, 37, 38, 94, 87, 84,
+	95, 98, 99, 100, 97, 101, 103, 102, 53, 54,
+	96, 57, 58, 56, 55, 54, 53, 52, 51, 50,
+	49, 48, 45, 43, 42, 39, 64, 70, 71, 38,
+	37, 36, 35, 34, 46, 47, 31, 54, 29, 33,
+	27, 28, 25, 26, 24, 23, 22, 30, 32, 39,
+	40, 41, 42, 43, 44, 45, 46, 47, 48, 53,
+	49, 50, 51, 52, 25, 42, 23, 22, 21, 40,
+	38, 37, 34, 33, 24, 20, 41, 18, 13, 14,
+	15, 16, 17, 26, 27, 28, 29, 30, 31, 32,
+	19, 35, 36, 9, 8, 7, 39, 5, 11, 6,
+	4, 3, 2, 1, 10, 22, 25, 23, 13, 14,
+	15, 16, 17, 18, 19, 1
+};
+
+static const byte s_svq1InterMeanLengths[512] = {
+	22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+	22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+	22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+	22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+	22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+	22, 22, 22, 21, 22, 22, 22, 22, 22, 22,
+	22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+	22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+	22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+	22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+	22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+	22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+	22, 22, 22, 22, 22, 22, 22, 22, 22, 21,
+	22, 22, 22, 22, 22, 22, 20, 21, 22, 21,
+	22, 22, 20, 22, 22, 21, 19, 18, 20, 22,
+	22, 21, 20, 19, 20, 20, 19, 19, 19, 18,
+	19, 18, 19, 20, 19, 19, 18, 18, 18, 19,
+	18, 18, 18, 17, 19, 18, 18, 17, 18, 18,
+	18, 17, 17, 17, 17, 16, 16, 16, 16, 16,
+	16, 16, 16, 16, 15, 16, 15, 15, 15, 15,
+	15, 15, 15, 15, 14, 14, 14, 14, 14, 14,
+	14, 14, 14, 13, 13, 13, 13, 13, 13, 13,
+	13, 12, 12, 12, 12, 12, 12, 11, 11, 11,
+	11, 11, 11, 10, 10, 10, 10, 10, 10, 9,
+	9, 9, 9, 9, 8, 8, 8, 8, 7, 7,
+	7, 6, 6, 5, 5, 4, 1, 3, 5, 5,
+	6, 6, 7, 7, 7, 7, 8, 8, 8, 9,
+	9, 9, 9, 9, 10, 10, 10, 10, 11, 11,
+	11, 11, 11, 11, 11, 12, 12, 12, 12, 12,
+	12, 13, 13, 13, 13, 13, 13, 13, 13, 13,
+	14, 14, 14, 14, 14, 14, 14, 14, 15, 15,
+	15, 15, 15, 15, 15, 15, 15, 15, 16, 16,
+	16, 16, 16, 16, 16, 16, 16, 16, 17, 17,
+	17, 17, 17, 17, 17, 17, 18, 17, 17, 17,
+	17, 17, 17, 17, 19, 18, 18, 19, 18, 18,
+	19, 18, 18, 18, 19, 18, 19, 19, 18, 20,
+	20, 19, 19, 19, 19, 19, 19, 18, 19, 20,
+	19, 19, 21, 20, 19, 20, 19, 19, 20, 20,
+	22, 20, 22, 22, 21, 22, 22, 21, 21, 22,
+	22, 20, 22, 22, 21, 22, 22, 22, 20, 22,
+	22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+	22, 22, 22, 22, 21, 21, 22, 22, 22, 21,
+	22, 21, 22, 22, 22, 22, 22, 22, 22, 22,
+	22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+	22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+	22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+	22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+	22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+	22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+	22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+	22, 22, 22, 22, 22, 22, 22, 22, 22, 22,
+	22, 22
+};
+
+static const uint32 s_svq1InterMeanCodes[512] = {
+	90, 212, 213, 214, 215, 216, 217, 218, 219, 220,
+	221, 222, 223, 224, 225, 226, 227, 228, 229, 230,
+	232, 203, 233, 234, 231, 236, 237, 238, 239, 240,
+	241, 242, 243, 244, 245, 246, 247, 248, 258, 235,
+	249, 252, 253, 254, 256, 92, 96, 257, 113, 260,
+	261, 251, 255, 134, 250, 124, 117, 259, 120, 211,
+	123, 130, 210, 209, 208, 207, 206, 205, 204, 195,
+	202, 201, 200, 199, 198, 197, 139, 196, 194, 193,
+	192, 191, 190, 189, 188, 187, 186, 185, 97, 132,
+	133, 134, 135, 136, 137, 138, 140, 141, 142, 143,
+	144, 145, 146, 147, 148, 149, 150, 151, 152, 153,
+	154, 155, 156, 157, 158, 159, 160, 161, 162, 163,
+	164, 165, 166, 167, 168, 169, 170, 171, 127, 143,
+	172, 173, 174, 175, 176, 177, 83, 144, 178, 145,
+	179, 180, 84, 181, 182, 140, 52, 61, 85, 183,
+	184, 139, 86, 61, 87, 88, 64, 67, 71, 42,
+	46, 44, 70, 89, 73, 45, 56, 54, 57, 69,
+	40, 48, 53, 32, 68, 50, 49, 31, 47, 46,
+	45, 33, 34, 35, 36, 39, 35, 32, 29, 37,
+	30, 36, 42, 38, 33, 41, 34, 35, 36, 27,
+	26, 29, 31, 39, 23, 24, 25, 27, 28, 30,
+	37, 32, 33, 19, 20, 21, 22, 23, 24, 25,
+	26, 24, 23, 21, 20, 19, 18, 15, 16, 18,
+	19, 27, 26, 14, 19, 15, 16, 17, 18, 13,
+	20, 21, 12, 19, 15, 14, 16, 17, 12, 9,
+	10, 8, 9, 9, 8, 5, 1, 3, 7, 6,
+	11, 10, 14, 15, 11, 13, 11, 13, 12, 15,
+	16, 17, 14, 18, 23, 20, 22, 21, 25, 24,
+	23, 22, 21, 20, 17, 25, 26, 22, 29, 27,
+	28, 32, 28, 35, 34, 33, 31, 30, 27, 29,
+	36, 22, 26, 34, 29, 31, 21, 35, 24, 32,
+	41, 40, 38, 37, 25, 28, 30, 23, 44, 43,
+	28, 33, 45, 40, 31, 27, 26, 34, 45, 50,
+	44, 39, 49, 51, 47, 43, 55, 42, 46, 48,
+	41, 40, 38, 37, 47, 51, 52, 48, 58, 59,
+	49, 60, 43, 41, 72, 39, 66, 65, 38, 82,
+	81, 63, 62, 57, 60, 59, 58, 37, 56, 80,
+	55, 54, 135, 79, 53, 78, 51, 50, 77, 76,
+	131, 75, 129, 128, 142, 126, 125, 132, 141, 122,
+	121, 74, 119, 118, 137, 116, 115, 114, 73, 112,
+	111, 110, 109, 108, 107, 106, 105, 104, 103, 102,
+	101, 100, 99, 98, 138, 136, 95, 94, 93, 133,
+	91, 131, 89, 88, 87, 86, 85, 84, 83, 82,
+	81, 80, 79, 78, 77, 76, 75, 74, 73, 72,
+	71, 70, 69, 68, 67, 66, 65, 64, 63, 62,
+	61, 60, 59, 58, 57, 56, 55, 54, 53, 52,
+	51, 50, 49, 48, 47, 46, 45, 44, 43, 42,
+	41, 40, 39, 38, 37, 36, 35, 34, 33, 32,
+	31, 30, 29, 28, 27, 26, 25, 24, 23, 22,
+	21, 20, 19, 18, 17, 16, 15, 14, 13, 12,
+	11, 10, 9, 8, 7, 6, 5, 4, 3, 2,
+	1, 0
+};
+
+static const byte s_svq1MotionComponentLengths[33] = {
+	1, 2, 3, 4, 6, 7, 7, 7, 9, 9,
+	9, 10, 10, 10, 10, 10, 10, 10, 10, 10,
+	10, 10, 10, 10, 10, 11, 11, 11, 11, 11,
+	11, 12, 12
+};
+
+static const uint32 s_svq1MotionComponentCodes[33] = {
+	1, 1, 1, 1, 3, 5, 4, 3, 11, 10,
+	9, 17, 16, 15, 14, 13, 12, 11, 10, 9,
+	8, 7, 6, 5, 4, 7, 6, 5, 4, 3,
+	2, 3, 2
 };
 
+} // End of namespace Video
 
 #endif


Commit: 97746e22815da0adc94bf0fbae7d564b0fb55bdd
    https://github.com/scummvm/scummvm/commit/97746e22815da0adc94bf0fbae7d564b0fb55bdd
Author: D G Turner (digitall at scummvm.org)
Date: 2012-04-07T19:29:24-07:00

Commit Message:
VIDEO: Correct SVQ1 Header Decoding and Last Frame Buffering.

Header was incorrectly documnented in reference documents.
Corrected with reference to FFMPEG.
Also, added missing buffering of last frame for P frame decoding.

Changed paths:
    video/codecs/svq1.cpp
    video/codecs/svq1.h



diff --git a/video/codecs/svq1.cpp b/video/codecs/svq1.cpp
index 0ccdc22..e91e5b3 100644
--- a/video/codecs/svq1.cpp
+++ b/video/codecs/svq1.cpp
@@ -45,13 +45,12 @@ namespace Video {
 #define SVQ1_BLOCK_INTRA    3
 
 SVQ1Decoder::SVQ1Decoder(uint16 width, uint16 height) {
+	debug(1, "SVQ1Decoder::SVQ1Decoder(width:%d, height:%d)", width, height);
+	_width = width;
+	_height = height;
 	_surface = new Graphics::Surface();
 	_surface->create(width, height, g_system->getScreenFormat());
 
-	_current[0] = new byte[width*height];
-	_current[1] = new byte[(width/4)*(height/4)];
-	_current[2] = new byte[(width/4)*(height/4)];
-
 	_last[0] = 0;
 	_last[1] = 0;
 	_last[2] = 0;
@@ -73,10 +72,6 @@ SVQ1Decoder::~SVQ1Decoder() {
 	_surface->free();
 	delete _surface;
 
-	delete[] _current[0];
-	delete[] _current[1];
-	delete[] _current[2];
-
 	delete[] _last[0];
 	delete[] _last[1];
 	delete[] _last[2];
@@ -166,6 +161,89 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 			//for (int i = 0; i < length; i++)
 				//	value = checksum_table[data[i] ^ (value >> 8)] ^ ((value & 0xFF) << 8);
 		}
+
+		static const uint8 stringXORTable[256] = {
+			0x00, 0xD5, 0x7F, 0xAA, 0xFE, 0x2B, 0x81, 0x54,
+			0x29, 0xFC, 0x56, 0x83, 0xD7, 0x02, 0xA8, 0x7D,
+			0x52, 0x87, 0x2D, 0xF8, 0xAC, 0x79, 0xD3, 0x06,
+			0x7B, 0xAE, 0x04, 0xD1, 0x85, 0x50, 0xFA, 0x2F,
+			0xA4, 0x71, 0xDB, 0x0E, 0x5A, 0x8F, 0x25, 0xF0,
+			0x8D, 0x58, 0xF2, 0x27, 0x73, 0xA6, 0x0C, 0xD9,
+			0xF6, 0x23, 0x89, 0x5C, 0x08, 0xDD, 0x77, 0xA2,
+			0xDF, 0x0A, 0xA0, 0x75, 0x21, 0xF4, 0x5E, 0x8B,
+			0x9D, 0x48, 0xE2, 0x37, 0x63, 0xB6, 0x1C, 0xC9,
+			0xB4, 0x61, 0xCB, 0x1E, 0x4A, 0x9F, 0x35, 0xE0,
+			0xCF, 0x1A, 0xB0, 0x65, 0x31, 0xE4, 0x4E, 0x9B,
+			0xE6, 0x33, 0x99, 0x4C, 0x18, 0xCD, 0x67, 0xB2,
+			0x39, 0xEC, 0x46, 0x93, 0xC7, 0x12, 0xB8, 0x6D,
+			0x10, 0xC5, 0x6F, 0xBA, 0xEE, 0x3B, 0x91, 0x44,
+			0x6B, 0xBE, 0x14, 0xC1, 0x95, 0x40, 0xEA, 0x3F,
+			0x42, 0x97, 0x3D, 0xE8, 0xBC, 0x69, 0xC3, 0x16,
+			0xEF, 0x3A, 0x90, 0x45, 0x11, 0xC4, 0x6E, 0xBB,
+			0xC6, 0x13, 0xB9, 0x6C, 0x38, 0xED, 0x47, 0x92,
+			0xBD, 0x68, 0xC2, 0x17, 0x43, 0x96, 0x3C, 0xE9,
+			0x94, 0x41, 0xEB, 0x3E, 0x6A, 0xBF, 0x15, 0xC0,
+			0x4B, 0x9E, 0x34, 0xE1, 0xB5, 0x60, 0xCA, 0x1F,
+			0x62, 0xB7, 0x1D, 0xC8, 0x9C, 0x49, 0xE3, 0x36,
+			0x19, 0xCC, 0x66, 0xB3, 0xE7, 0x32, 0x98, 0x4D,
+			0x30, 0xE5, 0x4F, 0x9A, 0xCE, 0x1B, 0xB1, 0x64,
+			0x72, 0xA7, 0x0D, 0xD8, 0x8C, 0x59, 0xF3, 0x26,
+			0x5B, 0x8E, 0x24, 0xF1, 0xA5, 0x70, 0xDA, 0x0F,
+			0x20, 0xF5, 0x5F, 0x8A, 0xDE, 0x0B, 0xA1, 0x74,
+			0x09, 0xDC, 0x76, 0xA3, 0xF7, 0x22, 0x88, 0x5D,
+			0xD6, 0x03, 0xA9, 0x7C, 0x28, 0xFD, 0x57, 0x82,
+			0xFF, 0x2A, 0x80, 0x55, 0x01, 0xD4, 0x7E, 0xAB,
+			0x84, 0x51, 0xFB, 0x2E, 0x7A, 0xAF, 0x05, 0xD0,
+			0xAD, 0x78, 0xD2, 0x07, 0x53, 0x86, 0x2C, 0xF9
+		};
+
+		if ((frameCode ^ 0x10) >= 0x50) {
+			// Decode embedded string
+			Common::String str;
+			uint8 stringLen = frameData.getBits(8);
+			byte xorVal = stringXORTable[stringLen];
+
+			for (uint16 i = 0; i < stringLen-1; i++) {
+				byte data = frameData.getBits(8);
+				str += data ^ xorVal;
+				xorVal = stringXORTable[data];
+			}
+			debug(1, " Embedded String of %d Characters: \"%s\"", stringLen, str.c_str());
+		}
+
+		byte unk1 = frameData.getBits(2); // Unknown
+		debug(1, " unk1: %d", unk1);
+		byte unk2 = frameData.getBits(2); // Unknown
+		debug(1, " unk2: %d", unk2);
+		bool unk3 = frameData.getBit(); // Unknown
+		debug(1, " unk3: %d", unk3);
+
+		static const struct { uint w, h; } standardFrameSizes[7] = {
+			{ 160, 120 }, // 0
+			{ 128,  96 }, // 1
+			{ 176, 144 }, // 2
+			{ 352, 288 }, // 3
+			{ 704, 576 }, // 4
+			{ 240, 180 }, // 5
+			{ 320, 240 }  // 6
+		};
+
+		byte frameSizeCode = frameData.getBits(3);
+		debug(1, " frameSizeCode: %d", frameSizeCode);
+		uint16 frameWidth, frameHeight;
+		if (frameSizeCode == 7) {
+			frameWidth = frameData.getBits(12);
+			frameHeight = frameData.getBits(12);
+		} else {
+			frameWidth = standardFrameSizes[frameSizeCode].w;
+			frameHeight = standardFrameSizes[frameSizeCode].h;
+		}
+		debug(1, " frameWidth: %d", frameWidth);
+		debug(1, " frameHeight: %d", frameHeight);
+		if (frameWidth != _width || frameHeight != _height) { // Invalid
+			warning("Invalid Frame Size");
+			return _surface;
+		}
 	} else if (frameType == 2) { // B Frame
 		warning("B Frames not supported by SVQ1 decoder");
 		return _surface;
@@ -174,88 +252,6 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 		return _surface;
 	}
 
-	static const uint8 stringXORTable[256] = {
-		0x00, 0xD5, 0x7F, 0xAA, 0xFE, 0x2B, 0x81, 0x54,
-		0x29, 0xFC, 0x56, 0x83, 0xD7, 0x02, 0xA8, 0x7D,
-		0x52, 0x87, 0x2D, 0xF8, 0xAC, 0x79, 0xD3, 0x06,
-		0x7B, 0xAE, 0x04, 0xD1, 0x85, 0x50, 0xFA, 0x2F,
-		0xA4, 0x71, 0xDB, 0x0E, 0x5A, 0x8F, 0x25, 0xF0,
-		0x8D, 0x58, 0xF2, 0x27, 0x73, 0xA6, 0x0C, 0xD9,
-		0xF6, 0x23, 0x89, 0x5C, 0x08, 0xDD, 0x77, 0xA2,
-		0xDF, 0x0A, 0xA0, 0x75, 0x21, 0xF4, 0x5E, 0x8B,
-		0x9D, 0x48, 0xE2, 0x37, 0x63, 0xB6, 0x1C, 0xC9,
-		0xB4, 0x61, 0xCB, 0x1E, 0x4A, 0x9F, 0x35, 0xE0,
-		0xCF, 0x1A, 0xB0, 0x65, 0x31, 0xE4, 0x4E, 0x9B,
-		0xE6, 0x33, 0x99, 0x4C, 0x18, 0xCD, 0x67, 0xB2,
-		0x39, 0xEC, 0x46, 0x93, 0xC7, 0x12, 0xB8, 0x6D,
-		0x10, 0xC5, 0x6F, 0xBA, 0xEE, 0x3B, 0x91, 0x44,
-		0x6B, 0xBE, 0x14, 0xC1, 0x95, 0x40, 0xEA, 0x3F,
-		0x42, 0x97, 0x3D, 0xE8, 0xBC, 0x69, 0xC3, 0x16,
-		0xEF, 0x3A, 0x90, 0x45, 0x11, 0xC4, 0x6E, 0xBB,
-		0xC6, 0x13, 0xB9, 0x6C, 0x38, 0xED, 0x47, 0x92,
-		0xBD, 0x68, 0xC2, 0x17, 0x43, 0x96, 0x3C, 0xE9,
-		0x94, 0x41, 0xEB, 0x3E, 0x6A, 0xBF, 0x15, 0xC0,
-		0x4B, 0x9E, 0x34, 0xE1, 0xB5, 0x60, 0xCA, 0x1F,
-		0x62, 0xB7, 0x1D, 0xC8, 0x9C, 0x49, 0xE3, 0x36,
-		0x19, 0xCC, 0x66, 0xB3, 0xE7, 0x32, 0x98, 0x4D,
-		0x30, 0xE5, 0x4F, 0x9A, 0xCE, 0x1B, 0xB1, 0x64,
-		0x72, 0xA7, 0x0D, 0xD8, 0x8C, 0x59, 0xF3, 0x26,
-		0x5B, 0x8E, 0x24, 0xF1, 0xA5, 0x70, 0xDA, 0x0F,
-		0x20, 0xF5, 0x5F, 0x8A, 0xDE, 0x0B, 0xA1, 0x74,
-		0x09, 0xDC, 0x76, 0xA3, 0xF7, 0x22, 0x88, 0x5D,
-		0xD6, 0x03, 0xA9, 0x7C, 0x28, 0xFD, 0x57, 0x82,
-		0xFF, 0x2A, 0x80, 0x55, 0x01, 0xD4, 0x7E, 0xAB,
-		0x84, 0x51, 0xFB, 0x2E, 0x7A, 0xAF, 0x05, 0xD0,
-		0xAD, 0x78, 0xD2, 0x07, 0x53, 0x86, 0x2C, 0xF9
-	};
-
-	if ((frameCode ^ 0x10) >= 0x50) {
-		// Decode embedded string
-		Common::String str;
-		uint8 stringLen = frameData.getBits(8);
-		byte xorVal = stringXORTable[stringLen];
-
-		for (uint16 i = 0; i < stringLen-1; i++) {
-			byte data = frameData.getBits(8);
-			str += data ^ xorVal;
-			xorVal = stringXORTable[data];
-		}
-		debug(1, " Embedded String of %d Characters: \"%s\"", stringLen, str.c_str());
-	}
-
-	byte unk1 = frameData.getBits(2); // Unknown
-	debug(1, " unk1: %d", unk1);
-	byte unk2 = frameData.getBits(2); // Unknown
-	debug(1, " unk2: %d", unk2);
-	bool unk3 = frameData.getBit(); // Unknown
-	debug(1, " unk3: %d", unk3);
-
-	static const struct { uint w, h; } standardFrameSizes[7] = {
-		{ 160, 120 }, // 0
-		{ 128,  96 }, // 1
-		{ 176, 144 }, // 2
-		{ 352, 288 }, // 3
-		{ 704, 576 }, // 4
-		{ 240, 180 }, // 5
-		{ 320, 240 }  // 6
-	};
-
-	byte frameSizeCode = frameData.getBits(3);
-	debug(1, " frameSizeCode: %d", frameSizeCode);
-	uint16 frameWidth, frameHeight;
-	if (frameSizeCode == 7) {
-		frameWidth = frameData.getBits(12);
-		frameHeight = frameData.getBits(12);
-	} else {
-		frameWidth = standardFrameSizes[frameSizeCode].w;
-		frameHeight = standardFrameSizes[frameSizeCode].h;
-	}
-	debug(1, " frameWidth: %d", frameWidth);
-	debug(1, " frameHeight: %d", frameHeight);
-	if (frameWidth == 0 || frameHeight == 0) { // Invalid
-		warning("Invalid Frame Size");
-		return _surface;
-	}
 	bool checksumPresent = frameData.getBit();
 	debug(1, " checksumPresent: %d", checksumPresent);
 	if (checksumPresent) {
@@ -286,91 +282,98 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 		}
 	}
 
-	if (frameWidth == _surface->w && frameHeight == _surface->h) {
-		// Decode Y, U and V component planes
-		for (int i = 0; i < 3; i++) {
-			int linesize, width, height;
-			if (i == 0) {
-				// Y Size is width * height
-				width  = frameWidth;
-				if (width % 16) {
-					width /= 16;
-					width++;
-					width *= 16;
-				}
-				assert(width % 16 == 0);
-				height = frameHeight;
-				if (height % 16) {
-					height /= 16;
-					height++;
-					height *= 16;
-				}
-				assert(height % 16 == 0);
-				linesize = width;
-			} else {
-				// U and V size is width/4 * height/4
-				width  = frameWidth/4;
-				if (width % 16) {
-					width /= 16;
-					width++;
-					width *= 16;
-				}
-				assert(width % 16 == 0);
-				height = frameHeight/4;
-				if (height % 16) {
-					height /= 16;
-					height++;
-					height *= 16;
-				}
-				assert(height % 16 == 0);
-				linesize = width;
+	byte *current[3];
+	current[0] = new byte[_width*_height];
+	current[1] = new byte[(_width/4)*(_height/4)];
+	current[2] = new byte[(_width/4)*(_height/4)];
+
+	// Decode Y, U and V component planes
+	for (int i = 0; i < 3; i++) {
+		int linesize, width, height;
+		if (i == 0) {
+			// Y Size is width * height
+			width  = _width;
+			if (width % 16) {
+				width /= 16;
+				width++;
+				width *= 16;
+			}
+			assert(width % 16 == 0);
+			height = _height;
+			if (height % 16) {
+				height /= 16;
+				height++;
+				height *= 16;
+			}
+			assert(height % 16 == 0);
+			linesize = _width;
+		} else {
+			// U and V size is width/4 * height/4
+			width  = _width/4;
+			if (width % 16) {
+				width /= 16;
+				width++;
+				width *= 16;
 			}
+			assert(width % 16 == 0);
+			height = _height/4;
+			if (height % 16) {
+				height /= 16;
+				height++;
+				height *= 16;
+			}
+			assert(height % 16 == 0);
+			linesize = _width/4;
+		}
 
-			if (frameType == 0) { // I Frame
-				// Keyframe (I)
-				byte *current = _current[i];
-				for (uint16 y = 0; y < height; y += 16) {
-					for (uint16 x = 0; x < width; x += 16) {
-						if (int result = svq1DecodeBlockIntra(&frameData, &current[x], linesize) != 0) {
-							warning("Error in svq1DecodeBlock %i (keyframe)", result);
-							return _surface;
-						}
+		if (frameType == 0) { // I Frame
+			// Keyframe (I)
+			byte *currentP = current[i];
+			for (uint16 y = 0; y < height; y += 16) {
+				for (uint16 x = 0; x < width; x += 16) {
+					if (int result = svq1DecodeBlockIntra(&frameData, &currentP[x], linesize) != 0) {
+						warning("Error in svq1DecodeBlock %i (keyframe)", result);
+						return _surface;
 					}
-					current += 16 * linesize;
 				}
-			} else {
-				// Delta frame (P or B)
-
-				// Prediction Motion Vector
-				Common::Point *pmv = new Common::Point[(width/8) + 3];
-
-				byte *previous;
-				if(frameType == 2) { // B Frame
-					warning("B Frame not supported currently");
-					//previous = _next[i];
-				} else
-					previous = _last[i];
-
-				byte *current = _current[i];
-				for (uint16 y = 0; y < height; y += 16) {
-					for (uint16 x = 0; x < width; x += 16) {
-						if (int result = svq1DecodeDeltaBlock(&frameData, &current[x], previous, linesize, pmv, x, y) != 0) {
-							warning("Error in svq1DecodeDeltaBlock %i", result);
-							return _surface;
-						}
+				currentP += 16 * linesize;
+			}
+		} else {
+			// Delta frame (P or B)
+
+			// Prediction Motion Vector
+			Common::Point *pmv = new Common::Point[(width/8) + 3];
+
+			byte *previous;
+			if(frameType == 2) { // B Frame
+				warning("B Frame not supported currently");
+				//previous = _next[i];
+			} else
+				previous = _last[i];
+
+			byte *currentP = current[i];
+			for (uint16 y = 0; y < height; y += 16) {
+				for (uint16 x = 0; x < width; x += 16) {
+					if (int result = svq1DecodeDeltaBlock(&frameData, &currentP[x], previous, linesize, pmv, x, y) != 0) {
+						warning("Error in svq1DecodeDeltaBlock %i", result);
+						return _surface;
 					}
+				}
 
-					pmv[0].x = pmv[0].y = 0;
+				pmv[0].x = pmv[0].y = 0;
 
-					current += 16*linesize;
-				}
-				delete[] pmv;
+				currentP += 16*linesize;
 			}
+			delete[] pmv;
 		}
+	}
 
-		convertYUV410ToRGB(_surface, _current[0], _current[1], _current[2], frameWidth, frameHeight, frameWidth, frameWidth/2);
-	} else
-		warning("FrameWidth/Height Sanity Check Failed!");
+	convertYUV410ToRGB(_surface, current[0], current[1], current[2], _width, _height, _width, _width/4);
+
+	for (int i = 0; i < 3; i++) {
+		delete _last[i];
+		_last[i] = current[i];
+	}
 
 	return _surface;
 }
diff --git a/video/codecs/svq1.h b/video/codecs/svq1.h
index 2271bf4..ed34439 100644
--- a/video/codecs/svq1.h
+++ b/video/codecs/svq1.h
@@ -43,8 +43,9 @@ public:
 
 private:
 	Graphics::Surface *_surface;
+	uint16 _width;
+	uint16 _height;
 
-	byte *_current[3];
 	byte *_last[3];
 
 	Common::Huffman *_blockType;


Commit: d15ff5a03ed098ba50303f06ad4e96147a43517a
    https://github.com/scummvm/scummvm/commit/d15ff5a03ed098ba50303f06ad4e96147a43517a
Author: D G Turner (digitall at scummvm.org)
Date: 2012-04-07T19:29:27-07:00

Commit Message:
VIDEO: Correct delete type in SVQ1 decoder.

Changed paths:
    video/codecs/svq1.cpp



diff --git a/video/codecs/svq1.cpp b/video/codecs/svq1.cpp
index e91e5b3..5ef45c2 100644
--- a/video/codecs/svq1.cpp
+++ b/video/codecs/svq1.cpp
@@ -371,7 +371,7 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 	convertYUV410ToRGB(_surface, current[0], current[1], current[2], _width, _height, _width, _width/4);
 
 	for (int i = 0; i < 3; i++) {
-		delete _last[i];
+		delete[] _last[i];
 		_last[i] = current[i];
 	}
 


Commit: 7109e26d04a90b718ad2ed635e0aeb35b011abd7
    https://github.com/scummvm/scummvm/commit/7109e26d04a90b718ad2ed635e0aeb35b011abd7
Author: D G Turner (digitall at scummvm.org)
Date: 2012-04-07T19:29:29-07:00

Commit Message:
VIDEO: Workaround for out of buffer accesses in SVQ1 codec.

This is a temporary workaround during development.
Keyframe (I) decoding is now working correctly, but Deltaframe (P) is
still giving corrupted output...

Changed paths:
    video/codecs/svq1.cpp



diff --git a/video/codecs/svq1.cpp b/video/codecs/svq1.cpp
index 5ef45c2..f19625b 100644
--- a/video/codecs/svq1.cpp
+++ b/video/codecs/svq1.cpp
@@ -283,9 +283,11 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 	}
 
 	byte *current[3];
-	current[0] = new byte[_width*_height];
-	current[1] = new byte[(_width/4)*(_height/4)];
-	current[2] = new byte[(_width/4)*(_height/4)];
+	// FIXME - Added extra _width of 16px blocks to stop out of
+	//         range access causing crashes. Need to correct code...
+	current[0] = new byte[_width*_height +(_width*16)];
+	current[1] = new byte[(_width/4)*(_height/4) +(_width/4*16)];
+	current[2] = new byte[(_width/4)*(_height/4) +(_width/4*16)];
 
 	// Decode Y, U and V component planes
 	for (int i = 0; i < 3; i++) {


Commit: 1ca81ee6ecff15c843c04a51c8757be5a685edc2
    https://github.com/scummvm/scummvm/commit/1ca81ee6ecff15c843c04a51c8757be5a685edc2
Author: Matthew Hoops (clone2727 at gmail.com)
Date: 2012-04-07T19:29:32-07:00

Commit Message:
VIDEO: Rework SVQ1 codebooks so they're endian-safe

Changed paths:
    video/codecs/svq1.cpp
    video/codecs/svq1_cb.h



diff --git a/video/codecs/svq1.cpp b/video/codecs/svq1.cpp
index f19625b..22e267e 100644
--- a/video/codecs/svq1.cpp
+++ b/video/codecs/svq1.cpp
@@ -438,7 +438,7 @@ int SVQ1Decoder::svq1DecodeBlockIntra(Common::BitStream *s, uint8 *pixels, int p
 			}
 		} else {
 			// SVQ1_CALC_CODEBOOK_ENTRIES(svq1_intra_codebooks);
-			const uint32 *codebook = (const uint32 *) svq1_intra_codebooks[level];
+			const uint32 *codebook = s_svq1IntraCodebooks[level];
 			uint32 bit_cache = s->getBits(4*stages);
 			// calculate codebook entries for this vector
 			for (j=0; j < stages; j++) {
@@ -534,7 +534,7 @@ int SVQ1Decoder::svq1DecodeBlockNonIntra(Common::BitStream *s, uint8 *pixels, in
 		mean = _interMean->getSymbol(*s) - 256;
 
 		// SVQ1_CALC_CODEBOOK_ENTRIES(svq1_inter_codebooks);
-		const uint32 *codebook = (const uint32 *) svq1_inter_codebooks[level];
+		const uint32 *codebook = s_svq1InterCodebooks[level];
 		uint32 bit_cache = s->getBits(4*stages);
 		// calculate codebook entries for this vector
 		for (j=0; j < stages; j++) {
diff --git a/video/codecs/svq1_cb.h b/video/codecs/svq1_cb.h
index 4eaf323..f764de0 100644
--- a/video/codecs/svq1_cb.h
+++ b/video/codecs/svq1_cb.h
@@ -23,1490 +23,1486 @@
 #ifndef VIDEO_CODECS_SVQ1_CB_H
 #define VIDEO_CODECS_SVQ1_CB_H
 
-// 6x16-entry codebook for inter-coded 4x2 vectors
-static const int8 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
+#include "common/scummsys.h"
+
+namespace Video {
+
+static const uint32 s_svq1InterCodebook4x2[192] = {
+	0xf9fa0207, 0xfcfd0307, 0x0807fef9, 0x0403fcf8,
+	0x03091113, 0xf8f4f0f2, 0xfdf8f0ee, 0x080c0e0b,
+	0x14f6f007, 0x14f6ef07, 0xeb0812fa, 0xec0912f9,
+	0xf2ec0319, 0xf3ee071d, 0x0e15fce3, 0x0e14fae1,
+	0xe8e4e6ed, 0x0a16201f, 0x1c1f180f, 0xf3eae0e0,
+	0xe6e9f802, 0x231b03f7, 0x15150b03, 0xdee5fc08,
+	0x2f0ce1e2, 0x2f0de2e3, 0xd2ef1e26, 0xd2ed1a22,
+	0xd5cdced6, 0x30373022, 0x2a333630, 0xd1cbccd4,
+	0xfa000504, 0x0100fefe, 0xfefffaf5, 0x01090801,
+	0x05fa0100, 0x02f40108, 0x08f9f207, 0x0800f805,
+	0x080b0401, 0xfb00f8f4, 0x040001ff, 0x1003f8f1,
+	0xfafc0811, 0xf8f3fc09, 0xee010602, 0xf40b0bff,
+	0x00020006, 0xebf9060e, 0xecf3ff01, 0x150a0101,
+	0x0d07fbea, 0x0c04fff5, 0x130e00f9, 0xedfb03fc,
+	0x0f0af2e6, 0xfefa0412, 0xeefb1319, 0x0204f9ec,
+	0xfcfffaf3, 0xddfe2519, 0x01010405, 0x2b02dceb,
+	0x03fffe02, 0xfffafe08, 0x0c02fdfe, 0xfffefefb,
+	0xfbfffffd, 0xfe0807ff, 0xfd050702, 0xf8fd0101,
+	0xfefdfffd, 0x0d02fdfe, 0xfaf5000f, 0x00000003,
+	0xfcfbf7fa, 0x03010412, 0x0400030c, 0xfd03fdf0,
+	0x021203ef, 0xfffffdff, 0x00f810fa, 0x00f90ef7,
+	0xfb0ef303, 0xfc0ef303, 0xe90e14f9, 0x04f8f908,
+	0x10edf108, 0xfd0b0df6, 0x1a01ff09, 0x02e5f105,
+	0xfc1007ec, 0x011f09d8, 0xf9e2f41a, 0x04edfe28,
+	0x00000006, 0x0201fefa, 0xfa00ff00, 0xfffe0009,
+	0xfd0208f9, 0x02fd02ff, 0x04fefc07, 0xfa000002,
+	0x0209fefd, 0xfc00fffe, 0xfd00fdfd, 0x040a02fa,
+	0x08f60003, 0x04fc0000, 0x020401ff, 0x07f7f903,
+	0xfcf70102, 0x00000cff, 0xfc07ff03, 0x0204f203,
+	0x0b01f7f4, 0x00010502, 0x02000103, 0xed060800,
+	0xfcf9f6fa, 0x07050709, 0xfd031506, 0xfefbf7f5,
+	0xfff0f7fc, 0x2401fbfe, 0x00130b08, 0xd7fc0502,
+	0xfffeffff, 0x0601fefe, 0xf8010400, 0x00010101,
+	0x0004fdfe, 0xfd03ff02, 0x01fc0301, 0xfb0003ff,
+	0x03020403, 0xfffafdfe, 0x02fefdfe, 0x000108fc,
+	0x060204f9, 0x0001fff9, 0x01fc02fe, 0xff02fa08,
+	0x020002fa, 0xfff80405, 0x0900f5ff, 0x0202fe00,
+	0xfffcfb11, 0xfefefcff, 0xfd09f300, 0x02f90cff,
+	0x02fbfe00, 0xfd14fbf9, 0xe2ff0707, 0x01080503,
+	0xfcff03fa, 0x12f5fe02, 0x0e03f900, 0xf7eefd14,
+	0xff00fe07, 0xff0000fe, 0x0001fffc, 0x040002fe,
+	0x0102fd01, 0x01fb0103, 0xfeff00fd, 0xfd000107,
+	0xfe000502, 0x01fffb02, 0xff04feff, 0x0005fd00,
+	0xfeff0300, 0xff0501fc, 0x09ff00ff, 0xfffffeff,
+	0xff0505fe, 0xfefd02fe, 0x01f50201, 0x02030102,
+	0xfefff602, 0x01040204, 0x01fb0504, 0x01f50600,
+	0x06060001, 0xf1010200, 0x09050307, 0x020202e2,
+	0x020901de, 0x02080805, 0x06060207, 0x0401e502
 };
 
-// 6x16-entry codebook for inter-coded 4x4 vectors
-static const int8 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
+static const uint32 s_svq1InterCodebook4x4[384] = {
+	0xf9fa0004, 0xf7f3f8fc, 0x06fff8f8, 0x1b1605fe,
+	0x0a0bf9f0, 0x0a0df9ee, 0x080cfcf1, 0x0509fff7,
+	0xf00f02fe, 0xed1302fd, 0xed1302fd, 0xf20f03fe,
+	0x10161611, 0xfefbf9fa, 0xf4f0f0f4, 0xfdff0101,
+	0x0800ef0b, 0x09ffeb0e, 0x08feeb0e, 0x06fef00b,
+	0x0bf0fe07, 0x0eebfe09, 0x0eeaff0a, 0x0aeeff08,
+	0xf70310f6, 0xf50414f3, 0xf60415f2, 0xf80310f5,
+	0xf7f7040b, 0xf2f4060f, 0xf2f40811, 0xf5f90a10,
+	0x0d0e0a04, 0x100f07ff, 0x0803f9f4, 0xf6eee9ec,
+	0xe7e6eef6, 0xf5fa0104, 0x030b0f0d, 0x080d0f0c,
+	0xf5f0edf0, 0x0b0f0c07, 0x0b10100b, 0xf6f5f7fa,
+	0x050c1312, 0xfc051012, 0xf1f60006, 0xeae9eff7,
+	0x15fff2f6, 0x1d00eff5, 0x1e01f0f5, 0x1700f2f6,
+	0xfaf4eff0, 0xf9f2eded, 0x0201fffd, 0x131d231b,
+	0x1717f8db, 0x1d1cf7d6, 0x1c1af6d5, 0x1613f5da,
+	0xdff01020, 0xdbee1427, 0xdaed1326, 0xdeef0f20,
+	0xfcfa0918, 0x03faf6ff, 0x03fff7f8, 0xfa020703,
+	0x00fffdff, 0xf90204ff, 0xf0030bfd, 0xee091401,
+	0x0c06f8fd, 0x0d07f6fb, 0x0705f7fa, 0xff02fbfb,
+	0xfffd0cf8, 0x01fd0ff6, 0x01fc0df5, 0x02fd08f5,
+	0xf4fb0609, 0xf3f80003, 0xfffffcfc, 0x120f01fc,
+	0x0c0e0d09, 0xfeff0304, 0xfbf8fbfe, 0xfcf7f5f9,
+	0xfcf9fb07, 0xfcf9fe0e, 0xfbf80011, 0xfbf9010f,
+	0x0406fff6, 0x0402f7f1, 0x00fdff02, 0xf6f80d19,
+	0xf0fd0b07, 0xf1fd0b07, 0xf7fe0706, 0xfbfd0204,
+	0x00fffff9, 0x0602fef7, 0x0e06fcf4, 0x1308faf3,
+	0xfbf5eeee, 0x040300fd, 0x06060806, 0x06060606,
+	0xf60d03fb, 0xf70f01fa, 0xfa0ffdfa, 0xfd0afafa,
+	0xf7f70109, 0x0506090b, 0x07080300, 0xfbfaf2f1,
+	0x130bfaf5, 0xf8f7fbfe, 0xf6f70206, 0x05040506,
+	0x0f08fdf9, 0x0f0a03ff, 0xfeff0505, 0xe7ebfe04,
+	0x05fafa06, 0x09f9f708, 0x0df9f408, 0x0ef9f204,
+	0x0101fdfc, 0xfdfefbfd, 0xfcfe0007, 0xfcfc0714,
+	0x0afaecfd, 0x01000006, 0xff050805, 0xfe0000fd,
+	0x02ff060d, 0x03020305, 0x000300fd, 0xfbfef8f0,
+	0x00faf9fe, 0x01fdfafd, 0xff02fffb, 0x05100cff,
+	0x080901f9, 0x0305fef6, 0x030702fa, 0xf9ff00fc,
+	0xe8f70403, 0x03060200, 0x0704ffff, 0xfeff0305,
+	0x02f70603, 0x01f30601, 0x02f60801, 0x01f90801,
+	0x1602fdfd, 0x0cfbfdfe, 0x02f6fdfe, 0x02fcfffd,
+	0x02080c0b, 0xf8fbfbfb, 0xfd00fcfa, 0x0303fffe,
+	0xfffefa0c, 0xfefef80c, 0xfd00f909, 0xfe02fa04,
+	0xfd0c01ed, 0xfc0504fc, 0xfffe0106, 0x07fefc04,
+	0xf8f9fcfd, 0x00fefcfc, 0x100e02ff, 0x0404fefc,
+	0xfb0207ff, 0x01ff00fe, 0x0dfffd04, 0x08f2f406,
+	0xfb0405ff, 0xf70305fe, 0xf40407fe, 0xf70407ff,
+	0x0101fdfa, 0xfa000b0b, 0xf9fe0406, 0x0a03f6f4,
+	0xfefdfdfe, 0x0a0e0b06, 0xf6f6f5f7, 0x02030202,
+	0xfff9fbf9, 0x070002ff, 0x090001ff, 0xfffb0403,
+	0xfff1ff0a, 0x02fb0104, 0x01ff01fd, 0x040401fd,
+	0x0a04ff02, 0x00ff0206, 0xf4f90202, 0xfd0002fc,
+	0xf8fffcff, 0xf702ff03, 0xfb050004, 0x03080002,
+	0x01010203, 0x0300fe04, 0x0104ff02, 0xe7ff0600,
+	0xfcfefeff, 0xfcff00fd, 0x02fcffff, 0x1902fa00,
+	0x0005fff5, 0x02fe0007, 0x04fdff0a, 0xfffefbfb,
+	0xff030600, 0x01fffffe, 0xfbf4f9ff, 0x04020608,
+	0xfaff0602, 0xfcff0a09, 0x00fc0001, 0xfbf7fe03,
+	0x000403fc, 0x000303fc, 0x020300f5, 0x020703f5,
+	0x0307fc02, 0x0107f801, 0x0104f4ff, 0x0202f703,
+	0x09fefe02, 0x0103fdef, 0xfa0107fc, 0x03ff0405,
+	0xfc0002ff, 0xff0c08f9, 0xfb0405fe, 0xfef8fb03,
+	0xfefb0000, 0x1b03f8fe, 0x06fdfcff, 0xf9fe01fd,
+	0xff010404, 0xfdf9f6f9, 0x03050a0a, 0xfdfcfefe,
+	0x07050100, 0xecf0fe04, 0x08070400, 0xfffe0002,
+	0x110301fe, 0xfffe01fd, 0xfefffeff, 0x00fffbff,
+	0x0001fd05, 0x0000fe06, 0xfd00feff, 0xff0801f5,
+	0x00000003, 0x01040200, 0x01060002, 0x02fdeefe,
+	0x010600f2, 0x01fffefb, 0x010001ff, 0x00040701,
+	0xfc0100ff, 0xfc030801, 0x030104fd, 0x01fc01fa,
+	0x0303f401, 0xff00f6ff, 0x01020002, 0x04020203,
+	0x03000003, 0x01fe0002, 0x00fb0205, 0xfff2ff06,
+	0xfdfdfafe, 0x0504ff02, 0x00feff06, 0xfbff0404,
+	0x00f501fc, 0x01fc02ff, 0xff03fd02, 0x000ffe01,
+	0xfe00ff01, 0x01f9fc01, 0x15fffafe, 0x01ff02fe,
+	0x00feff15, 0xfe01fdff, 0xff02fef7, 0xfffc0102,
+	0xfa020801, 0x0004fff6, 0x0303fdfc, 0xffff0005,
+	0xfe010203, 0x0304fefe, 0xeffc0205, 0x0304fe00,
+	0x0300fcf9, 0xff020909, 0xff00faf5, 0x01000105,
+	0xf5051100, 0x00fafe03, 0x01fcfe02, 0xff0201fc,
+	0xfdfbfffb, 0xfefd05fd, 0xfb021004, 0xffff05fe,
+	0x01fc0000, 0x0b0502ff, 0x01feffff, 0xfffdfefc,
+	0x000afffb, 0xfd000106, 0x0001fc00, 0xff03fcfe,
+	0x00030906, 0x00fe01fe, 0xfefefdfe, 0xfa010001,
+	0x01020001, 0x01fe03ff, 0x00f1ff00, 0x060205ff,
+	0x02020002, 0x06fcf400, 0xff040100, 0xfc010201,
+	0x00f9fe01, 0xff000000, 0x030b02fb, 0xfa000301,
+	0xfcf7fd00, 0x00ff0301, 0x00fe0104, 0x06fffd07,
+	0x0206fe01, 0xfe03ff00, 0x020004fe, 0x02f202ff,
+	0xff000202, 0xf2fd03fe, 0xfd030200, 0x02030105,
+	0xf204fd01, 0xff0bfe01, 0x0003ff00, 0x020001ff,
+	0x02fd03fe, 0x03fcfffc, 0x030102ff, 0x0702fefa,
+	0x000201fe, 0xff0000fe, 0x02ff050c, 0xf901fff8,
+	0x02fcfe02, 0xfef5000b, 0xfffd0103, 0xff010300,
+	0xfe000300, 0xfdfffa00, 0x00fef90c, 0x0101fe07,
+	0x02020201, 0x020002ff, 0x000400e9, 0x03010203,
+	0x05fffbfc, 0xff0a05fd, 0xfc030000, 0xfb02ff01
 };
 
-// 6x16-entry codebook for inter-coded 8x4 vectors
-static const int8 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
+static const uint32 s_svq1InterCodebook8x4[768] = {
+	0x00040809, 0xfdfcfcfd, 0xff040809, 0xfdfbfbfc,
+	0xfe030708, 0xfcfbfbfb, 0xfe010406, 0xfdfcfbfc,
+	0xfcf5f2f4, 0x06060501, 0xfbf9f6f8, 0x010101fe,
+	0x01030405, 0xffff0000, 0x06090d0d, 0xfeff0003,
+	0xfffdfcfc, 0x0b080401, 0xfefcfafb, 0x0c080300,
+	0xfcfaf9f9, 0x0a0702fe, 0xfcfbf9f9, 0x080501fe,
+	0x01fffefd, 0x06070603, 0x07050302, 0x04060808,
+	0x03040504, 0xf9fafe01, 0xf9fe0001, 0xf0eff2f6,
+	0x0801fcfb, 0xf9fd0309, 0x0b01faf9, 0xf8fd050c,
+	0x0900f9f8, 0xf9fd050b, 0x05fffaf8, 0xfafe0408,
+	0xf8f9fbfc, 0xfaf8f7f7, 0xf9fafbfc, 0xfefcfaf9,
+	0x03020100, 0x090a0805, 0x06030201, 0x0d0e0c09,
+	0x05060605, 0x01020304, 0x07070605, 0x04060606,
+	0x010100ff, 0x05050503, 0xefeff0f3, 0xfcfaf6f2,
+	0x100d0b09, 0x0a0c0d0f, 0xf9fafbfc, 0xfbfaf9f9,
+	0xf9f9fafa, 0xfbfaf9f9, 0x0000fffe, 0xff000000,
+	0xf0f1f3f5, 0xf6f4f2f0, 0x05040302, 0x03030304,
+	0x08080706, 0x05060708, 0x03030403, 0x03030303,
+	0x01040403, 0xeff3f9fe, 0x05070705, 0xedf3fb01,
+	0x08090806, 0xf0f7ff05, 0x0a0a0806, 0xf5fc0207,
+	0xf6ff0912, 0x00fcf7f3, 0xf4ff0c16, 0x02fcf6f1,
+	0xf6000d17, 0x02fdf7f3, 0xfa020c14, 0x02fefaf7,
+	0xf9fafafa, 0xfaf9f9f9, 0xf8f8f9fa, 0xf8f7f7f7,
+	0xfdfdfdfd, 0xfdfdfdfd, 0x15120f0c, 0x0e111315,
+	0x1212100e, 0x0d0f1012, 0x05060605, 0x03040405,
+	0xf6f7f9fa, 0xf9f7f6f6, 0xf2f3f5f6, 0xf6f4f3f2,
+	0x05fcefe5, 0x070a0a09, 0x07fdede0, 0x080b0c0b,
+	0x08fef0e2, 0x070a0c0c, 0x0700f4e9, 0x06090b0a,
+	0x0c101110, 0xf4f8ff06, 0x0a0f1211, 0xeef1f801,
+	0x040a0e0f, 0xe9ecf2fb, 0xff04080a, 0xeaebf0f7,
+	0xf5f4f4f6, 0x140e04fb, 0xf4f1f3f5, 0x1b1307fc,
+	0xf5f2f3f5, 0x1c1508fd, 0xf7f4f5f6, 0x191208fe,
+	0x01ffffff, 0x05060604, 0x02000000, 0xfe010304,
+	0x04020000, 0xf6f9ff04, 0x05030000, 0xf1f5fd03,
+	0xfff8f3f2, 0xfcff0303, 0x04fffcfb, 0x00030808,
+	0x03020203, 0x01030504, 0xfe000305, 0xfffffffe,
+	0xfafa0109, 0xfffefdfb, 0xfafa010c, 0x00fffefc,
+	0xfcfc040e, 0xfffffefe, 0xffff060e, 0xffffffff,
+	0x0a080604, 0x0507090b, 0x00ffffff, 0xfeffff00,
+	0xfbfcfcfe, 0xfcfbfbfb, 0xfcfdfdfe, 0xfffefdfc,
+	0x04040302, 0x00000103, 0x050401ff, 0x03040506,
+	0x02fefaf8, 0x03040403, 0xfbf7f3f2, 0x0000fffe,
+	0xfcfbfcfd, 0x0d0c0700, 0xfbfbfcfd, 0x0a0904fe,
+	0xfbfcfdfe, 0x0403fffc, 0xfdfeffff, 0x0100fefd,
+	0xf8fe0509, 0xfcf9f6f5, 0x02060a0c, 0x0000ff00,
+	0x04030202, 0x01010103, 0x00fcf8f7, 0x00010201,
+	0x05080806, 0xf3f5fb01, 0x02020100, 0xf5f8fcff,
+	0x0301fefd, 0xfcff0103, 0x0502fffe, 0x01040606,
+	0x05050403, 0xfafd0104, 0x02040605, 0xfd000202,
+	0xfb000506, 0xfefffefb, 0xf5fd0407, 0xfefdf9f4,
+	0xffff0001, 0x000000ff, 0x04040302, 0x03040505,
+	0xf6f7f7f9, 0xfaf9f7f6, 0x06050403, 0x05050505,
+	0xf9f9f9f9, 0xfcfbfafa, 0xfffdfcfb, 0x0000ffff,
+	0x0401fefd, 0x05050505, 0x0603fffe, 0x090a0a09,
+	0x030a01f2, 0x010100fe, 0x030d02f0, 0x0001fffd,
+	0x030c02f1, 0x0101fefc, 0x020a03f6, 0x0101fffd,
+	0x02040100, 0x0bfdf6fb, 0x020401ff, 0x0ffef3fa,
+	0x010300ff, 0x0ffff4fa, 0x010201ff, 0x0b00f8fc,
+	0xfefe050a, 0xfc010502, 0xfaf80007, 0xfc020501,
+	0xf9f4fb02, 0xff040702, 0xfcf6f9ff, 0x02070904,
+	0xfafcfbfb, 0xfdfbfbfa, 0xfcfefeff, 0xfcfbfafb,
+	0x04070706, 0xfdfdfe00, 0x0a0d0e0d, 0xfeff0105,
+	0x02020101, 0x02020202, 0xf7f8fafb, 0xfaf9f8f7,
+	0x0b0a0907, 0x0507090b, 0xfdfdfeff, 0xfdfcfcfc,
+	0x0000ffff, 0xffff0000, 0xfbfcfdfd, 0xfefdfdfc,
+	0xfdff0102, 0x00fffefd, 0x03080c0c, 0x01000001,
+	0xfaf8f8fa, 0x080602fe, 0xfeff0101, 0x07050300,
+	0xff010303, 0x020000ff, 0xff000100, 0xfffeffff,
+	0x00000001, 0x04020000, 0x04030102, 0x02000103,
+	0x00000102, 0x0300ffff, 0xf4fa0105, 0x04fff8f3,
+	0xfeff00fe, 0x030200ff, 0x00fefdfa, 0x01010101,
+	0x0400fbf7, 0x00010305, 0x0703fdf8, 0x00010408,
+	0x03020201, 0xfdff0103, 0x06050504, 0x00020506,
+	0x00000000, 0xfcfe0001, 0xfdfcfdfd, 0xf8f9fcfd,
+	0xff060c0e, 0x0000fdfd, 0xfd010507, 0xfffefcfb,
+	0xfefefefe, 0xfffffefe, 0x01fffcfa, 0xff000101,
+	0xfd010202, 0xfdfaf9fa, 0xfdff0001, 0x060401fe,
+	0x02010000, 0x07080704, 0x00000000, 0xf8f9fcff,
+	0xfe010200, 0xfffefdfd, 0xfd0001ff, 0x0200fefb,
+	0xfbfefffe, 0x090601fc, 0xfcfdfefd, 0x0d0b05fe,
+	0x0602fefc, 0xf2f6fd04, 0x0401fffe, 0xfeff0104,
+	0xfeff0000, 0x060400fe, 0xfd000202, 0x090500fd,
+	0x01fefcfc, 0xf9030906, 0xfffefefe, 0xf5000804,
+	0x00000101, 0xf6ff0602, 0x00010202, 0xf9000402,
+	0xfafdfeff, 0xf8f8f8f9, 0x01030302, 0xfcfdfeff,
+	0x04050505, 0xff000203, 0x03030303, 0x01010202,
+	0xfe020303, 0x0a0700fd, 0xfe020201, 0x0300fcfb,
+	0x02040300, 0xfcfafbfd, 0x04040200, 0xf9f9fc01,
+	0x05050402, 0x06060505, 0xfbfdfcfc, 0xfefdfdfb,
+	0xfbfcfcfd, 0xfefefefc, 0x00000101, 0x04050402,
+	0x040300fe, 0x02020304, 0x00fcf9f7, 0x06060603,
+	0xfefdfbfb, 0x04030100, 0xfe020505, 0xfdfbfafc,
+	0x07fcfa01, 0x01fefe05, 0x06fcfb05, 0x01fcfb04,
+	0x06fcfb05, 0x01fdfb04, 0x08fdf901, 0x01fdff07,
+	0x00fcf9f8, 0x05050402, 0x02050605, 0xf9f9fbff,
+	0x01040605, 0xfbfafbfd, 0xfefbf9f9, 0x0a090601,
+	0x01000306, 0xf2f80003, 0x01ff0003, 0xfc000304,
+	0x01000001, 0x01010102, 0x0201ffff, 0x00ffff01,
+	0x01010101, 0x00fdfe00, 0x00010201, 0xfcf7f8fe,
+	0x02030301, 0x01fdfd01, 0x01010100, 0x08040101,
+	0x07090502, 0x01ffff02, 0x0001fffc, 0x02fffcfd,
+	0x030300fd, 0x0200ff00, 0x0101fffc, 0xfcfbfcfe,
+	0xfefeff01, 0x050402ff, 0x00010102, 0x0000ffff,
+	0x05040302, 0x00010204, 0xfdfaf7f7, 0xffffffff,
+	0x0704fafa, 0xfefffe00, 0x0605feff, 0xff00feff,
+	0x0001ff04, 0xfe00fefc, 0xfeff0107, 0x010301fd,
+	0x03010204, 0x02010103, 0x00fcfe02, 0x00000103,
+	0xfcf8fc01, 0x00010201, 0xfaf7fd02, 0x02030300,
+	0xff00ffff, 0x020100ff, 0xf8fc0103, 0x0201fdf9,
+	0xfefdff02, 0x000100ff, 0x0b0500ff, 0xfdff0309,
+	0xfffefeff, 0x01010101, 0x0300ff00, 0x05050606,
+	0xffff0102, 0xfcfafbfe, 0x01020202, 0xfbfbfcff,
+	0xf9fafdff, 0x01fffcfa, 0x04030505, 0x05040304,
+	0xfefdfeff, 0x0100fefe, 0x00000000, 0x03020100,
+	0xfffcfafa, 0x02020202, 0xfefbf9fa, 0x00ffff00,
+	0x04020202, 0x04030304, 0xff000102, 0x04020000,
+	0xf8fb050c, 0x020200fb, 0xfdfafd02, 0xfeff0000,
+	0x03fffdfe, 0xfdfe0104, 0x04030202, 0xffff0103,
+	0x00010203, 0x00030401, 0xfb000304, 0x030300fa,
+	0xf9010302, 0x0301faf4, 0xff040301, 0x0100fcfa,
+	0x0602fcf7, 0x00010407, 0x0604fff9, 0xfdfd0004,
+	0x040400fa, 0xfefdfe01, 0x020301fc, 0x00fffe00,
+	0xfb020500, 0xfc0103fd, 0xfa0204fe, 0xfd0406fd,
+	0xfb0305ff, 0xfc0307ff, 0xfa0002ff, 0xfd0305fd,
+	0x0503fdf8, 0xfefe0103, 0xfe040402, 0x0301fdfc,
+	0xfbfd0102, 0x030403fd, 0x03fbfafb, 0xfbff080a,
+	0xfc020300, 0x0600f9f7, 0x0705fffb, 0xfdfdff04,
+	0x03fefbfb, 0xfcff0506, 0xfc000609, 0xff0101fe,
+	0x01ffffff, 0x00ff0001, 0x000000ff, 0x00ffff00,
+	0xfffe0102, 0x00000101, 0xff02080c, 0xf9f9fcff,
+	0x06030102, 0x00020407, 0x00ff0001, 0xf8f9fcff,
+	0x00ff0000, 0xfdff0000, 0x00000000, 0xfe000101,
+	0x010100ff, 0xfeff0000, 0xfdff0000, 0x01fffdfc,
+	0x000000ff, 0x0c0a0401, 0xfefe00ff, 0x01fffdfd,
+	0xfcfefffd, 0x07090902, 0xfdff00fd, 0x01ff0200,
+	0xfdfe01ff, 0x00fdff00, 0xfefd0000, 0x01ffff00,
+	0xfffffeff, 0xfefffffe, 0xfffeff02, 0xfe000100,
+	0x02feff03, 0xfdff0305, 0x01fbfb01, 0x00020606,
+	0xff000201, 0xfe000100, 0x00fffdfb, 0xfe010201,
+	0xfefefbf9, 0x0100fefe, 0x010100ff, 0x0c090300,
+	0x01050600, 0x0300fdfe, 0x01050600, 0x03020101,
+	0xfdfefefb, 0x00000000, 0xfefdfdfa, 0xfeff0000,
+	0x01020404, 0x00ffff00, 0x0100fefe, 0x00010102,
+	0xff010202, 0xf6f7fbfd, 0xffff0102, 0x01040401,
+	0xfefe0004, 0x00fffefe, 0xfdfc0107, 0x010100fe,
+	0xfeff050a, 0x00010100, 0xfcfd0105, 0xfefffffd,
+	0xfdff0102, 0xff0101fd, 0x0003fffe, 0x000101ff,
+	0x020701fd, 0x00fffefd, 0xff0804fe, 0x0200fbf8,
+	0x0201fffc, 0xfefcfd01, 0x01fefdfb, 0x06040404,
+	0xfdfcfefd, 0x02010100, 0x01020202, 0xffff0102,
+	0xff00fffc, 0xfffffdfd, 0x02040401, 0xfdfeff00,
+	0x03050604, 0xfcfe0102, 0x01010100, 0xfafcff01,
+	0xff020201, 0x02fffbfa, 0x0101fefd, 0x0502fdfc,
+	0x0202fffe, 0x0300fcfd, 0x0602fefe, 0x02010205,
+	0x00fdfd02, 0x01030200, 0x0301ff03, 0xfbff0201,
+	0xfefcf9fb, 0x01080801, 0x000200ff, 0xfd0100fd,
+	0xfefbfbfe, 0xfe00fffd, 0x0400fcff, 0x00040200,
+	0x0a080000, 0xff030102, 0x0302fdfc, 0xff01fdfd,
+	0x02fcfe01, 0xfffe0307, 0xfffe0406, 0x03ff0002,
+	0xfefe0101, 0x04fdfbfe, 0x0101fefa, 0x04fefcff,
+	0xfefefffe, 0xfe000100, 0xff0001ff, 0xfdff0000,
+	0xfcfe0100, 0x0000fffd, 0x00050806, 0x03020100,
+	0x0502fefe, 0x01000002, 0xfffefe02, 0x040201ff,
+	0x0100ff02, 0x01000000, 0x01fff9f8, 0x0301ffff,
+	0x02060300, 0x000201fe, 0x00fff9f6, 0x0102fffd,
+	0x02020000, 0xff010101, 0xfefe0003, 0x00010200,
+	0x00000108, 0x00fffdfe, 0x0502fe02, 0x01fffe01,
+	0xfffdfafd, 0x02fffdfd, 0x02010002, 0x00000102,
+	0xfeffff01, 0x000100ff, 0xff02090f, 0xfdfdfdfe,
+	0x00fefd00, 0xffffff00, 0x00010001, 0xffffff00,
+	0xfe020200, 0xf8f9fdfd, 0x00020200, 0x01010201,
+	0x02020201, 0x03000103, 0xfeff0001, 0x0500feff,
+	0x01fffaf5, 0xfd010302, 0xff030401, 0xff0201fe,
+	0xff010202, 0xff0100fe, 0xffff0000, 0x02030200,
+	0x01020101, 0xfc0001ff, 0xfe000000, 0xfe0402fe,
+	0x0000fdfe, 0xfa0102ff, 0x05050200, 0xf9ff0203,
+	0x00000204, 0xff010303, 0x03ffff00, 0xff010406,
+	0x0200fefe, 0xfefe0002, 0xfbff00ff, 0x01fffbf9,
+	0x00feff05, 0xfb020402, 0x02fefb00, 0xfa000201,
+	0x01000106, 0x0204fffe, 0x00fdfd02, 0x0000feff,
+	0x0200ff01, 0x0b060000, 0x00ffff02, 0x0503fefd,
+	0x00fffe00, 0xfd0000ff, 0xffffff01, 0xf9fdfffe,
+	0xfefe0101, 0xfe010301, 0xff0002ff, 0x000001ff,
+	0xff0302fc, 0x0100fefe, 0x0504fef5, 0xfeff0206,
+	0xff01fefa, 0x0901fcfd, 0x030300fd, 0x03fdfd02,
+	0x00000101, 0x03feff01, 0xfdfd0002, 0x03ffff00,
+	0x01fdff01, 0x06fcfa02, 0xfefbfe00, 0x03fefd00,
+	0xfe010202, 0xff0201fe, 0xfe0101ff, 0xff0706ff,
+	0xfefc0001, 0x01fdfe01, 0xfefd00fc, 0x00fd0002,
+	0x010304fd, 0xff000708, 0xfc0104fd, 0xfdfe0302,
+	0xfc0106fd, 0xffff0101, 0xfdfd04fe, 0xffff0003,
+	0x02fc0201, 0x02fffd04, 0x05fcff03, 0x02fdfa04
 };
 
-// 6x16-entry codebook for inter-coded 8x8 vectors
-static const int8 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
+static const uint32 s_svq1InterCodebook8x8[1536] = {
+	0x0504fdfc, 0x00010102, 0x0505fdfb, 0x00000102,
+	0x0505fcfa, 0x00000102, 0x0504fcf9, 0x00000102,
+	0x0403fbf8, 0x00000102, 0x0403faf8, 0x00010101,
+	0x0402faf8, 0x00010102, 0x0402faf8, 0x01010101,
+	0xffffffff, 0xffffffff, 0xfefefeff, 0xfefefefe,
+	0xfdfdfdfe, 0xfdfdfdfd, 0xfdfdfdfe, 0xfdfcfdfd,
+	0xfefefefe, 0xfefdfdfe, 0x01010101, 0xffff0001,
+	0x05050504, 0x02030304, 0x08080707, 0x05060708,
+	0x04020102, 0xfafc0004, 0x05020101, 0xf9fb0105,
+	0x04010201, 0xf8fb0105, 0x05010101, 0xf8fa0005,
+	0x05010100, 0xf7fa0106, 0x04010000, 0xf8fb0005,
+	0x04010000, 0xf9fb0005, 0x04010000, 0xf9fc0104,
+	0x00030201, 0xfffdfcfd, 0x00040301, 0xfffdfcfd,
+	0x01050402, 0xfefdfcfd, 0x01060502, 0xfefcfbfd,
+	0x01060603, 0xfefcfbfd, 0x01060603, 0xfefcfbfd,
+	0x01060603, 0xfefcfbfd, 0x01050503, 0xfefcfcfd,
+	0x02020202, 0xff000001, 0x03040404, 0x00010102,
+	0x04040504, 0x01020303, 0x04040404, 0x02020304,
+	0x03030302, 0x01020303, 0xffffffff, 0x00000000,
+	0xfbfafafb, 0xfdfdfcfb, 0xf8f7f7f9, 0xfbfafaf9,
+	0x06060606, 0x04050506, 0x03040404, 0x02030303,
+	0xffffff00, 0xfffffefe, 0xfafafbfd, 0xfcfbfafa,
+	0xf9fafbfd, 0xfcfbfafa, 0xfefefeff, 0xfffffefe,
+	0x01010100, 0x01010101, 0x03030303, 0x03030303,
+	0xfbfe0102, 0x050200fc, 0xfafe0102, 0x050300fb,
+	0xfafe0102, 0x0603fffa, 0xf9fe0203, 0x070400fa,
+	0xf9fe0102, 0x070500fb, 0xfafe0102, 0x070400fb,
+	0xfafe0102, 0x060400fc, 0xfbfe0101, 0x060300fc,
+	0xfcfaf7f6, 0x020302ff, 0xfdfbf7f6, 0x03040400,
+	0xfffdf9f7, 0x03050502, 0x00fefbf9, 0x03050503,
+	0x0100fdfa, 0x03050604, 0x0201fefc, 0x02040503,
+	0x020100fe, 0x01030402, 0x020201ff, 0x01030302,
+	0xfafbfbfc, 0xfbfafafa, 0xfcfcfdfd, 0xfcfcfcfc,
+	0x00000000, 0xffffffff, 0x05060505, 0x02030405,
+	0x07070605, 0x04050607, 0x04040303, 0x02030404,
+	0x0000ff00, 0xff00ffff, 0xfcfcfdfd, 0xfdfdfcfc,
+	0x01fbfe01, 0x00020405, 0x01fafd01, 0x00020506,
+	0x00f9fc00, 0x01020606, 0xfff7fbff, 0x01030606,
+	0xfef6faff, 0x01030606, 0xfef7faff, 0x01030605,
+	0xfef7fafe, 0x01030505, 0xfef9fafe, 0x01020404,
+	0xf7f8f9fb, 0xfaf9f8f7, 0xf9fafafb, 0xfbfafaf9,
+	0xfcfdfdfd, 0xfcfcfbfb, 0xff0000ff, 0xffffffff,
+	0x02020100, 0x01020202, 0x05040302, 0x04050505,
+	0x06050403, 0x07080808, 0x06050403, 0x06070707,
+	0x08070605, 0x090a0a09, 0x07060403, 0x08090908,
+	0x03020100, 0x05050504, 0xfffffeff, 0x02020100,
+	0xfdfdfdfe, 0x00fffefd, 0xfbfbfcfd, 0xfcfbfbfb,
+	0xfafbfbfc, 0xfbfaf9f9, 0xfafbfcfd, 0xfafaf9f9,
+	0xfd00070d, 0xfbfcfcfd, 0xfd00070e, 0xfcfcfcfd,
+	0xfcff080f, 0xfcfbfcfc, 0xfcff080f, 0xfdfcfbfc,
+	0xfcff070f, 0xfcfbfbfb, 0xfcff070e, 0xfdfcfcfc,
+	0xfcff060c, 0xfdfcfcfc, 0xfcff050b, 0xfdfcfcfc,
+	0x0405fcef, 0x03030404, 0x0405fbee, 0x03030404,
+	0x0406fbed, 0x02030404, 0x0406fbec, 0x03030404,
+	0x0406fcec, 0x03030504, 0x0406fbed, 0x03030504,
+	0x0405fcee, 0x02030404, 0x0304fbef, 0x03030404,
+	0xfcfafafa, 0x0b0601fe, 0xfcf9f9fa, 0x0d0802fe,
+	0xfcf9f8f8, 0x0e0903fe, 0xfbf9f8f8, 0x100a04ff,
+	0xfbf9f8f8, 0x110a04ff, 0xfcf9f8f8, 0x100a0500,
+	0xfdfaf8f8, 0x0f090400, 0xfdfbf9f9, 0x0c080400,
+	0x05070708, 0xf2f8fe02, 0x05070808, 0xf1f8fe02,
+	0x05070808, 0xf0f7fd01, 0x05070808, 0xeff6fd01,
+	0x05080908, 0xeff6fd01, 0x04070808, 0xf0f6fc01,
+	0x04070707, 0xf2f7fd01, 0x03060706, 0xf3f7fd00,
+	0xfcfc0105, 0x0000fffd, 0xfdfd0207, 0x0001fffe,
+	0xfdfd0107, 0x010100ff, 0xfefd0106, 0x000101ff,
+	0xfefc0006, 0x000100ff, 0xfdfc0005, 0xff0000ff,
+	0xfffd0005, 0xfe000000, 0xfffe0104, 0xff000100,
+	0x01010202, 0xf8f8fafe, 0x01010101, 0xf8f8fbfe,
+	0x00010101, 0xfbfbfdff, 0x00000000, 0xfeffffff,
+	0x0000ff00, 0x00010000, 0x00000001, 0x02030201,
+	0x01010102, 0x03040302, 0x03030303, 0x04050404,
+	0xfefdfcfc, 0x01010000, 0xfefdfcfc, 0x010000ff,
+	0xfffefefe, 0x0000ffff, 0x00000100, 0xff000000,
+	0x02020202, 0x01010202, 0x04040403, 0x03040404,
+	0x03010101, 0x03030403, 0xfcfbfafb, 0xfefefdfd,
+	0xfffffefc, 0x0100ffff, 0xfffffefc, 0x0100ffff,
+	0xfffffefd, 0x020100ff, 0xfffefdfc, 0x030301ff,
+	0xfffdfdfc, 0x050401ff, 0xfefefdfc, 0x070401ff,
+	0xfffffefe, 0x08060200, 0x010000ff, 0x08070401,
+	0xfefdfdfd, 0x00fffffe, 0x0100ffff, 0x03030202,
+	0x04020100, 0x05060605, 0x030200ff, 0x03050605,
+	0x0200ffff, 0x01020303, 0x00fffefe, 0xfcfcfdff,
+	0xffff0000, 0xf9f8fcfe, 0x00010201, 0xf9fafcff,
+	0xfa0104fe, 0x00000300, 0xf90105fe, 0x00000300,
+	0xf80105fd, 0xffff0300, 0xf70106fe, 0xff000300,
+	0xf80206fe, 0xff000400, 0xf90105fd, 0x00000401,
+	0xf90104fe, 0x00010400, 0xfa0104ff, 0x00010300,
+	0x03000000, 0x01040504, 0x02010101, 0x00020303,
+	0x02010202, 0xfeff0102, 0x01010304, 0xfbfdff00,
+	0xff010305, 0xfafcfdfe, 0xfe000305, 0xf9fafbfd,
+	0xfe000304, 0xfbfbfcfd, 0xff000304, 0xfdfdfefe,
+	0x00000000, 0x06fefbff, 0x01000000, 0x08fefaff,
+	0x02000000, 0x09fdfa00, 0x0200ff00, 0x0afef900,
+	0x0200ff00, 0x0afdf8ff, 0x02ffff00, 0x09fdf9ff,
+	0x0100ff00, 0x08fdfaff, 0x01000000, 0x07fefb00,
+	0x02030302, 0xffff0001, 0x02030403, 0xfeff0001,
+	0x02040403, 0xfdfeff01, 0x02030302, 0xfdfeff00,
+	0x010100ff, 0xfefeff00, 0xfffdfcfb, 0x01010100,
+	0xfffbf8f8, 0x03040301, 0x00fbf7f6, 0x05060503,
+	0x0504fffb, 0x00000103, 0x0504fffa, 0xfeff0002,
+	0x0405fffa, 0xfefeff02, 0x0404fff9, 0xfdfdfe01,
+	0x0405fffa, 0xfdfdfe01, 0x040400fb, 0xfefeff01,
+	0x040500fc, 0xfeffff01, 0x030401fd, 0xfeffff01,
+	0x01fefdfe, 0x03050604, 0x00fcfcfd, 0x02040503,
+	0xfffbfbfd, 0x01030402, 0xfffcfafc, 0xff020402,
+	0x01fdfcfe, 0xff020402, 0x01fefcfe, 0xfe010303,
+	0x01fefdfe, 0xfe010303, 0x01fffefe, 0xfe000303,
+	0xfefdfcfc, 0x070502ff, 0xfdfdfcfc, 0x070501fe,
+	0xfdfefdfe, 0x0503fffd, 0xfe00ffff, 0x0402fefd,
+	0xff010101, 0x0301fdfc, 0xff020304, 0x01fffdfc,
+	0x00030406, 0x00fefdfd, 0x01030506, 0xfffefdfe,
+	0x04080b0c, 0xfffefe00, 0x0206090a, 0x00fffeff,
+	0x00020304, 0x0100ffff, 0xffffffff, 0x020100fe,
+	0xfefcfbfd, 0x030200fe, 0xfefcfbfb, 0x020100ff,
+	0xfefcfbfb, 0x010100ff, 0xfefdfcfc, 0x0000fffe,
+	0xff020303, 0xfefdfcfd, 0xfe000203, 0xfefdfcfc,
+	0xff010202, 0xfdfcfbfd, 0x01030303, 0xfdfdfdfe,
+	0x03040404, 0xfefefe00, 0x03050505, 0xfefeff00,
+	0x02040505, 0xfefdfeff, 0x00030303, 0xfcfcfcfe,
+	0xfe04ffff, 0xfb0206fe, 0xfe0400ff, 0xfa0206fd,
+	0xfe0400ff, 0xf90307fd, 0xfd04ffff, 0xf90308fc,
+	0xfd04ff00, 0xfa0307fc, 0xfd04ffff, 0xfa0307fc,
+	0xfd03ffff, 0xfa0306fc, 0xfe0300ff, 0xfb0306fd,
+	0x02f9fe01, 0x01fffe05, 0x03f8fe01, 0x02fffd06,
+	0x04f7fe02, 0x02fefc07, 0x05f7ff03, 0x03fffc07,
+	0x04f7ff03, 0x02fefc07, 0x04f9ff03, 0x01fefc06,
+	0x04fa0002, 0x01fffc06, 0x03fb0002, 0x01fffd04,
+	0x000202fe, 0xfcfdff00, 0x010202fe, 0xfcfe0001,
+	0x020202fe, 0xfeff0102, 0x030302fd, 0xfe000204,
+	0x020302fd, 0xfd000204, 0x010201fc, 0xfdff0102,
+	0x000100fb, 0xfdfe0101, 0x000000fc, 0xfdfe0001,
+	0xfeff0000, 0x080702fe, 0xfdff0000, 0x070601fe,
+	0xfdff0100, 0x050400fd, 0xff000100, 0x030100ff,
+	0x01010200, 0x0100ff00, 0x020100fe, 0xffff0001,
+	0x0100fefb, 0xfdfd0001, 0x01fffcfa, 0xfcfdff01,
+	0x0502fefc, 0x02030406, 0x0401fdfb, 0x00000204,
+	0x0200fefc, 0xfefeff01, 0x0100fffe, 0xfefdfe00,
+	0x000000fe, 0xfffeffff, 0x00fffffe, 0x02010000,
+	0xfffffefe, 0x04030100, 0xfffefdfe, 0x05040200,
+	0xfefe0102, 0x000100ff, 0xfdfd0001, 0x000100ff,
+	0xfdfdff00, 0x010101ff, 0xfffd0000, 0x03030201,
+	0xfffdff00, 0x03030301, 0xfefcfefe, 0x04040301,
+	0xfefcfdfd, 0x04030301, 0xfefbfdfe, 0x03030201,
+	0x04030504, 0x05040404, 0x00010303, 0x01000000,
+	0xfeff0101, 0xfefdfcfd, 0xfe000202, 0xfefdfcfe,
+	0xff010302, 0xfefdfdff, 0x00000201, 0xfffefeff,
+	0xff000100, 0xfffefdff, 0xff000101, 0xfefefeff,
+	0x00fffffe, 0x00010201, 0x05030201, 0x03050506,
+	0x04030201, 0x03040505, 0xfdfdfefe, 0x0000fffe,
+	0xfbfcfdfd, 0xfffefdfc, 0xfefeffff, 0x0000fffe,
+	0xff000100, 0x010000ff, 0xfeff00ff, 0xfffefefd,
+	0x05060707, 0xfeff0204, 0x02020303, 0xfdfe0001,
+	0xffffff00, 0xfefeff00, 0xfffefdff, 0x01000000,
+	0xfffefe00, 0x020201ff, 0xffff0103, 0x020201ff,
+	0xfdfe0103, 0x0201fffe, 0xfafbfe01, 0x00fefdfb,
+	0xfdfeff00, 0xfefe00ff, 0xffff0000, 0xfeff0100,
+	0xfffe0000, 0xfe000000, 0xfdfdfeff, 0xfdfdfffe,
+	0xfdfdfeff, 0xfcfdfefe, 0x00000202, 0xfeff0000,
+	0x02030505, 0xff000202, 0x05060808, 0x01020404,
+	0xfdfaf8f9, 0xfffeffff, 0x00fdfbfb, 0x00000102,
+	0x0300ffff, 0x01010304, 0x03010102, 0x02020304,
+	0x02000203, 0x02010203, 0xffff0204, 0x01010100,
+	0xfdfe0203, 0x0100fffe, 0xfcfd0103, 0x0100fefd,
+	0x02fffefc, 0x00010303, 0xfefcfbf9, 0xfeff0000,
+	0xfcfbfbfa, 0xfdfefefe, 0xffff00ff, 0xff000000,
+	0x02020302, 0x00010202, 0x03040503, 0x00010001,
+	0x02030403, 0xffffff00, 0x01030505, 0xffffff00,
+	0xff000101, 0xfcfafbfd, 0x00000101, 0xfffdfd00,
+	0x00ffff00, 0x03010001, 0xfffdfefe, 0x07040202,
+	0x00fefefe, 0x06030202, 0x010000ff, 0x03000001,
+	0x03030300, 0xfffdfe01, 0x03040301, 0xfcfbfd00,
+	0xff000200, 0xfefefcfd, 0x00020401, 0xfffefdfe,
+	0x01030603, 0xff00fefe, 0x01040704, 0x00fffdfe,
+	0x00030603, 0x00fffdfd, 0xff000301, 0x0101fefd,
+	0xfeff0100, 0x0202fffd, 0xfdfdfffe, 0x0201fffd,
+	0x00ff0103, 0x00000001, 0xfffeff02, 0xffff0001,
+	0x00feff01, 0xfdfe0001, 0x01fffe00, 0xfbfd0103,
+	0x02fffe00, 0xfbfd0205, 0x04fffe00, 0xfbfe0306,
+	0x0400fe00, 0xfcfe0407, 0x0400fe00, 0xfcfe0406,
+	0xfcfdfefe, 0x00fffefd, 0xff000101, 0x0100ffff,
+	0x02020303, 0x01010101, 0x02020202, 0x01000001,
+	0x00000000, 0xffffffff, 0xfcfcfcfc, 0xfdfcfcfc,
+	0xfdfefdfd, 0x00fffffe, 0x05040403, 0x07060605,
+	0xfe07feff, 0x00fffffc, 0xff09feff, 0x00fffffc,
+	0xff0afdff, 0x01fffffc, 0xfe0afdff, 0x02fffffd,
+	0xfe0afeff, 0x02fffffc, 0xfe09feff, 0x02fffffc,
+	0xfe08feff, 0x01ff00fc, 0xfe07fe00, 0x0200fffd,
+	0x0301fc03, 0x0001fefd, 0x0401fb03, 0x0001fefd,
+	0x0502fa03, 0x0003fffd, 0x0502fa03, 0x0002fffd,
+	0x0501fa03, 0x0003fefc, 0x0501fa03, 0x0002fefd,
+	0x0401fa02, 0x0001fffd, 0x0401fa02, 0x0001fffe,
+	0x01010000, 0x02000001, 0x0101ff00, 0x02000001,
+	0x0000ff00, 0x02000000, 0x0000ff00, 0x00ff0000,
+	0x00010001, 0xfffeff00, 0x00010103, 0xfdfcfe00,
+	0x01020305, 0xfcfbfd00, 0x00020405, 0xfbfbfcff,
+	0xfeff0001, 0xf7fafdfe, 0xffff0002, 0xfafd0000,
+	0xff000001, 0xfbfe0000, 0x01010102, 0xfdff0201,
+	0x01020101, 0xff010202, 0x01020101, 0x01010101,
+	0x01020000, 0x02020000, 0x02020100, 0x02020000,
+	0x0100fdfc, 0x03040604, 0x0000fefd, 0x00010402,
+	0x0000ffff, 0xfdfe0101, 0x00010101, 0xfbfd0101,
+	0x00010101, 0xfbfd0101, 0xff0000ff, 0xfcfe0101,
+	0xff0000ff, 0xfe000201, 0x000000ff, 0x00010302,
+	0x040300ff, 0xfbfbfc00, 0x05040000, 0xfefdfe02,
+	0x0402ff00, 0x00ffff02, 0x01fffe00, 0x0100fe00,
+	0x00fefe01, 0x01ffff00, 0x00fdfe01, 0x00ff0001,
+	0x01fefe01, 0x00000103, 0x02fffe01, 0x00000204,
+	0x02030201, 0x01020200, 0x000100ff, 0x010101fd,
+	0xfe0000ff, 0x010200fc, 0xff0202ff, 0x010200fb,
+	0xff0403ff, 0x010200fb, 0x000402fe, 0x0000fffc,
+	0x000200fc, 0x0000fefc, 0x0102fffb, 0x020301fe,
+	0x00010001, 0xfeff0201, 0xfeff0002, 0xff000301,
+	0xfcfe0003, 0x00010300, 0xfbfd0105, 0x010102fe,
+	0xfbfe0106, 0x010001fe, 0xfbff0105, 0x00ff00fe,
+	0xfcfe0003, 0x00ff00fe, 0xfe00ff01, 0x01000100,
+	0x03020101, 0x02010102, 0x0100ffff, 0x01010001,
+	0x0000fdfc, 0x02010101, 0x0200fdfc, 0x02030202,
+	0x0100fcfb, 0x02010101, 0xfffffcfb, 0x00fffefe,
+	0x0000fefd, 0xfffefdfe, 0x04040302, 0x00000002,
+	0x0100fefc, 0x00000000, 0x0101fffd, 0x00000000,
+	0x020200fe, 0x02000000, 0x010201ff, 0x050300ff,
+	0xff010200, 0x060500fe, 0xfd000100, 0x060400fd,
+	0xfcfe0101, 0x0201fdfc, 0xfcfe0001, 0x00fefcfb,
+	0xfdfdfdff, 0xfffffefd, 0x00010203, 0x01010100,
+	0x02030405, 0x02020101, 0xfe000102, 0xfffffefe,
+	0xff000000, 0xfefefefe, 0x03030100, 0xffff0102,
+	0x04030100, 0xff010203, 0x01fffdfc, 0xfdfdfe00,
+	0xf8f9fcfd, 0x02fffcf9, 0xfcfdff00, 0x0200fefc,
+	0xff000001, 0x0200fefd, 0x00010102, 0x0200ffff,
+	0x01010101, 0x01000000, 0x01010101, 0x01010101,
+	0x02010000, 0x02020303, 0x03010000, 0x02030404,
+	0x00030303, 0x020100ff, 0xff010101, 0x01fffffe,
+	0xfdfffefe, 0x00fefefd, 0xfefefcfc, 0x00fdfefe,
+	0x01fffcfc, 0x02ff0001, 0x0302fffd, 0x05030304,
+	0x030200fe, 0x03030303, 0x0000fefe, 0x01000000,
+	0xff010200, 0xfe03fffd, 0xffff00ff, 0xfe0400fd,
+	0xfefefefe, 0xfe0501fe, 0xfffdfefd, 0xfd0401fe,
+	0x00ff00fe, 0xfb0300ff, 0x02010201, 0xfb020000,
+	0x03020402, 0xfd030101, 0x01010201, 0xfe040100,
+	0xfffcfd04, 0x03010303, 0xfffcfc04, 0x02000203,
+	0x00fcfd04, 0x01ff0202, 0x01fefd04, 0x00fe0102,
+	0x01fefc02, 0x00fd0002, 0x00fefd02, 0x02fe0001,
+	0x00ffff03, 0x03000000, 0xfefefe02, 0x02ffffff,
+	0x04030202, 0xff000103, 0x02010001, 0xfefeff01,
+	0x01020102, 0xffff0001, 0x03040304, 0x01010102,
+	0x02020203, 0x01010101, 0x00fffeff, 0xffffffff,
+	0xfffefdfd, 0xfefefefe, 0xfdfdfcfc, 0xfdfdfcfc,
+	0xfdff0102, 0x0403fefc, 0xff010202, 0x0201fefd,
+	0x03030201, 0xfefffe00, 0x040200ff, 0xfdff0002,
+	0x0300fefe, 0xfd000203, 0xfffdfe00, 0xff020201,
+	0xfbfcff03, 0x000200fd, 0xfafe0306, 0x010300fb,
+	0x00fe03fe, 0x01fefe03, 0x00fd04fd, 0x02fffe03,
+	0x00fd05fd, 0x02fffe04, 0xfffc04fe, 0x02fefd03,
+	0x00fd04fd, 0x02fffd03, 0x00fe05fe, 0x02fffd03,
+	0x01fd04fe, 0x02fffe03, 0x01fe03fe, 0x0200fe03,
+	0xff000001, 0xfffc0201, 0xff000002, 0xfefc0201,
+	0xff010101, 0x00fe0402, 0xff01ff00, 0x01ff0502,
+	0xfe00ff00, 0x01ff0501, 0xfeffff00, 0xfffd0300,
+	0xfe000101, 0xfffd0300, 0xfd000101, 0x00fe0300,
+	0x01ff0001, 0x05040201, 0x01ff0001, 0x07050101,
+	0xfffe0000, 0x050300ff, 0xfffeff00, 0x0302ffff,
+	0xfffdff00, 0x0201ffff, 0xfefcfeff, 0x0000fefe,
+	0xfffefeff, 0x0000fefe, 0x00ffff00, 0x0000ffff,
+	0xff000303, 0x040401ff, 0xfe000302, 0x010100fe,
+	0xff010302, 0x000100ff, 0xff000201, 0xfe00ffff,
+	0xff000100, 0xfe00fffe, 0xff000100, 0x0001fffe,
+	0xfdff0101, 0x0301fdfc, 0xfdff0201, 0x0301fcfb,
+	0x0100fefd, 0xfe000101, 0x01010100, 0xfdff0000,
+	0x01010201, 0xfeffff00, 0xfffdff00, 0xff00ffff,
+	0xfdfafd00, 0x0101fffe, 0xfdfcff02, 0x020200fe,
+	0x01010405, 0x02030100, 0x01020405, 0x0100ff00,
+	0xfbfe00fe, 0x0000fdfa, 0x000100fe, 0x020201ff,
+	0x030100fe, 0x01020202, 0x040200fe, 0x01010203,
+	0x030200fe, 0x00ff0002, 0x0101fffd, 0x01ffff00,
+	0x0001fffc, 0x0200feff, 0xff00fffc, 0x0401feff,
+	0xff0000fd, 0x00010101, 0xff0001fd, 0xffff0000,
+	0x000303ff, 0x01000001, 0xfe0202fd, 0x010000ff,
+	0xfe0000fb, 0x020001ff, 0x0001fef9, 0x02020201,
+	0x020300fb, 0x02020303, 0x010402fd, 0xfdfe0000,
+	0xfefe0205, 0xffffff00, 0xfdfcff02, 0xfffffeff,
+	0x01fefe00, 0x0100ff02, 0x03fffeff, 0x0200ff03,
+	0x03000001, 0x02fffe03, 0x03010102, 0x00fefe02,
+	0x01ff0001, 0xfefdfd01, 0x02010001, 0x00000003,
+	0x00fdfbfc, 0xfffeff01, 0x01fffdfe, 0x00000002,
+	0x01020101, 0x01010102, 0x01030403, 0xfffffe00,
+	0x00020303, 0xfefdfdfe, 0xff000101, 0xfefefcfe,
+	0x00000102, 0x0100ff00, 0x01010102, 0x03010101,
+	0xff000000, 0x0001fffe, 0xfefffffe, 0x0000fefd,
+	0xff0000ff, 0x010100fe, 0xff000101, 0x010301ff,
+	0xfe000202, 0x000302ff, 0xffff0103, 0xfe020401,
+	0xfffd0002, 0xfb000503, 0x00feff01, 0xfaff0303,
+	0x040300ff, 0x02010002, 0x0100fffe, 0x0100feff,
+	0xfdfefdfe, 0xfdfaf9fa, 0x01030202, 0xfefdfeff,
+	0x01030202, 0x00000000, 0x00010102, 0x01000101,
+	0x00000001, 0x02010100, 0x00ff0001, 0x01020200,
+	0x01030101, 0x01ffffff, 0x0000fffe, 0x02fffefe,
+	0x0101fefe, 0x03010001, 0xff00fefe, 0x0200ff00,
+	0x00010000, 0x01feffff, 0x01020203, 0x01fefe00,
+	0x02030305, 0x04010101, 0xfbfcfd00, 0x01fffdfc,
+	0x02fffcfa, 0xff000002, 0x0301fefc, 0x00020203,
+	0x02fffefd, 0x00020303, 0x01fefefd, 0xff010102,
+	0x00fefefe, 0xff010202, 0x01ffffff, 0x00020302,
+	0x01feffff, 0xff020202, 0x00feff00, 0xff000102,
+	0x01020406, 0x01000000, 0xfeff0204, 0xfffffefe,
+	0xfeff0102, 0xfffefefe, 0xfe000202, 0x00fffefe,
+	0xfeff0000, 0x0100fffe, 0xfffefdfd, 0x00fffeff,
+	0x0302fefd, 0xfeff0002, 0x050400fe, 0xff000205,
+	0x00020405, 0xfffffeff, 0x01020304, 0xff00ff00,
+	0x01000101, 0xff010001, 0x00fffffe, 0xfdfefe00,
+	0x000000ff, 0xfbfdfdff, 0xff010100, 0xfdfefeff,
+	0xfeffffff, 0x010301ff, 0xfffefeff, 0x05060502,
+	0x01fefdfd, 0xfffffe01, 0x04030201, 0xfdfffd01,
+	0x01000203, 0xfdfffdff, 0x00ff0001, 0x0001ffff,
+	0x01000101, 0x03050202, 0x02010101, 0x00030202,
+	0xfefefffd, 0xfdfffdfd, 0x000101ff, 0xfe00ffff,
+	0xfefe0002, 0xfe010402, 0xfffe0001, 0xff020503,
+	0xfefdfeff, 0xfe010301, 0xfffffeff, 0xff010200,
+	0x01010000, 0x00020201, 0x04040100, 0x01030202,
+	0x0102fffe, 0xfdfefdfe, 0x000100ff, 0xfbfcfcfd,
+	0xfcfd0004, 0xfffefcfc, 0x00ff0005, 0xfffefdff,
+	0x01000004, 0x00000001, 0xfffefd00, 0x00010000,
+	0x0000fe00, 0x01020101, 0x00000002, 0x00010101,
+	0xffff0002, 0x00010101, 0xfefeff01, 0x02020200,
+	0x00fefbfd, 0x00fdfdff, 0x0200fe00, 0x03000002,
+	0x00feff02, 0x02ffff00, 0xffff0205, 0x02ffffff,
+	0xff000205, 0x02ff00ff, 0x00000102, 0x02000100,
+	0x0101ffff, 0x02010202, 0x0000fefd, 0xfffe0000,
+	0x00020300, 0xfdfdfdfe, 0x01030300, 0x02010000,
+	0xfeff00ff, 0x0301ffff, 0xfeff00ff, 0x0200ffff,
+	0xfeff00ff, 0x02ff0000, 0xfeff00ff, 0x01feffff,
+	0xfd000100, 0x02ffffff, 0xff020505, 0x0301ffff,
+	0xff010000, 0x0200fefd, 0x00030101, 0x0100fefe,
+	0x01030101, 0xffff0000, 0x0102ff00, 0xfdff0001,
+	0x0101feff, 0xfcfe0001, 0x010200ff, 0xfdff0001,
+	0x02030101, 0xfdfe0001, 0x02040202, 0xfcfeff01,
+	0x02020201, 0x0200fe00, 0xfdfeffff, 0x01fdfbfc,
+	0x00010100, 0x01ffffff, 0x01010100, 0x02000000,
+	0x02010100, 0x02010101, 0x0200ffff, 0x03020202,
+	0xfffcfcfe, 0x00fefefe, 0x01000001, 0x01000000,
+	0xfefdff00, 0x01020200, 0xfdfeff00, 0x02010100,
+	0xfdfe0001, 0x010000ff, 0xfeff00ff, 0x00ff0000,
+	0x000101ff, 0x00000202, 0x01030200, 0x02030503,
+	0xfe0101ff, 0x01010300, 0xfc0000ff, 0xfffffffc,
+	0x000101ff, 0x02010201, 0x000100fd, 0x02000101,
+	0xfffffdfb, 0x01000100, 0xfdfefdfc, 0x00fffffe,
+	0xfeff0000, 0x00fefefe, 0x00020403, 0x01000000,
+	0x00000102, 0x00ff0000, 0x03020100, 0x02030404,
+	0x040704ff, 0x00000000, 0x030604ff, 0x01010100,
+	0x00040300, 0x010000ff, 0xfe010100, 0xffff00ff,
+	0xffff00ff, 0x000000ff, 0x00ffffff, 0x00000000,
+	0x00fdfdff, 0xfffeff01, 0xfefcfcfd, 0xfffefeff,
+	0x00010202, 0xfd000101, 0x0000fffe, 0xfd000101,
+	0x0100fffe, 0xfe010102, 0x02020201, 0xff020303,
+	0x00010201, 0xff020101, 0xfcfe0100, 0xff0100fe,
+	0xfdff0101, 0xfdff00fe, 0xff000201, 0xfcff0100,
+	0xfefeffff, 0x03040300, 0xfdff0101, 0x000000fe,
+	0x02020202, 0xffff0102, 0x03010101, 0xfefe0003,
+	0xffffff00, 0xfffffe00, 0xfdfcfdff, 0x0200fefe,
+	0x0100ffff, 0x05030202, 0x00fffffe, 0x01000000,
+	0x0002fdfe, 0xff010100, 0xfe01fcff, 0x000202ff,
+	0xfe00fc01, 0xff0101fe, 0xff01fd02, 0xff0101ff,
+	0x0103fe03, 0xff010100, 0x0102fd01, 0xff000100,
+	0x0001fbff, 0x010100ff, 0x0303fd00, 0x03030201,
+	0x01feff00, 0xff020505, 0xfffeff01, 0xfbfe0101,
+	0xfeff0101, 0xfdffffff, 0xffff0101, 0x030402ff,
+	0xffffffff, 0x030400ff, 0x0100ffff, 0xfffffdff,
+	0x02000000, 0xff000002, 0x00fdfe00, 0x02030101,
+	0x01020302, 0xfefe0000, 0x01000302, 0x02030301,
+	0xfffd0000, 0x030202ff, 0x01fdfefe, 0x01010201,
+	0x02fefffe, 0xfeff0101, 0x02000100, 0xfefe0000,
+	0x02000100, 0xfefe0000, 0x00fefefd, 0xfdfefeff,
+	0x03ff0100, 0xff0301ff, 0x03ff0100, 0xfd02ffff,
+	0x03fe0101, 0xfd00fdff, 0x03fe0202, 0xfe01fe00,
+	0x03fd0101, 0xfd01feff, 0x03fd0101, 0xfe01ff00,
+	0x04ff0201, 0xfe01ff00, 0x03ff0100, 0xfd00fdff,
+	0x01fffdfd, 0xfeff0102, 0x0200fefe, 0xfefe0001,
+	0x0201fefd, 0xfffeff01, 0x0402fefd, 0x01fefe00,
+	0x0402fffd, 0x02fefe00, 0x030401ff, 0x02fefdff,
+	0x02040200, 0x02fffeff, 0x00020100, 0x030100ff,
+	0x01fb0003, 0x01000004, 0x02fbfe01, 0x01feff05,
+	0x030000ff, 0xff000103, 0xfe0403fe, 0xfe00fffd,
+	0xfd0503fd, 0xfe0000fd, 0xfe0203ff, 0xff0202fe,
+	0xff000002, 0x00000000, 0x01fefd00, 0xfefe0003
 };
 
-// list of codebooks for inter-coded vectors
-const int8_t* const svq1_inter_codebooks[6] = {
-    svq1_inter_codebook_4x2, svq1_inter_codebook_4x4,
-    svq1_inter_codebook_8x4, svq1_inter_codebook_8x8,
-    NULL, NULL,
+const uint32 *const s_svq1InterCodebooks[6] = {
+    s_svq1InterCodebook4x2, s_svq1InterCodebook4x4,
+    s_svq1InterCodebook8x4, s_svq1InterCodebook8x8,
+    0, 0
 };
 
-// 6x16-entry codebook for intra-coded 4x2 vectors
-static const int8 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
+static const uint32 s_svq1IntraCodebook4x2[192] = {
+	0x0b0d0d0c, 0xeff1f6f9, 0xf6f4f1f0, 0x0c0f0f0b,
+	0x0f141102, 0x0d02e8d3, 0xdcfa1415, 0xe5ff100c,
+	0x2d0aebee, 0x15f9ecf5, 0x00e4f82b, 0x03e4f021,
+	0xfaeeeef4, 0x371cf6ec, 0xeeebeefb, 0xecfa1e38,
+	0xea1d1bde, 0xe71a1de2, 0x1a21221e, 0xdfdde1e7,
+	0xe0dcdde1, 0x1f25241d, 0x2226f4b9, 0x212affc1,
+	0xc4e1253a, 0xc3df2237, 0x5d16c7c7, 0x5d15c6c7,
+	0x3e46453b, 0xc4bcbcc1, 0xc0b9b9c0, 0x3e48493f,
+	0x0f0700fe, 0x05fdf6f5, 0xf6f6f8fb, 0x090e0901,
+	0xf5fc080f, 0xf4f5020c, 0x1c1300f8, 0xe6f1ff04,
+	0xf2021bf1, 0xf70116f2, 0xf6f3fafc, 0x2f06f2fa,
+	0x1706ecdd, 0x04060906, 0xea1702fa, 0xeb1c04f9,
+	0x06feea14, 0x08fbe416, 0xf4f0eef6, 0xff021324,
+	0x080400fd, 0x1717f6d3, 0xddec0f28, 0x0104fffc,
+	0x18dffb09, 0x13e60308, 0xfd0604ff, 0xcff31920,
+	0x070f1818, 0xf9ede5ef, 0x182700d1, 0x0407faeb,
+	0xf3f600ff, 0x10050101, 0xf7fd0514, 0xfafefcff,
+	0x0401f9ef, 0x0000070c, 0x0b0c0003, 0xe90001fd,
+	0x00fa1104, 0x00e70306, 0x05080aef, 0x040104f2,
+	0x02040a0d, 0x0201f7e9, 0x0701fd03, 0x14f9e901,
+	0x0c02eef9, 0x090afcfb, 0xe8070a04, 0xf6040306,
+	0x06eaf216, 0xff050500, 0xfcf503fc, 0xf2071ff9,
+	0x2afff0fb, 0xfbf7fefc, 0xfdfaf805, 0xfbebfc2a,
+	0xf4140cee, 0x07f6f30d, 0xeefef7f8, 0x082806f0,
+	0x0400ff0a, 0xf3ff04fd, 0xf10106fe, 0x02010305,
+	0x0301fefc, 0xfcf7000f, 0xfcfcfcfd, 0xfd1005fd,
+	0x04030d02, 0x00f6f8fd, 0xfffcfefa, 0x17fafdfe,
+	0x0107fa06, 0x0105ee04, 0x0ef101ff, 0x04fc06fb,
+	0x06020202, 0x030702e8, 0x030300e6, 0x06010705,
+	0xfdeefe0e, 0x02fc0507, 0x012003fa, 0xf4fafafa,
+	0x0607dc05, 0x000bff09, 0x03050404, 0xda030f04,
+	0xd6fb170a, 0x04040400, 0xf3fa1117, 0x1d01dbf3,
+	0x01fff205, 0x01030005, 0x02fb0400, 0xf6000008,
+	0xfdfe0704, 0x010103f6, 0x030dfff4, 0xfd01ff00,
+	0x0103ff00, 0x0903f7fa, 0xfafc01fa, 0x0800ff08,
+	0x1200fdfd, 0xfffcfffb, 0xfc03fef8, 0xfbff1100,
+	0xf609fe05, 0xfb06fb01, 0x03020204, 0x01f8f20a,
+	0xffeefeff, 0x020114ff, 0x01f701ff, 0xfc16f7ff,
+	0xfd08fc06, 0x05ed07ff, 0xfcfc1ff9, 0xfbfb00fa,
+	0xfcedf8f9, 0x20040101, 0x04f8ff26, 0xf4faf8f9,
+	0x01f900ff, 0x00ff09ff, 0x00ffff09, 0xfd01fa02,
+	0x010200f4, 0x00080101, 0x02000109, 0x00f501fe,
+	0xf6020800, 0x00ff02ff, 0xfb00fcfe, 0x0efffffe,
+	0x05ff07fd, 0x0101f600, 0xff0efbff, 0xfefd01fe,
+	0x060000fa, 0x04f70302, 0xfffffb04, 0xff0803f9,
+	0xf5fffc02, 0x0001020b, 0x090302ff, 0xf1000200,
+	0x03ec0503, 0x0303ff03, 0x0110ff01, 0x0209e302,
+	0xfdfffaf3, 0xfdf8ff24, 0x02040502, 0x030b09db
 };
 
-// 6x16-entry codebook for intra-coded 4x4 vectors
-static const int8 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
+static const uint32 s_svq1IntraCodebook4x4[384] = {
+	0x0603fdf5, 0x0705fff6, 0x0706fff7, 0x0604fff7,
+	0xf2000705, 0xf1020906, 0xf1020906, 0xf2000604,
+	0xfafb0310, 0xf8f80110, 0xf7f7ff0e, 0xf8f8000c,
+	0x11100c08, 0x090602fe, 0x00fcf8f6, 0xf9f5f2f1,
+	0x10fef6f9, 0x12fdf5f9, 0x14fff5f9, 0x1301f8fa,
+	0xeff0f3f7, 0xf7f9fe02, 0xff04080b, 0x070b0f10,
+	0x0f0dfeea, 0x100efee8, 0x0f0dfce7, 0x0d0afae7,
+	0x10161a1a, 0x03090f11, 0xf2f5fafe, 0xe4e4e7ec,
+	0xebe7e5e5, 0xf9f5f1f0, 0x0d0c0803, 0x1e1f1c17,
+	0xdff91014, 0xddfa1316, 0xdefa1316, 0xe0fa1114,
+	0x2602ecec, 0x2802eaeb, 0x2802eaeb, 0x2603ecec,
+	0x1a18fcd1, 0x1b1afdce, 0x1b1afdce, 0x1a18fcd1,
+	0xe5e9062d, 0xe4e70530, 0xe4e60530, 0xe5e8062c,
+	0x4cf6dce2, 0x4ef5dbe1, 0x4ef5dbe1, 0x4df6dce1,
+	0x3423e0cb, 0x3424deca, 0x3424deca, 0x3322dfcb,
+	0x413edea3, 0x423edea3, 0x413edea3, 0x403cdea3,
+	0x020200f9, 0x0303fff8, 0x050400f8, 0x050501fa,
+	0x0b0b0703, 0x03030202, 0xf9fafe01, 0xf3f5fb01,
+	0xfdfcfe03, 0xfbfb0007, 0xf9fb040c, 0xf9fc060e,
+	0xfe030e12, 0xfd000406, 0x00fefbf8, 0x02fef5f0,
+	0x1207faf8, 0x0d02f8f9, 0x06fefafc, 0x01fdfc00,
+	0xeef3fd01, 0xf9fbff00, 0x070601ff, 0x110f04fe,
+	0xfef9f2f1, 0x00fffbfa, 0x01030606, 0x01060d0f,
+	0x0af5fe02, 0x0bf4ff02, 0x0bf4ff03, 0x0bf5fe02,
+	0xfbff0ef7, 0xfbfe0ff7, 0xfbfe10f8, 0xfcff0ff9,
+	0x08080602, 0x0c0903fe, 0x0a04fbf5, 0x00f8f0ed,
+	0xf1f9080e, 0xf2f9070c, 0xf7fc0508, 0xfcff0305,
+	0x02fef20c, 0x03fff10d, 0x03fff10e, 0x03fff20d,
+	0xf30a0600, 0xf10a0600, 0xef090700, 0xf0080601,
+	0xfe0ffbf8, 0xfe11faf8, 0xfd10faf8, 0xfe0ffbf8,
+	0xf6f5f5f7, 0x08090a09, 0x090a0a08, 0xf9f8f7f8,
+	0x07090a09, 0xf6f6f6f8, 0xf5f5f6f9, 0x080b0c0b,
+	0x00070a00, 0xfa000700, 0xfafb0200, 0xfffcfffe,
+	0xf7fa0005, 0x01020202, 0x070500fe, 0x0401fbfa,
+	0xff02f803, 0x0003f704, 0x0003f905, 0x0003fb07,
+	0x0902fdfb, 0x0801fdfa, 0x0701fdfa, 0x0400fefb,
+	0x0103080d, 0xfffcfbfd, 0x00fdf9f8, 0x020301ff,
+	0xf4fb0203, 0xf7fe0304, 0xfc010403, 0xff040503,
+	0x00fcf8f7, 0x00020608, 0x0003080a, 0xfffdfbfa,
+	0xfbf4f7fd, 0x00fbfd00, 0x04020302, 0x06070805,
+	0x0c05feff, 0x0905ffff, 0xfeff0102, 0xeff5ff02,
+	0xff0303f9, 0xff0403f7, 0xff0604f6, 0x000705f7,
+	0x0202f9ee, 0x030501f8, 0x00010403, 0xfdfe0509,
+	0x080600fe, 0xfdfbfbfc, 0xf8fafe01, 0xff03090a,
+	0x00fefe00, 0x00fbfc00, 0x08fcf8fe, 0x1806f9fb,
+	0x01f90109, 0x01f80109, 0x01f60008, 0xfff5ff08,
+	0x03060808, 0x02030405, 0x00fffdfe, 0xfcf8f3f6,
+	0xfd020400, 0xfb030600, 0xf4020a03, 0xeafc0a05,
+	0x03fffc00, 0x05fffc01, 0x0800fb01, 0x07fefaff,
+	0xfcfeffff, 0xfafcfeff, 0xfeffffff, 0x090a0501,
+	0xfe00030a, 0xfbfeff06, 0xfafeff03, 0xfb000002,
+	0x00000306, 0x01010306, 0x01fefe04, 0xfef7f700,
+	0x0201fdf5, 0x050402fa, 0x040302fd, 0x020101fe,
+	0xfefffcfa, 0xfeffff02, 0xfefe020a, 0xfffc020b,
+	0x02fe0006, 0x00000303, 0x000303fa, 0x0005ffef,
+	0x0b0a04ff, 0x0100fefd, 0xfdfbfcfd, 0xfffefeff,
+	0xf4f7fd02, 0x02030303, 0x04040202, 0xfeff0102,
+	0xf60509fe, 0xfb0505fd, 0x000201fe, 0x01fefeff,
+	0xfe07fdfe, 0xfd07fdff, 0xfc08feff, 0xfd07fefe,
+	0x0cfdf801, 0x04fefe02, 0xfb000301, 0xf90205ff,
+	0xfb0103ff, 0x0103fef9, 0x02fef9fe, 0xfffb0314,
+	0xfefd0005, 0x0600f9f9, 0x060700fa, 0xf9000602,
+	0x01f906fe, 0x03f807fe, 0x03f907fe, 0x02fa07ff,
+	0x0705fefb, 0xf8fc0104, 0xfbfe0306, 0x0703fbf9,
+	0x0506ffff, 0xfc01ff00, 0xf9000102, 0xfc000001,
+	0x010300f8, 0xffff01fe, 0x01fdff01, 0x0901fe01,
+	0xfcfd0205, 0xfdff00ff, 0x010301fd, 0x020400fc,
+	0x0cfefe02, 0x03fbfe00, 0x01fd00ff, 0x01fefffd,
+	0x00030501, 0x01fefcfa, 0x02fefe00, 0xfffc0106,
+	0xfffbfbfd, 0x04050503, 0xff010300, 0xfdfe01fe,
+	0xfdfbfc02, 0xfefdfe04, 0xffff0006, 0x00000107,
+	0x00fefefd, 0xfffbfdfe, 0xff0002fe, 0xff090bff,
+	0xf6ff0100, 0xfa0001ff, 0x04010001, 0x0dfffb02,
+	0x000504fe, 0x030601fb, 0x0203fefa, 0xfe00fefb,
+	0xfe0101ff, 0x0200feff, 0x07050505, 0xf9f8fc00,
+	0xfbff0200, 0xfd0202ff, 0xfb030500, 0xf4020803,
+	0xfe000408, 0xfffcff0a, 0x00fdfa03, 0x0000fbfc,
+	0x02fcf600, 0x0503faff, 0x0406fdff, 0x0204fe00,
+	0xff010800, 0xfd010b00, 0xfcfe06ff, 0xfcf9fefd,
+	0xffffff00, 0x05060504, 0xfbf8f7fb, 0x02030202,
+	0x01060200, 0x00030002, 0xfefffe01, 0xfafdff00,
+	0x00020000, 0x01020004, 0x0000fe05, 0x02fff7fe,
+	0xf6000100, 0x000801ff, 0x0004feff, 0xff02ff01,
+	0xff02fefd, 0xfd02fffd, 0x0001ff00, 0x03ff0108,
+	0x02010100, 0x00fefc00, 0xff01fbff, 0x020bfffe,
+	0xfefe0501, 0x00fc0200, 0x01fb01fe, 0x01000500,
+	0x0600fdfb, 0x000002fc, 0x000105fd, 0x000003fd,
+	0x01fdfe03, 0x0800fc01, 0x03fefdfe, 0xffff0201,
+	0x02000101, 0x06010002, 0x0102ff01, 0xed000300,
+	0x02fefd01, 0xf9fe0506, 0x010301fd, 0x0200ffff,
+	0xfcfffff8, 0x02ff0101, 0x03020304, 0x000301fb,
+	0x01ff0200, 0x050000fd, 0x0800fefb, 0x06fcfcfc,
+	0x02010201, 0x02fd0202, 0x00f70004, 0x01f50007,
+	0xfe000000, 0xfaff0303, 0xf6fd0304, 0x020602ff,
+	0x05fdfe07, 0xff0300fc, 0xf90102fc, 0x03ffff02,
+	0x02020203, 0xfbf9f9fb, 0x02040605, 0x0100fffe
 };
 
-// 6x16-entry codebook for intra-coded 8x4 vectors
-static const int8 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
+static const uint32 s_svq1IntraCodebook8x4[768] = {
+	0x06060605, 0x08080707, 0x00000000, 0x03020100,
+	0xfbfcfcfd, 0xfefdfcfb, 0xfbfcfcfc, 0xfdfdfcfc,
+	0x02020201, 0x03030302, 0x04030302, 0x05050504,
+	0x010100ff, 0x04040302, 0xf7f7f6f7, 0xfbfaf9f8,
+	0xfafbfcfc, 0xf9f9f9fa, 0xfefeff00, 0xfcfcfdfd,
+	0x03030404, 0x00010102, 0x06070707, 0x04040506,
+	0x06050402, 0xfafd0104, 0x05050403, 0xf8fb0004,
+	0x04040302, 0xf6f9fe02, 0x01020202, 0xf4f7fc00,
+	0x01fdf9f7, 0x03030404, 0x03fef9f6, 0x03030505,
+	0x03fefaf7, 0x03040506, 0x03fffaf8, 0x02030404,
+	0xfbfbfbfb, 0x070401fd, 0xfcfbfbfb, 0x080601fe,
+	0xfdfcfbfc, 0x0a0803ff, 0xfefdfcfd, 0x0b090501,
+	0xfefefefe, 0xfefefefe, 0xfbfbfbfc, 0xfcfbfbfb,
+	0xfcfcfcfd, 0xfdfcfcfc, 0x0b0a0a09, 0x0a0a0b0b,
+	0xfe010407, 0xf6f7fafc, 0x00030709, 0xf7f8fcfe,
+	0x0204080b, 0xf8fafd00, 0x0305090b, 0xf9fbfe01,
+	0xf4f3f3f3, 0xf8f8f6f5, 0x03020100, 0x03040404,
+	0x06050403, 0x04050606, 0x04040403, 0x02030303,
+	0x0a0b0a0a, 0x07080909, 0x06060606, 0x02030405,
+	0xff000000, 0xfcfcfdfe, 0xf4f5f6f6, 0xf2f2f2f3,
+	0x10111010, 0x0b0c0d0f, 0xfcfdfeff, 0xfdfcfcfc,
+	0xfafafbfc, 0xfafafafa, 0xfafafafb, 0xfbfbfafa,
+	0xf4f3f3f3, 0xfaf8f6f5, 0xfaf9f8f7, 0x0100fefc,
+	0x0301fffe, 0x09080705, 0x0b090705, 0x0f0f0e0d,
+	0x070b0e10, 0xf7f9fd02, 0x03080c0e, 0xf5f7faff,
+	0x0004090b, 0xf3f5f8fc, 0xfd010508, 0xf2f4f6fa,
+	0xfdf7f1ee, 0x0b090601, 0xfff9f3ef, 0x0c0b0703,
+	0x01fbf5f1, 0x0d0c0905, 0x02fdf7f3, 0x0d0b0905,
+	0x0f131516, 0xf7fc030a, 0x090f1214, 0xeff4fb02,
+	0x01080d10, 0xe8ecf2f9, 0xf8ff060a, 0xe5e7ebf1,
+	0xf2ece9e7, 0x0e0901f9, 0xf7f0ebe9, 0x15100900,
+	0xfff6f0ec, 0x19161008, 0x06fdf5f1, 0x1b19140e,
+	0x0100fefc, 0x02020202, 0x0200fefb, 0x03030303,
+	0x01fffcfa, 0x03030302, 0x00fefbf9, 0x02020101,
+	0x01010102, 0xfdfe0001, 0x01020303, 0xfcfdff00,
+	0x01020304, 0xfafcfe00, 0x01030405, 0xfafbfdff,
+	0x04060605, 0xfdfe0002, 0x04040403, 0xff000103,
+	0xfffffefe, 0xfefeffff, 0xfefdfcfb, 0xfdfdfefe,
+	0xffffffff, 0xffffffff, 0xfcfcfcfd, 0xfdfdfdfd,
+	0xffffffff, 0xfeffffff, 0x06060605, 0x03040506,
+	0x04040404, 0x07060504, 0xffffff00, 0x020100ff,
+	0xfdfdfdfe, 0x00fffefd, 0xfcfcfdfd, 0xfffefdfc,
+	0xfcfcfe00, 0x030200fe, 0xfdfdfe00, 0x050402ff,
+	0xfdfcfeff, 0x06050300, 0xfdfcfdfe, 0x050402ff,
+	0xfd000409, 0x0100fffd, 0xfcff0408, 0x0201fffd,
+	0xfbfd0206, 0x0100fefc, 0xfcfd0105, 0x0100fefc,
+	0xff010305, 0xf6f6f8fc, 0x01020303, 0xfcfdfe00,
+	0x02010101, 0x00010203, 0x020100ff, 0x02030403,
+	0x02020100, 0xfdfdff01, 0x01010100, 0xfdfcfeff,
+	0xfdfdfdfd, 0x02fffdfd, 0x00fdfcfc, 0x0e0c0703,
+	0xfafafbfb, 0xfbfafafa, 0x01020202, 0x00000000,
+	0x02030404, 0x00000001, 0x04050606, 0x01010202,
+	0xfdfaf9f9, 0x08070400, 0xfdfdfeff, 0x0201fffe,
+	0xff010303, 0xfffefefe, 0x02040606, 0xfefefe00,
+	0x02fefbfa, 0x0c0b0905, 0x00fefcfc, 0x06050402,
+	0xfefefefd, 0x0100fffe, 0xfdfefefe, 0xfefdfdfd,
+	0x0301fdf9, 0xfbfd0003, 0x0503fefa, 0xfbfd0104,
+	0x0604fffb, 0xfcfd0205, 0x070500fc, 0xfdff0306,
+	0x00000000, 0x00000000, 0xfdfdfefe, 0xfffefdfd,
+	0x09080706, 0x06070809, 0xfbfbfcfc, 0xfcfbfafa,
+	0xfcfaf8f7, 0x06060300, 0x03fffcfb, 0x03050605,
+	0x06060301, 0xfbfe0104, 0x01050706, 0xf5f6f9fd,
+	0x0105090a, 0xfcfafafd, 0xfbff0305, 0x02fefbfa,
+	0xfafafcfe, 0x0a0601fc, 0xfcf9f9fa, 0x0c0b0701,
+	0x02030506, 0x00000000, 0xfeff0102, 0xfffffefd,
+	0xfcfeff00, 0x01fffefc, 0xfeff0000, 0x030200ff,
+	0xfefeff00, 0xfffffefe, 0x01020405, 0x00000000,
+	0x01030506, 0x00000000, 0xfcfe0002, 0xfefefdfc,
+	0x0200fcf9, 0x01020202, 0x0000fdf9, 0x00000000,
+	0x0101fffc, 0x01000000, 0x020201ff, 0x03030202,
+	0x020200fe, 0x01010101, 0x020201ff, 0xff000001,
+	0x02040200, 0xfdfeff00, 0x01030201, 0xfafafcfe,
+	0x04020201, 0x01040605, 0xffffff00, 0xfcfe0000,
+	0xfeff0000, 0xfafcfefe, 0x00000102, 0xfdff0101,
+	0x01010101, 0x03030201, 0x00010000, 0x04040201,
+	0xffffffff, 0x03020100, 0xfbfbfcfc, 0x00fffdfb,
+	0xfcfbfbfa, 0xfffffefd, 0x010000ff, 0x03030201,
+	0x01010100, 0x04030202, 0xffff0000, 0x03020100,
+	0x01010100, 0xffff0000, 0x02030301, 0xfefeff01,
+	0x020200fe, 0x01010202, 0xfefcf8f7, 0x03030301,
+	0xfeffffff, 0xfcfdfdfd, 0xff000000, 0xfdfdfefe,
+	0x00020202, 0xffffffff, 0x03040505, 0x02020202,
+	0xfcff0306, 0x0101fffd, 0xfcfdff02, 0x000202ff,
+	0x01fefeff, 0xfd010404, 0x0401fffe, 0xf8fd0306,
+	0x01020303, 0xfefefeff, 0xfffefcfc, 0x04040301,
+	0xfcfbfbfc, 0x020200fe, 0x01040707, 0xfefdfeff,
+	0x000301ff, 0x0600fafc, 0x010401fe, 0x07fffafc,
+	0x020401fd, 0x06fffafd, 0x020300fe, 0x04fffbfe,
+	0x01feff01, 0xf9ff0404, 0xfffcff01, 0xfa000605,
+	0xfdfc0003, 0xfc020603, 0xfcfb0003, 0xfd010401,
+	0x03030202, 0x02020303, 0xf9fafbfc, 0xfaf9f9f9,
+	0x03030201, 0x02020303, 0x01010000, 0x01020201,
+	0x03fdfd03, 0x02fefe04, 0x04fcfc03, 0x02fcfc04,
+	0x04fcfc04, 0x03fdfc04, 0x03fcfd03, 0x03fdfd03,
+	0xfefefefe, 0xfffffefe, 0x08080706, 0x05060708,
+	0xf9f9fafb, 0xfbfaf9f8, 0x02020101, 0x01010202,
+	0x00000000, 0x0000ff00, 0x000000ff, 0x0000ff00,
+	0xfefefdfe, 0xfdfdfdfe, 0x06050302, 0x00010204,
+	0x00020608, 0x00000000, 0x00000104, 0xffffff00,
+	0x0000ff01, 0xfdfeff00, 0x00fffefe, 0xfbfcfe00,
+	0xfeff0103, 0xfbfbfcfd, 0x00000102, 0x00000101,
+	0x00ffff00, 0x02020202, 0x01fffeff, 0x02020202,
+	0xfffeff00, 0x00ffffff, 0xfffefeff, 0x010000ff,
+	0x02010102, 0x00010102, 0x01030506, 0xfcfcfe00,
+	0x00fffefd, 0xff000101, 0x04030100, 0x01030505,
+	0x00ffffff, 0xfeff0001, 0xfffefefe, 0xfdfeff00,
+	0xfefeff00, 0x0200ffff, 0xfffeff01, 0x0200ffff,
+	0xfefe0001, 0x0501fefe, 0xfefeff01, 0x0a0500fe,
+	0x00000000, 0xffffff00, 0x00ffffff, 0x02010000,
+	0x03020201, 0x05060404, 0xfefdfdfd, 0xfdfdfdfe,
+	0xfefeff01, 0x07050300, 0xfdfe0002, 0x030200fe,
+	0xfdfe0103, 0xfffffefd, 0xff000103, 0xffffffff,
+	0x04050301, 0xfcfdff02, 0x0201fefd, 0xfeff0001,
+	0x0200fdfb, 0x00000102, 0x0201fffd, 0x00000102,
+	0xffffff00, 0x04030201, 0xfdfcfcfd, 0x010000ff,
+	0xfffefdfe, 0x01010101, 0x0300fefe, 0x02030404,
+	0xfefdfcfc, 0x030201ff, 0x01010100, 0xfdfdfeff,
+	0x04050403, 0xfdfdff02, 0x0200fefe, 0x00010202,
+	0x070500fc, 0xfcfcff04, 0x030402ff, 0xfefdfd00,
+	0xff000102, 0x0100fefe, 0xfeff0000, 0x0201fffe,
+	0xfffefdfc, 0x02020100, 0x0005090a, 0xfefdfcfd,
+	0xfefeff01, 0x000000ff, 0x01fffefe, 0xff000101,
+	0x0300fdfb, 0xfe000204, 0x0100fffe, 0xffff0001,
+	0xfeff0203, 0x0101fffe, 0xfbff0507, 0x0402fefa,
+	0xfd0303fe, 0xfe0201fc, 0xfd0403fd, 0xfe0302fc,
+	0xfd0403fd, 0xfe0302fc, 0xfe0402fc, 0xff0201fd,
+	0xfdff0304, 0x0201fffd, 0x00fcfafc, 0x01040504,
+	0x06050200, 0xfcfbfd02, 0xfdff0101, 0x0402fefb,
+	0x020100ff, 0x04030302, 0x010100ff, 0xffffff00,
+	0x020100ff, 0xfeff0102, 0x00fffefd, 0xfdfeff00,
+	0x01010101, 0x02010000, 0x00ff0001, 0x00010100,
+	0xfffcfe01, 0x00010201, 0xfdf9fc01, 0x01020301,
+	0x01010101, 0xff000101, 0x00010101, 0x00020201,
+	0x00000101, 0xfd000200, 0xff000203, 0xf7fafeff,
+	0x01000000, 0x02010000, 0x00000001, 0x0200ffff,
+	0x01010100, 0x00fefdff, 0x0601fbf9, 0xffff0206,
+	0xfdff0103, 0x0401fefc, 0xfdfe0002, 0x02fffdfc,
+	0x01010202, 0x01000001, 0x00000101, 0x01000000,
+	0xfe0101ff, 0xfffcfafb, 0x030401ff, 0x02010002,
+	0x030200ff, 0x01000001, 0x000100ff, 0x00ffff00,
+	0x02020100, 0x01fffe00, 0xfefffffe, 0x080602ff,
+	0xfdfeffff, 0x020100fe, 0xff0000ff, 0xffff00ff,
+	0x01010102, 0x00000001, 0x01010000, 0x01ffff01,
+	0x020200ff, 0x03fefdff, 0x00030200, 0x04fef9fb,
+	0x000000ff, 0xfdfdfeff, 0xfeff00ff, 0xfefefefe,
+	0x00000101, 0xff000201, 0x02010201, 0x00020605,
+	0x00fdfcfe, 0xfd000202, 0x01000103, 0xfdfe0102,
+	0x00000103, 0xff000000, 0xfefeff01, 0x030301ff,
+	0x02010203, 0xfe010304, 0xfdfcfcfe, 0xfdfe00ff,
+	0xffff0001, 0xff000100, 0x00000203, 0x00010100,
+	0x00000101, 0x00000000, 0x02030302, 0x01010202,
+	0xfdfeff00, 0xfcfbfbfb, 0xff000101, 0x03030100,
+	0x00fefaf7, 0x02020101, 0x0201fefa, 0x01000101,
+	0x020201fe, 0x01010101, 0x01020200, 0x01010100,
+	0x00000001, 0x00ff0000, 0x00000000, 0x00fefdff,
+	0xfefdfdfd, 0x090703ff, 0x02020201, 0xfdfcfe00,
+	0xfffe0002, 0xfaff0403, 0xfdfe0001, 0x000303ff,
+	0x00030300, 0x0101fffe, 0x0203fffa, 0x0100feff,
+	0xfe000305, 0x010200fd, 0x02020101, 0xf9fcfe00,
+	0x0201fefd, 0xfcff0102, 0xfe000202, 0x020200fe,
+	0xfdfe0000, 0x0000fffe, 0x00000000, 0x02020000,
+	0x0100fffe, 0x03020100, 0x0000fefc, 0x030200ff,
+	0xfffefefe, 0x040200ff, 0x00000000, 0x0100ffff,
+	0xffffff00, 0x0000ffff, 0x00020406, 0xfffffeff,
+	0x01010100, 0xf6fbff01, 0x01010101, 0xfc000101,
+	0x01010001, 0xff010101, 0x01010102, 0x00000000,
+	0x030401fd, 0x00ff0103, 0x000100fc, 0x000000ff,
+	0x010200fb, 0xff000101, 0xfe0102ff, 0xff00fffe,
+	0x03050402, 0x0201ff00, 0x00010000, 0xfffffefe,
+	0xfefefefe, 0x00fffefd, 0x00010000, 0x02010000,
+	0xfdfefe00, 0xff0202ff, 0x00000001, 0xfe030501,
+	0xff00ffff, 0xfb000200, 0x000100ff, 0xfe020200,
+	0xffff0103, 0x02010100, 0x01000001, 0x01010101,
+	0x01fef8f6, 0x01010102, 0x010201ff, 0x00000000,
+	0x0100ffff, 0x01020202, 0x00ffffff, 0xfcfbfdff,
+	0x01020101, 0x02000001, 0xfffffeff, 0x040200ff,
+	0x00fbf9fd, 0x00000002, 0x01feff03, 0x02010102,
+	0x01fffe01, 0x01000102, 0x0300ff00, 0xffffff02,
+	0x00010102, 0x00000000, 0x03fef9f7, 0x01010203,
+	0xfe000203, 0x0101fffe, 0x0000ff00, 0x00000101,
+	0x0101fffe, 0x00000001, 0xfe010201, 0x0201fdfc,
+	0xfe010201, 0x010300fd, 0x0000ffff, 0xfc000301,
+	0x01ff0002, 0x03fefe02, 0x02ff0002, 0x01fcfe03,
+	0x01010100, 0xfefafe02, 0x000000ff, 0xfffe0002,
+	0x0201ffff, 0xfefdfe01, 0xfffeff03, 0x020100ff,
+	0x0000040a, 0xfffefeff, 0xfffeff03, 0x00ffff00,
+	0x010702fb, 0x0001fefc, 0xff0302fe, 0x000200fd,
+	0x00000102, 0xfeff0101, 0xfffefe01, 0x0000feff,
+	0xf9fe0300, 0x000003ff, 0xfbfd0301, 0x00ff0302,
+	0xfefe0200, 0x00fe0204, 0x00ff01ff, 0x01feff02,
+	0xfcfd0004, 0x010201fe, 0x05030000, 0xfeff0103,
+	0xff010101, 0x0101fffd, 0xfefeff01, 0xfeff0000
 };
 
-// 6x16-entry codebook for intra-coded 8x8 vectors
-static const int8 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
+static const uint32 s_svq1IntraCodebook8x8[1536] = {
+	0x02030404, 0xff000102, 0x02030304, 0xffff0001,
+	0x02020303, 0xfeff0001, 0x01020203, 0xfdfeff00,
+	0x00010202, 0xfdfeffff, 0x00000102, 0xfcfdfeff,
+	0xff000001, 0xfcfcfdfe, 0xfeff0000, 0xfcfcfdfe,
+	0x03030302, 0x03030303, 0x02020202, 0x03030202,
+	0x02020201, 0x02020202, 0x01010100, 0x01010101,
+	0x000000ff, 0x01010000, 0xfffffefe, 0xffffffff,
+	0xfdfdfdfd, 0xfefefdfd, 0xfcfcfcfb, 0xfdfcfcfc,
+	0x00fffefc, 0x03020201, 0x00fffefc, 0x03030201,
+	0x00fffdfc, 0x03030201, 0x00fffdfc, 0x03030201,
+	0x00fffdfb, 0x03030201, 0x00fffdfb, 0x03030201,
+	0x00fffdfb, 0x03020101, 0xfffefdfb, 0x03020100,
+	0x05050404, 0x07070606, 0x03020202, 0x04040403,
+	0x00000000, 0x02010101, 0xfefefefe, 0x00ffffff,
+	0xfefefefe, 0xfefefefe, 0xfefefefe, 0xfefefefe,
+	0xfefefeff, 0xfefefefe, 0xffffffff, 0xfefefefe,
+	0xff010305, 0xfdfdfdfe, 0xff010305, 0xfdfdfdfe,
+	0xff010305, 0xfdfdfdfe, 0xff010305, 0xfdfdfdfe,
+	0x00010405, 0xfdfdfdfe, 0x00020406, 0xfdfdfefe,
+	0x00020406, 0xfdfefeff, 0x01020406, 0xfefefeff,
+	0x030301ff, 0xfafd0002, 0x040301ff, 0xfafd0003,
+	0x040401ff, 0xfafd0103, 0x040301ff, 0xfafd0103,
+	0x040301fe, 0xfafd0103, 0x040301fe, 0xf9fd0103,
+	0x030301fe, 0xf9fd0002, 0x030200fe, 0xfafd0002,
+	0x0608090a, 0x04040506, 0x03040506, 0x01020202,
+	0xff000102, 0xfffefefe, 0xfcfdfeff, 0xfdfcfcfc,
+	0xfcfcfdfe, 0xfdfcfcfb, 0xfdfdfefe, 0xfefefdfd,
+	0xffffffff, 0x00ffffff, 0x01010101, 0x02010101,
+	0x0201fffe, 0x08070504, 0x0100fefd, 0x08070503,
+	0x00fffdfc, 0x07060402, 0xfffefcfb, 0x07050301,
+	0xfefdfbfa, 0x06040200, 0xfefcfbfa, 0x050301ff,
+	0xfdfbfaf9, 0x030200fe, 0xfcfbf9f8, 0x0201fffd,
+	0x0507090b, 0xffff0103, 0x0306080a, 0xfefe0001,
+	0x02050709, 0xfcfdfe00, 0x01030608, 0xfcfcfdff,
+	0xff020406, 0xfbfbfcfd, 0xfe000305, 0xfafafbfc,
+	0xfdff0103, 0xf9f9fafb, 0xfcfe0002, 0xf9f9fafa,
+	0x07070605, 0x08080807, 0x05050403, 0x06060606,
+	0x03020200, 0x05040404, 0x0100fffe, 0x03030202,
+	0xfffefdfc, 0x02010100, 0xfdfcfbfa, 0x00fffefe,
+	0xfafaf9f8, 0xfdfdfcfb, 0xf8f8f7f6, 0xfbfafaf9,
+	0x01030506, 0xf8fafdff, 0x02040506, 0xf8fafdff,
+	0x02040506, 0xf8fafd00, 0x02040506, 0xf8fafd00,
+	0x02040606, 0xf8fafd00, 0x02040506, 0xf8fafd00,
+	0x02040506, 0xf8fafd00, 0x02040506, 0xf8fbfdff,
+	0x08090a0b, 0x04050607, 0x06070808, 0x02030405,
+	0x04040506, 0x00010202, 0x01020303, 0xfeff0000,
+	0xff000101, 0xfdfdfefe, 0xfdfeffff, 0xfbfbfcfc,
+	0xfbfcfcfd, 0xf9f9fafa, 0xf9fafbfb, 0xf8f8f8f8,
+	0xf5f4f3f2, 0xfcfaf9f7, 0xf7f6f5f4, 0xfffdfbf9,
+	0xfaf9f7f6, 0x0200fefd, 0xfefcfaf8, 0x05040200,
+	0x0200fdfb, 0x08070504, 0x040200fe, 0x0a090806,
+	0x07050300, 0x0c0b0a08, 0x08070503, 0x0c0c0b0a,
+	0xeeeeeded, 0xf2f1f0ef, 0xf3f2f1f1, 0xf7f6f5f4,
+	0xf8f7f6f5, 0xfdfcfbfa, 0xfefdfbfa, 0x020100ff,
+	0x030200ff, 0x06060504, 0x08070604, 0x0a0a0a09,
+	0x0c0b0a09, 0x0e0e0e0d, 0x0f0e0e0c, 0x10101010,
+	0x11131516, 0x05090b0e, 0x0e111314, 0x0104080b,
+	0x0a0d0f11, 0xfc000306, 0x05080b0d, 0xf7fbfe01,
+	0xff030609, 0xf3f5f9fc, 0xfafd0004, 0xeff1f4f7,
+	0xf5f8fbfe, 0xeceef0f2, 0xf0f3f6f8, 0xeaebedef,
+	0x12121211, 0x0e101011, 0x0f0f1010, 0x0b0c0d0e,
+	0x0a0b0c0c, 0x05070809, 0x04060607, 0xff010203,
+	0xfeff0001, 0xfafbfcfd, 0xf8f9fafb, 0xf4f5f6f7,
+	0xf2f3f4f5, 0xeff0f0f1, 0xeeefeff0, 0xecececed,
+	0x00000000, 0xfdfeffff, 0x00000001, 0xfdfeff00,
+	0x00000101, 0xfefeffff, 0x00010101, 0xfeffff00,
+	0x01010102, 0xfeffff00, 0x01010202, 0xfeff0000,
+	0x01010202, 0xffff0001, 0x01010202, 0xfe000001,
+	0x00ffff00, 0x03020100, 0x00ffff00, 0x02020101,
+	0xffffffff, 0x02020100, 0xfffeffff, 0x02010100,
+	0xfffefeff, 0x02010000, 0xfefefeff, 0x020100ff,
+	0xfffeffff, 0x02010000, 0xffffffff, 0x02010100,
+	0x02020203, 0x00000101, 0x02020203, 0x00000102,
+	0x01020202, 0x00000101, 0x01010202, 0xff000001,
+	0x00010101, 0xffff0000, 0xffff0000, 0xffffffff,
+	0xfefefefe, 0xfefefefe, 0xfdfdfdfe, 0xfefefefe,
+	0x00000205, 0x000000ff, 0xff000204, 0xff00ffff,
+	0xffff0104, 0xfffffffe, 0xffff0104, 0xfffffffe,
+	0xfeff0104, 0xfffffffe, 0xfeff0104, 0xfffffffe,
+	0xffff0104, 0xffffffff, 0xff000204, 0xff000000,
+	0x0100fffe, 0x01010101, 0x0100fffd, 0x01010101,
+	0x0100fffd, 0x01010101, 0x0100fffd, 0x01010101,
+	0x0100fefd, 0x01010202, 0x0100fefc, 0x02020202,
+	0x01fffdfb, 0x02010201, 0x00fefdfb, 0x01010101,
+	0x00010303, 0xfbfcfcfe, 0x00020303, 0xfcfdfeff,
+	0x01010202, 0xfefeff00, 0x01010101, 0x00000001,
+	0x01000000, 0x01010101, 0x00fffffe, 0x02020100,
+	0xfffefefd, 0x03020100, 0xfffefdfd, 0x03020100,
+	0xfdfdfdfd, 0xfefefefd, 0xfefefdfd, 0xfffffffe,
+	0xfffefefe, 0xffffffff, 0x00ffffff, 0x00000000,
+	0x00000000, 0x01010101, 0x01010000, 0x02020202,
+	0x02010101, 0x03030302, 0x02020202, 0x03030303,
+	0xfdfbf9f8, 0xff00fffe, 0x00fffdfc, 0x01010201,
+	0x030201ff, 0x01020203, 0x03030201, 0x00010202,
+	0x02030302, 0xff000001, 0x00010201, 0xffffffff,
+	0xff000101, 0xfffefeff, 0x00000101, 0xff00ffff,
+	0x00fefdfc, 0x03030201, 0x00fefdfc, 0x02020201,
+	0xfffefdfd, 0x01010100, 0xfffefefe, 0x000000ff,
+	0xffffff00, 0xffffffff, 0x00010102, 0xfeffff00,
+	0x01030303, 0xfefeff00, 0x02040405, 0xfeff0001,
+	0x00000000, 0x03030201, 0x0000ff00, 0x03030201,
+	0x0000ff00, 0x02030201, 0x01000000, 0x02020201,
+	0x01010102, 0x00010101, 0x01020202, 0xfeff0000,
+	0x00000102, 0xfafbfdfe, 0xfdffff00, 0xf7f8fafb,
+	0x020100fe, 0xfcff0102, 0x020200fe, 0xfcff0102,
+	0x020200fe, 0xfdff0102, 0x020200fe, 0xfdff0102,
+	0x0202fffe, 0xfdff0102, 0x0201fffe, 0xfdff0102,
+	0x0201fffd, 0xfdff0102, 0x0201fffe, 0xfdff0102,
+	0xff0101ff, 0x0400fdfd, 0xff0101ff, 0x0400fdfd,
+	0x000101ff, 0x0400fdfd, 0x000201ff, 0x0500fdfd,
+	0x00020100, 0x0400fcfd, 0x00020100, 0x0500fcfd,
+	0x00020100, 0x0400fdfd, 0xff020100, 0x0400fefe,
+	0x06050606, 0x05050505, 0x02020202, 0x02020202,
+	0x00000000, 0x00000000, 0xffffffff, 0xfefefefe,
+	0xfefefefe, 0xfefefefe, 0xfefefefe, 0xfefefefe,
+	0xfffeffff, 0xffffffff, 0xffffffff, 0xffffffff,
+	0x02020202, 0x02020202, 0x00010100, 0x00000000,
+	0xfefefeff, 0xfffefefe, 0xfdfdfdfd, 0xfefdfdfd,
+	0xfdfcfcfd, 0xfefefdfd, 0xfefefefe, 0x0000ffff,
+	0x01010100, 0x03030202, 0x05040403, 0x06060605,
+	0xfdfe0104, 0x0301fffd, 0xfcfe0104, 0x0301fffd,
+	0xfcfe0105, 0x0401fffd, 0xfdfe0105, 0x0402fffd,
+	0xfdfe0105, 0x0402fffd, 0xfcfd0004, 0x0402fffd,
+	0xfdfd0004, 0x0301fffd, 0xfdfe0003, 0x0301fffe,
+	0xfcfcfcfd, 0xfcfcfcfc, 0xffffffff, 0xfefeffff,
+	0x02010102, 0x01010102, 0x04030303, 0x03030304,
+	0x04030303, 0x03030404, 0x02010201, 0x02020202,
+	0xfffefefe, 0x0000ffff, 0xfcfcfcfc, 0xfdfdfdfd,
+	0xfdfdfeff, 0x00fffefe, 0xfefeff00, 0x0100fffe,
+	0xffff0102, 0x0100ffff, 0xff000103, 0x010000ff,
+	0xff000203, 0x01000000, 0xff000103, 0x01000000,
+	0xff000103, 0x01000000, 0x00000102, 0x01000000,
+	0x01000000, 0x04030201, 0x00ff0000, 0x03020000,
+	0xffffff00, 0x0100ffff, 0xffffff00, 0x00ffffff,
+	0xffff0000, 0xfffefeff, 0xff000001, 0xfffefeff,
+	0x00010202, 0xffffffff, 0x01020303, 0x00ffff00,
+	0x00010001, 0xfffeff00, 0x00000000, 0xfffeffff,
+	0x0000ff00, 0xffffffff, 0x00ffffff, 0x00000000,
+	0x00ffffff, 0x01010000, 0x00ffffff, 0x03020101,
+	0x00fffefe, 0x04030201, 0x00fffefe, 0x05040201,
+	0x0001fffd, 0x0100ff00, 0x000100fd, 0x0200ffff,
+	0x000100fd, 0x0200ffff, 0x000201fe, 0x0200ffff,
+	0x000201fe, 0x0200ffff, 0x000201fe, 0x0200ffff,
+	0x000202ff, 0x0200ffff, 0x000101ff, 0x01ffffff,
+	0x01fffefe, 0x01030403, 0x00fffefe, 0x00020302,
+	0x00fffefe, 0xff010201, 0x00ffffff, 0xff010201,
+	0x00ffffff, 0xfe000101, 0x00ffff00, 0xff000101,
+	0x00ffff00, 0xff010101, 0x00ffff00, 0xff000100,
+	0x0100fffe, 0x01010101, 0x0000fffe, 0x00000000,
+	0x00fffffe, 0xfefeffff, 0xfffffffe, 0xfdfefeff,
+	0x010100ff, 0xfefeff00, 0x03030201, 0x00000102,
+	0x03030201, 0x00010203, 0x01010000, 0x00000101,
+	0xffffff00, 0x00000000, 0x00000001, 0x01010000,
+	0x01010101, 0x01010101, 0x02020101, 0x01010101,
+	0x01010101, 0x01010101, 0x010000ff, 0x00000001,
+	0xfffffefd, 0xff00ffff, 0xfdfcfbfb, 0xfffefefe,
+	0x01010101, 0xff000102, 0x02010101, 0xff000101,
+	0x01010101, 0xfe000101, 0x01010102, 0xfe000101,
+	0x00000101, 0xfdff0000, 0x00000101, 0xfdfeff00,
+	0x00000101, 0xfcfeffff, 0xff000001, 0xfcfdfefe,
+	0x03050708, 0x01010102, 0x00000102, 0xfffeffff,
+	0xfeffffff, 0xfffefefe, 0xffffffff, 0x00ffff00,
+	0x01000000, 0x00000001, 0x01010000, 0x00000001,
+	0x000000ff, 0xffff0000, 0xfffffefe, 0xfffefeff,
+	0xfe000409, 0xfffffefe, 0xfeff0207, 0x0000fffe,
+	0xfefe0004, 0x010100ff, 0xfefefe01, 0x010100ff,
+	0xfffefeff, 0x01010100, 0x00fffeff, 0x00010101,
+	0x0100ffff, 0xff000101, 0x0100ff00, 0xffff0000,
+	0x01010100, 0x00000101, 0x02020201, 0x00000001,
+	0x02020202, 0xffff0001, 0x00010101, 0xfefefeff,
+	0xff000000, 0xfefefdfe, 0xfeffffff, 0x00fffefe,
+	0xffffffff, 0x02010000, 0x00ffffff, 0x04030201,
+	0x0000ffff, 0xfdfdfeff, 0x0000ffff, 0xffffff00,
+	0x00fffefe, 0x01010101, 0x00fefefe, 0x03030201,
+	0x00ffffff, 0x03030301, 0x00000001, 0x02020101,
+	0x00010202, 0xffffff00, 0x00010203, 0xfdfdfeff,
+	0xfeffffff, 0xfbfcfdfe, 0xff000000, 0xfcfdfdff,
+	0x00010101, 0xfdfeff00, 0x01020202, 0xffff0001,
+	0x02020202, 0xff000101, 0x02020202, 0x00000102,
+	0x01020101, 0x00000101, 0x01010000, 0xff000000,
+	0x010302fe, 0xff0101ff, 0x000302fd, 0xff0101ff,
+	0x000302fd, 0xff0101ff, 0x000302fc, 0xfe0101ff,
+	0x000301fc, 0xfe0101ff, 0xff0301fc, 0xfe0101fe,
+	0x000201fd, 0xfe0101ff, 0x000201fd, 0xff0101ff,
+	0xfeffffff, 0xfefefefe, 0x01010101, 0x00000000,
+	0x02020201, 0x02020202, 0x01010000, 0x02020201,
+	0xfffffefe, 0x000000ff, 0xfdfdfdfd, 0xfefdfdfd,
+	0xffffffff, 0xfefefefe, 0x04040404, 0x02030304,
+	0xfffefdfd, 0x05020100, 0xfefdfdfd, 0x060301ff,
+	0xfefefdfd, 0x05030200, 0xfefefefd, 0x05030100,
+	0xfffefefe, 0x050301ff, 0xfffffefe, 0x04020100,
+	0xffffffff, 0x04010100, 0xffffffff, 0x03020100,
+	0x0100ff00, 0xffff0001, 0x01000000, 0xffff0002,
+	0x00ff0001, 0x00000001, 0xfffeff01, 0x00000000,
+	0xfffdfe01, 0x01000000, 0xfefdff01, 0x02010100,
+	0xfffeff01, 0x02010100, 0x00ff0002, 0x02020101,
+	0x01010101, 0x02010000, 0xff0000ff, 0x01000000,
+	0xfffffefd, 0x010100ff, 0x00fffefc, 0x01010100,
+	0x0000fefd, 0x01010101, 0x0100fffd, 0x00000101,
+	0x010100ff, 0xff000001, 0x02020100, 0xff000001,
+	0xfdfcfcfc, 0xfffffffe, 0xfffefefe, 0x00000000,
+	0x000000ff, 0x01010101, 0x01010000, 0x01010101,
+	0x01010000, 0x00010202, 0x01010000, 0x00010101,
+	0x01000000, 0x00010101, 0x010000ff, 0x00000101,
+	0x02020201, 0xfcfeff01, 0x02020101, 0xfcfe0001,
+	0x01010100, 0xfdff0001, 0x010100ff, 0xfeff0000,
+	0x010100ff, 0xff000001, 0x0000fffe, 0xff000000,
+	0x0100ffff, 0x00000001, 0x010100ff, 0x00010101,
+	0xff000202, 0xfefffffe, 0xfeff0101, 0xfefffffe,
+	0xfeff0101, 0xff0000fe, 0xfe000101, 0x000101ff,
+	0xff000101, 0x010201ff, 0xff000101, 0x010201ff,
+	0xff000101, 0x010101ff, 0xff000101, 0x01010100,
+	0xfeff0000, 0xfcfcfcfc, 0x02030303, 0x00000001,
+	0x03030303, 0x02020202, 0x00000000, 0x01000000,
+	0xffffffff, 0x00ffffff, 0x0000ff00, 0x000000ff,
+	0x00000000, 0x00000000, 0x00000000, 0x00ffff00,
+	0xff00ffff, 0xff0201ff, 0x00000101, 0xff030200,
+	0xff000101, 0xff0301ff, 0xfe000101, 0xfe0100fe,
+	0xfe000001, 0xfd0100fe, 0x00000000, 0xfd0101ff,
+	0x00010100, 0xfd010201, 0x010100ff, 0xfc010201,
+	0x0100fdfc, 0x00000101, 0x0100fefc, 0xff000101,
+	0x0101fffd, 0xffff0001, 0x010101ff, 0x00ff0001,
+	0x01020201, 0x0000ff00, 0x00010202, 0x0100ffff,
+	0xff000102, 0x0100fffe, 0xff000202, 0x0101fffe,
+	0x00000101, 0xffffffff, 0xffffff00, 0xffffffff,
+	0xffffffff, 0xffffffff, 0xffff0000, 0xffffffff,
+	0xff000001, 0xffffffff, 0x00000102, 0xffffffff,
+	0x01020305, 0x00000000, 0x02030506, 0x00000001,
+	0x01030404, 0x01000000, 0x01020303, 0x01000000,
+	0x00010202, 0x0100ffff, 0xff000000, 0x0100ffff,
+	0xffff0000, 0x0200fffe, 0xfeffff00, 0x0100fefe,
+	0xfeffff00, 0x00fffefe, 0xfeff0000, 0x00fffefe,
+	0xffff0000, 0x030200ff, 0xfefeff00, 0x0201ffff,
+	0xffff0001, 0x000000ff, 0x00010101, 0xffff0000,
+	0x00010201, 0xffffff00, 0x000000ff, 0xffffffff,
+	0xfffffefd, 0x02010100, 0x01fffdfc, 0x05050302,
+	0x00000000, 0x00000000, 0x01010101, 0x01010101,
+	0xff000000, 0x01000000, 0xfefeffff, 0x00fffffe,
+	0x00000000, 0x01010100, 0x02020202, 0x03030302,
+	0x01010101, 0x01010202, 0xfcfcfdfc, 0xfdfdfcfc,
+	0x020100ff, 0x03030302, 0xffffffff, 0x00000000,
+	0xfeff0000, 0xfefdfdfe, 0x00010203, 0xfefefeff,
+	0x01020304, 0x00000001, 0x01010202, 0x01010100,
+	0xffffff00, 0x010000ff, 0xfefefefe, 0x0000fffe,
+	0x0200ff01, 0x01fffe01, 0x0200ff01, 0x01fefe01,
+	0x0300ff01, 0x01fffe02, 0x0300fe00, 0x01fefe02,
+	0x0300fe00, 0x01fefe02, 0x0300fe00, 0x01fffe01,
+	0x0200fe00, 0x01fefe01, 0x0200ff00, 0x01fffe01,
+	0x02020100, 0x02020303, 0x02010100, 0x01020303,
+	0x02010000, 0x01020202, 0x010000ff, 0x01010101,
+	0x0000ffff, 0x00000000, 0xffffffff, 0xffffffff,
+	0xfefefefe, 0xfffefefe, 0xfefefefe, 0xfffefefe,
+	0xfeff0000, 0x050300ff, 0xffff0000, 0x040200ff,
+	0x00000101, 0x0201ffff, 0x01010201, 0x00ffff00,
+	0x01020100, 0xfefeff00, 0x020100ff, 0xfdfd0001,
+	0x0201fffe, 0xfcfe0002, 0x0200fffe, 0xfdff0102,
+	0x00000000, 0xffff0000, 0x00ff0000, 0x00000000,
+	0xffffffff, 0x00000000, 0xffffffff, 0x00ffffff,
+	0xffffffff, 0x00ffffff, 0x000000ff, 0x00ffff00,
+	0x01010000, 0x01000000, 0x04030303, 0x03030303,
+	0xfefe0105, 0xff000000, 0xfffdff04, 0xff000000,
+	0x00ffff03, 0xff000101, 0x01000002, 0xfe000101,
+	0x01000001, 0xfe000101, 0xffffff00, 0xff000000,
+	0xffffff00, 0xff0000ff, 0x00000102, 0x00000100,
+	0x01010001, 0x00000101, 0x01000001, 0x00000001,
+	0x00ffff01, 0x00000000, 0xffff0002, 0x00ffffff,
+	0xffff0103, 0xfffefefe, 0x00010204, 0xfffefeff,
+	0x00000102, 0x0000ffff, 0xffffff00, 0x010100ff,
+	0x02020100, 0xfdff0102, 0x01010000, 0xfeff0001,
+	0x00000000, 0xffff0000, 0x00ff0000, 0x00010100,
+	0x00ff0000, 0x01010101, 0x00000000, 0x00010101,
+	0x01010000, 0xfdff0102, 0x01000000, 0xfbfcff01,
+	0xfffefefe, 0x02020200, 0x00000000, 0x00010101,
+	0x01010101, 0xfdfe0001, 0x01010000, 0xfcfdff00,
+	0x0100ffff, 0xfdfe0000, 0x0100ffff, 0xff000101,
+	0x01000000, 0x00010101, 0x01010101, 0x00000000,
+	0x00000100, 0x02010101, 0x00000201, 0x01ff0000,
+	0xff000200, 0x00ff0001, 0x00000100, 0x01000102,
+	0x00ff0100, 0x01000202, 0xffff00ff, 0x02010102,
+	0xfefdfefe, 0x01010100, 0xfdfdfefe, 0x00ffffff,
+	0x0100fffd, 0x00010102, 0x0100fffd, 0x01010102,
+	0x010000fe, 0x01010101, 0x000000ff, 0x00000000,
+	0x000000fe, 0x00ffff00, 0x000000fe, 0xffff0000,
+	0x010100fd, 0x01000101, 0x0100fefb, 0x02010202,
+	0x00fffffe, 0x03020100, 0x01010000, 0x02010000,
+	0x00010000, 0x0100ffff, 0xffffffff, 0x00fffefe,
+	0xfefefefe, 0x0100fffe, 0xff000000, 0x02020100,
+	0x00000102, 0x02020100, 0xff000102, 0x0000ffff,
+	0x01010100, 0xfcff0101, 0x0100ffff, 0xfd000101,
+	0x0000fffe, 0xfe020201, 0x000000ff, 0xff030200,
+	0x000000ff, 0x00020100, 0xfeff0000, 0x000101ff,
+	0xfeff0000, 0x010200fe, 0xfeff0000, 0x020201ff,
+	0x00000001, 0xfdfefdfe, 0x00010000, 0xfffffefe,
+	0x0101ff00, 0x0000ffff, 0x0101ff00, 0x0000ffff,
+	0x01020100, 0x0100ffff, 0x02030201, 0x02010000,
+	0x010200ff, 0x03020000, 0x0000fffe, 0x020100ff,
+	0xff000101, 0x01fffefe, 0xff010101, 0x0200fefe,
+	0xff010101, 0x0200ffff, 0x00000000, 0x02010000,
+	0x00ffffff, 0x02010000, 0x01fffeff, 0x00000101,
+	0x01fffeff, 0xff000202, 0x02fffeff, 0xff000202,
+	0xfeffffff, 0x0100ffff, 0xffff0000, 0x020100ff,
+	0x00000001, 0x02010100, 0x00000101, 0x01010101,
+	0x01000101, 0x01010001, 0x01010101, 0xffffff00,
+	0x00010201, 0xfdfefeff, 0x00010202, 0xfcfcfdfe,
+	0x0101fefc, 0x00000101, 0x000100fe, 0x00000000,
+	0xfe010100, 0x0100fffe, 0xfe010202, 0x0201fffe,
+	0xfe010201, 0x0201fffe, 0xff0101ff, 0x0100ffff,
+	0x010100fe, 0x00ffff00, 0x020200fe, 0x00ffff01,
+	0x00000101, 0x00000100, 0xfefdfdfe, 0x0000fffe,
+	0xfefdfcfd, 0x000000ff, 0x0100ffff, 0x01020302,
+	0x03020100, 0x01020303, 0x02010101, 0xff000001,
+	0x00000000, 0xffffffff, 0x00ffff00, 0x00000000,
+	0x00000101, 0x0200ffff, 0x00010000, 0x0101ffff,
+	0x0100fffe, 0x01010101, 0x0200fdfd, 0x00010102,
+	0x0100fefe, 0x00000101, 0x00000001, 0xffff0000,
+	0xfdff0103, 0x0100fffe, 0xfdff0204, 0x0201fffd,
+	0xff000000, 0xffffffff, 0x00010201, 0xffff0000,
+	0x02030302, 0xffff0001, 0x02040403, 0xfeff0001,
+	0x01020303, 0xfefeff00, 0xff000101, 0xfdfefeff,
+	0xff000000, 0xfefefeff, 0xffffffff, 0xfffefeff,
+	0x02020201, 0x02020102, 0x01010100, 0x00000001,
+	0x01000000, 0xfeff0001, 0x00000000, 0xfcff0001,
+	0x00000001, 0xfbfe0000, 0x00000001, 0xfcff0000,
+	0x00ff0001, 0xfdff0000, 0x00ffff00, 0xff010101,
+	0x0000fffe, 0xfeffffff, 0x000000ff, 0xfefeffff,
+	0x00010100, 0xfeffffff, 0x00010100, 0xffff0000,
+	0x00000100, 0x00010101, 0x00000101, 0x01020201,
+	0x00000101, 0x01020201, 0xff000101, 0x00010100,
+	0x00010204, 0x01010100, 0x00010204, 0x01000000,
+	0x00000103, 0x00ffffff, 0xff000001, 0x00fffeff,
+	0x00000000, 0x00ffffff, 0x0000ffff, 0x0100ffff,
+	0xff00fffe, 0x010000ff, 0xfefffefe, 0x010000ff,
+	0x01010100, 0xff000102, 0x00ffffff, 0xfefeff00,
+	0x00ff00ff, 0xfffeff00, 0x00000000, 0x02010000,
+	0x00000000, 0x03020000, 0xffff00ff, 0x0300ffff,
+	0xff0000ff, 0x0300feff, 0x00000000, 0x0401ffff,
+	0x00000202, 0x01000000, 0xfeff0101, 0x01fffeff,
+	0xfefeffff, 0x00fefdfe, 0xffff00ff, 0x01fffeff,
+	0x00000101, 0x01000001, 0x00000202, 0x01000001,
+	0x00000202, 0xffff0000, 0x00000202, 0xffff0001,
+	0x010100ff, 0xffffff00, 0x02030201, 0x00000001,
+	0x01010100, 0x0000ff00, 0x00fffefe, 0x00000001,
+	0x02fffefe, 0x00010202, 0x0100fffe, 0xff000001,
+	0x0000ffff, 0xfefffeff, 0x01010100, 0x01010000,
+	0xfefdfdfd, 0xfefeffff, 0x0100ffff, 0x00000102,
+	0x02010101, 0x00000102, 0x01010101, 0x01ff0001,
+	0xffff0001, 0x01ff0000, 0xffffff00, 0x01ffff00,
+	0x00ff0001, 0x0200ff00, 0x00ff0002, 0x02000000,
+	0xfffe0001, 0x00010100, 0xffff0002, 0x00010100,
+	0xfffe0001, 0xff000100, 0xffff0001, 0xff000100,
+	0x00010100, 0x00000101, 0x010201fe, 0x01000000,
+	0x010200fb, 0x0100ff00, 0x0102fffa, 0x0000ff00,
+	0xff000305, 0xfffffffe, 0xff000101, 0xffff00ff,
+	0x010100ff, 0x00010202, 0x0100fffe, 0x01010102,
+	0xfffffffe, 0x0100ff00, 0x00000100, 0x0000ffff,
+	0x01010100, 0x00000001, 0x0100fefd, 0xff000001,
+	0x000100ff, 0x030200ff, 0xfe0000ff, 0x00fffefc,
+	0x00010100, 0xff00fffe, 0x01030201, 0x00010100,
+	0x010100ff, 0x00010101, 0x00fefdfe, 0x00010000,
+	0x00fefeff, 0xff000001, 0x00000103, 0xffff0001,
+	0x0000fffe, 0x0000ffff, 0x000000ff, 0x01010100,
+	0x00ffffff, 0x01010101, 0xfffdfe00, 0x00000001,
+	0xfffdff01, 0xff000101, 0x01ff0103, 0xff000202,
+	0x01000103, 0x00010102, 0xfffefe00, 0x000000ff,
+	0xffff0001, 0x00010201, 0xfffeff00, 0x01020201,
+	0x00ffffff, 0x00020100, 0x000000fe, 0xff010000,
+	0x000100ff, 0xffffffff, 0x02010100, 0x00fffe00,
+	0x02020201, 0x00ffff01, 0x01010100, 0xfffefe00,
+	0xffff0000, 0xfefeffff, 0x00ff0000, 0x01020201,
+	0xffff0000, 0x02020100, 0xfeff0101, 0xffffffff,
+	0x00010202, 0xfefeff00, 0x01020201, 0xfefe0000,
+	0x00000000, 0xff000101, 0xffffff00, 0x01020302,
+	0x0201fe00, 0x010000ff, 0x0302feff, 0x000000ff,
+	0x0302fe00, 0x0000ffff, 0x0203ff00, 0x000100fe,
+	0x0103ff00, 0x000100fe, 0x0102ff00, 0xff0001ff,
+	0xff010000, 0xff0000fe, 0xfe000001, 0xfffffffe,
+	0x01010101, 0xfeffff01, 0x01000000, 0x01010101,
+	0x01000000, 0x03020101, 0xff000001, 0x02010000,
+	0xfeffff00, 0x020100ff, 0xfefefefe, 0x010100ff,
+	0xffffffff, 0xff000000, 0x00020202, 0xfcfeffff,
+	0xfffffeff, 0x03020100, 0xffffffff, 0x03020100,
+	0x00ff0001, 0x020100ff, 0x00000001, 0x020200ff,
+	0xffff0001, 0x020100fe, 0xfefefe00, 0x0100fffd,
+	0xfefefe00, 0x0101fffe, 0x00000000, 0x02020100
 };
 
-// list of codebooks for intra-coded vectors/
-const int8* const svq1_intra_codebooks[6] = {
-    svq1_intra_codebook_4x2, svq1_intra_codebook_4x4,
-    svq1_intra_codebook_8x4, svq1_intra_codebook_8x8,
-    NULL, NULL,
+const uint32 *const s_svq1IntraCodebooks[6] = {
+    s_svq1IntraCodebook4x2, s_svq1IntraCodebook4x4,
+    s_svq1IntraCodebook8x4, s_svq1IntraCodebook8x8,
+    0, 0
 };
 
+} // End of namespace Video
+
 #endif


Commit: 20434032070870f7734141d5d65dae785396e92f
    https://github.com/scummvm/scummvm/commit/20434032070870f7734141d5d65dae785396e92f
Author: D G Turner (digitall at scummvm.org)
Date: 2012-04-07T19:29:35-07:00

Commit Message:
VIDEO: Add Missing Half-Pel Motion Compensation Code to SVQ1 Codec.

Graphics output is now _almost_ correct.

Changed paths:
    video/codecs/svq1.cpp



diff --git a/video/codecs/svq1.cpp b/video/codecs/svq1.cpp
index 22e267e..d246855 100644
--- a/video/codecs/svq1.cpp
+++ b/video/codecs/svq1.cpp
@@ -632,6 +632,92 @@ void SVQ1Decoder::svq1SkipBlock(uint8 *current, uint8 *previous, int pitch, int
 	}
 }
 
+#define AV_RN32(x) ((((const uint8*)(x))[0] << 24) | (((const uint8*)(x))[1] << 16) | (((const uint8*)(x))[2] <<  8) | ((const uint8*)(x))[3])
+
+static void put_pixels8_c(uint8 *block, const uint8 *pixels, int line_size, int h) {
+	for (int i = 0; i < h; i++) {
+		*((uint32*)(block)) = AV_RN32(pixels);
+		*((uint32*)(block + 4)) = AV_RN32(pixels + 4);
+		pixels += line_size;
+		block += line_size;
+	}
+}
+
+static inline uint32 rnd_avg32(uint32 a, uint32 b) {
+	return (a | b) - (((a ^ b) & ~((0x01)*0x01010101UL)) >> 1);
+}
+
+static inline void put_pixels8_l2(uint8 *dst, const uint8 *src1, const uint8 *src2, 
+                                  int dst_stride, int src_stride1, int src_stride2, int h) {
+	for (int i = 0; i < h; i++){
+		uint32 a, b;
+		a= AV_RN32(&src1[i*src_stride1]);
+		b= AV_RN32(&src2[i*src_stride2]);
+		*((uint32*)&dst[i*dst_stride]) = rnd_avg32(a, b);
+		a= AV_RN32(&src1[i*src_stride1 + 4]);
+		b= AV_RN32(&src2[i*src_stride2 + 4]);
+		*((uint32*)&dst[i*dst_stride + 4]) = rnd_avg32(a, b);
+	}
+}
+
+static inline void put_pixels8_x2_c(uint8 *block, const uint8 *pixels, int line_size, int h) {
+	put_pixels8_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);
+}
+
+static inline void put_pixels8_y2_c(uint8 *block, const uint8 *pixels, int line_size, int h) {
+	put_pixels8_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);
+}
+
+static inline void put_pixels8_xy2_c(uint8 *block, const uint8 *pixels, int line_size, int h) {
+	for (int j = 0; j < 2; j++) {
+		uint32 a = AV_RN32(pixels);
+		uint32 b = AV_RN32(pixels+1);
+		uint32 l0 = (a & 0x03030303UL) + (b & 0x03030303UL) + 0x02020202UL;
+		uint32 h0 = ((a & 0xFCFCFCFCUL) >> 2) + ((b & 0xFCFCFCFCUL) >> 2);
+		uint32 l1, h1;
+
+		pixels += line_size;
+		for (int i = 0; i < h; i += 2) {
+			a = AV_RN32(pixels);
+			b = AV_RN32(pixels+1);
+			l1 = (a & 0x03030303UL) + (b & 0x03030303UL);
+			h1 = ((a & 0xFCFCFCFCUL) >> 2) + ((b & 0xFCFCFCFCUL) >> 2);
+			*((uint32*)block) = h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL);
+			pixels += line_size;
+			block += line_size;
+			a = AV_RN32(pixels);
+			b = AV_RN32(pixels+1);
+			l0 = (a & 0x03030303UL) + (b & 0x03030303UL) + 0x02020202UL;
+			h0 = ((a & 0xFCFCFCFCUL) >> 2) + ((b & 0xFCFCFCFCUL) >> 2);
+			*((uint32*)block) = h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL);
+			pixels += line_size;
+			block += line_size;
+		}
+		pixels += 4 - line_size*(h + 1);
+		block += 4 - line_size*h;
+	}
+}
+
+static void put_pixels16_c(uint8 *block, const uint8 *pixels, int line_size, int h) {
+	put_pixels8_c(block, pixels, line_size, h);
+	put_pixels8_c(block+8, pixels+8, line_size, h);
+}
+
+static void put_pixels16_x2_c(uint8 *block, const uint8 *pixels, int line_size, int h) {
+	put_pixels8_x2_c(block, pixels, line_size, h);
+	put_pixels8_x2_c(block+8, pixels+8, line_size, h);
+}
+
+static void put_pixels16_y2_c(uint8 *block, const uint8 *pixels, int line_size, int h) {
+	put_pixels8_y2_c(block, pixels, line_size, h);
+	put_pixels8_y2_c(block+8, pixels+8, line_size, h);
+}
+
+static void put_pixels16_xy2_c(uint8 *block, const uint8 *pixels, int line_size, int h) {
+	put_pixels8_xy2_c(block, pixels, line_size, h);
+	put_pixels8_xy2_c(block+8, pixels+8, line_size, h);
+}
+
 int SVQ1Decoder::svq1MotionInterBlock(Common::BitStream *ss,
                                 uint8 *current, uint8 *previous, int pitch,
                                 Common::Point *motion, int x, int y) {
@@ -677,9 +763,26 @@ int SVQ1Decoder::svq1MotionInterBlock(Common::BitStream *ss,
 	src = &previous[(x + (mv.x >> 1)) + (y + (mv.y >> 1))*pitch];
 	dst = current;
 
-	// FIXME
-	//MpegEncContext *s
-	//s->dsp.put_pixels_tab[0][((mv.y & 1) << 1) | (mv.x & 1)](dst,src,pitch,16);
+	// Halfpel motion compensation with rounding (a+b+1)>>1.
+	// 4 motion compensation functions for the 4 halfpel positions
+	// for 16x16 blocks
+	switch(((mv.y & 1)*2) + (mv.x & 1)) {
+	case 0:
+		put_pixels16_c(dst, src, pitch, 16);
+		break;
+	case 1:
+		put_pixels16_x2_c(dst, src, pitch, 16);
+		break;
+	case 2:
+		put_pixels16_y2_c(dst, src, pitch, 16);
+		break;
+	case 3:
+		put_pixels16_xy2_c(dst, src, pitch, 16);
+		break;
+	default:
+		error("Motion Compensation Function Lookup Error. Should Not Happen!");
+		break;
+	}
 
 	return 0;
 }
@@ -757,9 +860,26 @@ int SVQ1Decoder::svq1MotionInter4vBlock(Common::BitStream *ss,
 		src = &previous[(x + (mvx >> 1)) + (y + (mvy >> 1))*pitch];
 		dst = current;
 
-		// FIXME
-		//MpegEncContext *s
-		//s->dsp.put_pixels_tab[1][((mvy & 1) << 1) | (mvx & 1)](dst,src,pitch,8);
+		// Halfpel motion compensation with rounding (a+b+1)>>1.
+		// 4 motion compensation functions for the 4 halfpel positions
+		// for 8x8 blocks
+		switch(((mvy & 1)*2) + (mvx & 1)) {
+		case 0:
+			put_pixels8_c(dst, src, pitch, 8);
+			break;
+		case 1:
+			put_pixels8_x2_c(dst, src, pitch, 8);
+			break;
+		case 2:
+			put_pixels8_y2_c(dst, src, pitch, 8);
+			break;
+		case 3:
+			put_pixels8_xy2_c(dst, src, pitch, 8);
+			break;
+		default:
+			error("Motion Compensation Function Lookup Error. Should Not Happen!");
+			break;
+		}
 
 		// select next block
 		if (i & 1) {


Commit: 7e0510725656323513bbe4f51f8164f916a52936
    https://github.com/scummvm/scummvm/commit/7e0510725656323513bbe4f51f8164f916a52936
Author: Matthew Hoops (clone2727 at gmail.com)
Date: 2012-04-07T19:29:37-07:00

Commit Message:
VIDEO: Fix endian issue with SVQ1

Changed paths:
    video/codecs/svq1.cpp



diff --git a/video/codecs/svq1.cpp b/video/codecs/svq1.cpp
index d246855..d5baaba 100644
--- a/video/codecs/svq1.cpp
+++ b/video/codecs/svq1.cpp
@@ -632,12 +632,10 @@ void SVQ1Decoder::svq1SkipBlock(uint8 *current, uint8 *previous, int pitch, int
 	}
 }
 
-#define AV_RN32(x) ((((const uint8*)(x))[0] << 24) | (((const uint8*)(x))[1] << 16) | (((const uint8*)(x))[2] <<  8) | ((const uint8*)(x))[3])
-
 static void put_pixels8_c(uint8 *block, const uint8 *pixels, int line_size, int h) {
 	for (int i = 0; i < h; i++) {
-		*((uint32*)(block)) = AV_RN32(pixels);
-		*((uint32*)(block + 4)) = AV_RN32(pixels + 4);
+		*((uint32*)(block)) = READ_UINT32(pixels);
+		*((uint32*)(block + 4)) = READ_UINT32(pixels + 4);
 		pixels += line_size;
 		block += line_size;
 	}
@@ -651,11 +649,11 @@ static inline void put_pixels8_l2(uint8 *dst, const uint8 *src1, const uint8 *sr
                                   int dst_stride, int src_stride1, int src_stride2, int h) {
 	for (int i = 0; i < h; i++){
 		uint32 a, b;
-		a= AV_RN32(&src1[i*src_stride1]);
-		b= AV_RN32(&src2[i*src_stride2]);
+		a= READ_UINT32(&src1[i*src_stride1]);
+		b= READ_UINT32(&src2[i*src_stride2]);
 		*((uint32*)&dst[i*dst_stride]) = rnd_avg32(a, b);
-		a= AV_RN32(&src1[i*src_stride1 + 4]);
-		b= AV_RN32(&src2[i*src_stride2 + 4]);
+		a= READ_UINT32(&src1[i*src_stride1 + 4]);
+		b= READ_UINT32(&src2[i*src_stride2 + 4]);
 		*((uint32*)&dst[i*dst_stride + 4]) = rnd_avg32(a, b);
 	}
 }
@@ -670,23 +668,23 @@ static inline void put_pixels8_y2_c(uint8 *block, const uint8 *pixels, int line_
 
 static inline void put_pixels8_xy2_c(uint8 *block, const uint8 *pixels, int line_size, int h) {
 	for (int j = 0; j < 2; j++) {
-		uint32 a = AV_RN32(pixels);
-		uint32 b = AV_RN32(pixels+1);
+		uint32 a = READ_UINT32(pixels);
+		uint32 b = READ_UINT32(pixels+1);
 		uint32 l0 = (a & 0x03030303UL) + (b & 0x03030303UL) + 0x02020202UL;
 		uint32 h0 = ((a & 0xFCFCFCFCUL) >> 2) + ((b & 0xFCFCFCFCUL) >> 2);
 		uint32 l1, h1;
 
 		pixels += line_size;
 		for (int i = 0; i < h; i += 2) {
-			a = AV_RN32(pixels);
-			b = AV_RN32(pixels+1);
+			a = READ_UINT32(pixels);
+			b = READ_UINT32(pixels+1);
 			l1 = (a & 0x03030303UL) + (b & 0x03030303UL);
 			h1 = ((a & 0xFCFCFCFCUL) >> 2) + ((b & 0xFCFCFCFCUL) >> 2);
 			*((uint32*)block) = h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL);
 			pixels += line_size;
 			block += line_size;
-			a = AV_RN32(pixels);
-			b = AV_RN32(pixels+1);
+			a = READ_UINT32(pixels);
+			b = READ_UINT32(pixels+1);
 			l0 = (a & 0x03030303UL) + (b & 0x03030303UL) + 0x02020202UL;
 			h0 = ((a & 0xFCFCFCFCUL) >> 2) + ((b & 0xFCFCFCFCUL) >> 2);
 			*((uint32*)block) = h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL);


Commit: b0646529d1d36a2bc8113ccc21da0c7efc738288
    https://github.com/scummvm/scummvm/commit/b0646529d1d36a2bc8113ccc21da0c7efc738288
Author: Matthew Hoops (clone2727 at gmail.com)
Date: 2012-04-07T19:29:40-07:00

Commit Message:
VIDEO: Fix segfaults on different sized SVQ1 frames

Changed paths:
    video/codecs/svq1.cpp
    video/codecs/svq1.h



diff --git a/video/codecs/svq1.cpp b/video/codecs/svq1.cpp
index d5baaba..6281722 100644
--- a/video/codecs/svq1.cpp
+++ b/video/codecs/svq1.cpp
@@ -48,8 +48,8 @@ SVQ1Decoder::SVQ1Decoder(uint16 width, uint16 height) {
 	debug(1, "SVQ1Decoder::SVQ1Decoder(width:%d, height:%d)", width, height);
 	_width = width;
 	_height = height;
-	_surface = new Graphics::Surface();
-	_surface->create(width, height, g_system->getScreenFormat());
+	_frameWidth = _frameHeight = 0;
+	_surface = 0;
 
 	_last[0] = 0;
 	_last[1] = 0;
@@ -69,8 +69,10 @@ SVQ1Decoder::SVQ1Decoder(uint16 width, uint16 height) {
 }
 
 SVQ1Decoder::~SVQ1Decoder() {
-	_surface->free();
-	delete _surface;
+	if (_surface) {
+		_surface->free();
+		delete _surface;
+	}
 
 	delete[] _last[0];
 	delete[] _last[1];
@@ -230,19 +232,23 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 
 		byte frameSizeCode = frameData.getBits(3);
 		debug(1, " frameSizeCode: %d", frameSizeCode);
-		uint16 frameWidth, frameHeight;
+
 		if (frameSizeCode == 7) {
-			frameWidth = frameData.getBits(12);
-			frameHeight = frameData.getBits(12);
+			_frameWidth = frameData.getBits(12);
+			_frameHeight = frameData.getBits(12);
 		} else {
-			frameWidth = standardFrameSizes[frameSizeCode].w;
-			frameHeight = standardFrameSizes[frameSizeCode].h;
+			_frameWidth = standardFrameSizes[frameSizeCode].w;
+			_frameHeight = standardFrameSizes[frameSizeCode].h;
 		}
-		debug(1, " frameWidth: %d", frameWidth);
-		debug(1, " frameHeight: %d", frameHeight);
-		if (frameWidth != _width || frameHeight != _height) { // Invalid
-			warning("Invalid Frame Size");
-			return _surface;
+		debug(1, " frameWidth: %d", _frameWidth);
+		debug(1, " frameHeight: %d", _frameHeight);
+
+		// Now we'll create the surface
+		if (!_surface) {
+			_surface = new Graphics::Surface();
+			_surface->create(_frameWidth, _frameHeight, g_system->getScreenFormat());
+			_surface->w = _width;
+			_surface->h = _height;
 		}
 	} else if (frameType == 2) { // B Frame
 		warning("B Frames not supported by SVQ1 decoder");
@@ -285,47 +291,47 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 	byte *current[3];
 	// FIXME - Added extra _width of 16px blocks to stop out of
 	//         range access causing crashes. Need to correct code...
-	current[0] = new byte[_width*_height +(_width*16)];
-	current[1] = new byte[(_width/4)*(_height/4) +(_width/4*16)];
-	current[2] = new byte[(_width/4)*(_height/4) +(_width/4*16)];
+	current[0] = new byte[_frameWidth * _frameHeight + (_frameWidth * 16)];
+	current[1] = new byte[(_frameWidth / 4) * (_frameHeight / 4) + (_frameWidth / 4 * 16)];
+	current[2] = new byte[(_frameWidth / 4) * (_frameHeight / 4) + (_frameWidth / 4 * 16)];
 
 	// Decode Y, U and V component planes
 	for (int i = 0; i < 3; i++) {
 		int linesize, width, height;
 		if (i == 0) {
 			// Y Size is width * height
-			width  = _width;
+			width  = _frameWidth;
 			if (width % 16) {
 				width /= 16;
 				width++;
 				width *= 16;
 			}
 			assert(width % 16 == 0);
-			height = _height;
+			height = _frameHeight;
 			if (height % 16) {
 				height /= 16;
 				height++;
 				height *= 16;
 			}
 			assert(height % 16 == 0);
-			linesize = _width;
+			linesize = _frameWidth;
 		} else {
 			// U and V size is width/4 * height/4
-			width  = _width/4;
+			width  = _frameWidth / 4;
 			if (width % 16) {
 				width /= 16;
 				width++;
 				width *= 16;
 			}
 			assert(width % 16 == 0);
-			height = _height/4;
+			height = _frameHeight / 4;
 			if (height % 16) {
 				height /= 16;
 				height++;
 				height *= 16;
 			}
 			assert(height % 16 == 0);
-			linesize = _width/4;
+			linesize = _frameWidth / 4;
 		}
 
 		if (frameType == 0) { // I Frame
@@ -370,7 +376,7 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 		}
 	}
 
-	convertYUV410ToRGB(_surface, current[0], current[1], current[2], _width, _height, _width, _width/4);
+	convertYUV410ToRGB(_surface, current[0], current[1], current[2], _frameWidth, _frameHeight, _frameWidth, _frameWidth / 4);
 
 	for (int i = 0; i < 3; i++) {
 		delete[] _last[i];
diff --git a/video/codecs/svq1.h b/video/codecs/svq1.h
index ed34439..8442f07 100644
--- a/video/codecs/svq1.h
+++ b/video/codecs/svq1.h
@@ -43,8 +43,8 @@ public:
 
 private:
 	Graphics::Surface *_surface;
-	uint16 _width;
-	uint16 _height;
+	uint16 _width, _height;
+	uint16 _frameWidth, _frameHeight;
 
 	byte *_last[3];
 


Commit: c917db0754f5d459b18c663bb826457147889bfa
    https://github.com/scummvm/scummvm/commit/c917db0754f5d459b18c663bb826457147889bfa
Author: D G Turner (digitall at scummvm.org)
Date: 2012-04-07T19:29:42-07:00

Commit Message:
VIDEO: Change SVQ1 decoder to skip rather than decode embedded string.

This string field is not used and this avoids having to include a
xor table.

Changed paths:
    video/codecs/svq1.cpp



diff --git a/video/codecs/svq1.cpp b/video/codecs/svq1.cpp
index 6281722..72fb299 100644
--- a/video/codecs/svq1.cpp
+++ b/video/codecs/svq1.cpp
@@ -164,53 +164,11 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 				//	value = checksum_table[data[i] ^ (value >> 8)] ^ ((value & 0xFF) << 8);
 		}
 
-		static const uint8 stringXORTable[256] = {
-			0x00, 0xD5, 0x7F, 0xAA, 0xFE, 0x2B, 0x81, 0x54,
-			0x29, 0xFC, 0x56, 0x83, 0xD7, 0x02, 0xA8, 0x7D,
-			0x52, 0x87, 0x2D, 0xF8, 0xAC, 0x79, 0xD3, 0x06,
-			0x7B, 0xAE, 0x04, 0xD1, 0x85, 0x50, 0xFA, 0x2F,
-			0xA4, 0x71, 0xDB, 0x0E, 0x5A, 0x8F, 0x25, 0xF0,
-			0x8D, 0x58, 0xF2, 0x27, 0x73, 0xA6, 0x0C, 0xD9,
-			0xF6, 0x23, 0x89, 0x5C, 0x08, 0xDD, 0x77, 0xA2,
-			0xDF, 0x0A, 0xA0, 0x75, 0x21, 0xF4, 0x5E, 0x8B,
-			0x9D, 0x48, 0xE2, 0x37, 0x63, 0xB6, 0x1C, 0xC9,
-			0xB4, 0x61, 0xCB, 0x1E, 0x4A, 0x9F, 0x35, 0xE0,
-			0xCF, 0x1A, 0xB0, 0x65, 0x31, 0xE4, 0x4E, 0x9B,
-			0xE6, 0x33, 0x99, 0x4C, 0x18, 0xCD, 0x67, 0xB2,
-			0x39, 0xEC, 0x46, 0x93, 0xC7, 0x12, 0xB8, 0x6D,
-			0x10, 0xC5, 0x6F, 0xBA, 0xEE, 0x3B, 0x91, 0x44,
-			0x6B, 0xBE, 0x14, 0xC1, 0x95, 0x40, 0xEA, 0x3F,
-			0x42, 0x97, 0x3D, 0xE8, 0xBC, 0x69, 0xC3, 0x16,
-			0xEF, 0x3A, 0x90, 0x45, 0x11, 0xC4, 0x6E, 0xBB,
-			0xC6, 0x13, 0xB9, 0x6C, 0x38, 0xED, 0x47, 0x92,
-			0xBD, 0x68, 0xC2, 0x17, 0x43, 0x96, 0x3C, 0xE9,
-			0x94, 0x41, 0xEB, 0x3E, 0x6A, 0xBF, 0x15, 0xC0,
-			0x4B, 0x9E, 0x34, 0xE1, 0xB5, 0x60, 0xCA, 0x1F,
-			0x62, 0xB7, 0x1D, 0xC8, 0x9C, 0x49, 0xE3, 0x36,
-			0x19, 0xCC, 0x66, 0xB3, 0xE7, 0x32, 0x98, 0x4D,
-			0x30, 0xE5, 0x4F, 0x9A, 0xCE, 0x1B, 0xB1, 0x64,
-			0x72, 0xA7, 0x0D, 0xD8, 0x8C, 0x59, 0xF3, 0x26,
-			0x5B, 0x8E, 0x24, 0xF1, 0xA5, 0x70, 0xDA, 0x0F,
-			0x20, 0xF5, 0x5F, 0x8A, 0xDE, 0x0B, 0xA1, 0x74,
-			0x09, 0xDC, 0x76, 0xA3, 0xF7, 0x22, 0x88, 0x5D,
-			0xD6, 0x03, 0xA9, 0x7C, 0x28, 0xFD, 0x57, 0x82,
-			0xFF, 0x2A, 0x80, 0x55, 0x01, 0xD4, 0x7E, 0xAB,
-			0x84, 0x51, 0xFB, 0x2E, 0x7A, 0xAF, 0x05, 0xD0,
-			0xAD, 0x78, 0xD2, 0x07, 0x53, 0x86, 0x2C, 0xF9
-		};
-
 		if ((frameCode ^ 0x10) >= 0x50) {
-			// Decode embedded string
-			Common::String str;
+			// Skip embedded string
 			uint8 stringLen = frameData.getBits(8);
-			byte xorVal = stringXORTable[stringLen];
-
-			for (uint16 i = 0; i < stringLen-1; i++) {
-				byte data = frameData.getBits(8);
-				str += data ^ xorVal;
-				xorVal = stringXORTable[data];
-			}
-			debug(1, " Embedded String of %d Characters: \"%s\"", stringLen, str.c_str());
+			for (uint16 i = 0; i < stringLen-1; i++)
+				frameData.skip(8);
 		}
 
 		byte unk1 = frameData.getBits(2); // Unknown


Commit: 95d7c012d6635ac8124d74aeacfb6d52fc2d7ea0
    https://github.com/scummvm/scummvm/commit/95d7c012d6635ac8124d74aeacfb6d52fc2d7ea0
Author: D G Turner (digitall at scummvm.org)
Date: 2012-04-07T19:29:45-07:00

Commit Message:
VIDEO: Minor updates to SVQ1 decoder, mainly return flags to bool.

Since the returned int values from the decoding functions are just
0 for good or -1 for error, have changed these into an errorFlag
bool. This improves readability and cleans up some of the error
checking code. In addition, have fixed some oversights in formatting
spacing for readability.

Changed paths:
    video/codecs/svq1.cpp
    video/codecs/svq1.h



diff --git a/video/codecs/svq1.cpp b/video/codecs/svq1.cpp
index 72fb299..9d2faaa 100644
--- a/video/codecs/svq1.cpp
+++ b/video/codecs/svq1.cpp
@@ -297,8 +297,8 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 			byte *currentP = current[i];
 			for (uint16 y = 0; y < height; y += 16) {
 				for (uint16 x = 0; x < width; x += 16) {
-					if (int result = svq1DecodeBlockIntra(&frameData, &currentP[x], linesize) != 0) {
-						warning("Error in svq1DecodeBlock %i (keyframe)", result);
+					if (svq1DecodeBlockIntra(&frameData, &currentP[x], linesize)) {
+						warning("svq1DecodeBlockIntra decode failure");
 						return _surface;
 					}
 				}
@@ -320,8 +320,8 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 			byte *currentP = current[i];
 			for (uint16 y = 0; y < height; y += 16) {
 				for (uint16 x = 0; x < width; x += 16) {
-					if (int result = svq1DecodeDeltaBlock(&frameData, &currentP[x], previous, linesize, pmv, x, y) != 0) {
-						warning("Error in svq1DecodeDeltaBlock %i", result);
+					if (svq1DecodeDeltaBlock(&frameData, &currentP[x], previous, linesize, pmv, x, y)) {
+						warning("svq1DecodeDeltaBlock decode failure");
 						return _surface;
 					}
 				}
@@ -344,7 +344,7 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 	return _surface;
 }
 
-int SVQ1Decoder::svq1DecodeBlockIntra(Common::BitStream *s, uint8 *pixels, int pitch) {
+bool SVQ1Decoder::svq1DecodeBlockIntra(Common::BitStream *s, uint8 *pixels, int pitch) {
 	uint8 *list[63];
 	uint32 *dst;
 	int entries[6];
@@ -357,7 +357,7 @@ int SVQ1Decoder::svq1DecodeBlockIntra(Common::BitStream *s, uint8 *pixels, int p
 	list[0] = pixels;
 
 	// recursively process vector
-	for (i=0, m=1, n=1, level=5; i < n; i++) {
+	for (i = 0, m = 1, n = 1, level = 5; i < n; i++) {
 		// SVQ1_PROCESS_VECTOR()
 		for (; level > 0; i++) {
 			// process next depth
@@ -383,7 +383,7 @@ int SVQ1Decoder::svq1DecodeBlockIntra(Common::BitStream *s, uint8 *pixels, int p
 		stages = _intraMultistage[level]->getSymbol(*s) - 1;
 
 		if (stages == -1) {
-			for (y=0; y < height; y++) {
+			for (y = 0; y < height; y++) {
 				memset (&dst[y*(pitch / 4)], 0, width);
 			}
 		continue; // skip vector
@@ -391,13 +391,13 @@ int SVQ1Decoder::svq1DecodeBlockIntra(Common::BitStream *s, uint8 *pixels, int p
 
 		if ((stages > 0) && (level >= 4)) {
 			warning("Error (svq1_decode_block_intra): invalid vector: stages=%i level=%i", stages, level);
-		return -1; // invalid vector
+			return true; // error - invalid vector
 		}
 
 		mean = _intraMean->getSymbol(*s);
 
 		if (stages == 0) {
-			for (y=0; y < height; y++) {
+			for (y = 0; y < height; y++) {
 				memset (&dst[y*(pitch / 4)], mean, width);
 			}
 		} else {
@@ -405,15 +405,15 @@ int SVQ1Decoder::svq1DecodeBlockIntra(Common::BitStream *s, uint8 *pixels, int p
 			const uint32 *codebook = s_svq1IntraCodebooks[level];
 			uint32 bit_cache = s->getBits(4*stages);
 			// calculate codebook entries for this vector
-			for (j=0; j < stages; j++) {
+			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);
+			n4 = ((mean + (mean >> 31)) << 16) | (mean & 0xFFFF);
 
 			// SVQ1_DO_CODEBOOK_INTRA()
-			for (y=0; y < height; y++) {
-				for (x=0; x < (width / 4); x++, codebook++) {
+			for (y = 0; y < height; y++) {
+				for (x = 0; x < (width / 4); x++, codebook++) {
 					n1 = n4;
 					n2 = n4;
 					// SVQ1_ADD_CODEBOOK()
@@ -447,10 +447,10 @@ int SVQ1Decoder::svq1DecodeBlockIntra(Common::BitStream *s, uint8 *pixels, int p
 		}
 	}
 
-	return 0;
+	return false;
 }
 
-int SVQ1Decoder::svq1DecodeBlockNonIntra(Common::BitStream *s, uint8 *pixels, int pitch) {
+bool SVQ1Decoder::svq1DecodeBlockNonIntra(Common::BitStream *s, uint8 *pixels, int pitch) {
 	uint8 *list[63];
 	uint32 *dst;
 	int entries[6];
@@ -463,7 +463,7 @@ int SVQ1Decoder::svq1DecodeBlockNonIntra(Common::BitStream *s, uint8 *pixels, in
 	list[0] = pixels;
 
 	// recursively process vector
-	for (i=0, m=1, n=1, level=5; i < n; i++) {
+	for (i = 0, m = 1, n = 1, level = 5; i < n; i++) {
 		// SVQ1_PROCESS_VECTOR()
 		for (; level > 0; i++) {
 			// process next depth
@@ -492,7 +492,7 @@ int SVQ1Decoder::svq1DecodeBlockNonIntra(Common::BitStream *s, uint8 *pixels, in
 
 		if ((stages > 0) && (level >= 4)) {
 			warning("Error (svq1_decode_block_non_intra): invalid vector: stages=%i level=%i", stages, level);
-			return -1;        // invalid vector
+			return true; // error - invalid vector
 		}
 
 		mean = _interMean->getSymbol(*s) - 256;
@@ -508,8 +508,8 @@ int SVQ1Decoder::svq1DecodeBlockNonIntra(Common::BitStream *s, uint8 *pixels, in
 		n4 = ((mean + (mean >> 31)) << 16) | (mean & 0xFFFF);
 
 		// SVQ1_DO_CODEBOOK_NONINTRA()
-		for (y=0; y < height; y++) {
-			for (x=0; x < (width / 4); x++, codebook++) {
+		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;
@@ -543,7 +543,7 @@ int SVQ1Decoder::svq1DecodeBlockNonIntra(Common::BitStream *s, uint8 *pixels, in
 			dst += (pitch / 4);
 		}
 	}
-	return 0;
+	return false;
 }
 
 // median of 3
@@ -562,14 +562,14 @@ static inline int mid_pred(int a, int b, int c) {
 	return b;
 }
 
-int SVQ1Decoder::svq1DecodeMotionVector(Common::BitStream *s, Common::Point *mv, Common::Point **pmv) {
-	for (int i=0; i < 2; i++) {
+bool SVQ1Decoder::svq1DecodeMotionVector(Common::BitStream *s, Common::Point *mv, Common::Point **pmv) {
+	for (int i = 0; i < 2; i++) {
 		// get motion code
 		int diff = _motionComponent->getSymbol(*s);
 		if (diff < 0)
-			return -1;
+			return true; // error - invalid motion code
 		else if (diff) {
-			if (s->getBit()) diff= -diff;
+			if (s->getBit()) diff = -diff;
 		}
 
 		// add median of motion vector predictors and clip result
@@ -579,7 +579,7 @@ int SVQ1Decoder::svq1DecodeMotionVector(Common::BitStream *s, Common::Point *mv,
 			mv->x = ((diff + mid_pred(pmv[0]->x, pmv[1]->x, pmv[2]->x)) << 26) >> 26;
 	}
 
-	return 0;
+	return false;
 }
 
 void SVQ1Decoder::svq1SkipBlock(uint8 *current, uint8 *previous, int pitch, int x, int y) {
@@ -680,14 +680,14 @@ static void put_pixels16_xy2_c(uint8 *block, const uint8 *pixels, int line_size,
 	put_pixels8_xy2_c(block+8, pixels+8, line_size, h);
 }
 
-int SVQ1Decoder::svq1MotionInterBlock(Common::BitStream *ss,
+bool SVQ1Decoder::svq1MotionInterBlock(Common::BitStream *ss,
                                 uint8 *current, uint8 *previous, int pitch,
                                 Common::Point *motion, int x, int y) {
 	uint8 *src;
 	uint8 *dst;
 	Common::Point mv;
 	Common::Point *pmv[3];
-	int result;
+	bool errorFlag;
 
 	// predict and decode motion vector
 	pmv[0] = &motion[0];
@@ -698,27 +698,22 @@ int SVQ1Decoder::svq1MotionInterBlock(Common::BitStream *ss,
 		pmv[2] = &motion[(x / 8) + 4];
 	}
 
-	result = svq1DecodeMotionVector(ss, &mv, pmv);
+	errorFlag = svq1DecodeMotionVector(ss, &mv, pmv);
+	if (errorFlag)
+		return true;
 
-	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;
 
-	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;
-
-	if(y + (mv.y >> 1)<0)
-		mv.y= 0;
-	if(x + (mv.x >> 1)<0)
-		mv.x= 0;
+	if(y + (mv.y >> 1) < 0)
+		mv.y = 0;
+	if(x + (mv.x >> 1) < 0)
+		mv.x = 0;
 
 #if 0
-	int w = (s->width+15)&~15;
-	int h = (s->height+15)&~15;
-	if(x + (mv.x >> 1)<0 || y + (mv.y >> 1)<0 || x + (mv.x >> 1) + 16 > w || y + (mv.y >> 1) + 16> h)
+	int w = (s->width + 15) & ~15;
+	int h = (s->height + 15) & ~15;
+	if(x + (mv.x >> 1) < 0 || y + (mv.y >> 1) < 0 || x + (mv.x >> 1) + 16 > w || y + (mv.y >> 1) + 16 > h)
 		debug(1, "%d %d %d %d", x, y, x + (mv.x >> 1), y + (mv.y >> 1));
 #endif
 
@@ -746,17 +741,17 @@ int SVQ1Decoder::svq1MotionInterBlock(Common::BitStream *ss,
 		break;
 	}
 
-	return 0;
+	return false;
 }
 
-int SVQ1Decoder::svq1MotionInter4vBlock(Common::BitStream *ss,
+bool SVQ1Decoder::svq1MotionInter4vBlock(Common::BitStream *ss,
                                   uint8 *current, uint8 *previous, int pitch,
                                   Common::Point *motion, int x, int y) {
 	uint8 *src;
 	uint8 *dst;
 	Common::Point mv;
 	Common::Point *pmv[4];
-	int i, result;
+	bool errorFlag;
 
 	// predict and decode motion vector (0)
 	pmv[0] = &motion[0];
@@ -767,10 +762,9 @@ int SVQ1Decoder::svq1MotionInter4vBlock(Common::BitStream *ss,
 		pmv[2] = &motion[(x / 8) + 4];
 	}
 
-	result = svq1DecodeMotionVector(ss, &mv, pmv);
-
-	if (result != 0)
-		return result;
+	errorFlag = svq1DecodeMotionVector(ss, &mv, pmv);
+	if (errorFlag)
+		return true;
 
 	// predict and decode motion vector (1)
 	pmv[0] = &mv;
@@ -779,44 +773,42 @@ int SVQ1Decoder::svq1MotionInter4vBlock(Common::BitStream *ss,
 	} else {
 		pmv[1] = &motion[(x / 8) + 3];
 	}
-	result = svq1DecodeMotionVector(ss, &motion[0], pmv);
 
-	if (result != 0)
-		return result;
+	errorFlag = svq1DecodeMotionVector(ss, &motion[0], pmv);
+	if (errorFlag)
+		return true;
 
 	// predict and decode motion vector (2)
 	pmv[1] = &motion[0];
 	pmv[2] = &motion[(x / 8) + 1];
 
-	result = svq1DecodeMotionVector(ss, &motion[(x / 8) + 2], pmv);
-
-	if (result != 0)
-		return result;
+	errorFlag = svq1DecodeMotionVector(ss, &motion[(x / 8) + 2], pmv);
+	if (errorFlag)
+		return true;
 
 	// predict and decode motion vector (3)
 	pmv[2] = &motion[(x / 8) + 2];
 	pmv[3] = &motion[(x / 8) + 3];
 
-	result = svq1DecodeMotionVector(ss, pmv[3], pmv);
-
-	if (result != 0)
-		return result;
+	errorFlag = svq1DecodeMotionVector(ss, pmv[3], pmv);
+	if (errorFlag)
+		return true;
 
 	// form predictions
-	for (i=0; i < 4; i++) {
-		int mvx = pmv[i]->x + (i&1)*16;
-		int mvy = pmv[i]->y + (i>>1)*16;
+	for (int i = 0; i < 4; i++) {
+		int mvx = pmv[i]->x + (i & 1)*16;
+		int mvy = pmv[i]->y + (i >> 1)*16;
 
 		///XXX /FIXME clipping or padding?
-		if(y + (mvy >> 1)<0)
+		if(y + (mvy >> 1) < 0)
 			mvy = 0;
-		if(x + (mvx >> 1)<0)
+		if(x + (mvx >> 1) < 0)
 			mvx = 0;
 
 #if 0
-		int w = (s->width+15)&~15;
-		int h = (s->height+15)&~15;
-		if(x + (mvx >> 1)<0 || y + (mvy >> 1)<0 || x + (mvx >> 1) + 8 > w || y + (mvy >> 1) + 8> h)
+		int w = (s->width + 15) & ~15;
+		int h = (s->height + 15) & ~15;
+		if(x + (mvx >> 1) < 0 || y + (mvy >> 1) < 0 || x + (mvx >> 1) + 8 > w || y + (mvy >> 1) + 8 > h)
 			debug(1, "%d %d %d %d", x, y, x + (mvx >> 1), y + (mvy >> 1));
 #endif
 		src = &previous[(x + (mvx >> 1)) + (y + (mvy >> 1))*pitch];
@@ -851,14 +843,14 @@ int SVQ1Decoder::svq1MotionInter4vBlock(Common::BitStream *ss,
 		}
 	}
 
-	return 0;
+	return false;
 }
 
-int SVQ1Decoder::svq1DecodeDeltaBlock(Common::BitStream *ss,
+bool SVQ1Decoder::svq1DecodeDeltaBlock(Common::BitStream *ss,
                         uint8 *current, uint8 *previous, int pitch,
                         Common::Point *motion, int x, int y) {
 	uint32 block_type;
-	int result = 0;
+	bool errorFlag = false;
 
 	// get block type
 	block_type = _blockType->getSymbol(*ss);
@@ -879,29 +871,29 @@ int SVQ1Decoder::svq1DecodeDeltaBlock(Common::BitStream *ss,
 		break;
 
 	case SVQ1_BLOCK_INTER:
-		result = svq1MotionInterBlock(ss, current, previous, pitch, motion, x, y);
-		if (result != 0) {
-			warning("Error in svq1MotionInterBlock %i", result);
+		errorFlag = svq1MotionInterBlock(ss, current, previous, pitch, motion, x, y);
+		if (errorFlag) {
+			warning("svq1MotionInterBlock decode failure");
 			break;
 		}
-		result = svq1DecodeBlockNonIntra(ss, current, pitch);
+		errorFlag = svq1DecodeBlockNonIntra(ss, current, pitch);
 		break;
 
 	case SVQ1_BLOCK_INTER_4V:
-		result = svq1MotionInter4vBlock(ss, current, previous, pitch, motion, x, y);
-		if (result != 0) {
-			warning("Error in svq1MotionInter4vBlock %i", result);
+		errorFlag = svq1MotionInter4vBlock(ss, current, previous, pitch, motion, x, y);
+		if (errorFlag) {
+			warning("svq1MotionInter4vBlock decode failure");
 			break;
 		}
-		result = svq1DecodeBlockNonIntra(ss, current, pitch);
+		errorFlag = svq1DecodeBlockNonIntra(ss, current, pitch);
 		break;
 
 	case SVQ1_BLOCK_INTRA:
-		result = svq1DecodeBlockIntra(ss, current, pitch);
+		errorFlag = svq1DecodeBlockIntra(ss, current, pitch);
 		break;
 	}
 
-	return result;
+	return errorFlag;
 }
 
 } // End of namespace Video
diff --git a/video/codecs/svq1.h b/video/codecs/svq1.h
index 8442f07..2c35f6c 100644
--- a/video/codecs/svq1.h
+++ b/video/codecs/svq1.h
@@ -55,15 +55,15 @@ private:
 	Common::Huffman *_interMean;
 	Common::Huffman *_motionComponent;
 
-	int svq1DecodeBlockIntra(Common::BitStream *s, uint8 *pixels, int pitch);
-	int svq1DecodeBlockNonIntra(Common::BitStream *s, uint8 *pixels, int pitch);
-	int svq1DecodeMotionVector(Common::BitStream *s, Common::Point *mv, Common::Point **pmv);
+	bool svq1DecodeBlockIntra(Common::BitStream *s, uint8 *pixels, int pitch);
+	bool svq1DecodeBlockNonIntra(Common::BitStream *s, uint8 *pixels, int pitch);
+	bool svq1DecodeMotionVector(Common::BitStream *s, Common::Point *mv, Common::Point **pmv);
 	void svq1SkipBlock(uint8 *current, uint8 *previous, int pitch, int x, int y);
-	int svq1MotionInterBlock(Common::BitStream *ss, uint8 *current, uint8 *previous, int pitch,
+	bool svq1MotionInterBlock(Common::BitStream *ss, uint8 *current, uint8 *previous, int pitch,
 			Common::Point *motion, int x, int y);
-	int svq1MotionInter4vBlock(Common::BitStream *ss, uint8 *current, uint8 *previous, int pitch,
+	bool svq1MotionInter4vBlock(Common::BitStream *ss, uint8 *current, uint8 *previous, int pitch,
 			Common::Point *motion, int x, int y);
-	int svq1DecodeDeltaBlock(Common::BitStream *ss, uint8 *current, uint8 *previous, int pitch,
+	bool svq1DecodeDeltaBlock(Common::BitStream *ss, uint8 *current, uint8 *previous, int pitch,
 			Common::Point *motion, int x, int y);
 };
 


Commit: 8bf8a08048f20ad7a831564aaa384b8bcc1beb24
    https://github.com/scummvm/scummvm/commit/8bf8a08048f20ad7a831564aaa384b8bcc1beb24
Author: Matthew Hoops (clone2727 at gmail.com)
Date: 2012-04-07T19:29:48-07:00

Commit Message:
VIDEO: Fix SVQ1 plane pitch

All the Myst intro videos now decode correctly

Changed paths:
    video/codecs/svq1.cpp



diff --git a/video/codecs/svq1.cpp b/video/codecs/svq1.cpp
index 9d2faaa..3844213 100644
--- a/video/codecs/svq1.cpp
+++ b/video/codecs/svq1.cpp
@@ -89,6 +89,8 @@ SVQ1Decoder::~SVQ1Decoder() {
 	}
 }
 
+#define FFALIGN(x, a) (((x)+(a)-1)&~((a)-1))
+
 const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *stream) {
 	debug(1, "SVQ1Decoder::decodeImage()");
 
@@ -200,14 +202,6 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 		}
 		debug(1, " frameWidth: %d", _frameWidth);
 		debug(1, " frameHeight: %d", _frameHeight);
-
-		// Now we'll create the surface
-		if (!_surface) {
-			_surface = new Graphics::Surface();
-			_surface->create(_frameWidth, _frameHeight, g_system->getScreenFormat());
-			_surface->w = _width;
-			_surface->h = _height;
-		}
 	} else if (frameType == 2) { // B Frame
 		warning("B Frames not supported by SVQ1 decoder");
 		return _surface;
@@ -246,63 +240,37 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 		}
 	}
 
+	int yWidth = FFALIGN(_frameWidth, 16);
+	int yHeight = FFALIGN(_frameHeight, 16);
+	int uvWidth = FFALIGN(yWidth / 4, 16);
+	int uvHeight = FFALIGN(yHeight / 4, 16);
+
 	byte *current[3];
-	// FIXME - Added extra _width of 16px blocks to stop out of
-	//         range access causing crashes. Need to correct code...
-	current[0] = new byte[_frameWidth * _frameHeight + (_frameWidth * 16)];
-	current[1] = new byte[(_frameWidth / 4) * (_frameHeight / 4) + (_frameWidth / 4 * 16)];
-	current[2] = new byte[(_frameWidth / 4) * (_frameHeight / 4) + (_frameWidth / 4 * 16)];
 
 	// Decode Y, U and V component planes
 	for (int i = 0; i < 3; i++) {
-		int linesize, width, height;
+		int width, height;
 		if (i == 0) {
-			// Y Size is width * height
-			width  = _frameWidth;
-			if (width % 16) {
-				width /= 16;
-				width++;
-				width *= 16;
-			}
-			assert(width % 16 == 0);
-			height = _frameHeight;
-			if (height % 16) {
-				height /= 16;
-				height++;
-				height *= 16;
-			}
-			assert(height % 16 == 0);
-			linesize = _frameWidth;
+			width  = yWidth;
+			height = yHeight;
 		} else {
-			// U and V size is width/4 * height/4
-			width  = _frameWidth / 4;
-			if (width % 16) {
-				width /= 16;
-				width++;
-				width *= 16;
-			}
-			assert(width % 16 == 0);
-			height = _frameHeight / 4;
-			if (height % 16) {
-				height /= 16;
-				height++;
-				height *= 16;
-			}
-			assert(height % 16 == 0);
-			linesize = _frameWidth / 4;
+			width  = uvWidth;
+			height = uvHeight;
 		}
 
+		current[i] = new byte[width * height];
+
 		if (frameType == 0) { // I Frame
 			// Keyframe (I)
 			byte *currentP = current[i];
 			for (uint16 y = 0; y < height; y += 16) {
 				for (uint16 x = 0; x < width; x += 16) {
-					if (svq1DecodeBlockIntra(&frameData, &currentP[x], linesize)) {
+					if (svq1DecodeBlockIntra(&frameData, &currentP[x], width)) {
 						warning("svq1DecodeBlockIntra decode failure");
 						return _surface;
 					}
 				}
-				currentP += 16 * linesize;
+				currentP += 16 * width;
 			}
 		} else {
 			// Delta frame (P or B)
@@ -320,7 +288,7 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 			byte *currentP = current[i];
 			for (uint16 y = 0; y < height; y += 16) {
 				for (uint16 x = 0; x < width; x += 16) {
-					if (svq1DecodeDeltaBlock(&frameData, &currentP[x], previous, linesize, pmv, x, y)) {
+					if (svq1DecodeDeltaBlock(&frameData, &currentP[x], previous, width, pmv, x, y)) {
 						warning("svq1DecodeDeltaBlock decode failure");
 						return _surface;
 					}
@@ -328,13 +296,21 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 
 				pmv[0].x = pmv[0].y = 0;
 
-				currentP += 16*linesize;
+				currentP += 16*width;
 			}
 			delete[] pmv;
 		}
 	}
 
-	convertYUV410ToRGB(_surface, current[0], current[1], current[2], _frameWidth, _frameHeight, _frameWidth, _frameWidth / 4);
+	// Now we'll create the surface
+	if (!_surface) {
+		_surface = new Graphics::Surface();
+		_surface->create(yWidth, yHeight, g_system->getScreenFormat());
+		_surface->w = _width;
+		_surface->h = _height;
+	}
+
+	convertYUV410ToRGB(_surface, current[0], current[1], current[2], yWidth, yHeight, yWidth, uvWidth);
 
 	for (int i = 0; i < 3; i++) {
 		delete[] _last[i];


Commit: 7b6c4bb8e1cc7a9ffd79cf4908a0f2e29a684f76
    https://github.com/scummvm/scummvm/commit/7b6c4bb8e1cc7a9ffd79cf4908a0f2e29a684f76
Author: D G Turner (digitall at scummvm.org)
Date: 2012-04-07T19:29:50-07:00

Commit Message:
VIDEO: Minor update to SVQ1 decoder, reversing sense of return flags.

This changes the decoder function return flag meaning from "result
error" to "resultValid". This makes it more consistent with normal
C standard of returning 0 on success.

Changed paths:
    video/codecs/svq1.cpp



diff --git a/video/codecs/svq1.cpp b/video/codecs/svq1.cpp
index 3844213..f1ee337 100644
--- a/video/codecs/svq1.cpp
+++ b/video/codecs/svq1.cpp
@@ -265,7 +265,7 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 			byte *currentP = current[i];
 			for (uint16 y = 0; y < height; y += 16) {
 				for (uint16 x = 0; x < width; x += 16) {
-					if (svq1DecodeBlockIntra(&frameData, &currentP[x], width)) {
+					if (!svq1DecodeBlockIntra(&frameData, &currentP[x], width)) {
 						warning("svq1DecodeBlockIntra decode failure");
 						return _surface;
 					}
@@ -288,7 +288,7 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 			byte *currentP = current[i];
 			for (uint16 y = 0; y < height; y += 16) {
 				for (uint16 x = 0; x < width; x += 16) {
-					if (svq1DecodeDeltaBlock(&frameData, &currentP[x], previous, width, pmv, x, y)) {
+					if (!svq1DecodeDeltaBlock(&frameData, &currentP[x], previous, width, pmv, x, y)) {
 						warning("svq1DecodeDeltaBlock decode failure");
 						return _surface;
 					}
@@ -367,7 +367,7 @@ bool SVQ1Decoder::svq1DecodeBlockIntra(Common::BitStream *s, uint8 *pixels, int
 
 		if ((stages > 0) && (level >= 4)) {
 			warning("Error (svq1_decode_block_intra): invalid vector: stages=%i level=%i", stages, level);
-			return true; // error - invalid vector
+			return false; // error - invalid vector
 		}
 
 		mean = _intraMean->getSymbol(*s);
@@ -423,7 +423,7 @@ bool SVQ1Decoder::svq1DecodeBlockIntra(Common::BitStream *s, uint8 *pixels, int
 		}
 	}
 
-	return false;
+	return true;
 }
 
 bool SVQ1Decoder::svq1DecodeBlockNonIntra(Common::BitStream *s, uint8 *pixels, int pitch) {
@@ -468,7 +468,7 @@ bool SVQ1Decoder::svq1DecodeBlockNonIntra(Common::BitStream *s, uint8 *pixels, i
 
 		if ((stages > 0) && (level >= 4)) {
 			warning("Error (svq1_decode_block_non_intra): invalid vector: stages=%i level=%i", stages, level);
-			return true; // error - invalid vector
+			return false; // error - invalid vector
 		}
 
 		mean = _interMean->getSymbol(*s) - 256;
@@ -519,7 +519,7 @@ bool SVQ1Decoder::svq1DecodeBlockNonIntra(Common::BitStream *s, uint8 *pixels, i
 			dst += (pitch / 4);
 		}
 	}
-	return false;
+	return true;
 }
 
 // median of 3
@@ -543,7 +543,7 @@ bool SVQ1Decoder::svq1DecodeMotionVector(Common::BitStream *s, Common::Point *mv
 		// get motion code
 		int diff = _motionComponent->getSymbol(*s);
 		if (diff < 0)
-			return true; // error - invalid motion code
+			return false; // error - invalid motion code
 		else if (diff) {
 			if (s->getBit()) diff = -diff;
 		}
@@ -555,7 +555,7 @@ bool SVQ1Decoder::svq1DecodeMotionVector(Common::BitStream *s, Common::Point *mv
 			mv->x = ((diff + mid_pred(pmv[0]->x, pmv[1]->x, pmv[2]->x)) << 26) >> 26;
 	}
 
-	return false;
+	return true;
 }
 
 void SVQ1Decoder::svq1SkipBlock(uint8 *current, uint8 *previous, int pitch, int x, int y) {
@@ -663,7 +663,7 @@ bool SVQ1Decoder::svq1MotionInterBlock(Common::BitStream *ss,
 	uint8 *dst;
 	Common::Point mv;
 	Common::Point *pmv[3];
-	bool errorFlag;
+	bool resultValid;
 
 	// predict and decode motion vector
 	pmv[0] = &motion[0];
@@ -674,9 +674,9 @@ bool SVQ1Decoder::svq1MotionInterBlock(Common::BitStream *ss,
 		pmv[2] = &motion[(x / 8) + 4];
 	}
 
-	errorFlag = svq1DecodeMotionVector(ss, &mv, pmv);
-	if (errorFlag)
-		return true;
+	resultValid = svq1DecodeMotionVector(ss, &mv, pmv);
+	if (!resultValid)
+		return false;
 
 	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;
@@ -717,7 +717,7 @@ bool SVQ1Decoder::svq1MotionInterBlock(Common::BitStream *ss,
 		break;
 	}
 
-	return false;
+	return true;
 }
 
 bool SVQ1Decoder::svq1MotionInter4vBlock(Common::BitStream *ss,
@@ -727,7 +727,7 @@ bool SVQ1Decoder::svq1MotionInter4vBlock(Common::BitStream *ss,
 	uint8 *dst;
 	Common::Point mv;
 	Common::Point *pmv[4];
-	bool errorFlag;
+	bool resultValid;
 
 	// predict and decode motion vector (0)
 	pmv[0] = &motion[0];
@@ -738,9 +738,9 @@ bool SVQ1Decoder::svq1MotionInter4vBlock(Common::BitStream *ss,
 		pmv[2] = &motion[(x / 8) + 4];
 	}
 
-	errorFlag = svq1DecodeMotionVector(ss, &mv, pmv);
-	if (errorFlag)
-		return true;
+	resultValid = svq1DecodeMotionVector(ss, &mv, pmv);
+	if (!resultValid)
+		return false;
 
 	// predict and decode motion vector (1)
 	pmv[0] = &mv;
@@ -750,25 +750,25 @@ bool SVQ1Decoder::svq1MotionInter4vBlock(Common::BitStream *ss,
 		pmv[1] = &motion[(x / 8) + 3];
 	}
 
-	errorFlag = svq1DecodeMotionVector(ss, &motion[0], pmv);
-	if (errorFlag)
-		return true;
+	resultValid = svq1DecodeMotionVector(ss, &motion[0], pmv);
+	if (!resultValid)
+		return false;
 
 	// predict and decode motion vector (2)
 	pmv[1] = &motion[0];
 	pmv[2] = &motion[(x / 8) + 1];
 
-	errorFlag = svq1DecodeMotionVector(ss, &motion[(x / 8) + 2], pmv);
-	if (errorFlag)
-		return true;
+	resultValid = svq1DecodeMotionVector(ss, &motion[(x / 8) + 2], pmv);
+	if (!resultValid)
+		return false;
 
 	// predict and decode motion vector (3)
 	pmv[2] = &motion[(x / 8) + 2];
 	pmv[3] = &motion[(x / 8) + 3];
 
-	errorFlag = svq1DecodeMotionVector(ss, pmv[3], pmv);
-	if (errorFlag)
-		return true;
+	resultValid = svq1DecodeMotionVector(ss, pmv[3], pmv);
+	if (!resultValid)
+		return false;
 
 	// form predictions
 	for (int i = 0; i < 4; i++) {
@@ -819,14 +819,14 @@ bool SVQ1Decoder::svq1MotionInter4vBlock(Common::BitStream *ss,
 		}
 	}
 
-	return false;
+	return true;
 }
 
 bool SVQ1Decoder::svq1DecodeDeltaBlock(Common::BitStream *ss,
                         uint8 *current, uint8 *previous, int pitch,
                         Common::Point *motion, int x, int y) {
 	uint32 block_type;
-	bool errorFlag = false;
+	bool resultValid = true;
 
 	// get block type
 	block_type = _blockType->getSymbol(*ss);
@@ -847,29 +847,29 @@ bool SVQ1Decoder::svq1DecodeDeltaBlock(Common::BitStream *ss,
 		break;
 
 	case SVQ1_BLOCK_INTER:
-		errorFlag = svq1MotionInterBlock(ss, current, previous, pitch, motion, x, y);
-		if (errorFlag) {
+		resultValid = svq1MotionInterBlock(ss, current, previous, pitch, motion, x, y);
+		if (!resultValid) {
 			warning("svq1MotionInterBlock decode failure");
 			break;
 		}
-		errorFlag = svq1DecodeBlockNonIntra(ss, current, pitch);
+		resultValid = svq1DecodeBlockNonIntra(ss, current, pitch);
 		break;
 
 	case SVQ1_BLOCK_INTER_4V:
-		errorFlag = svq1MotionInter4vBlock(ss, current, previous, pitch, motion, x, y);
-		if (errorFlag) {
+		resultValid = svq1MotionInter4vBlock(ss, current, previous, pitch, motion, x, y);
+		if (!resultValid) {
 			warning("svq1MotionInter4vBlock decode failure");
 			break;
 		}
-		errorFlag = svq1DecodeBlockNonIntra(ss, current, pitch);
+		resultValid = svq1DecodeBlockNonIntra(ss, current, pitch);
 		break;
 
 	case SVQ1_BLOCK_INTRA:
-		errorFlag = svq1DecodeBlockIntra(ss, current, pitch);
+		resultValid = svq1DecodeBlockIntra(ss, current, pitch);
 		break;
 	}
 
-	return errorFlag;
+	return resultValid;
 }
 
 } // End of namespace Video


Commit: 8e107f8c78e9c17fd908c205c12fbb718f868648
    https://github.com/scummvm/scummvm/commit/8e107f8c78e9c17fd908c205c12fbb718f868648
Author: Matthew Hoops (clone2727 at gmail.com)
Date: 2012-04-07T19:29:53-07:00

Commit Message:
MOHAWK: Enable the SVQ1 intro for Myst ME Mac

Changed paths:
    engines/mohawk/myst_stacks/intro.cpp



diff --git a/engines/mohawk/myst_stacks/intro.cpp b/engines/mohawk/myst_stacks/intro.cpp
index 0af386f..a5f608d 100644
--- a/engines/mohawk/myst_stacks/intro.cpp
+++ b/engines/mohawk/myst_stacks/intro.cpp
@@ -133,14 +133,8 @@ void Intro::introMovies_run() {
 	case 6:
 		_introStep = 7;
 
-		if (!(_vm->getFeatures() & GF_DEMO)) { // The demo doesn't have the intro video
-			if ((_vm->getFeatures() & GF_ME) && _vm->getPlatform() == Common::kPlatformMacintosh)
-				// intro.mov uses Sorenson, introc uses Cinepak. Otherwise, they're the same.
-				// TODO: Switch back to the SVQ version when we support it
-				_vm->_video->playMovie(_vm->wrapMovieFilename("introc", kIntroStack));
-			else
-				_vm->_video->playMovie(_vm->wrapMovieFilename("intro", kIntroStack));
-		}
+		if (!(_vm->getFeatures() & GF_DEMO)) // The demo doesn't have the intro video
+			_vm->_video->playMovie(_vm->wrapMovieFilename("intro", kIntroStack));
 		break;
 	case 7:
 		if (!_vm->_video->isVideoPlaying())


Commit: 744528cb18ef6b79703a77804acf01864aaaf39e
    https://github.com/scummvm/scummvm/commit/744528cb18ef6b79703a77804acf01864aaaf39e
Author: Matthew Hoops (clone2727 at gmail.com)
Date: 2012-04-07T19:29:56-07:00

Commit Message:
VIDEO: Clean up the SVQ1 code

Changed paths:
    video/codecs/svq1.cpp
    video/codecs/svq1.h
    video/codecs/svq1_cb.h
    video/codecs/svq1_vlc.h
    video/qt_decoder.cpp



diff --git a/video/codecs/svq1.cpp b/video/codecs/svq1.cpp
index f1ee337..dc64429 100644
--- a/video/codecs/svq1.cpp
+++ b/video/codecs/svq1.cpp
@@ -21,7 +21,7 @@
  */
 
 // Sorenson Video 1 Codec
-// Based off ffmpeg's SVQ1 decoder (written by Mike Melanson)
+// Based off FFmpeg's SVQ1 decoder (written by Arpi and Nick Kurshev)
 
 #include "video/codecs/svq1.h"
 #include "video/codecs/svq1_cb.h"
@@ -89,7 +89,7 @@ SVQ1Decoder::~SVQ1Decoder() {
 	}
 }
 
-#define FFALIGN(x, a) (((x)+(a)-1)&~((a)-1))
+#define ALIGN(x, a) (((x)+(a)-1)&~((a)-1))
 
 const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *stream) {
 	debug(1, "SVQ1Decoder::decodeImage()");
@@ -104,81 +104,28 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 		return _surface;
 	}
 
-	// swap some header bytes (why?)
-	//if (frameCode != 0x20) {
-	//  uint32 *src = stream;
-	//
-	//  for (i = 4; i < 8; i++) {
-	//    src[i] = ((src[i] << 16) | (src[i] >> 16)) ^ src[7 - i];
-	// }
-	//}
-
-#if 0
-	static const uint16 checksum_table[256] = {
-		0x0000, 0x1021, 0x2042, 0x3063, 0x4084, 0x50A5, 0x60C6, 0x70E7,
-		0x8108, 0x9129, 0xA14A, 0xB16B, 0xC18C, 0xD1AD, 0xE1CE, 0xF1EF,
-		0x1231, 0x0210, 0x3273, 0x2252, 0x52B5, 0x4294, 0x72F7, 0x62D6,
-		0x9339, 0x8318, 0xB37B, 0xA35A, 0xD3BD, 0xC39C, 0xF3FF, 0xE3DE,
-		0x2462, 0x3443, 0x0420, 0x1401, 0x64E6, 0x74C7, 0x44A4, 0x5485,
-		0xA56A, 0xB54B, 0x8528, 0x9509, 0xE5EE, 0xF5CF, 0xC5AC, 0xD58D,
-		0x3653, 0x2672, 0x1611, 0x0630, 0x76D7, 0x66F6, 0x5695, 0x46B4,
-		0xB75B, 0xA77A, 0x9719, 0x8738, 0xF7DF, 0xE7FE, 0xD79D, 0xC7BC,
-		0x48C4, 0x58E5, 0x6886, 0x78A7, 0x0840, 0x1861, 0x2802, 0x3823,
-		0xC9CC, 0xD9ED, 0xE98E, 0xF9AF, 0x8948, 0x9969, 0xA90A, 0xB92B,
-		0x5AF5, 0x4AD4, 0x7AB7, 0x6A96, 0x1A71, 0x0A50, 0x3A33, 0x2A12,
-		0xDBFD, 0xCBDC, 0xFBBF, 0xEB9E, 0x9B79, 0x8B58, 0xBB3B, 0xAB1A,
-		0x6CA6, 0x7C87, 0x4CE4, 0x5CC5, 0x2C22, 0x3C03, 0x0C60, 0x1C41,
-		0xEDAE, 0xFD8F, 0xCDEC, 0xDDCD, 0xAD2A, 0xBD0B, 0x8D68, 0x9D49,
-		0x7E97, 0x6EB6, 0x5ED5, 0x4EF4, 0x3E13, 0x2E32, 0x1E51, 0x0E70,
-		0xFF9F, 0xEFBE, 0xDFDD, 0xCFFC, 0xBF1B, 0xAF3A, 0x9F59, 0x8F78,
-		0x9188, 0x81A9, 0xB1CA, 0xA1EB, 0xD10C, 0xC12D, 0xF14E, 0xE16F,
-		0x1080, 0x00A1, 0x30C2, 0x20E3, 0x5004, 0x4025, 0x7046, 0x6067,
-		0x83B9, 0x9398, 0xA3FB, 0xB3DA, 0xC33D, 0xD31C, 0xE37F, 0xF35E,
-		0x02B1, 0x1290, 0x22F3, 0x32D2, 0x4235, 0x5214, 0x6277, 0x7256,
-		0xB5EA, 0xA5CB, 0x95A8, 0x8589, 0xF56E, 0xE54F, 0xD52C, 0xC50D,
-		0x34E2, 0x24C3, 0x14A0, 0x0481, 0x7466, 0x6447, 0x5424, 0x4405,
-		0xA7DB, 0xB7FA, 0x8799, 0x97B8, 0xE75F, 0xF77E, 0xC71D, 0xD73C,
-		0x26D3, 0x36F2, 0x0691, 0x16B0, 0x6657, 0x7676, 0x4615, 0x5634,
-		0xD94C, 0xC96D, 0xF90E, 0xE92F, 0x99C8, 0x89E9, 0xB98A, 0xA9AB,
-		0x5844, 0x4865, 0x7806, 0x6827, 0x18C0, 0x08E1, 0x3882, 0x28A3,
-		0xCB7D, 0xDB5C, 0xEB3F, 0xFB1E, 0x8BF9, 0x9BD8, 0xABBB, 0xBB9A,
-		0x4A75, 0x5A54, 0x6A37, 0x7A16, 0x0AF1, 0x1AD0, 0x2AB3, 0x3A92,
-		0xFD2E, 0xED0F, 0xDD6C, 0xCD4D, 0xBDAA, 0xAD8B, 0x9DE8, 0x8DC9,
-		0x7C26, 0x6C07, 0x5C64, 0x4C45, 0x3CA2, 0x2C83, 0x1CE0, 0x0CC1,
-		0xEF1F, 0xFF3E, 0xCF5D, 0xDF7C, 0xAF9B, 0xBFBA, 0x8FD9, 0x9FF8,
-		0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0
-	};
-#endif
-
 	byte temporalReference = frameData.getBits(8);
 	debug(1, " temporalReference: %d", temporalReference);
-	const char* types[4] = { "I (Key)", "P (Delta from Previous)", "B (Delta from Next)", "Invalid" };
+	static const char *const types[4] = { "I (Key)", "P (Delta from Previous)", "B (Delta from Next)", "Invalid" };
 	byte frameType = frameData.getBits(2);
 	debug(1, " frameType: %d = %s Frame", frameType, types[frameType]);
+
 	if (frameType == 0) { // I Frame
 		// TODO: Validate checksum if present
 		if (frameCode == 0x50 || frameCode == 0x60) {
 			uint32 checksum = frameData.getBits(16);
 			debug(1, " checksum:0x%02x", checksum);
-			//uint16 calculate_packet_checksum (const uint8 *data, const int length) {
-			//  int value;
-			//for (int i = 0; i < length; i++)
-				//	value = checksum_table[data[i] ^ (value >> 8)] ^ ((value & 0xFF) << 8);
+			// We're currently just ignoring the checksum
 		}
 
 		if ((frameCode ^ 0x10) >= 0x50) {
 			// Skip embedded string
-			uint8 stringLen = frameData.getBits(8);
+			byte stringLen = frameData.getBits(8);
 			for (uint16 i = 0; i < stringLen-1; i++)
 				frameData.skip(8);
 		}
 
-		byte unk1 = frameData.getBits(2); // Unknown
-		debug(1, " unk1: %d", unk1);
-		byte unk2 = frameData.getBits(2); // Unknown
-		debug(1, " unk2: %d", unk2);
-		bool unk3 = frameData.getBit(); // Unknown
-		debug(1, " unk3: %d", unk3);
+		frameData.skip(5); // Unknown
 
 		static const struct { uint w, h; } standardFrameSizes[7] = {
 			{ 160, 120 }, // 0
@@ -200,22 +147,23 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 			_frameWidth = standardFrameSizes[frameSizeCode].w;
 			_frameHeight = standardFrameSizes[frameSizeCode].h;
 		}
+
 		debug(1, " frameWidth: %d", _frameWidth);
 		debug(1, " frameHeight: %d", _frameHeight);
 	} else if (frameType == 2) { // B Frame
-		warning("B Frames not supported by SVQ1 decoder");
+		warning("B Frames not supported by SVQ1 decoder (yet)");
 		return _surface;
 	} else if (frameType == 3) { // Invalid
 		warning("Invalid Frame Type");
 		return _surface;
 	}
 
-	bool checksumPresent = frameData.getBit();
+	bool checksumPresent = frameData.getBit() != 0;
 	debug(1, " checksumPresent: %d", checksumPresent);
 	if (checksumPresent) {
-		bool usePacketChecksum = frameData.getBit();
+		bool usePacketChecksum = frameData.getBit() != 0;
 		debug(1, " usePacketChecksum: %d", usePacketChecksum);
-		bool componentChecksumsAfterImageData = frameData.getBit();
+		bool componentChecksumsAfterImageData = frameData.getBit() != 0;
 		debug(1, " componentChecksumsAfterImageData: %d", componentChecksumsAfterImageData);
 		byte unk4 = frameData.getBits(2);
 		debug(1, " unk4: %d", unk4);
@@ -223,27 +171,19 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 			warning("Invalid Frame Header in SVQ1 Frame Decode");
 	}
 
-	bool unk5 = frameData.getBit();
-	debug(1, " unk5: %d", unk5);
+	// Some more unknown data
+	bool unk5 = frameData.getBit() != 0;
 	if (unk5) {
-		bool unk6 = frameData.getBit();
-		debug(1, " unk6: %d", unk6);
-		byte unk7 = frameData.getBits(4);
-		debug(1, " unk7: %d", unk7);
-		bool unk8 = frameData.getBit();
-		debug(1, " unk8: %d", unk8);
-		byte unk9 = frameData.getBits(2);
-		debug(1, " unk9: %d", unk9);
-		while (frameData.getBit()) {
-			byte unk10 = frameData.getBits(8);
-			debug(1, " unk10: %d", unk10);
-		}
+		frameData.skip(8);
+
+		while (frameData.getBit() != 0)
+			frameData.skip(8);
 	}
 
-	int yWidth = FFALIGN(_frameWidth, 16);
-	int yHeight = FFALIGN(_frameHeight, 16);
-	int uvWidth = FFALIGN(yWidth / 4, 16);
-	int uvHeight = FFALIGN(yHeight / 4, 16);
+	int yWidth = ALIGN(_frameWidth, 16);
+	int yHeight = ALIGN(_frameHeight, 16);
+	int uvWidth = ALIGN(yWidth / 4, 16);
+	int uvHeight = ALIGN(yHeight / 4, 16);
 
 	byte *current[3];
 
@@ -276,14 +216,15 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 			// Delta frame (P or B)
 
 			// Prediction Motion Vector
-			Common::Point *pmv = new Common::Point[(width/8) + 3];
+			Common::Point *pmv = new Common::Point[(width / 8) + 3];
 
 			byte *previous;
-			if(frameType == 2) { // B Frame
+			if (frameType == 2) { // B Frame
 				warning("B Frame not supported currently");
 				//previous = _next[i];
-			} else
+			} else {
 				previous = _last[i];
+			}
 
 			byte *currentP = current[i];
 			for (uint16 y = 0; y < height; y += 16) {
@@ -296,8 +237,9 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 
 				pmv[0].x = pmv[0].y = 0;
 
-				currentP += 16*width;
+				currentP += 16 * width;
 			}
+
 			delete[] pmv;
 		}
 	}
@@ -312,6 +254,7 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 
 	convertYUV410ToRGB(_surface, current[0], current[1], current[2], yWidth, yHeight, yWidth, uvWidth);
 
+	// Store the current surfaces for later and free the old ones
 	for (int i = 0; i < 3; i++) {
 		delete[] _last[i];
 		_last[i] = current[i];
@@ -320,21 +263,13 @@ const Graphics::Surface *SVQ1Decoder::decodeImage(Common::SeekableReadStream *st
 	return _surface;
 }
 
-bool SVQ1Decoder::svq1DecodeBlockIntra(Common::BitStream *s, uint8 *pixels, int pitch) {
-	uint8 *list[63];
-	uint32 *dst;
-	int entries[6];
-	int i, j, m, n;
-	int mean, stages;
-	unsigned int x, y, width, height, level;
-	uint32 n1, n2, n3, n4;
-
+bool SVQ1Decoder::svq1DecodeBlockIntra(Common::BitStream *s, byte *pixels, int pitch) {
 	// initialize list for breadth first processing of vectors
+	byte *list[63];
 	list[0] = pixels;
 
 	// recursively process vector
-	for (i = 0, m = 1, n = 1, level = 5; i < n; i++) {
-		// SVQ1_PROCESS_VECTOR()
+	for (int i = 0, m = 1, n = 1, level = 5; i < n; i++) {
 		for (; level > 0; i++) {
 			// process next depth
 			if (i == m) {
@@ -342,83 +277,86 @@ bool SVQ1Decoder::svq1DecodeBlockIntra(Common::BitStream *s, uint8 *pixels, int
 				if (--level == 0)
 					break;
 			}
+
 			// divide block if next bit set
 			if (s->getBit() == 0)
 				break;
+
 			// add child nodes
 			list[n++] = list[i];
 			list[n++] = list[i] + (((level & 1) ? pitch : 1) << ((level / 2) + 1));
 		}
 
 		// destination address and vector size
-		dst = (uint32 *) list[i];
-		width = 1 << ((4 + level) /2);
-		height = 1 << ((3 + level) /2);
+		uint32 *dst = (uint32 *)list[i];
+		uint width = 1 << ((level + 4) / 2);
+		uint height = 1 << ((level + 3) / 2);
 
 		// get number of stages (-1 skips vector, 0 for mean only)
-		stages = _intraMultistage[level]->getSymbol(*s) - 1;
+		int stages = _intraMultistage[level]->getSymbol(*s) - 1;
 
 		if (stages == -1) {
-			for (y = 0; y < height; y++) {
-				memset (&dst[y*(pitch / 4)], 0, width);
-			}
-		continue; // skip vector
+			for (uint y = 0; y < height; y++)
+				memset(&dst[y * (pitch / 4)], 0, width);
+
+			continue; // skip vector
 		}
 
-		if ((stages > 0) && (level >= 4)) {
-			warning("Error (svq1_decode_block_intra): invalid vector: stages=%i level=%i", stages, level);
+		if (stages > 0 && level >= 4) {
+			warning("Error (svq1_decode_block_intra): invalid vector: stages = %d, level = %d", stages, level);
 			return false; // error - invalid vector
 		}
 
-		mean = _intraMean->getSymbol(*s);
+		int mean = _intraMean->getSymbol(*s);
 
 		if (stages == 0) {
-			for (y = 0; y < height; y++) {
-				memset (&dst[y*(pitch / 4)], mean, width);
-			}
+			for (uint y = 0; y < height; y++)
+				memset(&dst[y * (pitch / 4)], mean, width);
 		} else {
-			// SVQ1_CALC_CODEBOOK_ENTRIES(svq1_intra_codebooks);
 			const uint32 *codebook = s_svq1IntraCodebooks[level];
-			uint32 bit_cache = s->getBits(4*stages);
+			uint32 bitCache = s->getBits(stages * 4);
+
 			// 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);
-
-			// 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()
+			int entries[6];
+			for (int j = 0; j < stages; j++)
+				entries[j] = (((bitCache >> ((stages - j - 1) * 4)) & 0xF) + j * 16) << (level + 1);
+
+			mean -= stages * 128;
+			uint32 n4 = ((mean + (mean >> 31)) << 16) | (mean & 0xFFFF);
+
+			for (uint y = 0; y < height; y++) {
+				for (uint x = 0; x < (width / 4); x++, codebook++) {
+					uint32 n1 = n4;
+					uint32 n2 = n4;
+					uint32 n3;
+
 					// add codebook entries to vector
-					for (j=0; j < stages; j++) {
-						n3  = codebook[entries[j]] ^ 0x80808080;
-						n1 += ((n3 & 0xFF00FF00) >> 8);
-						n2 +=  (n3 & 0x00FF00FF);
+					for (int 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;
+						n3 = (((n1 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;
 						n1 += 0x7F007F00;
 						n1 |= (((~n1 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;
-						n1 &= (n3 & 0x00FF00FF);
+						n1 &= n3 & 0x00FF00FF;
 					}
 
 					if (n2 & 0xFF00FF00) {
-						n3  = ((( n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;
+						n3 = (((n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;
 						n2 += 0x7F007F00;
 						n2 |= (((~n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;
-						n2 &= (n3 & 0x00FF00FF);
+						n2 &= n3 & 0x00FF00FF;
 					}
 
 					// store result
 					dst[x] = (n1 << 8) | n2;
 				}
-				dst += (pitch / 4);
+
+				dst += pitch / 4;
 			}
 		}
 	}
@@ -426,21 +364,13 @@ bool SVQ1Decoder::svq1DecodeBlockIntra(Common::BitStream *s, uint8 *pixels, int
 	return true;
 }
 
-bool SVQ1Decoder::svq1DecodeBlockNonIntra(Common::BitStream *s, uint8 *pixels, int pitch) {
-	uint8 *list[63];
-	uint32 *dst;
-	int entries[6];
-	int i, j, m, n;
-	int mean, stages;
-	int x, y, width, height, level;
-	uint32 n1, n2, n3, n4;
-
+bool SVQ1Decoder::svq1DecodeBlockNonIntra(Common::BitStream *s, byte *pixels, int pitch) {
 	// initialize list for breadth first processing of vectors
+	byte *list[63];
 	list[0] = pixels;
 
 	// recursively process vector
-	for (i = 0, m = 1, n = 1, level = 5; i < n; i++) {
-		// SVQ1_PROCESS_VECTOR()
+	for (int i = 0, m = 1, n = 1, level = 5; i < n; i++) {
 		for (; level > 0; i++) {
 			// process next depth
 			if (i == m) {
@@ -448,93 +378,103 @@ bool SVQ1Decoder::svq1DecodeBlockNonIntra(Common::BitStream *s, uint8 *pixels, i
 				if (--level == 0)
 					break;
 			}
+
 			// divide block if next bit set
 			if (s->getBit() == 0)
 				break;
+
 			// add child nodes
 			list[n++] = list[i];
 			list[n++] = list[i] + (((level & 1) ? pitch : 1) << ((level / 2) + 1));
 		}
 
 		// destination address and vector size
-		dst = (uint32 *) list[i];
-		width = 1 << ((4 + level) /2);
-		height = 1 << ((3 + level) /2);
+		uint32 *dst = (uint32 *)list[i];
+		int width = 1 << ((level + 4) / 2);
+		int height = 1 << ((level + 3) /  2);
 
 		// get number of stages (-1 skips vector, 0 for mean only)
-		stages = _interMultistage[level]->getSymbol(*s) - 1;
+		int stages = _interMultistage[level]->getSymbol(*s) - 1;
 
-		if (stages == -1) continue; // skip vector
+		if (stages == -1)
+			continue; // skip vector
 
-		if ((stages > 0) && (level >= 4)) {
-			warning("Error (svq1_decode_block_non_intra): invalid vector: stages=%i level=%i", stages, level);
+		if (stages > 0 && level >= 4) {
+			warning("Error (svq1_decode_block_non_intra): invalid vector: stages = %d, level = %d", stages, level);
 			return false; // error - invalid vector
 		}
 
-		mean = _interMean->getSymbol(*s) - 256;
-
-		// SVQ1_CALC_CODEBOOK_ENTRIES(svq1_inter_codebooks);
+		int mean = _interMean->getSymbol(*s) - 256;
 		const uint32 *codebook = s_svq1InterCodebooks[level];
-		uint32 bit_cache = s->getBits(4*stages);
+		uint32 bitCache = s->getBits(stages * 4);
+
 		// 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);
+		int entries[6];
+		for (int j = 0; j < stages; j++)
+			entries[j] = (((bitCache >> ((stages - j - 1) * 4)) & 0xF) + j * 16) << (level + 1);
+
+		mean -= stages * 128;
+		uint32 n4 = ((mean + (mean >> 31)) << 16) | (mean & 0xFFFF);
+
+		for (int y = 0; y < height; y++) {
+			for (int x = 0; x < (width / 4); x++, codebook++) {
+				uint32 n3 = dst[x];
 
-		// 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()
+				uint32 n1 = ((n3 & 0xFF00FF00) >> 8) + n4;
+				uint32 n2 = (n3 & 0x00FF00FF) + n4;
+
 				// add codebook entries to vector
-				for (j=0; j < stages; j++) {
-					n3  = codebook[entries[j]] ^ 0x80808080;
-					n1 += ((n3 & 0xFF00FF00) >> 8);
-					n2 +=  (n3 & 0x00FF00FF);
+				for (int 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;
+					n3 = ((( n1 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;
 					n1 += 0x7F007F00;
 					n1 |= (((~n1 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;
-					n1 &= (n3 & 0x00FF00FF);
+					n1 &= n3 & 0x00FF00FF;
 				}
 
 				if (n2 & 0xFF00FF00) {
 					n3  = ((( n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;
 					n2 += 0x7F007F00;
 					n2 |= (((~n2 >> 15) & 0x00010001) | 0x01000100) - 0x00010001;
-					n2 &= (n3 & 0x00FF00FF);
+					n2 &= n3 & 0x00FF00FF;
 				}
 
 				// store result
 				dst[x] = (n1 << 8) | n2;
 			}
-			dst += (pitch / 4);
+
+			dst += pitch / 4;
 		}
 	}
+
 	return true;
 }
 
 // median of 3
-static inline int mid_pred(int a, int b, int c) {
+static inline int midPred(int a, int b, int c) {
 	if (a > b) {
 		if (c > b) {
-			if (c > a) b = a;
-			else b = c;
+			if (c > a)
+				b = a;
+			else
+				b = c;
 		}
 	} else {
 		if (b > c) {
-			if (c > a) b = c;
-			else b = a;
+			if (c > a)
+				b = c;
+			else
+				b = a;
 		}
 	}
+
 	return b;
 }
 
@@ -544,26 +484,22 @@ bool SVQ1Decoder::svq1DecodeMotionVector(Common::BitStream *s, Common::Point *mv
 		int diff = _motionComponent->getSymbol(*s);
 		if (diff < 0)
 			return false; // error - invalid motion code
-		else if (diff) {
-			if (s->getBit()) diff = -diff;
-		}
+		else if (diff && s->getBit() != 0)
+			diff = -diff;
 
 		// add median of motion vector predictors and clip result
 		if (i == 1)
-			mv->y = ((diff + mid_pred(pmv[0]->y, pmv[1]->y, pmv[2]->y)) << 26) >> 26;
+			mv->y = ((diff + midPred(pmv[0]->y, pmv[1]->y, pmv[2]->y)) << 26) >> 26;
 		else
-			mv->x = ((diff + mid_pred(pmv[0]->x, pmv[1]->x, pmv[2]->x)) << 26) >> 26;
+			mv->x = ((diff + midPred(pmv[0]->x, pmv[1]->x, pmv[2]->x)) << 26) >> 26;
 	}
 
 	return true;
 }
 
-void SVQ1Decoder::svq1SkipBlock(uint8 *current, uint8 *previous, int pitch, int x, int y) {
-	uint8 *src;
-	uint8 *dst;
-
-	src = &previous[x + y*pitch];
-	dst = current;
+void SVQ1Decoder::svq1SkipBlock(byte *current, byte *previous, int pitch, int x, int y) {
+	const byte *src = &previous[x + y * pitch];
+	byte *dst = current;
 
 	for (int i = 0; i < 16; i++) {
 		memcpy(dst, src, 16);
@@ -572,100 +508,95 @@ void SVQ1Decoder::svq1SkipBlock(uint8 *current, uint8 *previous, int pitch, int
 	}
 }
 
-static void put_pixels8_c(uint8 *block, const uint8 *pixels, int line_size, int h) {
+void SVQ1Decoder::putPixels8C(byte *block, const byte *pixels, int lineSize, int h) {
 	for (int i = 0; i < h; i++) {
-		*((uint32*)(block)) = READ_UINT32(pixels);
-		*((uint32*)(block + 4)) = READ_UINT32(pixels + 4);
-		pixels += line_size;
-		block += line_size;
+		*((uint32 *)block) = READ_UINT32(pixels);
+		*((uint32 *)(block + 4)) = READ_UINT32(pixels + 4);
+		pixels += lineSize;
+		block += lineSize;
 	}
 }
 
-static inline uint32 rnd_avg32(uint32 a, uint32 b) {
-	return (a | b) - (((a ^ b) & ~((0x01)*0x01010101UL)) >> 1);
+static inline uint32 rndAvg32(uint32 a, uint32 b) {
+	return (a | b) - (((a ^ b) & ~0x01010101) >> 1);
 }
 
-static inline void put_pixels8_l2(uint8 *dst, const uint8 *src1, const uint8 *src2, 
-                                  int dst_stride, int src_stride1, int src_stride2, int h) {
-	for (int i = 0; i < h; i++){
-		uint32 a, b;
-		a= READ_UINT32(&src1[i*src_stride1]);
-		b= READ_UINT32(&src2[i*src_stride2]);
-		*((uint32*)&dst[i*dst_stride]) = rnd_avg32(a, b);
-		a= READ_UINT32(&src1[i*src_stride1 + 4]);
-		b= READ_UINT32(&src2[i*src_stride2 + 4]);
-		*((uint32*)&dst[i*dst_stride + 4]) = rnd_avg32(a, b);
+void SVQ1Decoder::putPixels8L2(byte *dst, const byte *src1, const byte *src2,
+		int dstStride, int srcStride1, int srcStride2, int h) {
+	for (int i = 0; i < h; i++) {
+		uint32 a = READ_UINT32(&src1[srcStride1 * i]);
+		uint32 b = READ_UINT32(&src2[srcStride2 * i]);
+		*((uint32 *)&dst[dstStride * i]) = rndAvg32(a, b);
+		a = READ_UINT32(&src1[srcStride1 * i + 4]);
+		b = READ_UINT32(&src2[srcStride2 * i + 4]);
+		*((uint32 *)&dst[dstStride * i + 4]) = rndAvg32(a, b);
 	}
 }
 
-static inline void put_pixels8_x2_c(uint8 *block, const uint8 *pixels, int line_size, int h) {
-	put_pixels8_l2(block, pixels, pixels+1, line_size, line_size, line_size, h);
+void SVQ1Decoder::putPixels8X2C(byte *block, const byte *pixels, int lineSize, int h) {
+	putPixels8L2(block, pixels, pixels + 1, lineSize, lineSize, lineSize, h);
 }
 
-static inline void put_pixels8_y2_c(uint8 *block, const uint8 *pixels, int line_size, int h) {
-	put_pixels8_l2(block, pixels, pixels+line_size, line_size, line_size, line_size, h);
+void SVQ1Decoder::putPixels8Y2C(byte *block, const byte *pixels, int lineSize, int h) {
+	putPixels8L2(block, pixels, pixels + lineSize, lineSize, lineSize, lineSize, h);
 }
 
-static inline void put_pixels8_xy2_c(uint8 *block, const uint8 *pixels, int line_size, int h) {
+void SVQ1Decoder::putPixels8XY2C(byte *block, const byte *pixels, int lineSize, int h) {
 	for (int j = 0; j < 2; j++) {
 		uint32 a = READ_UINT32(pixels);
-		uint32 b = READ_UINT32(pixels+1);
+		uint32 b = READ_UINT32(pixels + 1);
 		uint32 l0 = (a & 0x03030303UL) + (b & 0x03030303UL) + 0x02020202UL;
 		uint32 h0 = ((a & 0xFCFCFCFCUL) >> 2) + ((b & 0xFCFCFCFCUL) >> 2);
-		uint32 l1, h1;
 
-		pixels += line_size;
+		pixels += lineSize;
+
 		for (int i = 0; i < h; i += 2) {
 			a = READ_UINT32(pixels);
-			b = READ_UINT32(pixels+1);
-			l1 = (a & 0x03030303UL) + (b & 0x03030303UL);
-			h1 = ((a & 0xFCFCFCFCUL) >> 2) + ((b & 0xFCFCFCFCUL) >> 2);
-			*((uint32*)block) = h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL);
-			pixels += line_size;
-			block += line_size;
+			b = READ_UINT32(pixels + 1);
+			uint32 l1 = (a & 0x03030303UL) + (b & 0x03030303UL);
+			uint32 h1 = ((a & 0xFCFCFCFCUL) >> 2) + ((b & 0xFCFCFCFCUL) >> 2);
+			*((uint32 *)block) = h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL);
+			pixels += lineSize;
+			block += lineSize;
 			a = READ_UINT32(pixels);
-			b = READ_UINT32(pixels+1);
+			b = READ_UINT32(pixels + 1);
 			l0 = (a & 0x03030303UL) + (b & 0x03030303UL) + 0x02020202UL;
 			h0 = ((a & 0xFCFCFCFCUL) >> 2) + ((b & 0xFCFCFCFCUL) >> 2);
-			*((uint32*)block) = h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL);
-			pixels += line_size;
-			block += line_size;
+			*((uint32 *)block) = h0 + h1 + (((l0 + l1) >> 2) & 0x0F0F0F0FUL);
+			pixels += lineSize;
+			block += lineSize;
 		}
-		pixels += 4 - line_size*(h + 1);
-		block += 4 - line_size*h;
+
+		pixels += 4 - lineSize * (h + 1);
+		block += 4 - lineSize * h;
 	}
 }
 
-static void put_pixels16_c(uint8 *block, const uint8 *pixels, int line_size, int h) {
-	put_pixels8_c(block, pixels, line_size, h);
-	put_pixels8_c(block+8, pixels+8, line_size, h);
+void SVQ1Decoder::putPixels16C(byte *block, const byte *pixels, int lineSize, int h) {
+	putPixels8C(block, pixels, lineSize, h);
+	putPixels8C(block + 8, pixels + 8, lineSize, h);
 }
 
-static void put_pixels16_x2_c(uint8 *block, const uint8 *pixels, int line_size, int h) {
-	put_pixels8_x2_c(block, pixels, line_size, h);
-	put_pixels8_x2_c(block+8, pixels+8, line_size, h);
+void SVQ1Decoder::putPixels16X2C(byte *block, const byte *pixels, int lineSize, int h) {
+	putPixels8X2C(block, pixels, lineSize, h);
+	putPixels8X2C(block + 8, pixels + 8, lineSize, h);
 }
 
-static void put_pixels16_y2_c(uint8 *block, const uint8 *pixels, int line_size, int h) {
-	put_pixels8_y2_c(block, pixels, line_size, h);
-	put_pixels8_y2_c(block+8, pixels+8, line_size, h);
+void SVQ1Decoder::putPixels16Y2C(byte *block, const byte *pixels, int lineSize, int h) {
+	putPixels8Y2C(block, pixels, lineSize, h);
+	putPixels8Y2C(block + 8, pixels + 8, lineSize, h);
 }
 
-static void put_pixels16_xy2_c(uint8 *block, const uint8 *pixels, int line_size, int h) {
-	put_pixels8_xy2_c(block, pixels, line_size, h);
-	put_pixels8_xy2_c(block+8, pixels+8, line_size, h);
+void SVQ1Decoder::putPixels16XY2C(byte *block, const byte *pixels, int lineSize, int h) {
+	putPixels8XY2C(block, pixels, lineSize, h);
+	putPixels8XY2C(block + 8, pixels + 8, lineSize, h);
 }
 
-bool SVQ1Decoder::svq1MotionInterBlock(Common::BitStream *ss,
-                                uint8 *current, uint8 *previous, int pitch,
-                                Common::Point *motion, int x, int y) {
-	uint8 *src;
-	uint8 *dst;
-	Common::Point mv;
-	Common::Point *pmv[3];
-	bool resultValid;
+bool SVQ1Decoder::svq1MotionInterBlock(Common::BitStream *ss, byte *current, byte *previous, int pitch,
+		Common::Point *motion, int x, int y) {
 
 	// predict and decode motion vector
+	Common::Point *pmv[3];
 	pmv[0] = &motion[0];
 	if (y == 0) {
 		pmv[1] = pmv[2] = pmv[0];
@@ -674,62 +605,48 @@ bool SVQ1Decoder::svq1MotionInterBlock(Common::BitStream *ss,
 		pmv[2] = &motion[(x / 8) + 4];
 	}
 
-	resultValid = svq1DecodeMotionVector(ss, &mv, pmv);
+	Common::Point mv;
+	bool resultValid = svq1DecodeMotionVector(ss, &mv, pmv);
 	if (!resultValid)
 		return false;
 
 	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;
 
-	if(y + (mv.y >> 1) < 0)
+	if (y + (mv.y >> 1) < 0)
 		mv.y = 0;
-	if(x + (mv.x >> 1) < 0)
-		mv.x = 0;
 
-#if 0
-	int w = (s->width + 15) & ~15;
-	int h = (s->height + 15) & ~15;
-	if(x + (mv.x >> 1) < 0 || y + (mv.y >> 1) < 0 || x + (mv.x >> 1) + 16 > w || y + (mv.y >> 1) + 16 > h)
-		debug(1, "%d %d %d %d", x, y, x + (mv.x >> 1), y + (mv.y >> 1));
-#endif
+	if (x + (mv.x >> 1) < 0)
+		mv.x = 0;
 
-	src = &previous[(x + (mv.x >> 1)) + (y + (mv.y >> 1))*pitch];
-	dst = current;
+	const byte *src = &previous[(x + (mv.x >> 1)) + (y + (mv.y >> 1)) * pitch];
+	byte *dst = current;
 
-	// Halfpel motion compensation with rounding (a+b+1)>>1.
+	// Halfpel motion compensation with rounding (a + b + 1) >> 1.
 	// 4 motion compensation functions for the 4 halfpel positions
 	// for 16x16 blocks
-	switch(((mv.y & 1)*2) + (mv.x & 1)) {
+	switch(((mv.y & 1) << 1) + (mv.x & 1)) {
 	case 0:
-		put_pixels16_c(dst, src, pitch, 16);
+		putPixels16C(dst, src, pitch, 16);
 		break;
 	case 1:
-		put_pixels16_x2_c(dst, src, pitch, 16);
+		putPixels16X2C(dst, src, pitch, 16);
 		break;
 	case 2:
-		put_pixels16_y2_c(dst, src, pitch, 16);
+		putPixels16Y2C(dst, src, pitch, 16);
 		break;
 	case 3:
-		put_pixels16_xy2_c(dst, src, pitch, 16);
-		break;
-	default:
-		error("Motion Compensation Function Lookup Error. Should Not Happen!");
+		putPixels16XY2C(dst, src, pitch, 16);
 		break;
 	}
 
 	return true;
 }
 
-bool SVQ1Decoder::svq1MotionInter4vBlock(Common::BitStream *ss,
-                                  uint8 *current, uint8 *previous, int pitch,
-                                  Common::Point *motion, int x, int y) {
-	uint8 *src;
-	uint8 *dst;
-	Common::Point mv;
-	Common::Point *pmv[4];
-	bool resultValid;
-
+bool SVQ1Decoder::svq1MotionInter4vBlock(Common::BitStream *ss, byte *current, byte *previous, int pitch,
+		Common::Point *motion, int x, int y) {
 	// predict and decode motion vector (0)
+	Common::Point *pmv[4];
 	pmv[0] = &motion[0];
 	if (y == 0) {
 		pmv[1] = pmv[2] = pmv[0];
@@ -738,17 +655,17 @@ bool SVQ1Decoder::svq1MotionInter4vBlock(Common::BitStream *ss,
 		pmv[2] = &motion[(x / 8) + 4];
 	}
 
-	resultValid = svq1DecodeMotionVector(ss, &mv, pmv);
+	Common::Point mv;
+	bool resultValid = svq1DecodeMotionVector(ss, &mv, pmv);
 	if (!resultValid)
 		return false;
 
 	// predict and decode motion vector (1)
 	pmv[0] = &mv;
-	if (y == 0) {
+	if (y == 0)
 		pmv[1] = pmv[2] = pmv[0];
-	} else {
+	else
 		pmv[1] = &motion[(x / 8) + 3];
-	}
 
 	resultValid = svq1DecodeMotionVector(ss, &motion[0], pmv);
 	if (!resultValid)
@@ -772,80 +689,68 @@ bool SVQ1Decoder::svq1MotionInter4vBlock(Common::BitStream *ss,
 
 	// form predictions
 	for (int i = 0; i < 4; i++) {
-		int mvx = pmv[i]->x + (i & 1)*16;
-		int mvy = pmv[i]->y + (i >> 1)*16;
+		int mvx = pmv[i]->x + (i & 1) * 16;
+		int mvy = pmv[i]->y + (i >> 1) * 16;
 
-		///XXX /FIXME clipping or padding?
-		if(y + (mvy >> 1) < 0)
+		// FIXME: clipping or padding?
+		if (y + (mvy >> 1) < 0)
 			mvy = 0;
-		if(x + (mvx >> 1) < 0)
+
+		if (x + (mvx >> 1) < 0)
 			mvx = 0;
 
-#if 0
-		int w = (s->width + 15) & ~15;
-		int h = (s->height + 15) & ~15;
-		if(x + (mvx >> 1) < 0 || y + (mvy >> 1) < 0 || x + (mvx >> 1) + 8 > w || y + (mvy >> 1) + 8 > h)
-			debug(1, "%d %d %d %d", x, y, x + (mvx >> 1), y + (mvy >> 1));
-#endif
-		src = &previous[(x + (mvx >> 1)) + (y + (mvy >> 1))*pitch];
-		dst = current;
+		const byte *src = &previous[(x + (mvx >> 1)) + (y + (mvy >> 1)) * pitch];
+		byte *dst = current;
 
-		// Halfpel motion compensation with rounding (a+b+1)>>1.
+		// Halfpel motion compensation with rounding (a + b + 1) >> 1.
 		// 4 motion compensation functions for the 4 halfpel positions
 		// for 8x8 blocks
-		switch(((mvy & 1)*2) + (mvx & 1)) {
+		switch(((mvy & 1) << 1) + (mvx & 1)) {
 		case 0:
-			put_pixels8_c(dst, src, pitch, 8);
+			putPixels8C(dst, src, pitch, 8);
 			break;
 		case 1:
-			put_pixels8_x2_c(dst, src, pitch, 8);
+			putPixels8X2C(dst, src, pitch, 8);
 			break;
 		case 2:
-			put_pixels8_y2_c(dst, src, pitch, 8);
+			putPixels8Y2C(dst, src, pitch, 8);
 			break;
 		case 3:
-			put_pixels8_xy2_c(dst, src, pitch, 8);
-			break;
-		default:
-			error("Motion Compensation Function Lookup Error. Should Not Happen!");
+			putPixels8XY2C(dst, src, pitch, 8);
 			break;
 		}
 
 		// select next block
-		if (i & 1) {
-			current  += 8*(pitch - 1);
-		} else {
-			current  += 8;
-		}
+		if (i & 1)
+			current += (pitch - 1) * 8;
+		else
+			current += 8;
 	}
 
 	return true;
 }
 
-bool SVQ1Decoder::svq1DecodeDeltaBlock(Common::BitStream *ss,
-                        uint8 *current, uint8 *previous, int pitch,
-                        Common::Point *motion, int x, int y) {
-	uint32 block_type;
-	bool resultValid = true;
-
+bool SVQ1Decoder::svq1DecodeDeltaBlock(Common::BitStream *ss, byte *current, byte *previous, int pitch,
+		Common::Point *motion, int x, int y) {
 	// get block type
-	block_type = _blockType->getSymbol(*ss);
+	uint32 blockType = _blockType->getSymbol(*ss);
 
 	// reset motion vectors
-	if (block_type == SVQ1_BLOCK_SKIP || block_type == SVQ1_BLOCK_INTRA) {
-		motion[0].x                 =
-		motion[0].y                 =
+	if (blockType == SVQ1_BLOCK_SKIP || blockType == 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) {
+	bool resultValid = true;
+
+	switch (blockType) {
 	case SVQ1_BLOCK_SKIP:
 		svq1SkipBlock(current, previous, pitch, x, y);
 		break;
-
 	case SVQ1_BLOCK_INTER:
 		resultValid = svq1MotionInterBlock(ss, current, previous, pitch, motion, x, y);
 		if (!resultValid) {
@@ -854,7 +759,6 @@ bool SVQ1Decoder::svq1DecodeDeltaBlock(Common::BitStream *ss,
 		}
 		resultValid = svq1DecodeBlockNonIntra(ss, current, pitch);
 		break;
-
 	case SVQ1_BLOCK_INTER_4V:
 		resultValid = svq1MotionInter4vBlock(ss, current, previous, pitch, motion, x, y);
 		if (!resultValid) {
@@ -863,7 +767,6 @@ bool SVQ1Decoder::svq1DecodeDeltaBlock(Common::BitStream *ss,
 		}
 		resultValid = svq1DecodeBlockNonIntra(ss, current, pitch);
 		break;
-
 	case SVQ1_BLOCK_INTRA:
 		resultValid = svq1DecodeBlockIntra(ss, current, pitch);
 		break;
diff --git a/video/codecs/svq1.h b/video/codecs/svq1.h
index 2c35f6c..df22d4b 100644
--- a/video/codecs/svq1.h
+++ b/video/codecs/svq1.h
@@ -55,16 +55,26 @@ private:
 	Common::Huffman *_interMean;
 	Common::Huffman *_motionComponent;
 
-	bool svq1DecodeBlockIntra(Common::BitStream *s, uint8 *pixels, int pitch);
-	bool svq1DecodeBlockNonIntra(Common::BitStream *s, uint8 *pixels, int pitch);
+	bool svq1DecodeBlockIntra(Common::BitStream *s, byte *pixels, int pitch);
+	bool svq1DecodeBlockNonIntra(Common::BitStream *s, byte *pixels, int pitch);
 	bool svq1DecodeMotionVector(Common::BitStream *s, Common::Point *mv, Common::Point **pmv);
-	void svq1SkipBlock(uint8 *current, uint8 *previous, int pitch, int x, int y);
-	bool svq1MotionInterBlock(Common::BitStream *ss, uint8 *current, uint8 *previous, int pitch,
+	void svq1SkipBlock(byte *current, byte *previous, int pitch, int x, int y);
+	bool svq1MotionInterBlock(Common::BitStream *ss, byte *current, byte *previous, int pitch,
 			Common::Point *motion, int x, int y);
-	bool svq1MotionInter4vBlock(Common::BitStream *ss, uint8 *current, uint8 *previous, int pitch,
+	bool svq1MotionInter4vBlock(Common::BitStream *ss, byte *current, byte *previous, int pitch,
 			Common::Point *motion, int x, int y);
-	bool svq1DecodeDeltaBlock(Common::BitStream *ss, uint8 *current, uint8 *previous, int pitch,
+	bool svq1DecodeDeltaBlock(Common::BitStream *ss, byte *current, byte *previous, int pitch,
 			Common::Point *motion, int x, int y);
+
+	void putPixels8C(byte *block, const byte *pixels, int lineSize, int h);
+	void putPixels8L2(byte *dst, const byte *src1, const byte *src2, int dstStride, int srcStride1, int srcStride2, int h);
+	void putPixels8X2C(byte *block, const byte *pixels, int lineSize, int h);
+	void putPixels8Y2C(byte *block, const byte *pixels, int lineSize, int h);
+	void putPixels8XY2C(byte *block, const byte *pixels, int lineSize, int h);
+	void putPixels16C(byte *block, const byte *pixels, int lineSize, int h);
+	void putPixels16X2C(byte *block, const byte *pixels, int lineSize, int h);
+	void putPixels16Y2C(byte *block, const byte *pixels, int lineSize, int h);
+	void putPixels16XY2C(byte *block, const byte *pixels, int lineSize, int h);
 };
 
 } // End of namespace Video
diff --git a/video/codecs/svq1_cb.h b/video/codecs/svq1_cb.h
index f764de0..f9a8c54 100644
--- a/video/codecs/svq1_cb.h
+++ b/video/codecs/svq1_cb.h
@@ -20,6 +20,9 @@
  *
  */
 
+// These tables are modified from their FFmpeg counterparts so that
+// they work on both little and big endian systems.
+
 #ifndef VIDEO_CODECS_SVQ1_CB_H
 #define VIDEO_CODECS_SVQ1_CB_H
 
diff --git a/video/codecs/svq1_vlc.h b/video/codecs/svq1_vlc.h
index eb70eb5..5fb1098 100644
--- a/video/codecs/svq1_vlc.h
+++ b/video/codecs/svq1_vlc.h
@@ -20,6 +20,9 @@
  *
  */
 
+// These tables are modified versions of the FFmpeg ones so that they
+// will work with our BitStream class directly.
+
 #ifndef VIDEO_CODECS_SVQ1_VLC_H
 #define VIDEO_CODECS_SVQ1_VLC_H
 
diff --git a/video/qt_decoder.cpp b/video/qt_decoder.cpp
index 52e1806..df83961 100644
--- a/video/qt_decoder.cpp
+++ b/video/qt_decoder.cpp
@@ -46,9 +46,8 @@
 #include "video/codecs/qtrle.h"
 #include "video/codecs/rpza.h"
 #include "video/codecs/smc.h"
-#include "video/codecs/svq1.h"
 #include "video/codecs/cdtoons.h"
-
+#include "video/codecs/svq1.h"
 
 namespace Video {
 






More information about the Scummvm-git-logs mailing list