summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Changelog1
-rwxr-xr-xconfigure1
-rw-r--r--doc/general.texi4
-rw-r--r--libavcodec/Makefile1
-rw-r--r--libavcodec/allcodecs.c1
-rw-r--r--libavcodec/vp9.c3576
-rw-r--r--libavcodec/vp9.h72
-rw-r--r--libavcodec/vp9data.h2153
-rw-r--r--libavcodec/vp9dsp.c2047
-rw-r--r--libavcodec/vp9dsp.h115
-rw-r--r--tests/fate/vpx.mak30
-rw-r--r--tests/ref/fate/vp9-00-quantizer-003
-rw-r--r--tests/ref/fate/vp9-00-quantizer-013
-rw-r--r--tests/ref/fate/vp9-00-quantizer-023
-rw-r--r--tests/ref/fate/vp9-00-quantizer-033
-rw-r--r--tests/ref/fate/vp9-00-quantizer-043
-rw-r--r--tests/ref/fate/vp9-00-quantizer-053
-rw-r--r--tests/ref/fate/vp9-00-quantizer-063
-rw-r--r--tests/ref/fate/vp9-00-quantizer-073
-rw-r--r--tests/ref/fate/vp9-00-quantizer-083
-rw-r--r--tests/ref/fate/vp9-00-quantizer-093
-rw-r--r--tests/ref/fate/vp9-00-quantizer-103
-rw-r--r--tests/ref/fate/vp9-00-quantizer-113
-rw-r--r--tests/ref/fate/vp9-00-quantizer-123
-rw-r--r--tests/ref/fate/vp9-00-quantizer-133
-rw-r--r--tests/ref/fate/vp9-00-quantizer-143
-rw-r--r--tests/ref/fate/vp9-00-quantizer-153
-rw-r--r--tests/ref/fate/vp9-00-quantizer-163
-rw-r--r--tests/ref/fate/vp9-00-quantizer-173
-rw-r--r--tests/ref/fate/vp9-00-quantizer-183
-rw-r--r--tests/ref/fate/vp9-00-quantizer-193
-rw-r--r--tests/ref/fate/vp9-00-quantizer-203
-rw-r--r--tests/ref/fate/vp9-00-quantizer-213
-rw-r--r--tests/ref/fate/vp9-00-quantizer-223
-rw-r--r--tests/ref/fate/vp9-00-quantizer-233
-rw-r--r--tests/ref/fate/vp9-00-quantizer-243
-rw-r--r--tests/ref/fate/vp9-00-quantizer-253
-rw-r--r--tests/ref/fate/vp9-00-quantizer-263
-rw-r--r--tests/ref/fate/vp9-00-quantizer-273
-rw-r--r--tests/ref/fate/vp9-00-quantizer-283
-rw-r--r--tests/ref/fate/vp9-00-quantizer-293
-rw-r--r--tests/ref/fate/vp9-00-quantizer-303
-rw-r--r--tests/ref/fate/vp9-00-quantizer-313
-rw-r--r--tests/ref/fate/vp9-00-quantizer-323
-rw-r--r--tests/ref/fate/vp9-00-quantizer-333
-rw-r--r--tests/ref/fate/vp9-00-quantizer-343
-rw-r--r--tests/ref/fate/vp9-00-quantizer-353
-rw-r--r--tests/ref/fate/vp9-00-quantizer-363
-rw-r--r--tests/ref/fate/vp9-00-quantizer-373
-rw-r--r--tests/ref/fate/vp9-00-quantizer-383
-rw-r--r--tests/ref/fate/vp9-00-quantizer-393
-rw-r--r--tests/ref/fate/vp9-00-quantizer-403
-rw-r--r--tests/ref/fate/vp9-00-quantizer-413
-rw-r--r--tests/ref/fate/vp9-00-quantizer-423
-rw-r--r--tests/ref/fate/vp9-00-quantizer-433
-rw-r--r--tests/ref/fate/vp9-00-quantizer-443
-rw-r--r--tests/ref/fate/vp9-00-quantizer-453
-rw-r--r--tests/ref/fate/vp9-00-quantizer-463
-rw-r--r--tests/ref/fate/vp9-00-quantizer-473
-rw-r--r--tests/ref/fate/vp9-00-quantizer-483
-rw-r--r--tests/ref/fate/vp9-00-quantizer-493
-rw-r--r--tests/ref/fate/vp9-00-quantizer-503
-rw-r--r--tests/ref/fate/vp9-00-quantizer-513
-rw-r--r--tests/ref/fate/vp9-00-quantizer-523
-rw-r--r--tests/ref/fate/vp9-00-quantizer-533
-rw-r--r--tests/ref/fate/vp9-00-quantizer-543
-rw-r--r--tests/ref/fate/vp9-00-quantizer-553
-rw-r--r--tests/ref/fate/vp9-00-quantizer-563
-rw-r--r--tests/ref/fate/vp9-00-quantizer-573
-rw-r--r--tests/ref/fate/vp9-00-quantizer-583
-rw-r--r--tests/ref/fate/vp9-00-quantizer-593
-rw-r--r--tests/ref/fate/vp9-00-quantizer-603
-rw-r--r--tests/ref/fate/vp9-00-quantizer-613
-rw-r--r--tests/ref/fate/vp9-00-quantizer-623
-rw-r--r--tests/ref/fate/vp9-00-quantizer-633
-rw-r--r--tests/ref/fate/vp9-01-sharpness-111
-rw-r--r--tests/ref/fate/vp9-01-sharpness-211
-rw-r--r--tests/ref/fate/vp9-01-sharpness-311
-rw-r--r--tests/ref/fate/vp9-01-sharpness-411
-rw-r--r--tests/ref/fate/vp9-01-sharpness-511
-rw-r--r--tests/ref/fate/vp9-01-sharpness-611
-rw-r--r--tests/ref/fate/vp9-01-sharpness-711
-rw-r--r--tests/ref/fate/vp9-02-size-08x0811
-rw-r--r--tests/ref/fate/vp9-02-size-08x1011
-rw-r--r--tests/ref/fate/vp9-02-size-08x1611
-rw-r--r--tests/ref/fate/vp9-02-size-08x1811
-rw-r--r--tests/ref/fate/vp9-02-size-08x3211
-rw-r--r--tests/ref/fate/vp9-02-size-08x3411
-rw-r--r--tests/ref/fate/vp9-02-size-08x6411
-rw-r--r--tests/ref/fate/vp9-02-size-08x6611
-rw-r--r--tests/ref/fate/vp9-02-size-10x0811
-rw-r--r--tests/ref/fate/vp9-02-size-10x1011
-rw-r--r--tests/ref/fate/vp9-02-size-10x1611
-rw-r--r--tests/ref/fate/vp9-02-size-10x1811
-rw-r--r--tests/ref/fate/vp9-02-size-10x3211
-rw-r--r--tests/ref/fate/vp9-02-size-10x3411
-rw-r--r--tests/ref/fate/vp9-02-size-10x6411
-rw-r--r--tests/ref/fate/vp9-02-size-10x6611
-rw-r--r--tests/ref/fate/vp9-02-size-16x0811
-rw-r--r--tests/ref/fate/vp9-02-size-16x1011
-rw-r--r--tests/ref/fate/vp9-02-size-16x1611
-rw-r--r--tests/ref/fate/vp9-02-size-16x1811
-rw-r--r--tests/ref/fate/vp9-02-size-16x3211
-rw-r--r--tests/ref/fate/vp9-02-size-16x3411
-rw-r--r--tests/ref/fate/vp9-02-size-16x6411
-rw-r--r--tests/ref/fate/vp9-02-size-16x6611
-rw-r--r--tests/ref/fate/vp9-02-size-18x0811
-rw-r--r--tests/ref/fate/vp9-02-size-18x1011
-rw-r--r--tests/ref/fate/vp9-02-size-18x1611
-rw-r--r--tests/ref/fate/vp9-02-size-18x1811
-rw-r--r--tests/ref/fate/vp9-02-size-18x3211
-rw-r--r--tests/ref/fate/vp9-02-size-18x3411
-rw-r--r--tests/ref/fate/vp9-02-size-18x6411
-rw-r--r--tests/ref/fate/vp9-02-size-18x6611
-rw-r--r--tests/ref/fate/vp9-02-size-32x0811
-rw-r--r--tests/ref/fate/vp9-02-size-32x1011
-rw-r--r--tests/ref/fate/vp9-02-size-32x1611
-rw-r--r--tests/ref/fate/vp9-02-size-32x1811
-rw-r--r--tests/ref/fate/vp9-02-size-32x3211
-rw-r--r--tests/ref/fate/vp9-02-size-32x3411
-rw-r--r--tests/ref/fate/vp9-02-size-32x6411
-rw-r--r--tests/ref/fate/vp9-02-size-32x6611
-rw-r--r--tests/ref/fate/vp9-02-size-34x0811
-rw-r--r--tests/ref/fate/vp9-02-size-34x1011
-rw-r--r--tests/ref/fate/vp9-02-size-34x1611
-rw-r--r--tests/ref/fate/vp9-02-size-34x1811
-rw-r--r--tests/ref/fate/vp9-02-size-34x3211
-rw-r--r--tests/ref/fate/vp9-02-size-34x3411
-rw-r--r--tests/ref/fate/vp9-02-size-34x6411
-rw-r--r--tests/ref/fate/vp9-02-size-34x6611
-rw-r--r--tests/ref/fate/vp9-02-size-64x0811
-rw-r--r--tests/ref/fate/vp9-02-size-64x1011
-rw-r--r--tests/ref/fate/vp9-02-size-64x1611
-rw-r--r--tests/ref/fate/vp9-02-size-64x1811
-rw-r--r--tests/ref/fate/vp9-02-size-64x3211
-rw-r--r--tests/ref/fate/vp9-02-size-64x3411
-rw-r--r--tests/ref/fate/vp9-02-size-64x6411
-rw-r--r--tests/ref/fate/vp9-02-size-64x6611
-rw-r--r--tests/ref/fate/vp9-02-size-66x0811
-rw-r--r--tests/ref/fate/vp9-02-size-66x1011
-rw-r--r--tests/ref/fate/vp9-02-size-66x1611
-rw-r--r--tests/ref/fate/vp9-02-size-66x1811
-rw-r--r--tests/ref/fate/vp9-02-size-66x3211
-rw-r--r--tests/ref/fate/vp9-02-size-66x3411
-rw-r--r--tests/ref/fate/vp9-02-size-66x6411
-rw-r--r--tests/ref/fate/vp9-02-size-66x6611
-rw-r--r--tests/ref/fate/vp9-03-deltaq3
-rw-r--r--tests/ref/fate/vp9-03-size-196x19611
-rw-r--r--tests/ref/fate/vp9-03-size-196x19811
-rw-r--r--tests/ref/fate/vp9-03-size-196x20011
-rw-r--r--tests/ref/fate/vp9-03-size-196x20211
-rw-r--r--tests/ref/fate/vp9-03-size-196x20811
-rw-r--r--tests/ref/fate/vp9-03-size-196x21011
-rw-r--r--tests/ref/fate/vp9-03-size-196x22411
-rw-r--r--tests/ref/fate/vp9-03-size-196x22611
-rw-r--r--tests/ref/fate/vp9-03-size-198x19611
-rw-r--r--tests/ref/fate/vp9-03-size-198x19811
-rw-r--r--tests/ref/fate/vp9-03-size-198x20011
-rw-r--r--tests/ref/fate/vp9-03-size-198x20211
-rw-r--r--tests/ref/fate/vp9-03-size-198x20811
-rw-r--r--tests/ref/fate/vp9-03-size-198x21011
-rw-r--r--tests/ref/fate/vp9-03-size-198x22411
-rw-r--r--tests/ref/fate/vp9-03-size-198x22611
-rw-r--r--tests/ref/fate/vp9-03-size-200x19611
-rw-r--r--tests/ref/fate/vp9-03-size-200x19811
-rw-r--r--tests/ref/fate/vp9-03-size-200x20011
-rw-r--r--tests/ref/fate/vp9-03-size-200x20211
-rw-r--r--tests/ref/fate/vp9-03-size-200x20811
-rw-r--r--tests/ref/fate/vp9-03-size-200x21011
-rw-r--r--tests/ref/fate/vp9-03-size-200x22411
-rw-r--r--tests/ref/fate/vp9-03-size-200x22611
-rw-r--r--tests/ref/fate/vp9-03-size-202x19611
-rw-r--r--tests/ref/fate/vp9-03-size-202x19811
-rw-r--r--tests/ref/fate/vp9-03-size-202x20011
-rw-r--r--tests/ref/fate/vp9-03-size-202x20211
-rw-r--r--tests/ref/fate/vp9-03-size-202x20811
-rw-r--r--tests/ref/fate/vp9-03-size-202x21011
-rw-r--r--tests/ref/fate/vp9-03-size-202x22411
-rw-r--r--tests/ref/fate/vp9-03-size-202x22611
-rw-r--r--tests/ref/fate/vp9-03-size-208x19611
-rw-r--r--tests/ref/fate/vp9-03-size-208x19811
-rw-r--r--tests/ref/fate/vp9-03-size-208x20011
-rw-r--r--tests/ref/fate/vp9-03-size-208x20211
-rw-r--r--tests/ref/fate/vp9-03-size-208x20811
-rw-r--r--tests/ref/fate/vp9-03-size-208x21011
-rw-r--r--tests/ref/fate/vp9-03-size-208x22411
-rw-r--r--tests/ref/fate/vp9-03-size-208x22611
-rw-r--r--tests/ref/fate/vp9-03-size-210x19611
-rw-r--r--tests/ref/fate/vp9-03-size-210x19811
-rw-r--r--tests/ref/fate/vp9-03-size-210x20011
-rw-r--r--tests/ref/fate/vp9-03-size-210x20211
-rw-r--r--tests/ref/fate/vp9-03-size-210x20811
-rw-r--r--tests/ref/fate/vp9-03-size-210x21011
-rw-r--r--tests/ref/fate/vp9-03-size-210x22411
-rw-r--r--tests/ref/fate/vp9-03-size-210x22611
-rw-r--r--tests/ref/fate/vp9-03-size-224x19611
-rw-r--r--tests/ref/fate/vp9-03-size-224x19811
-rw-r--r--tests/ref/fate/vp9-03-size-224x20011
-rw-r--r--tests/ref/fate/vp9-03-size-224x20211
-rw-r--r--tests/ref/fate/vp9-03-size-224x20811
-rw-r--r--tests/ref/fate/vp9-03-size-224x21011
-rw-r--r--tests/ref/fate/vp9-03-size-224x22411
-rw-r--r--tests/ref/fate/vp9-03-size-224x22611
-rw-r--r--tests/ref/fate/vp9-03-size-226x19611
-rw-r--r--tests/ref/fate/vp9-03-size-226x19811
-rw-r--r--tests/ref/fate/vp9-03-size-226x20011
-rw-r--r--tests/ref/fate/vp9-03-size-226x20211
-rw-r--r--tests/ref/fate/vp9-03-size-226x20811
-rw-r--r--tests/ref/fate/vp9-03-size-226x21011
-rw-r--r--tests/ref/fate/vp9-03-size-226x22411
-rw-r--r--tests/ref/fate/vp9-03-size-226x22611
-rw-r--r--tests/ref/fate/vp9-2pass-akiyo51
-rw-r--r--tests/ref/fate/vp9-segmentation-akiyo51
-rw-r--r--tests/ref/fate/vp9-tiling-pedestrian3
214 files changed, 9785 insertions, 1 deletions
diff --git a/Changelog b/Changelog
index a091c76248..b63e036858 100644
--- a/Changelog
+++ b/Changelog
@@ -36,6 +36,7 @@ version <next>
- make decoding alpha optional for prores, ffv1 and vp6 by setting
the skip_alpha flag.
- ladspa wrapper filter
+- native VP9 decoder
version 2.0:
diff --git a/configure b/configure
index e29493aecd..10ee3a18bb 100755
--- a/configure
+++ b/configure
@@ -1909,6 +1909,7 @@ vp6_decoder_select="h264chroma hpeldsp huffman videodsp vp3dsp"
vp6a_decoder_select="vp6_decoder"
vp6f_decoder_select="vp6_decoder"
vp8_decoder_select="h264pred videodsp"
+vp9_decoder_select="videodsp"
webp_decoder_select="vp8_decoder"
wmapro_decoder_select="mdct sinewin"
wmav1_decoder_select="mdct sinewin"
diff --git a/doc/general.texi b/doc/general.texi
index f4776c8cb7..647c5e20ee 100644
--- a/doc/general.texi
+++ b/doc/general.texi
@@ -94,7 +94,7 @@ Then pass @code{--enable-libtwolame} to configure to enable it.
@section libvpx
-FFmpeg can make use of the libvpx library for VP8 encoding.
+FFmpeg can make use of the libvpx library for VP8/VP9 encoding.
Go to @url{http://www.webmproject.org/} and follow the instructions for
installing the library. Then pass @code{--enable-libvpx} to configure to
@@ -676,6 +676,8 @@ following image formats are supported:
@tab fourcc: VP60,VP61,VP62
@item VP8 @tab E @tab X
@tab fourcc: VP80, encoding supported through external library libvpx
+@item VP9 @tab E @tab X
+ @tab encoding supported through external library libvpx
@item Pinnacle TARGA CineWave YUV16 @tab @tab X
@tab fourcc: Y216
@item Prores @tab @tab X
diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 6c084d55a3..bd5c0be582 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -471,6 +471,7 @@ OBJS-$(CONFIG_VP5_DECODER) += vp5.o vp56.o vp56data.o vp56dsp.o \
OBJS-$(CONFIG_VP6_DECODER) += vp6.o vp56.o vp56data.o vp56dsp.o \
vp6dsp.o vp56rac.o
OBJS-$(CONFIG_VP8_DECODER) += vp8.o vp8dsp.o vp56rac.o
+OBJS-$(CONFIG_VP9_DECODER) += vp9.o vp9dsp.o vp56rac.o
OBJS-$(CONFIG_VPLAYER_DECODER) += textdec.o ass.o
OBJS-$(CONFIG_VQA_DECODER) += vqavideo.o
OBJS-$(CONFIG_WAVPACK_DECODER) += wavpack.o
diff --git a/libavcodec/allcodecs.c b/libavcodec/allcodecs.c
index 12f334e340..bf58d2bcd0 100644
--- a/libavcodec/allcodecs.c
+++ b/libavcodec/allcodecs.c
@@ -285,6 +285,7 @@ void avcodec_register_all(void)
REGISTER_DECODER(VP6A, vp6a);
REGISTER_DECODER(VP6F, vp6f);
REGISTER_DECODER(VP8, vp8);
+ REGISTER_DECODER(VP9, vp9);
REGISTER_DECODER(VQA, vqa);
REGISTER_DECODER(WEBP, webp);
REGISTER_ENCDEC (WMV1, wmv1);
diff --git a/libavcodec/vp9.c b/libavcodec/vp9.c
new file mode 100644
index 0000000000..a4aa97a9fa
--- /dev/null
+++ b/libavcodec/vp9.c
@@ -0,0 +1,3576 @@
+/*
+ * VP9 compatible video decoder
+ *
+ * Copyright (C) 2013 Ronald S. Bultje <rsbultje gmail com>
+ * Copyright (C) 2013 Clément Bœsch <u pkh me>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "avcodec.h"
+#include "get_bits.h"
+#include "internal.h"
+#include "videodsp.h"
+#include "vp56.h"
+#include "vp9.h"
+#include "vp9data.h"
+#include "vp9dsp.h"
+#include "libavutil/avassert.h"
+
+#define VP9_SYNCCODE 0x498342
+
+enum CompPredMode {
+ PRED_SINGLEREF,
+ PRED_COMPREF,
+ PRED_SWITCHABLE,
+};
+
+enum BlockLevel {
+ BL_64X64,
+ BL_32X32,
+ BL_16X16,
+ BL_8X8,
+};
+
+enum BlockSize {
+ BS_64x64,
+ BS_64x32,
+ BS_32x64,
+ BS_32x32,
+ BS_32x16,
+ BS_16x32,
+ BS_16x16,
+ BS_16x8,
+ BS_8x16,
+ BS_8x8,
+ BS_8x4,
+ BS_4x8,
+ BS_4x4,
+ N_BS_SIZES,
+};
+
+struct VP9mvrefPair {
+ VP56mv mv[2];
+ int8_t ref[2];
+};
+
+struct VP9Filter {
+ uint8_t level[8 * 8];
+ uint8_t /* bit=col */ mask[2 /* 0=y, 1=uv */][2 /* 0=col, 1=row */]
+ [8 /* rows */][4 /* 0=16, 1=8, 2=4, 3=inner4 */];
+};
+
+typedef struct VP9Block {
+ uint8_t seg_id, intra, comp, ref[2], mode[4], uvmode, skip;
+ enum FilterMode filter;
+ VP56mv mv[4 /* b_idx */][2 /* ref */];
+ enum BlockSize bs;
+ enum TxfmMode tx, uvtx;
+
+ int row, row7, col, col7;
+ uint8_t *dst[3];
+ ptrdiff_t y_stride, uv_stride;
+} VP9Block;
+
+typedef struct VP9Context {
+ VP9DSPContext dsp;
+ VideoDSPContext vdsp;
+ GetBitContext gb;
+ VP56RangeCoder c;
+ VP56RangeCoder *c_b;
+ unsigned c_b_size;
+ VP9Block b;
+
+ // bitstream header
+ uint8_t profile;
+ uint8_t keyframe, last_keyframe;
+ uint8_t invisible, last_invisible;
+ uint8_t use_last_frame_mvs;
+ uint8_t errorres;
+ uint8_t colorspace;
+ uint8_t fullrange;
+ uint8_t intraonly;
+ uint8_t resetctx;
+ uint8_t refreshrefmask;
+ uint8_t highprecisionmvs;
+ enum FilterMode filtermode;
+ uint8_t allowcompinter;
+ uint8_t fixcompref;
+ uint8_t refreshctx;
+ uint8_t parallelmode;
+ uint8_t framectxid;
+ uint8_t refidx[3];
+ uint8_t signbias[3];
+ uint8_t varcompref[2];
+ AVFrame *refs[8], *f, *fb[10];
+
+ struct {
+ uint8_t level;
+ int8_t sharpness;
+ uint8_t lim_lut[64];
+ uint8_t mblim_lut[64];
+ } filter;
+ struct {
+ uint8_t enabled;
+ int8_t mode[2];
+ int8_t ref[4];
+ } lf_delta;
+ uint8_t yac_qi;
+ int8_t ydc_qdelta, uvdc_qdelta, uvac_qdelta;
+ uint8_t lossless;
+ struct {
+ uint8_t enabled;
+ uint8_t temporal;
+ uint8_t absolute_vals;
+ uint8_t update_map;
+ struct {
+ uint8_t q_enabled;
+ uint8_t lf_enabled;
+ uint8_t ref_enabled;
+ uint8_t skip_enabled;
+ uint8_t ref_val;
+ int16_t q_val;
+ int8_t lf_val;
+ int16_t qmul[2][2];
+ uint8_t lflvl[4][2];
+ } feat[8];
+ } segmentation;
+ struct {
+ unsigned log2_tile_cols, log2_tile_rows;
+ unsigned tile_cols, tile_rows;
+ unsigned tile_row_start, tile_row_end, tile_col_start, tile_col_end;
+ } tiling;
+ unsigned sb_cols, sb_rows, rows, cols;
+ struct {
+ prob_context p;
+ uint8_t coef[4][2][2][6][6][3];
+ } prob_ctx[4];
+ struct {
+ prob_context p;
+ uint8_t coef[4][2][2][6][6][11];
+ uint8_t seg[7];
+ uint8_t segpred[3];
+ } prob;
+ struct {
+ unsigned y_mode[4][10];
+ unsigned uv_mode[10][10];
+ unsigned filter[4][3];
+ unsigned mv_mode[7][4];
+ unsigned intra[4][2];
+ unsigned comp[5][2];
+ unsigned single_ref[5][2][2];
+ unsigned comp_ref[5][2];
+ unsigned tx32p[2][4];
+ unsigned tx16p[2][3];
+ unsigned tx8p[2][2];
+ unsigned skip[3][2];
+ unsigned mv_joint[4];
+ struct {
+ unsigned sign[2];
+ unsigned classes[11];
+ unsigned class0[2];
+ unsigned bits[10][2];
+ unsigned class0_fp[2][4];
+ unsigned fp[4];
+ unsigned class0_hp[2];
+ unsigned hp[2];
+ } mv_comp[2];
+ unsigned partition[4][4][4];
+ unsigned coef[4][2][2][6][6][3];
+ unsigned eob[4][2][2][6][6][2];
+ } counts;
+ enum TxfmMode txfmmode;
+ enum CompPredMode comppredmode;
+
+ // contextual (left/above) cache
+ uint8_t left_partition_ctx[8], *above_partition_ctx;
+ uint8_t left_mode_ctx[16], *above_mode_ctx;
+ // FIXME maybe merge some of the below in a flags field?
+ uint8_t left_y_nnz_ctx[16], *above_y_nnz_ctx;
+ uint8_t left_uv_nnz_ctx[2][8], *above_uv_nnz_ctx[2];
+ uint8_t left_skip_ctx[8], *above_skip_ctx; // 1bit
+ uint8_t left_txfm_ctx[8], *above_txfm_ctx; // 2bit
+ uint8_t left_segpred_ctx[8], *above_segpred_ctx; // 1bit
+ uint8_t left_intra_ctx[8], *above_intra_ctx; // 1bit
+ uint8_t left_comp_ctx[8], *above_comp_ctx; // 1bit
+ uint8_t left_ref_ctx[8], *above_ref_ctx; // 2bit
+ uint8_t left_filter_ctx[8], *above_filter_ctx;
+ VP56mv left_mv_ctx[16][2], (*above_mv_ctx)[2];
+
+ // whole-frame cache
+ uint8_t *intra_pred_data[3];
+ uint8_t *segmentation_map;
+ struct VP9mvrefPair *mv[2];
+ struct VP9Filter *lflvl;
+ DECLARE_ALIGNED(32, uint8_t, edge_emu_buffer)[71*80];
+
+ // block reconstruction intermediates
+ DECLARE_ALIGNED(32, int16_t, block)[4096];
+ DECLARE_ALIGNED(32, int16_t, uvblock)[2][1024];
+ uint8_t eob[256];
+ uint8_t uveob[2][64];
+ VP56mv min_mv, max_mv;
+ DECLARE_ALIGNED(32, uint8_t, tmp_y)[64*64];
+ DECLARE_ALIGNED(32, uint8_t, tmp_uv)[2][32*32];
+} VP9Context;
+
+static const uint8_t bwh_tab[2][N_BS_SIZES][2] = {
+ {
+ { 16, 16 }, { 16, 8 }, { 8, 16 }, { 8, 8 }, { 8, 4 }, { 4, 8 },
+ { 4, 4 }, { 4, 2 }, { 2, 4 }, { 2, 2 }, { 2, 1 }, { 1, 2 }, { 1, 1 },
+ }, {
+ { 8, 8 }, { 8, 4 }, { 4, 8 }, { 4, 4 }, { 4, 2 }, { 2, 4 },
+ { 2, 2 }, { 2, 1 }, { 1, 2 }, { 1, 1 }, { 1, 1 }, { 1, 1 }, { 1, 1 },
+ }
+};
+
+static int update_size(AVCodecContext *ctx, int w, int h)
+{
+ VP9Context *s = ctx->priv_data;
+ uint8_t *p;
+
+ if (s->above_partition_ctx && w == ctx->width && h == ctx->height)
+ return 0;
+
+ ctx->width = w;
+ ctx->height = h;
+ s->sb_cols = (w + 63) >> 6;
+ s->sb_rows = (h + 63) >> 6;
+ s->cols = (w + 7) >> 3;
+ s->rows = (h + 7) >> 3;
+
+#define assign(var, type, n) var = (type) p; p += s->sb_cols * n * sizeof(*var)
+ av_free(s->above_partition_ctx);
+ p = av_malloc(s->sb_cols * (240 + sizeof(*s->lflvl) + 16 * sizeof(*s->above_mv_ctx) +
+ 64 * s->sb_rows * (1 + sizeof(*s->mv[0]) * 2)));
+ if (!p)
+ return AVERROR(ENOMEM);
+ assign(s->above_partition_ctx, uint8_t *, 8);
+ assign(s->above_skip_ctx, uint8_t *, 8);
+ assign(s->above_txfm_ctx, uint8_t *, 8);
+ assign(s->above_mode_ctx, uint8_t *, 16);
+ assign(s->above_y_nnz_ctx, uint8_t *, 16);
+ assign(s->above_uv_nnz_ctx[0], uint8_t *, 8);
+ assign(s->above_uv_nnz_ctx[1], uint8_t *, 8);
+ assign(s->intra_pred_data[0], uint8_t *, 64);
+ assign(s->intra_pred_data[1], uint8_t *, 32);
+ assign(s->intra_pred_data[2], uint8_t *, 32);
+ assign(s->above_segpred_ctx, uint8_t *, 8);
+ assign(s->above_intra_ctx, uint8_t *, 8);
+ assign(s->above_comp_ctx, uint8_t *, 8);
+ assign(s->above_ref_ctx, uint8_t *, 8);
+ assign(s->above_filter_ctx, uint8_t *, 8);
+ assign(s->lflvl, struct VP9Filter *, 1);
+ assign(s->above_mv_ctx, VP56mv(*)[2], 16);
+ assign(s->segmentation_map, uint8_t *, 64 * s->sb_rows);
+ assign(s->mv[0], struct VP9mvrefPair *, 64 * s->sb_rows);
+ assign(s->mv[1], struct VP9mvrefPair *, 64 * s->sb_rows);
+#undef assign
+
+ return 0;
+}
+
+// for some reason the sign bit is at the end, not the start, of a bit sequence
+static av_always_inline int get_sbits_inv(GetBitContext *gb, int n)
+{
+ int v = get_bits(gb, n);
+ return get_bits1(gb) ? -v : v;
+}
+
+static av_always_inline int inv_recenter_nonneg(int v, int m)
+{
+ return v > 2 * m ? v : v & 1 ? m - ((v + 1) >> 1) : m + (v >> 1);
+}
+
+// differential forward probability updates
+static int update_prob(VP56RangeCoder *c, int p)
+{
+ static const int inv_map_table[254] = {
+ 7, 20, 33, 46, 59, 72, 85, 98, 111, 124, 137, 150, 163, 176,
+ 189, 202, 215, 228, 241, 254, 1, 2, 3, 4, 5, 6, 8, 9,
+ 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 24,
+ 25, 26, 27, 28, 29, 30, 31, 32, 34, 35, 36, 37, 38, 39,
+ 40, 41, 42, 43, 44, 45, 47, 48, 49, 50, 51, 52, 53, 54,
+ 55, 56, 57, 58, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
+ 70, 71, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
+ 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 99, 100,
+ 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 112, 113, 114, 115,
+ 116, 117, 118, 119, 120, 121, 122, 123, 125, 126, 127, 128, 129, 130,
+ 131, 132, 133, 134, 135, 136, 138, 139, 140, 141, 142, 143, 144, 145,
+ 146, 147, 148, 149, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160,
+ 161, 162, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175,
+ 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 190, 191,
+ 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 203, 204, 205, 206,
+ 207, 208, 209, 210, 211, 212, 213, 214, 216, 217, 218, 219, 220, 221,
+ 222, 223, 224, 225, 226, 227, 229, 230, 231, 232, 233, 234, 235, 236,
+ 237, 238, 239, 240, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251,
+ 252, 253,
+ };
+ int d;
+
+ /* This code is trying to do a differential probability update. For a
+ * current probability A in the range [1, 255], the difference to a new
+ * probability of any value can be expressed differentially as 1-A,255-A
+ * where some part of this (absolute range) exists both in positive as
+ * well as the negative part, whereas another part only exists in one
+ * half. We're trying to code this shared part differentially, i.e.
+ * times two where the value of the lowest bit specifies the sign, and
+ * the single part is then coded on top of this. This absolute difference
+ * then again has a value of [0,254], but a bigger value in this range
+ * indicates that we're further away from the original value A, so we
+ * can code this as a VLC code, since higher values are increasingly
+ * unlikely. The first 20 values in inv_map_table[] allow 'cheap, rough'
+ * updates vs. the 'fine, exact' updates further down the range, which
+ * adds one extra dimension to this differential update model. */
+
+ if (!vp8_rac_get(c)) {
+ d = vp8_rac_get_uint(c, 4) + 0;
+ } else if (!vp8_rac_get(c)) {
+ d = vp8_rac_get_uint(c, 4) + 16;
+ } else if (!vp8_rac_get(c)) {
+ d = vp8_rac_get_uint(c, 5) + 32;
+ } else {
+ d = vp8_rac_get_uint(c, 7);
+ if (d >= 65)
+ d = (d << 1) - 65 + vp8_rac_get(c);
+ d += 64;
+ }
+
+ return p <= 128 ? 1 + inv_recenter_nonneg(inv_map_table[d], p - 1) :
+ 255 - inv_recenter_nonneg(inv_map_table[d], 255 - p);
+}
+
+static int decode_frame_header(AVCodecContext *ctx,
+ const uint8_t *data, int size, int *ref)
+{
+ VP9Context *s = ctx->priv_data;
+ int c, i, j, k, l, m, n, w, h, max, size2, res, sharp;
+ const uint8_t *data2;
+
+ /* general header */
+ if ((res = init_get_bits8(&s->gb, data, size)) < 0) {
+ av_log(ctx, AV_LOG_ERROR, "Failed to intialize bitstream reader\n");
+ return res;
+ }
+ if (get_bits(&s->gb, 2) != 0x2) { // frame marker
+ av_log(ctx, AV_LOG_ERROR, "Invalid frame marker\n");
+ return AVERROR_INVALIDDATA;
+ }
+ s->profile = get_bits1(&s->gb);
+ if (get_bits1(&s->gb)) { // reserved bit
+ av_log(ctx, AV_LOG_ERROR, "Reserved bit should be zero\n");
+ return AVERROR_INVALIDDATA;
+ }
+ if (get_bits1(&s->gb)) {
+ *ref = get_bits(&s->gb, 3);
+ return 0;
+ }
+ s->last_keyframe = s->keyframe;
+ s->keyframe = !get_bits1(&s->gb);
+ s->last_invisible = s->invisible;
+ s->invisible = !get_bits1(&s->gb);
+ s->errorres = get_bits1(&s->gb);
+ // FIXME disable this upon resolution change
+ s->use_last_frame_mvs = !s->errorres && !s->last_invisible;
+ if (s->keyframe) {
+ if (get_bits_long(&s->gb, 24) != VP9_SYNCCODE) { // synccode
+ av_log(ctx, AV_LOG_ERROR, "Invalid sync code\n");
+ return AVERROR_INVALIDDATA;
+ }
+ s->colorspace = get_bits(&s->gb, 3);
+ if (s->colorspace == 7) { // RGB = profile 1
+ av_log(ctx, AV_LOG_ERROR, "RGB not supported in profile 0\n");
+ return AVERROR_INVALIDDATA;
+ }
+ s->fullrange = get_bits1(&s->gb);
+ // for profile 1, here follows the subsampling bits
+ s->refreshrefmask = 0xff;
+ w = get_bits(&s->gb, 16) + 1;
+ h = get_bits(&s->gb, 16) + 1;
+ if (get_bits1(&s->gb)) // display size
+ skip_bits(&s->gb, 32);
+ } else {
+ s->intraonly = s->invisible ? get_bits1(&s->gb) : 0;
+ s->resetctx = s->errorres ? 0 : get_bits(&s->gb, 2);
+ if (s->intraonly) {
+ if (get_bits_long(&s->gb, 24) != VP9_SYNCCODE) { // synccode
+ av_log(ctx, AV_LOG_ERROR, "Invalid sync code\n");
+ return AVERROR_INVALIDDATA;
+ }
+ s->refreshrefmask = get_bits(&s->gb, 8);
+ w = get_bits(&s->gb, 16) + 1;
+ h = get_bits(&s->gb, 16) + 1;
+ if (get_bits1(&s->gb)) // display size
+ skip_bits(&s->gb, 32);
+ } else {
+ s->refreshrefmask = get_bits(&s->gb, 8);
+ s->refidx[0] = get_bits(&s->gb, 3);
+ s->signbias[0] = get_bits1(&s->gb);
+ s->refidx[1] = get_bits(&s->gb, 3);
+ s->signbias[1] = get_bits1(&s->gb);
+ s->refidx[2] = get_bits(&s->gb, 3);
+ s->signbias[2] = get_bits1(&s->gb);
+ if (!s->refs[s->refidx[0]] || !s->refs[s->refidx[1]] ||
+ !s->refs[s->refidx[2]]) {
+ av_log(ctx, AV_LOG_ERROR, "Not all references are available\n");
+ return AVERROR_INVALIDDATA;
+ }
+ if (get_bits1(&s->gb)) {
+ w = s->refs[s->refidx[0]]->width;
+ h = s->refs[s->refidx[0]]->height;
+ } else if (get_bits1(&s->gb)) {
+ w = s->refs[s->refidx[1]]->width;
+ h = s->refs[s->refidx[1]]->height;
+ } else if (get_bits1(&s->gb)) {
+ w = s->refs[s->refidx[2]]->width;
+ h = s->refs[s->refidx[2]]->height;
+ } else {
+ w = get_bits(&s->gb, 16) + 1;
+ h = get_bits(&s->gb, 16) + 1;
+ }
+ if (get_bits1(&s->gb)) // display size
+ skip_bits(&s->gb, 32);
+ s->highprecisionmvs = get_bits1(&s->gb);
+ s->filtermode = get_bits1(&s->gb) ? FILTER_SWITCHABLE :
+ get_bits(&s->gb, 2);
+ s->allowcompinter = s->signbias[0] != s->signbias[1] ||
+ s->signbias[0] != s->signbias[2];
+ if (s->allowcompinter) {
+ if (s->signbias[0] == s->signbias[1]) {
+ s->fixcompref = 2;
+ s->varcompref[0] = 0;
+ s->varcompref[1] = 1;
+ } else if (s->signbias[0] == s->signbias[2]) {
+ s->fixcompref = 1;
+ s->varcompref[0] = 0;
+ s->varcompref[1] = 2;
+ } else {
+ s->fixcompref = 0;
+ s->varcompref[0] = 1;
+ s->varcompref[1] = 2;
+ }
+ }
+ }
+ }
+ s->refreshctx = s->errorres ? 0 : get_bits1(&s->gb);
+ s->parallelmode = s->errorres ? 1 : get_bits1(&s->gb);
+ s->framectxid = c = get_bits(&s->gb, 2);
+
+ /* loopfilter header data */
+ s->filter.level = get_bits(&s->gb, 6);
+ sharp = get_bits(&s->gb, 3);
+ // if sharpness changed, reinit lim/mblim LUTs. if it didn't change, keep
+ // the old cache values since they are still valid
+ if (s->filter.sharpness != sharp)
+ memset(s->filter.lim_lut, 0, sizeof(s->filter.lim_lut));
+ s->filter.sharpness = sharp;
+ if ((s->lf_delta.enabled = get_bits1(&s->gb))) {
+ if (get_bits1(&s->gb)) {
+ for (i = 0; i < 4; i++)
+ if (get_bits1(&s->gb))
+ s->lf_delta.ref[i] = get_sbits_inv(&s->gb, 6);
+ for (i = 0; i < 2; i++)
+ if (get_bits1(&s->gb))
+ s->lf_delta.mode[i] = get_sbits_inv(&s->gb, 6);
+ }
+ } else {
+ memset(&s->lf_delta, 0, sizeof(s->lf_delta));
+ }
+
+ /* quantization header data */
+ s->yac_qi = get_bits(&s->gb, 8);
+ s->ydc_qdelta = get_bits1(&s->gb) ? get_sbits_inv(&s->gb, 4) : 0;
+ s->uvdc_qdelta = get_bits1(&s->gb) ? get_sbits_inv(&s->gb, 4) : 0;
+ s->uvac_qdelta = get_bits1(&s->gb) ? get_sbits_inv(&s->gb, 4) : 0;
+ s->lossless = s->yac_qi == 0 && s->ydc_qdelta == 0 &&
+ s->uvdc_qdelta == 0 && s->uvac_qdelta == 0;
+
+ /* segmentation header info */
+ if ((s->segmentation.enabled = get_bits1(&s->gb))) {
+ if ((s->segmentation.update_map = get_bits1(&s->gb))) {
+ for (i = 0; i < 7; i++)
+ s->prob.seg[i] = get_bits1(&s->gb) ?
+ get_bits(&s->gb, 8) : 255;
+ if ((s->segmentation.temporal = get_bits1(&s->gb)))
+ for (i = 0; i < 3; i++)
+ s->prob.segpred[i] = get_bits1(&s->gb) ?
+ get_bits(&s->gb, 8) : 255;
+ }
+
+ if (get_bits1(&s->gb)) {
+ s->segmentation.absolute_vals = get_bits1(&s->gb);
+ for (i = 0; i < 8; i++) {
+ if ((s->segmentation.feat[i].q_enabled = get_bits1(&s->gb)))
+ s->segmentation.feat[i].q_val = get_sbits_inv(&s->gb, 8);
+ if ((s->segmentation.feat[i].lf_enabled = get_bits1(&s->gb)))
+ s->segmentation.feat[i].lf_val = get_sbits_inv(&s->gb, 6);
+ if ((s->segmentation.feat[i].ref_enabled = get_bits1(&s->gb)))
+ s->segmentation.feat[i].ref_val = get_bits(&s->gb, 2);
+ s->segmentation.feat[i].skip_enabled = get_bits1(&s->gb);
+ }
+ }
+ } else {
+ s->segmentation.feat[0].q_enabled = 0;
+ s->segmentation.feat[0].lf_enabled = 0;
+ s->segmentation.feat[0].skip_enabled = 0;
+ s->segmentation.feat[0].ref_enabled = 0;
+ }
+
+ // set qmul[] based on Y/UV, AC/DC and segmentation Q idx deltas
+ for (i = 0; i < (s->segmentation.enabled ? 8 : 1); i++) {
+ int qyac, qydc, quvac, quvdc, lflvl, sh;
+
+ if (s->segmentation.feat[i].q_enabled) {
+ if (s->segmentation.absolute_vals)
+ qyac = s->segmentation.feat[i].q_val;
+ else
+ qyac = s->yac_qi + s->segmentation.feat[i].q_val;
+ } else {
+ qyac = s->yac_qi;
+ }
+ qydc = av_clip_uintp2(qyac + s->ydc_qdelta, 8);
+ quvdc = av_clip_uintp2(qyac + s->uvdc_qdelta, 8);
+ quvac = av_clip_uintp2(qyac + s->uvac_qdelta, 8);
+ qyac = av_clip_uintp2(qyac, 8);
+
+ s->segmentation.feat[i].qmul[0][0] = vp9_dc_qlookup[qydc];
+ s->segmentation.feat[i].qmul[0][1] = vp9_ac_qlookup[qyac];
+ s->segmentation.feat[i].qmul[1][0] = vp9_dc_qlookup[quvdc];
+ s->segmentation.feat[i].qmul[1][1] = vp9_ac_qlookup[quvac];
+
+ sh = s->filter.level >= 32;
+ if (s->segmentation.feat[i].lf_enabled) {
+ if (s->segmentation.absolute_vals)
+ lflvl = s->segmentation.feat[i].lf_val;
+ else
+ lflvl = s->filter.level + s->segmentation.feat[i].lf_val;
+ } else {
+ lflvl = s->filter.level;
+ }
+ s->segmentation.feat[i].lflvl[0][0] =
+ s->segmentation.feat[i].lflvl[0][1] =
+ av_clip_uintp2(lflvl + (s->lf_delta.ref[0] << sh), 6);
+ for (j = 1; j < 4; j++) {
+ s->segmentation.feat[i].lflvl[j][0] =
+ av_clip_uintp2(lflvl + ((s->lf_delta.ref[j] +
+ s->lf_delta.mode[0]) << sh), 6);
+ s->segmentation.feat[i].lflvl[j][1] =
+ av_clip_uintp2(lflvl + ((s->lf_delta.ref[j] +
+ s->lf_delta.mode[1]) << sh), 6);
+ }
+ }
+
+ /* tiling info */
+ if ((res = update_size(ctx, w, h)) < 0) {
+ av_log(ctx, AV_LOG_ERROR, "Failed to initialize decoder for %dx%d\n", w, h);
+ return res;
+ }
+ for (s->tiling.log2_tile_cols = 0;
+ (s->sb_cols >> s->tiling.log2_tile_cols) > 64;
+ s->tiling.log2_tile_cols++) ;
+ for (max = 0; (s->sb_cols >> max) >= 4; max++) ;
+ max = FFMAX(0, max - 1);
+ while (max > s->tiling.log2_tile_cols) {
+ if (get_bits1(&s->gb))
+ s->tiling.log2_tile_cols++;
+ else
+ break;
+ }
+ s->tiling.log2_tile_rows = decode012(&s->gb);
+ s->tiling.tile_rows = 1 << s->tiling.log2_tile_rows;
+ if (s->tiling.tile_cols != (1 << s->tiling.log2_tile_cols)) {
+ s->tiling.tile_cols = 1 << s->tiling.log2_tile_cols;
+ s->c_b = av_fast_realloc(s->c_b, &s->c_b_size,
+ sizeof(VP56RangeCoder) * s->tiling.tile_cols);
+ if (!s->c_b) {
+ av_log(ctx, AV_LOG_ERROR, "Ran out of memory during range coder init\n");
+ return AVERROR(ENOMEM);
+ }
+ }
+
+ if (s->keyframe || s->errorres || s->intraonly) {
+ s->prob_ctx[0].p = s->prob_ctx[1].p = s->prob_ctx[2].p =
+ s->prob_ctx[3].p = vp9_default_probs;
+ memcpy(s->prob_ctx[0].coef, vp9_default_coef_probs,
+ sizeof(vp9_default_coef_probs));
+ memcpy(s->prob_ctx[1].coef, vp9_default_coef_probs,
+ sizeof(vp9_default_coef_probs));
+ memcpy(s->prob_ctx[2].coef, vp9_default_coef_probs,
+ sizeof(vp9_default_coef_probs));
+ memcpy(s->prob_ctx[3].coef, vp9_default_coef_probs,
+ sizeof(vp9_default_coef_probs));
+ }
+
+ // next 16 bits is size of the rest of the header (arith-coded)
+ size2 = get_bits(&s->gb, 16);
+ data2 = align_get_bits(&s->gb);
+ if (size2 > size - (data2 - data)) {
+ av_log(ctx, AV_LOG_ERROR, "Invalid compressed header size\n");
+ return AVERROR_INVALIDDATA;
+ }
+ ff_vp56_init_range_decoder(&s->c, data2, size2);
+ if (vp56_rac_get_prob_branchy(&s->c, 128)) { // marker bit
+ av_log(ctx, AV_LOG_ERROR, "Marker bit was set\n");
+ return AVERROR_INVALIDDATA;
+ }
+
+ if (s->keyframe || s->intraonly) {
+ memset(s->counts.coef, 0, sizeof(s->counts.coef) + sizeof(s->counts.eob));
+ } else {
+ memset(&s->counts, 0, sizeof(s->counts));
+ }
+ // FIXME is it faster to not copy here, but do it down in the fw updates
+ // as explicit copies if the fw update is missing (and skip the copy upon
+ // fw update)?
+ s->prob.p = s->prob_ctx[c].p;
+
+ // txfm updates
+ if (s->lossless) {
+ s->txfmmode = TX_4X4;
+ } else {
+ s->txfmmode = vp8_rac_get_uint(&s->c, 2);
+ if (s->txfmmode == 3)
+ s->txfmmode += vp8_rac_get(&s->c);
+
+ if (s->txfmmode == TX_SWITCHABLE) {
+ for (i = 0; i < 2; i++)
+ if (vp56_rac_get_prob_branchy(&s->c, 252))
+ s->prob.p.tx8p[i] = update_prob(&s->c, s->prob.p.tx8p[i]);
+ for (i = 0; i < 2; i++)
+ for (j = 0; j < 2; j++)
+ if (vp56_rac_get_prob_branchy(&s->c, 252))
+ s->prob.p.tx16p[i][j] =
+ update_prob(&s->c, s->prob.p.tx16p[i][j]);
+ for (i = 0; i < 2; i++)
+ for (j = 0; j < 3; j++)
+ if (vp56_rac_get_prob_branchy(&s->c, 252))
+ s->prob.p.tx32p[i][j] =
+ update_prob(&s->c, s->prob.p.tx32p[i][j]);
+ }
+ }
+
+ // coef updates
+ for (i = 0; i < 4; i++) {
+ uint8_t (*ref)[2][6][6][3] = s->prob_ctx[c].coef[i];
+ if (vp8_rac_get(&s->c)) {
+ for (j = 0; j < 2; j++)
+ for (k = 0; k < 2; k++)
+ for (l = 0; l < 6; l++)
+ for (m = 0; m < 6; m++) {
+ uint8_t *p = s->prob.coef[i][j][k][l][m];
+ uint8_t *r = ref[j][k][l][m];
+ if (m >= 3 && l == 0) // dc only has 3 pt
+ break;
+ for (n = 0; n < 3; n++) {
+ if (vp56_rac_get_prob_branchy(&s->c, 252)) {
+ p[n] = update_prob(&s->c, r[n]);
+ } else {
+ p[n] = r[n];
+ }
+ }
+ p[3] = 0;
+ }
+ } else {
+ for (j = 0; j < 2; j++)
+ for (k = 0; k < 2; k++)
+ for (l = 0; l < 6; l++)
+ for (m = 0; m < 6; m++) {
+ uint8_t *p = s->prob.coef[i][j][k][l][m];
+ uint8_t *r = ref[j][k][l][m];
+ if (m > 3 && l == 0) // dc only has 3 pt
+ break;
+ memcpy(p, r, 3);
+ p[3] = 0;
+ }
+ }
+ if (s->txfmmode == i)
+ break;
+ }
+
+ // mode updates
+ for (i = 0; i < 3; i++)
+ if (vp56_rac_get_prob_branchy(&s->c, 252))
+ s->prob.p.skip[i] = update_prob(&s->c, s->prob.p.skip[i]);
+ if (!s->keyframe && !s->intraonly) {
+ for (i = 0; i < 7; i++)
+ for (j = 0; j < 3; j++)
+ if (vp56_rac_get_prob_branchy(&s->c, 252))
+ s->prob.p.mv_mode[i][j] =
+ update_prob(&s->c, s->prob.p.mv_mode[i][j]);
+
+ if (s->filtermode == FILTER_SWITCHABLE)
+ for (i = 0; i < 4; i++)
+ for (j = 0; j < 2; j++)
+ if (vp56_rac_get_prob_branchy(&s->c, 252))
+ s->prob.p.filter[i][j] =
+ update_prob(&s->c, s->prob.p.filter[i][j]);
+
+ for (i = 0; i < 4; i++)
+ if (vp56_rac_get_prob_branchy(&s->c, 252))
+ s->prob.p.intra[i] = update_prob(&s->c, s->prob.p.intra[i]);
+
+ if (s->allowcompinter) {
+ s->comppredmode = vp8_rac_get(&s->c);
+ if (s->comppredmode)
+ s->comppredmode += vp8_rac_get(&s->c);
+ if (s->comppredmode == PRED_SWITCHABLE)
+ for (i = 0; i < 5; i++)
+ if (vp56_rac_get_prob_branchy(&s->c, 252))
+ s->prob.p.comp[i] =
+ update_prob(&s->c, s->prob.p.comp[i]);
+ } else {
+ s->comppredmode = PRED_SINGLEREF;
+ }
+
+ if (s->comppredmode != PRED_COMPREF) {
+ for (i = 0; i < 5; i++) {
+ if (vp56_rac_get_prob_branchy(&s->c, 252))
+ s->prob.p.single_ref[i][0] =
+ update_prob(&s->c, s->prob.p.single_ref[i][0]);
+ if (vp56_rac_get_prob_branchy(&s->c, 252))
+ s->prob.p.single_ref[i][1] =
+ update_prob(&s->c, s->prob.p.single_ref[i][1]);
+ }
+ }
+
+ if (s->comppredmode != PRED_SINGLEREF) {
+ for (i = 0; i < 5; i++)
+ if (vp56_rac_get_prob_branchy(&s->c, 252))
+ s->prob.p.comp_ref[i] =
+ update_prob(&s->c, s->prob.p.comp_ref[i]);
+ }
+
+ for (i = 0; i < 4; i++)
+ for (j = 0; j < 9; j++)
+ if (vp56_rac_get_prob_branchy(&s->c, 252))
+ s->prob.p.y_mode[i][j] =
+ update_prob(&s->c, s->prob.p.y_mode[i][j]);
+
+ for (i = 0; i < 4; i++)
+ for (j = 0; j < 4; j++)
+ for (k = 0; k < 3; k++)
+ if (vp56_rac_get_prob_branchy(&s->c, 252))
+ s->prob.p.partition[3 - i][j][k] =
+ update_prob(&s->c, s->prob.p.partition[3 - i][j][k]);
+
+ // mv fields don't use the update_prob subexp model for some reason
+ for (i = 0; i < 3; i++)
+ if (vp56_rac_get_prob_branchy(&s->c, 252))
+ s->prob.p.mv_joint[i] = (vp8_rac_get_uint(&s->c, 7) << 1) | 1;
+
+ for (i = 0; i < 2; i++) {
+ if (vp56_rac_get_prob_branchy(&s->c, 252))
+ s->prob.p.mv_comp[i].sign = (vp8_rac_get_uint(&s->c, 7) << 1) | 1;
+
+ for (j = 0; j < 10; j++)
+ if (vp56_rac_get_prob_branchy(&s->c, 252))
+ s->prob.p.mv_comp[i].classes[j] =
+ (vp8_rac_get_uint(&s->c, 7) << 1) | 1;
+
+ if (vp56_rac_get_prob_branchy(&s->c, 252))
+ s->prob.p.mv_comp[i].class0 = (vp8_rac_get_uint(&s->c, 7) << 1) | 1;
+
+ for (j = 0; j < 10; j++)
+ if (vp56_rac_get_prob_branchy(&s->c, 252))
+ s->prob.p.mv_comp[i].bits[j] =
+ (vp8_rac_get_uint(&s->c, 7) << 1) | 1;
+ }
+
+ for (i = 0; i < 2; i++) {
+ for (j = 0; j < 2; j++)
+ for (k = 0; k < 3; k++)
+ if (vp56_rac_get_prob_branchy(&s->c, 252))
+ s->prob.p.mv_comp[i].class0_fp[j][k] =
+ (vp8_rac_get_uint(&s->c, 7) << 1) | 1;
+
+ for (j = 0; j < 3; j++)
+ if (vp56_rac_get_prob_branchy(&s->c, 252))
+ s->prob.p.mv_comp[i].fp[j] =
+ (vp8_rac_get_uint(&s->c, 7) << 1) | 1;
+ }
+
+ if (s->highprecisionmvs) {
+ for (i = 0; i < 2; i++) {
+ if (vp56_rac_get_prob_branchy(&s->c, 252))
+ s->prob.p.mv_comp[i].class0_hp =
+ (vp8_rac_get_uint(&s->c, 7) << 1) | 1;
+
+ if (vp56_rac_get_prob_branchy(&s->c, 252))
+ s->prob.p.mv_comp[i].hp =
+ (vp8_rac_get_uint(&s->c, 7) << 1) | 1;
+ }
+ }
+ }
+
+ return (data2 - data) + size2;
+}
+
+static av_always_inline void clamp_mv(VP56mv *dst, const VP56mv *src,
+ VP9Context *s)
+{
+ dst->x = av_clip(src->x, s->min_mv.x, s->max_mv.x);
+ dst->y = av_clip(src->y, s->min_mv.y, s->max_mv.y);
+}
+
+static void find_ref_mvs(VP9Context *s,
+ VP56mv *pmv, int ref, int z, int idx, int sb)
+{
+ static const int8_t mv_ref_blk_off[N_BS_SIZES][8][2] = {
+ [BS_64x64] = {{ 3, -1 }, { -1, 3 }, { 4, -1 }, { -1, 4 },
+ { -1, -1 }, { 0, -1 }, { -1, 0 }, { 6, -1 }},
+ [BS_64x32] = {{ 0, -1 }, { -1, 0 }, { 4, -1 }, { -1, 2 },
+ { -1, -1 }, { 0, -3 }, { -3, 0 }, { 2, -1 }},
+ [BS_32x64] = {{ -1, 0 }, { 0, -1 }, { -1, 4 }, { 2, -1 },
+ { -1, -1 }, { -3, 0 }, { 0, -3 }, { -1, 2 }},
+ [BS_32x32] = {{ 1, -1 }, { -1, 1 }, { 2, -1 }, { -1, 2 },
+ { -1, -1 }, { 0, -3 }, { -3, 0 }, { -3, -3 }},
+ [BS_32x16] = {{ 0, -1 }, { -1, 0 }, { 2, -1 }, { -1, -1 },
+ { -1, 1 }, { 0, -3 }, { -3, 0 }, { -3, -3 }},
+ [BS_16x32] = {{ -1, 0 }, { 0, -1 }, { -1, 2 }, { -1, -1 },
+ { 1, -1 }, { -3, 0 }, { 0, -3 }, { -3, -3 }},
+ [BS_16x16] = {{ 0, -1 }, { -1, 0 }, { 1, -1 }, { -1, 1 },
+ { -1, -1 }, { 0, -3 }, { -3, 0 }, { -3, -3 }},
+ [BS_16x8] = {{ 0, -1 }, { -1, 0 }, { 1, -1 }, { -1, -1 },
+ { 0, -2 }, { -2, 0 }, { -2, -1 }, { -1, -2 }},
+ [BS_8x16] = {{ -1, 0 }, { 0, -1 }, { -1, 1 }, { -1, -1 },
+ { -2, 0 }, { 0, -2 }, { -1, -2 }, { -2, -1 }},
+ [BS_8x8] = {{ 0, -1 }, { -1, 0 }, { -1, -1 }, { 0, -2 },
+ { -2, 0 }, { -1, -2 }, { -2, -1 }, { -2, -2 }},
+ [BS_8x4] = {{ 0, -1 }, { -1, 0 }, { -1, -1 }, { 0, -2 },
+ { -2, 0 }, { -1, -2 }, { -2, -1 }, { -2, -2 }},
+ [BS_4x8] = {{ 0, -1 }, { -1, 0 }, { -1, -1 }, { 0, -2 },
+ { -2, 0 }, { -1, -2 }, { -2, -1 }, { -2, -2 }},
+ [BS_4x4] = {{ 0, -1 }, { -1, 0 }, { -1, -1 }, { 0, -2 },
+ { -2, 0 }, { -1, -2 }, { -2, -1 }, { -2, -2 }},
+ };
+ VP9Block *const b = &s->b;
+ int row = b->row, col = b->col, row7 = b->row7;
+ const int8_t (*p)[2] = mv_ref_blk_off[b->bs];
+#define INVALID_MV 0x80008000U
+ uint32_t mem = INVALID_MV;
+ int i;
+
+#define RETURN_DIRECT_MV(mv) \
+ do { \
+ uint32_t m = AV_RN32A(&mv); \
+ if (!idx) { \
+ AV_WN32A(pmv, m); \
+ return; \
+ } else if (mem == INVALID_MV) { \
+ mem = m; \
+ } else if (m != mem) { \
+ AV_WN32A(pmv, m); \
+ return; \
+ } \
+ } while (0)
+
+ if (sb >= 0) {
+ if (sb == 2 || sb == 1) {
+ RETURN_DIRECT_MV(b->mv[0][z]);
+ } else if (sb == 3) {
+ RETURN_DIRECT_MV(b->mv[2][z]);
+ RETURN_DIRECT_MV(b->mv[1][z]);
+ RETURN_DIRECT_MV(b->mv[0][z]);
+ }
+
+#define RETURN_MV(mv) \
+ do { \
+ if (sb > 0) { \
+ VP56mv tmp; \
+ uint32_t m; \
+ clamp_mv(&tmp, &mv, s); \
+ m = AV_RN32A(&tmp); \
+ if (!idx) { \
+ AV_WN32A(pmv, m); \
+ return; \
+ } else if (mem == INVALID_MV) { \
+ mem = m; \
+ } else if (m != mem) { \
+ AV_WN32A(pmv, m); \
+ return; \
+ } \
+ } else { \
+ uint32_t m = AV_RN32A(&mv); \
+ if (!idx) { \
+ clamp_mv(pmv, &mv, s); \
+ return; \
+ } else if (mem == INVALID_MV) { \
+ mem = m; \
+ } else if (m != mem) { \
+ clamp_mv(pmv, &mv, s); \
+ return; \
+ } \
+ } \
+ } while (0)
+
+ if (row > 0) {
+ struct VP9mvrefPair *mv = &s->mv[0][(row - 1) * s->sb_cols * 8 + col];
+ if (mv->ref[0] == ref) {
+ RETURN_MV(s->above_mv_ctx[2 * col + (sb & 1)][0]);
+ } else if (mv->ref[1] == ref) {
+ RETURN_MV(s->above_mv_ctx[2 * col + (sb & 1)][1]);
+ }
+ }
+ if (col > s->tiling.tile_col_start) {
+ struct VP9mvrefPair *mv = &s->mv[0][row * s->sb_cols * 8 + col - 1];
+ if (mv->ref[0] == ref) {
+ RETURN_MV(s->left_mv_ctx[2 * row7 + (sb >> 1)][0]);
+ } else if (mv->ref[1] == ref) {
+ RETURN_MV(s->left_mv_ctx[2 * row7 + (sb >> 1)][1]);
+ }
+ }
+ i = 2;
+ } else {
+ i = 0;
+ }
+
+ // previously coded MVs in this neighbourhood, using same reference frame
+ for (; i < 8; i++) {
+ int c = p[i][0] + col, r = p[i][1] + row;
+
+ if (c >= s->tiling.tile_col_start && c < s->cols && r >= 0 && r < s->rows) {
+ struct VP9mvrefPair *mv = &s->mv[0][r * s->sb_cols * 8 + c];
+
+ if (mv->ref[0] == ref) {
+ RETURN_MV(mv->mv[0]);
+ } else if (mv->ref[1] == ref) {
+ RETURN_MV(mv->mv[1]);
+ }
+ }
+ }
+
+ // MV at this position in previous frame, using same reference frame
+ if (s->use_last_frame_mvs) {
+ struct VP9mvrefPair *mv = &s->mv[1][row * s->sb_cols * 8 + col];
+
+ if (mv->ref[0] == ref) {
+ RETURN_MV(mv->mv[0]);
+ } else if (mv->ref[1] == ref) {
+ RETURN_MV(mv->mv[1]);
+ }
+ }
+
+#define RETURN_SCALE_MV(mv, scale) \
+ do { \
+ if (scale) { \
+ VP56mv mv_temp = { -mv.x, -mv.y }; \
+ RETURN_MV(mv_temp); \
+ } else { \
+ RETURN_MV(mv); \
+ } \
+ } while (0)
+
+ // previously coded MVs in this neighbourhood, using different reference frame
+ for (i = 0; i < 8; i++) {
+ int c = p[i][0] + col, r = p[i][1] + row;
+
+ if (c >= s->tiling.tile_col_start && c < s->cols && r >= 0 && r < s->rows) {
+ struct VP9mvrefPair *mv = &s->mv[0][r * s->sb_cols * 8 + c];
+
+ if (mv->ref[0] != ref && mv->ref[0] >= 0) {
+ RETURN_SCALE_MV(mv->mv[0], s->signbias[mv->ref[0]] != s->signbias[ref]);
+ }
+ if (mv->ref[1] != ref && mv->ref[1] >= 0) {
+ RETURN_SCALE_MV(mv->mv[1], s->signbias[mv->ref[1]] != s->signbias[ref]);
+ }
+ }
+ }
+
+ // MV at this position in previous frame, using different reference frame
+ if (s->use_last_frame_mvs) {
+ struct VP9mvrefPair *mv = &s->mv[1][row * s->sb_cols * 8 + col];
+
+ if (mv->ref[0] != ref && mv->ref[0] >= 0) {
+ RETURN_SCALE_MV(mv->mv[0], s->signbias[mv->ref[0]] != s->signbias[ref]);
+ }
+ if (mv->ref[1] != ref && mv->ref[1] >= 0) {
+ RETURN_SCALE_MV(mv->mv[1], s->signbias[mv->ref[1]] != s->signbias[ref]);
+ }
+ }
+
+ AV_ZERO32(pmv);
+#undef INVALID_MV
+#undef RETURN_MV
+#undef RETURN_SCALE_MV
+}
+
+static av_always_inline int read_mv_component(VP9Context *s, int idx, int hp)
+{
+ int bit, sign = vp56_rac_get_prob(&s->c, s->prob.p.mv_comp[idx].sign);
+ int n, c = vp8_rac_get_tree(&s->c, vp9_mv_class_tree,
+ s->prob.p.mv_comp[idx].classes);
+
+ s->counts.mv_comp[idx].sign[sign]++;
+ s->counts.mv_comp[idx].classes[c]++;
+ if (c) {
+ int m;
+
+ for (n = 0, m = 0; m < c; m++) {
+ bit = vp56_rac_get_prob(&s->c, s->prob.p.mv_comp[idx].bits[m]);
+ n |= bit << m;
+ s->counts.mv_comp[idx].bits[m][bit]++;
+ }
+ n <<= 3;
+ bit = vp8_rac_get_tree(&s->c, vp9_mv_fp_tree, s->prob.p.mv_comp[idx].fp);
+ n |= bit << 1;
+ s->counts.mv_comp[idx].fp[bit]++;
+ if (hp) {
+ bit = vp56_rac_get_prob(&s->c, s->prob.p.mv_comp[idx].hp);
+ s->counts.mv_comp[idx].hp[bit]++;
+ n |= bit;
+ } else {
+ n |= 1;
+ // bug in libvpx - we count for bw entropy purposes even if the
+ // bit wasn't coded
+ s->counts.mv_comp[idx].hp[1]++;
+ }
+ n += 8 << c;
+ } else {
+ n = vp56_rac_get_prob(&s->c, s->prob.p.mv_comp[idx].class0);
+ s->counts.mv_comp[idx].class0[n]++;
+ bit = vp8_rac_get_tree(&s->c, vp9_mv_fp_tree,
+ s->prob.p.mv_comp[idx].class0_fp[n]);
+ s->counts.mv_comp[idx].class0_fp[n][bit]++;
+ n = (n << 3) | (bit << 1);
+ if (hp) {
+ bit = vp56_rac_get_prob(&s->c, s->prob.p.mv_comp[idx].class0_hp);
+ s->counts.mv_comp[idx].class0_hp[bit]++;
+ n |= bit;
+ } else {
+ n |= 1;
+ // bug in libvpx - we count for bw entropy purposes even if the
+ // bit wasn't coded
+ s->counts.mv_comp[idx].class0_hp[1]++;
+ }
+ }
+
+ return sign ? -(n + 1) : (n + 1);
+}
+
+static void fill_mv(VP9Context *s,
+ VP56mv *mv, int mode, int sb)
+{
+ VP9Block *const b = &s->b;
+
+ if (mode == ZEROMV) {
+ memset(mv, 0, sizeof(*mv) * 2);
+ } else {
+ int hp;
+
+ // FIXME cache this value and reuse for other subblocks
+ find_ref_mvs(s, &mv[0], b->ref[0], 0, mode == NEARMV,
+ mode == NEWMV ? -1 : sb);
+ // FIXME maybe move this code into find_ref_mvs()
+ if ((mode == NEWMV || sb == -1) &&
+ !(hp = s->highprecisionmvs && abs(mv[0].x) < 64 && abs(mv[0].y) < 64)) {
+ if (mv[0].y & 1) {
+ if (mv[0].y < 0)
+ mv[0].y++;
+ else
+ mv[0].y--;
+ }
+ if (mv[0].x & 1) {
+ if (mv[0].x < 0)
+ mv[0].x++;
+ else
+ mv[0].x--;
+ }
+ }
+ if (mode == NEWMV) {
+ enum MVJoint j = vp8_rac_get_tree(&s->c, vp9_mv_joint_tree,
+ s->prob.p.mv_joint);
+
+ s->counts.mv_joint[j]++;
+ if (j >= MV_JOINT_V)
+ mv[0].y += read_mv_component(s, 0, hp);
+ if (j & 1)
+ mv[0].x += read_mv_component(s, 1, hp);
+ }
+
+ if (b->comp) {
+ // FIXME cache this value and reuse for other subblocks
+ find_ref_mvs(s, &mv[1], b->ref[1], 1, mode == NEARMV,
+ mode == NEWMV ? -1 : sb);
+ if ((mode == NEWMV || sb == -1) &&
+ !(hp = s->highprecisionmvs && abs(mv[1].x) < 64 && abs(mv[1].y) < 64)) {
+ if (mv[1].y & 1) {
+ if (mv[1].y < 0)
+ mv[1].y++;
+ else
+ mv[1].y--;
+ }
+ if (mv[1].x & 1) {
+ if (mv[1].x < 0)
+ mv[1].x++;
+ else
+ mv[1].x--;
+ }
+ }
+ if (mode == NEWMV) {
+ enum MVJoint j = vp8_rac_get_tree(&s->c, vp9_mv_joint_tree,
+ s->prob.p.mv_joint);
+
+ s->counts.mv_joint[j]++;
+ if (j >= MV_JOINT_V)
+ mv[1].y += read_mv_component(s, 0, hp);
+ if (j & 1)
+ mv[1].x += read_mv_component(s, 1, hp);
+ }
+ }
+ }
+}
+
+static void decode_mode(AVCodecContext *ctx)
+{
+ static const uint8_t left_ctx[N_BS_SIZES] = {
+ 0x0, 0x8, 0x0, 0x8, 0xc, 0x8, 0xc, 0xe, 0xc, 0xe, 0xf, 0xe, 0xf
+ };
+ static const uint8_t above_ctx[N_BS_SIZES] = {
+ 0x0, 0x0, 0x8, 0x8, 0x8, 0xc, 0xc, 0xc, 0xe, 0xe, 0xe, 0xf, 0xf
+ };
+ static const uint8_t max_tx_for_bl_bp[N_BS_SIZES] = {
+ TX_32X32, TX_32X32, TX_32X32, TX_32X32, TX_16X16, TX_16X16,
+ TX_16X16, TX_8X8, TX_8X8, TX_8X8, TX_4X4, TX_4X4, TX_4X4
+ };
+ VP9Context *s = ctx->priv_data;
+ VP9Block *const b = &s->b;
+ int row = b->row, col = b->col, row7 = b->row7;
+ enum TxfmMode max_tx = max_tx_for_bl_bp[b->bs];
+ int w4 = FFMIN(s->cols - col, bwh_tab[1][b->bs][0]);
+ int h4 = FFMIN(s->rows - row, bwh_tab[1][b->bs][1]), y;
+ int have_a = row > 0, have_l = col > s->tiling.tile_col_start;
+
+ if (!s->segmentation.enabled) {
+ b->seg_id = 0;
+ } else if (s->keyframe || s->intraonly) {
+ b->seg_id = s->segmentation.update_map ?
+ vp8_rac_get_tree(&s->c, vp9_segmentation_tree, s->prob.seg) : 0;
+ } else if (!s->segmentation.update_map ||
+ (s->segmentation.temporal &&
+ vp56_rac_get_prob_branchy(&s->c,
+ s->prob.segpred[s->above_segpred_ctx[col] +
+ s->left_segpred_ctx[row7]]))) {
+ int pred = 8, x;
+
+ for (y = 0; y < h4; y++)
+ for (x = 0; x < w4; x++)
+ pred = FFMIN(pred, s->segmentation_map[(y + row) * 8 * s->sb_cols + x + col]);
+ b->seg_id = pred;
+
+ memset(&s->above_segpred_ctx[col], 1, w4);
+ memset(&s->left_segpred_ctx[row7], 1, h4);
+ } else {
+ b->seg_id = vp8_rac_get_tree(&s->c, vp9_segmentation_tree,
+ s->prob.seg);
+
+ memset(&s->above_segpred_ctx[col], 0, w4);
+ memset(&s->left_segpred_ctx[row7], 0, h4);
+ }
+ if ((s->segmentation.enabled && s->segmentation.update_map) || s->keyframe) {
+ for (y = 0; y < h4; y++)
+ memset(&s->segmentation_map[(y + row) * 8 * s->sb_cols + col],
+ b->seg_id, w4);
+ }
+
+ b->skip = s->segmentation.enabled &&
+ s->segmentation.feat[b->seg_id].skip_enabled;
+ if (!b->skip) {
+ int c = s->left_skip_ctx[row7] + s->above_skip_ctx[col];
+ b->skip = vp56_rac_get_prob(&s->c, s->prob.p.skip[c]);
+ s->counts.skip[c][b->skip]++;
+ }
+
+ if (s->keyframe || s->intraonly) {
+ b->intra = 1;
+ } else if (s->segmentation.feat[b->seg_id].ref_enabled) {
+ b->intra = !s->segmentation.feat[b->seg_id].ref_val;
+ } else {
+ int c, bit;
+
+ if (have_a && have_l) {
+ c = s->above_intra_ctx[col] + s->left_intra_ctx[row7];
+ c += (c == 2);
+ } else {
+ c = have_a ? 2 * s->above_intra_ctx[col] :
+ have_l ? 2 * s->left_intra_ctx[row7] : 0;
+ }
+ bit = vp56_rac_get_prob(&s->c, s->prob.p.intra[c]);
+ s->counts.intra[c][bit]++;
+ b->intra = !bit;
+ }
+
+ if ((b->intra || !b->skip) && s->txfmmode == TX_SWITCHABLE) {
+ int c;
+ if (have_a) {
+ if (have_l) {
+ c = (s->above_skip_ctx[col] ? max_tx :
+ s->above_txfm_ctx[col]) +
+ (s->left_skip_ctx[row7] ? max_tx :
+ s->left_txfm_ctx[row7]) > max_tx;
+ } else {
+ c = s->above_skip_ctx[col] ? 1 :
+ (s->above_txfm_ctx[col] * 2 > max_tx);
+ }
+ } else if (have_l) {
+ c = s->left_skip_ctx[row7] ? 1 :
+ (s->left_txfm_ctx[row7] * 2 > max_tx);
+ } else {
+ c = 1;
+ }
+ switch (max_tx) {
+ case TX_32X32:
+ b->tx = vp56_rac_get_prob(&s->c, s->prob.p.tx32p[c][0]);
+ if (b->tx) {
+ b->tx += vp56_rac_get_prob(&s->c, s->prob.p.tx32p[c][1]);
+ if (b->tx == 2)
+ b->tx += vp56_rac_get_prob(&s->c, s->prob.p.tx32p[c][2]);
+ }
+ s->counts.tx32p[c][b->tx]++;
+ break;
+ case TX_16X16:
+ b->tx = vp56_rac_get_prob(&s->c, s->prob.p.tx16p[c][0]);
+ if (b->tx)
+ b->tx += vp56_rac_get_prob(&s->c, s->prob.p.tx16p[c][1]);
+ s->counts.tx16p[c][b->tx]++;
+ break;
+ case TX_8X8:
+ b->tx = vp56_rac_get_prob(&s->c, s->prob.p.tx8p[c]);
+ s->counts.tx8p[c][b->tx]++;
+ break;
+ case TX_4X4:
+ b->tx = TX_4X4;
+ break;
+ }
+ } else {
+ b->tx = FFMIN(max_tx, s->txfmmode);
+ }
+
+ if (s->keyframe || s->intraonly) {
+ uint8_t *a = &s->above_mode_ctx[col * 2];
+ uint8_t *l = &s->left_mode_ctx[(row7) << 1];
+
+ b->comp = 0;
+ if (b->bs > BS_8x8) {
+ // FIXME the memory storage intermediates here aren't really
+ // necessary, they're just there to make the code slightly
+ // simpler for now
+ b->mode[0] = a[0] = vp8_rac_get_tree(&s->c, vp9_intramode_tree,
+ vp9_default_kf_ymode_probs[a[0]][l[0]]);
+ if (b->bs != BS_8x4) {
+ b->mode[1] = vp8_rac_get_tree(&s->c, vp9_intramode_tree,
+ vp9_default_kf_ymode_probs[a[1]][b->mode[0]]);
+ l[0] = a[1] = b->mode[1];
+ } else {
+ l[0] = a[1] = b->mode[1] = b->mode[0];
+ }
+ if (b->bs != BS_4x8) {
+ b->mode[2] = a[0] = vp8_rac_get_tree(&s->c, vp9_intramode_tree,
+ vp9_default_kf_ymode_probs[a[0]][l[1]]);
+ if (b->bs != BS_8x4) {
+ b->mode[3] = vp8_rac_get_tree(&s->c, vp9_intramode_tree,
+ vp9_default_kf_ymode_probs[a[1]][b->mode[2]]);
+ l[1] = a[1] = b->mode[3];
+ } else {
+ l[1] = a[1] = b->mode[3] = b->mode[2];
+ }
+ } else {
+ b->mode[2] = b->mode[0];
+ l[1] = a[1] = b->mode[3] = b->mode[1];
+ }
+ } else {
+ b->mode[0] = vp8_rac_get_tree(&s->c, vp9_intramode_tree,
+ vp9_default_kf_ymode_probs[*a][*l]);
+ b->mode[3] = b->mode[2] = b->mode[1] = b->mode[0];
+ // FIXME this can probably be optimized
+ memset(a, b->mode[0], bwh_tab[0][b->bs][0]);
+ memset(l, b->mode[0], bwh_tab[0][b->bs][1]);
+ }
+ b->uvmode = vp8_rac_get_tree(&s->c, vp9_intramode_tree,
+ vp9_default_kf_uvmode_probs[b->mode[3]]);
+ } else if (b->intra) {
+ b->comp = 0;
+ if (b->bs > BS_8x8) {
+ b->mode[0] = vp8_rac_get_tree(&s->c, vp9_intramode_tree,
+ s->prob.p.y_mode[0]);
+ s->counts.y_mode[0][b->mode[0]]++;
+ if (b->bs != BS_8x4) {
+ b->mode[1] = vp8_rac_get_tree(&s->c, vp9_intramode_tree,
+ s->prob.p.y_mode[0]);
+ s->counts.y_mode[0][b->mode[1]]++;
+ } else {
+ b->mode[1] = b->mode[0];
+ }
+ if (b->bs != BS_4x8) {
+ b->mode[2] = vp8_rac_get_tree(&s->c, vp9_intramode_tree,
+ s->prob.p.y_mode[0]);
+ s->counts.y_mode[0][b->mode[2]]++;
+ if (b->bs != BS_8x4) {
+ b->mode[3] = vp8_rac_get_tree(&s->c, vp9_intramode_tree,
+ s->prob.p.y_mode[0]);
+ s->counts.y_mode[0][b->mode[3]]++;
+ } else {
+ b->mode[3] = b->mode[2];
+ }
+ } else {
+ b->mode[2] = b->mode[0];
+ b->mode[3] = b->mode[1];
+ }
+ } else {
+ static const uint8_t size_group[10] = {
+ 3, 3, 3, 3, 2, 2, 2, 1, 1, 1
+ };
+ int sz = size_group[b->bs];
+
+ b->mode[0] = vp8_rac_get_tree(&s->c, vp9_intramode_tree,
+ s->prob.p.y_mode[sz]);
+ b->mode[1] = b->mode[2] = b->mode[3] = b->mode[0];
+ s->counts.y_mode[sz][b->mode[3]]++;
+ }
+ b->uvmode = vp8_rac_get_tree(&s->c, vp9_intramode_tree,
+ s->prob.p.uv_mode[b->mode[3]]);
+ s->counts.uv_mode[b->mode[3]][b->uvmode]++;
+ } else {
+ static const uint8_t inter_mode_ctx_lut[14][14] = {
+ { 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
+ { 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
+ { 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
+ { 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
+ { 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
+ { 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
+ { 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
+ { 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
+ { 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
+ { 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5 },
+ { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 2, 2, 1, 3 },
+ { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 2, 2, 1, 3 },
+ { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 1, 1, 0, 3 },
+ { 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 3, 3, 3, 4 },
+ };
+
+ if (s->segmentation.feat[b->seg_id].ref_enabled) {
+ av_assert2(s->segmentation.feat[b->seg_id].ref_val != 0);
+ b->comp = 0;
+ b->ref[0] = s->segmentation.feat[b->seg_id].ref_val - 1;
+ } else {
+ // read comp_pred flag
+ if (s->comppredmode != PRED_SWITCHABLE) {
+ b->comp = s->comppredmode == PRED_COMPREF;
+ } else {
+ int c;
+
+ // FIXME add intra as ref=0xff (or -1) to make these easier?
+ if (have_a) {
+ if (have_l) {
+ if (s->above_comp_ctx[col] && s->left_comp_ctx[row7]) {
+ c = 4;
+ } else if (s->above_comp_ctx[col]) {
+ c = 2 + (s->left_intra_ctx[row7] ||
+ s->left_ref_ctx[row7] == s->fixcompref);
+ } else if (s->left_comp_ctx[row7]) {
+ c = 2 + (s->above_intra_ctx[col] ||
+ s->above_ref_ctx[col] == s->fixcompref);
+ } else {
+ c = (!s->above_intra_ctx[col] &&
+ s->above_ref_ctx[col] == s->fixcompref) ^
+ (!s->left_intra_ctx[row7] &&
+ s->left_ref_ctx[row & 7] == s->fixcompref);
+ }
+ } else {
+ c = s->above_comp_ctx[col] ? 3 :
+ (!s->above_intra_ctx[col] && s->above_ref_ctx[col] == s->fixcompref);
+ }
+ } else if (have_l) {
+ c = s->left_comp_ctx[row7] ? 3 :
+ (!s->left_intra_ctx[row7] && s->left_ref_ctx[row7] == s->fixcompref);
+ } else {
+ c = 1;
+ }
+ b->comp = vp56_rac_get_prob(&s->c, s->prob.p.comp[c]);
+ s->counts.comp[c][b->comp]++;
+ }
+
+ // read actual references
+ // FIXME probably cache a few variables here to prevent repetitive
+ // memory accesses below
+ if (b->comp) /* two references */ {
+ int fix_idx = s->signbias[s->fixcompref], var_idx = !fix_idx, c, bit;
+
+ b->ref[fix_idx] = s->fixcompref;
+ // FIXME can this codeblob be replaced by some sort of LUT?
+ if (have_a) {
+ if (have_l) {
+ if (s->above_intra_ctx[col]) {
+ if (s->left_intra_ctx[row7]) {
+ c = 2;
+ } else {
+ c = 1 + 2 * (s->left_ref_ctx[row7] != s->varcompref[1]);
+ }
+ } else if (s->left_intra_ctx[row7]) {
+ c = 1 + 2 * (s->above_ref_ctx[col] != s->varcompref[1]);
+ } else {
+ int refl = s->left_ref_ctx[row7], refa = s->above_ref_ctx[col];
+
+ if (refl == refa && refa == s->varcompref[1]) {
+ c = 0;
+ } else if (!s->left_comp_ctx[row7] && !s->above_comp_ctx[col]) {
+ if ((refa == s->fixcompref && refl == s->varcompref[0]) ||
+ (refl == s->fixcompref && refa == s->varcompref[0])) {
+ c = 4;
+ } else {
+ c = (refa == refl) ? 3 : 1;
+ }
+ } else if (!s->left_comp_ctx[row7]) {
+ if (refa == s->varcompref[1] && refl != s->varcompref[1]) {
+ c = 1;
+ } else {
+ c = (refl == s->varcompref[1] &&
+ refa != s->varcompref[1]) ? 2 : 4;
+ }
+ } else if (!s->above_comp_ctx[col]) {
+ if (refl == s->varcompref[1] && refa != s->varcompref[1]) {
+ c = 1;
+ } else {
+ c = (refa == s->varcompref[1] &&
+ refl != s->varcompref[1]) ? 2 : 4;
+ }
+ } else {
+ c = (refl == refa) ? 4 : 2;
+ }
+ }
+ } else {
+ if (s->above_intra_ctx[col]) {
+ c = 2;
+ } else if (s->above_comp_ctx[col]) {
+ c = 4 * (s->above_ref_ctx[col] != s->varcompref[1]);
+ } else {
+ c = 3 * (s->above_ref_ctx[col] != s->varcompref[1]);
+ }
+ }
+ } else if (have_l) {
+ if (s->left_intra_ctx[row7]) {
+ c = 2;
+ } else if (s->left_comp_ctx[row7]) {
+ c = 4 * (s->left_ref_ctx[row7] != s->varcompref[1]);
+ } else {
+ c = 3 * (s->left_ref_ctx[row7] != s->varcompref[1]);
+ }
+ } else {
+ c = 2;
+ }
+ bit = vp56_rac_get_prob(&s->c, s->prob.p.comp_ref[c]);
+ b->ref[var_idx] = s->varcompref[bit];
+ s->counts.comp_ref[c][bit]++;
+ } else /* single reference */ {
+ int bit, c;
+
+ if (have_a && !s->above_intra_ctx[col]) {
+ if (have_l && !s->left_intra_ctx[row7]) {
+ if (s->left_comp_ctx[row7]) {
+ if (s->above_comp_ctx[col]) {
+ c = 1 + (!s->fixcompref || !s->left_ref_ctx[row7] ||
+ !s->above_ref_ctx[col]);
+ } else {
+ c = (3 * !s->above_ref_ctx[col]) +
+ (!s->fixcompref || !s->left_ref_ctx[row7]);
+ }
+ } else if (s->above_comp_ctx[col]) {
+ c = (3 * !s->left_ref_ctx[row7]) +
+ (!s->fixcompref || !s->above_ref_ctx[col]);
+ } else {
+ c = 2 * !s->left_ref_ctx[row7] + 2 * !s->above_ref_ctx[col];
+ }
+ } else if (s->above_intra_ctx[col]) {
+ c = 2;
+ } else if (s->above_comp_ctx[col]) {
+ c = 1 + (!s->fixcompref || !s->above_ref_ctx[col]);
+ } else {
+ c = 4 * (!s->above_ref_ctx[col]);
+ }
+ } else if (have_l && !s->left_intra_ctx[row7]) {
+ if (s->left_intra_ctx[row7]) {
+ c = 2;
+ } else if (s->left_comp_ctx[row7]) {
+ c = 1 + (!s->fixcompref || !s->left_ref_ctx[row7]);
+ } else {
+ c = 4 * (!s->left_ref_ctx[row7]);
+ }
+ } else {
+ c = 2;
+ }
+ bit = vp56_rac_get_prob(&s->c, s->prob.p.single_ref[c][0]);
+ s->counts.single_ref[c][0][bit]++;
+ if (!bit) {
+ b->ref[0] = 0;
+ } else {
+ // FIXME can this codeblob be replaced by some sort of LUT?
+ if (have_a) {
+ if (have_l) {
+ if (s->left_intra_ctx[row7]) {
+ if (s->above_intra_ctx[col]) {
+ c = 2;
+ } else if (s->above_comp_ctx[col]) {
+ c = 1 + 2 * (s->fixcompref == 1 ||
+ s->above_ref_ctx[col] == 1);
+ } else if (!s->above_ref_ctx[col]) {
+ c = 3;
+ } else {
+ c = 4 * (s->above_ref_ctx[col] == 1);
+ }
+ } else if (s->above_intra_ctx[col]) {
+ if (s->left_intra_ctx[row7]) {
+ c = 2;
+ } else if (s->left_comp_ctx[row7]) {
+ c = 1 + 2 * (s->fixcompref == 1 ||
+ s->left_ref_ctx[row7] == 1);
+ } else if (!s->left_ref_ctx[row7]) {
+ c = 3;
+ } else {
+ c = 4 * (s->left_ref_ctx[row7] == 1);
+ }
+ } else if (s->above_comp_ctx[col]) {
+ if (s->left_comp_ctx[row7]) {
+ if (s->left_ref_ctx[row7] == s->above_ref_ctx[col]) {
+ c = 3 * (s->fixcompref == 1 ||
+ s->left_ref_ctx[row7] == 1);
+ } else {
+ c = 2;
+ }
+ } else if (!s->left_ref_ctx[row7]) {
+ c = 1 + 2 * (s->fixcompref == 1 ||
+ s->above_ref_ctx[col] == 1);
+ } else {
+ c = 3 * (s->left_ref_ctx[row7] == 1) +
+ (s->fixcompref == 1 || s->above_ref_ctx[col] == 1);
+ }
+ } else if (s->left_comp_ctx[row7]) {
+ if (!s->above_ref_ctx[col]) {
+ c = 1 + 2 * (s->fixcompref == 1 ||
+ s->left_ref_ctx[row7] == 1);
+ } else {
+ c = 3 * (s->above_ref_ctx[col] == 1) +
+ (s->fixcompref == 1 || s->left_ref_ctx[row7] == 1);
+ }
+ } else if (!s->above_ref_ctx[col]) {
+ if (!s->left_ref_ctx[row7]) {
+ c = 3;
+ } else {
+ c = 4 * (s->left_ref_ctx[row7] == 1);
+ }
+ } else if (!s->left_ref_ctx[row7]) {
+ c = 4 * (s->above_ref_ctx[col] == 1);
+ } else {
+ c = 2 * (s->left_ref_ctx[row7] == 1) +
+ 2 * (s->above_ref_ctx[col] == 1);
+ }
+ } else {
+ if (s->above_intra_ctx[col] ||
+ (!s->above_comp_ctx[col] && !s->above_ref_ctx[col])) {
+ c = 2;
+ } else if (s->above_comp_ctx[col]) {
+ c = 3 * (s->fixcompref == 1 || s->above_ref_ctx[col] == 1);
+ } else {
+ c = 4 * (s->above_ref_ctx[col] == 1);
+ }
+ }
+ } else if (have_l) {
+ if (s->left_intra_ctx[row7] ||
+ (!s->left_comp_ctx[row7] && !s->left_ref_ctx[row7])) {
+ c = 2;
+ } else if (s->left_comp_ctx[row7]) {
+ c = 3 * (s->fixcompref == 1 || s->left_ref_ctx[row7] == 1);
+ } else {
+ c = 4 * (s->left_ref_ctx[row7] == 1);
+ }
+ } else {
+ c = 2;
+ }
+ bit = vp56_rac_get_prob(&s->c, s->prob.p.single_ref[c][1]);
+ s->counts.single_ref[c][1][bit]++;
+ b->ref[0] = 1 + bit;
+ }
+ }
+ }
+
+ if (b->bs <= BS_8x8) {
+ if (s->segmentation.feat[b->seg_id].skip_enabled) {
+ b->mode[0] = b->mode[1] = b->mode[2] = b->mode[3] = ZEROMV;
+ } else {
+ static const uint8_t off[10] = {
+ 3, 0, 0, 1, 0, 0, 0, 0, 0, 0
+ };
+
+ // FIXME this needs to use the LUT tables from find_ref_mvs
+ // because not all are -1,0/0,-1
+ int c = inter_mode_ctx_lut[s->above_mode_ctx[col + off[b->bs]]]
+ [s->left_mode_ctx[row7 + off[b->bs]]];
+
+ b->mode[0] = vp8_rac_get_tree(&s->c, vp9_inter_mode_tree,
+ s->prob.p.mv_mode[c]);
+ b->mode[1] = b->mode[2] = b->mode[3] = b->mode[0];
+ s->counts.mv_mode[c][b->mode[0] - 10]++;
+ }
+ }
+
+ if (s->filtermode == FILTER_SWITCHABLE) {
+ int c;
+
+ if (have_a && s->above_mode_ctx[col] >= NEARESTMV) {
+ if (have_l && s->left_mode_ctx[row7] >= NEARESTMV) {
+ c = s->above_filter_ctx[col] == s->left_filter_ctx[row7] ?
+ s->left_filter_ctx[row7] : 3;
+ } else {
+ c = s->above_filter_ctx[col];
+ }
+ } else if (have_l && s->left_mode_ctx[row7] >= NEARESTMV) {
+ c = s->left_filter_ctx[row7];
+ } else {
+ c = 3;
+ }
+
+ b->filter = vp8_rac_get_tree(&s->c, vp9_filter_tree,
+ s->prob.p.filter[c]);
+ s->counts.filter[c][b->filter]++;
+ } else {
+ b->filter = s->filtermode;
+ }
+
+ if (b->bs > BS_8x8) {
+ int c = inter_mode_ctx_lut[s->above_mode_ctx[col]][s->left_mode_ctx[row7]];
+
+ b->mode[0] = vp8_rac_get_tree(&s->c, vp9_inter_mode_tree,
+ s->prob.p.mv_mode[c]);
+ s->counts.mv_mode[c][b->mode[0] - 10]++;
+ fill_mv(s, b->mv[0], b->mode[0], 0);
+
+ if (b->bs != BS_8x4) {
+ b->mode[1] = vp8_rac_get_tree(&s->c, vp9_inter_mode_tree,
+ s->prob.p.mv_mode[c]);
+ s->counts.mv_mode[c][b->mode[1] - 10]++;
+ fill_mv(s, b->mv[1], b->mode[1], 1);
+ } else {
+ b->mode[1] = b->mode[0];
+ AV_COPY32(&b->mv[1][0], &b->mv[0][0]);
+ AV_COPY32(&b->mv[1][1], &b->mv[0][1]);
+ }
+
+ if (b->bs != BS_4x8) {
+ b->mode[2] = vp8_rac_get_tree(&s->c, vp9_inter_mode_tree,
+ s->prob.p.mv_mode[c]);
+ s->counts.mv_mode[c][b->mode[2] - 10]++;
+ fill_mv(s, b->mv[2], b->mode[2], 2);
+
+ if (b->bs != BS_8x4) {
+ b->mode[3] = vp8_rac_get_tree(&s->c, vp9_inter_mode_tree,
+ s->prob.p.mv_mode[c]);
+ s->counts.mv_mode[c][b->mode[3] - 10]++;
+ fill_mv(s, b->mv[3], b->mode[3], 3);
+ } else {
+ b->mode[3] = b->mode[2];
+ AV_COPY32(&b->mv[3][0], &b->mv[2][0]);
+ AV_COPY32(&b->mv[3][1], &b->mv[2][1]);
+ }
+ } else {
+ b->mode[2] = b->mode[0];
+ AV_COPY32(&b->mv[2][0], &b->mv[0][0]);
+ AV_COPY32(&b->mv[2][1], &b->mv[0][1]);
+ b->mode[3] = b->mode[1];
+ AV_COPY32(&b->mv[3][0], &b->mv[1][0]);
+ AV_COPY32(&b->mv[3][1], &b->mv[1][1]);
+ }
+ } else {
+ fill_mv(s, b->mv[0], b->mode[0], -1);
+ AV_COPY32(&b->mv[1][0], &b->mv[0][0]);
+ AV_COPY32(&b->mv[2][0], &b->mv[0][0]);
+ AV_COPY32(&b->mv[3][0], &b->mv[0][0]);
+ AV_COPY32(&b->mv[1][1], &b->mv[0][1]);
+ AV_COPY32(&b->mv[2][1], &b->mv[0][1]);
+ AV_COPY32(&b->mv[3][1], &b->mv[0][1]);
+ }
+ }
+
+ // FIXME this can probably be optimized
+ memset(&s->above_skip_ctx[col], b->skip, w4);
+ memset(&s->left_skip_ctx[row7], b->skip, h4);
+ memset(&s->above_txfm_ctx[col], b->tx, w4);
+ memset(&s->left_txfm_ctx[row7], b->tx, h4);
+ memset(&s->above_partition_ctx[col], above_ctx[b->bs], w4);
+ memset(&s->left_partition_ctx[row7], left_ctx[b->bs], h4);
+ if (!s->keyframe && !s->intraonly) {
+ memset(&s->above_intra_ctx[col], b->intra, w4);
+ memset(&s->left_intra_ctx[row7], b->intra, h4);
+ memset(&s->above_comp_ctx[col], b->comp, w4);
+ memset(&s->left_comp_ctx[row7], b->comp, h4);
+ memset(&s->above_mode_ctx[col], b->mode[3], w4);
+ memset(&s->left_mode_ctx[row7], b->mode[3], h4);
+ if (s->filtermode == FILTER_SWITCHABLE && !b->intra ) {
+ memset(&s->above_filter_ctx[col], b->filter, w4);
+ memset(&s->left_filter_ctx[row7], b->filter, h4);
+ b->filter = vp9_filter_lut[b->filter];
+ }
+ if (b->bs > BS_8x8) {
+ int mv0 = AV_RN32A(&b->mv[3][0]), mv1 = AV_RN32A(&b->mv[3][1]);
+
+ AV_COPY32(&s->left_mv_ctx[row7 * 2 + 0][0], &b->mv[1][0]);
+ AV_COPY32(&s->left_mv_ctx[row7 * 2 + 0][1], &b->mv[1][1]);
+ AV_WN32A(&s->left_mv_ctx[row7 * 2 + 1][0], mv0);
+ AV_WN32A(&s->left_mv_ctx[row7 * 2 + 1][1], mv1);
+ AV_COPY32(&s->above_mv_ctx[col * 2 + 0][0], &b->mv[2][0]);
+ AV_COPY32(&s->above_mv_ctx[col * 2 + 0][1], &b->mv[2][1]);
+ AV_WN32A(&s->above_mv_ctx[col * 2 + 1][0], mv0);
+ AV_WN32A(&s->above_mv_ctx[col * 2 + 1][1], mv1);
+ } else {
+ int n, mv0 = AV_RN32A(&b->mv[3][0]), mv1 = AV_RN32A(&b->mv[3][1]);
+
+ for (n = 0; n < w4 * 2; n++) {
+ AV_WN32A(&s->above_mv_ctx[col * 2 + n][0], mv0);
+ AV_WN32A(&s->above_mv_ctx[col * 2 + n][1], mv1);
+ }
+ for (n = 0; n < h4 * 2; n++) {
+ AV_WN32A(&s->left_mv_ctx[row7 * 2 + n][0], mv0);
+ AV_WN32A(&s->left_mv_ctx[row7 * 2 + n][1], mv1);
+ }
+ }
+
+ if (!b->intra) { // FIXME write 0xff or -1 if intra, so we can use this
+ // as a direct check in above branches
+ int vref = b->ref[b->comp ? s->signbias[s->varcompref[0]] : 0];
+
+ memset(&s->above_ref_ctx[col], vref, w4);
+ memset(&s->left_ref_ctx[row7], vref, h4);
+ }
+ }
+
+ // FIXME kinda ugly
+ for (y = 0; y < h4; y++) {
+ int x, o = (row + y) * s->sb_cols * 8 + col;
+
+ if (b->intra) {
+ for (x = 0; x < w4; x++) {
+ s->mv[0][o + x].ref[0] =
+ s->mv[0][o + x].ref[1] = -1;
+ }
+ } else if (b->comp) {
+ for (x = 0; x < w4; x++) {
+ s->mv[0][o + x].ref[0] = b->ref[0];
+ s->mv[0][o + x].ref[1] = b->ref[1];
+ AV_COPY32(&s->mv[0][o + x].mv[0], &b->mv[3][0]);
+ AV_COPY32(&s->mv[0][o + x].mv[1], &b->mv[3][1]);
+ }
+ } else {
+ for (x = 0; x < w4; x++) {
+ s->mv[0][o + x].ref[0] = b->ref[0];
+ s->mv[0][o + x].ref[1] = -1;
+ AV_COPY32(&s->mv[0][o + x].mv[0], &b->mv[3][0]);
+ }
+ }
+ }
+}
+
+// FIXME remove tx argument, and merge cnt/eob arguments?
+static int decode_coeffs_b(VP56RangeCoder *c, int16_t *coef, int n_coeffs,
+ enum TxfmMode tx, unsigned (*cnt)[6][3],
+ unsigned (*eob)[6][2], uint8_t (*p)[6][11],
+ int nnz, const int16_t *scan, const int16_t (*nb)[2],
+ const int16_t *band_counts, const int16_t *qmul)
+{
+ int i = 0, band = 0, band_left = band_counts[band];
+ uint8_t *tp = p[0][nnz];
+ uint8_t cache[1024];
+
+ do {
+ int val, rc;
+
+ val = vp56_rac_get_prob_branchy(c, tp[0]); // eob
+ eob[band][nnz][val]++;
+ if (!val)
+ break;
+
+ skip_eob:
+ if (!vp56_rac_get_prob_branchy(c, tp[1])) { // zero
+ cnt[band][nnz][0]++;
+ if (!--band_left)
+ band_left = band_counts[++band];
+ cache[scan[i]] = 0;
+ nnz = (1 + cache[nb[i][0]] + cache[nb[i][1]]) >> 1;
+ tp = p[band][nnz];
+ if (++i == n_coeffs)
+ break; //invalid input; blocks should end with EOB
+ goto skip_eob;
+ }
+
+ rc = scan[i];
+ if (!vp56_rac_get_prob_branchy(c, tp[2])) { // one
+ cnt[band][nnz][1]++;
+ val = 1;
+ cache[rc] = 1;
+ } else {
+ // fill in p[3-10] (model fill) - only once per frame for each pos
+ if (!tp[3])
+ memcpy(&tp[3], vp9_model_pareto8[tp[2]], 8);
+
+ cnt[band][nnz][2]++;
+ if (!vp56_rac_get_prob_branchy(c, tp[3])) { // 2, 3, 4
+ if (!vp56_rac_get_prob_branchy(c, tp[4])) {
+ cache[rc] = val = 2;
+ } else {
+ val = 3 + vp56_rac_get_prob(c, tp[5]);
+ cache[rc] = 3;
+ }
+ } else if (!vp56_rac_get_prob_branchy(c, tp[6])) { // cat1/2
+ cache[rc] = 4;
+ if (!vp56_rac_get_prob_branchy(c, tp[7])) {
+ val = 5 + vp56_rac_get_prob(c, 159);
+ } else {
+ val = 7 + (vp56_rac_get_prob(c, 165) << 1) +
+ vp56_rac_get_prob(c, 145);
+ }
+ } else { // cat 3-6
+ cache[rc] = 5;
+ if (!vp56_rac_get_prob_branchy(c, tp[8])) {
+ if (!vp56_rac_get_prob_branchy(c, tp[9])) {
+ val = 11 + (vp56_rac_get_prob(c, 173) << 2) +
+ (vp56_rac_get_prob(c, 148) << 1) +
+ vp56_rac_get_prob(c, 140);
+ } else {
+ val = 19 + (vp56_rac_get_prob(c, 176) << 3) +
+ (vp56_rac_get_prob(c, 155) << 2) +
+ (vp56_rac_get_prob(c, 140) << 1) +
+ vp56_rac_get_prob(c, 135);
+ }
+ } else if (!vp56_rac_get_prob_branchy(c, tp[10])) {
+ val = 35 + (vp56_rac_get_prob(c, 180) << 4) +
+ (vp56_rac_get_prob(c, 157) << 3) +
+ (vp56_rac_get_prob(c, 141) << 2) +
+ (vp56_rac_get_prob(c, 134) << 1) +
+ vp56_rac_get_prob(c, 130);
+ } else {
+ val = 67 + (vp56_rac_get_prob(c, 254) << 13) +
+ (vp56_rac_get_prob(c, 254) << 12) +
+ (vp56_rac_get_prob(c, 254) << 11) +
+ (vp56_rac_get_prob(c, 252) << 10) +
+ (vp56_rac_get_prob(c, 249) << 9) +
+ (vp56_rac_get_prob(c, 243) << 8) +
+ (vp56_rac_get_prob(c, 230) << 7) +
+ (vp56_rac_get_prob(c, 196) << 6) +
+ (vp56_rac_get_prob(c, 177) << 5) +
+ (vp56_rac_get_prob(c, 153) << 4) +
+ (vp56_rac_get_prob(c, 140) << 3) +
+ (vp56_rac_get_prob(c, 133) << 2) +
+ (vp56_rac_get_prob(c, 130) << 1) +
+ vp56_rac_get_prob(c, 129);
+ }
+ }
+ }
+ if (!--band_left)
+ band_left = band_counts[++band];
+ if (tx == TX_32X32) // FIXME slow
+ coef[rc] = ((vp8_rac_get(c) ? -val : val) * qmul[!!i]) / 2;
+ else
+ coef[rc] = (vp8_rac_get(c) ? -val : val) * qmul[!!i];
+ nnz = (1 + cache[nb[i][0]] + cache[nb[i][1]]) >> 1;
+ tp = p[band][nnz];
+ } while (++i < n_coeffs);
+
+ return i;
+}
+
+static int decode_coeffs(AVCodecContext *ctx)
+{
+ VP9Context *s = ctx->priv_data;
+ VP9Block *const b = &s->b;
+ int row = b->row, col = b->col;
+ uint8_t (*p)[6][11] = s->prob.coef[b->tx][0 /* y */][!b->intra];
+ unsigned (*c)[6][3] = s->counts.coef[b->tx][0 /* y */][!b->intra];
+ unsigned (*e)[6][2] = s->counts.eob[b->tx][0 /* y */][!b->intra];
+ int w4 = bwh_tab[1][b->bs][0] << 1, h4 = bwh_tab[1][b->bs][1] << 1;
+ int end_x = FFMIN(2 * (s->cols - col), w4);
+ int end_y = FFMIN(2 * (s->rows - row), h4);
+ int n, pl, x, y, step1d = 1 << b->tx, step = 1 << (b->tx * 2);
+ int uvstep1d = 1 << b->uvtx, uvstep = 1 << (b->uvtx * 2), res;
+ int16_t (*qmul)[2] = s->segmentation.feat[b->seg_id].qmul;
+ int tx = 4 * s->lossless + b->tx;
+ const int16_t **yscans = vp9_scans[tx];
+ const int16_t (**ynbs)[2] = vp9_scans_nb[tx];
+ const int16_t *uvscan = vp9_scans[b->uvtx][DCT_DCT];
+ const int16_t (*uvnb)[2] = vp9_scans_nb[b->uvtx][DCT_DCT];
+ uint8_t *a = &s->above_y_nnz_ctx[col * 2];
+ uint8_t *l = &s->left_y_nnz_ctx[(row & 7) << 1];
+ static const int16_t band_counts[4][6] = {
+ { 1, 2, 3, 4, 3, 16 - 13 },
+ { 1, 2, 3, 4, 11, 64 - 21 },
+ { 1, 2, 3, 4, 11, 256 - 21 },
+ { 1, 2, 3, 4, 11, 1024 - 21 },
+ };
+ const int16_t *y_band_counts = band_counts[b->tx];
+ const int16_t *uv_band_counts = band_counts[b->uvtx];
+
+ /* y tokens */
+ if (b->tx > TX_4X4) { // FIXME slow
+ for (y = 0; y < end_y; y += step1d)
+ for (x = 1; x < step1d; x++)
+ l[y] |= l[y + x];
+ for (x = 0; x < end_x; x += step1d)
+ for (y = 1; y < step1d; y++)
+ a[x] |= a[x + y];
+ }
+ for (n = 0, y = 0; y < end_y; y += step1d) {
+ for (x = 0; x < end_x; x += step1d, n += step) {
+ enum TxfmType txtp = vp9_intra_txfm_type[b->mode[b->tx == TX_4X4 &&
+ b->bs > BS_8x8 ?
+ n : 0]];
+ int nnz = a[x] + l[y];
+ if ((res = decode_coeffs_b(&s->c, s->block + 16 * n, 16 * step,
+ b->tx, c, e, p, nnz, yscans[txtp],
+ ynbs[txtp], y_band_counts, qmul[0])) < 0)
+ return res;
+ a[x] = l[y] = !!res;
+ if (b->tx > TX_8X8) {
+ AV_WN16A(&s->eob[n], res);
+ } else {
+ s->eob[n] = res;
+ }
+ }
+ }
+ if (b->tx > TX_4X4) { // FIXME slow
+ for (y = 0; y < end_y; y += step1d)
+ memset(&l[y + 1], l[y], FFMIN(end_y - y - 1, step1d - 1));
+ for (x = 0; x < end_x; x += step1d)
+ memset(&a[x + 1], a[x], FFMIN(end_x - x - 1, step1d - 1));
+ }
+
+ p = s->prob.coef[b->uvtx][1 /* uv */][!b->intra];
+ c = s->counts.coef[b->uvtx][1 /* uv */][!b->intra];
+ e = s->counts.eob[b->uvtx][1 /* uv */][!b->intra];
+ w4 >>= 1;
+ h4 >>= 1;
+ end_x >>= 1;
+ end_y >>= 1;
+ for (pl = 0; pl < 2; pl++) {
+ a = &s->above_uv_nnz_ctx[pl][col];
+ l = &s->left_uv_nnz_ctx[pl][row & 7];
+ if (b->uvtx > TX_4X4) { // FIXME slow
+ for (y = 0; y < end_y; y += uvstep1d)
+ for (x = 1; x < uvstep1d; x++)
+ l[y] |= l[y + x];
+ for (x = 0; x < end_x; x += uvstep1d)
+ for (y = 1; y < uvstep1d; y++)
+ a[x] |= a[x + y];
+ }
+ for (n = 0, y = 0; y < end_y; y += uvstep1d) {
+ for (x = 0; x < end_x; x += uvstep1d, n += uvstep) {
+ int nnz = a[x] + l[y];
+ if ((res = decode_coeffs_b(&s->c, s->uvblock[pl] + 16 * n,
+ 16 * uvstep, b->uvtx, c, e, p, nnz,
+ uvscan, uvnb, uv_band_counts,
+ qmul[1])) < 0)
+ return res;
+ a[x] = l[y] = !!res;
+ if (b->uvtx > TX_8X8) {
+ AV_WN16A(&s->uveob[pl][n], res);
+ } else {
+ s->uveob[pl][n] = res;
+ }
+ }
+ }
+ if (b->uvtx > TX_4X4) { // FIXME slow
+ for (y = 0; y < end_y; y += uvstep1d)
+ memset(&l[y + 1], l[y], FFMIN(end_y - y - 1, uvstep1d - 1));
+ for (x = 0; x < end_x; x += uvstep1d)
+ memset(&a[x + 1], a[x], FFMIN(end_x - x - 1, uvstep1d - 1));
+ }
+ }
+
+ return 0;
+}
+
+static av_always_inline int check_intra_mode(VP9Context *s, int mode, uint8_t **a,
+ uint8_t *dst_edge, ptrdiff_t stride_edge,
+ uint8_t *dst_inner, ptrdiff_t stride_inner,
+ uint8_t *l, int col, int x, int w,
+ int row, int y, enum TxfmMode tx,
+ int p)
+{
+ int have_top = row > 0 || y > 0;
+ int have_left = col > s->tiling.tile_col_start || x > 0;
+ int have_right = x < w - 1;
+ static const uint8_t mode_conv[10][2 /* have_left */][2 /* have_top */] = {
+ [VERT_PRED] = { { DC_127_PRED, VERT_PRED },
+ { DC_127_PRED, VERT_PRED } },
+ [HOR_PRED] = { { DC_129_PRED, DC_129_PRED },
+ { HOR_PRED, HOR_PRED } },
+ [DC_PRED] = { { DC_128_PRED, TOP_DC_PRED },
+ { LEFT_DC_PRED, DC_PRED } },
+ [DIAG_DOWN_LEFT_PRED] = { { DC_127_PRED, DIAG_DOWN_LEFT_PRED },
+ { DC_127_PRED, DIAG_DOWN_LEFT_PRED } },
+ [DIAG_DOWN_RIGHT_PRED] = { { DIAG_DOWN_RIGHT_PRED, DIAG_DOWN_RIGHT_PRED },
+ { DIAG_DOWN_RIGHT_PRED, DIAG_DOWN_RIGHT_PRED } },
+ [VERT_RIGHT_PRED] = { { VERT_RIGHT_PRED, VERT_RIGHT_PRED },
+ { VERT_RIGHT_PRED, VERT_RIGHT_PRED } },
+ [HOR_DOWN_PRED] = { { HOR_DOWN_PRED, HOR_DOWN_PRED },
+ { HOR_DOWN_PRED, HOR_DOWN_PRED } },
+ [VERT_LEFT_PRED] = { { DC_127_PRED, VERT_LEFT_PRED },
+ { DC_127_PRED, VERT_LEFT_PRED } },
+ [HOR_UP_PRED] = { { DC_129_PRED, DC_129_PRED },
+ { HOR_UP_PRED, HOR_UP_PRED } },
+ [TM_VP8_PRED] = { { DC_129_PRED, VERT_PRED },
+ { HOR_PRED, TM_VP8_PRED } },
+ };
+ static const struct {
+ uint8_t needs_left:1;
+ uint8_t needs_top:1;
+ uint8_t needs_topleft:1;
+ uint8_t needs_topright:1;
+ } edges[N_INTRA_PRED_MODES] = {
+ [VERT_PRED] = { .needs_top = 1 },
+ [HOR_PRED] = { .needs_left = 1 },
+ [DC_PRED] = { .needs_top = 1, .needs_left = 1 },
+ [DIAG_DOWN_LEFT_PRED] = { .needs_top = 1, .needs_topright = 1 },
+ [DIAG_DOWN_RIGHT_PRED] = { .needs_left = 1, .needs_top = 1, .needs_topleft = 1 },
+ [VERT_RIGHT_PRED] = { .needs_left = 1, .needs_top = 1, .needs_topleft = 1 },
+ [HOR_DOWN_PRED] = { .needs_left = 1, .needs_top = 1, .needs_topleft = 1 },
+ [VERT_LEFT_PRED] = { .needs_top = 1, .needs_topright = 1 },
+ [HOR_UP_PRED] = { .needs_left = 1 },
+ [TM_VP8_PRED] = { .needs_left = 1, .needs_top = 1, .needs_topleft = 1 },
+ [LEFT_DC_PRED] = { .needs_left = 1 },
+ [TOP_DC_PRED] = { .needs_top = 1 },
+ [DC_128_PRED] = { 0 },
+ [DC_127_PRED] = { 0 },
+ [DC_129_PRED] = { 0 }
+ };
+
+ av_assert2(mode >= 0 && mode < 10);
+ mode = mode_conv[mode][have_left][have_top];
+ if (edges[mode].needs_top) {
+ uint8_t *top, *topleft;
+ int n_px_need = 4 << tx, n_px_have = (((s->cols - col) << !p) - x) * 4;
+ int n_px_need_tr = 0;
+
+ if (tx == TX_4X4 && edges[mode].needs_topright && have_right)
+ n_px_need_tr = 4;
+
+ // if top of sb64-row, use s->intra_pred_data[] instead of
+ // dst[-stride] for intra prediction (it contains pre- instead of
+ // post-loopfilter data)
+ if (have_top) {
+ top = !(row & 7) && !y ?
+ s->intra_pred_data[p] + col * (8 >> !!p) + x * 4 :
+ y == 0 ? &dst_edge[-stride_edge] : &dst_inner[-stride_inner];
+ if (have_left)
+ topleft = !(row & 7) && !y ?
+ s->intra_pred_data[p] + col * (8 >> !!p) + x * 4 :
+ y == 0 || x == 0 ? &dst_edge[-stride_edge] :
+ &dst_inner[-stride_inner];
+ }
+
+ if (have_top &&
+ (!edges[mode].needs_topleft || (have_left && top == topleft)) &&
+ (tx != TX_4X4 || !edges[mode].needs_topright || have_right) &&
+ n_px_need + n_px_need_tr <= n_px_have) {
+ *a = top;
+ } else {
+ if (have_top) {
+ if (n_px_need <= n_px_have) {
+ memcpy(*a, top, n_px_need);
+ } else {
+ memcpy(*a, top, n_px_have);
+ memset(&(*a)[n_px_have], (*a)[n_px_have - 1],
+ n_px_need - n_px_have);
+ }
+ } else {
+ memset(*a, 127, n_px_need);
+ }
+ if (edges[mode].needs_topleft) {
+ if (have_left && have_top) {
+ (*a)[-1] = topleft[-1];
+ } else {
+ (*a)[-1] = have_top ? 129 : 127;
+ }
+ }
+ if (tx == TX_4X4 && edges[mode].needs_topright) {
+ if (have_top && have_right &&
+ n_px_need + n_px_need_tr <= n_px_have) {
+ memcpy(&(*a)[4], &top[4], 4);
+ } else {
+ memset(&(*a)[4], (*a)[3], 4);
+ }
+ }
+ }
+ }
+ if (edges[mode].needs_left) {
+ if (have_left) {
+ int n_px_need = 4 << tx, i, n_px_have = (((s->rows - row) << !p) - y) * 4;
+ uint8_t *dst = x == 0 ? dst_edge : dst_inner;
+ ptrdiff_t stride = x == 0 ? stride_edge : stride_inner;
+
+ if (n_px_need <= n_px_have) {
+ for (i = 0; i < n_px_need; i++)
+ l[i] = dst[i * stride - 1];
+ } else {
+ for (i = 0; i < n_px_have; i++)
+ l[i] = dst[i * stride - 1];
+ memset(&l[i], l[i - 1], n_px_need - n_px_have);
+ }
+ } else {
+ memset(l, 129, 4 << tx);
+ }
+ }
+
+ return mode;
+}
+
+static void intra_recon(AVCodecContext *ctx, ptrdiff_t y_off, ptrdiff_t uv_off)
+{
+ VP9Context *s = ctx->priv_data;
+ VP9Block *const b = &s->b;
+ int row = b->row, col = b->col;
+ int w4 = bwh_tab[1][b->bs][0] << 1, step1d = 1 << b->tx, n;
+ int h4 = bwh_tab[1][b->bs][1] << 1, x, y, step = 1 << (b->tx * 2);
+ int end_x = FFMIN(2 * (s->cols - col), w4);
+ int end_y = FFMIN(2 * (s->rows - row), h4);
+ int tx = 4 * s->lossless + b->tx, uvtx = b->uvtx + 4 * s->lossless;
+ int uvstep1d = 1 << b->uvtx, p;
+ uint8_t *dst = b->dst[0], *dst_r = s->f->data[0] + y_off;
+
+ for (n = 0, y = 0; y < end_y; y += step1d) {
+ uint8_t *ptr = dst, *ptr_r = dst_r;
+ for (x = 0; x < end_x; x += step1d, ptr += 4 * step1d,
+ ptr_r += 4 * step1d, n += step) {
+ int mode = b->mode[b->bs > BS_8x8 && b->tx == TX_4X4 ?
+ y * 2 + x : 0];
+ LOCAL_ALIGNED_16(uint8_t, a_buf, [48]);
+ uint8_t *a = &a_buf[16], l[32];
+ enum TxfmType txtp = vp9_intra_txfm_type[mode];
+ int eob = b->tx > TX_8X8 ? AV_RN16A(&s->eob[n]) : s->eob[n];
+
+ mode = check_intra_mode(s, mode, &a, ptr_r, s->f->linesize[0],
+ ptr, b->y_stride, l,
+ col, x, w4, row, y, b->tx, 0);
+ s->dsp.intra_pred[b->tx][mode](ptr, b->y_stride, l, a);
+ if (eob)
+ s->dsp.itxfm_add[tx][txtp](ptr, b->y_stride,
+ s->block + 16 * n, eob);
+ }
+ dst_r += 4 * s->f->linesize[0] * step1d;
+ dst += 4 * b->y_stride * step1d;
+ }
+
+ // U/V
+ h4 >>= 1;
+ w4 >>= 1;
+ end_x >>= 1;
+ end_y >>= 1;
+ step = 1 << (b->uvtx * 2);
+ for (p = 0; p < 2; p++) {
+ dst = b->dst[1 + p];
+ dst_r = s->f->data[1 + p] + uv_off;
+ for (n = 0, y = 0; y < end_y; y += uvstep1d) {
+ uint8_t *ptr = dst, *ptr_r = dst_r;
+ for (x = 0; x < end_x; x += uvstep1d, ptr += 4 * uvstep1d,
+ ptr_r += 4 * uvstep1d, n += step) {
+ int mode = b->uvmode;
+ LOCAL_ALIGNED_16(uint8_t, a_buf, [48]);
+ uint8_t *a = &a_buf[16], l[32];
+ int eob = b->uvtx > TX_8X8 ? AV_RN16A(&s->uveob[p][n]) : s->uveob[p][n];
+
+ mode = check_intra_mode(s, mode, &a, ptr_r, s->f->linesize[1],
+ ptr, b->uv_stride, l,
+ col, x, w4, row, y, b->uvtx, p + 1);
+ s->dsp.intra_pred[b->uvtx][mode](ptr, b->uv_stride, l, a);
+ if (eob)
+ s->dsp.itxfm_add[uvtx][DCT_DCT](ptr, b->uv_stride,
+ s->uvblock[p] + 16 * n, eob);
+ }
+ dst_r += 4 * uvstep1d * s->f->linesize[1];
+ dst += 4 * uvstep1d * b->uv_stride;
+ }
+ }
+}
+
+static av_always_inline void mc_luma_dir(VP9Context *s, vp9_mc_func (*mc)[2],
+ uint8_t *dst, ptrdiff_t dst_stride,
+ const uint8_t *ref, ptrdiff_t ref_stride,
+ ptrdiff_t y, ptrdiff_t x, const VP56mv *mv,
+ int bw, int bh, int w, int h)
+{
+ int mx = mv->x, my = mv->y;
+
+ y += my >> 3;
+ x += mx >> 3;
+ ref += y * ref_stride + x;
+ mx &= 7;
+ my &= 7;
+ // FIXME bilinear filter only needs 0/1 pixels, not 3/4
+ if (x < !!mx * 3 || y < !!my * 3 ||
+ x + !!mx * 4 > w - bw || y + !!my * 4 > h - bh) {
+ s->vdsp.emulated_edge_mc(s->edge_emu_buffer, 80,
+ ref - !!my * 3 * ref_stride - !!mx * 3,
+ ref_stride,
+ bw + !!mx * 7, bh + !!my * 7,
+ x - !!mx * 3, y - !!my * 3, w, h);
+ ref = s->edge_emu_buffer + !!my * 3 * 80 + !!mx * 3;
+ ref_stride = 80;
+ }
+ mc[!!mx][!!my](dst, dst_stride, ref, ref_stride, bh, mx << 1, my << 1);
+}
+
+static av_always_inline void mc_chroma_dir(VP9Context *s, vp9_mc_func (*mc)[2],
+ uint8_t *dst_u, uint8_t *dst_v,
+ ptrdiff_t dst_stride,
+ const uint8_t *ref_u, ptrdiff_t src_stride_u,
+ const uint8_t *ref_v, ptrdiff_t src_stride_v,
+ ptrdiff_t y, ptrdiff_t x, const VP56mv *mv,
+ int bw, int bh, int w, int h)
+{
+ int mx = mv->x, my = mv->y;
+
+ y += my >> 4;
+ x += mx >> 4;
+ ref_u += y * src_stride_u + x;
+ ref_v += y * src_stride_v + x;
+ mx &= 15;
+ my &= 15;
+ // FIXME bilinear filter only needs 0/1 pixels, not 3/4
+ if (x < !!mx * 3 || y < !!my * 3 ||
+ x + !!mx * 4 > w - bw || y + !!my * 4 > h - bh) {
+ s->vdsp.emulated_edge_mc(s->edge_emu_buffer, 80,
+ ref_u - !!my * 3 * src_stride_u - !!mx * 3, src_stride_u,
+ bw + !!mx * 7, bh + !!my * 7,
+ x - !!mx * 3, y - !!my * 3, w, h);
+ ref_u = s->edge_emu_buffer + !!my * 3 * 80 + !!mx * 3;
+ mc[!!mx][!!my](dst_u, dst_stride, ref_u, 80, bh, mx, my);
+
+ s->vdsp.emulated_edge_mc(s->edge_emu_buffer, 80,
+ ref_v - !!my * 3 * src_stride_v - !!mx * 3, src_stride_v,
+ bw + !!mx * 7, bh + !!my * 7,
+ x - !!mx * 3, y - !!my * 3, w, h);
+ ref_v = s->edge_emu_buffer + !!my * 3 * 80 + !!mx * 3;
+ mc[!!mx][!!my](dst_v, dst_stride, ref_v, 80, bh, mx, my);
+ } else {
+ mc[!!mx][!!my](dst_u, dst_stride, ref_u, src_stride_u, bh, mx, my);
+ mc[!!mx][!!my](dst_v, dst_stride, ref_v, src_stride_v, bh, mx, my);
+ }
+}
+
+static void inter_recon(AVCodecContext *ctx)
+{
+ static const uint8_t bwlog_tab[2][N_BS_SIZES] = {
+ { 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4, 4 },
+ { 1, 1, 2, 2, 2, 3, 3, 3, 4, 4, 4, 4, 4 },
+ };
+ VP9Context *s = ctx->priv_data;
+ VP9Block *const b = &s->b;
+ int row = b->row, col = b->col;
+ AVFrame *ref1 = s->refs[s->refidx[b->ref[0]]];
+ AVFrame *ref2 = b->comp ? s->refs[s->refidx[b->ref[1]]] : NULL;
+ int w = ctx->width, h = ctx->height;
+ ptrdiff_t ls_y = b->y_stride, ls_uv = b->uv_stride;
+
+ // y inter pred
+ if (b->bs > BS_8x8) {
+ if (b->bs == BS_8x4) {
+ mc_luma_dir(s, s->dsp.mc[3][b->filter][0], b->dst[0], ls_y,
+ ref1->data[0], ref1->linesize[0],
+ row << 3, col << 3, &b->mv[0][0], 8, 4, w, h);
+ mc_luma_dir(s, s->dsp.mc[3][b->filter][0],
+ b->dst[0] + 4 * ls_y, ls_y,
+ ref1->data[0], ref1->linesize[0],
+ (row << 3) + 4, col << 3, &b->mv[2][0], 8, 4, w, h);
+
+ if (b->comp) {
+ mc_luma_dir(s, s->dsp.mc[3][b->filter][1], b->dst[0], ls_y,
+ ref2->data[0], ref2->linesize[0],
+ row << 3, col << 3, &b->mv[0][1], 8, 4, w, h);
+ mc_luma_dir(s, s->dsp.mc[3][b->filter][1],
+ b->dst[0] + 4 * ls_y, ls_y,
+ ref2->data[0], ref2->linesize[0],
+ (row << 3) + 4, col << 3, &b->mv[2][1], 8, 4, w, h);
+ }
+ } else if (b->bs == BS_4x8) {
+ mc_luma_dir(s, s->dsp.mc[4][b->filter][0], b->dst[0], ls_y,
+ ref1->data[0], ref1->linesize[0],
+ row << 3, col << 3, &b->mv[0][0], 4, 8, w, h);
+ mc_luma_dir(s, s->dsp.mc[4][b->filter][0], b->dst[0] + 4, ls_y,
+ ref1->data[0], ref1->linesize[0],
+ row << 3, (col << 3) + 4, &b->mv[1][0], 4, 8, w, h);
+
+ if (b->comp) {
+ mc_luma_dir(s, s->dsp.mc[4][b->filter][1], b->dst[0], ls_y,
+ ref2->data[0], ref2->linesize[0],
+ row << 3, col << 3, &b->mv[0][1], 4, 8, w, h);
+ mc_luma_dir(s, s->dsp.mc[4][b->filter][1], b->dst[0] + 4, ls_y,
+ ref2->data[0], ref2->linesize[0],
+ row << 3, (col << 3) + 4, &b->mv[1][1], 4, 8, w, h);
+ }
+ } else {
+ av_assert2(b->bs == BS_4x4);
+
+ // FIXME if two horizontally adjacent blocks have the same MV,
+ // do a w8 instead of a w4 call
+ mc_luma_dir(s, s->dsp.mc[4][b->filter][0], b->dst[0], ls_y,
+ ref1->data[0], ref1->linesize[0],
+ row << 3, col << 3, &b->mv[0][0], 4, 4, w, h);
+ mc_luma_dir(s, s->dsp.mc[4][b->filter][0], b->dst[0] + 4, ls_y,
+ ref1->data[0], ref1->linesize[0],
+ row << 3, (col << 3) + 4, &b->mv[1][0], 4, 4, w, h);
+ mc_luma_dir(s, s->dsp.mc[4][b->filter][0],
+ b->dst[0] + 4 * ls_y, ls_y,
+ ref1->data[0], ref1->linesize[0],
+ (row << 3) + 4, col << 3, &b->mv[2][0], 4, 4, w, h);
+ mc_luma_dir(s, s->dsp.mc[4][b->filter][0],
+ b->dst[0] + 4 * ls_y + 4, ls_y,
+ ref1->data[0], ref1->linesize[0],
+ (row << 3) + 4, (col << 3) + 4, &b->mv[3][0], 4, 4, w, h);
+
+ if (b->comp) {
+ mc_luma_dir(s, s->dsp.mc[4][b->filter][1], b->dst[0], ls_y,
+ ref2->data[0], ref2->linesize[0],
+ row << 3, col << 3, &b->mv[0][1], 4, 4, w, h);
+ mc_luma_dir(s, s->dsp.mc[4][b->filter][1], b->dst[0] + 4, ls_y,
+ ref2->data[0], ref2->linesize[0],
+ row << 3, (col << 3) + 4, &b->mv[1][1], 4, 4, w, h);
+ mc_luma_dir(s, s->dsp.mc[4][b->filter][1],
+ b->dst[0] + 4 * ls_y, ls_y,
+ ref2->data[0], ref2->linesize[0],
+ (row << 3) + 4, col << 3, &b->mv[2][1], 4, 4, w, h);
+ mc_luma_dir(s, s->dsp.mc[4][b->filter][1],
+ b->dst[0] + 4 * ls_y + 4, ls_y,
+ ref2->data[0], ref2->linesize[0],
+ (row << 3) + 4, (col << 3) + 4, &b->mv[3][1], 4, 4, w, h);
+ }
+ }
+ } else {
+ int bwl = bwlog_tab[0][b->bs];
+ int bw = bwh_tab[0][b->bs][0] * 4, bh = bwh_tab[0][b->bs][1] * 4;
+
+ mc_luma_dir(s, s->dsp.mc[bwl][b->filter][0], b->dst[0], ls_y,
+ ref1->data[0], ref1->linesize[0],
+ row << 3, col << 3, &b->mv[0][0],bw, bh, w, h);
+
+ if (b->comp)
+ mc_luma_dir(s, s->dsp.mc[bwl][b->filter][1], b->dst[0], ls_y,
+ ref2->data[0], ref2->linesize[0],
+ row << 3, col << 3, &b->mv[0][1], bw, bh, w, h);
+ }
+
+ // uv inter pred
+ {
+ int bwl = bwlog_tab[1][b->bs];
+ int bw = bwh_tab[1][b->bs][0] * 4, bh = bwh_tab[1][b->bs][1] * 4;
+ VP56mv mvuv;
+
+ w = (w + 1) >> 1;
+ h = (h + 1) >> 1;
+ if (b->bs > BS_8x8) {
+ mvuv.x = ROUNDED_DIV(b->mv[0][0].x + b->mv[1][0].x + b->mv[2][0].x + b->mv[3][0].x, 4);
+ mvuv.y = ROUNDED_DIV(b->mv[0][0].y + b->mv[1][0].y + b->mv[2][0].y + b->mv[3][0].y, 4);
+ } else {
+ mvuv = b->mv[0][0];
+ }
+
+ mc_chroma_dir(s, s->dsp.mc[bwl][b->filter][0],
+ b->dst[1], b->dst[2], ls_uv,
+ ref1->data[1], ref1->linesize[1],
+ ref1->data[2], ref1->linesize[2],
+ row << 2, col << 2, &mvuv, bw, bh, w, h);
+
+ if (b->comp) {
+ if (b->bs > BS_8x8) {
+ mvuv.x = ROUNDED_DIV(b->mv[0][1].x + b->mv[1][1].x + b->mv[2][1].x + b->mv[3][1].x, 4);
+ mvuv.y = ROUNDED_DIV(b->mv[0][1].y + b->mv[1][1].y + b->mv[2][1].y + b->mv[3][1].y, 4);
+ } else {
+ mvuv = b->mv[0][1];
+ }
+ mc_chroma_dir(s, s->dsp.mc[bwl][b->filter][1],
+ b->dst[1], b->dst[2], ls_uv,
+ ref2->data[1], ref2->linesize[1],
+ ref2->data[2], ref2->linesize[2],
+ row << 2, col << 2, &mvuv, bw, bh, w, h);
+ }
+ }
+
+ if (!b->skip) {
+ /* mostly copied intra_reconn() */
+
+ int w4 = bwh_tab[1][b->bs][0] << 1, step1d = 1 << b->tx, n;
+ int h4 = bwh_tab[1][b->bs][1] << 1, x, y, step = 1 << (b->tx * 2);
+ int end_x = FFMIN(2 * (s->cols - col), w4);
+ int end_y = FFMIN(2 * (s->rows - row), h4);
+ int tx = 4 * s->lossless + b->tx, uvtx = b->uvtx + 4 * s->lossless;
+ int uvstep1d = 1 << b->uvtx, p;
+ uint8_t *dst = b->dst[0];
+
+ // y itxfm add
+ for (n = 0, y = 0; y < end_y; y += step1d) {
+ uint8_t *ptr = dst;
+ for (x = 0; x < end_x; x += step1d, ptr += 4 * step1d, n += step) {
+ int eob = b->tx > TX_8X8 ? AV_RN16A(&s->eob[n]) : s->eob[n];
+
+ if (eob)
+ s->dsp.itxfm_add[tx][DCT_DCT](ptr, b->y_stride,
+ s->block + 16 * n, eob);
+ }
+ dst += 4 * b->y_stride * step1d;
+ }
+
+ // uv itxfm add
+ h4 >>= 1;
+ w4 >>= 1;
+ end_x >>= 1;
+ end_y >>= 1;
+ step = 1 << (b->uvtx * 2);
+ for (p = 0; p < 2; p++) {
+ dst = b->dst[p + 1];
+ for (n = 0, y = 0; y < end_y; y += uvstep1d) {
+ uint8_t *ptr = dst;
+ for (x = 0; x < end_x; x += uvstep1d, ptr += 4 * uvstep1d, n += step) {
+ int eob = b->uvtx > TX_8X8 ? AV_RN16A(&s->uveob[p][n]) : s->uveob[p][n];
+
+ if (eob)
+ s->dsp.itxfm_add[uvtx][DCT_DCT](ptr, b->uv_stride,
+ s->uvblock[p] + 16 * n, eob);
+ }
+ dst += 4 * uvstep1d * b->uv_stride;
+ }
+ }
+ }
+}
+
+static av_always_inline void mask_edges(struct VP9Filter *lflvl, int is_uv,
+ int row_and_7, int col_and_7,
+ int w, int h, int col_end, int row_end,
+ enum TxfmMode tx, int skip_inter)
+{
+ // FIXME I'm pretty sure all loops can be replaced by a single LUT if
+ // we make VP9Filter.mask uint64_t (i.e. row/col all single variable)
+ // and make the LUT 5-indexed (bl, bp, is_uv, tx and row/col), and then
+ // use row_and_7/col_and_7 as shifts (1*col_and_7+8*row_and_7)
+
+ // the intended behaviour of the vp9 loopfilter is to work on 8-pixel
+ // edges. This means that for UV, we work on two subsampled blocks at
+ // a time, and we only use the topleft block's mode information to set
+ // things like block strength. Thus, for any block size smaller than
+ // 16x16, ignore the odd portion of the block.
+ if (tx == TX_4X4 && is_uv) {
+ if (h == 1) {
+ if (row_and_7 & 1)
+ return;
+ if (!row_end)
+ h += 1;
+ }
+ if (w == 1) {
+ if (col_and_7 & 1)
+ return;
+ if (!col_end)
+ w += 1;
+ }
+ }
+
+ if (tx == TX_4X4 && !skip_inter) {
+ int t = 1 << col_and_7, m_col = (t << w) - t, y;
+ int m_col_odd = (t << (w - 1)) - t;
+
+ // on 32-px edges, use the 8-px wide loopfilter; else, use 4-px wide
+ if (is_uv) {
+ int m_row_8 = m_col & 0x01, m_row_4 = m_col - m_row_8;
+
+ for (y = row_and_7; y < h + row_and_7; y++) {
+ int col_mask_id = 2 - !(y & 7);
+
+ lflvl->mask[is_uv][0][y][1] |= m_row_8;
+ lflvl->mask[is_uv][0][y][2] |= m_row_4;
+ // for odd lines, if the odd col is not being filtered,
+ // skip odd row also:
+ // .---. <-- a
+ // | |
+ // |___| <-- b
+ // ^ ^
+ // c d
+ //
+ // if a/c are even row/col and b/d are odd, and d is skipped,
+ // e.g. right edge of size-66x66.webm, then skip b also (bug)
+ if ((col_end & 1) && (y & 1)) {
+ lflvl->mask[is_uv][1][y][col_mask_id] |= m_col_odd;
+ } else {
+ lflvl->mask[is_uv][1][y][col_mask_id] |= m_col;
+ }
+ }
+ } else {
+ int m_row_8 = m_col & 0x11, m_row_4 = m_col - m_row_8;
+
+ for (y = row_and_7; y < h + row_and_7; y++) {
+ int col_mask_id = 2 - !(y & 3);
+
+ lflvl->mask[is_uv][0][y][1] |= m_row_8; // row edge
+ lflvl->mask[is_uv][0][y][2] |= m_row_4;
+ lflvl->mask[is_uv][1][y][col_mask_id] |= m_col; // col edge
+ lflvl->mask[is_uv][0][y][3] |= m_col;
+ lflvl->mask[is_uv][1][y][3] |= m_col;
+ }
+ }
+ } else {
+ int y, t = 1 << col_and_7, m_col = (t << w) - t;
+
+ if (!skip_inter) {
+ int mask_id = (tx == TX_8X8);
+ int l2 = tx + is_uv - 1, step1d = 1 << l2;
+ static const unsigned masks[4] = { 0xff, 0x55, 0x11, 0x01 };
+ int m_row = m_col & masks[l2];
+
+ // at odd UV col/row edges tx16/tx32 loopfilter edges, force
+ // 8wd loopfilter to prevent going off the visible edge.
+ if (is_uv && tx > TX_8X8 && (w ^ (w - 1)) == 1) {
+ int m_row_16 = ((t << (w - 1)) - t) & masks[l2];
+ int m_row_8 = m_row - m_row_16;
+
+ for (y = row_and_7; y < h + row_and_7; y++) {
+ lflvl->mask[is_uv][0][y][0] |= m_row_16;
+ lflvl->mask[is_uv][0][y][1] |= m_row_8;
+ }
+ } else {
+ for (y = row_and_7; y < h + row_and_7; y++)
+ lflvl->mask[is_uv][0][y][mask_id] |= m_row;
+ }
+
+ if (is_uv && tx > TX_8X8 && (h ^ (h - 1)) == 1) {
+ for (y = row_and_7; y < h + row_and_7 - 1; y += step1d)
+ lflvl->mask[is_uv][1][y][0] |= m_col;
+ if (y - row_and_7 == h - 1)
+ lflvl->mask[is_uv][1][y][1] |= m_col;
+ } else {
+ for (y = row_and_7; y < h + row_and_7; y += step1d)
+ lflvl->mask[is_uv][1][y][mask_id] |= m_col;
+ }
+ } else if (tx != TX_4X4) {
+ int mask_id;
+
+ mask_id = (tx == TX_8X8) || (is_uv && h == 1);
+ lflvl->mask[is_uv][1][row_and_7][mask_id] |= m_col;
+ mask_id = (tx == TX_8X8) || (is_uv && w == 1);
+ for (y = row_and_7; y < h + row_and_7; y++)
+ lflvl->mask[is_uv][0][y][mask_id] |= t;
+ } else if (is_uv) {
+ int t8 = t & 0x01, t4 = t - t8;
+
+ for (y = row_and_7; y < h + row_and_7; y++) {
+ lflvl->mask[is_uv][0][y][2] |= t4;
+ lflvl->mask[is_uv][0][y][1] |= t8;
+ }
+ lflvl->mask[is_uv][1][row_and_7][2 - !(row_and_7 & 7)] |= m_col;
+ } else {
+ int t8 = t & 0x11, t4 = t - t8;
+
+ for (y = row_and_7; y < h + row_and_7; y++) {
+ lflvl->mask[is_uv][0][y][2] |= t4;
+ lflvl->mask[is_uv][0][y][1] |= t8;
+ }
+ lflvl->mask[is_uv][1][row_and_7][2 - !(row_and_7 & 3)] |= m_col;
+ }
+ }
+}
+
+static int decode_b(AVCodecContext *ctx, int row, int col,
+ struct VP9Filter *lflvl, ptrdiff_t yoff, ptrdiff_t uvoff,
+ enum BlockLevel bl, enum BlockPartition bp)
+{
+ VP9Context *s = ctx->priv_data;
+ VP9Block *const b = &s->b;
+ enum BlockSize bs = bl * 3 + bp;
+ int res, y, w4 = bwh_tab[1][bs][0], h4 = bwh_tab[1][bs][1], lvl;
+ int emu[2];
+
+ b->row = row;
+ b->row7 = row & 7;
+ b->col = col;
+ b->col7 = col & 7;
+ s->min_mv.x = -(128 + col * 64);
+ s->min_mv.y = -(128 + row * 64);
+ s->max_mv.x = 128 + (s->cols - col - w4) * 64;
+ s->max_mv.y = 128 + (s->rows - row - h4) * 64;
+ b->bs = bs;
+ decode_mode(ctx);
+ b->uvtx = b->tx - (w4 * 2 == (1 << b->tx) || h4 * 2 == (1 << b->tx));
+
+ if (!b->skip) {
+ if ((res = decode_coeffs(ctx)) < 0)
+ return res;
+ } else {
+ int pl;
+
+ memset(&s->above_y_nnz_ctx[col * 2], 0, w4 * 2);
+ memset(&s->left_y_nnz_ctx[(row & 7) << 1], 0, h4 * 2);
+ for (pl = 0; pl < 2; pl++) {
+ memset(&s->above_uv_nnz_ctx[pl][col], 0, w4);
+ memset(&s->left_uv_nnz_ctx[pl][row & 7], 0, h4);
+ }
+ }
+
+ // emulated overhangs if the stride of the target buffer can't hold. This
+ // allows to support emu-edge and so on even if we have large block
+ // overhangs
+ emu[0] = (col + w4) * 8 > s->f->linesize[0] ||
+ (row + h4) > s->rows + 2 * !(ctx->flags & CODEC_FLAG_EMU_EDGE);
+ emu[1] = (col + w4) * 4 > s->f->linesize[1] ||
+ (row + h4) > s->rows + 2 * !(ctx->flags & CODEC_FLAG_EMU_EDGE);
+ if (emu[0]) {
+ b->dst[0] = s->tmp_y;
+ b->y_stride = 64;
+ } else {
+ b->dst[0] = s->f->data[0] + yoff;
+ b->y_stride = s->f->linesize[0];
+ }
+ if (emu[1]) {
+ b->dst[1] = s->tmp_uv[0];
+ b->dst[2] = s->tmp_uv[1];
+ b->uv_stride = 32;
+ } else {
+ b->dst[1] = s->f->data[1] + uvoff;
+ b->dst[2] = s->f->data[2] + uvoff;
+ b->uv_stride = s->f->linesize[1];
+ }
+ if (b->intra) {
+ intra_recon(ctx, yoff, uvoff);
+ } else {
+ inter_recon(ctx);
+ }
+ if (emu[0]) {
+ int w = FFMIN(s->cols - col, w4) * 8, h = FFMIN(s->rows - row, h4) * 8, n, o = 0;
+
+ for (n = 0; o < w; n++) {
+ int bw = 64 >> n;
+
+ av_assert2(n <= 4);
+ if (w & bw) {
+ s->dsp.mc[n][0][0][0][0](s->f->data[0] + yoff + o, s->f->linesize[0],
+ s->tmp_y + o, 64, h, 0, 0);
+ o += bw;
+ }
+ }
+ }
+ if (emu[1]) {
+ int w = FFMIN(s->cols - col, w4) * 4, h = FFMIN(s->rows - row, h4) * 4, n, o = 0;
+
+ for (n = 1; o < w; n++) {
+ int bw = 64 >> n;
+
+ av_assert2(n <= 4);
+ if (w & bw) {
+ s->dsp.mc[n][0][0][0][0](s->f->data[1] + uvoff + o, s->f->linesize[1],
+ s->tmp_uv[0] + o, 32, h, 0, 0);
+ s->dsp.mc[n][0][0][0][0](s->f->data[2] + uvoff + o, s->f->linesize[2],
+ s->tmp_uv[1] + o, 32, h, 0, 0);
+ o += bw;
+ }
+ }
+ }
+
+ // pick filter level and find edges to apply filter to
+ if (s->filter.level &&
+ (lvl = s->segmentation.feat[b->seg_id].lflvl[b->intra ? 0 : b->ref[0] + 1]
+ [b->mode[3] != ZEROMV]) > 0) {
+ int x_end = FFMIN(s->cols - col, w4), y_end = FFMIN(s->rows - row, h4);
+ int skip_inter = !b->intra && b->skip;
+
+ for (y = 0; y < h4; y++)
+ memset(&lflvl->level[((row & 7) + y) * 8 + (col & 7)], lvl, w4);
+ mask_edges(lflvl, 0, row & 7, col & 7, x_end, y_end, 0, 0, b->tx, skip_inter);
+ mask_edges(lflvl, 1, row & 7, col & 7, x_end, y_end,
+ s->cols & 1 && col + w4 >= s->cols ? s->cols & 7 : 0,
+ s->rows & 1 && row + h4 >= s->rows ? s->rows & 7 : 0,
+ b->uvtx, skip_inter);
+
+ if (!s->filter.lim_lut[lvl]) {
+ int sharp = s->filter.sharpness;
+ int limit = lvl;
+
+ if (sharp > 0) {
+ limit >>= (sharp + 3) >> 2;
+ limit = FFMIN(limit, 9 - sharp);
+ }
+ limit = FFMAX(limit, 1);
+
+ s->filter.lim_lut[lvl] = limit;
+ s->filter.mblim_lut[lvl] = 2 * (lvl + 2) + limit;
+ }
+ }
+
+ return 0;
+}
+
+static int decode_sb(AVCodecContext *ctx, int row, int col, struct VP9Filter *lflvl,
+ ptrdiff_t yoff, ptrdiff_t uvoff, enum BlockLevel bl)
+{
+ VP9Context *s = ctx->priv_data;
+ int c = ((s->above_partition_ctx[col] >> (3 - bl)) & 1) |
+ (((s->left_partition_ctx[row & 0x7] >> (3 - bl)) & 1) << 1), res;
+ const uint8_t *p = s->keyframe ? vp9_default_kf_partition_probs[bl][c] :
+ s->prob.p.partition[bl][c];
+ enum BlockPartition bp;
+ ptrdiff_t hbs = 4 >> bl;
+
+ if (bl == BL_8X8) {
+ bp = vp8_rac_get_tree(&s->c, vp9_partition_tree, p);
+ res = decode_b(ctx, row, col, lflvl, yoff, uvoff, bl, bp);
+ } else if (col + hbs < s->cols) {
+ if (row + hbs < s->rows) {
+ bp = vp8_rac_get_tree(&s->c, vp9_partition_tree, p);
+ switch (bp) {
+ case PARTITION_NONE:
+ res = decode_b(ctx, row, col, lflvl, yoff, uvoff, bl, bp);
+ break;
+ case PARTITION_H:
+ if (!(res = decode_b(ctx, row, col, lflvl, yoff, uvoff, bl, bp))) {
+ yoff += hbs * 8 * s->f->linesize[0];
+ uvoff += hbs * 4 * s->f->linesize[1];
+ res = decode_b(ctx, row + hbs, col, lflvl, yoff, uvoff, bl, bp);
+ }
+ break;
+ case PARTITION_V:
+ if (!(res = decode_b(ctx, row, col, lflvl, yoff, uvoff, bl, bp))) {
+ yoff += hbs * 8;
+ uvoff += hbs * 4;
+ res = decode_b(ctx, row, col + hbs, lflvl, yoff, uvoff, bl, bp);
+ }
+ break;
+ case PARTITION_SPLIT:
+ if (!(res = decode_sb(ctx, row, col, lflvl, yoff, uvoff, bl + 1))) {
+ if (!(res = decode_sb(ctx, row, col + hbs, lflvl,
+ yoff + 8 * hbs, uvoff + 4 * hbs, bl + 1))) {
+ yoff += hbs * 8 * s->f->linesize[0];
+ uvoff += hbs * 4 * s->f->linesize[1];
+ if (!(res = decode_sb(ctx, row + hbs, col, lflvl,
+ yoff, uvoff, bl + 1)))
+ res = decode_sb(ctx, row + hbs, col + hbs, lflvl,
+ yoff + 8 * hbs, uvoff + 4 * hbs, bl + 1);
+ }
+ }
+ break;
+ }
+ } else if (vp56_rac_get_prob_branchy(&s->c, p[1])) {
+ bp = PARTITION_SPLIT;
+ if (!(res = decode_sb(ctx, row, col, lflvl, yoff, uvoff, bl + 1)))
+ res = decode_sb(ctx, row, col + hbs, lflvl,
+ yoff + 8 * hbs, uvoff + 4 * hbs, bl + 1);
+ } else {
+ bp = PARTITION_H;
+ res = decode_b(ctx, row, col, lflvl, yoff, uvoff, bl, bp);
+ }
+ } else if (row + hbs < s->rows) {
+ if (vp56_rac_get_prob_branchy(&s->c, p[2])) {
+ bp = PARTITION_SPLIT;
+ if (!(res = decode_sb(ctx, row, col, lflvl, yoff, uvoff, bl + 1))) {
+ yoff += hbs * 8 * s->f->linesize[0];
+ uvoff += hbs * 4 * s->f->linesize[1];
+ res = decode_sb(ctx, row + hbs, col, lflvl,
+ yoff, uvoff, bl + 1);
+ }
+ } else {
+ bp = PARTITION_V;
+ res = decode_b(ctx, row, col, lflvl, yoff, uvoff, bl, bp);
+ }
+ } else {
+ bp = PARTITION_SPLIT;
+ res = decode_sb(ctx, row, col, lflvl, yoff, uvoff, bl + 1);
+ }
+ s->counts.partition[bl][c][bp]++;
+
+ return res;
+}
+
+static void loopfilter_sb(AVCodecContext *ctx, struct VP9Filter *lflvl,
+ int row, int col, ptrdiff_t yoff, ptrdiff_t uvoff)
+{
+ VP9Context *s = ctx->priv_data;
+ uint8_t *dst = s->f->data[0] + yoff, *lvl = lflvl->level;
+ ptrdiff_t ls_y = s->f->linesize[0], ls_uv = s->f->linesize[1];
+ int y, x, p;
+
+ // FIXME in how far can we interleave the v/h loopfilter calls? E.g.
+ // if you think of them as acting on a 8x8 block max, we can interleave
+ // each v/h within the single x loop, but that only works if we work on
+ // 8 pixel blocks, and we won't always do that (we want at least 16px
+ // to use SSE2 optimizations, perhaps 32 for AVX2)
+
+ // filter edges between columns, Y plane (e.g. block1 | block2)
+ for (y = 0; y < 8; y += 2, dst += 16 * ls_y, lvl += 16) {
+ uint8_t *ptr = dst, *l = lvl, *hmask1 = lflvl->mask[0][0][y];
+ uint8_t *hmask2 = lflvl->mask[0][0][y + 1];
+ unsigned hm1 = hmask1[0] | hmask1[1] | hmask1[2], hm13 = hmask1[3];
+ unsigned hm2 = hmask2[1] | hmask2[2], hm23 = hmask2[3];
+ unsigned hm = hm1 | hm2 | hm13 | hm23;
+
+ for (x = 1; hm & ~(x - 1); x <<= 1, ptr += 8, l++) {
+ if (hm1 & x) {
+ int L = *l, H = L >> 4;
+ int E = s->filter.mblim_lut[L], I = s->filter.lim_lut[L];
+
+ if (col || x > 1) {
+ if (hmask1[0] & x) {
+ if (hmask2[0] & x) {
+ av_assert2(l[8] == L);
+ s->dsp.loop_filter_16[0](ptr, ls_y, E, I, H);
+ } else {
+ s->dsp.loop_filter_8[2][0](ptr, ls_y, E, I, H);
+ }
+ } else if (hm2 & x) {
+ L = l[8];
+ H |= (L >> 4) << 8;
+ E |= s->filter.mblim_lut[L] << 8;
+ I |= s->filter.lim_lut[L] << 8;
+ s->dsp.loop_filter_mix2[!!(hmask1[1] & x)]
+ [!!(hmask2[1] & x)]
+ [0](ptr, ls_y, E, I, H);
+ } else {
+ s->dsp.loop_filter_8[!!(hmask1[1] & x)]
+ [0](ptr, ls_y, E, I, H);
+ }
+ }
+ } else if (hm2 & x) {
+ int L = l[8], H = L >> 4;
+ int E = s->filter.mblim_lut[L], I = s->filter.lim_lut[L];
+
+ if (col || x > 1) {
+ s->dsp.loop_filter_8[!!(hmask2[1] & x)]
+ [0](ptr + 8 * ls_y, ls_y, E, I, H);
+ }
+ }
+ if (hm13 & x) {
+ int L = *l, H = L >> 4;
+ int E = s->filter.mblim_lut[L], I = s->filter.lim_lut[L];
+
+ if (hm23 & x) {
+ L = l[8];
+ H |= (L >> 4) << 8;
+ E |= s->filter.mblim_lut[L] << 8;
+ I |= s->filter.lim_lut[L] << 8;
+ s->dsp.loop_filter_mix2[0][0][0](ptr + 4, ls_y, E, I, H);
+ } else {
+ s->dsp.loop_filter_8[0][0](ptr + 4, ls_y, E, I, H);
+ }
+ } else if (hm23 & x) {
+ int L = l[8], H = L >> 4;
+ int E = s->filter.mblim_lut[L], I = s->filter.lim_lut[L];
+
+ s->dsp.loop_filter_8[0][0](ptr + 8 * ls_y + 4, ls_y, E, I, H);
+ }
+ }
+ }
+
+ // block1
+ // filter edges between rows, Y plane (e.g. ------)
+ // block2
+ dst = s->f->data[0] + yoff;
+ lvl = lflvl->level;
+ for (y = 0; y < 8; y++, dst += 8 * ls_y, lvl += 8) {
+ uint8_t *ptr = dst, *l = lvl, *vmask = lflvl->mask[0][1][y];
+ unsigned vm = vmask[0] | vmask[1] | vmask[2], vm3 = vmask[3];
+
+ for (x = 1; vm & ~(x - 1); x <<= 2, ptr += 16, l += 2) {
+ if (row || y) {
+ if (vm & x) {
+ int L = *l, H = L >> 4;
+ int E = s->filter.mblim_lut[L], I = s->filter.lim_lut[L];
+
+ if (vmask[0] & x) {
+ if (vmask[0] & (x << 1)) {
+ av_assert2(l[1] == L);
+ s->dsp.loop_filter_16[1](ptr, ls_y, E, I, H);
+ } else {
+ s->dsp.loop_filter_8[2][1](ptr, ls_y, E, I, H);
+ }
+ } else if (vm & (x << 1)) {
+ L = l[1];
+ H |= (L >> 4) << 8;
+ E |= s->filter.mblim_lut[L] << 8;
+ I |= s->filter.lim_lut[L] << 8;
+ s->dsp.loop_filter_mix2[!!(vmask[1] & x)]
+ [!!(vmask[1] & (x << 1))]
+ [1](ptr, ls_y, E, I, H);
+ } else {
+ s->dsp.loop_filter_8[!!(vmask[1] & x)]
+ [1](ptr, ls_y, E, I, H);
+ }
+ } else if (vm & (x << 1)) {
+ int L = l[1], H = L >> 4;
+ int E = s->filter.mblim_lut[L], I = s->filter.lim_lut[L];
+
+ s->dsp.loop_filter_8[!!(vmask[1] & (x << 1))]
+ [1](ptr + 8, ls_y, E, I, H);
+ }
+ }
+ if (vm3 & x) {
+ int L = *l, H = L >> 4;
+ int E = s->filter.mblim_lut[L], I = s->filter.lim_lut[L];
+
+ if (vm3 & (x << 1)) {
+ L = l[1];
+ H |= (L >> 4) << 8;
+ E |= s->filter.mblim_lut[L] << 8;
+ I |= s->filter.lim_lut[L] << 8;
+ s->dsp.loop_filter_mix2[0][0][1](ptr + ls_y * 4, ls_y, E, I, H);
+ } else {
+ s->dsp.loop_filter_8[0][1](ptr + ls_y * 4, ls_y, E, I, H);
+ }
+ } else if (vm3 & (x << 1)) {
+ int L = l[1], H = L >> 4;
+ int E = s->filter.mblim_lut[L], I = s->filter.lim_lut[L];
+
+ s->dsp.loop_filter_8[0][1](ptr + ls_y * 4 + 8, ls_y, E, I, H);
+ }
+ }
+ }
+
+ // same principle but for U/V planes
+ for (p = 0; p < 2; p++) {
+ lvl = lflvl->level;
+ dst = s->f->data[1 + p] + uvoff;
+ for (y = 0; y < 8; y += 4, dst += 16 * ls_uv, lvl += 32) {
+ uint8_t *ptr = dst, *l = lvl, *hmask1 = lflvl->mask[1][0][y];
+ uint8_t *hmask2 = lflvl->mask[1][0][y + 2];
+ unsigned hm1 = hmask1[0] | hmask1[1] | hmask1[2];
+ unsigned hm2 = hmask2[1] | hmask2[2], hm = hm1 | hm2;
+
+ for (x = 1; hm & ~(x - 1); x <<= 1, ptr += 4) {
+ if (col || x > 1) {
+ if (hm1 & x) {
+ int L = *l, H = L >> 4;
+ int E = s->filter.mblim_lut[L], I = s->filter.lim_lut[L];
+
+ if (hmask1[0] & x) {
+ if (hmask2[0] & x) {
+ av_assert2(l[16] == L);
+ s->dsp.loop_filter_16[0](ptr, ls_uv, E, I, H);
+ } else {
+ s->dsp.loop_filter_8[2][0](ptr, ls_uv, E, I, H);
+ }
+ } else if (hm2 & x) {
+ L = l[16];
+ H |= (L >> 4) << 8;
+ E |= s->filter.mblim_lut[L] << 8;
+ I |= s->filter.lim_lut[L] << 8;
+ s->dsp.loop_filter_mix2[!!(hmask1[1] & x)]
+ [!!(hmask2[1] & x)]
+ [0](ptr, ls_uv, E, I, H);
+ } else {
+ s->dsp.loop_filter_8[!!(hmask1[1] & x)]
+ [0](ptr, ls_uv, E, I, H);
+ }
+ } else if (hm2 & x) {
+ int L = l[16], H = L >> 4;
+ int E = s->filter.mblim_lut[L], I = s->filter.lim_lut[L];
+
+ s->dsp.loop_filter_8[!!(hmask2[1] & x)]
+ [0](ptr + 8 * ls_uv, ls_uv, E, I, H);
+ }
+ }
+ if (x & 0xAA)
+ l += 2;
+ }
+ }
+ lvl = lflvl->level;
+ dst = s->f->data[1 + p] + uvoff;
+ for (y = 0; y < 8; y++, dst += 4 * ls_uv) {
+ uint8_t *ptr = dst, *l = lvl, *vmask = lflvl->mask[1][1][y];
+ unsigned vm = vmask[0] | vmask[1] | vmask[2];
+
+ for (x = 1; vm & ~(x - 1); x <<= 4, ptr += 16, l += 4) {
+ if (row || y) {
+ if (vm & x) {
+ int L = *l, H = L >> 4;
+ int E = s->filter.mblim_lut[L], I = s->filter.lim_lut[L];
+
+ if (vmask[0] & x) {
+ if (vmask[0] & (x << 2)) {
+ av_assert2(l[2] == L);
+ s->dsp.loop_filter_16[1](ptr, ls_uv, E, I, H);
+ } else {
+ s->dsp.loop_filter_8[2][1](ptr, ls_uv, E, I, H);
+ }
+ } else if (vm & (x << 2)) {
+ L = l[2];
+ H |= (L >> 4) << 8;
+ E |= s->filter.mblim_lut[L] << 8;
+ I |= s->filter.lim_lut[L] << 8;
+ s->dsp.loop_filter_mix2[!!(vmask[1] & x)]
+ [!!(vmask[1] & (x << 2))]
+ [1](ptr, ls_uv, E, I, H);
+ } else {
+ s->dsp.loop_filter_8[!!(vmask[1] & x)]
+ [1](ptr, ls_uv, E, I, H);
+ }
+ } else if (vm & (x << 2)) {
+ int L = l[2], H = L >> 4;
+ int E = s->filter.mblim_lut[L], I = s->filter.lim_lut[L];
+
+ s->dsp.loop_filter_8[!!(vmask[1] & (x << 2))]
+ [1](ptr + 8, ls_uv, E, I, H);
+ }
+ }
+ }
+ if (y & 1)
+ lvl += 16;
+ }
+ }
+}
+
+static void set_tile_offset(int *start, int *end, int idx, int log2_n, int n)
+{
+ int sb_start = ( idx * n) >> log2_n;
+ int sb_end = ((idx + 1) * n) >> log2_n;
+ *start = FFMIN(sb_start, n) << 3;
+ *end = FFMIN(sb_end, n) << 3;
+}
+
+static av_always_inline void adapt_prob(uint8_t *p, unsigned ct0, unsigned ct1,
+ int max_count, int update_factor)
+{
+ unsigned ct = ct0 + ct1, p2, p1;
+
+ if (!ct)
+ return;
+
+ p1 = *p;
+ p2 = ((ct0 << 8) + (ct >> 1)) / ct;
+ p2 = av_clip(p2, 1, 255);
+ ct = FFMIN(ct, max_count);
+ update_factor = FASTDIV(update_factor * ct, max_count);
+
+ // (p1 * (256 - update_factor) + p2 * update_factor + 128) >> 8
+ *p = p1 + (((p2 - p1) * update_factor + 128) >> 8);
+}
+
+static void adapt_probs(VP9Context *s)
+{
+ int i, j, k, l, m;
+ prob_context *p = &s->prob_ctx[s->framectxid].p;
+ int uf = (s->keyframe || s->intraonly || !s->last_keyframe) ? 112 : 128;
+
+ // coefficients
+ for (i = 0; i < 4; i++)
+ for (j = 0; j < 2; j++)
+ for (k = 0; k < 2; k++)
+ for (l = 0; l < 6; l++)
+ for (m = 0; m < 6; m++) {
+ uint8_t *pp = s->prob_ctx[s->framectxid].coef[i][j][k][l][m];
+ unsigned *e = s->counts.eob[i][j][k][l][m];
+ unsigned *c = s->counts.coef[i][j][k][l][m];
+
+ if (l == 0 && m >= 3) // dc only has 3 pt
+ break;
+
+ adapt_prob(&pp[0], e[0], e[1], 24, uf);
+ adapt_prob(&pp[1], c[0], c[1] + c[2], 24, uf);
+ adapt_prob(&pp[2], c[1], c[2], 24, uf);
+ }
+
+ if (s->keyframe || s->intraonly) {
+ memcpy(p->skip, s->prob.p.skip, sizeof(p->skip));
+ memcpy(p->tx32p, s->prob.p.tx32p, sizeof(p->tx32p));
+ memcpy(p->tx16p, s->prob.p.tx16p, sizeof(p->tx16p));
+ memcpy(p->tx8p, s->prob.p.tx8p, sizeof(p->tx8p));
+ return;
+ }
+
+ // skip flag
+ for (i = 0; i < 3; i++)
+ adapt_prob(&p->skip[i], s->counts.skip[i][0], s->counts.skip[i][1], 20, 128);
+
+ // intra/inter flag
+ for (i = 0; i < 4; i++)
+ adapt_prob(&p->intra[i], s->counts.intra[i][0], s->counts.intra[i][1], 20, 128);
+
+ // comppred flag
+ if (s->comppredmode == PRED_SWITCHABLE) {
+ for (i = 0; i < 5; i++)
+ adapt_prob(&p->comp[i], s->counts.comp[i][0], s->counts.comp[i][1], 20, 128);
+ }
+
+ // reference frames
+ if (s->comppredmode != PRED_SINGLEREF) {
+ for (i = 0; i < 5; i++)
+ adapt_prob(&p->comp_ref[i], s->counts.comp_ref[i][0],
+ s->counts.comp_ref[i][1], 20, 128);
+ }
+
+ if (s->comppredmode != PRED_COMPREF) {
+ for (i = 0; i < 5; i++) {
+ uint8_t *pp = p->single_ref[i];
+ unsigned (*c)[2] = s->counts.single_ref[i];
+
+ adapt_prob(&pp[0], c[0][0], c[0][1], 20, 128);
+ adapt_prob(&pp[1], c[1][0], c[1][1], 20, 128);
+ }
+ }
+
+ // block partitioning
+ for (i = 0; i < 4; i++)
+ for (j = 0; j < 4; j++) {
+ uint8_t *pp = p->partition[i][j];
+ unsigned *c = s->counts.partition[i][j];
+
+ adapt_prob(&pp[0], c[0], c[1] + c[2] + c[3], 20, 128);
+ adapt_prob(&pp[1], c[1], c[2] + c[3], 20, 128);
+ adapt_prob(&pp[2], c[2], c[3], 20, 128);
+ }
+
+ // tx size
+ if (s->txfmmode == TX_SWITCHABLE) {
+ for (i = 0; i < 2; i++) {
+ unsigned *c16 = s->counts.tx16p[i], *c32 = s->counts.tx32p[i];
+
+ adapt_prob(&p->tx8p[i], s->counts.tx8p[i][0], s->counts.tx8p[i][1], 20, 128);
+ adapt_prob(&p->tx16p[i][0], c16[0], c16[1] + c16[2], 20, 128);
+ adapt_prob(&p->tx16p[i][1], c16[1], c16[2], 20, 128);
+ adapt_prob(&p->tx32p[i][0], c32[0], c32[1] + c32[2] + c32[3], 20, 128);
+ adapt_prob(&p->tx32p[i][1], c32[1], c32[2] + c32[3], 20, 128);
+ adapt_prob(&p->tx32p[i][2], c32[2], c32[3], 20, 128);
+ }
+ }
+
+ // interpolation filter
+ if (s->filtermode == FILTER_SWITCHABLE) {
+ for (i = 0; i < 4; i++) {
+ uint8_t *pp = p->filter[i];
+ unsigned *c = s->counts.filter[i];
+
+ adapt_prob(&pp[0], c[0], c[1] + c[2], 20, 128);
+ adapt_prob(&pp[1], c[1], c[2], 20, 128);
+ }
+ }
+
+ // inter modes
+ for (i = 0; i < 7; i++) {
+ uint8_t *pp = p->mv_mode[i];
+ unsigned *c = s->counts.mv_mode[i];
+
+ adapt_prob(&pp[0], c[2], c[1] + c[0] + c[3], 20, 128);
+ adapt_prob(&pp[1], c[0], c[1] + c[3], 20, 128);
+ adapt_prob(&pp[2], c[1], c[3], 20, 128);
+ }
+
+ // mv joints
+ {
+ uint8_t *pp = p->mv_joint;
+ unsigned *c = s->counts.mv_joint;
+
+ adapt_prob(&pp[0], c[0], c[1] + c[2] + c[3], 20, 128);
+ adapt_prob(&pp[1], c[1], c[2] + c[3], 20, 128);
+ adapt_prob(&pp[2], c[2], c[3], 20, 128);
+ }
+
+ // mv components
+ for (i = 0; i < 2; i++) {
+ uint8_t *pp;
+ unsigned *c, (*c2)[2], sum;
+
+ adapt_prob(&p->mv_comp[i].sign, s->counts.mv_comp[i].sign[0],
+ s->counts.mv_comp[i].sign[1], 20, 128);
+
+ pp = p->mv_comp[i].classes;
+ c = s->counts.mv_comp[i].classes;
+ sum = c[1] + c[2] + c[3] + c[4] + c[5] + c[6] + c[7] + c[8] + c[9] + c[10];
+ adapt_prob(&pp[0], c[0], sum, 20, 128);
+ sum -= c[1];
+ adapt_prob(&pp[1], c[1], sum, 20, 128);
+ sum -= c[2] + c[3];
+ adapt_prob(&pp[2], c[2] + c[3], sum, 20, 128);
+ adapt_prob(&pp[3], c[2], c[3], 20, 128);
+ sum -= c[4] + c[5];
+ adapt_prob(&pp[4], c[4] + c[5], sum, 20, 128);
+ adapt_prob(&pp[5], c[4], c[5], 20, 128);
+ sum -= c[6];
+ adapt_prob(&pp[6], c[6], sum, 20, 128);
+ adapt_prob(&pp[7], c[7] + c[8], c[9] + c[10], 20, 128);
+ adapt_prob(&pp[8], c[7], c[8], 20, 128);
+ adapt_prob(&pp[9], c[9], c[10], 20, 128);
+
+ adapt_prob(&p->mv_comp[i].class0, s->counts.mv_comp[i].class0[0],
+ s->counts.mv_comp[i].class0[1], 20, 128);
+ pp = p->mv_comp[i].bits;
+ c2 = s->counts.mv_comp[i].bits;
+ for (j = 0; j < 10; j++)
+ adapt_prob(&pp[j], c2[j][0], c2[j][1], 20, 128);
+
+ for (j = 0; j < 2; j++) {
+ pp = p->mv_comp[i].class0_fp[j];
+ c = s->counts.mv_comp[i].class0_fp[j];
+ adapt_prob(&pp[0], c[0], c[1] + c[2] + c[3], 20, 128);
+ adapt_prob(&pp[1], c[1], c[2] + c[3], 20, 128);
+ adapt_prob(&pp[2], c[2], c[3], 20, 128);
+ }
+ pp = p->mv_comp[i].fp;
+ c = s->counts.mv_comp[i].fp;
+ adapt_prob(&pp[0], c[0], c[1] + c[2] + c[3], 20, 128);
+ adapt_prob(&pp[1], c[1], c[2] + c[3], 20, 128);
+ adapt_prob(&pp[2], c[2], c[3], 20, 128);
+
+ if (s->highprecisionmvs) {
+ adapt_prob(&p->mv_comp[i].class0_hp, s->counts.mv_comp[i].class0_hp[0],
+ s->counts.mv_comp[i].class0_hp[1], 20, 128);
+ adapt_prob(&p->mv_comp[i].hp, s->counts.mv_comp[i].hp[0],
+ s->counts.mv_comp[i].hp[1], 20, 128);
+ }
+ }
+
+ // y intra modes
+ for (i = 0; i < 4; i++) {
+ uint8_t *pp = p->y_mode[i];
+ unsigned *c = s->counts.y_mode[i], sum, s2;
+
+ sum = c[0] + c[1] + c[3] + c[4] + c[5] + c[6] + c[7] + c[8] + c[9];
+ adapt_prob(&pp[0], c[DC_PRED], sum, 20, 128);
+ sum -= c[TM_VP8_PRED];
+ adapt_prob(&pp[1], c[TM_VP8_PRED], sum, 20, 128);
+ sum -= c[VERT_PRED];
+ adapt_prob(&pp[2], c[VERT_PRED], sum, 20, 128);
+ s2 = c[HOR_PRED] + c[DIAG_DOWN_RIGHT_PRED] + c[VERT_RIGHT_PRED];
+ sum -= s2;
+ adapt_prob(&pp[3], s2, sum, 20, 128);
+ s2 -= c[HOR_PRED];
+ adapt_prob(&pp[4], c[HOR_PRED], s2, 20, 128);
+ adapt_prob(&pp[5], c[DIAG_DOWN_RIGHT_PRED], c[VERT_RIGHT_PRED], 20, 128);
+ sum -= c[DIAG_DOWN_LEFT_PRED];
+ adapt_prob(&pp[6], c[DIAG_DOWN_LEFT_PRED], sum, 20, 128);
+ sum -= c[VERT_LEFT_PRED];
+ adapt_prob(&pp[7], c[VERT_LEFT_PRED], sum, 20, 128);
+ adapt_prob(&pp[8], c[HOR_DOWN_PRED], c[HOR_UP_PRED], 20, 128);
+ }
+
+ // uv intra modes
+ for (i = 0; i < 10; i++) {
+ uint8_t *pp = p->uv_mode[i];
+ unsigned *c = s->counts.uv_mode[i], sum, s2;
+
+ sum = c[0] + c[1] + c[3] + c[4] + c[5] + c[6] + c[7] + c[8] + c[9];
+ adapt_prob(&pp[0], c[DC_PRED], sum, 20, 128);
+ sum -= c[TM_VP8_PRED];
+ adapt_prob(&pp[1], c[TM_VP8_PRED], sum, 20, 128);
+ sum -= c[VERT_PRED];
+ adapt_prob(&pp[2], c[VERT_PRED], sum, 20, 128);
+ s2 = c[HOR_PRED] + c[DIAG_DOWN_RIGHT_PRED] + c[VERT_RIGHT_PRED];
+ sum -= s2;
+ adapt_prob(&pp[3], s2, sum, 20, 128);
+ s2 -= c[HOR_PRED];
+ adapt_prob(&pp[4], c[HOR_PRED], s2, 20, 128);
+ adapt_prob(&pp[5], c[DIAG_DOWN_RIGHT_PRED], c[VERT_RIGHT_PRED], 20, 128);
+ sum -= c[DIAG_DOWN_LEFT_PRED];
+ adapt_prob(&pp[6], c[DIAG_DOWN_LEFT_PRED], sum, 20, 128);
+ sum -= c[VERT_LEFT_PRED];
+ adapt_prob(&pp[7], c[VERT_LEFT_PRED], sum, 20, 128);
+ adapt_prob(&pp[8], c[HOR_DOWN_PRED], c[HOR_UP_PRED], 20, 128);
+ }
+}
+
+static int vp9_decode_frame(AVCodecContext *ctx, void *out_pic,
+ int *got_frame, const uint8_t *data, int size)
+{
+ VP9Context *s = ctx->priv_data;
+ int res, tile_row, tile_col, i, ref, row, col;
+ ptrdiff_t yoff = 0, uvoff = 0;
+ //AVFrame *prev_frame = s->f; // for segmentation map
+
+ if ((res = decode_frame_header(ctx, data, size, &ref)) < 0) {
+ return res;
+ } else if (res == 0) {
+ if (!s->refs[ref]) {
+ av_log(ctx, AV_LOG_ERROR, "Requested reference %d not available\n", ref);
+ return AVERROR_INVALIDDATA;
+ }
+ if ((res = av_frame_ref(out_pic, s->refs[ref])) < 0)
+ return res;
+ *got_frame = 1;
+ return 0;
+ }
+ data += res;
+ size -= res;
+
+ // discard old references
+ for (i = 0; i < 10; i++) {
+ AVFrame *f = s->fb[i];
+ if (f->data[0] && f != s->f &&
+ f != s->refs[0] && f != s->refs[1] &&
+ f != s->refs[2] && f != s->refs[3] &&
+ f != s->refs[4] && f != s->refs[5] &&
+ f != s->refs[6] && f != s->refs[7])
+ av_frame_unref(f);
+ }
+
+ // find unused reference
+ for (i = 0; i < 10; i++)
+ if (!s->fb[i]->data[0])
+ break;
+ s->f = s->fb[i];
+ if ((res = ff_get_buffer(ctx, s->f,
+ s->refreshrefmask ? AV_GET_BUFFER_FLAG_REF : 0)) < 0)
+ return res;
+ s->f->key_frame = s->keyframe;
+ s->f->pict_type = s->keyframe ? AV_PICTURE_TYPE_I : AV_PICTURE_TYPE_P;
+
+ // main tile decode loop
+ memset(s->above_partition_ctx, 0, s->cols);
+ memset(s->above_skip_ctx, 0, s->cols);
+ if (s->keyframe || s->intraonly) {
+ memset(s->above_mode_ctx, DC_PRED, s->cols * 2);
+ } else {
+ memset(s->above_mode_ctx, NEARESTMV, s->cols);
+ }
+ memset(s->above_y_nnz_ctx, 0, s->sb_cols * 16);
+ memset(s->above_uv_nnz_ctx[0], 0, s->sb_cols * 8);
+ memset(s->above_uv_nnz_ctx[1], 0, s->sb_cols * 8);
+ memset(s->above_segpred_ctx, 0, s->cols);
+ for (tile_row = 0; tile_row < s->tiling.tile_rows; tile_row++) {
+ set_tile_offset(&s->tiling.tile_row_start, &s->tiling.tile_row_end,
+ tile_row, s->tiling.log2_tile_rows, s->sb_rows);
+ for (tile_col = 0; tile_col < s->tiling.tile_cols; tile_col++) {
+ unsigned tile_size;
+
+ if (tile_col == s->tiling.tile_cols - 1 &&
+ tile_row == s->tiling.tile_rows - 1) {
+ tile_size = size;
+ } else {
+ tile_size = AV_RB32(data);
+ data += 4;
+ size -= 4;
+ }
+ if (tile_size > size)
+ return AVERROR_INVALIDDATA;
+ ff_vp56_init_range_decoder(&s->c_b[tile_col], data, tile_size);
+ if (vp56_rac_get_prob_branchy(&s->c_b[tile_col], 128)) // marker bit
+ return AVERROR_INVALIDDATA;
+ data += tile_size;
+ size -= tile_size;
+ }
+
+ for (row = s->tiling.tile_row_start;
+ row < s->tiling.tile_row_end;
+ row += 8, yoff += s->f->linesize[0] * 64,
+ uvoff += s->f->linesize[1] * 32) {
+ struct VP9Filter *lflvl_ptr = s->lflvl;
+ ptrdiff_t yoff2 = yoff, uvoff2 = uvoff;
+
+ for (tile_col = 0; tile_col < s->tiling.tile_cols; tile_col++) {
+ set_tile_offset(&s->tiling.tile_col_start, &s->tiling.tile_col_end,
+ tile_col, s->tiling.log2_tile_cols, s->sb_cols);
+
+ memset(s->left_partition_ctx, 0, 8);
+ memset(s->left_skip_ctx, 0, 8);
+ if (s->keyframe || s->intraonly) {
+ memset(s->left_mode_ctx, DC_PRED, 16);
+ } else {
+ memset(s->left_mode_ctx, NEARESTMV, 8);
+ }
+ memset(s->left_y_nnz_ctx, 0, 16);
+ memset(s->left_uv_nnz_ctx, 0, 16);
+ memset(s->left_segpred_ctx, 0, 8);
+
+ memcpy(&s->c, &s->c_b[tile_col], sizeof(s->c));
+ for (col = s->tiling.tile_col_start;
+ col < s->tiling.tile_col_end;
+ col += 8, yoff2 += 64, uvoff2 += 32, lflvl_ptr++) {
+ // FIXME integrate with lf code (i.e. zero after each
+ // use, similar to invtxfm coefficients, or similar)
+ memset(lflvl_ptr->mask, 0, sizeof(lflvl_ptr->mask));
+
+ if ((res = decode_sb(ctx, row, col, lflvl_ptr,
+ yoff2, uvoff2, BL_64X64)) < 0)
+ return res;
+ }
+ memcpy(&s->c_b[tile_col], &s->c, sizeof(s->c));
+ }
+
+ // backup pre-loopfilter reconstruction data for intra
+ // prediction of next row of sb64s
+ if (row + 8 < s->rows) {
+ memcpy(s->intra_pred_data[0],
+ s->f->data[0] + yoff + 63 * s->f->linesize[0],
+ 8 * s->cols);
+ memcpy(s->intra_pred_data[1],
+ s->f->data[1] + uvoff + 31 * s->f->linesize[1],
+ 4 * s->cols);
+ memcpy(s->intra_pred_data[2],
+ s->f->data[2] + uvoff + 31 * s->f->linesize[2],
+ 4 * s->cols);
+ }
+
+ // loopfilter one row
+ if (s->filter.level) {
+ yoff2 = yoff;
+ uvoff2 = uvoff;
+ lflvl_ptr = s->lflvl;
+ for (col = 0; col < s->cols;
+ col += 8, yoff2 += 64, uvoff2 += 32, lflvl_ptr++) {
+ loopfilter_sb(ctx, lflvl_ptr, row, col, yoff2, uvoff2);
+ }
+ }
+ }
+ }
+
+ // bw adaptivity (or in case of parallel decoding mode, fw adaptivity
+ // probability maintenance between frames)
+ if (s->refreshctx) {
+ if (s->parallelmode) {
+ int i, j, k, l, m;
+
+ for (i = 0; i < 4; i++)
+ for (j = 0; j < 2; j++)
+ for (k = 0; k < 2; k++)
+ for (l = 0; l < 6; l++)
+ for (m = 0; m < 6; m++)
+ memcpy(s->prob_ctx[s->framectxid].coef[i][j][k][l][m],
+ s->prob.coef[i][j][k][l][m], 3);
+ s->prob_ctx[s->framectxid].p = s->prob.p;
+ } else {
+ adapt_probs(s);
+ }
+ }
+ FFSWAP(struct VP9mvrefPair *, s->mv[0], s->mv[1]);
+
+ // ref frame setup
+ for (i = 0; i < 8; i++)
+ if (s->refreshrefmask & (1 << i))
+ s->refs[i] = s->f;
+
+ if (!s->invisible) {
+ if ((res = av_frame_ref(out_pic, s->f)) < 0)
+ return res;
+ *got_frame = 1;
+ }
+
+ return 0;
+}
+
+static int vp9_decode_packet(AVCodecContext *avctx, void *out_pic,
+ int *got_frame, AVPacket *avpkt)
+{
+ const uint8_t *data = avpkt->data;
+ int size = avpkt->size, marker, res;
+
+ // read superframe index - this is a collection of individual frames that
+ // together lead to one visible frame
+ av_assert1(size > 0); // without CODEC_CAP_DELAY, this is implied
+ marker = data[size - 1];
+ if ((marker & 0xe0) == 0xc0) {
+ int nbytes = 1 + ((marker >> 3) & 0x3);
+ int n_frames = 1 + (marker & 0x7), idx_sz = 2 + n_frames * nbytes;
+
+ if (size >= idx_sz && data[size - idx_sz] == marker) {
+ const uint8_t *idx = data + size + 1 - idx_sz;
+ switch (nbytes) {
+#define case_n(a, rd) \
+ case a: \
+ while (n_frames--) { \
+ int sz = rd; \
+ idx += a; \
+ if (sz > size) { \
+ av_log(avctx, AV_LOG_ERROR, \
+ "Superframe packet size too big: %d > %d\n", \
+ sz, size); \
+ return AVERROR_INVALIDDATA; \
+ } \
+ res = vp9_decode_frame(avctx, out_pic, got_frame, \
+ data, sz); \
+ if (res < 0) \
+ return res; \
+ data += sz; \
+ size -= sz; \
+ } \
+ break;
+ case_n(1, *idx);
+ case_n(2, AV_RL16(idx));
+ case_n(3, AV_RL24(idx));
+ case_n(4, AV_RL32(idx));
+ }
+ return size;
+ }
+ }
+ // if we get here, there was no valid superframe index, i.e. this is just
+ // one whole single frame - decode it as such from the complete input buf
+ if ((res = vp9_decode_frame(avctx, out_pic, got_frame, data, size)) < 0)
+ return res;
+ return size;
+}
+
+static void vp9_decode_flush(AVCodecContext *ctx)
+{
+ VP9Context *s = ctx->priv_data;
+ int i;
+
+ for (i = 0; i < 10; i++)
+ if (s->fb[i]->data[0])
+ av_frame_unref(s->fb[i]);
+ for (i = 0; i < 8; i++)
+ s->refs[i] = NULL;
+ s->f = NULL;
+}
+
+static av_cold int vp9_decode_init(AVCodecContext *ctx)
+{
+ VP9Context *s = ctx->priv_data;
+ int i;
+
+ ctx->pix_fmt = AV_PIX_FMT_YUV420P;
+ ff_vp9dsp_init(&s->dsp);
+ ff_videodsp_init(&s->vdsp, 8);
+ for (i = 0; i < 10; i++) {
+ s->fb[i] = av_frame_alloc();
+ if (!s->fb[i]) {
+ av_log(ctx, AV_LOG_ERROR, "Failed to allocate frame buffer %d\n", i);
+ return AVERROR(ENOMEM);
+ }
+ }
+ s->filter.sharpness = -1;
+
+ return 0;
+}
+
+static av_cold int vp9_decode_free(AVCodecContext *ctx)
+{
+ VP9Context *s = ctx->priv_data;
+ int i;
+
+ for (i = 0; i < 10; i++) {
+ if (s->fb[i]->data[0])
+ av_frame_unref(s->fb[i]);
+ av_frame_free(&s->fb[i]);
+ }
+ av_freep(&s->above_partition_ctx);
+ s->above_skip_ctx = s->above_txfm_ctx = s->above_mode_ctx = NULL;
+ s->above_y_nnz_ctx = s->above_uv_nnz_ctx[0] = s->above_uv_nnz_ctx[1] = NULL;
+ s->intra_pred_data[0] = s->intra_pred_data[1] = s->intra_pred_data[2] = NULL;
+ s->above_segpred_ctx = s->above_intra_ctx = s->above_comp_ctx = NULL;
+ s->above_ref_ctx = s->above_filter_ctx = NULL;
+ s->above_mv_ctx = NULL;
+ s->segmentation_map = NULL;
+ s->mv[0] = s->mv[1] = NULL;
+ s->lflvl = NULL;
+ av_freep(&s->c_b);
+ s->c_b_size = 0;
+
+ return 0;
+}
+
+AVCodec ff_vp9_decoder = {
+ .name = "vp9",
+ .type = AVMEDIA_TYPE_VIDEO,
+ .id = AV_CODEC_ID_VP9,
+ .priv_data_size = sizeof(VP9Context),
+ .init = vp9_decode_init,
+ .close = vp9_decode_free,
+ .decode = vp9_decode_packet,
+ .capabilities = CODEC_CAP_DR1,
+ .flush = vp9_decode_flush,
+ .long_name = NULL_IF_CONFIG_SMALL("Google VP9"),
+};
diff --git a/libavcodec/vp9.h b/libavcodec/vp9.h
new file mode 100644
index 0000000000..9a29416e8d
--- /dev/null
+++ b/libavcodec/vp9.h
@@ -0,0 +1,72 @@
+/*
+ * VP9 compatible video decoder
+ *
+ * Copyright (C) 2013 Ronald S. Bultje <rsbultje gmail com>
+ * Copyright (C) 2013 Clément Bœsch <u pkh me>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_VP9_H
+#define AVCODEC_VP9_H
+
+enum TxfmMode {
+ TX_4X4,
+ TX_8X8,
+ TX_16X16,
+ TX_32X32,
+ N_TXFM_SIZES,
+ TX_SWITCHABLE = N_TXFM_SIZES,
+ N_TXFM_MODES
+};
+
+enum TxfmType {
+ DCT_DCT,
+ DCT_ADST,
+ ADST_DCT,
+ ADST_ADST,
+ N_TXFM_TYPES
+};
+
+enum IntraPredMode {
+ VERT_PRED,
+ HOR_PRED,
+ DC_PRED,
+ DIAG_DOWN_LEFT_PRED,
+ DIAG_DOWN_RIGHT_PRED,
+ VERT_RIGHT_PRED,
+ HOR_DOWN_PRED,
+ VERT_LEFT_PRED,
+ HOR_UP_PRED,
+ TM_VP8_PRED,
+ LEFT_DC_PRED,
+ TOP_DC_PRED,
+ DC_128_PRED,
+ DC_127_PRED,
+ DC_129_PRED,
+ N_INTRA_PRED_MODES
+};
+
+enum FilterMode {
+ FILTER_8TAP_SMOOTH,
+ FILTER_8TAP_REGULAR,
+ FILTER_8TAP_SHARP,
+ FILTER_BILINEAR,
+ FILTER_SWITCHABLE,
+};
+
+#endif /* AVCODEC_VP9_H */
diff --git a/libavcodec/vp9data.h b/libavcodec/vp9data.h
new file mode 100644
index 0000000000..502928abc7
--- /dev/null
+++ b/libavcodec/vp9data.h
@@ -0,0 +1,2153 @@
+/*
+ * Copyright (C) 2013 Ronald S. Bultje <rsbultje gmail com>
+ * Copyright (C) 2013 Clément Bœsch <u pkh me>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_VP9DATA_H
+#define AVCODEC_VP9DATA_H
+
+#include "vp9.h"
+
+enum BlockPartition {
+ PARTITION_NONE, // [ ] <-.
+ PARTITION_H, // [-] |
+ PARTITION_V, // [|] |
+ PARTITION_SPLIT, // [+] --'
+};
+
+static const int8_t vp9_partition_tree[3][2] = {
+ { -PARTITION_NONE, 1 }, // '0'
+ { -PARTITION_H, 2 }, // '10'
+ { -PARTITION_V, -PARTITION_SPLIT }, // '110', '111'
+};
+
+static const uint8_t vp9_default_kf_partition_probs[4][4][3] = {
+ { /* 64x64 -> 32x32 */
+ { 174, 35, 49 } /* a/l both not split */,
+ { 68, 11, 27 } /* a split, l not split */,
+ { 57, 15, 9 } /* l split, a not split */,
+ { 12, 3, 3 } /* a/l both split */
+ }, { /* 32x32 -> 16x16 */
+ { 150, 40, 39 } /* a/l both not split */,
+ { 78, 12, 26 } /* a split, l not split */,
+ { 67, 33, 11 } /* l split, a not split */,
+ { 24, 7, 5 } /* a/l both split */,
+ }, { /* 16x16 -> 8x8 */
+ { 149, 53, 53 } /* a/l both not split */,
+ { 94, 20, 48 } /* a split, l not split */,
+ { 83, 53, 24 } /* l split, a not split */,
+ { 52, 18, 18 } /* a/l both split */,
+ }, { /* 8x8 -> 4x4 */
+ { 158, 97, 94 } /* a/l both not split */,
+ { 93, 24, 99 } /* a split, l not split */,
+ { 85, 119, 44 } /* l split, a not split */,
+ { 62, 59, 67 } /* a/l both split */,
+ },
+};
+
+static const int8_t vp9_segmentation_tree[7][2] = {
+ { 1, 2 },
+ { 3, 4 },
+ { 5, 6 },
+ { -0, -1 }, // '00x'
+ { -2, -3 }, // '01x'
+ { -4, -5 }, // '10x'
+ { -6, -7 }, // '11x'
+};
+
+static const int8_t vp9_intramode_tree[9][2] = {
+ { -DC_PRED, 1 }, // '0'
+ { -TM_VP8_PRED, 2 }, // '10'
+ { -VERT_PRED, 3 }, // '110'
+ { 4, 6 },
+ { -HOR_PRED, 5 }, // '11100'
+ { -DIAG_DOWN_RIGHT_PRED, -VERT_RIGHT_PRED }, // '11101x'
+ { -DIAG_DOWN_LEFT_PRED, 7 }, // '11110'
+ { -VERT_LEFT_PRED, 8 }, // '111110'
+ { -HOR_DOWN_PRED, -HOR_UP_PRED }, // '111111x'
+};
+
+static const uint8_t vp9_default_kf_ymode_probs[10][10][9] = {
+ { /* above = v */
+ { 43, 46, 168, 134, 107, 128, 69, 142, 92 } /* left = v */,
+ { 44, 29, 68, 159, 201, 177, 50, 57, 77 } /* left = h */,
+ { 63, 36, 126, 146, 123, 158, 60, 90, 96 } /* left = dc */,
+ { 58, 38, 76, 114, 97, 172, 78, 133, 92 } /* left = d45 */,
+ { 46, 41, 76, 140, 63, 184, 69, 112, 57 } /* left = d135 */,
+ { 38, 32, 85, 140, 46, 112, 54, 151, 133 } /* left = d117 */,
+ { 39, 27, 61, 131, 110, 175, 44, 75, 136 } /* left = d153 */,
+ { 47, 35, 80, 100, 74, 143, 64, 163, 74 } /* left = d63 */,
+ { 52, 30, 74, 113, 130, 175, 51, 64, 58 } /* left = d27 */,
+ { 36, 61, 116, 114, 128, 162, 80, 125, 82 } /* left = tm */
+ }, { /* above = h */
+ { 55, 44, 68, 166, 179, 192, 57, 57, 108 } /* left = v */,
+ { 42, 26, 11, 199, 241, 228, 23, 15, 85 } /* left = h */,
+ { 82, 26, 26, 171, 208, 204, 44, 32, 105 } /* left = dc */,
+ { 68, 42, 19, 131, 160, 199, 55, 52, 83 } /* left = d45 */,
+ { 58, 50, 25, 139, 115, 232, 39, 52, 118 } /* left = d135 */,
+ { 50, 35, 33, 153, 104, 162, 64, 59, 131 } /* left = d117 */,
+ { 44, 24, 16, 150, 177, 202, 33, 19, 156 } /* left = d153 */,
+ { 53, 49, 21, 110, 116, 168, 59, 80, 76 } /* left = d63 */,
+ { 55, 27, 12, 153, 203, 218, 26, 27, 49 } /* left = d27 */,
+ { 38, 72, 19, 168, 203, 212, 50, 50, 107 } /* left = tm */
+ }, { /* above = dc */
+ { 92, 45, 102, 136, 116, 180, 74, 90, 100 } /* left = v */,
+ { 73, 32, 19, 187, 222, 215, 46, 34, 100 } /* left = h */,
+ { 137, 30, 42, 148, 151, 207, 70, 52, 91 } /* left = dc */,
+ { 91, 30, 32, 116, 121, 186, 93, 86, 94 } /* left = d45 */,
+ { 72, 35, 36, 149, 68, 206, 68, 63, 105 } /* left = d135 */,
+ { 73, 31, 28, 138, 57, 124, 55, 122, 151 } /* left = d117 */,
+ { 67, 23, 21, 140, 126, 197, 40, 37, 171 } /* left = d153 */,
+ { 74, 32, 27, 107, 86, 160, 63, 134, 102 } /* left = d63 */,
+ { 86, 27, 28, 128, 154, 212, 45, 43, 53 } /* left = d27 */,
+ { 59, 67, 44, 140, 161, 202, 78, 67, 119 } /* left = tm */
+ }, { /* above = d45 */
+ { 59, 38, 83, 112, 103, 162, 98, 136, 90 } /* left = v */,
+ { 62, 30, 23, 158, 200, 207, 59, 57, 50 } /* left = h */,
+ { 103, 26, 36, 129, 132, 201, 83, 80, 93 } /* left = dc */,
+ { 67, 30, 29, 84, 86, 191, 102, 91, 59 } /* left = d45 */,
+ { 60, 32, 33, 112, 71, 220, 64, 89, 104 } /* left = d135 */,
+ { 53, 26, 34, 130, 56, 149, 84, 120, 103 } /* left = d117 */,
+ { 53, 21, 23, 133, 109, 210, 56, 77, 172 } /* left = d153 */,
+ { 61, 29, 29, 93, 97, 165, 83, 175, 162 } /* left = d63 */,
+ { 77, 19, 29, 112, 142, 228, 55, 66, 36 } /* left = d27 */,
+ { 47, 47, 43, 114, 137, 181, 100, 99, 95 } /* left = tm */
+ }, { /* above = d135 */
+ { 53, 40, 55, 139, 69, 183, 61, 80, 110 } /* left = v */,
+ { 40, 29, 19, 161, 180, 207, 43, 24, 91 } /* left = h */,
+ { 69, 23, 29, 128, 83, 199, 46, 44, 101 } /* left = dc */,
+ { 60, 34, 19, 105, 61, 198, 53, 64, 89 } /* left = d45 */,
+ { 52, 31, 22, 158, 40, 209, 58, 62, 89 } /* left = d135 */,
+ { 44, 31, 29, 147, 46, 158, 56, 102, 198 } /* left = d117 */,
+ { 35, 19, 12, 135, 87, 209, 41, 45, 167 } /* left = d153 */,
+ { 51, 38, 25, 113, 58, 164, 70, 93, 97 } /* left = d63 */,
+ { 55, 25, 21, 118, 95, 215, 38, 39, 66 } /* left = d27 */,
+ { 47, 54, 34, 146, 108, 203, 72, 103, 151 } /* left = tm */
+ }, { /* above = d117 */
+ { 46, 27, 80, 150, 55, 124, 55, 121, 135 } /* left = v */,
+ { 36, 23, 27, 165, 149, 166, 54, 64, 118 } /* left = h */,
+ { 64, 19, 37, 156, 66, 138, 49, 95, 133 } /* left = dc */,
+ { 53, 21, 36, 131, 63, 163, 60, 109, 81 } /* left = d45 */,
+ { 40, 26, 35, 154, 40, 185, 51, 97, 123 } /* left = d135 */,
+ { 35, 19, 34, 179, 19, 97, 48, 129, 124 } /* left = d117 */,
+ { 36, 20, 26, 136, 62, 164, 33, 77, 154 } /* left = d153 */,
+ { 45, 26, 28, 129, 45, 129, 49, 147, 123 } /* left = d63 */,
+ { 45, 18, 32, 130, 90, 157, 40, 79, 91 } /* left = d27 */,
+ { 38, 44, 51, 136, 74, 162, 57, 97, 121 } /* left = tm */
+ }, { /* above = d153 */
+ { 56, 39, 58, 133, 117, 173, 48, 53, 187 } /* left = v */,
+ { 35, 21, 12, 161, 212, 207, 20, 23, 145 } /* left = h */,
+ { 75, 17, 22, 136, 138, 185, 32, 34, 166 } /* left = dc */,
+ { 56, 29, 19, 117, 109, 181, 55, 68, 112 } /* left = d45 */,
+ { 47, 29, 17, 153, 64, 220, 59, 51, 114 } /* left = d135 */,
+ { 46, 16, 24, 136, 76, 147, 41, 64, 172 } /* left = d117 */,
+ { 34, 17, 11, 108, 152, 187, 13, 15, 209 } /* left = d153 */,
+ { 55, 30, 18, 122, 79, 179, 44, 88, 116 } /* left = d63 */,
+ { 51, 24, 14, 115, 133, 209, 32, 26, 104 } /* left = d27 */,
+ { 37, 49, 25, 129, 168, 164, 41, 54, 148 } /* left = tm */
+ }, { /* above = d63 */
+ { 48, 34, 86, 101, 92, 146, 78, 179, 134 } /* left = v */,
+ { 47, 22, 24, 138, 187, 178, 68, 69, 59 } /* left = h */,
+ { 78, 23, 39, 111, 117, 170, 74, 124, 94 } /* left = dc */,
+ { 56, 25, 33, 105, 112, 187, 95, 177, 129 } /* left = d45 */,
+ { 48, 31, 27, 114, 63, 183, 82, 116, 56 } /* left = d135 */,
+ { 43, 28, 37, 121, 63, 123, 61, 192, 169 } /* left = d117 */,
+ { 42, 17, 24, 109, 97, 177, 56, 76, 122 } /* left = d153 */,
+ { 46, 23, 32, 74, 86, 150, 67, 183, 88 } /* left = d63 */,
+ { 58, 18, 28, 105, 139, 182, 70, 92, 63 } /* left = d27 */,
+ { 36, 38, 48, 92, 122, 165, 88, 137, 91 } /* left = tm */
+ }, { /* above = d27 */
+ { 62, 44, 61, 123, 105, 189, 48, 57, 64 } /* left = v */,
+ { 47, 25, 17, 175, 222, 220, 24, 30, 86 } /* left = h */,
+ { 82, 22, 32, 127, 143, 213, 39, 41, 70 } /* left = dc */,
+ { 68, 36, 17, 106, 102, 206, 59, 74, 74 } /* left = d45 */,
+ { 57, 39, 23, 151, 68, 216, 55, 63, 58 } /* left = d135 */,
+ { 49, 30, 35, 141, 70, 168, 82, 40, 115 } /* left = d117 */,
+ { 51, 25, 15, 136, 129, 202, 38, 35, 139 } /* left = d153 */,
+ { 59, 39, 19, 114, 75, 180, 77, 104, 42 } /* left = d63 */,
+ { 68, 26, 16, 111, 141, 215, 29, 28, 28 } /* left = d27 */,
+ { 40, 61, 26, 126, 152, 206, 61, 59, 93 } /* left = tm */
+ }, { /* above = tm */
+ { 44, 78, 115, 132, 119, 173, 71, 112, 93 } /* left = v */,
+ { 39, 38, 21, 184, 227, 206, 42, 32, 64 } /* left = h */,
+ { 65, 70, 60, 155, 159, 199, 61, 60, 81 } /* left = dc */,
+ { 58, 47, 36, 124, 137, 193, 80, 82, 78 } /* left = d45 */,
+ { 49, 50, 35, 144, 95, 205, 63, 78, 59 } /* left = d135 */,
+ { 41, 53, 52, 148, 71, 142, 65, 128, 51 } /* left = d117 */,
+ { 40, 36, 28, 143, 143, 202, 40, 55, 137 } /* left = d153 */,
+ { 42, 44, 44, 104, 105, 164, 64, 130, 80 } /* left = d63 */,
+ { 52, 34, 29, 129, 183, 227, 42, 35, 43 } /* left = d27 */,
+ { 43, 81, 53, 140, 169, 204, 68, 84, 72 } /* left = tm */
+ }
+};
+
+static const uint8_t vp9_default_kf_uvmode_probs[10][9] = {
+ { 118, 15, 123, 148, 131, 101, 44, 93, 131 } /* y = v */,
+ { 113, 12, 23, 188, 226, 142, 26, 32, 125 } /* y = h */,
+ { 144, 11, 54, 157, 195, 130, 46, 58, 108 } /* y = dc */,
+ { 120, 11, 50, 123, 163, 135, 64, 77, 103 } /* y = d45 */,
+ { 113, 9, 36, 155, 111, 157, 32, 44, 161 } /* y = d135 */,
+ { 116, 9, 55, 176, 76, 96, 37, 61, 149 } /* y = d117 */,
+ { 115, 9, 28, 141, 161, 167, 21, 25, 193 } /* y = d153 */,
+ { 116, 12, 64, 120, 140, 125, 49, 115, 121 } /* y = d63 */,
+ { 120, 12, 32, 145, 195, 142, 32, 38, 86 } /* y = d27 */,
+ { 102, 19, 66, 162, 182, 122, 35, 59, 128 } /* y = tm */
+};
+
+enum InterPredMode {
+ NEARESTMV = 10,
+ NEARMV = 11,
+ ZEROMV = 12,
+ NEWMV = 13,
+};
+
+static const int8_t vp9_inter_mode_tree[3][2] = {
+ { -ZEROMV, 1 }, // '0'
+ { -NEARESTMV, 2 }, // '10'
+ { -NEARMV, -NEWMV }, // '11x'
+};
+
+static const int8_t vp9_filter_tree[2][2] = {
+ { -0, 1 }, // '0'
+ { -1, -2 }, // '1x'
+};
+
+static const enum FilterMode vp9_filter_lut[3] = {
+ FILTER_8TAP_REGULAR,
+ FILTER_8TAP_SMOOTH,
+ FILTER_8TAP_SHARP,
+};
+
+static const int16_t vp9_dc_qlookup[256] = {
+ 4, 8, 8, 9, 10, 11, 12, 12,
+ 13, 14, 15, 16, 17, 18, 19, 19,
+ 20, 21, 22, 23, 24, 25, 26, 26,
+ 27, 28, 29, 30, 31, 32, 32, 33,
+ 34, 35, 36, 37, 38, 38, 39, 40,
+ 41, 42, 43, 43, 44, 45, 46, 47,
+ 48, 48, 49, 50, 51, 52, 53, 53,
+ 54, 55, 56, 57, 57, 58, 59, 60,
+ 61, 62, 62, 63, 64, 65, 66, 66,
+ 67, 68, 69, 70, 70, 71, 72, 73,
+ 74, 74, 75, 76, 77, 78, 78, 79,
+ 80, 81, 81, 82, 83, 84, 85, 85,
+ 87, 88, 90, 92, 93, 95, 96, 98,
+ 99, 101, 102, 104, 105, 107, 108, 110,
+ 111, 113, 114, 116, 117, 118, 120, 121,
+ 123, 125, 127, 129, 131, 134, 136, 138,
+ 140, 142, 144, 146, 148, 150, 152, 154,
+ 156, 158, 161, 164, 166, 169, 172, 174,
+ 177, 180, 182, 185, 187, 190, 192, 195,
+ 199, 202, 205, 208, 211, 214, 217, 220,
+ 223, 226, 230, 233, 237, 240, 243, 247,
+ 250, 253, 257, 261, 265, 269, 272, 276,
+ 280, 284, 288, 292, 296, 300, 304, 309,
+ 313, 317, 322, 326, 330, 335, 340, 344,
+ 349, 354, 359, 364, 369, 374, 379, 384,
+ 389, 395, 400, 406, 411, 417, 423, 429,
+ 435, 441, 447, 454, 461, 467, 475, 482,
+ 489, 497, 505, 513, 522, 530, 539, 549,
+ 559, 569, 579, 590, 602, 614, 626, 640,
+ 654, 668, 684, 700, 717, 736, 755, 775,
+ 796, 819, 843, 869, 896, 925, 955, 988,
+ 1022, 1058, 1098, 1139, 1184, 1232, 1282, 1336,
+};
+
+static const int16_t vp9_ac_qlookup[256] = {
+ 4, 8, 9, 10, 11, 12, 13, 14,
+ 15, 16, 17, 18, 19, 20, 21, 22,
+ 23, 24, 25, 26, 27, 28, 29, 30,
+ 31, 32, 33, 34, 35, 36, 37, 38,
+ 39, 40, 41, 42, 43, 44, 45, 46,
+ 47, 48, 49, 50, 51, 52, 53, 54,
+ 55, 56, 57, 58, 59, 60, 61, 62,
+ 63, 64, 65, 66, 67, 68, 69, 70,
+ 71, 72, 73, 74, 75, 76, 77, 78,
+ 79, 80, 81, 82, 83, 84, 85, 86,
+ 87, 88, 89, 90, 91, 92, 93, 94,
+ 95, 96, 97, 98, 99, 100, 101, 102,
+ 104, 106, 108, 110, 112, 114, 116, 118,
+ 120, 122, 124, 126, 128, 130, 132, 134,
+ 136, 138, 140, 142, 144, 146, 148, 150,
+ 152, 155, 158, 161, 164, 167, 170, 173,
+ 176, 179, 182, 185, 188, 191, 194, 197,
+ 200, 203, 207, 211, 215, 219, 223, 227,
+ 231, 235, 239, 243, 247, 251, 255, 260,
+ 265, 270, 275, 280, 285, 290, 295, 300,
+ 305, 311, 317, 323, 329, 335, 341, 347,
+ 353, 359, 366, 373, 380, 387, 394, 401,
+ 408, 416, 424, 432, 440, 448, 456, 465,
+ 474, 483, 492, 501, 510, 520, 530, 540,
+ 550, 560, 571, 582, 593, 604, 615, 627,
+ 639, 651, 663, 676, 689, 702, 715, 729,
+ 743, 757, 771, 786, 801, 816, 832, 848,
+ 864, 881, 898, 915, 933, 951, 969, 988,
+ 1007, 1026, 1046, 1066, 1087, 1108, 1129, 1151,
+ 1173, 1196, 1219, 1243, 1267, 1292, 1317, 1343,
+ 1369, 1396, 1423, 1451, 1479, 1508, 1537, 1567,
+ 1597, 1628, 1660, 1692, 1725, 1759, 1793, 1828,
+};
+
+static const enum TxfmType vp9_intra_txfm_type[14] = {
+ [VERT_PRED] = ADST_DCT,
+ [HOR_PRED] = DCT_ADST,
+ [DC_PRED] = DCT_DCT,
+ [DIAG_DOWN_LEFT_PRED] = DCT_DCT,
+ [DIAG_DOWN_RIGHT_PRED] = ADST_ADST,
+ [VERT_RIGHT_PRED] = ADST_DCT,
+ [HOR_DOWN_PRED] = DCT_ADST,
+ [VERT_LEFT_PRED] = ADST_DCT,
+ [HOR_UP_PRED] = DCT_ADST,
+ [TM_VP8_PRED] = ADST_ADST,
+ [NEARESTMV] = DCT_DCT,
+ [NEARMV] = DCT_DCT,
+ [ZEROMV] = DCT_DCT,
+ [NEWMV] = DCT_DCT,
+};
+
+static const int16_t vp9_default_scan_4x4[16] = {
+ 0, 1, 4, 5,
+ 2, 8, 3, 6,
+ 12, 9, 7, 10,
+ 13, 11, 14, 15,
+};
+
+static const int16_t vp9_col_scan_4x4[16] = {
+ 0, 1, 2, 4,
+ 3, 5, 6, 8,
+ 7, 9, 10, 12,
+ 13, 11, 14, 15,
+};
+
+static const int16_t vp9_row_scan_4x4[16] = {
+ 0, 4, 1, 8,
+ 5, 12, 9, 2,
+ 6, 13, 3, 10,
+ 7, 14, 11, 15,
+};
+
+static const int16_t vp9_default_scan_8x8[64] = {
+ 0, 1, 8, 2, 9, 16, 10, 3,
+ 17, 24, 18, 11, 4, 25, 32, 19,
+ 12, 26, 5, 33, 20, 27, 40, 13,
+ 34, 6, 41, 28, 21, 35, 42, 48,
+ 14, 7, 36, 29, 43, 56, 49, 22,
+ 15, 37, 50, 44, 57, 30, 23, 51,
+ 45, 58, 38, 31, 52, 59, 39, 46,
+ 53, 60, 47, 54, 61, 55, 62, 63,
+};
+
+static const int16_t vp9_col_scan_8x8[64] = {
+ 0, 1, 2, 8, 3, 9, 4, 10,
+ 16, 5, 11, 17, 12, 18, 6, 24,
+ 19, 13, 25, 7, 26, 20, 32, 14,
+ 27, 21, 33, 28, 34, 15, 22, 35,
+ 40, 29, 41, 36, 23, 30, 42, 37,
+ 48, 43, 31, 44, 49, 38, 50, 56,
+ 45, 39, 51, 57, 52, 46, 58, 53,
+ 59, 47, 60, 54, 61, 55, 62, 63,
+};
+
+static const int16_t vp9_row_scan_8x8[64] = {
+ 0, 8, 16, 1, 9, 24, 2, 17,
+ 32, 10, 25, 3, 40, 18, 11, 33,
+ 26, 19, 4, 48, 41, 34, 12, 27,
+ 56, 20, 5, 42, 35, 13, 49, 28,
+ 6, 21, 43, 36, 14, 50, 29, 57,
+ 7, 44, 22, 37, 51, 15, 58, 30,
+ 23, 45, 52, 38, 59, 31, 46, 53,
+ 39, 60, 47, 61, 54, 62, 55, 63,
+};
+
+static const int16_t vp9_default_scan_16x16[256] = {
+ 0, 1, 16, 2, 17, 32, 3, 18, 33, 48, 4, 34, 19, 49, 20, 5,
+ 35, 64, 50, 36, 65, 21, 6, 51, 80, 66, 37, 22, 52, 7, 81, 67,
+ 38, 82, 53, 23, 96, 68, 8, 83, 97, 54, 39, 69, 112, 24, 98, 84,
+ 70, 55, 9, 40, 85, 99, 113, 128, 25, 114, 100, 71, 86, 56, 10, 41,
+ 115, 101, 129, 116, 72, 87, 26, 130, 144, 102, 57, 11, 42, 117, 131, 145,
+ 88, 103, 27, 73, 132, 118, 146, 58, 160, 12, 43, 133, 147, 104, 89, 119,
+ 161, 74, 148, 134, 28, 162, 59, 13, 176, 120, 149, 90, 135, 105, 163, 44,
+ 75, 177, 164, 29, 150, 121, 136, 178, 165, 14, 106, 60, 91, 151, 45, 179,
+ 192, 137, 166, 122, 76, 180, 152, 30, 61, 15, 107, 167, 181, 193, 92, 208,
+ 46, 138, 123, 153, 194, 77, 168, 182, 31, 195, 209, 183, 108, 139, 62, 154,
+ 47, 196, 93, 169, 210, 197, 224, 124, 184, 211, 78, 109, 170, 155, 63, 198,
+ 212, 185, 225, 240, 140, 94, 199, 125, 79, 213, 226, 171, 186, 156, 214, 200,
+ 110, 227, 141, 95, 241, 215, 228, 201, 126, 242, 187, 172, 157, 229, 111, 216,
+ 243, 142, 202, 230, 127, 217, 244, 173, 188, 231, 158, 203, 143, 245, 218, 232,
+ 189, 246, 159, 174, 233, 247, 219, 204, 175, 190, 248, 234, 205, 220, 249, 191,
+ 235, 221, 250, 206, 222, 251, 236, 207, 237, 223, 252, 238, 253, 239, 254, 255,
+};
+
+static const int16_t vp9_col_scan_16x16[256] = {
+ 0, 1, 2, 3, 16, 4, 17, 5, 18, 6, 19, 32, 20, 7, 33, 21,
+ 34, 8, 35, 22, 48, 36, 9, 49, 23, 50, 37, 10, 38, 51, 24, 64,
+ 52, 11, 65, 39, 25, 53, 66, 54, 40, 67, 12, 80, 26, 68, 55, 81,
+ 41, 69, 13, 27, 82, 56, 70, 83, 42, 14, 84, 96, 71, 28, 57, 85,
+ 97, 15, 72, 98, 43, 86, 58, 99, 29, 87, 100, 112, 73, 44, 101, 59,
+ 30, 113, 88, 114, 74, 128, 102, 45, 31, 115, 60, 103, 89, 116, 75, 129,
+ 117, 46, 104, 90, 61, 130, 118, 131, 132, 105, 76, 47, 119, 144, 91, 62,
+ 133, 106, 145, 120, 146, 134, 77, 147, 121, 92, 135, 148, 63, 107, 136, 122,
+ 93, 149, 160, 78, 150, 137, 108, 161, 162, 151, 123, 79, 138, 163, 152, 94,
+ 164, 109, 165, 153, 124, 139, 176, 166, 95, 177, 167, 110, 154, 178, 125, 179,
+ 140, 168, 155, 111, 180, 192, 181, 169, 141, 126, 182, 193, 194, 156, 183, 170,
+ 195, 127, 142, 196, 184, 208, 197, 157, 171, 143, 185, 198, 209, 199, 210, 172,
+ 158, 186, 211, 224, 212, 200, 240, 159, 213, 225, 187, 201, 173, 226, 214, 215,
+ 227, 202, 228, 188, 241, 216, 174, 229, 242, 203, 243, 217, 230, 175, 189, 244,
+ 231, 204, 218, 232, 245, 219, 246, 190, 233, 205, 191, 247, 234, 248, 220, 206,
+ 249, 235, 221, 207, 250, 236, 222, 251, 223, 237, 238, 252, 239, 253, 254, 255,
+};
+
+static const int16_t vp9_row_scan_16x16[256] = {
+ 0, 16, 32, 1, 48, 17, 64, 33, 2, 80, 18, 49, 96, 34, 3, 65,
+ 19, 112, 50, 81, 35, 4, 128, 66, 20, 97, 51, 82, 5, 144, 36, 67,
+ 113, 98, 21, 52, 160, 83, 129, 37, 68, 6, 114, 176, 99, 53, 22, 84,
+ 145, 38, 69, 130, 7, 115, 192, 100, 54, 23, 85, 161, 146, 131, 39, 70,
+ 208, 116, 8, 101, 177, 55, 86, 24, 162, 147, 132, 71, 224, 117, 40, 102,
+ 9, 148, 56, 87, 193, 163, 240, 133, 178, 25, 118, 72, 41, 103, 164, 10,
+ 149, 88, 134, 209, 179, 57, 119, 194, 26, 73, 165, 150, 104, 42, 135, 11,
+ 180, 120, 89, 225, 195, 58, 27, 210, 151, 181, 166, 74, 43, 105, 12, 136,
+ 90, 59, 241, 121, 28, 196, 167, 211, 152, 44, 182, 137, 75, 13, 226, 106,
+ 122, 60, 197, 91, 168, 29, 183, 153, 14, 76, 212, 138, 45, 107, 15, 198,
+ 92, 227, 169, 30, 123, 154, 61, 242, 184, 213, 139, 46, 77, 31, 108, 170,
+ 199, 185, 124, 228, 93, 155, 214, 62, 140, 243, 78, 47, 200, 109, 186, 171,
+ 201, 94, 63, 215, 229, 156, 79, 125, 141, 110, 216, 187, 172, 244, 202, 230,
+ 217, 95, 157, 126, 245, 111, 142, 231, 188, 127, 158, 218, 173, 232, 246, 233,
+ 203, 143, 247, 174, 189, 159, 219, 204, 248, 234, 249, 175, 190, 220, 205, 250,
+ 235, 191, 221, 251, 236, 206, 252, 222, 207, 237, 223, 253, 238, 254, 239, 255,
+};
+
+static const int16_t vp9_default_scan_32x32[1024] = {
+ 0, 1, 32, 2, 33, 64, 3, 34, 65, 4, 96, 35, 66, 5, 36, 97, 67, 128, 98, 68, 37, 6, 129, 99, 7, 160, 69, 38, 130, 100, 161, 131,
+ 39, 70, 8, 101, 162, 132, 192, 71, 40, 9, 102, 163, 133, 193, 72, 224, 103, 41, 164, 10, 194, 134, 165, 73, 104, 135, 225, 42, 195, 11, 256, 166,
+ 226, 196, 74, 105, 136, 43, 12, 167, 197, 227, 257, 75, 106, 137, 228, 44, 198, 168, 258, 288, 13, 229, 76, 107, 199, 138, 259, 169, 289, 45, 230, 260,
+ 200, 108, 14, 170, 139, 320, 290, 77, 231, 261, 46, 201, 140, 291, 109, 232, 321, 262, 171, 78, 292, 15, 322, 202, 263, 352, 172, 293, 233, 141, 323, 110,
+ 47, 203, 264, 234, 294, 353, 324, 16, 79, 204, 265, 295, 325, 173, 354, 142, 235, 384, 48, 296, 111, 266, 355, 326, 80, 17, 205, 236, 174, 356, 385, 327,
+ 143, 297, 267, 357, 386, 112, 49, 328, 298, 206, 416, 237, 358, 387, 81, 175, 18, 329, 359, 388, 299, 330, 389, 113, 417, 238, 360, 50, 207, 418, 390, 331,
+ 19, 448, 361, 82, 419, 391, 239, 51, 362, 420, 114, 449, 480, 421, 83, 363, 450, 422, 512, 451, 423, 115, 452, 481, 453, 482, 454, 544, 483, 455, 513, 484,
+ 514, 485, 515, 486, 545, 576, 487, 546, 547, 608, 577, 578, 579, 609, 610, 611, 20, 144, 268, 392, 516, 640, 21, 52, 145, 176, 269, 300, 393, 424, 517, 548,
+ 641, 672, 22, 53, 84, 146, 177, 208, 270, 301, 332, 394, 425, 456, 518, 549, 580, 642, 673, 704, 23, 54, 85, 116, 147, 178, 209, 240, 271, 302, 333, 364,
+ 395, 426, 457, 488, 519, 550, 581, 612, 643, 674, 705, 736, 55, 86, 117, 179, 210, 241, 303, 334, 365, 427, 458, 489, 551, 582, 613, 675, 706, 737, 87, 118,
+ 211, 242, 335, 366, 459, 490, 583, 614, 707, 738, 119, 243, 367, 491, 615, 739, 24, 148, 272, 396, 520, 644, 768, 25, 56, 149, 180, 273, 304, 397, 428, 521,
+ 552, 645, 676, 769, 800, 26, 57, 88, 150, 181, 212, 274, 305, 336, 398, 429, 460, 522, 553, 584, 646, 677, 708, 770, 801, 832, 27, 58, 89, 120, 151, 182,
+ 213, 244, 275, 306, 337, 368, 399, 430, 461, 492, 523, 554, 585, 616, 647, 678, 709, 740, 771, 802, 833, 864, 59, 90, 121, 183, 214, 245, 307, 338, 369, 431,
+ 462, 493, 555, 586, 617, 679, 710, 741, 803, 834, 865, 91, 122, 215, 246, 339, 370, 463, 494, 587, 618, 711, 742, 835, 866, 123, 247, 371, 495, 619, 743, 867,
+ 28, 152, 276, 400, 524, 648, 772, 896, 29, 60, 153, 184, 277, 308, 401, 432, 525, 556, 649, 680, 773, 804, 897, 928, 30, 61, 92, 154, 185, 216, 278, 309,
+ 340, 402, 433, 464, 526, 557, 588, 650, 681, 712, 774, 805, 836, 898, 929, 960, 31, 62, 93, 124, 155, 186, 217, 248, 279, 310, 341, 372, 403, 434, 465, 496,
+ 527, 558, 589, 620, 651, 682, 713, 744, 775, 806, 837, 868, 899, 930, 961, 992, 63, 94, 125, 187, 218, 249, 311, 342, 373, 435, 466, 497, 559, 590, 621, 683,
+ 714, 745, 807, 838, 869, 931, 962, 993, 95, 126, 219, 250, 343, 374, 467, 498, 591, 622, 715, 746, 839, 870, 963, 994, 127, 251, 375, 499, 623, 747, 871, 995,
+ 156, 280, 404, 528, 652, 776, 900, 157, 188, 281, 312, 405, 436, 529, 560, 653, 684, 777, 808, 901, 932, 158, 189, 220, 282, 313, 344, 406, 437, 468, 530, 561,
+ 592, 654, 685, 716, 778, 809, 840, 902, 933, 964, 159, 190, 221, 252, 283, 314, 345, 376, 407, 438, 469, 500, 531, 562, 593, 624, 655, 686, 717, 748, 779, 810,
+ 841, 872, 903, 934, 965, 996, 191, 222, 253, 315, 346, 377, 439, 470, 501, 563, 594, 625, 687, 718, 749, 811, 842, 873, 935, 966, 997, 223, 254, 347, 378, 471,
+ 502, 595, 626, 719, 750, 843, 874, 967, 998, 255, 379, 503, 627, 751, 875, 999, 284, 408, 532, 656, 780, 904, 285, 316, 409, 440, 533, 564, 657, 688, 781, 812,
+ 905, 936, 286, 317, 348, 410, 441, 472, 534, 565, 596, 658, 689, 720, 782, 813, 844, 906, 937, 968, 287, 318, 349, 380, 411, 442, 473, 504, 535, 566, 597, 628,
+ 659, 690, 721, 752, 783, 814, 845, 876, 907, 938, 969, 1000, 319, 350, 381, 443, 474, 505, 567, 598, 629, 691, 722, 753, 815, 846, 877, 939, 970, 1001, 351, 382,
+ 475, 506, 599, 630, 723, 754, 847, 878, 971, 1002, 383, 507, 631, 755, 879, 1003, 412, 536, 660, 784, 908, 413, 444, 537, 568, 661, 692, 785, 816, 909, 940, 414,
+ 445, 476, 538, 569, 600, 662, 693, 724, 786, 817, 848, 910, 941, 972, 415, 446, 477, 508, 539, 570, 601, 632, 663, 694, 725, 756, 787, 818, 849, 880, 911, 942,
+ 973, 1004, 447, 478, 509, 571, 602, 633, 695, 726, 757, 819, 850, 881, 943, 974, 1005, 479, 510, 603, 634, 727, 758, 851, 882, 975, 1006, 511, 635, 759, 883, 1007,
+ 540, 664, 788, 912, 541, 572, 665, 696, 789, 820, 913, 944, 542, 573, 604, 666, 697, 728, 790, 821, 852, 914, 945, 976, 543, 574, 605, 636, 667, 698, 729, 760,
+ 791, 822, 853, 884, 915, 946, 977, 1008, 575, 606, 637, 699, 730, 761, 823, 854, 885, 947, 978, 1009, 607, 638, 731, 762, 855, 886, 979, 1010, 639, 763, 887, 1011,
+ 668, 792, 916, 669, 700, 793, 824, 917, 948, 670, 701, 732, 794, 825, 856, 918, 949, 980, 671, 702, 733, 764, 795, 826, 857, 888, 919, 950, 981, 1012, 703, 734,
+ 765, 827, 858, 889, 951, 982, 1013, 735, 766, 859, 890, 983, 1014, 767, 891, 1015, 796, 920, 797, 828, 921, 952, 798, 829, 860, 922, 953, 984, 799, 830, 861, 892,
+ 923, 954, 985, 1016, 831, 862, 893, 955, 986, 1017, 863, 894, 987, 1018, 895, 1019, 924, 925, 956, 926, 957, 988, 927, 958, 989, 1020, 959, 990, 1021, 991, 1022, 1023,
+};
+
+static const int16_t *vp9_scans[5][4] = {
+ {
+ vp9_default_scan_4x4, vp9_col_scan_4x4,
+ vp9_row_scan_4x4, vp9_default_scan_4x4
+ }, {
+ vp9_default_scan_8x8, vp9_col_scan_8x8,
+ vp9_row_scan_8x8, vp9_default_scan_8x8
+ }, {
+ vp9_default_scan_16x16, vp9_col_scan_16x16,
+ vp9_row_scan_16x16, vp9_default_scan_16x16
+ }, {
+ vp9_default_scan_32x32, vp9_default_scan_32x32,
+ vp9_default_scan_32x32, vp9_default_scan_32x32
+ }, { // lossless
+ vp9_default_scan_4x4, vp9_default_scan_4x4,
+ vp9_default_scan_4x4, vp9_default_scan_4x4
+ }
+};
+
+static const int16_t vp9_default_scan_4x4_nb[16][2] = {
+ { 0, 0 }, { 0, 0 }, { 4, 1 }, { 1, 1 },
+ { 4, 4 }, { 2, 2 }, { 5, 2 }, { 8, 8 },
+ { 8, 5 }, { 6, 3 }, { 9, 6 }, { 12, 9 },
+ { 10, 7 }, { 13, 10 }, { 14, 11 }, { 0, 0 },
+};
+
+static const int16_t vp9_col_scan_4x4_nb[16][2] = {
+ { 0, 0 }, { 1, 1 }, { 0, 0 }, { 2, 2 },
+ { 4, 4 }, { 5, 5 }, { 4, 4 }, { 6, 6 },
+ { 8, 8 }, { 9, 9 }, { 8, 8 }, { 12, 12 },
+ { 10, 10 }, { 13, 13 }, { 14, 14 }, { 0, 0 },
+};
+
+static const int16_t vp9_row_scan_4x4_nb[16][2] = {
+ { 0, 0 }, { 0, 0 }, { 4, 4 }, { 1, 1 },
+ { 8, 8 }, { 5, 5 }, { 1, 1 }, { 2, 2 },
+ { 9, 9 }, { 2, 2 }, { 6, 6 }, { 3, 3 },
+ { 10, 10 }, { 7, 7 }, { 11, 11 }, { 0, 0 },
+};
+
+static const int16_t vp9_default_scan_8x8_nb[64][2] = {
+ { 0, 0 }, { 0, 0 }, { 1, 1 }, { 8, 1 },
+ { 8, 8 }, { 9, 2 }, { 2, 2 }, { 16, 9 },
+ { 16, 16 }, { 17, 10 }, { 10, 3 }, { 3, 3 },
+ { 24, 17 }, { 24, 24 }, { 18, 11 }, { 11, 4 },
+ { 25, 18 }, { 4, 4 }, { 32, 25 }, { 19, 12 },
+ { 26, 19 }, { 32, 32 }, { 12, 5 }, { 33, 26 },
+ { 5, 5 }, { 40, 33 }, { 27, 20 }, { 20, 13 },
+ { 34, 27 }, { 41, 34 }, { 40, 40 }, { 13, 6 },
+ { 6, 6 }, { 35, 28 }, { 28, 21 }, { 42, 35 },
+ { 48, 48 }, { 48, 41 }, { 21, 14 }, { 14, 7 },
+ { 36, 29 }, { 49, 42 }, { 43, 36 }, { 56, 49 },
+ { 29, 22 }, { 22, 15 }, { 50, 43 }, { 44, 37 },
+ { 57, 50 }, { 37, 30 }, { 30, 23 }, { 51, 44 },
+ { 58, 51 }, { 38, 31 }, { 45, 38 }, { 52, 45 },
+ { 59, 52 }, { 46, 39 }, { 53, 46 }, { 60, 53 },
+ { 54, 47 }, { 61, 54 }, { 62, 55 }, { 0, 0 },
+};
+
+static const int16_t vp9_col_scan_8x8_nb[64][2] = {
+ { 0, 0 }, { 1, 1 }, { 0, 0 }, { 2, 2 },
+ { 8, 8 }, { 3, 3 }, { 9, 9 }, { 8, 8 },
+ { 4, 4 }, { 10, 10 }, { 16, 16 }, { 11, 11 },
+ { 17, 17 }, { 5, 5 }, { 16, 16 }, { 18, 18 },
+ { 12, 12 }, { 24, 24 }, { 6, 6 }, { 25, 25 },
+ { 19, 19 }, { 24, 24 }, { 13, 13 }, { 26, 26 },
+ { 20, 20 }, { 32, 32 }, { 27, 27 }, { 33, 33 },
+ { 14, 14 }, { 21, 21 }, { 34, 34 }, { 32, 32 },
+ { 28, 28 }, { 40, 40 }, { 35, 35 }, { 22, 22 },
+ { 29, 29 }, { 41, 41 }, { 36, 36 }, { 40, 40 },
+ { 42, 42 }, { 30, 30 }, { 43, 43 }, { 48, 48 },
+ { 37, 37 }, { 49, 49 }, { 48, 48 }, { 44, 44 },
+ { 38, 38 }, { 50, 50 }, { 56, 56 }, { 51, 51 },
+ { 45, 45 }, { 57, 57 }, { 52, 52 }, { 58, 58 },
+ { 46, 46 }, { 59, 59 }, { 53, 53 }, { 60, 60 },
+ { 54, 54 }, { 61, 61 }, { 62, 62 }, { 0, 0 },
+};
+
+static const int16_t vp9_row_scan_8x8_nb[64][2] = {
+ { 0, 0 }, { 8, 8 }, { 0, 0 }, { 1, 1 },
+ { 16, 16 }, { 1, 1 }, { 9, 9 }, { 24, 24 },
+ { 2, 2 }, { 17, 17 }, { 2, 2 }, { 32, 32 },
+ { 10, 10 }, { 3, 3 }, { 25, 25 }, { 18, 18 },
+ { 11, 11 }, { 3, 3 }, { 40, 40 }, { 33, 33 },
+ { 26, 26 }, { 4, 4 }, { 19, 19 }, { 48, 48 },
+ { 12, 12 }, { 4, 4 }, { 34, 34 }, { 27, 27 },
+ { 5, 5 }, { 41, 41 }, { 20, 20 }, { 5, 5 },
+ { 13, 13 }, { 35, 35 }, { 28, 28 }, { 6, 6 },
+ { 42, 42 }, { 21, 21 }, { 49, 49 }, { 6, 6 },
+ { 36, 36 }, { 14, 14 }, { 29, 29 }, { 43, 43 },
+ { 7, 7 }, { 50, 50 }, { 22, 22 }, { 15, 15 },
+ { 37, 37 }, { 44, 44 }, { 30, 30 }, { 51, 51 },
+ { 23, 23 }, { 38, 38 }, { 45, 45 }, { 31, 31 },
+ { 52, 52 }, { 39, 39 }, { 53, 53 }, { 46, 46 },
+ { 54, 54 }, { 47, 47 }, { 55, 55 }, { 0, 0 },
+};
+
+static const int16_t vp9_default_scan_16x16_nb[256][2] = {
+ { 0, 0 }, { 0, 0 }, { 1, 1 }, { 16, 1 },
+ { 16, 16 }, { 2, 2 }, { 17, 2 }, { 32, 17 },
+ { 32, 32 }, { 3, 3 }, { 33, 18 }, { 18, 3 },
+ { 48, 33 }, { 19, 4 }, { 4, 4 }, { 34, 19 },
+ { 48, 48 }, { 49, 34 }, { 35, 20 }, { 64, 49 },
+ { 20, 5 }, { 5, 5 }, { 50, 35 }, { 64, 64 },
+ { 65, 50 }, { 36, 21 }, { 21, 6 }, { 51, 36 },
+ { 6, 6 }, { 80, 65 }, { 66, 51 }, { 37, 22 },
+ { 81, 66 }, { 52, 37 }, { 22, 7 }, { 80, 80 },
+ { 67, 52 }, { 7, 7 }, { 82, 67 }, { 96, 81 },
+ { 53, 38 }, { 38, 23 }, { 68, 53 }, { 96, 96 },
+ { 23, 8 }, { 97, 82 }, { 83, 68 }, { 69, 54 },
+ { 54, 39 }, { 8, 8 }, { 39, 24 }, { 84, 69 },
+ { 98, 83 }, { 112, 97 }, { 112, 112 }, { 24, 9 },
+ { 113, 98 }, { 99, 84 }, { 70, 55 }, { 85, 70 },
+ { 55, 40 }, { 9, 9 }, { 40, 25 }, { 114, 99 },
+ { 100, 85 }, { 128, 113 }, { 115, 100 }, { 71, 56 },
+ { 86, 71 }, { 25, 10 }, { 129, 114 }, { 128, 128 },
+ { 101, 86 }, { 56, 41 }, { 10, 10 }, { 41, 26 },
+ { 116, 101 }, { 130, 115 }, { 144, 129 }, { 87, 72 },
+ { 102, 87 }, { 26, 11 }, { 72, 57 }, { 131, 116 },
+ { 117, 102 }, { 145, 130 }, { 57, 42 }, { 144, 144 },
+ { 11, 11 }, { 42, 27 }, { 132, 117 }, { 146, 131 },
+ { 103, 88 }, { 88, 73 }, { 118, 103 }, { 160, 145 },
+ { 73, 58 }, { 147, 132 }, { 133, 118 }, { 27, 12 },
+ { 161, 146 }, { 58, 43 }, { 12, 12 }, { 160, 160 },
+ { 119, 104 }, { 148, 133 }, { 89, 74 }, { 134, 119 },
+ { 104, 89 }, { 162, 147 }, { 43, 28 }, { 74, 59 },
+ { 176, 161 }, { 163, 148 }, { 28, 13 }, { 149, 134 },
+ { 120, 105 }, { 135, 120 }, { 177, 162 }, { 164, 149 },
+ { 13, 13 }, { 105, 90 }, { 59, 44 }, { 90, 75 },
+ { 150, 135 }, { 44, 29 }, { 178, 163 }, { 176, 176 },
+ { 136, 121 }, { 165, 150 }, { 121, 106 }, { 75, 60 },
+ { 179, 164 }, { 151, 136 }, { 29, 14 }, { 60, 45 },
+ { 14, 14 }, { 106, 91 }, { 166, 151 }, { 180, 165 },
+ { 192, 177 }, { 91, 76 }, { 192, 192 }, { 45, 30 },
+ { 137, 122 }, { 122, 107 }, { 152, 137 }, { 193, 178 },
+ { 76, 61 }, { 167, 152 }, { 181, 166 }, { 30, 15 },
+ { 194, 179 }, { 208, 193 }, { 182, 167 }, { 107, 92 },
+ { 138, 123 }, { 61, 46 }, { 153, 138 }, { 46, 31 },
+ { 195, 180 }, { 92, 77 }, { 168, 153 }, { 209, 194 },
+ { 196, 181 }, { 208, 208 }, { 123, 108 }, { 183, 168 },
+ { 210, 195 }, { 77, 62 }, { 108, 93 }, { 169, 154 },
+ { 154, 139 }, { 62, 47 }, { 197, 182 }, { 211, 196 },
+ { 184, 169 }, { 224, 209 }, { 224, 224 }, { 139, 124 },
+ { 93, 78 }, { 198, 183 }, { 124, 109 }, { 78, 63 },
+ { 212, 197 }, { 225, 210 }, { 170, 155 }, { 185, 170 },
+ { 155, 140 }, { 213, 198 }, { 199, 184 }, { 109, 94 },
+ { 226, 211 }, { 140, 125 }, { 94, 79 }, { 240, 225 },
+ { 214, 199 }, { 227, 212 }, { 200, 185 }, { 125, 110 },
+ { 241, 226 }, { 186, 171 }, { 171, 156 }, { 156, 141 },
+ { 228, 213 }, { 110, 95 }, { 215, 200 }, { 242, 227 },
+ { 141, 126 }, { 201, 186 }, { 229, 214 }, { 126, 111 },
+ { 216, 201 }, { 243, 228 }, { 172, 157 }, { 187, 172 },
+ { 230, 215 }, { 157, 142 }, { 202, 187 }, { 142, 127 },
+ { 244, 229 }, { 217, 202 }, { 231, 216 }, { 188, 173 },
+ { 245, 230 }, { 158, 143 }, { 173, 158 }, { 232, 217 },
+ { 246, 231 }, { 218, 203 }, { 203, 188 }, { 174, 159 },
+ { 189, 174 }, { 247, 232 }, { 233, 218 }, { 204, 189 },
+ { 219, 204 }, { 248, 233 }, { 190, 175 }, { 234, 219 },
+ { 220, 205 }, { 249, 234 }, { 205, 190 }, { 221, 206 },
+ { 250, 235 }, { 235, 220 }, { 206, 191 }, { 236, 221 },
+ { 222, 207 }, { 251, 236 }, { 237, 222 }, { 252, 237 },
+ { 238, 223 }, { 253, 238 }, { 254, 239 }, { 0, 0 },
+};
+
+static const int16_t vp9_col_scan_16x16_nb[256][2] = {
+ { 0, 0 }, { 1, 1 }, { 2, 2 }, { 0, 0 },
+ { 3, 3 }, { 16, 16 }, { 4, 4 }, { 17, 17 },
+ { 5, 5 }, { 18, 18 }, { 16, 16 }, { 19, 19 },
+ { 6, 6 }, { 32, 32 }, { 20, 20 }, { 33, 33 },
+ { 7, 7 }, { 34, 34 }, { 21, 21 }, { 32, 32 },
+ { 35, 35 }, { 8, 8 }, { 48, 48 }, { 22, 22 },
+ { 49, 49 }, { 36, 36 }, { 9, 9 }, { 37, 37 },
+ { 50, 50 }, { 23, 23 }, { 48, 48 }, { 51, 51 },
+ { 10, 10 }, { 64, 64 }, { 38, 38 }, { 24, 24 },
+ { 52, 52 }, { 65, 65 }, { 53, 53 }, { 39, 39 },
+ { 66, 66 }, { 11, 11 }, { 64, 64 }, { 25, 25 },
+ { 67, 67 }, { 54, 54 }, { 80, 80 }, { 40, 40 },
+ { 68, 68 }, { 12, 12 }, { 26, 26 }, { 81, 81 },
+ { 55, 55 }, { 69, 69 }, { 82, 82 }, { 41, 41 },
+ { 13, 13 }, { 83, 83 }, { 80, 80 }, { 70, 70 },
+ { 27, 27 }, { 56, 56 }, { 84, 84 }, { 96, 96 },
+ { 14, 14 }, { 71, 71 }, { 97, 97 }, { 42, 42 },
+ { 85, 85 }, { 57, 57 }, { 98, 98 }, { 28, 28 },
+ { 86, 86 }, { 99, 99 }, { 96, 96 }, { 72, 72 },
+ { 43, 43 }, { 100, 100 }, { 58, 58 }, { 29, 29 },
+ { 112, 112 }, { 87, 87 }, { 113, 113 }, { 73, 73 },
+ { 112, 112 }, { 101, 101 }, { 44, 44 }, { 30, 30 },
+ { 114, 114 }, { 59, 59 }, { 102, 102 }, { 88, 88 },
+ { 115, 115 }, { 74, 74 }, { 128, 128 }, { 116, 116 },
+ { 45, 45 }, { 103, 103 }, { 89, 89 }, { 60, 60 },
+ { 129, 129 }, { 117, 117 }, { 130, 130 }, { 131, 131 },
+ { 104, 104 }, { 75, 75 }, { 46, 46 }, { 118, 118 },
+ { 128, 128 }, { 90, 90 }, { 61, 61 }, { 132, 132 },
+ { 105, 105 }, { 144, 144 }, { 119, 119 }, { 145, 145 },
+ { 133, 133 }, { 76, 76 }, { 146, 146 }, { 120, 120 },
+ { 91, 91 }, { 134, 134 }, { 147, 147 }, { 62, 62 },
+ { 106, 106 }, { 135, 135 }, { 121, 121 }, { 92, 92 },
+ { 148, 148 }, { 144, 144 }, { 77, 77 }, { 149, 149 },
+ { 136, 136 }, { 107, 107 }, { 160, 160 }, { 161, 161 },
+ { 150, 150 }, { 122, 122 }, { 78, 78 }, { 137, 137 },
+ { 162, 162 }, { 151, 151 }, { 93, 93 }, { 163, 163 },
+ { 108, 108 }, { 164, 164 }, { 152, 152 }, { 123, 123 },
+ { 138, 138 }, { 160, 160 }, { 165, 165 }, { 94, 94 },
+ { 176, 176 }, { 166, 166 }, { 109, 109 }, { 153, 153 },
+ { 177, 177 }, { 124, 124 }, { 178, 178 }, { 139, 139 },
+ { 167, 167 }, { 154, 154 }, { 110, 110 }, { 179, 179 },
+ { 176, 176 }, { 180, 180 }, { 168, 168 }, { 140, 140 },
+ { 125, 125 }, { 181, 181 }, { 192, 192 }, { 193, 193 },
+ { 155, 155 }, { 182, 182 }, { 169, 169 }, { 194, 194 },
+ { 126, 126 }, { 141, 141 }, { 195, 195 }, { 183, 183 },
+ { 192, 192 }, { 196, 196 }, { 156, 156 }, { 170, 170 },
+ { 142, 142 }, { 184, 184 }, { 197, 197 }, { 208, 208 },
+ { 198, 198 }, { 209, 209 }, { 171, 171 }, { 157, 157 },
+ { 185, 185 }, { 210, 210 }, { 208, 208 }, { 211, 211 },
+ { 199, 199 }, { 224, 224 }, { 158, 158 }, { 212, 212 },
+ { 224, 224 }, { 186, 186 }, { 200, 200 }, { 172, 172 },
+ { 225, 225 }, { 213, 213 }, { 214, 214 }, { 226, 226 },
+ { 201, 201 }, { 227, 227 }, { 187, 187 }, { 240, 240 },
+ { 215, 215 }, { 173, 173 }, { 228, 228 }, { 241, 241 },
+ { 202, 202 }, { 242, 242 }, { 216, 216 }, { 229, 229 },
+ { 174, 174 }, { 188, 188 }, { 243, 243 }, { 230, 230 },
+ { 203, 203 }, { 217, 217 }, { 231, 231 }, { 244, 244 },
+ { 218, 218 }, { 245, 245 }, { 189, 189 }, { 232, 232 },
+ { 204, 204 }, { 190, 190 }, { 246, 246 }, { 233, 233 },
+ { 247, 247 }, { 219, 219 }, { 205, 205 }, { 248, 248 },
+ { 234, 234 }, { 220, 220 }, { 206, 206 }, { 249, 249 },
+ { 235, 235 }, { 221, 221 }, { 250, 250 }, { 222, 222 },
+ { 236, 236 }, { 237, 237 }, { 251, 251 }, { 238, 238 },
+ { 252, 252 }, { 253, 253 }, { 254, 254 }, { 0, 0 },
+};
+
+static const int16_t vp9_row_scan_16x16_nb[256][2] = {
+ { 0, 0 }, { 16, 16 }, { 0, 0 }, { 32, 32 },
+ { 1, 1 }, { 48, 48 }, { 17, 17 }, { 1, 1 },
+ { 64, 64 }, { 2, 2 }, { 33, 33 }, { 80, 80 },
+ { 18, 18 }, { 2, 2 }, { 49, 49 }, { 3, 3 },
+ { 96, 96 }, { 34, 34 }, { 65, 65 }, { 19, 19 },
+ { 3, 3 }, { 112, 112 }, { 50, 50 }, { 4, 4 },
+ { 81, 81 }, { 35, 35 }, { 66, 66 }, { 4, 4 },
+ { 128, 128 }, { 20, 20 }, { 51, 51 }, { 97, 97 },
+ { 82, 82 }, { 5, 5 }, { 36, 36 }, { 144, 144 },
+ { 67, 67 }, { 113, 113 }, { 21, 21 }, { 52, 52 },
+ { 5, 5 }, { 98, 98 }, { 160, 160 }, { 83, 83 },
+ { 37, 37 }, { 6, 6 }, { 68, 68 }, { 129, 129 },
+ { 22, 22 }, { 53, 53 }, { 114, 114 }, { 6, 6 },
+ { 99, 99 }, { 176, 176 }, { 84, 84 }, { 38, 38 },
+ { 7, 7 }, { 69, 69 }, { 145, 145 }, { 130, 130 },
+ { 115, 115 }, { 23, 23 }, { 54, 54 }, { 192, 192 },
+ { 100, 100 }, { 7, 7 }, { 85, 85 }, { 161, 161 },
+ { 39, 39 }, { 70, 70 }, { 8, 8 }, { 146, 146 },
+ { 131, 131 }, { 116, 116 }, { 55, 55 }, { 208, 208 },
+ { 101, 101 }, { 24, 24 }, { 86, 86 }, { 8, 8 },
+ { 132, 132 }, { 40, 40 }, { 71, 71 }, { 177, 177 },
+ { 147, 147 }, { 224, 224 }, { 117, 117 }, { 162, 162 },
+ { 9, 9 }, { 102, 102 }, { 56, 56 }, { 25, 25 },
+ { 87, 87 }, { 148, 148 }, { 9, 9 }, { 133, 133 },
+ { 72, 72 }, { 118, 118 }, { 193, 193 }, { 163, 163 },
+ { 41, 41 }, { 103, 103 }, { 178, 178 }, { 10, 10 },
+ { 57, 57 }, { 149, 149 }, { 134, 134 }, { 88, 88 },
+ { 26, 26 }, { 119, 119 }, { 10, 10 }, { 164, 164 },
+ { 104, 104 }, { 73, 73 }, { 209, 209 }, { 179, 179 },
+ { 42, 42 }, { 11, 11 }, { 194, 194 }, { 135, 135 },
+ { 165, 165 }, { 150, 150 }, { 58, 58 }, { 27, 27 },
+ { 89, 89 }, { 11, 11 }, { 120, 120 }, { 74, 74 },
+ { 43, 43 }, { 225, 225 }, { 105, 105 }, { 12, 12 },
+ { 180, 180 }, { 151, 151 }, { 195, 195 }, { 136, 136 },
+ { 28, 28 }, { 166, 166 }, { 121, 121 }, { 59, 59 },
+ { 12, 12 }, { 210, 210 }, { 90, 90 }, { 106, 106 },
+ { 44, 44 }, { 181, 181 }, { 75, 75 }, { 152, 152 },
+ { 13, 13 }, { 167, 167 }, { 137, 137 }, { 13, 13 },
+ { 60, 60 }, { 196, 196 }, { 122, 122 }, { 29, 29 },
+ { 91, 91 }, { 14, 14 }, { 182, 182 }, { 76, 76 },
+ { 211, 211 }, { 153, 153 }, { 14, 14 }, { 107, 107 },
+ { 138, 138 }, { 45, 45 }, { 226, 226 }, { 168, 168 },
+ { 197, 197 }, { 123, 123 }, { 30, 30 }, { 61, 61 },
+ { 15, 15 }, { 92, 92 }, { 154, 154 }, { 183, 183 },
+ { 169, 169 }, { 108, 108 }, { 212, 212 }, { 77, 77 },
+ { 139, 139 }, { 198, 198 }, { 46, 46 }, { 124, 124 },
+ { 227, 227 }, { 62, 62 }, { 31, 31 }, { 184, 184 },
+ { 93, 93 }, { 170, 170 }, { 155, 155 }, { 185, 185 },
+ { 78, 78 }, { 47, 47 }, { 199, 199 }, { 213, 213 },
+ { 140, 140 }, { 63, 63 }, { 109, 109 }, { 125, 125 },
+ { 94, 94 }, { 200, 200 }, { 171, 171 }, { 156, 156 },
+ { 228, 228 }, { 186, 186 }, { 214, 214 }, { 201, 201 },
+ { 79, 79 }, { 141, 141 }, { 110, 110 }, { 229, 229 },
+ { 95, 95 }, { 126, 126 }, { 215, 215 }, { 172, 172 },
+ { 111, 111 }, { 142, 142 }, { 202, 202 }, { 157, 157 },
+ { 216, 216 }, { 230, 230 }, { 217, 217 }, { 187, 187 },
+ { 127, 127 }, { 231, 231 }, { 158, 158 }, { 173, 173 },
+ { 143, 143 }, { 203, 203 }, { 188, 188 }, { 232, 232 },
+ { 218, 218 }, { 233, 233 }, { 159, 159 }, { 174, 174 },
+ { 204, 204 }, { 189, 189 }, { 234, 234 }, { 219, 219 },
+ { 175, 175 }, { 205, 205 }, { 235, 235 }, { 220, 220 },
+ { 190, 190 }, { 236, 236 }, { 206, 206 }, { 191, 191 },
+ { 221, 221 }, { 207, 207 }, { 237, 237 }, { 222, 222 },
+ { 238, 238 }, { 223, 223 }, { 239, 239 }, { 0, 0 },
+};
+
+static const int16_t vp9_default_scan_32x32_nb[1024][2] = {
+ { 0, 0 }, { 0, 0 }, { 1, 1 }, { 32, 1 },
+ { 32, 32 }, { 2, 2 }, { 33, 2 }, { 64, 33 },
+ { 3, 3 }, { 64, 64 }, { 34, 3 }, { 65, 34 },
+ { 4, 4 }, { 35, 4 }, { 96, 65 }, { 66, 35 },
+ { 96, 96 }, { 97, 66 }, { 67, 36 }, { 36, 5 },
+ { 5, 5 }, { 128, 97 }, { 98, 67 }, { 6, 6 },
+ { 128, 128 }, { 68, 37 }, { 37, 6 }, { 129, 98 },
+ { 99, 68 }, { 160, 129 }, { 130, 99 }, { 38, 7 },
+ { 69, 38 }, { 7, 7 }, { 100, 69 }, { 161, 130 },
+ { 131, 100 }, { 160, 160 }, { 70, 39 }, { 39, 8 },
+ { 8, 8 }, { 101, 70 }, { 162, 131 }, { 132, 101 },
+ { 192, 161 }, { 71, 40 }, { 192, 192 }, { 102, 71 },
+ { 40, 9 }, { 163, 132 }, { 9, 9 }, { 193, 162 },
+ { 133, 102 }, { 164, 133 }, { 72, 41 }, { 103, 72 },
+ { 134, 103 }, { 224, 193 }, { 41, 10 }, { 194, 163 },
+ { 10, 10 }, { 224, 224 }, { 165, 134 }, { 225, 194 },
+ { 195, 164 }, { 73, 42 }, { 104, 73 }, { 135, 104 },
+ { 42, 11 }, { 11, 11 }, { 166, 135 }, { 196, 165 },
+ { 226, 195 }, { 256, 225 }, { 74, 43 }, { 105, 74 },
+ { 136, 105 }, { 227, 196 }, { 43, 12 }, { 197, 166 },
+ { 167, 136 }, { 257, 226 }, { 256, 256 }, { 12, 12 },
+ { 228, 197 }, { 75, 44 }, { 106, 75 }, { 198, 167 },
+ { 137, 106 }, { 258, 227 }, { 168, 137 }, { 288, 257 },
+ { 44, 13 }, { 229, 198 }, { 259, 228 }, { 199, 168 },
+ { 107, 76 }, { 13, 13 }, { 169, 138 }, { 138, 107 },
+ { 288, 288 }, { 289, 258 }, { 76, 45 }, { 230, 199 },
+ { 260, 229 }, { 45, 14 }, { 200, 169 }, { 139, 108 },
+ { 290, 259 }, { 108, 77 }, { 231, 200 }, { 320, 289 },
+ { 261, 230 }, { 170, 139 }, { 77, 46 }, { 291, 260 },
+ { 14, 14 }, { 321, 290 }, { 201, 170 }, { 262, 231 },
+ { 320, 320 }, { 171, 140 }, { 292, 261 }, { 232, 201 },
+ { 140, 109 }, { 322, 291 }, { 109, 78 }, { 46, 15 },
+ { 202, 171 }, { 263, 232 }, { 233, 202 }, { 293, 262 },
+ { 352, 321 }, { 323, 292 }, { 15, 15 }, { 78, 47 },
+ { 203, 172 }, { 264, 233 }, { 294, 263 }, { 324, 293 },
+ { 172, 141 }, { 353, 322 }, { 141, 110 }, { 234, 203 },
+ { 352, 352 }, { 47, 16 }, { 295, 264 }, { 110, 79 },
+ { 265, 234 }, { 354, 323 }, { 325, 294 }, { 79, 48 },
+ { 16, 16 }, { 204, 173 }, { 235, 204 }, { 173, 142 },
+ { 355, 324 }, { 384, 353 }, { 326, 295 }, { 142, 111 },
+ { 296, 265 }, { 266, 235 }, { 356, 325 }, { 385, 354 },
+ { 111, 80 }, { 48, 17 }, { 327, 296 }, { 297, 266 },
+ { 205, 174 }, { 384, 384 }, { 236, 205 }, { 357, 326 },
+ { 386, 355 }, { 80, 49 }, { 174, 143 }, { 17, 17 },
+ { 328, 297 }, { 358, 327 }, { 387, 356 }, { 298, 267 },
+ { 329, 298 }, { 388, 357 }, { 112, 81 }, { 416, 385 },
+ { 237, 206 }, { 359, 328 }, { 49, 18 }, { 206, 175 },
+ { 417, 386 }, { 389, 358 }, { 330, 299 }, { 18, 18 },
+ { 416, 416 }, { 360, 329 }, { 81, 50 }, { 418, 387 },
+ { 390, 359 }, { 238, 207 }, { 50, 19 }, { 361, 330 },
+ { 419, 388 }, { 113, 82 }, { 448, 417 }, { 448, 448 },
+ { 420, 389 }, { 82, 51 }, { 362, 331 }, { 449, 418 },
+ { 421, 390 }, { 480, 480 }, { 450, 419 }, { 422, 391 },
+ { 114, 83 }, { 451, 420 }, { 480, 449 }, { 452, 421 },
+ { 481, 450 }, { 453, 422 }, { 512, 512 }, { 482, 451 },
+ { 454, 423 }, { 512, 481 }, { 483, 452 }, { 513, 482 },
+ { 484, 453 }, { 514, 483 }, { 485, 454 }, { 544, 513 },
+ { 544, 544 }, { 486, 455 }, { 545, 514 }, { 546, 515 },
+ { 576, 576 }, { 576, 545 }, { 577, 546 }, { 578, 547 },
+ { 608, 577 }, { 609, 578 }, { 610, 579 }, { 19, 19 },
+ { 143, 112 }, { 267, 236 }, { 391, 360 }, { 515, 484 },
+ { 608, 608 }, { 20, 20 }, { 51, 20 }, { 144, 113 },
+ { 175, 144 }, { 268, 237 }, { 299, 268 }, { 392, 361 },
+ { 423, 392 }, { 516, 485 }, { 547, 516 }, { 640, 609 },
+ { 640, 640 }, { 21, 21 }, { 52, 21 }, { 83, 52 },
+ { 145, 114 }, { 176, 145 }, { 207, 176 }, { 269, 238 },
+ { 300, 269 }, { 331, 300 }, { 393, 362 }, { 424, 393 },
+ { 455, 424 }, { 517, 486 }, { 548, 517 }, { 579, 548 },
+ { 641, 610 }, { 672, 641 }, { 672, 672 }, { 22, 22 },
+ { 53, 22 }, { 84, 53 }, { 115, 84 }, { 146, 115 },
+ { 177, 146 }, { 208, 177 }, { 239, 208 }, { 270, 239 },
+ { 301, 270 }, { 332, 301 }, { 363, 332 }, { 394, 363 },
+ { 425, 394 }, { 456, 425 }, { 487, 456 }, { 518, 487 },
+ { 549, 518 }, { 580, 549 }, { 611, 580 }, { 642, 611 },
+ { 673, 642 }, { 704, 673 }, { 704, 704 }, { 54, 23 },
+ { 85, 54 }, { 116, 85 }, { 178, 147 }, { 209, 178 },
+ { 240, 209 }, { 302, 271 }, { 333, 302 }, { 364, 333 },
+ { 426, 395 }, { 457, 426 }, { 488, 457 }, { 550, 519 },
+ { 581, 550 }, { 612, 581 }, { 674, 643 }, { 705, 674 },
+ { 736, 705 }, { 86, 55 }, { 117, 86 }, { 210, 179 },
+ { 241, 210 }, { 334, 303 }, { 365, 334 }, { 458, 427 },
+ { 489, 458 }, { 582, 551 }, { 613, 582 }, { 706, 675 },
+ { 737, 706 }, { 118, 87 }, { 242, 211 }, { 366, 335 },
+ { 490, 459 }, { 614, 583 }, { 738, 707 }, { 23, 23 },
+ { 147, 116 }, { 271, 240 }, { 395, 364 }, { 519, 488 },
+ { 643, 612 }, { 736, 736 }, { 24, 24 }, { 55, 24 },
+ { 148, 117 }, { 179, 148 }, { 272, 241 }, { 303, 272 },
+ { 396, 365 }, { 427, 396 }, { 520, 489 }, { 551, 520 },
+ { 644, 613 }, { 675, 644 }, { 768, 737 }, { 768, 768 },
+ { 25, 25 }, { 56, 25 }, { 87, 56 }, { 149, 118 },
+ { 180, 149 }, { 211, 180 }, { 273, 242 }, { 304, 273 },
+ { 335, 304 }, { 397, 366 }, { 428, 397 }, { 459, 428 },
+ { 521, 490 }, { 552, 521 }, { 583, 552 }, { 645, 614 },
+ { 676, 645 }, { 707, 676 }, { 769, 738 }, { 800, 769 },
+ { 800, 800 }, { 26, 26 }, { 57, 26 }, { 88, 57 },
+ { 119, 88 }, { 150, 119 }, { 181, 150 }, { 212, 181 },
+ { 243, 212 }, { 274, 243 }, { 305, 274 }, { 336, 305 },
+ { 367, 336 }, { 398, 367 }, { 429, 398 }, { 460, 429 },
+ { 491, 460 }, { 522, 491 }, { 553, 522 }, { 584, 553 },
+ { 615, 584 }, { 646, 615 }, { 677, 646 }, { 708, 677 },
+ { 739, 708 }, { 770, 739 }, { 801, 770 }, { 832, 801 },
+ { 832, 832 }, { 58, 27 }, { 89, 58 }, { 120, 89 },
+ { 182, 151 }, { 213, 182 }, { 244, 213 }, { 306, 275 },
+ { 337, 306 }, { 368, 337 }, { 430, 399 }, { 461, 430 },
+ { 492, 461 }, { 554, 523 }, { 585, 554 }, { 616, 585 },
+ { 678, 647 }, { 709, 678 }, { 740, 709 }, { 802, 771 },
+ { 833, 802 }, { 864, 833 }, { 90, 59 }, { 121, 90 },
+ { 214, 183 }, { 245, 214 }, { 338, 307 }, { 369, 338 },
+ { 462, 431 }, { 493, 462 }, { 586, 555 }, { 617, 586 },
+ { 710, 679 }, { 741, 710 }, { 834, 803 }, { 865, 834 },
+ { 122, 91 }, { 246, 215 }, { 370, 339 }, { 494, 463 },
+ { 618, 587 }, { 742, 711 }, { 866, 835 }, { 27, 27 },
+ { 151, 120 }, { 275, 244 }, { 399, 368 }, { 523, 492 },
+ { 647, 616 }, { 771, 740 }, { 864, 864 }, { 28, 28 },
+ { 59, 28 }, { 152, 121 }, { 183, 152 }, { 276, 245 },
+ { 307, 276 }, { 400, 369 }, { 431, 400 }, { 524, 493 },
+ { 555, 524 }, { 648, 617 }, { 679, 648 }, { 772, 741 },
+ { 803, 772 }, { 896, 865 }, { 896, 896 }, { 29, 29 },
+ { 60, 29 }, { 91, 60 }, { 153, 122 }, { 184, 153 },
+ { 215, 184 }, { 277, 246 }, { 308, 277 }, { 339, 308 },
+ { 401, 370 }, { 432, 401 }, { 463, 432 }, { 525, 494 },
+ { 556, 525 }, { 587, 556 }, { 649, 618 }, { 680, 649 },
+ { 711, 680 }, { 773, 742 }, { 804, 773 }, { 835, 804 },
+ { 897, 866 }, { 928, 897 }, { 928, 928 }, { 30, 30 },
+ { 61, 30 }, { 92, 61 }, { 123, 92 }, { 154, 123 },
+ { 185, 154 }, { 216, 185 }, { 247, 216 }, { 278, 247 },
+ { 309, 278 }, { 340, 309 }, { 371, 340 }, { 402, 371 },
+ { 433, 402 }, { 464, 433 }, { 495, 464 }, { 526, 495 },
+ { 557, 526 }, { 588, 557 }, { 619, 588 }, { 650, 619 },
+ { 681, 650 }, { 712, 681 }, { 743, 712 }, { 774, 743 },
+ { 805, 774 }, { 836, 805 }, { 867, 836 }, { 898, 867 },
+ { 929, 898 }, { 960, 929 }, { 960, 960 }, { 62, 31 },
+ { 93, 62 }, { 124, 93 }, { 186, 155 }, { 217, 186 },
+ { 248, 217 }, { 310, 279 }, { 341, 310 }, { 372, 341 },
+ { 434, 403 }, { 465, 434 }, { 496, 465 }, { 558, 527 },
+ { 589, 558 }, { 620, 589 }, { 682, 651 }, { 713, 682 },
+ { 744, 713 }, { 806, 775 }, { 837, 806 }, { 868, 837 },
+ { 930, 899 }, { 961, 930 }, { 992, 961 }, { 94, 63 },
+ { 125, 94 }, { 218, 187 }, { 249, 218 }, { 342, 311 },
+ { 373, 342 }, { 466, 435 }, { 497, 466 }, { 590, 559 },
+ { 621, 590 }, { 714, 683 }, { 745, 714 }, { 838, 807 },
+ { 869, 838 }, { 962, 931 }, { 993, 962 }, { 126, 95 },
+ { 250, 219 }, { 374, 343 }, { 498, 467 }, { 622, 591 },
+ { 746, 715 }, { 870, 839 }, { 994, 963 }, { 155, 124 },
+ { 279, 248 }, { 403, 372 }, { 527, 496 }, { 651, 620 },
+ { 775, 744 }, { 899, 868 }, { 156, 125 }, { 187, 156 },
+ { 280, 249 }, { 311, 280 }, { 404, 373 }, { 435, 404 },
+ { 528, 497 }, { 559, 528 }, { 652, 621 }, { 683, 652 },
+ { 776, 745 }, { 807, 776 }, { 900, 869 }, { 931, 900 },
+ { 157, 126 }, { 188, 157 }, { 219, 188 }, { 281, 250 },
+ { 312, 281 }, { 343, 312 }, { 405, 374 }, { 436, 405 },
+ { 467, 436 }, { 529, 498 }, { 560, 529 }, { 591, 560 },
+ { 653, 622 }, { 684, 653 }, { 715, 684 }, { 777, 746 },
+ { 808, 777 }, { 839, 808 }, { 901, 870 }, { 932, 901 },
+ { 963, 932 }, { 158, 127 }, { 189, 158 }, { 220, 189 },
+ { 251, 220 }, { 282, 251 }, { 313, 282 }, { 344, 313 },
+ { 375, 344 }, { 406, 375 }, { 437, 406 }, { 468, 437 },
+ { 499, 468 }, { 530, 499 }, { 561, 530 }, { 592, 561 },
+ { 623, 592 }, { 654, 623 }, { 685, 654 }, { 716, 685 },
+ { 747, 716 }, { 778, 747 }, { 809, 778 }, { 840, 809 },
+ { 871, 840 }, { 902, 871 }, { 933, 902 }, { 964, 933 },
+ { 995, 964 }, { 190, 159 }, { 221, 190 }, { 252, 221 },
+ { 314, 283 }, { 345, 314 }, { 376, 345 }, { 438, 407 },
+ { 469, 438 }, { 500, 469 }, { 562, 531 }, { 593, 562 },
+ { 624, 593 }, { 686, 655 }, { 717, 686 }, { 748, 717 },
+ { 810, 779 }, { 841, 810 }, { 872, 841 }, { 934, 903 },
+ { 965, 934 }, { 996, 965 }, { 222, 191 }, { 253, 222 },
+ { 346, 315 }, { 377, 346 }, { 470, 439 }, { 501, 470 },
+ { 594, 563 }, { 625, 594 }, { 718, 687 }, { 749, 718 },
+ { 842, 811 }, { 873, 842 }, { 966, 935 }, { 997, 966 },
+ { 254, 223 }, { 378, 347 }, { 502, 471 }, { 626, 595 },
+ { 750, 719 }, { 874, 843 }, { 998, 967 }, { 283, 252 },
+ { 407, 376 }, { 531, 500 }, { 655, 624 }, { 779, 748 },
+ { 903, 872 }, { 284, 253 }, { 315, 284 }, { 408, 377 },
+ { 439, 408 }, { 532, 501 }, { 563, 532 }, { 656, 625 },
+ { 687, 656 }, { 780, 749 }, { 811, 780 }, { 904, 873 },
+ { 935, 904 }, { 285, 254 }, { 316, 285 }, { 347, 316 },
+ { 409, 378 }, { 440, 409 }, { 471, 440 }, { 533, 502 },
+ { 564, 533 }, { 595, 564 }, { 657, 626 }, { 688, 657 },
+ { 719, 688 }, { 781, 750 }, { 812, 781 }, { 843, 812 },
+ { 905, 874 }, { 936, 905 }, { 967, 936 }, { 286, 255 },
+ { 317, 286 }, { 348, 317 }, { 379, 348 }, { 410, 379 },
+ { 441, 410 }, { 472, 441 }, { 503, 472 }, { 534, 503 },
+ { 565, 534 }, { 596, 565 }, { 627, 596 }, { 658, 627 },
+ { 689, 658 }, { 720, 689 }, { 751, 720 }, { 782, 751 },
+ { 813, 782 }, { 844, 813 }, { 875, 844 }, { 906, 875 },
+ { 937, 906 }, { 968, 937 }, { 999, 968 }, { 318, 287 },
+ { 349, 318 }, { 380, 349 }, { 442, 411 }, { 473, 442 },
+ { 504, 473 }, { 566, 535 }, { 597, 566 }, { 628, 597 },
+ { 690, 659 }, { 721, 690 }, { 752, 721 }, { 814, 783 },
+ { 845, 814 }, { 876, 845 }, { 938, 907 }, { 969, 938 },
+ { 1000, 969 }, { 350, 319 }, { 381, 350 }, { 474, 443 },
+ { 505, 474 }, { 598, 567 }, { 629, 598 }, { 722, 691 },
+ { 753, 722 }, { 846, 815 }, { 877, 846 }, { 970, 939 },
+ { 1001, 970 }, { 382, 351 }, { 506, 475 }, { 630, 599 },
+ { 754, 723 }, { 878, 847 }, { 1002, 971 }, { 411, 380 },
+ { 535, 504 }, { 659, 628 }, { 783, 752 }, { 907, 876 },
+ { 412, 381 }, { 443, 412 }, { 536, 505 }, { 567, 536 },
+ { 660, 629 }, { 691, 660 }, { 784, 753 }, { 815, 784 },
+ { 908, 877 }, { 939, 908 }, { 413, 382 }, { 444, 413 },
+ { 475, 444 }, { 537, 506 }, { 568, 537 }, { 599, 568 },
+ { 661, 630 }, { 692, 661 }, { 723, 692 }, { 785, 754 },
+ { 816, 785 }, { 847, 816 }, { 909, 878 }, { 940, 909 },
+ { 971, 940 }, { 414, 383 }, { 445, 414 }, { 476, 445 },
+ { 507, 476 }, { 538, 507 }, { 569, 538 }, { 600, 569 },
+ { 631, 600 }, { 662, 631 }, { 693, 662 }, { 724, 693 },
+ { 755, 724 }, { 786, 755 }, { 817, 786 }, { 848, 817 },
+ { 879, 848 }, { 910, 879 }, { 941, 910 }, { 972, 941 },
+ { 1003, 972 }, { 446, 415 }, { 477, 446 }, { 508, 477 },
+ { 570, 539 }, { 601, 570 }, { 632, 601 }, { 694, 663 },
+ { 725, 694 }, { 756, 725 }, { 818, 787 }, { 849, 818 },
+ { 880, 849 }, { 942, 911 }, { 973, 942 }, { 1004, 973 },
+ { 478, 447 }, { 509, 478 }, { 602, 571 }, { 633, 602 },
+ { 726, 695 }, { 757, 726 }, { 850, 819 }, { 881, 850 },
+ { 974, 943 }, { 1005, 974 }, { 510, 479 }, { 634, 603 },
+ { 758, 727 }, { 882, 851 }, { 1006, 975 }, { 539, 508 },
+ { 663, 632 }, { 787, 756 }, { 911, 880 }, { 540, 509 },
+ { 571, 540 }, { 664, 633 }, { 695, 664 }, { 788, 757 },
+ { 819, 788 }, { 912, 881 }, { 943, 912 }, { 541, 510 },
+ { 572, 541 }, { 603, 572 }, { 665, 634 }, { 696, 665 },
+ { 727, 696 }, { 789, 758 }, { 820, 789 }, { 851, 820 },
+ { 913, 882 }, { 944, 913 }, { 975, 944 }, { 542, 511 },
+ { 573, 542 }, { 604, 573 }, { 635, 604 }, { 666, 635 },
+ { 697, 666 }, { 728, 697 }, { 759, 728 }, { 790, 759 },
+ { 821, 790 }, { 852, 821 }, { 883, 852 }, { 914, 883 },
+ { 945, 914 }, { 976, 945 }, { 1007, 976 }, { 574, 543 },
+ { 605, 574 }, { 636, 605 }, { 698, 667 }, { 729, 698 },
+ { 760, 729 }, { 822, 791 }, { 853, 822 }, { 884, 853 },
+ { 946, 915 }, { 977, 946 }, { 1008, 977 }, { 606, 575 },
+ { 637, 606 }, { 730, 699 }, { 761, 730 }, { 854, 823 },
+ { 885, 854 }, { 978, 947 }, { 1009, 978 }, { 638, 607 },
+ { 762, 731 }, { 886, 855 }, { 1010, 979 }, { 667, 636 },
+ { 791, 760 }, { 915, 884 }, { 668, 637 }, { 699, 668 },
+ { 792, 761 }, { 823, 792 }, { 916, 885 }, { 947, 916 },
+ { 669, 638 }, { 700, 669 }, { 731, 700 }, { 793, 762 },
+ { 824, 793 }, { 855, 824 }, { 917, 886 }, { 948, 917 },
+ { 979, 948 }, { 670, 639 }, { 701, 670 }, { 732, 701 },
+ { 763, 732 }, { 794, 763 }, { 825, 794 }, { 856, 825 },
+ { 887, 856 }, { 918, 887 }, { 949, 918 }, { 980, 949 },
+ { 1011, 980 }, { 702, 671 }, { 733, 702 }, { 764, 733 },
+ { 826, 795 }, { 857, 826 }, { 888, 857 }, { 950, 919 },
+ { 981, 950 }, { 1012, 981 }, { 734, 703 }, { 765, 734 },
+ { 858, 827 }, { 889, 858 }, { 982, 951 }, { 1013, 982 },
+ { 766, 735 }, { 890, 859 }, { 1014, 983 }, { 795, 764 },
+ { 919, 888 }, { 796, 765 }, { 827, 796 }, { 920, 889 },
+ { 951, 920 }, { 797, 766 }, { 828, 797 }, { 859, 828 },
+ { 921, 890 }, { 952, 921 }, { 983, 952 }, { 798, 767 },
+ { 829, 798 }, { 860, 829 }, { 891, 860 }, { 922, 891 },
+ { 953, 922 }, { 984, 953 }, { 1015, 984 }, { 830, 799 },
+ { 861, 830 }, { 892, 861 }, { 954, 923 }, { 985, 954 },
+ { 1016, 985 }, { 862, 831 }, { 893, 862 }, { 986, 955 },
+ { 1017, 986 }, { 894, 863 }, { 1018, 987 }, { 923, 892 },
+ { 924, 893 }, { 955, 924 }, { 925, 894 }, { 956, 925 },
+ { 987, 956 }, { 926, 895 }, { 957, 926 }, { 988, 957 },
+ { 1019, 988 }, { 958, 927 }, { 989, 958 }, { 1020, 989 },
+ { 990, 959 }, { 1021, 990 }, { 1022, 991 }, { 0, 0 },
+};
+
+static const int16_t (*vp9_scans_nb[5][4])[2] = {
+ {
+ vp9_default_scan_4x4_nb, vp9_col_scan_4x4_nb,
+ vp9_row_scan_4x4_nb, vp9_default_scan_4x4_nb
+ }, {
+ vp9_default_scan_8x8_nb, vp9_col_scan_8x8_nb,
+ vp9_row_scan_8x8_nb, vp9_default_scan_8x8_nb
+ }, {
+ vp9_default_scan_16x16_nb, vp9_col_scan_16x16_nb,
+ vp9_row_scan_16x16_nb, vp9_default_scan_16x16_nb
+ }, {
+ vp9_default_scan_32x32_nb, vp9_default_scan_32x32_nb,
+ vp9_default_scan_32x32_nb, vp9_default_scan_32x32_nb
+ }, { // lossless
+ vp9_default_scan_4x4_nb, vp9_default_scan_4x4_nb,
+ vp9_default_scan_4x4_nb, vp9_default_scan_4x4_nb
+ }
+};
+
+static const uint8_t vp9_model_pareto8[256][8] = {
+ { 6, 86, 128, 11, 87, 42, 91, 52 },
+ { 3, 86, 128, 6, 86, 23, 88, 29 },
+ { 6, 86, 128, 11, 87, 42, 91, 52 },
+ { 9, 86, 129, 17, 88, 61, 94, 76 },
+ { 12, 86, 129, 22, 88, 77, 97, 93 },
+ { 15, 87, 129, 28, 89, 93, 100, 110 },
+ { 17, 87, 129, 33, 90, 105, 103, 123 },
+ { 20, 88, 130, 38, 91, 118, 106, 136 },
+ { 23, 88, 130, 43, 91, 128, 108, 146 },
+ { 26, 89, 131, 48, 92, 139, 111, 156 },
+ { 28, 89, 131, 53, 93, 147, 114, 163 },
+ { 31, 90, 131, 58, 94, 156, 117, 171 },
+ { 34, 90, 131, 62, 94, 163, 119, 177 },
+ { 37, 90, 132, 66, 95, 171, 122, 184 },
+ { 39, 90, 132, 70, 96, 177, 124, 189 },
+ { 42, 91, 132, 75, 97, 183, 127, 194 },
+ { 44, 91, 132, 79, 97, 188, 129, 198 },
+ { 47, 92, 133, 83, 98, 193, 132, 202 },
+ { 49, 92, 133, 86, 99, 197, 134, 205 },
+ { 52, 93, 133, 90, 100, 201, 137, 208 },
+ { 54, 93, 133, 94, 100, 204, 139, 211 },
+ { 57, 94, 134, 98, 101, 208, 142, 214 },
+ { 59, 94, 134, 101, 102, 211, 144, 216 },
+ { 62, 94, 135, 105, 103, 214, 146, 218 },
+ { 64, 94, 135, 108, 103, 216, 148, 220 },
+ { 66, 95, 135, 111, 104, 219, 151, 222 },
+ { 68, 95, 135, 114, 105, 221, 153, 223 },
+ { 71, 96, 136, 117, 106, 224, 155, 225 },
+ { 73, 96, 136, 120, 106, 225, 157, 226 },
+ { 76, 97, 136, 123, 107, 227, 159, 228 },
+ { 78, 97, 136, 126, 108, 229, 160, 229 },
+ { 80, 98, 137, 129, 109, 231, 162, 231 },
+ { 82, 98, 137, 131, 109, 232, 164, 232 },
+ { 84, 98, 138, 134, 110, 234, 166, 233 },
+ { 86, 98, 138, 137, 111, 235, 168, 234 },
+ { 89, 99, 138, 140, 112, 236, 170, 235 },
+ { 91, 99, 138, 142, 112, 237, 171, 235 },
+ { 93, 100, 139, 145, 113, 238, 173, 236 },
+ { 95, 100, 139, 147, 114, 239, 174, 237 },
+ { 97, 101, 140, 149, 115, 240, 176, 238 },
+ { 99, 101, 140, 151, 115, 241, 177, 238 },
+ { 101, 102, 140, 154, 116, 242, 179, 239 },
+ { 103, 102, 140, 156, 117, 242, 180, 239 },
+ { 105, 103, 141, 158, 118, 243, 182, 240 },
+ { 107, 103, 141, 160, 118, 243, 183, 240 },
+ { 109, 104, 141, 162, 119, 244, 185, 241 },
+ { 111, 104, 141, 164, 119, 244, 186, 241 },
+ { 113, 104, 142, 166, 120, 245, 187, 242 },
+ { 114, 104, 142, 168, 121, 245, 188, 242 },
+ { 116, 105, 143, 170, 122, 246, 190, 243 },
+ { 118, 105, 143, 171, 122, 246, 191, 243 },
+ { 120, 106, 143, 173, 123, 247, 192, 244 },
+ { 121, 106, 143, 175, 124, 247, 193, 244 },
+ { 123, 107, 144, 177, 125, 248, 195, 244 },
+ { 125, 107, 144, 178, 125, 248, 196, 244 },
+ { 127, 108, 145, 180, 126, 249, 197, 245 },
+ { 128, 108, 145, 181, 127, 249, 198, 245 },
+ { 130, 109, 145, 183, 128, 249, 199, 245 },
+ { 132, 109, 145, 184, 128, 249, 200, 245 },
+ { 134, 110, 146, 186, 129, 250, 201, 246 },
+ { 135, 110, 146, 187, 130, 250, 202, 246 },
+ { 137, 111, 147, 189, 131, 251, 203, 246 },
+ { 138, 111, 147, 190, 131, 251, 204, 246 },
+ { 140, 112, 147, 192, 132, 251, 205, 247 },
+ { 141, 112, 147, 193, 132, 251, 206, 247 },
+ { 143, 113, 148, 194, 133, 251, 207, 247 },
+ { 144, 113, 148, 195, 134, 251, 207, 247 },
+ { 146, 114, 149, 197, 135, 252, 208, 248 },
+ { 147, 114, 149, 198, 135, 252, 209, 248 },
+ { 149, 115, 149, 199, 136, 252, 210, 248 },
+ { 150, 115, 149, 200, 137, 252, 210, 248 },
+ { 152, 115, 150, 201, 138, 252, 211, 248 },
+ { 153, 115, 150, 202, 138, 252, 212, 248 },
+ { 155, 116, 151, 204, 139, 253, 213, 249 },
+ { 156, 116, 151, 205, 139, 253, 213, 249 },
+ { 158, 117, 151, 206, 140, 253, 214, 249 },
+ { 159, 117, 151, 207, 141, 253, 215, 249 },
+ { 161, 118, 152, 208, 142, 253, 216, 249 },
+ { 162, 118, 152, 209, 142, 253, 216, 249 },
+ { 163, 119, 153, 210, 143, 253, 217, 249 },
+ { 164, 119, 153, 211, 143, 253, 217, 249 },
+ { 166, 120, 153, 212, 144, 254, 218, 250 },
+ { 167, 120, 153, 212, 145, 254, 219, 250 },
+ { 168, 121, 154, 213, 146, 254, 220, 250 },
+ { 169, 121, 154, 214, 146, 254, 220, 250 },
+ { 171, 122, 155, 215, 147, 254, 221, 250 },
+ { 172, 122, 155, 216, 147, 254, 221, 250 },
+ { 173, 123, 155, 217, 148, 254, 222, 250 },
+ { 174, 123, 155, 217, 149, 254, 222, 250 },
+ { 176, 124, 156, 218, 150, 254, 223, 250 },
+ { 177, 124, 156, 219, 150, 254, 223, 250 },
+ { 178, 125, 157, 220, 151, 254, 224, 251 },
+ { 179, 125, 157, 220, 151, 254, 224, 251 },
+ { 180, 126, 157, 221, 152, 254, 225, 251 },
+ { 181, 126, 157, 221, 152, 254, 225, 251 },
+ { 183, 127, 158, 222, 153, 254, 226, 251 },
+ { 184, 127, 158, 223, 154, 254, 226, 251 },
+ { 185, 128, 159, 224, 155, 255, 227, 251 },
+ { 186, 128, 159, 224, 155, 255, 227, 251 },
+ { 187, 129, 160, 225, 156, 255, 228, 251 },
+ { 188, 130, 160, 225, 156, 255, 228, 251 },
+ { 189, 131, 160, 226, 157, 255, 228, 251 },
+ { 190, 131, 160, 226, 158, 255, 228, 251 },
+ { 191, 132, 161, 227, 159, 255, 229, 251 },
+ { 192, 132, 161, 227, 159, 255, 229, 251 },
+ { 193, 133, 162, 228, 160, 255, 230, 252 },
+ { 194, 133, 162, 229, 160, 255, 230, 252 },
+ { 195, 134, 163, 230, 161, 255, 231, 252 },
+ { 196, 134, 163, 230, 161, 255, 231, 252 },
+ { 197, 135, 163, 231, 162, 255, 231, 252 },
+ { 198, 135, 163, 231, 162, 255, 231, 252 },
+ { 199, 136, 164, 232, 163, 255, 232, 252 },
+ { 200, 136, 164, 232, 164, 255, 232, 252 },
+ { 201, 137, 165, 233, 165, 255, 233, 252 },
+ { 201, 137, 165, 233, 165, 255, 233, 252 },
+ { 202, 138, 166, 233, 166, 255, 233, 252 },
+ { 203, 138, 166, 233, 166, 255, 233, 252 },
+ { 204, 139, 166, 234, 167, 255, 234, 252 },
+ { 205, 139, 166, 234, 167, 255, 234, 252 },
+ { 206, 140, 167, 235, 168, 255, 235, 252 },
+ { 206, 140, 167, 235, 168, 255, 235, 252 },
+ { 207, 141, 168, 236, 169, 255, 235, 252 },
+ { 208, 141, 168, 236, 170, 255, 235, 252 },
+ { 209, 142, 169, 237, 171, 255, 236, 252 },
+ { 209, 143, 169, 237, 171, 255, 236, 252 },
+ { 210, 144, 169, 237, 172, 255, 236, 252 },
+ { 211, 144, 169, 237, 172, 255, 236, 252 },
+ { 212, 145, 170, 238, 173, 255, 237, 252 },
+ { 213, 145, 170, 238, 173, 255, 237, 252 },
+ { 214, 146, 171, 239, 174, 255, 237, 253 },
+ { 214, 146, 171, 239, 174, 255, 237, 253 },
+ { 215, 147, 172, 240, 175, 255, 238, 253 },
+ { 215, 147, 172, 240, 175, 255, 238, 253 },
+ { 216, 148, 173, 240, 176, 255, 238, 253 },
+ { 217, 148, 173, 240, 176, 255, 238, 253 },
+ { 218, 149, 173, 241, 177, 255, 239, 253 },
+ { 218, 149, 173, 241, 178, 255, 239, 253 },
+ { 219, 150, 174, 241, 179, 255, 239, 253 },
+ { 219, 151, 174, 241, 179, 255, 239, 253 },
+ { 220, 152, 175, 242, 180, 255, 240, 253 },
+ { 221, 152, 175, 242, 180, 255, 240, 253 },
+ { 222, 153, 176, 242, 181, 255, 240, 253 },
+ { 222, 153, 176, 242, 181, 255, 240, 253 },
+ { 223, 154, 177, 243, 182, 255, 240, 253 },
+ { 223, 154, 177, 243, 182, 255, 240, 253 },
+ { 224, 155, 178, 244, 183, 255, 241, 253 },
+ { 224, 155, 178, 244, 183, 255, 241, 253 },
+ { 225, 156, 178, 244, 184, 255, 241, 253 },
+ { 225, 157, 178, 244, 184, 255, 241, 253 },
+ { 226, 158, 179, 244, 185, 255, 242, 253 },
+ { 227, 158, 179, 244, 185, 255, 242, 253 },
+ { 228, 159, 180, 245, 186, 255, 242, 253 },
+ { 228, 159, 180, 245, 186, 255, 242, 253 },
+ { 229, 160, 181, 245, 187, 255, 242, 253 },
+ { 229, 160, 181, 245, 187, 255, 242, 253 },
+ { 230, 161, 182, 246, 188, 255, 243, 253 },
+ { 230, 162, 182, 246, 188, 255, 243, 253 },
+ { 231, 163, 183, 246, 189, 255, 243, 253 },
+ { 231, 163, 183, 246, 189, 255, 243, 253 },
+ { 232, 164, 184, 247, 190, 255, 243, 253 },
+ { 232, 164, 184, 247, 190, 255, 243, 253 },
+ { 233, 165, 185, 247, 191, 255, 244, 253 },
+ { 233, 165, 185, 247, 191, 255, 244, 253 },
+ { 234, 166, 185, 247, 192, 255, 244, 253 },
+ { 234, 167, 185, 247, 192, 255, 244, 253 },
+ { 235, 168, 186, 248, 193, 255, 244, 253 },
+ { 235, 168, 186, 248, 193, 255, 244, 253 },
+ { 236, 169, 187, 248, 194, 255, 244, 253 },
+ { 236, 169, 187, 248, 194, 255, 244, 253 },
+ { 236, 170, 188, 248, 195, 255, 245, 253 },
+ { 236, 170, 188, 248, 195, 255, 245, 253 },
+ { 237, 171, 189, 249, 196, 255, 245, 254 },
+ { 237, 172, 189, 249, 196, 255, 245, 254 },
+ { 238, 173, 190, 249, 197, 255, 245, 254 },
+ { 238, 173, 190, 249, 197, 255, 245, 254 },
+ { 239, 174, 191, 249, 198, 255, 245, 254 },
+ { 239, 174, 191, 249, 198, 255, 245, 254 },
+ { 240, 175, 192, 249, 199, 255, 246, 254 },
+ { 240, 176, 192, 249, 199, 255, 246, 254 },
+ { 240, 177, 193, 250, 200, 255, 246, 254 },
+ { 240, 177, 193, 250, 200, 255, 246, 254 },
+ { 241, 178, 194, 250, 201, 255, 246, 254 },
+ { 241, 178, 194, 250, 201, 255, 246, 254 },
+ { 242, 179, 195, 250, 202, 255, 246, 254 },
+ { 242, 180, 195, 250, 202, 255, 246, 254 },
+ { 242, 181, 196, 250, 203, 255, 247, 254 },
+ { 242, 181, 196, 250, 203, 255, 247, 254 },
+ { 243, 182, 197, 251, 204, 255, 247, 254 },
+ { 243, 183, 197, 251, 204, 255, 247, 254 },
+ { 244, 184, 198, 251, 205, 255, 247, 254 },
+ { 244, 184, 198, 251, 205, 255, 247, 254 },
+ { 244, 185, 199, 251, 206, 255, 247, 254 },
+ { 244, 185, 199, 251, 206, 255, 247, 254 },
+ { 245, 186, 200, 251, 207, 255, 247, 254 },
+ { 245, 187, 200, 251, 207, 255, 247, 254 },
+ { 246, 188, 201, 252, 207, 255, 248, 254 },
+ { 246, 188, 201, 252, 207, 255, 248, 254 },
+ { 246, 189, 202, 252, 208, 255, 248, 254 },
+ { 246, 190, 202, 252, 208, 255, 248, 254 },
+ { 247, 191, 203, 252, 209, 255, 248, 254 },
+ { 247, 191, 203, 252, 209, 255, 248, 254 },
+ { 247, 192, 204, 252, 210, 255, 248, 254 },
+ { 247, 193, 204, 252, 210, 255, 248, 254 },
+ { 248, 194, 205, 252, 211, 255, 248, 254 },
+ { 248, 194, 205, 252, 211, 255, 248, 254 },
+ { 248, 195, 206, 252, 212, 255, 249, 254 },
+ { 248, 196, 206, 252, 212, 255, 249, 254 },
+ { 249, 197, 207, 253, 213, 255, 249, 254 },
+ { 249, 197, 207, 253, 213, 255, 249, 254 },
+ { 249, 198, 208, 253, 214, 255, 249, 254 },
+ { 249, 199, 209, 253, 214, 255, 249, 254 },
+ { 250, 200, 210, 253, 215, 255, 249, 254 },
+ { 250, 200, 210, 253, 215, 255, 249, 254 },
+ { 250, 201, 211, 253, 215, 255, 249, 254 },
+ { 250, 202, 211, 253, 215, 255, 249, 254 },
+ { 250, 203, 212, 253, 216, 255, 249, 254 },
+ { 250, 203, 212, 253, 216, 255, 249, 254 },
+ { 251, 204, 213, 253, 217, 255, 250, 254 },
+ { 251, 205, 213, 253, 217, 255, 250, 254 },
+ { 251, 206, 214, 254, 218, 255, 250, 254 },
+ { 251, 206, 215, 254, 218, 255, 250, 254 },
+ { 252, 207, 216, 254, 219, 255, 250, 254 },
+ { 252, 208, 216, 254, 219, 255, 250, 254 },
+ { 252, 209, 217, 254, 220, 255, 250, 254 },
+ { 252, 210, 217, 254, 220, 255, 250, 254 },
+ { 252, 211, 218, 254, 221, 255, 250, 254 },
+ { 252, 212, 218, 254, 221, 255, 250, 254 },
+ { 253, 213, 219, 254, 222, 255, 250, 254 },
+ { 253, 213, 220, 254, 222, 255, 250, 254 },
+ { 253, 214, 221, 254, 223, 255, 250, 254 },
+ { 253, 215, 221, 254, 223, 255, 250, 254 },
+ { 253, 216, 222, 254, 224, 255, 251, 254 },
+ { 253, 217, 223, 254, 224, 255, 251, 254 },
+ { 253, 218, 224, 254, 225, 255, 251, 254 },
+ { 253, 219, 224, 254, 225, 255, 251, 254 },
+ { 254, 220, 225, 254, 225, 255, 251, 254 },
+ { 254, 221, 226, 254, 225, 255, 251, 254 },
+ { 254, 222, 227, 255, 226, 255, 251, 254 },
+ { 254, 223, 227, 255, 226, 255, 251, 254 },
+ { 254, 224, 228, 255, 227, 255, 251, 254 },
+ { 254, 225, 229, 255, 227, 255, 251, 254 },
+ { 254, 226, 230, 255, 228, 255, 251, 254 },
+ { 254, 227, 230, 255, 229, 255, 251, 254 },
+ { 255, 228, 231, 255, 230, 255, 251, 254 },
+ { 255, 229, 232, 255, 230, 255, 251, 254 },
+ { 255, 230, 233, 255, 231, 255, 252, 254 },
+ { 255, 231, 234, 255, 231, 255, 252, 254 },
+ { 255, 232, 235, 255, 232, 255, 252, 254 },
+ { 255, 233, 236, 255, 232, 255, 252, 254 },
+ { 255, 235, 237, 255, 233, 255, 252, 254 },
+ { 255, 236, 238, 255, 234, 255, 252, 254 },
+ { 255, 238, 240, 255, 235, 255, 252, 255 },
+ { 255, 239, 241, 255, 235, 255, 252, 254 },
+ { 255, 241, 243, 255, 236, 255, 252, 254 },
+ { 255, 243, 245, 255, 237, 255, 252, 254 },
+ { 255, 246, 247, 255, 239, 255, 253, 255 },
+};
+
+typedef struct {
+ uint8_t y_mode[4][9];
+ uint8_t uv_mode[10][9];
+ uint8_t filter[4][2];
+ uint8_t mv_mode[7][3];
+ uint8_t intra[4];
+ uint8_t comp[5];
+ uint8_t single_ref[5][2];
+ uint8_t comp_ref[5];
+ uint8_t tx32p[2][3];
+ uint8_t tx16p[2][2];
+ uint8_t tx8p[2];
+ uint8_t skip[3];
+ uint8_t mv_joint[3];
+ struct {
+ uint8_t sign;
+ uint8_t classes[10];
+ uint8_t class0;
+ uint8_t bits[10];
+ uint8_t class0_fp[2][3];
+ uint8_t fp[3];
+ uint8_t class0_hp;
+ uint8_t hp;
+ } mv_comp[2];
+ uint8_t partition[4][4][3];
+} prob_context;
+
+static const prob_context vp9_default_probs = {
+ { /* y_mode */
+ { 65, 32, 18, 144, 162, 194, 41, 51, 98 } /* bsize < 8x8 */,
+ { 132, 68, 18, 165, 217, 196, 45, 40, 78 } /* bsize < 16x16 */,
+ { 173, 80, 19, 176, 240, 193, 64, 35, 46 } /* bsize < 32x32 */,
+ { 221, 135, 38, 194, 248, 121, 96, 85, 29 } /* bsize >= 32x32 */
+ }, { /* uv_mode */
+ { 48, 12, 154, 155, 139, 90, 34, 117, 119 } /* y = v */,
+ { 67, 6, 25, 204, 243, 158, 13, 21, 96 } /* y = h */,
+ { 120, 7, 76, 176, 208, 126, 28, 54, 103 } /* y = dc */,
+ { 97, 5, 44, 131, 176, 139, 48, 68, 97 } /* y = d45 */,
+ { 83, 5, 42, 156, 111, 152, 26, 49, 152 } /* y = d135 */,
+ { 80, 5, 58, 178, 74, 83, 33, 62, 145 } /* y = d117 */,
+ { 86, 5, 32, 154, 192, 168, 14, 22, 163 } /* y = d153 */,
+ { 77, 7, 64, 116, 132, 122, 37, 126, 120 } /* y = d63 */,
+ { 85, 5, 32, 156, 216, 148, 19, 29, 73 } /* y = d27 */,
+ { 101, 21, 107, 181, 192, 103, 19, 67, 125 } /* y = tm */
+ }, { /* filter */
+ { 235, 162, },
+ { 36, 255, },
+ { 34, 3, },
+ { 149, 144, },
+ }, { /* mv_mode */
+ { 2, 173, 34}, // 0 = both zero mv
+ { 7, 145, 85}, // 1 = one zero mv + one a predicted mv
+ { 7, 166, 63}, // 2 = two predicted mvs
+ { 7, 94, 66}, // 3 = one predicted/zero and one new mv
+ { 8, 64, 46}, // 4 = two new mvs
+ { 17, 81, 31}, // 5 = one intra neighbour + x
+ { 25, 29, 30}, // 6 = two intra neighbours
+ }, { /* intra */
+ 9, 102, 187, 225
+ }, { /* comp */
+ 239, 183, 119, 96, 41
+ }, { /* single_ref */
+ { 33, 16 },
+ { 77, 74 },
+ { 142, 142 },
+ { 172, 170 },
+ { 238, 247 }
+ }, { /* comp_ref */
+ 50, 126, 123, 221, 226
+ }, { /* tx32p */
+ { 3, 136, 37, },
+ { 5, 52, 13, },
+ }, { /* tx16p */
+ { 20, 152, },
+ { 15, 101, },
+ }, { /* tx8p */
+ 100, 66
+ }, { /* skip */
+ 192, 128, 64
+ }, { /* mv_joint */
+ 32, 64, 96
+ }, {
+ { /* mv vertical component */
+ 128, /* sign */
+ { 224, 144, 192, 168, 192, 176, 192, 198, 198, 245 }, /* class */
+ 216, /* class0 */
+ { 136, 140, 148, 160, 176, 192, 224, 234, 234, 240}, /* bits */
+ { /* class0_fp */
+ { 128, 128, 64 },
+ { 96, 112, 64 }
+ },
+ { 64, 96, 64 }, /* fp */
+ 160, /* class0_hp bit */
+ 128, /* hp */
+ }, { /* mv horizontal component */
+ 128, /* sign */
+ { 216, 128, 176, 160, 176, 176, 192, 198, 198, 208 }, /* class */
+ 208, /* class0 */
+ { 136, 140, 148, 160, 176, 192, 224, 234, 234, 240 }, /* bits */
+ { /* class0_fp */
+ { 128, 128, 64 },
+ { 96, 112, 64 }
+ },
+ { 64, 96, 64 }, /* fp */
+ 160, /* class0_hp bit */
+ 128, /* hp */
+ }
+ }, { /* partition */
+ { /* 64x64 -> 32x32 */
+ { 222, 34, 30 } /* a/l both not split */,
+ { 72, 16, 44 } /* a split, l not split */,
+ { 58, 32, 12 } /* l split, a not split */,
+ { 10, 7, 6 } /* a/l both split */,
+ }, { /* 32x32 -> 16x16 */
+ { 177, 58, 59 } /* a/l both not split */,
+ { 68, 26, 63 } /* a split, l not split */,
+ { 52, 79, 25 } /* l split, a not split */,
+ { 17, 14, 12 } /* a/l both split */,
+ }, { /* 16x16 -> 8x8 */
+ { 174, 73, 87 } /* a/l both not split */,
+ { 92, 41, 83 } /* a split, l not split */,
+ { 82, 99, 50 } /* l split, a not split */,
+ { 53, 39, 39 } /* a/l both split */,
+ }, { /* 8x8 -> 4x4 */
+ { 199, 122, 141 } /* a/l both not split */,
+ { 147, 63, 159 } /* a split, l not split */,
+ { 148, 133, 118 } /* l split, a not split */,
+ { 121, 104, 114 } /* a/l both split */,
+ }
+ },
+};
+
+static const uint8_t vp9_default_coef_probs[4][2][2][6][6][3] = {
+ { /* tx = 4x4 */
+ { /* block Type 0 */
+ { /* Intra */
+ { /* Coeff Band 0 */
+ { 195, 29, 183 },
+ { 84, 49, 136 },
+ { 8, 42, 71 }
+ }, { /* Coeff Band 1 */
+ { 31, 107, 169 },
+ { 35, 99, 159 },
+ { 17, 82, 140 },
+ { 8, 66, 114 },
+ { 2, 44, 76 },
+ { 1, 19, 32 }
+ }, { /* Coeff Band 2 */
+ { 40, 132, 201 },
+ { 29, 114, 187 },
+ { 13, 91, 157 },
+ { 7, 75, 127 },
+ { 3, 58, 95 },
+ { 1, 28, 47 }
+ }, { /* Coeff Band 3 */
+ { 69, 142, 221 },
+ { 42, 122, 201 },
+ { 15, 91, 159 },
+ { 6, 67, 121 },
+ { 1, 42, 77 },
+ { 1, 17, 31 }
+ }, { /* Coeff Band 4 */
+ { 102, 148, 228 },
+ { 67, 117, 204 },
+ { 17, 82, 154 },
+ { 6, 59, 114 },
+ { 2, 39, 75 },
+ { 1, 15, 29 }
+ }, { /* Coeff Band 5 */
+ { 156, 57, 233 },
+ { 119, 57, 212 },
+ { 58, 48, 163 },
+ { 29, 40, 124 },
+ { 12, 30, 81 },
+ { 3, 12, 31 }
+ }
+ }, { /* Inter */
+ { /* Coeff Band 0 */
+ { 191, 107, 226 },
+ { 124, 117, 204 },
+ { 25, 99, 155 }
+ }, { /* Coeff Band 1 */
+ { 29, 148, 210 },
+ { 37, 126, 194 },
+ { 8, 93, 157 },
+ { 2, 68, 118 },
+ { 1, 39, 69 },
+ { 1, 17, 33 }
+ }, { /* Coeff Band 2 */
+ { 41, 151, 213 },
+ { 27, 123, 193 },
+ { 3, 82, 144 },
+ { 1, 58, 105 },
+ { 1, 32, 60 },
+ { 1, 13, 26 }
+ }, { /* Coeff Band 3 */
+ { 59, 159, 220 },
+ { 23, 126, 198 },
+ { 4, 88, 151 },
+ { 1, 66, 114 },
+ { 1, 38, 71 },
+ { 1, 18, 34 }
+ }, { /* Coeff Band 4 */
+ { 114, 136, 232 },
+ { 51, 114, 207 },
+ { 11, 83, 155 },
+ { 3, 56, 105 },
+ { 1, 33, 65 },
+ { 1, 17, 34 }
+ }, { /* Coeff Band 5 */
+ { 149, 65, 234 },
+ { 121, 57, 215 },
+ { 61, 49, 166 },
+ { 28, 36, 114 },
+ { 12, 25, 76 },
+ { 3, 16, 42 }
+ }
+ }
+ }, { /* block Type 1 */
+ { /* Intra */
+ { /* Coeff Band 0 */
+ { 214, 49, 220 },
+ { 132, 63, 188 },
+ { 42, 65, 137 }
+ }, { /* Coeff Band 1 */
+ { 85, 137, 221 },
+ { 104, 131, 216 },
+ { 49, 111, 192 },
+ { 21, 87, 155 },
+ { 2, 49, 87 },
+ { 1, 16, 28 }
+ }, { /* Coeff Band 2 */
+ { 89, 163, 230 },
+ { 90, 137, 220 },
+ { 29, 100, 183 },
+ { 10, 70, 135 },
+ { 2, 42, 81 },
+ { 1, 17, 33 }
+ }, { /* Coeff Band 3 */
+ { 108, 167, 237 },
+ { 55, 133, 222 },
+ { 15, 97, 179 },
+ { 4, 72, 135 },
+ { 1, 45, 85 },
+ { 1, 19, 38 }
+ }, { /* Coeff Band 4 */
+ { 124, 146, 240 },
+ { 66, 124, 224 },
+ { 17, 88, 175 },
+ { 4, 58, 122 },
+ { 1, 36, 75 },
+ { 1, 18, 37 }
+ }, { /* Coeff Band 5 */
+ { 141, 79, 241 },
+ { 126, 70, 227 },
+ { 66, 58, 182 },
+ { 30, 44, 136 },
+ { 12, 34, 96 },
+ { 2, 20, 47 }
+ }
+ }, { /* Inter */
+ { /* Coeff Band 0 */
+ { 229, 99, 249 },
+ { 143, 111, 235 },
+ { 46, 109, 192 }
+ }, { /* Coeff Band 1 */
+ { 82, 158, 236 },
+ { 94, 146, 224 },
+ { 25, 117, 191 },
+ { 9, 87, 149 },
+ { 3, 56, 99 },
+ { 1, 33, 57 }
+ }, { /* Coeff Band 2 */
+ { 83, 167, 237 },
+ { 68, 145, 222 },
+ { 10, 103, 177 },
+ { 2, 72, 131 },
+ { 1, 41, 79 },
+ { 1, 20, 39 }
+ }, { /* Coeff Band 3 */
+ { 99, 167, 239 },
+ { 47, 141, 224 },
+ { 10, 104, 178 },
+ { 2, 73, 133 },
+ { 1, 44, 85 },
+ { 1, 22, 47 }
+ }, { /* Coeff Band 4 */
+ { 127, 145, 243 },
+ { 71, 129, 228 },
+ { 17, 93, 177 },
+ { 3, 61, 124 },
+ { 1, 41, 84 },
+ { 1, 21, 52 }
+ }, { /* Coeff Band 5 */
+ { 157, 78, 244 },
+ { 140, 72, 231 },
+ { 69, 58, 184 },
+ { 31, 44, 137 },
+ { 14, 38, 105 },
+ { 8, 23, 61 }
+ }
+ }
+ }
+ }, { /* tx = 8x8 */
+ { /* block Type 0 */
+ { /* Intra */
+ { /* Coeff Band 0 */
+ { 125, 34, 187 },
+ { 52, 41, 133 },
+ { 6, 31, 56 }
+ }, { /* Coeff Band 1 */
+ { 37, 109, 153 },
+ { 51, 102, 147 },
+ { 23, 87, 128 },
+ { 8, 67, 101 },
+ { 1, 41, 63 },
+ { 1, 19, 29 }
+ }, { /* Coeff Band 2 */
+ { 31, 154, 185 },
+ { 17, 127, 175 },
+ { 6, 96, 145 },
+ { 2, 73, 114 },
+ { 1, 51, 82 },
+ { 1, 28, 45 }
+ }, { /* Coeff Band 3 */
+ { 23, 163, 200 },
+ { 10, 131, 185 },
+ { 2, 93, 148 },
+ { 1, 67, 111 },
+ { 1, 41, 69 },
+ { 1, 14, 24 }
+ }, { /* Coeff Band 4 */
+ { 29, 176, 217 },
+ { 12, 145, 201 },
+ { 3, 101, 156 },
+ { 1, 69, 111 },
+ { 1, 39, 63 },
+ { 1, 14, 23 }
+ }, { /* Coeff Band 5 */
+ { 57, 192, 233 },
+ { 25, 154, 215 },
+ { 6, 109, 167 },
+ { 3, 78, 118 },
+ { 1, 48, 69 },
+ { 1, 21, 29 }
+ }
+ }, { /* Inter */
+ { /* Coeff Band 0 */
+ { 202, 105, 245 },
+ { 108, 106, 216 },
+ { 18, 90, 144 }
+ }, { /* Coeff Band 1 */
+ { 33, 172, 219 },
+ { 64, 149, 206 },
+ { 14, 117, 177 },
+ { 5, 90, 141 },
+ { 2, 61, 95 },
+ { 1, 37, 57 }
+ }, { /* Coeff Band 2 */
+ { 33, 179, 220 },
+ { 11, 140, 198 },
+ { 1, 89, 148 },
+ { 1, 60, 104 },
+ { 1, 33, 57 },
+ { 1, 12, 21 }
+ }, { /* Coeff Band 3 */
+ { 30, 181, 221 },
+ { 8, 141, 198 },
+ { 1, 87, 145 },
+ { 1, 58, 100 },
+ { 1, 31, 55 },
+ { 1, 12, 20 }
+ }, { /* Coeff Band 4 */
+ { 32, 186, 224 },
+ { 7, 142, 198 },
+ { 1, 86, 143 },
+ { 1, 58, 100 },
+ { 1, 31, 55 },
+ { 1, 12, 22 }
+ }, { /* Coeff Band 5 */
+ { 57, 192, 227 },
+ { 20, 143, 204 },
+ { 3, 96, 154 },
+ { 1, 68, 112 },
+ { 1, 42, 69 },
+ { 1, 19, 32 }
+ }
+ }
+ }, { /* block Type 1 */
+ { /* Intra */
+ { /* Coeff Band 0 */
+ { 212, 35, 215 },
+ { 113, 47, 169 },
+ { 29, 48, 105 }
+ }, { /* Coeff Band 1 */
+ { 74, 129, 203 },
+ { 106, 120, 203 },
+ { 49, 107, 178 },
+ { 19, 84, 144 },
+ { 4, 50, 84 },
+ { 1, 15, 25 }
+ }, { /* Coeff Band 2 */
+ { 71, 172, 217 },
+ { 44, 141, 209 },
+ { 15, 102, 173 },
+ { 6, 76, 133 },
+ { 2, 51, 89 },
+ { 1, 24, 42 }
+ }, { /* Coeff Band 3 */
+ { 64, 185, 231 },
+ { 31, 148, 216 },
+ { 8, 103, 175 },
+ { 3, 74, 131 },
+ { 1, 46, 81 },
+ { 1, 18, 30 }
+ }, { /* Coeff Band 4 */
+ { 65, 196, 235 },
+ { 25, 157, 221 },
+ { 5, 105, 174 },
+ { 1, 67, 120 },
+ { 1, 38, 69 },
+ { 1, 15, 30 }
+ }, { /* Coeff Band 5 */
+ { 65, 204, 238 },
+ { 30, 156, 224 },
+ { 7, 107, 177 },
+ { 2, 70, 124 },
+ { 1, 42, 73 },
+ { 1, 18, 34 }
+ }
+ }, { /* Inter */
+ { /* Coeff Band 0 */
+ { 225, 86, 251 },
+ { 144, 104, 235 },
+ { 42, 99, 181 }
+ }, { /* Coeff Band 1 */
+ { 85, 175, 239 },
+ { 112, 165, 229 },
+ { 29, 136, 200 },
+ { 12, 103, 162 },
+ { 6, 77, 123 },
+ { 2, 53, 84 }
+ }, { /* Coeff Band 2 */
+ { 75, 183, 239 },
+ { 30, 155, 221 },
+ { 3, 106, 171 },
+ { 1, 74, 128 },
+ { 1, 44, 76 },
+ { 1, 17, 28 }
+ }, { /* Coeff Band 3 */
+ { 73, 185, 240 },
+ { 27, 159, 222 },
+ { 2, 107, 172 },
+ { 1, 75, 127 },
+ { 1, 42, 73 },
+ { 1, 17, 29 }
+ }, { /* Coeff Band 4 */
+ { 62, 190, 238 },
+ { 21, 159, 222 },
+ { 2, 107, 172 },
+ { 1, 72, 122 },
+ { 1, 40, 71 },
+ { 1, 18, 32 }
+ }, { /* Coeff Band 5 */
+ { 61, 199, 240 },
+ { 27, 161, 226 },
+ { 4, 113, 180 },
+ { 1, 76, 129 },
+ { 1, 46, 80 },
+ { 1, 23, 41 }
+ }
+ }
+ }
+ }, { /* tx = 16x16 */
+ { /* block Type 0 */
+ { /* Intra */
+ { /* Coeff Band 0 */
+ { 7, 27, 153 },
+ { 5, 30, 95 },
+ { 1, 16, 30 }
+ }, { /* Coeff Band 1 */
+ { 50, 75, 127 },
+ { 57, 75, 124 },
+ { 27, 67, 108 },
+ { 10, 54, 86 },
+ { 1, 33, 52 },
+ { 1, 12, 18 }
+ }, { /* Coeff Band 2 */
+ { 43, 125, 151 },
+ { 26, 108, 148 },
+ { 7, 83, 122 },
+ { 2, 59, 89 },
+ { 1, 38, 60 },
+ { 1, 17, 27 }
+ }, { /* Coeff Band 3 */
+ { 23, 144, 163 },
+ { 13, 112, 154 },
+ { 2, 75, 117 },
+ { 1, 50, 81 },
+ { 1, 31, 51 },
+ { 1, 14, 23 }
+ }, { /* Coeff Band 4 */
+ { 18, 162, 185 },
+ { 6, 123, 171 },
+ { 1, 78, 125 },
+ { 1, 51, 86 },
+ { 1, 31, 54 },
+ { 1, 14, 23 }
+ }, { /* Coeff Band 5 */
+ { 15, 199, 227 },
+ { 3, 150, 204 },
+ { 1, 91, 146 },
+ { 1, 55, 95 },
+ { 1, 30, 53 },
+ { 1, 11, 20 }
+ }
+ }, { /* Inter */
+ { /* Coeff Band 0 */
+ { 19, 55, 240 },
+ { 19, 59, 196 },
+ { 3, 52, 105 }
+ }, { /* Coeff Band 1 */
+ { 41, 166, 207 },
+ { 104, 153, 199 },
+ { 31, 123, 181 },
+ { 14, 101, 152 },
+ { 5, 72, 106 },
+ { 1, 36, 52 }
+ }, { /* Coeff Band 2 */
+ { 35, 176, 211 },
+ { 12, 131, 190 },
+ { 2, 88, 144 },
+ { 1, 60, 101 },
+ { 1, 36, 60 },
+ { 1, 16, 28 }
+ }, { /* Coeff Band 3 */
+ { 28, 183, 213 },
+ { 8, 134, 191 },
+ { 1, 86, 142 },
+ { 1, 56, 96 },
+ { 1, 30, 53 },
+ { 1, 12, 20 }
+ }, { /* Coeff Band 4 */
+ { 20, 190, 215 },
+ { 4, 135, 192 },
+ { 1, 84, 139 },
+ { 1, 53, 91 },
+ { 1, 28, 49 },
+ { 1, 11, 20 }
+ }, { /* Coeff Band 5 */
+ { 13, 196, 216 },
+ { 2, 137, 192 },
+ { 1, 86, 143 },
+ { 1, 57, 99 },
+ { 1, 32, 56 },
+ { 1, 13, 24 }
+ }
+ }
+ }, { /* block Type 1 */
+ { /* Intra */
+ { /* Coeff Band 0 */
+ { 211, 29, 217 },
+ { 96, 47, 156 },
+ { 22, 43, 87 }
+ }, { /* Coeff Band 1 */
+ { 78, 120, 193 },
+ { 111, 116, 186 },
+ { 46, 102, 164 },
+ { 15, 80, 128 },
+ { 2, 49, 76 },
+ { 1, 18, 28 }
+ }, { /* Coeff Band 2 */
+ { 71, 161, 203 },
+ { 42, 132, 192 },
+ { 10, 98, 150 },
+ { 3, 69, 109 },
+ { 1, 44, 70 },
+ { 1, 18, 29 }
+ }, { /* Coeff Band 3 */
+ { 57, 186, 211 },
+ { 30, 140, 196 },
+ { 4, 93, 146 },
+ { 1, 62, 102 },
+ { 1, 38, 65 },
+ { 1, 16, 27 }
+ }, { /* Coeff Band 4 */
+ { 47, 199, 217 },
+ { 14, 145, 196 },
+ { 1, 88, 142 },
+ { 1, 57, 98 },
+ { 1, 36, 62 },
+ { 1, 15, 26 }
+ }, { /* Coeff Band 5 */
+ { 26, 219, 229 },
+ { 5, 155, 207 },
+ { 1, 94, 151 },
+ { 1, 60, 104 },
+ { 1, 36, 62 },
+ { 1, 16, 28 }
+ }
+ }, { /* Inter */
+ { /* Coeff Band 0 */
+ { 233, 29, 248 },
+ { 146, 47, 220 },
+ { 43, 52, 140 }
+ }, { /* Coeff Band 1 */
+ { 100, 163, 232 },
+ { 179, 161, 222 },
+ { 63, 142, 204 },
+ { 37, 113, 174 },
+ { 26, 89, 137 },
+ { 18, 68, 97 }
+ }, { /* Coeff Band 2 */
+ { 85, 181, 230 },
+ { 32, 146, 209 },
+ { 7, 100, 164 },
+ { 3, 71, 121 },
+ { 1, 45, 77 },
+ { 1, 18, 30 }
+ }, { /* Coeff Band 3 */
+ { 65, 187, 230 },
+ { 20, 148, 207 },
+ { 2, 97, 159 },
+ { 1, 68, 116 },
+ { 1, 40, 70 },
+ { 1, 14, 29 }
+ }, { /* Coeff Band 4 */
+ { 40, 194, 227 },
+ { 8, 147, 204 },
+ { 1, 94, 155 },
+ { 1, 65, 112 },
+ { 1, 39, 66 },
+ { 1, 14, 26 }
+ }, { /* Coeff Band 5 */
+ { 16, 208, 228 },
+ { 3, 151, 207 },
+ { 1, 98, 160 },
+ { 1, 67, 117 },
+ { 1, 41, 74 },
+ { 1, 17, 31 }
+ }
+ }
+ }
+ }, { /* tx = 32x32 */
+ { /* block Type 0 */
+ { /* Intra */
+ { /* Coeff Band 0 */
+ { 17, 38, 140 },
+ { 7, 34, 80 },
+ { 1, 17, 29 }
+ }, { /* Coeff Band 1 */
+ { 37, 75, 128 },
+ { 41, 76, 128 },
+ { 26, 66, 116 },
+ { 12, 52, 94 },
+ { 2, 32, 55 },
+ { 1, 10, 16 }
+ }, { /* Coeff Band 2 */
+ { 50, 127, 154 },
+ { 37, 109, 152 },
+ { 16, 82, 121 },
+ { 5, 59, 85 },
+ { 1, 35, 54 },
+ { 1, 13, 20 }
+ }, { /* Coeff Band 3 */
+ { 40, 142, 167 },
+ { 17, 110, 157 },
+ { 2, 71, 112 },
+ { 1, 44, 72 },
+ { 1, 27, 45 },
+ { 1, 11, 17 }
+ }, { /* Coeff Band 4 */
+ { 30, 175, 188 },
+ { 9, 124, 169 },
+ { 1, 74, 116 },
+ { 1, 48, 78 },
+ { 1, 30, 49 },
+ { 1, 11, 18 }
+ }, { /* Coeff Band 5 */
+ { 10, 222, 223 },
+ { 2, 150, 194 },
+ { 1, 83, 128 },
+ { 1, 48, 79 },
+ { 1, 27, 45 },
+ { 1, 11, 17 }
+ }
+ }, { /* Inter */
+ { /* Coeff Band 0 */
+ { 36, 41, 235 },
+ { 29, 36, 193 },
+ { 10, 27, 111 }
+ }, { /* Coeff Band 1 */
+ { 85, 165, 222 },
+ { 177, 162, 215 },
+ { 110, 135, 195 },
+ { 57, 113, 168 },
+ { 23, 83, 120 },
+ { 10, 49, 61 }
+ }, { /* Coeff Band 2 */
+ { 85, 190, 223 },
+ { 36, 139, 200 },
+ { 5, 90, 146 },
+ { 1, 60, 103 },
+ { 1, 38, 65 },
+ { 1, 18, 30 }
+ }, { /* Coeff Band 3 */
+ { 72, 202, 223 },
+ { 23, 141, 199 },
+ { 2, 86, 140 },
+ { 1, 56, 97 },
+ { 1, 36, 61 },
+ { 1, 16, 27 }
+ }, { /* Coeff Band 4 */
+ { 55, 218, 225 },
+ { 13, 145, 200 },
+ { 1, 86, 141 },
+ { 1, 57, 99 },
+ { 1, 35, 61 },
+ { 1, 13, 22 }
+ }, { /* Coeff Band 5 */
+ { 15, 235, 212 },
+ { 1, 132, 184 },
+ { 1, 84, 139 },
+ { 1, 57, 97 },
+ { 1, 34, 56 },
+ { 1, 14, 23 }
+ }
+ }
+ }, { /* block Type 1 */
+ { /* Intra */
+ { /* Coeff Band 0 */
+ { 181, 21, 201 },
+ { 61, 37, 123 },
+ { 10, 38, 71 }
+ }, { /* Coeff Band 1 */
+ { 47, 106, 172 },
+ { 95, 104, 173 },
+ { 42, 93, 159 },
+ { 18, 77, 131 },
+ { 4, 50, 81 },
+ { 1, 17, 23 }
+ }, { /* Coeff Band 2 */
+ { 62, 147, 199 },
+ { 44, 130, 189 },
+ { 28, 102, 154 },
+ { 18, 75, 115 },
+ { 2, 44, 65 },
+ { 1, 12, 19 }
+ }, { /* Coeff Band 3 */
+ { 55, 153, 210 },
+ { 24, 130, 194 },
+ { 3, 93, 146 },
+ { 1, 61, 97 },
+ { 1, 31, 50 },
+ { 1, 10, 16 }
+ }, { /* Coeff Band 4 */
+ { 49, 186, 223 },
+ { 17, 148, 204 },
+ { 1, 96, 142 },
+ { 1, 53, 83 },
+ { 1, 26, 44 },
+ { 1, 11, 17 }
+ }, { /* Coeff Band 5 */
+ { 13, 217, 212 },
+ { 2, 136, 180 },
+ { 1, 78, 124 },
+ { 1, 50, 83 },
+ { 1, 29, 49 },
+ { 1, 14, 23 }
+ }
+ }, { /* Inter */
+ { /* Coeff Band 0 */
+ { 197, 13, 247 },
+ { 82, 17, 222 },
+ { 25, 17, 162 }
+ }, { /* Coeff Band 1 */
+ { 126, 186, 247 },
+ { 234, 191, 243 },
+ { 176, 177, 234 },
+ { 104, 158, 220 },
+ { 66, 128, 186 },
+ { 55, 90, 137 }
+ }, { /* Coeff Band 2 */
+ { 111, 197, 242 },
+ { 46, 158, 219 },
+ { 9, 104, 171 },
+ { 2, 65, 125 },
+ { 1, 44, 80 },
+ { 1, 17, 91 }
+ }, { /* Coeff Band 3 */
+ { 104, 208, 245 },
+ { 39, 168, 224 },
+ { 3, 109, 162 },
+ { 1, 79, 124 },
+ { 1, 50, 102 },
+ { 1, 43, 102 }
+ }, { /* Coeff Band 4 */
+ { 84, 220, 246 },
+ { 31, 177, 231 },
+ { 2, 115, 180 },
+ { 1, 79, 134 },
+ { 1, 55, 77 },
+ { 1, 60, 79 }
+ }, { /* Coeff Band 5 */
+ { 43, 243, 240 },
+ { 8, 180, 217 },
+ { 1, 115, 166 },
+ { 1, 84, 121 },
+ { 1, 51, 67 },
+ { 1, 16, 6 }
+ }
+ }
+ }
+ }
+};
+
+enum MVJoint {
+ MV_JOINT_ZERO,
+ MV_JOINT_H,
+ MV_JOINT_V,
+ MV_JOINT_HV,
+};
+
+static const int8_t vp9_mv_joint_tree[3][2] = {
+ { -MV_JOINT_ZERO, 1 }, // '0'
+ { -MV_JOINT_H, 2 }, // '10'
+ { -MV_JOINT_V, -MV_JOINT_HV }, // '11x'
+};
+
+static const int8_t vp9_mv_class_tree[10][2] = {
+ { -0, 1 }, // '0'
+ { -1, 2 }, // '10'
+ { 3, 4 },
+ { -2, -3 }, // '110x'
+ { 5, 6 },
+ { -4, -5 }, // '1110x'
+ { -6, 7 }, // '11110'
+ { 8, 9 },
+ { -7, -8 }, // '111110x'
+ { -9, -10 }, // '111111x'
+};
+
+static const int8_t vp9_mv_fp_tree[3][2] = {
+ { -0, 1 }, // '0'
+ { -1, 2 }, // '10'
+ { -2, -3 }, // '11x'
+};
+
+#endif /* AVCODEC_VP9DATA_H */
diff --git a/libavcodec/vp9dsp.c b/libavcodec/vp9dsp.c
new file mode 100644
index 0000000000..37caec10ac
--- /dev/null
+++ b/libavcodec/vp9dsp.c
@@ -0,0 +1,2047 @@
+/*
+ * VP9 compatible video decoder
+ *
+ * Copyright (C) 2013 Ronald S. Bultje <rsbultje gmail com>
+ * Copyright (C) 2013 Clément Bœsch <u pkh me>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/common.h"
+#include "libavutil/intreadwrite.h"
+#include "vp9dsp.h"
+#include "rnd_avg.h"
+
+// FIXME see whether we can merge parts of this (perhaps at least 4x4 and 8x8)
+// back with h264pred.[ch]
+
+static void vert_4x4_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ unsigned p4 = AV_RN32A(top);
+
+ AV_WN32A(dst + stride * 0, p4);
+ AV_WN32A(dst + stride * 1, p4);
+ AV_WN32A(dst + stride * 2, p4);
+ AV_WN32A(dst + stride * 3, p4);
+}
+
+static void vert_8x8_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ uint64_t p8 = AV_RN64A(top);
+ int y;
+
+ for (y = 0; y < 8; y++) {
+ AV_WN64A(dst, p8);
+ dst += stride;
+ }
+}
+
+static void vert_16x16_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ uint64_t p8a = AV_RN64A(top + 0), p8b = AV_RN64A(top + 8);
+ int y;
+
+ for (y = 0; y < 16; y++) {
+ AV_WN64A(dst + 0, p8a);
+ AV_WN64A(dst + 8, p8b);
+ dst += stride;
+ }
+}
+
+static void vert_32x32_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ uint64_t p8a = AV_RN64A(top + 0), p8b = AV_RN64A(top + 8),
+ p8c = AV_RN64A(top + 16), p8d = AV_RN64A(top + 24);
+ int y;
+
+ for (y = 0; y < 32; y++) {
+ AV_WN64A(dst + 0, p8a);
+ AV_WN64A(dst + 8, p8b);
+ AV_WN64A(dst + 16, p8c);
+ AV_WN64A(dst + 24, p8d);
+ dst += stride;
+ }
+}
+
+static void hor_4x4_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ AV_WN32A(dst + stride * 0, left[0] * 0x01010101U);
+ AV_WN32A(dst + stride * 1, left[1] * 0x01010101U);
+ AV_WN32A(dst + stride * 2, left[2] * 0x01010101U);
+ AV_WN32A(dst + stride * 3, left[3] * 0x01010101U);
+}
+
+static void hor_8x8_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ int y;
+
+ for (y = 0; y < 8; y++) {
+ AV_WN64A(dst, left[y] * 0x0101010101010101ULL);
+ dst += stride;
+ }
+}
+
+static void hor_16x16_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ int y;
+
+ for (y = 0; y < 16; y++) {
+ uint64_t p8 = left[y] * 0x0101010101010101ULL;
+
+ AV_WN64A(dst + 0, p8);
+ AV_WN64A(dst + 8, p8);
+ dst += stride;
+ }
+}
+
+static void hor_32x32_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ int y;
+
+ for (y = 0; y < 32; y++) {
+ uint64_t p8 = left[y] * 0x0101010101010101ULL;
+
+ AV_WN64A(dst + 0, p8);
+ AV_WN64A(dst + 8, p8);
+ AV_WN64A(dst + 16, p8);
+ AV_WN64A(dst + 24, p8);
+ dst += stride;
+ }
+}
+
+static void tm_4x4_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ int y, tl = top[-1];
+
+ for (y = 0; y < 4; y++) {
+ int l_m_tl = left[y] - tl;
+
+ dst[0] = av_clip_uint8(top[0] + l_m_tl);
+ dst[1] = av_clip_uint8(top[1] + l_m_tl);
+ dst[2] = av_clip_uint8(top[2] + l_m_tl);
+ dst[3] = av_clip_uint8(top[3] + l_m_tl);
+ dst += stride;
+ }
+}
+
+static void tm_8x8_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ int y, tl = top[-1];
+
+ for (y = 0; y < 8; y++) {
+ int l_m_tl = left[y] - tl;
+
+ dst[0] = av_clip_uint8(top[0] + l_m_tl);
+ dst[1] = av_clip_uint8(top[1] + l_m_tl);
+ dst[2] = av_clip_uint8(top[2] + l_m_tl);
+ dst[3] = av_clip_uint8(top[3] + l_m_tl);
+ dst[4] = av_clip_uint8(top[4] + l_m_tl);
+ dst[5] = av_clip_uint8(top[5] + l_m_tl);
+ dst[6] = av_clip_uint8(top[6] + l_m_tl);
+ dst[7] = av_clip_uint8(top[7] + l_m_tl);
+ dst += stride;
+ }
+}
+
+static void tm_16x16_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ int y, tl = top[-1];
+
+ for (y = 0; y < 16; y++) {
+ int l_m_tl = left[y] - tl;
+
+ dst[ 0] = av_clip_uint8(top[ 0] + l_m_tl);
+ dst[ 1] = av_clip_uint8(top[ 1] + l_m_tl);
+ dst[ 2] = av_clip_uint8(top[ 2] + l_m_tl);
+ dst[ 3] = av_clip_uint8(top[ 3] + l_m_tl);
+ dst[ 4] = av_clip_uint8(top[ 4] + l_m_tl);
+ dst[ 5] = av_clip_uint8(top[ 5] + l_m_tl);
+ dst[ 6] = av_clip_uint8(top[ 6] + l_m_tl);
+ dst[ 7] = av_clip_uint8(top[ 7] + l_m_tl);
+ dst[ 8] = av_clip_uint8(top[ 8] + l_m_tl);
+ dst[ 9] = av_clip_uint8(top[ 9] + l_m_tl);
+ dst[10] = av_clip_uint8(top[10] + l_m_tl);
+ dst[11] = av_clip_uint8(top[11] + l_m_tl);
+ dst[12] = av_clip_uint8(top[12] + l_m_tl);
+ dst[13] = av_clip_uint8(top[13] + l_m_tl);
+ dst[14] = av_clip_uint8(top[14] + l_m_tl);
+ dst[15] = av_clip_uint8(top[15] + l_m_tl);
+ dst += stride;
+ }
+}
+
+static void tm_32x32_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ int y, tl = top[-1];
+
+ for (y = 0; y < 32; y++) {
+ int l_m_tl = left[y] - tl;
+
+ dst[ 0] = av_clip_uint8(top[ 0] + l_m_tl);
+ dst[ 1] = av_clip_uint8(top[ 1] + l_m_tl);
+ dst[ 2] = av_clip_uint8(top[ 2] + l_m_tl);
+ dst[ 3] = av_clip_uint8(top[ 3] + l_m_tl);
+ dst[ 4] = av_clip_uint8(top[ 4] + l_m_tl);
+ dst[ 5] = av_clip_uint8(top[ 5] + l_m_tl);
+ dst[ 6] = av_clip_uint8(top[ 6] + l_m_tl);
+ dst[ 7] = av_clip_uint8(top[ 7] + l_m_tl);
+ dst[ 8] = av_clip_uint8(top[ 8] + l_m_tl);
+ dst[ 9] = av_clip_uint8(top[ 9] + l_m_tl);
+ dst[10] = av_clip_uint8(top[10] + l_m_tl);
+ dst[11] = av_clip_uint8(top[11] + l_m_tl);
+ dst[12] = av_clip_uint8(top[12] + l_m_tl);
+ dst[13] = av_clip_uint8(top[13] + l_m_tl);
+ dst[14] = av_clip_uint8(top[14] + l_m_tl);
+ dst[15] = av_clip_uint8(top[15] + l_m_tl);
+ dst[16] = av_clip_uint8(top[16] + l_m_tl);
+ dst[17] = av_clip_uint8(top[17] + l_m_tl);
+ dst[18] = av_clip_uint8(top[18] + l_m_tl);
+ dst[19] = av_clip_uint8(top[19] + l_m_tl);
+ dst[20] = av_clip_uint8(top[20] + l_m_tl);
+ dst[21] = av_clip_uint8(top[21] + l_m_tl);
+ dst[22] = av_clip_uint8(top[22] + l_m_tl);
+ dst[23] = av_clip_uint8(top[23] + l_m_tl);
+ dst[24] = av_clip_uint8(top[24] + l_m_tl);
+ dst[25] = av_clip_uint8(top[25] + l_m_tl);
+ dst[26] = av_clip_uint8(top[26] + l_m_tl);
+ dst[27] = av_clip_uint8(top[27] + l_m_tl);
+ dst[28] = av_clip_uint8(top[28] + l_m_tl);
+ dst[29] = av_clip_uint8(top[29] + l_m_tl);
+ dst[30] = av_clip_uint8(top[30] + l_m_tl);
+ dst[31] = av_clip_uint8(top[31] + l_m_tl);
+ dst += stride;
+ }
+}
+
+static void dc_4x4_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ unsigned dc = 0x01010101U * ((left[0] + left[1] + left[2] + left[3] +
+ top[0] + top[1] + top[2] + top[3] + 4) >> 3);
+
+ AV_WN32A(dst + stride * 0, dc);
+ AV_WN32A(dst + stride * 1, dc);
+ AV_WN32A(dst + stride * 2, dc);
+ AV_WN32A(dst + stride * 3, dc);
+}
+
+static void dc_8x8_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ uint64_t dc = 0x0101010101010101ULL *
+ ((left[0] + left[1] + left[2] + left[3] + left[4] + left[5] +
+ left[6] + left[7] + top[0] + top[1] + top[2] + top[3] +
+ top[4] + top[5] + top[6] + top[7] + 8) >> 4);
+ int y;
+
+ for (y = 0; y < 8; y++) {
+ AV_WN64A(dst, dc);
+ dst += stride;
+ }
+}
+
+static void dc_16x16_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ uint64_t dc = 0x0101010101010101ULL *
+ ((left[0] + left[1] + left[2] + left[3] + left[4] + left[5] + left[6] +
+ left[7] + left[8] + left[9] + left[10] + left[11] + left[12] +
+ left[13] + left[14] + left[15] + top[0] + top[1] + top[2] + top[3] +
+ top[4] + top[5] + top[6] + top[7] + top[8] + top[9] + top[10] +
+ top[11] + top[12] + top[13] + top[14] + top[15] + 16) >> 5);
+ int y;
+
+ for (y = 0; y < 16; y++) {
+ AV_WN64A(dst + 0, dc);
+ AV_WN64A(dst + 8, dc);
+ dst += stride;
+ }
+}
+
+static void dc_32x32_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ uint64_t dc = 0x0101010101010101ULL *
+ ((left[0] + left[1] + left[2] + left[3] + left[4] + left[5] + left[6] +
+ left[7] + left[8] + left[9] + left[10] + left[11] + left[12] +
+ left[13] + left[14] + left[15] + left[16] + left[17] + left[18] +
+ left[19] + left[20] + left[21] + left[22] + left[23] + left[24] +
+ left[25] + left[26] + left[27] + left[28] + left[29] + left[30] +
+ left[31] + top[0] + top[1] + top[2] + top[3] + top[4] + top[5] +
+ top[6] + top[7] + top[8] + top[9] + top[10] + top[11] + top[12] +
+ top[13] + top[14] + top[15] + top[16] + top[17] + top[18] + top[19] +
+ top[20] + top[21] + top[22] + top[23] + top[24] + top[25] + top[26] +
+ top[27] + top[28] + top[29] + top[30] + top[31] + 32) >> 6);
+ int y;
+
+ for (y = 0; y < 32; y++) {
+ AV_WN64A(dst + 0, dc);
+ AV_WN64A(dst + 8, dc);
+ AV_WN64A(dst + 16, dc);
+ AV_WN64A(dst + 24, dc);
+ dst += stride;
+ }
+}
+
+static void dc_left_4x4_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ unsigned dc = 0x01010101U * ((left[0] + left[1] + left[2] + left[3] + 2) >> 2);
+
+ AV_WN32A(dst + stride * 0, dc);
+ AV_WN32A(dst + stride * 1, dc);
+ AV_WN32A(dst + stride * 2, dc);
+ AV_WN32A(dst + stride * 3, dc);
+}
+
+static void dc_left_8x8_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ uint64_t dc = 0x0101010101010101ULL *
+ ((left[0] + left[1] + left[2] + left[3] +
+ left[4] + left[5] + left[6] + left[7] + 4) >> 3);
+ int y;
+
+ for (y = 0; y < 8; y++) {
+ AV_WN64A(dst, dc);
+ dst += stride;
+ }
+}
+
+static void dc_left_16x16_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ uint64_t dc = 0x0101010101010101ULL *
+ ((left[0] + left[1] + left[2] + left[3] + left[4] + left[5] +
+ left[6] + left[7] + left[8] + left[9] + left[10] + left[11] +
+ left[12] + left[13] + left[14] + left[15] + 8) >> 4);
+ int y;
+
+ for (y = 0; y < 16; y++) {
+ AV_WN64A(dst + 0, dc);
+ AV_WN64A(dst + 8, dc);
+ dst += stride;
+ }
+}
+
+static void dc_left_32x32_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ uint64_t dc = 0x0101010101010101ULL *
+ ((left[0] + left[1] + left[2] + left[3] + left[4] + left[5] +
+ left[6] + left[7] + left[8] + left[9] + left[10] + left[11] +
+ left[12] + left[13] + left[14] + left[15] + left[16] + left[17] +
+ left[18] + left[19] + left[20] + left[21] + left[22] + left[23] +
+ left[24] + left[25] + left[26] + left[27] + left[28] + left[29] +
+ left[30] + left[31] + 16) >> 5);
+ int y;
+
+ for (y = 0; y < 32; y++) {
+ AV_WN64A(dst + 0, dc);
+ AV_WN64A(dst + 8, dc);
+ AV_WN64A(dst + 16, dc);
+ AV_WN64A(dst + 24, dc);
+ dst += stride;
+ }
+}
+
+static void dc_top_4x4_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ unsigned dc = 0x01010101U * ((top[0] + top[1] + top[2] + top[3] + 2) >> 2);
+
+ AV_WN32A(dst + stride * 0, dc);
+ AV_WN32A(dst + stride * 1, dc);
+ AV_WN32A(dst + stride * 2, dc);
+ AV_WN32A(dst + stride * 3, dc);
+}
+
+static void dc_top_8x8_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ uint64_t dc = 0x0101010101010101ULL *
+ ((top[0] + top[1] + top[2] + top[3] +
+ top[4] + top[5] + top[6] + top[7] + 4) >> 3);
+ int y;
+
+ for (y = 0; y < 8; y++) {
+ AV_WN64A(dst, dc);
+ dst += stride;
+ }
+}
+
+static void dc_top_16x16_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ uint64_t dc = 0x0101010101010101ULL *
+ ((top[0] + top[1] + top[2] + top[3] + top[4] + top[5] +
+ top[6] + top[7] + top[8] + top[9] + top[10] + top[11] +
+ top[12] + top[13] + top[14] + top[15] + 8) >> 4);
+ int y;
+
+ for (y = 0; y < 16; y++) {
+ AV_WN64A(dst + 0, dc);
+ AV_WN64A(dst + 8, dc);
+ dst += stride;
+ }
+}
+
+static void dc_top_32x32_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ uint64_t dc = 0x0101010101010101ULL *
+ ((top[0] + top[1] + top[2] + top[3] + top[4] + top[5] +
+ top[6] + top[7] + top[8] + top[9] + top[10] + top[11] +
+ top[12] + top[13] + top[14] + top[15] + top[16] + top[17] +
+ top[18] + top[19] + top[20] + top[21] + top[22] + top[23] +
+ top[24] + top[25] + top[26] + top[27] + top[28] + top[29] +
+ top[30] + top[31] + 16) >> 5);
+ int y;
+
+ for (y = 0; y < 32; y++) {
+ AV_WN64A(dst + 0, dc);
+ AV_WN64A(dst + 8, dc);
+ AV_WN64A(dst + 16, dc);
+ AV_WN64A(dst + 24, dc);
+ dst += stride;
+ }
+}
+
+static void dc_128_4x4_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ AV_WN32A(dst + stride * 0, 0x80808080U);
+ AV_WN32A(dst + stride * 1, 0x80808080U);
+ AV_WN32A(dst + stride * 2, 0x80808080U);
+ AV_WN32A(dst + stride * 3, 0x80808080U);
+}
+
+static void dc_128_8x8_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ int y;
+
+ for (y = 0; y < 8; y++) {
+ AV_WN64A(dst, 0x8080808080808080ULL);
+ dst += stride;
+ }
+}
+
+static void dc_128_16x16_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ int y;
+
+ for (y = 0; y < 16; y++) {
+ AV_WN64A(dst + 0, 0x8080808080808080ULL);
+ AV_WN64A(dst + 8, 0x8080808080808080ULL);
+ dst += stride;
+ }
+}
+
+static void dc_128_32x32_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ int y;
+
+ for (y = 0; y < 32; y++) {
+ AV_WN64A(dst + 0, 0x8080808080808080ULL);
+ AV_WN64A(dst + 8, 0x8080808080808080ULL);
+ AV_WN64A(dst + 16, 0x8080808080808080ULL);
+ AV_WN64A(dst + 24, 0x8080808080808080ULL);
+ dst += stride;
+ }
+}
+
+static void dc_127_4x4_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ AV_WN32A(dst + stride * 0, 0x7F7F7F7FU);
+ AV_WN32A(dst + stride * 1, 0x7F7F7F7FU);
+ AV_WN32A(dst + stride * 2, 0x7F7F7F7FU);
+ AV_WN32A(dst + stride * 3, 0x7F7F7F7FU);
+}
+
+static void dc_127_8x8_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ int y;
+
+ for (y = 0; y < 8; y++) {
+ AV_WN64A(dst, 0x7F7F7F7F7F7F7F7FULL);
+ dst += stride;
+ }
+}
+
+static void dc_127_16x16_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ int y;
+
+ for (y = 0; y < 16; y++) {
+ AV_WN64A(dst + 0, 0x7F7F7F7F7F7F7F7FULL);
+ AV_WN64A(dst + 8, 0x7F7F7F7F7F7F7F7FULL);
+ dst += stride;
+ }
+}
+
+static void dc_127_32x32_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ int y;
+
+ for (y = 0; y < 32; y++) {
+ AV_WN64A(dst + 0, 0x7F7F7F7F7F7F7F7FULL);
+ AV_WN64A(dst + 8, 0x7F7F7F7F7F7F7F7FULL);
+ AV_WN64A(dst + 16, 0x7F7F7F7F7F7F7F7FULL);
+ AV_WN64A(dst + 24, 0x7F7F7F7F7F7F7F7FULL);
+ dst += stride;
+ }
+}
+
+static void dc_129_4x4_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ AV_WN32A(dst + stride * 0, 0x81818181U);
+ AV_WN32A(dst + stride * 1, 0x81818181U);
+ AV_WN32A(dst + stride * 2, 0x81818181U);
+ AV_WN32A(dst + stride * 3, 0x81818181U);
+}
+
+static void dc_129_8x8_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ int y;
+
+ for (y = 0; y < 8; y++) {
+ AV_WN64A(dst, 0x8181818181818181ULL);
+ dst += stride;
+ }
+}
+
+static void dc_129_16x16_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ int y;
+
+ for (y = 0; y < 16; y++) {
+ AV_WN64A(dst + 0, 0x8181818181818181ULL);
+ AV_WN64A(dst + 8, 0x8181818181818181ULL);
+ dst += stride;
+ }
+}
+
+static void dc_129_32x32_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ int y;
+
+ for (y = 0; y < 32; y++) {
+ AV_WN64A(dst + 0, 0x8181818181818181ULL);
+ AV_WN64A(dst + 8, 0x8181818181818181ULL);
+ AV_WN64A(dst + 16, 0x8181818181818181ULL);
+ AV_WN64A(dst + 24, 0x8181818181818181ULL);
+ dst += stride;
+ }
+}
+
+#define DST(x, y) dst[(x) + (y) * stride]
+
+static void diag_downleft_4x4_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ int a0 = top[0], a1 = top[1], a2 = top[2], a3 = top[3],
+ a4 = top[4], a5 = top[5], a6 = top[6], a7 = top[7];
+
+ DST(0,0) = (a0 + a1 * 2 + a2 + 2) >> 2;
+ DST(1,0) = DST(0,1) = (a1 + a2 * 2 + a3 + 2) >> 2;
+ DST(2,0) = DST(1,1) = DST(0,2) = (a2 + a3 * 2 + a4 + 2) >> 2;
+ DST(3,0) = DST(2,1) = DST(1,2) = DST(0,3) = (a3 + a4 * 2 + a5 + 2) >> 2;
+ DST(3,1) = DST(2,2) = DST(1,3) = (a4 + a5 * 2 + a6 + 2) >> 2;
+ DST(3,2) = DST(2,3) = (a5 + a6 * 2 + a7 + 2) >> 2;
+ DST(3,3) = a7; // note: this is different from vp8 and such
+}
+
+#define def_diag_downleft(size) \
+static void diag_downleft_##size##x##size##_c(uint8_t *dst, ptrdiff_t stride, \
+ const uint8_t *left, const uint8_t *top) \
+{ \
+ int i, j; \
+ uint8_t v[size - 1]; \
+\
+ for (i = 0; i < size - 2; i++) \
+ v[i] = (top[i] + top[i + 1] * 2 + top[i + 2] + 2) >> 2; \
+ v[size - 2] = (top[size - 2] + top[size - 1] * 3 + 2) >> 2; \
+\
+ for (j = 0; j < size; j++) { \
+ memcpy(dst + j*stride, v + j, size - 1 - j); \
+ memset(dst + j*stride + size - 1 - j, top[size - 1], j + 1); \
+ } \
+}
+
+def_diag_downleft(8)
+def_diag_downleft(16)
+def_diag_downleft(32)
+
+static void diag_downright_4x4_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ int tl = top[-1], a0 = top[0], a1 = top[1], a2 = top[2], a3 = top[3],
+ l0 = left[0], l1 = left[1], l2 = left[2], l3 = left[3];
+
+ DST(0,3) = (l1 + l2 * 2 + l3 + 2) >> 2;
+ DST(0,2) = DST(1,3) = (l0 + l1 * 2 + l2 + 2) >> 2;
+ DST(0,1) = DST(1,2) = DST(2,3) = (tl + l0 * 2 + l1 + 2) >> 2;
+ DST(0,0) = DST(1,1) = DST(2,2) = DST(3,3) = (l0 + tl * 2 + a0 + 2) >> 2;
+ DST(1,0) = DST(2,1) = DST(3,2) = (tl + a0 * 2 + a1 + 2) >> 2;
+ DST(2,0) = DST(3,1) = (a0 + a1 * 2 + a2 + 2) >> 2;
+ DST(3,0) = (a1 + a2 * 2 + a3 + 2) >> 2;
+}
+
+#define def_diag_downright(size) \
+static void diag_downright_##size##x##size##_c(uint8_t *dst, ptrdiff_t stride, \
+ const uint8_t *left, const uint8_t *top) \
+{ \
+ int i, j; \
+ uint8_t v[size + size - 1]; \
+\
+ for (i = 0; i < size - 2; i++) { \
+ v[i ] = (left[size - 1 - i] + left[size - 2 - i] * 2 + left[size - 3 - i] + 2) >> 2; \
+ v[size + 1 + i] = (top[i] + top[i + 1] * 2 + top[i + 2] + 2) >> 2; \
+ } \
+ v[size - 2] = (left[1] + left[0] * 2 + top[-1] + 2) >> 2; \
+ v[size - 1] = (left[0] + top[-1] * 2 + top[ 0] + 2) >> 2; \
+ v[size ] = (top[-1] + top[0] * 2 + top[ 1] + 2) >> 2; \
+\
+ for (j = 0; j < size; j++) \
+ memcpy(dst + j*stride, v + size - 1 - j, size); \
+}
+
+def_diag_downright(8)
+def_diag_downright(16)
+def_diag_downright(32)
+
+static void vert_right_4x4_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ int tl = top[-1], a0 = top[0], a1 = top[1], a2 = top[2], a3 = top[3],
+ l0 = left[0], l1 = left[1], l2 = left[2];
+
+ DST(0,3) = (l0 + l1 * 2 + l2 + 2) >> 2;
+ DST(0,2) = (tl + l0 * 2 + l1 + 2) >> 2;
+ DST(0,0) = DST(1,2) = (tl + a0 + 1) >> 1;
+ DST(0,1) = DST(1,3) = (l0 + tl * 2 + a0 + 2) >> 2;
+ DST(1,0) = DST(2,2) = (a0 + a1 + 1) >> 1;
+ DST(1,1) = DST(2,3) = (tl + a0 * 2 + a1 + 2) >> 2;
+ DST(2,0) = DST(3,2) = (a1 + a2 + 1) >> 1;
+ DST(2,1) = DST(3,3) = (a0 + a1 * 2 + a2 + 2) >> 2;
+ DST(3,0) = (a2 + a3 + 1) >> 1;
+ DST(3,1) = (a1 + a2 * 2 + a3 + 2) >> 2;
+}
+
+#define def_vert_right(size) \
+static void vert_right_##size##x##size##_c(uint8_t *dst, ptrdiff_t stride, \
+ const uint8_t *left, const uint8_t *top) \
+{ \
+ int i, j; \
+ uint8_t ve[size + size/2 - 1], vo[size + size/2 - 1]; \
+\
+ for (i = 0; i < size/2 - 2; i++) { \
+ vo[i] = (left[size - 4 - i*2] + left[size - 3 - i*2] * 2 + left[size - 2 - i*2] + 2) >> 2; \
+ ve[i] = (left[size - 5 - i*2] + left[size - 4 - i*2] * 2 + left[size - 3 - i*2] + 2) >> 2; \
+ } \
+ vo[size/2 - 2] = (left[0] + left[1] * 2 + left[2] + 2) >> 2; \
+ ve[size/2 - 2] = (top[-1] + left[0] * 2 + left[1] + 2) >> 2; \
+\
+ ve[size/2 - 1] = (top[-1] + top[0] + 1) >> 1; \
+ vo[size/2 - 1] = (left[0] + top[-1] * 2 + top[0] + 2) >> 2; \
+ for (i = 0; i < size - 1; i++) { \
+ ve[size/2 + i] = (top[i] + top[i + 1] + 1) >> 1; \
+ vo[size/2 + i] = (top[i - 1] + top[i] * 2 + top[i + 1] + 2) >> 2; \
+ } \
+\
+ for (j = 0; j < size / 2; j++) { \
+ memcpy(dst + j*2 *stride, ve + size/2 - 1 - j, size); \
+ memcpy(dst + (j*2 + 1)*stride, vo + size/2 - 1 - j, size); \
+ } \
+}
+
+def_vert_right(8)
+def_vert_right(16)
+def_vert_right(32)
+
+static void hor_down_4x4_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ int l0 = left[0], l1 = left[1], l2 = left[2], l3 = left[3],
+ tl = top[-1], a0 = top[0], a1 = top[1], a2 = top[2];
+
+ DST(2,0) = (tl + a0 * 2 + a1 + 2) >> 2;
+ DST(3,0) = (a0 + a1 * 2 + a2 + 2) >> 2;
+ DST(0,0) = DST(2,1) = (tl + l0 + 1) >> 1;
+ DST(1,0) = DST(3,1) = (a0 + tl * 2 + l0 + 2) >> 2;
+ DST(0,1) = DST(2,2) = (l0 + l1 + 1) >> 1;
+ DST(1,1) = DST(3,2) = (tl + l0 * 2 + l1 + 2) >> 2;
+ DST(0,2) = DST(2,3) = (l1 + l2 + 1) >> 1;
+ DST(1,2) = DST(3,3) = (l0 + l1 * 2 + l2 + 2) >> 2;
+ DST(0,3) = (l2 + l3 + 1) >> 1;
+ DST(1,3) = (l1 + l2 * 2 + l3 + 2) >> 2;
+}
+
+#define def_hor_down(size) \
+static void hor_down_##size##x##size##_c(uint8_t *dst, ptrdiff_t stride, \
+ const uint8_t *left, const uint8_t *top) \
+{ \
+ int i, j; \
+ uint8_t v[size * 3 - 2]; \
+\
+ for (i = 0; i < size - 2; i++) { \
+ v[i*2 ] = (left[size - 2 - i] + left[size - 1 - i] + 1) >> 1; \
+ v[i*2 + 1] = (left[size - 3 - i] + left[size - 2 - i] * 2 + left[size - 1 - i] + 2) >> 2; \
+ v[size*2 + i] = (top[i - 1] + top[i] * 2 + top[i + 1] + 2) >> 2; \
+ } \
+ v[size*2 - 2] = (top[-1] + left[0] + 1) >> 1; \
+ v[size*2 - 4] = (left[0] + left[1] + 1) >> 1; \
+ v[size*2 - 1] = (top[0] + top[-1] * 2 + left[0] + 2) >> 2; \
+ v[size*2 - 3] = (top[-1] + left[0] * 2 + left[1] + 2) >> 2; \
+\
+ for (j = 0; j < size; j++) \
+ memcpy(dst + j*stride, v + size*2 - 2 - j*2, size); \
+}
+
+def_hor_down(8)
+def_hor_down(16)
+def_hor_down(32)
+
+static void vert_left_4x4_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ int a0 = top[0], a1 = top[1], a2 = top[2], a3 = top[3],
+ a4 = top[4], a5 = top[5], a6 = top[6];
+
+ DST(0,0) = (a0 + a1 + 1) >> 1;
+ DST(0,1) = (a0 + a1 * 2 + a2 + 2) >> 2;
+ DST(1,0) = DST(0,2) = (a1 + a2 + 1) >> 1;
+ DST(1,1) = DST(0,3) = (a1 + a2 * 2 + a3 + 2) >> 2;
+ DST(2,0) = DST(1,2) = (a2 + a3 + 1) >> 1;
+ DST(2,1) = DST(1,3) = (a2 + a3 * 2 + a4 + 2) >> 2;
+ DST(3,0) = DST(2,2) = (a3 + a4 + 1) >> 1;
+ DST(3,1) = DST(2,3) = (a3 + a4 * 2 + a5 + 2) >> 2;
+ DST(3,2) = (a4 + a5 + 1) >> 1;
+ DST(3,3) = (a4 + a5 * 2 + a6 + 2) >> 2;
+}
+
+#define def_vert_left(size) \
+static void vert_left_##size##x##size##_c(uint8_t *dst, ptrdiff_t stride, \
+ const uint8_t *left, const uint8_t *top) \
+{ \
+ int i, j; \
+ uint8_t ve[size - 1], vo[size - 1]; \
+\
+ for (i = 0; i < size - 2; i++) { \
+ ve[i] = (top[i] + top[i + 1] + 1) >> 1; \
+ vo[i] = (top[i] + top[i + 1] * 2 + top[i + 2] + 2) >> 2; \
+ } \
+ ve[size - 2] = (top[size - 2] + top[size - 1] + 1) >> 1; \
+ vo[size - 2] = (top[size - 2] + top[size - 1] * 3 + 2) >> 2; \
+\
+ for (j = 0; j < size / 2; j++) { \
+ memcpy(dst + j*2 * stride, ve + j, size - j); \
+ memset(dst + j*2 * stride + size - j - 1, top[size - 1], j + 1); \
+ memcpy(dst + (j*2 + 1) * stride, vo + j, size - j); \
+ memset(dst + (j*2 + 1) * stride + size - j - 1, top[size - 1], j + 1); \
+ } \
+}
+
+def_vert_left(8)
+def_vert_left(16)
+def_vert_left(32)
+
+static void hor_up_4x4_c(uint8_t *dst, ptrdiff_t stride,
+ const uint8_t *left, const uint8_t *top)
+{
+ int l0 = left[0], l1 = left[1], l2 = left[2], l3 = left[3];
+
+ DST(0,0) = (l0 + l1 + 1) >> 1;
+ DST(1,0) = (l0 + l1 * 2 + l2 + 2) >> 2;
+ DST(0,1) = DST(2,0) = (l1 + l2 + 1) >> 1;
+ DST(1,1) = DST(3,0) = (l1 + l2 * 2 + l3 + 2) >> 2;
+ DST(0,2) = DST(2,1) = (l2 + l3 + 1) >> 1;
+ DST(1,2) = DST(3,1) = (l2 + l3 * 3 + 2) >> 2;
+ DST(0,3) = DST(1,3) = DST(2,2) = DST(2,3) = DST(3,2) = DST(3,3) = l3;
+}
+
+#define def_hor_up(size) \
+static void hor_up_##size##x##size##_c(uint8_t *dst, ptrdiff_t stride, \
+ const uint8_t *left, const uint8_t *top) \
+{ \
+ int i, j; \
+ uint8_t v[size*2 - 2]; \
+\
+ for (i = 0; i < size - 2; i++) { \
+ v[i*2 ] = (left[i] + left[i + 1] + 1) >> 1; \
+ v[i*2 + 1] = (left[i] + left[i + 1] * 2 + left[i + 2] + 2) >> 2; \
+ } \
+ v[size*2 - 4] = (left[size - 2] + left[size - 1] + 1) >> 1; \
+ v[size*2 - 3] = (left[size - 2] + left[size - 1] * 3 + 2) >> 2; \
+\
+ for (j = 0; j < size / 2; j++) \
+ memcpy(dst + j*stride, v + j*2, size); \
+ for (j = size / 2; j < size; j++) { \
+ memcpy(dst + j*stride, v + j*2, size*2 - 2 - j*2); \
+ memset(dst + j*stride + size*2 - 2 - j*2, left[size - 1], \
+ 2 + j*2 - size); \
+ } \
+}
+
+def_hor_up(8)
+def_hor_up(16)
+def_hor_up(32)
+
+#undef DST
+
+static av_cold void vp9dsp_intrapred_init(VP9DSPContext *dsp)
+{
+#define init_intra_pred(tx, sz) \
+ dsp->intra_pred[tx][VERT_PRED] = vert_##sz##_c; \
+ dsp->intra_pred[tx][HOR_PRED] = hor_##sz##_c; \
+ dsp->intra_pred[tx][DC_PRED] = dc_##sz##_c; \
+ dsp->intra_pred[tx][DIAG_DOWN_LEFT_PRED] = diag_downleft_##sz##_c; \
+ dsp->intra_pred[tx][DIAG_DOWN_RIGHT_PRED] = diag_downright_##sz##_c; \
+ dsp->intra_pred[tx][VERT_RIGHT_PRED] = vert_right_##sz##_c; \
+ dsp->intra_pred[tx][HOR_DOWN_PRED] = hor_down_##sz##_c; \
+ dsp->intra_pred[tx][VERT_LEFT_PRED] = vert_left_##sz##_c; \
+ dsp->intra_pred[tx][HOR_UP_PRED] = hor_up_##sz##_c; \
+ dsp->intra_pred[tx][TM_VP8_PRED] = tm_##sz##_c; \
+ dsp->intra_pred[tx][LEFT_DC_PRED] = dc_left_##sz##_c; \
+ dsp->intra_pred[tx][TOP_DC_PRED] = dc_top_##sz##_c; \
+ dsp->intra_pred[tx][DC_128_PRED] = dc_128_##sz##_c; \
+ dsp->intra_pred[tx][DC_127_PRED] = dc_127_##sz##_c; \
+ dsp->intra_pred[tx][DC_129_PRED] = dc_129_##sz##_c
+
+ init_intra_pred(TX_4X4, 4x4);
+ init_intra_pred(TX_8X8, 8x8);
+ init_intra_pred(TX_16X16, 16x16);
+ init_intra_pred(TX_32X32, 32x32);
+
+#undef init_intra_pred
+}
+
+#define itxfm_wrapper(type_a, type_b, sz, bits) \
+static void type_a##_##type_b##_##sz##x##sz##_add_c(uint8_t *dst, \
+ ptrdiff_t stride, \
+ int16_t *block, int eob) \
+{ \
+ int i, j; \
+ int16_t tmp[sz * sz], out[sz]; \
+ for (i = 0; i < sz; i++) \
+ type_a##sz##_1d(block + i, sz, tmp + i * sz, 0); \
+ memset(block, 0, sz * sz * sizeof(*block)); \
+ for (i = 0; i < sz; i++) { \
+ type_b##sz##_1d(tmp + i, sz, out, 1); \
+ for (j = 0; j < sz; j++) \
+ dst[j * stride] = av_clip_uint8(dst[j * stride] + \
+ (bits ? \
+ (out[j] + (1 << (bits - 1))) >> bits : \
+ out[j])); \
+ dst++; \
+ } \
+}
+
+#define itxfm_wrap(sz, bits) \
+itxfm_wrapper(idct, idct, sz, bits) \
+itxfm_wrapper(iadst, idct, sz, bits) \
+itxfm_wrapper(idct, iadst, sz, bits) \
+itxfm_wrapper(iadst, iadst, sz, bits)
+
+#define IN(x) in[x * stride]
+
+static av_always_inline void idct4_1d(const int16_t *in, ptrdiff_t stride,
+ int16_t *out, int pass)
+{
+ int t0, t1, t2, t3;
+
+ t0 = ((IN(0) + IN(2)) * 11585 + (1 << 13)) >> 14;
+ t1 = ((IN(0) - IN(2)) * 11585 + (1 << 13)) >> 14;
+ t2 = (IN(1) * 6270 - IN(3) * 15137 + (1 << 13)) >> 14;
+ t3 = (IN(1) * 15137 + IN(3) * 6270 + (1 << 13)) >> 14;
+
+ out[0] = t0 + t3;
+ out[1] = t1 + t2;
+ out[2] = t1 - t2;
+ out[3] = t0 - t3;
+}
+
+static av_always_inline void iadst4_1d(const int16_t *in, ptrdiff_t stride,
+ int16_t *out, int pass)
+{
+ int t0, t1, t2, t3;
+
+ t0 = 5283 * IN(0) + 15212 * IN(2) + 9929 * IN(3);
+ t1 = 9929 * IN(0) - 5283 * IN(2) - 15212 * IN(3);
+ t2 = 13377 * (IN(0) - IN(2) + IN(3));
+ t3 = 13377 * IN(1);
+
+ out[0] = (t0 + t3 + (1 << 13)) >> 14;
+ out[1] = (t1 + t3 + (1 << 13)) >> 14;
+ out[2] = (t2 + (1 << 13)) >> 14;
+ out[3] = (t0 + t1 - t3 + (1 << 13)) >> 14;
+}
+
+itxfm_wrap(4, 4)
+
+static av_always_inline void idct8_1d(const int16_t *in, ptrdiff_t stride,
+ int16_t *out, int pass)
+{
+ int t0, t0a, t1, t1a, t2, t2a, t3, t3a, t4, t4a, t5, t5a, t6, t6a, t7, t7a;
+
+ t0a = ((IN(0) + IN(4)) * 11585 + (1 << 13)) >> 14;
+ t1a = ((IN(0) - IN(4)) * 11585 + (1 << 13)) >> 14;
+ t2a = (IN(2) * 6270 - IN(6) * 15137 + (1 << 13)) >> 14;
+ t3a = (IN(2) * 15137 + IN(6) * 6270 + (1 << 13)) >> 14;
+ t4a = (IN(1) * 3196 - IN(7) * 16069 + (1 << 13)) >> 14;
+ t5a = (IN(5) * 13623 - IN(3) * 9102 + (1 << 13)) >> 14;
+ t6a = (IN(5) * 9102 + IN(3) * 13623 + (1 << 13)) >> 14;
+ t7a = (IN(1) * 16069 + IN(7) * 3196 + (1 << 13)) >> 14;
+
+ t0 = t0a + t3a;
+ t1 = t1a + t2a;
+ t2 = t1a - t2a;
+ t3 = t0a - t3a;
+ t4 = t4a + t5a;
+ t5a = t4a - t5a;
+ t7 = t7a + t6a;
+ t6a = t7a - t6a;
+
+ t5 = ((t6a - t5a) * 11585 + (1 << 13)) >> 14;
+ t6 = ((t6a + t5a) * 11585 + (1 << 13)) >> 14;
+
+ out[0] = t0 + t7;
+ out[1] = t1 + t6;
+ out[2] = t2 + t5;
+ out[3] = t3 + t4;
+ out[4] = t3 - t4;
+ out[5] = t2 - t5;
+ out[6] = t1 - t6;
+ out[7] = t0 - t7;
+}
+
+static av_always_inline void iadst8_1d(const int16_t *in, ptrdiff_t stride,
+ int16_t *out, int pass)
+{
+ int t0, t0a, t1, t1a, t2, t2a, t3, t3a, t4, t4a, t5, t5a, t6, t6a, t7, t7a;
+
+ t0a = 16305 * IN(7) + 1606 * IN(0);
+ t1a = 1606 * IN(7) - 16305 * IN(0);
+ t2a = 14449 * IN(5) + 7723 * IN(2);
+ t3a = 7723 * IN(5) - 14449 * IN(2);
+ t4a = 10394 * IN(3) + 12665 * IN(4);
+ t5a = 12665 * IN(3) - 10394 * IN(4);
+ t6a = 4756 * IN(1) + 15679 * IN(6);
+ t7a = 15679 * IN(1) - 4756 * IN(6);
+
+ t0 = (t0a + t4a + (1 << 13)) >> 14;
+ t1 = (t1a + t5a + (1 << 13)) >> 14;
+ t2 = (t2a + t6a + (1 << 13)) >> 14;
+ t3 = (t3a + t7a + (1 << 13)) >> 14;
+ t4 = (t0a - t4a + (1 << 13)) >> 14;
+ t5 = (t1a - t5a + (1 << 13)) >> 14;
+ t6 = (t2a - t6a + (1 << 13)) >> 14;
+ t7 = (t3a - t7a + (1 << 13)) >> 14;
+
+ t4a = 15137 * t4 + 6270 * t5;
+ t5a = 6270 * t4 - 15137 * t5;
+ t6a = 15137 * t7 - 6270 * t6;
+ t7a = 6270 * t7 + 15137 * t6;
+
+ out[0] = t0 + t2;
+ out[7] = -(t1 + t3);
+ t2 = t0 - t2;
+ t3 = t1 - t3;
+
+ out[1] = -((t4a + t6a + (1 << 13)) >> 14);
+ out[6] = (t5a + t7a + (1 << 13)) >> 14;
+ t6 = (t4a - t6a + (1 << 13)) >> 14;
+ t7 = (t5a - t7a + (1 << 13)) >> 14;
+
+ out[3] = -(((t2 + t3) * 11585 + (1 << 13)) >> 14);
+ out[4] = ((t2 - t3) * 11585 + (1 << 13)) >> 14;
+ out[2] = ((t6 + t7) * 11585 + (1 << 13)) >> 14;
+ out[5] = -(((t6 - t7) * 11585 + (1 << 13)) >> 14);
+}
+
+itxfm_wrap(8, 5)
+
+static av_always_inline void idct16_1d(const int16_t *in, ptrdiff_t stride,
+ int16_t *out, int pass)
+{
+ int t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15;
+ int t0a, t1a, t2a, t3a, t4a, t5a, t6a, t7a;
+ int t8a, t9a, t10a, t11a, t12a, t13a, t14a, t15a;
+
+ t0a = ((IN(0) + IN(8)) * 11585 + (1 << 13)) >> 14;
+ t1a = ((IN(0) - IN(8)) * 11585 + (1 << 13)) >> 14;
+ t2a = (IN(4) * 6270 - IN(12) * 15137 + (1 << 13)) >> 14;
+ t3a = (IN(4) * 15137 + IN(12) * 6270 + (1 << 13)) >> 14;
+ t4a = (IN(2) * 3196 - IN(14) * 16069 + (1 << 13)) >> 14;
+ t7a = (IN(2) * 16069 + IN(14) * 3196 + (1 << 13)) >> 14;
+ t5a = (IN(10) * 13623 - IN(6) * 9102 + (1 << 13)) >> 14;
+ t6a = (IN(10) * 9102 + IN(6) * 13623 + (1 << 13)) >> 14;
+ t8a = (IN(1) * 1606 - IN(15) * 16305 + (1 << 13)) >> 14;
+ t15a = (IN(1) * 16305 + IN(15) * 1606 + (1 << 13)) >> 14;
+ t9a = (IN(9) * 12665 - IN(7) * 10394 + (1 << 13)) >> 14;
+ t14a = (IN(9) * 10394 + IN(7) * 12665 + (1 << 13)) >> 14;
+ t10a = (IN(5) * 7723 - IN(11) * 14449 + (1 << 13)) >> 14;
+ t13a = (IN(5) * 14449 + IN(11) * 7723 + (1 << 13)) >> 14;
+ t11a = (IN(13) * 15679 - IN(3) * 4756 + (1 << 13)) >> 14;
+ t12a = (IN(13) * 4756 + IN(3) * 15679 + (1 << 13)) >> 14;
+
+ t0 = t0a + t3a;
+ t1 = t1a + t2a;
+ t2 = t1a - t2a;
+ t3 = t0a - t3a;
+ t4 = t4a + t5a;
+ t5 = t4a - t5a;
+ t6 = t7a - t6a;
+ t7 = t7a + t6a;
+ t8 = t8a + t9a;
+ t9 = t8a - t9a;
+ t10 = t11a - t10a;
+ t11 = t11a + t10a;
+ t12 = t12a + t13a;
+ t13 = t12a - t13a;
+ t14 = t15a - t14a;
+ t15 = t15a + t14a;
+
+ t5a = ((t6 - t5) * 11585 + (1 << 13)) >> 14;
+ t6a = ((t6 + t5) * 11585 + (1 << 13)) >> 14;
+ t9a = ( t14 * 6270 - t9 * 15137 + (1 << 13)) >> 14;
+ t14a = ( t14 * 15137 + t9 * 6270 + (1 << 13)) >> 14;
+ t10a = (-(t13 * 15137 + t10 * 6270) + (1 << 13)) >> 14;
+ t13a = ( t13 * 6270 - t10 * 15137 + (1 << 13)) >> 14;
+
+ t0a = t0 + t7;
+ t1a = t1 + t6a;
+ t2a = t2 + t5a;
+ t3a = t3 + t4;
+ t4 = t3 - t4;
+ t5 = t2 - t5a;
+ t6 = t1 - t6a;
+ t7 = t0 - t7;
+ t8a = t8 + t11;
+ t9 = t9a + t10a;
+ t10 = t9a - t10a;
+ t11a = t8 - t11;
+ t12a = t15 - t12;
+ t13 = t14a - t13a;
+ t14 = t14a + t13a;
+ t15a = t15 + t12;
+
+ t10a = ((t13 - t10) * 11585 + (1 << 13)) >> 14;
+ t13a = ((t13 + t10) * 11585 + (1 << 13)) >> 14;
+ t11 = ((t12a - t11a) * 11585 + (1 << 13)) >> 14;
+ t12 = ((t12a + t11a) * 11585 + (1 << 13)) >> 14;
+
+ out[ 0] = t0a + t15a;
+ out[ 1] = t1a + t14;
+ out[ 2] = t2a + t13a;
+ out[ 3] = t3a + t12;
+ out[ 4] = t4 + t11;
+ out[ 5] = t5 + t10a;
+ out[ 6] = t6 + t9;
+ out[ 7] = t7 + t8a;
+ out[ 8] = t7 - t8a;
+ out[ 9] = t6 - t9;
+ out[10] = t5 - t10a;
+ out[11] = t4 - t11;
+ out[12] = t3a - t12;
+ out[13] = t2a - t13a;
+ out[14] = t1a - t14;
+ out[15] = t0a - t15a;
+}
+
+static av_always_inline void iadst16_1d(const int16_t *in, ptrdiff_t stride,
+ int16_t *out, int pass)
+{
+ int t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15;
+ int t0a, t1a, t2a, t3a, t4a, t5a, t6a, t7a;
+ int t8a, t9a, t10a, t11a, t12a, t13a, t14a, t15a;
+
+ t0 = IN(15) * 16364 + IN(0) * 804;
+ t1 = IN(15) * 804 - IN(0) * 16364;
+ t2 = IN(13) * 15893 + IN(2) * 3981;
+ t3 = IN(13) * 3981 - IN(2) * 15893;
+ t4 = IN(11) * 14811 + IN(4) * 7005;
+ t5 = IN(11) * 7005 - IN(4) * 14811;
+ t6 = IN(9) * 13160 + IN(6) * 9760;
+ t7 = IN(9) * 9760 - IN(6) * 13160;
+ t8 = IN(7) * 11003 + IN(8) * 12140;
+ t9 = IN(7) * 12140 - IN(8) * 11003;
+ t10 = IN(5) * 8423 + IN(10) * 14053;
+ t11 = IN(5) * 14053 - IN(10) * 8423;
+ t12 = IN(3) * 5520 + IN(12) * 15426;
+ t13 = IN(3) * 15426 - IN(12) * 5520;
+ t14 = IN(1) * 2404 + IN(14) * 16207;
+ t15 = IN(1) * 16207 - IN(14) * 2404;
+
+ t0a = (t0 + t8 + (1 << 13)) >> 14;
+ t1a = (t1 + t9 + (1 << 13)) >> 14;
+ t2a = (t2 + t10 + (1 << 13)) >> 14;
+ t3a = (t3 + t11 + (1 << 13)) >> 14;
+ t4a = (t4 + t12 + (1 << 13)) >> 14;
+ t5a = (t5 + t13 + (1 << 13)) >> 14;
+ t6a = (t6 + t14 + (1 << 13)) >> 14;
+ t7a = (t7 + t15 + (1 << 13)) >> 14;
+ t8a = (t0 - t8 + (1 << 13)) >> 14;
+ t9a = (t1 - t9 + (1 << 13)) >> 14;
+ t10a = (t2 - t10 + (1 << 13)) >> 14;
+ t11a = (t3 - t11 + (1 << 13)) >> 14;
+ t12a = (t4 - t12 + (1 << 13)) >> 14;
+ t13a = (t5 - t13 + (1 << 13)) >> 14;
+ t14a = (t6 - t14 + (1 << 13)) >> 14;
+ t15a = (t7 - t15 + (1 << 13)) >> 14;
+
+ t8 = t8a * 16069 + t9a * 3196;
+ t9 = t8a * 3196 - t9a * 16069;
+ t10 = t10a * 9102 + t11a * 13623;
+ t11 = t10a * 13623 - t11a * 9102;
+ t12 = t13a * 16069 - t12a * 3196;
+ t13 = t13a * 3196 + t12a * 16069;
+ t14 = t15a * 9102 - t14a * 13623;
+ t15 = t15a * 13623 + t14a * 9102;
+
+ t0 = t0a + t4a;
+ t1 = t1a + t5a;
+ t2 = t2a + t6a;
+ t3 = t3a + t7a;
+ t4 = t0a - t4a;
+ t5 = t1a - t5a;
+ t6 = t2a - t6a;
+ t7 = t3a - t7a;
+ t8a = (t8 + t12 + (1 << 13)) >> 14;
+ t9a = (t9 + t13 + (1 << 13)) >> 14;
+ t10a = (t10 + t14 + (1 << 13)) >> 14;
+ t11a = (t11 + t15 + (1 << 13)) >> 14;
+ t12a = (t8 - t12 + (1 << 13)) >> 14;
+ t13a = (t9 - t13 + (1 << 13)) >> 14;
+ t14a = (t10 - t14 + (1 << 13)) >> 14;
+ t15a = (t11 - t15 + (1 << 13)) >> 14;
+
+ t4a = t4 * 15137 + t5 * 6270;
+ t5a = t4 * 6270 - t5 * 15137;
+ t6a = t7 * 15137 - t6 * 6270;
+ t7a = t7 * 6270 + t6 * 15137;
+ t12 = t12a * 15137 + t13a * 6270;
+ t13 = t12a * 6270 - t13a * 15137;
+ t14 = t15a * 15137 - t14a * 6270;
+ t15 = t15a * 6270 + t14a * 15137;
+
+ out[ 0] = t0 + t2;
+ out[15] = -(t1 + t3);
+ t2a = t0 - t2;
+ t3a = t1 - t3;
+ out[ 3] = -((t4a + t6a + (1 << 13)) >> 14);
+ out[12] = (t5a + t7a + (1 << 13)) >> 14;
+ t6 = (t4a - t6a + (1 << 13)) >> 14;
+ t7 = (t5a - t7a + (1 << 13)) >> 14;
+ out[ 1] = -(t8a + t10a);
+ out[14] = t9a + t11a;
+ t10 = t8a - t10a;
+ t11 = t9a - t11a;
+ out[ 2] = (t12 + t14 + (1 << 13)) >> 14;
+ out[13] = -((t13 + t15 + (1 << 13)) >> 14);
+ t14a = (t12 - t14 + (1 << 13)) >> 14;
+ t15a = (t13 - t15 + (1 << 13)) >> 14;
+
+ out[ 7] = ((t2a + t3a) * -11585 + (1 << 13)) >> 14;
+ out[ 8] = ((t2a - t3a) * 11585 + (1 << 13)) >> 14;
+ out[ 4] = ((t7 + t6) * 11585 + (1 << 13)) >> 14;
+ out[11] = ((t7 - t6) * 11585 + (1 << 13)) >> 14;
+ out[ 6] = ((t11 + t10) * 11585 + (1 << 13)) >> 14;
+ out[ 9] = ((t11 - t10) * 11585 + (1 << 13)) >> 14;
+ out[ 5] = ((t14a + t15a) * -11585 + (1 << 13)) >> 14;
+ out[10] = ((t14a - t15a) * 11585 + (1 << 13)) >> 14;
+}
+
+itxfm_wrap(16, 6)
+
+static av_always_inline void idct32_1d(const int16_t *in, ptrdiff_t stride,
+ int16_t *out, int pass)
+{
+ int t0a = ((IN(0) + IN(16)) * 11585 + (1 << 13)) >> 14;
+ int t1a = ((IN(0) - IN(16)) * 11585 + (1 << 13)) >> 14;
+ int t2a = (IN( 8) * 6270 - IN(24) * 15137 + (1 << 13)) >> 14;
+ int t3a = (IN( 8) * 15137 + IN(24) * 6270 + (1 << 13)) >> 14;
+ int t4a = (IN( 4) * 3196 - IN(28) * 16069 + (1 << 13)) >> 14;
+ int t7a = (IN( 4) * 16069 + IN(28) * 3196 + (1 << 13)) >> 14;
+ int t5a = (IN(20) * 13623 - IN(12) * 9102 + (1 << 13)) >> 14;
+ int t6a = (IN(20) * 9102 + IN(12) * 13623 + (1 << 13)) >> 14;
+ int t8a = (IN( 2) * 1606 - IN(30) * 16305 + (1 << 13)) >> 14;
+ int t15a = (IN( 2) * 16305 + IN(30) * 1606 + (1 << 13)) >> 14;
+ int t9a = (IN(18) * 12665 - IN(14) * 10394 + (1 << 13)) >> 14;
+ int t14a = (IN(18) * 10394 + IN(14) * 12665 + (1 << 13)) >> 14;
+ int t10a = (IN(10) * 7723 - IN(22) * 14449 + (1 << 13)) >> 14;
+ int t13a = (IN(10) * 14449 + IN(22) * 7723 + (1 << 13)) >> 14;
+ int t11a = (IN(26) * 15679 - IN( 6) * 4756 + (1 << 13)) >> 14;
+ int t12a = (IN(26) * 4756 + IN( 6) * 15679 + (1 << 13)) >> 14;
+ int t16a = (IN( 1) * 804 - IN(31) * 16364 + (1 << 13)) >> 14;
+ int t31a = (IN( 1) * 16364 + IN(31) * 804 + (1 << 13)) >> 14;
+ int t17a = (IN(17) * 12140 - IN(15) * 11003 + (1 << 13)) >> 14;
+ int t30a = (IN(17) * 11003 + IN(15) * 12140 + (1 << 13)) >> 14;
+ int t18a = (IN( 9) * 7005 - IN(23) * 14811 + (1 << 13)) >> 14;
+ int t29a = (IN( 9) * 14811 + IN(23) * 7005 + (1 << 13)) >> 14;
+ int t19a = (IN(25) * 15426 - IN( 7) * 5520 + (1 << 13)) >> 14;
+ int t28a = (IN(25) * 5520 + IN( 7) * 15426 + (1 << 13)) >> 14;
+ int t20a = (IN( 5) * 3981 - IN(27) * 15893 + (1 << 13)) >> 14;
+ int t27a = (IN( 5) * 15893 + IN(27) * 3981 + (1 << 13)) >> 14;
+ int t21a = (IN(21) * 14053 - IN(11) * 8423 + (1 << 13)) >> 14;
+ int t26a = (IN(21) * 8423 + IN(11) * 14053 + (1 << 13)) >> 14;
+ int t22a = (IN(13) * 9760 - IN(19) * 13160 + (1 << 13)) >> 14;
+ int t25a = (IN(13) * 13160 + IN(19) * 9760 + (1 << 13)) >> 14;
+ int t23a = (IN(29) * 16207 - IN( 3) * 2404 + (1 << 13)) >> 14;
+ int t24a = (IN(29) * 2404 + IN( 3) * 16207 + (1 << 13)) >> 14;
+
+ int t0 = t0a + t3a;
+ int t1 = t1a + t2a;
+ int t2 = t1a - t2a;
+ int t3 = t0a - t3a;
+ int t4 = t4a + t5a;
+ int t5 = t4a - t5a;
+ int t6 = t7a - t6a;
+ int t7 = t7a + t6a;
+ int t8 = t8a + t9a;
+ int t9 = t8a - t9a;
+ int t10 = t11a - t10a;
+ int t11 = t11a + t10a;
+ int t12 = t12a + t13a;
+ int t13 = t12a - t13a;
+ int t14 = t15a - t14a;
+ int t15 = t15a + t14a;
+ int t16 = t16a + t17a;
+ int t17 = t16a - t17a;
+ int t18 = t19a - t18a;
+ int t19 = t19a + t18a;
+ int t20 = t20a + t21a;
+ int t21 = t20a - t21a;
+ int t22 = t23a - t22a;
+ int t23 = t23a + t22a;
+ int t24 = t24a + t25a;
+ int t25 = t24a - t25a;
+ int t26 = t27a - t26a;
+ int t27 = t27a + t26a;
+ int t28 = t28a + t29a;
+ int t29 = t28a - t29a;
+ int t30 = t31a - t30a;
+ int t31 = t31a + t30a;
+
+ t5a = ((t6 - t5) * 11585 + (1 << 13)) >> 14;
+ t6a = ((t6 + t5) * 11585 + (1 << 13)) >> 14;
+ t9a = ( t14 * 6270 - t9 * 15137 + (1 << 13)) >> 14;
+ t14a = ( t14 * 15137 + t9 * 6270 + (1 << 13)) >> 14;
+ t10a = (-(t13 * 15137 + t10 * 6270) + (1 << 13)) >> 14;
+ t13a = ( t13 * 6270 - t10 * 15137 + (1 << 13)) >> 14;
+ t17a = ( t30 * 3196 - t17 * 16069 + (1 << 13)) >> 14;
+ t30a = ( t30 * 16069 + t17 * 3196 + (1 << 13)) >> 14;
+ t18a = (-(t29 * 16069 + t18 * 3196) + (1 << 13)) >> 14;
+ t29a = ( t29 * 3196 - t18 * 16069 + (1 << 13)) >> 14;
+ t21a = ( t26 * 13623 - t21 * 9102 + (1 << 13)) >> 14;
+ t26a = ( t26 * 9102 + t21 * 13623 + (1 << 13)) >> 14;
+ t22a = (-(t25 * 9102 + t22 * 13623) + (1 << 13)) >> 14;
+ t25a = ( t25 * 13623 - t22 * 9102 + (1 << 13)) >> 14;
+
+ t0a = t0 + t7;
+ t1a = t1 + t6a;
+ t2a = t2 + t5a;
+ t3a = t3 + t4;
+ t4a = t3 - t4;
+ t5 = t2 - t5a;
+ t6 = t1 - t6a;
+ t7a = t0 - t7;
+ t8a = t8 + t11;
+ t9 = t9a + t10a;
+ t10 = t9a - t10a;
+ t11a = t8 - t11;
+ t12a = t15 - t12;
+ t13 = t14a - t13a;
+ t14 = t14a + t13a;
+ t15a = t15 + t12;
+ t16a = t16 + t19;
+ t17 = t17a + t18a;
+ t18 = t17a - t18a;
+ t19a = t16 - t19;
+ t20a = t23 - t20;
+ t21 = t22a - t21a;
+ t22 = t22a + t21a;
+ t23a = t23 + t20;
+ t24a = t24 + t27;
+ t25 = t25a + t26a;
+ t26 = t25a - t26a;
+ t27a = t24 - t27;
+ t28a = t31 - t28;
+ t29 = t30a - t29a;
+ t30 = t30a + t29a;
+ t31a = t31 + t28;
+
+ t10a = ((t13 - t10) * 11585 + (1 << 13)) >> 14;
+ t13a = ((t13 + t10) * 11585 + (1 << 13)) >> 14;
+ t11 = ((t12a - t11a) * 11585 + (1 << 13)) >> 14;
+ t12 = ((t12a + t11a) * 11585 + (1 << 13)) >> 14;
+ t18a = ( t29 * 6270 - t18 * 15137 + (1 << 13)) >> 14;
+ t29a = ( t29 * 15137 + t18 * 6270 + (1 << 13)) >> 14;
+ t19 = ( t28a * 6270 - t19a * 15137 + (1 << 13)) >> 14;
+ t28 = ( t28a * 15137 + t19a * 6270 + (1 << 13)) >> 14;
+ t20 = (-(t27a * 15137 + t20a * 6270) + (1 << 13)) >> 14;
+ t27 = ( t27a * 6270 - t20a * 15137 + (1 << 13)) >> 14;
+ t21a = (-(t26 * 15137 + t21 * 6270) + (1 << 13)) >> 14;
+ t26a = ( t26 * 6270 - t21 * 15137 + (1 << 13)) >> 14;
+
+ t0 = t0a + t15a;
+ t1 = t1a + t14;
+ t2 = t2a + t13a;
+ t3 = t3a + t12;
+ t4 = t4a + t11;
+ t5a = t5 + t10a;
+ t6a = t6 + t9;
+ t7 = t7a + t8a;
+ t8 = t7a - t8a;
+ t9a = t6 - t9;
+ t10 = t5 - t10a;
+ t11a = t4a - t11;
+ t12a = t3a - t12;
+ t13 = t2a - t13a;
+ t14a = t1a - t14;
+ t15 = t0a - t15a;
+ t16 = t16a + t23a;
+ t17a = t17 + t22;
+ t18 = t18a + t21a;
+ t19a = t19 + t20;
+ t20a = t19 - t20;
+ t21 = t18a - t21a;
+ t22a = t17 - t22;
+ t23 = t16a - t23a;
+ t24 = t31a - t24a;
+ t25a = t30 - t25;
+ t26 = t29a - t26a;
+ t27a = t28 - t27;
+ t28a = t28 + t27;
+ t29 = t29a + t26a;
+ t30a = t30 + t25;
+ t31 = t31a + t24a;
+
+ t20 = ((t27a - t20a) * 11585 + (1 << 13)) >> 14;
+ t27 = ((t27a + t20a) * 11585 + (1 << 13)) >> 14;
+ t21a = ((t26 - t21 ) * 11585 + (1 << 13)) >> 14;
+ t26a = ((t26 + t21 ) * 11585 + (1 << 13)) >> 14;
+ t22 = ((t25a - t22a) * 11585 + (1 << 13)) >> 14;
+ t25 = ((t25a + t22a) * 11585 + (1 << 13)) >> 14;
+ t23a = ((t24 - t23 ) * 11585 + (1 << 13)) >> 14;
+ t24a = ((t24 + t23 ) * 11585 + (1 << 13)) >> 14;
+
+ out[ 0] = t0 + t31;
+ out[ 1] = t1 + t30a;
+ out[ 2] = t2 + t29;
+ out[ 3] = t3 + t28a;
+ out[ 4] = t4 + t27;
+ out[ 5] = t5a + t26a;
+ out[ 6] = t6a + t25;
+ out[ 7] = t7 + t24a;
+ out[ 8] = t8 + t23a;
+ out[ 9] = t9a + t22;
+ out[10] = t10 + t21a;
+ out[11] = t11a + t20;
+ out[12] = t12a + t19a;
+ out[13] = t13 + t18;
+ out[14] = t14a + t17a;
+ out[15] = t15 + t16;
+ out[16] = t15 - t16;
+ out[17] = t14a - t17a;
+ out[18] = t13 - t18;
+ out[19] = t12a - t19a;
+ out[20] = t11a - t20;
+ out[21] = t10 - t21a;
+ out[22] = t9a - t22;
+ out[23] = t8 - t23a;
+ out[24] = t7 - t24a;
+ out[25] = t6a - t25;
+ out[26] = t5a - t26a;
+ out[27] = t4 - t27;
+ out[28] = t3 - t28a;
+ out[29] = t2 - t29;
+ out[30] = t1 - t30a;
+ out[31] = t0 - t31;
+}
+
+itxfm_wrapper(idct, idct, 32, 6)
+
+static av_always_inline void iwht4_1d(const int16_t *in, ptrdiff_t stride,
+ int16_t *out, int pass)
+{
+ int t0, t1, t2, t3, t4;
+
+ if (pass == 0) {
+ t0 = IN(0) >> 2;
+ t1 = IN(3) >> 2;
+ t2 = IN(1) >> 2;
+ t3 = IN(2) >> 2;
+ } else {
+ t0 = IN(0);
+ t1 = IN(3);
+ t2 = IN(1);
+ t3 = IN(2);
+ }
+
+ t0 += t2;
+ t3 -= t1;
+ t4 = (t0 - t3) >> 1;
+ t1 = t4 - t1;
+ t2 = t4 - t2;
+ t0 -= t1;
+ t3 += t2;
+
+ out[0] = t0;
+ out[1] = t1;
+ out[2] = t2;
+ out[3] = t3;
+}
+
+itxfm_wrapper(iwht, iwht, 4, 0)
+
+#undef IN
+#undef itxfm_wrapper
+#undef itxfm_wrap
+
+static av_cold void vp9dsp_itxfm_init(VP9DSPContext *dsp)
+{
+#define init_itxfm(tx, sz) \
+ dsp->itxfm_add[tx][DCT_DCT] = idct_idct_##sz##_add_c; \
+ dsp->itxfm_add[tx][DCT_ADST] = iadst_idct_##sz##_add_c; \
+ dsp->itxfm_add[tx][ADST_DCT] = idct_iadst_##sz##_add_c; \
+ dsp->itxfm_add[tx][ADST_ADST] = iadst_iadst_##sz##_add_c
+
+#define init_idct(tx, nm) \
+ dsp->itxfm_add[tx][DCT_DCT] = \
+ dsp->itxfm_add[tx][ADST_DCT] = \
+ dsp->itxfm_add[tx][DCT_ADST] = \
+ dsp->itxfm_add[tx][ADST_ADST] = nm##_add_c
+
+ init_itxfm(TX_4X4, 4x4);
+ init_itxfm(TX_8X8, 8x8);
+ init_itxfm(TX_16X16, 16x16);
+ init_idct(TX_32X32, idct_idct_32x32);
+ init_idct(4 /* lossless */, iwht_iwht_4x4);
+
+#undef init_itxfm
+#undef init_idct
+}
+
+static av_always_inline void loop_filter(uint8_t *dst, ptrdiff_t stride,
+ int E, int I, int H,
+ ptrdiff_t stridea, ptrdiff_t strideb,
+ int wd)
+{
+ int i;
+
+ for (i = 0; i < 8; i++, dst += stridea) {
+ int p7, p6, p5, p4;
+ int p3 = dst[strideb * -4], p2 = dst[strideb * -3];
+ int p1 = dst[strideb * -2], p0 = dst[strideb * -1];
+ int q0 = dst[strideb * +0], q1 = dst[strideb * +1];
+ int q2 = dst[strideb * +2], q3 = dst[strideb * +3];
+ int q4, q5, q6, q7;
+ int fm = FFABS(p3 - p2) <= I && FFABS(p2 - p1) <= I &&
+ FFABS(p1 - p0) <= I && FFABS(q1 - q0) <= I &&
+ FFABS(q2 - q1) <= I && FFABS(q3 - q2) <= I &&
+ FFABS(p0 - q0) * 2 + (FFABS(p1 - q1) >> 1) <= E;
+ int flat8out, flat8in;
+
+ if (!fm)
+ continue;
+
+ if (wd >= 16) {
+ p7 = dst[strideb * -8];
+ p6 = dst[strideb * -7];
+ p5 = dst[strideb * -6];
+ p4 = dst[strideb * -5];
+ q4 = dst[strideb * +4];
+ q5 = dst[strideb * +5];
+ q6 = dst[strideb * +6];
+ q7 = dst[strideb * +7];
+
+ flat8out = FFABS(p7 - p0) <= 1 && FFABS(p6 - p0) <= 1 &&
+ FFABS(p5 - p0) <= 1 && FFABS(p4 - p0) <= 1 &&
+ FFABS(q4 - q0) <= 1 && FFABS(q5 - q0) <= 1 &&
+ FFABS(q6 - q0) <= 1 && FFABS(q7 - q0) <= 1;
+ }
+
+ if (wd >= 8)
+ flat8in = FFABS(p3 - p0) <= 1 && FFABS(p2 - p0) <= 1 &&
+ FFABS(p1 - p0) <= 1 && FFABS(q1 - q0) <= 1 &&
+ FFABS(q2 - q0) <= 1 && FFABS(q3 - q0) <= 1;
+
+ if (wd >= 16 && flat8out && flat8in) {
+ dst[strideb * -7] = (p7 + p7 + p7 + p7 + p7 + p7 + p7 + p6 * 2 +
+ p5 + p4 + p3 + p2 + p1 + p0 + q0 + 8) >> 4;
+ dst[strideb * -6] = (p7 + p7 + p7 + p7 + p7 + p7 + p6 + p5 * 2 +
+ p4 + p3 + p2 + p1 + p0 + q0 + q1 + 8) >> 4;
+ dst[strideb * -5] = (p7 + p7 + p7 + p7 + p7 + p6 + p5 + p4 * 2 +
+ p3 + p2 + p1 + p0 + q0 + q1 + q2 + 8) >> 4;
+ dst[strideb * -4] = (p7 + p7 + p7 + p7 + p6 + p5 + p4 + p3 * 2 +
+ p2 + p1 + p0 + q0 + q1 + q2 + q3 + 8) >> 4;
+ dst[strideb * -3] = (p7 + p7 + p7 + p6 + p5 + p4 + p3 + p2 * 2 +
+ p1 + p0 + q0 + q1 + q2 + q3 + q4 + 8) >> 4;
+ dst[strideb * -2] = (p7 + p7 + p6 + p5 + p4 + p3 + p2 + p1 * 2 +
+ p0 + q0 + q1 + q2 + q3 + q4 + q5 + 8) >> 4;
+ dst[strideb * -1] = (p7 + p6 + p5 + p4 + p3 + p2 + p1 + p0 * 2 +
+ q0 + q1 + q2 + q3 + q4 + q5 + q6 + 8) >> 4;
+ dst[strideb * +0] = (p6 + p5 + p4 + p3 + p2 + p1 + p0 + q0 * 2 +
+ q1 + q2 + q3 + q4 + q5 + q6 + q7 + 8) >> 4;
+ dst[strideb * +1] = (p5 + p4 + p3 + p2 + p1 + p0 + q0 + q1 * 2 +
+ q2 + q3 + q4 + q5 + q6 + q7 + q7 + 8) >> 4;
+ dst[strideb * +2] = (p4 + p3 + p2 + p1 + p0 + q0 + q1 + q2 * 2 +
+ q3 + q4 + q5 + q6 + q7 + q7 + q7 + 8) >> 4;
+ dst[strideb * +3] = (p3 + p2 + p1 + p0 + q0 + q1 + q2 + q3 * 2 +
+ q4 + q5 + q6 + q7 + q7 + q7 + q7 + 8) >> 4;
+ dst[strideb * +4] = (p2 + p1 + p0 + q0 + q1 + q2 + q3 + q4 * 2 +
+ q5 + q6 + q7 + q7 + q7 + q7 + q7 + 8) >> 4;
+ dst[strideb * +5] = (p1 + p0 + q0 + q1 + q2 + q3 + q4 + q5 * 2 +
+ q6 + q7 + q7 + q7 + q7 + q7 + q7 + 8) >> 4;
+ dst[strideb * +6] = (p0 + q0 + q1 + q2 + q3 + q4 + q5 + q6 * 2 +
+ q7 + q7 + q7 + q7 + q7 + q7 + q7 + 8) >> 4;
+ } else if (wd >= 8 && flat8in) {
+ dst[strideb * -3] = (p3 + p3 + p3 + 2 * p2 + p1 + p0 + q0 + 4) >> 3;
+ dst[strideb * -2] = (p3 + p3 + p2 + 2 * p1 + p0 + q0 + q1 + 4) >> 3;
+ dst[strideb * -1] = (p3 + p2 + p1 + 2 * p0 + q0 + q1 + q2 + 4) >> 3;
+ dst[strideb * +0] = (p2 + p1 + p0 + 2 * q0 + q1 + q2 + q3 + 4) >> 3;
+ dst[strideb * +1] = (p1 + p0 + q0 + 2 * q1 + q2 + q3 + q3 + 4) >> 3;
+ dst[strideb * +2] = (p0 + q0 + q1 + 2 * q2 + q3 + q3 + q3 + 4) >> 3;
+ } else {
+ int hev = FFABS(p1 - p0) > H || FFABS(q1 - q0) > H;
+
+ if (hev) {
+ int f = av_clip_int8(3 * (q0 - p0) + av_clip_int8(p1 - q1)), f1, f2;
+
+ f1 = FFMIN(f + 4, 127) >> 3;
+ f2 = FFMIN(f + 3, 127) >> 3;
+
+ dst[strideb * -1] = av_clip_uint8(p0 + f2);
+ dst[strideb * +0] = av_clip_uint8(q0 - f1);
+ } else {
+ int f = av_clip_int8(3 * (q0 - p0)), f1, f2;
+
+ f1 = FFMIN(f + 4, 127) >> 3;
+ f2 = FFMIN(f + 3, 127) >> 3;
+
+ dst[strideb * -1] = av_clip_uint8(p0 + f2);
+ dst[strideb * +0] = av_clip_uint8(q0 - f1);
+
+ f = (f1 + 1) >> 1;
+ dst[strideb * -2] = av_clip_uint8(p1 + f);
+ dst[strideb * +1] = av_clip_uint8(q1 - f);
+ }
+ }
+ }
+}
+
+#define lf_8_fn(dir, wd, stridea, strideb) \
+static void loop_filter_##dir##_##wd##_8_c(uint8_t *dst, \
+ ptrdiff_t stride, \
+ int E, int I, int H) \
+{ \
+ loop_filter(dst, stride, E, I, H, stridea, strideb, wd); \
+}
+
+#define lf_8_fns(wd) \
+lf_8_fn(h, wd, stride, 1) \
+lf_8_fn(v, wd, 1, stride)
+
+lf_8_fns(4)
+lf_8_fns(8)
+lf_8_fns(16)
+
+#undef lf_8_fn
+#undef lf_8_fns
+
+#define lf_16_fn(dir, stridea) \
+static void loop_filter_##dir##_16_16_c(uint8_t *dst, \
+ ptrdiff_t stride, \
+ int E, int I, int H) \
+{ \
+ loop_filter_##dir##_16_8_c(dst, stride, E, I, H); \
+ loop_filter_##dir##_16_8_c(dst + 8 * stridea, stride, E, I, H); \
+}
+
+lf_16_fn(h, stride)
+lf_16_fn(v, 1)
+
+#undef lf_16_fn
+
+#define lf_mix_fn(dir, wd1, wd2, stridea) \
+static void loop_filter_##dir##_##wd1##wd2##_16_c(uint8_t *dst, \
+ ptrdiff_t stride, \
+ int E, int I, int H) \
+{ \
+ loop_filter_##dir##_##wd1##_8_c(dst, stride, E & 0xff, I & 0xff, H & 0xff); \
+ loop_filter_##dir##_##wd2##_8_c(dst + 8 * stridea, stride, E >> 8, I >> 8, H >> 8); \
+}
+
+#define lf_mix_fns(wd1, wd2) \
+lf_mix_fn(h, wd1, wd2, stride) \
+lf_mix_fn(v, wd1, wd2, 1)
+
+lf_mix_fns(4, 4)
+lf_mix_fns(4, 8)
+lf_mix_fns(8, 4)
+lf_mix_fns(8, 8)
+
+#undef lf_mix_fn
+#undef lf_mix_fns
+
+static av_cold void vp9dsp_loopfilter_init(VP9DSPContext *dsp)
+{
+ dsp->loop_filter_8[0][0] = loop_filter_h_4_8_c;
+ dsp->loop_filter_8[0][1] = loop_filter_v_4_8_c;
+ dsp->loop_filter_8[1][0] = loop_filter_h_8_8_c;
+ dsp->loop_filter_8[1][1] = loop_filter_v_8_8_c;
+ dsp->loop_filter_8[2][0] = loop_filter_h_16_8_c;
+ dsp->loop_filter_8[2][1] = loop_filter_v_16_8_c;
+
+ dsp->loop_filter_16[0] = loop_filter_h_16_16_c;
+ dsp->loop_filter_16[1] = loop_filter_v_16_16_c;
+
+ dsp->loop_filter_mix2[0][0][0] = loop_filter_h_44_16_c;
+ dsp->loop_filter_mix2[0][0][1] = loop_filter_v_44_16_c;
+ dsp->loop_filter_mix2[0][1][0] = loop_filter_h_48_16_c;
+ dsp->loop_filter_mix2[0][1][1] = loop_filter_v_48_16_c;
+ dsp->loop_filter_mix2[1][0][0] = loop_filter_h_84_16_c;
+ dsp->loop_filter_mix2[1][0][1] = loop_filter_v_84_16_c;
+ dsp->loop_filter_mix2[1][1][0] = loop_filter_h_88_16_c;
+ dsp->loop_filter_mix2[1][1][1] = loop_filter_v_88_16_c;
+}
+
+static av_always_inline void copy_c(uint8_t *dst, ptrdiff_t dst_stride,
+ const uint8_t *src, ptrdiff_t src_stride,
+ int w, int h)
+{
+ do {
+ memcpy(dst, src, w);
+
+ dst += dst_stride;
+ src += src_stride;
+ } while (--h);
+}
+
+static av_always_inline void avg_c(uint8_t *dst, ptrdiff_t dst_stride,
+ const uint8_t *src, ptrdiff_t src_stride,
+ int w, int h)
+{
+ do {
+ int x;
+
+ for (x = 0; x < w; x += 4)
+ AV_WN32A(&dst[x], rnd_avg32(AV_RN32A(&dst[x]), AV_RN32(&src[x])));
+
+ dst += dst_stride;
+ src += src_stride;
+ } while (--h);
+}
+
+#define fpel_fn(type, sz) \
+static void type##sz##_c(uint8_t *dst, ptrdiff_t dst_stride, \
+ const uint8_t *src, ptrdiff_t src_stride, \
+ int h, int mx, int my) \
+{ \
+ type##_c(dst, dst_stride, src, src_stride, sz, h); \
+}
+
+#define copy_avg_fn(sz) \
+fpel_fn(copy, sz) \
+fpel_fn(avg, sz)
+
+copy_avg_fn(64)
+copy_avg_fn(32)
+copy_avg_fn(16)
+copy_avg_fn(8)
+copy_avg_fn(4)
+
+#undef fpel_fn
+#undef copy_avg_fn
+
+static const int8_t vp9_subpel_filters[3][15][8] = {
+ [FILTER_8TAP_REGULAR] = {
+ { 0, 1, -5, 126, 8, -3, 1, 0 },
+ { -1, 3, -10, 122, 18, -6, 2, 0 },
+ { -1, 4, -13, 118, 27, -9, 3, -1 },
+ { -1, 4, -16, 112, 37, -11, 4, -1 },
+ { -1, 5, -18, 105, 48, -14, 4, -1 },
+ { -1, 5, -19, 97, 58, -16, 5, -1 },
+ { -1, 6, -19, 88, 68, -18, 5, -1 },
+ { -1, 6, -19, 78, 78, -19, 6, -1 },
+ { -1, 5, -18, 68, 88, -19, 6, -1 },
+ { -1, 5, -16, 58, 97, -19, 5, -1 },
+ { -1, 4, -14, 48, 105, -18, 5, -1 },
+ { -1, 4, -11, 37, 112, -16, 4, -1 },
+ { -1, 3, -9, 27, 118, -13, 4, -1 },
+ { 0, 2, -6, 18, 122, -10, 3, -1 },
+ { 0, 1, -3, 8, 126, -5, 1, 0 },
+ }, [FILTER_8TAP_SHARP] = {
+ { -1, 3, -7, 127, 8, -3, 1, 0 },
+ { -2, 5, -13, 125, 17, -6, 3, -1 },
+ { -3, 7, -17, 121, 27, -10, 5, -2 },
+ { -4, 9, -20, 115, 37, -13, 6, -2 },
+ { -4, 10, -23, 108, 48, -16, 8, -3 },
+ { -4, 10, -24, 100, 59, -19, 9, -3 },
+ { -4, 11, -24, 90, 70, -21, 10, -4 },
+ { -4, 11, -23, 80, 80, -23, 11, -4 },
+ { -4, 10, -21, 70, 90, -24, 11, -4 },
+ { -3, 9, -19, 59, 100, -24, 10, -4 },
+ { -3, 8, -16, 48, 108, -23, 10, -4 },
+ { -2, 6, -13, 37, 115, -20, 9, -4 },
+ { -2, 5, -10, 27, 121, -17, 7, -3 },
+ { -1, 3, -6, 17, 125, -13, 5, -2 },
+ { 0, 1, -3, 8, 127, -7, 3, -1 },
+ }, [FILTER_8TAP_SMOOTH] = {
+ { -3, -1, 32, 64, 38, 1, -3, 0 },
+ { -2, -2, 29, 63, 41, 2, -3, 0 },
+ { -2, -2, 26, 63, 43, 4, -4, 0 },
+ { -2, -3, 24, 62, 46, 5, -4, 0 },
+ { -2, -3, 21, 60, 49, 7, -4, 0 },
+ { -1, -4, 18, 59, 51, 9, -4, 0 },
+ { -1, -4, 16, 57, 53, 12, -4, -1 },
+ { -1, -4, 14, 55, 55, 14, -4, -1 },
+ { -1, -4, 12, 53, 57, 16, -4, -1 },
+ { 0, -4, 9, 51, 59, 18, -4, -1 },
+ { 0, -4, 7, 49, 60, 21, -3, -2 },
+ { 0, -4, 5, 46, 62, 24, -3, -2 },
+ { 0, -4, 4, 43, 63, 26, -2, -2 },
+ { 0, -3, 2, 41, 63, 29, -2, -2 },
+ { 0, -3, 1, 38, 64, 32, -1, -3 },
+ }
+};
+
+#define FILTER_8TAP(src, x, F, stride) \
+ av_clip_uint8((F[0] * src[x + -3 * stride] + \
+ F[1] * src[x + -2 * stride] + \
+ F[2] * src[x + -1 * stride] + \
+ F[3] * src[x + +0 * stride] + \
+ F[4] * src[x + +1 * stride] + \
+ F[5] * src[x + +2 * stride] + \
+ F[6] * src[x + +3 * stride] + \
+ F[7] * src[x + +4 * stride] + 64) >> 7)
+
+static av_always_inline void do_8tap_1d_c(uint8_t *dst, ptrdiff_t dst_stride,
+ const uint8_t *src, ptrdiff_t src_stride,
+ int w, int h, ptrdiff_t ds,
+ const int8_t *filter, int avg)
+{
+ do {
+ int x;
+
+ for (x = 0; x < w; x++)
+ if (avg) {
+ dst[x] = (dst[x] + FILTER_8TAP(src, x, filter, ds) + 1) >> 1;
+ } else {
+ dst[x] = FILTER_8TAP(src, x, filter, ds);
+ }
+
+ dst += dst_stride;
+ src += src_stride;
+ } while (--h);
+}
+
+#define filter_8tap_1d_fn(opn, opa, dir, ds) \
+static av_noinline void opn##_8tap_1d_##dir##_c(uint8_t *dst, ptrdiff_t dst_stride, \
+ const uint8_t *src, ptrdiff_t src_stride, \
+ int w, int h, const int8_t *filter) \
+{ \
+ do_8tap_1d_c(dst, dst_stride, src, src_stride, w, h, ds, filter, opa); \
+}
+
+filter_8tap_1d_fn(put, 0, v, src_stride)
+filter_8tap_1d_fn(put, 0, h, 1)
+filter_8tap_1d_fn(avg, 1, v, src_stride)
+filter_8tap_1d_fn(avg, 1, h, 1)
+
+#undef filter_8tap_1d_fn
+
+static av_always_inline void do_8tap_2d_c(uint8_t *dst, ptrdiff_t dst_stride,
+ const uint8_t *src, ptrdiff_t src_stride,
+ int w, int h, const int8_t *filterx,
+ const int8_t *filtery, int avg)
+{
+ int tmp_h = h + 7;
+ uint8_t tmp[64 * 71], *tmp_ptr = tmp;
+
+ src -= src_stride * 3;
+ do {
+ int x;
+
+ for (x = 0; x < w; x++)
+ tmp_ptr[x] = FILTER_8TAP(src, x, filterx, 1);
+
+ tmp_ptr += 64;
+ src += src_stride;
+ } while (--tmp_h);
+
+ tmp_ptr = tmp + 64 * 3;
+ do {
+ int x;
+
+ for (x = 0; x < w; x++)
+ if (avg) {
+ dst[x] = (dst[x] + FILTER_8TAP(tmp_ptr, x, filtery, 64) + 1) >> 1;
+ } else {
+ dst[x] = FILTER_8TAP(tmp_ptr, x, filtery, 64);
+ }
+
+ tmp_ptr += 64;
+ dst += dst_stride;
+ } while (--h);
+}
+
+#define filter_8tap_2d_fn(opn, opa) \
+static av_noinline void opn##_8tap_2d_hv_c(uint8_t *dst, ptrdiff_t dst_stride, \
+ const uint8_t *src, ptrdiff_t src_stride, \
+ int w, int h, const int8_t *filterx, \
+ const int8_t *filtery) \
+{ \
+ do_8tap_2d_c(dst, dst_stride, src, src_stride, w, h, filterx, filtery, opa); \
+}
+
+filter_8tap_2d_fn(put, 0)
+filter_8tap_2d_fn(avg, 1)
+
+#undef filter_8tap_2d_fn
+
+#undef FILTER_8TAP
+
+#define filter_fn_1d(sz, dir, dir_m, type, type_idx, avg) \
+static void avg##_8tap_##type##_##sz##dir##_c(uint8_t *dst, ptrdiff_t dst_stride, \
+ const uint8_t *src, ptrdiff_t src_stride, \
+ int h, int mx, int my) \
+{ \
+ avg##_8tap_1d_##dir##_c(dst, dst_stride, src, src_stride, sz, h, \
+ vp9_subpel_filters[type_idx][dir_m - 1]); \
+}
+
+#define filter_fn_2d(sz, type, type_idx, avg) \
+static void avg##_8tap_##type##_##sz##hv_c(uint8_t *dst, ptrdiff_t dst_stride, \
+ const uint8_t *src, ptrdiff_t src_stride, \
+ int h, int mx, int my) \
+{ \
+ avg##_8tap_2d_hv_c(dst, dst_stride, src, src_stride, sz, h, \
+ vp9_subpel_filters[type_idx][mx - 1], \
+ vp9_subpel_filters[type_idx][my - 1]); \
+}
+
+#define FILTER_BILIN(src, x, mxy, stride) \
+ (src[x] + ((mxy * (src[x + stride] - src[x]) + 8) >> 4))
+
+static av_always_inline void do_bilin_1d_c(uint8_t *dst, ptrdiff_t dst_stride,
+ const uint8_t *src, ptrdiff_t src_stride,
+ int w, int h, ptrdiff_t ds, int mxy, int avg)
+{
+ do {
+ int x;
+
+ for (x = 0; x < w; x++)
+ if (avg) {
+ dst[x] = (dst[x] + FILTER_BILIN(src, x, mxy, ds) + 1) >> 1;
+ } else {
+ dst[x] = FILTER_BILIN(src, x, mxy, ds);
+ }
+
+ dst += dst_stride;
+ src += src_stride;
+ } while (--h);
+}
+
+#define bilin_1d_fn(opn, opa, dir, ds) \
+static av_noinline void opn##_bilin_1d_##dir##_c(uint8_t *dst, ptrdiff_t dst_stride, \
+ const uint8_t *src, ptrdiff_t src_stride, \
+ int w, int h, int mxy) \
+{ \
+ do_bilin_1d_c(dst, dst_stride, src, src_stride, w, h, ds, mxy, opa); \
+}
+
+bilin_1d_fn(put, 0, v, src_stride)
+bilin_1d_fn(put, 0, h, 1)
+bilin_1d_fn(avg, 1, v, src_stride)
+bilin_1d_fn(avg, 1, h, 1)
+
+#undef bilin_1d_fn
+
+static av_always_inline void do_bilin_2d_c(uint8_t *dst, ptrdiff_t dst_stride,
+ const uint8_t *src, ptrdiff_t src_stride,
+ int w, int h, int mx, int my, int avg)
+{
+ uint8_t tmp[64 * 65], *tmp_ptr = tmp;
+ int tmp_h = h + 1;
+
+ do {
+ int x;
+
+ for (x = 0; x < w; x++)
+ tmp_ptr[x] = FILTER_BILIN(src, x, mx, 1);
+
+ tmp_ptr += 64;
+ src += src_stride;
+ } while (--tmp_h);
+
+ tmp_ptr = tmp;
+ do {
+ int x;
+
+ for (x = 0; x < w; x++)
+ if (avg) {
+ dst[x] = (dst[x] + FILTER_BILIN(tmp_ptr, x, my, 64) + 1) >> 1;
+ } else {
+ dst[x] = FILTER_BILIN(tmp_ptr, x, my, 64);
+ }
+
+ tmp_ptr += 64;
+ dst += dst_stride;
+ } while (--h);
+}
+
+#define bilin_2d_fn(opn, opa) \
+static av_noinline void opn##_bilin_2d_hv_c(uint8_t *dst, ptrdiff_t dst_stride, \
+ const uint8_t *src, ptrdiff_t src_stride, \
+ int w, int h, int mx, int my) \
+{ \
+ do_bilin_2d_c(dst, dst_stride, src, src_stride, w, h, mx, my, opa); \
+}
+
+bilin_2d_fn(put, 0)
+bilin_2d_fn(avg, 1)
+
+#undef bilin_2d_fn
+
+#undef FILTER_BILIN
+
+#define bilinf_fn_1d(sz, dir, dir_m, avg) \
+static void avg##_bilin_##sz##dir##_c(uint8_t *dst, ptrdiff_t dst_stride, \
+ const uint8_t *src, ptrdiff_t src_stride, \
+ int h, int mx, int my) \
+{ \
+ avg##_bilin_1d_##dir##_c(dst, dst_stride, src, src_stride, sz, h, dir_m); \
+}
+
+#define bilinf_fn_2d(sz, avg) \
+static void avg##_bilin_##sz##hv_c(uint8_t *dst, ptrdiff_t dst_stride, \
+ const uint8_t *src, ptrdiff_t src_stride, \
+ int h, int mx, int my) \
+{ \
+ avg##_bilin_2d_hv_c(dst, dst_stride, src, src_stride, sz, h, mx, my); \
+}
+
+#define filter_fn(sz, avg) \
+filter_fn_1d(sz, h, mx, regular, FILTER_8TAP_REGULAR, avg) \
+filter_fn_1d(sz, v, my, regular, FILTER_8TAP_REGULAR, avg) \
+filter_fn_2d(sz, regular, FILTER_8TAP_REGULAR, avg) \
+filter_fn_1d(sz, h, mx, smooth, FILTER_8TAP_SMOOTH, avg) \
+filter_fn_1d(sz, v, my, smooth, FILTER_8TAP_SMOOTH, avg) \
+filter_fn_2d(sz, smooth, FILTER_8TAP_SMOOTH, avg) \
+filter_fn_1d(sz, h, mx, sharp, FILTER_8TAP_SHARP, avg) \
+filter_fn_1d(sz, v, my, sharp, FILTER_8TAP_SHARP, avg) \
+filter_fn_2d(sz, sharp, FILTER_8TAP_SHARP, avg) \
+bilinf_fn_1d(sz, h, mx, avg) \
+bilinf_fn_1d(sz, v, my, avg) \
+bilinf_fn_2d(sz, avg)
+
+#define filter_fn_set(avg) \
+filter_fn(64, avg) \
+filter_fn(32, avg) \
+filter_fn(16, avg) \
+filter_fn(8, avg) \
+filter_fn(4, avg)
+
+filter_fn_set(put)
+filter_fn_set(avg)
+
+#undef filter_fn
+#undef filter_fn_set
+#undef filter_fn_1d
+#undef filter_fn_2d
+#undef bilinf_fn_1d
+#undef bilinf_fn_2d
+
+static av_cold void vp9dsp_mc_init(VP9DSPContext *dsp)
+{
+#define init_fpel(idx1, idx2, sz, type) \
+ dsp->mc[idx1][FILTER_8TAP_SMOOTH ][idx2][0][0] = type##sz##_c; \
+ dsp->mc[idx1][FILTER_8TAP_REGULAR][idx2][0][0] = type##sz##_c; \
+ dsp->mc[idx1][FILTER_8TAP_SHARP ][idx2][0][0] = type##sz##_c; \
+ dsp->mc[idx1][FILTER_BILINEAR ][idx2][0][0] = type##sz##_c
+
+#define init_copy_avg(idx, sz) \
+ init_fpel(idx, 0, sz, copy); \
+ init_fpel(idx, 1, sz, avg)
+
+ init_copy_avg(0, 64);
+ init_copy_avg(1, 32);
+ init_copy_avg(2, 16);
+ init_copy_avg(3, 8);
+ init_copy_avg(4, 4);
+
+#undef init_copy_avg
+#undef init_fpel
+
+#define init_subpel1(idx1, idx2, idxh, idxv, sz, dir, type) \
+ dsp->mc[idx1][FILTER_8TAP_SMOOTH ][idx2][idxh][idxv] = type##_8tap_smooth_##sz##dir##_c; \
+ dsp->mc[idx1][FILTER_8TAP_REGULAR][idx2][idxh][idxv] = type##_8tap_regular_##sz##dir##_c; \
+ dsp->mc[idx1][FILTER_8TAP_SHARP ][idx2][idxh][idxv] = type##_8tap_sharp_##sz##dir##_c; \
+ dsp->mc[idx1][FILTER_BILINEAR ][idx2][idxh][idxv] = type##_bilin_##sz##dir##_c
+
+#define init_subpel2(idx, idxh, idxv, dir, type) \
+ init_subpel1(0, idx, idxh, idxv, 64, dir, type); \
+ init_subpel1(1, idx, idxh, idxv, 32, dir, type); \
+ init_subpel1(2, idx, idxh, idxv, 16, dir, type); \
+ init_subpel1(3, idx, idxh, idxv, 8, dir, type); \
+ init_subpel1(4, idx, idxh, idxv, 4, dir, type)
+
+#define init_subpel3(idx, type) \
+ init_subpel2(idx, 1, 1, hv, type); \
+ init_subpel2(idx, 0, 1, v, type); \
+ init_subpel2(idx, 1, 0, h, type)
+
+ init_subpel3(0, put);
+ init_subpel3(1, avg);
+
+#undef init_subpel1
+#undef init_subpel2
+#undef init_subpel3
+}
+
+av_cold void ff_vp9dsp_init(VP9DSPContext *dsp)
+{
+ vp9dsp_intrapred_init(dsp);
+ vp9dsp_itxfm_init(dsp);
+ vp9dsp_loopfilter_init(dsp);
+ vp9dsp_mc_init(dsp);
+}
diff --git a/libavcodec/vp9dsp.h b/libavcodec/vp9dsp.h
new file mode 100644
index 0000000000..bab98daf6a
--- /dev/null
+++ b/libavcodec/vp9dsp.h
@@ -0,0 +1,115 @@
+/*
+ * VP9 compatible video decoder
+ *
+ * Copyright (C) 2013 Ronald S. Bultje <rsbultje gmail com>
+ * Copyright (C) 2013 Clément Bœsch <u pkh me>
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef AVCODEC_VP9DSP_H
+#define AVCODEC_VP9DSP_H
+
+#include <stdint.h>
+
+#include "vp9.h"
+
+typedef void (*vp9_mc_func)(uint8_t *dst, ptrdiff_t dst_stride,
+ const uint8_t *ref, ptrdiff_t ref_stride,
+ int h, int mx, int my);
+
+typedef struct VP9DSPContext {
+ /*
+ * dimension 1: 0=4x4, 1=8x8, 2=16x16, 3=32x32
+ * dimension 2: intra prediction modes
+ *
+ * dst/left/top is aligned by transform-size (i.e. 4, 8, 16 or 32 pixels)
+ * stride is aligned by 16 pixels
+ * top[-1] is top/left; top[4,7] is top-right for 4x4
+ */
+ // FIXME(rbultje) maybe replace left/top pointers with HAVE_TOP/
+ // HAVE_LEFT/HAVE_TOPRIGHT flags instead, and then handle it in-place?
+ // also needs to fit in with what h264/vp8/etc do
+ void (*intra_pred[N_TXFM_SIZES][N_INTRA_PRED_MODES])(uint8_t *dst,
+ ptrdiff_t stride,
+ const uint8_t *left,
+ const uint8_t *top);
+
+ /*
+ * dimension 1: 0=4x4, 1=8x8, 2=16x16, 3=32x32, 4=lossless (3-4=dct only)
+ * dimension 2: 0=dct/dct, 1=dct/adst, 2=adst/dct, 3=adst/adst
+ *
+ * dst is aligned by transform-size (i.e. 4, 8, 16 or 32 pixels)
+ * stride is aligned by 16 pixels
+ * block is 16-byte aligned
+ * eob indicates the position (+1) of the last non-zero coefficient,
+ * in scan-order. This can be used to write faster versions, e.g. a
+ * dc-only 4x4/8x8/16x16/32x32, or a 4x4-only (eob<10) 8x8/16x16/32x32,
+ * etc.
+ */
+ // FIXME also write idct_add_block() versions for whole (inter) pred
+ // blocks, so we can do 2 4x4s at once
+ void (*itxfm_add[N_TXFM_SIZES + 1][N_TXFM_TYPES])(uint8_t *dst,
+ ptrdiff_t stride,
+ int16_t *block, int eob);
+
+ /*
+ * dimension 1: width of filter (0=4, 1=8, 2=16)
+ * dimension 2: 0=col-edge filter (h), 1=row-edge filter (v)
+ *
+ * dst/stride are aligned by 8
+ */
+ void (*loop_filter_8[3][2])(uint8_t *dst, ptrdiff_t stride,
+ int mb_lim, int lim, int hev_thr);
+
+ /*
+ * dimension 1: 0=col-edge filter (h), 1=row-edge filter (v)
+ *
+ * The width of filter is assumed to be 16; dst/stride are aligned by 16
+ */
+ void (*loop_filter_16[2])(uint8_t *dst, ptrdiff_t stride,
+ int mb_lim, int lim, int hev_thr);
+
+ /*
+ * dimension 1/2: width of filter (0=4, 1=8) for each filter half
+ * dimension 3: 0=col-edge filter (h), 1=row-edge filter (v)
+ *
+ * dst/stride are aligned by operation size
+ * this basically calls loop_filter[d1][d3][0](), followed by
+ * loop_filter[d2][d3][0]() on the next 8 pixels
+ * mb_lim/lim/hev_thr contain two values in the lowest two bytes of the
+ * integer.
+ */
+ // FIXME perhaps a mix4 that operates on 32px (for AVX2)
+ void (*loop_filter_mix2[2][2][2])(uint8_t *dst, ptrdiff_t stride,
+ int mb_lim, int lim, int hev_thr);
+
+ /*
+ * dimension 1: hsize (0: 64, 1: 32, 2: 16, 3: 8, 4: 4)
+ * dimension 2: filter type (0: smooth, 1: regular, 2: sharp, 3: bilin)
+ * dimension 3: averaging type (0: put, 1: avg)
+ * dimension 4: x subpel interpolation (0: none, 1: 8tap/bilin)
+ * dimension 5: y subpel interpolation (1: none, 1: 8tap/bilin)
+ *
+ * dst/stride are aligned by hsize
+ */
+ vp9_mc_func mc[5][4][2][2][2];
+} VP9DSPContext;
+
+void ff_vp9dsp_init(VP9DSPContext *dsp);
+
+#endif /* AVCODEC_VP9DSP_H */
diff --git a/tests/fate/vpx.mak b/tests/fate/vpx.mak
index 99a58559e4..839890302f 100644
--- a/tests/fate/vpx.mak
+++ b/tests/fate/vpx.mak
@@ -57,3 +57,33 @@ $(eval $(call FATE_VP8_FULL))
$(eval $(call FATE_VP8_FULL,-emu-edge,-flags +emu_edge))
FATE_SAMPLES_AVCONV-$(CONFIG_VP8_DECODER) += $(FATE_VP8-yes)
fate-vp8: $(FATE_VP8-yes)
+
+define FATE_VP9_SUITE
+FATE_VP9-$(CONFIG_MATROSKA_DEMUXER) += fate-vp9$(2)-$(1)
+fate-vp9$(2)-$(1): CMD = framemd5 $(3) -i $(TARGET_SAMPLES)/vp9-test-vectors/vp90-2-$(1).webm
+fate-vp9$(2)-$(1): REF = $(SRC_PATH)/tests/ref/fate/vp9-$(1)
+endef
+
+VP9_Q = 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 \
+ 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 \
+ 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 \
+ 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
+VP9_SHARP = 1 2 3 4 5 6 7
+VP9_SIZE_A = 08 10 16 18 32 34 64 66
+VP9_SIZE_B = 196 198 200 202 208 210 224 226
+
+define FATE_VP9_FULL
+$(foreach Q,$(VP9_Q),$(eval $(call FATE_VP9_SUITE,00-quantizer-$(Q),$(1),$(2))))
+$(foreach SHARP,$(VP9_SHARP),$(eval $(call FATE_VP9_SUITE,01-sharpness-$(SHARP),$(1),$(2))))
+$(foreach W,$(VP9_SIZE_A),$(eval $(foreach H,$(VP9_SIZE_A),$(eval $(call FATE_VP9_SUITE,02-size-$(W)x$(H),$(1),$(2))))))
+$(foreach W,$(VP9_SIZE_B),$(eval $(foreach H,$(VP9_SIZE_B),$(eval $(call FATE_VP9_SUITE,03-size-$(W)x$(H),$(1),$(2))))))
+$(eval $(call FATE_VP9_SUITE,03-deltaq,$(1),$(2)))
+$(eval $(call FATE_VP9_SUITE,2pass-akiyo,$(1),$(2)))
+$(eval $(call FATE_VP9_SUITE,segmentation-akiyo,$(1),$(2)))
+$(eval $(call FATE_VP9_SUITE,tiling-pedestrian,$(1),$(2)))
+endef
+
+$(eval $(call FATE_VP9_FULL))
+$(eval $(call FATE_VP9_FULL,-emu-edge,-flags +emu_edge))
+FATE_SAMPLES_AVCONV-$(CONFIG_VP9_DECODER) += $(FATE_VP9-yes)
+fate-vp9: $(FATE_VP9-yes)
diff --git a/tests/ref/fate/vp9-00-quantizer-00 b/tests/ref/fate/vp9-00-quantizer-00
new file mode 100644
index 0000000000..2aa81b4c61
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-00
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, c3fbb7abbdb5bd4ed4a7e34768c17df1
+0, 1, 1, 1, 152064, 08203c2595bdb2d58ead6f921345d699
diff --git a/tests/ref/fate/vp9-00-quantizer-01 b/tests/ref/fate/vp9-00-quantizer-01
new file mode 100644
index 0000000000..6f123493b2
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-01
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, f041b870cf9236d5f22e2b08a77d5958
+0, 1, 1, 1, 152064, cbdb7526986ae15592891488c9afc84c
diff --git a/tests/ref/fate/vp9-00-quantizer-02 b/tests/ref/fate/vp9-00-quantizer-02
new file mode 100644
index 0000000000..1ab0ed07b2
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-02
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 98048cfdb4af5059f4085c5acc94ef8f
+0, 1, 1, 1, 152064, 8160183e1eed1d0af4427be216b8b9f7
diff --git a/tests/ref/fate/vp9-00-quantizer-03 b/tests/ref/fate/vp9-00-quantizer-03
new file mode 100644
index 0000000000..e458d68522
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-03
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 15c548208f5eda243a151a42f4d64855
+0, 1, 1, 1, 152064, e96d463dc8e9b27b1c2ec40f77eee6ef
diff --git a/tests/ref/fate/vp9-00-quantizer-04 b/tests/ref/fate/vp9-00-quantizer-04
new file mode 100644
index 0000000000..60ec047535
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-04
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 928c64a0747ac57ab50c1520d694fea7
+0, 1, 1, 1, 152064, a6f6daa293231e95ef30ed168f582c84
diff --git a/tests/ref/fate/vp9-00-quantizer-05 b/tests/ref/fate/vp9-00-quantizer-05
new file mode 100644
index 0000000000..81f3cfb5bc
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-05
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 082460718b7d7046c8fb23184b7f71ca
+0, 1, 1, 1, 152064, 4a41aad51c40a92df72333e13f47d3fe
diff --git a/tests/ref/fate/vp9-00-quantizer-06 b/tests/ref/fate/vp9-00-quantizer-06
new file mode 100644
index 0000000000..d06fa0ce90
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-06
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, cfca1bed96ff62a69b2d841fda01c6b9
+0, 1, 1, 1, 152064, 9b4d61f1b998745c108f8eb67925e03d
diff --git a/tests/ref/fate/vp9-00-quantizer-07 b/tests/ref/fate/vp9-00-quantizer-07
new file mode 100644
index 0000000000..afce0abc7e
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-07
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 6f5122064bead9d9882bec2698a6ed9c
+0, 1, 1, 1, 152064, 50dae67d2f57a76eece210dee8b6df9e
diff --git a/tests/ref/fate/vp9-00-quantizer-08 b/tests/ref/fate/vp9-00-quantizer-08
new file mode 100644
index 0000000000..8092995ba0
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-08
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, eb3d6985fcda5d93dd62d53354e8a093
+0, 1, 1, 1, 152064, 5b1f5b7780b4cafe1f75e56a0b526643
diff --git a/tests/ref/fate/vp9-00-quantizer-09 b/tests/ref/fate/vp9-00-quantizer-09
new file mode 100644
index 0000000000..fd25ec529a
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-09
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, d7ccaf28c59875fe91983def5490d2b1
+0, 1, 1, 1, 152064, bd98fe9492054826748de840b4495309
diff --git a/tests/ref/fate/vp9-00-quantizer-10 b/tests/ref/fate/vp9-00-quantizer-10
new file mode 100644
index 0000000000..61c3fb8b7b
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-10
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 20dda6231f9801c9c237c6d09d9939b6
+0, 1, 1, 1, 152064, 23c91e93807fb9a4ed5bd5bdd449d99f
diff --git a/tests/ref/fate/vp9-00-quantizer-11 b/tests/ref/fate/vp9-00-quantizer-11
new file mode 100644
index 0000000000..6da2316613
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-11
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 960833315ebcdee97f46c4d98d0f3fef
+0, 1, 1, 1, 152064, eec40507d17b64b7895a61cb87b2096a
diff --git a/tests/ref/fate/vp9-00-quantizer-12 b/tests/ref/fate/vp9-00-quantizer-12
new file mode 100644
index 0000000000..492b07acb7
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-12
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 6533224d3b6ba1ec0dd973bbe56c6349
+0, 1, 1, 1, 152064, 12ceadc6d28327a24a75f8c40b6084d1
diff --git a/tests/ref/fate/vp9-00-quantizer-13 b/tests/ref/fate/vp9-00-quantizer-13
new file mode 100644
index 0000000000..2b9e635cc1
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-13
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 7268de6756014f79a56dcf010c52a97f
+0, 1, 1, 1, 152064, 9e39e9b0e2295b8460dfa05f44762771
diff --git a/tests/ref/fate/vp9-00-quantizer-14 b/tests/ref/fate/vp9-00-quantizer-14
new file mode 100644
index 0000000000..861dc3b9e9
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-14
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 57e9e333c641fa952f7485b788df225a
+0, 1, 1, 1, 152064, 551f0cea83dcdf4540c3983736757874
diff --git a/tests/ref/fate/vp9-00-quantizer-15 b/tests/ref/fate/vp9-00-quantizer-15
new file mode 100644
index 0000000000..a6c3c59fda
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-15
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 17a0a2842856b9e89aede237648d5dda
+0, 1, 1, 1, 152064, c9fcade888a38621bebe3d4b41664245
diff --git a/tests/ref/fate/vp9-00-quantizer-16 b/tests/ref/fate/vp9-00-quantizer-16
new file mode 100644
index 0000000000..9f049e54f9
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-16
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 6cc2089e9a3d352fe10b59ccd935c677
+0, 1, 1, 1, 152064, d165bf7b9cb901e121a65038758d8613
diff --git a/tests/ref/fate/vp9-00-quantizer-17 b/tests/ref/fate/vp9-00-quantizer-17
new file mode 100644
index 0000000000..6642088a09
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-17
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, bc80511c83162c09661f155cd29f6dd8
+0, 1, 1, 1, 152064, a62f1cbdb3f86d2fb4c880cfd917def5
diff --git a/tests/ref/fate/vp9-00-quantizer-18 b/tests/ref/fate/vp9-00-quantizer-18
new file mode 100644
index 0000000000..a456e716af
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-18
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, b2d350f6faa41cb50c2e8a9907d0f4a5
+0, 1, 1, 1, 152064, 39b4380d16bc8e093dd4dba475175fb3
diff --git a/tests/ref/fate/vp9-00-quantizer-19 b/tests/ref/fate/vp9-00-quantizer-19
new file mode 100644
index 0000000000..5daf04b12e
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-19
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 441e09be3c15fcb240afd74bb7a10a72
+0, 1, 1, 1, 152064, 32ae5dac876ca5d5ae6ab7c74f4dc25d
diff --git a/tests/ref/fate/vp9-00-quantizer-20 b/tests/ref/fate/vp9-00-quantizer-20
new file mode 100644
index 0000000000..550df975eb
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-20
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 7786eb9944dba0553e129133523a98c1
+0, 1, 1, 1, 152064, 206d888f8453427f10a40aa8bf5f6df0
diff --git a/tests/ref/fate/vp9-00-quantizer-21 b/tests/ref/fate/vp9-00-quantizer-21
new file mode 100644
index 0000000000..61dac5a61e
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-21
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, aab95e195be71feca050a839d7b3154d
+0, 1, 1, 1, 152064, 02a05d699bbbdc477e34bb0dad9f0391
diff --git a/tests/ref/fate/vp9-00-quantizer-22 b/tests/ref/fate/vp9-00-quantizer-22
new file mode 100644
index 0000000000..1a7e309a48
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-22
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 41f853c3ee2d4611b645cc643d82e287
+0, 1, 1, 1, 152064, 1c240c653110ff8609ca0f0287a6496d
diff --git a/tests/ref/fate/vp9-00-quantizer-23 b/tests/ref/fate/vp9-00-quantizer-23
new file mode 100644
index 0000000000..d636956ca1
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-23
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, bc5b07369df50c8f97ce1a377fe513cf
+0, 1, 1, 1, 152064, ce62ddb4f3e305d0f8587ae8bb44cc79
diff --git a/tests/ref/fate/vp9-00-quantizer-24 b/tests/ref/fate/vp9-00-quantizer-24
new file mode 100644
index 0000000000..fe3b8bd0a6
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-24
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 982d54041221c977b6f0e37a9236cc76
+0, 1, 1, 1, 152064, 57631e7f13f645c834e2944ebfd6d40e
diff --git a/tests/ref/fate/vp9-00-quantizer-25 b/tests/ref/fate/vp9-00-quantizer-25
new file mode 100644
index 0000000000..84f35eee91
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-25
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, b0fb55f3f2f56b3d27038e83c10123ce
+0, 1, 1, 1, 152064, 9fcac3becdcc2d30d778a55eca4c2018
diff --git a/tests/ref/fate/vp9-00-quantizer-26 b/tests/ref/fate/vp9-00-quantizer-26
new file mode 100644
index 0000000000..0fa04db323
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-26
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 4f645e0f354da77b9e2f2a6753c361da
+0, 1, 1, 1, 152064, b7542998ec298273ca662bc9b658d10e
diff --git a/tests/ref/fate/vp9-00-quantizer-27 b/tests/ref/fate/vp9-00-quantizer-27
new file mode 100644
index 0000000000..f56606ce8b
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-27
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 6edc96a3747cad43828397045764206e
+0, 1, 1, 1, 152064, 5fbc65d20fdca1abd69079851ce676d3
diff --git a/tests/ref/fate/vp9-00-quantizer-28 b/tests/ref/fate/vp9-00-quantizer-28
new file mode 100644
index 0000000000..b8946b0a54
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-28
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 5db3e910e70da38bb91d01d73acc33dd
+0, 1, 1, 1, 152064, b920ee7f7e61b7fdf9f44b1f738d0292
diff --git a/tests/ref/fate/vp9-00-quantizer-29 b/tests/ref/fate/vp9-00-quantizer-29
new file mode 100644
index 0000000000..e5780ee8ea
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-29
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 3cb3e310be5305077efa6216f6f10654
+0, 1, 1, 1, 152064, 692d3e098af5978fe1a898ebc1a66a7a
diff --git a/tests/ref/fate/vp9-00-quantizer-30 b/tests/ref/fate/vp9-00-quantizer-30
new file mode 100644
index 0000000000..91fa4e018c
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-30
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, e3b3cea66ea38c5dfba1aa73bb4c611d
+0, 1, 1, 1, 152064, 42bb3e54b19c3f4c4f7ee3a6ba012e19
diff --git a/tests/ref/fate/vp9-00-quantizer-31 b/tests/ref/fate/vp9-00-quantizer-31
new file mode 100644
index 0000000000..3cf3af8b56
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-31
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 2523e9ecfd3781eafcd7da192dc105e9
+0, 1, 1, 1, 152064, 6d5feea012b9a1f51fc643633e728764
diff --git a/tests/ref/fate/vp9-00-quantizer-32 b/tests/ref/fate/vp9-00-quantizer-32
new file mode 100644
index 0000000000..13616fc19c
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-32
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 0a0305eba36500ebf6cc6cc0f01f5a3b
+0, 1, 1, 1, 152064, 2c76bcd6763467f9057a726fbcf50ab1
diff --git a/tests/ref/fate/vp9-00-quantizer-33 b/tests/ref/fate/vp9-00-quantizer-33
new file mode 100644
index 0000000000..ad3e5b8b84
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-33
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, c68433e0e94047c220be9b629334f744
+0, 1, 1, 1, 152064, fcfa4dff7a39bc9c5e315849ecbb46ea
diff --git a/tests/ref/fate/vp9-00-quantizer-34 b/tests/ref/fate/vp9-00-quantizer-34
new file mode 100644
index 0000000000..aee58f89f7
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-34
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, ad9dc2f912c137b014a33e2792c88a25
+0, 1, 1, 1, 152064, 11221ee4ea5c776f43af68756682cd5a
diff --git a/tests/ref/fate/vp9-00-quantizer-35 b/tests/ref/fate/vp9-00-quantizer-35
new file mode 100644
index 0000000000..fbb68f73c3
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-35
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 75031f898cccf303a64ab46b1f815389
+0, 1, 1, 1, 152064, a4fc864e7fbc470dfcab6207e0eea152
diff --git a/tests/ref/fate/vp9-00-quantizer-36 b/tests/ref/fate/vp9-00-quantizer-36
new file mode 100644
index 0000000000..d5bcad600f
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-36
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, c7824af009fde6cafdd8d39fae6bb6cf
+0, 1, 1, 1, 152064, 516a82d5fc4dfa3daf713ed2ec36041b
diff --git a/tests/ref/fate/vp9-00-quantizer-37 b/tests/ref/fate/vp9-00-quantizer-37
new file mode 100644
index 0000000000..2a030b477c
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-37
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, a2e5c820fd9733e18f9349fb658ca281
+0, 1, 1, 1, 152064, fb23e0bc64728a492a33d985032f21b8
diff --git a/tests/ref/fate/vp9-00-quantizer-38 b/tests/ref/fate/vp9-00-quantizer-38
new file mode 100644
index 0000000000..d5e7076b55
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-38
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 8347bfb891317e89ef66781d6c28e24f
+0, 1, 1, 1, 152064, a5722f824d32deac042513a1a7dcdcd0
diff --git a/tests/ref/fate/vp9-00-quantizer-39 b/tests/ref/fate/vp9-00-quantizer-39
new file mode 100644
index 0000000000..464d265e44
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-39
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 018968f97fac3bdff146cf22c1da5ef0
+0, 1, 1, 1, 152064, ca8b09b01e5132183395e238f1c7901e
diff --git a/tests/ref/fate/vp9-00-quantizer-40 b/tests/ref/fate/vp9-00-quantizer-40
new file mode 100644
index 0000000000..69b230e110
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-40
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 792660f6589ad5340be4bd0554435866
+0, 1, 1, 1, 152064, 68c84c8a15d679e0a73678b93215c62c
diff --git a/tests/ref/fate/vp9-00-quantizer-41 b/tests/ref/fate/vp9-00-quantizer-41
new file mode 100644
index 0000000000..0dd4500d47
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-41
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, a456bdfc6c1c07b4cb3a3848843743b9
+0, 1, 1, 1, 152064, fe41a12b8cb6bc5667ba2179e076f3b0
diff --git a/tests/ref/fate/vp9-00-quantizer-42 b/tests/ref/fate/vp9-00-quantizer-42
new file mode 100644
index 0000000000..bf8125ce4e
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-42
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, f016dd8431694d989700fb1ba71a5b2d
+0, 1, 1, 1, 152064, e89c3c5b935157b40f2fb0ab92415828
diff --git a/tests/ref/fate/vp9-00-quantizer-43 b/tests/ref/fate/vp9-00-quantizer-43
new file mode 100644
index 0000000000..dd1257823b
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-43
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 7b8ab82625f3006bac89d4fb5197e71c
+0, 1, 1, 1, 152064, 18bd3716045563dfba2c72b640b3274b
diff --git a/tests/ref/fate/vp9-00-quantizer-44 b/tests/ref/fate/vp9-00-quantizer-44
new file mode 100644
index 0000000000..7917184ea9
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-44
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 66fde04d8320c750e56406feefd29979
+0, 1, 1, 1, 152064, f9d01d8fc1722ec345e624e14b404215
diff --git a/tests/ref/fate/vp9-00-quantizer-45 b/tests/ref/fate/vp9-00-quantizer-45
new file mode 100644
index 0000000000..a15e6f5f3d
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-45
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, cc97597b015896d73f3e60e7ae44c4da
+0, 1, 1, 1, 152064, fea98bc508f92135641ab99762444b14
diff --git a/tests/ref/fate/vp9-00-quantizer-46 b/tests/ref/fate/vp9-00-quantizer-46
new file mode 100644
index 0000000000..8eccf6b9b8
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-46
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 79ed95c741178bb3c0954f1f6f8e21a3
+0, 1, 1, 1, 152064, f02a06a5e2b5b7619c9a52c5bea0564d
diff --git a/tests/ref/fate/vp9-00-quantizer-47 b/tests/ref/fate/vp9-00-quantizer-47
new file mode 100644
index 0000000000..0616f1f2a8
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-47
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 9b98e948b8c2a822f21bd8419e6f4410
+0, 1, 1, 1, 152064, 491382d68c16c2a3c6f1746598bc4a97
diff --git a/tests/ref/fate/vp9-00-quantizer-48 b/tests/ref/fate/vp9-00-quantizer-48
new file mode 100644
index 0000000000..ebdb986b63
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-48
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, f0f095b0edae7262f44d7ed7ef84ded4
+0, 1, 1, 1, 152064, 0e833889ccac81d60251007d1baf6500
diff --git a/tests/ref/fate/vp9-00-quantizer-49 b/tests/ref/fate/vp9-00-quantizer-49
new file mode 100644
index 0000000000..cf287fa2de
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-49
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 6c1b7b7827617fb9b8417aca2cfdbcaa
+0, 1, 1, 1, 152064, 4c1fc8a89297fdcf79f0faabd42b8684
diff --git a/tests/ref/fate/vp9-00-quantizer-50 b/tests/ref/fate/vp9-00-quantizer-50
new file mode 100644
index 0000000000..2e88104b06
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-50
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, ca6142db68463487bc28c888ab38476c
+0, 1, 1, 1, 152064, 02a71153ec70f569524c3d814cb62f86
diff --git a/tests/ref/fate/vp9-00-quantizer-51 b/tests/ref/fate/vp9-00-quantizer-51
new file mode 100644
index 0000000000..6d7fadb890
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-51
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, eece2627df1ddf0872256eb92352e179
+0, 1, 1, 1, 152064, 0ee9f221246ad747250e4b5e8ba586e2
diff --git a/tests/ref/fate/vp9-00-quantizer-52 b/tests/ref/fate/vp9-00-quantizer-52
new file mode 100644
index 0000000000..244b7a8c7c
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-52
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 7290039d974c4e50db9d69f9864bcdbe
+0, 1, 1, 1, 152064, 264765de9d02503038a4da54133b9f85
diff --git a/tests/ref/fate/vp9-00-quantizer-53 b/tests/ref/fate/vp9-00-quantizer-53
new file mode 100644
index 0000000000..bced29dfe0
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-53
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 917af24da66f143a56a01eb2c2254285
+0, 1, 1, 1, 152064, 45a05d3bc644420519619e4115662a70
diff --git a/tests/ref/fate/vp9-00-quantizer-54 b/tests/ref/fate/vp9-00-quantizer-54
new file mode 100644
index 0000000000..5716f8e381
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-54
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 6fea2820bb10a9dec9add4d2452b01f5
+0, 1, 1, 1, 152064, 74675169a4bfc2ff5463c4db5d85a79f
diff --git a/tests/ref/fate/vp9-00-quantizer-55 b/tests/ref/fate/vp9-00-quantizer-55
new file mode 100644
index 0000000000..a6e796ee3b
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-55
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 11e5d196f6537fb7d85988d90195e556
+0, 1, 1, 1, 152064, 8536106795f7c93c5a43a11493527469
diff --git a/tests/ref/fate/vp9-00-quantizer-56 b/tests/ref/fate/vp9-00-quantizer-56
new file mode 100644
index 0000000000..8da01826be
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-56
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 40839b7a3a40ec10f96b8a75224f646d
+0, 1, 1, 1, 152064, 11408dd73e8c45ddaab99f5c9650102b
diff --git a/tests/ref/fate/vp9-00-quantizer-57 b/tests/ref/fate/vp9-00-quantizer-57
new file mode 100644
index 0000000000..10526d21fd
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-57
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, d0e9fa03dd48da4592ebaadb4e3794e0
+0, 1, 1, 1, 152064, 5172e29b1e04cd543833d6a68aab297c
diff --git a/tests/ref/fate/vp9-00-quantizer-58 b/tests/ref/fate/vp9-00-quantizer-58
new file mode 100644
index 0000000000..2b02267325
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-58
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, bef4a27d460e7697e038fe6f1c8bd597
+0, 1, 1, 1, 152064, 124674686cafc5f2ff5bc7ea412b8f3b
diff --git a/tests/ref/fate/vp9-00-quantizer-59 b/tests/ref/fate/vp9-00-quantizer-59
new file mode 100644
index 0000000000..2ea4328ca1
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-59
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, ae9d99e9d16ef20073300559566844ae
+0, 1, 1, 1, 152064, da9405e5a6bfe4ed18d927ba2004008e
diff --git a/tests/ref/fate/vp9-00-quantizer-60 b/tests/ref/fate/vp9-00-quantizer-60
new file mode 100644
index 0000000000..b042f3afc4
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-60
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 9e66bb8e1b5e206ea4afe4bf2d335ac5
+0, 1, 1, 1, 152064, 092b74c905c12c1e87e90f5a79857736
diff --git a/tests/ref/fate/vp9-00-quantizer-61 b/tests/ref/fate/vp9-00-quantizer-61
new file mode 100644
index 0000000000..cc8e72a479
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-61
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, d062dc6be246c8042744018765ef50a8
+0, 1, 1, 1, 152064, 45fd9cbacb6a91060a7e49a58a85869d
diff --git a/tests/ref/fate/vp9-00-quantizer-62 b/tests/ref/fate/vp9-00-quantizer-62
new file mode 100644
index 0000000000..881157458b
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-62
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 62f7e42fe653e81c5a65a25389e045b5
+0, 1, 1, 1, 152064, cb0cdd0b25689e0a43328550011d960d
diff --git a/tests/ref/fate/vp9-00-quantizer-63 b/tests/ref/fate/vp9-00-quantizer-63
new file mode 100644
index 0000000000..ab62af8406
--- /dev/null
+++ b/tests/ref/fate/vp9-00-quantizer-63
@@ -0,0 +1,3 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 8467643dceff827e04acd82eeff1d1b0
+0, 1, 1, 1, 152064, c786f49d66f4dfd685dea9605821a19f
diff --git a/tests/ref/fate/vp9-01-sharpness-1 b/tests/ref/fate/vp9-01-sharpness-1
new file mode 100644
index 0000000000..3e26060fc9
--- /dev/null
+++ b/tests/ref/fate/vp9-01-sharpness-1
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, a2e5c820fd9733e18f9349fb658ca281
+0, 1, 1, 1, 152064, aa20a75be3a316193496706c9f760d08
+0, 2, 2, 1, 152064, 95567be97a64d3c9efe45f2524116a2e
+0, 3, 3, 1, 152064, 219e86cd6b3cca312856eead21776b1c
+0, 4, 4, 1, 152064, 4a67fd359ca362398e97c15eb018a2bb
+0, 5, 5, 1, 152064, 9916d4e359274d690827f0eb22547423
+0, 6, 6, 1, 152064, a07785b52561150c48f1a8eff89d5d75
+0, 7, 7, 1, 152064, a3382a92982953dfa20018e5ac975b51
+0, 8, 8, 1, 152064, 911836989ca7b148438aa3ec7fc7e303
+0, 9, 9, 1, 152064, 5627b981e3fc9e4401d35d3a5ab25917
diff --git a/tests/ref/fate/vp9-01-sharpness-2 b/tests/ref/fate/vp9-01-sharpness-2
new file mode 100644
index 0000000000..e5987278fa
--- /dev/null
+++ b/tests/ref/fate/vp9-01-sharpness-2
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, a2e5c820fd9733e18f9349fb658ca281
+0, 1, 1, 1, 152064, cd94572239817ae7c9b07de739c3272b
+0, 2, 2, 1, 152064, 383cf752d457e122b5ff49d08960208e
+0, 3, 3, 1, 152064, 1c0a6ec9cd3ce29b8b004e7526f1b07e
+0, 4, 4, 1, 152064, 91c42a8a108d67947cabfc2a5a80df66
+0, 5, 5, 1, 152064, 08c57fc1f3fec0305883315a66c714d1
+0, 6, 6, 1, 152064, 70cb8d8dc83eac82f2d3c4b0376bb1aa
+0, 7, 7, 1, 152064, ffd62a9ef829ec81f0f74f740488a41f
+0, 8, 8, 1, 152064, bab0aa23b5854e2a70926046e4618710
+0, 9, 9, 1, 152064, fec456f38f2a43661e786a8d5f67ed15
diff --git a/tests/ref/fate/vp9-01-sharpness-3 b/tests/ref/fate/vp9-01-sharpness-3
new file mode 100644
index 0000000000..29e8f5539e
--- /dev/null
+++ b/tests/ref/fate/vp9-01-sharpness-3
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, a2e5c820fd9733e18f9349fb658ca281
+0, 1, 1, 1, 152064, 0d487a146393a0b8b84b4be1b371b507
+0, 2, 2, 1, 152064, 68372e191eba620a431cfff226026ac3
+0, 3, 3, 1, 152064, de7fd274460e36b983fe93acc208d72f
+0, 4, 4, 1, 152064, afbd36c61bab65b98ff9acf08e215721
+0, 5, 5, 1, 152064, e1e9fc2ab4e7a187a8d8d84aae48d6b9
+0, 6, 6, 1, 152064, 11d95de6a9cc5e00511e99534779faac
+0, 7, 7, 1, 152064, cd2f5539fdfc2d8eefe6b6da28c13398
+0, 8, 8, 1, 152064, a8b3aeed41da7aeb8d5b962ee4a4af93
+0, 9, 9, 1, 152064, 4283670bd1c1c506ef18d3dafca22035
diff --git a/tests/ref/fate/vp9-01-sharpness-4 b/tests/ref/fate/vp9-01-sharpness-4
new file mode 100644
index 0000000000..e6a9893680
--- /dev/null
+++ b/tests/ref/fate/vp9-01-sharpness-4
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, a2e5c820fd9733e18f9349fb658ca281
+0, 1, 1, 1, 152064, 8bad76c55b5149169d64ce6512521de6
+0, 2, 2, 1, 152064, c1d986e1f9bf46382e598ba289b9bd7c
+0, 3, 3, 1, 152064, 86c097ac6069c786023d3561dae68bac
+0, 4, 4, 1, 152064, 8c238a2831b8c7c49736b6de6ff76ed8
+0, 5, 5, 1, 152064, cb5a038ed0a74a317ee72dae93a7ee3e
+0, 6, 6, 1, 152064, f8fe330a257e3e4e4c39c1c12820a654
+0, 7, 7, 1, 152064, a73e2fcdcbb9334c0c123f8276a2c881
+0, 8, 8, 1, 152064, 24fccece8ee639e4d0e00e4060e1db0c
+0, 9, 9, 1, 152064, 46d6e9aad69a39c718c5fd1e41e86e6e
diff --git a/tests/ref/fate/vp9-01-sharpness-5 b/tests/ref/fate/vp9-01-sharpness-5
new file mode 100644
index 0000000000..8440700c2a
--- /dev/null
+++ b/tests/ref/fate/vp9-01-sharpness-5
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, a2e5c820fd9733e18f9349fb658ca281
+0, 1, 1, 1, 152064, f1ce0a5d57a46c9ff1331804b7b03fdb
+0, 2, 2, 1, 152064, 0364a085b06bee6b980189cf5378eda9
+0, 3, 3, 1, 152064, 4b5358698d734b0ae210909a913d4c1e
+0, 4, 4, 1, 152064, dc22565aaceee77b15fd8ab3c84bd5e0
+0, 5, 5, 1, 152064, 5f6340b656536292b46ba9a647aeb6e4
+0, 6, 6, 1, 152064, b7d4bce9a04b2a6caa45801be15e331e
+0, 7, 7, 1, 152064, 534c851cfe59ffc047815ece98d8cede
+0, 8, 8, 1, 152064, 786b0e1564d5c71aabfc2dd528cff4e7
+0, 9, 9, 1, 152064, cac0366209cf471bb7cc3e64966cbbd4
diff --git a/tests/ref/fate/vp9-01-sharpness-6 b/tests/ref/fate/vp9-01-sharpness-6
new file mode 100644
index 0000000000..116273c683
--- /dev/null
+++ b/tests/ref/fate/vp9-01-sharpness-6
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, a2e5c820fd9733e18f9349fb658ca281
+0, 1, 1, 1, 152064, 45d9ca07ed04210b1ebc743169bc8ec4
+0, 2, 2, 1, 152064, 5b646cc309a711f1d8814f925002d8c4
+0, 3, 3, 1, 152064, 34db8db727fa1ded0a55cc7cf85be249
+0, 4, 4, 1, 152064, 54173d08afe6369b16a9c0c9cc6ce04d
+0, 5, 5, 1, 152064, 76275b0a478cdb3c1fb527ebbce023c3
+0, 6, 6, 1, 152064, e7643cdf0c42f2af700d8730bfc1a453
+0, 7, 7, 1, 152064, 6e53097e56f680cb658d63100e7736f7
+0, 8, 8, 1, 152064, 1a407c3c8ea1d5245ae68c5ce7de70e1
+0, 9, 9, 1, 152064, 6cbca24912cadf09b20be74f14e359c9
diff --git a/tests/ref/fate/vp9-01-sharpness-7 b/tests/ref/fate/vp9-01-sharpness-7
new file mode 100644
index 0000000000..d682bb5d70
--- /dev/null
+++ b/tests/ref/fate/vp9-01-sharpness-7
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, a2e5c820fd9733e18f9349fb658ca281
+0, 1, 1, 1, 152064, f719d0be18d16a448b4e7da3e2d9bf28
+0, 2, 2, 1, 152064, 83ee8ebc0ca796782a2376a76f2ffc26
+0, 3, 3, 1, 152064, 7cf5afdbc229e1af50a5377cfc23d831
+0, 4, 4, 1, 152064, 44244e896e0362f6376ba5afa563ba8b
+0, 5, 5, 1, 152064, df5f518d44eb6cb91b2df5a30d27ef82
+0, 6, 6, 1, 152064, 43cc3f151b8337aca7ee659c8abeb783
+0, 7, 7, 1, 152064, 4e89573470d9b97464e10806fc81aa8b
+0, 8, 8, 1, 152064, 62e0ba70f07ece8d85372f0a42e83a9a
+0, 9, 9, 1, 152064, 45ac2928acb11326f6c4a21401f3609c
diff --git a/tests/ref/fate/vp9-02-size-08x08 b/tests/ref/fate/vp9-02-size-08x08
new file mode 100644
index 0000000000..70d2c16362
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-08x08
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 96, 52def242c36123e5a8f5f53d6a971399
+0, 1, 1, 1, 96, 79c93360fbd47179400414bbfee0901c
+0, 2, 2, 1, 96, c3b1947c79537baa7838905276276a91
+0, 3, 3, 1, 96, 20f35e501bdee0bc63e87b9240265c25
+0, 4, 4, 1, 96, 5e8f1c464bafd54833c51860906b5368
+0, 5, 5, 1, 96, f57b592600dfc99e634a083278af769a
+0, 6, 6, 1, 96, 7b02191f85590cbad3f148c7b92d6436
+0, 7, 7, 1, 96, b0a1c9870447a1744f64cd4087ef55ee
+0, 8, 8, 1, 96, c82712b1ba7a95efb67cbdde0ad708b6
+0, 9, 9, 1, 96, 89f4539f8d7a7b45a91fd2f46335988e
diff --git a/tests/ref/fate/vp9-02-size-08x10 b/tests/ref/fate/vp9-02-size-08x10
new file mode 100644
index 0000000000..0d8c0d8e98
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-08x10
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 120, ea3e0f807304b0eb2d3e329b0124f75c
+0, 1, 1, 1, 120, 8d13cf682d63e7eb13094f55d67fc458
+0, 2, 2, 1, 120, e729cc6c3684c94a8f6118c618efc3ea
+0, 3, 3, 1, 120, ac43a0ace8e4112e877c2491ecc14fb5
+0, 4, 4, 1, 120, 53695f90b88d8e8cb838f0faec3238d3
+0, 5, 5, 1, 120, 40afd1c4dfd4a2e3b31631c46d252bcc
+0, 6, 6, 1, 120, 2b656f76f2e84d2f82d9bda2b5be94d3
+0, 7, 7, 1, 120, b22f004d678d047bc401be5e040cf883
+0, 8, 8, 1, 120, 57c840319abfb9c31013fbde54de3fb0
+0, 9, 9, 1, 120, 0f3dfc156216d7cfb6fd1d8c77dadab9
diff --git a/tests/ref/fate/vp9-02-size-08x16 b/tests/ref/fate/vp9-02-size-08x16
new file mode 100644
index 0000000000..5bdc9f78b7
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-08x16
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 192, 0553e56a9d89aea496421885aab491f5
+0, 1, 1, 1, 192, b2a14cf676f7ebf3c50450050f76ad16
+0, 2, 2, 1, 192, a308d981e09b50571fb0c8ebdcefe505
+0, 3, 3, 1, 192, d592ec625a0ac0373e82610c3eed9864
+0, 4, 4, 1, 192, acd19642455e643023b4fb882c3891ba
+0, 5, 5, 1, 192, 5af5390fd8c29b795e0ddf83f3f34284
+0, 6, 6, 1, 192, 473505aa2a76231725cf2107d6c9dbef
+0, 7, 7, 1, 192, 84860db6887e320f2d64f80cf0032e57
+0, 8, 8, 1, 192, 408e9cf60e99ae99d204ff08f3196d1a
+0, 9, 9, 1, 192, d8af96b79258f9382e911ed38340bdf5
diff --git a/tests/ref/fate/vp9-02-size-08x18 b/tests/ref/fate/vp9-02-size-08x18
new file mode 100644
index 0000000000..a4aa018686
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-08x18
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 216, 4c41f93b1b280b37bc77d7047435eaa4
+0, 1, 1, 1, 216, c9c80fdba2ebc2b8c3490ae35e34f84f
+0, 2, 2, 1, 216, 089d86acb3263fa5ef4f591a7f44556d
+0, 3, 3, 1, 216, 938fca6d93b83484144f5054e4838a41
+0, 4, 4, 1, 216, e0592e2ac9f5e09525ce0d3904cadf47
+0, 5, 5, 1, 216, ea43ff5d1330986e60c08567262ea764
+0, 6, 6, 1, 216, 08b40fe109ee90188f1cba9bbb1b376e
+0, 7, 7, 1, 216, b067068a2a7e36d5c5b5b405a1e73a18
+0, 8, 8, 1, 216, 9cf2d350296288803434b7451bd2be85
+0, 9, 9, 1, 216, 3c785e21dc228d6396738fbfcb470289
diff --git a/tests/ref/fate/vp9-02-size-08x32 b/tests/ref/fate/vp9-02-size-08x32
new file mode 100644
index 0000000000..2d72ba3617
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-08x32
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 384, f92a7777fd69aa2f2914d9a41c4828ba
+0, 1, 1, 1, 384, 62e1cc73487d2249a88a60e35a22d9c7
+0, 2, 2, 1, 384, aa2619b605cb65eda15fdd99d5775550
+0, 3, 3, 1, 384, e6f0a491c543b835d0cefe5ca62c3dbe
+0, 4, 4, 1, 384, 361be1a06913c398f09494ca1b2d288f
+0, 5, 5, 1, 384, 0497bf849a973357c0ccb8d43f5bd8b4
+0, 6, 6, 1, 384, 5ac6ac523147c409dd00820622161dd7
+0, 7, 7, 1, 384, 7d07245574a46c524360f09be29a5f19
+0, 8, 8, 1, 384, fcfa7fbcaf42f81e4e34a4ee5a029ca1
+0, 9, 9, 1, 384, 336e3fe4f15d3d6c82d82b1855dcfeb4
diff --git a/tests/ref/fate/vp9-02-size-08x34 b/tests/ref/fate/vp9-02-size-08x34
new file mode 100644
index 0000000000..102eb47034
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-08x34
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 408, f3f2cd8f157466ff23dace85d77367ce
+0, 1, 1, 1, 408, 639d9b70a14062e95559c12d2b597f91
+0, 2, 2, 1, 408, b2ee07a6656af583f19593229fa11848
+0, 3, 3, 1, 408, 74e3b5ab4c798a0afe745694e871bbd5
+0, 4, 4, 1, 408, 35f1c30d0f8678f319a392a6c53b5989
+0, 5, 5, 1, 408, 07e2b4c0b92a394bfb11124fe80476f0
+0, 6, 6, 1, 408, 7864bd20dfc5280e5f027d67ea22bf30
+0, 7, 7, 1, 408, 10a2925a7b91dfa9b82de76069388fd4
+0, 8, 8, 1, 408, 79cc7f7a149e8d6e04e065f75e63733c
+0, 9, 9, 1, 408, 6453d10d97532d9bb03f7c06cba9fca0
diff --git a/tests/ref/fate/vp9-02-size-08x64 b/tests/ref/fate/vp9-02-size-08x64
new file mode 100644
index 0000000000..d4f827a9ab
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-08x64
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 768, 764bd02b781a38c621a109c12f3d9393
+0, 1, 1, 1, 768, 79496bd2b9212026af816b3b7a0587d5
+0, 2, 2, 1, 768, 2a3afd47ba3d075033fd94d5c3746c45
+0, 3, 3, 1, 768, fca00cad8d37a6646337baebadd0ca31
+0, 4, 4, 1, 768, aca376fb3f8a5ef670ecc2430037262a
+0, 5, 5, 1, 768, 7e6c8d96d1e24855c3e380f1bf2ce02c
+0, 6, 6, 1, 768, 09e051241972969d439f27f324d78490
+0, 7, 7, 1, 768, 2566b2a425caaba41305bf04ff10ea01
+0, 8, 8, 1, 768, db3995bedee42ada1b4ee63c339daf1b
+0, 9, 9, 1, 768, b00b8f1bf4fd907f0487738f5b5442c6
diff --git a/tests/ref/fate/vp9-02-size-08x66 b/tests/ref/fate/vp9-02-size-08x66
new file mode 100644
index 0000000000..675e0f2c2b
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-08x66
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 792, df20e8df89449fe50bb610e95a449a95
+0, 1, 1, 1, 792, 18f1a66d463274d1b0489f3a50e86857
+0, 2, 2, 1, 792, b0cc102875a94c9a92e53826617adbe9
+0, 3, 3, 1, 792, dfece7c17b4b149283ef51bdc1bd440e
+0, 4, 4, 1, 792, 6e346884f67be259fcabe493109cb63c
+0, 5, 5, 1, 792, 6d282127311eb2d958377490d7cb77f0
+0, 6, 6, 1, 792, 637ac8b14ca5ddbaf7b8910406c3cd08
+0, 7, 7, 1, 792, e7980f3fcb36969da0d218c4389fa9e8
+0, 8, 8, 1, 792, 730a1c95b9fb165f6e1a2f33a0d25de0
+0, 9, 9, 1, 792, 7bd8424d0783b1c8ad617e17408371bb
diff --git a/tests/ref/fate/vp9-02-size-10x08 b/tests/ref/fate/vp9-02-size-10x08
new file mode 100644
index 0000000000..d4fa723647
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-10x08
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 120, e1e66a88615da98523ef887f1463fc42
+0, 1, 1, 1, 120, 549842fa98c8faf572882d38b0aae390
+0, 2, 2, 1, 120, 17ee85785517705fdc78c6122a4b2548
+0, 3, 3, 1, 120, 1143391d419dac30a6c11f366157c974
+0, 4, 4, 1, 120, b62d2a962c4c36809ef75a610106715c
+0, 5, 5, 1, 120, e6f143ca33fbc0e776bb149950cdedff
+0, 6, 6, 1, 120, 01716a1077ec66df00474fd4510d2789
+0, 7, 7, 1, 120, 8cb5b6a865fa2cbb15f0d7736fda88a6
+0, 8, 8, 1, 120, 0fb9fd883e895a540fe1704dddbbab04
+0, 9, 9, 1, 120, 150a3b99aa24ef102c92f87c8adb4386
diff --git a/tests/ref/fate/vp9-02-size-10x10 b/tests/ref/fate/vp9-02-size-10x10
new file mode 100644
index 0000000000..d46eaa0afd
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-10x10
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 150, 083d638f2e147295d817bb14fff5e4f4
+0, 1, 1, 1, 150, 6dbdc445b6fd6bb99f2025cc2a40977e
+0, 2, 2, 1, 150, 41714089383b181d64fbfa7de5904608
+0, 3, 3, 1, 150, 11fdb8465e1599f7a9227706646d2cba
+0, 4, 4, 1, 150, 907876b3342a10040db0851a936af4e3
+0, 5, 5, 1, 150, e7b18d47d06b25de205d873d3d941640
+0, 6, 6, 1, 150, 523ce7413c8da7f6a657a9b661f36c44
+0, 7, 7, 1, 150, 23caff863af875c66c903662a3e1e6a1
+0, 8, 8, 1, 150, ed4cc5557203e5b7a119112ee9ceb00b
+0, 9, 9, 1, 150, 4bb78a996be3188888d1c60e11a08e1b
diff --git a/tests/ref/fate/vp9-02-size-10x16 b/tests/ref/fate/vp9-02-size-10x16
new file mode 100644
index 0000000000..c66861ce1f
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-10x16
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 240, fab07d6209d2413e0a434e1aaaa12154
+0, 1, 1, 1, 240, f9ffffdb96f98527ba2e553d1265edbb
+0, 2, 2, 1, 240, 56a992264cf7da2b23dd97435e9d0365
+0, 3, 3, 1, 240, b1db980423d8004bd45a789b02b92a65
+0, 4, 4, 1, 240, b29496aedc7026566367b634f55ebb28
+0, 5, 5, 1, 240, 2bc9def672da4a2fc17cbd669e2b8081
+0, 6, 6, 1, 240, 8c54721514cdf577a52a8668b9135f13
+0, 7, 7, 1, 240, 2efab81d5e039d82b3bc7b0303b022c4
+0, 8, 8, 1, 240, bd0f42b91b5d126fd0baec765b1096ad
+0, 9, 9, 1, 240, c6bfea2735a629167bc6a7a7c76eb7f3
diff --git a/tests/ref/fate/vp9-02-size-10x18 b/tests/ref/fate/vp9-02-size-10x18
new file mode 100644
index 0000000000..8cee77d793
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-10x18
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 270, 0e9182e214aae732d94d007e5fe44888
+0, 1, 1, 1, 270, 2630e2674b5611d68218fddac08815e2
+0, 2, 2, 1, 270, d5cdd7d6a3de17939f60bb60ef6877da
+0, 3, 3, 1, 270, 29d1961096061029e78963fa82581eca
+0, 4, 4, 1, 270, 5c2629f8aa59757f6b4aafa9f6cbcba1
+0, 5, 5, 1, 270, 1f1a8b61e4fbd6222ddf42e9d0a07032
+0, 6, 6, 1, 270, cfb9771190ac2d0129907102d6abb63f
+0, 7, 7, 1, 270, cd98dd856ba573a26a943cbe53221f26
+0, 8, 8, 1, 270, ca13c161f067c4a4ce22bd58a2aca55b
+0, 9, 9, 1, 270, de4bd1a474a76a35b796a5fc45b4f893
diff --git a/tests/ref/fate/vp9-02-size-10x32 b/tests/ref/fate/vp9-02-size-10x32
new file mode 100644
index 0000000000..5736e55778
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-10x32
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 480, 622e6407a051ea08706394d03330ffbf
+0, 1, 1, 1, 480, 1841a0daf7c3ef7be94e01fdb1d3968a
+0, 2, 2, 1, 480, 37790e6cb2415f7add0ac5d3ab354755
+0, 3, 3, 1, 480, 91485880e17c292096a7335566d3648f
+0, 4, 4, 1, 480, eb6f74983d5fd13d6bd90afbce8836e1
+0, 5, 5, 1, 480, 0069ab5ff7f0d4d601f7d0f9b7a08338
+0, 6, 6, 1, 480, dbf04254765f7497070387e8c34895c6
+0, 7, 7, 1, 480, 410a9b2d9855b2c29618070994adae96
+0, 8, 8, 1, 480, 7e7f34effd90209f29f1b9ae01488b3b
+0, 9, 9, 1, 480, 471530f74082c01c9b0f1fcf3d240d77
diff --git a/tests/ref/fate/vp9-02-size-10x34 b/tests/ref/fate/vp9-02-size-10x34
new file mode 100644
index 0000000000..c41d03b03d
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-10x34
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 510, bfeeaf51f972fd0dfe9ee757083cbb54
+0, 1, 1, 1, 510, 10cd4ed6d762004846412d9cd0caa407
+0, 2, 2, 1, 510, 04cca4008d656ed180de88dd2ddb4f21
+0, 3, 3, 1, 510, ec777e377836895748c06849fa35ed2d
+0, 4, 4, 1, 510, b55633d0f9239dff3e45a4abce4a35a7
+0, 5, 5, 1, 510, 063c3ab4b4c599942c3a8a5b7bfe5029
+0, 6, 6, 1, 510, 07b920169d32b5fc51d5b9ae16fef5bf
+0, 7, 7, 1, 510, 8d49e727db9d3072b5ab7bab2133d9be
+0, 8, 8, 1, 510, 17441437203447e946a57d2f96966332
+0, 9, 9, 1, 510, 5d3f14af0e5cd81d0c7d2059f13efa5a
diff --git a/tests/ref/fate/vp9-02-size-10x64 b/tests/ref/fate/vp9-02-size-10x64
new file mode 100644
index 0000000000..eff631f2d4
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-10x64
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 960, 835254d0eecb17bed1f2b0f3a1638165
+0, 1, 1, 1, 960, c0c95ce9890eab339a0e0f8b26cb095c
+0, 2, 2, 1, 960, f0337d645ade07cb716952b0d19352e8
+0, 3, 3, 1, 960, 7e3deb21cb3f0ead90c8af94464cde14
+0, 4, 4, 1, 960, c6b1ca6cfce358c411c0637c581157c8
+0, 5, 5, 1, 960, 10fce3f11f1ce90286ff4d74fe44fcfd
+0, 6, 6, 1, 960, ee0565a1f121bc905a35550619127a50
+0, 7, 7, 1, 960, 0624b601d379616eb792c94be60b6c91
+0, 8, 8, 1, 960, a1bb79cdf347548f1103f580f2b6930f
+0, 9, 9, 1, 960, 40e96e16c7e065aa7932e5aa57f32398
diff --git a/tests/ref/fate/vp9-02-size-10x66 b/tests/ref/fate/vp9-02-size-10x66
new file mode 100644
index 0000000000..a138dba909
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-10x66
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 990, 1bd8b2d3bf679c4b925780bf82e12fae
+0, 1, 1, 1, 990, a0254b4cd4928fe1080cd6f8828288a9
+0, 2, 2, 1, 990, e416e99644cca481dc2806708d716ecb
+0, 3, 3, 1, 990, b1ed3203ffc77ed814f1cda7bfe721d2
+0, 4, 4, 1, 990, 0ff7b9d84765f7b0b0650775ba72b334
+0, 5, 5, 1, 990, 8b6cd91e035bad19b46b132bd411231d
+0, 6, 6, 1, 990, c714759a9a64402043ad00e5677c954c
+0, 7, 7, 1, 990, 8e4738010b724ce66bcd0a5d5afcfbc1
+0, 8, 8, 1, 990, 998a7aab8ed94f4b69bed39fb487f8d5
+0, 9, 9, 1, 990, 9964683a15a65c032631a4f608e6009b
diff --git a/tests/ref/fate/vp9-02-size-16x08 b/tests/ref/fate/vp9-02-size-16x08
new file mode 100644
index 0000000000..611e99d255
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-16x08
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 192, 68dccd167f9aa18df0840ebb8715eb68
+0, 1, 1, 1, 192, 65c90bb99fdbee7abf21031d34cb18dc
+0, 2, 2, 1, 192, 9ef1feb2dcbd4d73f3ee84e9e1cd2668
+0, 3, 3, 1, 192, b6281f7c88e9aa132d3902046f8cde5a
+0, 4, 4, 1, 192, 4b439b716a294bddf9f56a229705907b
+0, 5, 5, 1, 192, d42c0a6f0d24522c90bc2233bc1df2c7
+0, 6, 6, 1, 192, 74b763a5a12c4c4a581efb1818a92970
+0, 7, 7, 1, 192, 0c3a0916ddfda5abdd3ac382f036e71f
+0, 8, 8, 1, 192, 26ff590e8ae726f70e8b36f5eaee7a19
+0, 9, 9, 1, 192, 30fa5810995d7132387ea585c4a1cc3a
diff --git a/tests/ref/fate/vp9-02-size-16x10 b/tests/ref/fate/vp9-02-size-16x10
new file mode 100644
index 0000000000..766ad34c5f
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-16x10
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 240, fb3cad61d7d9eb511758dbf87dd8abe1
+0, 1, 1, 1, 240, 4fbc1aa5559c8db2930803893bd6ba75
+0, 2, 2, 1, 240, 2d8e2ee04dcc6097ca9e3f27070cdcc8
+0, 3, 3, 1, 240, 05d419f1322855ba3620665b68ce9910
+0, 4, 4, 1, 240, b004f8d88cb2c94f4e9a13cfa5bd480a
+0, 5, 5, 1, 240, 9d9dec90e2213c0411939131aa9adf7f
+0, 6, 6, 1, 240, a00874356ff1b1e9da1a400424661f8d
+0, 7, 7, 1, 240, fda587eb6323cd98c773f05905ac1794
+0, 8, 8, 1, 240, 781c63d221a04d8130806c799d16753a
+0, 9, 9, 1, 240, f346e311829f3789dc5a94da48ada5f4
diff --git a/tests/ref/fate/vp9-02-size-16x16 b/tests/ref/fate/vp9-02-size-16x16
new file mode 100644
index 0000000000..da038447a2
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-16x16
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 384, b5c9daafa548e54a8e33e9881fda33f4
+0, 1, 1, 1, 384, 1193acd7ea4b7aac968e35ef83c64378
+0, 2, 2, 1, 384, cd0e42c0b5a8b3be6f0e1d224062bf99
+0, 3, 3, 1, 384, ed79c71d17f68f86cbfa75ea2bfe97f3
+0, 4, 4, 1, 384, 1502a859c7e07b31faad5b80e3e27cf7
+0, 5, 5, 1, 384, df3f093da914ea947db93c3baa188ecb
+0, 6, 6, 1, 384, 480f86eb183b99277c1b38fdaafe2970
+0, 7, 7, 1, 384, 023e0114282e04963f0f52e00e65ac61
+0, 8, 8, 1, 384, e67f29cf0acc7f9b553458e1e5c59ebf
+0, 9, 9, 1, 384, a779a14ba718f0c1df8a7edc9467d12e
diff --git a/tests/ref/fate/vp9-02-size-16x18 b/tests/ref/fate/vp9-02-size-16x18
new file mode 100644
index 0000000000..789122f8e7
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-16x18
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 432, 5156b11cd9995d0c1638c9b0d2b0786c
+0, 1, 1, 1, 432, ef78557f93fb3ea770c7d49ab60edf21
+0, 2, 2, 1, 432, f31fb9bb14566e4538a45ac7bf398b2a
+0, 3, 3, 1, 432, 97633875537f76ade183e975fa91b0fb
+0, 4, 4, 1, 432, 602cf54f9af852175173c21abd63796f
+0, 5, 5, 1, 432, 0b3741a6842cb65d6d21eda891882033
+0, 6, 6, 1, 432, 44240a27a6b6d36c9661d499fb965f87
+0, 7, 7, 1, 432, 9050f263f9a4767f9323ec8aa42cf7e6
+0, 8, 8, 1, 432, 57fa3a8494375f588a95376bc0c3cb28
+0, 9, 9, 1, 432, 084595f2a65aa10e7d3845044a0e7213
diff --git a/tests/ref/fate/vp9-02-size-16x32 b/tests/ref/fate/vp9-02-size-16x32
new file mode 100644
index 0000000000..88bab47866
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-16x32
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 768, c73d611490a5ddec6c690589deaf5e86
+0, 1, 1, 1, 768, 5d8eaeb222aa64abda59ce7b09b2f6d9
+0, 2, 2, 1, 768, 34321856b8dd5bbb9b63db04d3532289
+0, 3, 3, 1, 768, 947337d2fec8a09242f60e31e99f4065
+0, 4, 4, 1, 768, bb7d92f6fc055f0cf0e97bd2be56cc9e
+0, 5, 5, 1, 768, 5d343c82bcdd0e9d08581043cddfd0ca
+0, 6, 6, 1, 768, 612ded93207712e4916d584cc4a7b87c
+0, 7, 7, 1, 768, 6ba5e0d19893e1b96f5ca86e0bfd7e18
+0, 8, 8, 1, 768, 336572e1dcb110b1eb87bea81e0752f4
+0, 9, 9, 1, 768, 705f73d0a39afce59ea571e68bfe25df
diff --git a/tests/ref/fate/vp9-02-size-16x34 b/tests/ref/fate/vp9-02-size-16x34
new file mode 100644
index 0000000000..79c278e1d1
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-16x34
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 816, b8bf711d9a1ce49180ed56407c8a4b0a
+0, 1, 1, 1, 816, 0457929b06ce46aec63d66bd38586e3f
+0, 2, 2, 1, 816, 3b5f417ee5a936797a6f0d138b8ed73b
+0, 3, 3, 1, 816, 5d1a42aeecfd5c8513cb2df94c206c8b
+0, 4, 4, 1, 816, a0ab2dddbc810a1667d779f6ed69d010
+0, 5, 5, 1, 816, b150cd7c4ec83e6f9d948e99d7465350
+0, 6, 6, 1, 816, ea39622ad21312bd8bcecdaf09aa18fb
+0, 7, 7, 1, 816, 467a42e1226a01c8ba244f312f588bab
+0, 8, 8, 1, 816, f2311e15228ffc7fd377b89c203d0fbf
+0, 9, 9, 1, 816, 5df58b3ac0a7856796a46f27be7dcf4c
diff --git a/tests/ref/fate/vp9-02-size-16x64 b/tests/ref/fate/vp9-02-size-16x64
new file mode 100644
index 0000000000..13e8ea19c5
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-16x64
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 1536, 925fdc485f3baa1ed145ae391519d7fd
+0, 1, 1, 1, 1536, d37af656da2d7a727c8451773495d5ed
+0, 2, 2, 1, 1536, 8a0f207a99e46f3d3b2aaa3f1b061981
+0, 3, 3, 1, 1536, a3914c7b739d3af2641fd6aae35428ef
+0, 4, 4, 1, 1536, 0ba3b49970d7b029f2dfa991fdfc6e61
+0, 5, 5, 1, 1536, 55838d1d787dc5a4fa4da2994f04587f
+0, 6, 6, 1, 1536, c089f7ba2b2983df2a4dc2e07798af31
+0, 7, 7, 1, 1536, c23dcb3b109543a61ccfa404a726caae
+0, 8, 8, 1, 1536, 01aaf09960f5ca599ca32768f017d0c9
+0, 9, 9, 1, 1536, 79fe955692ecba8bbb00b20a42ca8104
diff --git a/tests/ref/fate/vp9-02-size-16x66 b/tests/ref/fate/vp9-02-size-16x66
new file mode 100644
index 0000000000..1b4b3d7ff6
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-16x66
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 1584, c7b0d91f362dff0a581434af6e902d43
+0, 1, 1, 1, 1584, d8b016ef59c6bc193b29d1c714f342c1
+0, 2, 2, 1, 1584, c520bd8d4b81aafc7687befff66c7396
+0, 3, 3, 1, 1584, 92e81bbd3af675c9cdb1cb00d03dabe1
+0, 4, 4, 1, 1584, a271db3defe5daa6d9e0a73a580f4f88
+0, 5, 5, 1, 1584, 4077e857321e241bb98dfd89c0aca46f
+0, 6, 6, 1, 1584, 0466e1453a94baf876e9f64b60235300
+0, 7, 7, 1, 1584, 9d2cb9c7b180d44841e0e4d8a595d912
+0, 8, 8, 1, 1584, 500f443eeb0ecef47c34d1e91f0df6ce
+0, 9, 9, 1, 1584, 83354487982915c33b1c6243d80adaeb
diff --git a/tests/ref/fate/vp9-02-size-18x08 b/tests/ref/fate/vp9-02-size-18x08
new file mode 100644
index 0000000000..249640ba58
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-18x08
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 216, 3219af4ef540636b0f67a989e9966059
+0, 1, 1, 1, 216, 1a3655c2cfd2ee332bc89da5b3faf778
+0, 2, 2, 1, 216, d638d5b361a6d81440e26993ed86c97d
+0, 3, 3, 1, 216, d9bc2e7cffd66db4ba9dcbce99448d4d
+0, 4, 4, 1, 216, 399f962e0a0573915bc4da4a9f1effcf
+0, 5, 5, 1, 216, 69d917e19b903e4f07f848e9e557bbe7
+0, 6, 6, 1, 216, d6311488a58acf6eb0cc45bc4fe3c2da
+0, 7, 7, 1, 216, 0ce360a84d5755307f98d65c83f190e1
+0, 8, 8, 1, 216, 2554828e6dbf94424ccac30fb153872e
+0, 9, 9, 1, 216, 598a55f9735e85b8d45105dd6be7f97b
diff --git a/tests/ref/fate/vp9-02-size-18x10 b/tests/ref/fate/vp9-02-size-18x10
new file mode 100644
index 0000000000..6678d1febc
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-18x10
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 270, bf574489e9360b6475aa012c747e7924
+0, 1, 1, 1, 270, 851100301c2937312a6fd32f5aab5a09
+0, 2, 2, 1, 270, 0f7c1209e44ea7cd4df12d82f9224684
+0, 3, 3, 1, 270, 28d121f9c40de5280435bfdeaec0c072
+0, 4, 4, 1, 270, bb00898d03ce4dff5f7bee719dd3f5b5
+0, 5, 5, 1, 270, a098cc66bc25b81f84b0e930b0915cdb
+0, 6, 6, 1, 270, 81e25f19bfcbfce17bd7138eedae04ee
+0, 7, 7, 1, 270, 69c36c5ce555a461f16a1733450f7258
+0, 8, 8, 1, 270, c95236d9e7c624bb664310bd9ef47fb4
+0, 9, 9, 1, 270, 7ab0942e686939951037314e9402d2c1
diff --git a/tests/ref/fate/vp9-02-size-18x16 b/tests/ref/fate/vp9-02-size-18x16
new file mode 100644
index 0000000000..09d266e91a
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-18x16
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 432, 9535aaa2ea26fbdc16e7fe9cba3fc9b4
+0, 1, 1, 1, 432, 7f6e7ca33c0b27ff052dc2ab6721e37d
+0, 2, 2, 1, 432, d37e3f169457a9c7f2a197353e39d3d6
+0, 3, 3, 1, 432, f26d7d81dd81d051680ea2485e812705
+0, 4, 4, 1, 432, 704b01955ced6d101b9e9315d3327f28
+0, 5, 5, 1, 432, 30d46d6a0f6be383dede451cacf465f4
+0, 6, 6, 1, 432, 83c7ed04f0af61ec665041967cbce05d
+0, 7, 7, 1, 432, 152daf37dd37607886c50dd4c7796357
+0, 8, 8, 1, 432, 609d807351ba74b1c432e3d0516add91
+0, 9, 9, 1, 432, 67953f0c735984232cb6782217cdcdf6
diff --git a/tests/ref/fate/vp9-02-size-18x18 b/tests/ref/fate/vp9-02-size-18x18
new file mode 100644
index 0000000000..fb2322aa92
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-18x18
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 486, 83790b0e7004d8d89b7134ee1a88d885
+0, 1, 1, 1, 486, 0baf0bf556ae56d2f4b04567e6ac7ed9
+0, 2, 2, 1, 486, c648854a4d49f7e407a2450cf4ba292a
+0, 3, 3, 1, 486, 510c3aca23339841ffc72ed5c75d184e
+0, 4, 4, 1, 486, 1c1f3116ec4d4ee1ad790652e49233ad
+0, 5, 5, 1, 486, f94891f4e16fd32d638a2c696f5922e6
+0, 6, 6, 1, 486, e164814c22e38cbe45312dfd48d987fc
+0, 7, 7, 1, 486, f582515fcc6c4308ad931d2f6cf371a0
+0, 8, 8, 1, 486, 0a446974bd227ee34a1621a2b7852abb
+0, 9, 9, 1, 486, beca28bdae8d1fe20036b3646f3109cd
diff --git a/tests/ref/fate/vp9-02-size-18x32 b/tests/ref/fate/vp9-02-size-18x32
new file mode 100644
index 0000000000..e528048c2a
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-18x32
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 864, 62eabc8819ded6ddba2c3a5029497cf0
+0, 1, 1, 1, 864, b760182fddf8bc05f149e80bbcb2c281
+0, 2, 2, 1, 864, 0c44be0472ebd2653ce9fb174c6180ab
+0, 3, 3, 1, 864, bbb033c3bfeeb6f59cb43013597b9d92
+0, 4, 4, 1, 864, a769975cdbc6529525f7cac8a0d9299a
+0, 5, 5, 1, 864, 15b02059bbced62f19c0626efea1ecb9
+0, 6, 6, 1, 864, 47f4b50322ed31649bdcfffb05c70fa2
+0, 7, 7, 1, 864, 8649cdd0a958047839f5b6e7bbf6f288
+0, 8, 8, 1, 864, 2c766e3fd3882a9a5aff52ffe9d1d341
+0, 9, 9, 1, 864, 184a62b7332a1c24acbf03f670fb7ac1
diff --git a/tests/ref/fate/vp9-02-size-18x34 b/tests/ref/fate/vp9-02-size-18x34
new file mode 100644
index 0000000000..c6ddbbddf5
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-18x34
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 918, 612cc424eaae924cb25c7732c422f752
+0, 1, 1, 1, 918, 010e8c2a814862529fcf8d7771ba2d7f
+0, 2, 2, 1, 918, 7d791b7a5916738998f77586339d5840
+0, 3, 3, 1, 918, aeada5f59f3dda9ab3e898f305428cb2
+0, 4, 4, 1, 918, 06af894d38a1f0d3665c0081f5397ddf
+0, 5, 5, 1, 918, 24bf31323c568e652550e9d35de9c96c
+0, 6, 6, 1, 918, a9681ec47d3e6a19321b9ea47221dc3f
+0, 7, 7, 1, 918, 73ae7268df79c4012952bd3e8011e894
+0, 8, 8, 1, 918, 67aa4145398ca17036959251cb4ce17b
+0, 9, 9, 1, 918, de247b80114c722da849f5aa23adbb38
diff --git a/tests/ref/fate/vp9-02-size-18x64 b/tests/ref/fate/vp9-02-size-18x64
new file mode 100644
index 0000000000..99ec59e7d9
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-18x64
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 1728, 72c74de547d9ed1b17bc962dbd5e0bb1
+0, 1, 1, 1, 1728, 462849f9e2204738e9f08b40e682a6ae
+0, 2, 2, 1, 1728, f0ee17692fd816747b11d5737b511cda
+0, 3, 3, 1, 1728, 0234d23406660ede76dd22b35a708390
+0, 4, 4, 1, 1728, 6544fdb9dc225d155820d3c7dfc909eb
+0, 5, 5, 1, 1728, 1c073544794389596177512fb4dcffce
+0, 6, 6, 1, 1728, 864709daac7b091d33afa2210c145084
+0, 7, 7, 1, 1728, b049c4ac941743613ede9a41b16acde5
+0, 8, 8, 1, 1728, ad0c4adb0efec03729a79f42eec66267
+0, 9, 9, 1, 1728, 146057d941f5a47eb8b2c9eefeaf3100
diff --git a/tests/ref/fate/vp9-02-size-18x66 b/tests/ref/fate/vp9-02-size-18x66
new file mode 100644
index 0000000000..e8cf87c84c
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-18x66
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 1782, c3fc4a1593b9cc2f3752106af8539386
+0, 1, 1, 1, 1782, 7f2ffe6bc1750f6749bb5ad12cbaf34b
+0, 2, 2, 1, 1782, 2539b10a981d59ef54efd77cd7276aaa
+0, 3, 3, 1, 1782, 0bff22b4dfb7485fbedd6ff5b99673d1
+0, 4, 4, 1, 1782, 6a2b38f4abee785260a61bc60f16e7fa
+0, 5, 5, 1, 1782, 2fbb69b5519b51548bf1ee425ff79c55
+0, 6, 6, 1, 1782, dbd267028be2256111b2411b91fcc117
+0, 7, 7, 1, 1782, 12b2f1003633c9e19cae3d0fda06102d
+0, 8, 8, 1, 1782, d419a756c492867523af5185fd57d989
+0, 9, 9, 1, 1782, 8a7d36760bf5db32baef349b97316b47
diff --git a/tests/ref/fate/vp9-02-size-32x08 b/tests/ref/fate/vp9-02-size-32x08
new file mode 100644
index 0000000000..ffc678f0de
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-32x08
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 384, c7b30cde5664387b0f7a80d9b01e4fe2
+0, 1, 1, 1, 384, 2228a2a4e54ab5145525e5803c314dcd
+0, 2, 2, 1, 384, 8c048469eba24f3163c36b7461b3b42a
+0, 3, 3, 1, 384, f6b8e8e701dea09dcf1158e9a52921c6
+0, 4, 4, 1, 384, b3a5fde0daf2eef8fc08521f88f79692
+0, 5, 5, 1, 384, 653ae11cc1380ae7f39b2e007f896d81
+0, 6, 6, 1, 384, 6e66fe002a7dff95e13cc9d3d13d9686
+0, 7, 7, 1, 384, 13308c917a1e22c2f702afc32b8a23c2
+0, 8, 8, 1, 384, 4fee1e63f9452dc3f81c1d634bd7f41d
+0, 9, 9, 1, 384, 666b43ead5c7c99ae5b7637da5aa4d62
diff --git a/tests/ref/fate/vp9-02-size-32x10 b/tests/ref/fate/vp9-02-size-32x10
new file mode 100644
index 0000000000..0469c7cab6
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-32x10
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 480, 7c5b5df373ebfd31d210ff910e02213b
+0, 1, 1, 1, 480, c5b0a5e3eceb792b15818324a43aa2a8
+0, 2, 2, 1, 480, 1d9c0eafd4638dfe4fe308174fde2faf
+0, 3, 3, 1, 480, 47301d12055944b35008028761cf5e7b
+0, 4, 4, 1, 480, 9586ac1087423dcd3b0ff96d43ae475e
+0, 5, 5, 1, 480, 26bfe1afea96c7ef2084fffd1fa99a33
+0, 6, 6, 1, 480, 0995c8a1935266159a7ef3f95d7f4697
+0, 7, 7, 1, 480, 8cfcc0ea67507ab7f3551d8ac50f93a5
+0, 8, 8, 1, 480, 658cf3cb887b055d9de7d50db4eb78a9
+0, 9, 9, 1, 480, 856bd5189688f7ccfe9995752bc0f1f6
diff --git a/tests/ref/fate/vp9-02-size-32x16 b/tests/ref/fate/vp9-02-size-32x16
new file mode 100644
index 0000000000..76f7860b38
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-32x16
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 768, 7c2818db2632e5c5beee17e7105d9209
+0, 1, 1, 1, 768, cead72bd22995e98b54a91c7b4a20975
+0, 2, 2, 1, 768, eb6baee5d65d778052c88ba5db2f9174
+0, 3, 3, 1, 768, 1f5f38e89e985e9e4172446de05e91fd
+0, 4, 4, 1, 768, 57b57ffcb03627942fc5868324a10feb
+0, 5, 5, 1, 768, 4b4066a452d8e9cd687cd611f5d9cb88
+0, 6, 6, 1, 768, 113e5069b2a4d2c2e802b72649eb435d
+0, 7, 7, 1, 768, e176bb233f76f9fd4c55d62d53487b60
+0, 8, 8, 1, 768, f2ff3def712a846ea7b678bd9078e32b
+0, 9, 9, 1, 768, 21007ed1c727c5ccc5955188a2cec276
diff --git a/tests/ref/fate/vp9-02-size-32x18 b/tests/ref/fate/vp9-02-size-32x18
new file mode 100644
index 0000000000..08201dbd2c
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-32x18
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 864, 9da5409d344e7b8380688569e54803a5
+0, 1, 1, 1, 864, 9b51e14e2e624ee2b430e9eaf1a48798
+0, 2, 2, 1, 864, b8811779f363b9a595e3a92737771ea9
+0, 3, 3, 1, 864, e5a0c335e5e713a3e77fff0b65127fb9
+0, 4, 4, 1, 864, 1bffa3283b463a356794c8f7a73f8c54
+0, 5, 5, 1, 864, 97c13270621a583eb9e13c05f9d792f0
+0, 6, 6, 1, 864, a6f81a4dde1ffc352ebe9d8ab8782f35
+0, 7, 7, 1, 864, 91a955a86ce9378ff3442794ce0934c6
+0, 8, 8, 1, 864, 2e4f8938e9c88b328a258a0b99366ea6
+0, 9, 9, 1, 864, adbbbc192cf36e1fc7c308824765d482
diff --git a/tests/ref/fate/vp9-02-size-32x32 b/tests/ref/fate/vp9-02-size-32x32
new file mode 100644
index 0000000000..01f414f008
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-32x32
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 1536, 117915db1856cee26f05a609c8c8de2e
+0, 1, 1, 1, 1536, 943771a98b26b174e88ed1f4e872e504
+0, 2, 2, 1, 1536, 3e0d2585e1f1cb540998d107aca5c395
+0, 3, 3, 1, 1536, e64a9e1e0232983a69ab48453025b23d
+0, 4, 4, 1, 1536, 2c6ef6637fb7b9425f7d7ea28cd84087
+0, 5, 5, 1, 1536, 419a5a31a43955d408c13ee8a5ddce9c
+0, 6, 6, 1, 1536, 2ab13e1c236553d42d59498ca350b190
+0, 7, 7, 1, 1536, b8068beb037f3232d4da38fe33a8a885
+0, 8, 8, 1, 1536, 160df68b9e3f75e9b1f8ed7cce327bc2
+0, 9, 9, 1, 1536, 1ccafa8c7babdce0983aeb20d298b0ee
diff --git a/tests/ref/fate/vp9-02-size-32x34 b/tests/ref/fate/vp9-02-size-32x34
new file mode 100644
index 0000000000..efbe8471e0
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-32x34
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 1632, 770582911fd0095ebbeae384e87665ac
+0, 1, 1, 1, 1632, f99d7e3131f04413cba2f9de6818976d
+0, 2, 2, 1, 1632, 3bfbb8c9c48f24cd596973a6deb33a3f
+0, 3, 3, 1, 1632, 0b8166afdd357f20c76f77d228bb7171
+0, 4, 4, 1, 1632, 3a3d7f2a03e19a82250d6ca0238f9791
+0, 5, 5, 1, 1632, 9b558f9b8744b016059f69f3fca90d2c
+0, 6, 6, 1, 1632, c857736342f1145d919cb77732120006
+0, 7, 7, 1, 1632, 11dc5dda4c883a3146db060dd50343d0
+0, 8, 8, 1, 1632, 7526a62ae87de174be86eac7bb36c7f3
+0, 9, 9, 1, 1632, 9ef38f47cfc461710ff0dd75690473c0
diff --git a/tests/ref/fate/vp9-02-size-32x64 b/tests/ref/fate/vp9-02-size-32x64
new file mode 100644
index 0000000000..d14a6a4f5f
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-32x64
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 3072, caa8471a8b381d53c3e8fc627946a871
+0, 1, 1, 1, 3072, 2cba86ea14c0f28e242625b08f5e9b88
+0, 2, 2, 1, 3072, cea0440ff6569fc82c3030e0340fb649
+0, 3, 3, 1, 3072, c18ef37f1356ade96a2f40af954b31c8
+0, 4, 4, 1, 3072, 21e6e549378bcff47913ef292e74dc37
+0, 5, 5, 1, 3072, a9d3d483f74a5afe5d80725ce696fd20
+0, 6, 6, 1, 3072, a436e2586b0963747deaf5e450e2b230
+0, 7, 7, 1, 3072, 9daaadf265df56974cb0950843d9fd8c
+0, 8, 8, 1, 3072, e0b84714bad2519e62b7d16705fb09d5
+0, 9, 9, 1, 3072, 8cdfce574edbe548da7f6cd9a7076b9e
diff --git a/tests/ref/fate/vp9-02-size-32x66 b/tests/ref/fate/vp9-02-size-32x66
new file mode 100644
index 0000000000..4e8c4264a2
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-32x66
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 3168, 920ea4b8a00d41489d122d641d6e4fe5
+0, 1, 1, 1, 3168, 8bfc8d452a79f2978b8e973b77cbf8a8
+0, 2, 2, 1, 3168, 09f3f0d31d3377a844fa5385d9b36b9f
+0, 3, 3, 1, 3168, df43fae763da9360c8062bb92ee091a8
+0, 4, 4, 1, 3168, 445d8c675bb865d1814fcfa6b8a9afd3
+0, 5, 5, 1, 3168, dc7d43db86aac6636724de8790eda555
+0, 6, 6, 1, 3168, d3a9fc272424449ffc5b7e69f8f9948b
+0, 7, 7, 1, 3168, 11ef33b9bccca54b3703bf24ab55e2d6
+0, 8, 8, 1, 3168, ce31b8bf9b00b427ca956abb800d8034
+0, 9, 9, 1, 3168, e707f824d6e95d482bf3a0b4d52ea069
diff --git a/tests/ref/fate/vp9-02-size-34x08 b/tests/ref/fate/vp9-02-size-34x08
new file mode 100644
index 0000000000..23fa1ee475
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-34x08
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 408, c14f2ba5b4582c9d3a488976814691b3
+0, 1, 1, 1, 408, 4387a4dce19007b7efb810b5a4069749
+0, 2, 2, 1, 408, ecfe868d28f4861a5612edfd57447a02
+0, 3, 3, 1, 408, 5cba54f568534d29169ac31c8fa505e0
+0, 4, 4, 1, 408, fe9aab7b3378b9fc3e373ee626b887db
+0, 5, 5, 1, 408, fce72dfc7f9c0cb50ff73761b4d82c1f
+0, 6, 6, 1, 408, d4d98f42b1377e0f0ffaa66aa81d40c3
+0, 7, 7, 1, 408, 65c027646dc95a749ce2d7ad0a6beccc
+0, 8, 8, 1, 408, 317b283a0d907270f671272771022e69
+0, 9, 9, 1, 408, d3e2c008584608502f3e24c5c5f64028
diff --git a/tests/ref/fate/vp9-02-size-34x10 b/tests/ref/fate/vp9-02-size-34x10
new file mode 100644
index 0000000000..b7aad337b2
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-34x10
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 510, fd7212b519783cf4831ce4bff91f2312
+0, 1, 1, 1, 510, 9768722ee939d80a6716865fdebca33d
+0, 2, 2, 1, 510, 328ee0f774eeafde00dcc4b9a8f4e9af
+0, 3, 3, 1, 510, f882fa6015fcb042094eadab5fa952cf
+0, 4, 4, 1, 510, 4331a3dabeae27d2bf3590eb96ce914a
+0, 5, 5, 1, 510, 0e15106bd8e90377f6ed8b464d17159c
+0, 6, 6, 1, 510, 8f062653ac2b83f7e541393e838d0e0f
+0, 7, 7, 1, 510, eeb98c1728c1a74510f8bfaf10fc0002
+0, 8, 8, 1, 510, 30bb058a67d6a5ee3693b21cbca5349a
+0, 9, 9, 1, 510, 7ce4b79983b3abc37b141a3bea56e0b7
diff --git a/tests/ref/fate/vp9-02-size-34x16 b/tests/ref/fate/vp9-02-size-34x16
new file mode 100644
index 0000000000..6630d732d8
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-34x16
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 816, e443c43101be00470c6a61c1a2995b5a
+0, 1, 1, 1, 816, 1e79b1b46ec704d360b5fb725913b0f1
+0, 2, 2, 1, 816, 6d5e77cafab6bc43498980c515d299d3
+0, 3, 3, 1, 816, 91c3bba5fd2aa29ee54c8f3783cfe5a2
+0, 4, 4, 1, 816, 9548d07c2a6204694d34e973e8339077
+0, 5, 5, 1, 816, 6819a34c7e3c13bee3ea2b18e12e92fd
+0, 6, 6, 1, 816, f75920457f01f65bf30ba1ec41076d4e
+0, 7, 7, 1, 816, 3a04f6cc0c348c21464b173ac6005043
+0, 8, 8, 1, 816, 93a3336374e8cc4dfb2c0b4716ab60ec
+0, 9, 9, 1, 816, 148af188b8a2ee93de406a01c2af180d
diff --git a/tests/ref/fate/vp9-02-size-34x18 b/tests/ref/fate/vp9-02-size-34x18
new file mode 100644
index 0000000000..787f4ff9eb
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-34x18
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 918, ab7eabb355e5163e7451945018fadebd
+0, 1, 1, 1, 918, b9a77cc0c769535808996a6de7b374ff
+0, 2, 2, 1, 918, bd773f11d89091b3c9ebc22d8291dd49
+0, 3, 3, 1, 918, 278c215d6c188752818f07f4d317c0e0
+0, 4, 4, 1, 918, b59856932c675c1ba587644c23cdb002
+0, 5, 5, 1, 918, 2bcaef04f89326a56025269a68742043
+0, 6, 6, 1, 918, 5abb4a1b96b4bc003cd19a146347c54e
+0, 7, 7, 1, 918, 26e36058f451ff80d498ac1c0343489f
+0, 8, 8, 1, 918, 57ac43fcc6f1a2c863188aca68d52524
+0, 9, 9, 1, 918, 282467118b5b7a986ccd28d16dab3ea7
diff --git a/tests/ref/fate/vp9-02-size-34x32 b/tests/ref/fate/vp9-02-size-34x32
new file mode 100644
index 0000000000..242e9ef462
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-34x32
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 1632, 7e334867e27046fabf0f39365311c38c
+0, 1, 1, 1, 1632, d2a49216ecedea62f546e54c1552f163
+0, 2, 2, 1, 1632, f66e10d1779533e5b6e2b98369134833
+0, 3, 3, 1, 1632, 0054b8d4393df58eee87784862a29901
+0, 4, 4, 1, 1632, b9cdf3ebea0d1e3f1e0c42db2e11a3c2
+0, 5, 5, 1, 1632, c08a728d955a559457c82e44c3296148
+0, 6, 6, 1, 1632, d05f4c4a8b0e606525c3d388d26a9351
+0, 7, 7, 1, 1632, 78fc2544da88a1a21d6626b0f7bbcf8c
+0, 8, 8, 1, 1632, 90832c4fed05390377551359bb9a91f7
+0, 9, 9, 1, 1632, 5290a0e77081863398f36c7ae192710b
diff --git a/tests/ref/fate/vp9-02-size-34x34 b/tests/ref/fate/vp9-02-size-34x34
new file mode 100644
index 0000000000..10ae9c27d0
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-34x34
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 1734, 1bb98ba89abf6b86f47a851f8126e1ff
+0, 1, 1, 1, 1734, b960cc795c179afe7eec360c57fddd7f
+0, 2, 2, 1, 1734, a93cd094a80c542ecb7b6ac7720c5eff
+0, 3, 3, 1, 1734, f1cd34e4f0bf9b1238769f028708b742
+0, 4, 4, 1, 1734, f01437ad14450d2136a8fc971f180eb7
+0, 5, 5, 1, 1734, 8778230f1182c2227bf1e253bd85df4c
+0, 6, 6, 1, 1734, 1d1d5cf6c5cc9e73a1fa5b882e441d74
+0, 7, 7, 1, 1734, 2f7a1867487c56c252e35225f71adb55
+0, 8, 8, 1, 1734, 1d1aea21f70ceed596f22ec32d8712ee
+0, 9, 9, 1, 1734, 260e66df92f32bc853f4cd4ede692ea4
diff --git a/tests/ref/fate/vp9-02-size-34x64 b/tests/ref/fate/vp9-02-size-34x64
new file mode 100644
index 0000000000..432f93cbfc
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-34x64
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 3264, 3856635223f578e1e7f7e7250a53cb8d
+0, 1, 1, 1, 3264, ee8d7c3a0ea165420d7e733b9e59219a
+0, 2, 2, 1, 3264, 3d33f06bac22131f04e3411fc216dc02
+0, 3, 3, 1, 3264, 7aea667775077de32250dac25fd24bb3
+0, 4, 4, 1, 3264, 43fb534551f153c5e9e60240df0bf3b4
+0, 5, 5, 1, 3264, d42b721aa2242d4258d97f840fdcc901
+0, 6, 6, 1, 3264, e876200d720cbe6e36e0ffb775c5ad6c
+0, 7, 7, 1, 3264, 453078449d8701270564086e58a1d69e
+0, 8, 8, 1, 3264, 22cb799a817d45a7591489e6faa31cb9
+0, 9, 9, 1, 3264, 628dc3f03bf5dd5cae135ad1e4b9ebf7
diff --git a/tests/ref/fate/vp9-02-size-34x66 b/tests/ref/fate/vp9-02-size-34x66
new file mode 100644
index 0000000000..e28d80c8dd
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-34x66
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 3366, bf4e568217906ee4b58dc4707bee8ef6
+0, 1, 1, 1, 3366, f823f8c7b6e47ba43215f3becd35208e
+0, 2, 2, 1, 3366, 1d986d65b502e77764428e21e77503a6
+0, 3, 3, 1, 3366, 73520382bc54d6aee165402518dd7b5d
+0, 4, 4, 1, 3366, c84e943758f2d7e37126172728838640
+0, 5, 5, 1, 3366, 1d4b298da98e4b66b31ad6874f726aa6
+0, 6, 6, 1, 3366, e67748eeb3c818deb8b51d321cd16a9c
+0, 7, 7, 1, 3366, 4d1514c63e669261beef9e35b04c241e
+0, 8, 8, 1, 3366, 57705e2131e2129efbc68b74a1e0459c
+0, 9, 9, 1, 3366, 681acf1b384856d6e544d8e7a79fc628
diff --git a/tests/ref/fate/vp9-02-size-64x08 b/tests/ref/fate/vp9-02-size-64x08
new file mode 100644
index 0000000000..92d64e9adf
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-64x08
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 768, d801797c94039b0a166d46e151ec912c
+0, 1, 1, 1, 768, 161ec22caa3689b214d9ab993424584b
+0, 2, 2, 1, 768, 499b589ecf1873e388c256ce948eabb9
+0, 3, 3, 1, 768, 22bc77650e3df70e3e36f2a1b8d8aa71
+0, 4, 4, 1, 768, 750e40530257a68211596a60de18bffa
+0, 5, 5, 1, 768, 4f812a92157e7186642656b59bc28a3d
+0, 6, 6, 1, 768, a3f141cec127a2c2e16740b8dd4ce56a
+0, 7, 7, 1, 768, a5ba9959bf65ab6e254e5b359a3d59b5
+0, 8, 8, 1, 768, baa72b8a57277d9e9ad4b92aab04f5d1
+0, 9, 9, 1, 768, 4cb9aebb6c9d5bd164461726de201549
diff --git a/tests/ref/fate/vp9-02-size-64x10 b/tests/ref/fate/vp9-02-size-64x10
new file mode 100644
index 0000000000..47f46af629
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-64x10
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 960, 97eb5fd0599d482662eb0a1def5c5ef2
+0, 1, 1, 1, 960, dfdc1b61b478dcca8d411021486aa2ec
+0, 2, 2, 1, 960, 2cf560f068bdcb9e345951739091808e
+0, 3, 3, 1, 960, 33cacb04c0797fc7bd774251e04b7fb9
+0, 4, 4, 1, 960, 7fca126c0542c0dcdcf769b156bd85f5
+0, 5, 5, 1, 960, 8a46c5a48cb5bd34be8e647c127f8d61
+0, 6, 6, 1, 960, 1ddf07562c0b7dc68ed61b8e1a09fcf0
+0, 7, 7, 1, 960, d75911d5eb7fc75ffc3ee40344fc7ed2
+0, 8, 8, 1, 960, 498329c8a01d950286af11e1fcf3ac07
+0, 9, 9, 1, 960, 7a6ec019df5f3e419d389699094f87c3
diff --git a/tests/ref/fate/vp9-02-size-64x16 b/tests/ref/fate/vp9-02-size-64x16
new file mode 100644
index 0000000000..50920f232f
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-64x16
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 1536, a43068a364cc42619e62406dcf17ddfc
+0, 1, 1, 1, 1536, 94691f93299bbf5b6ba3022b02b3e069
+0, 2, 2, 1, 1536, 3c8fc275490b4daf63ef6d8f9b7f81f6
+0, 3, 3, 1, 1536, 96c06031f0fcad49dfed256c5c737d07
+0, 4, 4, 1, 1536, f722d3a51790b55d070d57d3b9a53d0d
+0, 5, 5, 1, 1536, a753b3dfe13f5778f9f054e73e512ef1
+0, 6, 6, 1, 1536, fa12cbe6cbc38fa8a38ecbcf1af8833c
+0, 7, 7, 1, 1536, cb42303391ef6f76f77d14d2600cce12
+0, 8, 8, 1, 1536, e0c18bb1d4dcc8168b5fdd7c7963987e
+0, 9, 9, 1, 1536, 581b5291cb60e50326c0dfa6a2d09d8a
diff --git a/tests/ref/fate/vp9-02-size-64x18 b/tests/ref/fate/vp9-02-size-64x18
new file mode 100644
index 0000000000..ec9bc2d187
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-64x18
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 1728, adf7e84a351847683f6a8dd177019e29
+0, 1, 1, 1, 1728, 8227cf283a27277fbab3d7826e340337
+0, 2, 2, 1, 1728, a5551b16db948e395537310d12128e76
+0, 3, 3, 1, 1728, 4b57ed07dbc15de9ab6143656b2a7e8e
+0, 4, 4, 1, 1728, a15489495f0acc41f446e9689e4142d6
+0, 5, 5, 1, 1728, b0a0d5d3ff756e8ae19797455432755c
+0, 6, 6, 1, 1728, 094a440243d36edcdd3e9d0d070de011
+0, 7, 7, 1, 1728, a780bd61e1abbfbb28581784531608bd
+0, 8, 8, 1, 1728, 55886a8c7aad65683aa9366a38382512
+0, 9, 9, 1, 1728, 5ae5b24383f66720a62ed1001664051f
diff --git a/tests/ref/fate/vp9-02-size-64x32 b/tests/ref/fate/vp9-02-size-64x32
new file mode 100644
index 0000000000..51ce4ad28b
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-64x32
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 3072, 931ab6a2482c3e84bc7ef8dfbc251307
+0, 1, 1, 1, 3072, 3552a9d8470a64ed627a6dbb799b7811
+0, 2, 2, 1, 3072, cae1863fc606a0e3df3e708b7eefdf99
+0, 3, 3, 1, 3072, 4b825a07e235c4708b12a726da8e4cdf
+0, 4, 4, 1, 3072, 0dac578ef616a13be2b9db3c0d775524
+0, 5, 5, 1, 3072, bfd47cbab8285f301777351c8bc5553c
+0, 6, 6, 1, 3072, f29f9a0cfeaaae3bdeb26933bc7c17dc
+0, 7, 7, 1, 3072, c7f3a4d24dcf72ef195a402eff77d8f6
+0, 8, 8, 1, 3072, 88ede6207441a7953cf893032c353663
+0, 9, 9, 1, 3072, 258f4e86541813e3edb1fe5332ff4ab1
diff --git a/tests/ref/fate/vp9-02-size-64x34 b/tests/ref/fate/vp9-02-size-64x34
new file mode 100644
index 0000000000..7f9c0f3670
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-64x34
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 3264, 68d00958a78e6252dd75d632806e2022
+0, 1, 1, 1, 3264, f7b6266e74200a669eecd241db787ee2
+0, 2, 2, 1, 3264, c8b88d43aee037857310edeb74bc66f4
+0, 3, 3, 1, 3264, c6d9a52baf3ca962574bff1364fcb8dc
+0, 4, 4, 1, 3264, b384fbf3ceef0affa69f5e81681edc6e
+0, 5, 5, 1, 3264, cd473f0c8d1cde98153402123a3ee7cf
+0, 6, 6, 1, 3264, c0f320a23c3e39719a3b3590fe3c2ab5
+0, 7, 7, 1, 3264, 751207d15a791728c1022f711a25cd68
+0, 8, 8, 1, 3264, 7396df89a0d88044cf7527420d193636
+0, 9, 9, 1, 3264, b772dd247838b0c3ed12713447894323
diff --git a/tests/ref/fate/vp9-02-size-64x64 b/tests/ref/fate/vp9-02-size-64x64
new file mode 100644
index 0000000000..8d32eaee5f
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-64x64
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 6144, 35f17db9076fa20368fddfa01543c746
+0, 1, 1, 1, 6144, 61cd775dfc177262da9a91d3912e6718
+0, 2, 2, 1, 6144, 8b8cf175f91425d703332b22b46c1c0e
+0, 3, 3, 1, 6144, 6041afbdd81e228f8f16384d3f9e988e
+0, 4, 4, 1, 6144, d30bd08897b50f518920014c7fa55df9
+0, 5, 5, 1, 6144, fb67222a183876b502f93e48bb779b70
+0, 6, 6, 1, 6144, 60830425ca1dcf3df4ee9c6cd75f066a
+0, 7, 7, 1, 6144, 3e178df858f7fcaa2552a1c5c719b5cc
+0, 8, 8, 1, 6144, 66718eb0c3981beb7c1119df8a2cd27e
+0, 9, 9, 1, 6144, 7c1912448c7756f7451888050760d73d
diff --git a/tests/ref/fate/vp9-02-size-64x66 b/tests/ref/fate/vp9-02-size-64x66
new file mode 100644
index 0000000000..b7e5f13d56
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-64x66
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 6336, 88587de65acfc85ff56daac8ef5d12e6
+0, 1, 1, 1, 6336, be41f6c788b929b5b6b27c5674f40abd
+0, 2, 2, 1, 6336, 04ab3f88ca062a6911405fd84c7e9de4
+0, 3, 3, 1, 6336, 231436e0a68d19d3882f285d38aca3fb
+0, 4, 4, 1, 6336, 1a067e147a6740bb4ce57c4184437eea
+0, 5, 5, 1, 6336, be0c47e06c7e9439570473adf4713f5f
+0, 6, 6, 1, 6336, a213b0611247eafab0711748c25e88a0
+0, 7, 7, 1, 6336, b1df495aa3afb74399f91c74b527b93c
+0, 8, 8, 1, 6336, 46319f21069541e1ee1652621b957860
+0, 9, 9, 1, 6336, 313517a5721b2b14683e7eefc83e51b1
diff --git a/tests/ref/fate/vp9-02-size-66x08 b/tests/ref/fate/vp9-02-size-66x08
new file mode 100644
index 0000000000..6fe4e6f57b
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-66x08
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 792, 3b16847e60786706fc339abc452746ff
+0, 1, 1, 1, 792, 365a5951cb127d6df183fe5d5000f493
+0, 2, 2, 1, 792, 6d4bceb815ca7717c4a3f86a6670703a
+0, 3, 3, 1, 792, 5a0a03d4788934285448c85788ae8d71
+0, 4, 4, 1, 792, 8712f9a82d07447e7a0d0a37ddc3858d
+0, 5, 5, 1, 792, cff32e6c183c16962207a86d7c6cf0a0
+0, 6, 6, 1, 792, dc933d90f87110651d7efb39854d3d46
+0, 7, 7, 1, 792, d1299562a022521f0c3cb30668f83b6d
+0, 8, 8, 1, 792, 5054254ca125d7c7e6df4001397170cd
+0, 9, 9, 1, 792, a6bd7c7c0b02afa8d25f911ec847c61a
diff --git a/tests/ref/fate/vp9-02-size-66x10 b/tests/ref/fate/vp9-02-size-66x10
new file mode 100644
index 0000000000..0f8557357a
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-66x10
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 990, 7cbd8c6b2fb35c0c3063cb7a379944c9
+0, 1, 1, 1, 990, 14062e74b98bed1ca982f408bc14326c
+0, 2, 2, 1, 990, f6d6868d849aa74b27df1c5f40c7096e
+0, 3, 3, 1, 990, 719c8d7e3769466ee8e3dca3f4747a0e
+0, 4, 4, 1, 990, a72e1a7a4c82ec09ea77f87b0e6f25aa
+0, 5, 5, 1, 990, a5163d142b429afa155cc2f1401a0b8a
+0, 6, 6, 1, 990, 27762d813dd1f80d6aaed5f197124fa5
+0, 7, 7, 1, 990, 02e94454660f3528abbde8f50e94288f
+0, 8, 8, 1, 990, 1d57dcfa57a55d96f14cfe471aac2e0b
+0, 9, 9, 1, 990, 7804477923c0cd067bd09ebca3529775
diff --git a/tests/ref/fate/vp9-02-size-66x16 b/tests/ref/fate/vp9-02-size-66x16
new file mode 100644
index 0000000000..08937c2c64
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-66x16
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 1584, fa2f292d273c37dc2804a70d1cae1e9d
+0, 1, 1, 1, 1584, ba75d90652c021bc7ca061352e6e94ce
+0, 2, 2, 1, 1584, e65d9a205bd17d100e50c7b6a7ea772d
+0, 3, 3, 1, 1584, 46f9e9ff891576b9462f21d48b7b9e2b
+0, 4, 4, 1, 1584, d23cedacf3a37cf6b2774e0b18b6b9d7
+0, 5, 5, 1, 1584, 84329f7716a6db5a7e64a68a1155bfc6
+0, 6, 6, 1, 1584, ad62286b0e13f4e54df4445cdd4fd4e3
+0, 7, 7, 1, 1584, 4511529eb24b21eb63e280070f888642
+0, 8, 8, 1, 1584, 4e1c122df1785e0e9134c43c85082e05
+0, 9, 9, 1, 1584, ac3a3747a00be3f9f58155648fcf9b24
diff --git a/tests/ref/fate/vp9-02-size-66x18 b/tests/ref/fate/vp9-02-size-66x18
new file mode 100644
index 0000000000..b550f36826
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-66x18
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 1782, fda5ad9bf70a51b3a41bdcabf2cce32a
+0, 1, 1, 1, 1782, 91916fb20ad542a7a3ad276e6505f9b0
+0, 2, 2, 1, 1782, e18e5d11aec483c76afd68f7e64415a4
+0, 3, 3, 1, 1782, c13da01c2b6c09101bda7af93ad5fd07
+0, 4, 4, 1, 1782, ed8d2568b2ad9c7bd980cba0d3b95cff
+0, 5, 5, 1, 1782, e6f3cf312b69d37579e77f2e52cc936b
+0, 6, 6, 1, 1782, e509f3682e9c4bcdb0889e044b1979b7
+0, 7, 7, 1, 1782, acc3945e557cd7a9642f08a656444976
+0, 8, 8, 1, 1782, 44ddd03aa8f03ba393f12fc6a1b3fc17
+0, 9, 9, 1, 1782, fdd3e68132c742d9f0cf0ea6fff2a074
diff --git a/tests/ref/fate/vp9-02-size-66x32 b/tests/ref/fate/vp9-02-size-66x32
new file mode 100644
index 0000000000..3e48bed4a7
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-66x32
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 3168, 013cd22aea6bfeccc8ec809abd52be5c
+0, 1, 1, 1, 3168, 0980adfb0ef879b3c960797272f025ad
+0, 2, 2, 1, 3168, d1411ffa0429befb8c71d3ab45acee92
+0, 3, 3, 1, 3168, 6c6f825379eaf21709a45be77def7a63
+0, 4, 4, 1, 3168, bab632ef00a080739a41c692f2b21c3a
+0, 5, 5, 1, 3168, fc0f6045aca252f2e904730227b8f337
+0, 6, 6, 1, 3168, c8dbea209329463bfd9238a11b8d5b17
+0, 7, 7, 1, 3168, 457247bf4186ed8459e0a1564f0e68f2
+0, 8, 8, 1, 3168, baa55e20bd7c73960b080d8a0c8db4d5
+0, 9, 9, 1, 3168, dc8933e8edc98cd0cfca44ae22997c62
diff --git a/tests/ref/fate/vp9-02-size-66x34 b/tests/ref/fate/vp9-02-size-66x34
new file mode 100644
index 0000000000..fce01c43d7
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-66x34
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 3366, 6821eb3fcd1d10db32eff70468dcf9c1
+0, 1, 1, 1, 3366, ed0094d347d9f250d46b4903cbc14801
+0, 2, 2, 1, 3366, fd018555dc9a62b8074d46e7c0fd0b40
+0, 3, 3, 1, 3366, 05d5baf9f2e62bbeeb3809a099e84147
+0, 4, 4, 1, 3366, 7a150c265214269c08e05fe4f296122d
+0, 5, 5, 1, 3366, 9a7ae61d4bb125ee4c4ccce9cc1c3664
+0, 6, 6, 1, 3366, 5a88fd6d96dcbc4255e98dfe19ff96b8
+0, 7, 7, 1, 3366, 4192c273a46b2b196c871ead0e61ec71
+0, 8, 8, 1, 3366, e79ebfc47e755f5db221f392c3216278
+0, 9, 9, 1, 3366, b995c5f483a2e553baf4f66d1a47fc57
diff --git a/tests/ref/fate/vp9-02-size-66x64 b/tests/ref/fate/vp9-02-size-66x64
new file mode 100644
index 0000000000..4fb7c2297a
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-66x64
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 6336, 929086fbb3e117bd53110b64c1ee915b
+0, 1, 1, 1, 6336, 9ed45f5e40dd2393434e14a0c0160c63
+0, 2, 2, 1, 6336, 5cdade692b1baf23e61896da18e3e44f
+0, 3, 3, 1, 6336, 11a2ebac61a3f826ec41c8031899e55c
+0, 4, 4, 1, 6336, 621a1e0142b94d14db9c2121553a11fb
+0, 5, 5, 1, 6336, 029a29590f7255f1bc9ff9b7a000ca25
+0, 6, 6, 1, 6336, 5fde42becf6bf054d04e2a0fa1b2d55e
+0, 7, 7, 1, 6336, 5b8ba552cef1931e1412fb4f3420748b
+0, 8, 8, 1, 6336, d41cd7d418f6ec1db802a01a90cfee1e
+0, 9, 9, 1, 6336, cea99c93a84a82edff8c6069d131453f
diff --git a/tests/ref/fate/vp9-02-size-66x66 b/tests/ref/fate/vp9-02-size-66x66
new file mode 100644
index 0000000000..c181479974
--- /dev/null
+++ b/tests/ref/fate/vp9-02-size-66x66
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 6534, 69f9028d52f95d2e7f986c57b19fc018
+0, 1, 1, 1, 6534, 068e611f62b3f6222f6b1699748c8fbf
+0, 2, 2, 1, 6534, 3d3fec78ff2274241a7958f17a773a19
+0, 3, 3, 1, 6534, 93d71ef1a2d00c7e70e76ccc1859143d
+0, 4, 4, 1, 6534, 5a35a640d52bc0930825b963b0b9e830
+0, 5, 5, 1, 6534, 782223239e6b1ca1bedbd25d9652a07c
+0, 6, 6, 1, 6534, a4b5e8a319cbc9a12d3e36127c7f0fbb
+0, 7, 7, 1, 6534, a3e2d9a78fa42b3c817aadfd31fd2d16
+0, 8, 8, 1, 6534, e9fc6b83535735f46006f3e4b376755f
+0, 9, 9, 1, 6534, 80223f600dfe86021bd0e83fecdc4b2b
diff --git a/tests/ref/fate/vp9-03-deltaq b/tests/ref/fate/vp9-03-deltaq
new file mode 100644
index 0000000000..914704ce17
--- /dev/null
+++ b/tests/ref/fate/vp9-03-deltaq
@@ -0,0 +1,3 @@
+#tb 0: 1/30
+0, 0, 0, 1, 126720, 2f90d606edc511c8c960530dd915cb98
+0, 1, 1, 1, 126720, 7fd451a057d6341b2b0d116f59e41a13
diff --git a/tests/ref/fate/vp9-03-size-196x196 b/tests/ref/fate/vp9-03-size-196x196
new file mode 100644
index 0000000000..d7c62e1394
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-196x196
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 57624, 14cc1c34b8106e35238d4650a9123852
+0, 1, 1, 1, 57624, 66e0bb9136ea24e30b781a4610b428a1
+0, 2, 2, 1, 57624, 8e36679c20a3a3e974fdacf7a9343817
+0, 3, 3, 1, 57624, 2669fd03ce7ce01f4fc9db23e06fffdb
+0, 4, 4, 1, 57624, 46ced29eb6edf2136c8ee19e9a87380f
+0, 5, 5, 1, 57624, 4e4138b65a30bc56cd18663a1799f98f
+0, 6, 6, 1, 57624, 580b0431b5f808c67e50ed34e62f39ad
+0, 7, 7, 1, 57624, 1339bbe256d8499ab17d6a550f7dac70
+0, 8, 8, 1, 57624, 89b9dac29a4c4136249c40a3763dc114
+0, 9, 9, 1, 57624, a735d341d7df9dcd0b6e51a82b813f61
diff --git a/tests/ref/fate/vp9-03-size-196x198 b/tests/ref/fate/vp9-03-size-196x198
new file mode 100644
index 0000000000..72908cd007
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-196x198
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 58212, d2bd2dfaf2ac22b3f2499844f228d89a
+0, 1, 1, 1, 58212, e066448baeb39da04b22d4d2ebd27b0a
+0, 2, 2, 1, 58212, aace53c0ecca2596c51dd5e70da7abc4
+0, 3, 3, 1, 58212, 077256d024ab101918d10ae61142f203
+0, 4, 4, 1, 58212, e2bfdad36b0365d41dc6813a371111ee
+0, 5, 5, 1, 58212, 17495af68b0a2c075899849382f3b046
+0, 6, 6, 1, 58212, 7853db163344798e5c37672adaac92d8
+0, 7, 7, 1, 58212, 7b2ee2e1ca709c58457c7d818e47c95c
+0, 8, 8, 1, 58212, f7eb3ce10561628f932861358a30b414
+0, 9, 9, 1, 58212, 3182374f5aa539fd0faa44ed4a7492e5
diff --git a/tests/ref/fate/vp9-03-size-196x200 b/tests/ref/fate/vp9-03-size-196x200
new file mode 100644
index 0000000000..98fb8b9b0f
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-196x200
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 58800, b2f2ac3e3833ae1b4dd075fe00210373
+0, 1, 1, 1, 58800, c0cce05e56a07111fe62553fa3a87074
+0, 2, 2, 1, 58800, 626aab3de03242073e03504e166b4697
+0, 3, 3, 1, 58800, 574d2c810f0bbfac57f1f06c2b97445c
+0, 4, 4, 1, 58800, 7d5bc5860bd1422d08396fe080452099
+0, 5, 5, 1, 58800, 5d47bbfb0f5cdecfe8415ca2caddc206
+0, 6, 6, 1, 58800, fbef6a0fa51029d0475975945ccf4b36
+0, 7, 7, 1, 58800, c9179c153bcb2a8e9d17ed04e5e2c39c
+0, 8, 8, 1, 58800, 107d796592cf2140d4d492beadba2d68
+0, 9, 9, 1, 58800, eee46f9ee67fc1121bffb63aeb7c768f
diff --git a/tests/ref/fate/vp9-03-size-196x202 b/tests/ref/fate/vp9-03-size-196x202
new file mode 100644
index 0000000000..016e6eb3d2
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-196x202
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 59388, 7109d2ef160828ece26337f36fcfc092
+0, 1, 1, 1, 59388, bdaa6612f81a956d9b20d55a04df8346
+0, 2, 2, 1, 59388, 15eb75495d2713a64415b990b058d5ca
+0, 3, 3, 1, 59388, b997c84553475ba84e8ba3d7ee19ae4e
+0, 4, 4, 1, 59388, 63a8badd691bcf643cf676d029ce8a6c
+0, 5, 5, 1, 59388, b8ca23d9b3418c4c36040a215b2b7917
+0, 6, 6, 1, 59388, 1be0da18386c35e4a5e5d5d32d9a4468
+0, 7, 7, 1, 59388, e75a03fa70fe7e6b3a8d8ce7dc8305f1
+0, 8, 8, 1, 59388, cbd2b60df9209025c8e890771a05321d
+0, 9, 9, 1, 59388, c655d6fcc3333917b66358a9ac2b1357
diff --git a/tests/ref/fate/vp9-03-size-196x208 b/tests/ref/fate/vp9-03-size-196x208
new file mode 100644
index 0000000000..8b04856544
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-196x208
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 61152, efa2a2a76a0fe709a78e491346cfcf29
+0, 1, 1, 1, 61152, 97de85e21b408878853fa870104707d7
+0, 2, 2, 1, 61152, 419bd1157e156d3059190d6b561c57dd
+0, 3, 3, 1, 61152, fbb6e01c524fc7c8007c6cfe2c64f467
+0, 4, 4, 1, 61152, 7453994c2e9901fa23f295ec0b556f9c
+0, 5, 5, 1, 61152, ba39dc984789fa2c4b833cd88013cc97
+0, 6, 6, 1, 61152, cea5061cac1be18d5f9a9301a5460491
+0, 7, 7, 1, 61152, 1c583018c425b1a91949e0c3eb0a4152
+0, 8, 8, 1, 61152, b48be02280ac6f97731af69bcf18de25
+0, 9, 9, 1, 61152, 6f8ab465214d8374c9ff77b939da333e
diff --git a/tests/ref/fate/vp9-03-size-196x210 b/tests/ref/fate/vp9-03-size-196x210
new file mode 100644
index 0000000000..3d3f552c90
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-196x210
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 61740, fccc18714a9ed3840bd6e9c6ca4858e5
+0, 1, 1, 1, 61740, a8f6eb43cf6ed670eb180c5051de06f7
+0, 2, 2, 1, 61740, 6a9baf9eae6e799deaefd6e801f7ace3
+0, 3, 3, 1, 61740, 3bb44c8a45aab088c9887c11bc6a4acf
+0, 4, 4, 1, 61740, 0907a7e926be9e54bbb087251b4715d9
+0, 5, 5, 1, 61740, 10fef2876c20eb3f9570c0c23e5acc69
+0, 6, 6, 1, 61740, ffe5d2b6d874af0f878075c97940ccfb
+0, 7, 7, 1, 61740, d10fae10144ff88075048827203f7e9c
+0, 8, 8, 1, 61740, bdf35736ac625f2178902c1f24d513c0
+0, 9, 9, 1, 61740, 30882bf2c21785be6234b637c4b16b28
diff --git a/tests/ref/fate/vp9-03-size-196x224 b/tests/ref/fate/vp9-03-size-196x224
new file mode 100644
index 0000000000..45acadb67e
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-196x224
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 65856, 13263674ea5aa619250dfd139bda872f
+0, 1, 1, 1, 65856, 39f5cbd8917f2b3a1df8cf2b786266de
+0, 2, 2, 1, 65856, f9aade31f9e3065f3d5b8645ef099ac6
+0, 3, 3, 1, 65856, 124f9664380f092e692b5e881f5a8fcc
+0, 4, 4, 1, 65856, e8e040e417830f5e911537828ace21b7
+0, 5, 5, 1, 65856, 84ce09882b9c184a787e8022e6d8c8de
+0, 6, 6, 1, 65856, b1397fd91814e4fdc4f75c89161ced26
+0, 7, 7, 1, 65856, d64f39d64d248f0223ed359e092d46cb
+0, 8, 8, 1, 65856, e04ee663dcc52eebd74255671c6f4ec9
+0, 9, 9, 1, 65856, 955303cb73bf072c693f37d9778ca2b6
diff --git a/tests/ref/fate/vp9-03-size-196x226 b/tests/ref/fate/vp9-03-size-196x226
new file mode 100644
index 0000000000..a3f93da0b9
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-196x226
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 66444, 5cb240f10761f59687612ed589759800
+0, 1, 1, 1, 66444, 9d8d5b57336ddfa5c9c5100a0302197d
+0, 2, 2, 1, 66444, 9db74997d23b16f527c63e88795331dc
+0, 3, 3, 1, 66444, 52758cd901533e790334d464bee516da
+0, 4, 4, 1, 66444, 40e671b9b85d07b13acba85eb64bbbaa
+0, 5, 5, 1, 66444, 8524b2cd2c9bb3e41c6167f8269e75d2
+0, 6, 6, 1, 66444, ff194ad6fa180fde86cc05a99c0580ec
+0, 7, 7, 1, 66444, 22ab303cb37745a73c227cd7d1c70003
+0, 8, 8, 1, 66444, 01986c58e82e0b5194418f5b75a8599c
+0, 9, 9, 1, 66444, eedfc9c14cbf3fa10402dbed52103848
diff --git a/tests/ref/fate/vp9-03-size-198x196 b/tests/ref/fate/vp9-03-size-198x196
new file mode 100644
index 0000000000..544f4fad58
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-198x196
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 58212, c980866a6f17d4107ce128ee112d74cf
+0, 1, 1, 1, 58212, d4d5d2a10e73f1d09919355dc4d63d48
+0, 2, 2, 1, 58212, 82c76ed020acb68ff9d8bd81899aa6f8
+0, 3, 3, 1, 58212, 8330705fa354fb5838af56dcf9cc0980
+0, 4, 4, 1, 58212, e47b63d839a592e6372d18249bf5bc0c
+0, 5, 5, 1, 58212, b6095b6f752a50e96cab52e7c3fd52f3
+0, 6, 6, 1, 58212, fc4786f48b6ee31043d94f79c5c8a54f
+0, 7, 7, 1, 58212, 7d3d06c96496bd5ab44fe5489877771d
+0, 8, 8, 1, 58212, 5b96de089a9faa2dc01697fe9dd97f7f
+0, 9, 9, 1, 58212, d7361203b4c264067dcb7bf6912e8df2
diff --git a/tests/ref/fate/vp9-03-size-198x198 b/tests/ref/fate/vp9-03-size-198x198
new file mode 100644
index 0000000000..d6e60095e8
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-198x198
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 58806, ee0760611da9938e72f551d219671c76
+0, 1, 1, 1, 58806, c512cb8a864c25318254438c7170f373
+0, 2, 2, 1, 58806, aaea10aeb7dfd1f9f6dc77adccfcd56f
+0, 3, 3, 1, 58806, fb4e68ce202d9c6ecbddc6fe50b1cd7b
+0, 4, 4, 1, 58806, 57a803d02f0d71ec4c3c17a112574525
+0, 5, 5, 1, 58806, 526d0beaf7ef721c3a6ae8bf3505fd78
+0, 6, 6, 1, 58806, 972ab31f81dbb79c2273bcfc98569e8b
+0, 7, 7, 1, 58806, e1f05d62691bd1a9494d57449417415c
+0, 8, 8, 1, 58806, bc39a559b25e5a1ac698e0101bd6bf29
+0, 9, 9, 1, 58806, 04caed04ac21c76af873e21899860fb2
diff --git a/tests/ref/fate/vp9-03-size-198x200 b/tests/ref/fate/vp9-03-size-198x200
new file mode 100644
index 0000000000..c98092252b
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-198x200
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 59400, fb0e8171b0f91d9b2ceb5430db27a67b
+0, 1, 1, 1, 59400, 73f121e6aa0e6290cfd06ac9b033c772
+0, 2, 2, 1, 59400, 4113897efc44f49f5169a579bee03596
+0, 3, 3, 1, 59400, aec1d4cf1a15e12b689980cfe136d5d6
+0, 4, 4, 1, 59400, 1322af65f647254330120e67ddae38bd
+0, 5, 5, 1, 59400, 5d28c1684451812c9db41433e6286d85
+0, 6, 6, 1, 59400, 33843fc49d1d8655520c2f42332222ca
+0, 7, 7, 1, 59400, 92a8125d8c75eaf6159d5f431c5c71bf
+0, 8, 8, 1, 59400, 5bc96553842f65a3e37f012b72b580f5
+0, 9, 9, 1, 59400, de5eb6299ee5034dc3b01cdc94bf810a
diff --git a/tests/ref/fate/vp9-03-size-198x202 b/tests/ref/fate/vp9-03-size-198x202
new file mode 100644
index 0000000000..7147c9531a
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-198x202
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 59994, f5e1cf4cc56742fadddf42189a3f65e3
+0, 1, 1, 1, 59994, f3e8ca2c8deb29a6b5bfe415b39c901e
+0, 2, 2, 1, 59994, 89c513049e41e145bca46a7f7119567c
+0, 3, 3, 1, 59994, 419089035739e84f1aa14ccdf34edcb1
+0, 4, 4, 1, 59994, 4962c98c23b16b9257869a8ad5138731
+0, 5, 5, 1, 59994, fde9e858ec895c36c2d8071e69f68db6
+0, 6, 6, 1, 59994, 42e1271915f31a00be3627fa866ce3ee
+0, 7, 7, 1, 59994, c15f794933f913861a6d0041ff2fccdb
+0, 8, 8, 1, 59994, 35dab245ba952dc6fddc1a9668c30b28
+0, 9, 9, 1, 59994, 30bb4ef77cdde9cf5aea0f1287183b23
diff --git a/tests/ref/fate/vp9-03-size-198x208 b/tests/ref/fate/vp9-03-size-198x208
new file mode 100644
index 0000000000..2dfed239ec
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-198x208
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 61776, d45b561f81cbfcca8a1dddbc2bf8ca31
+0, 1, 1, 1, 61776, 3664f63b2e59e380622caadb7a05545e
+0, 2, 2, 1, 61776, 0662fa199512320704efecc10af1aaa4
+0, 3, 3, 1, 61776, d8dc00882e73be89d0585663892cbcff
+0, 4, 4, 1, 61776, ff64b8d50b7c5b484a06dab09a26147c
+0, 5, 5, 1, 61776, 1771b6a55112eb7ea10885d1390339cc
+0, 6, 6, 1, 61776, 0d5944e8a13e3c2faffb562bbe2671a8
+0, 7, 7, 1, 61776, 744bed3a88407b75a8ff27a1b0cec64e
+0, 8, 8, 1, 61776, 3887415f2ab10d2a265c4a413e7060b9
+0, 9, 9, 1, 61776, 7dd683019b19b464bc0436f41e0b7c87
diff --git a/tests/ref/fate/vp9-03-size-198x210 b/tests/ref/fate/vp9-03-size-198x210
new file mode 100644
index 0000000000..7221fe9970
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-198x210
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 62370, 8525a27170982c059d5904c1af3b43fb
+0, 1, 1, 1, 62370, c4eb329733913360384d3917a58f6f36
+0, 2, 2, 1, 62370, ec118b87c9cba0e4bd89fd43567cca4e
+0, 3, 3, 1, 62370, 7e57c6caba7924823977e2c9bc11f7fa
+0, 4, 4, 1, 62370, f77ffb7228a5eda848acc40ff636ecad
+0, 5, 5, 1, 62370, c5dddafbe3badcbbcaaebe97076e0394
+0, 6, 6, 1, 62370, 34d69ae2e5b4c4fbcc51627237c9abc5
+0, 7, 7, 1, 62370, d9c63fa8b18d6c54e5fa31db866c06cc
+0, 8, 8, 1, 62370, 7ab392764a399328bf35977539e3148a
+0, 9, 9, 1, 62370, 7fbb7bae3ec775298aaa49a286dfb9d1
diff --git a/tests/ref/fate/vp9-03-size-198x224 b/tests/ref/fate/vp9-03-size-198x224
new file mode 100644
index 0000000000..15d944e05f
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-198x224
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 66528, 5f69230bfd8bb485bd85552b18339fc0
+0, 1, 1, 1, 66528, f5c365774fc1d0bffd5025ce2e931aaf
+0, 2, 2, 1, 66528, 2898234103c3624e6470ae82c916e000
+0, 3, 3, 1, 66528, d82a7fa705180b68a8ee8cb7de0cdd2d
+0, 4, 4, 1, 66528, 144a162d418deae62883a2cc4c341b4c
+0, 5, 5, 1, 66528, b3419a48385e42ca15717289ff2daa1c
+0, 6, 6, 1, 66528, d6306b5737f88f989bf2e6a1084a94fe
+0, 7, 7, 1, 66528, 5669761d7417b52b3cf81d44a13e3fb7
+0, 8, 8, 1, 66528, 3f730b8658d7a6657d1af38c75357512
+0, 9, 9, 1, 66528, 27df68d515148f732325bf821037d59f
diff --git a/tests/ref/fate/vp9-03-size-198x226 b/tests/ref/fate/vp9-03-size-198x226
new file mode 100644
index 0000000000..8036ad33d5
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-198x226
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 67122, 412c33a8fd71c99e68e6701b050b107c
+0, 1, 1, 1, 67122, 8e69483ff8a094096dd550b30be20dde
+0, 2, 2, 1, 67122, b8df87ab3d2613be31a3743e34d7e794
+0, 3, 3, 1, 67122, ec4b08a4014950f1fe04e83f8a790af0
+0, 4, 4, 1, 67122, 030da2b60627d879730108826ce6632c
+0, 5, 5, 1, 67122, 03aab0c9b4d75bc0b47fa5237e9efe3d
+0, 6, 6, 1, 67122, fd01e369df258f340eb8e486c07ae136
+0, 7, 7, 1, 67122, 1c301f0e60c96008fd7b6e8de1ebaa29
+0, 8, 8, 1, 67122, 912723f43b2b36366c3e6ab122d31801
+0, 9, 9, 1, 67122, b2774a66f7aa0fb7dd7e64b0d67818cd
diff --git a/tests/ref/fate/vp9-03-size-200x196 b/tests/ref/fate/vp9-03-size-200x196
new file mode 100644
index 0000000000..daa72fc80f
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-200x196
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 58800, 651a0627c6cdaee8b46e1f8c4121a368
+0, 1, 1, 1, 58800, 3e63075148df16f69c933cf6c63e078c
+0, 2, 2, 1, 58800, edf18e52b7d52af2bb7594ed358542d8
+0, 3, 3, 1, 58800, 30284124756d00d10f4f8428206ceab8
+0, 4, 4, 1, 58800, 6f6ecde53cd0ea5298f4529d396460c6
+0, 5, 5, 1, 58800, 0431d389278957fbef3e72f69f3ce008
+0, 6, 6, 1, 58800, a047c60c4c60d2ea1f79c86dc98cdf8e
+0, 7, 7, 1, 58800, dceda8bf128a8cdcadfa6c5db49cde51
+0, 8, 8, 1, 58800, d8a6283637f5abda17e0bf150eac2983
+0, 9, 9, 1, 58800, 33dca31ef26fdd0daf9971c8de685d01
diff --git a/tests/ref/fate/vp9-03-size-200x198 b/tests/ref/fate/vp9-03-size-200x198
new file mode 100644
index 0000000000..5735262fac
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-200x198
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 59400, d4b3578d800c747bcabaa484a140ffb0
+0, 1, 1, 1, 59400, a40f6f8c384c5dc3d5546d960bb6d9e5
+0, 2, 2, 1, 59400, e270ae8754d9906dd88b1c7d05280801
+0, 3, 3, 1, 59400, bde7fde5012840c5e188f3b29f4f0003
+0, 4, 4, 1, 59400, 8f8510c1130615b64fb8469af66ff678
+0, 5, 5, 1, 59400, 79b9d4e0c64f82a6e9540394222a593d
+0, 6, 6, 1, 59400, 34852ac9ca5c6bfa51736296784343c7
+0, 7, 7, 1, 59400, b055218509dbed644113642f8f0ac8a8
+0, 8, 8, 1, 59400, 1628866b436f1c4b892474025226e545
+0, 9, 9, 1, 59400, 3fdec760c04e30c90e74afb38dbf757c
diff --git a/tests/ref/fate/vp9-03-size-200x200 b/tests/ref/fate/vp9-03-size-200x200
new file mode 100644
index 0000000000..d4d8aa1afa
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-200x200
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 60000, b339f4e563afadb25f43b8c05b12dc03
+0, 1, 1, 1, 60000, 3bd5280e7fb42400085b0b1dbba1905e
+0, 2, 2, 1, 60000, acf1c84cabff763fe2073d2c1f183bfc
+0, 3, 3, 1, 60000, eaa4983b6baf907efb11d137644569d2
+0, 4, 4, 1, 60000, 8a1871c8dc38a19dfd4ac571ad7f39be
+0, 5, 5, 1, 60000, 0be539bd51f5f364828dd0abc70360be
+0, 6, 6, 1, 60000, df60622d2c9f294f61d738be9e3bd16c
+0, 7, 7, 1, 60000, 22b3f1d51ddf92c7d2add305ba0ef405
+0, 8, 8, 1, 60000, 01ba29be721e64a5a50526de0797c7d3
+0, 9, 9, 1, 60000, 7b7aa7fa0e58202b3104671375762587
diff --git a/tests/ref/fate/vp9-03-size-200x202 b/tests/ref/fate/vp9-03-size-200x202
new file mode 100644
index 0000000000..fbaea3a249
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-200x202
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 60600, c4a13df44e66f06961dd72fc990439e9
+0, 1, 1, 1, 60600, 81c73b8d3806ad96af8f422914a253f8
+0, 2, 2, 1, 60600, 05f77526125e802be9cb306e375ded6e
+0, 3, 3, 1, 60600, ab2e224840ff89abec2c675a23a73094
+0, 4, 4, 1, 60600, c30f58f88819eb57102678b169e15188
+0, 5, 5, 1, 60600, 33e5e2799eb4a9c548c8372fd6769db9
+0, 6, 6, 1, 60600, fa53c1c7e60bd1d00335af542ec69ed7
+0, 7, 7, 1, 60600, 534cafe658af10a314d6d084e55b3620
+0, 8, 8, 1, 60600, 502529e4fbecc8b890abf665fa21f53c
+0, 9, 9, 1, 60600, bf1f73c6e77370bc51a770c8ae87bd12
diff --git a/tests/ref/fate/vp9-03-size-200x208 b/tests/ref/fate/vp9-03-size-200x208
new file mode 100644
index 0000000000..9e354f1744
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-200x208
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 62400, 702748bec18c500dd41d93ae74b11d56
+0, 1, 1, 1, 62400, 4fb542190dab2fd673724d47451ff6ee
+0, 2, 2, 1, 62400, dbb4d27d52797dab67e39d32092c9d44
+0, 3, 3, 1, 62400, e4a0ed1572207b7ba433896bba711148
+0, 4, 4, 1, 62400, 28ec32bc165f4f9d455efec8a7aa8737
+0, 5, 5, 1, 62400, a95910575a6423abffb28ca38c384b34
+0, 6, 6, 1, 62400, 791f1c558c5467725f4614a75a8a687e
+0, 7, 7, 1, 62400, cfd3e12f84f7a811966721e890228313
+0, 8, 8, 1, 62400, 824c5fdf938551c28ac1c996645ae52f
+0, 9, 9, 1, 62400, 7465917fdd0206e393968232a0ec5193
diff --git a/tests/ref/fate/vp9-03-size-200x210 b/tests/ref/fate/vp9-03-size-200x210
new file mode 100644
index 0000000000..ed8f2b8142
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-200x210
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 63000, 31ef44bd12ae702f306c55eba10d2ba7
+0, 1, 1, 1, 63000, 83e9d913f5aa058d79a81047ca45e4a2
+0, 2, 2, 1, 63000, b5e21313b859f1e2c67aaac5fefc9f68
+0, 3, 3, 1, 63000, 959d63c1b219c3479af673a9a8b8d82c
+0, 4, 4, 1, 63000, ffcfaf42b69c7cd92f6e3c21987ff7df
+0, 5, 5, 1, 63000, e9667d3ee4d8179da44de4fbffcb7df2
+0, 6, 6, 1, 63000, 5e2c841bcf4ec6f3a05020d36986fe5b
+0, 7, 7, 1, 63000, 19fe287c30bd4c90b00a9631409568c0
+0, 8, 8, 1, 63000, 58a8843e50b19860a0a91e1e1bb63bfd
+0, 9, 9, 1, 63000, 0ebd31e18597a567f96645acbb2500cf
diff --git a/tests/ref/fate/vp9-03-size-200x224 b/tests/ref/fate/vp9-03-size-200x224
new file mode 100644
index 0000000000..082fe9104a
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-200x224
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 67200, 315d69847bf752a84231a368278eb0b6
+0, 1, 1, 1, 67200, d245738f8627fc345ab38a547bc7d352
+0, 2, 2, 1, 67200, 982681cdca448919c2eead94435772ad
+0, 3, 3, 1, 67200, 7b67b2d96476e17cd407bbccb19fd070
+0, 4, 4, 1, 67200, c38dde73ca097049d1fc689e18a49b5d
+0, 5, 5, 1, 67200, 525f323b81d780c669a03655bb0d0b56
+0, 6, 6, 1, 67200, 5dbeb96f65e383771c1c877ec559044a
+0, 7, 7, 1, 67200, 7d96e976265ef0f9faf173376caaa9e9
+0, 8, 8, 1, 67200, 6047c805a724701b80a133486aae0e65
+0, 9, 9, 1, 67200, eb8895dd994076a52aa3a0c1758ccbb7
diff --git a/tests/ref/fate/vp9-03-size-200x226 b/tests/ref/fate/vp9-03-size-200x226
new file mode 100644
index 0000000000..ffdda6bce7
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-200x226
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 67800, e45b6b9dce4a8509b7d26bc3cfdf7c86
+0, 1, 1, 1, 67800, ddb9d5033ecfa2d6e9a5505dce374bda
+0, 2, 2, 1, 67800, 52c495d3137143e0bce9382fe5506057
+0, 3, 3, 1, 67800, d09f3d6ad084f2966196acd48246f951
+0, 4, 4, 1, 67800, 1556d006d0119a3172b98a500b27f8d0
+0, 5, 5, 1, 67800, 904f86cfbcc3fa683d3d7744a286cd88
+0, 6, 6, 1, 67800, b35907456b8ccab0ae8efc8405b04c89
+0, 7, 7, 1, 67800, b7f2648fe0f873f7e9ea4a6d913e45ec
+0, 8, 8, 1, 67800, 2da76544bc7e295486c335e17047e12e
+0, 9, 9, 1, 67800, 10fd6424caf837d37564ef15f1c6f93d
diff --git a/tests/ref/fate/vp9-03-size-202x196 b/tests/ref/fate/vp9-03-size-202x196
new file mode 100644
index 0000000000..eecdae5664
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-202x196
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 59388, 1261466179df96099e598e46c50fa7c1
+0, 1, 1, 1, 59388, cc0fe373cd0399cf0c95edf92d9ab01f
+0, 2, 2, 1, 59388, 7a2dc0afd06ecfcf54321fb759f57601
+0, 3, 3, 1, 59388, db9c138503d27f87449f870ab07cab03
+0, 4, 4, 1, 59388, ddea2e5e2659e97132a537566d5ed989
+0, 5, 5, 1, 59388, c31e90b5eee032526c4e0603332fd160
+0, 6, 6, 1, 59388, 7e5b40f03b905d9ee749d3097a484ea0
+0, 7, 7, 1, 59388, 93e9f7defa94ff03c041448ae1e55cea
+0, 8, 8, 1, 59388, aef8e03f0146699faa16ec28dea49dbe
+0, 9, 9, 1, 59388, a651d949b4c8f0e455c6592dc98385f7
diff --git a/tests/ref/fate/vp9-03-size-202x198 b/tests/ref/fate/vp9-03-size-202x198
new file mode 100644
index 0000000000..4962640ce8
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-202x198
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 59994, 181edc4ebeeff7f0527b93b84d5d8efb
+0, 1, 1, 1, 59994, 132c71b634fb67eed51fcdef1775b6b2
+0, 2, 2, 1, 59994, fd41144770765fc893adc5843ebe32e4
+0, 3, 3, 1, 59994, 77dcbaea101142940b6a78a271842829
+0, 4, 4, 1, 59994, 01737c38c1ac711a9744256788211177
+0, 5, 5, 1, 59994, 31cd0b5f621daac309c6f249f4c26cd8
+0, 6, 6, 1, 59994, e06d34e570dc46904fdb9eeb55811464
+0, 7, 7, 1, 59994, 71bf55030373bde1eaeb52d1e97bfa4a
+0, 8, 8, 1, 59994, e96063ff02e8a23a666222b59391de9c
+0, 9, 9, 1, 59994, 5aa0079168ab5069e8a3064f9e2a6d8b
diff --git a/tests/ref/fate/vp9-03-size-202x200 b/tests/ref/fate/vp9-03-size-202x200
new file mode 100644
index 0000000000..40dd8d41db
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-202x200
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 60600, 20c41d4a1271183dbbc7a44e6b90ea80
+0, 1, 1, 1, 60600, bd8c1fba8d8742f4d98b7d5097c8c828
+0, 2, 2, 1, 60600, 55cbe06a925009c1b1f9b609b60b4c1d
+0, 3, 3, 1, 60600, 78e80c7cf1f142e2dda1bc269b5b3e00
+0, 4, 4, 1, 60600, 42ee8157a4c8af6670b81e9324b251e9
+0, 5, 5, 1, 60600, 022bdf5a2e1ea5f98503cd25b383ae53
+0, 6, 6, 1, 60600, c2073865386a991da01966878ce1ce6d
+0, 7, 7, 1, 60600, 6a5b95cd4eff0836b9180a25f663d36a
+0, 8, 8, 1, 60600, 5e5498c357340d4755dc98eb0669f103
+0, 9, 9, 1, 60600, 0907d5e4020111b1ecfe707df71bcd8a
diff --git a/tests/ref/fate/vp9-03-size-202x202 b/tests/ref/fate/vp9-03-size-202x202
new file mode 100644
index 0000000000..0c68d9b441
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-202x202
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 61206, 610cef52d35e9c641f2b8c10489c3d12
+0, 1, 1, 1, 61206, 1f84062e607d4798b0544739fe0da99c
+0, 2, 2, 1, 61206, ea379947b5c52ea3989dfc3f47c729d9
+0, 3, 3, 1, 61206, 1d06b72f06178cbb6bb5d188d22bff43
+0, 4, 4, 1, 61206, 25bd41bd7607f88a01aa0cdc336c9975
+0, 5, 5, 1, 61206, 86836a95a7a9fb1eefb20f7c5a15a9ab
+0, 6, 6, 1, 61206, d8eb3fecce1b646b9877cd4fcca9f9bf
+0, 7, 7, 1, 61206, a057e0b29e4ac9717452cc478c418c12
+0, 8, 8, 1, 61206, 9a3bab91b4f0fff174536b1609c9632c
+0, 9, 9, 1, 61206, d1cd93975f746b6cae490aae31f89e7e
diff --git a/tests/ref/fate/vp9-03-size-202x208 b/tests/ref/fate/vp9-03-size-202x208
new file mode 100644
index 0000000000..0dad7a34dc
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-202x208
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 63024, d2128e290be81bb0700ebe19e3faed4f
+0, 1, 1, 1, 63024, dccaecb7e4ddb7e4224221a659af2a43
+0, 2, 2, 1, 63024, be8e0966aaf3a9fe9164f63695dc3b62
+0, 3, 3, 1, 63024, da944fadc3a239c2254678cadb4cf7fa
+0, 4, 4, 1, 63024, 3c270f3c02fcbd192b7f896f3f9ee6d9
+0, 5, 5, 1, 63024, 0b3ccda0a87c37e40104ae2f1060e8e9
+0, 6, 6, 1, 63024, 254253aba91758f302e7177e614596be
+0, 7, 7, 1, 63024, b1501a4e372a5249e74aab77e57a28f1
+0, 8, 8, 1, 63024, c4497fea1cefed5cf2b2908620153d26
+0, 9, 9, 1, 63024, 5ba20dfa2400b15b5394f315c5c3707d
diff --git a/tests/ref/fate/vp9-03-size-202x210 b/tests/ref/fate/vp9-03-size-202x210
new file mode 100644
index 0000000000..bf210575ba
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-202x210
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 63630, e4663a28cabbfdd3815efda2d38debcc
+0, 1, 1, 1, 63630, 3cc7dbec64e9f697f40d740a72c09fc7
+0, 2, 2, 1, 63630, f108981e0ce9c6c501b9ac61d0f1ba44
+0, 3, 3, 1, 63630, 63191c7aceb8ac6b030cc1a4b3cda18c
+0, 4, 4, 1, 63630, b0a527ae3aafe94d13573199c6f4944f
+0, 5, 5, 1, 63630, 1be14b213ebf1d653468b8c16bae03fb
+0, 6, 6, 1, 63630, 44e5a8333a043cd93b9d1cc78e5f188f
+0, 7, 7, 1, 63630, bfd7619f990f20e23b47d0738a6a8449
+0, 8, 8, 1, 63630, 800405f45ca5198014ef8d8521b044fa
+0, 9, 9, 1, 63630, dca4eda872349708f54486433efc8225
diff --git a/tests/ref/fate/vp9-03-size-202x224 b/tests/ref/fate/vp9-03-size-202x224
new file mode 100644
index 0000000000..22542f8b10
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-202x224
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 67872, 1d318f05310f6d40646f23c62c7eafe4
+0, 1, 1, 1, 67872, 42870bd73e1a0c5d84b986db3d24f0f0
+0, 2, 2, 1, 67872, afaac676150286143c6fec7992a81467
+0, 3, 3, 1, 67872, 128f84400c272628e802c2369b6bf548
+0, 4, 4, 1, 67872, 9adc24d69f12349d8b17c84f5c111767
+0, 5, 5, 1, 67872, b33d2f7a1955248652701f2ade8ab55d
+0, 6, 6, 1, 67872, b8acc23721097fce6c8835f5fcfaa6ee
+0, 7, 7, 1, 67872, b63bf9a08e4dc5879bbd91efaec95960
+0, 8, 8, 1, 67872, 96e8fe29935266f6bd486b99f917eabc
+0, 9, 9, 1, 67872, 54be14f8dde6857867cd4581f8557044
diff --git a/tests/ref/fate/vp9-03-size-202x226 b/tests/ref/fate/vp9-03-size-202x226
new file mode 100644
index 0000000000..cb3f5b7344
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-202x226
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 68478, 5aa0f439c58c6335cd86d4238a8c4b68
+0, 1, 1, 1, 68478, 3616cc306ec05f89d9b0db63200e4abf
+0, 2, 2, 1, 68478, 424e98f8ec0ebf2a326a917ee0159bbe
+0, 3, 3, 1, 68478, ed5710e412f056fa8c1a277d86dd45d7
+0, 4, 4, 1, 68478, 760b850feab485f0bda6cde9943102bc
+0, 5, 5, 1, 68478, f4bd90ca72aa707f9b68e6192ac230fd
+0, 6, 6, 1, 68478, 58e4aad0bc2a9f3fc279df10208bd6f6
+0, 7, 7, 1, 68478, b42f84723dd167d5c544d539275ad537
+0, 8, 8, 1, 68478, 5f54feca21331646e68797380260932a
+0, 9, 9, 1, 68478, 8e787dd318024aff25af8b4d85040f3c
diff --git a/tests/ref/fate/vp9-03-size-208x196 b/tests/ref/fate/vp9-03-size-208x196
new file mode 100644
index 0000000000..c64c283cfc
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-208x196
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 61152, 6195975181969789e101a83a555d13f7
+0, 1, 1, 1, 61152, 2aca5e3307d68a5e969564a943b8e723
+0, 2, 2, 1, 61152, aee4b00472ee0b6b7a13e31069181db4
+0, 3, 3, 1, 61152, 7808595b650a7c14d8a4800db7c014e0
+0, 4, 4, 1, 61152, 746eb763b176286aa875ae06b81118c4
+0, 5, 5, 1, 61152, 0e8a78ec061319e27d49ca25e333e017
+0, 6, 6, 1, 61152, ac4432db2bb0971d5f70a7dda1210c19
+0, 7, 7, 1, 61152, 78870f4bd767f8ab65d369a5b322735d
+0, 8, 8, 1, 61152, eee9ddd91209348a64259db6a4a3f80c
+0, 9, 9, 1, 61152, c48d21e36a9c0d0d1c64db3f776b3002
diff --git a/tests/ref/fate/vp9-03-size-208x198 b/tests/ref/fate/vp9-03-size-208x198
new file mode 100644
index 0000000000..f64ea4678a
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-208x198
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 61776, 1f1fa3cdf865d8c75183f4ba6203b675
+0, 1, 1, 1, 61776, ead33ead8fea5bd5d831a79f4c75a590
+0, 2, 2, 1, 61776, 9a406b4464989fd4bb7cbcb1b18aeaa7
+0, 3, 3, 1, 61776, fab3d228e7032f2cdc440dbfcb17c4c1
+0, 4, 4, 1, 61776, f2f3f8b8d9ece21c359c89245157c613
+0, 5, 5, 1, 61776, 321f5a8ecb2cec1780013fe72c237bde
+0, 6, 6, 1, 61776, 6f025b1f4ef61d261f05ca149a9470e6
+0, 7, 7, 1, 61776, 85abcc8d8e6b5f286ed6aa6c588cf416
+0, 8, 8, 1, 61776, b28d710dd44389f774aa02edd6327d5c
+0, 9, 9, 1, 61776, 79374bef9819eecafa7396d70c80be7f
diff --git a/tests/ref/fate/vp9-03-size-208x200 b/tests/ref/fate/vp9-03-size-208x200
new file mode 100644
index 0000000000..326e543ed1
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-208x200
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 62400, ff2dda3ddbe8b461d960baba0ad132bf
+0, 1, 1, 1, 62400, d6935ac8f2250316f498e8f01afa04fd
+0, 2, 2, 1, 62400, 57173ebaef7b21698c62fa959cb40ead
+0, 3, 3, 1, 62400, f354c76d7cf45e9f3adfdde0f6b3b5c9
+0, 4, 4, 1, 62400, fbc968ecd214b01509a76996e45dd09a
+0, 5, 5, 1, 62400, 9c314b51a80f2a081adf9b9cc26f5f8a
+0, 6, 6, 1, 62400, f22883a6a5b74ffa4bb16f22d496b5a5
+0, 7, 7, 1, 62400, eb4fa914fc5658d43e32c48a0c39bab3
+0, 8, 8, 1, 62400, d763c0c2f44b68e1e3fe9e165334eb0b
+0, 9, 9, 1, 62400, 344e1075a48cd61e79b0550809b4c91f
diff --git a/tests/ref/fate/vp9-03-size-208x202 b/tests/ref/fate/vp9-03-size-208x202
new file mode 100644
index 0000000000..4d1f413139
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-208x202
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 63024, e5164f87feadf4b65257f578affc3e04
+0, 1, 1, 1, 63024, 6aee5a3b6c3a096dfc1594762b2b248f
+0, 2, 2, 1, 63024, cb1c9dce6fdf7372e0eb2397251f0ade
+0, 3, 3, 1, 63024, 4fe5f24c08690c966b6a14ac3422510b
+0, 4, 4, 1, 63024, b22a273814523251b365f3278d8a3a9c
+0, 5, 5, 1, 63024, 190d9dff373023a25427fc859545ea24
+0, 6, 6, 1, 63024, a6307f38718ed686cb195e3833ab27ab
+0, 7, 7, 1, 63024, 79630bec5a91d69aca42a910413c2800
+0, 8, 8, 1, 63024, 2231cec9c03714b8671e5e1456b148c9
+0, 9, 9, 1, 63024, 278458f6734a24f2eb9bc877a6e9d7df
diff --git a/tests/ref/fate/vp9-03-size-208x208 b/tests/ref/fate/vp9-03-size-208x208
new file mode 100644
index 0000000000..25caefb2b2
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-208x208
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 64896, 6bff7c1f4c5ef8412ebf669852c70de6
+0, 1, 1, 1, 64896, fdfd7a2308de9509a41fed2880a8f0f5
+0, 2, 2, 1, 64896, d8b464811e9c3b8a6db9cc277ac88c59
+0, 3, 3, 1, 64896, b8fa29e79be3126dd74310d6dd09c747
+0, 4, 4, 1, 64896, dad29803fed686887a0873eb78a469c6
+0, 5, 5, 1, 64896, 684de29bbf800f52aea4af9850bcc5b3
+0, 6, 6, 1, 64896, 06862dbce7571b4487766b179a596e1d
+0, 7, 7, 1, 64896, 99582a966bc7070112e214ce7912e485
+0, 8, 8, 1, 64896, a61158581a5719cb0cf13fb3301cb8c4
+0, 9, 9, 1, 64896, 9c2295332f34fee3a249262c8ba843bc
diff --git a/tests/ref/fate/vp9-03-size-208x210 b/tests/ref/fate/vp9-03-size-208x210
new file mode 100644
index 0000000000..077ce0d2a8
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-208x210
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 65520, b15c7e98ddd137237b062cb51667522f
+0, 1, 1, 1, 65520, 00c594c68b19ef39a79a38e86853dc64
+0, 2, 2, 1, 65520, e6742abe3d2c178af4298e121391c299
+0, 3, 3, 1, 65520, efe5387b38c32f1c25c0fc9836921074
+0, 4, 4, 1, 65520, e0e696f4c18af09a74e052903db1468c
+0, 5, 5, 1, 65520, f1960270c6704ca47caed63161716025
+0, 6, 6, 1, 65520, a1542d7749cfa447481acd7835db838a
+0, 7, 7, 1, 65520, a91fb10a17d1d056667860cc43c81dae
+0, 8, 8, 1, 65520, b673bfbb722522b4e7b5e9c5b85cc31f
+0, 9, 9, 1, 65520, 8b4bb57d3cf609cbf9564a96a6ca6ade
diff --git a/tests/ref/fate/vp9-03-size-208x224 b/tests/ref/fate/vp9-03-size-208x224
new file mode 100644
index 0000000000..be2af41504
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-208x224
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 69888, 479d07bb96905ad7d5f0ec3ee12b41ba
+0, 1, 1, 1, 69888, 4b6555aaed8e5a45879773f1bf87962e
+0, 2, 2, 1, 69888, c5f42cb796dd7b6622957016ca6b502f
+0, 3, 3, 1, 69888, f06c954483560866fbff10bae7ba0785
+0, 4, 4, 1, 69888, af83aff39999852310395fe241ccb49b
+0, 5, 5, 1, 69888, 108377d6f30ceba6f2377330af2da38f
+0, 6, 6, 1, 69888, e81e6e0b37a7b92368ede9cab124567c
+0, 7, 7, 1, 69888, 59dbe51caaed8e6e825c78c5901fb22c
+0, 8, 8, 1, 69888, 24686123ea14c8d1a9b447733df0aaab
+0, 9, 9, 1, 69888, ce2035c49237c8076f8dac0d3f61848e
diff --git a/tests/ref/fate/vp9-03-size-208x226 b/tests/ref/fate/vp9-03-size-208x226
new file mode 100644
index 0000000000..713fb8043f
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-208x226
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 70512, 33aa4af6153570518c59960a0c959053
+0, 1, 1, 1, 70512, 024fa27dee80ad199528052aaa8d42c7
+0, 2, 2, 1, 70512, b949ef118c7e7e62a8b88e2308219ef9
+0, 3, 3, 1, 70512, 3061ee13696ced5e10a646fdd5ca6c34
+0, 4, 4, 1, 70512, c4984bd53dcb7b9e2570f2965d077b2f
+0, 5, 5, 1, 70512, d564c35c5caadcfd9f80377fa414af72
+0, 6, 6, 1, 70512, 9b7d7b10ee2f3eb7a9ffddcebff45b97
+0, 7, 7, 1, 70512, a0ede7085b04cbb3519d56b2e4347d14
+0, 8, 8, 1, 70512, 63d7af745f9e6a34b618db28fe878ffd
+0, 9, 9, 1, 70512, 85077809087e7bdfb9215bfcd1f1bbc0
diff --git a/tests/ref/fate/vp9-03-size-210x196 b/tests/ref/fate/vp9-03-size-210x196
new file mode 100644
index 0000000000..6591b753b6
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-210x196
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 61740, 5c69f80da667bfd20394995e93e4cd2b
+0, 1, 1, 1, 61740, 13363cd8e52ca8c1053db1c84c111bc9
+0, 2, 2, 1, 61740, 108976afdf99f59276d6f89879e3bdc3
+0, 3, 3, 1, 61740, 770ce25985e6b479d52a9185876cfe83
+0, 4, 4, 1, 61740, eba7cbb3c91989aa4c13487ed01675b5
+0, 5, 5, 1, 61740, f391c30a47c33a250dd20cb12f0a6e01
+0, 6, 6, 1, 61740, c38e12de302177d19dd744a3ea227e90
+0, 7, 7, 1, 61740, 8c9370439a0b7289919c6ee68e00570f
+0, 8, 8, 1, 61740, ac3748c4b99c4f1aba7430ae12c19cfd
+0, 9, 9, 1, 61740, e5228dc84f7933ccc9306907d737ad3c
diff --git a/tests/ref/fate/vp9-03-size-210x198 b/tests/ref/fate/vp9-03-size-210x198
new file mode 100644
index 0000000000..c16718d64a
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-210x198
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 62370, d83ee2413e701ae405a2b74863d4c5a9
+0, 1, 1, 1, 62370, f2ebc0f7dc171e0e5d2911c7ee2df5e1
+0, 2, 2, 1, 62370, e189ef4d8add227352a0d6ee62748ee7
+0, 3, 3, 1, 62370, 6dcb1dca1a0e2ba85034aba9f021427e
+0, 4, 4, 1, 62370, e98c633ba8912f6d65374055ec9af543
+0, 5, 5, 1, 62370, 82111cb7d5addce16d9bcba9e0a99503
+0, 6, 6, 1, 62370, bbbc73002f794ab0261fe384b2524226
+0, 7, 7, 1, 62370, 0bcdc427df47123959f7de9c44fe291e
+0, 8, 8, 1, 62370, 505776b3d82e38612393d60b6aa55c1d
+0, 9, 9, 1, 62370, feb93758242b847f3d53bb4c97b0ad9c
diff --git a/tests/ref/fate/vp9-03-size-210x200 b/tests/ref/fate/vp9-03-size-210x200
new file mode 100644
index 0000000000..6469672f76
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-210x200
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 63000, 2465560246c1ee24d937cb9cbc1422f1
+0, 1, 1, 1, 63000, 8926b628dcdf2182516822c7d0d778ec
+0, 2, 2, 1, 63000, 9bd14d3ebc7fe81c4223116de1b9c2ec
+0, 3, 3, 1, 63000, 2d029d8461c20236066c0786950540fb
+0, 4, 4, 1, 63000, 39412b6e62de43bd40c58d4e2e38daf8
+0, 5, 5, 1, 63000, 3ea211c24f606b29582147bf872994dd
+0, 6, 6, 1, 63000, 261c37f88bf7f40549642578d9464aeb
+0, 7, 7, 1, 63000, 98551d44de1e23165e05975babb72446
+0, 8, 8, 1, 63000, 1d85ad052dd27e7e6bfea5d2babf5176
+0, 9, 9, 1, 63000, ad18b6a3698a3674c2488f927810eb0d
diff --git a/tests/ref/fate/vp9-03-size-210x202 b/tests/ref/fate/vp9-03-size-210x202
new file mode 100644
index 0000000000..65439e57fc
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-210x202
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 63630, 5d01848aee2b324f2e356627f9c39532
+0, 1, 1, 1, 63630, b671fe34bc0e5a682baff929d26ea627
+0, 2, 2, 1, 63630, e9a40f87ca5aaa5af9772e286feb9063
+0, 3, 3, 1, 63630, 4730f60d4c856e8ad877c0d8b1729ec4
+0, 4, 4, 1, 63630, 317fc01349e0984c23d15f97a3a0f442
+0, 5, 5, 1, 63630, aea89116ffe48340d1752d1ad5195529
+0, 6, 6, 1, 63630, 14694ba65b6308e5f5571486b62ca1cc
+0, 7, 7, 1, 63630, 53c6102d877c9a30eaa20ddc45207ea0
+0, 8, 8, 1, 63630, 7d1e898b1bead878224e8ff15d624bd9
+0, 9, 9, 1, 63630, 37b684bfae5dbd33e8dbb8332b94ce8a
diff --git a/tests/ref/fate/vp9-03-size-210x208 b/tests/ref/fate/vp9-03-size-210x208
new file mode 100644
index 0000000000..95103588cc
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-210x208
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 65520, 1156d318c00d299cf5bdc7e485966dab
+0, 1, 1, 1, 65520, a8094f8f1e7e04e54251bee8c4c800ce
+0, 2, 2, 1, 65520, e2a07d99ffe1cfe6b9fce36e93677fe1
+0, 3, 3, 1, 65520, 63d179b00816dbad75b778d2c23955c6
+0, 4, 4, 1, 65520, 407de5fb2dfdd52e6173905b09ff22f2
+0, 5, 5, 1, 65520, 36900199c56310e651723de4e3ad2f2c
+0, 6, 6, 1, 65520, 908db56e975b5db07af17fdc51b12be8
+0, 7, 7, 1, 65520, 400e32490b1262009a481cc331a00e44
+0, 8, 8, 1, 65520, dc43b786cba033cc92b9921d12f7b3d7
+0, 9, 9, 1, 65520, e8c94c5965c729f5d1ef3ba4509c97c8
diff --git a/tests/ref/fate/vp9-03-size-210x210 b/tests/ref/fate/vp9-03-size-210x210
new file mode 100644
index 0000000000..6882c0d67e
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-210x210
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 66150, b65725c68978bdaaafdf735dfbafa9e3
+0, 1, 1, 1, 66150, 35be2f16bd5dedc9d3f7a016f0d71701
+0, 2, 2, 1, 66150, 8c2873a97b51510d7449869e24a348f5
+0, 3, 3, 1, 66150, 724a30e8ae539e797db8889dc08aec5e
+0, 4, 4, 1, 66150, e3ae1246a63ea22afd026bfb859fe165
+0, 5, 5, 1, 66150, 7e1fa363cf3f44c7a3019f29c14a6da4
+0, 6, 6, 1, 66150, c6f26619ab5687a2a698c8766b79f2eb
+0, 7, 7, 1, 66150, be5b8c50a772afe95d72bf3cc7c4fd2f
+0, 8, 8, 1, 66150, 9eab1417ac249ce31c79750143d52084
+0, 9, 9, 1, 66150, 9d2455048dbc3cdc2343a818c5a2bcb1
diff --git a/tests/ref/fate/vp9-03-size-210x224 b/tests/ref/fate/vp9-03-size-210x224
new file mode 100644
index 0000000000..63519b164b
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-210x224
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 70560, bb903b926c4b34ae336e21d65ad8fd25
+0, 1, 1, 1, 70560, c4c0bc3b112487e994d22176817ace3c
+0, 2, 2, 1, 70560, 24e699f7a92ab1b0fe12e0b747470b5b
+0, 3, 3, 1, 70560, 200f403694d3acfda63f52e8373f1420
+0, 4, 4, 1, 70560, 6df417a8ec1810562301c89724b739d1
+0, 5, 5, 1, 70560, 55757b633d8fe669fc0f507dab4fa9f7
+0, 6, 6, 1, 70560, 45bc82bee02cb45422be3ac1019896d0
+0, 7, 7, 1, 70560, 4aaf5d07d2796910767d5084556c9cf9
+0, 8, 8, 1, 70560, f100fa26da47250b98d95a18915f521d
+0, 9, 9, 1, 70560, f5a8def53b4638b6ce7c8588d595d0ad
diff --git a/tests/ref/fate/vp9-03-size-210x226 b/tests/ref/fate/vp9-03-size-210x226
new file mode 100644
index 0000000000..445d53d24d
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-210x226
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 71190, 03707b2f5c392933f7336f380423a0a1
+0, 1, 1, 1, 71190, b388553c79573555a3b660f5e36d4e36
+0, 2, 2, 1, 71190, a1a7fd8ba7fb0fe7733cdf5440c7c1f3
+0, 3, 3, 1, 71190, 9daff7ef71dd54951f0b75a902065259
+0, 4, 4, 1, 71190, 60218a4b8bc0a5b0b40fa560a40fb4c0
+0, 5, 5, 1, 71190, 21229bfed833468fafc27ce93db1450c
+0, 6, 6, 1, 71190, 7aa290c6e503315d7aa3517258d5f63a
+0, 7, 7, 1, 71190, 63fd08ae2e859ff3d874ab2c2ce41a42
+0, 8, 8, 1, 71190, 725b371247fae28ef4b912368738df64
+0, 9, 9, 1, 71190, 7cf2d8d9e464307311b499ff0c3ea05e
diff --git a/tests/ref/fate/vp9-03-size-224x196 b/tests/ref/fate/vp9-03-size-224x196
new file mode 100644
index 0000000000..ab442fc288
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-224x196
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 65856, 3ffc096f1b42b4d319d4a9efbefc7625
+0, 1, 1, 1, 65856, 78b3655d5cad30fa6b2c2d8fd29463de
+0, 2, 2, 1, 65856, ab197553d9599b2a03aff62d1d694848
+0, 3, 3, 1, 65856, be368d1f3d3fcc710565b5433940f0df
+0, 4, 4, 1, 65856, 374c5db60ea9c110b871bb45be0efff1
+0, 5, 5, 1, 65856, ec50085400d626de5833bc0a94d9941f
+0, 6, 6, 1, 65856, d4ae69937e2a8d9bf2023d4215749635
+0, 7, 7, 1, 65856, 9b0b81eb6d62b8014e0639932fe35bc0
+0, 8, 8, 1, 65856, cd02d0cc268e6b6df0b2dbd3f3b137e6
+0, 9, 9, 1, 65856, 5322ba1085c114f93534e1761a0d8aa1
diff --git a/tests/ref/fate/vp9-03-size-224x198 b/tests/ref/fate/vp9-03-size-224x198
new file mode 100644
index 0000000000..54abb1a215
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-224x198
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 66528, cf35dffc80946e87bb9d3e18aab9d320
+0, 1, 1, 1, 66528, a76ac92f05e9b097f8ac5882e1ffe656
+0, 2, 2, 1, 66528, faa1e8a11c9df3e9c9a9dafbebea6d04
+0, 3, 3, 1, 66528, 905a28289c8ac793b335096ca7f84e1d
+0, 4, 4, 1, 66528, cb480fa6977baf98a74bddf213ecba82
+0, 5, 5, 1, 66528, 35224d3708e3ba1dafcc58b803d5ea77
+0, 6, 6, 1, 66528, d166d764e87854bca47ab7a2bc8b1f9b
+0, 7, 7, 1, 66528, 562f1e06ae36abba5f1fb53e3d6cd7e8
+0, 8, 8, 1, 66528, 1599cebef060f6464aeef15aacbde446
+0, 9, 9, 1, 66528, 3316ebca2864a9dc04db86069efb1dd1
diff --git a/tests/ref/fate/vp9-03-size-224x200 b/tests/ref/fate/vp9-03-size-224x200
new file mode 100644
index 0000000000..f5c8ed8012
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-224x200
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 67200, 0819e6d715c9b4d94f05f63a7ca86199
+0, 1, 1, 1, 67200, 9b9a4b01ed4c8a93687e45245b3092a3
+0, 2, 2, 1, 67200, 3a076f5b8dba60552e84a391ee04d1c7
+0, 3, 3, 1, 67200, 7aafc561f5b96e9d286bd8deb5687774
+0, 4, 4, 1, 67200, daa43a89ab6b2761eedaa183e33a3465
+0, 5, 5, 1, 67200, c14874409872357b11b65f35a283e058
+0, 6, 6, 1, 67200, 37d2ef52a9c694b2596d58ed9ca0d90b
+0, 7, 7, 1, 67200, c97bc860c006896d80f52ccc0759f472
+0, 8, 8, 1, 67200, 5f8618114a723a017e39a1af695996f3
+0, 9, 9, 1, 67200, ee8234fc5ccd41d05eb87e1510f9795e
diff --git a/tests/ref/fate/vp9-03-size-224x202 b/tests/ref/fate/vp9-03-size-224x202
new file mode 100644
index 0000000000..33bf0bb1bb
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-224x202
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 67872, e1e3b4af5910383ff6f66b6ab1a29544
+0, 1, 1, 1, 67872, 8668ef92b72f35728ebb456665d48b95
+0, 2, 2, 1, 67872, dffc7c28f86f07bf28451292990e9594
+0, 3, 3, 1, 67872, aebfb446fa6d48db36dbd9b5cd147f1e
+0, 4, 4, 1, 67872, e3c6cb8c5bb3a26928493bfc297ab827
+0, 5, 5, 1, 67872, 68dabae76c1d27ab0e1079d99cb6d413
+0, 6, 6, 1, 67872, d1f7745eef748688f3871d00a7e67ef8
+0, 7, 7, 1, 67872, 36738851cc2af83fd250dea4cd63941b
+0, 8, 8, 1, 67872, 16c0315c43427e7e6719806a89551703
+0, 9, 9, 1, 67872, c4d589c0ea4cdfc1dd6dff72084c61fd
diff --git a/tests/ref/fate/vp9-03-size-224x208 b/tests/ref/fate/vp9-03-size-224x208
new file mode 100644
index 0000000000..3eb03ff495
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-224x208
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 69888, 85f08afadfd1204d4131b9ee9c8cc10b
+0, 1, 1, 1, 69888, f893de5432a082b3dffcf7499827f548
+0, 2, 2, 1, 69888, cb81e0d7b657bc5a4a9cf8ad75a76a77
+0, 3, 3, 1, 69888, 8a40842123965731c15fc23fb6366d1d
+0, 4, 4, 1, 69888, 09c6d92af14a3fcfb12705cd5da57f2a
+0, 5, 5, 1, 69888, 6bede4dc8770df534b599021b0425309
+0, 6, 6, 1, 69888, 334b0b0448e9e4e6a0cddcd2e3a0af3f
+0, 7, 7, 1, 69888, 09f491f0f3870ef96cff0384cd7183d1
+0, 8, 8, 1, 69888, c9e5f81186ac947a77b051c8f0e76eac
+0, 9, 9, 1, 69888, 917565c3327bff78b53a78ea739472ff
diff --git a/tests/ref/fate/vp9-03-size-224x210 b/tests/ref/fate/vp9-03-size-224x210
new file mode 100644
index 0000000000..673cb66c40
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-224x210
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 70560, 427421e5fd2087c6ff7b87a27982332f
+0, 1, 1, 1, 70560, b68311fd44e189e4174ac357d5415068
+0, 2, 2, 1, 70560, 2c822ff45be7a1ea412d21ff82c7bc1d
+0, 3, 3, 1, 70560, 34659186d93516eae1dd4d9a391d1c3f
+0, 4, 4, 1, 70560, 1990dd822abc3a10f511589db5aa50f4
+0, 5, 5, 1, 70560, 4a4dc076172c79d9fde3e17b47109835
+0, 6, 6, 1, 70560, 51874c79850120537fa5c405721d0107
+0, 7, 7, 1, 70560, 15d7897a128de9be90be17f1679012c9
+0, 8, 8, 1, 70560, a8d9480accf8585e94161a5f7c371cef
+0, 9, 9, 1, 70560, 8a9d3f09561b895b423ae9428f620b9b
diff --git a/tests/ref/fate/vp9-03-size-224x224 b/tests/ref/fate/vp9-03-size-224x224
new file mode 100644
index 0000000000..5a3c1a3efe
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-224x224
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 75264, bedd5d2725ffff06a50e23841bc2dfb8
+0, 1, 1, 1, 75264, 8c363f68b0b30f507563516aa99e23ac
+0, 2, 2, 1, 75264, 9cb7d51ca4439614dc3f5980507a4d32
+0, 3, 3, 1, 75264, b393a18de28ab6b8d1c6afd67a7794e0
+0, 4, 4, 1, 75264, 81f69ee1e3d89cb78cac192c352f7741
+0, 5, 5, 1, 75264, aabb51f029a9a02e71524cf3500931e9
+0, 6, 6, 1, 75264, 6581aec620c508d2b42ccceaa2c6044d
+0, 7, 7, 1, 75264, 993cde759158c30dcf0f0a9fdcdfb0d8
+0, 8, 8, 1, 75264, 85985ae8d35514d601800a06c8226625
+0, 9, 9, 1, 75264, 0eba1d7c193e473586e4a5c87d0e0d21
diff --git a/tests/ref/fate/vp9-03-size-224x226 b/tests/ref/fate/vp9-03-size-224x226
new file mode 100644
index 0000000000..53a8fa899f
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-224x226
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 75936, dca556e648a576b3973fbe4b34d0328c
+0, 1, 1, 1, 75936, 34a49e4aba4aca5c76ab0f751341c32b
+0, 2, 2, 1, 75936, 4b7cc6d500b273efe7e30fc3a3946f74
+0, 3, 3, 1, 75936, 1960f0f1edf9196c96b0de742a3cd53c
+0, 4, 4, 1, 75936, 3cb7d90178636911c5d53a5f8e75599c
+0, 5, 5, 1, 75936, 84b56c60c2282f85102048cc2cf40b88
+0, 6, 6, 1, 75936, 3ca34d2978307ec0fca05130d81bcc26
+0, 7, 7, 1, 75936, c15560be737e02ea9d1deeca0af9bb77
+0, 8, 8, 1, 75936, 391439789a6aa7bb02d7e699795a9559
+0, 9, 9, 1, 75936, 9f681e91cbcbe9920f21236b8ff093c7
diff --git a/tests/ref/fate/vp9-03-size-226x196 b/tests/ref/fate/vp9-03-size-226x196
new file mode 100644
index 0000000000..15f171add8
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-226x196
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 66444, 4757a31842453f806de2f2256329547e
+0, 1, 1, 1, 66444, fe5fb955a4143091c5bfae7c4a4afe0f
+0, 2, 2, 1, 66444, 93766c5a03d71f99afb7705add7b63f0
+0, 3, 3, 1, 66444, 30c91162aa6fb0ed3e47325146bb6d8a
+0, 4, 4, 1, 66444, 501fe67785b970b1b62c2ae0b36b19ad
+0, 5, 5, 1, 66444, 836be5e778e3d20e75c4fcd71f765b3d
+0, 6, 6, 1, 66444, 21a9fd5e78212fe71719e173844bc6e6
+0, 7, 7, 1, 66444, 81b3919208e345d93dde62740b47dd93
+0, 8, 8, 1, 66444, df010555a929ba88a2f25c6267e3786e
+0, 9, 9, 1, 66444, d2cff8282e5e7a5bbd879c73df0670c3
diff --git a/tests/ref/fate/vp9-03-size-226x198 b/tests/ref/fate/vp9-03-size-226x198
new file mode 100644
index 0000000000..acf25117f9
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-226x198
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 67122, b97087eb8c53cf56dc44576912654fb2
+0, 1, 1, 1, 67122, 219bb68a59dc166806a5b5689a943b66
+0, 2, 2, 1, 67122, 67b2ec19dd3b74d828b51912c25249d6
+0, 3, 3, 1, 67122, 73dd9625538e10a0f94d31ac9fe3db23
+0, 4, 4, 1, 67122, 51e68f201130da18beb0cb27adcf6fa9
+0, 5, 5, 1, 67122, 455d9753b3c0ac5ad7d9da022f69acd0
+0, 6, 6, 1, 67122, 60a8905a63db4cdd2560583fb6415030
+0, 7, 7, 1, 67122, 48c156f4b2c9f936487b43713a4573fd
+0, 8, 8, 1, 67122, a5c8f4190cb34b3ecd42ca8e09bf1646
+0, 9, 9, 1, 67122, 233a5d5187137e047993532fc2e725d3
diff --git a/tests/ref/fate/vp9-03-size-226x200 b/tests/ref/fate/vp9-03-size-226x200
new file mode 100644
index 0000000000..ec78516993
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-226x200
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 67800, 0ae27db338f73f37eaed806b1c789593
+0, 1, 1, 1, 67800, 3f69273752f43699a3bc7b22a88cc3aa
+0, 2, 2, 1, 67800, ce0dfafb59910241d2b1a2275a2c2143
+0, 3, 3, 1, 67800, 8d20f404e25766c819ee728858bcbc76
+0, 4, 4, 1, 67800, 67bc5604c5b0f6c3484b605c1f93c83a
+0, 5, 5, 1, 67800, 1c82def3a06430d205cce0db7b5714de
+0, 6, 6, 1, 67800, 654d7a676e3b8b64541ed8cdefbd7286
+0, 7, 7, 1, 67800, 6c80c78c7b652c5b3b117a0960e89951
+0, 8, 8, 1, 67800, ae73e3c69ec6747c5234d58c5e1e36eb
+0, 9, 9, 1, 67800, e40d716efd8caf2d4004d299fb914328
diff --git a/tests/ref/fate/vp9-03-size-226x202 b/tests/ref/fate/vp9-03-size-226x202
new file mode 100644
index 0000000000..4ef59366a6
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-226x202
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 68478, 0cd2876640e71de3a6df7839bd6f0b51
+0, 1, 1, 1, 68478, f887db6839c0cddd1ea9ae6bfd2cc16d
+0, 2, 2, 1, 68478, ff2a890cf4c4973bf181ba8424c2eadc
+0, 3, 3, 1, 68478, f69f2e4f3036a21deb43a0bf4b95771f
+0, 4, 4, 1, 68478, 93f511739c19f1a3b356dda39d945c93
+0, 5, 5, 1, 68478, 7f79633c93765b504fef0324bd10fdba
+0, 6, 6, 1, 68478, d6c53d3937c9a40b227b4486452e0b33
+0, 7, 7, 1, 68478, 4e26625e8997ad6fe08ae68fbdfdbfd7
+0, 8, 8, 1, 68478, 3bf4c8ac0279351bf904cf57b0fc13c1
+0, 9, 9, 1, 68478, 12d64d856025185fa9e610dfa62b05af
diff --git a/tests/ref/fate/vp9-03-size-226x208 b/tests/ref/fate/vp9-03-size-226x208
new file mode 100644
index 0000000000..cc9b00c39a
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-226x208
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 70512, 6006cac6628cf9e7cea58aec07471b06
+0, 1, 1, 1, 70512, f7e994921248b6933920c984880ec96c
+0, 2, 2, 1, 70512, c0aeeb9d2009538d8d5e837f45e1542d
+0, 3, 3, 1, 70512, 7dacf9d00e85bd52045eb47bae5225b3
+0, 4, 4, 1, 70512, 024fd008a099ae954e38a3f0a8ebb6c9
+0, 5, 5, 1, 70512, fb6c368a1b3578ab59aa30e0b5cc4853
+0, 6, 6, 1, 70512, 07815251f7020b627c365a7a7be694c7
+0, 7, 7, 1, 70512, db8b8f48f3693867d2bd8208cf4f929a
+0, 8, 8, 1, 70512, 88b42d943c0978d832333a8a3f7b6bbc
+0, 9, 9, 1, 70512, 7aa760190f9328ba4f6fa87d1d9e8d3e
diff --git a/tests/ref/fate/vp9-03-size-226x210 b/tests/ref/fate/vp9-03-size-226x210
new file mode 100644
index 0000000000..a800558a60
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-226x210
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 71190, a6c1b7686202f5cc64335f92be595309
+0, 1, 1, 1, 71190, 3e573d4c693a39c5d6cd46b8873e99bb
+0, 2, 2, 1, 71190, d2388f6f641c8ddec98f11493f1a1390
+0, 3, 3, 1, 71190, 16473e33532ebc8de2f02077c406346b
+0, 4, 4, 1, 71190, 6c75d1c01276838fce40837e373f49db
+0, 5, 5, 1, 71190, b718e7445e2b08dde78fa7f30be01346
+0, 6, 6, 1, 71190, 2f556ed5afd60b1bbae76984ce073107
+0, 7, 7, 1, 71190, 4e5d59daed044c39a14c35f18cb4fb7a
+0, 8, 8, 1, 71190, c14901a9906ffcd0eb1efc068ce32941
+0, 9, 9, 1, 71190, 3d73b7f87bcd16c1ec565b5cc8d0fe93
diff --git a/tests/ref/fate/vp9-03-size-226x224 b/tests/ref/fate/vp9-03-size-226x224
new file mode 100644
index 0000000000..7b0b33de75
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-226x224
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 75936, 80fb3a643384386beadc0991f171669d
+0, 1, 1, 1, 75936, 65a4a51163f49a75f8eeecd94cb2ba47
+0, 2, 2, 1, 75936, d5b2aac9889d2991b83fd4360ada0258
+0, 3, 3, 1, 75936, 7958ff5535358567ea7df351d78256a7
+0, 4, 4, 1, 75936, 7e7413b9a61967d0ade07b81944e9a15
+0, 5, 5, 1, 75936, 40a008016adbf9673adbbc4c0edb4454
+0, 6, 6, 1, 75936, fef7b5e2809ef79917ab394a067ef4be
+0, 7, 7, 1, 75936, 91ee2360faf46a25b95927c55eea603f
+0, 8, 8, 1, 75936, a47f14a80a529f79f97accbe23188046
+0, 9, 9, 1, 75936, 3613bcd41ff13006fbba3bd0087c44f4
diff --git a/tests/ref/fate/vp9-03-size-226x226 b/tests/ref/fate/vp9-03-size-226x226
new file mode 100644
index 0000000000..6f9d9e67fd
--- /dev/null
+++ b/tests/ref/fate/vp9-03-size-226x226
@@ -0,0 +1,11 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 76614, f2370fc802dafdf5082beffc1907a9c6
+0, 1, 1, 1, 76614, aad6de7b986234a1d621935b272501c9
+0, 2, 2, 1, 76614, 8a6d3784e22e3b4f735e78916fbc3821
+0, 3, 3, 1, 76614, 0c4afce19c43fdf3bb1b972810cc9126
+0, 4, 4, 1, 76614, 814a68dd76a3135221131988910f51ba
+0, 5, 5, 1, 76614, b2379c4b28dca10e67ac58631f9731c0
+0, 6, 6, 1, 76614, b16fd651884340a428cea3fe0ac18ba6
+0, 7, 7, 1, 76614, cb65cd4c421cfd6a19fb123ec27abbe6
+0, 8, 8, 1, 76614, 7f1d2686b9808de8ecc723b18136d57d
+0, 9, 9, 1, 76614, da7fd4bff4b6db0221c42492876c5c4d
diff --git a/tests/ref/fate/vp9-2pass-akiyo b/tests/ref/fate/vp9-2pass-akiyo
new file mode 100644
index 0000000000..ad5a2cfdf0
--- /dev/null
+++ b/tests/ref/fate/vp9-2pass-akiyo
@@ -0,0 +1,51 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 043ce065a309514e1e8ebdcbb3c2458b
+0, 1, 1, 1, 152064, 8579c9cffd95b11db86158e518b2e34a
+0, 2, 2, 1, 152064, ebbba105e499604f5e69b8aa48fe86f4
+0, 3, 3, 1, 152064, b08526fab7e106021f9fb9b1e2d4b725
+0, 4, 4, 1, 152064, 92afa561d06f41ccc6d2e2bcc3ab2ee4
+0, 5, 5, 1, 152064, 50de8ec2db66c783289a3982dd1c4f97
+0, 6, 6, 1, 152064, c2ab55d114b8822adef06ccb093b5ac7
+0, 7, 7, 1, 152064, e3ee4edbe8a1f0b5486bbd8a52e7cbcb
+0, 8, 8, 1, 152064, fc33fd50566cd64e5b13911ee06c6e24
+0, 9, 9, 1, 152064, 05297e847f983a19fe2ba5e05932a110
+0, 10, 10, 1, 152064, d21db9adb27be89ab3b7f75d89175e24
+0, 11, 11, 1, 152064, 29bb87bdebd078f8dd953a70def6c4dc
+0, 12, 12, 1, 152064, c57f7bc772f6143a22edaf926f92de5f
+0, 13, 13, 1, 152064, 39f2fc755d4bc2cc5ec077035382be22
+0, 14, 14, 1, 152064, 000ec9c75374f6d74a5e61189e6fd782
+0, 15, 15, 1, 152064, 3027187c9bdb2a755d14513b7e597bb1
+0, 16, 16, 1, 152064, 2b3129659df2b3aa10b9398c50301e00
+0, 17, 17, 1, 152064, e23bcacf1cafca9a7959508b33e63907
+0, 18, 18, 1, 152064, fe0382dd155284998a0d7eb7effb5adf
+0, 19, 19, 1, 152064, e0a487860dd0df3d865971b483fab3e9
+0, 20, 20, 1, 152064, 7ca757c55b0ea4779cdfa3a535f8f234
+0, 21, 21, 1, 152064, 1a276d27f4ce0e2720e25dbed2e524ae
+0, 22, 22, 1, 152064, dd39bc322c8bdce196a9c2129bcb5d6e
+0, 23, 23, 1, 152064, 63e295427977d645462e0fb3277ccb53
+0, 24, 24, 1, 152064, e9a35655c71da22fb0c7865e0bbc91b8
+0, 25, 25, 1, 152064, 5903bcbccabb3366382b37bf08119dde
+0, 26, 26, 1, 152064, 3b6ce09353b07b193914a71ca2334d8c
+0, 27, 27, 1, 152064, cb3731eb5dbe338125c0a7d6b4bf2868
+0, 28, 28, 1, 152064, 0837c62b54912ed06f7f755894ad3f6b
+0, 29, 29, 1, 152064, 7f215dc14d8e280fc18ad3fb3122fa58
+0, 30, 30, 1, 152064, 6dafaf5adc45fead74f0153e3764b17d
+0, 31, 31, 1, 152064, e19c8274ee6377dbf005f6516a81c413
+0, 32, 32, 1, 152064, 358cbf29bd136d2f9dcb60ab82a2e9e5
+0, 33, 33, 1, 152064, 2276d4670ff35c3a76c27c3a5810eea3
+0, 34, 34, 1, 152064, 636dd3390d4011c377915d7d3acc9ee1
+0, 35, 35, 1, 152064, 5e7a1ed17d80168567d61987425f4e60
+0, 36, 36, 1, 152064, c10a4830c5f268888789fccd16c0cc0e
+0, 37, 37, 1, 152064, 298ef49418d730a031ff23311031c969
+0, 38, 38, 1, 152064, 4dd2249e13cda0f99fa46786d345c96a
+0, 39, 39, 1, 152064, 24232dbc6e35a069c60422c4c23dfa51
+0, 40, 40, 1, 152064, ae8751c5ac168d6aa4499fe69f018ae2
+0, 41, 41, 1, 152064, 6a3a7e60a569e7415f2c3a1453e4dc38
+0, 42, 42, 1, 152064, 5475af1c118d1b7cc0a357bc434241a8
+0, 43, 43, 1, 152064, c6b5ab39e630e66e8f09698fd1dfa160
+0, 44, 44, 1, 152064, f1c0310adf115456167e3fa790e43dde
+0, 45, 45, 1, 152064, 3028296307b47d10156fc9657693edc3
+0, 46, 46, 1, 152064, 0903dabcb8ac707b423b222ac5bb4898
+0, 47, 47, 1, 152064, 713cf71b994e2c85ed577062814c5732
+0, 48, 48, 1, 152064, 674f56b9cccf5c9d1f88f68c3996a671
+0, 49, 49, 1, 152064, f63732c2ff823960d8b62d866dfb5e6a
diff --git a/tests/ref/fate/vp9-segmentation-akiyo b/tests/ref/fate/vp9-segmentation-akiyo
new file mode 100644
index 0000000000..372cc8dfda
--- /dev/null
+++ b/tests/ref/fate/vp9-segmentation-akiyo
@@ -0,0 +1,51 @@
+#tb 0: 1001/30000
+0, 0, 0, 1, 152064, 20cf714300c5e28ffb77bf9c682129bc
+0, 1, 1, 1, 152064, 2f271e4de29f87d6b90511fbafdf9fbb
+0, 2, 2, 1, 152064, 2f271e4de29f87d6b90511fbafdf9fbb
+0, 3, 3, 1, 152064, a88532a043f5f2c6bce729a8e20ee5af
+0, 4, 4, 1, 152064, 8d7b5482ed8072a7c95d722783773436
+0, 5, 5, 1, 152064, 04872d8619b163b5e0c20123ccddf7dc
+0, 6, 6, 1, 152064, ed6d9677782aa6e87b6576541391557f
+0, 7, 7, 1, 152064, 689f71108e9bf024cd9ccf48800dcdc7
+0, 8, 8, 1, 152064, f7c555792884499bb62a8e739b201739
+0, 9, 9, 1, 152064, 7fed82c38ce428a178c56f6131eff5ec
+0, 10, 10, 1, 152064, fb638e587ade05baa027bb63edc7ec7c
+0, 11, 11, 1, 152064, 319295f5aa44661a80570e844050156a
+0, 12, 12, 1, 152064, de2d8635966a1cd57290eac449a5fb4b
+0, 13, 13, 1, 152064, 9ac3d711a00aac6b17004bb6451e4cab
+0, 14, 14, 1, 152064, d12eced084e72b5230493e2dc2de0f0a
+0, 15, 15, 1, 152064, 197761d11407fed723a63b8e28cb8e19
+0, 16, 16, 1, 152064, 28d8e807bc142b74f1eaf30dbbf1b7bd
+0, 17, 17, 1, 152064, abe88f1f7490d13ba3def9511beaceec
+0, 18, 18, 1, 152064, 7d297b9c989ebc0408fd41b14900242a
+0, 19, 19, 1, 152064, d5e7adfa2b207d860feff5c894585fd1
+0, 20, 20, 1, 152064, aea3e9de9de237f8379785f3467dc9c9
+0, 21, 21, 1, 152064, 211967cd949c1d83a8cc4c8267aa6034
+0, 22, 22, 1, 152064, 3f49bf8e0434114c15b867be2d53d283
+0, 23, 23, 1, 152064, 8d5e629c0e941ca6f049ed2bb59d09a8
+0, 24, 24, 1, 152064, d359620957877534bc94cd137dc652fe
+0, 25, 25, 1, 152064, 83610fc1969fdfa267e7e462a83ea40c
+0, 26, 26, 1, 152064, b2d20dcc3f77a238ce7210991eebe1a7
+0, 27, 27, 1, 152064, a42ad37808f30e1d968882bf42e9c641
+0, 28, 28, 1, 152064, 55084cded938266a2c3c658dcc162781
+0, 29, 29, 1, 152064, e392a3a7d33e10e95fc9cdf0a2080eac
+0, 30, 30, 1, 152064, 73977c4827463c17e63c0769bb90722f
+0, 31, 31, 1, 152064, cb5dd87344af7d6fd4ed0e06cb90d9c2
+0, 32, 32, 1, 152064, 533338860124e392cef2039468c22f75
+0, 33, 33, 1, 152064, da30f077490042367502a6fe11a46e0f
+0, 34, 34, 1, 152064, 860ab1bfbd3fe6a27bee5ef8c4e0b600
+0, 35, 35, 1, 152064, 339ec3863eaed689d46289ffe47bc45d
+0, 36, 36, 1, 152064, ffa6c990577093106796ed0dee56c483
+0, 37, 37, 1, 152064, 3fcdc2bc064c79f35ea81a715ff089d0
+0, 38, 38, 1, 152064, adaef9ec97e23a542db22bcd23c740bd
+0, 39, 39, 1, 152064, ddcff4bd2c9579181182eb49add0ce3c
+0, 40, 40, 1, 152064, b3b039c84cffb9272c8ddf9086748696
+0, 41, 41, 1, 152064, 70939a961ec1e4697031b79e7ebb7919
+0, 42, 42, 1, 152064, 6b3ff2e003749c6ffeb2d71edecf884c
+0, 43, 43, 1, 152064, 5e4efc96971f81218c472482b5a79374
+0, 44, 44, 1, 152064, 279132c87d81a5747824b06423bf6785
+0, 45, 45, 1, 152064, 1da48caa08007523aab41a56e21dd99b
+0, 46, 46, 1, 152064, 36ecffb2bfcb587d2556fddcbbd3448b
+0, 47, 47, 1, 152064, 7823e3c86cd5a05c2959c7ef4d1cfa89
+0, 48, 48, 1, 152064, b53f78afbad1a43f7aea58814eacd824
+0, 49, 49, 1, 152064, b9b127b4bc54123bec19b2f4a3fa157c
diff --git a/tests/ref/fate/vp9-tiling-pedestrian b/tests/ref/fate/vp9-tiling-pedestrian
new file mode 100644
index 0000000000..23c760e0a7
--- /dev/null
+++ b/tests/ref/fate/vp9-tiling-pedestrian
@@ -0,0 +1,3 @@
+#tb 0: 1/1000
+0, 0, 0, 0, 3110400, 1e6c2e768a5107e57e6d626f0511193a
+0, 40, 40, 0, 3110400, 972d3e2b5ee2e3b0907218a243e4cb7d