History

Initial decoder implementation.

With minor contributions from: - Jean-Baptiste Kempf <jb@videolan.org> - Marvin Scholz <epirat07@gmail.com> - Hugo Beauzée-Luyssen <hugo@videolan.org>

Ronald S. Bultje committed 8 years ago

Commit e2892ff1 parent d32eb2d89 files · +30590 −2Browse files

Unified · Split

89 files
  1. include/common/attributes.h +54 −0
  2. include/common/bitdepth.h +68 −0
  3. include/common/dump.h +75 −0
  4. include/common/intops.h +78 −0
  5. include/common/mem.h +76 −0
  6. include/common/validate.h +59 −0
  7. include/dav1d/common.h +43 −0
  8. include/dav1d/data.h +52 −0
  9. include/dav1d/dav1d.h +87 −0
  10. include/dav1d/picture.h +145 −0
  11. meson.build +97 −2
  12. meson_options.txt +6 −0
  13. src/cdef.c +271 −0
  14. src/cdef.h +62 −0
  15. src/cdef_apply.c +237 −0
  16. src/cdef_apply.h +38 −0
  17. src/cdf.c +4251 −0
  18. src/cdf.h +148 −0
  19. src/data.c +54 −0
  20. src/data.h +35 −0
  21. src/decode.c +2908 −0
  22. src/decode.h +35 −0
  23. src/dequant_tables.c +164 −0
  24. src/dequant_tables.h +37 −0
  25. src/env.h +754 −0
  26. src/getbits.c +129 −0
  27. src/getbits.h +49 −0
  28. src/internal.h +275 −0
  29. src/intra_edge.c +166 −0
  30. src/intra_edge.h +57 −0
  31. src/ipred.c +1010 −0
  32. src/ipred.h +92 −0
  33. src/ipred_prepare.c +209 −0
  34. src/ipred_prepare.h +102 −0
  35. src/itx.c +224 −0
  36. src/itx.h +46 −0
  37. src/itx_1d.c +861 −0
  38. src/levels.h +525 −0
  39. src/lf_apply.c +330 −0
  40. src/lf_apply.h +42 −0
  41. src/lf_mask.c +402 −0
  42. src/lf_mask.h +80 −0
  43. src/lib.c +297 −0
  44. src/loopfilter.c +195 −0
  45. src/loopfilter.h +56 −0
  46. src/looprestoration.c +577 −0
  47. src/looprestoration.h +65 −0
  48. src/lr_apply.c +302 −0
  49. src/lr_apply.h +44 −0
  50. src/mc.c +533 −0
  51. src/mc.h +104 −0
  52. src/msac.c +318 −0
  53. src/msac.h +56 −0
  54. src/obu.c +1102 −0
  55. src/obu.h +36 −0
  56. src/picture.c +187 −0
  57. src/picture.h +91 −0
  58. src/qm.c +3152 −0
  59. src/qm.h +37 −0
  60. src/recon.c +1503 −0
  61. src/recon.h +75 −0
  62. src/ref.c +60 −0
  63. src/ref.h +46 −0
  64. src/ref_mvs.c +3550 −0
  65. src/ref_mvs.h +185 −0
  66. src/scan.c +527 −0
  67. src/scan.h +37 −0
  68. src/tables.c +756 −0
  69. src/tables.h +84 −0
  70. src/thread_data.h +37 −0
  71. src/thread_task.c +137 −0
  72. src/thread_task.h +39 −0
  73. src/warpmv.c +194 −0
  74. src/warpmv.h +37 −0
  75. src/wedge.c +334 −0
  76. src/wedge.h +41 −0
  77. tools/dav1d.c +173 −0
  78. tools/dav1d_cli_parse.c +160 −0
  79. tools/dav1d_cli_parse.h +44 −0
  80. tools/input/demuxer.h +44 −0
  81. tools/input/input.c +124 −0
  82. tools/input/input.h +41 −0
  83. tools/input/ivf.c +113 −0
  84. tools/output/md5.c +220 −0
  85. tools/output/muxer.h +44 −0
  86. tools/output/output.c +141 −0
  87. tools/output/output.h +41 −0
  88. tools/output/y4m2.c +114 −0
  89. tools/output/yuv.c +104 −0
include/common/attributes.h+54−0
@@ -0,0 +1,54 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __DAV1D_COMMON_ATTRIBUTES_H__
29+#define __DAV1D_COMMON_ATTRIBUTES_H__
30+
31+#include <stddef.h>
32+
33+/*
34+ * API for variables, struct members (ALIGN()) like:
35+ * uint8_t var[1][2][3][4]
36+ * becomes:
37+ * ALIGN(uint8_t var[1][2][3][4], alignment).
38+ */
39+#define ALIGN(line, align) \
40+ line __attribute__((aligned(align)))
41+
42+/*
43+ * API for stack alignment (ALIGN_STK_$align()) of variables like:
44+ * uint8_t var[1][2][3][4]
45+ * becomes:
46+ * ALIGN_STK_$align(uint8_t, var, 1, [2][3][4])
47+ */
48+#define ALIGN_STK_32(type, var, sz1d, sznd) \
49+ ALIGN(type var[sz1d]sznd, 32)
50+// as long as stack is itself 16-byte aligned, this works (win64, gcc)
51+#define ALIGN_STK_16(type, var, sz1d, sznd) \
52+ ALIGN(type var[sz1d]sznd, 16)
53+
54+#endif /* __DAV1D_COMMON_ATTRIBUTES_H__ */
include/common/bitdepth.h+68−0
@@ -0,0 +1,68 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __DAV1D_COMMON_BITDEPTH_H__
29+#define __DAV1D_COMMON_BITDEPTH_H__ 1
30+
31+#include <stdint.h>
32+#include <string.h>
33+
34+#if !defined(BITDEPTH)
35+typedef void pixel;
36+typedef void coef;
37+#elif BITDEPTH == 8
38+typedef uint8_t pixel;
39+typedef int16_t coef;
40+#define pixel_copy memcpy
41+#define pixel_set memset
42+#define iclip_pixel iclip_u8
43+#define PIX_HEX_FMT "%02x"
44+#define bytefn(x) x##_8bpc
45+#define bitfn(x) x##_8bpc
46+#define PXSTRIDE(x) x
47+#elif BITDEPTH == 10 || BITDEPTH == 12
48+typedef uint16_t pixel;
49+typedef int32_t coef;
50+#define pixel_copy(a, b, c) memcpy(a, b, (c) << 1)
51+#define iclip_pixel(x) iclip(x, 0, ((1 << BITDEPTH) - 1))
52+static inline void pixel_set(pixel *const dst, const int val, const int num) {
53+ for (int n = 0; n < num; n++)
54+ dst[n] = val;
55+}
56+#define PIX_HEX_FMT "%03x"
57+#define bytefn(x) x##_16bpc
58+#if BITDEPTH == 10
59+#define bitfn(x) x##_10bpc
60+#else
61+#define bitfn(x) x##_12bpc
62+#endif
63+#define PXSTRIDE(x) (x >> 1)
64+#else
65+#error invalid value for bitdepth
66+#endif
67+
68+#endif /* __DAV1D_COMMON_BITDEPTH_H__ */
include/common/dump.h+75−0
@@ -0,0 +1,75 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __DAV1D_COMMON_DUMP_H__
29+#define __DAV1D_COMMON_DUMP_H__
30+
31+#include <stddef.h>
32+#include <stdint.h>
33+#include <stdio.h>
34+
35+#include "common/bitdepth.h"
36+
37+static inline void append_plane_to_file(const pixel *buf, ptrdiff_t stride,
38+ int w, int h, const char *const file)
39+{
40+ FILE *const f = fopen(file, "ab");
41+ while (h--) {
42+ fwrite(buf, w * sizeof(pixel), 1, f);
43+ buf += PXSTRIDE(stride);
44+ }
45+ fclose(f);
46+}
47+
48+static inline void hex_dump(const pixel *buf, ptrdiff_t stride,
49+ int w, int h, const char *what)
50+{
51+ printf("%s\n", what);
52+ while (h--) {
53+ int x;
54+ for (x = 0; x < w; x++)
55+ printf(" " PIX_HEX_FMT, buf[x]);
56+ buf += PXSTRIDE(stride);
57+ printf("\n");
58+ }
59+}
60+
61+static inline void coef_dump(const coef *buf, const int w, const int h,
62+ const int len, const char *what)
63+{
64+ int y;
65+ printf("%s\n", what);
66+ for (y = 0; y < h; y++) {
67+ int x;
68+ for (x = 0; x < w; x++)
69+ printf(" %*d", len, buf[x]);
70+ buf += w;
71+ printf("\n");
72+ }
73+}
74+
75+#endif /* __DAV1D_COMMON_DUMP_H__ */
include/common/intops.h+78−0
@@ -0,0 +1,78 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __DAV1D_COMMON_INTOPS_H__
29+#define __DAV1D_COMMON_INTOPS_H__
30+
31+#include <stdint.h>
32+
33+static inline int imax(const int a, const int b) {
34+ return a > b ? a : b;
35+}
36+
37+static inline int imin(const int a, const int b) {
38+ return a < b ? a : b;
39+}
40+
41+static inline int iclip(const int v, const int min, const int max) {
42+ return v < min ? min : v > max ? max : v;
43+}
44+
45+static inline int iclip_u8(const int v) {
46+ return iclip(v, 0, 255);
47+}
48+
49+static inline int apply_sign(const int v, const int s) {
50+ return s < 0 ? -v : v;
51+}
52+
53+static inline int ulog2(const unsigned v) {
54+ return 31 - __builtin_clz(v);
55+}
56+
57+static inline int u64log2(const uint64_t v) {
58+ return 63 - __builtin_clzll(v);
59+}
60+
61+static inline unsigned rl16(const uint8_t *const ptr) {
62+ return (ptr[1] << 8) | ptr[0];
63+}
64+
65+static inline unsigned rl32(const uint8_t *const ptr) {
66+ return (rl16(&ptr[2]) << 16) | rl16(ptr);
67+}
68+
69+static inline unsigned inv_recenter(const unsigned r, const unsigned v) {
70+ if (v > (r << 1))
71+ return v;
72+ else if ((v & 1) == 0)
73+ return (v >> 1) + r;
74+ else
75+ return r - ((v + 1) >> 1);
76+}
77+
78+#endif /* __DAV1D_COMMON_INTOPS_H__ */
include/common/mem.h+76−0
@@ -0,0 +1,76 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __DAV1D_COMMON_MEM_H__
29+#define __DAV1D_COMMON_MEM_H__
30+
31+#include <assert.h>
32+#include <stdlib.h>
33+#include <malloc.h>
34+
35+/*
36+ * Allocate 32-byte aligned memory. The return value can be released
37+ * by calling the standard free() function.
38+ */
39+static inline void *dav1d_alloc_aligned(size_t sz, size_t align) {
40+#ifdef HAVE_POSIX_MEMALIGN
41+ void *ptr;
42+ assert(!(align & (align - 1)));
43+ if (posix_memalign(&ptr, align, sz)) return NULL;
44+ return ptr;
45+#elif defined(HAVE_ALIGNED_MALLOC)
46+ return _aligned_malloc(sz, align);
47+#else
48+#error Missing aligned alloc implementation
49+#endif
50+}
51+
52+static inline void dav1d_free_aligned(void* ptr) {
53+#ifdef HAVE_POSIX_MEMALIGN
54+ free(ptr);
55+#elif defined(HAVE_ALIGNED_MALLOC)
56+ _aligned_free(ptr);
57+#endif
58+}
59+
60+static inline void dav1d_freep_aligned(void* ptr) {
61+ void **mem = (void **) ptr;
62+ if (*mem) {
63+ dav1d_free_aligned(*mem);
64+ *mem = NULL;
65+ }
66+}
67+
68+static inline void freep(void *ptr) {
69+ void **mem = (void **) ptr;
70+ if (*mem) {
71+ free(*mem);
72+ *mem = NULL;
73+ }
74+}
75+
76+#endif /* __DAV1D_COMMON_MEM_H__ */
include/common/validate.h+59−0
@@ -0,0 +1,59 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __DAV1D_COMMON_VALIDATE_H__
29+#define __DAV1D_COMMON_VALIDATE_H__
30+
31+#include <stdio.h>
32+#include <stdlib.h>
33+
34+#if defined(NDEBUG)
35+#define debug_abort()
36+#else
37+#define debug_abort abort
38+#endif
39+
40+#define validate_input_or_ret_with_msg(x, r, msg...) \
41+ if (!(x)) { \
42+ fprintf(stderr, "Input validation check \'%s\' failed in %s!\n", \
43+ #x, __PRETTY_FUNCTION__); \
44+ fprintf(stderr, msg); \
45+ debug_abort(); \
46+ return r; \
47+ }
48+
49+#define validate_input_or_ret(x, r) \
50+ if (!(x)) { \
51+ fprintf(stderr, "Input validation check \'%s\' failed in %s!\n", \
52+ #x, __PRETTY_FUNCTION__); \
53+ debug_abort(); \
54+ return r; \
55+ }
56+
57+#define validate_input(x) validate_input_or_ret(x, )
58+
59+#endif /* __DAV1D_COMMON_VALIDATE_H__ */
include/dav1d/common.h+43−0
@@ -0,0 +1,43 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __COMMON_H__
29+#define __COMMON_H__
30+
31+#ifndef DAV1D_API
32+ #if defined _WIN32
33+ #define DAV1D_API __declspec(dllexport)
34+ #else
35+ #if __GNUC__ >= 4
36+ #define DAV1D_API __attribute__ ((visibility ("default")))
37+ #else
38+ #define DAV1D_API
39+ #endif
40+ #endif
41+#endif
42+
43+#endif // __COMMON_H__
include/dav1d/data.h+52−0
@@ -0,0 +1,52 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __DAV1D_DATA_H__
29+#define __DAV1D_DATA_H__
30+
31+#include <stddef.h>
32+#include <stdint.h>
33+
34+#include "common.h"
35+
36+typedef struct Dav1dData {
37+ uint8_t *data; ///< data pointer
38+ size_t sz; ///< data size
39+ struct Dav1dRef *ref; ///< allocation origin
40+} Dav1dData;
41+
42+/**
43+ * Allocate data.
44+ */
45+DAV1D_API int dav1d_data_create(Dav1dData *data, size_t sz);
46+
47+/**
48+ * Free data.
49+ */
50+DAV1D_API void dav1d_data_unref(Dav1dData *buf);
51+
52+#endif /* __DAV1D_DATA_H__ */
include/dav1d/dav1d.h+87−0
@@ -0,0 +1,87 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __DAV1D_H__
29+#define __DAV1D_H__
30+
31+#include "common.h"
32+#include "picture.h"
33+#include "data.h"
34+
35+typedef struct Dav1dContext Dav1dContext;
36+typedef struct Dav1dRef Dav1dRef;
37+
38+typedef struct Dav1dSettings {
39+ int n_frame_threads;
40+ int n_tile_threads;
41+} Dav1dSettings;
42+
43+/*
44+ * Init the library.
45+ */
46+DAV1D_API void dav1d_init(void);
47+
48+/**
49+ * Get library version.
50+ */
51+DAV1D_API const char *dav1d_version(void);
52+
53+/**
54+ * Initialize settings to default values.
55+ */
56+DAV1D_API void dav1d_default_settings(Dav1dSettings *s);
57+
58+/**
59+ * Open/allocate decoder instance.
60+ *
61+ * The resulting instance context will be placed in $c_out and can be used in
62+ * iterative calls to dav1d_decode().
63+ *
64+ * You should free the context using dav1d_close() when you're done decoding.
65+ *
66+ * This returns < 0 (a negative errno code) on error, or 0 on success.
67+ */
68+DAV1D_API int dav1d_open(Dav1dContext **c_out, const Dav1dSettings *s);
69+
70+/**
71+ * Decode one input frame. Library takes ownership of the passed-in reference.
72+ * After that, it will return < 0 (a negative errno code, but not -EAGAIN) on
73+ * failure, or 0 on success. If any decoded output frames are available, they
74+ * will be placed in $out. The caller assumes ownership of the returned output
75+ * picture.
76+ *
77+ * To flush the decoder (i.e. all input is finished), feed it NULL input data
78+ * until it returns -EAGAIN.
79+ */
80+DAV1D_API int dav1d_decode(Dav1dContext *c, Dav1dData *in, Dav1dPicture *out);
81+
82+/**
83+ * Close decoder instance, free all associated memory.
84+ */
85+DAV1D_API void dav1d_close(Dav1dContext *c);
86+
87+#endif /* __DAV1D_H__ */
include/dav1d/picture.h+145−0
@@ -0,0 +1,145 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __DAV1D_PICTURE_H__
29+#define __DAV1D_PICTURE_H__
30+
31+#include <stddef.h>
32+#include <stdint.h>
33+
34+#include "common.h"
35+
36+enum Dav1dPixelLayout {
37+ DAV1D_PIXEL_LAYOUT_I400, ///< monochrome
38+ DAV1D_PIXEL_LAYOUT_I420, ///< 4:2:0 planar
39+ DAV1D_PIXEL_LAYOUT_I422, ///< 4:2:2 planar
40+ DAV1D_PIXEL_LAYOUT_I444, ///< 4:4:4 planar
41+};
42+
43+enum Dav1dColorPrimaries {
44+ DAV1D_COLOR_PRI_BT709 = 1,
45+ DAV1D_COLOR_PRI_UNKNOWN = 2,
46+ DAV1D_COLOR_PRI_BT470M = 4,
47+ DAV1D_COLOR_PRI_BT470BG = 5,
48+ DAV1D_COLOR_PRI_BT601 = 6,
49+ DAV1D_COLOR_PRI_SMPTE240 = 7,
50+ DAV1D_COLOR_PRI_FILM = 8,
51+ DAV1D_COLOR_PRI_BT2020 = 9,
52+ DAV1D_COLOR_PRI_XYZ = 10,
53+ DAV1D_COLOR_PRI_SMPTE431 = 11,
54+ DAV1D_COLOR_PRI_SMPTE432 = 12,
55+ DAV1D_COLOR_PRI_EBU3213 = 22,
56+};
57+
58+enum Dav1dTransferCharacteristics {
59+ DAV1D_TRC_BT709 = 1,
60+ DAV1D_TRC_UNKNOWN = 2,
61+ DAV1D_TRC_BT470M = 4,
62+ DAV1D_TRC_BT470BG = 5,
63+ DAV1D_TRC_BT601 = 6,
64+ DAV1D_TRC_SMPTE240 = 7,
65+ DAV1D_TRC_LINEAR = 8,
66+ DAV1D_TRC_LOG100 = 9, ///< logarithmic (100:1 range)
67+ DAV1D_TRC_LOG100_SQRT10 = 10, ///< lograithmic (100*sqrt(10):1 range)
68+ DAV1D_TRC_IEC61966 = 11,
69+ DAV1D_TRC_BT1361 = 12,
70+ DAV1D_TRC_SRGB = 13,
71+ DAV1D_TRC_BT2020_10BIT = 14,
72+ DAV1D_TRC_BT2020_12BIT = 15,
73+ DAV1D_TRC_SMPTE2084 = 16, ///< PQ
74+ DAV1D_TRC_SMPTE428 = 17,
75+ DAV1D_TRC_HLG = 18, ///< hybrid log/gamma (BT.2100 / ARIB STD-B67)
76+};
77+
78+enum Dav1dMatrixCoefficients {
79+ DAV1D_MC_IDENTITY = 0,
80+ DAV1D_MC_BT709 = 1,
81+ DAV1D_MC_UNKNOWN = 2,
82+ DAV1D_MC_FCC = 4,
83+ DAV1D_MC_BT470BG = 5,
84+ DAV1D_MC_BT601 = 6,
85+ DAV1D_MC_SMPTE240 = 7,
86+ DAV1D_MC_SMPTE_YCGCO = 8,
87+ DAV1D_MC_BT2020_NCL = 9,
88+ DAV1D_MC_BT2020_CL = 10,
89+ DAV1D_MC_SMPTE2085 = 11,
90+ DAV1D_MC_CHROMAT_NCL = 12, ///< Chromaticity-derived
91+ DAV1D_MC_CHROMAT_CL = 13,
92+ DAV1D_MC_ICTCP = 14,
93+};
94+
95+enum Dav1dChromaSamplePosition {
96+ DAV1D_CHR_UNKNOWN = 0,
97+ DAV1D_CHR_VERTICAL = 1, ///< Horizontally co-located with luma(0, 0)
98+ ///< sample, between two vertical samples
99+ DAV1D_CHR_COLOCATED = 2, ///< Co-located with luma(0, 0) sample
100+};
101+
102+typedef struct Dav1dPictureParameters {
103+ int w; ///< width (in pixels)
104+ int h; ///< height (in pixels)
105+ enum Dav1dPixelLayout layout; ///< format of the picture
106+ int bpc; ///< bits per pixel component (8 or 10)
107+
108+ enum Dav1dColorPrimaries pri; ///< color primaries (av1)
109+ enum Dav1dTransferCharacteristics trc; ///< transfer characteristics (av1)
110+ enum Dav1dMatrixCoefficients mtrx; ///< matrix coefficients (av1)
111+ enum Dav1dChromaSamplePosition chr; ///< chroma sample position (av1)
112+ /**
113+ * Pixel data uses JPEG pixel range ([0,255] for 8bits) instead of
114+ * MPEG pixel range ([16,235] for 8bits luma, [16,240] for 8bits chroma).
115+ */
116+ int fullrange;
117+} Dav1dPictureParameters;
118+
119+typedef struct Dav1dPicture {
120+ /**
121+ * Pointers to planar image data (Y is [0], U is [1], V is [2]). The data
122+ * should be bytes (for 8 bpc) or words (for 10 bpc). In case of words
123+ * containing 10 bpc image data, the pixels should be located in the LSB
124+ * bits, so that values range between [0, 1023]; the upper bits should be
125+ * zero'ed out.
126+ */
127+ void *data[3];
128+ struct Dav1dRef *ref; ///< allocation origin
129+
130+ /**
131+ * Number of bytes between 2 lines in data[] for luma [0] or chroma [1].
132+ */
133+ ptrdiff_t stride[2];
134+
135+ Dav1dPictureParameters p;
136+
137+ int poc; ///< frame number
138+} Dav1dPicture;
139+
140+/**
141+ * Release reference to a picture.
142+ */
143+DAV1D_API void dav1d_picture_unref(Dav1dPicture *p);
144+
145+#endif /* __DAV1D_PICTURE_H__ */
meson.build+97−2
@@ -37,7 +37,15 @@ else · 36 unmodified lines
3737 thread_dependency = cc.find_library('pthread')
3838 endif
3939
40−dav1d_inc_dirs = include_directories('include')
40+dav1d_inc_dirs = include_directories(['include', 'include/dav1d'])
41+
42+#
43+# Option handling
44+#
45+dav1d_bitdepths = get_option('bitdepths')
46+foreach bitdepth : dav1d_bitdepths
47+ cdata.set('CONFIG_@0@BPC'.format(bitdepth), 1)
48+endforeach
4149
4250 #
4351 # OS/Compiler feature detection
@@ -121,15 +129,102 @@ config_h_target = configure_file(output: 'config.h', configuration: cdata) · 77 unmodified lines
121129
122130 subdir('include')
123131
132+#
133+# dav1d library
134+#
135+libdav1d_tmpl_sources = files(
136+ 'src/ipred.c',
137+ 'src/itx.c',
138+ 'src/ipred_prepare.c',
139+ 'src/lf_apply.c',
140+ 'src/loopfilter.c',
141+ 'src/mc.c',
142+ 'src/cdef_apply.c',
143+ 'src/cdef.c',
144+ 'src/lr_apply.c',
145+ 'src/looprestoration.c',
146+ 'src/recon.c'
147+)
148+
149+# Build a helper library for each bitdepth
150+bitdepth_objs = []
151+foreach bitdepth : dav1d_bitdepths
152+ bitdepth_lib = static_library(
153+ 'dav1d_bitdepth_@0@'.format(bitdepth),
154+ libdav1d_tmpl_sources, config_h_target,
155+ include_directories: dav1d_inc_dirs,
156+ c_args: ['-DBITDEPTH=@0@'.format(bitdepth), stackalign_flag],
157+ install: false,
158+ build_by_default: false,
159+ )
160+ bitdepth_objs += bitdepth_lib.extract_all_objects()
161+endforeach
162+
163+entrypoints_src = files(
164+ 'src/lib.c',
165+ 'src/thread_task.c'
166+)
167+entrypoints_lib = static_library(
168+ 'libdav1dentrypoint',
169+ entrypoints_src,
170+ include_directories: dav1d_inc_dirs,
171+ c_args: [stackrealign_flag],
172+ install: false,
173+)
174+entrypoints_objs = entrypoints_lib.extract_all_objects()
175+
176+libdav1d_sources = files(
177+ 'src/picture.c',
178+ 'src/data.c',
179+ 'src/ref.c',
180+ 'src/getbits.c',
181+ 'src/obu.c',
182+ 'src/decode.c',
183+ 'src/cdf.c',
184+ 'src/msac.c',
185+ 'src/tables.c',
186+ 'src/scan.c',
187+ 'src/dequant_tables.c',
188+ 'src/intra_edge.c',
189+ 'src/lf_mask.c',
190+ 'src/ref_mvs.c',
191+ 'src/warpmv.c',
192+ 'src/wedge.c',
193+ 'src/qm.c',
194+)
195+
124196 libdav1d = library('dav1d',
125− rev_target,
197+ libdav1d_sources, rev_target,
126198 version: '0.0.1',
199+ objects: [bitdepth_objs, entrypoints_objs],
127200 include_directories: dav1d_inc_dirs,
128201 c_args: [stackalign_flag],
129202 dependencies: thread_dependency,
130203 install: true
131204 )
132205
206+install_subdir('include/dav1d/', install_dir: 'include')
207+
208+#
209+# dav1d cli tool
210+#
211+dav1d_sources = files(
212+ 'tools/dav1d.c',
213+ 'tools/dav1d_cli_parse.c',
214+ 'tools/input/input.c',
215+ 'tools/input/ivf.c',
216+ 'tools/output/md5.c',
217+ 'tools/output/output.c',
218+ 'tools/output/y4m2.c',
219+ 'tools/output/yuv.c'
220+)
221+
222+dav1d = executable('dav1d',
223+ dav1d_sources, rev_target,
224+ link_with: libdav1d,
225+ include_directories: [dav1d_inc_dirs, include_directories('tools')]
226+)
227+
133228 #
134229 # pkg-config boilerplate
135230 #
meson_options.txt+6−0
@@ -0,0 +1,6 @@
1+# General options
2+
3+option('bitdepths',
4+ type: 'array',
5+ choices: ['8', '10'],
6+ description: 'Enable only specified bitdepths')
src/cdef.c+271−0
@@ -0,0 +1,271 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#include "config.h"
29+
30+#include <stdlib.h>
31+
32+#include "common/intops.h"
33+
34+#include "src/cdef.h"
35+
36+static const int8_t cdef_directions[8 /* dir */][2 /* pass */][2 /* y, x */] = {
37+ { { -1, 1 }, { -2, 2 } },
38+ { { 0, 1 }, { -1, 2 } },
39+ { { 0, 1 }, { 0, 2 } },
40+ { { 0, 1 }, { 1, 2 } },
41+ { { 1, 1 }, { 2, 2 } },
42+ { { 1, 0 }, { 2, 1 } },
43+ { { 1, 0 }, { 2, 0 } },
44+ { { 1, 0 }, { 2, -1 } }
45+};
46+static const uint8_t cdef_pri_taps[2][2] = { { 4, 2 }, { 3, 3 } };
47+static const uint8_t cdef_sec_taps[2][2] = { { 2, 1 }, { 2, 1 } };
48+
49+static inline int constrain(const int diff, const int threshold,
50+ const int damping)
51+{
52+ if (!threshold) return 0;
53+ const int shift = imax(0, damping - ulog2(threshold));
54+ return apply_sign(imin(abs(diff), imax(0, threshold - (abs(diff) >> shift))),
55+ diff);
56+}
57+
58+/*
59+ * <code partially copied from libaom>
60+ */
61+
62+#define CDEF_VERY_LARGE (30000)
63+
64+static void fill(uint16_t *tmp, const ptrdiff_t stride,
65+ const int w, const int h)
66+{
67+ for (int y = 0; y < h; y++) {
68+ for (int x = 0; x < w; x++)
69+ tmp[x] = CDEF_VERY_LARGE;
70+ tmp += stride;
71+ }
72+}
73+
74+/* Smooth in the direction detected. */
75+static void cdef_filter_block_c(pixel *const dst, const ptrdiff_t dst_stride,
76+ /*const*/ pixel *const top[2],
77+ const int w, const int h, const int pri_strength,
78+ const int sec_strength, const int dir,
79+ const int damping, const enum CdefEdgeFlags edges)
80+{
81+ const ptrdiff_t tmp_stride = w + 4;
82+ uint16_t tmp[tmp_stride * (h + 4)];
83+ const uint8_t *const pri_taps = cdef_pri_taps[(pri_strength >> (BITDEPTH - 8)) & 1];
84+ const uint8_t *const sec_taps = cdef_sec_taps[(pri_strength >> (BITDEPTH - 8)) & 1];
85+
86+ // fill extended input buffer
87+ int x_start = -2, x_end = w + 2, y_start = -2, y_end = h + 2;
88+ if (!(edges & HAVE_TOP)) {
89+ fill(tmp, tmp_stride, w + 4, 2);
90+ y_start = 0;
91+ }
92+ if (!(edges & HAVE_BOTTOM)) {
93+ fill(tmp + (h + 2) * tmp_stride, tmp_stride, w + 4, 2);
94+ y_end -= 2;
95+ }
96+ if (!(edges & HAVE_LEFT)) {
97+ fill(tmp + (2 + y_start) * tmp_stride, tmp_stride, 2, y_end - y_start);
98+ x_start = 0;
99+ }
100+ if (!(edges & HAVE_RIGHT)) {
101+ fill(tmp + (2 + y_start) * tmp_stride + w + 2, tmp_stride,
102+ 2, y_end - y_start);
103+ x_end -= 2;
104+ }
105+ for (int y = y_start; y < 0; y++)
106+ for (int x = x_start; x < x_end; x++)
107+ tmp[(y + 2) * tmp_stride + (x + 2)] = top[y & 1][x];
108+ for (int y = 0; y < y_end; y++)
109+ for (int x = x_start; x < x_end; x++)
110+ tmp[(y + 2) * tmp_stride + (x + 2)] = dst[y * PXSTRIDE(dst_stride) + x];
111+
112+ // run actual filter
113+ for (int y = 0; y < h; y++) {
114+ for (int x = 0; x < w; x++) {
115+ int sum = 0;
116+ const int px = dst[y * PXSTRIDE(dst_stride) + x];
117+ int max = px, min = px;
118+ for (int k = 0; k < 2; k++) {
119+#define extpx(y, x) tmp[((y) + 2) * tmp_stride + ((x) + 2)]
120+ const int8_t *const off1 = cdef_directions[dir][k];
121+ const int p0 = extpx(y + off1[0], x + off1[1]);
122+ const int p1 = extpx(y - off1[0], x - off1[1]);
123+ sum += pri_taps[k] * constrain(p0 - px, pri_strength, damping);
124+ sum += pri_taps[k] * constrain(p1 - px, pri_strength, damping);
125+ if (p0 != CDEF_VERY_LARGE) max = imax(p0, max);
126+ if (p1 != CDEF_VERY_LARGE) max = imax(p1, max);
127+ min = imin(p0, min);
128+ min = imin(p1, min);
129+ const int8_t *const off2 = cdef_directions[(dir + 2) & 7][k];
130+ const int s0 = extpx(y + off2[0], x + off2[1]);
131+ const int s1 = extpx(y - off2[0], x - off2[1]);
132+ const int8_t *const off3 = cdef_directions[(dir + 6) & 7][k];
133+ const int s2 = extpx(y + off3[0], x + off3[1]);
134+ const int s3 = extpx(y - off3[0], x - off3[1]);
135+#undef extpx
136+ if (s0 != CDEF_VERY_LARGE) max = imax(s0, max);
137+ if (s1 != CDEF_VERY_LARGE) max = imax(s1, max);
138+ if (s2 != CDEF_VERY_LARGE) max = imax(s2, max);
139+ if (s3 != CDEF_VERY_LARGE) max = imax(s3, max);
140+ min = imin(s0, min);
141+ min = imin(s1, min);
142+ min = imin(s2, min);
143+ min = imin(s3, min);
144+ sum += sec_taps[k] * constrain(s0 - px, sec_strength, damping);
145+ sum += sec_taps[k] * constrain(s1 - px, sec_strength, damping);
146+ sum += sec_taps[k] * constrain(s2 - px, sec_strength, damping);
147+ sum += sec_taps[k] * constrain(s3 - px, sec_strength, damping);
148+ }
149+ dst[y * PXSTRIDE(dst_stride) + x] =
150+ iclip(px + ((8 + sum - (sum < 0)) >> 4), min, max);
151+ }
152+ }
153+}
154+
155+/*
156+ * </code partially copied from libaom>
157+ */
158+
159+#define cdef_fn(w, h) \
160+static void cdef_filter_block_##w##x##h##_c(pixel *const dst, \
161+ const ptrdiff_t stride, \
162+ /*const*/ pixel *const top[2], \
163+ const int pri_strength, \
164+ const int sec_strength, \
165+ const int dir, \
166+ const int damping, \
167+ const enum CdefEdgeFlags edges) \
168+{ \
169+ cdef_filter_block_c(dst, stride, top, w, h, pri_strength, sec_strength, \
170+ dir, damping, edges); \
171+}
172+
173+cdef_fn(4, 4);
174+cdef_fn(4, 8);
175+cdef_fn(8, 8);
176+
177+/*
178+ * <code copied from libaom>
179+ */
180+
181+/* Detect direction. 0 means 45-degree up-right, 2 is horizontal, and so on.
182+ The search minimizes the weighted variance along all the lines in a
183+ particular direction, i.e. the squared error between the input and a
184+ "predicted" block where each pixel is replaced by the average along a line
185+ in a particular direction. Since each direction have the same sum(x^2) term,
186+ that term is never computed. See Section 2, step 2, of:
187+ http://jmvalin.ca/notes/intra_paint.pdf */
188+static const uint16_t div_table[] = {
189+ 0, 840, 420, 280, 210, 168, 140, 120, 105
190+};
191+static int cdef_find_dir_c(const pixel *img, const ptrdiff_t stride,
192+ unsigned *const var)
193+{
194+ int i;
195+ int32_t cost[8] = { 0 };
196+ int partial[8][15] = { { 0 } };
197+ int32_t best_cost = 0;
198+ int best_dir = 0;
199+ /* Instead of dividing by n between 2 and 8, we multiply by 3*5*7*8/n.
200+ The output is then 840 times larger, but we don't care for finding
201+ the max. */
202+ for (i = 0; i < 8; i++) {
203+ int j;
204+ for (j = 0; j < 8; j++) {
205+ int x;
206+ /* We subtract 128 here to reduce the maximum range of the squared
207+ partial sums. */
208+ x = (img[i * PXSTRIDE(stride) + j] >> (BITDEPTH - 8)) - 128;
209+ partial[0][i + j] += x;
210+ partial[1][i + j / 2] += x;
211+ partial[2][i] += x;
212+ partial[3][3 + i - j / 2] += x;
213+ partial[4][7 + i - j] += x;
214+ partial[5][3 - i / 2 + j] += x;
215+ partial[6][j] += x;
216+ partial[7][i / 2 + j] += x;
217+ }
218+ }
219+ for (i = 0; i < 8; i++) {
220+ cost[2] += partial[2][i] * partial[2][i];
221+ cost[6] += partial[6][i] * partial[6][i];
222+ }
223+ cost[2] *= div_table[8];
224+ cost[6] *= div_table[8];
225+ for (i = 0; i < 7; i++) {
226+ cost[0] += (partial[0][i] * partial[0][i] +
227+ partial[0][14 - i] * partial[0][14 - i]) *
228+ div_table[i + 1];
229+ cost[4] += (partial[4][i] * partial[4][i] +
230+ partial[4][14 - i] * partial[4][14 - i]) *
231+ div_table[i + 1];
232+ }
233+ cost[0] += partial[0][7] * partial[0][7] * div_table[8];
234+ cost[4] += partial[4][7] * partial[4][7] * div_table[8];
235+ for (i = 1; i < 8; i += 2) {
236+ int j;
237+ for (j = 0; j < 4 + 1; j++) {
238+ cost[i] += partial[i][3 + j] * partial[i][3 + j];
239+ }
240+ cost[i] *= div_table[8];
241+ for (j = 0; j < 4 - 1; j++) {
242+ cost[i] += (partial[i][j] * partial[i][j] +
243+ partial[i][10 - j] * partial[i][10 - j]) *
244+ div_table[2 * j + 2];
245+ }
246+ }
247+ for (i = 0; i < 8; i++) {
248+ if (cost[i] > best_cost) {
249+ best_cost = cost[i];
250+ best_dir = i;
251+ }
252+ }
253+ /* Difference between the optimal variance and the variance along the
254+ orthogonal direction. Again, the sum(x^2) terms cancel out. */
255+ *var = best_cost - cost[(best_dir + 4) & 7];
256+ /* We'd normally divide by 840, but dividing by 1024 is close enough
257+ for what we're going to do with this. */
258+ *var >>= 10;
259+ return best_dir;
260+}
261+
262+/*
263+ * </code copied from libaom>
264+ */
265+
266+void bitfn(dav1d_cdef_dsp_init)(Dav1dCdefDSPContext *const c) {
267+ c->dir = cdef_find_dir_c;
268+ c->fb[0] = cdef_filter_block_8x8_c;
269+ c->fb[1] = cdef_filter_block_4x8_c;
270+ c->fb[2] = cdef_filter_block_4x4_c;
271+}
src/cdef.h+62−0
@@ -0,0 +1,62 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __DAV1D_SRC_CDEF_H__
29+#define __DAV1D_SRC_CDEF_H__
30+
31+#include <stddef.h>
32+#include <stdint.h>
33+
34+#include "common/bitdepth.h"
35+
36+enum CdefEdgeFlags {
37+ HAVE_LEFT = 1 << 0,
38+ HAVE_RIGHT = 1 << 1,
39+ HAVE_TOP = 1 << 2,
40+ HAVE_BOTTOM = 1 << 3,
41+};
42+
43+// CDEF operates entirely on pre-filter data; if bottom/right edges are
44+// present (according to $edges), then the pre-filter data is located in
45+// $dst. However, the edge pixels above $dst may be post-filter, so in
46+// order to get access to pre-filter top pixels, use $top.
47+typedef void (*cdef_fn)(pixel *dst, ptrdiff_t stride,
48+ /*const*/ pixel *const top[2],
49+ int pri_strength, int sec_strength,
50+ int dir, int damping, enum CdefEdgeFlags edges);
51+typedef int (*cdef_dir_fn)(const pixel *dst, ptrdiff_t stride,
52+ unsigned *var);
53+
54+typedef struct Dav1dCdefDSPContext {
55+ cdef_dir_fn dir;
56+ cdef_fn fb[3 /* 444/luma, 422, 420 */];
57+} Dav1dCdefDSPContext;
58+
59+void dav1d_cdef_dsp_init_8bpc(Dav1dCdefDSPContext *c);
60+void dav1d_cdef_dsp_init_10bpc(Dav1dCdefDSPContext *c);
61+
62+#endif /* __DAV1D_SRC_CDEF_H__ */
src/cdef_apply.c+237−0
@@ -0,0 +1,237 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#include "config.h"
29+
30+#include <string.h>
31+
32+#include "common/intops.h"
33+
34+#include "src/cdef_apply.h"
35+
36+static void backup2lines(pixel *const dst[3][2],
37+ /*const*/ pixel *const src[3],
38+ const ptrdiff_t src_stride[2], int y_off, int w,
39+ const enum Dav1dPixelLayout layout)
40+{
41+ pixel_copy(dst[0][0], src[0] + (y_off - 2) * PXSTRIDE(src_stride[0]), w);
42+ pixel_copy(dst[0][1], src[0] + (y_off - 1) * PXSTRIDE(src_stride[0]), w);
43+
44+ if (layout == DAV1D_PIXEL_LAYOUT_I400) return;
45+ const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420;
46+ const int ss_hor = layout != DAV1D_PIXEL_LAYOUT_I444;
47+
48+ w >>= ss_hor;
49+ y_off >>= ss_ver;
50+ pixel_copy(dst[1][0], src[1] + (y_off - 2) * PXSTRIDE(src_stride[1]), w);
51+ pixel_copy(dst[1][1], src[1] + (y_off - 1) * PXSTRIDE(src_stride[1]), w);
52+ pixel_copy(dst[2][0], src[2] + (y_off - 2) * PXSTRIDE(src_stride[1]), w);
53+ pixel_copy(dst[2][1], src[2] + (y_off - 1) * PXSTRIDE(src_stride[1]), w);
54+}
55+
56+static void backup2x8(pixel dst[3][8][2],
57+ /*const*/ pixel *const src[3],
58+ const ptrdiff_t src_stride[2], int x_off,
59+ const enum Dav1dPixelLayout layout)
60+{
61+ for (int y = 0, y_off = 0; y < 8; y++, y_off += PXSTRIDE(src_stride[0]))
62+ pixel_copy(dst[0][y], &src[0][y_off + x_off - 2], 2);
63+
64+ if (layout == DAV1D_PIXEL_LAYOUT_I400) return;
65+ const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420;
66+ const int ss_hor = layout != DAV1D_PIXEL_LAYOUT_I444;
67+
68+ x_off >>= ss_hor;
69+ for (int y = 0, y_off = 0; y < (8 >> ss_ver); y++, y_off += PXSTRIDE(src_stride[1])) {
70+ pixel_copy(dst[1][y], &src[1][y_off + x_off - 2], 2);
71+ pixel_copy(dst[2][y], &src[2][y_off + x_off - 2], 2);
72+ }
73+}
74+
75+static void restore2x8(pixel *const dst[3],
76+ const ptrdiff_t dst_stride[2],
77+ const pixel src[3][8][2], const enum Dav1dPixelLayout layout)
78+{
79+ for (int y = 0, y_off = 0; y < 8; y++, y_off += PXSTRIDE(dst_stride[0]))
80+ pixel_copy(&dst[0][y_off - 2], src[0][y], 2);
81+
82+ if (layout == DAV1D_PIXEL_LAYOUT_I400) return;
83+ const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420;
84+
85+ for (int y = 0, y_off = 0; y < (8 >> ss_ver); y++, y_off += PXSTRIDE(dst_stride[1])) {
86+ pixel_copy(&dst[1][y_off - 2], src[1][y], 2);
87+ pixel_copy(&dst[2][y_off - 2], src[2][y], 2);
88+ }
89+}
90+
91+static int adjust_strength(const int strength, const unsigned var) {
92+ if (!var) return 0;
93+ const int i = var >> 6 ? imin(ulog2(var >> 6), 12) : 0;
94+ return (strength * (4 + i) + 8) >> 4;
95+}
96+
97+void bytefn(dav1d_cdef_brow)(Dav1dFrameContext *const f,
98+ pixel *const p[3],
99+ const Av1Filter *const lflvl,
100+ const int by_start, const int by_end)
101+{
102+ const Dav1dDSPContext *const dsp = f->dsp;
103+ enum CdefEdgeFlags edges = HAVE_BOTTOM | (by_start > 0 ? HAVE_TOP : 0);
104+ pixel *ptrs[3] = { p[0], p[1], p[2] };
105+ const int sbsz = 16;
106+ const int sb64w = f->sb128w << 1;
107+ const int damping = f->frame_hdr.cdef.damping + BITDEPTH - 8;
108+ const enum Dav1dPixelLayout layout = f->cur.p.p.layout;
109+ const int uv_idx = DAV1D_PIXEL_LAYOUT_I444 - layout;
110+ const int has_chroma = layout != DAV1D_PIXEL_LAYOUT_I400;
111+ const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420;
112+ const int ss_hor = layout != DAV1D_PIXEL_LAYOUT_I444;
113+
114+ // FIXME a design improvement that could be made here is to keep a set of
115+ // flags for each block position on whether the block was filtered; if not,
116+ // the backup of pre-filter data is empty, and the restore is therefore
117+ // unnecessary as well.
118+
119+ for (int by = by_start; by < by_end; by += 2, edges |= HAVE_TOP) {
120+ const int tf = f->lf.top_pre_cdef_toggle;
121+ if (by + 2 >= f->bh) edges &= ~HAVE_BOTTOM;
122+
123+ if (edges & HAVE_BOTTOM) {
124+ // backup pre-filter data for next iteration
125+ backup2lines(f->lf.cdef_line_ptr[!tf], ptrs, f->cur.p.stride,
126+ 8, f->bw * 4, layout);
127+ }
128+
129+ pixel lr_bak[2 /* idx */][3 /* plane */][8 /* y */][2 /* x */];
130+ pixel *iptrs[3] = { ptrs[0], ptrs[1], ptrs[2] };
131+ edges &= ~HAVE_LEFT;
132+ edges |= HAVE_RIGHT;
133+ for (int sbx = 0, last_skip = 1; sbx < sb64w; sbx++, edges |= HAVE_LEFT) {
134+ const int sb128x = sbx >>1;
135+ const int sb64_idx = ((by & sbsz) >> 3) + (sbx & 1);
136+ const int cdef_idx = lflvl[sb128x].cdef_idx[sb64_idx];
137+ if (cdef_idx == -1 ||
138+ (!f->frame_hdr.cdef.y_strength[cdef_idx] &&
139+ !f->frame_hdr.cdef.uv_strength[cdef_idx]))
140+ {
141+ last_skip = 1;
142+ goto next_sb;
143+ }
144+
145+ const int y_lvl = f->frame_hdr.cdef.y_strength[cdef_idx];
146+ const int uv_lvl = f->frame_hdr.cdef.uv_strength[cdef_idx];
147+ pixel *bptrs[3] = { iptrs[0], iptrs[1], iptrs[2] };
148+ for (int bx = sbx * sbsz; bx < imin((sbx + 1) * sbsz, f->bw);
149+ bx += 2, edges |= HAVE_LEFT)
150+ {
151+ if (bx + 2 >= f->bw) edges &= ~HAVE_RIGHT;
152+
153+ // check if this 8x8 block had any coded coefficients; if not,
154+ // go to the next block
155+ const unsigned bx_mask = 3U << (bx & 30);
156+ const int by_idx = by & 30;
157+ if (!((lflvl[sb128x].noskip_mask[by_idx + 0] |
158+ lflvl[sb128x].noskip_mask[by_idx + 1]) & bx_mask))
159+ {
160+ last_skip = 1;
161+ goto next_b;
162+ }
163+
164+ if (!last_skip) {
165+ // backup post-filter data (will be restored at the end)
166+ backup2x8(lr_bak[1], bptrs, f->cur.p.stride, 0, layout);
167+
168+ // restore pre-filter data from last iteration
169+ restore2x8(bptrs, f->cur.p.stride, lr_bak[0], layout);
170+ }
171+ if (edges & HAVE_RIGHT) {
172+ // backup pre-filter data for next iteration
173+ backup2x8(lr_bak[0], bptrs, f->cur.p.stride, 8, layout);
174+ }
175+
176+ // the actual filter
177+ const int y_pri_lvl = (y_lvl >> 2) << (BITDEPTH - 8);
178+ int y_sec_lvl = y_lvl & 3;
179+ y_sec_lvl += y_sec_lvl == 3;
180+ y_sec_lvl <<= BITDEPTH - 8;
181+ const int uv_pri_lvl = (uv_lvl >> 2) << (BITDEPTH - 8);
182+ int uv_sec_lvl = uv_lvl & 3;
183+ uv_sec_lvl += uv_sec_lvl == 3;
184+ uv_sec_lvl <<= BITDEPTH - 8;
185+ unsigned variance;
186+ const int dir = dsp->cdef.dir(bptrs[0], f->cur.p.stride[0],
187+ &variance);
188+ if (y_lvl) {
189+ dsp->cdef.fb[0](bptrs[0], f->cur.p.stride[0],
190+ (pixel *const [2]) {
191+ &f->lf.cdef_line_ptr[tf][0][0][bx * 4],
192+ &f->lf.cdef_line_ptr[tf][0][1][bx * 4],
193+ },
194+ adjust_strength(y_pri_lvl, variance),
195+ y_sec_lvl, y_pri_lvl ? dir : 0,
196+ damping, edges);
197+ }
198+ if (uv_lvl && has_chroma) {
199+ const int uvdir =
200+ f->cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I422 ? dir :
201+ ((uint8_t[]) { 7, 0, 2, 4, 5, 6, 6, 6 })[dir];
202+ for (int pl = 1; pl <= 2; pl++) {
203+ dsp->cdef.fb[uv_idx](bptrs[pl], f->cur.p.stride[1],
204+ (pixel *const [2]) {
205+ &f->lf.cdef_line_ptr[tf][pl][0][bx * 4 >> ss_hor],
206+ &f->lf.cdef_line_ptr[tf][pl][1][bx * 4 >> ss_hor],
207+ },
208+ uv_pri_lvl, uv_sec_lvl,
209+ uv_pri_lvl ? uvdir : 0,
210+ damping - 1, edges);
211+ }
212+ }
213+
214+ if (!last_skip) {
215+ // restore post-filter data from the beginning of this loop
216+ restore2x8(bptrs, f->cur.p.stride, lr_bak[1], layout);
217+ }
218+ last_skip = 0;
219+
220+ next_b:
221+ bptrs[0] += 8;
222+ bptrs[1] += 8 >> ss_hor;
223+ bptrs[2] += 8 >> ss_hor;
224+ }
225+
226+ next_sb:
227+ iptrs[0] += sbsz * 4;
228+ iptrs[1] += sbsz * 4 >> ss_hor;
229+ iptrs[2] += sbsz * 4 >> ss_hor;
230+ }
231+
232+ ptrs[0] += 8 * PXSTRIDE(f->cur.p.stride[0]);
233+ ptrs[1] += 8 * PXSTRIDE(f->cur.p.stride[1]) >> ss_ver;
234+ ptrs[2] += 8 * PXSTRIDE(f->cur.p.stride[1]) >> ss_ver;
235+ f->lf.top_pre_cdef_toggle ^= 1;
236+ }
237+}
src/cdef_apply.h+38−0
@@ -0,0 +1,38 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __DAV1D_SRC_CDEF_APPLY_H__
29+#define __DAV1D_SRC_CDEF_APPLY_H__
30+
31+#include "common/bitdepth.h"
32+
33+#include "src/internal.h"
34+
35+void bytefn(dav1d_cdef_brow)(Dav1dFrameContext *f, pixel *const p[3],
36+ const Av1Filter *lflvl, int by_start, int by_end);
37+
38+#endif /* __DAV1D_SRC_CDEF_APPLY_H__ */
src/cdf.c+4251−0
@@ -0,0 +1,4251 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#include "config.h"
29+
30+#include <assert.h>
31+#include <pthread.h>
32+#include <string.h>
33+
34+#include "common/intops.h"
35+
36+#include "src/cdf.h"
37+
38+#define AOM_ICDF(x) (32768-(x))
39+
40+#define AOM_CDF2(a) \
41+ AOM_ICDF(a)
42+#define AOM_CDF3(a,b) \
43+ AOM_ICDF(a), AOM_ICDF(b)
44+#define AOM_CDF4(a,b,c) \
45+ AOM_ICDF(a), AOM_CDF3(b,c)
46+#define AOM_CDF5(a,b,c,d) \
47+ AOM_ICDF(a), AOM_CDF4(b,c,d)
48+#define AOM_CDF6(a,b,c,d,e) \
49+ AOM_ICDF(a), AOM_CDF5(b,c,d,e)
50+#define AOM_CDF7(a,b,c,d,e,f) \
51+ AOM_ICDF(a), AOM_CDF6(b,c,d,e,f)
52+#define AOM_CDF8(a,b,c,d,e,f,g) \
53+ AOM_ICDF(a), AOM_CDF7(b,c,d,e,f,g)
54+#define AOM_CDF9(a,b,c,d,e,f,g,h) \
55+ AOM_ICDF(a), AOM_CDF8(b,c,d,e,f,g,h)
56+#define AOM_CDF10(a,b,c,d,e,f,g,h,i) \
57+ AOM_ICDF(a), AOM_CDF9(b,c,d,e,f,g,h,i)
58+#define AOM_CDF11(a,b,c,d,e,f,g,h,i,j) \
59+ AOM_ICDF(a), AOM_CDF10(b,c,d,e,f,g,h,i,j)
60+#define AOM_CDF12(a,b,c,d,e,f,g,h,i,j,k) \
61+ AOM_ICDF(a), AOM_CDF11(b,c,d,e,f,g,h,i,j,k)
62+#define AOM_CDF13(a,b,c,d,e,f,g,h,i,j,k,l) \
63+ AOM_ICDF(a), AOM_CDF12(b,c,d,e,f,g,h,i,j,k,l)
64+#define AOM_CDF14(a,b,c,d,e,f,g,h,i,j,k,l,m) \
65+ AOM_ICDF(a), AOM_CDF13(b,c,d,e,f,g,h,i,j,k,l,m)
66+#define AOM_CDF15(a,b,c,d,e,f,g,h,i,j,k,l,m,n) \
67+ AOM_ICDF(a), AOM_CDF14(b,c,d,e,f,g,h,i,j,k,l,m,n)
68+#define AOM_CDF16(a,b,c,d,e,f,g,h,i,j,k,l,m,n,o) \
69+ AOM_ICDF(a), AOM_CDF15(b,c,d,e,f,g,h,i,j,k,l,m,n,o)
70+
71+static const CdfModeContext av1_default_cdf = {
72+ .y_mode = {
73+ { AOM_CDF13(22801, 23489, 24293, 24756, 25601, 26123,
74+ 26606, 27418, 27945, 29228, 29685, 30349) },
75+ { AOM_CDF13(18673, 19845, 22631, 23318, 23950, 24649,
76+ 25527, 27364, 28152, 29701, 29984, 30852) },
77+ { AOM_CDF13(19770, 20979, 23396, 23939, 24241, 24654,
78+ 25136, 27073, 27830, 29360, 29730, 30659) },
79+ { AOM_CDF13(20155, 21301, 22838, 23178, 23261, 23533,
80+ 23703, 24804, 25352, 26575, 27016, 28049) },
81+ }, .use_filter_intra = {
82+ [BS_4x4] = { AOM_CDF2(4621) },
83+ [BS_4x8] = { AOM_CDF2(6743) },
84+ [BS_8x4] = { AOM_CDF2(5893) },
85+ [BS_8x8] = { AOM_CDF2(7866) },
86+ [BS_8x16] = { AOM_CDF2(12551) },
87+ [BS_16x8] = { AOM_CDF2(9394) },
88+ [BS_16x16] = { AOM_CDF2(12408) },
89+ [BS_16x32] = { AOM_CDF2(14301) },
90+ [BS_32x16] = { AOM_CDF2(12756) },
91+ [BS_32x32] = { AOM_CDF2(22343) },
92+ [BS_32x64] = { AOM_CDF2(16384) },
93+ [BS_64x32] = { AOM_CDF2(16384) },
94+ [BS_64x64] = { AOM_CDF2(16384) },
95+ [BS_64x128] = { AOM_CDF2(16384) },
96+ [BS_128x64] = { AOM_CDF2(16384) },
97+ [BS_128x128] = { AOM_CDF2(16384) },
98+ [BS_4x16] = { AOM_CDF2(12770) },
99+ [BS_16x4] = { AOM_CDF2(10368) },
100+ [BS_8x32] = { AOM_CDF2(20229) },
101+ [BS_32x8] = { AOM_CDF2(18101) },
102+ [BS_16x64] = { AOM_CDF2(16384) },
103+ [BS_64x16] = { AOM_CDF2(16384) },
104+ }, .filter_intra = {
105+ AOM_CDF5(8949, 12776, 17211, 29558),
106+ }, .uv_mode = {
107+ {
108+ { AOM_CDF13(22631, 24152, 25378, 25661, 25986, 26520, 27055, 27923,
109+ 28244, 30059, 30941, 31961) },
110+ { AOM_CDF13(9513, 26881, 26973, 27046, 27118, 27664, 27739, 27824,
111+ 28359, 29505, 29800, 31796) },
112+ { AOM_CDF13(9845, 9915, 28663, 28704, 28757, 28780, 29198, 29822,
113+ 29854, 30764, 31777, 32029) },
114+ { AOM_CDF13(13639, 13897, 14171, 25331, 25606, 25727, 25953, 27148,
115+ 28577, 30612, 31355, 32493) },
116+ { AOM_CDF13(9764, 9835, 9930, 9954, 25386, 27053, 27958, 28148,
117+ 28243, 31101, 31744, 32363) },
118+ { AOM_CDF13(11825, 13589, 13677, 13720, 15048, 29213, 29301, 29458,
119+ 29711, 31161, 31441, 32550) },
120+ { AOM_CDF13(14175, 14399, 16608, 16821, 17718, 17775, 28551, 30200,
121+ 30245, 31837, 32342, 32667) },
122+ { AOM_CDF13(12885, 13038, 14978, 15590, 15673, 15748, 16176, 29128,
123+ 29267, 30643, 31961, 32461) },
124+ { AOM_CDF13(12026, 13661, 13874, 15305, 15490, 15726, 15995, 16273,
125+ 28443, 30388, 30767, 32416) },
126+ { AOM_CDF13(19052, 19840, 20579, 20916, 21150, 21467, 21885, 22719,
127+ 23174, 28861, 30379, 32175) },
128+ { AOM_CDF13(18627, 19649, 20974, 21219, 21492, 21816, 22199, 23119,
129+ 23527, 27053, 31397, 32148) },
130+ { AOM_CDF13(17026, 19004, 19997, 20339, 20586, 21103, 21349, 21907,
131+ 22482, 25896, 26541, 31819) },
132+ { AOM_CDF13(12124, 13759, 14959, 14992, 15007, 15051, 15078, 15166,
133+ 15255, 15753, 16039, 16606) }
134+ }, {
135+ { AOM_CDF14(10407, 11208, 12900, 13181, 13823, 14175, 14899, 15656,
136+ 15986, 20086, 20995, 22455, 24212) },
137+ { AOM_CDF14(4532, 19780, 20057, 20215, 20428, 21071, 21199, 21451,
138+ 22099, 24228, 24693, 27032, 29472) },
139+ { AOM_CDF14(5273, 5379, 20177, 20270, 20385, 20439, 20949, 21695,
140+ 21774, 23138, 24256, 24703, 26679) },
141+ { AOM_CDF14(6740, 7167, 7662, 14152, 14536, 14785, 15034, 16741,
142+ 18371, 21520, 22206, 23389, 24182) },
143+ { AOM_CDF14(4987, 5368, 5928, 6068, 19114, 20315, 21857, 22253,
144+ 22411, 24911, 25380, 26027, 26376) },
145+ { AOM_CDF14(5370, 6889, 7247, 7393, 9498, 21114, 21402, 21753,
146+ 21981, 24780, 25386, 26517, 27176) },
147+ { AOM_CDF14(4816, 4961, 7204, 7326, 8765, 8930, 20169, 20682,
148+ 20803, 23188, 23763, 24455, 24940) },
149+ { AOM_CDF14(6608, 6740, 8529, 9049, 9257, 9356, 9735, 18827,
150+ 19059, 22336, 23204, 23964, 24793) },
151+ { AOM_CDF14(5998, 7419, 7781, 8933, 9255, 9549, 9753, 10417,
152+ 18898, 22494, 23139, 24764, 25989) },
153+ { AOM_CDF14(10660, 11298, 12550, 12957, 13322, 13624, 14040, 15004,
154+ 15534, 20714, 21789, 23443, 24861) },
155+ { AOM_CDF14(10522, 11530, 12552, 12963, 13378, 13779, 14245, 15235,
156+ 15902, 20102, 22696, 23774, 25838) },
157+ { AOM_CDF14(10099, 10691, 12639, 13049, 13386, 13665, 14125, 15163,
158+ 15636, 19676, 20474, 23519, 25208) },
159+ { AOM_CDF14(3144, 5087, 7382, 7504, 7593, 7690, 7801, 8064,
160+ 8232, 9248, 9875, 10521, 29048) }
161+ }
162+ }, .angle_delta = {
163+ { AOM_CDF7(2180, 5032, 7567, 22776, 26989, 30217) },
164+ { AOM_CDF7(2301, 5608, 8801, 23487, 26974, 30330) },
165+ { AOM_CDF7(3780, 11018, 13699, 19354, 23083, 31286) },
166+ { AOM_CDF7(4581, 11226, 15147, 17138, 21834, 28397) },
167+ { AOM_CDF7(1737, 10927, 14509, 19588, 22745, 28823) },
168+ { AOM_CDF7(2664, 10176, 12485, 17650, 21600, 30495) },
169+ { AOM_CDF7(2240, 11096, 15453, 20341, 22561, 28917) },
170+ { AOM_CDF7(3605, 10428, 12459, 17676, 21244, 30655) }
171+ }, .filter = {
172+ {
173+ { AOM_CDF3(31935, 32720) },
174+ { AOM_CDF3(5568, 32719) },
175+ { AOM_CDF3(422, 2938) },
176+ { AOM_CDF3(28244, 32608) },
177+ { AOM_CDF3(31206, 31953) },
178+ { AOM_CDF3(4862, 32121) },
179+ { AOM_CDF3(770, 1152) },
180+ { AOM_CDF3(20889, 25637) },
181+ }, {
182+ { AOM_CDF3(31910, 32724) },
183+ { AOM_CDF3(4120, 32712) },
184+ { AOM_CDF3(305, 2247) },
185+ { AOM_CDF3(27403, 32636) },
186+ { AOM_CDF3(31022, 32009) },
187+ { AOM_CDF3(2963, 32093) },
188+ { AOM_CDF3(601, 943) },
189+ { AOM_CDF3(14969, 21398) }
190+ }
191+ }, .newmv_mode = {
192+ { AOM_CDF2(24035) },
193+ { AOM_CDF2(16630) },
194+ { AOM_CDF2(15339) },
195+ { AOM_CDF2(8386) },
196+ { AOM_CDF2(12222) },
197+ { AOM_CDF2(4676) },
198+ }, .globalmv_mode = {
199+ { AOM_CDF2(2175) },
200+ { AOM_CDF2(1054) }
201+ }, .refmv_mode = {
202+ { AOM_CDF2(23974) },
203+ { AOM_CDF2(24188) },
204+ { AOM_CDF2(17848) },
205+ { AOM_CDF2(28622) },
206+ { AOM_CDF2(24312) },
207+ { AOM_CDF2(19923) }
208+ }, .drl_bit = {
209+ { AOM_CDF2(13104) },
210+ { AOM_CDF2(24560) },
211+ { AOM_CDF2(18945) }
212+ }, .comp_inter_mode = {
213+ { AOM_CDF8(7760, 13823, 15808, 17641, 19156, 20666, 26891) },
214+ { AOM_CDF8(10730, 19452, 21145, 22749, 24039, 25131, 28724) },
215+ { AOM_CDF8(10664, 20221, 21588, 22906, 24295, 25387, 28436) },
216+ { AOM_CDF8(13298, 16984, 20471, 24182, 25067, 25736, 26422) },
217+ { AOM_CDF8(18904, 23325, 25242, 27432, 27898, 28258, 30758) },
218+ { AOM_CDF8(10725, 17454, 20124, 22820, 24195, 25168, 26046) },
219+ { AOM_CDF8(17125, 24273, 25814, 27492, 28214, 28704, 30592) },
220+ { AOM_CDF8(13046, 23214, 24505, 25942, 27435, 28442, 29330) }
221+ }, .intra = {
222+ { AOM_CDF2(806) },
223+ { AOM_CDF2(16662) },
224+ { AOM_CDF2(20186) },
225+ { AOM_CDF2(26538) }
226+ }, .comp = {
227+ { AOM_CDF2(26828) },
228+ { AOM_CDF2(24035) },
229+ { AOM_CDF2(12031) },
230+ { AOM_CDF2(10640) },
231+ { AOM_CDF2(2901) }
232+ }, .comp_dir = {
233+ { AOM_CDF2(1198) },
234+ { AOM_CDF2(2070) },
235+ { AOM_CDF2(9166) },
236+ { AOM_CDF2(7499) },
237+ { AOM_CDF2(22475) }
238+ }, .jnt_comp = {
239+ { AOM_CDF2(18244) },
240+ { AOM_CDF2(12865) },
241+ { AOM_CDF2(7053) },
242+ { AOM_CDF2(13259) },
243+ { AOM_CDF2(9334) },
244+ { AOM_CDF2(4644) }
245+ }, .mask_comp = {
246+ { AOM_CDF2(26607) },
247+ { AOM_CDF2(22891) },
248+ { AOM_CDF2(18840) },
249+ { AOM_CDF2(24594) },
250+ { AOM_CDF2(19934) },
251+ { AOM_CDF2(22674) }
252+ }, .wedge_comp = {
253+ { AOM_CDF2(23431) },
254+ { AOM_CDF2(13171) },
255+ { AOM_CDF2(11470) },
256+ { AOM_CDF2(9770) },
257+ { AOM_CDF2(9100) },
258+ { AOM_CDF2(8233) },
259+ { AOM_CDF2(6172) },
260+ { AOM_CDF2(11820) },
261+ { AOM_CDF2(7701) },
262+ }, .wedge_idx = {
263+ { AOM_CDF16(2438, 4440, 6599, 8663, 11005, 12874, 15751, 18094,
264+ 20359, 22362, 24127, 25702, 27752, 29450, 31171) },
265+ { AOM_CDF16(806, 3266, 6005, 6738, 7218, 7367, 7771, 14588,
266+ 16323, 17367, 18452, 19422, 22839, 26127, 29629) },
267+ { AOM_CDF16(2779, 3738, 4683, 7213, 7775, 8017, 8655, 14357,
268+ 17939, 21332, 24520, 27470, 29456, 30529, 31656) },
269+ { AOM_CDF16(1684, 3625, 5675, 7108, 9302, 11274, 14429, 17144,
270+ 19163, 20961, 22884, 24471, 26719, 28714, 30877) },
271+ { AOM_CDF16(1142, 3491, 6277, 7314, 8089, 8355, 9023, 13624,
272+ 15369, 16730, 18114, 19313, 22521, 26012, 29550) },
273+ { AOM_CDF16(2742, 4195, 5727, 8035, 8980, 9336, 10146, 14124,
274+ 17270, 20533, 23434, 25972, 27944, 29570, 31416) },
275+ { AOM_CDF16(1727, 3948, 6101, 7796, 9841, 12344, 15766, 18944,
276+ 20638, 22038, 23963, 25311, 26988, 28766, 31012) },
277+ { AOM_CDF16(154, 987, 1925, 2051, 2088, 2111, 2151, 23033,
278+ 23703, 24284, 24985, 25684, 27259, 28883, 30911) },
279+ { AOM_CDF16(1135, 1322, 1493, 2635, 2696, 2737, 2770, 21016,
280+ 22935, 25057, 27251, 29173, 30089, 30960, 31933) },
281+ }, .interintra = {
282+ { AOM_CDF2(16384) },
283+ { AOM_CDF2(26887) },
284+ { AOM_CDF2(27597) },
285+ { AOM_CDF2(30237) }
286+ }, .interintra_mode = {
287+ { AOM_CDF4(8192, 16384, 24576) },
288+ { AOM_CDF4(1875, 11082, 27332) },
289+ { AOM_CDF4(2473, 9996, 26388) },
290+ { AOM_CDF4(4238, 11537, 25926) }
291+ }, .interintra_wedge = {
292+ { AOM_CDF2(20036) },
293+ { AOM_CDF2(24957) },
294+ { AOM_CDF2(26704) },
295+ { AOM_CDF2(27530) },
296+ { AOM_CDF2(29564) },
297+ { AOM_CDF2(29444) },
298+ { AOM_CDF2(26872) },
299+ }, .ref = {
300+ {
301+ { AOM_CDF2(4897) },
302+ { AOM_CDF2(16973) },
303+ { AOM_CDF2(29744) },
304+ }, {
305+ { AOM_CDF2(1555) },
306+ { AOM_CDF2(16751) },
307+ { AOM_CDF2(30279) },
308+ }, {
309+ { AOM_CDF2(4236) },
310+ { AOM_CDF2(19647) },
311+ { AOM_CDF2(31194) },
312+ }, {
313+ { AOM_CDF2(8650) },
314+ { AOM_CDF2(24773) },
315+ { AOM_CDF2(31895) },
316+ }, {
317+ { AOM_CDF2(904) },
318+ { AOM_CDF2(11014) },
319+ { AOM_CDF2(26875) },
320+ }, {
321+ { AOM_CDF2(1444) },
322+ { AOM_CDF2(15087) },
323+ { AOM_CDF2(30304) },
324+ }
325+ }, .comp_fwd_ref = {
326+ {
327+ { AOM_CDF2(4946) },
328+ { AOM_CDF2(19891) },
329+ { AOM_CDF2(30731) },
330+ }, {
331+ { AOM_CDF2(9468) },
332+ { AOM_CDF2(22441) },
333+ { AOM_CDF2(31059) },
334+ }, {
335+ { AOM_CDF2(1503) },
336+ { AOM_CDF2(15160) },
337+ { AOM_CDF2(27544) },
338+ }
339+ }, .comp_bwd_ref = {
340+ {
341+ { AOM_CDF2(2235) },
342+ { AOM_CDF2(17182) },
343+ { AOM_CDF2(30606) },
344+ }, {
345+ { AOM_CDF2(1423) },
346+ { AOM_CDF2(15175) },
347+ { AOM_CDF2(30489) },
348+ }
349+ }, .comp_uni_ref = {
350+ {
351+ { AOM_CDF2(5284) },
352+ { AOM_CDF2(23152) },
353+ { AOM_CDF2(31774) },
354+ }, {
355+ { AOM_CDF2(3865) },
356+ { AOM_CDF2(14173) },
357+ { AOM_CDF2(25120) },
358+ }, {
359+ { AOM_CDF2(3128) },
360+ { AOM_CDF2(15270) },
361+ { AOM_CDF2(26710) },
362+ }
363+ }, .txsz = {
364+ {
365+ { AOM_CDF2(19968) },
366+ { AOM_CDF2(19968) },
367+ { AOM_CDF2(24320) }
368+ }, {
369+ { AOM_CDF3(12272, 30172) },
370+ { AOM_CDF3(12272, 30172) },
371+ { AOM_CDF3(18677, 30848) }
372+ }, {
373+ { AOM_CDF3(12986, 15180) },
374+ { AOM_CDF3(12986, 15180) },
375+ { AOM_CDF3(24302, 25602) }
376+ }, {
377+ { AOM_CDF3(5782, 11475) },
378+ { AOM_CDF3(5782, 11475) },
379+ { AOM_CDF3(16803, 22759) }
380+ }
381+ }, .txpart = {
382+ { { AOM_CDF2(28581) }, { AOM_CDF2(23846) }, { AOM_CDF2(20847) }, },
383+ { { AOM_CDF2(24315) }, { AOM_CDF2(18196) }, { AOM_CDF2(12133) }, },
384+ { { AOM_CDF2(18791) }, { AOM_CDF2(10887) }, { AOM_CDF2(11005) }, },
385+ { { AOM_CDF2(27179) }, { AOM_CDF2(20004) }, { AOM_CDF2(11281) }, },
386+ { { AOM_CDF2(26549) }, { AOM_CDF2(19308) }, { AOM_CDF2(14224) }, },
387+ { { AOM_CDF2(28015) }, { AOM_CDF2(21546) }, { AOM_CDF2(14400) }, },
388+ { { AOM_CDF2(28165) }, { AOM_CDF2(22401) }, { AOM_CDF2(16088) }, },
389+ }, .txtp_inter = {
390+ {}, {
391+ { AOM_CDF16(4458, 5560, 7695, 9709, 13330, 14789, 17537, 20266,
392+ 21504, 22848, 23934, 25474, 27727, 28915, 30631) },
393+ { AOM_CDF16(1645, 2573, 4778, 5711, 7807, 8622, 10522, 15357,
394+ 17674, 20408, 22517, 25010, 27116, 28856, 30749) },
395+ { AOM_CDF16(2048, 4096, 6144, 8192, 10240, 12288, 14336, 16384,
396+ 18432, 20480, 22528, 24576, 26624, 28672, 30720) },
397+ { AOM_CDF16(2048, 4096, 6144, 8192, 10240, 12288, 14336, 16384,
398+ 18432, 20480, 22528, 24576, 26624, 28672, 30720) },
399+ }, {
400+ { AOM_CDF12(2731, 5461, 8192, 10923, 13653, 16384, 19115, 21845,
401+ 24576, 27307, 30037) },
402+ { AOM_CDF12(2731, 5461, 8192, 10923, 13653, 16384, 19115, 21845,
403+ 24576, 27307, 30037) },
404+ { AOM_CDF12(770, 2421, 5225, 12907, 15819, 18927, 21561, 24089,
405+ 26595, 28526, 30529) },
406+ { AOM_CDF12(2731, 5461, 8192, 10923, 13653, 16384, 19115, 21845,
407+ 24576, 27307, 30037) },
408+ }, {
409+ { AOM_CDF2(16384) },
410+ { AOM_CDF2(4167) },
411+ { AOM_CDF2(1998) },
412+ { AOM_CDF2(748) },
413+ },
414+ }, .txtp_intra = {
415+ {}, {
416+ {
417+ { AOM_CDF7(1535, 8035, 9461, 12751, 23467, 27825) },
418+ { AOM_CDF7(564, 3335, 9709, 10870, 18143, 28094) },
419+ { AOM_CDF7(672, 3247, 3676, 11982, 19415, 23127) },
420+ { AOM_CDF7(5279, 13885, 15487, 18044, 23527, 30252) },
421+ { AOM_CDF7(4423, 6074, 7985, 10416, 25693, 29298) },
422+ { AOM_CDF7(1486, 4241, 9460, 10662, 16456, 27694) },
423+ { AOM_CDF7(439, 2838, 3522, 6737, 18058, 23754) },
424+ { AOM_CDF7(1190, 4233, 4855, 11670, 20281, 24377) },
425+ { AOM_CDF7(1045, 4312, 8647, 10159, 18644, 29335) },
426+ { AOM_CDF7(202, 3734, 4747, 7298, 17127, 24016) },
427+ { AOM_CDF7(447, 4312, 6819, 8884, 16010, 23858) },
428+ { AOM_CDF7(277, 4369, 5255, 8905, 16465, 22271) },
429+ { AOM_CDF7(3409, 5436, 10599, 15599, 19687, 24040) },
430+ }, {
431+ { AOM_CDF7(1870, 13742, 14530, 16498, 23770, 27698) },
432+ { AOM_CDF7(326, 8796, 14632, 15079, 19272, 27486) },
433+ { AOM_CDF7(484, 7576, 7712, 14443, 19159, 22591) },
434+ { AOM_CDF7(1126, 15340, 15895, 17023, 20896, 30279) },
435+ { AOM_CDF7(655, 4854, 5249, 5913, 22099, 27138) },
436+ { AOM_CDF7(1299, 6458, 8885, 9290, 14851, 25497) },
437+ { AOM_CDF7(311, 5295, 5552, 6885, 16107, 22672) },
438+ { AOM_CDF7(883, 8059, 8270, 11258, 17289, 21549) },
439+ { AOM_CDF7(741, 7580, 9318, 10345, 16688, 29046) },
440+ { AOM_CDF7(110, 7406, 7915, 9195, 16041, 23329) },
441+ { AOM_CDF7(363, 7974, 9357, 10673, 15629, 24474) },
442+ { AOM_CDF7(153, 7647, 8112, 9936, 15307, 19996) },
443+ { AOM_CDF7(3511, 6332, 11165, 15335, 19323, 23594) },
444+ }, {
445+ { AOM_CDF7(4681, 9362, 14043, 18725, 23406, 28087) },
446+ { AOM_CDF7(4681, 9362, 14043, 18725, 23406, 28087) },
447+ { AOM_CDF7(4681, 9362, 14043, 18725, 23406, 28087) },
448+ { AOM_CDF7(4681, 9362, 14043, 18725, 23406, 28087) },
449+ { AOM_CDF7(4681, 9362, 14043, 18725, 23406, 28087) },
450+ { AOM_CDF7(4681, 9362, 14043, 18725, 23406, 28087) },
451+ { AOM_CDF7(4681, 9362, 14043, 18725, 23406, 28087) },
452+ { AOM_CDF7(4681, 9362, 14043, 18725, 23406, 28087) },
453+ { AOM_CDF7(4681, 9362, 14043, 18725, 23406, 28087) },
454+ { AOM_CDF7(4681, 9362, 14043, 18725, 23406, 28087) },
455+ { AOM_CDF7(4681, 9362, 14043, 18725, 23406, 28087) },
456+ { AOM_CDF7(4681, 9362, 14043, 18725, 23406, 28087) },
457+ { AOM_CDF7(4681, 9362, 14043, 18725, 23406, 28087) },
458+ }, {
459+ { AOM_CDF7(4681, 9362, 14043, 18725, 23406, 28087) },
460+ { AOM_CDF7(4681, 9362, 14043, 18725, 23406, 28087) },
461+ { AOM_CDF7(4681, 9362, 14043, 18725, 23406, 28087) },
462+ { AOM_CDF7(4681, 9362, 14043, 18725, 23406, 28087) },
463+ { AOM_CDF7(4681, 9362, 14043, 18725, 23406, 28087) },
464+ { AOM_CDF7(4681, 9362, 14043, 18725, 23406, 28087) },
465+ { AOM_CDF7(4681, 9362, 14043, 18725, 23406, 28087) },
466+ { AOM_CDF7(4681, 9362, 14043, 18725, 23406, 28087) },
467+ { AOM_CDF7(4681, 9362, 14043, 18725, 23406, 28087) },
468+ { AOM_CDF7(4681, 9362, 14043, 18725, 23406, 28087) },
469+ { AOM_CDF7(4681, 9362, 14043, 18725, 23406, 28087) },
470+ { AOM_CDF7(4681, 9362, 14043, 18725, 23406, 28087) },
471+ { AOM_CDF7(4681, 9362, 14043, 18725, 23406, 28087) },
472+ },
473+ }, {
474+ {
475+ { AOM_CDF5(6554, 13107, 19661, 26214) },
476+ { AOM_CDF5(6554, 13107, 19661, 26214) },
477+ { AOM_CDF5(6554, 13107, 19661, 26214) },
478+ { AOM_CDF5(6554, 13107, 19661, 26214) },
479+ { AOM_CDF5(6554, 13107, 19661, 26214) },
480+ { AOM_CDF5(6554, 13107, 19661, 26214) },
481+ { AOM_CDF5(6554, 13107, 19661, 26214) },
482+ { AOM_CDF5(6554, 13107, 19661, 26214) },
483+ { AOM_CDF5(6554, 13107, 19661, 26214) },
484+ { AOM_CDF5(6554, 13107, 19661, 26214) },
485+ { AOM_CDF5(6554, 13107, 19661, 26214) },
486+ { AOM_CDF5(6554, 13107, 19661, 26214) },
487+ { AOM_CDF5(6554, 13107, 19661, 26214) },
488+ }, {
489+ { AOM_CDF5(6554, 13107, 19661, 26214) },
490+ { AOM_CDF5(6554, 13107, 19661, 26214) },
491+ { AOM_CDF5(6554, 13107, 19661, 26214) },
492+ { AOM_CDF5(6554, 13107, 19661, 26214) },
493+ { AOM_CDF5(6554, 13107, 19661, 26214) },
494+ { AOM_CDF5(6554, 13107, 19661, 26214) },
495+ { AOM_CDF5(6554, 13107, 19661, 26214) },
496+ { AOM_CDF5(6554, 13107, 19661, 26214) },
497+ { AOM_CDF5(6554, 13107, 19661, 26214) },
498+ { AOM_CDF5(6554, 13107, 19661, 26214) },
499+ { AOM_CDF5(6554, 13107, 19661, 26214) },
500+ { AOM_CDF5(6554, 13107, 19661, 26214) },
501+ { AOM_CDF5(6554, 13107, 19661, 26214) },
502+ }, {
503+ { AOM_CDF5(1127, 12814, 22772, 27483) },
504+ { AOM_CDF5(145, 6761, 11980, 26667) },
505+ { AOM_CDF5(362, 5887, 11678, 16725) },
506+ { AOM_CDF5(385, 15213, 18587, 30693) },
507+ { AOM_CDF5(25, 2914, 23134, 27903) },
508+ { AOM_CDF5(60, 4470, 11749, 23991) },
509+ { AOM_CDF5(37, 3332, 14511, 21448) },
510+ { AOM_CDF5(157, 6320, 13036, 17439) },
511+ { AOM_CDF5(119, 6719, 12906, 29396) },
512+ { AOM_CDF5(47, 5537, 12576, 21499) },
513+ { AOM_CDF5(269, 6076, 11258, 23115) },
514+ { AOM_CDF5(83, 5615, 12001, 17228) },
515+ { AOM_CDF5(1968, 5556, 12023, 18547) },
516+ }, {
517+ { AOM_CDF5(6554, 13107, 19661, 26214) },
518+ { AOM_CDF5(6554, 13107, 19661, 26214) },
519+ { AOM_CDF5(6554, 13107, 19661, 26214) },
520+ { AOM_CDF5(6554, 13107, 19661, 26214) },
521+ { AOM_CDF5(6554, 13107, 19661, 26214) },
522+ { AOM_CDF5(6554, 13107, 19661, 26214) },
523+ { AOM_CDF5(6554, 13107, 19661, 26214) },
524+ { AOM_CDF5(6554, 13107, 19661, 26214) },
525+ { AOM_CDF5(6554, 13107, 19661, 26214) },
526+ { AOM_CDF5(6554, 13107, 19661, 26214) },
527+ { AOM_CDF5(6554, 13107, 19661, 26214) },
528+ { AOM_CDF5(6554, 13107, 19661, 26214) },
529+ { AOM_CDF5(6554, 13107, 19661, 26214) },
530+ },
531+ },
532+ }, .skip = {
533+ { AOM_CDF2(31671) },
534+ { AOM_CDF2(16515) },
535+ { AOM_CDF2(4576) }
536+ }, .skip_mode = {
537+ { AOM_CDF2(32621) },
538+ { AOM_CDF2(20708) },
539+ { AOM_CDF2(8127) }
540+ }, .partition = {
541+ {
542+ // 128x128 -> 64x64
543+ { AOM_CDF8(27899, 28219, 28529, 32484, 32539, 32619, 32639) },
544+ { AOM_CDF8(6607, 6990, 8268, 32060, 32219, 32338, 32371) },
545+ { AOM_CDF8(5429, 6676, 7122, 32027, 32227, 32531, 32582) },
546+ { AOM_CDF8(711, 966, 1172, 32448, 32538, 32617, 32664) },
547+ }, {
548+ // 64x64 -> 32x32
549+ { AOM_CDF10(20137, 21547, 23078, 29566, 29837, 30261, 30524, 30892,
550+ 31724) },
551+ { AOM_CDF10(6732, 7490, 9497, 27944, 28250, 28515, 28969, 29630,
552+ 30104) },
553+ { AOM_CDF10(5945, 7663, 8348, 28683, 29117, 29749, 30064, 30298,
554+ 32238) },
555+ { AOM_CDF10(870, 1212, 1487, 31198, 31394, 31574, 31743, 31881,
556+ 32332) },
557+ }, {
558+ // 32x32 -> 16x16
559+ { AOM_CDF10(18462, 20920, 23124, 27647, 28227, 29049, 29519, 30178,
560+ 31544) },
561+ { AOM_CDF10(7689, 9060, 12056, 24992, 25660, 26182, 26951, 28041,
562+ 29052) },
563+ { AOM_CDF10(6015, 9009, 10062, 24544, 25409, 26545, 27071, 27526,
564+ 32047) },
565+ { AOM_CDF10(1394, 2208, 2796, 28614, 29061, 29466, 29840, 30185,
566+ 31899) },
567+ }, {
568+ // 16x16 -> 8x8
569+ { AOM_CDF10(15597, 20929, 24571, 26706, 27664, 28821, 29601, 30571,
570+ 31902) },
571+ { AOM_CDF10(7925, 11043, 16785, 22470, 23971, 25043, 26651, 28701,
572+ 29834) },
573+ { AOM_CDF10(5414, 13269, 15111, 20488, 22360, 24500, 25537, 26336,
574+ 32117) },
575+ { AOM_CDF10(2662, 6362, 8614, 20860, 23053, 24778, 26436, 27829,
576+ 31171) },
577+ }, {
578+ // 8x8 -> 4x4 only supports the four legacy partition types
579+ { AOM_CDF4(19132, 25510, 30392) },
580+ { AOM_CDF4(13928, 19855, 28540) },
581+ { AOM_CDF4(12522, 23679, 28629) },
582+ { AOM_CDF4(9896, 18783, 25853) },
583+ }
584+ }, .seg_pred = {
585+ { AOM_CDF2(128 * 128) },
586+ { AOM_CDF2(128 * 128) },
587+ { AOM_CDF2(128 * 128) }
588+ }, .seg_id = {
589+ { AOM_CDF8(5622, 7893, 16093, 18233, 27809, 28373, 32533), },
590+ { AOM_CDF8(14274, 18230, 22557, 24935, 29980, 30851, 32344), },
591+ { AOM_CDF8(27527, 28487, 28723, 28890, 32397, 32647, 32679), },
592+ }, .cfl_sign = {
593+ AOM_CDF8(1418, 2123, 13340, 18405, 26972, 28343, 32294)
594+ }, .cfl_alpha = {
595+ { AOM_CDF16(7637, 20719, 31401, 32481, 32657, 32688, 32692, 32696,
596+ 32700, 32704, 32708, 32712, 32716, 32720, 32724) },
597+ { AOM_CDF16(14365, 23603, 28135, 31168, 32167, 32395, 32487, 32573,
598+ 32620, 32647, 32668, 32672, 32676, 32680, 32684) },
599+ { AOM_CDF16(11532, 22380, 28445, 31360, 32349, 32523, 32584, 32649,
600+ 32673, 32677, 32681, 32685, 32689, 32693, 32697) },
601+ { AOM_CDF16(26990, 31402, 32282, 32571, 32692, 32696, 32700, 32704,
602+ 32708, 32712, 32716, 32720, 32724, 32728, 32732) },
603+ { AOM_CDF16(17248, 26058, 28904, 30608, 31305, 31877, 32126, 32321,
604+ 32394, 32464, 32516, 32560, 32576, 32593, 32622) },
605+ { AOM_CDF16(14738, 21678, 25779, 27901, 29024, 30302, 30980, 31843,
606+ 32144, 32413, 32520, 32594, 32622, 32656, 32660) }
607+ }, .restore_wiener = {
608+ AOM_CDF2(11570)
609+ }, .restore_sgrproj = {
610+ AOM_CDF2(16855)
611+ }, .restore_switchable = {
612+ AOM_CDF3(9413, 22581)
613+ }, .delta_q = {
614+ AOM_CDF4(28160, 32120, 32677)
615+ }, .delta_lf = {
616+ { AOM_CDF4(28160, 32120, 32677) },
617+ { AOM_CDF4(28160, 32120, 32677) },
618+ { AOM_CDF4(28160, 32120, 32677) },
619+ { AOM_CDF4(28160, 32120, 32677) },
620+ { AOM_CDF4(28160, 32120, 32677) },
621+ }, .motion_mode = {
622+ [BS_8x8] = { AOM_CDF3(7651, 24760) },
623+ [BS_8x16] = { AOM_CDF3(4738, 24765) },
624+ [BS_8x32] = { AOM_CDF3(28799, 31390) },
625+ [BS_16x8] = { AOM_CDF3(5391, 25528) },
626+ [BS_16x16] = { AOM_CDF3(19419, 26810) },
627+ [BS_16x32] = { AOM_CDF3(5123, 23606) },
628+ [BS_16x64] = { AOM_CDF3(28973, 31594) },
629+ [BS_32x8] = { AOM_CDF3(26431, 30774) },
630+ [BS_32x16] = { AOM_CDF3(11606, 24308) },
631+ [BS_32x32] = { AOM_CDF3(26260, 29116) },
632+ [BS_32x64] = { AOM_CDF3(20360, 28062) },
633+ [BS_64x16] = { AOM_CDF3(29742, 31203) },
634+ [BS_64x32] = { AOM_CDF3(21679, 26830) },
635+ [BS_64x64] = { AOM_CDF3(29516, 30701) },
636+ [BS_64x128] = { AOM_CDF3(28898, 30397) },
637+ [BS_128x64] = { AOM_CDF3(30878, 31335) },
638+ [BS_128x128] = { AOM_CDF3(32507, 32558) },
639+ }, .obmc = {
640+ [BS_8x8] = { AOM_CDF2(10437) },
641+ [BS_8x16] = { AOM_CDF2(9371) },
642+ [BS_8x32] = { AOM_CDF2(23664) },
643+ [BS_16x8] = { AOM_CDF2(9301) },
644+ [BS_16x16] = { AOM_CDF2(17432) },
645+ [BS_16x32] = { AOM_CDF2(14423) },
646+ [BS_16x64] = { AOM_CDF2(24008) },
647+ [BS_32x8] = { AOM_CDF2(20901) },
648+ [BS_32x16] = { AOM_CDF2(15142) },
649+ [BS_32x32] = { AOM_CDF2(25817) },
650+ [BS_32x64] = { AOM_CDF2(22823) },
651+ [BS_64x16] = { AOM_CDF2(26879) },
652+ [BS_64x32] = { AOM_CDF2(22083) },
653+ [BS_64x64] = { AOM_CDF2(30128) },
654+ [BS_64x128] = { AOM_CDF2(31014) },
655+ [BS_128x64] = { AOM_CDF2(31560) },
656+ [BS_128x128] = { AOM_CDF2(32638) },
657+ }, .pal_y = {
658+ { { AOM_CDF2(31676) }, { AOM_CDF2(3419) }, { AOM_CDF2(1261) } },
659+ { { AOM_CDF2(31912) }, { AOM_CDF2(2859) }, { AOM_CDF2(980) } },
660+ { { AOM_CDF2(31823) }, { AOM_CDF2(3400) }, { AOM_CDF2(781) } },
661+ { { AOM_CDF2(32030) }, { AOM_CDF2(3561) }, { AOM_CDF2(904) } },
662+ { { AOM_CDF2(32309) }, { AOM_CDF2(7337) }, { AOM_CDF2(1462) } },
663+ { { AOM_CDF2(32265) }, { AOM_CDF2(4015) }, { AOM_CDF2(1521) } },
664+ { { AOM_CDF2(32450) }, { AOM_CDF2(7946) }, { AOM_CDF2(129) } },
665+ }, .pal_sz = {
666+ {
667+ { AOM_CDF7(7952, 13000, 18149, 21478, 25527, 29241) },
668+ { AOM_CDF7(7139, 11421, 16195, 19544, 23666, 28073) },
669+ { AOM_CDF7(7788, 12741, 17325, 20500, 24315, 28530) },
670+ { AOM_CDF7(8271, 14064, 18246, 21564, 25071, 28533) },
671+ { AOM_CDF7(12725, 19180, 21863, 24839, 27535, 30120) },
672+ { AOM_CDF7(9711, 14888, 16923, 21052, 25661, 27875) },
673+ { AOM_CDF7(14940, 20797, 21678, 24186, 27033, 28999) },
674+ }, {
675+ { AOM_CDF7(8713, 19979, 27128, 29609, 31331, 32272) },
676+ { AOM_CDF7(5839, 15573, 23581, 26947, 29848, 31700) },
677+ { AOM_CDF7(4426, 11260, 17999, 21483, 25863, 29430) },
678+ { AOM_CDF7(3228, 9464, 14993, 18089, 22523, 27420) },
679+ { AOM_CDF7(3768, 8886, 13091, 17852, 22495, 27207) },
680+ { AOM_CDF7(2464, 8451, 12861, 21632, 25525, 28555) },
681+ { AOM_CDF7(1269, 5435, 10433, 18963, 21700, 25865) },
682+ }
683+ }, .pal_uv = {
684+ { AOM_CDF2(32461) }, { AOM_CDF2(21488) },
685+ }, .color_map = {
686+ { /* y */
687+ {
688+ { AOM_CDF2(28710) },
689+ { AOM_CDF2(16384) },
690+ { AOM_CDF2(10553) },
691+ { AOM_CDF2(27036) },
692+ { AOM_CDF2(31603) },
693+ }, {
694+ { AOM_CDF3(27877, 30490) },
695+ { AOM_CDF3(11532, 25697) },
696+ { AOM_CDF3(6544, 30234) },
697+ { AOM_CDF3(23018, 28072) },
698+ { AOM_CDF3(31915, 32385) },
699+ }, {
700+ { AOM_CDF4(25572, 28046, 30045) },
701+ { AOM_CDF4(9478, 21590, 27256) },
702+ { AOM_CDF4(7248, 26837, 29824) },
703+ { AOM_CDF4(19167, 24486, 28349) },
704+ { AOM_CDF4(31400, 31825, 32250) },
705+ }, {
706+ { AOM_CDF5(24779, 26955, 28576, 30282) },
707+ { AOM_CDF5(8669, 20364, 24073, 28093) },
708+ { AOM_CDF5(4255, 27565, 29377, 31067) },
709+ { AOM_CDF5(19864, 23674, 26716, 29530) },
710+ { AOM_CDF5(31646, 31893, 32147, 32426) },
711+ }, {
712+ { AOM_CDF6(23132, 25407, 26970, 28435, 30073) },
713+ { AOM_CDF6(7443, 17242, 20717, 24762, 27982) },
714+ { AOM_CDF6(6300, 24862, 26944, 28784, 30671) },
715+ { AOM_CDF6(18916, 22895, 25267, 27435, 29652) },
716+ { AOM_CDF6(31270, 31550, 31808, 32059, 32353) },
717+ }, {
718+ { AOM_CDF7(23105, 25199, 26464, 27684, 28931, 30318) },
719+ { AOM_CDF7(6950, 15447, 18952, 22681, 25567, 28563) },
720+ { AOM_CDF7(7560, 23474, 25490, 27203, 28921, 30708) },
721+ { AOM_CDF7(18544, 22373, 24457, 26195, 28119, 30045) },
722+ { AOM_CDF7(31198, 31451, 31670, 31882, 32123, 32391) },
723+ }, {
724+ { AOM_CDF8(21689, 23883, 25163, 26352, 27506, 28827, 30195) },
725+ { AOM_CDF8(6892, 15385, 17840, 21606, 24287, 26753, 29204) },
726+ { AOM_CDF8(5651, 23182, 25042, 26518, 27982, 29392, 30900) },
727+ { AOM_CDF8(19349, 22578, 24418, 25994, 27524, 29031, 30448) },
728+ { AOM_CDF8(31028, 31270, 31504, 31705, 31927, 32153, 32392) },
729+ },
730+ }, { /* uv */
731+ {
732+ { AOM_CDF2(29089) },
733+ { AOM_CDF2(16384) },
734+ { AOM_CDF2(8713) },
735+ { AOM_CDF2(29257) },
736+ { AOM_CDF2(31610) },
737+ }, {
738+ { AOM_CDF3(25257, 29145) },
739+ { AOM_CDF3(12287, 27293) },
740+ { AOM_CDF3(7033, 27960) },
741+ { AOM_CDF3(20145, 25405) },
742+ { AOM_CDF3(30608, 31639) },
743+ }, {
744+ { AOM_CDF4(24210, 27175, 29903) },
745+ { AOM_CDF4(9888, 22386, 27214) },
746+ { AOM_CDF4(5901, 26053, 29293) },
747+ { AOM_CDF4(18318, 22152, 28333) },
748+ { AOM_CDF4(30459, 31136, 31926) },
749+ }, {
750+ { AOM_CDF5(22980, 25479, 27781, 29986) },
751+ { AOM_CDF5(8413, 21408, 24859, 28874) },
752+ { AOM_CDF5(2257, 29449, 30594, 31598) },
753+ { AOM_CDF5(19189, 21202, 25915, 28620) },
754+ { AOM_CDF5(31844, 32044, 32281, 32518) },
755+ }, {
756+ { AOM_CDF6(22217, 24567, 26637, 28683, 30548) },
757+ { AOM_CDF6(7307, 16406, 19636, 24632, 28424) },
758+ { AOM_CDF6(4441, 25064, 26879, 28942, 30919) },
759+ { AOM_CDF6(17210, 20528, 23319, 26750, 29582) },
760+ { AOM_CDF6(30674, 30953, 31396, 31735, 32207) },
761+ }, {
762+ { AOM_CDF7(21239, 23168, 25044, 26962, 28705, 30506) },
763+ { AOM_CDF7(6545, 15012, 18004, 21817, 25503, 28701) },
764+ { AOM_CDF7(3448, 26295, 27437, 28704, 30126, 31442) },
765+ { AOM_CDF7(15889, 18323, 21704, 24698, 26976, 29690) },
766+ { AOM_CDF7(30988, 31204, 31479, 31734, 31983, 32325) },
767+ }, {
768+ { AOM_CDF8(21442, 23288, 24758, 26246, 27649, 28980, 30563) },
769+ { AOM_CDF8(5863, 14933, 17552, 20668, 23683, 26411, 29273) },
770+ { AOM_CDF8(3415, 25810, 26877, 27990, 29223, 30394, 31618) },
771+ { AOM_CDF8(17965, 20084, 22232, 23974, 26274, 28402, 30390) },
772+ { AOM_CDF8(31190, 31329, 31516, 31679, 31825, 32026, 32322) },
773+ },
774+ },
775+ }, .intrabc = {
776+ AOM_CDF2(30531)
777+ },
778+};
779+
780+static const CdfMvContext default_mv_cdf = {
781+ .comp = {
782+ { /* mv vertical component */
783+ .classes = {
784+ AOM_CDF11(28672, 30976, 31858, 32320, 32551, 32656, 32740,
785+ 32757, 32762, 32767)
786+ }, .class0 = {
787+ AOM_CDF2(216 * 128)
788+ }, .classN = {
789+ { AOM_CDF2(128 * 136) },
790+ { AOM_CDF2(128 * 140) },
791+ { AOM_CDF2(128 * 148) },
792+ { AOM_CDF2(128 * 160) },
793+ { AOM_CDF2(128 * 176) },
794+ { AOM_CDF2(128 * 192) },
795+ { AOM_CDF2(128 * 224) },
796+ { AOM_CDF2(128 * 234) },
797+ { AOM_CDF2(128 * 234) },
798+ { AOM_CDF2(128 * 240) }
799+ }, .class0_fp = {
800+ { AOM_CDF4(16384, 24576, 26624) },
801+ { AOM_CDF4(12288, 21248, 24128) }
802+ }, .classN_fp = {
803+ AOM_CDF4(8192, 17408, 21248)
804+ }, .class0_hp = {
805+ AOM_CDF2(160 * 128)
806+ }, .classN_hp = {
807+ AOM_CDF2(128 * 128)
808+ }, .sign = {
809+ AOM_CDF2(128 * 128)
810+ }
811+ }, { /* mv horizontal component */
812+ .classes = {
813+ AOM_CDF11(28672, 30976, 31858, 32320, 32551, 32656, 32740,
814+ 32757, 32762, 32767)
815+ }, .class0 = {
816+ AOM_CDF2(216 * 128)
817+ }, .classN = {
818+ { AOM_CDF2(128 * 136) },
819+ { AOM_CDF2(128 * 140) },
820+ { AOM_CDF2(128 * 148) },
821+ { AOM_CDF2(128 * 160) },
822+ { AOM_CDF2(128 * 176) },
823+ { AOM_CDF2(128 * 192) },
824+ { AOM_CDF2(128 * 224) },
825+ { AOM_CDF2(128 * 234) },
826+ { AOM_CDF2(128 * 234) },
827+ { AOM_CDF2(128 * 240) }
828+ }, .class0_fp = {
829+ { AOM_CDF4(16384, 24576, 26624) },
830+ { AOM_CDF4(12288, 21248, 24128) }
831+ }, .classN_fp = {
832+ AOM_CDF4(8192, 17408, 21248)
833+ }, .class0_hp = {
834+ AOM_CDF2(160 * 128)
835+ }, .classN_hp = {
836+ AOM_CDF2(128 * 128)
837+ }, .sign = {
838+ AOM_CDF2(128 * 128)
839+ },
840+ }
841+ }, .joint = {
842+ AOM_CDF4(4096, 11264, 19328)
843+ }
844+};
845+
846+static const uint16_t default_kf_y_mode_cdf[5][5][N_INTRA_PRED_MODES + 1] = {
847+ {
848+ { AOM_CDF13(15588, 17027, 19338, 20218, 20682, 21110, 21825, 23244,
849+ 24189, 28165, 29093, 30466) },
850+ { AOM_CDF13(12016, 18066, 19516, 20303, 20719, 21444, 21888, 23032,
851+ 24434, 28658, 30172, 31409) },
852+ { AOM_CDF13(10052, 10771, 22296, 22788, 23055, 23239, 24133, 25620,
853+ 26160, 29336, 29929, 31567) },
854+ { AOM_CDF13(14091, 15406, 16442, 18808, 19136, 19546, 19998, 22096,
855+ 24746, 29585, 30958, 32462) },
856+ { AOM_CDF13(12122, 13265, 15603, 16501, 18609, 20033, 22391, 25583,
857+ 26437, 30261, 31073, 32475) }
858+ }, {
859+ { AOM_CDF13(10023, 19585, 20848, 21440, 21832, 22760, 23089, 24023,
860+ 25381, 29014, 30482, 31436) },
861+ { AOM_CDF13(5983, 24099, 24560, 24886, 25066, 25795, 25913, 26423,
862+ 27610, 29905, 31276, 31794) },
863+ { AOM_CDF13(7444, 12781, 20177, 20728, 21077, 21607, 22170, 23405,
864+ 24469, 27915, 29090, 30492) },
865+ { AOM_CDF13(8537, 14689, 15432, 17087, 17408, 18172, 18408, 19825,
866+ 24649, 29153, 31096, 32210) },
867+ { AOM_CDF13(7543, 14231, 15496, 16195, 17905, 20717, 21984, 24516,
868+ 26001, 29675, 30981, 31994) }
869+ }, {
870+ { AOM_CDF13(12613, 13591, 21383, 22004, 22312, 22577, 23401, 25055,
871+ 25729, 29538, 30305, 32077) },
872+ { AOM_CDF13(9687, 13470, 18506, 19230, 19604, 20147, 20695, 22062,
873+ 23219, 27743, 29211, 30907) },
874+ { AOM_CDF13(6183, 6505, 26024, 26252, 26366, 26434, 27082, 28354,
875+ 28555, 30467, 30794, 32086) },
876+ { AOM_CDF13(10718, 11734, 14954, 17224, 17565, 17924, 18561, 21523,
877+ 23878, 28975, 30287, 32252) },
878+ { AOM_CDF13(9194, 9858, 16501, 17263, 18424, 19171, 21563, 25961,
879+ 26561, 30072, 30737, 32463) }
880+ }, {
881+ { AOM_CDF13(12602, 14399, 15488, 18381, 18778, 19315, 19724, 21419,
882+ 25060, 29696, 30917, 32409) },
883+ { AOM_CDF13(8203, 13821, 14524, 17105, 17439, 18131, 18404, 19468,
884+ 25225, 29485, 31158, 32342) },
885+ { AOM_CDF13(8451, 9731, 15004, 17643, 18012, 18425, 19070, 21538,
886+ 24605, 29118, 30078, 32018) },
887+ { AOM_CDF13(7714, 9048, 9516, 16667, 16817, 16994, 17153, 18767,
888+ 26743, 30389, 31536, 32528) },
889+ { AOM_CDF13(8843, 10280, 11496, 15317, 16652, 17943, 19108, 22718,
890+ 25769, 29953, 30983, 32485) }
891+ }, {
892+ { AOM_CDF13(12578, 13671, 15979, 16834, 19075, 20913, 22989, 25449,
893+ 26219, 30214, 31150, 32477) },
894+ { AOM_CDF13(9563, 13626, 15080, 15892, 17756, 20863, 22207, 24236,
895+ 25380, 29653, 31143, 32277) },
896+ { AOM_CDF13(8356, 8901, 17616, 18256, 19350, 20106, 22598, 25947,
897+ 26466, 29900, 30523, 32261) },
898+ { AOM_CDF13(10835, 11815, 13124, 16042, 17018, 18039, 18947, 22753,
899+ 24615, 29489, 30883, 32482) },
900+ { AOM_CDF13(7618, 8288, 9859, 10509, 15386, 18657, 22903, 28776,
901+ 29180, 31355, 31802, 32593) }
902+ }
903+};
904+
905+static const CdfCoefContext av1_default_coef_cdf[4] = {
906+ [0] = {
907+ .skip = {
908+ { { AOM_CDF2(31849) },
909+ { AOM_CDF2(5892) },
910+ { AOM_CDF2(12112) },
911+ { AOM_CDF2(21935) },
912+ { AOM_CDF2(20289) },
913+ { AOM_CDF2(27473) },
914+ { AOM_CDF2(32487) },
915+ { AOM_CDF2(7654) },
916+ { AOM_CDF2(19473) },
917+ { AOM_CDF2(29984) },
918+ { AOM_CDF2(9961) },
919+ { AOM_CDF2(30242) },
920+ { AOM_CDF2(32117) } },
921+ { { AOM_CDF2(31548) },
922+ { AOM_CDF2(1549) },
923+ { AOM_CDF2(10130) },
924+ { AOM_CDF2(16656) },
925+ { AOM_CDF2(18591) },
926+ { AOM_CDF2(26308) },
927+ { AOM_CDF2(32537) },
928+ { AOM_CDF2(5403) },
929+ { AOM_CDF2(18096) },
930+ { AOM_CDF2(30003) },
931+ { AOM_CDF2(16384) },
932+ { AOM_CDF2(16384) },
933+ { AOM_CDF2(16384) } },
934+ { { AOM_CDF2(29957) },
935+ { AOM_CDF2(5391) },
936+ { AOM_CDF2(18039) },
937+ { AOM_CDF2(23566) },
938+ { AOM_CDF2(22431) },
939+ { AOM_CDF2(25822) },
940+ { AOM_CDF2(32197) },
941+ { AOM_CDF2(3778) },
942+ { AOM_CDF2(15336) },
943+ { AOM_CDF2(28981) },
944+ { AOM_CDF2(16384) },
945+ { AOM_CDF2(16384) },
946+ { AOM_CDF2(16384) } },
947+ { { AOM_CDF2(17920) },
948+ { AOM_CDF2(1818) },
949+ { AOM_CDF2(7282) },
950+ { AOM_CDF2(25273) },
951+ { AOM_CDF2(10923) },
952+ { AOM_CDF2(31554) },
953+ { AOM_CDF2(32624) },
954+ { AOM_CDF2(1366) },
955+ { AOM_CDF2(15628) },
956+ { AOM_CDF2(30462) },
957+ { AOM_CDF2(146) },
958+ { AOM_CDF2(5132) },
959+ { AOM_CDF2(31657) } },
960+ { { AOM_CDF2(6308) },
961+ { AOM_CDF2(117) },
962+ { AOM_CDF2(1638) },
963+ { AOM_CDF2(2161) },
964+ { AOM_CDF2(16384) },
965+ { AOM_CDF2(10923) },
966+ { AOM_CDF2(30247) },
967+ { AOM_CDF2(16384) },
968+ { AOM_CDF2(16384) },
969+ { AOM_CDF2(16384) },
970+ { AOM_CDF2(16384) },
971+ { AOM_CDF2(16384) },
972+ { AOM_CDF2(16384) } }
973+ }, .eob_bin_16 = {
974+ { { AOM_CDF5(840, 1039, 1980, 4895) },
975+ { AOM_CDF5(370, 671, 1883, 4471) } },
976+ { { AOM_CDF5(3247, 4950, 9688, 14563) },
977+ { AOM_CDF5(1904, 3354, 7763, 14647) } }
978+ }, .eob_bin_32 = {
979+ { { AOM_CDF6(400, 520, 977, 2102, 6542) },
980+ { AOM_CDF6(210, 405, 1315, 3326, 7537) } },
981+ { { AOM_CDF6(2636, 4273, 7588, 11794, 20401) },
982+ { AOM_CDF6(1786, 3179, 6902, 11357, 19054) } }
983+ }, .eob_bin_64 = {
984+ { { AOM_CDF7(329, 498, 1101, 1784, 3265, 7758) },
985+ { AOM_CDF7(335, 730, 1459, 5494, 8755, 12997) } },
986+ { { AOM_CDF7(3505, 5304, 10086, 13814, 17684, 23370) },
987+ { AOM_CDF7(1563, 2700, 4876, 10911, 14706, 22480) } }
988+ }, .eob_bin_128 = {
989+ { { AOM_CDF8(219, 482, 1140, 2091, 3680, 6028, 12586) },
990+ { AOM_CDF8(371, 699, 1254, 4830, 9479, 12562, 17497) } },
991+ { { AOM_CDF8(5245, 7456, 12880, 15852, 20033, 23932, 27608) },
992+ { AOM_CDF8(2054, 3472, 5869, 14232, 18242, 20590, 26752) } }
993+ }, .eob_bin_256 = {
994+ { { AOM_CDF9(310, 584, 1887, 3589, 6168, 8611, 11352, 15652) },
995+ { AOM_CDF9(998, 1850, 2998, 5604, 17341, 19888, 22899, 25583) } },
996+ { { AOM_CDF9(2520, 3240, 5952, 8870, 12577, 17558, 19954, 24168) },
997+ { AOM_CDF9(2203, 4130, 7435, 10739, 20652, 23681, 25609, 27261) } }
998+ }, .eob_bin_512 = {
999+ { { AOM_CDF10(641, 983, 3707, 5430, 10234, 14958, 18788,
1000+ 23412, 26061) },
1001+ { AOM_CDF10(3277, 6554, 9830, 13107, 16384, 19661, 22938,
1002+ 26214, 29491) } },
1003+ { { AOM_CDF10(5095, 6446, 9996, 13354, 16017, 17986, 20919,
1004+ 26129, 29140) },
1005+ { AOM_CDF10(3277, 6554, 9830, 13107, 16384, 19661, 22938,
1006+ 26214, 29491) } }
1007+ }, .eob_bin_1024 = {
1008+ { { AOM_CDF11(393, 421, 751, 1623, 3160, 6352, 13345, 18047,
1009+ 22571, 25830) },
1010+ { AOM_CDF11(2979, 5958, 8937, 11916, 14895, 17873, 20852,
1011+ 23831, 26810, 29789) } },
1012+ { { AOM_CDF11(1865, 1988, 2930, 4242, 10533, 16538, 21354,
1013+ 27255, 28546, 31784) },
1014+ { AOM_CDF11(2979, 5958, 8937, 11916, 14895, 17873, 20852,
1015+ 23831, 26810, 29789) } }
1016+ }, .eob_hi_bit = {
1017+ { { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
1018+ { AOM_CDF2(16961) }, { AOM_CDF2(17223) }, { AOM_CDF2(7621) },
1019+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
1020+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) } },
1021+ { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
1022+ { AOM_CDF2(19069) }, { AOM_CDF2(22525) }, { AOM_CDF2(13377) },
1023+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
1024+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) } } },
1025+ { { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
1026+ { AOM_CDF2(20401) }, { AOM_CDF2(17025) }, { AOM_CDF2(12845) },
1027+ { AOM_CDF2(12873) }, { AOM_CDF2(14094) }, { AOM_CDF2(16384) },
1028+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) } },
1029+ { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
1030+ { AOM_CDF2(20681) }, { AOM_CDF2(20701) }, { AOM_CDF2(15250) },
1031+ { AOM_CDF2(15017) }, { AOM_CDF2(14928) }, { AOM_CDF2(16384) },
1032+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) } } },
1033+ { { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
1034+ { AOM_CDF2(23905) }, { AOM_CDF2(17194) }, { AOM_CDF2(16170) },
1035+ { AOM_CDF2(17695) }, { AOM_CDF2(13826) }, { AOM_CDF2(15810) },
1036+ { AOM_CDF2(12036) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) } },
1037+ { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
1038+ { AOM_CDF2(23959) }, { AOM_CDF2(20799) }, { AOM_CDF2(19021) },
1039+ { AOM_CDF2(16203) }, { AOM_CDF2(17886) }, { AOM_CDF2(14144) },
1040+ { AOM_CDF2(12010) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) } } },
1041+ { { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
1042+ { AOM_CDF2(27399) }, { AOM_CDF2(16327) }, { AOM_CDF2(18071) },
1043+ { AOM_CDF2(19584) }, { AOM_CDF2(20721) }, { AOM_CDF2(18432) },
1044+ { AOM_CDF2(19560) }, { AOM_CDF2(10150) }, { AOM_CDF2(8805) } },
1045+ { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
1046+ { AOM_CDF2(24932) }, { AOM_CDF2(20833) }, { AOM_CDF2(12027) },
1047+ { AOM_CDF2(16670) }, { AOM_CDF2(19914) }, { AOM_CDF2(15106) },
1048+ { AOM_CDF2(17662) }, { AOM_CDF2(13783) }, { AOM_CDF2(28756) } } },
1049+ { { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
1050+ { AOM_CDF2(23406) }, { AOM_CDF2(21845) }, { AOM_CDF2(18432) },
1051+ { AOM_CDF2(16384) }, { AOM_CDF2(17096) }, { AOM_CDF2(12561) },
1052+ { AOM_CDF2(17320) }, { AOM_CDF2(22395) }, { AOM_CDF2(21370) } },
1053+ { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
1054+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
1055+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
1056+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) } } }
1057+ }, .eob_base_tok = {
1058+ { { { AOM_CDF3(17837, 29055) },
1059+ { AOM_CDF3(29600, 31446) },
1060+ { AOM_CDF3(30844, 31878) },
1061+ { AOM_CDF3(24926, 28948) } },
1062+ { { AOM_CDF3(21365, 30026) },
1063+ { AOM_CDF3(30512, 32423) },
1064+ { AOM_CDF3(31658, 32621) },
1065+ { AOM_CDF3(29630, 31881) } } },
1066+ { { { AOM_CDF3(5717, 26477) },
1067+ { AOM_CDF3(30491, 31703) },
1068+ { AOM_CDF3(31550, 32158) },
1069+ { AOM_CDF3(29648, 31491) } },
1070+ { { AOM_CDF3(12608, 27820) },
1071+ { AOM_CDF3(30680, 32225) },
1072+ { AOM_CDF3(30809, 32335) },
1073+ { AOM_CDF3(31299, 32423) } } },
1074+ { { { AOM_CDF3(1786, 12612) },
1075+ { AOM_CDF3(30663, 31625) },
1076+ { AOM_CDF3(32339, 32468) },
1077+ { AOM_CDF3(31148, 31833) } },
1078+ { { AOM_CDF3(18857, 23865) },
1079+ { AOM_CDF3(31428, 32428) },
1080+ { AOM_CDF3(31744, 32373) },
1081+ { AOM_CDF3(31775, 32526) } } },
1082+ { { { AOM_CDF3(1787, 2532) },
1083+ { AOM_CDF3(30832, 31662) },
1084+ { AOM_CDF3(31824, 32682) },
1085+ { AOM_CDF3(32133, 32569) } },
1086+ { { AOM_CDF3(13751, 22235) },
1087+ { AOM_CDF3(32089, 32409) },
1088+ { AOM_CDF3(27084, 27920) },
1089+ { AOM_CDF3(29291, 32594) } } },
1090+ { { { AOM_CDF3(1725, 3449) },
1091+ { AOM_CDF3(31102, 31935) },
1092+ { AOM_CDF3(32457, 32613) },
1093+ { AOM_CDF3(32412, 32649) } },
1094+ { { AOM_CDF3(10923, 21845) },
1095+ { AOM_CDF3(10923, 21845) },
1096+ { AOM_CDF3(10923, 21845) },
1097+ { AOM_CDF3(10923, 21845) } } }
1098+ }, .base_tok = {
1099+ { { { AOM_CDF4(4034, 8930, 12727) },
1100+ { AOM_CDF4(18082, 29741, 31877) },
1101+ { AOM_CDF4(12596, 26124, 30493) },
1102+ { AOM_CDF4(9446, 21118, 27005) },
1103+ { AOM_CDF4(6308, 15141, 21279) },
1104+ { AOM_CDF4(2463, 6357, 9783) },
1105+ { AOM_CDF4(20667, 30546, 31929) },
1106+ { AOM_CDF4(13043, 26123, 30134) },
1107+ { AOM_CDF4(8151, 18757, 24778) },
1108+ { AOM_CDF4(5255, 12839, 18632) },
1109+ { AOM_CDF4(2820, 7206, 11161) },
1110+ { AOM_CDF4(8192, 16384, 24576) },
1111+ { AOM_CDF4(8192, 16384, 24576) },
1112+ { AOM_CDF4(8192, 16384, 24576) },
1113+ { AOM_CDF4(8192, 16384, 24576) },
1114+ { AOM_CDF4(8192, 16384, 24576) },
1115+ { AOM_CDF4(8192, 16384, 24576) },
1116+ { AOM_CDF4(8192, 16384, 24576) },
1117+ { AOM_CDF4(8192, 16384, 24576) },
1118+ { AOM_CDF4(8192, 16384, 24576) },
1119+ { AOM_CDF4(8192, 16384, 24576) },
1120+ { AOM_CDF4(15736, 27553, 30604) },
1121+ { AOM_CDF4(11210, 23794, 28787) },
1122+ { AOM_CDF4(5947, 13874, 19701) },
1123+ { AOM_CDF4(4215, 9323, 13891) },
1124+ { AOM_CDF4(2833, 6462, 10059) },
1125+ { AOM_CDF4(19605, 30393, 31582) },
1126+ { AOM_CDF4(13523, 26252, 30248) },
1127+ { AOM_CDF4(8446, 18622, 24512) },
1128+ { AOM_CDF4(3818, 10343, 15974) },
1129+ { AOM_CDF4(1481, 4117, 6796) },
1130+ { AOM_CDF4(22649, 31302, 32190) },
1131+ { AOM_CDF4(14829, 27127, 30449) },
1132+ { AOM_CDF4(8313, 17702, 23304) },
1133+ { AOM_CDF4(3022, 8301, 12786) },
1134+ { AOM_CDF4(1536, 4412, 7184) },
1135+ { AOM_CDF4(22354, 29774, 31372) },
1136+ { AOM_CDF4(14723, 25472, 29214) },
1137+ { AOM_CDF4(6673, 13745, 18662) },
1138+ { AOM_CDF4(2068, 5766, 9322) },
1139+ { AOM_CDF4(8192, 16384, 24576) } },
1140+ { { AOM_CDF4(6302, 16444, 21761) },
1141+ { AOM_CDF4(23040, 31538, 32475) },
1142+ { AOM_CDF4(15196, 28452, 31496) },
1143+ { AOM_CDF4(10020, 22946, 28514) },
1144+ { AOM_CDF4(6533, 16862, 23501) },
1145+ { AOM_CDF4(3538, 9816, 15076) },
1146+ { AOM_CDF4(24444, 31875, 32525) },
1147+ { AOM_CDF4(15881, 28924, 31635) },
1148+ { AOM_CDF4(9922, 22873, 28466) },
1149+ { AOM_CDF4(6527, 16966, 23691) },
1150+ { AOM_CDF4(4114, 11303, 17220) },
1151+ { AOM_CDF4(8192, 16384, 24576) },
1152+ { AOM_CDF4(8192, 16384, 24576) },
1153+ { AOM_CDF4(8192, 16384, 24576) },
1154+ { AOM_CDF4(8192, 16384, 24576) },
1155+ { AOM_CDF4(8192, 16384, 24576) },
1156+ { AOM_CDF4(8192, 16384, 24576) },
1157+ { AOM_CDF4(8192, 16384, 24576) },
1158+ { AOM_CDF4(8192, 16384, 24576) },
1159+ { AOM_CDF4(8192, 16384, 24576) },
1160+ { AOM_CDF4(8192, 16384, 24576) },
1161+ { AOM_CDF4(20201, 30770, 32209) },
1162+ { AOM_CDF4(14754, 28071, 31258) },
1163+ { AOM_CDF4(8378, 20186, 26517) },
1164+ { AOM_CDF4(5916, 15299, 21978) },
1165+ { AOM_CDF4(4268, 11583, 17901) },
1166+ { AOM_CDF4(24361, 32025, 32581) },
1167+ { AOM_CDF4(18673, 30105, 31943) },
1168+ { AOM_CDF4(10196, 22244, 27576) },
1169+ { AOM_CDF4(5495, 14349, 20417) },
1170+ { AOM_CDF4(2676, 7415, 11498) },
1171+ { AOM_CDF4(24678, 31958, 32585) },
1172+ { AOM_CDF4(18629, 29906, 31831) },
1173+ { AOM_CDF4(9364, 20724, 26315) },
1174+ { AOM_CDF4(4641, 12318, 18094) },
1175+ { AOM_CDF4(2758, 7387, 11579) },
1176+ { AOM_CDF4(25433, 31842, 32469) },
1177+ { AOM_CDF4(18795, 29289, 31411) },
1178+ { AOM_CDF4(7644, 17584, 23592) },
1179+ { AOM_CDF4(3408, 9014, 15047) },
1180+ { AOM_CDF4(8192, 16384, 24576) } } },
1181+ { { { AOM_CDF4(4536, 10072, 14001) },
1182+ { AOM_CDF4(25459, 31416, 32206) },
1183+ { AOM_CDF4(16605, 28048, 30818) },
1184+ { AOM_CDF4(11008, 22857, 27719) },
1185+ { AOM_CDF4(6915, 16268, 22315) },
1186+ { AOM_CDF4(2625, 6812, 10537) },
1187+ { AOM_CDF4(24257, 31788, 32499) },
1188+ { AOM_CDF4(16880, 29454, 31879) },
1189+ { AOM_CDF4(11958, 25054, 29778) },
1190+ { AOM_CDF4(7916, 18718, 25084) },
1191+ { AOM_CDF4(3383, 8777, 13446) },
1192+ { AOM_CDF4(22720, 31603, 32393) },
1193+ { AOM_CDF4(14960, 28125, 31335) },
1194+ { AOM_CDF4(9731, 22210, 27928) },
1195+ { AOM_CDF4(6304, 15832, 22277) },
1196+ { AOM_CDF4(2910, 7818, 12166) },
1197+ { AOM_CDF4(20375, 30627, 32131) },
1198+ { AOM_CDF4(13904, 27284, 30887) },
1199+ { AOM_CDF4(9368, 21558, 27144) },
1200+ { AOM_CDF4(5937, 14966, 21119) },
1201+ { AOM_CDF4(2667, 7225, 11319) },
1202+ { AOM_CDF4(23970, 31470, 32378) },
1203+ { AOM_CDF4(17173, 29734, 32018) },
1204+ { AOM_CDF4(12795, 25441, 29965) },
1205+ { AOM_CDF4(8981, 19680, 25893) },
1206+ { AOM_CDF4(4728, 11372, 16902) },
1207+ { AOM_CDF4(24287, 31797, 32439) },
1208+ { AOM_CDF4(16703, 29145, 31696) },
1209+ { AOM_CDF4(10833, 23554, 28725) },
1210+ { AOM_CDF4(6468, 16566, 23057) },
1211+ { AOM_CDF4(2415, 6562, 10278) },
1212+ { AOM_CDF4(26610, 32395, 32659) },
1213+ { AOM_CDF4(18590, 30498, 32117) },
1214+ { AOM_CDF4(12420, 25756, 29950) },
1215+ { AOM_CDF4(7639, 18746, 24710) },
1216+ { AOM_CDF4(3001, 8086, 12347) },
1217+ { AOM_CDF4(25076, 32064, 32580) },
1218+ { AOM_CDF4(17946, 30128, 32028) },
1219+ { AOM_CDF4(12024, 24985, 29378) },
1220+ { AOM_CDF4(7517, 18390, 24304) },
1221+ { AOM_CDF4(3243, 8781, 13331) } },
1222+ { { AOM_CDF4(6037, 16771, 21957) },
1223+ { AOM_CDF4(24774, 31704, 32426) },
1224+ { AOM_CDF4(16830, 28589, 31056) },
1225+ { AOM_CDF4(10602, 22828, 27760) },
1226+ { AOM_CDF4(6733, 16829, 23071) },
1227+ { AOM_CDF4(3250, 8914, 13556) },
1228+ { AOM_CDF4(25582, 32220, 32668) },
1229+ { AOM_CDF4(18659, 30342, 32223) },
1230+ { AOM_CDF4(12546, 26149, 30515) },
1231+ { AOM_CDF4(8420, 20451, 26801) },
1232+ { AOM_CDF4(4636, 12420, 18344) },
1233+ { AOM_CDF4(27581, 32362, 32639) },
1234+ { AOM_CDF4(18987, 30083, 31978) },
1235+ { AOM_CDF4(11327, 24248, 29084) },
1236+ { AOM_CDF4(7264, 17719, 24120) },
1237+ { AOM_CDF4(3995, 10768, 16169) },
1238+ { AOM_CDF4(25893, 31831, 32487) },
1239+ { AOM_CDF4(16577, 28587, 31379) },
1240+ { AOM_CDF4(10189, 22748, 28182) },
1241+ { AOM_CDF4(6832, 17094, 23556) },
1242+ { AOM_CDF4(3708, 10110, 15334) },
1243+ { AOM_CDF4(25904, 32282, 32656) },
1244+ { AOM_CDF4(19721, 30792, 32276) },
1245+ { AOM_CDF4(12819, 26243, 30411) },
1246+ { AOM_CDF4(8572, 20614, 26891) },
1247+ { AOM_CDF4(5364, 14059, 20467) },
1248+ { AOM_CDF4(26580, 32438, 32677) },
1249+ { AOM_CDF4(20852, 31225, 32340) },
1250+ { AOM_CDF4(12435, 25700, 29967) },
1251+ { AOM_CDF4(8691, 20825, 26976) },
1252+ { AOM_CDF4(4446, 12209, 17269) },
1253+ { AOM_CDF4(27350, 32429, 32696) },
1254+ { AOM_CDF4(21372, 30977, 32272) },
1255+ { AOM_CDF4(12673, 25270, 29853) },
1256+ { AOM_CDF4(9208, 20925, 26640) },
1257+ { AOM_CDF4(5018, 13351, 18732) },
1258+ { AOM_CDF4(27351, 32479, 32713) },
1259+ { AOM_CDF4(21398, 31209, 32387) },
1260+ { AOM_CDF4(12162, 25047, 29842) },
1261+ { AOM_CDF4(7896, 18691, 25319) },
1262+ { AOM_CDF4(4670, 12882, 18881) } } },
1263+ { { { AOM_CDF4(5487, 10460, 13708) },
1264+ { AOM_CDF4(21597, 28303, 30674) },
1265+ { AOM_CDF4(11037, 21953, 26476) },
1266+ { AOM_CDF4(8147, 17962, 22952) },
1267+ { AOM_CDF4(5242, 13061, 18532) },
1268+ { AOM_CDF4(1889, 5208, 8182) },
1269+ { AOM_CDF4(26774, 32133, 32590) },
1270+ { AOM_CDF4(17844, 29564, 31767) },
1271+ { AOM_CDF4(11690, 24438, 29171) },
1272+ { AOM_CDF4(7542, 18215, 24459) },
1273+ { AOM_CDF4(2993, 8050, 12319) },
1274+ { AOM_CDF4(28023, 32328, 32591) },
1275+ { AOM_CDF4(18651, 30126, 31954) },
1276+ { AOM_CDF4(12164, 25146, 29589) },
1277+ { AOM_CDF4(7762, 18530, 24771) },
1278+ { AOM_CDF4(3492, 9183, 13920) },
1279+ { AOM_CDF4(27591, 32008, 32491) },
1280+ { AOM_CDF4(17149, 28853, 31510) },
1281+ { AOM_CDF4(11485, 24003, 28860) },
1282+ { AOM_CDF4(7697, 18086, 24210) },
1283+ { AOM_CDF4(3075, 7999, 12218) },
1284+ { AOM_CDF4(28268, 32482, 32654) },
1285+ { AOM_CDF4(19631, 31051, 32404) },
1286+ { AOM_CDF4(13860, 27260, 31020) },
1287+ { AOM_CDF4(9605, 21613, 27594) },
1288+ { AOM_CDF4(4876, 12162, 17908) },
1289+ { AOM_CDF4(27248, 32316, 32576) },
1290+ { AOM_CDF4(18955, 30457, 32075) },
1291+ { AOM_CDF4(11824, 23997, 28795) },
1292+ { AOM_CDF4(7346, 18196, 24647) },
1293+ { AOM_CDF4(3403, 9247, 14111) },
1294+ { AOM_CDF4(29711, 32655, 32735) },
1295+ { AOM_CDF4(21169, 31394, 32417) },
1296+ { AOM_CDF4(13487, 27198, 30957) },
1297+ { AOM_CDF4(8828, 21683, 27614) },
1298+ { AOM_CDF4(4270, 11451, 17038) },
1299+ { AOM_CDF4(28708, 32578, 32731) },
1300+ { AOM_CDF4(20120, 31241, 32482) },
1301+ { AOM_CDF4(13692, 27550, 31321) },
1302+ { AOM_CDF4(9418, 22514, 28439) },
1303+ { AOM_CDF4(4999, 13283, 19462) } },
1304+ { { AOM_CDF4(5673, 14302, 19711) },
1305+ { AOM_CDF4(26251, 30701, 31834) },
1306+ { AOM_CDF4(12782, 23783, 27803) },
1307+ { AOM_CDF4(9127, 20657, 25808) },
1308+ { AOM_CDF4(6368, 16208, 21462) },
1309+ { AOM_CDF4(2465, 7177, 10822) },
1310+ { AOM_CDF4(29961, 32563, 32719) },
1311+ { AOM_CDF4(18318, 29891, 31949) },
1312+ { AOM_CDF4(11361, 24514, 29357) },
1313+ { AOM_CDF4(7900, 19603, 25607) },
1314+ { AOM_CDF4(4002, 10590, 15546) },
1315+ { AOM_CDF4(29637, 32310, 32595) },
1316+ { AOM_CDF4(18296, 29913, 31809) },
1317+ { AOM_CDF4(10144, 21515, 26871) },
1318+ { AOM_CDF4(5358, 14322, 20394) },
1319+ { AOM_CDF4(3067, 8362, 13346) },
1320+ { AOM_CDF4(28652, 32470, 32676) },
1321+ { AOM_CDF4(17538, 30771, 32209) },
1322+ { AOM_CDF4(13924, 26882, 30494) },
1323+ { AOM_CDF4(10496, 22837, 27869) },
1324+ { AOM_CDF4(7236, 16396, 21621) },
1325+ { AOM_CDF4(30743, 32687, 32746) },
1326+ { AOM_CDF4(23006, 31676, 32489) },
1327+ { AOM_CDF4(14494, 27828, 31120) },
1328+ { AOM_CDF4(10174, 22801, 28352) },
1329+ { AOM_CDF4(6242, 15281, 21043) },
1330+ { AOM_CDF4(25817, 32243, 32720) },
1331+ { AOM_CDF4(18618, 31367, 32325) },
1332+ { AOM_CDF4(13997, 28318, 31878) },
1333+ { AOM_CDF4(12255, 26534, 31383) },
1334+ { AOM_CDF4(9561, 21588, 28450) },
1335+ { AOM_CDF4(28188, 32635, 32724) },
1336+ { AOM_CDF4(22060, 32365, 32728) },
1337+ { AOM_CDF4(18102, 30690, 32528) },
1338+ { AOM_CDF4(14196, 28864, 31999) },
1339+ { AOM_CDF4(12262, 25792, 30865) },
1340+ { AOM_CDF4(24176, 32109, 32628) },
1341+ { AOM_CDF4(18280, 29681, 31963) },
1342+ { AOM_CDF4(10205, 23703, 29664) },
1343+ { AOM_CDF4(7889, 20025, 27676) },
1344+ { AOM_CDF4(6060, 16743, 23970) } } },
1345+ { { { AOM_CDF4(5141, 7096, 8260) },
1346+ { AOM_CDF4(27186, 29022, 29789) },
1347+ { AOM_CDF4(6668, 12568, 15682) },
1348+ { AOM_CDF4(2172, 6181, 8638) },
1349+ { AOM_CDF4(1126, 3379, 4531) },
1350+ { AOM_CDF4(443, 1361, 2254) },
1351+ { AOM_CDF4(26083, 31153, 32436) },
1352+ { AOM_CDF4(13486, 24603, 28483) },
1353+ { AOM_CDF4(6508, 14840, 19910) },
1354+ { AOM_CDF4(3386, 8800, 13286) },
1355+ { AOM_CDF4(1530, 4322, 7054) },
1356+ { AOM_CDF4(29639, 32080, 32548) },
1357+ { AOM_CDF4(15897, 27552, 30290) },
1358+ { AOM_CDF4(8588, 20047, 25383) },
1359+ { AOM_CDF4(4889, 13339, 19269) },
1360+ { AOM_CDF4(2240, 6871, 10498) },
1361+ { AOM_CDF4(28165, 32197, 32517) },
1362+ { AOM_CDF4(20735, 30427, 31568) },
1363+ { AOM_CDF4(14325, 24671, 27692) },
1364+ { AOM_CDF4(5119, 12554, 17805) },
1365+ { AOM_CDF4(1810, 5441, 8261) },
1366+ { AOM_CDF4(31212, 32724, 32748) },
1367+ { AOM_CDF4(23352, 31766, 32545) },
1368+ { AOM_CDF4(14669, 27570, 31059) },
1369+ { AOM_CDF4(8492, 20894, 27272) },
1370+ { AOM_CDF4(3644, 10194, 15204) },
1371+ { AOM_CDF4(8192, 16384, 24576) },
1372+ { AOM_CDF4(8192, 16384, 24576) },
1373+ { AOM_CDF4(8192, 16384, 24576) },
1374+ { AOM_CDF4(8192, 16384, 24576) },
1375+ { AOM_CDF4(8192, 16384, 24576) },
1376+ { AOM_CDF4(8192, 16384, 24576) },
1377+ { AOM_CDF4(8192, 16384, 24576) },
1378+ { AOM_CDF4(8192, 16384, 24576) },
1379+ { AOM_CDF4(8192, 16384, 24576) },
1380+ { AOM_CDF4(8192, 16384, 24576) },
1381+ { AOM_CDF4(8192, 16384, 24576) },
1382+ { AOM_CDF4(8192, 16384, 24576) },
1383+ { AOM_CDF4(8192, 16384, 24576) },
1384+ { AOM_CDF4(8192, 16384, 24576) },
1385+ { AOM_CDF4(8192, 16384, 24576) } },
1386+ { { AOM_CDF4(2461, 7013, 9371) },
1387+ { AOM_CDF4(24749, 29600, 30986) },
1388+ { AOM_CDF4(9466, 19037, 22417) },
1389+ { AOM_CDF4(3584, 9280, 14400) },
1390+ { AOM_CDF4(1505, 3929, 5433) },
1391+ { AOM_CDF4(677, 1500, 2736) },
1392+ { AOM_CDF4(23987, 30702, 32117) },
1393+ { AOM_CDF4(13554, 24571, 29263) },
1394+ { AOM_CDF4(6211, 14556, 21155) },
1395+ { AOM_CDF4(3135, 10972, 15625) },
1396+ { AOM_CDF4(2435, 7127, 11427) },
1397+ { AOM_CDF4(31300, 32532, 32550) },
1398+ { AOM_CDF4(14757, 30365, 31954) },
1399+ { AOM_CDF4(4405, 11612, 18553) },
1400+ { AOM_CDF4(580, 4132, 7322) },
1401+ { AOM_CDF4(1695, 10169, 14124) },
1402+ { AOM_CDF4(30008, 32282, 32591) },
1403+ { AOM_CDF4(19244, 30108, 31748) },
1404+ { AOM_CDF4(11180, 24158, 29555) },
1405+ { AOM_CDF4(5650, 14972, 19209) },
1406+ { AOM_CDF4(2114, 5109, 8456) },
1407+ { AOM_CDF4(31856, 32716, 32748) },
1408+ { AOM_CDF4(23012, 31664, 32572) },
1409+ { AOM_CDF4(13694, 26656, 30636) },
1410+ { AOM_CDF4(8142, 19508, 26093) },
1411+ { AOM_CDF4(4253, 10955, 16724) },
1412+ { AOM_CDF4(8192, 16384, 24576) },
1413+ { AOM_CDF4(8192, 16384, 24576) },
1414+ { AOM_CDF4(8192, 16384, 24576) },
1415+ { AOM_CDF4(8192, 16384, 24576) },
1416+ { AOM_CDF4(8192, 16384, 24576) },
1417+ { AOM_CDF4(8192, 16384, 24576) },
1418+ { AOM_CDF4(8192, 16384, 24576) },
1419+ { AOM_CDF4(8192, 16384, 24576) },
1420+ { AOM_CDF4(8192, 16384, 24576) },
1421+ { AOM_CDF4(8192, 16384, 24576) },
1422+ { AOM_CDF4(8192, 16384, 24576) },
1423+ { AOM_CDF4(8192, 16384, 24576) },
1424+ { AOM_CDF4(8192, 16384, 24576) },
1425+ { AOM_CDF4(8192, 16384, 24576) },
1426+ { AOM_CDF4(8192, 16384, 24576) } } },
1427+ { { { AOM_CDF4(601, 983, 1311) },
1428+ { AOM_CDF4(18725, 23406, 28087) },
1429+ { AOM_CDF4(5461, 8192, 10923) },
1430+ { AOM_CDF4(3781, 15124, 21425) },
1431+ { AOM_CDF4(2587, 7761, 12072) },
1432+ { AOM_CDF4(106, 458, 810) },
1433+ { AOM_CDF4(22282, 29710, 31894) },
1434+ { AOM_CDF4(8508, 20926, 25984) },
1435+ { AOM_CDF4(3726, 12713, 18083) },
1436+ { AOM_CDF4(1620, 7112, 10893) },
1437+ { AOM_CDF4(729, 2236, 3495) },
1438+ { AOM_CDF4(30163, 32474, 32684) },
1439+ { AOM_CDF4(18304, 30464, 32000) },
1440+ { AOM_CDF4(11443, 26526, 29647) },
1441+ { AOM_CDF4(6007, 15292, 21299) },
1442+ { AOM_CDF4(2234, 6703, 8937) },
1443+ { AOM_CDF4(30954, 32177, 32571) },
1444+ { AOM_CDF4(17363, 29562, 31076) },
1445+ { AOM_CDF4(9686, 22464, 27410) },
1446+ { AOM_CDF4(8192, 16384, 21390) },
1447+ { AOM_CDF4(1755, 8046, 11264) },
1448+ { AOM_CDF4(31168, 32734, 32748) },
1449+ { AOM_CDF4(22486, 31441, 32471) },
1450+ { AOM_CDF4(12833, 25627, 29738) },
1451+ { AOM_CDF4(6980, 17379, 23122) },
1452+ { AOM_CDF4(3111, 8887, 13479) },
1453+ { AOM_CDF4(8192, 16384, 24576) },
1454+ { AOM_CDF4(8192, 16384, 24576) },
1455+ { AOM_CDF4(8192, 16384, 24576) },
1456+ { AOM_CDF4(8192, 16384, 24576) },
1457+ { AOM_CDF4(8192, 16384, 24576) },
1458+ { AOM_CDF4(8192, 16384, 24576) },
1459+ { AOM_CDF4(8192, 16384, 24576) },
1460+ { AOM_CDF4(8192, 16384, 24576) },
1461+ { AOM_CDF4(8192, 16384, 24576) },
1462+ { AOM_CDF4(8192, 16384, 24576) },
1463+ { AOM_CDF4(8192, 16384, 24576) },
1464+ { AOM_CDF4(8192, 16384, 24576) },
1465+ { AOM_CDF4(8192, 16384, 24576) },
1466+ { AOM_CDF4(8192, 16384, 24576) },
1467+ { AOM_CDF4(8192, 16384, 24576) } },
1468+ { { AOM_CDF4(8192, 16384, 24576) },
1469+ { AOM_CDF4(8192, 16384, 24576) },
1470+ { AOM_CDF4(8192, 16384, 24576) },
1471+ { AOM_CDF4(8192, 16384, 24576) },
1472+ { AOM_CDF4(8192, 16384, 24576) },
1473+ { AOM_CDF4(8192, 16384, 24576) },
1474+ { AOM_CDF4(8192, 16384, 24576) },
1475+ { AOM_CDF4(8192, 16384, 24576) },
1476+ { AOM_CDF4(8192, 16384, 24576) },
1477+ { AOM_CDF4(8192, 16384, 24576) },
1478+ { AOM_CDF4(8192, 16384, 24576) },
1479+ { AOM_CDF4(8192, 16384, 24576) },
1480+ { AOM_CDF4(8192, 16384, 24576) },
1481+ { AOM_CDF4(8192, 16384, 24576) },
1482+ { AOM_CDF4(8192, 16384, 24576) },
1483+ { AOM_CDF4(8192, 16384, 24576) },
1484+ { AOM_CDF4(8192, 16384, 24576) },
1485+ { AOM_CDF4(8192, 16384, 24576) },
1486+ { AOM_CDF4(8192, 16384, 24576) },
1487+ { AOM_CDF4(8192, 16384, 24576) },
1488+ { AOM_CDF4(8192, 16384, 24576) },
1489+ { AOM_CDF4(8192, 16384, 24576) },
1490+ { AOM_CDF4(8192, 16384, 24576) },
1491+ { AOM_CDF4(8192, 16384, 24576) },
1492+ { AOM_CDF4(8192, 16384, 24576) },
1493+ { AOM_CDF4(8192, 16384, 24576) },
1494+ { AOM_CDF4(8192, 16384, 24576) },
1495+ { AOM_CDF4(8192, 16384, 24576) },
1496+ { AOM_CDF4(8192, 16384, 24576) },
1497+ { AOM_CDF4(8192, 16384, 24576) },
1498+ { AOM_CDF4(8192, 16384, 24576) },
1499+ { AOM_CDF4(8192, 16384, 24576) },
1500+ { AOM_CDF4(8192, 16384, 24576) },
1501+ { AOM_CDF4(8192, 16384, 24576) },
1502+ { AOM_CDF4(8192, 16384, 24576) },
1503+ { AOM_CDF4(8192, 16384, 24576) },
1504+ { AOM_CDF4(8192, 16384, 24576) },
1505+ { AOM_CDF4(8192, 16384, 24576) },
1506+ { AOM_CDF4(8192, 16384, 24576) },
1507+ { AOM_CDF4(8192, 16384, 24576) },
1508+ { AOM_CDF4(8192, 16384, 24576) } } }
1509+ }, .dc_sign = {
1510+ {
1511+ { AOM_CDF2(128 * 125) },
1512+ { AOM_CDF2(128 * 102) },
1513+ { AOM_CDF2(128 * 147) },
1514+ }, {
1515+ { AOM_CDF2(128 * 119) },
1516+ { AOM_CDF2(128 * 101) },
1517+ { AOM_CDF2(128 * 135) },
1518+ }
1519+ }, .br_tok = {
1520+ { { { AOM_CDF4(14298, 20718, 24174) },
1521+ { AOM_CDF4(12536, 19601, 23789) },
1522+ { AOM_CDF4(8712, 15051, 19503) },
1523+ { AOM_CDF4(6170, 11327, 15434) },
1524+ { AOM_CDF4(4742, 8926, 12538) },
1525+ { AOM_CDF4(3803, 7317, 10546) },
1526+ { AOM_CDF4(1696, 3317, 4871) },
1527+ { AOM_CDF4(14392, 19951, 22756) },
1528+ { AOM_CDF4(15978, 23218, 26818) },
1529+ { AOM_CDF4(12187, 19474, 23889) },
1530+ { AOM_CDF4(9176, 15640, 20259) },
1531+ { AOM_CDF4(7068, 12655, 17028) },
1532+ { AOM_CDF4(5656, 10442, 14472) },
1533+ { AOM_CDF4(2580, 4992, 7244) },
1534+ { AOM_CDF4(12136, 18049, 21426) },
1535+ { AOM_CDF4(13784, 20721, 24481) },
1536+ { AOM_CDF4(10836, 17621, 21900) },
1537+ { AOM_CDF4(8372, 14444, 18847) },
1538+ { AOM_CDF4(6523, 11779, 16000) },
1539+ { AOM_CDF4(5337, 9898, 13760) },
1540+ { AOM_CDF4(3034, 5860, 8462) } },
1541+ { { AOM_CDF4(15967, 22905, 26286) },
1542+ { AOM_CDF4(13534, 20654, 24579) },
1543+ { AOM_CDF4(9504, 16092, 20535) },
1544+ { AOM_CDF4(6975, 12568, 16903) },
1545+ { AOM_CDF4(5364, 10091, 14020) },
1546+ { AOM_CDF4(4357, 8370, 11857) },
1547+ { AOM_CDF4(2506, 4934, 7218) },
1548+ { AOM_CDF4(23032, 28815, 30936) },
1549+ { AOM_CDF4(19540, 26704, 29719) },
1550+ { AOM_CDF4(15158, 22969, 27097) },
1551+ { AOM_CDF4(11408, 18865, 23650) },
1552+ { AOM_CDF4(8885, 15448, 20250) },
1553+ { AOM_CDF4(7108, 12853, 17416) },
1554+ { AOM_CDF4(4231, 8041, 11480) },
1555+ { AOM_CDF4(19823, 26490, 29156) },
1556+ { AOM_CDF4(18890, 25929, 28932) },
1557+ { AOM_CDF4(15660, 23491, 27433) },
1558+ { AOM_CDF4(12147, 19776, 24488) },
1559+ { AOM_CDF4(9728, 16774, 21649) },
1560+ { AOM_CDF4(7919, 14277, 19066) },
1561+ { AOM_CDF4(5440, 10170, 14185) } } },
1562+ { { { AOM_CDF4(14406, 20862, 24414) },
1563+ { AOM_CDF4(11824, 18907, 23109) },
1564+ { AOM_CDF4(8257, 14393, 18803) },
1565+ { AOM_CDF4(5860, 10747, 14778) },
1566+ { AOM_CDF4(4475, 8486, 11984) },
1567+ { AOM_CDF4(3606, 6954, 10043) },
1568+ { AOM_CDF4(1736, 3410, 5048) },
1569+ { AOM_CDF4(14430, 20046, 22882) },
1570+ { AOM_CDF4(15593, 22899, 26709) },
1571+ { AOM_CDF4(12102, 19368, 23811) },
1572+ { AOM_CDF4(9059, 15584, 20262) },
1573+ { AOM_CDF4(6999, 12603, 17048) },
1574+ { AOM_CDF4(5684, 10497, 14553) },
1575+ { AOM_CDF4(2822, 5438, 7862) },
1576+ { AOM_CDF4(15785, 21585, 24359) },
1577+ { AOM_CDF4(18347, 25229, 28266) },
1578+ { AOM_CDF4(14974, 22487, 26389) },
1579+ { AOM_CDF4(11423, 18681, 23271) },
1580+ { AOM_CDF4(8863, 15350, 20008) },
1581+ { AOM_CDF4(7153, 12852, 17278) },
1582+ { AOM_CDF4(3707, 7036, 9982) } },
1583+ { { AOM_CDF4(15460, 21696, 25469) },
1584+ { AOM_CDF4(12170, 19249, 23191) },
1585+ { AOM_CDF4(8723, 15027, 19332) },
1586+ { AOM_CDF4(6428, 11704, 15874) },
1587+ { AOM_CDF4(4922, 9292, 13052) },
1588+ { AOM_CDF4(4139, 7695, 11010) },
1589+ { AOM_CDF4(2291, 4508, 6598) },
1590+ { AOM_CDF4(19856, 26920, 29828) },
1591+ { AOM_CDF4(17923, 25289, 28792) },
1592+ { AOM_CDF4(14278, 21968, 26297) },
1593+ { AOM_CDF4(10910, 18136, 22950) },
1594+ { AOM_CDF4(8423, 14815, 19627) },
1595+ { AOM_CDF4(6771, 12283, 16774) },
1596+ { AOM_CDF4(4074, 7750, 11081) },
1597+ { AOM_CDF4(19852, 26074, 28672) },
1598+ { AOM_CDF4(19371, 26110, 28989) },
1599+ { AOM_CDF4(16265, 23873, 27663) },
1600+ { AOM_CDF4(12758, 20378, 24952) },
1601+ { AOM_CDF4(10095, 17098, 21961) },
1602+ { AOM_CDF4(8250, 14628, 19451) },
1603+ { AOM_CDF4(5205, 9745, 13622) } } },
1604+ { { { AOM_CDF4(10563, 16233, 19763) },
1605+ { AOM_CDF4(9794, 16022, 19804) },
1606+ { AOM_CDF4(6750, 11945, 15759) },
1607+ { AOM_CDF4(4963, 9186, 12752) },
1608+ { AOM_CDF4(3845, 7435, 10627) },
1609+ { AOM_CDF4(3051, 6085, 8834) },
1610+ { AOM_CDF4(1311, 2596, 3830) },
1611+ { AOM_CDF4(11246, 16404, 19689) },
1612+ { AOM_CDF4(12315, 18911, 22731) },
1613+ { AOM_CDF4(10557, 17095, 21289) },
1614+ { AOM_CDF4(8136, 14006, 18249) },
1615+ { AOM_CDF4(6348, 11474, 15565) },
1616+ { AOM_CDF4(5196, 9655, 13400) },
1617+ { AOM_CDF4(2349, 4526, 6587) },
1618+ { AOM_CDF4(13337, 18730, 21569) },
1619+ { AOM_CDF4(19306, 26071, 28882) },
1620+ { AOM_CDF4(15952, 23540, 27254) },
1621+ { AOM_CDF4(12409, 19934, 24430) },
1622+ { AOM_CDF4(9760, 16706, 21389) },
1623+ { AOM_CDF4(8004, 14220, 18818) },
1624+ { AOM_CDF4(4138, 7794, 10961) } },
1625+ { { AOM_CDF4(10870, 16684, 20949) },
1626+ { AOM_CDF4(9664, 15230, 18680) },
1627+ { AOM_CDF4(6886, 12109, 15408) },
1628+ { AOM_CDF4(4825, 8900, 12305) },
1629+ { AOM_CDF4(3630, 7162, 10314) },
1630+ { AOM_CDF4(3036, 6429, 9387) },
1631+ { AOM_CDF4(1671, 3296, 4940) },
1632+ { AOM_CDF4(13819, 19159, 23026) },
1633+ { AOM_CDF4(11984, 19108, 23120) },
1634+ { AOM_CDF4(10690, 17210, 21663) },
1635+ { AOM_CDF4(7984, 14154, 18333) },
1636+ { AOM_CDF4(6868, 12294, 16124) },
1637+ { AOM_CDF4(5274, 8994, 12868) },
1638+ { AOM_CDF4(2988, 5771, 8424) },
1639+ { AOM_CDF4(19736, 26647, 29141) },
1640+ { AOM_CDF4(18933, 26070, 28984) },
1641+ { AOM_CDF4(15779, 23048, 27200) },
1642+ { AOM_CDF4(12638, 20061, 24532) },
1643+ { AOM_CDF4(10692, 17545, 22220) },
1644+ { AOM_CDF4(9217, 15251, 20054) },
1645+ { AOM_CDF4(5078, 9284, 12594) } } },
1646+ { { { AOM_CDF4(2331, 3662, 5244) },
1647+ { AOM_CDF4(2891, 4771, 6145) },
1648+ { AOM_CDF4(4598, 7623, 9729) },
1649+ { AOM_CDF4(3520, 6845, 9199) },
1650+ { AOM_CDF4(3417, 6119, 9324) },
1651+ { AOM_CDF4(2601, 5412, 7385) },
1652+ { AOM_CDF4(600, 1173, 1744) },
1653+ { AOM_CDF4(7672, 13286, 17469) },
1654+ { AOM_CDF4(4232, 7792, 10793) },
1655+ { AOM_CDF4(2915, 5317, 7397) },
1656+ { AOM_CDF4(2318, 4356, 6152) },
1657+ { AOM_CDF4(2127, 4000, 5554) },
1658+ { AOM_CDF4(1850, 3478, 5275) },
1659+ { AOM_CDF4(977, 1933, 2843) },
1660+ { AOM_CDF4(18280, 24387, 27989) },
1661+ { AOM_CDF4(15852, 22671, 26185) },
1662+ { AOM_CDF4(13845, 20951, 24789) },
1663+ { AOM_CDF4(11055, 17966, 22129) },
1664+ { AOM_CDF4(9138, 15422, 19801) },
1665+ { AOM_CDF4(7454, 13145, 17456) },
1666+ { AOM_CDF4(3370, 6393, 9013) } },
1667+ { { AOM_CDF4(5842, 9229, 10838) },
1668+ { AOM_CDF4(2313, 3491, 4276) },
1669+ { AOM_CDF4(2998, 6104, 7496) },
1670+ { AOM_CDF4(2420, 7447, 9868) },
1671+ { AOM_CDF4(3034, 8495, 10923) },
1672+ { AOM_CDF4(4076, 8937, 10975) },
1673+ { AOM_CDF4(1086, 2370, 3299) },
1674+ { AOM_CDF4(9714, 17254, 20444) },
1675+ { AOM_CDF4(8543, 13698, 17123) },
1676+ { AOM_CDF4(4918, 9007, 11910) },
1677+ { AOM_CDF4(4129, 7532, 10553) },
1678+ { AOM_CDF4(2364, 5533, 8058) },
1679+ { AOM_CDF4(1834, 3546, 5563) },
1680+ { AOM_CDF4(1473, 2908, 4133) },
1681+ { AOM_CDF4(15405, 21193, 25619) },
1682+ { AOM_CDF4(15691, 21952, 26561) },
1683+ { AOM_CDF4(12962, 19194, 24165) },
1684+ { AOM_CDF4(10272, 17855, 22129) },
1685+ { AOM_CDF4(8588, 15270, 20718) },
1686+ { AOM_CDF4(8682, 14669, 19500) },
1687+ { AOM_CDF4(4870, 9636, 13205) } } }
1688+ },
1689+ }, [1] = {
1690+ .skip = {
1691+ { { AOM_CDF2(30371) },
1692+ { AOM_CDF2(7570) },
1693+ { AOM_CDF2(13155) },
1694+ { AOM_CDF2(20751) },
1695+ { AOM_CDF2(20969) },
1696+ { AOM_CDF2(27067) },
1697+ { AOM_CDF2(32013) },
1698+ { AOM_CDF2(5495) },
1699+ { AOM_CDF2(17942) },
1700+ { AOM_CDF2(28280) },
1701+ { AOM_CDF2(16384) },
1702+ { AOM_CDF2(16384) },
1703+ { AOM_CDF2(16384) } },
1704+ { { AOM_CDF2(31782) },
1705+ { AOM_CDF2(1836) },
1706+ { AOM_CDF2(10689) },
1707+ { AOM_CDF2(17604) },
1708+ { AOM_CDF2(21622) },
1709+ { AOM_CDF2(27518) },
1710+ { AOM_CDF2(32399) },
1711+ { AOM_CDF2(4419) },
1712+ { AOM_CDF2(16294) },
1713+ { AOM_CDF2(28345) },
1714+ { AOM_CDF2(16384) },
1715+ { AOM_CDF2(16384) },
1716+ { AOM_CDF2(16384) } },
1717+ { { AOM_CDF2(31901) },
1718+ { AOM_CDF2(10311) },
1719+ { AOM_CDF2(18047) },
1720+ { AOM_CDF2(24806) },
1721+ { AOM_CDF2(23288) },
1722+ { AOM_CDF2(27914) },
1723+ { AOM_CDF2(32296) },
1724+ { AOM_CDF2(4215) },
1725+ { AOM_CDF2(15756) },
1726+ { AOM_CDF2(28341) },
1727+ { AOM_CDF2(16384) },
1728+ { AOM_CDF2(16384) },
1729+ { AOM_CDF2(16384) } },
1730+ { { AOM_CDF2(26726) },
1731+ { AOM_CDF2(1045) },
1732+ { AOM_CDF2(11703) },
1733+ { AOM_CDF2(20590) },
1734+ { AOM_CDF2(18554) },
1735+ { AOM_CDF2(25970) },
1736+ { AOM_CDF2(31938) },
1737+ { AOM_CDF2(5583) },
1738+ { AOM_CDF2(21313) },
1739+ { AOM_CDF2(29390) },
1740+ { AOM_CDF2(641) },
1741+ { AOM_CDF2(22265) },
1742+ { AOM_CDF2(31452) } },
1743+ { { AOM_CDF2(26584) },
1744+ { AOM_CDF2(188) },
1745+ { AOM_CDF2(8847) },
1746+ { AOM_CDF2(24519) },
1747+ { AOM_CDF2(22938) },
1748+ { AOM_CDF2(30583) },
1749+ { AOM_CDF2(32608) },
1750+ { AOM_CDF2(16384) },
1751+ { AOM_CDF2(16384) },
1752+ { AOM_CDF2(16384) },
1753+ { AOM_CDF2(16384) },
1754+ { AOM_CDF2(16384) },
1755+ { AOM_CDF2(16384) } }
1756+ }, .eob_bin_16 = {
1757+ { { AOM_CDF5(2125, 2551, 5165, 8946) },
1758+ { AOM_CDF5(513, 765, 1859, 6339) } },
1759+ { { AOM_CDF5(7637, 9498, 14259, 19108) },
1760+ { AOM_CDF5(2497, 4096, 8866, 16993) } }
1761+ }, .eob_bin_32 = {
1762+ { { AOM_CDF6(989, 1249, 2019, 4151, 10785) },
1763+ { AOM_CDF6(313, 441, 1099, 2917, 8562) } },
1764+ { { AOM_CDF6(8394, 10352, 13932, 18855, 26014) },
1765+ { AOM_CDF6(2578, 4124, 8181, 13670, 24234) } }
1766+ }, .eob_bin_64 = {
1767+ { { AOM_CDF7(1260, 1446, 2253, 3712, 6652, 13369) },
1768+ { AOM_CDF7(401, 605, 1029, 2563, 5845, 12626) } },
1769+ { { AOM_CDF7(8609, 10612, 14624, 18714, 22614, 29024) },
1770+ { AOM_CDF7(1923, 3127, 5867, 9703, 14277, 27100) } }
1771+ }, .eob_bin_128 = {
1772+ { { AOM_CDF8(685, 933, 1488, 2714, 4766, 8562, 19254) },
1773+ { AOM_CDF8(217, 352, 618, 2303, 5261, 9969, 17472) } },
1774+ { { AOM_CDF8(8045, 11200, 15497, 19595, 23948, 27408, 30938) },
1775+ { AOM_CDF8(2310, 4160, 7471, 14997, 17931, 20768, 30240) } }
1776+ }, .eob_bin_256 = {
1777+ { { AOM_CDF9(1448, 2109, 4151, 6263, 9329, 13260, 17944, 23300) },
1778+ { AOM_CDF9(399, 1019, 1749, 3038, 10444, 15546, 22739, 27294) } },
1779+ { { AOM_CDF9(6402, 8148, 12623, 15072, 18728, 22847, 26447, 29377) },
1780+ { AOM_CDF9(1674, 3252, 5734, 10159, 22397, 23802, 24821, 30940) } }
1781+ }, .eob_bin_512 = {
1782+ { { AOM_CDF10(1230, 2278, 5035, 7776, 11871, 15346, 19590,
1783+ 24584, 28749) },
1784+ { AOM_CDF10(3277, 6554, 9830, 13107, 16384, 19661, 22938,
1785+ 26214, 29491) } },
1786+ { { AOM_CDF10(7265, 9979, 15819, 19250, 21780, 23846, 26478,
1787+ 28396, 31811) },
1788+ { AOM_CDF10(3277, 6554, 9830, 13107, 16384, 19661, 22938,
1789+ 26214, 29491) } }
1790+ }, .eob_bin_1024 = {
1791+ { { AOM_CDF11(696, 948, 3145, 5702, 9706, 13217, 17851,
1792+ 21856, 25692, 28034) },
1793+ { AOM_CDF11(2979, 5958, 8937, 11916, 14895, 17873, 20852,
1794+ 23831, 26810, 29789) } },
1795+ { { AOM_CDF11(2672, 3591, 9330, 17084, 22725, 24284, 26527,
1796+ 28027, 28377, 30876) },
1797+ { AOM_CDF11(2979, 5958, 8937, 11916, 14895, 17873, 20852,
1798+ 23831, 26810, 29789) } }
1799+ }, .eob_hi_bit = {
1800+ { { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
1801+ { AOM_CDF2(17471) }, { AOM_CDF2(20223) }, { AOM_CDF2(11357) },
1802+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
1803+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) } },
1804+ { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
1805+ { AOM_CDF2(20335) }, { AOM_CDF2(21667) }, { AOM_CDF2(14818) },
1806+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
1807+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) } } },
1808+ { { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
1809+ { AOM_CDF2(20430) }, { AOM_CDF2(20662) }, { AOM_CDF2(15367) },
1810+ { AOM_CDF2(16970) }, { AOM_CDF2(14657) }, { AOM_CDF2(16384) },
1811+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) } },
1812+ { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
1813+ { AOM_CDF2(22117) }, { AOM_CDF2(22028) }, { AOM_CDF2(18650) },
1814+ { AOM_CDF2(16042) }, { AOM_CDF2(15885) }, { AOM_CDF2(16384) },
1815+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) } } },
1816+ { { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
1817+ { AOM_CDF2(22409) }, { AOM_CDF2(21012) }, { AOM_CDF2(15650) },
1818+ { AOM_CDF2(17395) }, { AOM_CDF2(15469) }, { AOM_CDF2(20205) },
1819+ { AOM_CDF2(19511) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) } },
1820+ { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
1821+ { AOM_CDF2(24220) }, { AOM_CDF2(22480) }, { AOM_CDF2(17737) },
1822+ { AOM_CDF2(18916) }, { AOM_CDF2(19268) }, { AOM_CDF2(18412) },
1823+ { AOM_CDF2(18844) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) } } },
1824+ { { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
1825+ { AOM_CDF2(25991) }, { AOM_CDF2(20314) }, { AOM_CDF2(17731) },
1826+ { AOM_CDF2(19678) }, { AOM_CDF2(18649) }, { AOM_CDF2(17307) },
1827+ { AOM_CDF2(21798) }, { AOM_CDF2(17549) }, { AOM_CDF2(15630) } },
1828+ { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
1829+ { AOM_CDF2(26585) }, { AOM_CDF2(21469) }, { AOM_CDF2(20432) },
1830+ { AOM_CDF2(17735) }, { AOM_CDF2(19280) }, { AOM_CDF2(15235) },
1831+ { AOM_CDF2(20297) }, { AOM_CDF2(22471) }, { AOM_CDF2(28997) } } },
1832+ { { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
1833+ { AOM_CDF2(26605) }, { AOM_CDF2(11304) }, { AOM_CDF2(16726) },
1834+ { AOM_CDF2(16560) }, { AOM_CDF2(20866) }, { AOM_CDF2(23524) },
1835+ { AOM_CDF2(19878) }, { AOM_CDF2(13469) }, { AOM_CDF2(23084) } },
1836+ { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
1837+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
1838+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
1839+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) } } }
1840+ }, .eob_base_tok = {
1841+ { { { AOM_CDF3(17560, 29888) },
1842+ { AOM_CDF3(29671, 31549) },
1843+ { AOM_CDF3(31007, 32056) },
1844+ { AOM_CDF3(27286, 30006) } },
1845+ { { AOM_CDF3(26594, 31212) },
1846+ { AOM_CDF3(31208, 32582) },
1847+ { AOM_CDF3(31835, 32637) },
1848+ { AOM_CDF3(30595, 32206) } } },
1849+ { { { AOM_CDF3(15239, 29932) },
1850+ { AOM_CDF3(31315, 32095) },
1851+ { AOM_CDF3(32130, 32434) },
1852+ { AOM_CDF3(30864, 31996) } },
1853+ { { AOM_CDF3(26279, 30968) },
1854+ { AOM_CDF3(31142, 32495) },
1855+ { AOM_CDF3(31713, 32540) },
1856+ { AOM_CDF3(31929, 32594) } } },
1857+ { { { AOM_CDF3(2644, 25198) },
1858+ { AOM_CDF3(32038, 32451) },
1859+ { AOM_CDF3(32639, 32695) },
1860+ { AOM_CDF3(32166, 32518) } },
1861+ { { AOM_CDF3(17187, 27668) },
1862+ { AOM_CDF3(31714, 32550) },
1863+ { AOM_CDF3(32283, 32678) },
1864+ { AOM_CDF3(31930, 32563) } } },
1865+ { { { AOM_CDF3(1044, 2257) },
1866+ { AOM_CDF3(30755, 31923) },
1867+ { AOM_CDF3(32208, 32693) },
1868+ { AOM_CDF3(32244, 32615) } },
1869+ { { AOM_CDF3(21317, 26207) },
1870+ { AOM_CDF3(29133, 30868) },
1871+ { AOM_CDF3(29311, 31231) },
1872+ { AOM_CDF3(29657, 31087) } } },
1873+ { { { AOM_CDF3(478, 1834) },
1874+ { AOM_CDF3(31005, 31987) },
1875+ { AOM_CDF3(32317, 32724) },
1876+ { AOM_CDF3(30865, 32648) } },
1877+ { { AOM_CDF3(10923, 21845) },
1878+ { AOM_CDF3(10923, 21845) },
1879+ { AOM_CDF3(10923, 21845) },
1880+ { AOM_CDF3(10923, 21845) } } }
1881+ }, .base_tok = {
1882+ { { { AOM_CDF4(6041, 11854, 15927) },
1883+ { AOM_CDF4(20326, 30905, 32251) },
1884+ { AOM_CDF4(14164, 26831, 30725) },
1885+ { AOM_CDF4(9760, 20647, 26585) },
1886+ { AOM_CDF4(6416, 14953, 21219) },
1887+ { AOM_CDF4(2966, 7151, 10891) },
1888+ { AOM_CDF4(23567, 31374, 32254) },
1889+ { AOM_CDF4(14978, 27416, 30946) },
1890+ { AOM_CDF4(9434, 20225, 26254) },
1891+ { AOM_CDF4(6658, 14558, 20535) },
1892+ { AOM_CDF4(3916, 8677, 12989) },
1893+ { AOM_CDF4(8192, 16384, 24576) },
1894+ { AOM_CDF4(8192, 16384, 24576) },
1895+ { AOM_CDF4(8192, 16384, 24576) },
1896+ { AOM_CDF4(8192, 16384, 24576) },
1897+ { AOM_CDF4(8192, 16384, 24576) },
1898+ { AOM_CDF4(8192, 16384, 24576) },
1899+ { AOM_CDF4(8192, 16384, 24576) },
1900+ { AOM_CDF4(8192, 16384, 24576) },
1901+ { AOM_CDF4(8192, 16384, 24576) },
1902+ { AOM_CDF4(8192, 16384, 24576) },
1903+ { AOM_CDF4(18088, 29545, 31587) },
1904+ { AOM_CDF4(13062, 25843, 30073) },
1905+ { AOM_CDF4(8940, 16827, 22251) },
1906+ { AOM_CDF4(7654, 13220, 17973) },
1907+ { AOM_CDF4(5733, 10316, 14456) },
1908+ { AOM_CDF4(22879, 31388, 32114) },
1909+ { AOM_CDF4(15215, 27993, 30955) },
1910+ { AOM_CDF4(9397, 19445, 24978) },
1911+ { AOM_CDF4(3442, 9813, 15344) },
1912+ { AOM_CDF4(1368, 3936, 6532) },
1913+ { AOM_CDF4(25494, 32033, 32406) },
1914+ { AOM_CDF4(16772, 27963, 30718) },
1915+ { AOM_CDF4(9419, 18165, 23260) },
1916+ { AOM_CDF4(2677, 7501, 11797) },
1917+ { AOM_CDF4(1516, 4344, 7170) },
1918+ { AOM_CDF4(26556, 31454, 32101) },
1919+ { AOM_CDF4(17128, 27035, 30108) },
1920+ { AOM_CDF4(8324, 15344, 20249) },
1921+ { AOM_CDF4(1903, 5696, 9469) },
1922+ { AOM_CDF4(8192, 16384, 24576) } },
1923+ { { AOM_CDF4(8455, 19003, 24368) },
1924+ { AOM_CDF4(23563, 32021, 32604) },
1925+ { AOM_CDF4(16237, 29446, 31935) },
1926+ { AOM_CDF4(10724, 23999, 29358) },
1927+ { AOM_CDF4(6725, 17528, 24416) },
1928+ { AOM_CDF4(3927, 10927, 16825) },
1929+ { AOM_CDF4(26313, 32288, 32634) },
1930+ { AOM_CDF4(17430, 30095, 32095) },
1931+ { AOM_CDF4(11116, 24606, 29679) },
1932+ { AOM_CDF4(7195, 18384, 25269) },
1933+ { AOM_CDF4(4726, 12852, 19315) },
1934+ { AOM_CDF4(8192, 16384, 24576) },
1935+ { AOM_CDF4(8192, 16384, 24576) },
1936+ { AOM_CDF4(8192, 16384, 24576) },
1937+ { AOM_CDF4(8192, 16384, 24576) },
1938+ { AOM_CDF4(8192, 16384, 24576) },
1939+ { AOM_CDF4(8192, 16384, 24576) },
1940+ { AOM_CDF4(8192, 16384, 24576) },
1941+ { AOM_CDF4(8192, 16384, 24576) },
1942+ { AOM_CDF4(8192, 16384, 24576) },
1943+ { AOM_CDF4(8192, 16384, 24576) },
1944+ { AOM_CDF4(22822, 31648, 32483) },
1945+ { AOM_CDF4(16724, 29633, 31929) },
1946+ { AOM_CDF4(10261, 23033, 28725) },
1947+ { AOM_CDF4(7029, 17840, 24528) },
1948+ { AOM_CDF4(4867, 13886, 21502) },
1949+ { AOM_CDF4(25298, 31892, 32491) },
1950+ { AOM_CDF4(17809, 29330, 31512) },
1951+ { AOM_CDF4(9668, 21329, 26579) },
1952+ { AOM_CDF4(4774, 12956, 18976) },
1953+ { AOM_CDF4(2322, 7030, 11540) },
1954+ { AOM_CDF4(25472, 31920, 32543) },
1955+ { AOM_CDF4(17957, 29387, 31632) },
1956+ { AOM_CDF4(9196, 20593, 26400) },
1957+ { AOM_CDF4(4680, 12705, 19202) },
1958+ { AOM_CDF4(2917, 8456, 13436) },
1959+ { AOM_CDF4(26471, 32059, 32574) },
1960+ { AOM_CDF4(18458, 29783, 31909) },
1961+ { AOM_CDF4(8400, 19464, 25956) },
1962+ { AOM_CDF4(3812, 10973, 17206) },
1963+ { AOM_CDF4(8192, 16384, 24576) } } },
1964+ { { { AOM_CDF4(6779, 13743, 17678) },
1965+ { AOM_CDF4(24806, 31797, 32457) },
1966+ { AOM_CDF4(17616, 29047, 31372) },
1967+ { AOM_CDF4(11063, 23175, 28003) },
1968+ { AOM_CDF4(6521, 16110, 22324) },
1969+ { AOM_CDF4(2764, 7504, 11654) },
1970+ { AOM_CDF4(25266, 32367, 32637) },
1971+ { AOM_CDF4(19054, 30553, 32175) },
1972+ { AOM_CDF4(12139, 25212, 29807) },
1973+ { AOM_CDF4(7311, 18162, 24704) },
1974+ { AOM_CDF4(3397, 9164, 14074) },
1975+ { AOM_CDF4(25988, 32208, 32522) },
1976+ { AOM_CDF4(16253, 28912, 31526) },
1977+ { AOM_CDF4(9151, 21387, 27372) },
1978+ { AOM_CDF4(5688, 14915, 21496) },
1979+ { AOM_CDF4(2717, 7627, 12004) },
1980+ { AOM_CDF4(23144, 31855, 32443) },
1981+ { AOM_CDF4(16070, 28491, 31325) },
1982+ { AOM_CDF4(8702, 20467, 26517) },
1983+ { AOM_CDF4(5243, 13956, 20367) },
1984+ { AOM_CDF4(2621, 7335, 11567) },
1985+ { AOM_CDF4(26636, 32340, 32630) },
1986+ { AOM_CDF4(19990, 31050, 32341) },
1987+ { AOM_CDF4(13243, 26105, 30315) },
1988+ { AOM_CDF4(8588, 19521, 25918) },
1989+ { AOM_CDF4(4717, 11585, 17304) },
1990+ { AOM_CDF4(25844, 32292, 32582) },
1991+ { AOM_CDF4(19090, 30635, 32097) },
1992+ { AOM_CDF4(11963, 24546, 28939) },
1993+ { AOM_CDF4(6218, 16087, 22354) },
1994+ { AOM_CDF4(2340, 6608, 10426) },
1995+ { AOM_CDF4(28046, 32576, 32694) },
1996+ { AOM_CDF4(21178, 31313, 32296) },
1997+ { AOM_CDF4(13486, 26184, 29870) },
1998+ { AOM_CDF4(7149, 17871, 23723) },
1999+ { AOM_CDF4(2833, 7958, 12259) },
2000+ { AOM_CDF4(27710, 32528, 32686) },
2001+ { AOM_CDF4(20674, 31076, 32268) },
2002+ { AOM_CDF4(12413, 24955, 29243) },
2003+ { AOM_CDF4(6676, 16927, 23097) },
2004+ { AOM_CDF4(2966, 8333, 12919) } },
2005+ { { AOM_CDF4(8639, 19339, 24429) },
2006+ { AOM_CDF4(24404, 31837, 32525) },
2007+ { AOM_CDF4(16997, 29425, 31784) },
2008+ { AOM_CDF4(11253, 24234, 29149) },
2009+ { AOM_CDF4(6751, 17394, 24028) },
2010+ { AOM_CDF4(3490, 9830, 15191) },
2011+ { AOM_CDF4(26283, 32471, 32714) },
2012+ { AOM_CDF4(19599, 31168, 32442) },
2013+ { AOM_CDF4(13146, 26954, 30893) },
2014+ { AOM_CDF4(8214, 20588, 26890) },
2015+ { AOM_CDF4(4699, 13081, 19300) },
2016+ { AOM_CDF4(28212, 32458, 32669) },
2017+ { AOM_CDF4(18594, 30316, 32100) },
2018+ { AOM_CDF4(11219, 24408, 29234) },
2019+ { AOM_CDF4(6865, 17656, 24149) },
2020+ { AOM_CDF4(3678, 10362, 16006) },
2021+ { AOM_CDF4(25825, 32136, 32616) },
2022+ { AOM_CDF4(17313, 29853, 32021) },
2023+ { AOM_CDF4(11197, 24471, 29472) },
2024+ { AOM_CDF4(6947, 17781, 24405) },
2025+ { AOM_CDF4(3768, 10660, 16261) },
2026+ { AOM_CDF4(27352, 32500, 32706) },
2027+ { AOM_CDF4(20850, 31468, 32469) },
2028+ { AOM_CDF4(14021, 27707, 31133) },
2029+ { AOM_CDF4(8964, 21748, 27838) },
2030+ { AOM_CDF4(5437, 14665, 21187) },
2031+ { AOM_CDF4(26304, 32492, 32698) },
2032+ { AOM_CDF4(20409, 31380, 32385) },
2033+ { AOM_CDF4(13682, 27222, 30632) },
2034+ { AOM_CDF4(8974, 21236, 26685) },
2035+ { AOM_CDF4(4234, 11665, 16934) },
2036+ { AOM_CDF4(26273, 32357, 32711) },
2037+ { AOM_CDF4(20672, 31242, 32441) },
2038+ { AOM_CDF4(14172, 27254, 30902) },
2039+ { AOM_CDF4(9870, 21898, 27275) },
2040+ { AOM_CDF4(5164, 13506, 19270) },
2041+ { AOM_CDF4(26725, 32459, 32728) },
2042+ { AOM_CDF4(20991, 31442, 32527) },
2043+ { AOM_CDF4(13071, 26434, 30811) },
2044+ { AOM_CDF4(8184, 20090, 26742) },
2045+ { AOM_CDF4(4803, 13255, 19895) } } },
2046+ { { { AOM_CDF4(7555, 14942, 18501) },
2047+ { AOM_CDF4(24410, 31178, 32287) },
2048+ { AOM_CDF4(14394, 26738, 30253) },
2049+ { AOM_CDF4(8413, 19554, 25195) },
2050+ { AOM_CDF4(4766, 12924, 18785) },
2051+ { AOM_CDF4(2029, 5806, 9207) },
2052+ { AOM_CDF4(26776, 32364, 32663) },
2053+ { AOM_CDF4(18732, 29967, 31931) },
2054+ { AOM_CDF4(11005, 23786, 28852) },
2055+ { AOM_CDF4(6466, 16909, 23510) },
2056+ { AOM_CDF4(3044, 8638, 13419) },
2057+ { AOM_CDF4(29208, 32582, 32704) },
2058+ { AOM_CDF4(20068, 30857, 32208) },
2059+ { AOM_CDF4(12003, 25085, 29595) },
2060+ { AOM_CDF4(6947, 17750, 24189) },
2061+ { AOM_CDF4(3245, 9103, 14007) },
2062+ { AOM_CDF4(27359, 32465, 32669) },
2063+ { AOM_CDF4(19421, 30614, 32174) },
2064+ { AOM_CDF4(11915, 25010, 29579) },
2065+ { AOM_CDF4(6950, 17676, 24074) },
2066+ { AOM_CDF4(3007, 8473, 13096) },
2067+ { AOM_CDF4(29002, 32676, 32735) },
2068+ { AOM_CDF4(22102, 31849, 32576) },
2069+ { AOM_CDF4(14408, 28009, 31405) },
2070+ { AOM_CDF4(9027, 21679, 27931) },
2071+ { AOM_CDF4(4694, 12678, 18748) },
2072+ { AOM_CDF4(28216, 32528, 32682) },
2073+ { AOM_CDF4(20849, 31264, 32318) },
2074+ { AOM_CDF4(12756, 25815, 29751) },
2075+ { AOM_CDF4(7565, 18801, 24923) },
2076+ { AOM_CDF4(3509, 9533, 14477) },
2077+ { AOM_CDF4(30133, 32687, 32739) },
2078+ { AOM_CDF4(23063, 31910, 32515) },
2079+ { AOM_CDF4(14588, 28051, 31132) },
2080+ { AOM_CDF4(9085, 21649, 27457) },
2081+ { AOM_CDF4(4261, 11654, 17264) },
2082+ { AOM_CDF4(29518, 32691, 32748) },
2083+ { AOM_CDF4(22451, 31959, 32613) },
2084+ { AOM_CDF4(14864, 28722, 31700) },
2085+ { AOM_CDF4(9695, 22964, 28716) },
2086+ { AOM_CDF4(4932, 13358, 19502) } },
2087+ { { AOM_CDF4(6465, 16958, 21688) },
2088+ { AOM_CDF4(25199, 31514, 32360) },
2089+ { AOM_CDF4(14774, 27149, 30607) },
2090+ { AOM_CDF4(9257, 21438, 26972) },
2091+ { AOM_CDF4(5723, 15183, 21882) },
2092+ { AOM_CDF4(3150, 8879, 13731) },
2093+ { AOM_CDF4(26989, 32262, 32682) },
2094+ { AOM_CDF4(17396, 29937, 32085) },
2095+ { AOM_CDF4(11387, 24901, 29784) },
2096+ { AOM_CDF4(7289, 18821, 25548) },
2097+ { AOM_CDF4(3734, 10577, 16086) },
2098+ { AOM_CDF4(29728, 32501, 32695) },
2099+ { AOM_CDF4(17431, 29701, 31903) },
2100+ { AOM_CDF4(9921, 22826, 28300) },
2101+ { AOM_CDF4(5896, 15434, 22068) },
2102+ { AOM_CDF4(3430, 9646, 14757) },
2103+ { AOM_CDF4(28614, 32511, 32705) },
2104+ { AOM_CDF4(19364, 30638, 32263) },
2105+ { AOM_CDF4(13129, 26254, 30402) },
2106+ { AOM_CDF4(8754, 20484, 26440) },
2107+ { AOM_CDF4(4378, 11607, 17110) },
2108+ { AOM_CDF4(30292, 32671, 32744) },
2109+ { AOM_CDF4(21780, 31603, 32501) },
2110+ { AOM_CDF4(14314, 27829, 31291) },
2111+ { AOM_CDF4(9611, 22327, 28263) },
2112+ { AOM_CDF4(4890, 13087, 19065) },
2113+ { AOM_CDF4(25862, 32567, 32733) },
2114+ { AOM_CDF4(20794, 32050, 32567) },
2115+ { AOM_CDF4(17243, 30625, 32254) },
2116+ { AOM_CDF4(13283, 27628, 31474) },
2117+ { AOM_CDF4(9669, 22532, 28918) },
2118+ { AOM_CDF4(27435, 32697, 32748) },
2119+ { AOM_CDF4(24922, 32390, 32714) },
2120+ { AOM_CDF4(21449, 31504, 32536) },
2121+ { AOM_CDF4(16392, 29729, 31832) },
2122+ { AOM_CDF4(11692, 24884, 29076) },
2123+ { AOM_CDF4(24193, 32290, 32735) },
2124+ { AOM_CDF4(18909, 31104, 32563) },
2125+ { AOM_CDF4(12236, 26841, 31403) },
2126+ { AOM_CDF4(8171, 21840, 29082) },
2127+ { AOM_CDF4(7224, 17280, 25275) } } },
2128+ { { { AOM_CDF4(3078, 6839, 9890) },
2129+ { AOM_CDF4(13837, 20450, 24479) },
2130+ { AOM_CDF4(5914, 14222, 19328) },
2131+ { AOM_CDF4(3866, 10267, 14762) },
2132+ { AOM_CDF4(2612, 7208, 11042) },
2133+ { AOM_CDF4(1067, 2991, 4776) },
2134+ { AOM_CDF4(25817, 31646, 32529) },
2135+ { AOM_CDF4(13708, 26338, 30385) },
2136+ { AOM_CDF4(7328, 18585, 24870) },
2137+ { AOM_CDF4(4691, 13080, 19276) },
2138+ { AOM_CDF4(1825, 5253, 8352) },
2139+ { AOM_CDF4(29386, 32315, 32624) },
2140+ { AOM_CDF4(17160, 29001, 31360) },
2141+ { AOM_CDF4(9602, 21862, 27396) },
2142+ { AOM_CDF4(5915, 15772, 22148) },
2143+ { AOM_CDF4(2786, 7779, 12047) },
2144+ { AOM_CDF4(29246, 32450, 32663) },
2145+ { AOM_CDF4(18696, 29929, 31818) },
2146+ { AOM_CDF4(10510, 23369, 28560) },
2147+ { AOM_CDF4(6229, 16499, 23125) },
2148+ { AOM_CDF4(2608, 7448, 11705) },
2149+ { AOM_CDF4(30753, 32710, 32748) },
2150+ { AOM_CDF4(21638, 31487, 32503) },
2151+ { AOM_CDF4(12937, 26854, 30870) },
2152+ { AOM_CDF4(8182, 20596, 26970) },
2153+ { AOM_CDF4(3637, 10269, 15497) },
2154+ { AOM_CDF4(8192, 16384, 24576) },
2155+ { AOM_CDF4(8192, 16384, 24576) },
2156+ { AOM_CDF4(8192, 16384, 24576) },
2157+ { AOM_CDF4(8192, 16384, 24576) },
2158+ { AOM_CDF4(8192, 16384, 24576) },
2159+ { AOM_CDF4(8192, 16384, 24576) },
2160+ { AOM_CDF4(8192, 16384, 24576) },
2161+ { AOM_CDF4(8192, 16384, 24576) },
2162+ { AOM_CDF4(8192, 16384, 24576) },
2163+ { AOM_CDF4(8192, 16384, 24576) },
2164+ { AOM_CDF4(8192, 16384, 24576) },
2165+ { AOM_CDF4(8192, 16384, 24576) },
2166+ { AOM_CDF4(8192, 16384, 24576) },
2167+ { AOM_CDF4(8192, 16384, 24576) },
2168+ { AOM_CDF4(8192, 16384, 24576) } },
2169+ { { AOM_CDF4(5244, 12150, 16906) },
2170+ { AOM_CDF4(20486, 26858, 29701) },
2171+ { AOM_CDF4(7756, 18317, 23735) },
2172+ { AOM_CDF4(3452, 9256, 13146) },
2173+ { AOM_CDF4(2020, 5206, 8229) },
2174+ { AOM_CDF4(1801, 4993, 7903) },
2175+ { AOM_CDF4(27051, 31858, 32531) },
2176+ { AOM_CDF4(15988, 27531, 30619) },
2177+ { AOM_CDF4(9188, 21484, 26719) },
2178+ { AOM_CDF4(6273, 17186, 23800) },
2179+ { AOM_CDF4(3108, 9355, 14764) },
2180+ { AOM_CDF4(31076, 32520, 32680) },
2181+ { AOM_CDF4(18119, 30037, 31850) },
2182+ { AOM_CDF4(10244, 22969, 27472) },
2183+ { AOM_CDF4(4692, 14077, 19273) },
2184+ { AOM_CDF4(3694, 11677, 17556) },
2185+ { AOM_CDF4(30060, 32581, 32720) },
2186+ { AOM_CDF4(21011, 30775, 32120) },
2187+ { AOM_CDF4(11931, 24820, 29289) },
2188+ { AOM_CDF4(7119, 17662, 24356) },
2189+ { AOM_CDF4(3833, 10706, 16304) },
2190+ { AOM_CDF4(31954, 32731, 32748) },
2191+ { AOM_CDF4(23913, 31724, 32489) },
2192+ { AOM_CDF4(15520, 28060, 31286) },
2193+ { AOM_CDF4(11517, 23008, 28571) },
2194+ { AOM_CDF4(6193, 14508, 20629) },
2195+ { AOM_CDF4(8192, 16384, 24576) },
2196+ { AOM_CDF4(8192, 16384, 24576) },
2197+ { AOM_CDF4(8192, 16384, 24576) },
2198+ { AOM_CDF4(8192, 16384, 24576) },
2199+ { AOM_CDF4(8192, 16384, 24576) },
2200+ { AOM_CDF4(8192, 16384, 24576) },
2201+ { AOM_CDF4(8192, 16384, 24576) },
2202+ { AOM_CDF4(8192, 16384, 24576) },
2203+ { AOM_CDF4(8192, 16384, 24576) },
2204+ { AOM_CDF4(8192, 16384, 24576) },
2205+ { AOM_CDF4(8192, 16384, 24576) },
2206+ { AOM_CDF4(8192, 16384, 24576) },
2207+ { AOM_CDF4(8192, 16384, 24576) },
2208+ { AOM_CDF4(8192, 16384, 24576) },
2209+ { AOM_CDF4(8192, 16384, 24576) } } },
2210+ { { { AOM_CDF4(1035, 2807, 4156) },
2211+ { AOM_CDF4(13162, 18138, 20939) },
2212+ { AOM_CDF4(2696, 6633, 8755) },
2213+ { AOM_CDF4(1373, 4161, 6853) },
2214+ { AOM_CDF4(1099, 2746, 4716) },
2215+ { AOM_CDF4(340, 1021, 1599) },
2216+ { AOM_CDF4(22826, 30419, 32135) },
2217+ { AOM_CDF4(10395, 21762, 26942) },
2218+ { AOM_CDF4(4726, 12407, 17361) },
2219+ { AOM_CDF4(2447, 7080, 10593) },
2220+ { AOM_CDF4(1227, 3717, 6011) },
2221+ { AOM_CDF4(28156, 31424, 31934) },
2222+ { AOM_CDF4(16915, 27754, 30373) },
2223+ { AOM_CDF4(9148, 20990, 26431) },
2224+ { AOM_CDF4(5950, 15515, 21148) },
2225+ { AOM_CDF4(2492, 7327, 11526) },
2226+ { AOM_CDF4(30602, 32477, 32670) },
2227+ { AOM_CDF4(20026, 29955, 31568) },
2228+ { AOM_CDF4(11220, 23628, 28105) },
2229+ { AOM_CDF4(6652, 17019, 22973) },
2230+ { AOM_CDF4(3064, 8536, 13043) },
2231+ { AOM_CDF4(31769, 32724, 32748) },
2232+ { AOM_CDF4(22230, 30887, 32373) },
2233+ { AOM_CDF4(12234, 25079, 29731) },
2234+ { AOM_CDF4(7326, 18816, 25353) },
2235+ { AOM_CDF4(3933, 10907, 16616) },
2236+ { AOM_CDF4(8192, 16384, 24576) },
2237+ { AOM_CDF4(8192, 16384, 24576) },
2238+ { AOM_CDF4(8192, 16384, 24576) },
2239+ { AOM_CDF4(8192, 16384, 24576) },
2240+ { AOM_CDF4(8192, 16384, 24576) },
2241+ { AOM_CDF4(8192, 16384, 24576) },
2242+ { AOM_CDF4(8192, 16384, 24576) },
2243+ { AOM_CDF4(8192, 16384, 24576) },
2244+ { AOM_CDF4(8192, 16384, 24576) },
2245+ { AOM_CDF4(8192, 16384, 24576) },
2246+ { AOM_CDF4(8192, 16384, 24576) },
2247+ { AOM_CDF4(8192, 16384, 24576) },
2248+ { AOM_CDF4(8192, 16384, 24576) },
2249+ { AOM_CDF4(8192, 16384, 24576) },
2250+ { AOM_CDF4(8192, 16384, 24576) } },
2251+ { { AOM_CDF4(8192, 16384, 24576) },
2252+ { AOM_CDF4(8192, 16384, 24576) },
2253+ { AOM_CDF4(8192, 16384, 24576) },
2254+ { AOM_CDF4(8192, 16384, 24576) },
2255+ { AOM_CDF4(8192, 16384, 24576) },
2256+ { AOM_CDF4(8192, 16384, 24576) },
2257+ { AOM_CDF4(8192, 16384, 24576) },
2258+ { AOM_CDF4(8192, 16384, 24576) },
2259+ { AOM_CDF4(8192, 16384, 24576) },
2260+ { AOM_CDF4(8192, 16384, 24576) },
2261+ { AOM_CDF4(8192, 16384, 24576) },
2262+ { AOM_CDF4(8192, 16384, 24576) },
2263+ { AOM_CDF4(8192, 16384, 24576) },
2264+ { AOM_CDF4(8192, 16384, 24576) },
2265+ { AOM_CDF4(8192, 16384, 24576) },
2266+ { AOM_CDF4(8192, 16384, 24576) },
2267+ { AOM_CDF4(8192, 16384, 24576) },
2268+ { AOM_CDF4(8192, 16384, 24576) },
2269+ { AOM_CDF4(8192, 16384, 24576) },
2270+ { AOM_CDF4(8192, 16384, 24576) },
2271+ { AOM_CDF4(8192, 16384, 24576) },
2272+ { AOM_CDF4(8192, 16384, 24576) },
2273+ { AOM_CDF4(8192, 16384, 24576) },
2274+ { AOM_CDF4(8192, 16384, 24576) },
2275+ { AOM_CDF4(8192, 16384, 24576) },
2276+ { AOM_CDF4(8192, 16384, 24576) },
2277+ { AOM_CDF4(8192, 16384, 24576) },
2278+ { AOM_CDF4(8192, 16384, 24576) },
2279+ { AOM_CDF4(8192, 16384, 24576) },
2280+ { AOM_CDF4(8192, 16384, 24576) },
2281+ { AOM_CDF4(8192, 16384, 24576) },
2282+ { AOM_CDF4(8192, 16384, 24576) },
2283+ { AOM_CDF4(8192, 16384, 24576) },
2284+ { AOM_CDF4(8192, 16384, 24576) },
2285+ { AOM_CDF4(8192, 16384, 24576) },
2286+ { AOM_CDF4(8192, 16384, 24576) },
2287+ { AOM_CDF4(8192, 16384, 24576) },
2288+ { AOM_CDF4(8192, 16384, 24576) },
2289+ { AOM_CDF4(8192, 16384, 24576) },
2290+ { AOM_CDF4(8192, 16384, 24576) },
2291+ { AOM_CDF4(8192, 16384, 24576) } } }
2292+ }, .dc_sign = {
2293+ {
2294+ { AOM_CDF2(128 * 125) },
2295+ { AOM_CDF2(128 * 102) },
2296+ { AOM_CDF2(128 * 147) },
2297+ },
2298+ {
2299+ { AOM_CDF2(128 * 119) },
2300+ { AOM_CDF2(128 * 101) },
2301+ { AOM_CDF2(128 * 135) },
2302+ }
2303+ }, .br_tok = {
2304+ { { { AOM_CDF4(14995, 21341, 24749) },
2305+ { AOM_CDF4(13158, 20289, 24601) },
2306+ { AOM_CDF4(8941, 15326, 19876) },
2307+ { AOM_CDF4(6297, 11541, 15807) },
2308+ { AOM_CDF4(4817, 9029, 12776) },
2309+ { AOM_CDF4(3731, 7273, 10627) },
2310+ { AOM_CDF4(1847, 3617, 5354) },
2311+ { AOM_CDF4(14472, 19659, 22343) },
2312+ { AOM_CDF4(16806, 24162, 27533) },
2313+ { AOM_CDF4(12900, 20404, 24713) },
2314+ { AOM_CDF4(9411, 16112, 20797) },
2315+ { AOM_CDF4(7056, 12697, 17148) },
2316+ { AOM_CDF4(5544, 10339, 14460) },
2317+ { AOM_CDF4(2954, 5704, 8319) },
2318+ { AOM_CDF4(12464, 18071, 21354) },
2319+ { AOM_CDF4(15482, 22528, 26034) },
2320+ { AOM_CDF4(12070, 19269, 23624) },
2321+ { AOM_CDF4(8953, 15406, 20106) },
2322+ { AOM_CDF4(7027, 12730, 17220) },
2323+ { AOM_CDF4(5887, 10913, 15140) },
2324+ { AOM_CDF4(3793, 7278, 10447) } },
2325+ { { AOM_CDF4(15571, 22232, 25749) },
2326+ { AOM_CDF4(14506, 21575, 25374) },
2327+ { AOM_CDF4(10189, 17089, 21569) },
2328+ { AOM_CDF4(7316, 13301, 17915) },
2329+ { AOM_CDF4(5783, 10912, 15190) },
2330+ { AOM_CDF4(4760, 9155, 13088) },
2331+ { AOM_CDF4(2993, 5966, 8774) },
2332+ { AOM_CDF4(23424, 28903, 30778) },
2333+ { AOM_CDF4(20775, 27666, 30290) },
2334+ { AOM_CDF4(16474, 24410, 28299) },
2335+ { AOM_CDF4(12471, 20180, 24987) },
2336+ { AOM_CDF4(9410, 16487, 21439) },
2337+ { AOM_CDF4(7536, 13614, 18529) },
2338+ { AOM_CDF4(5048, 9586, 13549) },
2339+ { AOM_CDF4(21090, 27290, 29756) },
2340+ { AOM_CDF4(20796, 27402, 30026) },
2341+ { AOM_CDF4(17819, 25485, 28969) },
2342+ { AOM_CDF4(13860, 21909, 26462) },
2343+ { AOM_CDF4(11002, 18494, 23529) },
2344+ { AOM_CDF4(8953, 15929, 20897) },
2345+ { AOM_CDF4(6448, 11918, 16454) } } },
2346+ { { { AOM_CDF4(15999, 22208, 25449) },
2347+ { AOM_CDF4(13050, 19988, 24122) },
2348+ { AOM_CDF4(8594, 14864, 19378) },
2349+ { AOM_CDF4(6033, 11079, 15238) },
2350+ { AOM_CDF4(4554, 8683, 12347) },
2351+ { AOM_CDF4(3672, 7139, 10337) },
2352+ { AOM_CDF4(1900, 3771, 5576) },
2353+ { AOM_CDF4(15788, 21340, 23949) },
2354+ { AOM_CDF4(16825, 24235, 27758) },
2355+ { AOM_CDF4(12873, 20402, 24810) },
2356+ { AOM_CDF4(9590, 16363, 21094) },
2357+ { AOM_CDF4(7352, 13209, 17733) },
2358+ { AOM_CDF4(5960, 10989, 15184) },
2359+ { AOM_CDF4(3232, 6234, 9007) },
2360+ { AOM_CDF4(15761, 20716, 23224) },
2361+ { AOM_CDF4(19318, 25989, 28759) },
2362+ { AOM_CDF4(15529, 23094, 26929) },
2363+ { AOM_CDF4(11662, 18989, 23641) },
2364+ { AOM_CDF4(8955, 15568, 20366) },
2365+ { AOM_CDF4(7281, 13106, 17708) },
2366+ { AOM_CDF4(4248, 8059, 11440) } },
2367+ { { AOM_CDF4(14899, 21217, 24503) },
2368+ { AOM_CDF4(13519, 20283, 24047) },
2369+ { AOM_CDF4(9429, 15966, 20365) },
2370+ { AOM_CDF4(6700, 12355, 16652) },
2371+ { AOM_CDF4(5088, 9704, 13716) },
2372+ { AOM_CDF4(4243, 8154, 11731) },
2373+ { AOM_CDF4(2702, 5364, 7861) },
2374+ { AOM_CDF4(22745, 28388, 30454) },
2375+ { AOM_CDF4(20235, 27146, 29922) },
2376+ { AOM_CDF4(15896, 23715, 27637) },
2377+ { AOM_CDF4(11840, 19350, 24131) },
2378+ { AOM_CDF4(9122, 15932, 20880) },
2379+ { AOM_CDF4(7488, 13581, 18362) },
2380+ { AOM_CDF4(5114, 9568, 13370) },
2381+ { AOM_CDF4(20845, 26553, 28932) },
2382+ { AOM_CDF4(20981, 27372, 29884) },
2383+ { AOM_CDF4(17781, 25335, 28785) },
2384+ { AOM_CDF4(13760, 21708, 26297) },
2385+ { AOM_CDF4(10975, 18415, 23365) },
2386+ { AOM_CDF4(9045, 15789, 20686) },
2387+ { AOM_CDF4(6130, 11199, 15423) } } },
2388+ { { { AOM_CDF4(13549, 19724, 23158) },
2389+ { AOM_CDF4(11844, 18382, 22246) },
2390+ { AOM_CDF4(7919, 13619, 17773) },
2391+ { AOM_CDF4(5486, 10143, 13946) },
2392+ { AOM_CDF4(4166, 7983, 11324) },
2393+ { AOM_CDF4(3364, 6506, 9427) },
2394+ { AOM_CDF4(1598, 3160, 4674) },
2395+ { AOM_CDF4(15281, 20979, 23781) },
2396+ { AOM_CDF4(14939, 22119, 25952) },
2397+ { AOM_CDF4(11363, 18407, 22812) },
2398+ { AOM_CDF4(8609, 14857, 19370) },
2399+ { AOM_CDF4(6737, 12184, 16480) },
2400+ { AOM_CDF4(5506, 10263, 14262) },
2401+ { AOM_CDF4(2990, 5786, 8380) },
2402+ { AOM_CDF4(20249, 25253, 27417) },
2403+ { AOM_CDF4(21070, 27518, 30001) },
2404+ { AOM_CDF4(16854, 24469, 28074) },
2405+ { AOM_CDF4(12864, 20486, 25000) },
2406+ { AOM_CDF4(9962, 16978, 21778) },
2407+ { AOM_CDF4(8074, 14338, 19048) },
2408+ { AOM_CDF4(4494, 8479, 11906) } },
2409+ { { AOM_CDF4(13960, 19617, 22829) },
2410+ { AOM_CDF4(11150, 17341, 21228) },
2411+ { AOM_CDF4(7150, 12964, 17190) },
2412+ { AOM_CDF4(5331, 10002, 13867) },
2413+ { AOM_CDF4(4167, 7744, 11057) },
2414+ { AOM_CDF4(3480, 6629, 9646) },
2415+ { AOM_CDF4(1883, 3784, 5686) },
2416+ { AOM_CDF4(18752, 25660, 28912) },
2417+ { AOM_CDF4(16968, 24586, 28030) },
2418+ { AOM_CDF4(13520, 21055, 25313) },
2419+ { AOM_CDF4(10453, 17626, 22280) },
2420+ { AOM_CDF4(8386, 14505, 19116) },
2421+ { AOM_CDF4(6742, 12595, 17008) },
2422+ { AOM_CDF4(4273, 8140, 11499) },
2423+ { AOM_CDF4(22120, 27827, 30233) },
2424+ { AOM_CDF4(20563, 27358, 29895) },
2425+ { AOM_CDF4(17076, 24644, 28153) },
2426+ { AOM_CDF4(13362, 20942, 25309) },
2427+ { AOM_CDF4(10794, 17965, 22695) },
2428+ { AOM_CDF4(9014, 15652, 20319) },
2429+ { AOM_CDF4(5708, 10512, 14497) } } },
2430+ { { { AOM_CDF4(5705, 10930, 15725) },
2431+ { AOM_CDF4(7946, 12765, 16115) },
2432+ { AOM_CDF4(6801, 12123, 16226) },
2433+ { AOM_CDF4(5462, 10135, 14200) },
2434+ { AOM_CDF4(4189, 8011, 11507) },
2435+ { AOM_CDF4(3191, 6229, 9408) },
2436+ { AOM_CDF4(1057, 2137, 3212) },
2437+ { AOM_CDF4(10018, 17067, 21491) },
2438+ { AOM_CDF4(7380, 12582, 16453) },
2439+ { AOM_CDF4(6068, 10845, 14339) },
2440+ { AOM_CDF4(5098, 9198, 12555) },
2441+ { AOM_CDF4(4312, 8010, 11119) },
2442+ { AOM_CDF4(3700, 6966, 9781) },
2443+ { AOM_CDF4(1693, 3326, 4887) },
2444+ { AOM_CDF4(18757, 24930, 27774) },
2445+ { AOM_CDF4(17648, 24596, 27817) },
2446+ { AOM_CDF4(14707, 22052, 26026) },
2447+ { AOM_CDF4(11720, 18852, 23292) },
2448+ { AOM_CDF4(9357, 15952, 20525) },
2449+ { AOM_CDF4(7810, 13753, 18210) },
2450+ { AOM_CDF4(3879, 7333, 10328) } },
2451+ { { AOM_CDF4(8278, 13242, 15922) },
2452+ { AOM_CDF4(10547, 15867, 18919) },
2453+ { AOM_CDF4(9106, 15842, 20609) },
2454+ { AOM_CDF4(6833, 13007, 17218) },
2455+ { AOM_CDF4(4811, 9712, 13923) },
2456+ { AOM_CDF4(3985, 7352, 11128) },
2457+ { AOM_CDF4(1688, 3458, 5262) },
2458+ { AOM_CDF4(12951, 21861, 26510) },
2459+ { AOM_CDF4(9788, 16044, 20276) },
2460+ { AOM_CDF4(6309, 11244, 14870) },
2461+ { AOM_CDF4(5183, 9349, 12566) },
2462+ { AOM_CDF4(4389, 8229, 11492) },
2463+ { AOM_CDF4(3633, 6945, 10620) },
2464+ { AOM_CDF4(3600, 6847, 9907) },
2465+ { AOM_CDF4(21748, 28137, 30255) },
2466+ { AOM_CDF4(19436, 26581, 29560) },
2467+ { AOM_CDF4(16359, 24201, 27953) },
2468+ { AOM_CDF4(13961, 21693, 25871) },
2469+ { AOM_CDF4(11544, 18686, 23322) },
2470+ { AOM_CDF4(9372, 16462, 20952) },
2471+ { AOM_CDF4(6138, 11210, 15390) } } }
2472+ },
2473+ }, [2] = {
2474+ .skip = {
2475+ { { AOM_CDF2(29614) },
2476+ { AOM_CDF2(9068) },
2477+ { AOM_CDF2(12924) },
2478+ { AOM_CDF2(19538) },
2479+ { AOM_CDF2(17737) },
2480+ { AOM_CDF2(24619) },
2481+ { AOM_CDF2(30642) },
2482+ { AOM_CDF2(4119) },
2483+ { AOM_CDF2(16026) },
2484+ { AOM_CDF2(25657) },
2485+ { AOM_CDF2(16384) },
2486+ { AOM_CDF2(16384) },
2487+ { AOM_CDF2(16384) } },
2488+ { { AOM_CDF2(31957) },
2489+ { AOM_CDF2(3230) },
2490+ { AOM_CDF2(11153) },
2491+ { AOM_CDF2(18123) },
2492+ { AOM_CDF2(20143) },
2493+ { AOM_CDF2(26536) },
2494+ { AOM_CDF2(31986) },
2495+ { AOM_CDF2(3050) },
2496+ { AOM_CDF2(14603) },
2497+ { AOM_CDF2(25155) },
2498+ { AOM_CDF2(16384) },
2499+ { AOM_CDF2(16384) },
2500+ { AOM_CDF2(16384) } },
2501+ { { AOM_CDF2(32363) },
2502+ { AOM_CDF2(10692) },
2503+ { AOM_CDF2(19090) },
2504+ { AOM_CDF2(24357) },
2505+ { AOM_CDF2(24442) },
2506+ { AOM_CDF2(28312) },
2507+ { AOM_CDF2(32169) },
2508+ { AOM_CDF2(3648) },
2509+ { AOM_CDF2(15690) },
2510+ { AOM_CDF2(26815) },
2511+ { AOM_CDF2(16384) },
2512+ { AOM_CDF2(16384) },
2513+ { AOM_CDF2(16384) } },
2514+ { { AOM_CDF2(30669) },
2515+ { AOM_CDF2(3832) },
2516+ { AOM_CDF2(11663) },
2517+ { AOM_CDF2(18889) },
2518+ { AOM_CDF2(19782) },
2519+ { AOM_CDF2(23313) },
2520+ { AOM_CDF2(31330) },
2521+ { AOM_CDF2(5124) },
2522+ { AOM_CDF2(18719) },
2523+ { AOM_CDF2(28468) },
2524+ { AOM_CDF2(3082) },
2525+ { AOM_CDF2(20982) },
2526+ { AOM_CDF2(29443) } },
2527+ { { AOM_CDF2(28573) },
2528+ { AOM_CDF2(3183) },
2529+ { AOM_CDF2(17802) },
2530+ { AOM_CDF2(25977) },
2531+ { AOM_CDF2(26677) },
2532+ { AOM_CDF2(27832) },
2533+ { AOM_CDF2(32387) },
2534+ { AOM_CDF2(16384) },
2535+ { AOM_CDF2(16384) },
2536+ { AOM_CDF2(16384) },
2537+ { AOM_CDF2(16384) },
2538+ { AOM_CDF2(16384) },
2539+ { AOM_CDF2(16384) } }
2540+ }, .eob_bin_16 = {
2541+ { { AOM_CDF5(4016, 4897, 8881, 14968) },
2542+ { AOM_CDF5(716, 1105, 2646, 10056) } },
2543+ { { AOM_CDF5(11139, 13270, 18241, 23566) },
2544+ { AOM_CDF5(3192, 5032, 10297, 19755) } }
2545+ }, .eob_bin_32 = {
2546+ { { AOM_CDF6(2515, 3003, 4452, 8162, 16041) },
2547+ { AOM_CDF6(574, 821, 1836, 5089, 13128) } },
2548+ { { AOM_CDF6(13468, 16303, 20361, 25105, 29281) },
2549+ { AOM_CDF6(3542, 5502, 10415, 16760, 25644) } }
2550+ }, .eob_bin_64 = {
2551+ { { AOM_CDF7(2374, 2772, 4583, 7276, 12288, 19706) },
2552+ { AOM_CDF7(497, 810, 1315, 3000, 7004, 15641) } },
2553+ { { AOM_CDF7(15050, 17126, 21410, 24886, 28156, 30726) },
2554+ { AOM_CDF7(4034, 6290, 10235, 14982, 21214, 28491) } }
2555+ }, .eob_bin_128 = {
2556+ { { AOM_CDF8(1366, 1738, 2527, 5016, 9355, 15797, 24643) },
2557+ { AOM_CDF8(354, 558, 944, 2760, 7287, 14037, 21779) } },
2558+ { { AOM_CDF8(13627, 16246, 20173, 24429, 27948, 30415, 31863) },
2559+ { AOM_CDF8(6275, 9889, 14769, 23164, 27988, 30493, 32272) } }
2560+ }, .eob_bin_256 = {
2561+ { { AOM_CDF9(3089, 3920, 6038, 9460, 14266, 19881, 25766, 29176) },
2562+ { AOM_CDF9(1084, 2358, 3488, 5122, 11483, 18103, 26023, 29799) } },
2563+ { { AOM_CDF9(11514, 13794, 17480, 20754, 24361, 27378, 29492, 31277) },
2564+ { AOM_CDF9(6571, 9610, 15516, 21826, 29092, 30829, 31842, 32708) } }
2565+ }, .eob_bin_512 = {
2566+ { { AOM_CDF10(2624, 3936, 6480, 9686, 13979, 17726, 23267,
2567+ 28410, 31078) },
2568+ { AOM_CDF10(3277, 6554, 9830, 13107, 16384, 19661, 22938,
2569+ 26214, 29491) } },
2570+ { { AOM_CDF10(12015, 14769, 19588, 22052, 24222, 25812,
2571+ 27300, 29219, 32114) },
2572+ { AOM_CDF10(3277, 6554, 9830, 13107, 16384, 19661, 22938,
2573+ 26214, 29491) } }
2574+ }, .eob_bin_1024 = {
2575+ { { AOM_CDF11(2784, 3831, 7041, 10521, 14847, 18844, 23155,
2576+ 26682, 29229, 31045) },
2577+ { AOM_CDF11(2979, 5958, 8937, 11916, 14895, 17873, 20852,
2578+ 23831, 26810, 29789) } },
2579+ { { AOM_CDF11(9577, 12466, 17739, 20750, 22061, 23215, 24601,
2580+ 25483, 25843, 32056) },
2581+ { AOM_CDF11(2979, 5958, 8937, 11916, 14895, 17873, 20852,
2582+ 23831, 26810, 29789) } }
2583+ }, .eob_hi_bit = {
2584+ { { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
2585+ { AOM_CDF2(18983) }, { AOM_CDF2(20512) }, { AOM_CDF2(14885) },
2586+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
2587+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) } },
2588+ { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
2589+ { AOM_CDF2(20090) }, { AOM_CDF2(19444) }, { AOM_CDF2(17286) },
2590+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
2591+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) } } },
2592+ { { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
2593+ { AOM_CDF2(19139) }, { AOM_CDF2(21487) }, { AOM_CDF2(18959) },
2594+ { AOM_CDF2(20910) }, { AOM_CDF2(19089) }, { AOM_CDF2(16384) },
2595+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) } },
2596+ { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
2597+ { AOM_CDF2(20536) }, { AOM_CDF2(20664) }, { AOM_CDF2(20625) },
2598+ { AOM_CDF2(19123) }, { AOM_CDF2(14862) }, { AOM_CDF2(16384) },
2599+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) } } },
2600+ { { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
2601+ { AOM_CDF2(19833) }, { AOM_CDF2(21502) }, { AOM_CDF2(17485) },
2602+ { AOM_CDF2(20267) }, { AOM_CDF2(18353) }, { AOM_CDF2(23329) },
2603+ { AOM_CDF2(21478) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) } },
2604+ { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
2605+ { AOM_CDF2(22041) }, { AOM_CDF2(23434) }, { AOM_CDF2(20001) },
2606+ { AOM_CDF2(20554) }, { AOM_CDF2(20951) }, { AOM_CDF2(20145) },
2607+ { AOM_CDF2(15562) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) } } },
2608+ { { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
2609+ { AOM_CDF2(23312) }, { AOM_CDF2(21607) }, { AOM_CDF2(16526) },
2610+ { AOM_CDF2(18957) }, { AOM_CDF2(18034) }, { AOM_CDF2(18934) },
2611+ { AOM_CDF2(24247) }, { AOM_CDF2(16921) }, { AOM_CDF2(17080) } },
2612+ { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
2613+ { AOM_CDF2(26579) }, { AOM_CDF2(24910) }, { AOM_CDF2(18637) },
2614+ { AOM_CDF2(19800) }, { AOM_CDF2(20388) }, { AOM_CDF2(9887) },
2615+ { AOM_CDF2(15642) }, { AOM_CDF2(30198) }, { AOM_CDF2(24721) } } },
2616+ { { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
2617+ { AOM_CDF2(26998) }, { AOM_CDF2(16737) }, { AOM_CDF2(17838) },
2618+ { AOM_CDF2(18922) }, { AOM_CDF2(19515) }, { AOM_CDF2(18636) },
2619+ { AOM_CDF2(17333) }, { AOM_CDF2(15776) }, { AOM_CDF2(22658) } },
2620+ { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
2621+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
2622+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
2623+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) } } }
2624+ }, .eob_base_tok = {
2625+ { { { AOM_CDF3(20092, 30774) },
2626+ { AOM_CDF3(30695, 32020) },
2627+ { AOM_CDF3(31131, 32103) },
2628+ { AOM_CDF3(28666, 30870) } },
2629+ { { AOM_CDF3(27258, 31095) },
2630+ { AOM_CDF3(31804, 32623) },
2631+ { AOM_CDF3(31763, 32528) },
2632+ { AOM_CDF3(31438, 32506) } } },
2633+ { { { AOM_CDF3(18049, 30489) },
2634+ { AOM_CDF3(31706, 32286) },
2635+ { AOM_CDF3(32163, 32473) },
2636+ { AOM_CDF3(31550, 32184) } },
2637+ { { AOM_CDF3(27116, 30842) },
2638+ { AOM_CDF3(31971, 32598) },
2639+ { AOM_CDF3(32088, 32576) },
2640+ { AOM_CDF3(32067, 32664) } } },
2641+ { { { AOM_CDF3(12854, 29093) },
2642+ { AOM_CDF3(32272, 32558) },
2643+ { AOM_CDF3(32667, 32729) },
2644+ { AOM_CDF3(32306, 32585) } },
2645+ { { AOM_CDF3(25476, 30366) },
2646+ { AOM_CDF3(32169, 32687) },
2647+ { AOM_CDF3(32479, 32689) },
2648+ { AOM_CDF3(31673, 32634) } } },
2649+ { { { AOM_CDF3(2809, 19301) },
2650+ { AOM_CDF3(32205, 32622) },
2651+ { AOM_CDF3(32338, 32730) },
2652+ { AOM_CDF3(31786, 32616) } },
2653+ { { AOM_CDF3(22737, 29105) },
2654+ { AOM_CDF3(30810, 32362) },
2655+ { AOM_CDF3(30014, 32627) },
2656+ { AOM_CDF3(30528, 32574) } } },
2657+ { { { AOM_CDF3(935, 3382) },
2658+ { AOM_CDF3(30789, 31909) },
2659+ { AOM_CDF3(32466, 32756) },
2660+ { AOM_CDF3(30860, 32513) } },
2661+ { { AOM_CDF3(10923, 21845) },
2662+ { AOM_CDF3(10923, 21845) },
2663+ { AOM_CDF3(10923, 21845) },
2664+ { AOM_CDF3(10923, 21845) } } }
2665+ }, .base_tok = {
2666+ { { { AOM_CDF4(8896, 16227, 20630) },
2667+ { AOM_CDF4(23629, 31782, 32527) },
2668+ { AOM_CDF4(15173, 27755, 31321) },
2669+ { AOM_CDF4(10158, 21233, 27382) },
2670+ { AOM_CDF4(6420, 14857, 21558) },
2671+ { AOM_CDF4(3269, 8155, 12646) },
2672+ { AOM_CDF4(24835, 32009, 32496) },
2673+ { AOM_CDF4(16509, 28421, 31579) },
2674+ { AOM_CDF4(10957, 21514, 27418) },
2675+ { AOM_CDF4(7881, 15930, 22096) },
2676+ { AOM_CDF4(5388, 10960, 15918) },
2677+ { AOM_CDF4(8192, 16384, 24576) },
2678+ { AOM_CDF4(8192, 16384, 24576) },
2679+ { AOM_CDF4(8192, 16384, 24576) },
2680+ { AOM_CDF4(8192, 16384, 24576) },
2681+ { AOM_CDF4(8192, 16384, 24576) },
2682+ { AOM_CDF4(8192, 16384, 24576) },
2683+ { AOM_CDF4(8192, 16384, 24576) },
2684+ { AOM_CDF4(8192, 16384, 24576) },
2685+ { AOM_CDF4(8192, 16384, 24576) },
2686+ { AOM_CDF4(8192, 16384, 24576) },
2687+ { AOM_CDF4(20745, 30773, 32093) },
2688+ { AOM_CDF4(15200, 27221, 30861) },
2689+ { AOM_CDF4(13032, 20873, 25667) },
2690+ { AOM_CDF4(12285, 18663, 23494) },
2691+ { AOM_CDF4(11563, 17481, 21489) },
2692+ { AOM_CDF4(26260, 31982, 32320) },
2693+ { AOM_CDF4(15397, 28083, 31100) },
2694+ { AOM_CDF4(9742, 19217, 24824) },
2695+ { AOM_CDF4(3261, 9629, 15362) },
2696+ { AOM_CDF4(1480, 4322, 7499) },
2697+ { AOM_CDF4(27599, 32256, 32460) },
2698+ { AOM_CDF4(16857, 27659, 30774) },
2699+ { AOM_CDF4(9551, 18290, 23748) },
2700+ { AOM_CDF4(3052, 8933, 14103) },
2701+ { AOM_CDF4(2021, 5910, 9787) },
2702+ { AOM_CDF4(29005, 32015, 32392) },
2703+ { AOM_CDF4(17677, 27694, 30863) },
2704+ { AOM_CDF4(9204, 17356, 23219) },
2705+ { AOM_CDF4(2403, 7516, 12814) },
2706+ { AOM_CDF4(8192, 16384, 24576) } },
2707+ { { AOM_CDF4(10808, 22056, 26896) },
2708+ { AOM_CDF4(25739, 32313, 32676) },
2709+ { AOM_CDF4(17288, 30203, 32221) },
2710+ { AOM_CDF4(11359, 24878, 29896) },
2711+ { AOM_CDF4(6949, 17767, 24893) },
2712+ { AOM_CDF4(4287, 11796, 18071) },
2713+ { AOM_CDF4(27880, 32521, 32705) },
2714+ { AOM_CDF4(19038, 31004, 32414) },
2715+ { AOM_CDF4(12564, 26345, 30768) },
2716+ { AOM_CDF4(8269, 19947, 26779) },
2717+ { AOM_CDF4(5674, 14657, 21674) },
2718+ { AOM_CDF4(8192, 16384, 24576) },
2719+ { AOM_CDF4(8192, 16384, 24576) },
2720+ { AOM_CDF4(8192, 16384, 24576) },
2721+ { AOM_CDF4(8192, 16384, 24576) },
2722+ { AOM_CDF4(8192, 16384, 24576) },
2723+ { AOM_CDF4(8192, 16384, 24576) },
2724+ { AOM_CDF4(8192, 16384, 24576) },
2725+ { AOM_CDF4(8192, 16384, 24576) },
2726+ { AOM_CDF4(8192, 16384, 24576) },
2727+ { AOM_CDF4(8192, 16384, 24576) },
2728+ { AOM_CDF4(25742, 32319, 32671) },
2729+ { AOM_CDF4(19557, 31164, 32454) },
2730+ { AOM_CDF4(13381, 26381, 30755) },
2731+ { AOM_CDF4(10101, 21466, 26722) },
2732+ { AOM_CDF4(9209, 19650, 26825) },
2733+ { AOM_CDF4(27107, 31917, 32432) },
2734+ { AOM_CDF4(18056, 28893, 31203) },
2735+ { AOM_CDF4(10200, 21434, 26764) },
2736+ { AOM_CDF4(4660, 12913, 19502) },
2737+ { AOM_CDF4(2368, 6930, 12504) },
2738+ { AOM_CDF4(26960, 32158, 32613) },
2739+ { AOM_CDF4(18628, 30005, 32031) },
2740+ { AOM_CDF4(10233, 22442, 28232) },
2741+ { AOM_CDF4(5471, 14630, 21516) },
2742+ { AOM_CDF4(3235, 10767, 17109) },
2743+ { AOM_CDF4(27696, 32440, 32692) },
2744+ { AOM_CDF4(20032, 31167, 32438) },
2745+ { AOM_CDF4(8700, 21341, 28442) },
2746+ { AOM_CDF4(5662, 14831, 21795) },
2747+ { AOM_CDF4(8192, 16384, 24576) } } },
2748+ { { { AOM_CDF4(9704, 17294, 21132) },
2749+ { AOM_CDF4(26762, 32278, 32633) },
2750+ { AOM_CDF4(18382, 29620, 31819) },
2751+ { AOM_CDF4(10891, 23475, 28723) },
2752+ { AOM_CDF4(6358, 16583, 23309) },
2753+ { AOM_CDF4(3248, 9118, 14141) },
2754+ { AOM_CDF4(27204, 32573, 32699) },
2755+ { AOM_CDF4(19818, 30824, 32329) },
2756+ { AOM_CDF4(11772, 25120, 30041) },
2757+ { AOM_CDF4(6995, 18033, 25039) },
2758+ { AOM_CDF4(3752, 10442, 16098) },
2759+ { AOM_CDF4(27222, 32256, 32559) },
2760+ { AOM_CDF4(15356, 28399, 31475) },
2761+ { AOM_CDF4(8821, 20635, 27057) },
2762+ { AOM_CDF4(5511, 14404, 21239) },
2763+ { AOM_CDF4(2935, 8222, 13051) },
2764+ { AOM_CDF4(24875, 32120, 32529) },
2765+ { AOM_CDF4(15233, 28265, 31445) },
2766+ { AOM_CDF4(8605, 20570, 26932) },
2767+ { AOM_CDF4(5431, 14413, 21196) },
2768+ { AOM_CDF4(2994, 8341, 13223) },
2769+ { AOM_CDF4(28201, 32604, 32700) },
2770+ { AOM_CDF4(21041, 31446, 32456) },
2771+ { AOM_CDF4(13221, 26213, 30475) },
2772+ { AOM_CDF4(8255, 19385, 26037) },
2773+ { AOM_CDF4(4930, 12585, 18830) },
2774+ { AOM_CDF4(28768, 32448, 32627) },
2775+ { AOM_CDF4(19705, 30561, 32021) },
2776+ { AOM_CDF4(11572, 23589, 28220) },
2777+ { AOM_CDF4(5532, 15034, 21446) },
2778+ { AOM_CDF4(2460, 7150, 11456) },
2779+ { AOM_CDF4(29874, 32619, 32699) },
2780+ { AOM_CDF4(21621, 31071, 32201) },
2781+ { AOM_CDF4(12511, 24747, 28992) },
2782+ { AOM_CDF4(6281, 16395, 22748) },
2783+ { AOM_CDF4(3246, 9278, 14497) },
2784+ { AOM_CDF4(29715, 32625, 32712) },
2785+ { AOM_CDF4(20958, 31011, 32283) },
2786+ { AOM_CDF4(11233, 23671, 28806) },
2787+ { AOM_CDF4(6012, 16128, 22868) },
2788+ { AOM_CDF4(3427, 9851, 15414) } },
2789+ { { AOM_CDF4(11016, 22111, 26794) },
2790+ { AOM_CDF4(25946, 32357, 32677) },
2791+ { AOM_CDF4(17890, 30452, 32252) },
2792+ { AOM_CDF4(11678, 25142, 29816) },
2793+ { AOM_CDF4(6720, 17534, 24584) },
2794+ { AOM_CDF4(4230, 11665, 17820) },
2795+ { AOM_CDF4(28400, 32623, 32747) },
2796+ { AOM_CDF4(21164, 31668, 32575) },
2797+ { AOM_CDF4(13572, 27388, 31182) },
2798+ { AOM_CDF4(8234, 20750, 27358) },
2799+ { AOM_CDF4(5065, 14055, 20897) },
2800+ { AOM_CDF4(28981, 32547, 32705) },
2801+ { AOM_CDF4(18681, 30543, 32239) },
2802+ { AOM_CDF4(10919, 24075, 29286) },
2803+ { AOM_CDF4(6431, 17199, 24077) },
2804+ { AOM_CDF4(3819, 10464, 16618) },
2805+ { AOM_CDF4(26870, 32467, 32693) },
2806+ { AOM_CDF4(19041, 30831, 32347) },
2807+ { AOM_CDF4(11794, 25211, 30016) },
2808+ { AOM_CDF4(6888, 18019, 24970) },
2809+ { AOM_CDF4(4370, 12363, 18992) },
2810+ { AOM_CDF4(29578, 32670, 32744) },
2811+ { AOM_CDF4(23159, 32007, 32613) },
2812+ { AOM_CDF4(15315, 28669, 31676) },
2813+ { AOM_CDF4(9298, 22607, 28782) },
2814+ { AOM_CDF4(6144, 15913, 22968) },
2815+ { AOM_CDF4(28110, 32499, 32669) },
2816+ { AOM_CDF4(21574, 30937, 32015) },
2817+ { AOM_CDF4(12759, 24818, 28727) },
2818+ { AOM_CDF4(6545, 16761, 23042) },
2819+ { AOM_CDF4(3649, 10597, 16833) },
2820+ { AOM_CDF4(28163, 32552, 32728) },
2821+ { AOM_CDF4(22101, 31469, 32464) },
2822+ { AOM_CDF4(13160, 25472, 30143) },
2823+ { AOM_CDF4(7303, 18684, 25468) },
2824+ { AOM_CDF4(5241, 13975, 20955) },
2825+ { AOM_CDF4(28400, 32631, 32744) },
2826+ { AOM_CDF4(22104, 31793, 32603) },
2827+ { AOM_CDF4(13557, 26571, 30846) },
2828+ { AOM_CDF4(7749, 19861, 26675) },
2829+ { AOM_CDF4(4873, 14030, 21234) } } },
2830+ { { { AOM_CDF4(9800, 17635, 21073) },
2831+ { AOM_CDF4(26153, 31885, 32527) },
2832+ { AOM_CDF4(15038, 27852, 31006) },
2833+ { AOM_CDF4(8718, 20564, 26486) },
2834+ { AOM_CDF4(5128, 14076, 20514) },
2835+ { AOM_CDF4(2636, 7566, 11925) },
2836+ { AOM_CDF4(27551, 32504, 32701) },
2837+ { AOM_CDF4(18310, 30054, 32100) },
2838+ { AOM_CDF4(10211, 23420, 29082) },
2839+ { AOM_CDF4(6222, 16876, 23916) },
2840+ { AOM_CDF4(3462, 9954, 15498) },
2841+ { AOM_CDF4(29991, 32633, 32721) },
2842+ { AOM_CDF4(19883, 30751, 32201) },
2843+ { AOM_CDF4(11141, 24184, 29285) },
2844+ { AOM_CDF4(6420, 16940, 23774) },
2845+ { AOM_CDF4(3392, 9753, 15118) },
2846+ { AOM_CDF4(28465, 32616, 32712) },
2847+ { AOM_CDF4(19850, 30702, 32244) },
2848+ { AOM_CDF4(10983, 24024, 29223) },
2849+ { AOM_CDF4(6294, 16770, 23582) },
2850+ { AOM_CDF4(3244, 9283, 14509) },
2851+ { AOM_CDF4(30023, 32717, 32748) },
2852+ { AOM_CDF4(22940, 32032, 32626) },
2853+ { AOM_CDF4(14282, 27928, 31473) },
2854+ { AOM_CDF4(8562, 21327, 27914) },
2855+ { AOM_CDF4(4846, 13393, 19919) },
2856+ { AOM_CDF4(29981, 32590, 32695) },
2857+ { AOM_CDF4(20465, 30963, 32166) },
2858+ { AOM_CDF4(11479, 23579, 28195) },
2859+ { AOM_CDF4(5916, 15648, 22073) },
2860+ { AOM_CDF4(3031, 8605, 13398) },
2861+ { AOM_CDF4(31146, 32691, 32739) },
2862+ { AOM_CDF4(23106, 31724, 32444) },
2863+ { AOM_CDF4(13783, 26738, 30439) },
2864+ { AOM_CDF4(7852, 19468, 25807) },
2865+ { AOM_CDF4(3860, 11124, 16853) },
2866+ { AOM_CDF4(31014, 32724, 32748) },
2867+ { AOM_CDF4(23629, 32109, 32628) },
2868+ { AOM_CDF4(14747, 28115, 31403) },
2869+ { AOM_CDF4(8545, 21242, 27478) },
2870+ { AOM_CDF4(4574, 12781, 19067) } },
2871+ { { AOM_CDF4(9185, 19694, 24688) },
2872+ { AOM_CDF4(26081, 31985, 32621) },
2873+ { AOM_CDF4(16015, 29000, 31787) },
2874+ { AOM_CDF4(10542, 23690, 29206) },
2875+ { AOM_CDF4(6732, 17945, 24677) },
2876+ { AOM_CDF4(3916, 11039, 16722) },
2877+ { AOM_CDF4(28224, 32566, 32744) },
2878+ { AOM_CDF4(19100, 31138, 32485) },
2879+ { AOM_CDF4(12528, 26620, 30879) },
2880+ { AOM_CDF4(7741, 20277, 26885) },
2881+ { AOM_CDF4(4566, 12845, 18990) },
2882+ { AOM_CDF4(29933, 32593, 32718) },
2883+ { AOM_CDF4(17670, 30333, 32155) },
2884+ { AOM_CDF4(10385, 23600, 28909) },
2885+ { AOM_CDF4(6243, 16236, 22407) },
2886+ { AOM_CDF4(3976, 10389, 16017) },
2887+ { AOM_CDF4(28377, 32561, 32738) },
2888+ { AOM_CDF4(19366, 31175, 32482) },
2889+ { AOM_CDF4(13327, 27175, 31094) },
2890+ { AOM_CDF4(8258, 20769, 27143) },
2891+ { AOM_CDF4(4703, 13198, 19527) },
2892+ { AOM_CDF4(31086, 32706, 32748) },
2893+ { AOM_CDF4(22853, 31902, 32583) },
2894+ { AOM_CDF4(14759, 28186, 31419) },
2895+ { AOM_CDF4(9284, 22382, 28348) },
2896+ { AOM_CDF4(5585, 15192, 21868) },
2897+ { AOM_CDF4(28291, 32652, 32746) },
2898+ { AOM_CDF4(19849, 32107, 32571) },
2899+ { AOM_CDF4(14834, 26818, 29214) },
2900+ { AOM_CDF4(10306, 22594, 28672) },
2901+ { AOM_CDF4(6615, 17384, 23384) },
2902+ { AOM_CDF4(28947, 32604, 32745) },
2903+ { AOM_CDF4(25625, 32289, 32646) },
2904+ { AOM_CDF4(18758, 28672, 31403) },
2905+ { AOM_CDF4(10017, 23430, 28523) },
2906+ { AOM_CDF4(6862, 15269, 22131) },
2907+ { AOM_CDF4(23933, 32509, 32739) },
2908+ { AOM_CDF4(19927, 31495, 32631) },
2909+ { AOM_CDF4(11903, 26023, 30621) },
2910+ { AOM_CDF4(7026, 20094, 27252) },
2911+ { AOM_CDF4(5998, 18106, 24437) } } },
2912+ { { { AOM_CDF4(4456, 11274, 15533) },
2913+ { AOM_CDF4(21219, 29079, 31616) },
2914+ { AOM_CDF4(11173, 23774, 28567) },
2915+ { AOM_CDF4(7282, 18293, 24263) },
2916+ { AOM_CDF4(4890, 13286, 19115) },
2917+ { AOM_CDF4(1890, 5508, 8659) },
2918+ { AOM_CDF4(26651, 32136, 32647) },
2919+ { AOM_CDF4(14630, 28254, 31455) },
2920+ { AOM_CDF4(8716, 21287, 27395) },
2921+ { AOM_CDF4(5615, 15331, 22008) },
2922+ { AOM_CDF4(2675, 7700, 12150) },
2923+ { AOM_CDF4(29954, 32526, 32690) },
2924+ { AOM_CDF4(16126, 28982, 31633) },
2925+ { AOM_CDF4(9030, 21361, 27352) },
2926+ { AOM_CDF4(5411, 14793, 21271) },
2927+ { AOM_CDF4(2943, 8422, 13163) },
2928+ { AOM_CDF4(29539, 32601, 32730) },
2929+ { AOM_CDF4(18125, 30385, 32201) },
2930+ { AOM_CDF4(10422, 24090, 29468) },
2931+ { AOM_CDF4(6468, 17487, 24438) },
2932+ { AOM_CDF4(2970, 8653, 13531) },
2933+ { AOM_CDF4(30912, 32715, 32748) },
2934+ { AOM_CDF4(20666, 31373, 32497) },
2935+ { AOM_CDF4(12509, 26640, 30917) },
2936+ { AOM_CDF4(8058, 20629, 27290) },
2937+ { AOM_CDF4(4231, 12006, 18052) },
2938+ { AOM_CDF4(8192, 16384, 24576) },
2939+ { AOM_CDF4(8192, 16384, 24576) },
2940+ { AOM_CDF4(8192, 16384, 24576) },
2941+ { AOM_CDF4(8192, 16384, 24576) },
2942+ { AOM_CDF4(8192, 16384, 24576) },
2943+ { AOM_CDF4(8192, 16384, 24576) },
2944+ { AOM_CDF4(8192, 16384, 24576) },
2945+ { AOM_CDF4(8192, 16384, 24576) },
2946+ { AOM_CDF4(8192, 16384, 24576) },
2947+ { AOM_CDF4(8192, 16384, 24576) },
2948+ { AOM_CDF4(8192, 16384, 24576) },
2949+ { AOM_CDF4(8192, 16384, 24576) },
2950+ { AOM_CDF4(8192, 16384, 24576) },
2951+ { AOM_CDF4(8192, 16384, 24576) },
2952+ { AOM_CDF4(8192, 16384, 24576) } },
2953+ { { AOM_CDF4(10202, 20633, 25484) },
2954+ { AOM_CDF4(27336, 31445, 32352) },
2955+ { AOM_CDF4(12420, 24384, 28552) },
2956+ { AOM_CDF4(7648, 18115, 23856) },
2957+ { AOM_CDF4(5662, 14341, 19902) },
2958+ { AOM_CDF4(3611, 10328, 15390) },
2959+ { AOM_CDF4(30945, 32616, 32736) },
2960+ { AOM_CDF4(18682, 30505, 32253) },
2961+ { AOM_CDF4(11513, 25336, 30203) },
2962+ { AOM_CDF4(7449, 19452, 26148) },
2963+ { AOM_CDF4(4482, 13051, 18886) },
2964+ { AOM_CDF4(32022, 32690, 32747) },
2965+ { AOM_CDF4(18578, 30501, 32146) },
2966+ { AOM_CDF4(11249, 23368, 28631) },
2967+ { AOM_CDF4(5645, 16958, 22158) },
2968+ { AOM_CDF4(5009, 11444, 16637) },
2969+ { AOM_CDF4(31357, 32710, 32748) },
2970+ { AOM_CDF4(21552, 31494, 32504) },
2971+ { AOM_CDF4(13891, 27677, 31340) },
2972+ { AOM_CDF4(9051, 22098, 28172) },
2973+ { AOM_CDF4(5190, 13377, 19486) },
2974+ { AOM_CDF4(32364, 32740, 32748) },
2975+ { AOM_CDF4(24839, 31907, 32551) },
2976+ { AOM_CDF4(17160, 28779, 31696) },
2977+ { AOM_CDF4(12452, 24137, 29602) },
2978+ { AOM_CDF4(6165, 15389, 22477) },
2979+ { AOM_CDF4(8192, 16384, 24576) },
2980+ { AOM_CDF4(8192, 16384, 24576) },
2981+ { AOM_CDF4(8192, 16384, 24576) },
2982+ { AOM_CDF4(8192, 16384, 24576) },
2983+ { AOM_CDF4(8192, 16384, 24576) },
2984+ { AOM_CDF4(8192, 16384, 24576) },
2985+ { AOM_CDF4(8192, 16384, 24576) },
2986+ { AOM_CDF4(8192, 16384, 24576) },
2987+ { AOM_CDF4(8192, 16384, 24576) },
2988+ { AOM_CDF4(8192, 16384, 24576) },
2989+ { AOM_CDF4(8192, 16384, 24576) },
2990+ { AOM_CDF4(8192, 16384, 24576) },
2991+ { AOM_CDF4(8192, 16384, 24576) },
2992+ { AOM_CDF4(8192, 16384, 24576) },
2993+ { AOM_CDF4(8192, 16384, 24576) } } },
2994+ { { { AOM_CDF4(2575, 7281, 11077) },
2995+ { AOM_CDF4(14002, 20866, 25402) },
2996+ { AOM_CDF4(6343, 15056, 19658) },
2997+ { AOM_CDF4(4474, 11858, 17041) },
2998+ { AOM_CDF4(2865, 8299, 12534) },
2999+ { AOM_CDF4(1344, 3949, 6391) },
3000+ { AOM_CDF4(24720, 31239, 32459) },
3001+ { AOM_CDF4(12585, 25356, 29968) },
3002+ { AOM_CDF4(7181, 18246, 24444) },
3003+ { AOM_CDF4(5025, 13667, 19885) },
3004+ { AOM_CDF4(2521, 7304, 11605) },
3005+ { AOM_CDF4(29908, 32252, 32584) },
3006+ { AOM_CDF4(17421, 29156, 31575) },
3007+ { AOM_CDF4(9889, 22188, 27782) },
3008+ { AOM_CDF4(5878, 15647, 22123) },
3009+ { AOM_CDF4(2814, 8665, 13323) },
3010+ { AOM_CDF4(30183, 32568, 32713) },
3011+ { AOM_CDF4(18528, 30195, 32049) },
3012+ { AOM_CDF4(10982, 24606, 29657) },
3013+ { AOM_CDF4(6957, 18165, 25231) },
3014+ { AOM_CDF4(3508, 10118, 15468) },
3015+ { AOM_CDF4(31761, 32736, 32748) },
3016+ { AOM_CDF4(21041, 31328, 32546) },
3017+ { AOM_CDF4(12568, 26732, 31166) },
3018+ { AOM_CDF4(8052, 20720, 27733) },
3019+ { AOM_CDF4(4336, 12192, 18396) },
3020+ { AOM_CDF4(8192, 16384, 24576) },
3021+ { AOM_CDF4(8192, 16384, 24576) },
3022+ { AOM_CDF4(8192, 16384, 24576) },
3023+ { AOM_CDF4(8192, 16384, 24576) },
3024+ { AOM_CDF4(8192, 16384, 24576) },
3025+ { AOM_CDF4(8192, 16384, 24576) },
3026+ { AOM_CDF4(8192, 16384, 24576) },
3027+ { AOM_CDF4(8192, 16384, 24576) },
3028+ { AOM_CDF4(8192, 16384, 24576) },
3029+ { AOM_CDF4(8192, 16384, 24576) },
3030+ { AOM_CDF4(8192, 16384, 24576) },
3031+ { AOM_CDF4(8192, 16384, 24576) },
3032+ { AOM_CDF4(8192, 16384, 24576) },
3033+ { AOM_CDF4(8192, 16384, 24576) },
3034+ { AOM_CDF4(8192, 16384, 24576) } },
3035+ { { AOM_CDF4(8192, 16384, 24576) },
3036+ { AOM_CDF4(8192, 16384, 24576) },
3037+ { AOM_CDF4(8192, 16384, 24576) },
3038+ { AOM_CDF4(8192, 16384, 24576) },
3039+ { AOM_CDF4(8192, 16384, 24576) },
3040+ { AOM_CDF4(8192, 16384, 24576) },
3041+ { AOM_CDF4(8192, 16384, 24576) },
3042+ { AOM_CDF4(8192, 16384, 24576) },
3043+ { AOM_CDF4(8192, 16384, 24576) },
3044+ { AOM_CDF4(8192, 16384, 24576) },
3045+ { AOM_CDF4(8192, 16384, 24576) },
3046+ { AOM_CDF4(8192, 16384, 24576) },
3047+ { AOM_CDF4(8192, 16384, 24576) },
3048+ { AOM_CDF4(8192, 16384, 24576) },
3049+ { AOM_CDF4(8192, 16384, 24576) },
3050+ { AOM_CDF4(8192, 16384, 24576) },
3051+ { AOM_CDF4(8192, 16384, 24576) },
3052+ { AOM_CDF4(8192, 16384, 24576) },
3053+ { AOM_CDF4(8192, 16384, 24576) },
3054+ { AOM_CDF4(8192, 16384, 24576) },
3055+ { AOM_CDF4(8192, 16384, 24576) },
3056+ { AOM_CDF4(8192, 16384, 24576) },
3057+ { AOM_CDF4(8192, 16384, 24576) },
3058+ { AOM_CDF4(8192, 16384, 24576) },
3059+ { AOM_CDF4(8192, 16384, 24576) },
3060+ { AOM_CDF4(8192, 16384, 24576) },
3061+ { AOM_CDF4(8192, 16384, 24576) },
3062+ { AOM_CDF4(8192, 16384, 24576) },
3063+ { AOM_CDF4(8192, 16384, 24576) },
3064+ { AOM_CDF4(8192, 16384, 24576) },
3065+ { AOM_CDF4(8192, 16384, 24576) },
3066+ { AOM_CDF4(8192, 16384, 24576) },
3067+ { AOM_CDF4(8192, 16384, 24576) },
3068+ { AOM_CDF4(8192, 16384, 24576) },
3069+ { AOM_CDF4(8192, 16384, 24576) },
3070+ { AOM_CDF4(8192, 16384, 24576) },
3071+ { AOM_CDF4(8192, 16384, 24576) },
3072+ { AOM_CDF4(8192, 16384, 24576) },
3073+ { AOM_CDF4(8192, 16384, 24576) },
3074+ { AOM_CDF4(8192, 16384, 24576) },
3075+ { AOM_CDF4(8192, 16384, 24576) } } }
3076+ }, .dc_sign = {
3077+ {
3078+ { AOM_CDF2(128 * 125) },
3079+ { AOM_CDF2(128 * 102) },
3080+ { AOM_CDF2(128 * 147) },
3081+ },
3082+ {
3083+ { AOM_CDF2(128 * 119) },
3084+ { AOM_CDF2(128 * 101) },
3085+ { AOM_CDF2(128 * 135) },
3086+ }
3087+ }, .br_tok = {
3088+ { { { AOM_CDF4(16138, 22223, 25509) },
3089+ { AOM_CDF4(15347, 22430, 26332) },
3090+ { AOM_CDF4(9614, 16736, 21332) },
3091+ { AOM_CDF4(6600, 12275, 16907) },
3092+ { AOM_CDF4(4811, 9424, 13547) },
3093+ { AOM_CDF4(3748, 7809, 11420) },
3094+ { AOM_CDF4(2254, 4587, 6890) },
3095+ { AOM_CDF4(15196, 20284, 23177) },
3096+ { AOM_CDF4(18317, 25469, 28451) },
3097+ { AOM_CDF4(13918, 21651, 25842) },
3098+ { AOM_CDF4(10052, 17150, 21995) },
3099+ { AOM_CDF4(7499, 13630, 18587) },
3100+ { AOM_CDF4(6158, 11417, 16003) },
3101+ { AOM_CDF4(4014, 7785, 11252) },
3102+ { AOM_CDF4(15048, 21067, 24384) },
3103+ { AOM_CDF4(18202, 25346, 28553) },
3104+ { AOM_CDF4(14302, 22019, 26356) },
3105+ { AOM_CDF4(10839, 18139, 23166) },
3106+ { AOM_CDF4(8715, 15744, 20806) },
3107+ { AOM_CDF4(7536, 13576, 18544) },
3108+ { AOM_CDF4(5413, 10335, 14498) } },
3109+ { { AOM_CDF4(17394, 24501, 27895) },
3110+ { AOM_CDF4(15889, 23420, 27185) },
3111+ { AOM_CDF4(11561, 19133, 23870) },
3112+ { AOM_CDF4(8285, 14812, 19844) },
3113+ { AOM_CDF4(6496, 12043, 16550) },
3114+ { AOM_CDF4(4771, 9574, 13677) },
3115+ { AOM_CDF4(3603, 6830, 10144) },
3116+ { AOM_CDF4(21656, 27704, 30200) },
3117+ { AOM_CDF4(21324, 27915, 30511) },
3118+ { AOM_CDF4(17327, 25336, 28997) },
3119+ { AOM_CDF4(13417, 21381, 26033) },
3120+ { AOM_CDF4(10132, 17425, 22338) },
3121+ { AOM_CDF4(8580, 15016, 19633) },
3122+ { AOM_CDF4(5694, 11477, 16411) },
3123+ { AOM_CDF4(24116, 29780, 31450) },
3124+ { AOM_CDF4(23853, 29695, 31591) },
3125+ { AOM_CDF4(20085, 27614, 30428) },
3126+ { AOM_CDF4(15326, 24335, 28575) },
3127+ { AOM_CDF4(11814, 19472, 24810) },
3128+ { AOM_CDF4(10221, 18611, 24767) },
3129+ { AOM_CDF4(7689, 14558, 20321) } } },
3130+ { { { AOM_CDF4(16214, 22380, 25770) },
3131+ { AOM_CDF4(14213, 21304, 25295) },
3132+ { AOM_CDF4(9213, 15823, 20455) },
3133+ { AOM_CDF4(6395, 11758, 16139) },
3134+ { AOM_CDF4(4779, 9187, 13066) },
3135+ { AOM_CDF4(3821, 7501, 10953) },
3136+ { AOM_CDF4(2293, 4567, 6795) },
3137+ { AOM_CDF4(15859, 21283, 23820) },
3138+ { AOM_CDF4(18404, 25602, 28726) },
3139+ { AOM_CDF4(14325, 21980, 26206) },
3140+ { AOM_CDF4(10669, 17937, 22720) },
3141+ { AOM_CDF4(8297, 14642, 19447) },
3142+ { AOM_CDF4(6746, 12389, 16893) },
3143+ { AOM_CDF4(4324, 8251, 11770) },
3144+ { AOM_CDF4(16532, 21631, 24475) },
3145+ { AOM_CDF4(20667, 27150, 29668) },
3146+ { AOM_CDF4(16728, 24510, 28175) },
3147+ { AOM_CDF4(12861, 20645, 25332) },
3148+ { AOM_CDF4(10076, 17361, 22417) },
3149+ { AOM_CDF4(8395, 14940, 19963) },
3150+ { AOM_CDF4(5731, 10683, 14912) } },
3151+ { { AOM_CDF4(14433, 21155, 24938) },
3152+ { AOM_CDF4(14658, 21716, 25545) },
3153+ { AOM_CDF4(9923, 16824, 21557) },
3154+ { AOM_CDF4(6982, 13052, 17721) },
3155+ { AOM_CDF4(5419, 10503, 15050) },
3156+ { AOM_CDF4(4852, 9162, 13014) },
3157+ { AOM_CDF4(3271, 6395, 9630) },
3158+ { AOM_CDF4(22210, 27833, 30109) },
3159+ { AOM_CDF4(20750, 27368, 29821) },
3160+ { AOM_CDF4(16894, 24828, 28573) },
3161+ { AOM_CDF4(13247, 21276, 25757) },
3162+ { AOM_CDF4(10038, 17265, 22563) },
3163+ { AOM_CDF4(8587, 14947, 20327) },
3164+ { AOM_CDF4(5645, 11371, 15252) },
3165+ { AOM_CDF4(22027, 27526, 29714) },
3166+ { AOM_CDF4(23098, 29146, 31221) },
3167+ { AOM_CDF4(19886, 27341, 30272) },
3168+ { AOM_CDF4(15609, 23747, 28046) },
3169+ { AOM_CDF4(11993, 20065, 24939) },
3170+ { AOM_CDF4(9637, 18267, 23671) },
3171+ { AOM_CDF4(7625, 13801, 19144) } } },
3172+ { { { AOM_CDF4(14438, 20798, 24089) },
3173+ { AOM_CDF4(12621, 19203, 23097) },
3174+ { AOM_CDF4(8177, 14125, 18402) },
3175+ { AOM_CDF4(5674, 10501, 14456) },
3176+ { AOM_CDF4(4236, 8239, 11733) },
3177+ { AOM_CDF4(3447, 6750, 9806) },
3178+ { AOM_CDF4(1986, 3950, 5864) },
3179+ { AOM_CDF4(16208, 22099, 24930) },
3180+ { AOM_CDF4(16537, 24025, 27585) },
3181+ { AOM_CDF4(12780, 20381, 24867) },
3182+ { AOM_CDF4(9767, 16612, 21416) },
3183+ { AOM_CDF4(7686, 13738, 18398) },
3184+ { AOM_CDF4(6333, 11614, 15964) },
3185+ { AOM_CDF4(3941, 7571, 10836) },
3186+ { AOM_CDF4(22819, 27422, 29202) },
3187+ { AOM_CDF4(22224, 28514, 30721) },
3188+ { AOM_CDF4(17660, 25433, 28913) },
3189+ { AOM_CDF4(13574, 21482, 26002) },
3190+ { AOM_CDF4(10629, 17977, 22938) },
3191+ { AOM_CDF4(8612, 15298, 20265) },
3192+ { AOM_CDF4(5607, 10491, 14596) } },
3193+ { { AOM_CDF4(13569, 19800, 23206) },
3194+ { AOM_CDF4(13128, 19924, 23869) },
3195+ { AOM_CDF4(8329, 14841, 19403) },
3196+ { AOM_CDF4(6130, 10976, 15057) },
3197+ { AOM_CDF4(4682, 8839, 12518) },
3198+ { AOM_CDF4(3656, 7409, 10588) },
3199+ { AOM_CDF4(2577, 5099, 7412) },
3200+ { AOM_CDF4(22427, 28684, 30585) },
3201+ { AOM_CDF4(20913, 27750, 30139) },
3202+ { AOM_CDF4(15840, 24109, 27834) },
3203+ { AOM_CDF4(12308, 20029, 24569) },
3204+ { AOM_CDF4(10216, 16785, 21458) },
3205+ { AOM_CDF4(8309, 14203, 19113) },
3206+ { AOM_CDF4(6043, 11168, 15307) },
3207+ { AOM_CDF4(23166, 28901, 30998) },
3208+ { AOM_CDF4(21899, 28405, 30751) },
3209+ { AOM_CDF4(18413, 26091, 29443) },
3210+ { AOM_CDF4(15233, 23114, 27352) },
3211+ { AOM_CDF4(12683, 20472, 25288) },
3212+ { AOM_CDF4(10702, 18259, 23409) },
3213+ { AOM_CDF4(8125, 14464, 19226) } } },
3214+ { { { AOM_CDF4(9040, 14786, 18360) },
3215+ { AOM_CDF4(9979, 15718, 19415) },
3216+ { AOM_CDF4(7913, 13918, 18311) },
3217+ { AOM_CDF4(5859, 10889, 15184) },
3218+ { AOM_CDF4(4593, 8677, 12510) },
3219+ { AOM_CDF4(3820, 7396, 10791) },
3220+ { AOM_CDF4(1730, 3471, 5192) },
3221+ { AOM_CDF4(11803, 18365, 22709) },
3222+ { AOM_CDF4(11419, 18058, 22225) },
3223+ { AOM_CDF4(9418, 15774, 20243) },
3224+ { AOM_CDF4(7539, 13325, 17657) },
3225+ { AOM_CDF4(6233, 11317, 15384) },
3226+ { AOM_CDF4(5137, 9656, 13545) },
3227+ { AOM_CDF4(2977, 5774, 8349) },
3228+ { AOM_CDF4(21207, 27246, 29640) },
3229+ { AOM_CDF4(19547, 26578, 29497) },
3230+ { AOM_CDF4(16169, 23871, 27690) },
3231+ { AOM_CDF4(12820, 20458, 25018) },
3232+ { AOM_CDF4(10224, 17332, 22214) },
3233+ { AOM_CDF4(8526, 15048, 19884) },
3234+ { AOM_CDF4(5037, 9410, 13118) } },
3235+ { { AOM_CDF4(12339, 17329, 20140) },
3236+ { AOM_CDF4(13505, 19895, 23225) },
3237+ { AOM_CDF4(9847, 16944, 21564) },
3238+ { AOM_CDF4(7280, 13256, 18348) },
3239+ { AOM_CDF4(4712, 10009, 14454) },
3240+ { AOM_CDF4(4361, 7914, 12477) },
3241+ { AOM_CDF4(2870, 5628, 7995) },
3242+ { AOM_CDF4(20061, 25504, 28526) },
3243+ { AOM_CDF4(15235, 22878, 26145) },
3244+ { AOM_CDF4(12985, 19958, 24155) },
3245+ { AOM_CDF4(9782, 16641, 21403) },
3246+ { AOM_CDF4(9456, 16360, 20760) },
3247+ { AOM_CDF4(6855, 12940, 18557) },
3248+ { AOM_CDF4(5661, 10564, 15002) },
3249+ { AOM_CDF4(25656, 30602, 31894) },
3250+ { AOM_CDF4(22570, 29107, 31092) },
3251+ { AOM_CDF4(18917, 26423, 29541) },
3252+ { AOM_CDF4(15940, 23649, 27754) },
3253+ { AOM_CDF4(12803, 20581, 25219) },
3254+ { AOM_CDF4(11082, 18695, 23376) },
3255+ { AOM_CDF4(7939, 14373, 19005) } } }
3256+ },
3257+ }, [3] = {
3258+ .skip = {
3259+ { { AOM_CDF2(26887) },
3260+ { AOM_CDF2(6729) },
3261+ { AOM_CDF2(10361) },
3262+ { AOM_CDF2(17442) },
3263+ { AOM_CDF2(15045) },
3264+ { AOM_CDF2(22478) },
3265+ { AOM_CDF2(29072) },
3266+ { AOM_CDF2(2713) },
3267+ { AOM_CDF2(11861) },
3268+ { AOM_CDF2(20773) },
3269+ { AOM_CDF2(16384) },
3270+ { AOM_CDF2(16384) },
3271+ { AOM_CDF2(16384) } },
3272+ { { AOM_CDF2(31903) },
3273+ { AOM_CDF2(2044) },
3274+ { AOM_CDF2(7528) },
3275+ { AOM_CDF2(14618) },
3276+ { AOM_CDF2(16182) },
3277+ { AOM_CDF2(24168) },
3278+ { AOM_CDF2(31037) },
3279+ { AOM_CDF2(2786) },
3280+ { AOM_CDF2(11194) },
3281+ { AOM_CDF2(20155) },
3282+ { AOM_CDF2(16384) },
3283+ { AOM_CDF2(16384) },
3284+ { AOM_CDF2(16384) } },
3285+ { { AOM_CDF2(32510) },
3286+ { AOM_CDF2(8430) },
3287+ { AOM_CDF2(17318) },
3288+ { AOM_CDF2(24154) },
3289+ { AOM_CDF2(23674) },
3290+ { AOM_CDF2(28789) },
3291+ { AOM_CDF2(32139) },
3292+ { AOM_CDF2(3440) },
3293+ { AOM_CDF2(13117) },
3294+ { AOM_CDF2(22702) },
3295+ { AOM_CDF2(16384) },
3296+ { AOM_CDF2(16384) },
3297+ { AOM_CDF2(16384) } },
3298+ { { AOM_CDF2(31671) },
3299+ { AOM_CDF2(2056) },
3300+ { AOM_CDF2(11746) },
3301+ { AOM_CDF2(16852) },
3302+ { AOM_CDF2(18635) },
3303+ { AOM_CDF2(24715) },
3304+ { AOM_CDF2(31484) },
3305+ { AOM_CDF2(4656) },
3306+ { AOM_CDF2(16074) },
3307+ { AOM_CDF2(24704) },
3308+ { AOM_CDF2(1806) },
3309+ { AOM_CDF2(14645) },
3310+ { AOM_CDF2(25336) } },
3311+ { { AOM_CDF2(31539) },
3312+ { AOM_CDF2(8433) },
3313+ { AOM_CDF2(20576) },
3314+ { AOM_CDF2(27904) },
3315+ { AOM_CDF2(27852) },
3316+ { AOM_CDF2(30026) },
3317+ { AOM_CDF2(32441) },
3318+ { AOM_CDF2(16384) },
3319+ { AOM_CDF2(16384) },
3320+ { AOM_CDF2(16384) },
3321+ { AOM_CDF2(16384) },
3322+ { AOM_CDF2(16384) },
3323+ { AOM_CDF2(16384) } }
3324+ }, .eob_bin_16 = {
3325+ { { AOM_CDF5(6708, 8958, 14746, 22133) },
3326+ { AOM_CDF5(1222, 2074, 4783, 15410) } },
3327+ { { AOM_CDF5(19575, 21766, 26044, 29709) },
3328+ { AOM_CDF5(7297, 10767, 19273, 28194) } }
3329+ }, .eob_bin_32 = {
3330+ { { AOM_CDF6(4617, 5709, 8446, 13584, 23135) },
3331+ { AOM_CDF6(1156, 1702, 3675, 9274, 20539) } },
3332+ { { AOM_CDF6(22086, 24282, 27010, 29770, 31743) },
3333+ { AOM_CDF6(7699, 10897, 20891, 26926, 31628) } }
3334+ }, .eob_bin_64 = {
3335+ { { AOM_CDF7(6307, 7541, 12060, 16358, 22553, 27865) },
3336+ { AOM_CDF7(1289, 2320, 3971, 7926, 14153, 24291) } },
3337+ { { AOM_CDF7(24212, 25708, 28268, 30035, 31307, 32049) },
3338+ { AOM_CDF7(8726, 12378, 19409, 26450, 30038, 32462) } }
3339+ }, .eob_bin_128 = {
3340+ { { AOM_CDF8(3472, 4885, 7489, 12481, 18517, 24536, 29635) },
3341+ { AOM_CDF8(886, 1731, 3271, 8469, 15569, 22126, 28383) } },
3342+ { { AOM_CDF8(24313, 26062, 28385, 30107, 31217, 31898, 32345) },
3343+ { AOM_CDF8(9165, 13282, 21150, 30286, 31894, 32571, 32712) } }
3344+ }, .eob_bin_256 = {
3345+ { { AOM_CDF9(5348, 7113, 11820, 15924, 22106, 26777, 30334, 31757) },
3346+ { AOM_CDF9(2453, 4474, 6307, 8777, 16474, 22975, 29000, 31547) } },
3347+ { { AOM_CDF9(23110, 24597, 27140, 28894, 30167, 30927, 31392, 32094) },
3348+ { AOM_CDF9(9998, 17661, 25178, 28097, 31308, 32038, 32403, 32695) } }
3349+ }, .eob_bin_512 = {
3350+ { { AOM_CDF10(5927, 7809, 10923, 14597, 19439, 24135, 28456,
3351+ 31142, 32060) },
3352+ { AOM_CDF10(3277, 6554, 9830, 13107, 16384, 19661, 22938,
3353+ 26214, 29491) } },
3354+ { { AOM_CDF10(21093, 23043, 25742, 27658, 29097, 29716,
3355+ 30073, 30820, 31956) },
3356+ { AOM_CDF10(3277, 6554, 9830, 13107, 16384, 19661, 22938,
3357+ 26214, 29491) } }
3358+ }, .eob_bin_1024 = {
3359+ { { AOM_CDF11(6698, 8334, 11961, 15762, 20186, 23862, 27434,
3360+ 29326, 31082, 32050) },
3361+ { AOM_CDF11(2979, 5958, 8937, 11916, 14895, 17873, 20852,
3362+ 23831, 26810, 29789) } },
3363+ { { AOM_CDF11(20569, 22426, 25569, 26859, 28053, 28913,
3364+ 29486, 29724, 29807, 32570) },
3365+ { AOM_CDF11(2979, 5958, 8937, 11916, 14895, 17873, 20852,
3366+ 23831, 26810, 29789) } }
3367+ }, .eob_hi_bit = {
3368+ { { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
3369+ { AOM_CDF2(20177) }, { AOM_CDF2(20789) }, { AOM_CDF2(20262) },
3370+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
3371+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) } },
3372+ { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
3373+ { AOM_CDF2(21416) }, { AOM_CDF2(20855) }, { AOM_CDF2(23410) },
3374+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
3375+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) } } },
3376+ { { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
3377+ { AOM_CDF2(20238) }, { AOM_CDF2(21057) }, { AOM_CDF2(19159) },
3378+ { AOM_CDF2(22337) }, { AOM_CDF2(20159) }, { AOM_CDF2(16384) },
3379+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) } },
3380+ { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
3381+ { AOM_CDF2(20125) }, { AOM_CDF2(20559) }, { AOM_CDF2(21707) },
3382+ { AOM_CDF2(22296) }, { AOM_CDF2(17333) }, { AOM_CDF2(16384) },
3383+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) } } },
3384+ { { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
3385+ { AOM_CDF2(19941) }, { AOM_CDF2(20527) }, { AOM_CDF2(21470) },
3386+ { AOM_CDF2(22487) }, { AOM_CDF2(19558) }, { AOM_CDF2(22354) },
3387+ { AOM_CDF2(20331) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) } },
3388+ { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
3389+ { AOM_CDF2(22752) }, { AOM_CDF2(25006) }, { AOM_CDF2(22075) },
3390+ { AOM_CDF2(21576) }, { AOM_CDF2(17740) }, { AOM_CDF2(21690) },
3391+ { AOM_CDF2(19211) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) } } },
3392+ { { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
3393+ { AOM_CDF2(21442) }, { AOM_CDF2(22358) }, { AOM_CDF2(18503) },
3394+ { AOM_CDF2(20291) }, { AOM_CDF2(19945) }, { AOM_CDF2(21294) },
3395+ { AOM_CDF2(21178) }, { AOM_CDF2(19400) }, { AOM_CDF2(10556) } },
3396+ { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
3397+ { AOM_CDF2(24648) }, { AOM_CDF2(24949) }, { AOM_CDF2(20708) },
3398+ { AOM_CDF2(23905) }, { AOM_CDF2(20501) }, { AOM_CDF2(9558) },
3399+ { AOM_CDF2(9423) }, { AOM_CDF2(30365) }, { AOM_CDF2(19253) } } },
3400+ { { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
3401+ { AOM_CDF2(26064) }, { AOM_CDF2(22098) }, { AOM_CDF2(19613) },
3402+ { AOM_CDF2(20525) }, { AOM_CDF2(17595) }, { AOM_CDF2(16618) },
3403+ { AOM_CDF2(20497) }, { AOM_CDF2(18989) }, { AOM_CDF2(15513) } },
3404+ { { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
3405+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
3406+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) },
3407+ { AOM_CDF2(16384) }, { AOM_CDF2(16384) }, { AOM_CDF2(16384) } } }
3408+ }, .eob_base_tok = {
3409+ { { { AOM_CDF3(22497, 31198) },
3410+ { AOM_CDF3(31715, 32495) },
3411+ { AOM_CDF3(31606, 32337) },
3412+ { AOM_CDF3(30388, 31990) } },
3413+ { { AOM_CDF3(27877, 31584) },
3414+ { AOM_CDF3(32170, 32728) },
3415+ { AOM_CDF3(32155, 32688) },
3416+ { AOM_CDF3(32219, 32702) } } },
3417+ { { { AOM_CDF3(21457, 31043) },
3418+ { AOM_CDF3(31951, 32483) },
3419+ { AOM_CDF3(32153, 32562) },
3420+ { AOM_CDF3(31473, 32215) } },
3421+ { { AOM_CDF3(27558, 31151) },
3422+ { AOM_CDF3(32020, 32640) },
3423+ { AOM_CDF3(32097, 32575) },
3424+ { AOM_CDF3(32242, 32719) } } },
3425+ { { { AOM_CDF3(19980, 30591) },
3426+ { AOM_CDF3(32219, 32597) },
3427+ { AOM_CDF3(32581, 32706) },
3428+ { AOM_CDF3(31803, 32287) } },
3429+ { { AOM_CDF3(26473, 30507) },
3430+ { AOM_CDF3(32431, 32723) },
3431+ { AOM_CDF3(32196, 32611) },
3432+ { AOM_CDF3(31588, 32528) } } },
3433+ { { { AOM_CDF3(24647, 30463) },
3434+ { AOM_CDF3(32412, 32695) },
3435+ { AOM_CDF3(32468, 32720) },
3436+ { AOM_CDF3(31269, 32523) } },
3437+ { { AOM_CDF3(28482, 31505) },
3438+ { AOM_CDF3(32152, 32701) },
3439+ { AOM_CDF3(31732, 32598) },
3440+ { AOM_CDF3(31767, 32712) } } },
3441+ { { { AOM_CDF3(12358, 24977) },
3442+ { AOM_CDF3(31331, 32385) },
3443+ { AOM_CDF3(32634, 32756) },
3444+ { AOM_CDF3(30411, 32548) } },
3445+ { { AOM_CDF3(10923, 21845) },
3446+ { AOM_CDF3(10923, 21845) },
3447+ { AOM_CDF3(10923, 21845) },
3448+ { AOM_CDF3(10923, 21845) } } }
3449+ }, .base_tok = {
3450+ { { { AOM_CDF4(7062, 16472, 22319) },
3451+ { AOM_CDF4(24538, 32261, 32674) },
3452+ { AOM_CDF4(13675, 28041, 31779) },
3453+ { AOM_CDF4(8590, 20674, 27631) },
3454+ { AOM_CDF4(5685, 14675, 22013) },
3455+ { AOM_CDF4(3655, 9898, 15731) },
3456+ { AOM_CDF4(26493, 32418, 32658) },
3457+ { AOM_CDF4(16376, 29342, 32090) },
3458+ { AOM_CDF4(10594, 22649, 28970) },
3459+ { AOM_CDF4(8176, 17170, 24303) },
3460+ { AOM_CDF4(5605, 12694, 19139) },
3461+ { AOM_CDF4(8192, 16384, 24576) },
3462+ { AOM_CDF4(8192, 16384, 24576) },
3463+ { AOM_CDF4(8192, 16384, 24576) },
3464+ { AOM_CDF4(8192, 16384, 24576) },
3465+ { AOM_CDF4(8192, 16384, 24576) },
3466+ { AOM_CDF4(8192, 16384, 24576) },
3467+ { AOM_CDF4(8192, 16384, 24576) },
3468+ { AOM_CDF4(8192, 16384, 24576) },
3469+ { AOM_CDF4(8192, 16384, 24576) },
3470+ { AOM_CDF4(8192, 16384, 24576) },
3471+ { AOM_CDF4(23888, 31902, 32542) },
3472+ { AOM_CDF4(18612, 29687, 31987) },
3473+ { AOM_CDF4(16245, 24852, 29249) },
3474+ { AOM_CDF4(15765, 22608, 27559) },
3475+ { AOM_CDF4(19895, 24699, 27510) },
3476+ { AOM_CDF4(28401, 32212, 32457) },
3477+ { AOM_CDF4(15274, 27825, 30980) },
3478+ { AOM_CDF4(9364, 18128, 24332) },
3479+ { AOM_CDF4(2283, 8193, 15082) },
3480+ { AOM_CDF4(1228, 3972, 7881) },
3481+ { AOM_CDF4(29455, 32469, 32620) },
3482+ { AOM_CDF4(17981, 28245, 31388) },
3483+ { AOM_CDF4(10921, 20098, 26240) },
3484+ { AOM_CDF4(3743, 11829, 18657) },
3485+ { AOM_CDF4(2374, 9593, 15715) },
3486+ { AOM_CDF4(31068, 32466, 32635) },
3487+ { AOM_CDF4(20321, 29572, 31971) },
3488+ { AOM_CDF4(10771, 20255, 27119) },
3489+ { AOM_CDF4(2795, 10410, 17361) },
3490+ { AOM_CDF4(8192, 16384, 24576) } },
3491+ { { AOM_CDF4(9320, 22102, 27840) },
3492+ { AOM_CDF4(27057, 32464, 32724) },
3493+ { AOM_CDF4(16331, 30268, 32309) },
3494+ { AOM_CDF4(10319, 23935, 29720) },
3495+ { AOM_CDF4(6189, 16448, 24106) },
3496+ { AOM_CDF4(3589, 10884, 18808) },
3497+ { AOM_CDF4(29026, 32624, 32748) },
3498+ { AOM_CDF4(19226, 31507, 32587) },
3499+ { AOM_CDF4(12692, 26921, 31203) },
3500+ { AOM_CDF4(7049, 19532, 27635) },
3501+ { AOM_CDF4(7727, 15669, 23252) },
3502+ { AOM_CDF4(8192, 16384, 24576) },
3503+ { AOM_CDF4(8192, 16384, 24576) },
3504+ { AOM_CDF4(8192, 16384, 24576) },
3505+ { AOM_CDF4(8192, 16384, 24576) },
3506+ { AOM_CDF4(8192, 16384, 24576) },
3507+ { AOM_CDF4(8192, 16384, 24576) },
3508+ { AOM_CDF4(8192, 16384, 24576) },
3509+ { AOM_CDF4(8192, 16384, 24576) },
3510+ { AOM_CDF4(8192, 16384, 24576) },
3511+ { AOM_CDF4(8192, 16384, 24576) },
3512+ { AOM_CDF4(28056, 32625, 32748) },
3513+ { AOM_CDF4(22383, 32075, 32669) },
3514+ { AOM_CDF4(15417, 27098, 31749) },
3515+ { AOM_CDF4(18127, 26493, 27190) },
3516+ { AOM_CDF4(5461, 16384, 21845) },
3517+ { AOM_CDF4(27982, 32091, 32584) },
3518+ { AOM_CDF4(19045, 29868, 31972) },
3519+ { AOM_CDF4(10397, 22266, 27932) },
3520+ { AOM_CDF4(5990, 13697, 21500) },
3521+ { AOM_CDF4(1792, 6912, 15104) },
3522+ { AOM_CDF4(28198, 32501, 32718) },
3523+ { AOM_CDF4(21534, 31521, 32569) },
3524+ { AOM_CDF4(11109, 25217, 30017) },
3525+ { AOM_CDF4(5671, 15124, 26151) },
3526+ { AOM_CDF4(4681, 14043, 18725) },
3527+ { AOM_CDF4(28688, 32580, 32741) },
3528+ { AOM_CDF4(22576, 32079, 32661) },
3529+ { AOM_CDF4(10627, 22141, 28340) },
3530+ { AOM_CDF4(9362, 14043, 28087) },
3531+ { AOM_CDF4(8192, 16384, 24576) } } },
3532+ { { { AOM_CDF4(7754, 16948, 22142) },
3533+ { AOM_CDF4(25670, 32330, 32691) },
3534+ { AOM_CDF4(15663, 29225, 31994) },
3535+ { AOM_CDF4(9878, 23288, 29158) },
3536+ { AOM_CDF4(6419, 17088, 24336) },
3537+ { AOM_CDF4(3859, 11003, 17039) },
3538+ { AOM_CDF4(27562, 32595, 32725) },
3539+ { AOM_CDF4(17575, 30588, 32399) },
3540+ { AOM_CDF4(10819, 24838, 30309) },
3541+ { AOM_CDF4(7124, 18686, 25916) },
3542+ { AOM_CDF4(4479, 12688, 19340) },
3543+ { AOM_CDF4(28385, 32476, 32673) },
3544+ { AOM_CDF4(15306, 29005, 31938) },
3545+ { AOM_CDF4(8937, 21615, 28322) },
3546+ { AOM_CDF4(5982, 15603, 22786) },
3547+ { AOM_CDF4(3620, 10267, 16136) },
3548+ { AOM_CDF4(27280, 32464, 32667) },
3549+ { AOM_CDF4(15607, 29160, 32004) },
3550+ { AOM_CDF4(9091, 22135, 28740) },
3551+ { AOM_CDF4(6232, 16632, 24020) },
3552+ { AOM_CDF4(4047, 11377, 17672) },
3553+ { AOM_CDF4(29220, 32630, 32718) },
3554+ { AOM_CDF4(19650, 31220, 32462) },
3555+ { AOM_CDF4(13050, 26312, 30827) },
3556+ { AOM_CDF4(9228, 20870, 27468) },
3557+ { AOM_CDF4(6146, 15149, 21971) },
3558+ { AOM_CDF4(30169, 32481, 32623) },
3559+ { AOM_CDF4(17212, 29311, 31554) },
3560+ { AOM_CDF4(9911, 21311, 26882) },
3561+ { AOM_CDF4(4487, 13314, 20372) },
3562+ { AOM_CDF4(2570, 7772, 12889) },
3563+ { AOM_CDF4(30924, 32613, 32708) },
3564+ { AOM_CDF4(19490, 30206, 32107) },
3565+ { AOM_CDF4(11232, 23998, 29276) },
3566+ { AOM_CDF4(6769, 17955, 25035) },
3567+ { AOM_CDF4(4398, 12623, 19214) },
3568+ { AOM_CDF4(30609, 32627, 32722) },
3569+ { AOM_CDF4(19370, 30582, 32287) },
3570+ { AOM_CDF4(10457, 23619, 29409) },
3571+ { AOM_CDF4(6443, 17637, 24834) },
3572+ { AOM_CDF4(4645, 13236, 20106) } },
3573+ { { AOM_CDF4(8626, 20271, 26216) },
3574+ { AOM_CDF4(26707, 32406, 32711) },
3575+ { AOM_CDF4(16999, 30329, 32286) },
3576+ { AOM_CDF4(11445, 25123, 30286) },
3577+ { AOM_CDF4(6411, 18828, 25601) },
3578+ { AOM_CDF4(6801, 12458, 20248) },
3579+ { AOM_CDF4(29918, 32682, 32748) },
3580+ { AOM_CDF4(20649, 31739, 32618) },
3581+ { AOM_CDF4(12879, 27773, 31581) },
3582+ { AOM_CDF4(7896, 21751, 28244) },
3583+ { AOM_CDF4(5260, 14870, 23698) },
3584+ { AOM_CDF4(29252, 32593, 32731) },
3585+ { AOM_CDF4(17072, 30460, 32294) },
3586+ { AOM_CDF4(10653, 24143, 29365) },
3587+ { AOM_CDF4(6536, 17490, 23983) },
3588+ { AOM_CDF4(4929, 13170, 20085) },
3589+ { AOM_CDF4(28137, 32518, 32715) },
3590+ { AOM_CDF4(18171, 30784, 32407) },
3591+ { AOM_CDF4(11437, 25436, 30459) },
3592+ { AOM_CDF4(7252, 18534, 26176) },
3593+ { AOM_CDF4(4126, 13353, 20978) },
3594+ { AOM_CDF4(31162, 32726, 32748) },
3595+ { AOM_CDF4(23017, 32222, 32701) },
3596+ { AOM_CDF4(15629, 29233, 32046) },
3597+ { AOM_CDF4(9387, 22621, 29480) },
3598+ { AOM_CDF4(6922, 17616, 25010) },
3599+ { AOM_CDF4(28838, 32265, 32614) },
3600+ { AOM_CDF4(19701, 30206, 31920) },
3601+ { AOM_CDF4(11214, 22410, 27933) },
3602+ { AOM_CDF4(5320, 14177, 23034) },
3603+ { AOM_CDF4(5049, 12881, 17827) },
3604+ { AOM_CDF4(27484, 32471, 32734) },
3605+ { AOM_CDF4(21076, 31526, 32561) },
3606+ { AOM_CDF4(12707, 26303, 31211) },
3607+ { AOM_CDF4(8169, 21722, 28219) },
3608+ { AOM_CDF4(6045, 19406, 27042) },
3609+ { AOM_CDF4(27753, 32572, 32745) },
3610+ { AOM_CDF4(20832, 31878, 32653) },
3611+ { AOM_CDF4(13250, 27356, 31674) },
3612+ { AOM_CDF4(7718, 21508, 29858) },
3613+ { AOM_CDF4(7209, 18350, 25559) } } },
3614+ { { { AOM_CDF4(7876, 16901, 21741) },
3615+ { AOM_CDF4(24001, 31898, 32625) },
3616+ { AOM_CDF4(14529, 27959, 31451) },
3617+ { AOM_CDF4(8273, 20818, 27258) },
3618+ { AOM_CDF4(5278, 14673, 21510) },
3619+ { AOM_CDF4(2983, 8843, 14039) },
3620+ { AOM_CDF4(28016, 32574, 32732) },
3621+ { AOM_CDF4(17471, 30306, 32301) },
3622+ { AOM_CDF4(10224, 24063, 29728) },
3623+ { AOM_CDF4(6602, 17954, 25052) },
3624+ { AOM_CDF4(4002, 11585, 17759) },
3625+ { AOM_CDF4(30190, 32634, 32739) },
3626+ { AOM_CDF4(17497, 30282, 32270) },
3627+ { AOM_CDF4(10229, 23729, 29538) },
3628+ { AOM_CDF4(6344, 17211, 24440) },
3629+ { AOM_CDF4(3849, 11189, 17108) },
3630+ { AOM_CDF4(28570, 32583, 32726) },
3631+ { AOM_CDF4(17521, 30161, 32238) },
3632+ { AOM_CDF4(10153, 23565, 29378) },
3633+ { AOM_CDF4(6455, 17341, 24443) },
3634+ { AOM_CDF4(3907, 11042, 17024) },
3635+ { AOM_CDF4(30689, 32715, 32748) },
3636+ { AOM_CDF4(21546, 31840, 32610) },
3637+ { AOM_CDF4(13547, 27581, 31459) },
3638+ { AOM_CDF4(8912, 21757, 28309) },
3639+ { AOM_CDF4(5548, 15080, 22046) },
3640+ { AOM_CDF4(30783, 32540, 32685) },
3641+ { AOM_CDF4(17540, 29528, 31668) },
3642+ { AOM_CDF4(10160, 21468, 26783) },
3643+ { AOM_CDF4(4724, 13393, 20054) },
3644+ { AOM_CDF4(2702, 8174, 13102) },
3645+ { AOM_CDF4(31648, 32686, 32742) },
3646+ { AOM_CDF4(20954, 31094, 32337) },
3647+ { AOM_CDF4(12420, 25698, 30179) },
3648+ { AOM_CDF4(7304, 19320, 26248) },
3649+ { AOM_CDF4(4366, 12261, 18864) },
3650+ { AOM_CDF4(31581, 32723, 32748) },
3651+ { AOM_CDF4(21373, 31586, 32525) },
3652+ { AOM_CDF4(12744, 26625, 30885) },
3653+ { AOM_CDF4(7431, 20322, 26950) },
3654+ { AOM_CDF4(4692, 13323, 20111) } },
3655+ { { AOM_CDF4(7833, 18369, 24095) },
3656+ { AOM_CDF4(26650, 32273, 32702) },
3657+ { AOM_CDF4(16371, 29961, 32191) },
3658+ { AOM_CDF4(11055, 24082, 29629) },
3659+ { AOM_CDF4(6892, 18644, 25400) },
3660+ { AOM_CDF4(5006, 13057, 19240) },
3661+ { AOM_CDF4(29834, 32666, 32748) },
3662+ { AOM_CDF4(19577, 31335, 32570) },
3663+ { AOM_CDF4(12253, 26509, 31122) },
3664+ { AOM_CDF4(7991, 20772, 27711) },
3665+ { AOM_CDF4(5677, 15910, 23059) },
3666+ { AOM_CDF4(30109, 32532, 32720) },
3667+ { AOM_CDF4(16747, 30166, 32252) },
3668+ { AOM_CDF4(10134, 23542, 29184) },
3669+ { AOM_CDF4(5791, 16176, 23556) },
3670+ { AOM_CDF4(4362, 10414, 17284) },
3671+ { AOM_CDF4(29492, 32626, 32748) },
3672+ { AOM_CDF4(19894, 31402, 32525) },
3673+ { AOM_CDF4(12942, 27071, 30869) },
3674+ { AOM_CDF4(8346, 21216, 27405) },
3675+ { AOM_CDF4(6572, 17087, 23859) },
3676+ { AOM_CDF4(32035, 32735, 32748) },
3677+ { AOM_CDF4(22957, 31838, 32618) },
3678+ { AOM_CDF4(14724, 28572, 31772) },
3679+ { AOM_CDF4(10364, 23999, 29553) },
3680+ { AOM_CDF4(7004, 18433, 25655) },
3681+ { AOM_CDF4(27528, 32277, 32681) },
3682+ { AOM_CDF4(16959, 31171, 32096) },
3683+ { AOM_CDF4(10486, 23593, 27962) },
3684+ { AOM_CDF4(8192, 16384, 23211) },
3685+ { AOM_CDF4(8937, 17873, 20852) },
3686+ { AOM_CDF4(27715, 32002, 32615) },
3687+ { AOM_CDF4(15073, 29491, 31676) },
3688+ { AOM_CDF4(11264, 24576, 28672) },
3689+ { AOM_CDF4(2341, 18725, 23406) },
3690+ { AOM_CDF4(7282, 18204, 25486) },
3691+ { AOM_CDF4(28547, 32213, 32657) },
3692+ { AOM_CDF4(20788, 29773, 32239) },
3693+ { AOM_CDF4(6780, 21469, 30508) },
3694+ { AOM_CDF4(5958, 14895, 23831) },
3695+ { AOM_CDF4(16384, 21845, 27307) } } },
3696+ { { { AOM_CDF4(5992, 14304, 19765) },
3697+ { AOM_CDF4(22612, 31238, 32456) },
3698+ { AOM_CDF4(13456, 27162, 31087) },
3699+ { AOM_CDF4(8001, 20062, 26504) },
3700+ { AOM_CDF4(5168, 14105, 20764) },
3701+ { AOM_CDF4(2632, 7771, 12385) },
3702+ { AOM_CDF4(27034, 32344, 32709) },
3703+ { AOM_CDF4(15850, 29415, 31997) },
3704+ { AOM_CDF4(9494, 22776, 28841) },
3705+ { AOM_CDF4(6151, 16830, 23969) },
3706+ { AOM_CDF4(3461, 10039, 15722) },
3707+ { AOM_CDF4(30134, 32569, 32731) },
3708+ { AOM_CDF4(15638, 29422, 31945) },
3709+ { AOM_CDF4(9150, 21865, 28218) },
3710+ { AOM_CDF4(5647, 15719, 22676) },
3711+ { AOM_CDF4(3402, 9772, 15477) },
3712+ { AOM_CDF4(28530, 32586, 32735) },
3713+ { AOM_CDF4(17139, 30298, 32292) },
3714+ { AOM_CDF4(10200, 24039, 29685) },
3715+ { AOM_CDF4(6419, 17674, 24786) },
3716+ { AOM_CDF4(3544, 10225, 15824) },
3717+ { AOM_CDF4(31333, 32726, 32748) },
3718+ { AOM_CDF4(20618, 31487, 32544) },
3719+ { AOM_CDF4(12901, 27217, 31232) },
3720+ { AOM_CDF4(8624, 21734, 28171) },
3721+ { AOM_CDF4(5104, 14191, 20748) },
3722+ { AOM_CDF4(8192, 16384, 24576) },
3723+ { AOM_CDF4(8192, 16384, 24576) },
3724+ { AOM_CDF4(8192, 16384, 24576) },
3725+ { AOM_CDF4(8192, 16384, 24576) },
3726+ { AOM_CDF4(8192, 16384, 24576) },
3727+ { AOM_CDF4(8192, 16384, 24576) },
3728+ { AOM_CDF4(8192, 16384, 24576) },
3729+ { AOM_CDF4(8192, 16384, 24576) },
3730+ { AOM_CDF4(8192, 16384, 24576) },
3731+ { AOM_CDF4(8192, 16384, 24576) },
3732+ { AOM_CDF4(8192, 16384, 24576) },
3733+ { AOM_CDF4(8192, 16384, 24576) },
3734+ { AOM_CDF4(8192, 16384, 24576) },
3735+ { AOM_CDF4(8192, 16384, 24576) },
3736+ { AOM_CDF4(8192, 16384, 24576) } },
3737+ { { AOM_CDF4(11206, 21090, 26561) },
3738+ { AOM_CDF4(28759, 32279, 32671) },
3739+ { AOM_CDF4(14171, 27952, 31569) },
3740+ { AOM_CDF4(9743, 22907, 29141) },
3741+ { AOM_CDF4(6871, 17886, 24868) },
3742+ { AOM_CDF4(4960, 13152, 19315) },
3743+ { AOM_CDF4(31077, 32661, 32748) },
3744+ { AOM_CDF4(19400, 31195, 32515) },
3745+ { AOM_CDF4(12752, 26858, 31040) },
3746+ { AOM_CDF4(8370, 22098, 28591) },
3747+ { AOM_CDF4(5457, 15373, 22298) },
3748+ { AOM_CDF4(31697, 32706, 32748) },
3749+ { AOM_CDF4(17860, 30657, 32333) },
3750+ { AOM_CDF4(12510, 24812, 29261) },
3751+ { AOM_CDF4(6180, 19124, 24722) },
3752+ { AOM_CDF4(5041, 13548, 17959) },
3753+ { AOM_CDF4(31552, 32716, 32748) },
3754+ { AOM_CDF4(21908, 31769, 32623) },
3755+ { AOM_CDF4(14470, 28201, 31565) },
3756+ { AOM_CDF4(9493, 22982, 28608) },
3757+ { AOM_CDF4(6858, 17240, 24137) },
3758+ { AOM_CDF4(32543, 32752, 32756) },
3759+ { AOM_CDF4(24286, 32097, 32666) },
3760+ { AOM_CDF4(15958, 29217, 32024) },
3761+ { AOM_CDF4(10207, 24234, 29958) },
3762+ { AOM_CDF4(6929, 18305, 25652) },
3763+ { AOM_CDF4(8192, 16384, 24576) },
3764+ { AOM_CDF4(8192, 16384, 24576) },
3765+ { AOM_CDF4(8192, 16384, 24576) },
3766+ { AOM_CDF4(8192, 16384, 24576) },
3767+ { AOM_CDF4(8192, 16384, 24576) },
3768+ { AOM_CDF4(8192, 16384, 24576) },
3769+ { AOM_CDF4(8192, 16384, 24576) },
3770+ { AOM_CDF4(8192, 16384, 24576) },
3771+ { AOM_CDF4(8192, 16384, 24576) },
3772+ { AOM_CDF4(8192, 16384, 24576) },
3773+ { AOM_CDF4(8192, 16384, 24576) },
3774+ { AOM_CDF4(8192, 16384, 24576) },
3775+ { AOM_CDF4(8192, 16384, 24576) },
3776+ { AOM_CDF4(8192, 16384, 24576) },
3777+ { AOM_CDF4(8192, 16384, 24576) } } },
3778+ { { { AOM_CDF4(4137, 10847, 15682) },
3779+ { AOM_CDF4(17824, 27001, 30058) },
3780+ { AOM_CDF4(10204, 22796, 28291) },
3781+ { AOM_CDF4(6076, 15935, 22125) },
3782+ { AOM_CDF4(3852, 10937, 16816) },
3783+ { AOM_CDF4(2252, 6324, 10131) },
3784+ { AOM_CDF4(25840, 32016, 32662) },
3785+ { AOM_CDF4(15109, 28268, 31531) },
3786+ { AOM_CDF4(9385, 22231, 28340) },
3787+ { AOM_CDF4(6082, 16672, 23479) },
3788+ { AOM_CDF4(3318, 9427, 14681) },
3789+ { AOM_CDF4(30594, 32574, 32718) },
3790+ { AOM_CDF4(16836, 29552, 31859) },
3791+ { AOM_CDF4(9556, 22542, 28356) },
3792+ { AOM_CDF4(6305, 16725, 23540) },
3793+ { AOM_CDF4(3376, 9895, 15184) },
3794+ { AOM_CDF4(29383, 32617, 32745) },
3795+ { AOM_CDF4(18891, 30809, 32401) },
3796+ { AOM_CDF4(11688, 25942, 30687) },
3797+ { AOM_CDF4(7468, 19469, 26651) },
3798+ { AOM_CDF4(3909, 11358, 17012) },
3799+ { AOM_CDF4(31564, 32736, 32748) },
3800+ { AOM_CDF4(20906, 31611, 32600) },
3801+ { AOM_CDF4(13191, 27621, 31537) },
3802+ { AOM_CDF4(8768, 22029, 28676) },
3803+ { AOM_CDF4(5079, 14109, 20906) },
3804+ { AOM_CDF4(8192, 16384, 24576) },
3805+ { AOM_CDF4(8192, 16384, 24576) },
3806+ { AOM_CDF4(8192, 16384, 24576) },
3807+ { AOM_CDF4(8192, 16384, 24576) },
3808+ { AOM_CDF4(8192, 16384, 24576) },
3809+ { AOM_CDF4(8192, 16384, 24576) },
3810+ { AOM_CDF4(8192, 16384, 24576) },
3811+ { AOM_CDF4(8192, 16384, 24576) },
3812+ { AOM_CDF4(8192, 16384, 24576) },
3813+ { AOM_CDF4(8192, 16384, 24576) },
3814+ { AOM_CDF4(8192, 16384, 24576) },
3815+ { AOM_CDF4(8192, 16384, 24576) },
3816+ { AOM_CDF4(8192, 16384, 24576) },
3817+ { AOM_CDF4(8192, 16384, 24576) },
3818+ { AOM_CDF4(8192, 16384, 24576) } },
3819+ { { AOM_CDF4(8192, 16384, 24576) },
3820+ { AOM_CDF4(8192, 16384, 24576) },
3821+ { AOM_CDF4(8192, 16384, 24576) },
3822+ { AOM_CDF4(8192, 16384, 24576) },
3823+ { AOM_CDF4(8192, 16384, 24576) },
3824+ { AOM_CDF4(8192, 16384, 24576) },
3825+ { AOM_CDF4(8192, 16384, 24576) },
3826+ { AOM_CDF4(8192, 16384, 24576) },
3827+ { AOM_CDF4(8192, 16384, 24576) },
3828+ { AOM_CDF4(8192, 16384, 24576) },
3829+ { AOM_CDF4(8192, 16384, 24576) },
3830+ { AOM_CDF4(8192, 16384, 24576) },
3831+ { AOM_CDF4(8192, 16384, 24576) },
3832+ { AOM_CDF4(8192, 16384, 24576) },
3833+ { AOM_CDF4(8192, 16384, 24576) },
3834+ { AOM_CDF4(8192, 16384, 24576) },
3835+ { AOM_CDF4(8192, 16384, 24576) },
3836+ { AOM_CDF4(8192, 16384, 24576) },
3837+ { AOM_CDF4(8192, 16384, 24576) },
3838+ { AOM_CDF4(8192, 16384, 24576) },
3839+ { AOM_CDF4(8192, 16384, 24576) },
3840+ { AOM_CDF4(8192, 16384, 24576) },
3841+ { AOM_CDF4(8192, 16384, 24576) },
3842+ { AOM_CDF4(8192, 16384, 24576) },
3843+ { AOM_CDF4(8192, 16384, 24576) },
3844+ { AOM_CDF4(8192, 16384, 24576) },
3845+ { AOM_CDF4(8192, 16384, 24576) },
3846+ { AOM_CDF4(8192, 16384, 24576) },
3847+ { AOM_CDF4(8192, 16384, 24576) },
3848+ { AOM_CDF4(8192, 16384, 24576) },
3849+ { AOM_CDF4(8192, 16384, 24576) },
3850+ { AOM_CDF4(8192, 16384, 24576) },
3851+ { AOM_CDF4(8192, 16384, 24576) },
3852+ { AOM_CDF4(8192, 16384, 24576) },
3853+ { AOM_CDF4(8192, 16384, 24576) },
3854+ { AOM_CDF4(8192, 16384, 24576) },
3855+ { AOM_CDF4(8192, 16384, 24576) },
3856+ { AOM_CDF4(8192, 16384, 24576) },
3857+ { AOM_CDF4(8192, 16384, 24576) },
3858+ { AOM_CDF4(8192, 16384, 24576) },
3859+ { AOM_CDF4(8192, 16384, 24576) } } }
3860+ }, .dc_sign = {
3861+ {
3862+ { AOM_CDF2(128 * 125) },
3863+ { AOM_CDF2(128 * 102) },
3864+ { AOM_CDF2(128 * 147) },
3865+ },
3866+ {
3867+ { AOM_CDF2(128 * 119) },
3868+ { AOM_CDF2(128 * 101) },
3869+ { AOM_CDF2(128 * 135) },
3870+ }
3871+ }, .br_tok = {
3872+ { { { AOM_CDF4(18315, 24289, 27551) },
3873+ { AOM_CDF4(16854, 24068, 27835) },
3874+ { AOM_CDF4(10140, 17927, 23173) },
3875+ { AOM_CDF4(6722, 12982, 18267) },
3876+ { AOM_CDF4(4661, 9826, 14706) },
3877+ { AOM_CDF4(3832, 8165, 12294) },
3878+ { AOM_CDF4(2795, 6098, 9245) },
3879+ { AOM_CDF4(17145, 23326, 26672) },
3880+ { AOM_CDF4(20733, 27680, 30308) },
3881+ { AOM_CDF4(16032, 24461, 28546) },
3882+ { AOM_CDF4(11653, 20093, 25081) },
3883+ { AOM_CDF4(9290, 16429, 22086) },
3884+ { AOM_CDF4(7796, 14598, 19982) },
3885+ { AOM_CDF4(6502, 12378, 17441) },
3886+ { AOM_CDF4(21681, 27732, 30320) },
3887+ { AOM_CDF4(22389, 29044, 31261) },
3888+ { AOM_CDF4(19027, 26731, 30087) },
3889+ { AOM_CDF4(14739, 23755, 28624) },
3890+ { AOM_CDF4(11358, 20778, 25511) },
3891+ { AOM_CDF4(10995, 18073, 24190) },
3892+ { AOM_CDF4(9162, 14990, 20617) } },
3893+ { { AOM_CDF4(21425, 27952, 30388) },
3894+ { AOM_CDF4(18062, 25838, 29034) },
3895+ { AOM_CDF4(11956, 19881, 24808) },
3896+ { AOM_CDF4(7718, 15000, 20980) },
3897+ { AOM_CDF4(5702, 11254, 16143) },
3898+ { AOM_CDF4(4898, 9088, 16864) },
3899+ { AOM_CDF4(3679, 6776, 11907) },
3900+ { AOM_CDF4(23294, 30160, 31663) },
3901+ { AOM_CDF4(24397, 29896, 31836) },
3902+ { AOM_CDF4(19245, 27128, 30593) },
3903+ { AOM_CDF4(13202, 19825, 26404) },
3904+ { AOM_CDF4(11578, 19297, 23957) },
3905+ { AOM_CDF4(8073, 13297, 21370) },
3906+ { AOM_CDF4(5461, 10923, 19745) },
3907+ { AOM_CDF4(27367, 30521, 31934) },
3908+ { AOM_CDF4(24904, 30671, 31940) },
3909+ { AOM_CDF4(23075, 28460, 31299) },
3910+ { AOM_CDF4(14400, 23658, 30417) },
3911+ { AOM_CDF4(13885, 23882, 28325) },
3912+ { AOM_CDF4(14746, 22938, 27853) },
3913+ { AOM_CDF4(5461, 16384, 27307) } } },
3914+ { { { AOM_CDF4(18274, 24813, 27890) },
3915+ { AOM_CDF4(15537, 23149, 27003) },
3916+ { AOM_CDF4(9449, 16740, 21827) },
3917+ { AOM_CDF4(6700, 12498, 17261) },
3918+ { AOM_CDF4(4988, 9866, 14198) },
3919+ { AOM_CDF4(4236, 8147, 11902) },
3920+ { AOM_CDF4(2867, 5860, 8654) },
3921+ { AOM_CDF4(17124, 23171, 26101) },
3922+ { AOM_CDF4(20396, 27477, 30148) },
3923+ { AOM_CDF4(16573, 24629, 28492) },
3924+ { AOM_CDF4(12749, 20846, 25674) },
3925+ { AOM_CDF4(10233, 17878, 22818) },
3926+ { AOM_CDF4(8525, 15332, 20363) },
3927+ { AOM_CDF4(6283, 11632, 16255) },
3928+ { AOM_CDF4(20466, 26511, 29286) },
3929+ { AOM_CDF4(23059, 29174, 31191) },
3930+ { AOM_CDF4(19481, 27263, 30241) },
3931+ { AOM_CDF4(15458, 23631, 28137) },
3932+ { AOM_CDF4(12416, 20608, 25693) },
3933+ { AOM_CDF4(10261, 18011, 23261) },
3934+ { AOM_CDF4(8016, 14655, 19666) } },
3935+ { { AOM_CDF4(17616, 24586, 28112) },
3936+ { AOM_CDF4(15809, 23299, 27155) },
3937+ { AOM_CDF4(10767, 18890, 23793) },
3938+ { AOM_CDF4(7727, 14255, 18865) },
3939+ { AOM_CDF4(6129, 11926, 16882) },
3940+ { AOM_CDF4(4482, 9704, 14861) },
3941+ { AOM_CDF4(3277, 7452, 11522) },
3942+ { AOM_CDF4(22956, 28551, 30730) },
3943+ { AOM_CDF4(22724, 28937, 30961) },
3944+ { AOM_CDF4(18467, 26324, 29580) },
3945+ { AOM_CDF4(13234, 20713, 25649) },
3946+ { AOM_CDF4(11181, 17592, 22481) },
3947+ { AOM_CDF4(8291, 18358, 24576) },
3948+ { AOM_CDF4(7568, 11881, 14984) },
3949+ { AOM_CDF4(24948, 29001, 31147) },
3950+ { AOM_CDF4(25674, 30619, 32151) },
3951+ { AOM_CDF4(20841, 26793, 29603) },
3952+ { AOM_CDF4(14669, 24356, 28666) },
3953+ { AOM_CDF4(11334, 23593, 28219) },
3954+ { AOM_CDF4(8922, 14762, 22873) },
3955+ { AOM_CDF4(8301, 13544, 20535) } } },
3956+ { { { AOM_CDF4(17113, 23733, 27081) },
3957+ { AOM_CDF4(14139, 21406, 25452) },
3958+ { AOM_CDF4(8552, 15002, 19776) },
3959+ { AOM_CDF4(5871, 11120, 15378) },
3960+ { AOM_CDF4(4455, 8616, 12253) },
3961+ { AOM_CDF4(3469, 6910, 10386) },
3962+ { AOM_CDF4(2255, 4553, 6782) },
3963+ { AOM_CDF4(18224, 24376, 27053) },
3964+ { AOM_CDF4(19290, 26710, 29614) },
3965+ { AOM_CDF4(14936, 22991, 27184) },
3966+ { AOM_CDF4(11238, 18951, 23762) },
3967+ { AOM_CDF4(8786, 15617, 20588) },
3968+ { AOM_CDF4(7317, 13228, 18003) },
3969+ { AOM_CDF4(5101, 9512, 13493) },
3970+ { AOM_CDF4(22639, 28222, 30210) },
3971+ { AOM_CDF4(23216, 29331, 31307) },
3972+ { AOM_CDF4(19075, 26762, 29895) },
3973+ { AOM_CDF4(15014, 23113, 27457) },
3974+ { AOM_CDF4(11938, 19857, 24752) },
3975+ { AOM_CDF4(9942, 17280, 22282) },
3976+ { AOM_CDF4(7167, 13144, 17752) } },
3977+ { { AOM_CDF4(15820, 22738, 26488) },
3978+ { AOM_CDF4(13530, 20885, 25216) },
3979+ { AOM_CDF4(8395, 15530, 20452) },
3980+ { AOM_CDF4(6574, 12321, 16380) },
3981+ { AOM_CDF4(5353, 10419, 14568) },
3982+ { AOM_CDF4(4613, 8446, 12381) },
3983+ { AOM_CDF4(3440, 7158, 9903) },
3984+ { AOM_CDF4(24247, 29051, 31224) },
3985+ { AOM_CDF4(22118, 28058, 30369) },
3986+ { AOM_CDF4(16498, 24768, 28389) },
3987+ { AOM_CDF4(12920, 21175, 26137) },
3988+ { AOM_CDF4(10730, 18619, 25352) },
3989+ { AOM_CDF4(10187, 16279, 22791) },
3990+ { AOM_CDF4(9310, 14631, 22127) },
3991+ { AOM_CDF4(24970, 30558, 32057) },
3992+ { AOM_CDF4(24801, 29942, 31698) },
3993+ { AOM_CDF4(22432, 28453, 30855) },
3994+ { AOM_CDF4(19054, 25680, 29580) },
3995+ { AOM_CDF4(14392, 23036, 28109) },
3996+ { AOM_CDF4(12495, 20947, 26650) },
3997+ { AOM_CDF4(12442, 20326, 26214) } } },
3998+ { { { AOM_CDF4(12162, 18785, 22648) },
3999+ { AOM_CDF4(12749, 19697, 23806) },
4000+ { AOM_CDF4(8580, 15297, 20346) },
4001+ { AOM_CDF4(6169, 11749, 16543) },
4002+ { AOM_CDF4(4836, 9391, 13448) },
4003+ { AOM_CDF4(3821, 7711, 11613) },
4004+ { AOM_CDF4(2228, 4601, 7070) },
4005+ { AOM_CDF4(16319, 24725, 28280) },
4006+ { AOM_CDF4(15698, 23277, 27168) },
4007+ { AOM_CDF4(12726, 20368, 25047) },
4008+ { AOM_CDF4(9912, 17015, 21976) },
4009+ { AOM_CDF4(7888, 14220, 19179) },
4010+ { AOM_CDF4(6777, 12284, 17018) },
4011+ { AOM_CDF4(4492, 8590, 12252) },
4012+ { AOM_CDF4(23249, 28904, 30947) },
4013+ { AOM_CDF4(21050, 27908, 30512) },
4014+ { AOM_CDF4(17440, 25340, 28949) },
4015+ { AOM_CDF4(14059, 22018, 26541) },
4016+ { AOM_CDF4(11288, 18903, 23898) },
4017+ { AOM_CDF4(9411, 16342, 21428) },
4018+ { AOM_CDF4(6278, 11588, 15944) } },
4019+ { { AOM_CDF4(13981, 20067, 23226) },
4020+ { AOM_CDF4(16922, 23580, 26783) },
4021+ { AOM_CDF4(11005, 19039, 24487) },
4022+ { AOM_CDF4(7389, 14218, 19798) },
4023+ { AOM_CDF4(5598, 11505, 17206) },
4024+ { AOM_CDF4(6090, 11213, 15659) },
4025+ { AOM_CDF4(3820, 7371, 10119) },
4026+ { AOM_CDF4(21082, 26925, 29675) },
4027+ { AOM_CDF4(21262, 28627, 31128) },
4028+ { AOM_CDF4(18392, 26454, 30437) },
4029+ { AOM_CDF4(14870, 22910, 27096) },
4030+ { AOM_CDF4(12620, 19484, 24908) },
4031+ { AOM_CDF4(9290, 16553, 22802) },
4032+ { AOM_CDF4(6668, 14288, 20004) },
4033+ { AOM_CDF4(27704, 31055, 31949) },
4034+ { AOM_CDF4(24709, 29978, 31788) },
4035+ { AOM_CDF4(21668, 29264, 31657) },
4036+ { AOM_CDF4(18295, 26968, 30074) },
4037+ { AOM_CDF4(16399, 24422, 29313) },
4038+ { AOM_CDF4(14347, 23026, 28104) },
4039+ { AOM_CDF4(12370, 19806, 24477) } } }
4040+ },
4041+ }
4042+};
4043+
4044+static inline int get_qcat_idx(int q) {
4045+ if (q <= 20) return 0;
4046+ if (q <= 60) return 1;
4047+ if (q <= 120) return 2;
4048+ return 3;
4049+}
4050+
4051+static CdfThreadContext cdf_init[4] = {
4052+ [0] = { .cdf = NULL },
4053+ [1] = { .cdf = NULL },
4054+ [2] = { .cdf = NULL },
4055+ [3] = { .cdf = NULL },
4056+};
4057+
4058+void av1_init_states(CdfThreadContext *const cdf, const int qidx) {
4059+ const int qcat = get_qcat_idx(qidx);
4060+ if (cdf_init[qcat].cdf) {
4061+ cdf_thread_ref(cdf, &cdf_init[qcat]);
4062+ return;
4063+ }
4064+
4065+ cdf_thread_alloc(&cdf_init[qcat], NULL);
4066+ cdf_init[qcat].cdf->m = av1_default_cdf;
4067+ memcpy(cdf_init[qcat].cdf->kfym, default_kf_y_mode_cdf,
4068+ sizeof(default_kf_y_mode_cdf));
4069+ cdf_init[qcat].cdf->coef = av1_default_coef_cdf[qcat];
4070+ cdf_init[qcat].cdf->mv = default_mv_cdf;
4071+ cdf_init[qcat].cdf->dmv = default_mv_cdf;
4072+ cdf_thread_ref(cdf, &cdf_init[qcat]);
4073+}
4074+
4075+void av1_update_tile_cdf(const Av1FrameHeader *const hdr,
4076+ CdfContext *const dst,
4077+ const CdfContext *const src)
4078+{
4079+ int i, j, k, l;
4080+
4081+#define update_cdf_1d(n1d, name) \
4082+ do { \
4083+ memcpy(dst->name, src->name, sizeof(*dst->name) * n1d); \
4084+ assert(!dst->name[n1d - 1]); \
4085+ dst->name[n1d] = 0; \
4086+ } while (0)
4087+
4088+#define update_cdf_2d(n1d, n2d, name) \
4089+ for (j = 0; j < (n1d); j++) update_cdf_1d(n2d, name[j])
4090+#define update_cdf_3d(n1d, n2d, n3d, name) \
4091+ for (k = 0; k < (n1d); k++) update_cdf_2d(n2d, n3d, name[k])
4092+#define update_cdf_4d(n1d, n2d, n3d, n4d, name) \
4093+ for (l = 0; l < (n1d); l++) update_cdf_3d(n2d, n3d, n4d, name[l])
4094+#define update_cdf_6d(n1d, n2d, n3d, n4d, n5d, n6d, name) \
4095+ for (n = 0; n < (n1d); n++) \
4096+ for (m = 0; m < (n2d); m++) \
4097+ update_cdf_4d(n3d, n4d, n5d, n6d, name[n][m])
4098+
4099+#define update_bit_0d(name) \
4100+ do { \
4101+ dst->name[0] = src->name[0]; \
4102+ dst->name[1] = 0; \
4103+ } while (0)
4104+
4105+#define update_bit_1d(n1d, name) \
4106+ for (i = 0; i < (n1d); i++) update_bit_0d(name[i])
4107+#define update_bit_2d(n1d, n2d, name) \
4108+ for (j = 0; j < (n1d); j++) update_bit_1d(n2d, name[j])
4109+#define update_bit_3d(n1d, n2d, n3d, name) \
4110+ for (k = 0; k < (n1d); k++) update_bit_2d(n2d, n3d, name[k])
4111+
4112+ update_bit_1d(N_BS_SIZES, m.use_filter_intra);
4113+ update_cdf_1d(5, m.filter_intra);
4114+ update_cdf_3d(2, N_INTRA_PRED_MODES, N_UV_INTRA_PRED_MODES - !k, m.uv_mode);
4115+ update_cdf_2d(8, 7, m.angle_delta);
4116+ update_cdf_3d(N_TX_SIZES - 1, 3, imin(k + 2, 3), m.txsz);
4117+ update_cdf_3d(N_TX_SIZES - 1, N_INTRA_PRED_MODES, 7, m.txtp_intra[1]);
4118+ update_cdf_3d(N_TX_SIZES - 1, N_INTRA_PRED_MODES, 5, m.txtp_intra[2]);
4119+ update_bit_1d(3, m.skip);
4120+ static const uint8_t n_partitions[N_BL_LEVELS] = {
4121+ [BL_128X128] = N_PARTITIONS - 2,
4122+ [BL_64X64] = N_PARTITIONS,
4123+ [BL_32X32] = N_PARTITIONS,
4124+ [BL_16X16] = N_PARTITIONS,
4125+ [BL_8X8] = N_SUB8X8_PARTITIONS,
4126+ };
4127+ update_cdf_3d(N_BL_LEVELS, 4, n_partitions[k], m.partition);
4128+ update_bit_2d(N_TX_SIZES, 13, coef.skip);
4129+ update_cdf_3d(2, 2, 5, coef.eob_bin_16);
4130+ update_cdf_3d(2, 2, 6, coef.eob_bin_32);
4131+ update_cdf_3d(2, 2, 7, coef.eob_bin_64);
4132+ update_cdf_3d(2, 2, 8, coef.eob_bin_128);
4133+ update_cdf_3d(2, 2, 9, coef.eob_bin_256);
4134+ update_cdf_3d(2, 2, 10, coef.eob_bin_512);
4135+ update_cdf_3d(2, 2, 11, coef.eob_bin_1024);
4136+ update_bit_3d(N_TX_SIZES, 2, 11 /*22*/, coef.eob_hi_bit);
4137+ update_cdf_4d(N_TX_SIZES, 2, 4, 3, coef.eob_base_tok);
4138+ update_cdf_4d(N_TX_SIZES, 2, 41 /*42*/, 4, coef.base_tok);
4139+ update_bit_2d(2, 3, coef.dc_sign);
4140+ update_cdf_4d(4, 2, 21, 4, coef.br_tok);
4141+ update_cdf_2d(3, NUM_SEGMENTS, m.seg_id);
4142+ update_cdf_1d(8, m.cfl_sign);
4143+ update_cdf_2d(6, 16, m.cfl_alpha);
4144+ update_bit_0d(m.restore_wiener);
4145+ update_bit_0d(m.restore_sgrproj);
4146+ update_cdf_1d(3, m.restore_switchable);
4147+ update_cdf_1d(4, m.delta_q);
4148+ update_cdf_2d(5, 4, m.delta_lf);
4149+ update_bit_2d(7, 3, m.pal_y);
4150+ update_bit_1d(2, m.pal_uv);
4151+ update_cdf_3d(2, 7, 7, m.pal_sz);
4152+ update_cdf_4d(2, 7, 5, k + 2, m.color_map);
4153+
4154+ if (!(hdr->frame_type & 1)) {
4155+ update_bit_0d(m.intrabc);
4156+
4157+ update_cdf_1d(N_MV_JOINTS, dmv.joint);
4158+ for (k = 0; k < 2; k++) {
4159+ update_cdf_1d(11, dmv.comp[k].classes);
4160+ update_bit_0d(dmv.comp[k].class0);
4161+ update_bit_1d(10, dmv.comp[k].classN);
4162+ update_bit_0d(dmv.comp[k].sign);
4163+ }
4164+ return;
4165+ }
4166+
4167+ update_bit_1d(3, m.skip_mode);
4168+ update_cdf_2d(4, N_INTRA_PRED_MODES, m.y_mode);
4169+ update_cdf_3d(2, 8, N_SWITCHABLE_FILTERS, m.filter);
4170+ update_bit_1d(6, m.newmv_mode);
4171+ update_bit_1d(2, m.globalmv_mode);
4172+ update_bit_1d(6, m.refmv_mode);
4173+ update_bit_1d(3, m.drl_bit);
4174+ update_cdf_2d(8, N_COMP_INTER_PRED_MODES, m.comp_inter_mode);
4175+ update_bit_1d(4, m.intra);
4176+ update_bit_1d(5, m.comp);
4177+ update_bit_1d(5, m.comp_dir);
4178+ update_bit_1d(6, m.jnt_comp);
4179+ update_bit_1d(6, m.mask_comp);
4180+ update_bit_1d(9, m.wedge_comp);
4181+ update_cdf_2d(9, 16, m.wedge_idx);
4182+ update_bit_2d(6, 3, m.ref);
4183+ update_bit_2d(3, 3, m.comp_fwd_ref);
4184+ update_bit_2d(2, 3, m.comp_bwd_ref);
4185+ update_bit_2d(3, 3, m.comp_uni_ref);
4186+ update_bit_2d(7, 3, m.txpart);
4187+ update_cdf_2d(N_TX_SIZES - 1, 16, m.txtp_inter[1]);
4188+ update_cdf_2d(N_TX_SIZES - 1, 12, m.txtp_inter[2]);
4189+ update_cdf_2d(N_TX_SIZES - 1, 2, m.txtp_inter[3]);
4190+ update_bit_1d(3, m.seg_pred);
4191+ update_bit_1d(4, m.interintra);
4192+ update_bit_1d(7, m.interintra_wedge);
4193+ update_cdf_2d(4, 4, m.interintra_mode);
4194+ update_cdf_2d(N_BS_SIZES, 3, m.motion_mode);
4195+ update_bit_1d(N_BS_SIZES, m.obmc);
4196+
4197+ update_cdf_1d(N_MV_JOINTS, mv.joint);
4198+ for (k = 0; k < 2; k++) {
4199+ update_cdf_1d(11, mv.comp[k].classes);
4200+ update_bit_0d(mv.comp[k].class0);
4201+ update_bit_1d(10, mv.comp[k].classN);
4202+ update_cdf_2d(2, 4, mv.comp[k].class0_fp);
4203+ update_cdf_1d(4, mv.comp[k].classN_fp);
4204+ update_bit_0d(mv.comp[k].class0_hp);
4205+ update_bit_0d(mv.comp[k].classN_hp);
4206+ update_bit_0d(mv.comp[k].sign);
4207+ }
4208+}
4209+
4210+/*
4211+ * CDF threading wrappers.
4212+ */
4213+void cdf_thread_alloc(CdfThreadContext *const cdf, struct thread_data *const t) {
4214+ cdf->ref = dav1d_ref_create(sizeof(CdfContext) +
4215+ (t != NULL) * sizeof(atomic_uint));
4216+ cdf->cdf = cdf->ref->data;
4217+ if (t) {
4218+ cdf->progress = (atomic_uint *) &cdf->cdf[1];
4219+ atomic_init(cdf->progress, 0);
4220+ cdf->t = t;
4221+ }
4222+}
4223+
4224+void cdf_thread_ref(CdfThreadContext *const dst, CdfThreadContext *const src) {
4225+ dav1d_ref_inc(src->ref);
4226+ *dst = *src;
4227+}
4228+
4229+void cdf_thread_unref(CdfThreadContext *const cdf) {
4230+ dav1d_ref_dec(cdf->ref);
4231+ memset(cdf, 0, sizeof(*cdf));
4232+}
4233+
4234+void cdf_thread_wait(CdfThreadContext *const cdf) {
4235+ if (!cdf->t) return;
4236+
4237+ if (atomic_load(cdf->progress)) return;
4238+ pthread_mutex_lock(&cdf->t->lock);
4239+ while (!atomic_load(cdf->progress))
4240+ pthread_cond_wait(&cdf->t->cond, &cdf->t->lock);
4241+ pthread_mutex_unlock(&cdf->t->lock);
4242+}
4243+
4244+void cdf_thread_signal(CdfThreadContext *const cdf) {
4245+ if (!cdf->t) return;
4246+
4247+ pthread_mutex_lock(&cdf->t->lock);
4248+ atomic_store(cdf->progress, 1);
4249+ pthread_cond_broadcast(&cdf->t->cond);
4250+ pthread_mutex_unlock(&cdf->t->lock);
4251+}
src/cdf.h+148−0
@@ -0,0 +1,148 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __AV1_CDF_H__
29+#define __AV1_CDF_H__
30+
31+#include <stdint.h>
32+
33+#include "src/levels.h"
34+#include "src/ref.h"
35+#include "src/thread_data.h"
36+
37+typedef struct CdfModeContext {
38+ uint16_t y_mode[4][N_INTRA_PRED_MODES + 1];
39+ uint16_t use_filter_intra[N_BS_SIZES][2];
40+ uint16_t filter_intra[5 + 1];
41+ uint16_t uv_mode[2][N_INTRA_PRED_MODES][N_UV_INTRA_PRED_MODES + 1];
42+ uint16_t angle_delta[8][8];
43+ uint16_t filter[2][8][N_SWITCHABLE_FILTERS + 1];
44+ uint16_t newmv_mode[6][2];
45+ uint16_t globalmv_mode[2][2];
46+ uint16_t refmv_mode[6][2];
47+ uint16_t drl_bit[3][2];
48+ uint16_t comp_inter_mode[8][N_COMP_INTER_PRED_MODES + 1];
49+ uint16_t intra[4][2];
50+ uint16_t comp[5][2];
51+ uint16_t comp_dir[5][2];
52+ uint16_t jnt_comp[6][2];
53+ uint16_t mask_comp[6][2];
54+ uint16_t wedge_comp[9][2];
55+ uint16_t wedge_idx[9][16 + 1];
56+ uint16_t interintra[7][2];
57+ uint16_t interintra_mode[4][5];
58+ uint16_t interintra_wedge[7][2];
59+ uint16_t ref[6][3][2];
60+ uint16_t comp_fwd_ref[3][3][2];
61+ uint16_t comp_bwd_ref[2][3][2];
62+ uint16_t comp_uni_ref[3][3][2];
63+ uint16_t txsz[N_TX_SIZES - 1][3][4];
64+ uint16_t txpart[7][3][2];
65+ uint16_t txtp_inter[4][N_TX_SIZES][N_TX_TYPES + 1];
66+ uint16_t txtp_intra[3][N_TX_SIZES][N_INTRA_PRED_MODES][N_TX_TYPES + 1];
67+ uint16_t skip[3][2];
68+ uint16_t skip_mode[3][2];
69+ uint16_t partition[N_BL_LEVELS][4][N_PARTITIONS + 1];
70+ uint16_t seg_pred[3][2];
71+ uint16_t seg_id[3][NUM_SEGMENTS + 1];
72+ uint16_t cfl_sign[8 + 1];
73+ uint16_t cfl_alpha[6][16 + 1];
74+ uint16_t restore_wiener[2];
75+ uint16_t restore_sgrproj[2];
76+ uint16_t restore_switchable[3 + 1];
77+ uint16_t delta_q[4 + 1];
78+ uint16_t delta_lf[5][4 + 1];
79+ uint16_t obmc[N_BS_SIZES][2];
80+ uint16_t motion_mode[N_BS_SIZES][3 + 1];
81+ uint16_t pal_y[7][3][2];
82+ uint16_t pal_uv[2][2];
83+ uint16_t pal_sz[2][7][7 + 1];
84+ uint16_t color_map[2][7][5][8 + 1];
85+ uint16_t intrabc[2];
86+} CdfModeContext;
87+
88+typedef struct CdfCoefContext {
89+ uint16_t skip[N_TX_SIZES][13][2];
90+ uint16_t eob_bin_16[2][2][6];
91+ uint16_t eob_bin_32[2][2][7];
92+ uint16_t eob_bin_64[2][2][8];
93+ uint16_t eob_bin_128[2][2][9];
94+ uint16_t eob_bin_256[2][2][10];
95+ uint16_t eob_bin_512[2][2][11];
96+ uint16_t eob_bin_1024[2][2][12];
97+ uint16_t eob_hi_bit[N_TX_SIZES][2][11 /*22*/][2];
98+ uint16_t eob_base_tok[N_TX_SIZES][2][4][4];
99+ uint16_t base_tok[N_TX_SIZES][2][41][5];
100+ uint16_t dc_sign[2][3][2];
101+ uint16_t br_tok[4 /*5*/][2][21][5];
102+} CdfCoefContext;
103+
104+typedef struct CdfMvComponent {
105+ uint16_t classes[11 + 1];
106+ uint16_t class0[2];
107+ uint16_t classN[10][2];
108+ uint16_t class0_fp[2][4 + 1];
109+ uint16_t classN_fp[4 + 1];
110+ uint16_t class0_hp[2];
111+ uint16_t classN_hp[2];
112+ uint16_t sign[2];
113+} CdfMvComponent;
114+
115+typedef struct CdfMvContext {
116+ CdfMvComponent comp[2];
117+ uint16_t joint[N_MV_JOINTS + 1];
118+} CdfMvContext;
119+
120+typedef struct CdfContext {
121+ CdfModeContext m;
122+ uint16_t kfym[5][5][N_INTRA_PRED_MODES + 1];
123+ CdfCoefContext coef;
124+ CdfMvContext mv, dmv;
125+} CdfContext;
126+
127+typedef struct CdfThreadContext {
128+ CdfContext *cdf;
129+ Dav1dRef *ref; ///< allocation origin
130+ struct thread_data *t;
131+ atomic_uint *progress;
132+} CdfThreadContext;
133+
134+void av1_init_states(CdfThreadContext *cdf, int qidx);
135+void av1_update_tile_cdf(const Av1FrameHeader *hdr, CdfContext *dst,
136+ const CdfContext *src);
137+
138+void cdf_thread_alloc(CdfThreadContext *cdf, struct thread_data *t);
139+void cdf_thread_ref(CdfThreadContext *dst, CdfThreadContext *src);
140+void cdf_thread_unref(CdfThreadContext *cdf);
141+
142+/*
143+ * These are binary signals (so a signal is either "done" or "not done").
144+ */
145+void cdf_thread_wait(CdfThreadContext *cdf);
146+void cdf_thread_signal(CdfThreadContext *cdf);
147+
148+#endif /* __AV1_CDF_H__ */
src/data.c+54−0
@@ -0,0 +1,54 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#include "config.h"
29+
30+#include <errno.h>
31+#include <stdlib.h>
32+#include <string.h>
33+
34+#include "dav1d/data.h"
35+
36+#include "common/validate.h"
37+
38+#include "src/ref.h"
39+
40+int dav1d_data_create(Dav1dData *const buf, const size_t sz) {
41+ validate_input_or_ret(buf != NULL, -EINVAL);
42+
43+ buf->ref = dav1d_ref_create(sz);
44+ if (!buf->ref) return -ENOMEM;
45+ buf->data = buf->ref->data;
46+ buf->sz = sz;
47+
48+ return 0;
49+}
50+
51+void dav1d_data_unref(Dav1dData *const buf) {
52+ dav1d_ref_dec(buf->ref);
53+ memset(buf, 0, sizeof(*buf));
54+}
src/data.h+35−0
@@ -0,0 +1,35 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __DAV1D_SRC_DATA_H__
29+#define __DAV1D_SRC_DATA_H__
30+
31+#include "dav1d/data.h"
32+
33+void dav1d_data_unref(Dav1dData *buf);
34+
35+#endif /* __DAV1D_SRC_DATA_H__ */
src/decode.c+2908−0
@@ -0,0 +1,2908 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#include "config.h"
29+
30+#include <errno.h>
31+#include <limits.h>
32+#include <string.h>
33+#include <stdio.h>
34+#include <inttypes.h>
35+
36+#include "dav1d/data.h"
37+
38+#include "common/intops.h"
39+#include "common/mem.h"
40+
41+#include "src/decode.h"
42+#include "src/dequant_tables.h"
43+#include "src/env.h"
44+#include "src/qm.h"
45+#include "src/recon.h"
46+#include "src/ref.h"
47+#include "src/tables.h"
48+#include "src/thread_task.h"
49+#include "src/warpmv.h"
50+
51+static void init_quant_tables(const Av1SequenceHeader *const seq_hdr,
52+ const Av1FrameHeader *const frame_hdr,
53+ const int qidx, uint16_t (*dq)[3][2])
54+{
55+ for (int i = 0; i < (frame_hdr->segmentation.enabled ? 8 : 1); i++) {
56+ const int yac = frame_hdr->segmentation.enabled ?
57+ iclip_u8(qidx + frame_hdr->segmentation.seg_data.d[i].delta_q) : qidx;
58+ const int ydc = iclip_u8(yac + frame_hdr->quant.ydc_delta);
59+ const int uac = iclip_u8(yac + frame_hdr->quant.uac_delta);
60+ const int udc = iclip_u8(yac + frame_hdr->quant.udc_delta);
61+ const int vac = iclip_u8(yac + frame_hdr->quant.vac_delta);
62+ const int vdc = iclip_u8(yac + frame_hdr->quant.vdc_delta);
63+
64+ dq[i][0][0] = dav1d_dq_tbl[seq_hdr->bpc > 8][ydc][0];
65+ dq[i][0][1] = dav1d_dq_tbl[seq_hdr->bpc > 8][yac][1];
66+ dq[i][1][0] = dav1d_dq_tbl[seq_hdr->bpc > 8][udc][0];
67+ dq[i][1][1] = dav1d_dq_tbl[seq_hdr->bpc > 8][uac][1];
68+ dq[i][2][0] = dav1d_dq_tbl[seq_hdr->bpc > 8][vdc][0];
69+ dq[i][2][1] = dav1d_dq_tbl[seq_hdr->bpc > 8][vac][1];
70+ }
71+}
72+
73+static int read_mv_component_diff(Dav1dTileContext *const t,
74+ CdfMvComponent *const mv_comp,
75+ const int have_fp)
76+{
77+ Dav1dTileState *const ts = t->ts;
78+ const Dav1dFrameContext *const f = t->f;
79+ const int have_hp = f->frame_hdr.hp;
80+ const int sign = msac_decode_bool_adapt(&ts->msac, mv_comp->sign);
81+ const int cl = msac_decode_symbol_adapt(&ts->msac, mv_comp->classes, 11);
82+ int up, fp, hp;
83+
84+ if (!cl) {
85+ up = msac_decode_bool_adapt(&ts->msac, mv_comp->class0);
86+ if (have_fp) {
87+ fp = msac_decode_symbol_adapt(&ts->msac, mv_comp->class0_fp[up], 4);
88+ hp = have_hp ? msac_decode_bool_adapt(&ts->msac, mv_comp->class0_hp) : 1;
89+ } else {
90+ fp = 3;
91+ hp = 1;
92+ }
93+ } else {
94+ up = 1 << cl;
95+ for (int n = 0; n < cl; n++)
96+ up |= msac_decode_bool_adapt(&ts->msac, mv_comp->classN[n]) << n;
97+ if (have_fp) {
98+ fp = msac_decode_symbol_adapt(&ts->msac, mv_comp->classN_fp, 4);
99+ hp = have_hp ? msac_decode_bool_adapt(&ts->msac, mv_comp->classN_hp) : 1;
100+ } else {
101+ fp = 3;
102+ hp = 1;
103+ }
104+ }
105+
106+ const int diff = ((up << 3) | (fp << 1) | hp) + 1;
107+
108+ return sign ? -diff : diff;
109+}
110+
111+static void read_mv_residual(Dav1dTileContext *const t, mv *const ref_mv,
112+ CdfMvContext *const mv_cdf, const int have_fp)
113+{
114+ switch (msac_decode_symbol_adapt(&t->ts->msac, t->ts->cdf.mv.joint, N_MV_JOINTS)) {
115+ case MV_JOINT_HV:
116+ ref_mv->y += read_mv_component_diff(t, &mv_cdf->comp[0], have_fp);
117+ ref_mv->x += read_mv_component_diff(t, &mv_cdf->comp[1], have_fp);
118+ break;
119+ case MV_JOINT_H:
120+ ref_mv->x += read_mv_component_diff(t, &mv_cdf->comp[1], have_fp);
121+ break;
122+ case MV_JOINT_V:
123+ ref_mv->y += read_mv_component_diff(t, &mv_cdf->comp[0], have_fp);
124+ break;
125+ default:
126+ break;
127+ }
128+}
129+
130+static void read_tx_tree(Dav1dTileContext *const t,
131+ const enum RectTxfmSize from,
132+ const int depth, uint16_t *const masks,
133+ const int x_off, const int y_off)
134+{
135+ const Dav1dFrameContext *const f = t->f;
136+ const int bx4 = t->bx & 31, by4 = t->by & 31;
137+ const TxfmInfo *const t_dim = &av1_txfm_dimensions[from];
138+ const int txw = t_dim->lw, txh = t_dim->lh;
139+ int is_split;
140+
141+ if (depth < 2 && from > (int) TX_4X4) {
142+ const int cat = 2 * (TX_64X64 - t_dim->max) - depth;
143+ const int a = t->a->tx[bx4] < txw;
144+ const int l = t->l.tx[by4] < txh;
145+
146+ is_split = msac_decode_bool_adapt(&t->ts->msac, t->ts->cdf.m.txpart[cat][a + l]);
147+ if (is_split)
148+ masks[depth] |= 1 << (y_off * 4 + x_off);
149+ } else {
150+ is_split = 0;
151+ }
152+
153+ if (is_split && t_dim->max > TX_8X8) {
154+ const enum RectTxfmSize sub = t_dim->sub;
155+ const TxfmInfo *const sub_t_dim = &av1_txfm_dimensions[sub];
156+ const int txsw = sub_t_dim->w, txsh = sub_t_dim->h;
157+
158+ read_tx_tree(t, sub, depth + 1, masks, x_off * 2 + 0, y_off * 2 + 0);
159+ t->bx += txsw;
160+ if (txw >= txh && t->bx < f->bw)
161+ read_tx_tree(t, sub, depth + 1, masks, x_off * 2 + 1, y_off * 2 + 0);
162+ t->bx -= txsw;
163+ t->by += txsh;
164+ if (txh >= txw && t->by < f->bh) {
165+ read_tx_tree(t, sub, depth + 1, masks, x_off * 2 + 0, y_off * 2 + 1);
166+ t->bx += txsw;
167+ if (txw >= txh && t->bx < f->bw)
168+ read_tx_tree(t, sub, depth + 1, masks,
169+ x_off * 2 + 1, y_off * 2 + 1);
170+ t->bx -= txsw;
171+ }
172+ t->by -= txsh;
173+ } else {
174+ memset(&t->a->tx[bx4], is_split ? TX_4X4 : txw, t_dim->w);
175+ memset(&t->l.tx[by4], is_split ? TX_4X4 : txh, t_dim->h);
176+ }
177+}
178+
179+int av1_neg_deinterleave(int diff, int ref, int max) {
180+ if (!ref) return diff;
181+ if (ref >= (max - 1)) return max - diff - 1;
182+ if (2 * ref < max) {
183+ if (diff <= 2 * ref) {
184+ if (diff & 1)
185+ return ref + ((diff + 1) >> 1);
186+ else
187+ return ref - (diff >> 1);
188+ }
189+ return diff;
190+ } else {
191+ if (diff <= 2 * (max - ref - 1)) {
192+ if (diff & 1)
193+ return ref + ((diff + 1) >> 1);
194+ else
195+ return ref - (diff >> 1);
196+ }
197+ return max - (diff + 1);
198+ }
199+}
200+
201+static void find_matching_ref(const Dav1dTileContext *const t,
202+ const enum EdgeFlags intra_edge_flags,
203+ const int bw4, const int bh4,
204+ const int w4, const int h4,
205+ const int have_left, const int have_top,
206+ const int ref, uint64_t masks[2])
207+{
208+ const Dav1dFrameContext *const f = t->f;
209+ const ptrdiff_t b4_stride = f->b4_stride;
210+ const refmvs *const r = &f->mvs[t->by * b4_stride + t->bx];
211+ int count = 0;
212+ int have_topleft = have_top && have_left;
213+ int have_topright = imax(bw4, bh4) < 32 &&
214+ have_top && t->bx + bw4 < t->ts->tiling.col_end &&
215+ (intra_edge_flags & EDGE_I444_TOP_HAS_RIGHT);
216+
217+#define bs(rp) av1_block_dimensions[sbtype_to_bs[(rp)->sb_type]]
218+#define matches(rp) ((rp)->ref[0] == ref + 1 && (rp)->ref[1] == -1)
219+
220+ if (have_top) {
221+ const refmvs *r2 = &r[-b4_stride];
222+ if (matches(r2)) {
223+ masks[0] |= 1;
224+ count = 1;
225+ }
226+ int aw4 = bs(r2)[0];
227+ if (aw4 >= bw4) {
228+ const int off = t->bx & (aw4 - 1);
229+ if (off) have_topleft = 0;
230+ if (aw4 - off > bw4) have_topright = 0;
231+ } else {
232+ unsigned mask = 1 << aw4;
233+ for (int x = aw4; x < w4; x += aw4) {
234+ r2 += aw4;
235+ if (matches(r2)) {
236+ masks[0] |= mask;
237+ if (++count >= 8) return;
238+ }
239+ aw4 = bs(r2)[0];
240+ mask <<= aw4;
241+ }
242+ }
243+ }
244+ if (have_left) {
245+ const refmvs *r2 = &r[-1];
246+ if (matches(r2)) {
247+ masks[1] |= 1;
248+ if (++count >= 8) return;
249+ }
250+ int lh4 = bs(r2)[1];
251+ if (lh4 >= bh4) {
252+ if (t->by & (lh4 - 1)) have_topleft = 0;
253+ } else {
254+ unsigned mask = 1 << lh4;
255+ for (int y = lh4; y < h4; y += lh4) {
256+ r2 += lh4 * b4_stride;
257+ if (matches(r2)) {
258+ masks[1] |= mask;
259+ if (++count >= 8) return;
260+ }
261+ lh4 = bs(r2)[1];
262+ mask <<= lh4;
263+ }
264+ }
265+ }
266+ if (have_topleft && matches(&r[-(1 + b4_stride)])) {
267+ masks[1] |= 1ULL << 32;
268+ if (++count >= 8) return;
269+ }
270+ if (have_topright && matches(&r[bw4 - b4_stride])) {
271+ masks[0] |= 1ULL << 32;
272+ }
273+#undef matches
274+}
275+
276+static void derive_warpmv(const Dav1dTileContext *const t,
277+ const int bw4, const int bh4,
278+ const uint64_t masks[2], const struct mv mv,
279+ WarpedMotionParams *const wmp)
280+{
281+ int pts[8][2 /* in, out */][2 /* x, y */], np = 0;
282+ const Dav1dFrameContext *const f = t->f;
283+ const ptrdiff_t b4_stride = f->b4_stride;
284+ const refmvs *const r = &f->mvs[t->by * b4_stride + t->bx];
285+
286+#define add_sample(dx, dy, sx, sy, rp) do { \
287+ pts[np][0][0] = 16 * (2 * dx + sx * bs(rp)[0]) - 8; \
288+ pts[np][0][1] = 16 * (2 * dy + sy * bs(rp)[1]) - 8; \
289+ pts[np][1][0] = pts[np][0][0] + (rp)->mv[0].x; \
290+ pts[np][1][1] = pts[np][0][1] + (rp)->mv[0].y; \
291+ np++; \
292+} while (0)
293+
294+ // use masks[] to find the projectable motion vectors in the edges
295+ if ((unsigned) masks[0] == 1 && !(masks[1] >> 32)) {
296+ const int off = t->bx & (bs(&r[-b4_stride])[0] - 1);
297+ add_sample(-off, 0, 1, -1, &r[-b4_stride]);
298+ } else for (unsigned off = 0, xmask = masks[0]; np < 8 && xmask;) { // top
299+ const int tz = __builtin_ctz(xmask);
300+ off += tz;
301+ add_sample(off, 0, 1, -1, &r[off - b4_stride]);
302+ xmask >>= tz + 1;
303+ off += 1;
304+ }
305+ if (np < 8 && masks[1] == 1) {
306+ const int off = t->by & (bs(&r[-1])[1] - 1);
307+ add_sample(0, -off, -1, 1, &r[-1 - off * b4_stride]);
308+ } else for (unsigned off = 0, ymask = masks[1]; np < 8 && ymask;) { // left
309+ const int tz = __builtin_ctz(ymask);
310+ off += tz;
311+ add_sample(0, off, -1, 1, &r[off * b4_stride - 1]);
312+ ymask >>= tz + 1;
313+ off += 1;
314+ }
315+ if (np < 8 && masks[1] >> 32) // top/left
316+ add_sample(0, 0, -1, -1, &r[-(1 + b4_stride)]);
317+ if (np < 8 && masks[0] >> 32) // top/right
318+ add_sample(bw4, 0, 1, -1, &r[bw4 - b4_stride]);
319+ assert(np > 0 && np <= 8);
320+#undef bs
321+
322+ // select according to motion vector difference against a threshold
323+ int mvd[8], ret = 0;
324+ const int thresh = 4 * iclip(imax(bw4, bh4), 4, 28);
325+ for (int i = 0; i < np; i++) {
326+ mvd[i] = labs(pts[i][1][0] - pts[i][0][0] - mv.x) +
327+ labs(pts[i][1][1] - pts[i][0][1] - mv.y);
328+ if (mvd[i] > thresh)
329+ mvd[i] = -1;
330+ else
331+ ret++;
332+ }
333+ if (!ret) {
334+ ret = 1;
335+ } else for (int i = 0, j = np - 1, k = 0; k < np - ret; k++, i++, j--) {
336+ while (mvd[i] != -1) i++;
337+ while (mvd[j] == -1) j--;
338+ assert(i != j);
339+ if (i > j) break;
340+ // replace the discarded samples;
341+ mvd[i] = mvd[j];
342+ memcpy(pts[i], pts[j], sizeof(*pts));
343+ }
344+
345+ if (!find_affine_int(pts, ret, bw4, bh4, mv, wmp, t->bx, t->by) &&
346+ !get_shear_params(wmp))
347+ {
348+ wmp->type = WM_TYPE_AFFINE;
349+ } else
350+ wmp->type = WM_TYPE_IDENTITY;
351+}
352+
353+static inline int findoddzero(const uint8_t *buf, int len) {
354+ for (int n = 0; n < len; n++)
355+ if (!buf[n * 2]) return 1;
356+ return 0;
357+}
358+
359+static void read_pal_plane(Dav1dTileContext *const t, Av1Block *const b,
360+ const int pl, const int sz_ctx,
361+ const int bx4, const int by4)
362+{
363+ Dav1dTileState *const ts = t->ts;
364+ const Dav1dFrameContext *const f = t->f;
365+ const int pal_sz = b->pal_sz[pl] = 2 + msac_decode_symbol_adapt(&ts->msac,
366+ ts->cdf.m.pal_sz[pl][sz_ctx], 7);
367+ uint16_t cache[16], used_cache[8];
368+ int l_cache = pl ? t->pal_sz_uv[1][by4] : t->l.pal_sz[by4];
369+ int n_cache = 0;
370+ // don't reuse above palette outside SB64 boundaries
371+ int a_cache = by4 & 15 ? pl ? t->pal_sz_uv[0][bx4] : t->a->pal_sz[bx4] : 0;
372+ const uint16_t *l = t->al_pal[1][by4][pl], *a = t->al_pal[0][bx4][pl];
373+
374+ // fill/sort cache
375+ while (l_cache && a_cache) {
376+ if (*l < *a) {
377+ if (!n_cache || cache[n_cache - 1] != *l)
378+ cache[n_cache++] = *l;
379+ l++;
380+ l_cache--;
381+ } else {
382+ if (*a == *l) {
383+ l++;
384+ l_cache--;
385+ }
386+ if (!n_cache || cache[n_cache - 1] != *a)
387+ cache[n_cache++] = *a;
388+ a++;
389+ a_cache--;
390+ }
391+ }
392+ if (l_cache) {
393+ do {
394+ if (!n_cache || cache[n_cache - 1] != *l)
395+ cache[n_cache++] = *l;
396+ l++;
397+ } while (--l_cache > 0);
398+ } else if (a_cache) {
399+ do {
400+ if (!n_cache || cache[n_cache - 1] != *a)
401+ cache[n_cache++] = *a;
402+ a++;
403+ } while (--a_cache > 0);
404+ }
405+
406+ // find reused cache entries
407+ int i = 0;
408+ for (int n = 0; n < n_cache && i < pal_sz; n++)
409+ if (msac_decode_bool(&ts->msac, 128 << 7))
410+ used_cache[i++] = cache[n];
411+ const int n_used_cache = i;
412+
413+ // parse new entries
414+ uint16_t *const pal = f->frame_thread.pass ?
415+ f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
416+ ((t->bx >> 1) + (t->by & 1))][pl] : t->pal[pl];
417+ if (i < pal_sz) {
418+ int prev = pal[i++] = msac_decode_bools(&ts->msac, f->cur.p.p.bpc);
419+
420+ if (i < pal_sz) {
421+ int bits = f->cur.p.p.bpc - 3 + msac_decode_bools(&ts->msac, 2);
422+ const int max = (1 << f->cur.p.p.bpc) - 1;
423+
424+ do {
425+ const int delta = msac_decode_bools(&ts->msac, bits);
426+ prev = pal[i++] = imin(prev + delta + !pl, max);
427+ if (prev + !pl >= max) {
428+ for (; i < pal_sz; i++)
429+ pal[i] = pal[i - 1];
430+ break;
431+ }
432+ bits = imin(bits, 1 + ulog2(max - prev - !pl));
433+ } while (i < pal_sz);
434+ }
435+
436+ // merge cache+new entries
437+ int n = 0, m = n_used_cache;
438+ for (i = 0; i < pal_sz; i++) {
439+ if (n < n_used_cache && (m >= pal_sz || used_cache[n] <= pal[m])) {
440+ pal[i] = used_cache[n++];
441+ } else {
442+ assert(m < pal_sz);
443+ pal[i] = pal[m++];
444+ }
445+ }
446+ } else {
447+ memcpy(pal, used_cache, n_used_cache * sizeof(*used_cache));
448+ }
449+
450+ if (DEBUG_BLOCK_INFO) {
451+ printf("Post-pal[pl=%d,sz=%d,cache_size=%d,used_cache=%d]: r=%d, cache=",
452+ pl, b->pal_sz[pl], n_cache, n_used_cache, ts->msac.rng);
453+ for (int n = 0; n < n_cache; n++)
454+ printf("%c%02x", n ? ' ' : '[', cache[n]);
455+ printf("%s, pal=", n_cache ? "]" : "[]");
456+ for (int n = 0; n < b->pal_sz[0]; n++)
457+ printf("%c%02x", n ? ' ' : '[', pal[n]);
458+ printf("]\n");
459+ }
460+}
461+
462+static void read_pal_uv(Dav1dTileContext *const t, Av1Block *const b,
463+ const int sz_ctx, const int cbx4, const int cby4)
464+{
465+ read_pal_plane(t, b, 1, sz_ctx, cbx4, cby4);
466+
467+ // V pal coding
468+ Dav1dTileState *const ts = t->ts;
469+ const Dav1dFrameContext *const f = t->f;
470+ uint16_t *const pal = f->frame_thread.pass ?
471+ f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
472+ ((t->bx >> 1) + (t->by & 1))][2] : t->pal[2];
473+ if (msac_decode_bool(&ts->msac, 128 << 7)) {
474+ const int bits = f->cur.p.p.bpc - 4 + msac_decode_bools(&ts->msac, 2);
475+ int prev = pal[0] = msac_decode_bools(&ts->msac, f->cur.p.p.bpc);
476+ const int max = (1 << f->cur.p.p.bpc) - 1;
477+ for (int i = 1; i < b->pal_sz[1]; i++) {
478+ int delta = msac_decode_bools(&ts->msac, bits);
479+ if (delta && msac_decode_bool(&ts->msac, 128 << 7)) delta = -delta;
480+ prev = pal[i] = (prev + delta) & max;
481+ }
482+ } else {
483+ for (int i = 0; i < b->pal_sz[1]; i++)
484+ pal[i] = msac_decode_bools(&ts->msac, f->cur.p.p.bpc);
485+ }
486+ if (DEBUG_BLOCK_INFO) {
487+ printf("Post-pal[pl=2]: r=%d ", ts->msac.rng);
488+ for (int n = 0; n < b->pal_sz[1]; n++)
489+ printf("%c%02x", n ? ' ' : '[', pal[n]);
490+ printf("]\n");
491+ }
492+}
493+
494+// meant to be SIMD'able, so that theoretical complexity of this function
495+// times block size goes from w4*h4 to w4+h4-1
496+// a and b are previous two lines containing (a) top/left entries or (b)
497+// top/left entries, with a[0] being either the first top or first left entry,
498+// depending on top_offset being 1 or 0, and b being the first top/left entry
499+// for whichever has one. left_offset indicates whether the (len-1)th entry
500+// has a left neighbour.
501+// output is order[] and ctx for each member of this diagonal.
502+static void order_palette(const uint8_t *pal_idx, const ptrdiff_t stride,
503+ const int i, const int first, const int last,
504+ uint8_t (*const order)[8], uint8_t *const ctx)
505+{
506+ int have_top = i > first;
507+
508+ pal_idx += first + (i - first) * stride;
509+ for (int j = first, n = 0; j >= last; have_top = 1, j--, n++, pal_idx += stride - 1) {
510+ const int have_left = j > 0;
511+
512+ assert(have_left || have_top);
513+
514+#define add(v_in) do { \
515+ const int v = v_in; \
516+ assert(v < 8U); \
517+ order[n][o_idx++] = v; \
518+ mask |= 1 << v; \
519+ } while (0)
520+
521+ unsigned mask = 0;
522+ int o_idx = 0;
523+ if (!have_left) {
524+ ctx[n] = 0;
525+ add(pal_idx[-stride]);
526+ } else if (!have_top) {
527+ ctx[n] = 0;
528+ add(pal_idx[-1]);
529+ } else {
530+ const int l = pal_idx[-1], t = pal_idx[-stride], tl = pal_idx[-(stride + 1)];
531+ const int same_t_l = t == l;
532+ const int same_t_tl = t == tl;
533+ const int same_l_tl = l == tl;
534+ const int same_all = same_t_l & same_t_tl & same_l_tl;
535+
536+ if (same_all) {
537+ ctx[n] = 4;
538+ add(t);
539+ } else if (same_t_l) {
540+ ctx[n] = 3;
541+ add(t);
542+ add(tl);
543+ } else if (same_t_tl | same_l_tl) {
544+ ctx[n] = 2;
545+ add(tl);
546+ add(same_t_tl ? l : t);
547+ } else {
548+ ctx[n] = 1;
549+ add(imin(t, l));
550+ add(imax(t, l));
551+ add(tl);
552+ }
553+ }
554+ for (unsigned m = 1, bit = 0; m < 0x100; m <<= 1, bit++)
555+ if (!(mask & m))
556+ order[n][o_idx++] = bit;
557+ assert(o_idx == 8);
558+#undef add
559+ }
560+}
561+
562+static void read_pal_indices(Dav1dTileContext *const t,
563+ uint8_t *const pal_idx,
564+ const Av1Block *const b, const int pl,
565+ const int w4, const int h4,
566+ const int bw4, const int bh4)
567+{
568+ Dav1dTileState *const ts = t->ts;
569+ const ptrdiff_t stride = bw4 * 4;
570+ pal_idx[0] = msac_decode_uniform(&ts->msac, b->pal_sz[pl]);
571+ uint16_t (*const color_map_cdf)[8 + 1] =
572+ ts->cdf.m.color_map[pl][b->pal_sz[pl] - 2];
573+ for (int i = 1; i < 4 * (w4 + h4) - 1; i++) {
574+ // top/left-to-bottom/right diagonals ("wave-front")
575+ uint8_t order[64][8], ctx[64];
576+ const int first = imin(i, w4 * 4 - 1);
577+ const int last = imax(0, i - h4 * 4 + 1);
578+ order_palette(pal_idx, stride, i, first, last, order, ctx);
579+ for (int j = first, m = 0; j >= last; j--, m++) {
580+ const int color_idx =
581+ msac_decode_symbol_adapt(&ts->msac, color_map_cdf[ctx[m]],
582+ b->pal_sz[pl]);
583+ pal_idx[(i - j) * stride + j] = order[m][color_idx];
584+ }
585+ }
586+ // fill invisible edges
587+ if (bw4 > w4)
588+ for (int y = 0; y < 4 * h4; y++)
589+ memset(&pal_idx[y * stride + 4 * w4],
590+ pal_idx[y * stride + 4 * w4 - 1], 4 * (bw4 - w4));
591+ if (h4 < bh4) {
592+ const uint8_t *const src = &pal_idx[stride * (4 * h4 - 1)];
593+ for (int y = h4 * 4; y < bh4 * 4; y++)
594+ memcpy(&pal_idx[y * stride], src, bw4 * 4);
595+ }
596+}
597+
598+static void read_vartx_tree(Dav1dTileContext *const t,
599+ Av1Block *const b, const enum BlockSize bs,
600+ const int bx4, const int by4)
601+{
602+ const Dav1dFrameContext *const f = t->f;
603+ const uint8_t *const b_dim = av1_block_dimensions[bs];
604+ const int bw4 = b_dim[0], bh4 = b_dim[1];
605+
606+ // var-tx tree coding
607+ b->tx_split[0] = b->tx_split[1] = 0;
608+ b->max_ytx = av1_max_txfm_size_for_bs[bs][0];
609+ if (f->frame_hdr.segmentation.lossless[b->seg_id] ||
610+ b->max_ytx == TX_4X4)
611+ {
612+ b->max_ytx = b->uvtx = TX_4X4;
613+ if (f->frame_hdr.txfm_mode == TX_SWITCHABLE) {
614+ memset(&t->a->tx[bx4], TX_4X4, bw4);
615+ memset(&t->l.tx[by4], TX_4X4, bh4);
616+ }
617+ } else if (f->frame_hdr.txfm_mode != TX_SWITCHABLE || b->skip) {
618+ if (f->frame_hdr.txfm_mode == TX_SWITCHABLE) {
619+ memset(&t->a->tx[bx4], b_dim[2], bw4);
620+ memset(&t->l.tx[by4], b_dim[3], bh4);
621+ } else {
622+ assert(f->frame_hdr.txfm_mode == TX_LARGEST);
623+ }
624+ b->uvtx = av1_max_txfm_size_for_bs[bs][f->cur.p.p.layout];
625+ } else {
626+ assert(imin(bw4, bh4) <= 16 || b->max_ytx == TX_64X64);
627+ int y, x, y_off, x_off;
628+ const TxfmInfo *const ytx = &av1_txfm_dimensions[b->max_ytx];
629+ for (y = 0, y_off = 0; y < bh4; y += ytx->h, y_off++) {
630+ for (x = 0, x_off = 0; x < bw4; x += ytx->w, x_off++) {
631+ read_tx_tree(t, b->max_ytx, 0, b->tx_split, x_off, y_off);
632+ // contexts are updated inside read_tx_tree()
633+ t->bx += ytx->w;
634+ }
635+ t->bx -= x;
636+ t->by += ytx->h;
637+ }
638+ t->by -= y;
639+ if (DEBUG_BLOCK_INFO)
640+ printf("Post-vartxtree[%x/%x]: r=%d\n",
641+ b->tx_split[0], b->tx_split[1], t->ts->msac.rng);
642+ b->uvtx = av1_max_txfm_size_for_bs[bs][f->cur.p.p.layout];
643+ }
644+}
645+
646+static inline unsigned get_prev_frame_segid(const Dav1dFrameContext *const f,
647+ const int by, const int bx,
648+ const int w4, int h4,
649+ const uint8_t *ref_seg_map,
650+ const ptrdiff_t stride)
651+{
652+ unsigned seg_id = 8;
653+
654+ assert(f->frame_hdr.primary_ref_frame != PRIMARY_REF_NONE);
655+ dav1d_thread_picture_wait(&f->refp[f->frame_hdr.primary_ref_frame],
656+ (by + h4) * 4, PLANE_TYPE_BLOCK);
657+
658+ ref_seg_map += by * stride + bx;
659+ do {
660+ for (int x = 0; x < w4; x++)
661+ seg_id = imin(seg_id, ref_seg_map[x]);
662+ ref_seg_map += stride;
663+ } while (--h4 > 0);
664+ assert(seg_id < 8);
665+
666+ return seg_id;
667+}
668+
669+static void decode_b(Dav1dTileContext *const t,
670+ const enum BlockLevel bl,
671+ const enum BlockSize bs,
672+ const enum BlockPartition bp,
673+ const enum EdgeFlags intra_edge_flags)
674+{
675+ Dav1dTileState *const ts = t->ts;
676+ const Dav1dFrameContext *const f = t->f;
677+ Av1Block b_mem, *const b = f->frame_thread.pass ?
678+ &f->frame_thread.b[t->by * f->b4_stride + t->bx] : &b_mem;
679+ const uint8_t *const b_dim = av1_block_dimensions[bs];
680+ const int bx4 = t->bx & 31, by4 = t->by & 31;
681+ const int ss_ver = f->cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
682+ const int ss_hor = f->cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
683+ const int cbx4 = bx4 >> ss_hor, cby4 = by4 >> ss_ver;
684+ const int bw4 = b_dim[0], bh4 = b_dim[1];
685+ const int w4 = imin(bw4, f->bw - t->bx), h4 = imin(bh4, f->bh - t->by);
686+ const int cbw4 = (bw4 + ss_hor) >> ss_hor, cbh4 = (bh4 + ss_ver) >> ss_ver;
687+ const int have_left = t->bx > ts->tiling.col_start;
688+ const int have_top = t->by > ts->tiling.row_start;
689+ const int has_chroma = f->seq_hdr.layout != DAV1D_PIXEL_LAYOUT_I400 &&
690+ (bw4 > ss_hor || t->bx & 1) &&
691+ (bh4 > ss_ver || t->by & 1);
692+
693+ if (f->frame_thread.pass == 2) {
694+ if (b->intra) {
695+ f->bd_fn.recon_b_intra(t, bs, intra_edge_flags, b);
696+
697+ if (has_chroma) {
698+ memset(&t->l.uvmode[cby4], b->uv_mode, cbh4);
699+ memset(&t->a->uvmode[cbx4], b->uv_mode, cbw4);
700+ }
701+ const enum IntraPredMode y_mode_nofilt =
702+ b->y_mode == FILTER_PRED ? DC_PRED : b->y_mode;
703+ memset(&t->l.mode[by4], y_mode_nofilt, bh4);
704+ memset(&t->a->mode[bx4], y_mode_nofilt, bw4);
705+ } else {
706+ if (b->comp_type == COMP_INTER_NONE && b->motion_mode == MM_WARP) {
707+ uint64_t mask[2] = { 0, 0 };
708+ find_matching_ref(t, intra_edge_flags, bw4, bh4, w4, h4,
709+ have_left, have_top, b->ref[0], mask);
710+ derive_warpmv(t, bw4, bh4, mask, b->mv[0], &t->warpmv);
711+ }
712+ f->bd_fn.recon_b_inter(t, bs, b);
713+
714+ const uint8_t *const filter = eve_av1_filter_dir[b->filter2d];
715+ memset(&t->l.filter[0][by4], filter[0], bh4);
716+ memset(&t->a->filter[0][bx4], filter[0], bw4);
717+ memset(&t->l.filter[1][by4], filter[1], bh4);
718+ memset(&t->a->filter[1][bx4], filter[1], bw4);
719+ if (has_chroma) {
720+ memset(&t->l.uvmode[cby4], DC_PRED, cbh4);
721+ memset(&t->a->uvmode[cbx4], DC_PRED, cbw4);
722+ }
723+ }
724+ memset(&t->l.intra[by4], b->intra, bh4);
725+ memset(&t->a->intra[bx4], b->intra, bw4);
726+ return;
727+ }
728+
729+ const int cw4 = (w4 + ss_hor) >> ss_hor, ch4 = (h4 + ss_ver) >> ss_ver;
730+
731+ b->bl = bl;
732+ b->bp = bp;
733+ b->bs = bs;
734+
735+ // skip_mode
736+ if (f->frame_hdr.skip_mode_enabled && imin(bw4, bh4) > 1) {
737+ const int smctx = t->a->skip_mode[bx4] + t->l.skip_mode[by4];
738+ b->skip_mode = msac_decode_bool_adapt(&ts->msac,
739+ ts->cdf.m.skip_mode[smctx]);
740+ if (DEBUG_BLOCK_INFO)
741+ printf("Post-skipmode[%d]: r=%d\n", b->skip_mode, ts->msac.rng);
742+ } else {
743+ b->skip_mode = 0;
744+ }
745+
746+ // segment_id (if seg_feature for skip/ref/gmv is enabled)
747+ int seg_pred = 0;
748+ if (f->frame_hdr.segmentation.enabled) {
749+ if (!f->frame_hdr.segmentation.update_map) {
750+ b->seg_id = f->prev_segmap ?
751+ get_prev_frame_segid(f, t->by, t->bx, w4, h4,
752+ f->prev_segmap, f->b4_stride) : 0;
753+ } else if (f->frame_hdr.segmentation.seg_data.preskip) {
754+ if (f->frame_hdr.segmentation.temporal &&
755+ (seg_pred = msac_decode_bool_adapt(&ts->msac,
756+ ts->cdf.m.seg_pred[t->a->seg_pred[bx4] +
757+ t->l.seg_pred[by4]])))
758+ {
759+ // temporal predicted seg_id
760+ b->seg_id = f->prev_segmap ?
761+ get_prev_frame_segid(f, t->by, t->bx, w4, h4,
762+ f->prev_segmap, f->b4_stride) : 0;
763+ } else {
764+ int seg_ctx;
765+ const unsigned pred_seg_id =
766+ get_cur_frame_segid(t->by, t->bx, have_top, have_left,
767+ &seg_ctx, f->cur_segmap, f->b4_stride);
768+ const unsigned diff = msac_decode_symbol_adapt(&ts->msac,
769+ ts->cdf.m.seg_id[seg_ctx],
770+ NUM_SEGMENTS);
771+ const unsigned last_active_seg_id =
772+ f->frame_hdr.segmentation.seg_data.last_active_segid;
773+ b->seg_id = av1_neg_deinterleave(diff, pred_seg_id,
774+ last_active_seg_id + 1);
775+ if (b->seg_id > last_active_seg_id) b->seg_id = 0; // error?
776+ }
777+
778+ if (DEBUG_BLOCK_INFO)
779+ printf("Post-segid[preskip;%d]: r=%d\n",
780+ b->seg_id, ts->msac.rng);
781+ }
782+ } else {
783+ b->seg_id = 0;
784+ }
785+
786+ // skip
787+ const int sctx = t->a->skip[bx4] + t->l.skip[by4];
788+ b->skip = b->skip_mode ? 1 :
789+ msac_decode_bool_adapt(&ts->msac, ts->cdf.m.skip[sctx]);
790+ if (DEBUG_BLOCK_INFO)
791+ printf("Post-skip[%d]: r=%d\n", b->skip, ts->msac.rng);
792+
793+ // segment_id
794+ if (f->frame_hdr.segmentation.enabled &&
795+ f->frame_hdr.segmentation.update_map &&
796+ !f->frame_hdr.segmentation.seg_data.preskip)
797+ {
798+ if (!b->skip && f->frame_hdr.segmentation.temporal &&
799+ (seg_pred = msac_decode_bool_adapt(&ts->msac,
800+ ts->cdf.m.seg_pred[t->a->seg_pred[bx4] +
801+ t->l.seg_pred[by4]])))
802+ {
803+ // temporal predicted seg_id
804+ b->seg_id = f->prev_segmap ?
805+ get_prev_frame_segid(f, t->by, t->bx, w4, h4,
806+ f->prev_segmap, f->b4_stride) : 0;
807+ } else {
808+ int seg_ctx;
809+ const unsigned pred_seg_id =
810+ get_cur_frame_segid(t->by, t->bx, have_top, have_left,
811+ &seg_ctx, f->cur_segmap, f->b4_stride);
812+ if (b->skip) {
813+ b->seg_id = pred_seg_id;
814+ } else {
815+ const unsigned diff = msac_decode_symbol_adapt(&ts->msac,
816+ ts->cdf.m.seg_id[seg_ctx],
817+ NUM_SEGMENTS);
818+ const unsigned last_active_seg_id =
819+ f->frame_hdr.segmentation.seg_data.last_active_segid;
820+ b->seg_id = av1_neg_deinterleave(diff, pred_seg_id,
821+ last_active_seg_id + 1);
822+ if (b->seg_id > last_active_seg_id) b->seg_id = 0; // error?
823+ }
824+ }
825+
826+ if (DEBUG_BLOCK_INFO)
827+ printf("Post-segid[postskip;%d]: r=%d\n",
828+ b->seg_id, ts->msac.rng);
829+ }
830+
831+ // cdef index
832+ if (!b->skip) {
833+ const int idx = f->seq_hdr.sb128 ? ((t->bx & 16) >> 4) +
834+ ((t->by & 16) >> 3) : 0;
835+ if (t->cur_sb_cdef_idx_ptr[idx] == -1) {
836+ const int v = msac_decode_bools(&ts->msac, f->frame_hdr.cdef.n_bits);
837+ t->cur_sb_cdef_idx_ptr[idx] = v;
838+ if (bw4 > 16) t->cur_sb_cdef_idx_ptr[idx + 1] = v;
839+ if (bh4 > 16) t->cur_sb_cdef_idx_ptr[idx + 2] = v;
840+ if (bw4 == 32 && bh4 == 32) t->cur_sb_cdef_idx_ptr[idx + 3] = v;
841+
842+ if (DEBUG_BLOCK_INFO)
843+ printf("Post-cdef_idx[%d]: r=%d\n",
844+ *t->cur_sb_cdef_idx_ptr, ts->msac.rng);
845+ }
846+ }
847+
848+ // delta-q/lf
849+ if (!(t->bx & (31 >> !f->seq_hdr.sb128)) &&
850+ !(t->by & (31 >> !f->seq_hdr.sb128)))
851+ {
852+ const int prev_qidx = ts->last_qidx;
853+ const int have_delta_q = f->frame_hdr.delta_q_present &&
854+ (bs != (f->seq_hdr.sb128 ? BS_128x128 : BS_64x64) || !b->skip);
855+ if (have_delta_q) {
856+ int delta_q = msac_decode_symbol_adapt(&ts->msac, ts->cdf.m.delta_q, 4);
857+ if (delta_q == 3) {
858+ const int n_bits = 1 + msac_decode_bools(&ts->msac, 3);
859+ delta_q = msac_decode_bools(&ts->msac, n_bits) + 1 + (1 << n_bits);
860+ }
861+ if (delta_q) {
862+ if (msac_decode_bool(&ts->msac, 128 << 7)) delta_q = -delta_q;
863+ delta_q *= 1 << f->frame_hdr.delta_q_res_log2;
864+ }
865+ ts->last_qidx = iclip(ts->last_qidx + delta_q, 1, 255);
866+ if (have_delta_q && DEBUG_BLOCK_INFO)
867+ printf("Post-delta_q[%d->%d]: r=%d\n",
868+ delta_q, ts->last_qidx, ts->msac.rng);
869+ }
870+ if (ts->last_qidx == f->frame_hdr.quant.yac) {
871+ // assign frame-wide q values to this sb
872+ ts->dq = f->dq;
873+ } else if (ts->last_qidx != prev_qidx) {
874+ // find sb-specific quant parameters
875+ init_quant_tables(&f->seq_hdr, &f->frame_hdr, ts->last_qidx, ts->dqmem);
876+ ts->dq = ts->dqmem;
877+ }
878+
879+ // delta_lf
880+ int8_t prev_delta_lf[4];
881+ memcpy(prev_delta_lf, ts->last_delta_lf, 4);
882+ if (have_delta_q && f->frame_hdr.delta_lf_present) {
883+ const int n_lfs = f->frame_hdr.delta_lf_multi ?
884+ f->seq_hdr.layout != DAV1D_PIXEL_LAYOUT_I400 ? 4 : 2 : 1;
885+
886+ for (int i = 0; i < n_lfs; i++) {
887+ int delta_lf = msac_decode_symbol_adapt(&ts->msac,
888+ ts->cdf.m.delta_lf[i + f->frame_hdr.delta_lf_multi], 4);
889+ if (delta_lf == 3) {
890+ const int n_bits = 1 + msac_decode_bools(&ts->msac, 3);
891+ delta_lf = msac_decode_bools(&ts->msac, n_bits) + 1 + (1 << n_bits);
892+ }
893+ if (delta_lf) {
894+ if (msac_decode_bool(&ts->msac, 128 << 7)) delta_lf = -delta_lf;
895+ delta_lf *= 1 << f->frame_hdr.delta_lf_res_log2;
896+ }
897+ ts->last_delta_lf[i] = iclip(ts->last_delta_lf[i] + delta_lf, -63, 63);
898+ if (have_delta_q && DEBUG_BLOCK_INFO)
899+ printf("Post-delta_lf[%d:%d]: r=%d\n", i, delta_lf, ts->msac.rng);
900+ }
901+ }
902+ if (!memcmp(ts->last_delta_lf, (int8_t[4]) { 0, 0, 0, 0 }, 4)) {
903+ // assign frame-wide lf values to this sb
904+ ts->lflvl = f->lf.lvl;
905+ } else if (memcmp(ts->last_delta_lf, prev_delta_lf, 4)) {
906+ // find sb-specific lf lvl parameters
907+ dav1d_calc_lf_values(ts->lflvlmem, &f->frame_hdr, ts->last_delta_lf);
908+ ts->lflvl = ts->lflvlmem;
909+ }
910+ }
911+
912+ if (b->skip_mode) {
913+ b->intra = 0;
914+ } else if (f->frame_hdr.frame_type & 1) {
915+ const int ictx = get_intra_ctx(t->a, &t->l, by4, bx4,
916+ have_top, have_left);
917+ b->intra = !msac_decode_bool_adapt(&ts->msac, ts->cdf.m.intra[ictx]);
918+ if (DEBUG_BLOCK_INFO)
919+ printf("Post-intra[%d]: r=%d\n", b->intra, ts->msac.rng);
920+ } else if (f->frame_hdr.allow_intrabc) {
921+ b->intra = !msac_decode_bool_adapt(&ts->msac, ts->cdf.m.intrabc);
922+ if (DEBUG_BLOCK_INFO)
923+ printf("Post-intrabcflag[%d]: r=%d\n", b->intra, ts->msac.rng);
924+ } else {
925+ b->intra = 1;
926+ }
927+
928+ // intra/inter-specific stuff
929+ if (b->intra) {
930+ uint16_t *const ymode_cdf = f->frame_hdr.frame_type & 1 ?
931+ ts->cdf.m.y_mode[av1_ymode_size_context[bs]] :
932+ ts->cdf.kfym[intra_mode_context[t->a->mode[bx4]]]
933+ [intra_mode_context[t->l.mode[by4]]];
934+ b->y_mode = msac_decode_symbol_adapt(&ts->msac, ymode_cdf,
935+ N_INTRA_PRED_MODES);
936+ if (DEBUG_BLOCK_INFO)
937+ printf("Post-ymode[%d]: r=%d\n", b->y_mode, ts->msac.rng);
938+
939+ // angle delta
940+ if (b_dim[2] + b_dim[3] >= 2 && b->y_mode >= VERT_PRED &&
941+ b->y_mode <= VERT_LEFT_PRED)
942+ {
943+ uint16_t *const acdf = ts->cdf.m.angle_delta[b->y_mode - VERT_PRED];
944+ const int angle = msac_decode_symbol_adapt(&ts->msac, acdf, 7);
945+ b->y_angle = angle - 3;
946+ } else {
947+ b->y_angle = 0;
948+ }
949+
950+ if (has_chroma) {
951+ const int cfl_allowed = !!(cfl_allowed_mask & (1 << bs));
952+ uint16_t *const uvmode_cdf = ts->cdf.m.uv_mode[cfl_allowed][b->y_mode];
953+ b->uv_mode = msac_decode_symbol_adapt(&ts->msac, uvmode_cdf,
954+ N_UV_INTRA_PRED_MODES - !cfl_allowed);
955+ if (DEBUG_BLOCK_INFO)
956+ printf("Post-uvmode[%d]: r=%d\n", b->uv_mode, ts->msac.rng);
957+
958+ if (b->uv_mode == CFL_PRED) {
959+#define SIGN(a) (!!(a) + ((a) > 0))
960+ const int sign =
961+ msac_decode_symbol_adapt(&ts->msac, ts->cdf.m.cfl_sign, 8) + 1;
962+ const int sign_u = sign * 0x56 >> 8, sign_v = sign - sign_u * 3;
963+ assert(sign_u == sign / 3);
964+ if (sign_u) {
965+ const int ctx = (sign_u == 2) * 3 + sign_v;
966+ b->cfl_alpha[0] = msac_decode_symbol_adapt(&ts->msac,
967+ ts->cdf.m.cfl_alpha[ctx], 16) + 1;
968+ if (sign_u == 1) b->cfl_alpha[0] = -b->cfl_alpha[0];
969+ } else {
970+ b->cfl_alpha[0] = 0;
971+ }
972+ if (sign_v) {
973+ const int ctx = (sign_v == 2) * 3 + sign_u;
974+ b->cfl_alpha[1] = msac_decode_symbol_adapt(&ts->msac,
975+ ts->cdf.m.cfl_alpha[ctx], 16) + 1;
976+ if (sign_v == 1) b->cfl_alpha[1] = -b->cfl_alpha[1];
977+ } else {
978+ b->cfl_alpha[1] = 0;
979+ }
980+#undef SIGN
981+ if (DEBUG_BLOCK_INFO)
982+ printf("Post-uvalphas[%d/%d]: r=%d\n",
983+ b->cfl_alpha[0], b->cfl_alpha[1], ts->msac.rng);
984+ } else if (b_dim[2] + b_dim[3] >= 2 && b->uv_mode >= VERT_PRED &&
985+ b->uv_mode <= VERT_LEFT_PRED)
986+ {
987+ uint16_t *const acdf = ts->cdf.m.angle_delta[b->uv_mode - VERT_PRED];
988+ const int angle = msac_decode_symbol_adapt(&ts->msac, acdf, 7);
989+ b->uv_angle = angle - 3;
990+ } else {
991+ b->uv_angle = 0;
992+ }
993+ }
994+
995+ b->pal_sz[0] = b->pal_sz[1] = 0;
996+ if (f->frame_hdr.allow_screen_content_tools &&
997+ imax(bw4, bh4) <= 16 && bw4 + bh4 >= 4)
998+ {
999+ const int sz_ctx = b_dim[2] + b_dim[3] - 2;
1000+ if (b->y_mode == DC_PRED) {
1001+ const int pal_ctx = (t->a->pal_sz[bx4] > 0) + (t->l.pal_sz[by4] > 0);
1002+ const int use_y_pal =
1003+ msac_decode_bool_adapt(&ts->msac, ts->cdf.m.pal_y[sz_ctx][pal_ctx]);
1004+ if (DEBUG_BLOCK_INFO)
1005+ printf("Post-y_pal[%d]: r=%d\n", use_y_pal, ts->msac.rng);
1006+ if (use_y_pal)
1007+ read_pal_plane(t, b, 0, sz_ctx, bx4, by4);
1008+ }
1009+
1010+ if (has_chroma && b->uv_mode == DC_PRED) {
1011+ const int pal_ctx = b->pal_sz[0] > 0;
1012+ const int use_uv_pal =
1013+ msac_decode_bool_adapt(&ts->msac, ts->cdf.m.pal_uv[pal_ctx]);
1014+ if (DEBUG_BLOCK_INFO)
1015+ printf("Post-uv_pal[%d]: r=%d\n", use_uv_pal, ts->msac.rng);
1016+ if (use_uv_pal)
1017+ read_pal_uv(t, b, sz_ctx, cbx4, cby4);
1018+ }
1019+ }
1020+
1021+ if (b->y_mode == DC_PRED && !b->pal_sz[0] &&
1022+ imax(b_dim[2], b_dim[3]) <= 3 && f->seq_hdr.filter_intra)
1023+ {
1024+ const int is_filter = msac_decode_bool_adapt(&ts->msac,
1025+ ts->cdf.m.use_filter_intra[bs]);
1026+ if (is_filter) {
1027+ b->y_mode = FILTER_PRED;
1028+ b->y_angle = msac_decode_symbol_adapt(&ts->msac,
1029+ ts->cdf.m.filter_intra, 5);
1030+ }
1031+ if (DEBUG_BLOCK_INFO)
1032+ printf("Post-filterintramode[%d/%d]: r=%d\n",
1033+ b->y_mode, b->y_angle, ts->msac.rng);
1034+ }
1035+
1036+ if (b->pal_sz[0]) {
1037+ uint8_t *pal_idx;
1038+ if (f->frame_thread.pass) {
1039+ pal_idx = ts->frame_thread.pal_idx;
1040+ ts->frame_thread.pal_idx += bw4 * bh4 * 16;
1041+ } else
1042+ pal_idx = t->scratch.pal_idx;
1043+ read_pal_indices(t, pal_idx, b, 0, w4, h4, bw4, bh4);
1044+ if (DEBUG_BLOCK_INFO)
1045+ printf("Post-y-pal-indices: r=%d\n", ts->msac.rng);
1046+ }
1047+
1048+ if (has_chroma && b->pal_sz[1]) {
1049+ uint8_t *pal_idx;
1050+ if (f->frame_thread.pass) {
1051+ pal_idx = ts->frame_thread.pal_idx;
1052+ ts->frame_thread.pal_idx += cbw4 * cbh4 * 16;
1053+ } else
1054+ pal_idx = &t->scratch.pal_idx[bw4 * bh4 * 16];
1055+ read_pal_indices(t, pal_idx, b, 1, cw4, ch4, cbw4, cbh4);
1056+ if (DEBUG_BLOCK_INFO)
1057+ printf("Post-uv-pal-indices: r=%d\n", ts->msac.rng);
1058+ }
1059+
1060+ const TxfmInfo *t_dim;
1061+ if (f->frame_hdr.segmentation.lossless[b->seg_id]) {
1062+ b->tx = b->uvtx = (int) TX_4X4;
1063+ t_dim = &av1_txfm_dimensions[TX_4X4];
1064+ } else {
1065+ b->tx = av1_max_txfm_size_for_bs[bs][0];
1066+ b->uvtx = av1_max_txfm_size_for_bs[bs][f->cur.p.p.layout];
1067+ t_dim = &av1_txfm_dimensions[b->tx];
1068+ if (f->frame_hdr.txfm_mode == TX_SWITCHABLE && t_dim->max > TX_4X4) {
1069+ const int tctx = get_tx_ctx(t->a, &t->l, t_dim, by4, bx4,
1070+ have_top, have_left);
1071+ uint16_t *const tx_cdf = ts->cdf.m.txsz[t_dim->max - 1][tctx];
1072+ int depth = msac_decode_symbol_adapt(&ts->msac, tx_cdf,
1073+ imin(t_dim->max + 1, 3));
1074+
1075+ while (depth--) {
1076+ b->tx = t_dim->sub;
1077+ t_dim = &av1_txfm_dimensions[b->tx];
1078+ }
1079+ }
1080+ if (DEBUG_BLOCK_INFO)
1081+ printf("Post-tx[%d]: r=%d\n", b->tx, ts->msac.rng);
1082+ }
1083+
1084+ // reconstruction
1085+ if (f->frame_thread.pass == 1) {
1086+ f->bd_fn.read_coef_blocks(t, bs, b);
1087+ } else {
1088+ f->bd_fn.recon_b_intra(t, bs, intra_edge_flags, b);
1089+ }
1090+
1091+ dav1d_create_lf_mask_intra(t->lf_mask, f->lf.level, f->b4_stride,
1092+ &f->frame_hdr, (const uint8_t (*)[8][2])
1093+ &ts->lflvl[b->seg_id][0][0][0],
1094+ t->bx, t->by, f->bw, f->bh, bs,
1095+ b->tx, b->uvtx, f->cur.p.p.layout,
1096+ &t->a->tx_lpf_y[bx4], &t->l.tx_lpf_y[by4],
1097+ has_chroma ? &t->a->tx_lpf_uv[cbx4] : NULL,
1098+ has_chroma ? &t->l.tx_lpf_uv[cby4] : NULL);
1099+
1100+ // update contexts
1101+ memset(&t->a->tx_intra[bx4], t_dim->lw, bw4);
1102+ memset(&t->l.tx_intra[by4], t_dim->lh, bh4);
1103+ const enum IntraPredMode y_mode_nofilt =
1104+ b->y_mode == FILTER_PRED ? DC_PRED : b->y_mode;
1105+ memset(&t->l.mode[by4], y_mode_nofilt, bh4);
1106+ memset(&t->a->mode[bx4], y_mode_nofilt, bw4);
1107+ memset(&t->l.pal_sz[by4], b->pal_sz[0], bh4);
1108+ memset(&t->a->pal_sz[bx4], b->pal_sz[0], bw4);
1109+ if (b->pal_sz[0]) {
1110+ uint16_t *const pal = f->frame_thread.pass ?
1111+ f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1112+ ((t->bx >> 1) + (t->by & 1))][0] : t->pal[0];
1113+ for (int x = 0; x < bw4; x++)
1114+ memcpy(t->al_pal[0][bx4 + x][0], pal, 16);
1115+ for (int y = 0; y < bh4; y++)
1116+ memcpy(t->al_pal[1][by4 + y][0], pal, 16);
1117+ }
1118+ if (has_chroma) {
1119+ memset(&t->l.uvmode[cby4], b->uv_mode, cbh4);
1120+ memset(&t->a->uvmode[cbx4], b->uv_mode, cbw4);
1121+ memset(&t->pal_sz_uv[1][cby4], b->pal_sz[1], cbh4);
1122+ memset(&t->pal_sz_uv[0][cbx4], b->pal_sz[1], cbw4);
1123+ if (b->pal_sz[1]) for (int pl = 1; pl < 3; pl++) {
1124+ uint16_t *const pal = f->frame_thread.pass ?
1125+ f->frame_thread.pal[((t->by >> 1) + (t->bx & 1)) * (f->b4_stride >> 1) +
1126+ ((t->bx >> 1) + (t->by & 1))][pl] : t->pal[pl];
1127+ for (int x = 0; x < cbw4; x++)
1128+ memcpy(t->al_pal[0][cbx4 + x][pl], pal, 16);
1129+ for (int y = 0; y < cbh4; y++)
1130+ memcpy(t->al_pal[1][cby4 + y][pl], pal, 16);
1131+ }
1132+ }
1133+ if ((f->frame_hdr.frame_type & 1) || f->frame_hdr.allow_intrabc) {
1134+ memset(&t->a->tx[bx4], t_dim->lw, bw4);
1135+ memset(&t->l.tx[by4], t_dim->lh, bh4);
1136+ splat_intraref(f->mvs, f->b4_stride, t->by, t->bx, bs,
1137+ y_mode_nofilt);
1138+ }
1139+ if (f->frame_hdr.frame_type & 1) {
1140+ memset(&t->l.comp_type[by4], COMP_INTER_NONE, bh4);
1141+ memset(&t->a->comp_type[bx4], COMP_INTER_NONE, bw4);
1142+ memset(&t->l.ref[0][by4], -1, bh4);
1143+ memset(&t->a->ref[0][bx4], -1, bw4);
1144+ memset(&t->l.ref[1][by4], -1, bh4);
1145+ memset(&t->a->ref[1][bx4], -1, bw4);
1146+ memset(&t->l.filter[0][by4], N_SWITCHABLE_FILTERS, bh4);
1147+ memset(&t->a->filter[0][bx4], N_SWITCHABLE_FILTERS, bw4);
1148+ memset(&t->l.filter[1][by4], N_SWITCHABLE_FILTERS, bh4);
1149+ memset(&t->a->filter[1][bx4], N_SWITCHABLE_FILTERS, bw4);
1150+ }
1151+ } else if (!(f->frame_hdr.frame_type & 1)) {
1152+ // intra block copy
1153+ candidate_mv mvstack[8];
1154+ int n_mvs;
1155+ mv mvlist[2][2];
1156+ av1_find_ref_mvs(mvstack, &n_mvs, mvlist, NULL,
1157+ (int[2]) { -1, -1 }, f->bw, f->bh,
1158+ bs, bp, t->by, t->bx, ts->tiling.col_start,
1159+ ts->tiling.col_end, ts->tiling.row_start,
1160+ ts->tiling.row_end, f->libaom_cm);
1161+
1162+ if (mvlist[0][0].y | mvlist[0][0].x)
1163+ b->mv[0] = mvlist[0][0];
1164+ else if (mvlist[0][1].y | mvlist[0][1].x)
1165+ b->mv[0] = mvlist[0][1];
1166+ else {
1167+ if (t->by - (16 << f->seq_hdr.sb128) < ts->tiling.row_start) {
1168+ b->mv[0].y = 0;
1169+ b->mv[0].x = -(512 << f->seq_hdr.sb128) - 2048;
1170+ } else {
1171+ b->mv[0].y = -(512 << f->seq_hdr.sb128);
1172+ b->mv[0].x = 0;
1173+ }
1174+ }
1175+
1176+ const struct mv ref = b->mv[0];
1177+ read_mv_residual(t, &b->mv[0], &ts->cdf.dmv, 0);
1178+ if (DEBUG_BLOCK_INFO)
1179+ printf("Post-dmv[%d/%d,ref=%d/%d|%d/%d]: r=%d\n",
1180+ b->mv[0].y, b->mv[0].x, ref.y, ref.x,
1181+ mvlist[0][0].y, mvlist[0][0].x, ts->msac.rng);
1182+ read_vartx_tree(t, b, bs, bx4, by4);
1183+
1184+ // reconstruction
1185+ if (f->frame_thread.pass == 1) {
1186+ f->bd_fn.read_coef_blocks(t, bs, b);
1187+ } else {
1188+ f->bd_fn.recon_b_inter(t, bs, b);
1189+ }
1190+
1191+ splat_intrabc_mv(f->mvs, f->b4_stride, t->by, t->bx, bs, b->mv[0]);
1192+
1193+ memset(&t->a->tx_intra[bx4], b_dim[2], bw4);
1194+ memset(&t->l.tx_intra[by4], b_dim[3], bh4);
1195+ memset(&t->l.mode[by4], DC_PRED, bh4);
1196+ memset(&t->a->mode[bx4], DC_PRED, bw4);
1197+ memset(&t->l.pal_sz[by4], 0, bh4);
1198+ memset(&t->a->pal_sz[bx4], 0, bw4);
1199+ if (has_chroma) {
1200+ memset(&t->l.uvmode[cby4], DC_PRED, cbh4);
1201+ memset(&t->a->uvmode[cbx4], DC_PRED, cbw4);
1202+ memset(&t->pal_sz_uv[1][cby4], 0, cbh4);
1203+ memset(&t->pal_sz_uv[0][cbx4], 0, cbw4);
1204+ }
1205+ } else {
1206+ // inter-specific mode/mv coding
1207+ int is_comp, has_subpel_filter;
1208+
1209+ if (b->skip_mode) {
1210+ is_comp = 1;
1211+ } else if (f->frame_hdr.switchable_comp_refs && imin(bw4, bh4) > 1) {
1212+ const int ctx = get_comp_ctx(t->a, &t->l, by4, bx4,
1213+ have_top, have_left);
1214+ is_comp = msac_decode_bool_adapt(&ts->msac, ts->cdf.m.comp[ctx]);
1215+ if (DEBUG_BLOCK_INFO)
1216+ printf("Post-compflag[%d]: r=%d\n", is_comp, ts->msac.rng);
1217+ } else {
1218+ is_comp = 0;
1219+ }
1220+
1221+ if (b->skip_mode) {
1222+ b->ref[0] = f->frame_hdr.skip_mode_refs[0];
1223+ b->ref[1] = f->frame_hdr.skip_mode_refs[1];
1224+ b->comp_type = COMP_INTER_AVG;
1225+ b->inter_mode = NEARESTMV_NEARESTMV;
1226+ b->drl_idx = 0;
1227+ has_subpel_filter = 0;
1228+
1229+ candidate_mv mvstack[8];
1230+ int n_mvs, ctx;
1231+ mv mvlist[2][2];
1232+ av1_find_ref_mvs(mvstack, &n_mvs, mvlist, &ctx,
1233+ (int[2]) { b->ref[0], b->ref[1] }, f->bw, f->bh,
1234+ bs, bp, t->by, t->bx, ts->tiling.col_start,
1235+ ts->tiling.col_end, ts->tiling.row_start,
1236+ ts->tiling.row_end, f->libaom_cm);
1237+
1238+ b->mv[0] = mvstack[0].this_mv;
1239+ b->mv[1] = mvstack[0].comp_mv;
1240+ if (!f->frame_hdr.hp) {
1241+ unset_hp_bit(&b->mv[0]);
1242+ unset_hp_bit(&b->mv[1]);
1243+ }
1244+ if (DEBUG_BLOCK_INFO)
1245+ printf("Post-skipmodeblock[mv=1:y=%d,x=%d,2:y=%d,x=%d,refs=%d+%d\n",
1246+ b->mv[0].y, b->mv[0].x, b->mv[1].y, b->mv[1].x,
1247+ b->ref[0], b->ref[1]);
1248+ } else if (is_comp) {
1249+ const int dir_ctx = get_comp_dir_ctx(t->a, &t->l, by4, bx4,
1250+ have_top, have_left);
1251+ if (msac_decode_bool_adapt(&ts->msac, ts->cdf.m.comp_dir[dir_ctx])) {
1252+ // bidir - first reference (fw)
1253+ const int ctx1 = av1_get_fwd_ref_ctx(t->a, &t->l, by4, bx4,
1254+ have_top, have_left);
1255+ if (msac_decode_bool_adapt(&ts->msac,
1256+ ts->cdf.m.comp_fwd_ref[0][ctx1]))
1257+ {
1258+ const int ctx2 = av1_get_fwd_ref_2_ctx(t->a, &t->l, by4, bx4,
1259+ have_top, have_left);
1260+ b->ref[0] = 2 + msac_decode_bool_adapt(&ts->msac,
1261+ ts->cdf.m.comp_fwd_ref[2][ctx2]);
1262+ } else {
1263+ const int ctx2 = av1_get_fwd_ref_1_ctx(t->a, &t->l, by4, bx4,
1264+ have_top, have_left);
1265+ b->ref[0] = msac_decode_bool_adapt(&ts->msac,
1266+ ts->cdf.m.comp_fwd_ref[1][ctx2]);
1267+ }
1268+
1269+ // second reference (bw)
1270+ const int ctx3 = av1_get_bwd_ref_ctx(t->a, &t->l, by4, bx4,
1271+ have_top, have_left);
1272+ if (msac_decode_bool_adapt(&ts->msac,
1273+ ts->cdf.m.comp_bwd_ref[0][ctx3]))
1274+ {
1275+ b->ref[1] = 6;
1276+ } else {
1277+ const int ctx4 = av1_get_bwd_ref_1_ctx(t->a, &t->l, by4, bx4,
1278+ have_top, have_left);
1279+ b->ref[1] = 4 + msac_decode_bool_adapt(&ts->msac,
1280+ ts->cdf.m.comp_bwd_ref[1][ctx4]);
1281+ }
1282+ } else {
1283+ // unidir
1284+ const int uctx_p = av1_get_uni_p_ctx(t->a, &t->l, by4, bx4,
1285+ have_top, have_left);
1286+ if (msac_decode_bool_adapt(&ts->msac,
1287+ ts->cdf.m.comp_uni_ref[0][uctx_p]))
1288+ {
1289+ b->ref[0] = 4;
1290+ b->ref[1] = 6;
1291+ } else {
1292+ const int uctx_p1 = av1_get_uni_p1_ctx(t->a, &t->l, by4, bx4,
1293+ have_top, have_left);
1294+ b->ref[0] = 0;
1295+ b->ref[1] = 1 + msac_decode_bool_adapt(&ts->msac,
1296+ ts->cdf.m.comp_uni_ref[1][uctx_p1]);
1297+ if (b->ref[1] == 2) {
1298+ const int uctx_p2 = av1_get_uni_p2_ctx(t->a, &t->l, by4, bx4,
1299+ have_top, have_left);
1300+ b->ref[1] += msac_decode_bool_adapt(&ts->msac,
1301+ ts->cdf.m.comp_uni_ref[2][uctx_p2]);
1302+ }
1303+ }
1304+ }
1305+ if (DEBUG_BLOCK_INFO)
1306+ printf("Post-refs[%d/%d]: r=%d\n",
1307+ b->ref[0], b->ref[1], ts->msac.rng);
1308+
1309+ candidate_mv mvstack[8];
1310+ int n_mvs, ctx;
1311+ mv mvlist[2][2];
1312+ av1_find_ref_mvs(mvstack, &n_mvs, mvlist, &ctx,
1313+ (int[2]) { b->ref[0], b->ref[1] }, f->bw, f->bh,
1314+ bs, bp, t->by, t->bx, ts->tiling.col_start,
1315+ ts->tiling.col_end, ts->tiling.row_start,
1316+ ts->tiling.row_end, f->libaom_cm);
1317+
1318+ b->inter_mode = msac_decode_symbol_adapt(&ts->msac,
1319+ ts->cdf.m.comp_inter_mode[ctx],
1320+ N_COMP_INTER_PRED_MODES);
1321+ if (DEBUG_BLOCK_INFO)
1322+ printf("Post-compintermode[%d,ctx=%d,n_mvs=%d]: r=%d\n",
1323+ b->inter_mode, ctx, n_mvs, ts->msac.rng);
1324+
1325+ const uint8_t *const im = av1_comp_inter_pred_modes[b->inter_mode];
1326+ b->drl_idx = 0;
1327+ if (b->inter_mode == NEWMV_NEWMV) {
1328+ if (n_mvs > 1) {
1329+ const int drl_ctx_v1 = get_drl_context(mvstack, 0);
1330+ b->drl_idx += msac_decode_bool_adapt(&ts->msac,
1331+ ts->cdf.m.drl_bit[drl_ctx_v1]);
1332+ if (b->drl_idx == 1 && n_mvs > 2) {
1333+ const int drl_ctx_v2 = get_drl_context(mvstack, 1);
1334+ b->drl_idx += msac_decode_bool_adapt(&ts->msac,
1335+ ts->cdf.m.drl_bit[drl_ctx_v2]);
1336+ }
1337+ if (DEBUG_BLOCK_INFO)
1338+ printf("Post-drlidx[%d,n_mvs=%d]: r=%d\n",
1339+ b->drl_idx, n_mvs, ts->msac.rng);
1340+ }
1341+ } else if (im[0] == NEARMV || im[1] == NEARMV) {
1342+ b->drl_idx = 1;
1343+ if (n_mvs > 2) {
1344+ const int drl_ctx_v2 = get_drl_context(mvstack, 1);
1345+ b->drl_idx += msac_decode_bool_adapt(&ts->msac,
1346+ ts->cdf.m.drl_bit[drl_ctx_v2]);
1347+ if (b->drl_idx == 2 && n_mvs > 3) {
1348+ const int drl_ctx_v3 = get_drl_context(mvstack, 2);
1349+ b->drl_idx += msac_decode_bool_adapt(&ts->msac,
1350+ ts->cdf.m.drl_bit[drl_ctx_v3]);
1351+ }
1352+ if (DEBUG_BLOCK_INFO)
1353+ printf("Post-drlidx[%d,n_mvs=%d]: r=%d\n",
1354+ b->drl_idx, n_mvs, ts->msac.rng);
1355+ }
1356+ }
1357+
1358+#define assign_comp_mv(idx, pfx) \
1359+ switch (im[idx]) { \
1360+ case NEARMV: \
1361+ case NEARESTMV: \
1362+ b->mv[idx] = mvstack[b->drl_idx].pfx##_mv; \
1363+ if (!f->frame_hdr.hp) unset_hp_bit(&b->mv[idx]); \
1364+ break; \
1365+ case GLOBALMV: \
1366+ has_subpel_filter |= \
1367+ f->frame_hdr.gmv[b->ref[idx]].type == WM_TYPE_TRANSLATION; \
1368+ b->mv[idx] = get_gmv_2d(&f->frame_hdr.gmv[b->ref[idx]], \
1369+ t->bx, t->by, bw4, bh4, &f->frame_hdr); \
1370+ break; \
1371+ case NEWMV: \
1372+ b->mv[idx] = mvstack[b->drl_idx].pfx##_mv; \
1373+ read_mv_residual(t, &b->mv[idx], &ts->cdf.mv, \
1374+ !f->frame_hdr.force_integer_mv); \
1375+ break; \
1376+ }
1377+ has_subpel_filter = imin(bw4, bh4) == 1 ||
1378+ b->inter_mode != GLOBALMV_GLOBALMV;
1379+ assign_comp_mv(0, this);
1380+ assign_comp_mv(1, comp);
1381+#undef assign_comp_mv
1382+ if (DEBUG_BLOCK_INFO)
1383+ printf("Post-residual_mv[1:y=%d,x=%d,2:y=%d,x=%d]: r=%d\n",
1384+ b->mv[0].y, b->mv[0].x, b->mv[1].y, b->mv[1].x,
1385+ ts->msac.rng);
1386+
1387+ // jnt_comp vs. seg vs. wedge
1388+ int is_segwedge = 0;
1389+ if (f->seq_hdr.masked_compound) {
1390+ const int mask_ctx = get_mask_comp_ctx(t->a, &t->l, by4, bx4);
1391+
1392+ is_segwedge = msac_decode_bool_adapt(&ts->msac,
1393+ ts->cdf.m.mask_comp[mask_ctx]);
1394+ if (DEBUG_BLOCK_INFO)
1395+ printf("Post-segwedge_vs_jntavg[%d,ctx=%d]: r=%d\n",
1396+ is_segwedge, mask_ctx, ts->msac.rng);
1397+ }
1398+
1399+ if (!is_segwedge) {
1400+ if (f->seq_hdr.jnt_comp) {
1401+ const int jnt_ctx =
1402+ get_jnt_comp_ctx(f->seq_hdr.order_hint_n_bits,
1403+ f->cur.p.poc, f->refp[b->ref[0]].p.poc,
1404+ f->refp[b->ref[1]].p.poc, t->a, &t->l,
1405+ by4, bx4);
1406+ b->comp_type = COMP_INTER_WEIGHTED_AVG +
1407+ msac_decode_bool_adapt(&ts->msac,
1408+ ts->cdf.m.jnt_comp[jnt_ctx]);
1409+ if (DEBUG_BLOCK_INFO)
1410+ printf("Post-jnt_comp[%d,ctx=%d[ac:%d,ar:%d,lc:%d,lr:%d]]: r=%d\n",
1411+ b->comp_type == COMP_INTER_AVG,
1412+ jnt_ctx, t->a->comp_type[bx4], t->a->ref[0][bx4],
1413+ t->l.comp_type[by4], t->l.ref[0][by4],
1414+ ts->msac.rng);
1415+ } else {
1416+ b->comp_type = COMP_INTER_AVG;
1417+ }
1418+ } else {
1419+ if (wedge_allowed_mask & (1 << bs)) {
1420+ const int ctx = av1_wedge_ctx_lut[bs];
1421+ b->comp_type = COMP_INTER_WEDGE -
1422+ msac_decode_bool_adapt(&ts->msac,
1423+ ts->cdf.m.wedge_comp[ctx]);
1424+ if (b->comp_type == COMP_INTER_WEDGE)
1425+ b->wedge_idx = msac_decode_symbol_adapt(&ts->msac,
1426+ ts->cdf.m.wedge_idx[ctx], 16);
1427+ } else {
1428+ b->comp_type = COMP_INTER_SEG;
1429+ }
1430+ b->mask_sign = msac_decode_bool(&ts->msac, 128 << 7);
1431+ if (DEBUG_BLOCK_INFO)
1432+ printf("Post-seg/wedge[%d,wedge_idx=%d,sign=%d]: r=%d\n",
1433+ b->comp_type == COMP_INTER_WEDGE,
1434+ b->wedge_idx, b->mask_sign, ts->msac.rng);
1435+ }
1436+ } else {
1437+ b->comp_type = COMP_INTER_NONE;
1438+
1439+ // ref
1440+ const int ctx1 = av1_get_ref_ctx(t->a, &t->l, by4, bx4,
1441+ have_top, have_left);
1442+ if (msac_decode_bool_adapt(&ts->msac, ts->cdf.m.ref[0][ctx1])) {
1443+ const int ctx2 = av1_get_ref_2_ctx(t->a, &t->l, by4, bx4,
1444+ have_top, have_left);
1445+ if (msac_decode_bool_adapt(&ts->msac, ts->cdf.m.ref[1][ctx2])) {
1446+ b->ref[0] = 6;
1447+ } else {
1448+ const int ctx3 = av1_get_ref_6_ctx(t->a, &t->l, by4, bx4,
1449+ have_top, have_left);
1450+ b->ref[0] = 4 + msac_decode_bool_adapt(&ts->msac,
1451+ ts->cdf.m.ref[5][ctx3]);
1452+ }
1453+ } else {
1454+ const int ctx2 = av1_get_ref_3_ctx(t->a, &t->l, by4, bx4,
1455+ have_top, have_left);
1456+ if (msac_decode_bool_adapt(&ts->msac, ts->cdf.m.ref[2][ctx2])) {
1457+ const int ctx3 = av1_get_ref_5_ctx(t->a, &t->l, by4, bx4,
1458+ have_top, have_left);
1459+ b->ref[0] = 2 + msac_decode_bool_adapt(&ts->msac,
1460+ ts->cdf.m.ref[4][ctx3]);
1461+ } else {
1462+ const int ctx3 = av1_get_ref_4_ctx(t->a, &t->l, by4, bx4,
1463+ have_top, have_left);
1464+ b->ref[0] = msac_decode_bool_adapt(&ts->msac,
1465+ ts->cdf.m.ref[3][ctx3]);
1466+ }
1467+ }
1468+ b->ref[1] = -1;
1469+ if (DEBUG_BLOCK_INFO)
1470+ printf("Post-ref[%d]: r=%d\n", b->ref[0], ts->msac.rng);
1471+
1472+ candidate_mv mvstack[8];
1473+ int n_mvs, ctx;
1474+ mv mvlist[2][2];
1475+ av1_find_ref_mvs(mvstack, &n_mvs, mvlist, &ctx,
1476+ (int[2]) { b->ref[0], -1 }, f->bw, f->bh, bs, bp,
1477+ t->by, t->bx, ts->tiling.col_start,
1478+ ts->tiling.col_end, ts->tiling.row_start,
1479+ ts->tiling.row_end, f->libaom_cm);
1480+
1481+ // mode parsing and mv derivation from ref_mvs
1482+ if (msac_decode_bool_adapt(&ts->msac, ts->cdf.m.newmv_mode[ctx & 7])) {
1483+ if (!msac_decode_bool_adapt(&ts->msac,
1484+ ts->cdf.m.globalmv_mode[(ctx >> 3) & 1]))
1485+ {
1486+ b->inter_mode = GLOBALMV;
1487+ b->mv[0] = get_gmv_2d(&f->frame_hdr.gmv[b->ref[0]],
1488+ t->bx, t->by, bw4, bh4, &f->frame_hdr);
1489+ has_subpel_filter = imin(bw4, bh4) == 1 ||
1490+ f->frame_hdr.gmv[b->ref[0]].type == WM_TYPE_TRANSLATION;
1491+ } else {
1492+ has_subpel_filter = 1;
1493+ if (msac_decode_bool_adapt(&ts->msac,
1494+ ts->cdf.m.refmv_mode[(ctx >> 4) & 15]))
1495+ {
1496+ b->inter_mode = NEARMV;
1497+ b->drl_idx = 1;
1498+ if (n_mvs > 2) {
1499+ const int drl_ctx_v2 = get_drl_context(mvstack, 1);
1500+ b->drl_idx += msac_decode_bool_adapt(&ts->msac,
1501+ ts->cdf.m.drl_bit[drl_ctx_v2]);
1502+ if (b->drl_idx == 2 && n_mvs > 3) {
1503+ const int drl_ctx_v3 =
1504+ get_drl_context(mvstack, 2);
1505+ b->drl_idx += msac_decode_bool_adapt(&ts->msac,
1506+ ts->cdf.m.drl_bit[drl_ctx_v3]);
1507+ }
1508+ }
1509+ } else {
1510+ b->inter_mode = NEARESTMV;
1511+ b->drl_idx = 0;
1512+ }
1513+ if (b->drl_idx >= 2) {
1514+ b->mv[0] = mvstack[b->drl_idx].this_mv;
1515+ } else {
1516+ b->mv[0] = mvlist[0][b->drl_idx];
1517+ if (!f->frame_hdr.hp) unset_hp_bit(&b->mv[0]);
1518+ }
1519+ }
1520+
1521+ if (DEBUG_BLOCK_INFO)
1522+ printf("Post-intermode[%d,drl=%d,mv=y:%d,x:%d,n_mvs=%d]: r=%d\n",
1523+ b->inter_mode, b->drl_idx, b->mv[0].y, b->mv[0].x, n_mvs,
1524+ ts->msac.rng);
1525+ } else {
1526+ has_subpel_filter = 1;
1527+ b->inter_mode = NEWMV;
1528+ b->drl_idx = 0;
1529+ if (n_mvs > 1) {
1530+ const int drl_ctx_v1 = get_drl_context(mvstack, 0);
1531+ b->drl_idx += msac_decode_bool_adapt(&ts->msac,
1532+ ts->cdf.m.drl_bit[drl_ctx_v1]);
1533+ if (b->drl_idx == 1 && n_mvs > 2) {
1534+ const int drl_ctx_v2 = get_drl_context(mvstack, 1);
1535+ b->drl_idx += msac_decode_bool_adapt(&ts->msac,
1536+ ts->cdf.m.drl_bit[drl_ctx_v2]);
1537+ }
1538+ }
1539+ if (n_mvs > 1) {
1540+ b->mv[0] = mvstack[b->drl_idx].this_mv;
1541+ } else {
1542+ b->mv[0] = mvlist[0][0];
1543+ if (!f->frame_hdr.hp) unset_hp_bit(&b->mv[0]);
1544+ }
1545+ if (DEBUG_BLOCK_INFO)
1546+ printf("Post-intermode[%d,drl=%d]: r=%d\n",
1547+ b->inter_mode, b->drl_idx, ts->msac.rng);
1548+ read_mv_residual(t, &b->mv[0], &ts->cdf.mv,
1549+ !f->frame_hdr.force_integer_mv);
1550+ if (DEBUG_BLOCK_INFO)
1551+ printf("Post-residualmv[mv=y:%d,x:%d]: r=%d\n",
1552+ b->mv[0].y, b->mv[0].x, ts->msac.rng);
1553+ }
1554+
1555+ // interintra flags
1556+ const int ii_sz_grp = av1_ymode_size_context[bs];
1557+ if (f->seq_hdr.inter_intra &&
1558+ interintra_allowed_mask & (1 << bs) &&
1559+ msac_decode_bool_adapt(&ts->msac, ts->cdf.m.interintra[ii_sz_grp]))
1560+ {
1561+ b->interintra_mode = msac_decode_symbol_adapt(&ts->msac,
1562+ ts->cdf.m.interintra_mode[ii_sz_grp],
1563+ N_INTER_INTRA_PRED_MODES);
1564+ const int wedge_ctx = av1_wedge_ctx_lut[bs];
1565+ b->interintra_type = INTER_INTRA_BLEND +
1566+ msac_decode_bool_adapt(&ts->msac,
1567+ ts->cdf.m.interintra_wedge[wedge_ctx]);
1568+ if (b->interintra_type == INTER_INTRA_WEDGE)
1569+ b->wedge_idx = msac_decode_symbol_adapt(&ts->msac,
1570+ ts->cdf.m.wedge_idx[wedge_ctx], 16);
1571+ } else {
1572+ b->interintra_type = INTER_INTRA_NONE;
1573+ }
1574+ if (DEBUG_BLOCK_INFO && f->seq_hdr.inter_intra &&
1575+ interintra_allowed_mask & (1 << bs))
1576+ {
1577+ printf("Post-interintra[t=%d,m=%d,w=%d]: r=%d\n",
1578+ b->interintra_type, b->interintra_mode,
1579+ b->wedge_idx, ts->msac.rng);
1580+ }
1581+
1582+ // motion variation
1583+ if (f->frame_hdr.switchable_motion_mode &&
1584+ b->interintra_type == INTER_INTRA_NONE && imin(bw4, bh4) >= 2 &&
1585+ // is not warped global motion
1586+ !(!f->frame_hdr.force_integer_mv && b->inter_mode == GLOBALMV &&
1587+ f->frame_hdr.gmv[b->ref[0]].type > WM_TYPE_TRANSLATION) &&
1588+ // has overlappable neighbours
1589+ ((have_left && findoddzero(&t->l.intra[by4 + 1], h4 >> 1)) ||
1590+ (have_top && findoddzero(&t->a->intra[bx4 + 1], w4 >> 1))))
1591+ {
1592+ // reaching here means the block allows obmc - check warp by
1593+ // finding matching-ref blocks in top/left edges
1594+ uint64_t mask[2] = { 0, 0 };
1595+ find_matching_ref(t, intra_edge_flags, bw4, bh4, w4, h4,
1596+ have_left, have_top, b->ref[0], mask);
1597+ const int allow_warp = !f->frame_hdr.force_integer_mv &&
1598+ f->frame_hdr.warp_motion && (mask[0] | mask[1]);
1599+
1600+ b->motion_mode = allow_warp ?
1601+ msac_decode_symbol_adapt(&ts->msac, ts->cdf.m.motion_mode[bs], 3) :
1602+ msac_decode_bool_adapt(&ts->msac, ts->cdf.m.obmc[bs]);
1603+ if (b->motion_mode == MM_WARP) {
1604+ has_subpel_filter = 0;
1605+ derive_warpmv(t, bw4, bh4, mask, b->mv[0], &t->warpmv);
1606+#define signabs(v) v < 0 ? '-' : ' ', abs(v)
1607+ if (DEBUG_BLOCK_INFO)
1608+ printf("[ %c%x %c%x %c%x\n %c%x %c%x %c%x ]\n"
1609+ "alpha=%c%x, beta=%c%x, gamma=%c%x, delta=%c%x\n",
1610+ signabs(t->warpmv.matrix[0]),
1611+ signabs(t->warpmv.matrix[1]),
1612+ signabs(t->warpmv.matrix[2]),
1613+ signabs(t->warpmv.matrix[3]),
1614+ signabs(t->warpmv.matrix[4]),
1615+ signabs(t->warpmv.matrix[5]),
1616+ signabs(t->warpmv.alpha),
1617+ signabs(t->warpmv.beta),
1618+ signabs(t->warpmv.gamma),
1619+ signabs(t->warpmv.delta));
1620+#undef signabs
1621+ }
1622+
1623+ if (DEBUG_BLOCK_INFO)
1624+ printf("Post-motionmode[%d]: r=%d [mask: 0x%" PRIu64 "x/0x%"
1625+ PRIu64 "x]\n", b->motion_mode, ts->msac.rng, mask[0],
1626+ mask[1]);
1627+ } else {
1628+ b->motion_mode = MM_TRANSLATION;
1629+ }
1630+ }
1631+
1632+ // subpel filter
1633+ enum FilterMode filter[2];
1634+ if (f->frame_hdr.subpel_filter_mode == FILTER_SWITCHABLE) {
1635+ if (has_subpel_filter) {
1636+ const int comp = b->comp_type != COMP_INTER_NONE;
1637+ const int ctx1 = get_filter_ctx(t->a, &t->l, comp, 0, b->ref[0],
1638+ by4, bx4);
1639+ filter[0] = msac_decode_symbol_adapt(&ts->msac,
1640+ ts->cdf.m.filter[0][ctx1], N_SWITCHABLE_FILTERS);
1641+ if (f->seq_hdr.dual_filter) {
1642+ const int ctx2 = get_filter_ctx(t->a, &t->l, comp, 1,
1643+ b->ref[0], by4, bx4);
1644+ if (DEBUG_BLOCK_INFO)
1645+ printf("Post-subpel_filter1[%d,ctx=%d]: r=%d\n",
1646+ filter[0], ctx1, ts->msac.rng);
1647+ filter[1] = msac_decode_symbol_adapt(&ts->msac,
1648+ ts->cdf.m.filter[1][ctx2], N_SWITCHABLE_FILTERS);
1649+ if (DEBUG_BLOCK_INFO)
1650+ printf("Post-subpel_filter2[%d,ctx=%d]: r=%d\n",
1651+ filter[1], ctx2, ts->msac.rng);
1652+ } else {
1653+ filter[1] = filter[0];
1654+ if (DEBUG_BLOCK_INFO)
1655+ printf("Post-subpel_filter[%d,ctx=%d]: r=%d\n",
1656+ filter[0], ctx1, ts->msac.rng);
1657+ }
1658+ } else {
1659+ filter[0] = filter[1] = FILTER_8TAP_REGULAR;
1660+ }
1661+ } else {
1662+ filter[0] = filter[1] = f->frame_hdr.subpel_filter_mode;
1663+ }
1664+ b->filter2d = av1_filter_2d[filter[1]][filter[0]];
1665+
1666+ read_vartx_tree(t, b, bs, bx4, by4);
1667+
1668+ // reconstruction
1669+ if (f->frame_thread.pass == 1) {
1670+ f->bd_fn.read_coef_blocks(t, bs, b);
1671+ } else {
1672+ f->bd_fn.recon_b_inter(t, bs, b);
1673+ }
1674+
1675+ const int is_globalmv =
1676+ b->inter_mode == (is_comp ? GLOBALMV_GLOBALMV : GLOBALMV);
1677+ const uint8_t (*const lf_lvls)[8][2] = (const uint8_t (*)[8][2])
1678+ &ts->lflvl[b->seg_id][0][b->ref[0] + 1][!is_globalmv];
1679+ dav1d_create_lf_mask_inter(t->lf_mask, f->lf.level, f->b4_stride,
1680+ &f->frame_hdr, lf_lvls, t->bx, t->by,
1681+ f->bw, f->bh, b->skip, bs, b->tx_split,
1682+ b->uvtx, f->cur.p.p.layout,
1683+ &t->a->tx_lpf_y[bx4], &t->l.tx_lpf_y[by4],
1684+ has_chroma ? &t->a->tx_lpf_uv[cbx4] : NULL,
1685+ has_chroma ? &t->l.tx_lpf_uv[cby4] : NULL);
1686+
1687+ // context updates
1688+ if (is_comp) {
1689+ splat_tworef_mv(f->mvs, f->b4_stride, t->by, t->bx, bs,
1690+ b->inter_mode, b->ref[0], b->ref[1],
1691+ b->mv[0], b->mv[1]);
1692+ } else {
1693+ splat_oneref_mv(f->mvs, f->b4_stride, t->by, t->bx, bs,
1694+ b->inter_mode, b->ref[0], b->mv[0],
1695+ b->interintra_type);
1696+ }
1697+ memset(&t->l.pal_sz[by4], 0, bh4);
1698+ memset(&t->a->pal_sz[bx4], 0, bw4);
1699+ if (has_chroma) {
1700+ memset(&t->l.uvmode[cby4], DC_PRED, cbh4);
1701+ memset(&t->a->uvmode[cbx4], DC_PRED, cbw4);
1702+ memset(&t->pal_sz_uv[1][cby4], 0, cbh4);
1703+ memset(&t->pal_sz_uv[0][cbx4], 0, cbw4);
1704+ }
1705+ memset(&t->a->tx_intra[bx4], b_dim[2], bw4);
1706+ memset(&t->l.tx_intra[by4], b_dim[3], bh4);
1707+ memset(&t->l.comp_type[by4], b->comp_type, bh4);
1708+ memset(&t->a->comp_type[bx4], b->comp_type, bw4);
1709+ memset(&t->l.filter[0][by4], filter[0], bh4);
1710+ memset(&t->a->filter[0][bx4], filter[0], bw4);
1711+ memset(&t->l.filter[1][by4], filter[1], bh4);
1712+ memset(&t->a->filter[1][bx4], filter[1], bw4);
1713+ memset(&t->l.mode[by4], b->inter_mode, bh4);
1714+ memset(&t->a->mode[bx4], b->inter_mode, bw4);
1715+ memset(&t->l.ref[0][by4], b->ref[0], bh4);
1716+ memset(&t->a->ref[0][bx4], b->ref[0], bw4);
1717+ memset(&t->l.ref[1][by4], b->ref[1], bh4);
1718+ memset(&t->a->ref[1][bx4], b->ref[1], bw4);
1719+ }
1720+
1721+ // update contexts
1722+ if (f->frame_hdr.segmentation.enabled &&
1723+ f->frame_hdr.segmentation.update_map)
1724+ {
1725+ uint8_t *seg_ptr = &f->cur_segmap[t->by * f->b4_stride + t->bx];
1726+ for (int y = 0; y < bh4; y++) {
1727+ memset(seg_ptr, b->seg_id, bw4);
1728+ seg_ptr += f->b4_stride;
1729+ }
1730+ }
1731+ memset(&t->l.seg_pred[by4], seg_pred, bh4);
1732+ memset(&t->a->seg_pred[bx4], seg_pred, bw4);
1733+ memset(&t->l.skip_mode[by4], b->skip_mode, bh4);
1734+ memset(&t->a->skip_mode[bx4], b->skip_mode, bw4);
1735+ memset(&t->l.intra[by4], b->intra, bh4);
1736+ memset(&t->a->intra[bx4], b->intra, bw4);
1737+ memset(&t->l.skip[by4], b->skip, bh4);
1738+ memset(&t->a->skip[bx4], b->skip, bw4);
1739+ if (!b->skip) {
1740+ uint32_t *noskip_mask = &t->lf_mask->noskip_mask[by4];
1741+ const unsigned mask = ((1ULL << bw4) - 1) << bx4;
1742+ for (int y = 0; y < bh4; y++)
1743+ *noskip_mask++ |= mask;
1744+ }
1745+}
1746+
1747+static int decode_sb(Dav1dTileContext *const t, const enum BlockLevel bl,
1748+ const EdgeNode *const node)
1749+{
1750+ const Dav1dFrameContext *const f = t->f;
1751+ const int hsz = 16 >> bl;
1752+ const int have_h_split = f->bw > t->bx + hsz;
1753+ const int have_v_split = f->bh > t->by + hsz;
1754+
1755+ if (!have_h_split && !have_v_split) {
1756+ assert(bl < BL_8X8);
1757+ return decode_sb(t, bl + 1, ((const EdgeBranch *) node)->split[0]);
1758+ }
1759+
1760+ uint16_t *pc;
1761+ enum BlockPartition bp;
1762+ int ctx, bx8, by8;
1763+ if (f->frame_thread.pass != 2) {
1764+ if (0 && bl == BL_64X64)
1765+ printf("poc=%d,y=%d,x=%d,bl=%d,r=%d\n",
1766+ f->frame_hdr.frame_offset, t->by, t->bx, bl, t->ts->msac.rng);
1767+ bx8 = (t->bx & 31) >> 1;
1768+ by8 = (t->by & 31) >> 1;
1769+ ctx = get_partition_ctx(t->a, &t->l, bl, by8, bx8);
1770+ pc = t->ts->cdf.m.partition[bl][ctx];
1771+ }
1772+
1773+ if (have_h_split && have_v_split) {
1774+ if (f->frame_thread.pass == 2) {
1775+ const Av1Block *const b = &f->frame_thread.b[t->by * f->b4_stride + t->bx];
1776+ bp = b->bl == bl ? b->bp : PARTITION_SPLIT;
1777+ } else {
1778+ const unsigned n_part = bl == BL_8X8 ? N_SUB8X8_PARTITIONS :
1779+ bl == BL_128X128 ? N_PARTITIONS - 2 : N_PARTITIONS;
1780+ bp = msac_decode_symbol_adapt(&t->ts->msac, pc, n_part);
1781+ if (f->cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I422 &&
1782+ (bp == PARTITION_V || bp == PARTITION_V4 ||
1783+ bp == PARTITION_T_LEFT_SPLIT || bp == PARTITION_T_RIGHT_SPLIT))
1784+ {
1785+ return 1;
1786+ }
1787+ if (DEBUG_BLOCK_INFO)
1788+ printf("poc=%d,y=%d,x=%d,bl=%d,ctx=%d,bp=%d: r=%d\n",
1789+ f->frame_hdr.frame_offset, t->by, t->bx, bl, ctx, bp,
1790+ t->ts->msac.rng);
1791+ }
1792+ const uint8_t *const b = av1_block_sizes[bl][bp];
1793+
1794+ switch (bp) {
1795+ case PARTITION_NONE:
1796+ decode_b(t, bl, b[0], PARTITION_NONE, node->o);
1797+ break;
1798+ case PARTITION_H:
1799+ decode_b(t, bl, b[0], PARTITION_H, node->h[0]);
1800+ t->by += hsz;
1801+ decode_b(t, bl, b[0], PARTITION_H, node->h[1]);
1802+ t->by -= hsz;
1803+ break;
1804+ case PARTITION_V:
1805+ decode_b(t, bl, b[0], PARTITION_V, node->v[0]);
1806+ t->bx += hsz;
1807+ decode_b(t, bl, b[0], PARTITION_V, node->v[1]);
1808+ t->bx -= hsz;
1809+ break;
1810+ case PARTITION_SPLIT:
1811+ if (bl == BL_8X8) {
1812+ const EdgeTip *const tip = (const EdgeTip *) node;
1813+ assert(hsz == 1);
1814+ decode_b(t, bl, BS_4x4, PARTITION_SPLIT, tip->split[0]);
1815+ const enum Filter2d tl_filter = t->tl_4x4_filter;
1816+ t->bx++;
1817+ decode_b(t, bl, BS_4x4, PARTITION_SPLIT, tip->split[1]);
1818+ t->bx--;
1819+ t->by++;
1820+ decode_b(t, bl, BS_4x4, PARTITION_SPLIT, tip->split[2]);
1821+ t->bx++;
1822+ t->tl_4x4_filter = tl_filter;
1823+ decode_b(t, bl, BS_4x4, PARTITION_SPLIT, tip->split[3]);
1824+ t->bx--;
1825+ t->by--;
1826+ } else {
1827+ const EdgeBranch *const branch = (const EdgeBranch *) node;
1828+ if (decode_sb(t, bl + 1, branch->split[0])) return 1;
1829+ t->bx += hsz;
1830+ if (decode_sb(t, bl + 1, branch->split[1])) return 1;
1831+ t->bx -= hsz;
1832+ t->by += hsz;
1833+ if (decode_sb(t, bl + 1, branch->split[2])) return 1;
1834+ t->bx += hsz;
1835+ if (decode_sb(t, bl + 1, branch->split[3])) return 1;
1836+ t->bx -= hsz;
1837+ t->by -= hsz;
1838+ }
1839+ break;
1840+ case PARTITION_T_TOP_SPLIT: {
1841+ const EdgeBranch *const branch = (const EdgeBranch *) node;
1842+ decode_b(t, bl, b[0], PARTITION_T_TOP_SPLIT, branch->tts[0]);
1843+ t->bx += hsz;
1844+ decode_b(t, bl, b[0], PARTITION_T_TOP_SPLIT, branch->tts[1]);
1845+ t->bx -= hsz;
1846+ t->by += hsz;
1847+ decode_b(t, bl, b[1], PARTITION_T_TOP_SPLIT, branch->tts[2]);
1848+ t->by -= hsz;
1849+ break;
1850+ }
1851+ case PARTITION_T_BOTTOM_SPLIT: {
1852+ const EdgeBranch *const branch = (const EdgeBranch *) node;
1853+ decode_b(t, bl, b[0], PARTITION_T_BOTTOM_SPLIT, branch->tbs[0]);
1854+ t->by += hsz;
1855+ decode_b(t, bl, b[1], PARTITION_T_BOTTOM_SPLIT, branch->tbs[1]);
1856+ t->bx += hsz;
1857+ decode_b(t, bl, b[1], PARTITION_T_BOTTOM_SPLIT, branch->tbs[2]);
1858+ t->bx -= hsz;
1859+ t->by -= hsz;
1860+ break;
1861+ }
1862+ case PARTITION_T_LEFT_SPLIT: {
1863+ const EdgeBranch *const branch = (const EdgeBranch *) node;
1864+ decode_b(t, bl, b[0], PARTITION_T_LEFT_SPLIT, branch->tls[0]);
1865+ t->by += hsz;
1866+ decode_b(t, bl, b[0], PARTITION_T_LEFT_SPLIT, branch->tls[1]);
1867+ t->by -= hsz;
1868+ t->bx += hsz;
1869+ decode_b(t, bl, b[1], PARTITION_T_LEFT_SPLIT, branch->tls[2]);
1870+ t->bx -= hsz;
1871+ break;
1872+ }
1873+ case PARTITION_T_RIGHT_SPLIT: {
1874+ const EdgeBranch *const branch = (const EdgeBranch *) node;
1875+ decode_b(t, bl, b[0], PARTITION_T_RIGHT_SPLIT, branch->trs[0]);
1876+ t->bx += hsz;
1877+ decode_b(t, bl, b[1], PARTITION_T_RIGHT_SPLIT, branch->trs[1]);
1878+ t->by += hsz;
1879+ decode_b(t, bl, b[1], PARTITION_T_RIGHT_SPLIT, branch->trs[2]);
1880+ t->by -= hsz;
1881+ t->bx -= hsz;
1882+ break;
1883+ }
1884+ case PARTITION_H4: {
1885+ const EdgeBranch *const branch = (const EdgeBranch *) node;
1886+ decode_b(t, bl, b[0], PARTITION_H4, branch->h4[0]);
1887+ t->by += hsz >> 1;
1888+ decode_b(t, bl, b[0], PARTITION_H4, branch->h4[1]);
1889+ t->by += hsz >> 1;
1890+ decode_b(t, bl, b[0], PARTITION_H4, branch->h4[2]);
1891+ t->by += hsz >> 1;
1892+ if (t->by < f->bh)
1893+ decode_b(t, bl, b[0], PARTITION_H4, branch->h4[3]);
1894+ t->by -= hsz * 3 >> 1;
1895+ break;
1896+ }
1897+ case PARTITION_V4: {
1898+ const EdgeBranch *const branch = (const EdgeBranch *) node;
1899+ decode_b(t, bl, b[0], PARTITION_V4, branch->v4[0]);
1900+ t->bx += hsz >> 1;
1901+ decode_b(t, bl, b[0], PARTITION_V4, branch->v4[1]);
1902+ t->bx += hsz >> 1;
1903+ decode_b(t, bl, b[0], PARTITION_V4, branch->v4[2]);
1904+ t->bx += hsz >> 1;
1905+ if (t->bx < f->bw)
1906+ decode_b(t, bl, b[0], PARTITION_V4, branch->v4[3]);
1907+ t->bx -= hsz * 3 >> 1;
1908+ break;
1909+ }
1910+ default: assert(0);
1911+ }
1912+ } else if (have_h_split) {
1913+ unsigned is_split;
1914+ if (f->frame_thread.pass == 2) {
1915+ const Av1Block *const b = &f->frame_thread.b[t->by * f->b4_stride + t->bx];
1916+ is_split = b->bl != bl;
1917+ } else {
1918+ const unsigned p = gather_top_partition_prob(pc, bl);
1919+ is_split = msac_decode_bool(&t->ts->msac, p);
1920+ if (DEBUG_BLOCK_INFO)
1921+ printf("poc=%d,y=%d,x=%d,bl=%d,ctx=%d,bp=%d: r=%d\n",
1922+ f->frame_hdr.frame_offset, t->by, t->bx, bl, ctx,
1923+ is_split ? PARTITION_SPLIT : PARTITION_H, t->ts->msac.rng);
1924+ }
1925+
1926+ assert(bl < BL_8X8);
1927+ if (is_split) {
1928+ const EdgeBranch *const branch = (const EdgeBranch *) node;
1929+ bp = PARTITION_SPLIT;
1930+ if (decode_sb(t, bl + 1, branch->split[0])) return 1;
1931+ t->bx += hsz;
1932+ if (decode_sb(t, bl + 1, branch->split[1])) return 1;
1933+ t->bx -= hsz;
1934+ } else {
1935+ bp = PARTITION_H;
1936+ decode_b(t, bl, av1_block_sizes[bl][PARTITION_H][0], PARTITION_H,
1937+ node->h[0]);
1938+ }
1939+ } else {
1940+ assert(have_v_split);
1941+ unsigned is_split;
1942+ if (f->frame_thread.pass == 2) {
1943+ const Av1Block *const b = &f->frame_thread.b[t->by * f->b4_stride + t->bx];
1944+ is_split = b->bl != bl;
1945+ } else {
1946+ const unsigned p = gather_left_partition_prob(pc, bl);
1947+ is_split = msac_decode_bool(&t->ts->msac, p);
1948+ if (f->cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I422 && !is_split)
1949+ return 1;
1950+ if (DEBUG_BLOCK_INFO)
1951+ printf("poc=%d,y=%d,x=%d,bl=%d,ctx=%d,bp=%d: r=%d\n",
1952+ f->frame_hdr.frame_offset, t->by, t->bx, bl, ctx,
1953+ is_split ? PARTITION_SPLIT : PARTITION_V, t->ts->msac.rng);
1954+ }
1955+
1956+ assert(bl < BL_8X8);
1957+ if (is_split) {
1958+ const EdgeBranch *const branch = (const EdgeBranch *) node;
1959+ bp = PARTITION_SPLIT;
1960+ if (decode_sb(t, bl + 1, branch->split[0])) return 1;
1961+ t->by += hsz;
1962+ if (decode_sb(t, bl + 1, branch->split[2])) return 1;
1963+ t->by -= hsz;
1964+ } else {
1965+ bp = PARTITION_V;
1966+ decode_b(t, bl, av1_block_sizes[bl][PARTITION_V][0], PARTITION_V,
1967+ node->v[0]);
1968+ }
1969+ }
1970+
1971+ if (f->frame_thread.pass != 2 && (bp != PARTITION_SPLIT || bl == BL_8X8)) {
1972+ memset(&t->a->partition[bx8], av1_al_part_ctx[0][bl][bp], hsz);
1973+ memset(&t->l.partition[by8], av1_al_part_ctx[1][bl][bp], hsz);
1974+ }
1975+
1976+ return 0;
1977+}
1978+
1979+static void reset_context(BlockContext *const ctx, const int keyframe, const int pass) {
1980+ memset(ctx->intra, keyframe, sizeof(ctx->intra));
1981+ memset(ctx->uvmode, DC_PRED, sizeof(ctx->uvmode));
1982+ if (keyframe)
1983+ memset(ctx->mode, DC_PRED, sizeof(ctx->mode));
1984+
1985+ if (pass == 2) return;
1986+
1987+ memset(ctx->partition, 0, sizeof(ctx->partition));
1988+ memset(ctx->skip, 0, sizeof(ctx->skip));
1989+ memset(ctx->skip_mode, 0, sizeof(ctx->skip_mode));
1990+ memset(ctx->tx_lpf_y, 2, sizeof(ctx->tx_lpf_y));
1991+ memset(ctx->tx_lpf_uv, 1, sizeof(ctx->tx_lpf_uv));
1992+ memset(ctx->tx_intra, -1, sizeof(ctx->tx_intra));
1993+ memset(ctx->tx, TX_64X64, sizeof(ctx->tx));
1994+ if (!keyframe) {
1995+ memset(ctx->ref, -1, sizeof(ctx->ref));
1996+ memset(ctx->comp_type, 0, sizeof(ctx->comp_type));
1997+ memset(ctx->mode, NEARESTMV, sizeof(ctx->mode));
1998+ }
1999+ memset(ctx->lcoef, 0x40, sizeof(ctx->lcoef));
2000+ memset(ctx->ccoef, 0x40, sizeof(ctx->ccoef));
2001+ memset(ctx->filter, N_SWITCHABLE_FILTERS, sizeof(ctx->filter));
2002+ memset(ctx->seg_pred, 0, sizeof(ctx->seg_pred));
2003+ memset(ctx->pal_sz, 0, sizeof(ctx->pal_sz));
2004+}
2005+
2006+static void setup_tile(Dav1dTileState *const ts,
2007+ const Dav1dFrameContext *const f,
2008+ const uint8_t *const data, const size_t sz,
2009+ const int tile_row, const int tile_col,
2010+ const int tile_start_off)
2011+{
2012+ const int col_sb_start = f->frame_hdr.tiling.col_start_sb[tile_col];
2013+ const int col_sb128_start = col_sb_start >> !f->seq_hdr.sb128;
2014+ const int col_sb_end = f->frame_hdr.tiling.col_start_sb[tile_col + 1];
2015+ const int row_sb_start = f->frame_hdr.tiling.row_start_sb[tile_row];
2016+ const int row_sb_end = f->frame_hdr.tiling.row_start_sb[tile_row + 1];
2017+ const int sb_shift = f->sb_shift;
2018+
2019+ ts->frame_thread.pal_idx = &f->frame_thread.pal_idx[tile_start_off * 2];
2020+ ts->frame_thread.cf = &((int32_t *) f->frame_thread.cf)[tile_start_off * 3];
2021+ ts->cdf = *f->in_cdf.cdf;
2022+ ts->last_qidx = f->frame_hdr.quant.yac;
2023+ memset(ts->last_delta_lf, 0, sizeof(ts->last_delta_lf));
2024+
2025+ msac_init(&ts->msac, data, sz);
2026+
2027+ ts->tiling.row = tile_row;
2028+ ts->tiling.col = tile_col;
2029+ ts->tiling.col_start = col_sb_start << sb_shift;
2030+ ts->tiling.col_end = imin(col_sb_end << sb_shift, f->bw);
2031+ ts->tiling.row_start = row_sb_start << sb_shift;
2032+ ts->tiling.row_end = imin(row_sb_end << sb_shift, f->bh);
2033+
2034+ // Reference Restoration Unit (used for exp coding)
2035+ Av1Filter *const lf_mask =
2036+ f->lf.mask + (ts->tiling.row_start >> 5) * f->sb128w + col_sb128_start;
2037+ const int unit_idx = ((ts->tiling.row_start & 16) >> 3) +
2038+ ((ts->tiling.col_start & 16) >> 4);
2039+ for (int p = 0; p < 3; p++) {
2040+ ts->lr_ref[p] = &lf_mask->lr[p][unit_idx];
2041+ ts->lr_ref[p]->filter_v[0] = 3;
2042+ ts->lr_ref[p]->filter_v[1] = -7;
2043+ ts->lr_ref[p]->filter_v[2] = 15;
2044+ ts->lr_ref[p]->filter_h[0] = 3;
2045+ ts->lr_ref[p]->filter_h[1] = -7;
2046+ ts->lr_ref[p]->filter_h[2] = 15;
2047+ ts->lr_ref[p]->sgr_weights[0] = -32;
2048+ ts->lr_ref[p]->sgr_weights[1] = 31;
2049+ }
2050+
2051+ if (f->n_tc > 1)
2052+ atomic_init(&ts->progress, 0);
2053+}
2054+
2055+int decode_tile_sbrow(Dav1dTileContext *const t) {
2056+ const Dav1dFrameContext *const f = t->f;
2057+ const enum BlockLevel root_bl = f->seq_hdr.sb128 ? BL_128X128 : BL_64X64;
2058+ Dav1dTileState *const ts = t->ts;
2059+ const Dav1dContext *const c = f->c;
2060+ const int sb_step = f->sb_step;
2061+ const int tile_row = ts->tiling.row, tile_col = ts->tiling.col;
2062+ const int col_sb_start = f->frame_hdr.tiling.col_start_sb[tile_col];
2063+ const int col_sb128_start = col_sb_start >> !f->seq_hdr.sb128;
2064+
2065+ reset_context(&t->l, !(f->frame_hdr.frame_type & 1), f->frame_thread.pass);
2066+ if (f->frame_thread.pass == 2) {
2067+ for (t->bx = ts->tiling.col_start,
2068+ t->a = f->a + col_sb128_start + tile_row * f->sb128w;
2069+ t->bx < ts->tiling.col_end; t->bx += sb_step)
2070+ {
2071+ if (decode_sb(t, root_bl, c->intra_edge.root[root_bl]))
2072+ return 1;
2073+ if (t->bx & 16 || f->seq_hdr.sb128)
2074+ t->a++;
2075+ }
2076+ f->bd_fn.backup_ipred_edge(t);
2077+ return 0;
2078+ }
2079+
2080+ const int ss_ver = f->cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
2081+ const int ss_hor = f->cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
2082+
2083+ if (c->n_fc > 1 && f->frame_hdr.use_ref_frame_mvs) {
2084+ for (int n = 0; n < 7; n++)
2085+ dav1d_thread_picture_wait(&f->refp[n], 4 * (t->by + sb_step),
2086+ PLANE_TYPE_BLOCK);
2087+ av1_init_ref_mv_tile_row(f->libaom_cm,
2088+ ts->tiling.col_start, ts->tiling.col_end,
2089+ t->by, imin(t->by + sb_step, f->bh));
2090+ }
2091+ memset(t->pal_sz_uv[1], 0, sizeof(*t->pal_sz_uv));
2092+ const int sb128y = t->by >> 5;
2093+ for (t->bx = ts->tiling.col_start, t->a = f->a + col_sb128_start + tile_row * f->sb128w,
2094+ t->lf_mask = f->lf.mask + sb128y * f->sb128w + col_sb128_start;
2095+ t->bx < ts->tiling.col_end; t->bx += sb_step)
2096+ {
2097+ if (root_bl == BL_128X128) {
2098+ t->cur_sb_cdef_idx_ptr = t->lf_mask->cdef_idx;
2099+ t->cur_sb_cdef_idx_ptr[0] = -1;
2100+ t->cur_sb_cdef_idx_ptr[1] = -1;
2101+ t->cur_sb_cdef_idx_ptr[2] = -1;
2102+ t->cur_sb_cdef_idx_ptr[3] = -1;
2103+ } else {
2104+ t->cur_sb_cdef_idx_ptr =
2105+ &t->lf_mask->cdef_idx[((t->bx & 16) >> 4) +
2106+ ((t->by & 16) >> 3)];
2107+ t->cur_sb_cdef_idx_ptr[0] = -1;
2108+ }
2109+ // Restoration filter
2110+ for (int p = 0; p < 3; p++) {
2111+ if (f->frame_hdr.restoration.type[p] == RESTORATION_NONE)
2112+ continue;
2113+ const int by = t->by >> (ss_ver & !!p);
2114+ const int bx = t->bx >> (ss_hor & !!p);
2115+ const int bh = f->bh >> (ss_ver & !!p);
2116+ const int bw = f->bw >> (ss_hor & !!p);
2117+
2118+ const int unit_size_log2 =
2119+ f->frame_hdr.restoration.unit_size[!!p];
2120+ // 4pel unit size
2121+ const int b_unit_size = 1 << (unit_size_log2 - 2);
2122+ const unsigned mask = b_unit_size - 1;
2123+ if (by & mask || bx & mask) continue;
2124+ const int half_unit = b_unit_size >> 1;
2125+ // Round half up at frame boundaries, if there's more than one
2126+ // restoration unit
2127+ const int bottom_round = by && by + half_unit > bh;
2128+ const int right_round = bx && bx + half_unit > bw;
2129+ if (bottom_round || right_round) continue;
2130+ const int unit_idx = ((t->by & 16) >> 3) + ((t->bx & 16) >> 4);
2131+ Av1RestorationUnit *const lr = &t->lf_mask->lr[p][unit_idx];
2132+ const enum RestorationType frame_type =
2133+ f->frame_hdr.restoration.type[p];
2134+
2135+ if (frame_type == RESTORATION_SWITCHABLE) {
2136+ const int filter =
2137+ msac_decode_symbol_adapt(&ts->msac,
2138+ ts->cdf.m.restore_switchable, 3);
2139+ lr->type = filter ? filter == 2 ? RESTORATION_SGRPROJ :
2140+ RESTORATION_WIENER :
2141+ RESTORATION_NONE;
2142+ } else {
2143+ const unsigned type =
2144+ msac_decode_bool_adapt(&ts->msac,
2145+ frame_type == RESTORATION_WIENER ?
2146+ ts->cdf.m.restore_wiener :
2147+ ts->cdf.m.restore_sgrproj);
2148+ lr->type = type ? frame_type : RESTORATION_NONE;
2149+ }
2150+
2151+ if (lr->type == RESTORATION_WIENER) {
2152+ lr->filter_v[0] =
2153+ !p ? msac_decode_subexp(&ts->msac,
2154+ ts->lr_ref[p]->filter_v[0] + 5, 16,
2155+ 1) - 5:
2156+ 0;
2157+ lr->filter_v[1] =
2158+ msac_decode_subexp(&ts->msac,
2159+ ts->lr_ref[p]->filter_v[1] + 23, 32,
2160+ 2) - 23;
2161+ lr->filter_v[2] =
2162+ msac_decode_subexp(&ts->msac,
2163+ ts->lr_ref[p]->filter_v[2] + 17, 64,
2164+ 3) - 17;
2165+
2166+ lr->filter_h[0] =
2167+ !p ? msac_decode_subexp(&ts->msac,
2168+ ts->lr_ref[p]->filter_h[0] + 5, 16,
2169+ 1) - 5:
2170+ 0;
2171+ lr->filter_h[1] =
2172+ msac_decode_subexp(&ts->msac,
2173+ ts->lr_ref[p]->filter_h[1] + 23, 32,
2174+ 2) - 23;
2175+ lr->filter_h[2] =
2176+ msac_decode_subexp(&ts->msac,
2177+ ts->lr_ref[p]->filter_h[2] + 17, 64,
2178+ 3) - 17;
2179+ memcpy(lr->sgr_weights, ts->lr_ref[p]->sgr_weights, sizeof(lr->sgr_weights));
2180+ ts->lr_ref[p] = lr;
2181+ if (DEBUG_BLOCK_INFO)
2182+ printf("Post-lr_wiener[pl=%d,v[%d,%d,%d],h[%d,%d,%d]]: r=%d\n",
2183+ p, lr->filter_v[0], lr->filter_v[1],
2184+ lr->filter_v[2], lr->filter_h[0],
2185+ lr->filter_h[1], lr->filter_h[2], ts->msac.rng);
2186+ } else if (lr->type == RESTORATION_SGRPROJ) {
2187+ const unsigned idx = msac_decode_bools(&ts->msac, 4);
2188+ lr->sgr_idx = idx;
2189+ lr->sgr_weights[0] = sgr_params[idx][0] ?
2190+ msac_decode_subexp(&ts->msac,
2191+ ts->lr_ref[p]->sgr_weights[0] + 96, 128,
2192+ 4) - 96 :
2193+ 0;
2194+ lr->sgr_weights[1] = sgr_params[idx][1] ?
2195+ msac_decode_subexp(&ts->msac,
2196+ ts->lr_ref[p]->sgr_weights[1] + 32, 128,
2197+ 4) - 32 :
2198+ iclip(128 - lr->sgr_weights[0], -32, 95);
2199+ memcpy(lr->filter_v, ts->lr_ref[p]->filter_v, sizeof(lr->filter_v));
2200+ memcpy(lr->filter_h, ts->lr_ref[p]->filter_h, sizeof(lr->filter_h));
2201+ ts->lr_ref[p] = lr;
2202+ if (DEBUG_BLOCK_INFO)
2203+ printf("Post-lr_sgrproj[pl=%d,idx=%d,w[%d,%d]]: r=%d\n",
2204+ p, lr->sgr_idx, lr->sgr_weights[0],
2205+ lr->sgr_weights[1], ts->msac.rng);
2206+ }
2207+ }
2208+ if (decode_sb(t, root_bl, c->intra_edge.root[root_bl]))
2209+ return 1;
2210+ if (t->bx & 16 || f->seq_hdr.sb128) {
2211+ t->a++;
2212+ t->lf_mask++;
2213+ }
2214+ }
2215+
2216+ // backup pre-loopfilter pixels for intra prediction of the next sbrow
2217+ if (f->frame_thread.pass != 1)
2218+ f->bd_fn.backup_ipred_edge(t);
2219+
2220+ // backup t->a/l.tx_lpf_y/uv at tile boundaries to use them to "fix"
2221+ // up the initial value in neighbour tiles when running the loopfilter
2222+ int align_h = (f->bh + 31) & ~31;
2223+ memcpy(&f->lf.tx_lpf_right_edge[0][align_h * tile_col + t->by],
2224+ &t->l.tx_lpf_y[t->by & 16], sb_step);
2225+ align_h >>= 1;
2226+ memcpy(&f->lf.tx_lpf_right_edge[1][align_h * tile_col + (t->by >> 1)],
2227+ &t->l.tx_lpf_uv[(t->by & 16) >> 1], sb_step >> 1);
2228+
2229+ return 0;
2230+}
2231+
2232+int decode_frame(Dav1dFrameContext *const f) {
2233+ const Dav1dContext *const c = f->c;
2234+
2235+ if (f->n_tc > 1) {
2236+ if (f->frame_hdr.tiling.cols * f->sbh > f->tile_thread.titsati_sz) {
2237+ f->tile_thread.task_idx_to_sby_and_tile_idx =
2238+ malloc(sizeof(*f->tile_thread.task_idx_to_sby_and_tile_idx) *
2239+ f->frame_hdr.tiling.cols * f->sbh);
2240+ if (!f->tile_thread.task_idx_to_sby_and_tile_idx) return -ENOMEM;
2241+ f->tile_thread.titsati_sz = f->frame_hdr.tiling.cols * f->sbh;
2242+ }
2243+ if (f->tile_thread.titsati_init[0] != f->frame_hdr.tiling.cols ||
2244+ f->tile_thread.titsati_init[1] != f->sbh)
2245+ {
2246+ for (int tile_row = 0, tile_idx = 0;
2247+ tile_row < f->frame_hdr.tiling.rows; tile_row++)
2248+ {
2249+ for (int sby = f->frame_hdr.tiling.row_start_sb[tile_row];
2250+ sby < f->frame_hdr.tiling.row_start_sb[tile_row + 1]; sby++)
2251+ {
2252+ for (int tile_col = 0; tile_col < f->frame_hdr.tiling.cols;
2253+ tile_col++, tile_idx++)
2254+ {
2255+ f->tile_thread.task_idx_to_sby_and_tile_idx[tile_idx][0] = sby;
2256+ f->tile_thread.task_idx_to_sby_and_tile_idx[tile_idx][1] =
2257+ tile_row * f->frame_hdr.tiling.cols + tile_col;
2258+ }
2259+ }
2260+ }
2261+ f->tile_thread.titsati_init[0] = f->frame_hdr.tiling.cols;
2262+ f->tile_thread.titsati_init[1] = f->sbh;
2263+ }
2264+ }
2265+
2266+ if (f->frame_hdr.tiling.cols * f->frame_hdr.tiling.rows > f->n_ts) {
2267+ f->ts = realloc(f->ts, f->frame_hdr.tiling.cols *
2268+ f->frame_hdr.tiling.rows * sizeof(*f->ts));
2269+ if (!f->ts) return -ENOMEM;
2270+ for (int n = f->n_ts;
2271+ n < f->frame_hdr.tiling.cols * f->frame_hdr.tiling.rows; n++)
2272+ {
2273+ Dav1dTileState *const ts = &f->ts[n];
2274+ pthread_mutex_init(&ts->tile_thread.lock, NULL);
2275+ pthread_cond_init(&ts->tile_thread.cond, NULL);
2276+ }
2277+ if (c->n_fc > 1) {
2278+ freep(&f->frame_thread.tile_start_off);
2279+ f->frame_thread.tile_start_off =
2280+ malloc(sizeof(*f->frame_thread.tile_start_off) *
2281+ f->frame_hdr.tiling.cols * f->frame_hdr.tiling.rows);
2282+ }
2283+ f->n_ts = f->frame_hdr.tiling.cols * f->frame_hdr.tiling.rows;
2284+ }
2285+
2286+ if (c->n_fc > 1) {
2287+ int tile_idx = 0;
2288+ for (int tile_row = 0; tile_row < f->frame_hdr.tiling.rows; tile_row++) {
2289+ int row_off = f->frame_hdr.tiling.row_start_sb[tile_row] *
2290+ f->sb_step * 4 * f->sb128w * 128;
2291+ int b_diff = (f->frame_hdr.tiling.row_start_sb[tile_row + 1] -
2292+ f->frame_hdr.tiling.row_start_sb[tile_row]) * f->sb_step * 4;
2293+ for (int tile_col = 0; tile_col < f->frame_hdr.tiling.cols; tile_col++) {
2294+ f->frame_thread.tile_start_off[tile_idx++] = row_off + b_diff *
2295+ f->frame_hdr.tiling.col_start_sb[tile_col] * f->sb_step * 4;
2296+ }
2297+ }
2298+ }
2299+
2300+ if (f->sb128w * f->frame_hdr.tiling.rows > f->a_sz) {
2301+ freep(&f->a);
2302+ f->a = malloc(f->sb128w * f->frame_hdr.tiling.rows * sizeof(*f->a));
2303+ if (!f->a) return -ENOMEM;
2304+ f->a_sz = f->sb128w * f->frame_hdr.tiling.rows;
2305+ }
2306+
2307+ // update allocation of block contexts for above
2308+ if (f->sb128w > f->lf.line_sz) {
2309+ dav1d_freep_aligned(&f->lf.cdef_line);
2310+ dav1d_freep_aligned(&f->lf.lr_lpf_line);
2311+
2312+ // note that we allocate all pixel arrays as if we were dealing with
2313+ // 10 bits/component data
2314+ uint16_t *ptr = f->lf.cdef_line =
2315+ dav1d_alloc_aligned(f->b4_stride * 4 * 12 * sizeof(uint16_t), 32);
2316+
2317+ uint16_t *lr_ptr = f->lf.lr_lpf_line =
2318+ dav1d_alloc_aligned(f->b4_stride * 4 * 3 * 12 * sizeof(uint16_t), 32);
2319+
2320+ for (int pl = 0; pl <= 2; pl++) {
2321+ f->lf.cdef_line_ptr[0][pl][0] = ptr + f->b4_stride * 4 * 0;
2322+ f->lf.cdef_line_ptr[0][pl][1] = ptr + f->b4_stride * 4 * 1;
2323+ f->lf.cdef_line_ptr[1][pl][0] = ptr + f->b4_stride * 4 * 2;
2324+ f->lf.cdef_line_ptr[1][pl][1] = ptr + f->b4_stride * 4 * 3;
2325+ ptr += f->b4_stride * 4 * 4;
2326+
2327+ f->lf.lr_lpf_line_ptr[pl] = lr_ptr;
2328+ lr_ptr += f->b4_stride * 4 * 12;
2329+ }
2330+
2331+ f->lf.line_sz = f->sb128w;
2332+ }
2333+
2334+ // update allocation for loopfilter masks
2335+ if (f->sb128w * f->sb128h > f->lf.mask_sz) {
2336+ freep(&f->lf.mask);
2337+ freep(&f->lf.level);
2338+ freep(&f->frame_thread.b);
2339+ f->lf.mask = malloc(f->sb128w * f->sb128h * sizeof(*f->lf.mask));
2340+ f->lf.level = malloc(f->sb128w * f->sb128h * 32 * 32 *
2341+ sizeof(*f->lf.level));
2342+ if (!f->lf.mask || !f->lf.level) return -ENOMEM;
2343+ if (c->n_fc > 1) {
2344+ freep(&f->frame_thread.b);
2345+ freep(&f->frame_thread.cbi);
2346+ dav1d_freep_aligned(&f->frame_thread.cf);
2347+ dav1d_freep_aligned(&f->frame_thread.pal_idx);
2348+ freep(&f->frame_thread.pal);
2349+ f->frame_thread.b = malloc(sizeof(*f->frame_thread.b) *
2350+ f->sb128w * f->sb128h * 32 * 32);
2351+ f->frame_thread.pal = malloc(sizeof(*f->frame_thread.pal) *
2352+ f->sb128w * f->sb128h * 16 * 16);
2353+ f->frame_thread.pal_idx =
2354+ dav1d_alloc_aligned(sizeof(*f->frame_thread.pal_idx) *
2355+ f->sb128w * f->sb128h * 128 * 128 * 2, 32);
2356+ f->frame_thread.cbi = malloc(sizeof(*f->frame_thread.cbi) *
2357+ f->sb128w * f->sb128h * 32 * 32);
2358+ f->frame_thread.cf =
2359+ dav1d_alloc_aligned(sizeof(int32_t) * 3 *
2360+ f->sb128w * f->sb128h * 128 * 128, 32);
2361+ if (!f->frame_thread.b || !f->frame_thread.pal_idx ||
2362+ !f->frame_thread.cf)
2363+ {
2364+ return -ENOMEM;
2365+ }
2366+ memset(f->frame_thread.cf, 0,
2367+ sizeof(int32_t) * 3 * f->sb128w * f->sb128h * 128 * 128);
2368+ }
2369+ f->lf.mask_sz = f->sb128w * f->sb128h;
2370+ }
2371+ if (f->frame_hdr.loopfilter.sharpness != f->lf.last_sharpness) {
2372+ dav1d_calc_eih(&f->lf.lim_lut, f->frame_hdr.loopfilter.sharpness);
2373+ f->lf.last_sharpness = f->frame_hdr.loopfilter.sharpness;
2374+ }
2375+ dav1d_calc_lf_values(f->lf.lvl, &f->frame_hdr, (int8_t[4]) { 0, 0, 0, 0 });
2376+ memset(f->lf.mask, 0, sizeof(*f->lf.mask) * f->sb128w * f->sb128h);
2377+
2378+ if (f->sbh * f->sb128w * 128 > f->ipred_edge_sz) {
2379+ dav1d_freep_aligned(&f->ipred_edge[0]);
2380+ uint16_t *ptr = f->ipred_edge[0] =
2381+ dav1d_alloc_aligned(f->sb128w * 128 * f->sbh * 3 * sizeof(uint16_t), 32);
2382+ if (!f->ipred_edge[0]) return -ENOMEM;
2383+ f->ipred_edge_sz = f->sbh * f->sb128w * 128;
2384+ f->ipred_edge[1] = &ptr[f->ipred_edge_sz];
2385+ f->ipred_edge[2] = &ptr[f->ipred_edge_sz * 2];
2386+ }
2387+
2388+ if (f->sb128h > f->lf.re_sz) {
2389+ freep(&f->lf.tx_lpf_right_edge[0]);
2390+ f->lf.tx_lpf_right_edge[0] = malloc((f->sb128h * 32 * 2) *
2391+ f->frame_hdr.tiling.cols);
2392+ if (!f->lf.tx_lpf_right_edge[0]) return -ENOMEM;
2393+ f->lf.tx_lpf_right_edge[1] = f->lf.tx_lpf_right_edge[0] +
2394+ f->sb128h * 32 * f->frame_hdr.tiling.cols;
2395+ f->lf.re_sz = f->sb128h;
2396+ }
2397+
2398+ // init ref mvs
2399+ if ((f->frame_hdr.frame_type & 1) || f->frame_hdr.allow_intrabc) {
2400+ f->mvs = f->mvs_ref->data;
2401+ const int order_hint_n_bits = f->seq_hdr.order_hint * f->seq_hdr.order_hint_n_bits;
2402+ av1_init_ref_mv_common(f->libaom_cm, f->bw >> 1, f->bh >> 1,
2403+ f->b4_stride, f->seq_hdr.sb128,
2404+ f->mvs, f->ref_mvs, f->cur.p.poc, f->refpoc,
2405+ f->refrefpoc, f->frame_hdr.gmv,
2406+ f->frame_hdr.hp, f->frame_hdr.force_integer_mv,
2407+ f->frame_hdr.use_ref_frame_mvs,
2408+ order_hint_n_bits);
2409+ if (c->n_fc == 1 && f->frame_hdr.use_ref_frame_mvs)
2410+ av1_init_ref_mv_tile_row(f->libaom_cm, 0, f->bw, 0, f->bh);
2411+ }
2412+
2413+ // setup dequant tables
2414+ init_quant_tables(&f->seq_hdr, &f->frame_hdr, f->frame_hdr.quant.yac, f->dq);
2415+ if (f->frame_hdr.quant.qm)
2416+ for (int j = 0; j < N_RECT_TX_SIZES; j++) {
2417+ f->qm[0][j][0] = av1_qm_tbl[f->frame_hdr.quant.qm_y][0][j];
2418+ f->qm[0][j][1] = av1_qm_tbl[f->frame_hdr.quant.qm_u][1][j];
2419+ f->qm[0][j][2] = av1_qm_tbl[f->frame_hdr.quant.qm_v][1][j];
2420+ }
2421+ for (int i = f->frame_hdr.quant.qm; i < 2; i++)
2422+ for (int tx = 0; tx < N_RECT_TX_SIZES; tx++)
2423+ for (int pl = 0; pl < 3; pl++)
2424+ f->qm[i][tx][pl] = av1_qm_tbl[15][!!pl][tx];
2425+
2426+ // setup jnt_comp weights
2427+ if (f->frame_hdr.switchable_comp_refs) {
2428+ for (int i = 0; i < 7; i++) {
2429+ const unsigned ref0poc = f->refp[i].p.poc;
2430+
2431+ for (int j = i + 1; j < 7; j++) {
2432+ const unsigned ref1poc = f->refp[j].p.poc;
2433+
2434+ const unsigned d1 = imin(abs(get_poc_diff(f->seq_hdr.order_hint_n_bits,
2435+ ref0poc, f->cur.p.poc)), 31);
2436+ const unsigned d0 = imin(abs(get_poc_diff(f->seq_hdr.order_hint_n_bits,
2437+ ref1poc, f->cur.p.poc)), 31);
2438+ const int order = d0 <= d1;
2439+
2440+ static const uint8_t quant_dist_weight[3][2] = {
2441+ { 2, 3 }, { 2, 5 }, { 2, 7 }
2442+ };
2443+ static const uint8_t quant_dist_lookup_table[4][2] = {
2444+ { 9, 7 }, { 11, 5 }, { 12, 4 }, { 13, 3 }
2445+ };
2446+
2447+ int k;
2448+ for (k = 0; k < 3; k++) {
2449+ const int c0 = quant_dist_weight[k][order];
2450+ const int c1 = quant_dist_weight[k][!order];
2451+ const int d0_c0 = d0 * c0;
2452+ const int d1_c1 = d1 * c1;
2453+ if ((d0 > d1 && d0_c0 < d1_c1) || (d0 <= d1 && d0_c0 > d1_c1)) break;
2454+ }
2455+
2456+ f->jnt_weights[i][j] = quant_dist_lookup_table[k][order];
2457+ }
2458+ }
2459+ }
2460+
2461+ // init loopfilter pointers
2462+ f->lf.mask_ptr = f->lf.mask;
2463+ f->lf.p[0] = f->cur.p.data[0];
2464+ f->lf.p[1] = f->cur.p.data[1];
2465+ f->lf.p[2] = f->cur.p.data[2];
2466+ f->lf.tile_row = 1;
2467+
2468+ cdf_thread_wait(&f->in_cdf);
2469+
2470+ // parse individual tiles per tile group
2471+ int update_set = 0, tile_idx = 0;
2472+ const unsigned tile_col_mask = (1 << f->frame_hdr.tiling.log2_cols) - 1;
2473+ for (int i = 0; i < f->n_tile_data; i++) {
2474+ const uint8_t *data = f->tile[i].data.data;
2475+ size_t size = f->tile[i].data.sz;
2476+
2477+ const int last_tile_row_plus1 = 1 + (f->tile[i].end >> f->frame_hdr.tiling.log2_cols);
2478+ const int last_tile_col_plus1 = 1 + (f->tile[i].end & tile_col_mask);
2479+ const int empty_tile_cols = imax(0, last_tile_col_plus1 - f->frame_hdr.tiling.cols);
2480+ const int empty_tile_rows = imax(0, last_tile_row_plus1 - f->frame_hdr.tiling.rows);
2481+ const int empty_tiles =
2482+ (empty_tile_rows << f->frame_hdr.tiling.log2_cols) + empty_tile_cols;
2483+ for (int j = f->tile[i].start; j <= f->tile[i].end - empty_tiles; j++) {
2484+ const int tile_row = j >> f->frame_hdr.tiling.log2_cols;
2485+ const int tile_col = j & tile_col_mask;
2486+
2487+ if (tile_col >= f->frame_hdr.tiling.cols) continue;
2488+ if (tile_row >= f->frame_hdr.tiling.rows) continue;
2489+
2490+ size_t tile_sz;
2491+ if (j == f->tile[i].end - empty_tiles) {
2492+ tile_sz = size;
2493+ } else {
2494+ tile_sz = 0;
2495+ for (int k = 0; k < f->frame_hdr.tiling.n_bytes; k++)
2496+ tile_sz |= *data++ << (k * 8);
2497+ tile_sz++;
2498+ size -= f->frame_hdr.tiling.n_bytes;
2499+ if (tile_sz > size) goto error;
2500+ }
2501+
2502+ setup_tile(&f->ts[tile_row * f->frame_hdr.tiling.cols + tile_col],
2503+ f, data, tile_sz, tile_row, tile_col,
2504+ c->n_fc > 1 ? f->frame_thread.tile_start_off[tile_idx++] : 0);
2505+ if (j == f->frame_hdr.tiling.update && f->frame_hdr.refresh_context)
2506+ update_set = 1;
2507+ data += tile_sz;
2508+ size -= tile_sz;
2509+ }
2510+ }
2511+
2512+ cdf_thread_unref(&f->in_cdf);
2513+
2514+ // 2-pass decoding:
2515+ // - enabled for frame-threading, so that one frame can do symbol parsing
2516+ // as another (or multiple) are doing reconstruction. One advantage here
2517+ // is that although reconstruction is limited by reference availability,
2518+ // symbol parsing is not. Therefore, symbol parsing can effectively use
2519+ // row and col tile threading, but reconstruction only col tile threading;
2520+ // - pass 0 means no 2-pass;
2521+ // - pass 1 means symbol parsing only;
2522+ // - pass 2 means reconstruction and loop filtering.
2523+
2524+ const int uses_2pass = c->n_fc > 1 && f->frame_hdr.refresh_context;
2525+ for (f->frame_thread.pass = uses_2pass;
2526+ f->frame_thread.pass <= 2 * uses_2pass; f->frame_thread.pass++)
2527+ {
2528+ const enum PlaneType progress_plane_type =
2529+ f->frame_thread.pass == 0 ? PLANE_TYPE_ALL :
2530+ f->frame_thread.pass == 1 ? PLANE_TYPE_BLOCK : PLANE_TYPE_Y;
2531+
2532+ for (int n = 0; n < f->sb128w * f->frame_hdr.tiling.rows; n++)
2533+ reset_context(&f->a[n], !(f->frame_hdr.frame_type & 1), f->frame_thread.pass);
2534+
2535+ if (f->n_tc == 1) {
2536+ Dav1dTileContext *const t = f->tc;
2537+
2538+ // no tile threading - we explicitly interleave tile/sbrow decoding
2539+ // and post-filtering, so that the full process runs in-line, so
2540+ // that frame threading is still possible
2541+ for (int tile_row = 0; tile_row < f->frame_hdr.tiling.rows; tile_row++) {
2542+ for (int sby = f->frame_hdr.tiling.row_start_sb[tile_row];
2543+ sby < f->frame_hdr.tiling.row_start_sb[tile_row + 1]; sby++)
2544+ {
2545+ t->by = sby << (4 + f->seq_hdr.sb128);
2546+ for (int tile_col = 0; tile_col < f->frame_hdr.tiling.cols; tile_col++) {
2547+ t->ts = &f->ts[tile_row * f->frame_hdr.tiling.rows + tile_col];
2548+
2549+ int res;
2550+ if ((res = decode_tile_sbrow(t)))
2551+ return res;
2552+ }
2553+
2554+ // loopfilter + cdef + restoration
2555+ if (f->frame_thread.pass != 1)
2556+ f->bd_fn.filter_sbrow(f, sby);
2557+ dav1d_thread_picture_signal(&f->cur, (sby + 1) * f->sb_step * 4,
2558+ progress_plane_type);
2559+ }
2560+ }
2561+ } else {
2562+ // signal available tasks to worker threads
2563+ int num_tasks;
2564+
2565+ const uint64_t all_mask = ~0ULL >> (64 - f->n_tc);
2566+ pthread_mutex_lock(&f->tile_thread.lock);
2567+ while (f->tile_thread.available != all_mask)
2568+ pthread_cond_wait(&f->tile_thread.icond, &f->tile_thread.lock);
2569+ assert(!f->tile_thread.tasks_left);
2570+ if (f->frame_thread.pass == 1 || f->n_tc >= f->frame_hdr.tiling.cols) {
2571+ // we can (or in fact, if >, we need to) do full tile decoding.
2572+ // loopfilter happens below
2573+ num_tasks = f->frame_hdr.tiling.cols * f->frame_hdr.tiling.rows;
2574+ } else {
2575+ // we need to interleave sbrow decoding for all tile cols in a
2576+ // tile row, since otherwise subsequent threads will be blocked
2577+ // waiting for the post-filter to complete
2578+ num_tasks = f->sbh * f->frame_hdr.tiling.cols;
2579+ }
2580+ f->tile_thread.num_tasks = f->tile_thread.tasks_left = num_tasks;
2581+ pthread_cond_broadcast(&f->tile_thread.cond);
2582+ pthread_mutex_unlock(&f->tile_thread.lock);
2583+
2584+ // loopfilter + cdef + restoration
2585+ for (int tile_row = 0; tile_row < f->frame_hdr.tiling.rows; tile_row++) {
2586+ for (int sby = f->frame_hdr.tiling.row_start_sb[tile_row];
2587+ sby < f->frame_hdr.tiling.row_start_sb[tile_row + 1]; sby++)
2588+ {
2589+ for (int tile_col = 0; tile_col < f->frame_hdr.tiling.cols;
2590+ tile_col++)
2591+ {
2592+ Dav1dTileState *const ts =
2593+ &f->ts[tile_row * f->frame_hdr.tiling.cols + tile_col];
2594+
2595+ if (atomic_load(&ts->progress) <= sby) {
2596+ pthread_mutex_lock(&ts->tile_thread.lock);
2597+ while (atomic_load(&ts->progress) <= sby)
2598+ pthread_cond_wait(&ts->tile_thread.cond,
2599+ &ts->tile_thread.lock);
2600+ pthread_mutex_unlock(&ts->tile_thread.lock);
2601+ }
2602+ }
2603+
2604+ // loopfilter + cdef + restoration
2605+ if (f->frame_thread.pass != 1)
2606+ f->bd_fn.filter_sbrow(f, sby);
2607+ dav1d_thread_picture_signal(&f->cur, (sby + 1) * f->sb_step * 4,
2608+ progress_plane_type);
2609+ }
2610+ }
2611+ }
2612+
2613+ if (f->frame_thread.pass <= 1 && f->frame_hdr.refresh_context) {
2614+ // cdf update
2615+ if (update_set)
2616+ av1_update_tile_cdf(&f->frame_hdr, f->out_cdf.cdf,
2617+ &f->ts[f->frame_hdr.tiling.update].cdf);
2618+ cdf_thread_signal(&f->out_cdf);
2619+ cdf_thread_unref(&f->out_cdf);
2620+ }
2621+ if (f->frame_thread.pass == 1) {
2622+ assert(c->n_fc > 1);
2623+ for (int tile_idx = 0;
2624+ tile_idx < f->frame_hdr.tiling.rows * f->frame_hdr.tiling.cols;
2625+ tile_idx++)
2626+ {
2627+ Dav1dTileState *const ts = &f->ts[tile_idx];
2628+ const int tile_start_off = f->frame_thread.tile_start_off[tile_idx];
2629+ ts->frame_thread.pal_idx = &f->frame_thread.pal_idx[tile_start_off * 2];
2630+ ts->frame_thread.cf = &((int32_t *) f->frame_thread.cf)[tile_start_off * 3];
2631+ if (f->n_tc > 0)
2632+ atomic_init(&ts->progress, 0);
2633+ }
2634+ }
2635+ }
2636+
2637+ dav1d_thread_picture_signal(&f->cur, UINT_MAX, PLANE_TYPE_ALL);
2638+
2639+ for (int i = 0; i < 7; i++) {
2640+ if (f->refp[i].p.data[0])
2641+ dav1d_thread_picture_unref(&f->refp[i]);
2642+ if (f->ref_mvs_ref[i])
2643+ dav1d_ref_dec(f->ref_mvs_ref[i]);
2644+ }
2645+
2646+ dav1d_thread_picture_unref(&f->cur);
2647+ if (f->cur_segmap_ref)
2648+ dav1d_ref_dec(f->cur_segmap_ref);
2649+ if (f->prev_segmap_ref)
2650+ dav1d_ref_dec(f->prev_segmap_ref);
2651+ if (f->mvs_ref)
2652+ dav1d_ref_dec(f->mvs_ref);
2653+
2654+ for (int i = 0; i < f->n_tile_data; i++)
2655+ dav1d_data_unref(&f->tile[i].data);
2656+
2657+ return 0;
2658+
2659+error:
2660+ for (int i = 0; i < f->n_tile_data; i++)
2661+ dav1d_data_unref(&f->tile[i].data);
2662+
2663+ return -EINVAL;
2664+}
2665+
2666+int submit_frame(Dav1dContext *const c) {
2667+ Dav1dFrameContext *f;
2668+ int res;
2669+
2670+ // wait for c->out_delayed[next] and move into c->out if visible
2671+ Dav1dThreadPicture *out_delayed;
2672+ if (c->n_fc > 1) {
2673+ const unsigned next = c->frame_thread.next++;
2674+ if (c->frame_thread.next == c->n_fc)
2675+ c->frame_thread.next = 0;
2676+
2677+ f = &c->fc[next];
2678+ pthread_mutex_lock(&f->frame_thread.td.lock);
2679+ while (f->n_tile_data > 0)
2680+ pthread_cond_wait(&f->frame_thread.td.cond,
2681+ &f->frame_thread.td.lock);
2682+ out_delayed = &c->frame_thread.out_delayed[next];
2683+ if (out_delayed->p.data[0]) {
2684+ if (out_delayed->visible)
2685+ dav1d_picture_ref(&c->out, &out_delayed->p);
2686+ dav1d_thread_picture_unref(out_delayed);
2687+ }
2688+ } else {
2689+ f = c->fc;
2690+ }
2691+
2692+ f->seq_hdr = c->seq_hdr;
2693+ f->frame_hdr = c->frame_hdr;
2694+ const int bd_idx = (f->seq_hdr.bpc - 8) >> 1;
2695+ f->dsp = &c->dsp[bd_idx];
2696+
2697+ if (!f->dsp->ipred.intra_pred[TX_4X4][DC_PRED]) {
2698+ Dav1dDSPContext *const dsp = &c->dsp[bd_idx];
2699+
2700+ switch (f->seq_hdr.bpc) {
2701+#define assign_bitdepth_case(bd) \
2702+ case bd: \
2703+ dav1d_cdef_dsp_init_##bd##bpc(&dsp->cdef); \
2704+ dav1d_intra_pred_dsp_init_##bd##bpc(&dsp->ipred); \
2705+ dav1d_itx_dsp_init_##bd##bpc(&dsp->itx); \
2706+ dav1d_loop_filter_dsp_init_##bd##bpc(&dsp->lf); \
2707+ dav1d_loop_restoration_dsp_init_##bd##bpc(&dsp->lr); \
2708+ dav1d_mc_dsp_init_##bd##bpc(&dsp->mc); \
2709+ break
2710+#if CONFIG_8BPC
2711+ assign_bitdepth_case(8);
2712+#endif
2713+#if CONFIG_10BPC
2714+ assign_bitdepth_case(10);
2715+#endif
2716+#undef assign_bitdepth_case
2717+ default:
2718+ fprintf(stderr, "Compiled without support for %d-bit decoding\n",
2719+ f->seq_hdr.bpc);
2720+ return -ENOPROTOOPT;
2721+ }
2722+ }
2723+
2724+#define assign_bitdepth_case(bd) \
2725+ f->bd_fn.recon_b_inter = recon_b_inter_##bd##bpc; \
2726+ f->bd_fn.recon_b_intra = recon_b_intra_##bd##bpc; \
2727+ f->bd_fn.filter_sbrow = filter_sbrow_##bd##bpc; \
2728+ f->bd_fn.backup_ipred_edge = backup_ipred_edge_##bd##bpc; \
2729+ f->bd_fn.read_coef_blocks = read_coef_blocks_##bd##bpc
2730+ if (f->seq_hdr.bpc <= 8) {
2731+#if CONFIG_8BPC
2732+ assign_bitdepth_case(8);
2733+#endif
2734+ } else {
2735+#if CONFIG_10BPC
2736+ assign_bitdepth_case(16);
2737+#endif
2738+ }
2739+#undef assign_bitdepth_case
2740+
2741+ if (f->frame_hdr.frame_type & 1)
2742+ for (int i = 0; i < 7; i++) {
2743+ const int refidx = f->frame_hdr.refidx[i];
2744+ dav1d_thread_picture_ref(&f->refp[i], &c->refs[refidx].p);
2745+ }
2746+
2747+ // setup entropy
2748+ if (f->frame_hdr.primary_ref_frame == PRIMARY_REF_NONE) {
2749+ av1_init_states(&f->in_cdf, f->frame_hdr.quant.yac);
2750+ } else {
2751+ const int pri_ref = f->frame_hdr.refidx[f->frame_hdr.primary_ref_frame];
2752+ cdf_thread_ref(&f->in_cdf, &c->cdf[pri_ref]);
2753+ }
2754+ if (f->frame_hdr.refresh_context) {
2755+ cdf_thread_alloc(&f->out_cdf, c->n_fc > 1 ? &f->frame_thread.td : NULL);
2756+ memcpy(f->out_cdf.cdf, f->in_cdf.cdf, sizeof(*f->in_cdf.cdf));
2757+ }
2758+
2759+ // FIXME qsort so tiles are in order (for frame threading)
2760+ memcpy(f->tile, c->tile, c->n_tile_data * sizeof(*f->tile));
2761+ f->n_tile_data = c->n_tile_data;
2762+ c->n_tile_data = 0;
2763+
2764+ // allocate frame
2765+ if ((res = dav1d_thread_picture_alloc(&f->cur, f->frame_hdr.width,
2766+ f->frame_hdr.height,
2767+ f->seq_hdr.layout, f->seq_hdr.bpc,
2768+ c->n_fc > 1 ? &f->frame_thread.td : NULL,
2769+ f->frame_hdr.show_frame)) < 0)
2770+ {
2771+ return res;
2772+ }
2773+
2774+ f->cur.p.poc = f->frame_hdr.frame_offset;
2775+ f->cur.p.p.pri = f->seq_hdr.pri;
2776+ f->cur.p.p.trc = f->seq_hdr.trc;
2777+ f->cur.p.p.mtrx = f->seq_hdr.mtrx;
2778+ f->cur.p.p.chr = f->seq_hdr.chr;
2779+ f->cur.p.p.fullrange = f->seq_hdr.color_range;
2780+
2781+ // move f->cur into output queue
2782+ if (c->n_fc == 1) {
2783+ if (f->frame_hdr.show_frame)
2784+ dav1d_picture_ref(&c->out, &f->cur.p);
2785+ } else {
2786+ dav1d_thread_picture_ref(out_delayed, &f->cur);
2787+ }
2788+
2789+ f->bw = (f->frame_hdr.width + 3) >> 2;
2790+ f->bh = (f->frame_hdr.height + 3) >> 2;
2791+ f->sb128w = (f->bw + 31) >> 5;
2792+ f->sb128h = (f->bh + 31) >> 5;
2793+ f->sb_shift = 4 + f->seq_hdr.sb128;
2794+ f->sb_step = 16 << f->seq_hdr.sb128;
2795+ f->sbh = (f->bh + f->sb_step - 1) >> f->sb_shift;
2796+ f->b4_stride = (f->bw + 31) & ~31;
2797+
2798+ // ref_mvs
2799+ if ((f->frame_hdr.frame_type & 1) || f->frame_hdr.allow_intrabc) {
2800+ f->mvs_ref = dav1d_ref_create(f->sb128h * 32 * f->b4_stride *
2801+ sizeof(*f->mvs));
2802+ f->mvs = f->mvs_ref->data;
2803+ if (f->frame_hdr.use_ref_frame_mvs) {
2804+ for (int i = 0; i < 7; i++) {
2805+ const int refidx = f->frame_hdr.refidx[i];
2806+ f->refpoc[i] = f->refp[i].p.poc;
2807+ if (c->refs[refidx].refmvs != NULL &&
2808+ f->refp[i].p.p.w == f->cur.p.p.w &&
2809+ f->refp[i].p.p.h == f->cur.p.p.h)
2810+ {
2811+ f->ref_mvs_ref[i] = c->refs[refidx].refmvs;
2812+ dav1d_ref_inc(f->ref_mvs_ref[i]);
2813+ f->ref_mvs[i] = c->refs[refidx].refmvs->data;
2814+ } else {
2815+ f->ref_mvs[i] = NULL;
2816+ f->ref_mvs_ref[i] = NULL;
2817+ }
2818+ memcpy(f->refrefpoc[i], c->refs[refidx].refpoc,
2819+ sizeof(*f->refrefpoc));
2820+ }
2821+ } else {
2822+ memset(f->ref_mvs_ref, 0, sizeof(f->ref_mvs_ref));
2823+ }
2824+ } else {
2825+ f->mvs_ref = NULL;
2826+ memset(f->ref_mvs_ref, 0, sizeof(f->ref_mvs_ref));
2827+ }
2828+
2829+ // segmap
2830+ if (f->frame_hdr.segmentation.enabled) {
2831+ if (f->frame_hdr.segmentation.temporal) {
2832+ const int pri_ref = f->frame_hdr.primary_ref_frame;
2833+ assert(pri_ref != PRIMARY_REF_NONE);
2834+ const int ref_w = (f->refp[pri_ref].p.p.w + 3) >> 2;
2835+ const int ref_h = (f->refp[pri_ref].p.p.h + 3) >> 2;
2836+ if (ref_w == f->bw && ref_h == f->bh) {
2837+ f->prev_segmap_ref = c->refs[f->frame_hdr.refidx[pri_ref]].segmap;
2838+ dav1d_ref_inc(f->prev_segmap_ref);
2839+ f->prev_segmap = f->prev_segmap_ref->data;
2840+ } else {
2841+ f->prev_segmap_ref = NULL;
2842+ f->prev_segmap = NULL;
2843+ }
2844+ } else {
2845+ f->prev_segmap_ref = NULL;
2846+ f->prev_segmap = NULL;
2847+ }
2848+ if (f->frame_hdr.segmentation.update_map) {
2849+ f->cur_segmap_ref = dav1d_ref_create(f->b4_stride * 32 * f->sb128h);
2850+ f->cur_segmap = f->cur_segmap_ref->data;
2851+ } else {
2852+ f->cur_segmap_ref = f->prev_segmap_ref;
2853+ dav1d_ref_inc(f->cur_segmap_ref);
2854+ f->cur_segmap = f->prev_segmap_ref->data;
2855+ }
2856+ } else {
2857+ f->cur_segmap = NULL;
2858+ f->cur_segmap_ref = NULL;
2859+ f->prev_segmap_ref = NULL;
2860+ }
2861+
2862+ // update references etc.
2863+ for (int i = 0; i < 8; i++) {
2864+ if (f->frame_hdr.refresh_frame_flags & (1 << i)) {
2865+ if (c->refs[i].p.p.data[0])
2866+ dav1d_thread_picture_unref(&c->refs[i].p);
2867+ dav1d_thread_picture_ref(&c->refs[i].p, &f->cur);
2868+
2869+ if (c->cdf[i].cdf) cdf_thread_unref(&c->cdf[i]);
2870+ if (f->frame_hdr.refresh_context) {
2871+ cdf_thread_ref(&c->cdf[i], &f->out_cdf);
2872+ } else {
2873+ cdf_thread_ref(&c->cdf[i], &f->in_cdf);
2874+ }
2875+ c->refs[i].lf_mode_ref_deltas =
2876+ f->frame_hdr.loopfilter.mode_ref_deltas;
2877+ c->refs[i].seg_data = f->frame_hdr.segmentation.seg_data;
2878+ memcpy(c->refs[i].gmv, f->frame_hdr.gmv, sizeof(c->refs[i].gmv));
2879+ c->refs[i].film_grain = f->frame_hdr.film_grain.data;
2880+
2881+ if (c->refs[i].segmap)
2882+ dav1d_ref_dec(c->refs[i].segmap);
2883+ c->refs[i].segmap = f->cur_segmap_ref;
2884+ if (f->cur_segmap_ref)
2885+ dav1d_ref_inc(f->cur_segmap_ref);
2886+ if (c->refs[i].refmvs)
2887+ dav1d_ref_dec(c->refs[i].refmvs);
2888+ if (f->frame_hdr.allow_intrabc) {
2889+ c->refs[i].refmvs = NULL;
2890+ } else {
2891+ c->refs[i].refmvs = f->mvs_ref;
2892+ if (f->mvs_ref)
2893+ dav1d_ref_inc(f->mvs_ref);
2894+ }
2895+ memcpy(c->refs[i].refpoc, f->refpoc, sizeof(f->refpoc));
2896+ }
2897+ }
2898+
2899+ if (c->n_fc == 1) {
2900+ if ((res = decode_frame(f)) < 0)
2901+ return res;
2902+ } else {
2903+ pthread_cond_signal(&f->frame_thread.td.cond);
2904+ pthread_mutex_unlock(&f->frame_thread.td.lock);
2905+ }
2906+
2907+ return 0;
2908+}
src/decode.h+35−0
@@ -0,0 +1,35 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __DAV1D_SRC_DECODE_H__
29+#define __DAV1D_SRC_DECODE_H__
30+
31+#include "src/internal.h"
32+
33+int submit_frame(Dav1dContext *c);
34+
35+#endif /* __DAV1D_SRC_DECODE_H__ */
src/dequant_tables.c+164−0
@@ -0,0 +1,164 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#include "config.h"
29+
30+#include "src/dequant_tables.h"
31+
32+const uint16_t dav1d_dq_tbl[][QINDEX_RANGE][2] = {
33+ {
34+ { 4, 4, }, { 8, 8, }, { 8, 9, }, { 9, 10, },
35+ { 10, 11, }, { 11, 12, }, { 12, 13, }, { 12, 14, },
36+ { 13, 15, }, { 14, 16, }, { 15, 17, }, { 16, 18, },
37+ { 17, 19, }, { 18, 20, }, { 19, 21, }, { 19, 22, },
38+ { 20, 23, }, { 21, 24, }, { 22, 25, }, { 23, 26, },
39+ { 24, 27, }, { 25, 28, }, { 26, 29, }, { 26, 30, },
40+ { 27, 31, }, { 28, 32, }, { 29, 33, }, { 30, 34, },
41+ { 31, 35, }, { 32, 36, }, { 32, 37, }, { 33, 38, },
42+ { 34, 39, }, { 35, 40, }, { 36, 41, }, { 37, 42, },
43+ { 38, 43, }, { 38, 44, }, { 39, 45, }, { 40, 46, },
44+ { 41, 47, }, { 42, 48, }, { 43, 49, }, { 43, 50, },
45+ { 44, 51, }, { 45, 52, }, { 46, 53, }, { 47, 54, },
46+ { 48, 55, }, { 48, 56, }, { 49, 57, }, { 50, 58, },
47+ { 51, 59, }, { 52, 60, }, { 53, 61, }, { 53, 62, },
48+ { 54, 63, }, { 55, 64, }, { 56, 65, }, { 57, 66, },
49+ { 57, 67, }, { 58, 68, }, { 59, 69, }, { 60, 70, },
50+ { 61, 71, }, { 62, 72, }, { 62, 73, }, { 63, 74, },
51+ { 64, 75, }, { 65, 76, }, { 66, 77, }, { 66, 78, },
52+ { 67, 79, }, { 68, 80, }, { 69, 81, }, { 70, 82, },
53+ { 70, 83, }, { 71, 84, }, { 72, 85, }, { 73, 86, },
54+ { 74, 87, }, { 74, 88, }, { 75, 89, }, { 76, 90, },
55+ { 77, 91, }, { 78, 92, }, { 78, 93, }, { 79, 94, },
56+ { 80, 95, }, { 81, 96, }, { 81, 97, }, { 82, 98, },
57+ { 83, 99, }, { 84, 100, }, { 85, 101, }, { 85, 102, },
58+ { 87, 104, }, { 88, 106, }, { 90, 108, }, { 92, 110, },
59+ { 93, 112, }, { 95, 114, }, { 96, 116, }, { 98, 118, },
60+ { 99, 120, }, { 101, 122, }, { 102, 124, }, { 104, 126, },
61+ { 105, 128, }, { 107, 130, }, { 108, 132, }, { 110, 134, },
62+ { 111, 136, }, { 113, 138, }, { 114, 140, }, { 116, 142, },
63+ { 117, 144, }, { 118, 146, }, { 120, 148, }, { 121, 150, },
64+ { 123, 152, }, { 125, 155, }, { 127, 158, }, { 129, 161, },
65+ { 131, 164, }, { 134, 167, }, { 136, 170, }, { 138, 173, },
66+ { 140, 176, }, { 142, 179, }, { 144, 182, }, { 146, 185, },
67+ { 148, 188, }, { 150, 191, }, { 152, 194, }, { 154, 197, },
68+ { 156, 200, }, { 158, 203, }, { 161, 207, }, { 164, 211, },
69+ { 166, 215, }, { 169, 219, }, { 172, 223, }, { 174, 227, },
70+ { 177, 231, }, { 180, 235, }, { 182, 239, }, { 185, 243, },
71+ { 187, 247, }, { 190, 251, }, { 192, 255, }, { 195, 260, },
72+ { 199, 265, }, { 202, 270, }, { 205, 275, }, { 208, 280, },
73+ { 211, 285, }, { 214, 290, }, { 217, 295, }, { 220, 300, },
74+ { 223, 305, }, { 226, 311, }, { 230, 317, }, { 233, 323, },
75+ { 237, 329, }, { 240, 335, }, { 243, 341, }, { 247, 347, },
76+ { 250, 353, }, { 253, 359, }, { 257, 366, }, { 261, 373, },
77+ { 265, 380, }, { 269, 387, }, { 272, 394, }, { 276, 401, },
78+ { 280, 408, }, { 284, 416, }, { 288, 424, }, { 292, 432, },
79+ { 296, 440, }, { 300, 448, }, { 304, 456, }, { 309, 465, },
80+ { 313, 474, }, { 317, 483, }, { 322, 492, }, { 326, 501, },
81+ { 330, 510, }, { 335, 520, }, { 340, 530, }, { 344, 540, },
82+ { 349, 550, }, { 354, 560, }, { 359, 571, }, { 364, 582, },
83+ { 369, 593, }, { 374, 604, }, { 379, 615, }, { 384, 627, },
84+ { 389, 639, }, { 395, 651, }, { 400, 663, }, { 406, 676, },
85+ { 411, 689, }, { 417, 702, }, { 423, 715, }, { 429, 729, },
86+ { 435, 743, }, { 441, 757, }, { 447, 771, }, { 454, 786, },
87+ { 461, 801, }, { 467, 816, }, { 475, 832, }, { 482, 848, },
88+ { 489, 864, }, { 497, 881, }, { 505, 898, }, { 513, 915, },
89+ { 522, 933, }, { 530, 951, }, { 539, 969, }, { 549, 988, },
90+ { 559, 1007, }, { 569, 1026, }, { 579, 1046, }, { 590, 1066, },
91+ { 602, 1087, }, { 614, 1108, }, { 626, 1129, }, { 640, 1151, },
92+ { 654, 1173, }, { 668, 1196, }, { 684, 1219, }, { 700, 1243, },
93+ { 717, 1267, }, { 736, 1292, }, { 755, 1317, }, { 775, 1343, },
94+ { 796, 1369, }, { 819, 1396, }, { 843, 1423, }, { 869, 1451, },
95+ { 896, 1479, }, { 925, 1508, }, { 955, 1537, }, { 988, 1567, },
96+ { 1022, 1597, }, { 1058, 1628, }, { 1098, 1660, }, { 1139, 1692, },
97+ { 1184, 1725, }, { 1232, 1759, }, { 1282, 1793, }, { 1336, 1828, },
98+ }, {
99+ { 4, 4, }, { 9, 9, }, { 10, 11, }, { 13, 13, },
100+ { 15, 16, }, { 17, 18, }, { 20, 21, }, { 22, 24, },
101+ { 25, 27, }, { 28, 30, }, { 31, 33, }, { 34, 37, },
102+ { 37, 40, }, { 40, 44, }, { 43, 48, }, { 47, 51, },
103+ { 50, 55, }, { 53, 59, }, { 57, 63, }, { 60, 67, },
104+ { 64, 71, }, { 68, 75, }, { 71, 79, }, { 75, 83, },
105+ { 78, 88, }, { 82, 92, }, { 86, 96, }, { 90, 100, },
106+ { 93, 105, }, { 97, 109, }, { 101, 114, }, { 105, 118, },
107+ { 109, 122, }, { 113, 127, }, { 116, 131, }, { 120, 136, },
108+ { 124, 140, }, { 128, 145, }, { 132, 149, }, { 136, 154, },
109+ { 140, 158, }, { 143, 163, }, { 147, 168, }, { 151, 172, },
110+ { 155, 177, }, { 159, 181, }, { 163, 186, }, { 166, 190, },
111+ { 170, 195, }, { 174, 199, }, { 178, 204, }, { 182, 208, },
112+ { 185, 213, }, { 189, 217, }, { 193, 222, }, { 197, 226, },
113+ { 200, 231, }, { 204, 235, }, { 208, 240, }, { 212, 244, },
114+ { 215, 249, }, { 219, 253, }, { 223, 258, }, { 226, 262, },
115+ { 230, 267, }, { 233, 271, }, { 237, 275, }, { 241, 280, },
116+ { 244, 284, }, { 248, 289, }, { 251, 293, }, { 255, 297, },
117+ { 259, 302, }, { 262, 306, }, { 266, 311, }, { 269, 315, },
118+ { 273, 319, }, { 276, 324, }, { 280, 328, }, { 283, 332, },
119+ { 287, 337, }, { 290, 341, }, { 293, 345, }, { 297, 349, },
120+ { 300, 354, }, { 304, 358, }, { 307, 362, }, { 310, 367, },
121+ { 314, 371, }, { 317, 375, }, { 321, 379, }, { 324, 384, },
122+ { 327, 388, }, { 331, 392, }, { 334, 396, }, { 337, 401, },
123+ { 343, 409, }, { 350, 417, }, { 356, 425, }, { 362, 433, },
124+ { 369, 441, }, { 375, 449, }, { 381, 458, }, { 387, 466, },
125+ { 394, 474, }, { 400, 482, }, { 406, 490, }, { 412, 498, },
126+ { 418, 506, }, { 424, 514, }, { 430, 523, }, { 436, 531, },
127+ { 442, 539, }, { 448, 547, }, { 454, 555, }, { 460, 563, },
128+ { 466, 571, }, { 472, 579, }, { 478, 588, }, { 484, 596, },
129+ { 490, 604, }, { 499, 616, }, { 507, 628, }, { 516, 640, },
130+ { 525, 652, }, { 533, 664, }, { 542, 676, }, { 550, 688, },
131+ { 559, 700, }, { 567, 713, }, { 576, 725, }, { 584, 737, },
132+ { 592, 749, }, { 601, 761, }, { 609, 773, }, { 617, 785, },
133+ { 625, 797, }, { 634, 809, }, { 644, 825, }, { 655, 841, },
134+ { 666, 857, }, { 676, 873, }, { 687, 889, }, { 698, 905, },
135+ { 708, 922, }, { 718, 938, }, { 729, 954, }, { 739, 970, },
136+ { 749, 986, }, { 759, 1002, }, { 770, 1018, }, { 782, 1038, },
137+ { 795, 1058, }, { 807, 1078, }, { 819, 1098, }, { 831, 1118, },
138+ { 844, 1138, }, { 856, 1158, }, { 868, 1178, }, { 880, 1198, },
139+ { 891, 1218, }, { 906, 1242, }, { 920, 1266, }, { 933, 1290, },
140+ { 947, 1314, }, { 961, 1338, }, { 975, 1362, }, { 988, 1386, },
141+ { 1001, 1411, }, { 1015, 1435, }, { 1030, 1463, }, { 1045, 1491, },
142+ { 1061, 1519, }, { 1076, 1547, }, { 1090, 1575, }, { 1105, 1603, },
143+ { 1120, 1631, }, { 1137, 1663, }, { 1153, 1695, }, { 1170, 1727, },
144+ { 1186, 1759, }, { 1202, 1791, }, { 1218, 1823, }, { 1236, 1859, },
145+ { 1253, 1895, }, { 1271, 1931, }, { 1288, 1967, }, { 1306, 2003, },
146+ { 1323, 2039, }, { 1342, 2079, }, { 1361, 2119, }, { 1379, 2159, },
147+ { 1398, 2199, }, { 1416, 2239, }, { 1436, 2283, }, { 1456, 2327, },
148+ { 1476, 2371, }, { 1496, 2415, }, { 1516, 2459, }, { 1537, 2507, },
149+ { 1559, 2555, }, { 1580, 2603, }, { 1601, 2651, }, { 1624, 2703, },
150+ { 1647, 2755, }, { 1670, 2807, }, { 1692, 2859, }, { 1717, 2915, },
151+ { 1741, 2971, }, { 1766, 3027, }, { 1791, 3083, }, { 1817, 3143, },
152+ { 1844, 3203, }, { 1871, 3263, }, { 1900, 3327, }, { 1929, 3391, },
153+ { 1958, 3455, }, { 1990, 3523, }, { 2021, 3591, }, { 2054, 3659, },
154+ { 2088, 3731, }, { 2123, 3803, }, { 2159, 3876, }, { 2197, 3952, },
155+ { 2236, 4028, }, { 2276, 4104, }, { 2319, 4184, }, { 2363, 4264, },
156+ { 2410, 4348, }, { 2458, 4432, }, { 2508, 4516, }, { 2561, 4604, },
157+ { 2616, 4692, }, { 2675, 4784, }, { 2737, 4876, }, { 2802, 4972, },
158+ { 2871, 5068, }, { 2944, 5168, }, { 3020, 5268, }, { 3102, 5372, },
159+ { 3188, 5476, }, { 3280, 5584, }, { 3375, 5692, }, { 3478, 5804, },
160+ { 3586, 5916, }, { 3702, 6032, }, { 3823, 6148, }, { 3953, 6268, },
161+ { 4089, 6388, }, { 4236, 6512, }, { 4394, 6640, }, { 4559, 6768, },
162+ { 4737, 6900, }, { 4929, 7036, }, { 5130, 7172, }, { 5347, 7312, },
163+ }
164+};
src/dequant_tables.h+37−0
@@ -0,0 +1,37 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __DAV1D_SRC_DEQUANT_TABLES_H__
29+#define __DAV1D_SRC_DEQUANT_TABLES_H__
30+
31+#include <stdint.h>
32+
33+#include "src/levels.h"
34+
35+extern const uint16_t dav1d_dq_tbl[][QINDEX_RANGE][2];
36+
37+#endif /* __DAV1D_SRC_DEQUANT_TABLES_H__ */
src/env.h+754−0
@@ -0,0 +1,754 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __DAV1D_SRC_ENV_H__
29+#define __DAV1D_SRC_ENV_H__
30+
31+#include <assert.h>
32+#include <stddef.h>
33+#include <stdint.h>
34+#include <stdlib.h>
35+
36+#include "src/levels.h"
37+#include "src/ref_mvs.h"
38+#include "src/tables.h"
39+
40+typedef struct BlockContext {
41+ uint8_t mode[32];
42+ uint8_t lcoef[32];
43+ uint8_t ccoef[2][32];
44+ uint8_t seg_pred[32];
45+ uint8_t skip[32];
46+ uint8_t skip_mode[32];
47+ uint8_t intra[32];
48+ uint8_t comp_type[32];
49+ int8_t ref[2][32]; // -1 means intra
50+ uint8_t filter[2][32]; // 3 means unset
51+ int8_t tx_intra[32];
52+ int8_t tx[32];
53+ uint8_t tx_lpf_y[32];
54+ uint8_t tx_lpf_uv[32];
55+ uint8_t partition[16];
56+ uint8_t uvmode[32];
57+ uint8_t pal_sz[32];
58+} BlockContext;
59+
60+static inline int get_intra_ctx(const BlockContext *const a,
61+ const BlockContext *const l,
62+ const int yb4, const int xb4,
63+ const int have_top, const int have_left)
64+{
65+ if (have_left) {
66+ if (have_top) {
67+ const int ctx = l->intra[yb4] + a->intra[xb4];
68+ return ctx + (ctx == 2);
69+ } else
70+ return l->intra[yb4] * 2;
71+ } else {
72+ return have_top ? a->intra[xb4] * 2 : 0;
73+ }
74+}
75+
76+static inline int get_tx_ctx(const BlockContext *const a,
77+ const BlockContext *const l,
78+ const TxfmInfo *const max_tx,
79+ const int yb4, const int xb4,
80+ const int have_top, const int have_left)
81+{
82+ return (l->tx_intra[yb4] >= max_tx->lh) + (a->tx_intra[xb4] >= max_tx->lw);
83+}
84+
85+static inline int get_partition_ctx(const BlockContext *const a,
86+ const BlockContext *const l,
87+ const enum BlockLevel bl,
88+ const int yb8, const int xb8)
89+{
90+ return ((a->partition[xb8] >> (4 - bl)) & 1) +
91+ (((l->partition[yb8] >> (4 - bl)) & 1) << 1);
92+}
93+
94+static inline unsigned cdf_element_prob(const uint16_t *const cdf, const int e) {
95+ return (e > 0 ? cdf[e - 1] : 32768) - cdf[e];
96+}
97+
98+static inline unsigned gather_left_partition_prob(const uint16_t *const in,
99+ const enum BlockLevel bl)
100+{
101+ unsigned out = 32768;
102+ out -= cdf_element_prob(in, PARTITION_H);
103+ if (bl != BL_128X128)
104+ out -= cdf_element_prob(in, PARTITION_H4);
105+ out -= cdf_element_prob(in, PARTITION_SPLIT);
106+ out -= cdf_element_prob(in, PARTITION_T_TOP_SPLIT);
107+ out -= cdf_element_prob(in, PARTITION_T_BOTTOM_SPLIT);
108+ out -= cdf_element_prob(in, PARTITION_T_LEFT_SPLIT);
109+ return 32768 - out;
110+}
111+
112+static inline unsigned gather_top_partition_prob(const uint16_t *const in,
113+ const enum BlockLevel bl)
114+{
115+ unsigned out = 32768;
116+ out -= cdf_element_prob(in, PARTITION_V);
117+ if (bl != BL_128X128)
118+ out -= cdf_element_prob(in, PARTITION_V4);
119+ out -= cdf_element_prob(in, PARTITION_SPLIT);
120+ out -= cdf_element_prob(in, PARTITION_T_TOP_SPLIT);
121+ out -= cdf_element_prob(in, PARTITION_T_LEFT_SPLIT);
122+ out -= cdf_element_prob(in, PARTITION_T_RIGHT_SPLIT);
123+ return 32768 - out;
124+}
125+
126+static inline enum TxfmTypeSet get_ext_txtp_set(const enum RectTxfmSize tx,
127+ const int inter,
128+ const Av1FrameHeader *const hdr,
129+ const int seg_id)
130+{
131+ if (hdr->segmentation.lossless[seg_id]) {
132+ assert(tx == (int) TX_4X4);
133+ return TXTP_SET_LOSSLESS;
134+ }
135+
136+ const TxfmInfo *const t_dim = &av1_txfm_dimensions[tx];
137+
138+ if (t_dim->max >= TX_64X64)
139+ return TXTP_SET_DCT;
140+
141+ if (t_dim->max == TX_32X32)
142+ return inter ? TXTP_SET_DCT_ID : TXTP_SET_DCT;
143+
144+ if (hdr->reduced_txtp_set)
145+ return inter ? TXTP_SET_DCT_ID : TXTP_SET_DT4_ID;
146+
147+ const enum TxfmSize txsqsz = t_dim->min;
148+
149+ if (inter)
150+ return txsqsz == TX_16X16 ? TXTP_SET_DT9_ID_1D : TXTP_SET_ALL;
151+ else
152+ return txsqsz == TX_16X16 ? TXTP_SET_DT4_ID : TXTP_SET_DT4_ID_1D;
153+}
154+
155+static inline enum TxfmType get_uv_intra_txtp(const enum IntraPredMode uv_mode,
156+ const enum RectTxfmSize tx,
157+ const Av1FrameHeader *const hdr,
158+ const int seg_id)
159+{
160+ if (hdr->segmentation.lossless[seg_id]) {
161+ assert(tx == (int) TX_4X4);
162+ return WHT_WHT;
163+ }
164+
165+ const TxfmInfo *const t_dim = &av1_txfm_dimensions[tx];
166+
167+ return t_dim->max == TX_32X32 ? DCT_DCT : av1_txtp_from_uvmode[uv_mode];
168+}
169+
170+static inline enum TxfmType get_uv_inter_txtp(const TxfmInfo *const uvt_dim,
171+ const enum TxfmType ytxtp,
172+ const Av1FrameHeader *const hdr,
173+ const int seg_id)
174+{
175+ if (hdr->segmentation.lossless[seg_id]) {
176+ assert(uvt_dim->max == TX_4X4);
177+ return WHT_WHT;
178+ }
179+
180+ if (uvt_dim->max == TX_32X32)
181+ return ytxtp == IDTX ? IDTX : DCT_DCT;
182+ if (uvt_dim->min == TX_16X16 &&
183+ ((1 << ytxtp) & ((1 << H_FLIPADST) | (1 << V_FLIPADST) |
184+ (1 << H_ADST) | (1 << V_ADST))))
185+ {
186+ return DCT_DCT;
187+ }
188+
189+ return ytxtp;
190+}
191+
192+static inline int get_filter_ctx(const BlockContext *const a,
193+ const BlockContext *const l,
194+ const int comp, const int dir, const int ref,
195+ const int yb4, const int xb4)
196+{
197+ const int a_filter = (a->ref[0][xb4] == ref || a->ref[1][xb4] == ref) ?
198+ a->filter[dir][xb4] : N_SWITCHABLE_FILTERS;
199+ const int l_filter = (l->ref[0][yb4] == ref || l->ref[1][yb4] == ref) ?
200+ l->filter[dir][yb4] : N_SWITCHABLE_FILTERS;
201+
202+ if (a_filter == l_filter) {
203+ return comp * 4 + a_filter;
204+ } else if (a_filter == N_SWITCHABLE_FILTERS) {
205+ return comp * 4 + l_filter;
206+ } else if (l_filter == N_SWITCHABLE_FILTERS) {
207+ return comp * 4 + a_filter;
208+ } else {
209+ return comp * 4 + N_SWITCHABLE_FILTERS;
210+ }
211+}
212+
213+static inline int get_comp_ctx(const BlockContext *const a,
214+ const BlockContext *const l,
215+ const int yb4, const int xb4,
216+ const int have_top, const int have_left)
217+{
218+ if (have_top) {
219+ if (have_left) {
220+ if (a->comp_type[xb4]) {
221+ if (l->comp_type[yb4]) {
222+ return 4;
223+ } else {
224+ // 4U means intra (-1) or bwd (>= 4)
225+ return 2 + (l->ref[0][yb4] >= 4U);
226+ }
227+ } else if (l->comp_type[yb4]) {
228+ // 4U means intra (-1) or bwd (>= 4)
229+ return 2 + (a->ref[0][xb4] >= 4U);
230+ } else {
231+ return (l->ref[0][yb4] >= 4) ^ (a->ref[0][xb4] >= 4);
232+ }
233+ } else {
234+ return a->comp_type[xb4] ? 3 : a->ref[0][xb4] >= 4;
235+ }
236+ } else if (have_left) {
237+ return l->comp_type[yb4] ? 3 : l->ref[0][yb4] >= 4;
238+ } else {
239+ return 1;
240+ }
241+}
242+
243+static inline int get_comp_dir_ctx(const BlockContext *const a,
244+ const BlockContext *const l,
245+ const int yb4, const int xb4,
246+ const int have_top, const int have_left)
247+{
248+#define has_uni_comp(edge, off) \
249+ ((edge->ref[0][off] < 4) == (edge->ref[1][off] < 4))
250+
251+ if (have_top && have_left) {
252+ const int a_intra = a->intra[xb4], l_intra = l->intra[yb4];
253+
254+ if (a_intra && l_intra) return 2;
255+ if (a_intra || l_intra) {
256+ const BlockContext *const edge = a_intra ? l : a;
257+ const int off = a_intra ? yb4 : xb4;
258+
259+ if (edge->comp_type[off] == COMP_INTER_NONE) return 2;
260+ return 1 + 2 * has_uni_comp(edge, off);
261+ }
262+
263+ const int a_comp = a->comp_type[xb4] != COMP_INTER_NONE;
264+ const int l_comp = l->comp_type[yb4] != COMP_INTER_NONE;
265+ const int a_ref0 = a->ref[0][xb4], l_ref0 = l->ref[0][yb4];
266+
267+ if (!a_comp && !l_comp) {
268+ return 1 + 2 * ((a_ref0 >= 4) == (l_ref0 >= 4));
269+ } else if (!a_comp || !l_comp) {
270+ const BlockContext *const edge = a_comp ? a : l;
271+ const int off = a_comp ? xb4 : yb4;
272+
273+ if (!has_uni_comp(edge, off)) return 1;
274+ return 3 + ((a_ref0 >= 4) == (l_ref0 >= 4));
275+ } else {
276+ const int a_uni = has_uni_comp(a, xb4), l_uni = has_uni_comp(l, yb4);
277+
278+ if (!a_uni && !l_uni) return 0;
279+ if (!a_uni || !l_uni) return 2;
280+ return 3 + ((a_ref0 == 4) == (l_ref0 == 4));
281+ }
282+ } else if (have_top || have_left) {
283+ const BlockContext *const edge = have_left ? l : a;
284+ const int off = have_left ? yb4 : xb4;
285+
286+ if (edge->intra[off]) return 2;
287+ if (edge->comp_type[off] == COMP_INTER_NONE) return 2;
288+ return 4 * has_uni_comp(edge, off);
289+ } else {
290+ return 2;
291+ }
292+}
293+
294+static inline int get_poc_diff(const int order_hint_n_bits,
295+ const int poc0, const int poc1)
296+{
297+ const int mask = 1 << (order_hint_n_bits - 1);
298+ const int diff = poc0 - poc1;
299+ return (diff & (mask - 1)) - (diff & mask);
300+}
301+
302+static inline int get_jnt_comp_ctx(const int order_hint_n_bits,
303+ const unsigned poc, const unsigned ref0poc,
304+ const unsigned ref1poc,
305+ const BlockContext *const a,
306+ const BlockContext *const l,
307+ const int yb4, const int xb4)
308+{
309+ const unsigned d0 = abs(get_poc_diff(order_hint_n_bits, ref0poc, poc));
310+ const unsigned d1 = abs(get_poc_diff(order_hint_n_bits, ref1poc, poc));
311+ const int offset = d0 == d1;
312+ const int a_ctx = a->comp_type[xb4] >= COMP_INTER_AVG ||
313+ a->ref[0][xb4] == 6;
314+ const int l_ctx = l->comp_type[yb4] >= COMP_INTER_AVG ||
315+ l->ref[0][yb4] == 6;
316+
317+ return 3 * offset + a_ctx + l_ctx;
318+}
319+
320+static inline int get_mask_comp_ctx(const BlockContext *const a,
321+ const BlockContext *const l,
322+ const int yb4, const int xb4)
323+{
324+ const int a_ctx = a->comp_type[xb4] >= COMP_INTER_SEG ? 1 :
325+ a->ref[0][xb4] == 6 ? 3 : 0;
326+ const int l_ctx = l->comp_type[yb4] >= COMP_INTER_SEG ? 1 :
327+ l->ref[0][yb4] == 6 ? 3 : 0;
328+
329+ return imin(a_ctx + l_ctx, 5);
330+}
331+
332+#define av1_get_ref_2_ctx av1_get_bwd_ref_ctx
333+#define av1_get_ref_3_ctx av1_get_fwd_ref_ctx
334+#define av1_get_ref_4_ctx av1_get_fwd_ref_1_ctx
335+#define av1_get_ref_5_ctx av1_get_fwd_ref_2_ctx
336+#define av1_get_ref_6_ctx av1_get_bwd_ref_1_ctx
337+#define av1_get_uni_p_ctx av1_get_ref_ctx
338+#define av1_get_uni_p2_ctx av1_get_fwd_ref_2_ctx
339+
340+static inline int av1_get_ref_ctx(const BlockContext *const a,
341+ const BlockContext *const l,
342+ const int yb4, const int xb4,
343+ int have_top, int have_left)
344+{
345+ int cnt[2] = { 0 };
346+
347+ if (have_top && !a->intra[xb4]) {
348+ cnt[a->ref[0][xb4] >= 4]++;
349+ if (a->comp_type[xb4]) cnt[a->ref[1][xb4] >= 4]++;
350+ }
351+
352+ if (have_left && !l->intra[yb4]) {
353+ cnt[l->ref[0][yb4] >= 4]++;
354+ if (l->comp_type[yb4]) cnt[l->ref[1][yb4] >= 4]++;
355+ }
356+
357+ return cnt[0] == cnt[1] ? 1 : cnt[0] < cnt[1] ? 0 : 2;
358+}
359+
360+static inline int av1_get_fwd_ref_ctx(const BlockContext *const a,
361+ const BlockContext *const l,
362+ const int yb4, const int xb4,
363+ const int have_top, const int have_left)
364+{
365+ int cnt[4] = { 0 };
366+
367+ if (have_top && !a->intra[xb4]) {
368+ if (a->ref[0][xb4] < 4) cnt[a->ref[0][xb4]]++;
369+ if (a->comp_type[xb4] && a->ref[1][xb4] < 4) cnt[a->ref[1][xb4]]++;
370+ }
371+
372+ if (have_left && !l->intra[yb4]) {
373+ if (l->ref[0][yb4] < 4) cnt[l->ref[0][yb4]]++;
374+ if (l->comp_type[yb4] && l->ref[1][yb4] < 4) cnt[l->ref[1][yb4]]++;
375+ }
376+
377+ cnt[0] += cnt[1];
378+ cnt[2] += cnt[3];
379+
380+ return cnt[0] == cnt[2] ? 1 : cnt[0] < cnt[2] ? 0 : 2;
381+}
382+
383+static inline int av1_get_fwd_ref_1_ctx(const BlockContext *const a,
384+ const BlockContext *const l,
385+ const int yb4, const int xb4,
386+ const int have_top, const int have_left)
387+{
388+ int cnt[2] = { 0 };
389+
390+ if (have_top && !a->intra[xb4]) {
391+ if (a->ref[0][xb4] < 2) cnt[a->ref[0][xb4]]++;
392+ if (a->comp_type[xb4] && a->ref[1][xb4] < 2) cnt[a->ref[1][xb4]]++;
393+ }
394+
395+ if (have_left && !l->intra[yb4]) {
396+ if (l->ref[0][yb4] < 2) cnt[l->ref[0][yb4]]++;
397+ if (l->comp_type[yb4] && l->ref[1][yb4] < 2) cnt[l->ref[1][yb4]]++;
398+ }
399+
400+ return cnt[0] == cnt[1] ? 1 : cnt[0] < cnt[1] ? 0 : 2;
401+}
402+
403+static inline int av1_get_fwd_ref_2_ctx(const BlockContext *const a,
404+ const BlockContext *const l,
405+ const int yb4, const int xb4,
406+ const int have_top, const int have_left)
407+{
408+ int cnt[2] = { 0 };
409+
410+ if (have_top && !a->intra[xb4]) {
411+ if (a->ref[0][xb4] - 2U < 2) cnt[a->ref[0][xb4] - 2]++;
412+ if (a->comp_type[xb4] && a->ref[1][xb4] - 2U < 2) cnt[a->ref[1][xb4] - 2]++;
413+ }
414+
415+ if (have_left && !l->intra[yb4]) {
416+ if (l->ref[0][yb4] - 2U < 2) cnt[l->ref[0][yb4] - 2]++;
417+ if (l->comp_type[yb4] && l->ref[1][yb4] - 2U < 2) cnt[l->ref[1][yb4] - 2]++;
418+ }
419+
420+ return cnt[0] == cnt[1] ? 1 : cnt[0] < cnt[1] ? 0 : 2;
421+}
422+
423+static inline int av1_get_bwd_ref_ctx(const BlockContext *const a,
424+ const BlockContext *const l,
425+ const int yb4, const int xb4,
426+ const int have_top, const int have_left)
427+{
428+ int cnt[3] = { 0 };
429+
430+ if (have_top && !a->intra[xb4]) {
431+ if (a->ref[0][xb4] >= 4) cnt[a->ref[0][xb4] - 4]++;
432+ if (a->comp_type[xb4] && a->ref[1][xb4] >= 4) cnt[a->ref[1][xb4] - 4]++;
433+ }
434+
435+ if (have_left && !l->intra[yb4]) {
436+ if (l->ref[0][yb4] >= 4) cnt[l->ref[0][yb4] - 4]++;
437+ if (l->comp_type[yb4] && l->ref[1][yb4] >= 4) cnt[l->ref[1][yb4] - 4]++;
438+ }
439+
440+ cnt[1] += cnt[0];
441+
442+ return cnt[2] == cnt[1] ? 1 : cnt[1] < cnt[2] ? 0 : 2;
443+}
444+
445+static inline int av1_get_bwd_ref_1_ctx(const BlockContext *const a,
446+ const BlockContext *const l,
447+ const int yb4, const int xb4,
448+ const int have_top, const int have_left)
449+{
450+ int cnt[3] = { 0 };
451+
452+ if (have_top && !a->intra[xb4]) {
453+ if (a->ref[0][xb4] >= 4) cnt[a->ref[0][xb4] - 4]++;
454+ if (a->comp_type[xb4] && a->ref[1][xb4] >= 4) cnt[a->ref[1][xb4] - 4]++;
455+ }
456+
457+ if (have_left && !l->intra[yb4]) {
458+ if (l->ref[0][yb4] >= 4) cnt[l->ref[0][yb4] - 4]++;
459+ if (l->comp_type[yb4] && l->ref[1][yb4] >= 4) cnt[l->ref[1][yb4] - 4]++;
460+ }
461+
462+ return cnt[0] == cnt[1] ? 1 : cnt[0] < cnt[1] ? 0 : 2;
463+}
464+
465+static inline int av1_get_uni_p1_ctx(const BlockContext *const a,
466+ const BlockContext *const l,
467+ const int yb4, const int xb4,
468+ const int have_top, const int have_left)
469+{
470+ int cnt[3] = { 0 };
471+
472+ if (have_top && !a->intra[xb4]) {
473+ if (a->ref[0][xb4] - 1U < 3) cnt[a->ref[0][xb4] - 1]++;
474+ if (a->comp_type[xb4] && a->ref[1][xb4] - 1U < 3) cnt[a->ref[1][xb4] - 1]++;
475+ }
476+
477+ if (have_left && !l->intra[yb4]) {
478+ if (l->ref[0][yb4] - 1U < 3) cnt[l->ref[0][yb4] - 1]++;
479+ if (l->comp_type[yb4] && l->ref[1][yb4] - 1U < 3) cnt[l->ref[1][yb4] - 1]++;
480+ }
481+
482+ cnt[1] += cnt[2];
483+
484+ return cnt[0] == cnt[1] ? 1 : cnt[0] < cnt[1] ? 0 : 2;
485+}
486+
487+static inline int get_drl_context(const candidate_mv *const ref_mv_stack,
488+ const int ref_idx)
489+{
490+ if (ref_mv_stack[ref_idx].weight >= 640 &&
491+ ref_mv_stack[ref_idx + 1].weight >= 640)
492+ return 0;
493+
494+ if (ref_mv_stack[ref_idx].weight >= 640 &&
495+ ref_mv_stack[ref_idx + 1].weight < 640)
496+ return 1;
497+
498+ if (ref_mv_stack[ref_idx].weight < 640 &&
499+ ref_mv_stack[ref_idx + 1].weight < 640)
500+ return 2;
501+
502+ return 0;
503+}
504+
505+static inline unsigned get_cur_frame_segid(const int by, const int bx,
506+ const int have_top,
507+ const int have_left,
508+ int *const seg_ctx,
509+ const uint8_t *cur_seg_map,
510+ const ptrdiff_t stride)
511+{
512+ cur_seg_map += bx + by * stride;
513+ if (have_left && have_top) {
514+ const int l = cur_seg_map[-1];
515+ const int a = cur_seg_map[-stride];
516+ const int al = cur_seg_map[-(stride + 1)];
517+
518+ if (l == a && al == l) *seg_ctx = 2;
519+ else if (l == a || al == l || a == al) *seg_ctx = 1;
520+ else *seg_ctx = 0;
521+ return a == al ? a : l;
522+ } else {
523+ *seg_ctx = 0;
524+ return have_left ? cur_seg_map[-1] : have_top ? cur_seg_map[-stride] : 0;
525+ }
526+}
527+
528+static inline int get_coef_skip_ctx(const TxfmInfo *const t_dim,
529+ const enum BlockSize bs,
530+ const uint8_t *const a,
531+ const uint8_t *const l,
532+ const int chroma,
533+ const enum Dav1dPixelLayout layout)
534+{
535+ const uint8_t *const b_dim = av1_block_dimensions[bs];
536+
537+ if (chroma) {
538+ const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420;
539+ const int ss_hor = layout != DAV1D_PIXEL_LAYOUT_I444;
540+ const int not_one_blk = b_dim[2] - (!!b_dim[2] && ss_hor) > t_dim->lw ||
541+ b_dim[3] - (!!b_dim[3] && ss_ver) > t_dim->lh;
542+ int ca, cl;
543+
544+#define MERGE_CTX(dir, type, mask) \
545+ c##dir = !!((*(const type *) dir) & mask); \
546+ break
547+ switch (t_dim->lw) {
548+ case TX_4X4: MERGE_CTX(a, uint8_t, 0x3F);
549+ case TX_8X8: MERGE_CTX(a, uint16_t, 0x3F3F);
550+ case TX_16X16: MERGE_CTX(a, uint32_t, 0x3F3F3F3FU);
551+ case TX_32X32: MERGE_CTX(a, uint64_t, 0x3F3F3F3F3F3F3F3FULL);
552+ default: abort();
553+ }
554+ switch (t_dim->lh) {
555+ case TX_4X4: MERGE_CTX(l, uint8_t, 0x3F);
556+ case TX_8X8: MERGE_CTX(l, uint16_t, 0x3F3F);
557+ case TX_16X16: MERGE_CTX(l, uint32_t, 0x3F3F3F3FU);
558+ case TX_32X32: MERGE_CTX(l, uint64_t, 0x3F3F3F3F3F3F3F3FULL);
559+ default: abort();
560+ }
561+#undef MERGE_CTX
562+
563+ return 7 + not_one_blk * 3 + ca + cl;
564+ } else if (b_dim[2] == t_dim->lw && b_dim[3] == t_dim->lh) {
565+ return 0;
566+ } else {
567+ static const uint8_t skip_contexts[5][5] = {
568+ { 1, 2, 2, 2, 3 },
569+ { 1, 4, 4, 4, 5 },
570+ { 1, 4, 4, 4, 5 },
571+ { 1, 4, 4, 4, 5 },
572+ { 1, 4, 4, 4, 6 }
573+ };
574+ uint64_t la, ll;
575+
576+#define MERGE_CTX(dir, type, tx) do { \
577+ l##dir = *(const type *) dir; \
578+ if (tx == TX_64X64) \
579+ l##dir |= *(const type *) &dir[sizeof(type)]; \
580+ if (tx >= TX_32X32) l##dir |= l##dir >> 32; \
581+ if (tx >= TX_16X16) l##dir |= l##dir >> 16; \
582+ if (tx >= TX_8X8) l##dir |= l##dir >> 8; \
583+ l##dir &= 0x3F; \
584+ } while (0); \
585+ break
586+ switch (t_dim->lw) {
587+ case TX_4X4: MERGE_CTX(a, uint8_t, TX_4X4);
588+ case TX_8X8: MERGE_CTX(a, uint16_t, TX_8X8);
589+ case TX_16X16: MERGE_CTX(a, uint32_t, TX_16X16);
590+ case TX_32X32: MERGE_CTX(a, uint64_t, TX_32X32);
591+ case TX_64X64: MERGE_CTX(a, uint64_t, TX_64X64);
592+ }
593+ switch (t_dim->lh) {
594+ case TX_4X4: MERGE_CTX(l, uint8_t, TX_4X4);
595+ case TX_8X8: MERGE_CTX(l, uint16_t, TX_8X8);
596+ case TX_16X16: MERGE_CTX(l, uint32_t, TX_16X16);
597+ case TX_32X32: MERGE_CTX(l, uint64_t, TX_32X32);
598+ case TX_64X64: MERGE_CTX(l, uint64_t, TX_64X64);
599+ }
600+#undef MERGE_CTX
601+
602+ const int max = imin(la | ll, 4);
603+ const int min = imin(imin(la, ll), 4);
604+
605+ return skip_contexts[min][max];
606+ }
607+}
608+
609+static inline int get_coef_nz_ctx(uint8_t *const levels, const int scan_idx,
610+ const int rc, const int is_eob,
611+ const enum RectTxfmSize tx,
612+ const enum TxClass tx_class)
613+{
614+ const TxfmInfo *const t_dim = &av1_txfm_dimensions[tx];
615+
616+ if (is_eob) {
617+ if (scan_idx == 0) return 0;
618+ const int eighth_sz = imin(t_dim->w, 8) * imin(t_dim->h, 8) * 2;
619+ if (scan_idx <= eighth_sz) return 1;
620+ const int quart_sz = eighth_sz * 2;
621+ if (scan_idx <= quart_sz) return 2;
622+ return 3;
623+ }
624+
625+ const int x = rc >> (2 + imin(t_dim->lh, 3));
626+ const int y = rc & (4 * imin(t_dim->h, 8) - 1);
627+ const ptrdiff_t stride = 4 * (imin(t_dim->h, 8) + 1);
628+ static const uint8_t offsets[3][5][2 /* x, y */] = {
629+ [TX_CLASS_2D] = {
630+ { 0, 1 }, { 1, 0 }, { 2, 0 }, { 0, 2 }, { 1, 1 }
631+ }, [TX_CLASS_V] = {
632+ { 0, 1 }, { 1, 0 }, { 0, 2 }, { 0, 3 }, { 0, 4 }
633+ }, [TX_CLASS_H] = {
634+ { 0, 1 }, { 1, 0 }, { 2, 0 }, { 3, 0 }, { 4, 0 }
635+ }
636+ };
637+ const uint8_t (*const off)[2] = offsets[tx_class];
638+ int mag = 0;
639+ for (int i = 0; i < 5; i++)
640+ mag += imin(levels[(x + off[i][0]) * stride + (y + off[i][1])], 3);
641+ const int ctx = imin((mag + 1) >> 1, 4);
642+ if (tx_class == TX_CLASS_2D) {
643+ return !rc ? 0 :
644+ av1_nz_map_ctx_offset[tx][imin(y, 4)][imin(x, 4)] + ctx;
645+ } else {
646+ return 26 + imin((tx_class == TX_CLASS_V) ? y : x, 2) * 5 + ctx;
647+ }
648+}
649+
650+static inline int get_dc_sign_ctx(const TxfmInfo *const t_dim,
651+ const uint8_t *const a,
652+ const uint8_t *const l)
653+{
654+ uint64_t sa, sl;
655+
656+#define MERGE_CTX(dir, type, tx, mask) do { \
657+ s##dir = ((*(const type *) dir) >> 6) & mask; \
658+ if (tx == TX_64X64) \
659+ s##dir += ((*(const type *) &dir[sizeof(type)]) >> 6) & mask; \
660+ if (tx >= TX_32X32) s##dir += s##dir >> 32; \
661+ if (tx >= TX_16X16) s##dir += s##dir >> 16; \
662+ if (tx >= TX_8X8) s##dir += s##dir >> 8; \
663+ } while (0); \
664+ break
665+ switch (t_dim->lw) {
666+ case TX_4X4: MERGE_CTX(a, uint8_t, TX_4X4, 0x03);
667+ case TX_8X8: MERGE_CTX(a, uint16_t, TX_8X8, 0x0303);
668+ case TX_16X16: MERGE_CTX(a, uint32_t, TX_16X16, 0x03030303U);
669+ case TX_32X32: MERGE_CTX(a, uint64_t, TX_32X32, 0x0303030303030303ULL);
670+ case TX_64X64: MERGE_CTX(a, uint64_t, TX_64X64, 0x0303030303030303ULL);
671+ }
672+ switch (t_dim->lh) {
673+ case TX_4X4: MERGE_CTX(l, uint8_t, TX_4X4, 0x03);
674+ case TX_8X8: MERGE_CTX(l, uint16_t, TX_8X8, 0x0303);
675+ case TX_16X16: MERGE_CTX(l, uint32_t, TX_16X16, 0x03030303U);
676+ case TX_32X32: MERGE_CTX(l, uint64_t, TX_32X32, 0x0303030303030303ULL);
677+ case TX_64X64: MERGE_CTX(l, uint64_t, TX_64X64, 0x0303030303030303ULL);
678+ }
679+#undef MERGE_CTX
680+ const int s = ((int) ((sa + sl) & 0xFF)) - (t_dim->w + t_dim->h);
681+
682+ return s < 0 ? 1 : s > 0 ? 2 : 0;
683+}
684+
685+static inline int get_br_ctx(const uint8_t *const levels,
686+ const int rc, const enum RectTxfmSize tx,
687+ const enum TxClass tx_class)
688+{
689+ const TxfmInfo *const t_dim = &av1_txfm_dimensions[tx];
690+ const int x = rc >> (imin(t_dim->lh, 3) + 2);
691+ const int y = rc & (4 * imin(t_dim->h, 8) - 1);
692+ const int stride = 4 * (imin(t_dim->h, 8) + 1);
693+ int mag = 0;
694+ static const uint8_t offsets_from_txclass[3][3][2] = {
695+ [TX_CLASS_2D] = { { 0, 1 }, { 1, 0 }, { 1, 1 } },
696+ [TX_CLASS_H] = { { 0, 1 }, { 1, 0 }, { 0, 2 } },
697+ [TX_CLASS_V] = { { 0, 1 }, { 1, 0 }, { 2, 0 } }
698+ };
699+ const uint8_t (*const offsets)[2] = offsets_from_txclass[tx_class];
700+ for (int i = 0; i < 3; i++)
701+ mag += levels[(x + offsets[i][1]) * stride + y + offsets[i][0]];
702+
703+ mag = imin((mag + 1) >> 1, 6);
704+ if (rc == 0) return mag;
705+ switch (tx_class) {
706+ case TX_CLASS_2D:
707+ if (y < 2 && x < 2) return mag + 7;
708+ break;
709+ case TX_CLASS_H:
710+ if (x == 0) return mag + 7;
711+ break;
712+ case TX_CLASS_V:
713+ if (y == 0) return mag + 7;
714+ break;
715+ }
716+ return mag + 14;
717+}
718+
719+static inline mv get_gmv_2d(const WarpedMotionParams *const gmv,
720+ const int bx4, const int by4,
721+ const int bw4, const int bh4,
722+ const Av1FrameHeader *const hdr)
723+{
724+ switch (gmv->type) {
725+ case WM_TYPE_ROT_ZOOM:
726+ assert(gmv->matrix[5] == gmv->matrix[2]);
727+ assert(gmv->matrix[4] == -gmv->matrix[3]);
728+ // fall-through
729+ default:
730+ case WM_TYPE_AFFINE: {
731+ const int x = bx4 * 4 + bw4 * 2 - 1;
732+ const int y = by4 * 4 + bh4 * 2 - 1;
733+ const int xc = (gmv->matrix[2] - (1 << 16)) * x +
734+ gmv->matrix[3] * y + gmv->matrix[0];
735+ const int yc = (gmv->matrix[5] - (1 << 16)) * y +
736+ gmv->matrix[4] * x + gmv->matrix[1];
737+ const int shift = 16 - (3 - !hdr->hp);
738+ const int round = (1 << shift) >> 1;
739+ return (mv) {
740+ .y = apply_sign(((abs(yc) + round) >> shift) << !hdr->hp, yc),
741+ .x = apply_sign(((abs(xc) + round) >> shift) << !hdr->hp, xc),
742+ };
743+ }
744+ case WM_TYPE_TRANSLATION:
745+ return (mv) {
746+ .y = gmv->matrix[0] >> 13,
747+ .x = gmv->matrix[1] >> 13,
748+ };
749+ case WM_TYPE_IDENTITY:
750+ return (mv) { .x = 0, .y = 0 };
751+ }
752+}
753+
754+#endif /* __DAV1D_SRC_ENV_H__ */
src/getbits.c+129−0
@@ -0,0 +1,129 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#include "config.h"
29+
30+#include <assert.h>
31+
32+#include "common/intops.h"
33+
34+#include "src/getbits.h"
35+
36+void init_get_bits(GetBits *const c,
37+ const uint8_t *const data, const size_t sz)
38+{
39+ c->ptr = c->ptr_start = data;
40+ c->ptr_end = &c->ptr_start[sz];
41+ c->bits_left = 0;
42+ c->state = 0;
43+ c->error = 0;
44+ c->eof = 0;
45+}
46+
47+static void refill(GetBits *const c, const unsigned n) {
48+ assert(c->bits_left <= 56);
49+ uint64_t state = 0;
50+ do {
51+ state <<= 8;
52+ c->bits_left += 8;
53+ if (!c->eof)
54+ state |= *c->ptr++;
55+ if (c->ptr >= c->ptr_end) {
56+ c->error = c->eof;
57+ c->eof = 1;
58+ }
59+ } while (n > c->bits_left);
60+ c->state |= state << (64 - c->bits_left);
61+}
62+
63+unsigned get_bits(GetBits *const c, const unsigned n) {
64+ assert(n <= 32 /* can go up to 57 if we change return type */);
65+
66+ if (n > c->bits_left) refill(c, n);
67+
68+ const uint64_t state = c->state;
69+ c->bits_left -= n;
70+ c->state <<= n;
71+
72+ return state >> (64 - n);
73+}
74+
75+int get_sbits(GetBits *const c, const unsigned n) {
76+ const int shift = 31 - n;
77+ const int res = get_bits(c, n + 1) << shift;
78+ return res >> shift;
79+}
80+
81+unsigned get_uniform(GetBits *const c, const unsigned n) {
82+ assert(n > 0);
83+ const int l = ulog2(n) + 1;
84+ assert(l > 0);
85+ const int m = (1 << l) - n;
86+ const int v = get_bits(c, l - 1);
87+ return v < m ? v : (v << 1) - m + get_bits(c, 1);
88+}
89+
90+unsigned get_vlc(GetBits *const c) {
91+ int n_bits = 0;
92+ while (!get_bits(c, 1)) n_bits++;
93+ if (n_bits >= 32) return 0xFFFFFFFFU;
94+ return ((1 << n_bits) - 1) + get_bits(c, n_bits);
95+}
96+
97+static unsigned get_bits_subexp_u(GetBits *const c, const unsigned ref,
98+ const unsigned n)
99+{
100+ unsigned v = 0;
101+
102+ for (int i = 0;; i++) {
103+ const int b = i ? 3 + i - 1 : 3;
104+
105+ if (n < v + 3 * (1 << b)) {
106+ v += get_uniform(c, n - v + 1);
107+ break;
108+ }
109+
110+ if (!get_bits(c, 1)) {
111+ v += get_bits(c, b);
112+ break;
113+ }
114+
115+ v += 1 << b;
116+ }
117+
118+ return ref * 2 <= n ? inv_recenter(ref, v) : n - inv_recenter(n - ref, v);
119+}
120+
121+int get_bits_subexp(GetBits *const c, const int ref, const unsigned n) {
122+ return (int) get_bits_subexp_u(c, ref + (1 << n), 2 << n) - (1 << n);
123+}
124+
125+const uint8_t *flush_get_bits(GetBits *c) {
126+ c->bits_left = 0;
127+ c->state = 0;
128+ return c->ptr;
129+}
src/getbits.h+49−0
@@ -0,0 +1,49 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __DAV1D_SRC_GETBITS_H__
29+#define __DAV1D_SRC_GETBITS_H__
30+
31+#include <stddef.h>
32+#include <stdint.h>
33+
34+typedef struct GetBits {
35+ int error, eof;
36+ uint64_t state;
37+ unsigned bits_left;
38+ const uint8_t *ptr, *ptr_start, *ptr_end;
39+} GetBits;
40+
41+void init_get_bits(GetBits *c, const uint8_t *data, size_t sz);
42+unsigned get_bits(GetBits *c, unsigned n);
43+int get_sbits(GetBits *c, unsigned n);
44+unsigned get_uniform(GetBits *c, unsigned range);
45+unsigned get_vlc(GetBits *c);
46+int get_bits_subexp(GetBits *c, int ref, unsigned n);
47+const uint8_t *flush_get_bits(GetBits *c);
48+
49+#endif /* __DAV1D_SRC_GETBITS_H__ */
src/internal.h+275−0
@@ -0,0 +1,275 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __DAV1D_SRC_INTERNAL_H__
29+#define __DAV1D_SRC_INTERNAL_H__
30+
31+#include <pthread.h>
32+#include <stdatomic.h>
33+
34+#include "dav1d/data.h"
35+
36+typedef struct Dav1dFrameContext Dav1dFrameContext;
37+typedef struct Dav1dTileState Dav1dTileState;
38+typedef struct Dav1dTileContext Dav1dTileContext;
39+
40+#include "common/attributes.h"
41+
42+#include "src/cdef.h"
43+#include "src/cdf.h"
44+#include "src/env.h"
45+#include "src/intra_edge.h"
46+#include "src/ipred.h"
47+#include "src/itx.h"
48+#include "src/levels.h"
49+#include "src/lf_mask.h"
50+#include "src/loopfilter.h"
51+#include "src/looprestoration.h"
52+#include "src/mc.h"
53+#include "src/msac.h"
54+#include "src/picture.h"
55+#include "src/recon.h"
56+#include "src/ref_mvs.h"
57+
58+typedef struct Dav1dDSPContext {
59+ Dav1dIntraPredDSPContext ipred;
60+ Dav1dMCDSPContext mc;
61+ Dav1dInvTxfmDSPContext itx;
62+ Dav1dLoopFilterDSPContext lf;
63+ Dav1dCdefDSPContext cdef;
64+ Dav1dLoopRestorationDSPContext lr;
65+} Dav1dDSPContext;
66+
67+struct Dav1dContext {
68+ Dav1dFrameContext *fc;
69+ int n_fc;
70+
71+ // cache of OBUs that make up a single frame before we submit them
72+ // to a frame worker to be decoded
73+ struct {
74+ Dav1dData data;
75+ int start, end;
76+ } tile[256];
77+ int n_tile_data, have_seq_hdr, have_frame_hdr;
78+ unsigned tile_mask;
79+ Av1SequenceHeader seq_hdr; // FIXME make ref?
80+ Av1FrameHeader frame_hdr; // FIXME make ref?
81+
82+ // decoded output picture queue
83+ Dav1dPicture out;
84+ struct {
85+ Dav1dThreadPicture *out_delayed;
86+ unsigned next;
87+ } frame_thread;
88+
89+ // reference/entropy state
90+ struct {
91+ Dav1dThreadPicture p;
92+ Dav1dRef *segmap;
93+ Av1SegmentationDataSet seg_data;
94+ Dav1dRef *refmvs;
95+ unsigned refpoc[7];
96+ WarpedMotionParams gmv[7];
97+ Av1LoopfilterModeRefDeltas lf_mode_ref_deltas;
98+ Av1FilmGrainData film_grain;
99+ } refs[8];
100+ CdfThreadContext cdf[8];
101+
102+ Dav1dDSPContext dsp[3 /* 8, 10, 12 bits/component */];
103+
104+ // tree to keep track of which edges are available
105+ struct {
106+ EdgeNode *root[2 /* BL_128X128 vs. BL_64X64 */];
107+ EdgeBranch branch_sb128[1 + 4 + 16 + 64];
108+ EdgeBranch branch_sb64[1 + 4 + 16];
109+ EdgeTip tip_sb128[256];
110+ EdgeTip tip_sb64[64];
111+ } intra_edge;
112+};
113+
114+struct Dav1dFrameContext {
115+ Av1SequenceHeader seq_hdr;
116+ Av1FrameHeader frame_hdr;
117+ Dav1dThreadPicture refp[7], cur;
118+ Dav1dRef *mvs_ref;
119+ refmvs *mvs, *ref_mvs[7];
120+ Dav1dRef *ref_mvs_ref[7];
121+ Dav1dRef *cur_segmap_ref, *prev_segmap_ref;
122+ uint8_t *cur_segmap;
123+ const uint8_t *prev_segmap;
124+ unsigned refpoc[7], refrefpoc[7][7];
125+ CdfThreadContext in_cdf, out_cdf;
126+ struct {
127+ Dav1dData data;
128+ int start, end;
129+ } tile[256];
130+ int n_tile_data;
131+
132+ const Dav1dContext *c;
133+ Dav1dTileContext *tc;
134+ int n_tc;
135+ Dav1dTileState *ts;
136+ int n_ts;
137+ const Dav1dDSPContext *dsp;
138+ struct {
139+ recon_b_intra_fn recon_b_intra;
140+ recon_b_inter_fn recon_b_inter;
141+ filter_sbrow_fn filter_sbrow;
142+ backup_ipred_edge_fn backup_ipred_edge;
143+ read_coef_blocks_fn read_coef_blocks;
144+ } bd_fn;
145+
146+ int ipred_edge_sz;
147+ pixel *ipred_edge[3];
148+ ptrdiff_t b4_stride;
149+ int bw, bh, sb128w, sb128h, sbh, sb_shift, sb_step;
150+ uint16_t dq[NUM_SEGMENTS][3 /* plane */][2 /* dc/ac */];
151+ const uint8_t *qm[2 /* is_1d */][N_RECT_TX_SIZES][3 /* plane */];
152+ BlockContext *a;
153+ int a_sz /* w*tile_rows */;
154+ AV1_COMMON *libaom_cm; // FIXME
155+ uint8_t jnt_weights[7][7];
156+
157+ struct {
158+ struct thread_data td;
159+ int pass, die;
160+ // indexed using t->by * f->b4_stride + t->bx
161+ Av1Block *b;
162+ struct CodedBlockInfo {
163+ int16_t eob[3 /* plane */];
164+ uint8_t txtp[3 /* plane */];
165+ } *cbi;
166+ int8_t *txtp;
167+ // indexed using (t->by >> 1) * (f->b4_stride >> 1) + (t->bx >> 1)
168+ uint16_t (*pal)[3 /* plane */][8 /* idx */];
169+ // iterated over inside tile state
170+ uint8_t *pal_idx;
171+ coef *cf;
172+ // start offsets per tile
173+ int *tile_start_off;
174+ } frame_thread;
175+
176+ // loopfilter
177+ struct {
178+ uint8_t (*level)[4];
179+ Av1Filter *mask;
180+ int top_pre_cdef_toggle;
181+ int mask_sz /* w*h */, line_sz /* w */, re_sz /* h */;
182+ Av1FilterLUT lim_lut;
183+ int last_sharpness;
184+ uint8_t lvl[8 /* seg_id */][4 /* dir */][8 /* ref */][2 /* is_gmv */];
185+ uint8_t *tx_lpf_right_edge[2];
186+ pixel *cdef_line;
187+ pixel *cdef_line_ptr[2 /* pre, post */][3 /* plane */][2 /* y */];
188+ pixel *lr_lpf_line;
189+ pixel *lr_lpf_line_ptr[3 /* plane */];
190+
191+ // in-loop filter per-frame state keeping
192+ int tile_row; // for carry-over at tile row edges
193+ pixel *p[3];
194+ Av1Filter *mask_ptr, *prev_mask_ptr;
195+ } lf;
196+
197+ // threading (refer to tc[] for per-thread things)
198+ struct FrameTileThreadData {
199+ uint64_t available;
200+ pthread_mutex_t lock;
201+ pthread_cond_t cond, icond;
202+ int tasks_left, num_tasks;
203+ int (*task_idx_to_sby_and_tile_idx)[2];
204+ int titsati_sz, titsati_init[2];
205+ } tile_thread;
206+};
207+
208+struct Dav1dTileState {
209+ struct {
210+ int col_start, col_end, row_start, row_end; // in 4px units
211+ int col, row; // in tile units
212+ } tiling;
213+
214+ CdfContext cdf;
215+ MsacContext msac;
216+
217+ atomic_int progress; // in sby units
218+ struct {
219+ pthread_mutex_t lock;
220+ pthread_cond_t cond;
221+ } tile_thread;
222+ struct {
223+ uint8_t *pal_idx;
224+ coef *cf;
225+ } frame_thread;
226+
227+ uint16_t dqmem[NUM_SEGMENTS][3 /* plane */][2 /* dc/ac */];
228+ const uint16_t (*dq)[3][2];
229+ int last_qidx;
230+
231+ int8_t last_delta_lf[4];
232+ uint8_t lflvlmem[8 /* seg_id */][4 /* dir */][8 /* ref */][2 /* is_gmv */];
233+ const uint8_t (*lflvl)[4][8][2];
234+
235+ Av1RestorationUnit *lr_ref[3];
236+};
237+
238+struct Dav1dTileContext {
239+ const Dav1dFrameContext *f;
240+ Dav1dTileState *ts;
241+ int bx, by;
242+ BlockContext l, *a;
243+ coef *cf;
244+ pixel *emu_edge; // stride=160
245+ // FIXME types can be changed to pixel (and dynamically allocated)
246+ // which would make copy/assign operations slightly faster?
247+ uint16_t al_pal[2 /* a/l */][32 /* bx/y4 */][3 /* plane */][8 /* palette_idx */];
248+ uint16_t pal[3 /* plane */][8 /* palette_idx */];
249+ uint8_t pal_sz_uv[2 /* a/l */][32 /* bx4/by4 */];
250+ uint8_t txtp_map[32 * 32]; // inter-only
251+ WarpedMotionParams warpmv;
252+ union {
253+ void *mem;
254+ uint8_t *pal_idx;
255+ int16_t *ac;
256+ pixel *interintra, *lap;
257+ coef *compinter;
258+ } scratch;
259+ ALIGN(uint8_t scratch_seg_mask[128 * 128], 32);
260+
261+ Av1Filter *lf_mask;
262+ int8_t *cur_sb_cdef_idx_ptr;
263+ // for chroma sub8x8, we need to know the filter for all 4 subblocks in
264+ // a 4x4 area, but the top/left one can go out of cache already, so this
265+ // keeps it accessible
266+ enum Filter2d tl_4x4_filter;
267+
268+ struct {
269+ struct thread_data td;
270+ struct FrameTileThreadData *fttd;
271+ int die;
272+ } tile_thread;
273+};
274+
275+#endif /* __DAV1D_SRC_INTERNAL_H__ */
src/intra_edge.c+166−0
@@ -0,0 +1,166 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#include "config.h"
29+
30+#include <assert.h>
31+
32+#include "src/intra_edge.h"
33+#include "src/levels.h"
34+
35+struct ModeSelMem {
36+ EdgeBranch *nwc[3 /* 64x64, 32x32, 16x16 */];
37+ EdgeTip *nt;
38+};
39+
40+static void init_edges(EdgeNode *const node,
41+ const enum BlockLevel bl,
42+ const enum EdgeFlags edge_flags)
43+{
44+ node->o = edge_flags;
45+
46+#define ALL_FL(t) (EDGE_I444_##t | EDGE_I422_##t | EDGE_I420_##t)
47+ if (bl == BL_8X8) {
48+ EdgeTip *const nt = (EdgeTip *) node;
49+
50+ node->h[0] = edge_flags | ALL_FL(LEFT_HAS_BOTTOM);
51+ node->h[1] = edge_flags & (ALL_FL(LEFT_HAS_BOTTOM) |
52+ EDGE_I420_TOP_HAS_RIGHT);
53+
54+ node->v[0] = edge_flags | ALL_FL(TOP_HAS_RIGHT);
55+ node->v[1] = edge_flags & (ALL_FL(TOP_HAS_RIGHT) |
56+ EDGE_I420_LEFT_HAS_BOTTOM |
57+ EDGE_I422_LEFT_HAS_BOTTOM);
58+
59+ nt->split[0] = ALL_FL(TOP_HAS_RIGHT) | ALL_FL(LEFT_HAS_BOTTOM);
60+ nt->split[1] = (edge_flags & ALL_FL(TOP_HAS_RIGHT)) |
61+ EDGE_I422_LEFT_HAS_BOTTOM;
62+ nt->split[2] = edge_flags | EDGE_I444_TOP_HAS_RIGHT;
63+ nt->split[3] = edge_flags & (EDGE_I420_TOP_HAS_RIGHT |
64+ EDGE_I420_LEFT_HAS_BOTTOM |
65+ EDGE_I422_LEFT_HAS_BOTTOM);
66+ } else {
67+ EdgeBranch *const nwc = (EdgeBranch *) node;
68+
69+ node->h[0] = edge_flags | ALL_FL(LEFT_HAS_BOTTOM);
70+ node->h[1] = edge_flags & ALL_FL(LEFT_HAS_BOTTOM);
71+
72+ node->v[0] = edge_flags | ALL_FL(TOP_HAS_RIGHT);
73+ node->v[1] = edge_flags & ALL_FL(TOP_HAS_RIGHT);
74+
75+ nwc->h4[0] = edge_flags | ALL_FL(LEFT_HAS_BOTTOM);
76+ nwc->h4[1] =
77+ nwc->h4[2] = ALL_FL(LEFT_HAS_BOTTOM);
78+ nwc->h4[3] = edge_flags & ALL_FL(LEFT_HAS_BOTTOM);
79+ if (bl == BL_16X16)
80+ nwc->h4[1] |= edge_flags & EDGE_I420_TOP_HAS_RIGHT;
81+
82+ nwc->v4[0] = edge_flags | ALL_FL(TOP_HAS_RIGHT);
83+ nwc->v4[1] =
84+ nwc->v4[2] = ALL_FL(TOP_HAS_RIGHT);
85+ nwc->v4[3] = edge_flags & ALL_FL(TOP_HAS_RIGHT);
86+ if (bl == BL_16X16)
87+ nwc->v4[1] |= edge_flags & (EDGE_I420_LEFT_HAS_BOTTOM |
88+ EDGE_I422_LEFT_HAS_BOTTOM);
89+
90+ nwc->tls[0] = ALL_FL(TOP_HAS_RIGHT) | ALL_FL(LEFT_HAS_BOTTOM);
91+ nwc->tls[1] = edge_flags & ALL_FL(LEFT_HAS_BOTTOM);
92+ nwc->tls[2] = edge_flags & ALL_FL(TOP_HAS_RIGHT);
93+
94+ nwc->trs[0] = edge_flags | ALL_FL(TOP_HAS_RIGHT);
95+ nwc->trs[1] = edge_flags | ALL_FL(LEFT_HAS_BOTTOM);
96+ nwc->trs[2] = 0;
97+
98+ nwc->tts[0] = ALL_FL(TOP_HAS_RIGHT) | ALL_FL(LEFT_HAS_BOTTOM);
99+ nwc->tts[1] = edge_flags & ALL_FL(TOP_HAS_RIGHT);
100+ nwc->tts[2] = edge_flags & ALL_FL(LEFT_HAS_BOTTOM);
101+
102+ nwc->tbs[0] = edge_flags | ALL_FL(LEFT_HAS_BOTTOM);
103+ nwc->tbs[1] = edge_flags | ALL_FL(TOP_HAS_RIGHT);
104+ nwc->tbs[2] = 0;
105+ }
106+}
107+
108+static void init_mode_node(EdgeBranch *const nwc,
109+ const enum BlockLevel bl,
110+ struct ModeSelMem *const mem,
111+ const int top_has_right,
112+ const int left_has_bottom)
113+{
114+ int n;
115+
116+ init_edges(&nwc->node, bl,
117+ (top_has_right ? ALL_FL(TOP_HAS_RIGHT) : 0) |
118+ (left_has_bottom ? ALL_FL(LEFT_HAS_BOTTOM) : 0));
119+ if (bl == BL_16X16) {
120+ for (n = 0; n < 4; n++) {
121+ EdgeTip *const nt = mem->nt++;
122+ nwc->split[n] = &nt->node;
123+ init_edges(&nt->node, bl + 1,
124+ ((n == 3 || (n == 1 && !top_has_right)) ? 0 :
125+ ALL_FL(TOP_HAS_RIGHT)) |
126+ (!(n == 0 || (n == 2 && left_has_bottom)) ? 0 :
127+ ALL_FL(LEFT_HAS_BOTTOM)));
128+ }
129+ } else {
130+ for (n = 0; n < 4; n++) {
131+ EdgeBranch *const nwc_child = mem->nwc[bl]++;
132+ nwc->split[n] = &nwc_child->node;
133+ init_mode_node(nwc_child, bl + 1, mem,
134+ !(n == 3 || (n == 1 && !top_has_right)),
135+ n == 0 || (n == 2 && left_has_bottom));
136+ }
137+ }
138+}
139+
140+void init_mode_tree(EdgeNode *const root_node, EdgeTip *const nt,
141+ const int allow_sb128)
142+{
143+ EdgeBranch *const root = (EdgeBranch *) root_node;
144+ struct ModeSelMem mem;
145+
146+ if (allow_sb128) {
147+ mem.nwc[BL_128X128] = &root[1];
148+ mem.nwc[BL_64X64] = &root[1 + 4];
149+ mem.nwc[BL_32X32] = &root[1 + 4 + 16];
150+ mem.nt = nt;
151+ init_mode_node(root, BL_128X128, &mem, 1, 0);
152+ assert(mem.nwc[BL_128X128] == &root[1 + 4]);
153+ assert(mem.nwc[BL_64X64] == &root[1 + 4 + 16]);
154+ assert(mem.nwc[BL_32X32] == &root[1 + 4 + 16 + 64]);
155+ assert(mem.nt == &nt[256]);
156+ } else {
157+ mem.nwc[BL_128X128] = NULL;
158+ mem.nwc[BL_64X64] = &root[1];
159+ mem.nwc[BL_32X32] = &root[1 + 4];
160+ mem.nt = nt;
161+ init_mode_node(root, BL_64X64, &mem, 1, 0);
162+ assert(mem.nwc[BL_64X64] == &root[1 + 4]);
163+ assert(mem.nwc[BL_32X32] == &root[1 + 4 + 16]);
164+ assert(mem.nt == &nt[64]);
165+ }
166+}
src/intra_edge.h+57−0
@@ -0,0 +1,57 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __DAV1D_SRC_INTRA_EDGE_H__
29+#define __DAV1D_SRC_INTRA_EDGE_H__
30+
31+enum EdgeFlags {
32+ EDGE_I444_TOP_HAS_RIGHT = 1 << 0,
33+ EDGE_I422_TOP_HAS_RIGHT = 1 << 1,
34+ EDGE_I420_TOP_HAS_RIGHT = 1 << 2,
35+ EDGE_I444_LEFT_HAS_BOTTOM = 1 << 3,
36+ EDGE_I422_LEFT_HAS_BOTTOM = 1 << 4,
37+ EDGE_I420_LEFT_HAS_BOTTOM = 1 << 5,
38+};
39+
40+typedef struct EdgeNode EdgeNode;
41+struct EdgeNode {
42+ enum EdgeFlags o, h[2], v[2];
43+};
44+typedef struct EdgeTip {
45+ EdgeNode node;
46+ enum EdgeFlags split[4];
47+} EdgeTip;
48+typedef struct EdgeBranch {
49+ EdgeNode node;
50+ enum EdgeFlags tts[3], tbs[3], tls[3], trs[3], h4[4], v4[4];
51+ EdgeNode *split[4];
52+} EdgeBranch;
53+
54+void init_mode_tree(EdgeNode *const root, EdgeTip *const nt,
55+ const int allow_sb128);
56+
57+#endif /* __DAV1D_SRC_INTRA_EDGE_H__ */
src/ipred.c+1010−0
@@ -0,0 +1,1010 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#include "config.h"
29+
30+#include <assert.h>
31+#include <stdlib.h>
32+#include <string.h>
33+
34+#include "common/intops.h"
35+
36+#include "src/ipred.h"
37+
38+#define sz_grid(l_fn) \
39+l_fn( 4, 4); \
40+l_fn( 4, 8); \
41+l_fn( 4, 16); \
42+l_fn( 8, 4); \
43+l_fn( 8, 8); \
44+l_fn( 8, 16); \
45+l_fn( 8, 32); \
46+l_fn(16, 4); \
47+l_fn(16, 8); \
48+l_fn(16, 16); \
49+l_fn(16, 32); \
50+l_fn(16, 64); \
51+l_fn(32, 8); \
52+l_fn(32, 16); \
53+l_fn(32, 32); \
54+l_fn(32, 64); \
55+l_fn(64, 16); \
56+l_fn(64, 32); \
57+l_fn(64, 64)
58+
59+static __attribute__((noinline)) void
60+splat_dc_c(pixel *dst, const ptrdiff_t stride,
61+ const int w, const int h, const unsigned dc)
62+{
63+ assert(dc <= (1 << BITDEPTH) - 1);
64+#if BITDEPTH == 8
65+ if (w > 4) {
66+ const uint64_t dcN = dc * 0x0101010101010101ULL;
67+ for (int y = 0; y < h; y++) {
68+ for (int x = 0; x < w; x += sizeof(dcN))
69+ *((uint64_t *) &dst[x]) = dcN;
70+ dst += PXSTRIDE(stride);
71+ }
72+ } else {
73+ const unsigned dcN = dc * 0x01010101U;
74+ for (int y = 0; y < h; y++) {
75+ for (int x = 0; x < w; x += sizeof(dcN))
76+ *((unsigned *) &dst[x]) = dcN;
77+ dst += PXSTRIDE(stride);
78+ }
79+ }
80+#else
81+ const uint64_t dcN = dc * 0x0001000100010001ULL;
82+ for (int y = 0; y < h; y++) {
83+ for (int x = 0; x < w; x += sizeof(dcN) >> 1)
84+ *((uint64_t *) &dst[x]) = dcN;
85+ dst += PXSTRIDE(stride);
86+ }
87+#endif
88+}
89+
90+#define dc_lfn(w, h, dir, dc_gen) \
91+static void dc##dir##_##w##x##h##_c(pixel *dst, const ptrdiff_t stride, \
92+ const pixel *const topleft, const int a) \
93+{ \
94+ dc_gen; \
95+ splat_dc_c(dst, stride, w, h, dc); \
96+}
97+
98+#define dc1d_lfns(width, height, sh1, sh2) \
99+dc_lfn(width, height, top, unsigned dc = width >> 1; \
100+ for (int i = 0; i < width; i++) \
101+ dc += topleft[1 + i]; \
102+ dc >>= sh1); \
103+dc_lfn(width, height, left, unsigned dc = height >> 1; \
104+ for (int i = 0; i < height; i++) \
105+ dc += topleft[-(1 + i)]; \
106+ dc >>= sh2)
107+
108+dc1d_lfns( 4, 4, 2, 2);
109+dc1d_lfns( 4, 8, 2, 3);
110+dc1d_lfns( 4, 16, 2, 4);
111+dc1d_lfns( 8, 4, 3, 2);
112+dc1d_lfns( 8, 8, 3, 3);
113+dc1d_lfns( 8, 16, 3, 4);
114+dc1d_lfns( 8, 32, 3, 5);
115+dc1d_lfns(16, 4, 4, 2);
116+dc1d_lfns(16, 8, 4, 3);
117+dc1d_lfns(16, 16, 4, 4);
118+dc1d_lfns(16, 32, 4, 5);
119+dc1d_lfns(16, 64, 4, 6);
120+dc1d_lfns(32, 8, 5, 3);
121+dc1d_lfns(32, 16, 5, 4);
122+dc1d_lfns(32, 32, 5, 5);
123+dc1d_lfns(32, 64, 5, 6);
124+dc1d_lfns(64, 16, 6, 4);
125+dc1d_lfns(64, 32, 6, 5);
126+dc1d_lfns(64, 64, 6, 6);
127+
128+#define dc2d_lfn(width, height, dc_gen) \
129+dc_lfn(width, height,, unsigned dc = (width + height) >> 1; \
130+ for (int i = 0; i < width; i++) \
131+ dc += topleft[i + 1]; \
132+ for (int i = 0; i < height; i++) \
133+ dc += topleft[-(i + 1)]; \
134+ dc_gen)
135+
136+dc2d_lfn( 4, 4, dc >>= 3);
137+dc2d_lfn( 4, 8, dc = iclip_pixel(0x5556 * dc >> 18));
138+dc2d_lfn( 4, 16, dc = iclip_pixel(0x3334 * dc >> 18));
139+dc2d_lfn( 8, 4, dc = iclip_pixel(0x5556 * dc >> 18));
140+dc2d_lfn( 8, 8, dc >>= 4);
141+dc2d_lfn( 8, 16, dc = iclip_pixel(0x5556 * dc >> 19));
142+dc2d_lfn( 8, 32, dc = iclip_pixel(0x3334 * dc >> 19));
143+dc2d_lfn(16, 4, dc = iclip_pixel(0x3334 * dc >> 18));
144+dc2d_lfn(16, 8, dc = iclip_pixel(0x5556 * dc >> 19));
145+dc2d_lfn(16, 16, dc >>= 5);
146+dc2d_lfn(16, 32, dc = iclip_pixel(0x5556 * dc >> 20));
147+dc2d_lfn(16, 64, dc = iclip_pixel(0x3334 * dc >> 20));
148+dc2d_lfn(32, 8, dc = iclip_pixel(0x3334 * dc >> 19));
149+dc2d_lfn(32, 16, dc = iclip_pixel(0x5556 * dc >> 20));
150+dc2d_lfn(32, 32, dc >>= 6);
151+dc2d_lfn(32, 64, dc = iclip_pixel(0x5556 * dc >> 21));
152+dc2d_lfn(64, 16, dc = iclip_pixel(0x3334 * dc >> 20));
153+dc2d_lfn(64, 32, dc = iclip_pixel(0x5556 * dc >> 21));
154+dc2d_lfn(64, 64, dc >>= 7);
155+
156+#define dc128_lfn(width, height) \
157+dc_lfn(width, height, 128, const unsigned dc = (1 << BITDEPTH) >> 1)
158+
159+sz_grid(dc128_lfn);
160+
161+static __attribute__((noinline)) void
162+v_c(pixel *dst, const ptrdiff_t stride,
163+ const pixel *const topleft, const int width, const int height)
164+{
165+ for (int y = 0; y < height; y++) {
166+ pixel_copy(dst, topleft + 1, width);
167+ dst += PXSTRIDE(stride);
168+ }
169+}
170+
171+#define v_lfn(width, height) \
172+static void v_##width##x##height##_##c(pixel *dst, const ptrdiff_t stride, \
173+ const pixel *const topleft, const int a) \
174+{ \
175+ v_c(dst, stride, topleft, width, height); \
176+}
177+
178+sz_grid(v_lfn);
179+
180+static __attribute__((noinline)) void
181+h_c(pixel *dst, const ptrdiff_t stride,
182+ const pixel *const topleft, const int width, const int height)
183+{
184+ for (int y = 0; y < height; y++) {
185+ pixel_set(dst, topleft[-(1 + y)], width);
186+ dst += PXSTRIDE(stride);
187+ }
188+}
189+
190+#define h_lfn(width, height) \
191+static void h_##width##x##height##_c(pixel *dst, const ptrdiff_t stride, \
192+ const pixel *const topleft, const int a) \
193+{ \
194+ h_c(dst, stride, topleft, width, height); \
195+}
196+
197+sz_grid(h_lfn);
198+
199+static __attribute__((noinline)) void
200+paeth_c(pixel *dst, const ptrdiff_t stride, const pixel *const tl_ptr,
201+ const int width, const int height)
202+{
203+ const int topleft = tl_ptr[0];
204+ for (int y = 0; y < height; y++) {
205+ const int left = tl_ptr[-(y + 1)];
206+ for (int x = 0; x < width; x++) {
207+ const int top = tl_ptr[1 + x];
208+ const int base = left + top - topleft;
209+ const int ldiff = abs(left - base);
210+ const int tdiff = abs(top - base);
211+ const int tldiff = abs(topleft - base);
212+
213+ dst[x] = ldiff <= tdiff && ldiff <= tldiff ? left :
214+ tdiff <= tldiff ? top : topleft;
215+ }
216+ dst += PXSTRIDE(stride);
217+ }
218+}
219+
220+#define paeth_lfn(width, height) \
221+static void paeth_##width##x##height##_c(pixel *dst, const ptrdiff_t stride, \
222+ const pixel *const topleft, \
223+ const int a) \
224+{ \
225+ paeth_c(dst, stride, topleft, width, height); \
226+}
227+
228+sz_grid(paeth_lfn);
229+
230+static const uint8_t sm_weight_arrays[] = {
231+ // Unused, because we always offset by bs, which is at least 2.
232+ 0, 0,
233+ // bs = 2
234+ 255, 128,
235+ // bs = 4
236+ 255, 149, 85, 64,
237+ // bs = 8
238+ 255, 197, 146, 105, 73, 50, 37, 32,
239+ // bs = 16
240+ 255, 225, 196, 170, 145, 123, 102, 84, 68, 54, 43, 33, 26, 20, 17, 16,
241+ // bs = 32
242+ 255, 240, 225, 210, 196, 182, 169, 157, 145, 133, 122, 111, 101, 92, 83, 74,
243+ 66, 59, 52, 45, 39, 34, 29, 25, 21, 17, 14, 12, 10, 9, 8, 8,
244+ // bs = 64
245+ 255, 248, 240, 233, 225, 218, 210, 203, 196, 189, 182, 176, 169, 163, 156,
246+ 150, 144, 138, 133, 127, 121, 116, 111, 106, 101, 96, 91, 86, 82, 77, 73, 69,
247+ 65, 61, 57, 54, 50, 47, 44, 41, 38, 35, 32, 29, 27, 25, 22, 20, 18, 16, 15,
248+ 13, 12, 10, 9, 8, 7, 6, 6, 5, 5, 4, 4, 4,
249+};
250+
251+static __attribute__((noinline)) void
252+smooth_c(pixel *dst, const ptrdiff_t stride, const pixel *const topleft,
253+ const int width, const int height)
254+{
255+ const uint8_t *const weights_hor = &sm_weight_arrays[width];
256+ const uint8_t *const weights_ver = &sm_weight_arrays[height];
257+ const int right = topleft[width], bottom = topleft[-height];
258+
259+ for (int y = 0; y < height; y++) {
260+ for (int x = 0; x < width; x++) {
261+ const int pred = weights_ver[y] * topleft[1 + x] +
262+ (256 - weights_ver[y]) * bottom +
263+ weights_hor[x] * topleft[-(1 + y)] +
264+ (256 - weights_hor[x]) * right;
265+ dst[x] = (pred + 256) >> 9;
266+ }
267+ dst += PXSTRIDE(stride);
268+ }
269+}
270+
271+#define smooth_lfn(width, height) \
272+static void smooth_##width##x##height##_c(pixel *dst, const ptrdiff_t stride, \
273+ const pixel *const topleft, \
274+ const int a) \
275+{ \
276+ smooth_c(dst, stride, topleft, width, height); \
277+}
278+
279+sz_grid(smooth_lfn);
280+
281+static __attribute__((noinline)) void
282+smooth_v_c(pixel *dst, const ptrdiff_t stride, const pixel *const topleft,
283+ const int width, const int height)
284+{
285+ const uint8_t *const weights_ver = &sm_weight_arrays[height];
286+ const int bottom = topleft[-height];
287+
288+ for (int y = 0; y < height; y++) {
289+ for (int x = 0; x < width; x++) {
290+ const int pred = weights_ver[y] * topleft[1 + x] +
291+ (256 - weights_ver[y]) * bottom;
292+ dst[x] = (pred + 128) >> 8;
293+ }
294+ dst += PXSTRIDE(stride);
295+ }
296+}
297+
298+#define smooth_v_lfn(width, height) \
299+static void smooth_v_##width##x##height##_c(pixel *dst, const ptrdiff_t stride, \
300+ const pixel *const topleft, \
301+ const int a) \
302+{ \
303+ smooth_v_c(dst, stride, topleft, width, height); \
304+}
305+
306+sz_grid(smooth_v_lfn);
307+
308+static __attribute__((noinline)) void
309+smooth_h_c(pixel *dst, const ptrdiff_t stride, const pixel *const topleft,
310+ const int width, const int height)
311+{
312+ const uint8_t *const weights_hor = &sm_weight_arrays[width];
313+ const int right = topleft[width];
314+
315+ for (int y = 0; y < height; y++) {
316+ for (int x = 0; x < width; x++) {
317+ const int pred = weights_hor[x] * topleft[-(y + 1)] +
318+ (256 - weights_hor[x]) * right;
319+ dst[x] = (pred + 128) >> 8;
320+ }
321+ dst += PXSTRIDE(stride);
322+ }
323+}
324+
325+#define smooth_h_lfn(width, height) \
326+static void smooth_h_##width##x##height##_c(pixel *dst, const ptrdiff_t stride, \
327+ const pixel *const topleft, \
328+ const int a) \
329+{ \
330+ smooth_h_c(dst, stride, topleft, width, height); \
331+}
332+
333+sz_grid(smooth_h_lfn);
334+
335+static const int16_t dr_intra_derivative[90] = {
336+ // More evenly spread out angles and limited to 10-bit
337+ // Values that are 0 will never be used
338+ // Approx angle
339+ 0, 0, 0, //
340+ 1023, 0, 0, // 3, ...
341+ 547, 0, 0, // 6, ...
342+ 372, 0, 0, 0, 0, // 9, ...
343+ 273, 0, 0, // 14, ...
344+ 215, 0, 0, // 17, ...
345+ 178, 0, 0, // 20, ...
346+ 151, 0, 0, // 23, ... (113 & 203 are base angles)
347+ 132, 0, 0, // 26, ...
348+ 116, 0, 0, // 29, ...
349+ 102, 0, 0, 0, // 32, ...
350+ 90, 0, 0, // 36, ...
351+ 80, 0, 0, // 39, ...
352+ 71, 0, 0, // 42, ...
353+ 64, 0, 0, // 45, ... (45 & 135 are base angles)
354+ 57, 0, 0, // 48, ...
355+ 51, 0, 0, // 51, ...
356+ 45, 0, 0, 0, // 54, ...
357+ 40, 0, 0, // 58, ...
358+ 35, 0, 0, // 61, ...
359+ 31, 0, 0, // 64, ...
360+ 27, 0, 0, // 67, ... (67 & 157 are base angles)
361+ 23, 0, 0, // 70, ...
362+ 19, 0, 0, // 73, ...
363+ 15, 0, 0, 0, 0, // 76, ...
364+ 11, 0, 0, // 81, ...
365+ 7, 0, 0, // 84, ...
366+ 3, 0, 0, // 87, ...
367+};
368+
369+static int get_filter_strength(const unsigned blk_wh, const unsigned d,
370+ const int type)
371+{
372+ int strength = 0;
373+
374+ if (type == 0) {
375+ if (blk_wh <= 8) {
376+ if (d >= 56) strength = 1;
377+ } else if (blk_wh <= 12) {
378+ if (d >= 40) strength = 1;
379+ } else if (blk_wh <= 16) {
380+ if (d >= 40) strength = 1;
381+ } else if (blk_wh <= 24) {
382+ if (d >= 8) strength = 1;
383+ if (d >= 16) strength = 2;
384+ if (d >= 32) strength = 3;
385+ } else if (blk_wh <= 32) {
386+ if (d >= 1) strength = 1;
387+ if (d >= 4) strength = 2;
388+ if (d >= 32) strength = 3;
389+ } else {
390+ if (d >= 1) strength = 3;
391+ }
392+ } else {
393+ if (blk_wh <= 8) {
394+ if (d >= 40) strength = 1;
395+ if (d >= 64) strength = 2;
396+ } else if (blk_wh <= 16) {
397+ if (d >= 20) strength = 1;
398+ if (d >= 48) strength = 2;
399+ } else if (blk_wh <= 24) {
400+ if (d >= 4) strength = 3;
401+ } else {
402+ if (d >= 1) strength = 3;
403+ }
404+ }
405+
406+ return strength;
407+}
408+
409+static void filter_edge(pixel *const out, const int sz,
410+ const pixel *const in, const int from, const int to,
411+ const unsigned strength)
412+{
413+ const uint8_t kernel[3][5] = {
414+ { 0, 4, 8, 4, 0 },
415+ { 0, 5, 6, 5, 0 },
416+ { 2, 4, 4, 4, 2 }
417+ };
418+
419+ assert(strength > 0);
420+ for (int i = 0; i < sz; i++) {
421+ int s = 0;
422+ for (int j = 0; j < 5; j++)
423+ s += in[iclip(i - 2 + j, from, to - 1)] * kernel[strength - 1][j];
424+ out[i] = (s + 8) >> 4;
425+ }
426+}
427+
428+static int get_upsample(const int blk_wh, const unsigned d, const int type) {
429+ if (d >= 40) return 0;
430+ return type ? (blk_wh <= 8) : (blk_wh <= 16);
431+}
432+
433+static void upsample_edge(pixel *const out, const int hsz,
434+ const pixel *const in, const int from, const int to)
435+{
436+ const int8_t kernel[4] = { -1, 9, 9, -1 };
437+ int i;
438+ for (i = 0; i < hsz - 1; i++) {
439+ out[i * 2] = in[iclip(i, from, to - 1)];
440+
441+ int s = 0;
442+ for (int j = 0; j < 4; j++)
443+ s += in[iclip(i + j - 1, from, to - 1)] * kernel[j];
444+ out[i * 2 + 1] = iclip_pixel((s + 8) >> 4);
445+ }
446+ out[i * 2] = in[iclip(i, from, to - 1)];
447+}
448+
449+static __attribute__((noinline)) void
450+z1_c(pixel *dst, const ptrdiff_t stride, const pixel *const topleft_in,
451+ int angle, const int width, const int height)
452+{
453+ const int is_sm = angle >> 9;
454+ angle &= 511;
455+ assert(angle < 90);
456+ const int dx = dr_intra_derivative[angle];
457+ pixel top_out[(width + height) * 2];
458+ const pixel *top;
459+ int max_base_x;
460+ const int upsample_above = get_upsample(width + height, 90 - angle, is_sm);
461+ if (upsample_above) {
462+ upsample_edge(top_out, width + height,
463+ &topleft_in[1], -1, width + imin(width, height));
464+ top = top_out;
465+ max_base_x = 2 * (width + height) - 2;
466+ } else {
467+ const int filter_strength =
468+ get_filter_strength(width + height, 90 - angle, is_sm);
469+
470+ if (filter_strength) {
471+ filter_edge(top_out, width + height,
472+ &topleft_in[1], -1, width + imin(width, height),
473+ filter_strength);
474+ top = top_out;
475+ max_base_x = width + height - 1;
476+ } else {
477+ top = &topleft_in[1];
478+ max_base_x = width + imin(width, height) - 1;
479+ }
480+ }
481+ const int frac_bits = 6 - upsample_above;
482+ const int base_inc = 1 << upsample_above;
483+ for (int y = 0, xpos = dx; y < height;
484+ y++, dst += PXSTRIDE(stride), xpos += dx)
485+ {
486+ int base = xpos >> frac_bits;
487+ const int frac = ((xpos << upsample_above) & 0x3F) >> 1;
488+
489+ for (int x = 0; x < width; x++, base += base_inc) {
490+ if (base < max_base_x) {
491+ const int v = top[base] * (32 - frac) + top[base + 1] * frac;
492+ dst[x] = iclip_pixel((v + 16) >> 5);
493+ } else {
494+ pixel_set(&dst[x], top[max_base_x], width - x);
495+ break;
496+ }
497+ }
498+ }
499+}
500+
501+#define z1_lfn(width, height) \
502+static void z1_##width##x##height##_c(pixel *dst, const ptrdiff_t stride, \
503+ const pixel *const topleft, \
504+ const int angle) \
505+{ \
506+ z1_c(dst, stride, topleft, angle, width, height); \
507+}
508+
509+sz_grid(z1_lfn);
510+
511+static __attribute__((noinline)) void
512+z2_c(pixel *dst, const ptrdiff_t stride, const pixel *const topleft_in,
513+ int angle, const int width, const int height)
514+{
515+ const int is_sm = angle >> 9;
516+ angle &= 511;
517+ assert(angle > 90 && angle < 180);
518+ const int dy = dr_intra_derivative[angle - 90];
519+ const int dx = dr_intra_derivative[180 - angle];
520+ const int upsample_left = get_upsample(width + height, 180 - angle, is_sm);
521+ const int upsample_above = get_upsample(width + height, angle - 90, is_sm);
522+ pixel edge[width * 2 + height * 2 + 1];
523+ pixel *const topleft = &edge[height * 2];
524+
525+ if (upsample_above) {
526+ upsample_edge(topleft, width + 1, topleft_in, 0, width + 1);
527+ } else {
528+ const int filter_strength =
529+ get_filter_strength(width + height, angle - 90, is_sm);
530+
531+ if (filter_strength) {
532+ filter_edge(&topleft[1], width, &topleft_in[1], -1, width,
533+ filter_strength);
534+ } else {
535+ pixel_copy(&topleft[1], &topleft_in[1], width);
536+ }
537+ }
538+ if (upsample_left) {
539+ upsample_edge(edge, height + 1, &topleft_in[-height], 0, height + 1);
540+ } else {
541+ const int filter_strength =
542+ get_filter_strength(width + height, 180 - angle, is_sm);
543+
544+ if (filter_strength) {
545+ filter_edge(&topleft[-height], height, &topleft_in[-height],
546+ 0, height + 1, filter_strength);
547+ } else {
548+ pixel_copy(&topleft[-height], &topleft_in[-height], height);
549+ }
550+ }
551+ *topleft = *topleft_in;
552+
553+ const int min_base_x = -(1 << upsample_above);
554+ const int frac_bits_y = 6 - upsample_left, frac_bits_x = 6 - upsample_above;
555+ const int base_inc_x = 1 << upsample_above;
556+ const pixel *const left = &topleft[-(1 << upsample_left)];
557+ const pixel *const top = &topleft[1 << upsample_above];
558+ for (int y = 0, xpos = -dx; y < height;
559+ y++, xpos -= dx, dst += PXSTRIDE(stride))
560+ {
561+ int base_x = xpos >> frac_bits_x;
562+ const int frac_x = ((xpos * (1 << upsample_above)) & 0x3F) >> 1;
563+
564+ for (int x = 0, ypos = (y << 6) - dy; x < width;
565+ x++, base_x += base_inc_x, ypos -= dy)
566+ {
567+ int v;
568+
569+ if (base_x >= min_base_x) {
570+ v = top[base_x] * (32 - frac_x) + top[base_x + 1] * frac_x;
571+ } else {
572+ const int base_y = ypos >> frac_bits_y;
573+ assert(base_y >= -(1 << upsample_left));
574+ const int frac_y = ((ypos * (1 << upsample_left)) & 0x3F) >> 1;
575+ v = left[-base_y] * (32 - frac_y) + left[-(base_y + 1)] * frac_y;
576+ }
577+ dst[x] = iclip_pixel((v + 16) >> 5);
578+ }
579+ }
580+}
581+
582+#define z2_lfn(width, height) \
583+static void z2_##width##x##height##_c(pixel *dst, const ptrdiff_t stride, \
584+ const pixel *const topleft, \
585+ const int angle) \
586+{ \
587+ z2_c(dst, stride, topleft, angle, width, height); \
588+}
589+
590+sz_grid(z2_lfn);
591+
592+static __attribute__((noinline)) void
593+z3_c(pixel *dst, const ptrdiff_t stride, const pixel *const topleft_in,
594+ int angle, const int width, const int height)
595+{
596+ const int is_sm = angle >> 9;
597+ angle &= 511;
598+ assert(angle > 180);
599+ const int dy = dr_intra_derivative[270 - angle];
600+ pixel left_out[(width + height) * 2];
601+ const pixel *left;
602+ int max_base_y;
603+ const int upsample_left = get_upsample(width + height, angle - 180, is_sm);
604+ if (upsample_left) {
605+ upsample_edge(left_out, width + height,
606+ &topleft_in[-(width + height)],
607+ imax(width - height, 0), width + height + 1);
608+ left = &left_out[2 * (width + height) - 2];
609+ max_base_y = 2 * (width + height) - 2;
610+ } else {
611+ const int filter_strength =
612+ get_filter_strength(width + height, angle - 180, is_sm);
613+
614+ if (filter_strength) {
615+ filter_edge(left_out, width + height,
616+ &topleft_in[-(width + height)],
617+ imax(width - height, 0), width + height + 1,
618+ filter_strength);
619+ left = &left_out[width + height - 1];
620+ max_base_y = width + height - 1;
621+ } else {
622+ left = &topleft_in[-1];
623+ max_base_y = height + imin(width, height) - 1;
624+ }
625+ }
626+ const int frac_bits = 6 - upsample_left;
627+ const int base_inc = 1 << upsample_left;
628+ for (int x = 0, ypos = dy; x < width; x++, ypos += dy) {
629+ int base = ypos >> frac_bits;
630+ const int frac = ((ypos << upsample_left) & 0x3F) >> 1;
631+
632+ for (int y = 0; y < height; y++, base += base_inc) {
633+ if (base < max_base_y) {
634+ const int v = left[-base] * (32 - frac) +
635+ left[-(base + 1)] * frac;
636+ dst[y * PXSTRIDE(stride) + x] = iclip_pixel((v + 16) >> 5);
637+ } else {
638+ do {
639+ dst[y * PXSTRIDE(stride) + x] = left[-max_base_y];
640+ } while (++y < height);
641+ break;
642+ }
643+ }
644+ }
645+}
646+
647+#define z3_lfn(width, height) \
648+static void z3_##width##x##height##_c(pixel *dst, const ptrdiff_t stride, \
649+ const pixel *const topleft, \
650+ const int angle) \
651+{ \
652+ z3_c(dst, stride, topleft, angle, width, height); \
653+}
654+
655+sz_grid(z3_lfn);
656+
657+static const int8_t av1_filter_intra_taps[5][8][8] = {
658+ {
659+ { -6, 10, 0, 0, 0, 12, 0, 0 },
660+ { -5, 2, 10, 0, 0, 9, 0, 0 },
661+ { -3, 1, 1, 10, 0, 7, 0, 0 },
662+ { -3, 1, 1, 2, 10, 5, 0, 0 },
663+ { -4, 6, 0, 0, 0, 2, 12, 0 },
664+ { -3, 2, 6, 0, 0, 2, 9, 0 },
665+ { -3, 2, 2, 6, 0, 2, 7, 0 },
666+ { -3, 1, 2, 2, 6, 3, 5, 0 },
667+ }, {
668+ { -10, 16, 0, 0, 0, 10, 0, 0 },
669+ { -6, 0, 16, 0, 0, 6, 0, 0 },
670+ { -4, 0, 0, 16, 0, 4, 0, 0 },
671+ { -2, 0, 0, 0, 16, 2, 0, 0 },
672+ { -10, 16, 0, 0, 0, 0, 10, 0 },
673+ { -6, 0, 16, 0, 0, 0, 6, 0 },
674+ { -4, 0, 0, 16, 0, 0, 4, 0 },
675+ { -2, 0, 0, 0, 16, 0, 2, 0 },
676+ }, {
677+ { -8, 8, 0, 0, 0, 16, 0, 0 },
678+ { -8, 0, 8, 0, 0, 16, 0, 0 },
679+ { -8, 0, 0, 8, 0, 16, 0, 0 },
680+ { -8, 0, 0, 0, 8, 16, 0, 0 },
681+ { -4, 4, 0, 0, 0, 0, 16, 0 },
682+ { -4, 0, 4, 0, 0, 0, 16, 0 },
683+ { -4, 0, 0, 4, 0, 0, 16, 0 },
684+ { -4, 0, 0, 0, 4, 0, 16, 0 },
685+ }, {
686+ { -2, 8, 0, 0, 0, 10, 0, 0 },
687+ { -1, 3, 8, 0, 0, 6, 0, 0 },
688+ { -1, 2, 3, 8, 0, 4, 0, 0 },
689+ { 0, 1, 2, 3, 8, 2, 0, 0 },
690+ { -1, 4, 0, 0, 0, 3, 10, 0 },
691+ { -1, 3, 4, 0, 0, 4, 6, 0 },
692+ { -1, 2, 3, 4, 0, 4, 4, 0 },
693+ { -1, 2, 2, 3, 4, 3, 3, 0 },
694+ }, {
695+ { -12, 14, 0, 0, 0, 14, 0, 0 },
696+ { -10, 0, 14, 0, 0, 12, 0, 0 },
697+ { -9, 0, 0, 14, 0, 11, 0, 0 },
698+ { -8, 0, 0, 0, 14, 10, 0, 0 },
699+ { -10, 12, 0, 0, 0, 0, 14, 0 },
700+ { -9, 1, 12, 0, 0, 0, 12, 0 },
701+ { -8, 0, 0, 12, 0, 1, 11, 0 },
702+ { -7, 0, 0, 1, 12, 1, 9, 0 },
703+ },
704+};
705+
706+static __attribute__((noinline)) void
707+filter_intra_c(pixel *dst, const ptrdiff_t stride,
708+ const pixel *const topleft_in,
709+ int filt_idx, const int width, const int height)
710+{
711+ filt_idx &= 511;
712+ assert(filt_idx < 5);
713+
714+ const int8_t (*const filter)[8] = av1_filter_intra_taps[filt_idx];
715+ int x, y;
716+ ptrdiff_t left_stride;
717+ const pixel *left, *topleft, *top;
718+
719+ top = &topleft_in[1];
720+ for (y = 0; y < height; y += 2) {
721+ topleft = &topleft_in[-y];
722+ left = &topleft[-1];
723+ left_stride = -1;
724+ for (x = 0; x < width; x += 4) {
725+ const int p0 = *topleft;
726+ const int p1 = top[0], p2 = top[1], p3 = top[2], p4 = top[3];
727+ const int p5 = left[0 * left_stride], p6 = left[1 * left_stride];
728+ pixel *ptr = &dst[x];
729+ const int8_t (*flt_ptr)[8] = filter;
730+
731+ for (int yy = 0; yy < 2; yy++) {
732+ for (int xx = 0; xx < 4; xx++, flt_ptr++) {
733+ int acc = flt_ptr[0][0] * p0 + flt_ptr[0][1] * p1 +
734+ flt_ptr[0][2] * p2 + flt_ptr[0][3] * p3 +
735+ flt_ptr[0][4] * p4 + flt_ptr[0][5] * p5 +
736+ flt_ptr[0][6] * p6;
737+ ptr[xx] = iclip_pixel((acc + 8) >> 4);
738+ }
739+ ptr += PXSTRIDE(stride);
740+ }
741+
742+ left = &dst[x + 4 - 1];
743+ left_stride = PXSTRIDE(stride);
744+ top += 4;
745+ topleft = &top[-1];
746+ }
747+ top = &dst[PXSTRIDE(stride)];
748+ dst = &dst[PXSTRIDE(stride) * 2];
749+ }
750+}
751+
752+#define filter_lfn(width, height) \
753+static void filter_##width##x##height##_c(pixel *const dst, \
754+ const ptrdiff_t stride, \
755+ const pixel *const topleft, \
756+ const int filt_idx) \
757+{ \
758+ filter_intra_c(dst, stride, topleft, filt_idx, width, height); \
759+}
760+
761+filter_lfn( 4, 4);
762+filter_lfn( 8, 4);
763+filter_lfn(16, 4);
764+filter_lfn( 4, 8);
765+filter_lfn( 8, 8);
766+filter_lfn(16, 8);
767+filter_lfn(32, 8);
768+filter_lfn( 4, 16);
769+filter_lfn( 8, 16);
770+filter_lfn(16, 16);
771+filter_lfn(32, 16);
772+filter_lfn( 8, 32);
773+filter_lfn(16, 32);
774+filter_lfn(32, 32);
775+
776+static __attribute__((noinline)) void
777+cfl_ac_c(int16_t *ac, const pixel *ypx, const ptrdiff_t stride,
778+ const int w_pad, const int h_pad, const int width, const int height,
779+ const int ss_hor, const int ss_ver, const int log2sz)
780+{
781+ int y, x;
782+ int16_t *const ac_orig = ac;
783+
784+ assert(w_pad >= 0 && w_pad * 4 < width);
785+ assert(h_pad >= 0 && h_pad * 4 < height);
786+
787+ for (y = 0; y < height - 4 * h_pad; y++) {
788+ for (x = 0; x < width - 4 * w_pad; x++) {
789+ int ac_sum = ypx[x << ss_hor];
790+ if (ss_hor) ac_sum += ypx[x * 2 + 1];
791+ if (ss_ver) {
792+ ac_sum += ypx[(x << ss_hor) + PXSTRIDE(stride)];
793+ if (ss_hor) ac_sum += ypx[x * 2 + 1 + PXSTRIDE(stride)];
794+ }
795+ ac[x] = ac_sum << (1 + !ss_ver + !ss_hor);
796+ }
797+ for (; x < width; x++)
798+ ac[x] = ac[x - 1];
799+ ac += width;
800+ ypx += PXSTRIDE(stride) << ss_ver;
801+ }
802+ for (; y < height; y++) {
803+ memcpy(ac, &ac[-32], width * sizeof(*ac));
804+ ac += width;
805+ }
806+
807+ int sum = (1 << log2sz) >> 1;
808+ for (ac = ac_orig, y = 0; y < height; y++) {
809+ for (x = 0; x < width; x++)
810+ sum += ac[x];
811+ ac += width;
812+ }
813+ sum >>= log2sz;
814+
815+ // subtract DC
816+ for (ac = ac_orig, y = 0; y < height; y++) {
817+ for (x = 0; x < width; x++)
818+ ac[x] -= sum;
819+ ac += width;
820+ }
821+}
822+
823+#define cfl_ac_fn(lw, lh, cw, ch, ss_hor, ss_ver, log2sz) \
824+static void cfl_ac_##lw##x##lh##_to_##cw##x##ch##_c(int16_t *const ac, \
825+ const pixel *const ypx, \
826+ const ptrdiff_t stride, \
827+ const int w_pad, \
828+ const int h_pad) \
829+{ \
830+ cfl_ac_c(ac, ypx, stride, w_pad, h_pad, cw, ch, ss_hor, ss_ver, log2sz); \
831+}
832+
833+cfl_ac_fn( 8, 8, 4, 4, 1, 1, 4);
834+cfl_ac_fn( 8, 16, 4, 8, 1, 1, 5);
835+cfl_ac_fn( 8, 32, 4, 16, 1, 1, 6);
836+cfl_ac_fn(16, 8, 8, 4, 1, 1, 5);
837+cfl_ac_fn(16, 16, 8, 8, 1, 1, 6);
838+cfl_ac_fn(16, 32, 8, 16, 1, 1, 7);
839+cfl_ac_fn(32, 8, 16, 4, 1, 1, 6);
840+cfl_ac_fn(32, 16, 16, 8, 1, 1, 7);
841+cfl_ac_fn(32, 32, 16, 16, 1, 1, 8);
842+
843+cfl_ac_fn( 8, 4, 4, 4, 1, 0, 4);
844+cfl_ac_fn( 8, 8, 4, 8, 1, 0, 5);
845+cfl_ac_fn(16, 4, 8, 4, 1, 0, 5);
846+cfl_ac_fn(16, 8, 8, 8, 1, 0, 6);
847+cfl_ac_fn(16, 16, 8, 16, 1, 0, 7);
848+cfl_ac_fn(32, 8, 16, 8, 1, 0, 7);
849+cfl_ac_fn(32, 16, 16, 16, 1, 0, 8);
850+cfl_ac_fn(32, 32, 16, 32, 1, 0, 9);
851+
852+cfl_ac_fn( 4, 4, 4, 4, 0, 0, 4);
853+cfl_ac_fn( 4, 8, 4, 8, 0, 0, 5);
854+cfl_ac_fn( 4, 16, 4, 16, 0, 0, 6);
855+cfl_ac_fn( 8, 4, 8, 4, 0, 0, 5);
856+cfl_ac_fn( 8, 8, 8, 8, 0, 0, 6);
857+cfl_ac_fn( 8, 16, 8, 16, 0, 0, 7);
858+cfl_ac_fn( 8, 32, 8, 32, 0, 0, 8);
859+cfl_ac_fn(16, 4, 16, 4, 0, 0, 6);
860+cfl_ac_fn(16, 8, 16, 8, 0, 0, 7);
861+cfl_ac_fn(16, 16, 16, 16, 0, 0, 8);
862+cfl_ac_fn(16, 32, 16, 32, 0, 0, 9);
863+cfl_ac_fn(32, 8, 32, 8, 0, 0, 8);
864+cfl_ac_fn(32, 16, 32, 16, 0, 0, 9);
865+cfl_ac_fn(32, 32, 32, 32, 0, 0, 10);
866+
867+static __attribute__((noinline)) void
868+cfl_pred_c(pixel *dstU, pixel *dstV, const ptrdiff_t stride,
869+ const int16_t *ac, const pixel *const dc_pred,
870+ const int8_t *const alphas, const int width, const int height)
871+{
872+ for (int y = 0; y < height; y++) {
873+ for (int x = 0; x < width; x++) {
874+ const int diff1 = alphas[0] * ac[x];
875+ dstU[x] = iclip_pixel(dc_pred[ 0] + apply_sign((abs(diff1) + 32) >> 6,
876+ diff1));
877+ const int diff2 = alphas[1] * ac[x];
878+ dstV[x] = iclip_pixel(dc_pred[32] + apply_sign((abs(diff2) + 32) >> 6,
879+ diff2));
880+ }
881+ ac += width;
882+ dstU += PXSTRIDE(stride);
883+ dstV += PXSTRIDE(stride);
884+ }
885+}
886+
887+#define cfl_pred_fn(width) \
888+static void cfl_pred_##width##xN_c(pixel *const dstU, \
889+ pixel *const dstV, \
890+ const ptrdiff_t stride, \
891+ const int16_t *const ac, \
892+ const pixel *const dc_pred, \
893+ const int8_t *const alphas, \
894+ const int height) \
895+{ \
896+ cfl_pred_c(dstU, dstV, stride, ac, dc_pred, alphas, width, height); \
897+}
898+
899+cfl_pred_fn( 4);
900+cfl_pred_fn( 8);
901+cfl_pred_fn(16);
902+cfl_pred_fn(32);
903+
904+static void pal_pred_c(pixel *dst, const ptrdiff_t stride,
905+ const uint16_t *const pal, const uint8_t *idx,
906+ const int w, const int h)
907+{
908+ for (int y = 0; y < h; y++) {
909+ for (int x = 0; x < w; x++)
910+ dst[x] = pal[idx[x]];
911+ idx += w;
912+ dst += PXSTRIDE(stride);
913+ }
914+}
915+
916+void bitfn(dav1d_intra_pred_dsp_init)(Dav1dIntraPredDSPContext *const c) {
917+#define assign_lfn(w, h, p1, p2, pfx) \
918+ c->intra_pred[pfx##TX_##w##X##h][p1##_PRED] = p2##_##w##x##h##_c
919+#define assign_fns(p1, p2) \
920+ assign_lfn( 4, 4, p1, p2,); \
921+ assign_lfn( 4, 8, p1, p2, R); \
922+ assign_lfn( 4, 16, p1, p2, R); \
923+ assign_lfn( 8, 4, p1, p2, R); \
924+ assign_lfn( 8, 8, p1, p2,); \
925+ assign_lfn( 8, 16, p1, p2, R); \
926+ assign_lfn( 8, 32, p1, p2, R); \
927+ assign_lfn(16, 4, p1, p2, R); \
928+ assign_lfn(16, 8, p1, p2, R); \
929+ assign_lfn(16, 16, p1, p2,); \
930+ assign_lfn(16, 32, p1, p2, R); \
931+ assign_lfn(16, 64, p1, p2, R); \
932+ assign_lfn(32, 8, p1, p2, R); \
933+ assign_lfn(32, 16, p1, p2, R); \
934+ assign_lfn(32, 32, p1, p2,); \
935+ assign_lfn(32, 64, p1, p2, R); \
936+ assign_lfn(64, 16, p1, p2, R); \
937+ assign_lfn(64, 32, p1, p2, R); \
938+ assign_lfn(64, 64, p1, p2,); \
939+
940+ assign_fns(DC, dc);
941+ assign_fns(DC_128, dc128);
942+ assign_fns(TOP_DC, dctop);
943+ assign_fns(LEFT_DC, dcleft);
944+ assign_fns(HOR, h);
945+ assign_fns(VERT, v);
946+ assign_fns(PAETH, paeth);
947+ assign_fns(SMOOTH, smooth);
948+ assign_fns(SMOOTH_V, smooth_v);
949+ assign_fns(SMOOTH_H, smooth_h);
950+ assign_fns(Z1, z1);
951+ assign_fns(Z2, z2);
952+ assign_fns(Z3, z3);
953+
954+ assign_lfn( 4, 4, FILTER, filter,);
955+ assign_lfn( 8, 4, FILTER, filter, R);
956+ assign_lfn(16, 4, FILTER, filter, R);
957+ assign_lfn( 4, 8, FILTER, filter, R);
958+ assign_lfn( 8, 8, FILTER, filter,);
959+ assign_lfn(16, 8, FILTER, filter, R);
960+ assign_lfn(32, 8, FILTER, filter, R);
961+ assign_lfn( 4, 16, FILTER, filter, R);
962+ assign_lfn( 8, 16, FILTER, filter, R);
963+ assign_lfn(16, 16, FILTER, filter,);
964+ assign_lfn(32, 16, FILTER, filter, R);
965+ assign_lfn( 8, 32, FILTER, filter, R);
966+ assign_lfn(16, 32, FILTER, filter, R);
967+ assign_lfn(32, 32, FILTER, filter,);
968+
969+ // cfl functions are split per chroma subsampling type
970+ c->cfl_ac[DAV1D_PIXEL_LAYOUT_I420 - 1][ TX_4X4 ] = cfl_ac_8x8_to_4x4_c;
971+ c->cfl_ac[DAV1D_PIXEL_LAYOUT_I420 - 1][RTX_4X8 ] = cfl_ac_8x16_to_4x8_c;
972+ c->cfl_ac[DAV1D_PIXEL_LAYOUT_I420 - 1][RTX_4X16 ] = cfl_ac_8x32_to_4x16_c;
973+ c->cfl_ac[DAV1D_PIXEL_LAYOUT_I420 - 1][RTX_8X4 ] = cfl_ac_16x8_to_8x4_c;
974+ c->cfl_ac[DAV1D_PIXEL_LAYOUT_I420 - 1][ TX_8X8 ] = cfl_ac_16x16_to_8x8_c;
975+ c->cfl_ac[DAV1D_PIXEL_LAYOUT_I420 - 1][RTX_8X16 ] = cfl_ac_16x32_to_8x16_c;
976+ c->cfl_ac[DAV1D_PIXEL_LAYOUT_I420 - 1][RTX_16X4 ] = cfl_ac_32x8_to_16x4_c;
977+ c->cfl_ac[DAV1D_PIXEL_LAYOUT_I420 - 1][RTX_16X8 ] = cfl_ac_32x16_to_16x8_c;
978+ c->cfl_ac[DAV1D_PIXEL_LAYOUT_I420 - 1][ TX_16X16] = cfl_ac_32x32_to_16x16_c;
979+
980+ c->cfl_ac[DAV1D_PIXEL_LAYOUT_I422 - 1][ TX_4X4 ] = cfl_ac_8x4_to_4x4_c;
981+ c->cfl_ac[DAV1D_PIXEL_LAYOUT_I422 - 1][RTX_4X8 ] = cfl_ac_8x8_to_4x8_c;
982+ c->cfl_ac[DAV1D_PIXEL_LAYOUT_I422 - 1][RTX_8X4 ] = cfl_ac_16x4_to_8x4_c;
983+ c->cfl_ac[DAV1D_PIXEL_LAYOUT_I422 - 1][ TX_8X8 ] = cfl_ac_16x8_to_8x8_c;
984+ c->cfl_ac[DAV1D_PIXEL_LAYOUT_I422 - 1][RTX_8X16] = cfl_ac_16x16_to_8x16_c;
985+ c->cfl_ac[DAV1D_PIXEL_LAYOUT_I422 - 1][RTX_16X8 ] = cfl_ac_32x8_to_16x8_c;
986+ c->cfl_ac[DAV1D_PIXEL_LAYOUT_I422 - 1][ TX_16X16] = cfl_ac_32x16_to_16x16_c;
987+ c->cfl_ac[DAV1D_PIXEL_LAYOUT_I422 - 1][RTX_16X32] = cfl_ac_32x32_to_16x32_c;
988+
989+ c->cfl_ac[DAV1D_PIXEL_LAYOUT_I444 - 1][ TX_4X4 ] = cfl_ac_4x4_to_4x4_c;
990+ c->cfl_ac[DAV1D_PIXEL_LAYOUT_I444 - 1][RTX_4X8 ] = cfl_ac_4x8_to_4x8_c;
991+ c->cfl_ac[DAV1D_PIXEL_LAYOUT_I444 - 1][RTX_4X16 ] = cfl_ac_4x16_to_4x16_c;
992+ c->cfl_ac[DAV1D_PIXEL_LAYOUT_I444 - 1][RTX_8X4 ] = cfl_ac_8x4_to_8x4_c;
993+ c->cfl_ac[DAV1D_PIXEL_LAYOUT_I444 - 1][ TX_8X8 ] = cfl_ac_8x8_to_8x8_c;
994+ c->cfl_ac[DAV1D_PIXEL_LAYOUT_I444 - 1][RTX_8X16 ] = cfl_ac_8x16_to_8x16_c;
995+ c->cfl_ac[DAV1D_PIXEL_LAYOUT_I444 - 1][RTX_8X32 ] = cfl_ac_8x32_to_8x32_c;
996+ c->cfl_ac[DAV1D_PIXEL_LAYOUT_I444 - 1][RTX_16X4 ] = cfl_ac_16x4_to_16x4_c;
997+ c->cfl_ac[DAV1D_PIXEL_LAYOUT_I444 - 1][RTX_16X8 ] = cfl_ac_16x8_to_16x8_c;
998+ c->cfl_ac[DAV1D_PIXEL_LAYOUT_I444 - 1][ TX_16X16] = cfl_ac_16x16_to_16x16_c;
999+ c->cfl_ac[DAV1D_PIXEL_LAYOUT_I444 - 1][RTX_16X32] = cfl_ac_16x32_to_16x32_c;
1000+ c->cfl_ac[DAV1D_PIXEL_LAYOUT_I444 - 1][RTX_32X8 ] = cfl_ac_32x8_to_32x8_c;
1001+ c->cfl_ac[DAV1D_PIXEL_LAYOUT_I444 - 1][RTX_32X16] = cfl_ac_32x16_to_32x16_c;
1002+ c->cfl_ac[DAV1D_PIXEL_LAYOUT_I444 - 1][ TX_32X32] = cfl_ac_32x32_to_32x32_c;
1003+
1004+ c->cfl_pred[0] = cfl_pred_4xN_c;
1005+ c->cfl_pred[1] = cfl_pred_8xN_c;
1006+ c->cfl_pred[2] = cfl_pred_16xN_c;
1007+ c->cfl_pred[3] = cfl_pred_32xN_c;
1008+
1009+ c->pal_pred = pal_pred_c;
1010+}
src/ipred.h+92−0
@@ -0,0 +1,92 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __DAV1D_SRC_IPRED_H__
29+#define __DAV1D_SRC_IPRED_H__
30+
31+#include "common/bitdepth.h"
32+
33+#include "src/levels.h"
34+
35+/*
36+ * Intra prediction.
37+ * - a is the angle (in degrees) for directional intra predictors. For other
38+ * modes, it is ignored;
39+ * - topleft is the same as the argument given to dav1d_prepare_intra_edges(),
40+ * see ipred_prepare.h for more detailed documentation.
41+ */
42+#define decl_angular_ipred_fn(name) \
43+void (name)(pixel *dst, ptrdiff_t stride, const pixel *topleft, int angle);
44+typedef decl_angular_ipred_fn(*angular_ipred_fn);
45+
46+/*
47+ * Create a subsampled Y plane with the DC subtracted.
48+ * - w/h_pad is the edge of the width/height that extends outside the visible
49+ * portion of the frame in 4px units;
50+ * - ac has a stride of 16.
51+ */
52+#define decl_cfl_ac_fn(name) \
53+void (name)(int16_t *ac, const pixel *y, ptrdiff_t stride, \
54+ int w_pad, int h_pad)
55+typedef decl_cfl_ac_fn(*cfl_ac_fn);
56+
57+/*
58+ * dst[plane][x,y] = dc[plane] + alpha[plane] * ac[x,y]
59+ * - alphas contains two q3 scalars (one for each plane) in [-16,16] range;
60+ * - dc_pred[] is the first line of each plane's DC prediction, the second plane
61+ * starting at an offset of 16 * sizeof(pixel) bytes.
62+ */
63+#define decl_cfl_pred_fn(name) \
64+void (name)(pixel *u_dst, pixel *v_dst, ptrdiff_t stride, \
65+ const int16_t *ac, const pixel *dc_pred, \
66+ const int8_t *const alphas, const int height)
67+typedef decl_cfl_pred_fn(*cfl_pred_fn);
68+
69+/*
70+ * dst[x,y] = pal[idx[x,y]]
71+ * - palette indices are [0-7]
72+ */
73+#define decl_pal_pred_fn(name) \
74+void (name)(pixel *dst, ptrdiff_t stride, const uint16_t *pal, \
75+ const uint8_t *idx, const int w, const int h)
76+typedef decl_pal_pred_fn(*pal_pred_fn);
77+
78+typedef struct Dav1dIntraPredDSPContext {
79+ angular_ipred_fn intra_pred[N_RECT_TX_SIZES][N_IMPL_INTRA_PRED_MODES];
80+
81+ // chroma-from-luma
82+ cfl_ac_fn cfl_ac[3 /* 420, 422, 444 */][N_RECT_TX_SIZES /* chroma tx size */];
83+ cfl_pred_fn cfl_pred[4];
84+
85+ // palette
86+ pal_pred_fn pal_pred;
87+} Dav1dIntraPredDSPContext;
88+
89+void dav1d_intra_pred_dsp_init_8bpc(Dav1dIntraPredDSPContext *c);
90+void dav1d_intra_pred_dsp_init_10bpc(Dav1dIntraPredDSPContext *c);
91+
92+#endif /* __DAV1D_SRC_IPRED_H__ */
src/ipred_prepare.c+209−0
@@ -0,0 +1,209 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#include "config.h"
29+
30+#include <assert.h>
31+#include <stdint.h>
32+#include <string.h>
33+
34+#include "common/intops.h"
35+
36+#include "src/ipred_prepare.h"
37+
38+static const uint8_t av1_mode_conv[N_INTRA_PRED_MODES]
39+ [2 /* have_left */][2 /* have_top */] =
40+{
41+ [DC_PRED] = { { DC_128_PRED, TOP_DC_PRED },
42+ { LEFT_DC_PRED, DC_PRED } },
43+ [PAETH_PRED] = { { DC_128_PRED, VERT_PRED },
44+ { HOR_PRED, PAETH_PRED } },
45+};
46+
47+static const uint8_t av1_mode_to_angle_map[8] = {
48+ 90, 180, 45, 135, 113, 157, 203, 67
49+};
50+
51+static const struct {
52+ uint8_t needs_left:1;
53+ uint8_t needs_top:1;
54+ uint8_t needs_topleft:1;
55+ uint8_t needs_topright:1;
56+ uint8_t needs_bottomleft:1;
57+} av1_intra_prediction_edges[N_IMPL_INTRA_PRED_MODES] = {
58+ [DC_PRED] = { .needs_top = 1, .needs_left = 1 },
59+ [VERT_PRED] = { .needs_top = 1 },
60+ [HOR_PRED] = { .needs_left = 1 },
61+ [LEFT_DC_PRED] = { .needs_left = 1 },
62+ [TOP_DC_PRED] = { .needs_top = 1 },
63+ [DC_128_PRED] = { 0 },
64+ [Z1_PRED] = { .needs_top = 1, .needs_topright = 1,
65+ .needs_topleft = 1 },
66+ [Z2_PRED] = { .needs_left = 1, .needs_top = 1, .needs_topleft = 1 },
67+ [Z3_PRED] = { .needs_left = 1, .needs_bottomleft = 1,
68+ .needs_topleft = 1 },
69+ [SMOOTH_PRED] = { .needs_left = 1, .needs_top = 1 },
70+ [SMOOTH_V_PRED] = { .needs_left = 1, .needs_top = 1 },
71+ [SMOOTH_H_PRED] = { .needs_left = 1, .needs_top = 1 },
72+ [PAETH_PRED] = { .needs_left = 1, .needs_top = 1, .needs_topleft = 1 },
73+ [FILTER_PRED] = { .needs_left = 1, .needs_top = 1, .needs_topleft = 1 },
74+};
75+
76+enum IntraPredMode
77+bytefn(prepare_intra_edges)(const int x, const int have_left,
78+ const int y, const int have_top,
79+ const int w, const int h,
80+ const enum EdgeFlags edge_flags,
81+ const pixel *const dst,
82+ const ptrdiff_t stride,
83+ const pixel *prefilter_toplevel_sb_edge,
84+ enum IntraPredMode mode, int *const angle,
85+ const int tw, const int th,
86+ pixel *const topleft_out)
87+{
88+ assert(y < h && x < w);
89+
90+ switch (mode) {
91+ case VERT_PRED:
92+ case HOR_PRED:
93+ case DIAG_DOWN_LEFT_PRED:
94+ case DIAG_DOWN_RIGHT_PRED:
95+ case VERT_RIGHT_PRED:
96+ case HOR_DOWN_PRED:
97+ case HOR_UP_PRED:
98+ case VERT_LEFT_PRED: {
99+ *angle = av1_mode_to_angle_map[mode - VERT_PRED] + 3 * *angle;
100+
101+ if (*angle < 90) {
102+ mode = have_top ? Z1_PRED : VERT_PRED;
103+ } else if (*angle == 90) {
104+ mode = VERT_PRED;
105+ } else if (*angle < 180) {
106+ mode = Z2_PRED;
107+ } else if (*angle == 180) {
108+ mode = HOR_PRED;
109+ } else {
110+ mode = have_left ? Z3_PRED : HOR_PRED;
111+ }
112+ break;
113+ }
114+ case DC_PRED:
115+ case PAETH_PRED:
116+ mode = av1_mode_conv[mode][have_left][have_top];
117+ break;
118+ default:
119+ break;
120+ }
121+
122+ const pixel *dst_top;
123+ if (have_top &&
124+ (av1_intra_prediction_edges[mode].needs_top ||
125+ av1_intra_prediction_edges[mode].needs_topleft ||
126+ (av1_intra_prediction_edges[mode].needs_left && !have_left)))
127+ {
128+ if (prefilter_toplevel_sb_edge) {
129+ dst_top = &prefilter_toplevel_sb_edge[x * 4];
130+ } else {
131+ dst_top = &dst[-PXSTRIDE(stride)];
132+ }
133+ }
134+
135+ if (av1_intra_prediction_edges[mode].needs_left) {
136+ const int sz = th << 2;
137+ pixel *const left = &topleft_out[-sz];
138+
139+ if (have_left) {
140+ const int px_have = imin(sz, (h - y) << 2);
141+
142+ for (int i = 0; i < px_have; i++)
143+ left[sz - 1 - i] = dst[PXSTRIDE(stride) * i - 1];
144+ if (px_have < sz)
145+ pixel_set(left, left[sz - px_have], sz - px_have);
146+ } else {
147+ pixel_set(left, have_top ? *dst_top : ((1 << BITDEPTH) >> 1) + 1, sz);
148+ }
149+
150+ if (av1_intra_prediction_edges[mode].needs_bottomleft) {
151+ const int have_bottomleft = (!have_left || y + th >= h) ? 0 :
152+ (edge_flags & EDGE_I444_LEFT_HAS_BOTTOM);
153+
154+ if (have_bottomleft) {
155+ const int px_have = imin(sz, (h - y - th) << 2);
156+
157+ for (int i = 0; i < px_have; i++)
158+ left[-(i + 1)] = dst[(sz + i) * PXSTRIDE(stride) - 1];
159+ if (px_have < sz)
160+ pixel_set(left - sz, left[-px_have], sz - px_have);
161+ } else {
162+ pixel_set(left - sz, left[0], sz);
163+ }
164+ }
165+ }
166+
167+ if (av1_intra_prediction_edges[mode].needs_top) {
168+ const int sz = tw << 2;
169+ pixel *const top = &topleft_out[1];
170+
171+ if (have_top) {
172+ const int px_have = imin(sz, (w - x) << 2);
173+ pixel_copy(top, dst_top, px_have);
174+ if (px_have < sz)
175+ pixel_set(top + px_have, top[px_have - 1], sz - px_have);
176+ } else {
177+ pixel_set(top, have_left ? dst[-1] : ((1 << BITDEPTH) >> 1) - 1, sz);
178+ }
179+
180+ if (av1_intra_prediction_edges[mode].needs_topright) {
181+ const int have_topright = (!have_top || x + tw >= w) ? 0 :
182+ (edge_flags & EDGE_I444_TOP_HAS_RIGHT);
183+
184+ if (have_topright) {
185+ const int px_have = imin(sz, (w - x - tw) << 2);
186+
187+ pixel_copy(top + sz, &dst_top[sz], px_have);
188+ if (px_have < sz)
189+ pixel_set(top + sz + px_have, top[sz + px_have - 1],
190+ sz - px_have);
191+ } else {
192+ pixel_set(top + sz, top[sz - 1], sz);
193+ }
194+ }
195+ }
196+
197+ if (av1_intra_prediction_edges[mode].needs_topleft) {
198+ if (have_left) {
199+ *topleft_out = have_top ? dst_top[-1] : dst[-1];
200+ } else {
201+ *topleft_out = have_top ? *dst_top : (1 << BITDEPTH) >> 1;
202+ }
203+ if (mode == Z2_PRED && tw + th >= 6)
204+ *topleft_out = (topleft_out[-1] * 5 + topleft_out[0] * 6 +
205+ topleft_out[1] * 5 + 8) >> 4;
206+ }
207+
208+ return mode;
209+}
src/ipred_prepare.h+102−0
@@ -0,0 +1,102 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __DAV1D_SRC_IPRED_PREPARE_H__
29+#define __DAV1D_SRC_IPRED_PREPARE_H__
30+
31+#include <stddef.h>
32+#include <stdint.h>
33+
34+#include "common/bitdepth.h"
35+
36+#include "src/env.h"
37+#include "src/intra_edge.h"
38+#include "src/levels.h"
39+
40+/*
41+ * Luma intra edge preparation.
42+ *
43+ * x/y/start/w/h are in luma block (4px) units:
44+ * - x and y are the absolute block positions in the image;
45+ * - start/w/h are the *dependent tile* boundary positions. In practice, start
46+ * is the horizontal tile start, w is the horizontal tile end, the vertical
47+ * tile start is assumed to be 0 and h is the vertical image end.
48+ *
49+ * edge_flags signals which edges are available for this transform-block inside
50+ * the given partition, as well as for the partition inside the superblock
51+ * structure.
52+ *
53+ * dst and stride are pointers to the top/left position of the current block,
54+ * and can be used to locate the top, left, top/left, top/right and bottom/left
55+ * edge pointers also.
56+ *
57+ * angle is the angle_delta [-3..3] on input, and the absolute angle on output.
58+ *
59+ * mode is the intra prediction mode as coded in the bitstream. The return value
60+ * is this same mode, converted to an index in the DSP functions.
61+ *
62+ * tw/th are the size of the transform block in block (4px) units.
63+ *
64+ * topleft_out is a pointer to scratch memory that will be filled with the edge
65+ * pixels. The memory array should have space to be indexed in the [-2*w,2*w]
66+ * range, in the following order:
67+ * - [0] will be the top/left edge pixel;
68+ * - [1..w] will be the top edge pixels (1 being left-most, w being right-most);
69+ * - [w+1..w*w] will be the top/right edge pixels;
70+ * - [-1..-w] will be the left edge pixels (-1 being top-most, -w being bottom-
71+ * most);
72+ * - [-w-1..-2*w] will be the bottom/left edge pixels.
73+ * Each edge may remain uninitialized if it is not used by the returned mode
74+ * index. If edges are not available (because the edge position is outside the
75+ * tile dimensions or because edge_flags indicates lack of edge availability),
76+ * they will be extended from nearby edges as defined by the av1 spec.
77+ */
78+enum IntraPredMode
79+ bytefn(prepare_intra_edges)(int x, int have_left, int y, int have_top,
80+ int w, int h, enum EdgeFlags edge_flags,
81+ const pixel *dst, ptrdiff_t stride,
82+ const pixel *prefilter_toplevel_sb_edge,
83+ enum IntraPredMode mode, int *angle,
84+ int tw, int th, pixel *topleft_out);
85+
86+// is or'ed with the angle argument into intra predictors to signal that edges
87+// are smooth and should use reduced filter strength
88+#define ANGLE_SMOOTH_EDGE_FLAG 512
89+static inline int sm_flag(const BlockContext *const b, const int idx) {
90+ if (!b->intra[idx]) return 0;
91+ const enum IntraPredMode m = b->mode[idx];
92+ return (m == SMOOTH_PRED || m == SMOOTH_H_PRED ||
93+ m == SMOOTH_V_PRED) ? ANGLE_SMOOTH_EDGE_FLAG : 0;
94+}
95+
96+static inline int sm_uv_flag(const BlockContext *const b, const int idx) {
97+ const enum IntraPredMode m = b->uvmode[idx];
98+ return (m == SMOOTH_PRED || m == SMOOTH_H_PRED ||
99+ m == SMOOTH_V_PRED) ? ANGLE_SMOOTH_EDGE_FLAG : 0;
100+}
101+
102+#endif /* __DAV1D_SRC_IPRED_PREPARE_H__ */
src/itx.c+224−0
@@ -0,0 +1,224 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#include "config.h"
29+
30+#include <assert.h>
31+#include <stddef.h>
32+#include <stdint.h>
33+#include <string.h>
34+
35+#include "common/intops.h"
36+
37+#include "src/itx.h"
38+
39+#include "src/itx_1d.c"
40+
41+typedef void (*itx_1d_fn)(const coef *in, ptrdiff_t in_s,
42+ coef *out, ptrdiff_t out_s);
43+
44+static void __attribute__((noinline))
45+inv_txfm_add_c(pixel *dst, const ptrdiff_t stride,
46+ coef *const coeff, const int eob,
47+ const int w, const int h, const int shift1, const int shift2,
48+ const itx_1d_fn first_1d_fn, const itx_1d_fn second_1d_fn)
49+{
50+ int i, j;
51+ const ptrdiff_t sh = imin(h, 32), sw = imin(w, 32);
52+ coef tmp[w * h], out[h], in_mem[w];
53+ const int is_rect2 = w * 2 == h || h * 2 == w;
54+
55+ if (w != sw) memset(&in_mem[sw], 0, (w - sw) * sizeof(*in_mem));
56+ const int rnd1 = (1 << shift1) >> 1;
57+ for (i = 0; i < sh; i++) {
58+ if (w != sw || is_rect2) {
59+ for (j = 0; j < sw; j++) {
60+ in_mem[j] = coeff[i + j * sh];
61+ if (is_rect2)
62+ in_mem[j] = (in_mem[j] * 2896 + 2048) >> 12;
63+ }
64+ first_1d_fn(in_mem, 1, &tmp[i * w], 1);
65+ } else {
66+ first_1d_fn(&coeff[i], sh, &tmp[i * w], 1);
67+ }
68+ for (j = 0; j < w; j++)
69+ tmp[i * w + j] = (tmp[i * w + j] + (rnd1)) >> shift1;
70+ }
71+
72+ if (h != sh) memset(&tmp[sh * w], 0, w * (h - sh) * sizeof(*tmp));
73+ const int rnd2 = (1 << shift2) >> 1;
74+ for (i = 0; i < w; i++) {
75+ second_1d_fn(&tmp[i], w, out, 1);
76+ for (j = 0; j < h; j++)
77+ dst[i + j * PXSTRIDE(stride)] =
78+ iclip_pixel(dst[i + j * PXSTRIDE(stride)] +
79+ ((out[j] + (rnd2)) >> shift2));
80+ }
81+ memset(coeff, 0, sizeof(*coeff) * sh * sw);
82+}
83+
84+#define inv_txfm_fn(type1, type2, w, h, shift1, shift2) \
85+static void \
86+inv_txfm_add_##type1##_##type2##_##w##x##h##_c(pixel *dst, \
87+ const ptrdiff_t stride, \
88+ coef *const coeff, \
89+ const int eob) \
90+{ \
91+ inv_txfm_add_c(dst, stride, coeff, eob, w, h, shift1, shift2, \
92+ inv_##type1##w##_1d, inv_##type2##h##_1d); \
93+}
94+
95+#define inv_txfm_fn64(w, h, shift1, shift2) \
96+inv_txfm_fn(dct, dct, w, h, shift1, shift2)
97+
98+#define inv_txfm_fn32(w, h, shift1, shift2) \
99+inv_txfm_fn64(w, h, shift1, shift2); \
100+inv_txfm_fn(identity, identity, w, h, shift1, shift2)
101+
102+#define inv_txfm_fn16(w, h, shift1, shift2) \
103+inv_txfm_fn32(w, h, shift1, shift2); \
104+inv_txfm_fn(adst, dct, w, h, shift1, shift2); \
105+inv_txfm_fn(dct, adst, w, h, shift1, shift2); \
106+inv_txfm_fn(adst, adst, w, h, shift1, shift2); \
107+inv_txfm_fn(dct, flipadst, w, h, shift1, shift2); \
108+inv_txfm_fn(flipadst, dct, w, h, shift1, shift2); \
109+inv_txfm_fn(adst, flipadst, w, h, shift1, shift2); \
110+inv_txfm_fn(flipadst, adst, w, h, shift1, shift2); \
111+inv_txfm_fn(flipadst, flipadst, w, h, shift1, shift2); \
112+inv_txfm_fn(identity, dct, w, h, shift1, shift2); \
113+inv_txfm_fn(dct, identity, w, h, shift1, shift2); \
114+
115+#define inv_txfm_fn84(w, h, shift1, shift2) \
116+inv_txfm_fn16(w, h, shift1, shift2); \
117+inv_txfm_fn(identity, flipadst, w, h, shift1, shift2); \
118+inv_txfm_fn(flipadst, identity, w, h, shift1, shift2); \
119+inv_txfm_fn(identity, adst, w, h, shift1, shift2); \
120+inv_txfm_fn(adst, identity, w, h, shift1, shift2); \
121+
122+inv_txfm_fn84( 4, 4, 0, 4);
123+inv_txfm_fn84( 4, 8, 0, 4);
124+inv_txfm_fn84( 4, 16, 1, 4);
125+inv_txfm_fn84( 8, 4, 0, 4);
126+inv_txfm_fn84( 8, 8, 1, 4);
127+inv_txfm_fn84( 8, 16, 1, 4);
128+inv_txfm_fn32( 8, 32, 2, 4);
129+inv_txfm_fn84(16, 4, 1, 4);
130+inv_txfm_fn84(16, 8, 1, 4);
131+inv_txfm_fn16(16, 16, 2, 4);
132+inv_txfm_fn32(16, 32, 1, 4);
133+inv_txfm_fn64(16, 64, 2, 4);
134+inv_txfm_fn32(32, 8, 2, 4);
135+inv_txfm_fn32(32, 16, 1, 4);
136+inv_txfm_fn32(32, 32, 2, 4);
137+inv_txfm_fn64(32, 64, 1, 4);
138+inv_txfm_fn64(64, 16, 2, 4);
139+inv_txfm_fn64(64, 32, 1, 4);
140+inv_txfm_fn64(64, 64, 2, 4);
141+
142+static void inv_txfm_add_wht_wht_4x4_c(pixel *dst, const ptrdiff_t stride,
143+ coef *const coeff, const int eob)
144+{
145+ int i, j;
146+ coef tmp[4 * 4], out[4];
147+
148+ for (i = 0; i < 4; i++)
149+ inv_wht4_1d(&coeff[i], 4, &tmp[i * 4], 1, 0);
150+
151+ for (i = 0; i < 4; i++) {
152+ inv_wht4_1d(&tmp[i], 4, out, 1, 1);
153+ for (j = 0; j < 4; j++)
154+ dst[i + j * PXSTRIDE(stride)] =
155+ iclip_pixel(dst[i + j * PXSTRIDE(stride)] + out[j]);
156+ }
157+ memset(coeff, 0, sizeof(*coeff) * 4 * 4);
158+}
159+
160+void bitfn(dav1d_itx_dsp_init)(Dav1dInvTxfmDSPContext *const c) {
161+#define assign_itx_all_fn64(w, h, pfx) \
162+ c->itxfm_add[pfx##TX_##w##X##h][DCT_DCT ] = \
163+ inv_txfm_add_dct_dct_##w##x##h##_c
164+
165+#define assign_itx_all_fn32(w, h, pfx) \
166+ assign_itx_all_fn64(w, h, pfx); \
167+ c->itxfm_add[pfx##TX_##w##X##h][IDTX] = \
168+ inv_txfm_add_identity_identity_##w##x##h##_c
169+
170+#define assign_itx_all_fn16(w, h, pfx) \
171+ assign_itx_all_fn32(w, h, pfx); \
172+ c->itxfm_add[pfx##TX_##w##X##h][DCT_ADST ] = \
173+ inv_txfm_add_adst_dct_##w##x##h##_c; \
174+ c->itxfm_add[pfx##TX_##w##X##h][ADST_DCT ] = \
175+ inv_txfm_add_dct_adst_##w##x##h##_c; \
176+ c->itxfm_add[pfx##TX_##w##X##h][ADST_ADST] = \
177+ inv_txfm_add_adst_adst_##w##x##h##_c; \
178+ c->itxfm_add[pfx##TX_##w##X##h][ADST_FLIPADST] = \
179+ inv_txfm_add_flipadst_adst_##w##x##h##_c; \
180+ c->itxfm_add[pfx##TX_##w##X##h][FLIPADST_ADST] = \
181+ inv_txfm_add_adst_flipadst_##w##x##h##_c; \
182+ c->itxfm_add[pfx##TX_##w##X##h][DCT_FLIPADST] = \
183+ inv_txfm_add_flipadst_dct_##w##x##h##_c; \
184+ c->itxfm_add[pfx##TX_##w##X##h][FLIPADST_DCT] = \
185+ inv_txfm_add_dct_flipadst_##w##x##h##_c; \
186+ c->itxfm_add[pfx##TX_##w##X##h][FLIPADST_FLIPADST] = \
187+ inv_txfm_add_flipadst_flipadst_##w##x##h##_c; \
188+ c->itxfm_add[pfx##TX_##w##X##h][H_DCT] = \
189+ inv_txfm_add_dct_identity_##w##x##h##_c; \
190+ c->itxfm_add[pfx##TX_##w##X##h][V_DCT] = \
191+ inv_txfm_add_identity_dct_##w##x##h##_c
192+
193+#define assign_itx_all_fn84(w, h, pfx) \
194+ assign_itx_all_fn16(w, h, pfx); \
195+ c->itxfm_add[pfx##TX_##w##X##h][H_FLIPADST] = \
196+ inv_txfm_add_flipadst_identity_##w##x##h##_c; \
197+ c->itxfm_add[pfx##TX_##w##X##h][V_FLIPADST] = \
198+ inv_txfm_add_identity_flipadst_##w##x##h##_c; \
199+ c->itxfm_add[pfx##TX_##w##X##h][H_ADST] = \
200+ inv_txfm_add_adst_identity_##w##x##h##_c; \
201+ c->itxfm_add[pfx##TX_##w##X##h][V_ADST] = \
202+ inv_txfm_add_identity_adst_##w##x##h##_c; \
203+
204+ c->itxfm_add[TX_4X4][WHT_WHT] = inv_txfm_add_wht_wht_4x4_c;
205+ assign_itx_all_fn84( 4, 4, );
206+ assign_itx_all_fn84( 4, 8, R);
207+ assign_itx_all_fn84( 4, 16, R);
208+ assign_itx_all_fn84( 8, 4, R);
209+ assign_itx_all_fn84( 8, 8, );
210+ assign_itx_all_fn84( 8, 16, R);
211+ assign_itx_all_fn32( 8, 32, R);
212+ assign_itx_all_fn84(16, 4, R);
213+ assign_itx_all_fn84(16, 8, R);
214+ assign_itx_all_fn16(16, 16, );
215+ assign_itx_all_fn32(16, 32, R);
216+ assign_itx_all_fn64(16, 64, R);
217+ assign_itx_all_fn32(32, 8, R);
218+ assign_itx_all_fn32(32, 16, R);
219+ assign_itx_all_fn32(32, 32, );
220+ assign_itx_all_fn64(32, 64, R);
221+ assign_itx_all_fn64(64, 16, R);
222+ assign_itx_all_fn64(64, 32, R);
223+ assign_itx_all_fn64(64, 64, );
224+}
src/itx.h+46−0
@@ -0,0 +1,46 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __DAV1D_SRC_ITX_H__
29+#define __DAV1D_SRC_ITX_H__
30+
31+#include "common/bitdepth.h"
32+
33+#include "src/levels.h"
34+
35+#define decl_itx_fn(name) \
36+void (name)(pixel *dst, ptrdiff_t dst_stride, coef *coeff, int eob)
37+typedef decl_itx_fn(*itxfm_fn);
38+
39+typedef struct Dav1dInvTxfmDSPContext {
40+ itxfm_fn itxfm_add[N_RECT_TX_SIZES][N_TX_TYPES_PLUS_LL];
41+} Dav1dInvTxfmDSPContext;
42+
43+void dav1d_itx_dsp_init_8bpc(Dav1dInvTxfmDSPContext *c);
44+void dav1d_itx_dsp_init_10bpc(Dav1dInvTxfmDSPContext *c);
45+
46+#endif /* __DAV1D_SRC_ITX_H__ */
src/itx_1d.c+861−0
@@ -0,0 +1,861 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#include "config.h"
29+
30+#include <stddef.h>
31+#include <stdint.h>
32+
33+static void __attribute__((noinline))
34+inv_dct4_1d(const coef *const in, const ptrdiff_t in_s,
35+ coef *const out, const ptrdiff_t out_s)
36+{
37+ const int in0 = in[0 * in_s], in1 = in[1 * in_s];
38+ const int in2 = in[2 * in_s], in3 = in[3 * in_s];
39+
40+ int t0 = ((in0 + in2) * 2896 + 2048) >> 12;
41+ int t1 = ((in0 - in2) * 2896 + 2048) >> 12;
42+ int t2 = (in1 * 1567 - in3 * 3784 + 2048) >> 12;
43+ int t3 = (in1 * 3784 + in3 * 1567 + 2048) >> 12;
44+
45+ out[0 * out_s] = t0 + t3;
46+ out[1 * out_s] = t1 + t2;
47+ out[2 * out_s] = t1 - t2;
48+ out[3 * out_s] = t0 - t3;
49+}
50+
51+static void __attribute__((noinline))
52+inv_dct8_1d(const coef *const in, const ptrdiff_t in_s,
53+ coef *const out, const ptrdiff_t out_s)
54+{
55+ coef tmp[4];
56+
57+ inv_dct4_1d(in, in_s * 2, tmp, 1);
58+
59+ const int in1 = in[1 * in_s], in3 = in[3 * in_s];
60+ const int in5 = in[5 * in_s], in7 = in[7 * in_s];
61+
62+ int t4a = (in1 * 799 - in7 * 4017 + 2048) >> 12;
63+ int t5a = (in5 * 3406 - in3 * 2276 + 2048) >> 12;
64+ int t6a = (in5 * 2276 + in3 * 3406 + 2048) >> 12;
65+ int t7a = (in1 * 4017 + in7 * 799 + 2048) >> 12;
66+
67+ int t4 = t4a + t5a;
68+ t5a = t4a - t5a;
69+ int t7 = t7a + t6a;
70+ t6a = t7a - t6a;
71+
72+ int t5 = ((t6a - t5a) * 2896 + 2048) >> 12;
73+ int t6 = ((t6a + t5a) * 2896 + 2048) >> 12;
74+
75+ out[0 * out_s] = tmp[0] + t7;
76+ out[1 * out_s] = tmp[1] + t6;
77+ out[2 * out_s] = tmp[2] + t5;
78+ out[3 * out_s] = tmp[3] + t4;
79+ out[4 * out_s] = tmp[3] - t4;
80+ out[5 * out_s] = tmp[2] - t5;
81+ out[6 * out_s] = tmp[1] - t6;
82+ out[7 * out_s] = tmp[0] - t7;
83+}
84+
85+static void __attribute__((noinline))
86+inv_dct16_1d(const coef *const in, const ptrdiff_t in_s,
87+ coef *const out, const ptrdiff_t out_s)
88+{
89+ coef tmp[8];
90+
91+ inv_dct8_1d(in, in_s * 2, tmp, 1);
92+
93+ const int in1 = in[ 1 * in_s], in3 = in[ 3 * in_s];
94+ const int in5 = in[ 5 * in_s], in7 = in[ 7 * in_s];
95+ const int in9 = in[ 9 * in_s], in11 = in[11 * in_s];
96+ const int in13 = in[13 * in_s], in15 = in[15 * in_s];
97+
98+ int t8a = (in1 * 401 - in15 * 4076 + 2048) >> 12;
99+ int t15a = (in1 * 4076 + in15 * 401 + 2048) >> 12;
100+ int t9a = (in9 * 3166 - in7 * 2598 + 2048) >> 12;
101+ int t14a = (in9 * 2598 + in7 * 3166 + 2048) >> 12;
102+ int t10a = (in5 * 1931 - in11 * 3612 + 2048) >> 12;
103+ int t13a = (in5 * 3612 + in11 * 1931 + 2048) >> 12;
104+ int t11a = (in13 * 3920 - in3 * 1189 + 2048) >> 12;
105+ int t12a = (in13 * 1189 + in3 * 3920 + 2048) >> 12;
106+
107+ int t8 = t8a + t9a;
108+ int t9 = t8a - t9a;
109+ int t10 = t11a - t10a;
110+ int t11 = t11a + t10a;
111+ int t12 = t12a + t13a;
112+ int t13 = t12a - t13a;
113+ int t14 = t15a - t14a;
114+ int t15 = t15a + t14a;
115+
116+ t9a = ( t14 * 1567 - t9 * 3784 + 2048) >> 12;
117+ t14a = ( t14 * 3784 + t9 * 1567 + 2048) >> 12;
118+ t10a = (-(t13 * 3784 + t10 * 1567) + 2048) >> 12;
119+ t13a = ( t13 * 1567 - t10 * 3784 + 2048) >> 12;
120+
121+ t8a = t8 + t11;
122+ t9 = t9a + t10a;
123+ t10 = t9a - t10a;
124+ t11a = t8 - t11;
125+ t12a = t15 - t12;
126+ t13 = t14a - t13a;
127+ t14 = t14a + t13a;
128+ t15a = t15 + t12;
129+
130+ t10a = ((t13 - t10) * 2896 + 2048) >> 12;
131+ t13a = ((t13 + t10) * 2896 + 2048) >> 12;
132+ t11 = ((t12a - t11a) * 2896 + 2048) >> 12;
133+ t12 = ((t12a + t11a) * 2896 + 2048) >> 12;
134+
135+ out[ 0 * out_s] = tmp[0] + t15a;
136+ out[ 1 * out_s] = tmp[1] + t14;
137+ out[ 2 * out_s] = tmp[2] + t13a;
138+ out[ 3 * out_s] = tmp[3] + t12;
139+ out[ 4 * out_s] = tmp[4] + t11;
140+ out[ 5 * out_s] = tmp[5] + t10a;
141+ out[ 6 * out_s] = tmp[6] + t9;
142+ out[ 7 * out_s] = tmp[7] + t8a;
143+ out[ 8 * out_s] = tmp[7] - t8a;
144+ out[ 9 * out_s] = tmp[6] - t9;
145+ out[10 * out_s] = tmp[5] - t10a;
146+ out[11 * out_s] = tmp[4] - t11;
147+ out[12 * out_s] = tmp[3] - t12;
148+ out[13 * out_s] = tmp[2] - t13a;
149+ out[14 * out_s] = tmp[1] - t14;
150+ out[15 * out_s] = tmp[0] - t15a;
151+}
152+
153+static void __attribute__((noinline))
154+inv_dct32_1d(const coef *const in, const ptrdiff_t in_s,
155+ coef *const out, const ptrdiff_t out_s)
156+{
157+ coef tmp[16];
158+
159+ inv_dct16_1d(in, in_s * 2, tmp, 1);
160+
161+ const int in1 = in[ 1 * in_s], in3 = in[ 3 * in_s];
162+ const int in5 = in[ 5 * in_s], in7 = in[ 7 * in_s];
163+ const int in9 = in[ 9 * in_s], in11 = in[11 * in_s];
164+ const int in13 = in[13 * in_s], in15 = in[15 * in_s];
165+ const int in17 = in[17 * in_s], in19 = in[19 * in_s];
166+ const int in21 = in[21 * in_s], in23 = in[23 * in_s];
167+ const int in25 = in[25 * in_s], in27 = in[27 * in_s];
168+ const int in29 = in[29 * in_s], in31 = in[31 * in_s];
169+
170+ int t16a = (in1 * 201 - in31 * 4091 + 2048) >> 12;
171+ int t31a = (in1 * 4091 + in31 * 201 + 2048) >> 12;
172+ int t17a = (in17 * 3035 - in15 * 2751 + 2048) >> 12;
173+ int t30a = (in17 * 2751 + in15 * 3035 + 2048) >> 12;
174+ int t18a = (in9 * 1751 - in23 * 3703 + 2048) >> 12;
175+ int t29a = (in9 * 3703 + in23 * 1751 + 2048) >> 12;
176+ int t19a = (in25 * 3857 - in7 * 1380 + 2048) >> 12;
177+ int t28a = (in25 * 1380 + in7 * 3857 + 2048) >> 12;
178+ int t20a = (in5 * 995 - in27 * 3973 + 2048) >> 12;
179+ int t27a = (in5 * 3973 + in27 * 995 + 2048) >> 12;
180+ int t21a = (in21 * 3513 - in11 * 2106 + 2048) >> 12;
181+ int t26a = (in21 * 2106 + in11 * 3513 + 2048) >> 12;
182+ int t22a = (in13 * 2440 - in19 * 3290 + 2048) >> 12;
183+ int t25a = (in13 * 3290 + in19 * 2440 + 2048) >> 12;
184+ int t23a = (in29 * 4052 - in3 * 601 + 2048) >> 12;
185+ int t24a = (in29 * 601 + in3 * 4052 + 2048) >> 12;
186+
187+ int t16 = t16a + t17a;
188+ int t17 = t16a - t17a;
189+ int t18 = t19a - t18a;
190+ int t19 = t19a + t18a;
191+ int t20 = t20a + t21a;
192+ int t21 = t20a - t21a;
193+ int t22 = t23a - t22a;
194+ int t23 = t23a + t22a;
195+ int t24 = t24a + t25a;
196+ int t25 = t24a - t25a;
197+ int t26 = t27a - t26a;
198+ int t27 = t27a + t26a;
199+ int t28 = t28a + t29a;
200+ int t29 = t28a - t29a;
201+ int t30 = t31a - t30a;
202+ int t31 = t31a + t30a;
203+
204+ t17a = ( t30 * 799 - t17 * 4017 + 2048) >> 12;
205+ t30a = ( t30 * 4017 + t17 * 799 + 2048) >> 12;
206+ t18a = (-(t29 * 4017 + t18 * 799) + 2048) >> 12;
207+ t29a = ( t29 * 799 - t18 * 4017 + 2048) >> 12;
208+ t21a = ( t26 * 3406 - t21 * 2276 + 2048) >> 12;
209+ t26a = ( t26 * 2276 + t21 * 3406 + 2048) >> 12;
210+ t22a = (-(t25 * 2276 + t22 * 3406) + 2048) >> 12;
211+ t25a = ( t25 * 3406 - t22 * 2276 + 2048) >> 12;
212+
213+ t16a = t16 + t19;
214+ t17 = t17a + t18a;
215+ t18 = t17a - t18a;
216+ t19a = t16 - t19;
217+ t20a = t23 - t20;
218+ t21 = t22a - t21a;
219+ t22 = t22a + t21a;
220+ t23a = t23 + t20;
221+ t24a = t24 + t27;
222+ t25 = t25a + t26a;
223+ t26 = t25a - t26a;
224+ t27a = t24 - t27;
225+ t28a = t31 - t28;
226+ t29 = t30a - t29a;
227+ t30 = t30a + t29a;
228+ t31a = t31 + t28;
229+
230+ t18a = ( t29 * 1567 - t18 * 3784 + 2048) >> 12;
231+ t29a = ( t29 * 3784 + t18 * 1567 + 2048) >> 12;
232+ t19 = ( t28a * 1567 - t19a * 3784 + 2048) >> 12;
233+ t28 = ( t28a * 3784 + t19a * 1567 + 2048) >> 12;
234+ t20 = (-(t27a * 3784 + t20a * 1567) + 2048) >> 12;
235+ t27 = ( t27a * 1567 - t20a * 3784 + 2048) >> 12;
236+ t21a = (-(t26 * 3784 + t21 * 1567) + 2048) >> 12;
237+ t26a = ( t26 * 1567 - t21 * 3784 + 2048) >> 12;
238+
239+ t16 = t16a + t23a;
240+ t17a = t17 + t22;
241+ t18 = t18a + t21a;
242+ t19a = t19 + t20;
243+ t20a = t19 - t20;
244+ t21 = t18a - t21a;
245+ t22a = t17 - t22;
246+ t23 = t16a - t23a;
247+ t24 = t31a - t24a;
248+ t25a = t30 - t25;
249+ t26 = t29a - t26a;
250+ t27a = t28 - t27;
251+ t28a = t28 + t27;
252+ t29 = t29a + t26a;
253+ t30a = t30 + t25;
254+ t31 = t31a + t24a;
255+
256+ t20 = ((t27a - t20a) * 2896 + 2048) >> 12;
257+ t27 = ((t27a + t20a) * 2896 + 2048) >> 12;
258+ t21a = ((t26 - t21 ) * 2896 + 2048) >> 12;
259+ t26a = ((t26 + t21 ) * 2896 + 2048) >> 12;
260+ t22 = ((t25a - t22a) * 2896 + 2048) >> 12;
261+ t25 = ((t25a + t22a) * 2896 + 2048) >> 12;
262+ t23a = ((t24 - t23 ) * 2896 + 2048) >> 12;
263+ t24a = ((t24 + t23 ) * 2896 + 2048) >> 12;
264+
265+ out[ 0 * out_s] = tmp[ 0] + t31;
266+ out[ 1 * out_s] = tmp[ 1] + t30a;
267+ out[ 2 * out_s] = tmp[ 2] + t29;
268+ out[ 3 * out_s] = tmp[ 3] + t28a;
269+ out[ 4 * out_s] = tmp[ 4] + t27;
270+ out[ 5 * out_s] = tmp[ 5] + t26a;
271+ out[ 6 * out_s] = tmp[ 6] + t25;
272+ out[ 7 * out_s] = tmp[ 7] + t24a;
273+ out[ 8 * out_s] = tmp[ 8] + t23a;
274+ out[ 9 * out_s] = tmp[ 9] + t22;
275+ out[10 * out_s] = tmp[10] + t21a;
276+ out[11 * out_s] = tmp[11] + t20;
277+ out[12 * out_s] = tmp[12] + t19a;
278+ out[13 * out_s] = tmp[13] + t18;
279+ out[14 * out_s] = tmp[14] + t17a;
280+ out[15 * out_s] = tmp[15] + t16;
281+ out[16 * out_s] = tmp[15] - t16;
282+ out[17 * out_s] = tmp[14] - t17a;
283+ out[18 * out_s] = tmp[13] - t18;
284+ out[19 * out_s] = tmp[12] - t19a;
285+ out[20 * out_s] = tmp[11] - t20;
286+ out[21 * out_s] = tmp[10] - t21a;
287+ out[22 * out_s] = tmp[ 9] - t22;
288+ out[23 * out_s] = tmp[ 8] - t23a;
289+ out[24 * out_s] = tmp[ 7] - t24a;
290+ out[25 * out_s] = tmp[ 6] - t25;
291+ out[26 * out_s] = tmp[ 5] - t26a;
292+ out[27 * out_s] = tmp[ 4] - t27;
293+ out[28 * out_s] = tmp[ 3] - t28a;
294+ out[29 * out_s] = tmp[ 2] - t29;
295+ out[30 * out_s] = tmp[ 1] - t30a;
296+ out[31 * out_s] = tmp[ 0] - t31;
297+}
298+
299+static void __attribute__((noinline))
300+inv_dct64_1d(const coef *const in, const ptrdiff_t in_s,
301+ coef *const out, const ptrdiff_t out_s)
302+{
303+ coef tmp[32];
304+
305+ inv_dct32_1d(in, in_s * 2, tmp, 1);
306+
307+ const int in1 = in[ 1 * in_s], in3 = in[ 3 * in_s];
308+ const int in5 = in[ 5 * in_s], in7 = in[ 7 * in_s];
309+ const int in9 = in[ 9 * in_s], in11 = in[11 * in_s];
310+ const int in13 = in[13 * in_s], in15 = in[15 * in_s];
311+ const int in17 = in[17 * in_s], in19 = in[19 * in_s];
312+ const int in21 = in[21 * in_s], in23 = in[23 * in_s];
313+ const int in25 = in[25 * in_s], in27 = in[27 * in_s];
314+ const int in29 = in[29 * in_s], in31 = in[31 * in_s];
315+ const int in33 = in[33 * in_s], in35 = in[35 * in_s];
316+ const int in37 = in[37 * in_s], in39 = in[39 * in_s];
317+ const int in41 = in[41 * in_s], in43 = in[43 * in_s];
318+ const int in45 = in[45 * in_s], in47 = in[47 * in_s];
319+ const int in49 = in[49 * in_s], in51 = in[51 * in_s];
320+ const int in53 = in[53 * in_s], in55 = in[55 * in_s];
321+ const int in57 = in[57 * in_s], in59 = in[59 * in_s];
322+ const int in61 = in[61 * in_s], in63 = in[63 * in_s];
323+
324+ int t32a = (in1 * 101 - in63 * 4095 + 2048) >> 12;
325+ int t33a = (in33 * 2967 - in31 * 2824 + 2048) >> 12;
326+ int t34a = (in17 * 1660 - in47 * 3745 + 2048) >> 12;
327+ int t35a = (in49 * 3822 - in15 * 1474 + 2048) >> 12;
328+ int t36a = (in9 * 897 - in55 * 3996 + 2048) >> 12;
329+ int t37a = (in41 * 3461 - in23 * 2191 + 2048) >> 12;
330+ int t38a = (in25 * 2359 - in39 * 3349 + 2048) >> 12;
331+ int t39a = (in57 * 4036 - in7 * 700 + 2048) >> 12;
332+ int t40a = (in5 * 501 - in59 * 4065 + 2048) >> 12;
333+ int t41a = (in37 * 3229 - in27 * 2520 + 2048) >> 12;
334+ int t42a = (in21 * 2019 - in43 * 3564 + 2048) >> 12;
335+ int t43a = (in53 * 3948 - in11 * 1092 + 2048) >> 12;
336+ int t44a = (in13 * 1285 - in51 * 3889 + 2048) >> 12;
337+ int t45a = (in45 * 3659 - in19 * 1842 + 2048) >> 12;
338+ int t46a = (in29 * 2675 - in35 * 3102 + 2048) >> 12;
339+ int t47a = (in61 * 4085 - in3 * 301 + 2048) >> 12;
340+ int t48a = (in61 * 301 + in3 * 4085 + 2048) >> 12;
341+ int t49a = (in29 * 3102 + in35 * 2675 + 2048) >> 12;
342+ int t50a = (in45 * 1842 + in19 * 3659 + 2048) >> 12;
343+ int t51a = (in13 * 3889 + in51 * 1285 + 2048) >> 12;
344+ int t52a = (in53 * 1092 + in11 * 3948 + 2048) >> 12;
345+ int t53a = (in21 * 3564 + in43 * 2019 + 2048) >> 12;
346+ int t54a = (in37 * 2520 + in27 * 3229 + 2048) >> 12;
347+ int t55a = (in5 * 4065 + in59 * 501 + 2048) >> 12;
348+ int t56a = (in57 * 700 + in7 * 4036 + 2048) >> 12;
349+ int t57a = (in25 * 3349 + in39 * 2359 + 2048) >> 12;
350+ int t58a = (in41 * 2191 + in23 * 3461 + 2048) >> 12;
351+ int t59a = (in9 * 3996 + in55 * 897 + 2048) >> 12;
352+ int t60a = (in49 * 1474 + in15 * 3822 + 2048) >> 12;
353+ int t61a = (in17 * 3745 + in47 * 1660 + 2048) >> 12;
354+ int t62a = (in33 * 2824 + in31 * 2967 + 2048) >> 12;
355+ int t63a = (in1 * 4095 + in63 * 101 + 2048) >> 12;
356+
357+ int t32 = t32a + t33a;
358+ int t33 = t32a - t33a;
359+ int t34 = t35a - t34a;
360+ int t35 = t35a + t34a;
361+ int t36 = t36a + t37a;
362+ int t37 = t36a - t37a;
363+ int t38 = t39a - t38a;
364+ int t39 = t39a + t38a;
365+ int t40 = t40a + t41a;
366+ int t41 = t40a - t41a;
367+ int t42 = t43a - t42a;
368+ int t43 = t43a + t42a;
369+ int t44 = t44a + t45a;
370+ int t45 = t44a - t45a;
371+ int t46 = t47a - t46a;
372+ int t47 = t47a + t46a;
373+ int t48 = t48a + t49a;
374+ int t49 = t48a - t49a;
375+ int t50 = t51a - t50a;
376+ int t51 = t51a + t50a;
377+ int t52 = t52a + t53a;
378+ int t53 = t52a - t53a;
379+ int t54 = t55a - t54a;
380+ int t55 = t55a + t54a;
381+ int t56 = t56a + t57a;
382+ int t57 = t56a - t57a;
383+ int t58 = t59a - t58a;
384+ int t59 = t59a + t58a;
385+ int t60 = t60a + t61a;
386+ int t61 = t60a - t61a;
387+ int t62 = t63a - t62a;
388+ int t63 = t63a + t62a;
389+
390+ t33a = (t33 * -4076 + t62 * 401 + 2048) >> 12;
391+ t34a = (t34 * - 401 + t61 * -4076 + 2048) >> 12;
392+ t37a = (t37 * -2598 + t58 * 3166 + 2048) >> 12;
393+ t38a = (t38 * -3166 + t57 * -2598 + 2048) >> 12;
394+ t41a = (t41 * -3612 + t54 * 1931 + 2048) >> 12;
395+ t42a = (t42 * -1931 + t53 * -3612 + 2048) >> 12;
396+ t45a = (t45 * -1189 + t50 * 3920 + 2048) >> 12;
397+ t46a = (t46 * -3920 + t49 * -1189 + 2048) >> 12;
398+ t49a = (t46 * -1189 + t49 * 3920 + 2048) >> 12;
399+ t50a = (t45 * 3920 + t50 * 1189 + 2048) >> 12;
400+ t53a = (t42 * -3612 + t53 * 1931 + 2048) >> 12;
401+ t54a = (t41 * 1931 + t54 * 3612 + 2048) >> 12;
402+ t57a = (t38 * -2598 + t57 * 3166 + 2048) >> 12;
403+ t58a = (t37 * 3166 + t58 * 2598 + 2048) >> 12;
404+ t61a = (t34 * -4076 + t61 * 401 + 2048) >> 12;
405+ t62a = (t33 * 401 + t62 * 4076 + 2048) >> 12;
406+
407+ t32a = t32 + t35;
408+ t33 = t33a + t34a;
409+ t34 = t33a - t34a;
410+ t35a = t32 - t35;
411+ t36a = t39 - t36;
412+ t37 = t38a - t37a;
413+ t38 = t38a + t37a;
414+ t39a = t39 + t36;
415+ t40a = t40 + t43;
416+ t41 = t41a + t42a;
417+ t42 = t41a - t42a;
418+ t43a = t40 - t43;
419+ t44a = t47 - t44;
420+ t45 = t46a - t45a;
421+ t46 = t46a + t45a;
422+ t47a = t47 + t44;
423+ t48a = t48 + t51;
424+ t49 = t49a + t50a;
425+ t50 = t49a - t50a;
426+ t51a = t48 - t51;
427+ t52a = t55 - t52;
428+ t53 = t54a - t53a;
429+ t54 = t54a + t53a;
430+ t55a = t55 + t52;
431+ t56a = t56 + t59;
432+ t57 = t57a + t58a;
433+ t58 = t57a - t58a;
434+ t59a = t56 - t59;
435+ t60a = t63 - t60;
436+ t61 = t62a - t61a;
437+ t62 = t62a + t61a;
438+ t63a = t63 + t60;
439+
440+ t34a = (t34 * -4017 + t61 * 799 + 2048) >> 12;
441+ t35 = (t35a * -4017 + t60a * 799 + 2048) >> 12;
442+ t36 = (t36a * - 799 + t59a * -4017 + 2048) >> 12;
443+ t37a = (t37 * - 799 + t58 * -4017 + 2048) >> 12;
444+ t42a = (t42 * -2276 + t53 * 3406 + 2048) >> 12;
445+ t43 = (t43a * -2276 + t52a * 3406 + 2048) >> 12;
446+ t44 = (t44a * -3406 + t51a * -2276 + 2048) >> 12;
447+ t45a = (t45 * -3406 + t50 * -2276 + 2048) >> 12;
448+ t50a = (t45 * -2276 + t50 * 3406 + 2048) >> 12;
449+ t51 = (t44a * -2276 + t51a * 3406 + 2048) >> 12;
450+ t52 = (t43a * 3406 + t52a * 2276 + 2048) >> 12;
451+ t53a = (t42 * 3406 + t53 * 2276 + 2048) >> 12;
452+ t58a = (t37 * -4017 + t58 * 799 + 2048) >> 12;
453+ t59 = (t36a * -4017 + t59a * 799 + 2048) >> 12;
454+ t60 = (t35a * 799 + t60a * 4017 + 2048) >> 12;
455+ t61a = (t34 * 799 + t61 * 4017 + 2048) >> 12;
456+
457+ t32 = t32a + t39a;
458+ t33a = t33 + t38;
459+ t34 = t34a + t37a;
460+ t35a = t35 + t36;
461+ t36a = t35 - t36;
462+ t37 = t34a - t37a;
463+ t38a = t33 - t38;
464+ t39 = t32a - t39a;
465+ t40 = t47a - t40a;
466+ t41a = t46 - t41;
467+ t42 = t45a - t42a;
468+ t43a = t44 - t43;
469+ t44a = t44 + t43;
470+ t45 = t45a + t42a;
471+ t46a = t46 + t41;
472+ t47 = t47a + t40a;
473+ t48 = t48a + t55a;
474+ t49a = t49 + t54;
475+ t50 = t50a + t53a;
476+ t51a = t51 + t52;
477+ t52a = t51 - t52;
478+ t53 = t50a - t53a;
479+ t54a = t49 - t54;
480+ t55 = t48a - t55a;
481+ t56 = t63a - t56a;
482+ t57a = t62 - t57;
483+ t58 = t61a - t58a;
484+ t59a = t60 - t59;
485+ t60a = t60 + t59;
486+ t61 = t61a + t58a;
487+ t62a = t62 + t57;
488+ t63 = t63a + t56a;
489+
490+ t36 = (t36a * -3784 + t59a * 1567 + 2048) >> 12;
491+ t37a = (t37 * -3784 + t58 * 1567 + 2048) >> 12;
492+ t38 = (t38a * -3784 + t57a * 1567 + 2048) >> 12;
493+ t39a = (t39 * -3784 + t56 * 1567 + 2048) >> 12;
494+ t40a = (t40 * -1567 + t55 * -3784 + 2048) >> 12;
495+ t41 = (t41a * -1567 + t54a * -3784 + 2048) >> 12;
496+ t42a = (t42 * -1567 + t53 * -3784 + 2048) >> 12;
497+ t43 = (t43a * -1567 + t52a * -3784 + 2048) >> 12;
498+ t52 = (t43a * -3784 + t52a * 1567 + 2048) >> 12;
499+ t53a = (t42 * -3784 + t53 * 1567 + 2048) >> 12;
500+ t54 = (t41a * -3784 + t54a * 1567 + 2048) >> 12;
501+ t55a = (t40 * -3784 + t55 * 1567 + 2048) >> 12;
502+ t56a = (t39 * 1567 + t56 * 3784 + 2048) >> 12;
503+ t57 = (t38a * 1567 + t57a * 3784 + 2048) >> 12;
504+ t58a = (t37 * 1567 + t58 * 3784 + 2048) >> 12;
505+ t59 = (t36a * 1567 + t59a * 3784 + 2048) >> 12;
506+
507+ t32a = t32 + t47;
508+ t33 = t33a + t46a;
509+ t34a = t34 + t45;
510+ t35 = t35a + t44a;
511+ t36a = t36 + t43;
512+ t37 = t37a + t42a;
513+ t38a = t38 + t41;
514+ t39 = t39a + t40a;
515+ t40 = t39a - t40a;
516+ t41a = t38 - t41;
517+ t42 = t37a - t42a;
518+ t43a = t36 - t43;
519+ t44 = t35a - t44a;
520+ t45a = t34 - t45;
521+ t46 = t33a - t46a;
522+ t47a = t32 - t47;
523+ t48a = t63 - t48;
524+ t49 = t62a - t49a;
525+ t50a = t61 - t50;
526+ t51 = t60a - t51a;
527+ t52a = t59 - t52;
528+ t53 = t58a - t53a;
529+ t54a = t57 - t54;
530+ t55 = t56a - t55a;
531+ t56 = t56a + t55a;
532+ t57a = t57 + t54;
533+ t58 = t58a + t53a;
534+ t59a = t59 + t52;
535+ t60 = t60a + t51a;
536+ t61a = t61 + t50;
537+ t62 = t62a + t49a;
538+ t63a = t63 + t48;
539+
540+ t40a = (t40 * -2896 + t55 * 2896 + 2048) >> 12;
541+ t41 = (t41a * -2896 + t54a * 2896 + 2048) >> 12;
542+ t42a = (t42 * -2896 + t53 * 2896 + 2048) >> 12;
543+ t43 = (t43a * -2896 + t52a * 2896 + 2048) >> 12;
544+ t44a = (t44 * -2896 + t51 * 2896 + 2048) >> 12;
545+ t45 = (t45a * -2896 + t50a * 2896 + 2048) >> 12;
546+ t46a = (t46 * -2896 + t49 * 2896 + 2048) >> 12;
547+ t47 = (t47a * -2896 + t48a * 2896 + 2048) >> 12;
548+ t48 = (t47a * 2896 + t48a * 2896 + 2048) >> 12;
549+ t49a = (t46 * 2896 + t49 * 2896 + 2048) >> 12;
550+ t50 = (t45a * 2896 + t50a * 2896 + 2048) >> 12;
551+ t51a = (t44 * 2896 + t51 * 2896 + 2048) >> 12;
552+ t52 = (t43a * 2896 + t52a * 2896 + 2048) >> 12;
553+ t53a = (t42 * 2896 + t53 * 2896 + 2048) >> 12;
554+ t54 = (t41a * 2896 + t54a * 2896 + 2048) >> 12;
555+ t55a = (t40 * 2896 + t55 * 2896 + 2048) >> 12;
556+
557+ out[ 0 * out_s] = tmp[ 0] + t63a;
558+ out[ 1 * out_s] = tmp[ 1] + t62;
559+ out[ 2 * out_s] = tmp[ 2] + t61a;
560+ out[ 3 * out_s] = tmp[ 3] + t60;
561+ out[ 4 * out_s] = tmp[ 4] + t59a;
562+ out[ 5 * out_s] = tmp[ 5] + t58;
563+ out[ 6 * out_s] = tmp[ 6] + t57a;
564+ out[ 7 * out_s] = tmp[ 7] + t56;
565+ out[ 8 * out_s] = tmp[ 8] + t55a;
566+ out[ 9 * out_s] = tmp[ 9] + t54;
567+ out[10 * out_s] = tmp[10] + t53a;
568+ out[11 * out_s] = tmp[11] + t52;
569+ out[12 * out_s] = tmp[12] + t51a;
570+ out[13 * out_s] = tmp[13] + t50;
571+ out[14 * out_s] = tmp[14] + t49a;
572+ out[15 * out_s] = tmp[15] + t48;
573+ out[16 * out_s] = tmp[16] + t47;
574+ out[17 * out_s] = tmp[17] + t46a;
575+ out[18 * out_s] = tmp[18] + t45;
576+ out[19 * out_s] = tmp[19] + t44a;
577+ out[20 * out_s] = tmp[20] + t43;
578+ out[21 * out_s] = tmp[21] + t42a;
579+ out[22 * out_s] = tmp[22] + t41;
580+ out[23 * out_s] = tmp[23] + t40a;
581+ out[24 * out_s] = tmp[24] + t39;
582+ out[25 * out_s] = tmp[25] + t38a;
583+ out[26 * out_s] = tmp[26] + t37;
584+ out[27 * out_s] = tmp[27] + t36a;
585+ out[28 * out_s] = tmp[28] + t35;
586+ out[29 * out_s] = tmp[29] + t34a;
587+ out[30 * out_s] = tmp[30] + t33;
588+ out[31 * out_s] = tmp[31] + t32a;
589+ out[32 * out_s] = tmp[31] - t32a;
590+ out[33 * out_s] = tmp[30] - t33;
591+ out[34 * out_s] = tmp[29] - t34a;
592+ out[35 * out_s] = tmp[28] - t35;
593+ out[36 * out_s] = tmp[27] - t36a;
594+ out[37 * out_s] = tmp[26] - t37;
595+ out[38 * out_s] = tmp[25] - t38a;
596+ out[39 * out_s] = tmp[24] - t39;
597+ out[40 * out_s] = tmp[23] - t40a;
598+ out[41 * out_s] = tmp[22] - t41;
599+ out[42 * out_s] = tmp[21] - t42a;
600+ out[43 * out_s] = tmp[20] - t43;
601+ out[44 * out_s] = tmp[19] - t44a;
602+ out[45 * out_s] = tmp[18] - t45;
603+ out[46 * out_s] = tmp[17] - t46a;
604+ out[47 * out_s] = tmp[16] - t47;
605+ out[48 * out_s] = tmp[15] - t48;
606+ out[49 * out_s] = tmp[14] - t49a;
607+ out[50 * out_s] = tmp[13] - t50;
608+ out[51 * out_s] = tmp[12] - t51a;
609+ out[52 * out_s] = tmp[11] - t52;
610+ out[53 * out_s] = tmp[10] - t53a;
611+ out[54 * out_s] = tmp[ 9] - t54;
612+ out[55 * out_s] = tmp[ 8] - t55a;
613+ out[56 * out_s] = tmp[ 7] - t56;
614+ out[57 * out_s] = tmp[ 6] - t57a;
615+ out[58 * out_s] = tmp[ 5] - t58;
616+ out[59 * out_s] = tmp[ 4] - t59a;
617+ out[60 * out_s] = tmp[ 3] - t60;
618+ out[61 * out_s] = tmp[ 2] - t61a;
619+ out[62 * out_s] = tmp[ 1] - t62;
620+ out[63 * out_s] = tmp[ 0] - t63a;
621+}
622+
623+static void __attribute__((noinline))
624+inv_adst4_1d(const coef *const in, const ptrdiff_t in_s,
625+ coef *const out, const ptrdiff_t out_s)
626+{
627+ const int in0 = in[0 * in_s], in1 = in[1 * in_s];
628+ const int in2 = in[2 * in_s], in3 = in[3 * in_s];
629+
630+ int t0 = 1321 * in0 + 3803 * in2 + 2482 * in3;
631+ int t1 = 2482 * in0 - 1321 * in2 - 3803 * in3;
632+ int t2 = 3344 * (in0 - in2 + in3);
633+ int t3 = 3344 * in1;
634+
635+ out[0 * out_s] = (t0 + t3 + 2048) >> 12;
636+ out[1 * out_s] = (t1 + t3 + 2048) >> 12;
637+ out[2 * out_s] = (t2 + 2048) >> 12;
638+ out[3 * out_s] = (t0 + t1 - t3 + 2048) >> 12;
639+}
640+
641+static void __attribute__((noinline))
642+inv_adst8_1d(const coef *const in, const ptrdiff_t in_s,
643+ coef *const out, const ptrdiff_t out_s)
644+{
645+ const int in0 = in[0 * in_s], in1 = in[1 * in_s];
646+ const int in2 = in[2 * in_s], in3 = in[3 * in_s];
647+ const int in4 = in[4 * in_s], in5 = in[5 * in_s];
648+ const int in6 = in[6 * in_s], in7 = in[7 * in_s];
649+
650+ int t0a = (4076 * in7 + 401 * in0 + 2048) >> 12;
651+ int t1a = ( 401 * in7 - 4076 * in0 + 2048) >> 12;
652+ int t2a = (3612 * in5 + 1931 * in2 + 2048) >> 12;
653+ int t3a = (1931 * in5 - 3612 * in2 + 2048) >> 12;
654+ int t4a = (2598 * in3 + 3166 * in4 + 2048) >> 12;
655+ int t5a = (3166 * in3 - 2598 * in4 + 2048) >> 12;
656+ int t6a = (1189 * in1 + 3920 * in6 + 2048) >> 12;
657+ int t7a = (3920 * in1 - 1189 * in6 + 2048) >> 12;
658+
659+ int t0 = t0a + t4a;
660+ int t1 = t1a + t5a;
661+ int t2 = t2a + t6a;
662+ int t3 = t3a + t7a;
663+ int t4 = t0a - t4a;
664+ int t5 = t1a - t5a;
665+ int t6 = t2a - t6a;
666+ int t7 = t3a - t7a;
667+
668+ t4a = (3784 * t4 + 1567 * t5 + 2048) >> 12;
669+ t5a = (1567 * t4 - 3784 * t5 + 2048) >> 12;
670+ t6a = (3784 * t7 - 1567 * t6 + 2048) >> 12;
671+ t7a = (1567 * t7 + 3784 * t6 + 2048) >> 12;
672+
673+ out[0 * out_s] = t0 + t2;
674+ out[7 * out_s] = -(t1 + t3);
675+ t2 = t0 - t2;
676+ t3 = t1 - t3;
677+
678+ out[1 * out_s] = -(t4a + t6a);
679+ out[6 * out_s] = t5a + t7a;
680+ t6 = t4a - t6a;
681+ t7 = t5a - t7a;
682+
683+ out[3 * out_s] = -(((t2 + t3) * 2896 + 2048) >> 12);
684+ out[4 * out_s] = ((t2 - t3) * 2896 + 2048) >> 12;
685+ out[2 * out_s] = ((t6 + t7) * 2896 + 2048) >> 12;
686+ out[5 * out_s] = -(((t6 - t7) * 2896 + 2048) >> 12);
687+}
688+
689+static void __attribute__((noinline))
690+inv_adst16_1d(const coef *const in, const ptrdiff_t in_s,
691+ coef *const out, const ptrdiff_t out_s)
692+{
693+ const int in0 = in[ 0 * in_s], in1 = in[ 1 * in_s];
694+ const int in2 = in[ 2 * in_s], in3 = in[ 3 * in_s];
695+ const int in4 = in[ 4 * in_s], in5 = in[ 5 * in_s];
696+ const int in6 = in[ 6 * in_s], in7 = in[ 7 * in_s];
697+ const int in8 = in[ 8 * in_s], in9 = in[ 9 * in_s];
698+ const int in10 = in[10 * in_s], in11 = in[11 * in_s];
699+ const int in12 = in[12 * in_s], in13 = in[13 * in_s];
700+ const int in14 = in[14 * in_s], in15 = in[15 * in_s];
701+
702+ int t0 = (in15 * 4091 + in0 * 201 + 2048) >> 12;
703+ int t1 = (in15 * 201 - in0 * 4091 + 2048) >> 12;
704+ int t2 = (in13 * 3973 + in2 * 995 + 2048) >> 12;
705+ int t3 = (in13 * 995 - in2 * 3973 + 2048) >> 12;
706+ int t4 = (in11 * 3703 + in4 * 1751 + 2048) >> 12;
707+ int t5 = (in11 * 1751 - in4 * 3703 + 2048) >> 12;
708+ int t6 = (in9 * 3290 + in6 * 2440 + 2048) >> 12;
709+ int t7 = (in9 * 2440 - in6 * 3290 + 2048) >> 12;
710+ int t8 = (in7 * 2751 + in8 * 3035 + 2048) >> 12;
711+ int t9 = (in7 * 3035 - in8 * 2751 + 2048) >> 12;
712+ int t10 = (in5 * 2106 + in10 * 3513 + 2048) >> 12;
713+ int t11 = (in5 * 3513 - in10 * 2106 + 2048) >> 12;
714+ int t12 = (in3 * 1380 + in12 * 3857 + 2048) >> 12;
715+ int t13 = (in3 * 3857 - in12 * 1380 + 2048) >> 12;
716+ int t14 = (in1 * 601 + in14 * 4052 + 2048) >> 12;
717+ int t15 = (in1 * 4052 - in14 * 601 + 2048) >> 12;
718+
719+ int t0a = t0 + t8;
720+ int t1a = t1 + t9;
721+ int t2a = t2 + t10;
722+ int t3a = t3 + t11;
723+ int t4a = t4 + t12;
724+ int t5a = t5 + t13;
725+ int t6a = t6 + t14;
726+ int t7a = t7 + t15;
727+ int t8a = t0 - t8;
728+ int t9a = t1 - t9;
729+ int t10a = t2 - t10;
730+ int t11a = t3 - t11;
731+ int t12a = t4 - t12;
732+ int t13a = t5 - t13;
733+ int t14a = t6 - t14;
734+ int t15a = t7 - t15;
735+
736+ t8 = (t8a * 4017 + t9a * 799 + 2048) >> 12;
737+ t9 = (t8a * 799 - t9a * 4017 + 2048) >> 12;
738+ t10 = (t10a * 2276 + t11a * 3406 + 2048) >> 12;
739+ t11 = (t10a * 3406 - t11a * 2276 + 2048) >> 12;
740+ t12 = (t13a * 4017 - t12a * 799 + 2048) >> 12;
741+ t13 = (t13a * 799 + t12a * 4017 + 2048) >> 12;
742+ t14 = (t15a * 2276 - t14a * 3406 + 2048) >> 12;
743+ t15 = (t15a * 3406 + t14a * 2276 + 2048) >> 12;
744+
745+ t0 = t0a + t4a;
746+ t1 = t1a + t5a;
747+ t2 = t2a + t6a;
748+ t3 = t3a + t7a;
749+ t4 = t0a - t4a;
750+ t5 = t1a - t5a;
751+ t6 = t2a - t6a;
752+ t7 = t3a - t7a;
753+ t8a = t8 + t12;
754+ t9a = t9 + t13;
755+ t10a = t10 + t14;
756+ t11a = t11 + t15;
757+ t12a = t8 - t12;
758+ t13a = t9 - t13;
759+ t14a = t10 - t14;
760+ t15a = t11 - t15;
761+
762+ t4a = (t4 * 3784 + t5 * 1567 + 2048) >> 12;
763+ t5a = (t4 * 1567 - t5 * 3784 + 2048) >> 12;
764+ t6a = (t7 * 3784 - t6 * 1567 + 2048) >> 12;
765+ t7a = (t7 * 1567 + t6 * 3784 + 2048) >> 12;
766+ t12 = (t12a * 3784 + t13a * 1567 + 2048) >> 12;
767+ t13 = (t12a * 1567 - t13a * 3784 + 2048) >> 12;
768+ t14 = (t15a * 3784 - t14a * 1567 + 2048) >> 12;
769+ t15 = (t15a * 1567 + t14a * 3784 + 2048) >> 12;
770+
771+ out[ 0 * out_s] = t0 + t2;
772+ out[15 * out_s] = -(t1 + t3);
773+ t2a = t0 - t2;
774+ t3a = t1 - t3;
775+ out[ 3 * out_s] = -(t4a + t6a);
776+ out[12 * out_s] = t5a + t7a;
777+ t6 = t4a - t6a;
778+ t7 = t5a - t7a;
779+ out[ 1 * out_s] = -(t8a + t10a);
780+ out[14 * out_s] = t9a + t11a;
781+ t10 = t8a - t10a;
782+ t11 = t9a - t11a;
783+ out[ 2 * out_s] = t12 + t14;
784+ out[13 * out_s] = -(t13 + t15);
785+ t14a = t12 - t14;
786+ t15a = t13 - t15;
787+
788+ out[ 7 * out_s] = -(((t2a + t3a) * 2896 + 2048) >> 12);
789+ out[ 8 * out_s] = ((t2a - t3a) * 2896 + 2048) >> 12;
790+ out[ 4 * out_s] = ((t6 + t7) * 2896 + 2048) >> 12;
791+ out[11 * out_s] = -(((t6 - t7) * 2896 + 2048) >> 12);
792+ out[ 6 * out_s] = ((t10 + t11) * 2896 + 2048) >> 12;
793+ out[ 9 * out_s] = -(((t10 - t11) * 2896 + 2048) >> 12);
794+ out[ 5 * out_s] = -(((t14a + t15a) * 2896 + 2048) >> 12);
795+ out[10 * out_s] = ((t14a - t15a) * 2896 + 2048) >> 12;
796+}
797+
798+#define flip_inv_adst(sz) \
799+static void inv_flipadst##sz##_1d(const coef *const in, const ptrdiff_t in_s, \
800+ coef *const out, const ptrdiff_t out_s) \
801+{ \
802+ inv_adst##sz##_1d(in, in_s, &out[(sz - 1) * out_s], -out_s); \
803+}
804+
805+flip_inv_adst(4);
806+flip_inv_adst(8);
807+flip_inv_adst(16);
808+
809+#undef flip_inv_adst
810+
811+static void __attribute__((noinline))
812+inv_identity4_1d(const coef *const in, const ptrdiff_t in_s,
813+ coef *const out, const ptrdiff_t out_s)
814+{
815+ for (int i = 0; i < 4; i++)
816+ out[out_s * i] = (in[in_s * i] * 5793 + 2048) >> 12;
817+}
818+
819+static void __attribute__((noinline))
820+inv_identity8_1d(const coef *const in, const ptrdiff_t in_s,
821+ coef *const out, const ptrdiff_t out_s)
822+{
823+ for (int i = 0; i < 8; i++)
824+ out[out_s * i] = in[in_s * i] * 2;
825+}
826+
827+static void __attribute__((noinline))
828+inv_identity16_1d(const coef *const in, const ptrdiff_t in_s,
829+ coef *const out, const ptrdiff_t out_s)
830+{
831+ for (int i = 0; i < 16; i++)
832+ out[out_s * i] = (in[in_s * i] * 2 * 5793 + 2048) >> 12;
833+}
834+
835+static void __attribute__((noinline))
836+inv_identity32_1d(const coef *const in, const ptrdiff_t in_s,
837+ coef *const out, const ptrdiff_t out_s)
838+{
839+ for (int i = 0; i < 32; i++)
840+ out[out_s * i] = in[in_s * i] * 4;
841+}
842+
843+static void __attribute__((noinline))
844+inv_wht4_1d(const coef *const in, const ptrdiff_t in_s,
845+ coef *const out, const ptrdiff_t out_s,
846+ const int pass)
847+{
848+ const int sh = 2 * !pass;
849+ const int in0 = in[0 * in_s] >> sh, in1 = in[1 * in_s] >> sh;
850+ const int in2 = in[2 * in_s] >> sh, in3 = in[3 * in_s] >> sh;
851+ const int t0 = in0 + in1;
852+ const int t2 = in2 - in3;
853+ const int t4 = (t0 - t2) >> 1;
854+ const int t3 = t4 - in3;
855+ const int t1 = t4 - in1;
856+
857+ out[0 * out_s] = t0 - t3;
858+ out[1 * out_s] = t3;
859+ out[2 * out_s] = t1;
860+ out[3 * out_s] = t2 + t1;
861+}
src/levels.h+525−0
@@ -0,0 +1,525 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __DAV1D_SRC_LEVELS_H__
29+#define __DAV1D_SRC_LEVELS_H__
30+
31+#include "dav1d/picture.h"
32+
33+enum ObuType {
34+ OBU_SEQ_HDR = 1,
35+ OBU_TD = 2,
36+ OBU_FRAME_HDR = 3,
37+ OBU_TILE_GRP = 4,
38+ OBU_METADATA = 5,
39+ OBU_FRAME = 6,
40+ OBU_PADDING = 15,
41+};
42+
43+enum FrameType {
44+ KEY_FRAME = 0,
45+ INTER_FRAME = 1,
46+ INTRAONLY_FRAME = 2,
47+ S_FRAME = 3,
48+} FRAME_TYPE;
49+
50+enum TxfmSize {
51+ TX_4X4,
52+ TX_8X8,
53+ TX_16X16,
54+ TX_32X32,
55+ TX_64X64,
56+ N_TX_SIZES,
57+};
58+
59+enum BlockLevel {
60+ BL_128X128,
61+ BL_64X64,
62+ BL_32X32,
63+ BL_16X16,
64+ BL_8X8,
65+ N_BL_LEVELS,
66+};
67+
68+enum TxfmMode {
69+ TX_4X4_ONLY,
70+ TX_LARGEST,
71+ TX_SWITCHABLE,
72+ N_TX_MODES,
73+};
74+
75+enum RectTxfmSize {
76+ RTX_4X8 = N_TX_SIZES,
77+ RTX_8X4,
78+ RTX_8X16,
79+ RTX_16X8,
80+ RTX_16X32,
81+ RTX_32X16,
82+ RTX_32X64,
83+ RTX_64X32,
84+ RTX_4X16,
85+ RTX_16X4,
86+ RTX_8X32,
87+ RTX_32X8,
88+ RTX_16X64,
89+ RTX_64X16,
90+ N_RECT_TX_SIZES
91+};
92+
93+enum TxfmType {
94+ DCT_DCT, // DCT in both horizontal and vertical
95+ ADST_DCT, // ADST in vertical, DCT in horizontal
96+ DCT_ADST, // DCT in vertical, ADST in horizontal
97+ ADST_ADST, // ADST in both directions
98+ FLIPADST_DCT,
99+ DCT_FLIPADST,
100+ FLIPADST_FLIPADST,
101+ ADST_FLIPADST,
102+ FLIPADST_ADST,
103+ IDTX,
104+ V_DCT,
105+ H_DCT,
106+ V_ADST,
107+ H_ADST,
108+ V_FLIPADST,
109+ H_FLIPADST,
110+ N_TX_TYPES,
111+ WHT_WHT = N_TX_TYPES,
112+ N_TX_TYPES_PLUS_LL,
113+};
114+
115+enum TxfmTypeSet {
116+ TXTP_SET_DCT,
117+ TXTP_SET_DCT_ID,
118+ TXTP_SET_DT4_ID,
119+ TXTP_SET_DT4_ID_1D,
120+ TXTP_SET_DT9_ID_1D,
121+ TXTP_SET_ALL,
122+ TXTP_SET_LOSSLESS,
123+ N_TXTP_SETS
124+};
125+
126+enum TxClass {
127+ TX_CLASS_2D,
128+ TX_CLASS_H,
129+ TX_CLASS_V,
130+};
131+
132+enum IntraPredMode {
133+ DC_PRED,
134+ VERT_PRED,
135+ HOR_PRED,
136+ DIAG_DOWN_LEFT_PRED,
137+ DIAG_DOWN_RIGHT_PRED,
138+ VERT_RIGHT_PRED,
139+ HOR_DOWN_PRED,
140+ HOR_UP_PRED,
141+ VERT_LEFT_PRED,
142+ SMOOTH_PRED,
143+ SMOOTH_V_PRED,
144+ SMOOTH_H_PRED,
145+ PAETH_PRED,
146+ N_INTRA_PRED_MODES,
147+ CFL_PRED = N_INTRA_PRED_MODES,
148+ N_UV_INTRA_PRED_MODES,
149+ N_IMPL_INTRA_PRED_MODES = N_UV_INTRA_PRED_MODES,
150+ LEFT_DC_PRED = DIAG_DOWN_LEFT_PRED,
151+ TOP_DC_PRED,
152+ DC_128_PRED,
153+ Z1_PRED,
154+ Z2_PRED,
155+ Z3_PRED,
156+ FILTER_PRED = N_INTRA_PRED_MODES,
157+};
158+
159+enum InterIntraPredMode {
160+ II_DC_PRED,
161+ II_VERT_PRED,
162+ II_HOR_PRED,
163+ II_SMOOTH_PRED,
164+ N_INTER_INTRA_PRED_MODES,
165+};
166+
167+enum BlockPartition {
168+ PARTITION_NONE, // [ ] <-.
169+ PARTITION_H, // [-] |
170+ PARTITION_V, // [|] |
171+ PARTITION_SPLIT, // [+] --'
172+ PARTITION_T_TOP_SPLIT, // [⊥] i.e. split top, H bottom
173+ PARTITION_T_BOTTOM_SPLIT, // [т] i.e. H top, split bottom
174+ PARTITION_T_LEFT_SPLIT, // [-|] i.e. split left, V right
175+ PARTITION_T_RIGHT_SPLIT, // [|-] i.e. V left, split right
176+ PARTITION_H4, // [Ⲷ]
177+ PARTITION_V4, // [Ⲽ]
178+ N_PARTITIONS,
179+ N_SUB8X8_PARTITIONS = PARTITION_T_TOP_SPLIT,
180+};
181+
182+enum BlockSize {
183+ BS_128x128,
184+ BS_128x64,
185+ BS_64x128,
186+ BS_64x64,
187+ BS_64x32,
188+ BS_64x16,
189+ BS_32x64,
190+ BS_32x32,
191+ BS_32x16,
192+ BS_32x8,
193+ BS_16x64,
194+ BS_16x32,
195+ BS_16x16,
196+ BS_16x8,
197+ BS_16x4,
198+ BS_8x32,
199+ BS_8x16,
200+ BS_8x8,
201+ BS_8x4,
202+ BS_4x16,
203+ BS_4x8,
204+ BS_4x4,
205+ N_BS_SIZES,
206+};
207+
208+enum FilterMode {
209+ FILTER_8TAP_REGULAR,
210+ FILTER_8TAP_SMOOTH,
211+ FILTER_8TAP_SHARP,
212+ N_SWITCHABLE_FILTERS,
213+ FILTER_BILINEAR = N_SWITCHABLE_FILTERS,
214+ N_FILTERS,
215+ FILTER_SWITCHABLE = N_FILTERS,
216+};
217+
218+enum Filter2d { // order is horizontal, vertical
219+ FILTER_2D_8TAP_REGULAR,
220+ FILTER_2D_8TAP_REGULAR_SMOOTH,
221+ FILTER_2D_8TAP_REGULAR_SHARP,
222+ FILTER_2D_8TAP_SHARP_REGULAR,
223+ FILTER_2D_8TAP_SHARP_SMOOTH,
224+ FILTER_2D_8TAP_SHARP,
225+ FILTER_2D_8TAP_SMOOTH_REGULAR,
226+ FILTER_2D_8TAP_SMOOTH,
227+ FILTER_2D_8TAP_SMOOTH_SHARP,
228+ FILTER_2D_BILINEAR,
229+ N_2D_FILTERS,
230+};
231+
232+enum MVJoint {
233+ MV_JOINT_ZERO,
234+ MV_JOINT_H,
235+ MV_JOINT_V,
236+ MV_JOINT_HV,
237+ N_MV_JOINTS,
238+};
239+
240+enum InterPredMode {
241+ NEARESTMV,
242+ NEARMV,
243+ GLOBALMV,
244+ NEWMV,
245+ N_INTER_PRED_MODES,
246+};
247+
248+enum CompInterPredMode {
249+ NEARESTMV_NEARESTMV,
250+ NEARMV_NEARMV,
251+ NEARESTMV_NEWMV,
252+ NEWMV_NEARESTMV,
253+ NEARMV_NEWMV,
254+ NEWMV_NEARMV,
255+ GLOBALMV_GLOBALMV,
256+ NEWMV_NEWMV,
257+ N_COMP_INTER_PRED_MODES,
258+};
259+
260+enum CompInterType {
261+ COMP_INTER_NONE,
262+ COMP_INTER_WEIGHTED_AVG,
263+ COMP_INTER_AVG,
264+ COMP_INTER_SEG,
265+ COMP_INTER_WEDGE,
266+};
267+
268+enum InterIntraType {
269+ INTER_INTRA_NONE,
270+ INTER_INTRA_BLEND,
271+ INTER_INTRA_WEDGE,
272+};
273+
274+enum AdaptiveBoolean {
275+ OFF = 0,
276+ ON = 1,
277+ ADAPTIVE = 2,
278+};
279+
280+enum RestorationType {
281+ RESTORATION_NONE,
282+ RESTORATION_SWITCHABLE,
283+ RESTORATION_WIENER,
284+ RESTORATION_SGRPROJ,
285+};
286+
287+typedef struct mv {
288+ int16_t y, x;
289+} mv;
290+
291+enum WarpedMotionType {
292+ WM_TYPE_IDENTITY,
293+ WM_TYPE_TRANSLATION,
294+ WM_TYPE_ROT_ZOOM,
295+ WM_TYPE_AFFINE,
296+};
297+
298+typedef struct WarpedMotionParams {
299+ enum WarpedMotionType type;
300+ int32_t matrix[6];
301+ union {
302+ struct {
303+ int16_t alpha, beta, gamma, delta;
304+ };
305+ int16_t abcd[4];
306+ };
307+} WarpedMotionParams;
308+
309+enum MotionMode {
310+ MM_TRANSLATION,
311+ MM_OBMC,
312+ MM_WARP,
313+};
314+
315+typedef struct Av1SequenceHeader {
316+ int profile;
317+ int still_picture;
318+ int reduced_still_picture_header;
319+ int timing_info_present;
320+ int num_units_in_tick;
321+ int time_scale;
322+ int equal_picture_interval;
323+ int num_ticks_per_picture;
324+ int decoder_model_info_present;
325+ int bitrate_scale;
326+ int buffer_size_scale;
327+ int encoder_decoder_buffer_delay_length;
328+ int num_units_in_decoding_tick;
329+ int buffer_removal_delay_length;
330+ int frame_presentation_delay_length;
331+ int display_model_info_present;
332+ int num_operating_points;
333+ struct Av1SequenceHeaderOperatingPoint {
334+ int idc;
335+ int major_level, minor_level;
336+ int tier;
337+ int decoder_model_param_present;
338+ int bitrate;
339+ int buffer_size;
340+ int cbr;
341+ int decoder_buffer_delay;
342+ int encoder_buffer_delay;
343+ int low_delay_mode;
344+ int display_model_param_present;
345+ int initial_display_delay;
346+ } operating_points[32];
347+ int max_width, max_height, width_n_bits, height_n_bits;
348+ int frame_id_numbers_present;
349+ int delta_frame_id_n_bits;
350+ int frame_id_n_bits;
351+ int sb128;
352+ int filter_intra;
353+ int intra_edge_filter;
354+ int inter_intra;
355+ int masked_compound;
356+ int warped_motion;
357+ int dual_filter;
358+ int order_hint;
359+ int jnt_comp;
360+ int ref_frame_mvs;
361+ enum AdaptiveBoolean screen_content_tools;
362+ enum AdaptiveBoolean force_integer_mv;
363+ int order_hint_n_bits;
364+ int super_res;
365+ int cdef;
366+ int restoration;
367+ int bpc;
368+ int hbd;
369+ int color_description_present;
370+ enum Dav1dPixelLayout layout;
371+ enum Dav1dColorPrimaries pri;
372+ enum Dav1dTransferCharacteristics trc;
373+ enum Dav1dMatrixCoefficients mtrx;
374+ enum Dav1dChromaSamplePosition chr;
375+ int color_range;
376+ int separate_uv_delta_q;
377+ int film_grain_present;
378+} Av1SequenceHeader;
379+
380+#define NUM_SEGMENTS 8
381+
382+typedef struct Av1SegmentationData {
383+ int delta_q;
384+ int delta_lf_y_v, delta_lf_y_h, delta_lf_u, delta_lf_v;
385+ int ref;
386+ int skip;
387+ int globalmv;
388+} Av1SegmentationData;
389+
390+typedef struct Av1SegmentationDataSet {
391+ Av1SegmentationData d[NUM_SEGMENTS];
392+ int preskip;
393+ int last_active_segid;
394+} Av1SegmentationDataSet;
395+
396+typedef struct Av1LoopfilterModeRefDeltas {
397+ int mode_delta[2];
398+ int ref_delta[8];
399+} Av1LoopfilterModeRefDeltas;
400+
401+typedef struct Av1FilmGrainData {
402+ int num_y_points;
403+ uint8_t y_points[14][2 /* value, scaling */];
404+ int chroma_scaling_from_luma;
405+ int num_uv_points[2];
406+ uint8_t uv_points[2][10][2 /* value, scaling */];
407+ int scaling_shift;
408+ int ar_coeff_lag;
409+ int8_t ar_coeffs_y[24];
410+ int8_t ar_coeffs_uv[2][25];
411+ int ar_coeff_shift;
412+ int grain_scale_shift;
413+ int uv_mult[2];
414+ int uv_luma_mult[2];
415+ int uv_offset[2];
416+ int overlap_flag;
417+ int clip_to_restricted_range;
418+} Av1FilmGrainData;
419+
420+typedef struct Av1FrameHeader {
421+ int show_existing_frame;
422+ int existing_frame_idx;
423+ int frame_id;
424+ enum FrameType frame_type;
425+ int show_frame;
426+ int showable_frame;
427+ int error_resilient_mode;
428+ int disable_cdf_update;
429+ int allow_screen_content_tools;
430+ int force_integer_mv;
431+ int frame_size_override;
432+#define PRIMARY_REF_NONE 7
433+ int primary_ref_frame;
434+ int frame_offset;
435+ int refresh_frame_flags;
436+ int width, height;
437+ int render_width, render_height;
438+ int super_res;
439+ int have_render_size;
440+ int allow_intrabc;
441+ int frame_ref_short_signaling;
442+ int refidx[7];
443+ int hp;
444+ enum FilterMode subpel_filter_mode;
445+ int switchable_motion_mode;
446+ int use_ref_frame_mvs;
447+ int refresh_context;
448+ struct {
449+ int uniform;
450+ int n_bytes;
451+ int min_log2_cols, max_log2_cols, log2_cols, cols;
452+ int col_start_sb[1025];
453+ int min_log2_rows, max_log2_rows, log2_rows, rows;
454+ int row_start_sb[1025];
455+ int update;
456+ } tiling;
457+ struct {
458+ int yac;
459+ int ydc_delta;
460+ int udc_delta, uac_delta, vdc_delta, vac_delta;
461+ int qm, qm_y, qm_u, qm_v;
462+ } quant;
463+ struct {
464+ int enabled, update_map, temporal, update_data;
465+ Av1SegmentationDataSet seg_data;
466+ int lossless[NUM_SEGMENTS], qidx[NUM_SEGMENTS];
467+ } segmentation;
468+ int delta_q_present;
469+ int delta_q_res_log2;
470+ int delta_lf_present;
471+ int delta_lf_res_log2;
472+ int delta_lf_multi;
473+ int all_lossless;
474+ struct {
475+ int level_y[2];
476+ int level_u, level_v;
477+ int mode_ref_delta_enabled;
478+ int mode_ref_delta_update;
479+ Av1LoopfilterModeRefDeltas mode_ref_deltas;
480+ int sharpness;
481+ } loopfilter;
482+ struct {
483+ int damping;
484+ int n_bits;
485+ int y_strength[8];
486+ int uv_strength[8];
487+ } cdef;
488+ struct {
489+ enum RestorationType type[3];
490+ int unit_size[2];
491+ } restoration;
492+ enum TxfmMode txfm_mode;
493+ int switchable_comp_refs;
494+ int skip_mode_allowed, skip_mode_enabled, skip_mode_refs[2];
495+ int warp_motion;
496+ int reduced_txtp_set;
497+ WarpedMotionParams gmv[7];
498+ struct {
499+ int present, update, seed;
500+ Av1FilmGrainData data;
501+ } film_grain;
502+} Av1FrameHeader;
503+
504+#define QINDEX_RANGE 256
505+
506+typedef struct Av1Block {
507+ uint8_t bl, bs, bp;
508+ uint8_t intra, seg_id, skip_mode, skip, uvtx;
509+ union {
510+ struct {
511+ uint8_t y_mode, uv_mode, tx, pal_sz[2];
512+ int8_t y_angle, uv_angle, cfl_alpha[2];
513+ }; // intra
514+ struct {
515+ int8_t ref[2];
516+ uint8_t comp_type, wedge_idx, mask_sign, inter_mode, drl_idx;
517+ uint8_t interintra_type, interintra_mode, motion_mode;
518+ uint8_t max_ytx, filter2d;
519+ uint16_t tx_split[2];
520+ mv mv[2];
521+ }; // inter
522+ };
523+} Av1Block;
524+
525+#endif /* __DAV1D_SRC_LEVELS_H__ */
src/lf_apply.c+330−0
@@ -0,0 +1,330 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#include "config.h"
29+
30+#include <assert.h>
31+#include <string.h>
32+
33+#include "common/intops.h"
34+
35+#include "src/lf_apply.h"
36+
37+static inline int maxifzero(const uint8_t (*const a)[4], const int have_b,
38+ const uint8_t (*const b)[4], const int diridx)
39+{
40+ const int a_val = (*a)[diridx];
41+ if (a_val) return a_val;
42+ if (!have_b) return a_val;
43+ return (*b)[diridx];
44+}
45+
46+static inline void filter_plane_cols_y(const Dav1dFrameContext *const f,
47+ const int have_left,
48+ const uint8_t (*lvl)[4],
49+ const ptrdiff_t b4_stride,
50+ const uint32_t (*const mask)[3],
51+ pixel *dst, const ptrdiff_t ls,
52+ const int starty4, const int endy4)
53+{
54+ const Dav1dDSPContext *const dsp = f->dsp;
55+
56+ // filter edges between columns (e.g. block1 | block2)
57+ for (int y = starty4; y < endy4;
58+ y++, dst += 4 * PXSTRIDE(ls), lvl += b4_stride)
59+ {
60+ pixel *ptr = dst;
61+ const uint8_t (*l)[4] = lvl;
62+ const uint32_t *const hmask = mask[y];
63+ const unsigned hm = hmask[0] | hmask[1] | hmask[2];
64+
65+ for (unsigned x = 1; hm & ~(x - 1); l++, x <<= 1, ptr += 4) {
66+ if ((have_left || x > 1) && (hm & x)) {
67+ const int L = maxifzero(l, have_left || x > 1, &l[-1], 0);
68+ if (!L) continue;
69+ const int H = L >> 4;
70+ const int E = f->lf.lim_lut.e[L], I = f->lf.lim_lut.i[L];
71+ const int idx = (hmask[2] & x) ? 2 : !!(hmask[1] & x);
72+
73+ dsp->lf.loop_filter[idx][0](ptr, ls, E, I, H);
74+ }
75+ }
76+ }
77+}
78+
79+static inline void filter_plane_rows_y(const Dav1dFrameContext *const f,
80+ const int have_top,
81+ const uint8_t (*lvl)[4],
82+ const ptrdiff_t b4_stride,
83+ const uint32_t (*const mask)[3],
84+ pixel *dst, const ptrdiff_t ls,
85+ const int starty4, const int endy4)
86+{
87+ const Dav1dDSPContext *const dsp = f->dsp;
88+
89+ // block1
90+ // filter edges between rows (e.g. ------)
91+ // block2
92+ for (int y = starty4; y < endy4;
93+ y++, dst += 4 * PXSTRIDE(ls), lvl += b4_stride)
94+ {
95+ pixel *ptr = dst;
96+ const uint8_t (*l)[4] = lvl;
97+ const uint32_t *const vmask = mask[y];
98+ const unsigned vm = vmask[0] | vmask[1] | vmask[2];
99+
100+ for (unsigned x = 1; vm & ~(x - 1); x <<= 1, ptr += 4, l++) {
101+ if ((have_top || y) && (vm & x)) {
102+ const int L = maxifzero(l, have_top || y, &l[-b4_stride], 1);
103+ if (!L) continue;
104+ const int H = L >> 4;
105+ const int E = f->lf.lim_lut.e[L], I = f->lf.lim_lut.i[L];
106+ const int idx = (vmask[2] & x) ? 2 : !!(vmask[1] & x);
107+
108+ dsp->lf.loop_filter[idx][1](ptr, ls, E, I, H);
109+ }
110+ }
111+ }
112+}
113+
114+static inline void filter_plane_cols_uv(const Dav1dFrameContext *const f,
115+ const int have_left,
116+ const uint8_t (*lvl)[4],
117+ const ptrdiff_t b4_stride,
118+ const uint32_t (*const mask)[2],
119+ pixel *const u, pixel *const v,
120+ const ptrdiff_t ls,
121+ const int starty4, const int endy4)
122+{
123+ const Dav1dDSPContext *const dsp = f->dsp;
124+ int y;
125+ ptrdiff_t off_l;
126+ const int ss_ver = f->cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
127+ const int ss_hor = f->cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
128+ const int hstep = 1 << ss_hor;
129+
130+ // filter edges between columns (e.g. block1 | block2)
131+ lvl += ss_hor + ss_ver * b4_stride;
132+ for (off_l = 0, y = starty4; y < endy4;
133+ y++, off_l += 4 * PXSTRIDE(ls), lvl += b4_stride << ss_ver)
134+ {
135+ ptrdiff_t off = off_l;
136+ const uint8_t (*l)[4] = lvl;
137+ const uint32_t *const hmask = mask[y];
138+ const unsigned hm = hmask[0] | hmask[1];
139+
140+ for (unsigned x = 1; hm & ~(x - 1); l += hstep, x <<= 1, off += 4) {
141+ if ((have_left || x > 1) && (hm & x)) {
142+ const int idx = !!(hmask[1] & x);
143+
144+ const int Lu = maxifzero(l, have_left || x > 1, &l[-hstep], 2);
145+ if (Lu) {
146+ const int H = Lu >> 4;
147+ const int E = f->lf.lim_lut.e[Lu], I = f->lf.lim_lut.i[Lu];
148+
149+ dsp->lf.loop_filter_uv[idx][0](&u[off], ls, E, I, H);
150+ }
151+
152+ const int Lv = maxifzero(l, have_left || x > 1, &l[-hstep], 3);
153+ if (Lv) {
154+ const int H = Lv >> 4;
155+ const int E = f->lf.lim_lut.e[Lv], I = f->lf.lim_lut.i[Lv];
156+
157+ dsp->lf.loop_filter_uv[idx][0](&v[off], ls, E, I, H);
158+ }
159+ }
160+ }
161+ }
162+}
163+
164+static inline void filter_plane_rows_uv(const Dav1dFrameContext *const f,
165+ const int have_top,
166+ const uint8_t (*lvl)[4],
167+ const ptrdiff_t b4_stride,
168+ const uint32_t (*const mask)[2],
169+ pixel *const u, pixel *const v,
170+ const ptrdiff_t ls,
171+ const int starty4, const int endy4)
172+{
173+ const Dav1dDSPContext *const dsp = f->dsp;
174+ int y;
175+ ptrdiff_t off_l;
176+ const int ss_ver = f->cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
177+ const int ss_hor = f->cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
178+ const int hstep = 1 << ss_hor;
179+
180+ // block1
181+ // filter edges between rows (e.g. ------)
182+ // block2
183+ lvl += ss_ver * b4_stride + ss_hor;
184+ for (off_l = 0, y = starty4; y < endy4;
185+ y++, off_l += 4 * PXSTRIDE(ls), lvl += b4_stride << ss_ver)
186+ {
187+ ptrdiff_t off = off_l;
188+ const uint8_t (*l)[4] = lvl;
189+ const uint32_t *const vmask = mask[y];
190+ const unsigned vm = vmask[0] | vmask[1];
191+
192+ for (unsigned x = 1; vm & ~(x - 1); x <<= 1, off += 4, l += hstep) {
193+ if ((have_top || y) && (vm & x)) {
194+ const int idx = !!(vmask[1] & x);
195+
196+ const int Lu = maxifzero(l, have_top || y,
197+ &l[-(b4_stride << ss_ver)], 2);
198+ if (Lu) {
199+ const int H = Lu >> 4;
200+ const int E = f->lf.lim_lut.e[Lu], I = f->lf.lim_lut.i[Lu];
201+
202+ dsp->lf.loop_filter_uv[idx][1](&u[off], ls, E, I, H);
203+ }
204+
205+ const int Lv = maxifzero(l, have_top || y,
206+ &l[-(b4_stride << ss_ver)], 3);
207+ if (Lv) {
208+ const int H = Lv >> 4;
209+ const int E = f->lf.lim_lut.e[Lv], I = f->lf.lim_lut.i[Lv];
210+
211+ dsp->lf.loop_filter_uv[idx][1](&v[off], ls, E, I, H);
212+ }
213+ }
214+ }
215+ }
216+}
217+
218+void bytefn(dav1d_loopfilter_sbrow)(const Dav1dFrameContext *const f,
219+ pixel *const p[3], Av1Filter *const lflvl,
220+ int sby, const int start_of_tile_row)
221+{
222+ int x, have_left;
223+ const int have_top = sby > 0;
224+ const int is_sb64 = !f->seq_hdr.sb128;
225+ const int starty4 = (sby & is_sb64) << 4;
226+ const int sbsz = 32 >> is_sb64;
227+ const int sbl2 = 5 - is_sb64;
228+ const int endy4 = starty4 + imin(f->bh - sby * f->sb_step, sbsz);
229+ const int halign = (f->bh + 31) & ~31;
230+ const int ss_ver = f->cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
231+ const int ss_hor = f->cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
232+
233+ // fix lpf strength at tile col boundaries
234+ const uint8_t *lpf_y = &f->lf.tx_lpf_right_edge[0][sby << sbl2];
235+ const uint8_t *lpf_uv = &f->lf.tx_lpf_right_edge[1][sby << (sbl2 - ss_ver)];
236+ for (int tile_col = 1;; tile_col++) {
237+ x = f->frame_hdr.tiling.col_start_sb[tile_col];
238+ if ((x << sbl2) >= f->bw) break;
239+ const int mask = x & is_sb64 ? 1 << 16 : 1;
240+ const int uv_mask = x & is_sb64 ? 1 << (16 >> ss_hor) : 1;
241+ x >>= is_sb64;
242+ for (int y = starty4; y < endy4; y++) {
243+ const int idx = 2 * !!(lflvl[x].filter_y[0][y][2] & mask) +
244+ !!(lflvl[x].filter_y[0][y][1] & mask);
245+ lflvl[x].filter_y[0][y][2] &= ~mask;
246+ lflvl[x].filter_y[0][y][1] &= ~mask;
247+ lflvl[x].filter_y[0][y][0] &= ~mask;
248+ lflvl[x].filter_y[0][y][imin(idx, lpf_y[y - starty4])] |= mask;
249+ }
250+ for (int y = starty4 >> ss_ver; y < (endy4 >> ss_ver); y++) {
251+ const int idx = !!(lflvl[x].filter_uv[0][y][1] & uv_mask);
252+ lflvl[x].filter_uv[0][y][1] &= ~uv_mask;
253+ lflvl[x].filter_uv[0][y][0] &= ~uv_mask;
254+ lflvl[x].filter_uv[0][y][imin(idx, lpf_uv[y - (starty4 >> ss_ver)])] |= uv_mask;
255+ }
256+ lpf_y += halign;
257+ lpf_uv += halign >> ss_ver;
258+ }
259+
260+ // fix lpf strength at tile row boundaries
261+ if (start_of_tile_row) {
262+ const BlockContext *a;
263+ for (x = 0, a = &f->a[f->sb128w * (start_of_tile_row - 1)];
264+ x < f->sb128w; x++, a++)
265+ {
266+ uint32_t *const y_vmask = lflvl[x].filter_y[1][starty4];
267+ const unsigned y_vm = y_vmask[0] | y_vmask[1] | y_vmask[2];
268+
269+ for (unsigned mask = 1, i = 0; i < 32; mask <<= 1, i++) {
270+ if (!(y_vm & mask)) continue;
271+ const int idx = 2 * !!(y_vmask[2] & mask) + !!(y_vmask[1] & mask);
272+ y_vmask[2] &= ~mask;
273+ y_vmask[1] &= ~mask;
274+ y_vmask[0] &= ~mask;
275+ y_vmask[imin(idx, a->tx_lpf_y[i])] |= mask;
276+ }
277+
278+ uint32_t *const uv_vmask = lflvl[x].filter_uv[1][starty4 >> ss_ver];
279+ const unsigned uv_vm = uv_vmask[0] | uv_vmask[1];
280+ for (unsigned mask = 1, i = 0; i < (32 >> ss_hor); mask <<= 1, i++) {
281+ if (!(uv_vm & mask)) continue;
282+ const int idx = !!(uv_vmask[1] & mask);
283+ uv_vmask[1] &= ~mask;
284+ uv_vmask[0] &= ~mask;
285+ uv_vmask[imin(idx, a->tx_lpf_uv[i])] |= mask;
286+ }
287+ }
288+ }
289+
290+ pixel *ptr;
291+ uint8_t (*level_ptr)[4] = f->lf.level + f->b4_stride * sby * sbsz;
292+ for (ptr = p[0], have_left = 0, x = 0; x < f->sb128w;
293+ x++, have_left = 1, ptr += 128, level_ptr += 32)
294+ {
295+ filter_plane_cols_y(f, have_left, level_ptr, f->b4_stride,
296+ lflvl[x].filter_y[0],
297+ ptr, f->cur.p.stride[0], starty4, endy4);
298+ }
299+
300+ level_ptr = f->lf.level + f->b4_stride * sby * sbsz;
301+ for (ptr = p[0], x = 0; x < f->sb128w; x++, ptr += 128, level_ptr += 32) {
302+ filter_plane_rows_y(f, have_top, level_ptr, f->b4_stride,
303+ lflvl[x].filter_y[1],
304+ ptr, f->cur.p.stride[0], starty4, endy4);
305+ }
306+
307+ if (!f->frame_hdr.loopfilter.level_u && !f->frame_hdr.loopfilter.level_v)
308+ return;
309+
310+ ptrdiff_t uv_off;
311+ level_ptr = f->lf.level + f->b4_stride * sby * sbsz;
312+ for (uv_off = 0, have_left = 0, x = 0; x < f->sb128w;
313+ x++, have_left = 1, uv_off += 128 >> ss_hor, level_ptr += 32)
314+ {
315+ filter_plane_cols_uv(f, have_left, level_ptr, f->b4_stride,
316+ lflvl[x].filter_uv[0],
317+ &p[1][uv_off], &p[2][uv_off], f->cur.p.stride[1],
318+ starty4 >> ss_ver, endy4 >> ss_ver);
319+ }
320+
321+ level_ptr = f->lf.level + f->b4_stride * sby * sbsz;
322+ for (uv_off = 0, x = 0; x < f->sb128w;
323+ x++, uv_off += 128 >> ss_hor, level_ptr += 32)
324+ {
325+ filter_plane_rows_uv(f, have_top, level_ptr, f->b4_stride,
326+ lflvl[x].filter_uv[1],
327+ &p[1][uv_off], &p[2][uv_off], f->cur.p.stride[1],
328+ starty4 >> ss_ver, endy4 >> ss_ver);
329+ }
330+}
src/lf_apply.h+42−0
@@ -0,0 +1,42 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __DAV1D_SRC_LF_APPLY_H__
29+#define __DAV1D_SRC_LF_APPLY_H__
30+
31+#include <stdint.h>
32+
33+#include "common/bitdepth.h"
34+
35+#include "src/internal.h"
36+#include "src/levels.h"
37+
38+void bytefn(dav1d_loopfilter_sbrow)(const Dav1dFrameContext *f,
39+ pixel *const p[3], Av1Filter *lflvl,
40+ int sby, int start_of_tile_row);
41+
42+#endif /* __DAV1D_SRC_LF_APPLY_H__ */
src/lf_mask.c+402−0
@@ -0,0 +1,402 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#include "config.h"
29+
30+#include <assert.h>
31+#include <string.h>
32+
33+#include "common/intops.h"
34+
35+#include "src/levels.h"
36+#include "src/lf_mask.h"
37+#include "src/tables.h"
38+
39+static void decomp_tx(uint8_t (*txa)[2 /* txsz, step */][32 /* y */][32 /* x */],
40+ const enum RectTxfmSize from,
41+ const int depth,
42+ const int y_off, const int x_off,
43+ const uint16_t *const tx_masks)
44+{
45+ const TxfmInfo *const t_dim = &av1_txfm_dimensions[from];
46+ int is_split;
47+
48+ if (depth > 1) {
49+ is_split = 0;
50+ } else {
51+ const int off = y_off * 4 + x_off;
52+ is_split = (tx_masks[depth] >> off) & 1;
53+ }
54+
55+ if (is_split) {
56+ const enum RectTxfmSize sub = t_dim->sub;
57+ const int htw4 = t_dim->w >> 1, hth4 = t_dim->h >> 1;
58+
59+ decomp_tx(txa, sub, depth + 1, y_off * 2 + 0, x_off * 2 + 0, tx_masks);
60+ if (t_dim->w >= t_dim->h)
61+ decomp_tx((uint8_t(*)[2][32][32]) &txa[0][0][0][htw4],
62+ sub, depth + 1, y_off * 2 + 0, x_off * 2 + 1, tx_masks);
63+ if (t_dim->h >= t_dim->w) {
64+ decomp_tx((uint8_t(*)[2][32][32]) &txa[0][0][hth4][0],
65+ sub, depth + 1, y_off * 2 + 1, x_off * 2 + 0, tx_masks);
66+ if (t_dim->w >= t_dim->h)
67+ decomp_tx((uint8_t(*)[2][32][32]) &txa[0][0][hth4][htw4],
68+ sub, depth + 1, y_off * 2 + 1, x_off * 2 + 1, tx_masks);
69+ }
70+ } else {
71+ const int lw = imin(2, t_dim->lw), lh = imin(2, t_dim->lh);
72+ int y;
73+
74+ for (y = 0; y < t_dim->h; y++) {
75+ memset(txa[0][0][y], lw, t_dim->w);
76+ memset(txa[1][0][y], lh, t_dim->w);
77+ txa[0][1][y][0] = t_dim->w;
78+ }
79+ memset(txa[1][1][0], t_dim->h, t_dim->w);
80+ }
81+}
82+
83+static inline void mask_edges_inter(uint32_t (*masks)[32][3],
84+ const int by4, const int bx4,
85+ const int w4, const int h4, const int skip,
86+ const enum RectTxfmSize max_tx,
87+ const uint16_t *const tx_masks,
88+ uint8_t *const a, uint8_t *const l)
89+{
90+ const TxfmInfo *const t_dim = &av1_txfm_dimensions[max_tx];
91+ int y, x;
92+
93+ uint8_t txa[2 /* edge */][2 /* txsz, step */][32 /* y */][32 /* x */];
94+ int y_off, x_off;
95+ for (y_off = 0, y = 0; y < h4; y += t_dim->h, y_off++)
96+ for (x_off = 0, x = 0; x < w4; x += t_dim->w, x_off++)
97+ decomp_tx((uint8_t(*)[2][32][32]) &txa[0][0][y][x],
98+ max_tx, 0, y_off, x_off, tx_masks);
99+
100+ // left block edge
101+ unsigned mask = 1U << bx4;
102+ for (y = 0; y < h4; y++)
103+ masks[0][by4 + y][imin(txa[0][0][y][0], l[y])] |= mask;
104+
105+ // top block edge
106+ for (x = 0; x < w4; x++, mask <<= 1)
107+ masks[1][by4][imin(txa[1][0][0][x], a[x])] |= mask;
108+
109+ if (!skip) {
110+ // inner (tx) left|right edges
111+ for (y = 0; y < h4; y++) {
112+ int ltx = txa[0][0][y][0];
113+ int step = txa[0][1][y][0];
114+ for (x = step, mask = 1U << (bx4 + step);
115+ x < w4; x += step, mask <<= step)
116+ {
117+ const int rtx = txa[0][0][y][x];
118+ masks[0][by4 + y][imin(rtx, ltx)] |= mask;
119+ ltx = rtx;
120+ step = txa[0][1][y][x];
121+ }
122+ }
123+
124+ // top
125+ // inner (tx) --- edges
126+ // bottom
127+ for (x = 0, mask = 1U << bx4; x < w4; x++, mask <<= 1) {
128+ int ttx = txa[1][0][0][x];
129+ int step = txa[1][1][0][x];
130+ for (y = step; y < h4; y += step) {
131+ const int btx = txa[1][0][y][x];
132+ masks[1][by4 + y][imin(ttx, btx)] |= mask;
133+ ttx = btx;
134+ step = txa[1][1][y][x];
135+ }
136+ }
137+ }
138+
139+ for (y = 0; y < h4; y++)
140+ l[y] = txa[0][0][y][w4 - 1];
141+ memcpy(a, txa[1][0][h4 - 1], w4);
142+}
143+
144+static inline void mask_edges_intra(uint32_t (*const masks)[32][3],
145+ const int by4, const int bx4,
146+ const int w4, const int h4,
147+ const enum RectTxfmSize tx,
148+ uint8_t *const a, uint8_t *const l)
149+{
150+ const TxfmInfo *const t_dim = &av1_txfm_dimensions[tx];
151+ const int twl4 = t_dim->lw, thl4 = t_dim->lh;
152+ const int twl4c = imin(2, twl4), thl4c = imin(2, thl4);
153+ int y, x;
154+
155+ // left block edge
156+ unsigned mask = 1U << bx4;
157+ for (y = 0; y < h4; y++)
158+ masks[0][by4 + y][imin(twl4c, l[y])] |= mask;
159+
160+ // top block edge
161+ for (mask = 1U << bx4, x = 0; x < w4; x++, mask <<= 1)
162+ masks[1][by4][imin(thl4c, a[x])] |= mask;
163+
164+ static const uint32_t hstep[] = {
165+ 0xffffffff, 0x55555555, 0x11111111, 0x01010101, 0x00010001
166+ };
167+
168+ // inner (tx) left|right edges
169+ const unsigned t = 1U << bx4;
170+ const unsigned inner = (((uint64_t) t) << w4) - t;
171+ mask = (inner - t) & hstep[twl4];
172+ for (y = 0; y < h4; y++)
173+ masks[0][by4 + y][twl4c] |= mask;
174+
175+ // top
176+ // inner (tx) --- edges
177+ // bottom
178+ const int vstep = t_dim->h;
179+ for (y = vstep; y < h4; y += vstep)
180+ masks[1][by4 + y][thl4c] |= inner;
181+
182+ memset(a, thl4c, w4);
183+ memset(l, twl4c, h4);
184+}
185+
186+static inline void mask_edges_chroma(uint32_t (*const masks)[32][2],
187+ const int cby4, const int cbx4,
188+ const int cw4, const int ch4,
189+ const int skip_inter,
190+ const enum RectTxfmSize tx,
191+ uint8_t *const a, uint8_t *const l)
192+{
193+ const TxfmInfo *const t_dim = &av1_txfm_dimensions[tx];
194+ const int twl4 = t_dim->lw, thl4 = t_dim->lh;
195+ const int twl4c = !!twl4, thl4c = !!thl4;
196+ int y, x;
197+
198+ // left block edge
199+ unsigned mask = 1U << cbx4;
200+ for (y = 0; y < ch4; y++)
201+ masks[0][cby4 + y][imin(twl4c, l[y])] |= mask;
202+
203+ // top block edge
204+ for (mask = 1U << cbx4, x = 0; x < cw4; x++, mask <<= 1)
205+ masks[1][cby4][imin(thl4c, a[x])] |= mask;
206+
207+ if (!skip_inter) {
208+ static const uint32_t hstep[] = {
209+ 0xffffffff, 0x55555555, 0x11111111, 0x01010101
210+ };
211+
212+ // inner (tx) left|right edges
213+ const int t = 1U << cbx4;
214+ const unsigned inner = (((uint64_t) t) << cw4) - t;
215+ mask = (inner - t) & hstep[twl4];
216+ for (y = 0; y < ch4; y++)
217+ masks[0][cby4 + y][twl4c] |= mask;
218+
219+ // top
220+ // inner (tx) --- edges
221+ // bottom
222+ const int vstep = t_dim->h;
223+ for (y = vstep; y < ch4; y += vstep)
224+ masks[1][cby4 + y][thl4c] |= inner;
225+ }
226+
227+ memset(a, thl4c, cw4);
228+ memset(l, twl4c, ch4);
229+}
230+
231+void dav1d_create_lf_mask_intra(Av1Filter *const lflvl,
232+ uint8_t (*level_cache)[4],
233+ const ptrdiff_t b4_stride,
234+ const Av1FrameHeader *const hdr,
235+ const uint8_t (*filter_level)[8][2],
236+ const int bx, const int by,
237+ const int iw, const int ih,
238+ const enum BlockSize bs,
239+ const enum RectTxfmSize ytx,
240+ const enum RectTxfmSize uvtx,
241+ const enum Dav1dPixelLayout layout,
242+ uint8_t *const ay, uint8_t *const ly,
243+ uint8_t *const auv, uint8_t *const luv)
244+{
245+ if (!hdr->loopfilter.level_y[0] && !hdr->loopfilter.level_y[1])
246+ return;
247+
248+ const uint8_t *const b_dim = av1_block_dimensions[bs];
249+ const int bw4 = imin(iw - bx, b_dim[0]);
250+ const int bh4 = imin(ih - by, b_dim[1]);
251+ const int bx4 = bx & 31;
252+ const int by4 = by & 31;
253+
254+ level_cache += by * b4_stride + bx;
255+ for (int y = 0; y < bh4; y++) {
256+ for (int x = 0; x < bw4; x++) {
257+ level_cache[x][0] = filter_level[0][0][0];
258+ level_cache[x][1] = filter_level[1][0][0];
259+ level_cache[x][2] = filter_level[2][0][0];
260+ level_cache[x][3] = filter_level[3][0][0];
261+ }
262+ level_cache += b4_stride;
263+ }
264+
265+ mask_edges_intra(lflvl->filter_y, by4, bx4, bw4, bh4, ytx, ay, ly);
266+
267+ if (!auv) return;
268+
269+ const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420;
270+ const int ss_hor = layout != DAV1D_PIXEL_LAYOUT_I444;
271+ const int cbw4 = (bw4 + ss_hor) >> ss_hor;
272+ const int cbh4 = (bh4 + ss_ver) >> ss_ver;
273+ const int cbx4 = bx4 >> ss_hor;
274+ const int cby4 = by4 >> ss_ver;
275+
276+ mask_edges_chroma(lflvl->filter_uv, cby4, cbx4, cbw4, cbh4, 0, uvtx, auv, luv);
277+}
278+
279+void dav1d_create_lf_mask_inter(Av1Filter *const lflvl,
280+ uint8_t (*level_cache)[4],
281+ const ptrdiff_t b4_stride,
282+ const Av1FrameHeader *const hdr,
283+ const uint8_t (*filter_level)[8][2],
284+ const int bx, const int by,
285+ const int iw, const int ih,
286+ const int skip, const enum BlockSize bs,
287+ const uint16_t *const tx_masks,
288+ const enum RectTxfmSize uvtx,
289+ const enum Dav1dPixelLayout layout,
290+ uint8_t *const ay, uint8_t *const ly,
291+ uint8_t *const auv, uint8_t *const luv)
292+{
293+ if (!hdr->loopfilter.level_y[0] && !hdr->loopfilter.level_y[1])
294+ return;
295+
296+ const uint8_t *const b_dim = av1_block_dimensions[bs];
297+ const int bw4 = imin(iw - bx, b_dim[0]);
298+ const int bh4 = imin(ih - by, b_dim[1]);
299+ const int bx4 = bx & 31;
300+ const int by4 = by & 31;
301+
302+ level_cache += by * b4_stride + bx;
303+ for (int y = 0; y < bh4; y++) {
304+ for (int x = 0; x < bw4; x++) {
305+ level_cache[x][0] = filter_level[0][0][0];
306+ level_cache[x][1] = filter_level[1][0][0];
307+ level_cache[x][2] = filter_level[2][0][0];
308+ level_cache[x][3] = filter_level[3][0][0];
309+ }
310+ level_cache += b4_stride;
311+ }
312+
313+ mask_edges_inter(lflvl->filter_y, by4, bx4, bw4, bh4, skip,
314+ av1_max_txfm_size_for_bs[bs][0], tx_masks, ay, ly);
315+
316+ if (!auv) return;
317+
318+ const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420;
319+ const int ss_hor = layout != DAV1D_PIXEL_LAYOUT_I444;
320+ const int cbw4 = (bw4 + ss_hor) >> ss_hor;
321+ const int cbh4 = (bh4 + ss_ver) >> ss_ver;
322+ const int cbx4 = bx4 >> ss_hor;
323+ const int cby4 = by4 >> ss_ver;
324+
325+ mask_edges_chroma(lflvl->filter_uv, cby4, cbx4, cbw4, cbh4, skip, uvtx, auv, luv);
326+}
327+
328+void dav1d_calc_eih(Av1FilterLUT *const lim_lut, const int filter_sharpness) {
329+ int level;
330+
331+ // set E/I/H values from loopfilter level
332+ for (level = 0; level < 64; level++) {
333+ const int sharp = filter_sharpness;
334+ int limit = level;
335+
336+ if (sharp > 0) {
337+ limit >>= (sharp + 3) >> 2;
338+ limit = imin(limit, 9 - sharp);
339+ }
340+ limit = imax(limit, 1);
341+
342+ lim_lut->i[level] = limit;
343+ lim_lut->e[level] = 2 * (level + 2) + limit;
344+ }
345+}
346+
347+static void dav1d_calc_lf_value(uint8_t (*const lflvl_values)[2],
348+ const int is_chroma, const int base_lvl,
349+ const int lf_delta, const int seg_delta,
350+ const Av1LoopfilterModeRefDeltas *const mr_delta)
351+{
352+ const int base = iclip(iclip(base_lvl + lf_delta, 0, 63) + seg_delta, 0, 63);
353+
354+ if (!base_lvl && is_chroma) {
355+ memset(lflvl_values, 0, 8 * 2);
356+ } else if (!mr_delta) {
357+ memset(lflvl_values, base, 8 * 2);
358+ } else {
359+ const int sh = base >= 32;
360+ lflvl_values[0][0] = lflvl_values[0][1] =
361+ iclip(base + (mr_delta->ref_delta[0] * (1 << sh)), 0, 63);
362+ for (int r = 1; r < 8; r++) {
363+ for (int m = 0; m < 2; m++) {
364+ const int delta =
365+ mr_delta->mode_delta[m] + mr_delta->ref_delta[r];
366+ lflvl_values[r][m] = iclip(base + (delta * (1 << sh)), 0, 63);
367+ }
368+ }
369+ }
370+}
371+
372+void dav1d_calc_lf_values(uint8_t (*const lflvl_values)[4][8][2],
373+ const Av1FrameHeader *const hdr,
374+ const int8_t lf_delta[4])
375+{
376+ const int n_seg = hdr->segmentation.enabled ? 8 : 1;
377+
378+ if (!hdr->loopfilter.level_y[0] && !hdr->loopfilter.level_y[1]) {
379+ memset(lflvl_values, 0, 8 * 4 * 2 * n_seg);
380+ return;
381+ }
382+
383+ const Av1LoopfilterModeRefDeltas *const mr_deltas =
384+ hdr->loopfilter.mode_ref_delta_enabled ?
385+ &hdr->loopfilter.mode_ref_deltas : NULL;
386+ for (int s = 0; s < n_seg; s++) {
387+ const Av1SegmentationData *const segd =
388+ hdr->segmentation.enabled ? &hdr->segmentation.seg_data.d[s] : NULL;
389+
390+ dav1d_calc_lf_value(lflvl_values[s][0], 0, hdr->loopfilter.level_y[0],
391+ lf_delta[0], segd ? segd->delta_lf_y_v : 0, mr_deltas);
392+ dav1d_calc_lf_value(lflvl_values[s][1], 0, hdr->loopfilter.level_y[1],
393+ lf_delta[hdr->delta_lf_multi ? 1 : 0],
394+ segd ? segd->delta_lf_y_h : 0, mr_deltas);
395+ dav1d_calc_lf_value(lflvl_values[s][2], 1, hdr->loopfilter.level_u,
396+ lf_delta[hdr->delta_lf_multi ? 2 : 0],
397+ segd ? segd->delta_lf_u : 0, mr_deltas);
398+ dav1d_calc_lf_value(lflvl_values[s][3], 1, hdr->loopfilter.level_v,
399+ lf_delta[hdr->delta_lf_multi ? 3 : 0],
400+ segd ? segd->delta_lf_v : 0, mr_deltas);
401+ }
402+}
src/lf_mask.h+80−0
@@ -0,0 +1,80 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __DAV1D_SRC_LF_MASK_H__
29+#define __DAV1D_SRC_LF_MASK_H__
30+
31+#include <stddef.h>
32+#include <stdint.h>
33+
34+#include "src/levels.h"
35+
36+typedef struct Av1FilterLUT {
37+ uint8_t e[64];
38+ uint8_t i[64];
39+} Av1FilterLUT;
40+
41+typedef struct Av1RestorationUnit {
42+ enum RestorationType type;
43+ int16_t filter_h[3];
44+ int16_t filter_v[3];
45+ uint8_t sgr_idx;
46+ int16_t sgr_weights[2];
47+} Av1RestorationUnit;
48+
49+// each struct describes one 128x128 area (1 or 4 SBs)
50+typedef struct Av1Filter {
51+ // each bit is 1 col
52+ uint32_t filter_y[2 /* 0=col, 1=row */][32][3];
53+ uint32_t filter_uv[2 /* 0=col, 1=row */][32][2];
54+ int8_t cdef_idx[4]; // -1 means "unset"
55+ uint32_t noskip_mask[32];
56+ Av1RestorationUnit lr[3][4];
57+} Av1Filter;
58+
59+void dav1d_create_lf_mask_intra(Av1Filter *lflvl, uint8_t (*level_cache)[4],
60+ const ptrdiff_t b4_stride,
61+ const Av1FrameHeader *hdr,
62+ const uint8_t (*level)[8][2], int bx, int by,
63+ int iw, int ih, enum BlockSize bs,
64+ enum RectTxfmSize ytx, enum RectTxfmSize uvtx,
65+ enum Dav1dPixelLayout layout, uint8_t *ay,
66+ uint8_t *ly, uint8_t *auv, uint8_t *luv);
67+void dav1d_create_lf_mask_inter(Av1Filter *lflvl, uint8_t (*level_cache)[4],
68+ const ptrdiff_t b4_stride,
69+ const Av1FrameHeader *hdr,
70+ const uint8_t (*level)[8][2], int bx, int by,
71+ int iw, int ih, int skip_inter,
72+ enum BlockSize bs, const uint16_t *tx_mask,
73+ enum RectTxfmSize uvtx,
74+ enum Dav1dPixelLayout layout, uint8_t *ay,
75+ uint8_t *ly, uint8_t *auv, uint8_t *luv);
76+void dav1d_calc_eih(Av1FilterLUT *lim_lut, int filter_sharpness);
77+void dav1d_calc_lf_values(uint8_t (*values)[4][8][2], const Av1FrameHeader *hdr,
78+ const int8_t lf_delta[4]);
79+
80+#endif /* __DAV1D_SRC_LF_MASK_H__ */
src/lib.c+297−0
@@ -0,0 +1,297 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#include "config.h"
29+
30+#include <errno.h>
31+#include <string.h>
32+
33+#include "dav1d/dav1d.h"
34+#include "dav1d/data.h"
35+
36+#include "include/version.h"
37+
38+#include "common/mem.h"
39+#include "common/validate.h"
40+
41+#include "src/internal.h"
42+#include "src/obu.h"
43+#include "src/qm.h"
44+#include "src/ref.h"
45+#include "src/thread_task.h"
46+#include "src/wedge.h"
47+
48+void dav1d_init(void) {
49+ av1_init_wedge_masks();
50+ av1_init_interintra_masks();
51+ av1_init_qm_tables();
52+}
53+
54+const char *dav1d_version(void) {
55+ return DAV1D_VERSION;
56+}
57+
58+void dav1d_default_settings(Dav1dSettings *const s) {
59+ s->n_frame_threads = 1;
60+ s->n_tile_threads = 1;
61+}
62+
63+int dav1d_open(Dav1dContext **const c_out,
64+ const Dav1dSettings *const s)
65+{
66+ validate_input_or_ret(c_out != NULL, -EINVAL);
67+ validate_input_or_ret(s != NULL, -EINVAL);
68+ validate_input_or_ret(s->n_tile_threads >= 1 &&
69+ s->n_tile_threads <= 64, -EINVAL);
70+ validate_input_or_ret(s->n_frame_threads >= 1 &&
71+ s->n_frame_threads <= 256, -EINVAL);
72+
73+ Dav1dContext *const c = *c_out = dav1d_alloc_aligned(sizeof(*c), 32);
74+ if (!c) goto error;
75+ memset(c, 0, sizeof(*c));
76+
77+ c->n_fc = s->n_frame_threads;
78+ c->fc = dav1d_alloc_aligned(sizeof(*c->fc) * s->n_frame_threads, 32);
79+ if (!c->fc) goto error;
80+ memset(c->fc, 0, sizeof(*c->fc) * s->n_frame_threads);
81+ if (c->n_fc > 1) {
82+ c->frame_thread.out_delayed =
83+ malloc(sizeof(*c->frame_thread.out_delayed) * c->n_fc);
84+ memset(c->frame_thread.out_delayed, 0,
85+ sizeof(*c->frame_thread.out_delayed) * c->n_fc);
86+ }
87+ for (int n = 0; n < s->n_frame_threads; n++) {
88+ Dav1dFrameContext *const f = &c->fc[n];
89+ f->c = c;
90+ f->lf.last_sharpness = -1;
91+ f->n_tc = s->n_tile_threads;
92+ f->tc = dav1d_alloc_aligned(sizeof(*f->tc) * s->n_tile_threads, 32);
93+ if (!f->tc) goto error;
94+ memset(f->tc, 0, sizeof(*f->tc) * s->n_tile_threads);
95+ if (f->n_tc > 1) {
96+ pthread_mutex_init(&f->tile_thread.lock, NULL);
97+ pthread_cond_init(&f->tile_thread.cond, NULL);
98+ pthread_cond_init(&f->tile_thread.icond, NULL);
99+ }
100+ for (int m = 0; m < s->n_tile_threads; m++) {
101+ Dav1dTileContext *const t = &f->tc[m];
102+ t->f = f;
103+ t->cf = dav1d_alloc_aligned(32 * 32 * sizeof(int32_t), 32);
104+ if (!t->cf) goto error;
105+ t->scratch.mem = dav1d_alloc_aligned(128 * 128 * 8, 32);
106+ if (!t->scratch.mem) goto error;
107+ memset(t->cf, 0, 32 * 32 * sizeof(int32_t));
108+ t->emu_edge =
109+ dav1d_alloc_aligned(160 * (128 + 7) * sizeof(uint16_t), 32);
110+ if (!t->emu_edge) goto error;
111+ if (f->n_tc > 1) {
112+ pthread_mutex_init(&t->tile_thread.td.lock, NULL);
113+ pthread_cond_init(&t->tile_thread.td.cond, NULL);
114+ t->tile_thread.fttd = &f->tile_thread;
115+ pthread_create(&t->tile_thread.td.thread, NULL, dav1d_tile_task, t);
116+ }
117+ }
118+ f->libaom_cm = av1_alloc_ref_mv_common();
119+ if (c->n_fc > 1) {
120+ pthread_mutex_init(&f->frame_thread.td.lock, NULL);
121+ pthread_cond_init(&f->frame_thread.td.cond, NULL);
122+ pthread_create(&f->frame_thread.td.thread, NULL, dav1d_frame_task, f);
123+ }
124+ }
125+
126+ // intra edge tree
127+ c->intra_edge.root[BL_128X128] = &c->intra_edge.branch_sb128[0].node;
128+ init_mode_tree(c->intra_edge.root[BL_128X128], c->intra_edge.tip_sb128, 1);
129+ c->intra_edge.root[BL_64X64] = &c->intra_edge.branch_sb64[0].node;
130+ init_mode_tree(c->intra_edge.root[BL_64X64], c->intra_edge.tip_sb64, 0);
131+
132+ return 0;
133+
134+error:
135+ if (c) {
136+ if (c->fc) {
137+ for (int n = 0; n < c->n_fc; n++)
138+ if (c->fc[n].tc)
139+ free(c->fc[n].tc);
140+ free(c->fc);
141+ }
142+ free(c);
143+ }
144+ fprintf(stderr, "Failed to allocate memory: %s\n", strerror(errno));
145+ return -ENOMEM;
146+}
147+
148+int dav1d_decode(Dav1dContext *const c,
149+ Dav1dData *const in, Dav1dPicture *const out)
150+{
151+ int res;
152+
153+ validate_input_or_ret(c != NULL, -EINVAL);
154+ validate_input_or_ret(out != NULL, -EINVAL);
155+
156+ while (!in) {
157+ if (c->n_fc == 1) return -EAGAIN;
158+
159+ // flush
160+ const unsigned next = c->frame_thread.next;
161+ Dav1dFrameContext *const f = &c->fc[next];
162+
163+ pthread_mutex_lock(&f->frame_thread.td.lock);
164+ while (f->n_tile_data > 0)
165+ pthread_cond_wait(&f->frame_thread.td.cond,
166+ &f->frame_thread.td.lock);
167+ pthread_mutex_unlock(&f->frame_thread.td.lock);
168+ Dav1dThreadPicture *const out_delayed =
169+ &c->frame_thread.out_delayed[next];
170+ if (out_delayed->p.data[0]) {
171+ if (++c->frame_thread.next == c->n_fc)
172+ c->frame_thread.next = 0;
173+ if (out_delayed->visible) {
174+ dav1d_picture_ref(out, &out_delayed->p);
175+ }
176+ dav1d_thread_picture_unref(out_delayed);
177+ if (out->data[0]) {
178+ return 0;
179+ }
180+ // else continue
181+ } else {
182+ return -EAGAIN;
183+ }
184+ }
185+
186+ while (in->sz > 0) {
187+ if ((res = parse_obus(c, in)) < 0)
188+ return res;
189+
190+ assert(res <= in->sz);
191+ in->sz -= res;
192+ in->data += res;
193+ if (c->out.data[0]) {
194+ if (!in->sz) dav1d_data_unref(in);
195+ dav1d_picture_ref(out, &c->out);
196+ dav1d_picture_unref(&c->out);
197+ return 0;
198+ }
199+ }
200+
201+ if (c->out.data[0]) {
202+ dav1d_picture_ref(out, &c->out);
203+ dav1d_picture_unref(&c->out);
204+ return 0;
205+ }
206+
207+ return -EAGAIN;
208+}
209+
210+void dav1d_close(Dav1dContext *const c) {
211+ validate_input(c != NULL);
212+
213+ for (int n = 0; n < c->n_fc; n++) {
214+ Dav1dFrameContext *const f = &c->fc[n];
215+
216+ // clean-up threading stuff
217+ if (c->n_fc > 1) {
218+ pthread_mutex_lock(&f->frame_thread.td.lock);
219+ f->frame_thread.die = 1;
220+ pthread_cond_signal(&f->frame_thread.td.cond);
221+ pthread_mutex_unlock(&f->frame_thread.td.lock);
222+ pthread_join(f->frame_thread.td.thread, NULL);
223+ freep(&f->frame_thread.b);
224+ dav1d_free_aligned(&f->frame_thread.pal_idx);
225+ dav1d_free_aligned(&f->frame_thread.cf);
226+ freep(&f->frame_thread.tile_start_off);
227+ freep(&f->frame_thread.pal);
228+ freep(&f->frame_thread.cbi);
229+ pthread_mutex_destroy(&f->frame_thread.td.lock);
230+ pthread_cond_destroy(&f->frame_thread.td.cond);
231+ }
232+ if (f->n_tc > 1) {
233+ pthread_mutex_lock(&f->tile_thread.lock);
234+ for (int m = 0; m < f->n_tc; m++) {
235+ Dav1dTileContext *const t = &f->tc[m];
236+ t->tile_thread.die = 1;
237+ }
238+ pthread_cond_broadcast(&f->tile_thread.cond);
239+ while (f->tile_thread.available != (1 << f->n_tc) - 1)
240+ pthread_cond_wait(&f->tile_thread.icond,
241+ &f->tile_thread.lock);
242+ pthread_mutex_unlock(&f->tile_thread.lock);
243+ for (int m = 0; m < f->n_tc; m++) {
244+ Dav1dTileContext *const t = &f->tc[m];
245+ if (f->n_tc > 1) {
246+ pthread_join(t->tile_thread.td.thread, NULL);
247+ pthread_mutex_destroy(&t->tile_thread.td.lock);
248+ pthread_cond_destroy(&t->tile_thread.td.cond);
249+ }
250+ }
251+ pthread_mutex_destroy(&f->tile_thread.lock);
252+ pthread_cond_destroy(&f->tile_thread.cond);
253+ pthread_cond_destroy(&f->tile_thread.icond);
254+ }
255+ for (int m = 0; m < f->n_tc; m++) {
256+ Dav1dTileContext *const t = &f->tc[m];
257+ dav1d_free_aligned(t->cf);
258+ dav1d_free_aligned(t->scratch.mem);
259+ dav1d_free_aligned(t->emu_edge);
260+ }
261+ for (int m = 0; m < f->n_ts; m++) {
262+ Dav1dTileState *const ts = &f->ts[m];
263+ pthread_cond_destroy(&ts->tile_thread.cond);
264+ pthread_mutex_destroy(&ts->tile_thread.lock);
265+ }
266+ free(f->ts);
267+ dav1d_free_aligned(f->tc);
268+ dav1d_free_aligned(f->ipred_edge[0]);
269+ free(f->a);
270+ free(f->lf.mask);
271+ free(f->lf.level);
272+ free(f->lf.tx_lpf_right_edge[0]);
273+ av1_free_ref_mv_common(f->libaom_cm);
274+ dav1d_free_aligned(f->lf.cdef_line);
275+ dav1d_free_aligned(f->lf.lr_lpf_line);
276+ }
277+ dav1d_free_aligned(c->fc);
278+ if (c->n_fc > 1) {
279+ for (int n = 0; n < c->n_fc; n++)
280+ if (c->frame_thread.out_delayed[n].p.data[0])
281+ dav1d_thread_picture_unref(&c->frame_thread.out_delayed[n]);
282+ free(c->frame_thread.out_delayed);
283+ }
284+ for (int n = 0; n < c->n_tile_data; n++)
285+ dav1d_data_unref(&c->tile[n].data);
286+ for (int n = 0; n < 8; n++) {
287+ if (c->cdf[n].cdf)
288+ cdf_thread_unref(&c->cdf[n]);
289+ if (c->refs[n].p.p.data[0])
290+ dav1d_thread_picture_unref(&c->refs[n].p);
291+ if (c->refs[n].refmvs)
292+ dav1d_ref_dec(c->refs[n].refmvs);
293+ if (c->refs[n].segmap)
294+ dav1d_ref_dec(c->refs[n].segmap);
295+ }
296+ dav1d_free_aligned(c);
297+}
src/loopfilter.c+195−0
@@ -0,0 +1,195 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#include "config.h"
29+
30+#include <stdlib.h>
31+
32+#include "common/intops.h"
33+
34+#include "src/loopfilter.h"
35+
36+static __attribute__((noinline)) void
37+loop_filter(pixel *dst, int E, int I, int H,
38+ const ptrdiff_t stridea, const ptrdiff_t strideb, const int wd)
39+{
40+ int i, F = 1 << (BITDEPTH - 8);
41+
42+ E <<= BITDEPTH - 8;
43+ I <<= BITDEPTH - 8;
44+ H <<= BITDEPTH - 8;
45+
46+ for (i = 0; i < 4; i++, dst += stridea) {
47+ int p6, p5, p4, p3, p2;
48+ int p1 = dst[strideb * -2], p0 = dst[strideb * -1];
49+ int q0 = dst[strideb * +0], q1 = dst[strideb * +1];
50+ int q2, q3, q4, q5, q6;
51+ int fm, flat8out, flat8in;
52+
53+ fm = abs(p1 - p0) <= I && abs(q1 - q0) <= I &&
54+ abs(p0 - q0) * 2 + (abs(p1 - q1) >> 1) <= E;
55+
56+ if (wd > 4) {
57+ p2 = dst[strideb * -3];
58+ q2 = dst[strideb * +2];
59+
60+ fm &= abs(p2 - p1) <= I && abs(q2 - q1) <= I;
61+
62+ if (wd > 6) {
63+ p3 = dst[strideb * -4];
64+ q3 = dst[strideb * +3];
65+
66+ fm &= abs(p3 - p2) <= I && abs(q3 - q2) <= I;
67+ }
68+ }
69+
70+ if (!fm) continue;
71+
72+ if (wd >= 16) {
73+ p6 = dst[strideb * -7];
74+ p5 = dst[strideb * -6];
75+ p4 = dst[strideb * -5];
76+ q4 = dst[strideb * +4];
77+ q5 = dst[strideb * +5];
78+ q6 = dst[strideb * +6];
79+
80+ flat8out = abs(p6 - p0) <= F && abs(p5 - p0) <= F &&
81+ abs(p4 - p0) <= F && abs(q4 - q0) <= F &&
82+ abs(q5 - q0) <= F && abs(q6 - q0) <= F;
83+ }
84+
85+ if (wd >= 6)
86+ flat8in = abs(p2 - p0) <= F && abs(p1 - p0) <= F &&
87+ abs(q1 - q0) <= F && abs(q2 - q0) <= F;
88+
89+ if (wd >= 8)
90+ flat8in &= abs(p3 - p0) <= F && abs(q3 - q0) <= F;
91+
92+ if (wd >= 16 && (flat8out & flat8in)) {
93+ dst[strideb * -6] = (p6 + p6 + p6 + p6 + p6 + p6 * 2 + p5 * 2 +
94+ p4 * 2 + p3 + p2 + p1 + p0 + q0 + 8) >> 4;
95+ dst[strideb * -5] = (p6 + p6 + p6 + p6 + p6 + p5 * 2 + p4 * 2 +
96+ p3 * 2 + p2 + p1 + p0 + q0 + q1 + 8) >> 4;
97+ dst[strideb * -4] = (p6 + p6 + p6 + p6 + p5 + p4 * 2 + p3 * 2 +
98+ p2 * 2 + p1 + p0 + q0 + q1 + q2 + 8) >> 4;
99+ dst[strideb * -3] = (p6 + p6 + p6 + p5 + p4 + p3 * 2 + p2 * 2 +
100+ p1 * 2 + p0 + q0 + q1 + q2 + q3 + 8) >> 4;
101+ dst[strideb * -2] = (p6 + p6 + p5 + p4 + p3 + p2 * 2 + p1 * 2 +
102+ p0 * 2 + q0 + q1 + q2 + q3 + q4 + 8) >> 4;
103+ dst[strideb * -1] = (p6 + p5 + p4 + p3 + p2 + p1 * 2 + p0 * 2 +
104+ q0 * 2 + q1 + q2 + q3 + q4 + q5 + 8) >> 4;
105+ dst[strideb * +0] = (p5 + p4 + p3 + p2 + p1 + p0 * 2 + q0 * 2 +
106+ q1 * 2 + q2 + q3 + q4 + q5 + q6 + 8) >> 4;
107+ dst[strideb * +1] = (p4 + p3 + p2 + p1 + p0 + q0 * 2 + q1 * 2 +
108+ q2 * 2 + q3 + q4 + q5 + q6 + q6 + 8) >> 4;
109+ dst[strideb * +2] = (p3 + p2 + p1 + p0 + q0 + q1 * 2 + q2 * 2 +
110+ q3 * 2 + q4 + q5 + q6 + q6 + q6 + 8) >> 4;
111+ dst[strideb * +3] = (p2 + p1 + p0 + q0 + q1 + q2 * 2 + q3 * 2 +
112+ q4 * 2 + q5 + q6 + q6 + q6 + q6 + 8) >> 4;
113+ dst[strideb * +4] = (p1 + p0 + q0 + q1 + q2 + q3 * 2 + q4 * 2 +
114+ q5 * 2 + q6 + q6 + q6 + q6 + q6 + 8) >> 4;
115+ dst[strideb * +5] = (p0 + q0 + q1 + q2 + q3 + q4 * 2 + q5 * 2 +
116+ q6 * 2 + q6 + q6 + q6 + q6 + q6 + 8) >> 4;
117+ } else if (wd >= 8 && flat8in) {
118+ dst[strideb * -3] = (p3 + p3 + p3 + 2 * p2 + p1 + p0 + q0 + 4) >> 3;
119+ dst[strideb * -2] = (p3 + p3 + p2 + 2 * p1 + p0 + q0 + q1 + 4) >> 3;
120+ dst[strideb * -1] = (p3 + p2 + p1 + 2 * p0 + q0 + q1 + q2 + 4) >> 3;
121+ dst[strideb * +0] = (p2 + p1 + p0 + 2 * q0 + q1 + q2 + q3 + 4) >> 3;
122+ dst[strideb * +1] = (p1 + p0 + q0 + 2 * q1 + q2 + q3 + q3 + 4) >> 3;
123+ dst[strideb * +2] = (p0 + q0 + q1 + 2 * q2 + q3 + q3 + q3 + 4) >> 3;
124+ } else if (wd == 6 && flat8in) {
125+ dst[strideb * -2] = (p2 + 2 * p2 + 2 * p1 + 2 * p0 + q0 + 4) >> 3;
126+ dst[strideb * -1] = (p2 + 2 * p1 + 2 * p0 + 2 * q0 + q1 + 4) >> 3;
127+ dst[strideb * +0] = (p1 + 2 * p0 + 2 * q0 + 2 * q1 + q2 + 4) >> 3;
128+ dst[strideb * +1] = (p0 + 2 * q0 + 2 * q1 + 2 * q2 + q2 + 4) >> 3;
129+ } else {
130+ int hev = abs(p1 - p0) > H || abs(q1 - q0) > H;
131+
132+#define iclip_diff(v) iclip(v, -128 * (1 << (BITDEPTH - 8)), \
133+ 127 * (1 << (BITDEPTH - 8)))
134+
135+ if (hev) {
136+ int f = iclip_diff(p1 - q1), f1, f2;
137+ f = iclip_diff(3 * (q0 - p0) + f);
138+
139+ f1 = imin(f + 4, 127) >> 3;
140+ f2 = imin(f + 3, 127) >> 3;
141+
142+ dst[strideb * -1] = iclip_pixel(p0 + f2);
143+ dst[strideb * +0] = iclip_pixel(q0 - f1);
144+ } else {
145+ int f = iclip_diff(3 * (q0 - p0)), f1, f2;
146+
147+ f1 = imin(f + 4, 127) >> 3;
148+ f2 = imin(f + 3, 127) >> 3;
149+
150+ dst[strideb * -1] = iclip_pixel(p0 + f2);
151+ dst[strideb * +0] = iclip_pixel(q0 - f1);
152+
153+ f = (f1 + 1) >> 1;
154+ dst[strideb * -2] = iclip_pixel(p1 + f);
155+ dst[strideb * +1] = iclip_pixel(q1 - f);
156+ }
157+#undef iclip_diff
158+ }
159+ }
160+}
161+
162+#define lf_4_fn(dir, wd, stridea, strideb) \
163+static void loop_filter_##dir##_##wd##wd_4px_c(pixel *const dst, \
164+ const ptrdiff_t stride, \
165+ const int E, const int I, \
166+ const int H) \
167+{ \
168+ loop_filter(dst, E, I, H, stridea, strideb, wd); \
169+}
170+
171+#define lf_4_fns(wd) \
172+lf_4_fn(h, wd, PXSTRIDE(stride), 1) \
173+lf_4_fn(v, wd, 1, PXSTRIDE(stride))
174+
175+lf_4_fns(4)
176+lf_4_fns(6)
177+lf_4_fns(8)
178+lf_4_fns(16)
179+
180+#undef lf_4_fn
181+#undef lf_4_fns
182+
183+void bitfn(dav1d_loop_filter_dsp_init)(Dav1dLoopFilterDSPContext *const c) {
184+ c->loop_filter[0][0] = loop_filter_h_4wd_4px_c;
185+ c->loop_filter[0][1] = loop_filter_v_4wd_4px_c;
186+ c->loop_filter[1][0] = loop_filter_h_8wd_4px_c;
187+ c->loop_filter[1][1] = loop_filter_v_8wd_4px_c;
188+ c->loop_filter[2][0] = loop_filter_h_16wd_4px_c;
189+ c->loop_filter[2][1] = loop_filter_v_16wd_4px_c;
190+
191+ c->loop_filter_uv[0][0] = loop_filter_h_4wd_4px_c;
192+ c->loop_filter_uv[0][1] = loop_filter_v_4wd_4px_c;
193+ c->loop_filter_uv[1][0] = loop_filter_h_6wd_4px_c;
194+ c->loop_filter_uv[1][1] = loop_filter_v_6wd_4px_c;
195+}
src/loopfilter.h+56−0
@@ -0,0 +1,56 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __DAV1D_SRC_LOOPFILTER_H__
29+#define __DAV1D_SRC_LOOPFILTER_H__
30+
31+#include <stdint.h>
32+#include <stddef.h>
33+
34+#include "common/bitdepth.h"
35+
36+#include "src/levels.h"
37+
38+#define decl_loopfilter_fn(name) \
39+void (name)(pixel *dst, ptrdiff_t stride, int mb_lim, int lim, int hev_thr);
40+typedef decl_loopfilter_fn(*loopfilter_fn);
41+
42+typedef struct Dav1dLoopFilterDSPContext {
43+ /*
44+ * dimension 1: filter taps (0=4, 1=8, 2=16 for luma; 0=4, 1=6 for chroma)
45+ * dimension 2: 0=col-edge filter (h), 1=row-edge filter (v)
46+ *
47+ * dst/stride are aligned by 4
48+ */
49+ loopfilter_fn loop_filter[3][2];
50+ loopfilter_fn loop_filter_uv[2][2];
51+} Dav1dLoopFilterDSPContext;
52+
53+void dav1d_loop_filter_dsp_init_8bpc(Dav1dLoopFilterDSPContext *c);
54+void dav1d_loop_filter_dsp_init_10bpc(Dav1dLoopFilterDSPContext *c);
55+
56+#endif /* __DAV1D_SRC_LOOPFILTER_H__ */
src/looprestoration.c+577−0
@@ -0,0 +1,577 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#include "config.h"
29+
30+#include <stdlib.h>
31+
32+#include "common/intops.h"
33+
34+#include "src/looprestoration.h"
35+#include "src/tables.h"
36+
37+
38+// TODO Reuse p when no padding is needed (add and remove lpf pixels in p)
39+// TODO Chroma only requires 2 rows of padding.
40+static void padding(pixel *dst, const ptrdiff_t dst_stride,
41+ const pixel *p, const ptrdiff_t p_stride,
42+ const pixel *lpf, const ptrdiff_t lpf_stride,
43+ int unit_w, const int stripe_h, const enum LrEdgeFlags edges)
44+{
45+ const int have_left = !!(edges & LR_HAVE_LEFT);
46+ const int have_right = !!(edges & LR_HAVE_RIGHT);
47+
48+ // Copy more pixels if we don't have to pad them
49+ unit_w += 3 * have_left + 3 * have_right;
50+ pixel *dst_l = dst + 3 * !have_left;
51+ p -= 3 * have_left;
52+ lpf -= 3 * have_left;
53+
54+ if (edges & LR_HAVE_TOP) {
55+ // Copy previous loop filtered rows
56+ const pixel *const above_1 = lpf;
57+ const pixel *const above_2 = above_1 + PXSTRIDE(lpf_stride);
58+ pixel_copy(dst_l, above_1, unit_w);
59+ pixel_copy(dst_l + PXSTRIDE(dst_stride), above_1, unit_w);
60+ pixel_copy(dst_l + 2 * PXSTRIDE(dst_stride), above_2, unit_w);
61+ } else {
62+ // Pad with first row
63+ pixel_copy(dst_l, p, unit_w);
64+ pixel_copy(dst_l + PXSTRIDE(dst_stride), p, unit_w);
65+ pixel_copy(dst_l + 2 * PXSTRIDE(dst_stride), p, unit_w);
66+ }
67+
68+ pixel *dst_tl = dst_l + 3 * PXSTRIDE(dst_stride);
69+ if (edges & LR_HAVE_BOTTOM) {
70+ // Copy next loop filtered rows
71+ const pixel *const below_1 = lpf + 6 * PXSTRIDE(lpf_stride);
72+ const pixel *const below_2 = below_1 + PXSTRIDE(lpf_stride);
73+ pixel_copy(dst_tl + stripe_h * PXSTRIDE(dst_stride), below_1, unit_w);
74+ pixel_copy(dst_tl + (stripe_h + 1) * PXSTRIDE(dst_stride), below_2, unit_w);
75+ pixel_copy(dst_tl + (stripe_h + 2) * PXSTRIDE(dst_stride), below_2, unit_w);
76+ } else {
77+ // Pad with last row
78+ const pixel *const src = p + (stripe_h - 1) * PXSTRIDE(p_stride);
79+ pixel_copy(dst_tl + stripe_h * PXSTRIDE(dst_stride), src, unit_w);
80+ pixel_copy(dst_tl + (stripe_h + 1) * PXSTRIDE(dst_stride), src, unit_w);
81+ pixel_copy(dst_tl + (stripe_h + 2) * PXSTRIDE(dst_stride), src, unit_w);
82+ }
83+
84+ // Inner UNIT_WxSTRIPE_H
85+ for (int j = 0; j < stripe_h; j++) {
86+ pixel_copy(dst_tl, p, unit_w);
87+ dst_tl += PXSTRIDE(dst_stride);
88+ p += PXSTRIDE(p_stride);
89+ }
90+
91+ if (!have_right) {
92+ pixel *pad = dst_l + unit_w;
93+ pixel *row_last = &dst_l[unit_w - 1];
94+ // Pad 3x(STRIPE_H+6) with last column
95+ for (int j = 0; j < stripe_h + 6; j++) {
96+ pixel_set(pad, *row_last, 3);
97+ pad += PXSTRIDE(dst_stride);
98+ row_last += PXSTRIDE(dst_stride);
99+ }
100+ }
101+
102+ if (!have_left) {
103+ // Pad 3x(STRIPE_H+6) with first column
104+ for (int j = 0; j < stripe_h + 6; j++) {
105+ pixel_set(dst, *dst_l, 3);
106+ dst += PXSTRIDE(dst_stride);
107+ dst_l += PXSTRIDE(dst_stride);
108+ }
109+ }
110+}
111+
112+// FIXME Could split into luma and chroma specific functions,
113+// (since first and last tops are always 0 for chroma)
114+// FIXME Could implement a version that requires less temporary memory
115+// (should be possible to implement with only 6 rows of temp storage)
116+static void wiener_c(pixel *p, const ptrdiff_t p_stride,
117+ const pixel *lpf, const ptrdiff_t lpf_stride,
118+ const int w, const int h,
119+ const int16_t filterh[7], const int16_t filterv[7],
120+ const enum LrEdgeFlags edges)
121+{
122+ // padding is 3 pixels above and 3 pixels below
123+ const ptrdiff_t tmp_stride = sizeof(pixel) * (w + 6);
124+ pixel tmp[(h + 6) * PXSTRIDE(tmp_stride)];
125+ pixel *tmp_ptr = tmp;
126+
127+ padding(tmp, tmp_stride, p, p_stride, lpf, lpf_stride, w, h, edges);
128+
129+ // Values stored between horizontal and vertical filtering don't
130+ // fit in a uint8_t.
131+ uint16_t hor[(h + 6 /*padding*/) * w];
132+ uint16_t *hor_ptr = hor;
133+
134+ const int round_bits_h = 3 + (BITDEPTH == 12) * 2;
135+ const int rounding_off_h = 1 << (round_bits_h - 1);
136+ const int clip_limit = 1 << ((BITDEPTH) + 1 + 7 - round_bits_h);
137+ for (int j = 0; j < h + 6; j++) {
138+ for (int i = 0; i < w; i++) {
139+ int sum = (tmp_ptr[i + 3] << 7) + (1 << (BITDEPTH + 6));
140+
141+ for (int k = 0; k < 7; k++) {
142+ sum += tmp_ptr[i + k] * filterh[k];
143+ }
144+
145+ hor_ptr[i] =
146+ iclip((sum + rounding_off_h) >> round_bits_h, 0, clip_limit);
147+ }
148+ tmp_ptr += PXSTRIDE(tmp_stride);
149+ hor_ptr += w;
150+ }
151+
152+ const int round_bits_v = 11 - (BITDEPTH == 12) * 2;
153+ const int rounding_off_v = 1 << (round_bits_v - 1);
154+ const int round_offset = 1 << (BITDEPTH + (round_bits_v - 1));
155+ for (int i = 0; i < w; i++) {
156+ for (int j = 0; j < h; j++) {
157+ int sum = (hor[w * (j + 3) + i] << 7) - round_offset;
158+
159+ for (int k = 0; k < 7; k++) {
160+ sum += hor[(j + k) * w + i] * filterv[k];
161+ }
162+
163+ p[j * PXSTRIDE(p_stride) + i] =
164+ iclip_pixel((sum + rounding_off_v) >> round_bits_v);
165+ }
166+ }
167+}
168+
169+// Sum over a 3x3 area
170+// The dst and src pointers are positioned 3 pixels above and 3 pixels to the
171+// left of the top left corner. However, the self guided filter only needs 1
172+// pixel above and one pixel to the left. As for the pixels below and to the
173+// right they must be computed in the sums, but don't need to be stored.
174+//
175+// Example for a 4x4 block:
176+// x x x x x x x x x x
177+// x c c c c c c c c x
178+// x i s s s s s s i x
179+// x i s s s s s s i x
180+// x i s s s s s s i x
181+// x i s s s s s s i x
182+// x i s s s s s s i x
183+// x i s s s s s s i x
184+// x c c c c c c c c x
185+// x x x x x x x x x x
186+//
187+// s: Pixel summed and stored
188+// i: Pixel summed and stored (between loops)
189+// c: Pixel summed not stored
190+// x: Pixel not summed not stored
191+static void boxsum3(coef *dst, const ptrdiff_t dst_stride,
192+ const pixel *src, ptrdiff_t src_stride,
193+ const int w, const int h)
194+{
195+ src_stride = PXSTRIDE(src_stride);
196+ // We skip the first row, as it is never used
197+ src += src_stride;
198+ dst += dst_stride;
199+
200+ // We skip the first and last columns, as they are never used
201+ for (int x = 1; x < w - 1; x++) {
202+ coef *ds = dst + x;
203+ const pixel *s = src + x;
204+ int a = s[0], b = s[src_stride];
205+
206+ // We skip the first 2 rows, as they are skipped in the next loop and
207+ // we don't need the last 2 row as it is skipped in the next loop
208+ for (int y = 2; y < h - 2; y++) {
209+ s += src_stride;
210+ const int c = s[src_stride];
211+ ds += dst_stride;
212+ *ds = a + b + c;
213+ a = b;
214+ b = c;
215+ }
216+ }
217+
218+ // We skip the first 2 rows as they are never read
219+ dst += dst_stride;
220+ // We skip the last 2 rows as it is never read
221+ for (int y = 2; y < h - 2; y++) {
222+ int a = dst[1], b = dst[2];
223+
224+ // We don't store the first column as it is never read and
225+ // we don't store the last 2 columns as they are never read
226+ for (int x = 2; x < w - 2; x++) {
227+ const int c = dst[x + 1];
228+ dst[x] = a + b + c;
229+ a = b;
230+ b = c;
231+ }
232+ dst += dst_stride;
233+ }
234+}
235+
236+// Sum over a 5x5 area
237+// The dst and src pointers are positioned 3 pixels above and 3 pixels to the
238+// left of the top left corner. However, the self guided filter only needs 1
239+// pixel above and one pixel to the left. As for the pixels below and to the
240+// right they must be computed in the sums, but don't need to be stored.
241+//
242+// Example for a 4x4 block:
243+// c c c c c c c c c c
244+// c c c c c c c c c c
245+// i i s s s s s s i i
246+// i i s s s s s s i i
247+// i i s s s s s s i i
248+// i i s s s s s s i i
249+// i i s s s s s s i i
250+// i i s s s s s s i i
251+// c c c c c c c c c c
252+// c c c c c c c c c c
253+//
254+// s: Pixel summed and stored
255+// i: Pixel summed and stored (between loops)
256+// c: Pixel summed not stored
257+// x: Pixel not summed not stored
258+static void boxsum5(coef *dst, const ptrdiff_t dst_stride,
259+ const pixel *const src, ptrdiff_t src_stride,
260+ const int w, const int h)
261+{
262+ src_stride = PXSTRIDE(src_stride);
263+
264+ // We skip the first row, as it is never used
265+ dst += dst_stride;
266+
267+ for (int x = 0; x < w; x++) {
268+ coef *ds = dst + x;
269+ const pixel *s = src + 3 * src_stride + x;
270+ int a = s[-3 * src_stride];
271+ int b = s[-2 * src_stride];
272+ int c = s[-1 * src_stride];
273+ int d = s[0];
274+
275+ // We skip the first 2 rows, as they are skipped in the next loop and
276+ // we don't need the last 2 row as it is skipped in the next loop
277+ for (int y = 2; y < h - 2; y++) {
278+ s += src_stride;
279+ const int e = *s;
280+ ds += dst_stride;
281+ *ds = a + b + c + d + e;
282+ a = b;
283+ b = c;
284+ c = d;
285+ d = e;
286+ }
287+ }
288+
289+ // We skip the first 2 rows as they are never read
290+ dst += dst_stride;
291+ for (int y = 2; y < h - 2; y++) {
292+ int a = dst[0];
293+ int b = dst[1];
294+ int c = dst[2];
295+ int d = dst[3];
296+
297+ for (int x = 2; x < w - 2; x++) {
298+ const int e = dst[x + 2];
299+ dst[x] = a + b + c + d + e;
300+ a = b;
301+ b = c;
302+ c = d;
303+ d = e;
304+ }
305+ dst += dst_stride;
306+ }
307+}
308+
309+// See boxsum3 function comments for details on row and column skipping
310+static void boxsum3sqr(int32_t *dst, const ptrdiff_t dst_stride,
311+ const pixel *src, ptrdiff_t src_stride,
312+ const int w, const int h)
313+{
314+ src_stride = PXSTRIDE(src_stride);
315+
316+ // We skip the first row, as it is never used
317+ src += src_stride;
318+ dst += dst_stride;
319+
320+ // We skip the first and last columns, as they are never used
321+ for (int x = 1; x < w - 1; x++) {
322+ int *ds = dst + x;
323+ const pixel *s = src + x;
324+ int a = s[0] * s[0];
325+ int b = s[src_stride] * s[src_stride];
326+
327+ // We skip the first row, as it is skipped in the next loop and
328+ // we don't need the last row as it is skipped in the next loop
329+ for (int y = 2; y < h - 2; y++) {
330+ s += src_stride;
331+ const int c = s[src_stride] * s[src_stride];
332+ ds += dst_stride;
333+ *ds = a + b + c;
334+ a = b;
335+ b = c;
336+ }
337+ }
338+
339+ // We skip the first row as it is never read
340+ dst += dst_stride;
341+ // We skip the last row as it is never read
342+ for (int y = 2; y < h - 2; y++) {
343+ int a = dst[1], b = dst[2];
344+
345+ // We don't store the first column as it is never read and
346+ // we don't store the last 2 columns as they are never read
347+ for (int x = 2; x < w - 2; x++) {
348+ const int c = dst[x + 1];
349+ dst[x] = a + b + c;
350+ a = b;
351+ b = c;
352+ }
353+ dst += dst_stride;
354+ }
355+}
356+
357+// See boxsum5 function comments for details on row and column skipping
358+static void boxsum5sqr(int32_t *dst, const ptrdiff_t dst_stride,
359+ const pixel *const src, ptrdiff_t src_stride,
360+ const int w, const int h)
361+{
362+ src_stride = PXSTRIDE(src_stride);
363+
364+ // We skip the first row, as it is never used
365+ dst += dst_stride;
366+
367+ for (int x = 0; x < w; x++) {
368+ int *ds = dst + x;
369+ const pixel *s = src + 3 * src_stride + x;
370+ int a = s[-3 * src_stride] * s[-3 * src_stride];
371+ int b = s[-2 * src_stride] * s[-2 * src_stride];
372+ int c = s[-1 * src_stride] * s[-1 * src_stride];
373+ int d = s[0] * s[0];
374+
375+ // We skip the first 2 rows, as they are skipped in the next loop and
376+ // we don't need the last 2 row as it is skipped in the next loop
377+ for (int y = 2; y < h - 2; y++) {
378+ s += src_stride;
379+ const int e = s[0] * s[0];
380+ ds += dst_stride;
381+ *ds = a + b + c + d + e;
382+ a = b;
383+ b = c;
384+ c = d;
385+ d = e;
386+ }
387+ }
388+
389+ // We skip the first 2 rows as they are never read
390+ dst += dst_stride;
391+ for (int y = 2; y < h - 2; y++) {
392+ int a = dst[0];
393+ int b = dst[1];
394+ int c = dst[2];
395+ int d = dst[3];
396+
397+ for (int x = 2; x < w - 2; x++) {
398+ const int e = dst[x + 2];
399+ dst[x] = a + b + c + d + e;
400+ a = b;
401+ b = c;
402+ c = d;
403+ d = e;
404+ }
405+ dst += dst_stride;
406+ }
407+}
408+
409+static void selfguided_filter(int32_t *dst, const ptrdiff_t dst_stride,
410+ const pixel *src, const ptrdiff_t src_stride,
411+ const int w, const int h, const int n, const int s)
412+{
413+ const int tmp_stride = w + 6;
414+ // FIXME Replace array with scratch memory
415+ int32_t A_[(h + 6) * tmp_stride];
416+ int32_t *A = A_ + 3 * tmp_stride + 3;
417+ // By inverting A and B after the boxsums, B can be of size coef instead
418+ // of int32_t
419+ coef B_[(h + 6) * tmp_stride];
420+ coef *B = B_ + 3 * tmp_stride + 3;
421+
422+ const int step = (n == 25) + 1;
423+ if (n == 25) {
424+ boxsum5(B_, tmp_stride, src, src_stride, w + 6, h + 6);
425+ boxsum5sqr(A_, tmp_stride, src, src_stride, w + 6, h + 6);
426+ } else {
427+ boxsum3(B_, tmp_stride, src, src_stride, w + 6, h + 6);
428+ boxsum3sqr(A_, tmp_stride, src, src_stride, w + 6, h + 6);
429+ }
430+
431+ int32_t *AA = A - tmp_stride;
432+ coef *BB = B - tmp_stride;
433+ for (int j = -1; j < h + 1; j+= step) {
434+ for (int i = -1; i < w + 1; i++) {
435+ const int a =
436+ (AA[i] + (1 << (2 * (BITDEPTH - 8)) >> 1)) >> (2 * (BITDEPTH - 8));
437+ const int b =
438+ (BB[i] + (1 << (BITDEPTH - 8) >> 1)) >> (BITDEPTH - 8);
439+
440+ const uint32_t p = (a * n >= b * b) * (a * n - b * b);
441+ const uint32_t z = (p * s + (1 << 19)) >> 20;
442+
443+ const int x = sgr_x_by_xplus1[imin(z, 255)];
444+ // This is where we invert A and B, so that B is of size coef.
445+ AA[i] = (((1 << 8) - x) * BB[i] * sgr_one_by_x[n - 1] + (1 << 11)) >> 12;
446+ BB[i] = x;
447+ }
448+ AA += step * tmp_stride;
449+ BB += step * tmp_stride;
450+ }
451+
452+ src += 3 * PXSTRIDE(src_stride) + 3;
453+ if (n == 25) {
454+ for (int j = 0; j < h; j+=2) {
455+ for (int i = 0; i < w; i++) {
456+ const int32_t a = (B[i - tmp_stride] +
457+ B[i + tmp_stride]) * 6 +
458+ (B[i - 1 - tmp_stride] +
459+ B[i - 1 + tmp_stride] +
460+ B[i + 1 - tmp_stride] +
461+ B[i + 1 + tmp_stride]) * 5;
462+ const int32_t b = (A[i - tmp_stride] +
463+ A[i + tmp_stride]) * 6 +
464+ (A[i - 1 - tmp_stride] +
465+ A[i - 1 + tmp_stride] +
466+ A[i + 1 - tmp_stride] +
467+ A[i + 1 + tmp_stride]) * 5;
468+ dst[i] = (a * src[i] + b + (1 << 8)) >> 9;
469+ }
470+ dst += dst_stride;
471+ src += PXSTRIDE(src_stride);
472+ B += tmp_stride;
473+ A += tmp_stride;
474+ for (int i = 0; i < w; i++) {
475+ const int32_t a = B[i] * 6 + (B[i - 1] + B[i + 1]) * 5;
476+ const int32_t b = A[i] * 6 + (A[i - 1] + A[i + 1]) * 5;
477+ dst[i] = (a * src[i] + b + (1 << 7)) >> 8;
478+ }
479+ dst += dst_stride;
480+ src += PXSTRIDE(src_stride);
481+ B += tmp_stride;
482+ A += tmp_stride;
483+ }
484+ } else {
485+ for (int j = 0; j < h; j++) {
486+ for (int i = 0; i < w; i++) {
487+ const int32_t a =
488+ (B[i] + B[i - 1] + B[i + 1] +
489+ B[i - tmp_stride] +
490+ B[i + tmp_stride]) * 4 +
491+ (B[i - 1 - tmp_stride] +
492+ B[i - 1 + tmp_stride] +
493+ B[i + 1 - tmp_stride] +
494+ B[i + 1 + tmp_stride]) * 3;
495+
496+ const int32_t b =
497+ (A[i] + A[i - 1] + A[i + 1] +
498+ A[i - tmp_stride] +
499+ A[i + tmp_stride]) * 4 +
500+ (A[i - 1 - tmp_stride] +
501+ A[i - 1 + tmp_stride] +
502+ A[i + 1 - tmp_stride] +
503+ A[i + 1 + tmp_stride]) * 3;
504+
505+ dst[i] = (a * src[i] + b + (1 << 8)) >> 9;
506+ }
507+ dst += dst_stride;
508+ src += PXSTRIDE(src_stride);
509+ B += tmp_stride;
510+ A += tmp_stride;
511+ }
512+ }
513+}
514+
515+static void selfguided_c(pixel *p, const ptrdiff_t p_stride,
516+ const pixel *lpf, const ptrdiff_t lpf_stride,
517+ const int w, const int h, const int sgr_idx,
518+ const int16_t sgr_w[2], const enum LrEdgeFlags edges)
519+{
520+ // padding is 3 pixels above and 3 pixels below
521+ const int tmp_stride = sizeof(pixel) * (w + 6);
522+ pixel tmp[(h + 6) * PXSTRIDE(tmp_stride)];
523+
524+ padding(tmp, tmp_stride, p, p_stride, lpf, lpf_stride, w, h, edges);
525+
526+ // both r1 and r0 can't be zero
527+ if (!sgr_params[sgr_idx][0]) {
528+ int32_t dst[h * w];
529+ const int s1 = sgr_params[sgr_idx][3];
530+ selfguided_filter(dst, w, tmp, tmp_stride, w, h, 9, s1);
531+ const int w1 = (1 << 7) - sgr_w[1];
532+ for (int j = 0; j < h; j++) {
533+ for (int i = 0; i < w; i++) {
534+ const int32_t u = (p[i] << 4);
535+ const int32_t v = (u << 7) + w1 * (dst[j * w + i] - u);
536+ p[i] = iclip_pixel((v + (1 << 10)) >> 11);
537+ }
538+ p += PXSTRIDE(p_stride);
539+ }
540+ } else if (!sgr_params[sgr_idx][1]) {
541+ int32_t dst[h * w];
542+ const int s0 = sgr_params[sgr_idx][2];
543+ selfguided_filter(dst, w, tmp, tmp_stride, w, h, 25, s0);
544+ const int w0 = sgr_w[0];
545+ for (int j = 0; j < h; j++) {
546+ for (int i = 0; i < w; i++) {
547+ const int32_t u = (p[i] << 4);
548+ const int32_t v = (u << 7) + w0 * (dst[j * w + i] - u);
549+ p[i] = iclip_pixel((v + (1 << 10)) >> 11);
550+ }
551+ p += PXSTRIDE(p_stride);
552+ }
553+ } else {
554+ int32_t dst0[h * w];
555+ int32_t dst1[h * w];
556+ const int s0 = sgr_params[sgr_idx][2];
557+ const int s1 = sgr_params[sgr_idx][3];
558+ const int w0 = sgr_w[0];
559+ const int w1 = (1 << 7) - w0 - sgr_w[1];
560+ selfguided_filter(dst0, w, tmp, tmp_stride, w, h, 25, s0);
561+ selfguided_filter(dst1, w, tmp, tmp_stride, w, h, 9, s1);
562+ for (int j = 0; j < h; j++) {
563+ for (int i = 0; i < w; i++) {
564+ const int32_t u = (p[i] << 4);
565+ const int32_t v = (u << 7) + w0 * (dst0[j * w + i] - u) +
566+ w1 * (dst1[j * w + i] - u);
567+ p[i] = iclip_pixel((v + (1 << 10)) >> 11);
568+ }
569+ p += PXSTRIDE(p_stride);
570+ }
571+ }
572+}
573+
574+void bitfn(dav1d_loop_restoration_dsp_init)(Dav1dLoopRestorationDSPContext *const c) {
575+ c->wiener = wiener_c;
576+ c->selfguided = selfguided_c;
577+}
src/looprestoration.h+65−0
@@ -0,0 +1,65 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __DAV1D_SRC_LOOPRESTORATION_H__
29+#define __DAV1D_SRC_LOOPRESTORATION_H__
30+
31+#include <stdint.h>
32+#include <stddef.h>
33+
34+#include "common/bitdepth.h"
35+
36+enum LrEdgeFlags {
37+ LR_HAVE_LEFT = 1 << 0,
38+ LR_HAVE_RIGHT = 1 << 1,
39+ LR_HAVE_TOP = 1 << 2,
40+ LR_HAVE_BOTTOM = 1 << 3,
41+};
42+
43+// Although the spec applies restoration filters over 4x4 blocks, the wiener
44+// filter can be applied to a bigger surface.
45+// * w is constrained by the restoration unit size (w <= 256)
46+// * h is constrained by the stripe height (h <= 64)
47+typedef void (*wienerfilter_fn)(pixel *dst, ptrdiff_t dst_stride,
48+ const pixel *lpf, ptrdiff_t lpf_stride,
49+ int w, int h, const int16_t filterh[7],
50+ const int16_t filterv[7], enum LrEdgeFlags edges);
51+
52+typedef void (*selfguided_fn)(pixel *dst, ptrdiff_t dst_stride,
53+ const pixel *lpf, ptrdiff_t lpf_stride,
54+ int w, int h, int sgr_idx, const int16_t sgr_w[2],
55+ const enum LrEdgeFlags edges);
56+
57+typedef struct Dav1dLoopRestorationDSPContext {
58+ wienerfilter_fn wiener;
59+ selfguided_fn selfguided;
60+} Dav1dLoopRestorationDSPContext;
61+
62+void dav1d_loop_restoration_dsp_init_8bpc(Dav1dLoopRestorationDSPContext *c);
63+void dav1d_loop_restoration_dsp_init_10bpc(Dav1dLoopRestorationDSPContext *c);
64+
65+#endif /* __DAV1D_SRC_LOOPRESTORATION_H__ */
src/lr_apply.c+302−0
@@ -0,0 +1,302 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#include "config.h"
29+
30+#include <stdio.h>
31+
32+#include "common/intops.h"
33+
34+#include "src/lr_apply.h"
35+
36+
37+enum LrRestorePlanes {
38+ LR_RESTORE_Y = 1 << 0,
39+ LR_RESTORE_U = 1 << 1,
40+ LR_RESTORE_V = 1 << 2,
41+};
42+
43+static void backup_lpf(pixel *dst, ptrdiff_t dst_stride,
44+ const pixel *src, ptrdiff_t src_stride,
45+ const int first_stripe_h, const int next_stripe_h,
46+ int row, const int row_h, const int w, const int h)
47+{
48+ src_stride = PXSTRIDE(src_stride);
49+ dst_stride = PXSTRIDE(dst_stride);
50+ if (row) {
51+ // Copy the top part of the stored loop filtered pixels from the
52+ // previous sb row needed above the first stripe of this sb row.
53+ pixel_copy(&dst[dst_stride * 0], &dst[dst_stride * 8], w);
54+ pixel_copy(&dst[dst_stride * 1], &dst[dst_stride * 9], w);
55+ pixel_copy(&dst[dst_stride * 2], &dst[dst_stride * 10], w);
56+ pixel_copy(&dst[dst_stride * 3], &dst[dst_stride * 11], w);
57+ }
58+
59+ int stripe_h = first_stripe_h;
60+ dst += 4 * dst_stride;
61+ src += (stripe_h - 2) * src_stride;
62+ for (; row + stripe_h <= row_h; row += stripe_h) {
63+ for (int i = 0; i < 4; i++) {
64+ pixel_copy(dst, src, w);
65+ dst += dst_stride;
66+ src += src_stride;
67+ }
68+ stripe_h = next_stripe_h;
69+ src += (stripe_h - 4) * src_stride;
70+ }
71+}
72+
73+void bytefn(dav1d_lr_copy_lpf)(Dav1dFrameContext *const f,
74+ /*const*/ pixel *const src[3], const int sby)
75+{
76+ const int stripe_h = 64 - (8 * !sby);
77+ const ptrdiff_t offset = 8 * !!sby;
78+ const ptrdiff_t *const src_stride = f->cur.p.stride;
79+
80+ // TODO Also check block level restore type to reduce copying.
81+ const int restore_planes =
82+ ((f->frame_hdr.restoration.type[0] != RESTORATION_NONE) << 0) +
83+ ((f->frame_hdr.restoration.type[1] != RESTORATION_NONE) << 1) +
84+ ((f->frame_hdr.restoration.type[2] != RESTORATION_NONE) << 2);
85+
86+ if (restore_planes & LR_RESTORE_Y) {
87+ const int h = f->bh << 2;
88+ const int w = f->bw << 2;
89+ const int row_h = imin((sby + 1) << (6 + f->seq_hdr.sb128), h);
90+ const int y_stripe = (sby << (6 + f->seq_hdr.sb128)) - offset;
91+ backup_lpf(f->lf.lr_lpf_line_ptr[0], sizeof(pixel) * f->b4_stride * 4,
92+ src[0] - offset * PXSTRIDE(src_stride[0]),
93+ src_stride[0], stripe_h, 64, y_stripe, row_h, w, h);
94+ }
95+ if (restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) {
96+ const int ss_ver = f->cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
97+ const int ss_hor = f->cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
98+ const int h = f->bh << (2 - ss_ver);
99+ const int w = f->bw << (2 - ss_hor);
100+ const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr.sb128), h);
101+ const int stripe_h_uv = stripe_h >> ss_ver;
102+ const ptrdiff_t offset_uv = offset >> ss_ver;
103+ const int y_stripe =
104+ (sby << ((6 - ss_ver) + f->seq_hdr.sb128)) - offset_uv;
105+
106+ if (restore_planes & LR_RESTORE_U) {
107+ backup_lpf(f->lf.lr_lpf_line_ptr[1], sizeof(pixel) * f->b4_stride * 4,
108+ src[1] - offset_uv * PXSTRIDE(src_stride[1]),
109+ src_stride[1], stripe_h_uv, 32, y_stripe,
110+ row_h, w, h);
111+ }
112+ if (restore_planes & LR_RESTORE_V) {
113+ backup_lpf(f->lf.lr_lpf_line_ptr[2], sizeof(pixel) * f->b4_stride * 4,
114+ src[2] - offset_uv * PXSTRIDE(src_stride[1]),
115+ src_stride[1], stripe_h_uv, 32, y_stripe,
116+ row_h, w, h);
117+ }
118+ }
119+}
120+
121+
122+static void lr_stripe(const Dav1dFrameContext *const f, pixel *p, int x, int y,
123+ const int plane, const int unit_w,
124+ const int first_stripe_h, const int next_stripe_h,
125+ const int row_h, const Av1RestorationUnit *const lr,
126+ enum LrEdgeFlags edges)
127+{
128+ const Dav1dDSPContext *const dsp = f->dsp;
129+ const int sbrow_has_bottom = (edges & LR_HAVE_BOTTOM);
130+ const pixel *lpf = f->lf.lr_lpf_line_ptr[plane] + x;
131+ const ptrdiff_t p_stride = f->cur.p.stride[!!plane];
132+ const ptrdiff_t lpf_stride = sizeof(pixel) * f->b4_stride * 4;
133+
134+ int stripe_h = first_stripe_h;
135+
136+ // FIXME [8] might be easier for SIMD
137+ int16_t filterh[7], filterv[7];
138+ if (lr->type == RESTORATION_WIENER) {
139+ filterh[0] = filterh[6] = lr->filter_h[0];
140+ filterh[1] = filterh[5] = lr->filter_h[1];
141+ filterh[2] = filterh[4] = lr->filter_h[2];
142+ filterh[3] = -((filterh[0] + filterh[1] + filterh[2]) * 2);
143+
144+ filterv[0] = filterv[6] = lr->filter_v[0];
145+ filterv[1] = filterv[5] = lr->filter_v[1];
146+ filterv[2] = filterv[4] = lr->filter_v[2];
147+ filterv[3] = -((filterv[0] + filterv[1] + filterv[2]) * 2);
148+ }
149+
150+ while (y + stripe_h <= row_h) {
151+ // TODO Look into getting rid of the this if
152+ if (y + stripe_h == row_h) {
153+ edges &= ~LR_HAVE_BOTTOM;
154+ } else {
155+ edges |= LR_HAVE_BOTTOM;
156+ }
157+ if (lr->type == RESTORATION_WIENER) {
158+ dsp->lr.wiener(p, p_stride, lpf, lpf_stride, unit_w, stripe_h,
159+ filterh, filterv, edges);
160+ } else {
161+ assert(lr->type == RESTORATION_SGRPROJ);
162+ dsp->lr.selfguided(p, p_stride, lpf, lpf_stride, unit_w, stripe_h,
163+ lr->sgr_idx, lr->sgr_weights, edges);
164+ }
165+
166+ y += stripe_h;
167+ edges |= LR_HAVE_TOP;
168+ if (y + stripe_h > row_h && sbrow_has_bottom) break;
169+ p += stripe_h * PXSTRIDE(p_stride);
170+ stripe_h = imin(next_stripe_h, row_h - y);
171+ if (stripe_h == 0) break;
172+ lpf += 4 * PXSTRIDE(lpf_stride);
173+ }
174+}
175+
176+static void backup3xU(pixel *dst, const pixel *src, const ptrdiff_t src_stride,
177+ int u)
178+{
179+ for (; u > 0; u--, dst += 3, src += PXSTRIDE(src_stride))
180+ pixel_copy(dst, src, 3);
181+}
182+
183+static void restore3xU(pixel *dst, const ptrdiff_t dst_stride, const pixel *src,
184+ int u)
185+{
186+ for (; u > 0; u--, dst += PXSTRIDE(dst_stride), src += 3)
187+ pixel_copy(dst, src, 3);
188+}
189+
190+static void lr_sbrow(const Dav1dFrameContext *const f, pixel *p, const int y,
191+ const int w, const int h, const int row_h, const int plane)
192+{
193+ const int ss_ver = !!plane * f->cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
194+ const ptrdiff_t p_stride = f->cur.p.stride[!!plane];
195+
196+ const int unit_size_log2 = f->frame_hdr.restoration.unit_size[!!plane];
197+ const int unit_size = 1 << unit_size_log2;
198+ const int half_unit_size = unit_size >> 1;
199+ const int max_unit_size = unit_size + half_unit_size;
200+
201+ const int row_y = y + ((8 >> ss_ver) * !!y);
202+
203+ // FIXME This is an ugly hack to lookup the proper AV1Filter unit for
204+ // chroma planes. Question: For Multithreaded decoding, is it better
205+ // to store the chroma LR information with collocated Luma information?
206+ // In other words. For a chroma restoration unit locate at 128,128 and
207+ // with a 4:2:0 chroma subsampling, do we store the filter information at
208+ // the AV1Filter unit located at (128,128) or (256,256)
209+ // TODO Support chroma subsampling.
210+ const int shift = plane ? 6 : 7;
211+
212+ int ruy = (row_y >> unit_size_log2);
213+ // Merge last restoration unit if its height is < half_unit_size
214+ if (ruy > 0) ruy -= (ruy << unit_size_log2) + half_unit_size > h;
215+
216+ const int proc_h = 64 >> ss_ver;
217+ const int stripe_h = proc_h - ((8 >> ss_ver) * !y);
218+ const int filter_h = imin(stripe_h + proc_h * f->seq_hdr.sb128, h - y);
219+
220+ pixel pre_lr_border[filter_h * 3];
221+ pixel post_lr_border[filter_h * 3];
222+
223+ int unit_w = unit_size;
224+
225+ enum LrEdgeFlags edges = (y > 0 ? LR_HAVE_TOP : 0) |
226+ (row_h < h ? LR_HAVE_BOTTOM : 0);
227+
228+ for (int x = 0, rux = 0; x < w; x+= unit_w, rux++, edges |= LR_HAVE_LEFT) {
229+ // TODO Clean up this if statement.
230+ if (x + max_unit_size > w) {
231+ unit_w = w - x;
232+ edges &= ~LR_HAVE_RIGHT;
233+ } else {
234+ edges |= LR_HAVE_RIGHT;
235+ }
236+
237+ // Based on the position of the restoration unit, find the corresponding
238+ // AV1Filter unit.
239+ const int unit_idx = ((ruy & 16) >> 3) + ((rux & 16) >> 4);
240+ const Av1RestorationUnit *const lr =
241+ &f->lf.mask[(((ruy << unit_size_log2) >> shift) * f->sb128w) +
242+ (x >> shift)].lr[plane][unit_idx];
243+
244+ if (edges & LR_HAVE_LEFT) {
245+ restore3xU(p - 3, p_stride, pre_lr_border, filter_h);
246+ }
247+ // FIXME Don't backup if the next restoration unit is RESTORE_NONE
248+ // This also requires not restoring in the same conditions.
249+ if (edges & LR_HAVE_RIGHT) {
250+ backup3xU(pre_lr_border, p + unit_w - 3, p_stride, filter_h);
251+ }
252+ if (lr->type != RESTORATION_NONE) {
253+ lr_stripe(f, p, x, y, plane, unit_w, stripe_h, proc_h,
254+ row_h, lr, edges);
255+ }
256+ if (edges & LR_HAVE_LEFT) {
257+ restore3xU(p - 3, p_stride, post_lr_border, filter_h);
258+ }
259+ if (edges & LR_HAVE_RIGHT) {
260+ backup3xU(post_lr_border, p + unit_w - 3, p_stride, filter_h);
261+ }
262+ p += unit_w;
263+ }
264+}
265+
266+void bytefn(dav1d_lr_sbrow)(Dav1dFrameContext *const f, pixel *const dst[3],
267+ const int sby)
268+{
269+ const ptrdiff_t offset_y = 8 * !!sby;
270+ const ptrdiff_t *const dst_stride = f->cur.p.stride;
271+
272+ const int restore_planes =
273+ ((f->frame_hdr.restoration.type[0] != RESTORATION_NONE) << 0) +
274+ ((f->frame_hdr.restoration.type[1] != RESTORATION_NONE) << 1) +
275+ ((f->frame_hdr.restoration.type[2] != RESTORATION_NONE) << 2);
276+
277+ if (restore_planes & LR_RESTORE_Y) {
278+ const int h = f->bh << 2;
279+ const int w = f->bw << 2;
280+ const int row_h = imin((sby + 1) << (6 + f->seq_hdr.sb128), h);
281+ const int y_stripe = (sby << (6 + f->seq_hdr.sb128)) - offset_y;
282+ lr_sbrow(f, dst[0] - offset_y * PXSTRIDE(dst_stride[0]), y_stripe, w,
283+ h, row_h, 0);
284+ }
285+ if (restore_planes & (LR_RESTORE_U | LR_RESTORE_V)) {
286+ const int ss_ver = f->cur.p.p.layout == DAV1D_PIXEL_LAYOUT_I420;
287+ const int ss_hor = f->cur.p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
288+ const int h = f->bh << (2 - ss_ver);
289+ const int w = f->bw << (2 - ss_hor);
290+ const int row_h = imin((sby + 1) << ((6 - ss_ver) + f->seq_hdr.sb128), h);
291+ const ptrdiff_t offset_uv = offset_y >> ss_ver;
292+ const int y_stripe =
293+ (sby << ((6 - ss_ver) + f->seq_hdr.sb128)) - offset_uv;
294+ if (restore_planes & LR_RESTORE_U)
295+ lr_sbrow(f, dst[1] - offset_uv * PXSTRIDE(dst_stride[1]), y_stripe,
296+ w, h, row_h, 1);
297+
298+ if (restore_planes & LR_RESTORE_V)
299+ lr_sbrow(f, dst[2] - offset_uv * PXSTRIDE(dst_stride[1]), y_stripe,
300+ w, h, row_h, 2);
301+ }
302+}
src/lr_apply.h+44−0
@@ -0,0 +1,44 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __DAV1D_SRC_LR_APPLY_H__
29+#define __DAV1D_SRC_LR_APPLY_H__
30+
31+#include <stdint.h>
32+#include <stddef.h>
33+
34+#include "common/bitdepth.h"
35+
36+#include "src/internal.h"
37+
38+void bytefn(dav1d_lr_copy_lpf)(Dav1dFrameContext *const f,
39+ /*const*/ pixel *const src[3], int sby);
40+
41+void bytefn(dav1d_lr_sbrow)(Dav1dFrameContext *const f, pixel *const dst[3],
42+ int sby);
43+
44+#endif /* __DAV1D_SRC_LR_APPLY_H__ */
src/mc.c+533−0
@@ -0,0 +1,533 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#include "config.h"
29+
30+#include <stdlib.h>
31+#include <string.h>
32+
33+#include "common/intops.h"
34+
35+#include "src/mc.h"
36+#include "src/tables.h"
37+
38+static __attribute__((noinline)) void
39+put_c(pixel *dst, const ptrdiff_t dst_stride,
40+ const pixel *src, const ptrdiff_t src_stride, const int w, int h)
41+{
42+ do {
43+ pixel_copy(dst, src, w);
44+
45+ dst += dst_stride;
46+ src += src_stride;
47+ } while (--h);
48+}
49+
50+static __attribute__((noinline)) void
51+prep_c(coef *tmp, const pixel *src, const ptrdiff_t src_stride,
52+ const int w, int h)
53+{
54+ do {
55+ for (int x = 0; x < w; x++)
56+ tmp[x] = src[x] << 4;
57+
58+ tmp += w;
59+ src += src_stride;
60+ } while (--h);
61+}
62+
63+#define FILTER_8TAP(src, x, F, stride) \
64+ (F[0] * src[x + -3 * stride] + \
65+ F[1] * src[x + -2 * stride] + \
66+ F[2] * src[x + -1 * stride] + \
67+ F[3] * src[x + +0 * stride] + \
68+ F[4] * src[x + +1 * stride] + \
69+ F[5] * src[x + +2 * stride] + \
70+ F[6] * src[x + +3 * stride] + \
71+ F[7] * src[x + +4 * stride])
72+
73+#define FILTER_8TAP_RND(src, x, F, stride, sh) \
74+ ((FILTER_8TAP(src, x, F, stride) + ((1 << sh) >> 1)) >> sh)
75+
76+#define FILTER_8TAP_CLIP(src, x, F, stride, sh) \
77+ iclip_pixel(FILTER_8TAP_RND(src, x, F, stride, sh))
78+
79+#define GET_FILTERS() \
80+ const int8_t *const fh = !mx ? NULL : w > 4 ? \
81+ dav1d_mc_subpel_filters[filter_type & 3][mx - 1] : \
82+ dav1d_mc_subpel_filters[3 + (filter_type & 1)][mx - 1]; \
83+ const int8_t *const fv = !my ? NULL : h > 4 ? \
84+ dav1d_mc_subpel_filters[filter_type >> 2][my - 1] : \
85+ dav1d_mc_subpel_filters[3 + ((filter_type >> 2) & 1)][my - 1]; \
86+
87+static __attribute__((noinline)) void
88+put_8tap_c(pixel *dst, ptrdiff_t dst_stride,
89+ const pixel *src, ptrdiff_t src_stride,
90+ const int w, int h, const int mx, const int my,
91+ const int filter_type)
92+{
93+ GET_FILTERS();
94+ dst_stride = PXSTRIDE(dst_stride);
95+ src_stride = PXSTRIDE(src_stride);
96+
97+ if (fh) {
98+ if (fv) {
99+ int tmp_h = h + 7;
100+ coef mid[128 * 135], *mid_ptr = mid;
101+
102+ src -= src_stride * 3;
103+ do {
104+ for (int x = 0; x < w; x++)
105+ mid_ptr[x] = FILTER_8TAP_RND(src, x, fh, 1, 3);
106+
107+ mid_ptr += 128;
108+ src += src_stride;
109+ } while (--tmp_h);
110+
111+ mid_ptr = mid + 128 * 3;
112+ do {
113+ for (int x = 0; x < w; x++)
114+ dst[x] = FILTER_8TAP_CLIP(mid_ptr, x, fv, 128, 11);
115+
116+ mid_ptr += 128;
117+ dst += dst_stride;
118+ } while (--h);
119+ } else {
120+ do {
121+ for (int x = 0; x < w; x++) {
122+ const int px = FILTER_8TAP_RND(src, x, fh, 1, 3);
123+ dst[x] = iclip_pixel((px + 8) >> 4);
124+ }
125+
126+ dst += dst_stride;
127+ src += src_stride;
128+ } while (--h);
129+ }
130+ } else if (fv) {
131+ do {
132+ for (int x = 0; x < w; x++)
133+ dst[x] = FILTER_8TAP_CLIP(src, x, fv, src_stride, 7);
134+
135+ dst += dst_stride;
136+ src += src_stride;
137+ } while (--h);
138+ } else
139+ put_c(dst, dst_stride, src, src_stride, w, h);
140+}
141+
142+static __attribute__((noinline)) void
143+prep_8tap_c(coef *tmp, const pixel *src, ptrdiff_t src_stride,
144+ const int w, int h, const int mx, const int my,
145+ const int filter_type)
146+{
147+ GET_FILTERS();
148+ src_stride = PXSTRIDE(src_stride);
149+
150+ if (fh) {
151+ if (fv) {
152+ int tmp_h = h + 7;
153+ coef mid[128 * 135], *mid_ptr = mid;
154+
155+ src -= src_stride * 3;
156+ do {
157+ for (int x = 0; x < w; x++)
158+ mid_ptr[x] = FILTER_8TAP_RND(src, x, fh, 1, 3);
159+
160+ mid_ptr += 128;
161+ src += src_stride;
162+ } while (--tmp_h);
163+
164+ mid_ptr = mid + 128 * 3;
165+ do {
166+ for (int x = 0; x < w; x++)
167+ tmp[x] = FILTER_8TAP_RND(mid_ptr, x, fv, 128, 7);
168+
169+ mid_ptr += 128;
170+ tmp += w;
171+ } while (--h);
172+ } else {
173+ do {
174+ for (int x = 0; x < w; x++)
175+ tmp[x] = FILTER_8TAP_RND(src, x, fh, 1, 3);
176+
177+ tmp += w;
178+ src += src_stride;
179+ } while (--h);
180+ }
181+ } else if (fv) {
182+ do {
183+ for (int x = 0; x < w; x++)
184+ tmp[x] = FILTER_8TAP_RND(src, x, fv, src_stride, 3);
185+
186+ tmp += w;
187+ src += src_stride;
188+ } while (--h);
189+ } else
190+ prep_c(tmp, src, src_stride, w, h);
191+}
192+
193+#define filter_fns(type, type_h, type_v) \
194+static void put_8tap_##type##_c(pixel *const dst, \
195+ const ptrdiff_t dst_stride, \
196+ const pixel *const src, \
197+ const ptrdiff_t src_stride, \
198+ const int w, const int h, \
199+ const int mx, const int my) \
200+{ \
201+ put_8tap_c(dst, dst_stride, src, src_stride, w, h, mx, my, \
202+ type_h | (type_v << 2)); \
203+} \
204+static void prep_8tap_##type##_c(coef *const tmp, \
205+ const pixel *const src, \
206+ const ptrdiff_t src_stride, \
207+ const int w, const int h, \
208+ const int mx, const int my) \
209+{ \
210+ prep_8tap_c(tmp, src, src_stride, w, h, mx, my, \
211+ type_h | (type_v << 2)); \
212+}
213+
214+filter_fns(regular, FILTER_8TAP_REGULAR, FILTER_8TAP_REGULAR)
215+filter_fns(regular_sharp, FILTER_8TAP_REGULAR, FILTER_8TAP_SHARP)
216+filter_fns(regular_smooth, FILTER_8TAP_REGULAR, FILTER_8TAP_SMOOTH)
217+filter_fns(smooth, FILTER_8TAP_SMOOTH, FILTER_8TAP_SMOOTH)
218+filter_fns(smooth_regular, FILTER_8TAP_SMOOTH, FILTER_8TAP_REGULAR)
219+filter_fns(smooth_sharp, FILTER_8TAP_SMOOTH, FILTER_8TAP_SHARP)
220+filter_fns(sharp, FILTER_8TAP_SHARP, FILTER_8TAP_SHARP)
221+filter_fns(sharp_regular, FILTER_8TAP_SHARP, FILTER_8TAP_REGULAR)
222+filter_fns(sharp_smooth, FILTER_8TAP_SHARP, FILTER_8TAP_SMOOTH)
223+
224+#define FILTER_BILIN(src, x, mxy, stride) \
225+ (16 * src[x] + (mxy * (src[x + stride] - src[x])))
226+
227+#define FILTER_BILIN_RND(src, x, mxy, stride, sh) \
228+ ((FILTER_BILIN(src, x, mxy, stride) + ((1 << sh) >> 1)) >> sh)
229+
230+#define FILTER_BILIN_CLIP(src, x, mxy, stride, sh) \
231+ iclip_pixel(FILTER_BILIN_RND(src, x, mxy, stride, sh))
232+
233+static void put_bilin_c(pixel *dst, ptrdiff_t dst_stride,
234+ const pixel *src, ptrdiff_t src_stride,
235+ const int w, int h, const int mx, const int my)
236+{
237+ dst_stride = PXSTRIDE(dst_stride);
238+ src_stride = PXSTRIDE(src_stride);
239+
240+ if (mx) {
241+ if (my) {
242+ coef mid[128 * 129], *mid_ptr = mid;
243+ int tmp_h = h + 1;
244+
245+ do {
246+ for (int x = 0; x < w; x++)
247+ mid_ptr[x] = FILTER_BILIN(src, x, mx, 1);
248+
249+ mid_ptr += 128;
250+ src += src_stride;
251+ } while (--tmp_h);
252+
253+ mid_ptr = mid;
254+ do {
255+ for (int x = 0; x < w; x++)
256+ dst[x] = FILTER_BILIN_CLIP(mid_ptr, x, my, 128, 8);
257+
258+ mid_ptr += 128;
259+ dst += dst_stride;
260+ } while (--h);
261+ } else {
262+ do {
263+ for (int x = 0; x < w; x++)
264+ dst[x] = FILTER_BILIN_CLIP(src, x, mx, 1, 4);
265+
266+ dst += dst_stride;
267+ src += src_stride;
268+ } while (--h);
269+ }
270+ } else if (my) {
271+ do {
272+ for (int x = 0; x < w; x++)
273+ dst[x] = FILTER_BILIN_CLIP(src, x, my, src_stride, 4);
274+
275+ dst += dst_stride;
276+ src += src_stride;
277+ } while (--h);
278+ } else
279+ put_c(dst, dst_stride, src, src_stride, w, h);
280+}
281+
282+static void prep_bilin_c(coef *tmp,
283+ const pixel *src, ptrdiff_t src_stride,
284+ const int w, int h, const int mx, const int my)
285+{
286+ src_stride = PXSTRIDE(src_stride);
287+
288+ if (mx) {
289+ if (my) {
290+ coef mid[128 * 129], *mid_ptr = mid;
291+ int tmp_h = h + 1;
292+
293+ do {
294+ for (int x = 0; x < w; x++)
295+ mid_ptr[x] = FILTER_BILIN(src, x, mx, 1);
296+
297+ mid_ptr += 128;
298+ src += src_stride;
299+ } while (--tmp_h);
300+
301+ mid_ptr = mid;
302+ do {
303+ for (int x = 0; x < w; x++)
304+ tmp[x] = FILTER_BILIN_RND(mid_ptr, x, my, 128, 4);
305+
306+ mid_ptr += 128;
307+ tmp += w;
308+ } while (--h);
309+ } else {
310+ do {
311+ for (int x = 0; x < w; x++)
312+ tmp[x] = FILTER_BILIN(src, x, mx, 1);
313+
314+ tmp += w;
315+ src += src_stride;
316+ } while (--h);
317+ }
318+ } else if (my) {
319+ do {
320+ for (int x = 0; x < w; x++)
321+ tmp[x] = FILTER_BILIN(src, x, my, src_stride);
322+
323+ tmp += w;
324+ src += src_stride;
325+ } while (--h);
326+ } else
327+ prep_c(tmp, src, src_stride, w, h);
328+}
329+
330+static void avg_c(pixel *dst, const ptrdiff_t dst_stride,
331+ const coef *tmp1, const coef *tmp2, const int w, int h)
332+{
333+ do {
334+ for (int x = 0; x < w; x++)
335+ dst[x] = iclip_pixel((tmp1[x] + tmp2[x] + 16) >> 5);
336+
337+ tmp1 += w;
338+ tmp2 += w;
339+ dst += PXSTRIDE(dst_stride);
340+ } while (--h);
341+}
342+
343+static void w_avg_c(pixel *dst, const ptrdiff_t dst_stride,
344+ const coef *tmp1, const coef *tmp2, const int w, int h,
345+ const int weight)
346+{
347+ do {
348+ for (int x = 0; x < w; x++)
349+ dst[x] = iclip_pixel((tmp1[x] * weight +
350+ tmp2[x] * (16 - weight) + 128) >> 8);
351+
352+ tmp1 += w;
353+ tmp2 += w;
354+ dst += PXSTRIDE(dst_stride);
355+ } while (--h);
356+}
357+
358+static void mask_c(pixel *dst, const ptrdiff_t dst_stride,
359+ const coef *tmp1, const coef *tmp2, const int w, int h,
360+ const uint8_t *mask)
361+{
362+ do {
363+ for (int x = 0; x < w; x++)
364+ dst[x] = iclip_pixel((tmp1[x] * mask[x] +
365+ tmp2[x] * (64 - mask[x]) + 512) >> 10);
366+
367+ tmp1 += w;
368+ tmp2 += w;
369+ mask += w;
370+ dst += PXSTRIDE(dst_stride);
371+ } while (--h);
372+}
373+
374+static void blend_c(pixel *dst, const ptrdiff_t dst_stride,
375+ const pixel *tmp, const ptrdiff_t tmp_stride,
376+ const int w, const int h,
377+ const uint8_t *mask, const ptrdiff_t m_stride)
378+{
379+ for (int y = 0; y < h; y++) {
380+ for (int x = 0; x < w; x++) {
381+#define blend_px(a, b, m) (((a * (64 - m) + b * m) + 32) >> 6)
382+ dst[x] = blend_px(dst[x], tmp[x], mask[m_stride == 1 ? 0 : x]);
383+ }
384+ dst += PXSTRIDE(dst_stride);
385+ tmp += PXSTRIDE(tmp_stride);
386+ mask += m_stride;
387+ }
388+}
389+
390+static void w_mask_c(pixel *dst, const ptrdiff_t dst_stride,
391+ const coef *tmp1, const coef *tmp2, const int w, int h,
392+ uint8_t *mask, const int sign,
393+ const int ss_hor, const int ss_ver)
394+{
395+ // store mask at 2x2 resolution, i.e. store 2x1 sum for even rows,
396+ // and then load this intermediate to calculate final value for odd rows
397+ const int rnd = 8 << (BITDEPTH - 8);
398+ do {
399+ for (int x = 0; x < w; x++) {
400+ const int m = imin(38 + ((abs(tmp1[x] - tmp2[x]) + rnd) >> BITDEPTH), 64);
401+ dst[x] = iclip_pixel((tmp1[x] * m +
402+ tmp2[x] * (64 - m) + 512) >> 10);
403+
404+ if (ss_hor) {
405+ x++;
406+
407+ const int n = imin(38 + ((abs(tmp1[x] - tmp2[x]) + rnd) >> BITDEPTH), 64);
408+ dst[x] = iclip_pixel((tmp1[x] * n +
409+ tmp2[x] * (64 - n) + 512) >> 10);
410+
411+ if (h & ss_ver) {
412+ mask[x >> 1] = (m + n + mask[x >> 1] + 2 - sign) >> 2;
413+ } else if (ss_ver) {
414+ mask[x >> 1] = m + n;
415+ } else {
416+ mask[x >> 1] = (m + n + 1 - sign) >> 1;
417+ }
418+ } else {
419+ mask[x] = m;
420+ }
421+ }
422+
423+ tmp1 += w;
424+ tmp2 += w;
425+ dst += PXSTRIDE(dst_stride);
426+ if (!ss_ver || (h & 1)) mask += w >> ss_hor;
427+ } while (--h);
428+}
429+
430+#define w_mask_fns(ssn, ss_hor, ss_ver) \
431+static void w_mask_##ssn##_c(pixel *const dst, const ptrdiff_t dst_stride, \
432+ const coef *const tmp1, const coef *const tmp2, \
433+ const int w, const int h, uint8_t *mask, \
434+ const int sign) \
435+{ \
436+ w_mask_c(dst, dst_stride, tmp1, tmp2, w, h, mask, sign, ss_hor, ss_ver); \
437+}
438+
439+w_mask_fns(444, 0, 0);
440+w_mask_fns(422, 1, 0);
441+w_mask_fns(420, 1, 1);
442+
443+#undef w_mask_fns
444+
445+static void warp_affine_8x8_c(pixel *dst, const ptrdiff_t dst_stride,
446+ const pixel *src, const ptrdiff_t src_stride,
447+ const int16_t *const abcd, int mx, int my)
448+{
449+ coef mid[15 * 8], *mid_ptr = mid;
450+
451+ src -= 3 * PXSTRIDE(src_stride);
452+ for (int y = 0; y < 15; y++, mx += abcd[1]) {
453+ for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
454+ const int8_t *const filter =
455+ dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
456+
457+ mid_ptr[x] = FILTER_8TAP_RND(src, x, filter, 1, 3);
458+ }
459+ src += PXSTRIDE(src_stride);
460+ mid_ptr += 8;
461+ }
462+
463+ mid_ptr = &mid[3 * 8];
464+ for (int y = 0; y < 8; y++, my += abcd[3]) {
465+ for (int x = 0, tmy = my; x < 8; x++, tmy += abcd[2]) {
466+ const int8_t *const filter =
467+ dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
468+
469+ dst[x] = FILTER_8TAP_CLIP(mid_ptr, x, filter, 8, 11);
470+ }
471+ mid_ptr += 8;
472+ dst += PXSTRIDE(dst_stride);
473+ }
474+}
475+
476+static void warp_affine_8x8t_c(coef *tmp, const ptrdiff_t tmp_stride,
477+ const pixel *src, const ptrdiff_t src_stride,
478+ const int16_t *const abcd, int mx, int my)
479+{
480+ coef mid[15 * 8], *mid_ptr = mid;
481+
482+ src -= 3 * PXSTRIDE(src_stride);
483+ for (int y = 0; y < 15; y++, mx += abcd[1]) {
484+ for (int x = 0, tmx = mx; x < 8; x++, tmx += abcd[0]) {
485+ const int8_t *const filter =
486+ dav1d_mc_warp_filter[64 + ((tmx + 512) >> 10)];
487+
488+ mid_ptr[x] = FILTER_8TAP_RND(src, x, filter, 1, 3);
489+ }
490+ src += PXSTRIDE(src_stride);
491+ mid_ptr += 8;
492+ }
493+
494+ mid_ptr = &mid[3 * 8];
495+ for (int y = 0; y < 8; y++, my += abcd[3]) {
496+ for (int x = 0, tmy = my; x < 8; x++, tmy += abcd[2]) {
497+ const int8_t *const filter =
498+ dav1d_mc_warp_filter[64 + ((tmy + 512) >> 10)];
499+
500+ tmp[x] = FILTER_8TAP_RND(mid_ptr, x, filter, 8, 7);
501+ }
502+ mid_ptr += 8;
503+ tmp += tmp_stride;
504+ }
505+}
506+
507+void bitfn(dav1d_mc_dsp_init)(Dav1dMCDSPContext *const c) {
508+#define init_mc_fns(type, name) do { \
509+ c->mc [type] = put_##name##_c; \
510+ c->mct[type] = prep_##name##_c; \
511+} while (0)
512+
513+ init_mc_fns(FILTER_2D_8TAP_REGULAR, 8tap_regular);
514+ init_mc_fns(FILTER_2D_8TAP_REGULAR_SMOOTH, 8tap_regular_smooth);
515+ init_mc_fns(FILTER_2D_8TAP_REGULAR_SHARP, 8tap_regular_sharp);
516+ init_mc_fns(FILTER_2D_8TAP_SHARP_REGULAR, 8tap_sharp_regular);
517+ init_mc_fns(FILTER_2D_8TAP_SHARP_SMOOTH, 8tap_sharp_smooth);
518+ init_mc_fns(FILTER_2D_8TAP_SHARP, 8tap_sharp);
519+ init_mc_fns(FILTER_2D_8TAP_SMOOTH_REGULAR, 8tap_smooth_regular);
520+ init_mc_fns(FILTER_2D_8TAP_SMOOTH, 8tap_smooth);
521+ init_mc_fns(FILTER_2D_8TAP_SMOOTH_SHARP, 8tap_smooth_sharp);
522+ init_mc_fns(FILTER_2D_BILINEAR, bilin);
523+
524+ c->avg = avg_c;
525+ c->w_avg = w_avg_c;
526+ c->mask = mask_c;
527+ c->blend = blend_c;
528+ c->w_mask[0] = w_mask_444_c;
529+ c->w_mask[1] = w_mask_422_c;
530+ c->w_mask[2] = w_mask_420_c;
531+ c->warp8x8 = warp_affine_8x8_c;
532+ c->warp8x8t = warp_affine_8x8t_c;
533+}
src/mc.h+104−0
@@ -0,0 +1,104 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __DAV1D_SRC_MC_H__
29+#define __DAV1D_SRC_MC_H__
30+
31+#include <stdint.h>
32+#include <stddef.h>
33+
34+#include "common/bitdepth.h"
35+
36+#include "src/levels.h"
37+
38+#define decl_mc_fn(name) \
39+void (name)(pixel *dst, ptrdiff_t dst_stride, \
40+ const pixel *src, ptrdiff_t src_stride, \
41+ int w, int h, int mx, int my)
42+typedef decl_mc_fn(*mc_fn);
43+
44+#define decl_warp8x8_fn(name) \
45+void (name)(pixel *dst, ptrdiff_t dst_stride, \
46+ const pixel *src, ptrdiff_t src_stride, \
47+ const int16_t *abcd, int mx, int my)
48+typedef decl_warp8x8_fn(*warp8x8_fn);
49+
50+#define decl_mct_fn(name) \
51+void (name)(coef *tmp, const pixel *src, ptrdiff_t src_stride, \
52+ int w, int h, int mx, int my)
53+typedef decl_mct_fn(*mct_fn);
54+
55+#define decl_warp8x8t_fn(name) \
56+void (name)(coef *tmp, const ptrdiff_t tmp_stride, \
57+ const pixel *src, ptrdiff_t src_stride, \
58+ const int16_t *abcd, int mx, int my)
59+typedef decl_warp8x8t_fn(*warp8x8t_fn);
60+
61+#define decl_avg_fn(name) \
62+void (name)(pixel *dst, ptrdiff_t dst_stride, \
63+ const coef *tmp1, const coef *tmp2, int w, int h)
64+typedef decl_avg_fn(*avg_fn);
65+
66+#define decl_w_avg_fn(name) \
67+void (name)(pixel *dst, ptrdiff_t dst_stride, \
68+ const coef *tmp1, const coef *tmp2, int w, int h, int weight)
69+typedef decl_w_avg_fn(*w_avg_fn);
70+
71+#define decl_mask_fn(name) \
72+void (name)(pixel *dst, ptrdiff_t dst_stride, \
73+ const coef *tmp1, const coef *tmp2, int w, int h, \
74+ const uint8_t *mask)
75+typedef decl_mask_fn(*mask_fn);
76+
77+#define decl_w_mask_fn(name) \
78+void (name)(pixel *dst, ptrdiff_t dst_stride, \
79+ const coef *tmp1, const coef *tmp2, int w, int h, \
80+ uint8_t *mask, int sign)
81+typedef decl_w_mask_fn(*w_mask_fn);
82+
83+#define decl_blend_fn(name) \
84+void (name)(pixel *dst, ptrdiff_t dst_stride, \
85+ const pixel *tmp, ptrdiff_t tmp_stride, int w, int h, \
86+ const uint8_t *mask, ptrdiff_t mstride)
87+typedef decl_blend_fn(*blend_fn);
88+
89+typedef struct Dav1dMCDSPContext {
90+ mc_fn mc[N_2D_FILTERS];
91+ mct_fn mct[N_2D_FILTERS];
92+ avg_fn avg;
93+ w_avg_fn w_avg;
94+ mask_fn mask;
95+ w_mask_fn w_mask[3 /* 444, 422, 420 */];
96+ blend_fn blend;
97+ warp8x8_fn warp8x8;
98+ warp8x8t_fn warp8x8t;
99+} Dav1dMCDSPContext;
100+
101+void dav1d_mc_dsp_init_8bpc(Dav1dMCDSPContext *c);
102+void dav1d_mc_dsp_init_10bpc(Dav1dMCDSPContext *c);
103+
104+#endif /* __DAV1D_SRC_MC_H__ */
src/msac.c+318−0
@@ -0,0 +1,318 @@
1+/*
2+ * Copyright (c) 2001-2016, Alliance for Open Media. All rights reserved
3+ *
4+ * This source code is subject to the terms of the BSD 2 Clause License and
5+ * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6+ * was not distributed with this source code in the LICENSE file, you can
7+ * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8+ * Media Patent License 1.0 was not distributed with this source code in the
9+ * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10+ */
11+
12+#include "config.h"
13+
14+#include <assert.h>
15+#include <limits.h>
16+
17+#include "common/intops.h"
18+
19+#include "src/msac.h"
20+
21+typedef MsacContext od_ec_dec;
22+
23+//#define CDF_SIZE(x) ((x) + 1)
24+#define CDF_PROB_BITS 15
25+#define CDF_PROB_TOP (1 << CDF_PROB_BITS)
26+//#define CDF_INIT_TOP 32768
27+#define CDF_SHIFT (15 - CDF_PROB_BITS)
28+
29+#define OD_CLZ0 (1)
30+#define OD_CLZ(x) (-get_msb(x))
31+#define OD_ILOG_NZ(x) (OD_CLZ0 - OD_CLZ(x))
32+
33+static inline int get_msb(unsigned int n) {
34+ assert(n != 0);
35+ return 31 ^ __builtin_clz(n);
36+}
37+
38+#define EC_PROB_SHIFT 6
39+#define EC_MIN_PROB 4 // must be <= (1<<EC_PROB_SHIFT)/16
40+
41+/*OPT: od_ec_window must be at least 32 bits, but if you have fast arithmetic
42+ on a larger type, you can speed up the decoder by using it here.*/
43+typedef uint32_t od_ec_window;
44+
45+#define OD_EC_WINDOW_SIZE ((int)sizeof(od_ec_window) * CHAR_BIT)
46+
47+/*The resolution of fractional-precision bit usage measurements, i.e.,
48+ 3 => 1/8th bits.*/
49+#define OD_BITRES (3)
50+
51+#define OD_ICDF AOM_ICDF
52+
53+#define AOM_ICDF(a) (32768-(a))
54+
55+/*A range decoder.
56+ This is an entropy decoder based upon \cite{Mar79}, which is itself a
57+ rediscovery of the FIFO arithmetic code introduced by \cite{Pas76}.
58+ It is very similar to arithmetic encoding, except that encoding is done with
59+ digits in any base, instead of with bits, and so it is faster when using
60+ larger bases (i.e.: a byte).
61+ The author claims an average waste of $\frac{1}{2}\log_b(2b)$ bits, where $b$
62+ is the base, longer than the theoretical optimum, but to my knowledge there
63+ is no published justification for this claim.
64+ This only seems true when using near-infinite precision arithmetic so that
65+ the process is carried out with no rounding errors.
66+
67+ An excellent description of implementation details is available at
68+ http://www.arturocampos.com/ac_range.html
69+ A recent work \cite{MNW98} which proposes several changes to arithmetic
70+ encoding for efficiency actually re-discovers many of the principles
71+ behind range encoding, and presents a good theoretical analysis of them.
72+
73+ End of stream is handled by writing out the smallest number of bits that
74+ ensures that the stream will be correctly decoded regardless of the value of
75+ any subsequent bits.
76+ od_ec_dec_tell() can be used to determine how many bits were needed to decode
77+ all the symbols thus far; other data can be packed in the remaining bits of
78+ the input buffer.
79+ @PHDTHESIS{Pas76,
80+ author="Richard Clark Pasco",
81+ title="Source coding algorithms for fast data compression",
82+ school="Dept. of Electrical Engineering, Stanford University",
83+ address="Stanford, CA",
84+ month=May,
85+ year=1976,
86+ URL="http://www.richpasco.org/scaffdc.pdf"
87+ }
88+ @INPROCEEDINGS{Mar79,
89+ author="Martin, G.N.N.",
90+ title="Range encoding: an algorithm for removing redundancy from a digitised
91+ message",
92+ booktitle="Video & Data Recording Conference",
93+ year=1979,
94+ address="Southampton",
95+ month=Jul,
96+ URL="http://www.compressconsult.com/rangecoder/rngcod.pdf.gz"
97+ }
98+ @ARTICLE{MNW98,
99+ author="Alistair Moffat and Radford Neal and Ian H. Witten",
100+ title="Arithmetic Coding Revisited",
101+ journal="{ACM} Transactions on Information Systems",
102+ year=1998,
103+ volume=16,
104+ number=3,
105+ pages="256--294",
106+ month=Jul,
107+ URL="http://researchcommons.waikato.ac.nz/bitstream/handle/10289/78/content.pdf"
108+ }*/
109+
110+/*This is meant to be a large, positive constant that can still be efficiently
111+ loaded as an immediate (on platforms like ARM, for example).
112+ Even relatively modest values like 100 would work fine.*/
113+#define OD_EC_LOTS_OF_BITS (0x4000)
114+
115+static void od_ec_dec_refill(od_ec_dec *dec) {
116+ int s;
117+ od_ec_window dif;
118+ int16_t cnt;
119+ const unsigned char *bptr;
120+ const unsigned char *end;
121+ dif = dec->dif;
122+ cnt = dec->cnt;
123+ bptr = dec->bptr;
124+ end = dec->end;
125+ s = OD_EC_WINDOW_SIZE - 9 - (cnt + 15);
126+ for (; s >= 0 && bptr < end; s -= 8, bptr++) {
127+ assert(s <= OD_EC_WINDOW_SIZE - 8);
128+ dif ^= (od_ec_window)bptr[0] << s;
129+ cnt += 8;
130+ }
131+ if (bptr >= end) {
132+ dec->tell_offs += OD_EC_LOTS_OF_BITS - cnt;
133+ cnt = OD_EC_LOTS_OF_BITS;
134+ }
135+ dec->dif = dif;
136+ dec->cnt = cnt;
137+ dec->bptr = bptr;
138+}
139+
140+/*Takes updated dif and range values, renormalizes them so that
141+ 32768 <= rng < 65536 (reading more bytes from the stream into dif if
142+ necessary), and stores them back in the decoder context.
143+ dif: The new value of dif.
144+ rng: The new value of the range.
145+ ret: The value to return.
146+ Return: ret.
147+ This allows the compiler to jump to this function via a tail-call.*/
148+static int od_ec_dec_normalize(od_ec_dec *dec, od_ec_window dif, unsigned rng,
149+ int ret) {
150+ int d;
151+ assert(rng <= 65535U);
152+ d = 16 - OD_ILOG_NZ(rng);
153+ dec->cnt -= d;
154+ /*This is equivalent to shifting in 1's instead of 0's.*/
155+ dec->dif = ((dif + 1) << d) - 1;
156+ dec->rng = rng << d;
157+ if (dec->cnt < 0) od_ec_dec_refill(dec);
158+ return ret;
159+}
160+
161+/*Initializes the decoder.
162+ buf: The input buffer to use.
163+ Return: 0 on success, or a negative value on error.*/
164+void od_ec_dec_init(od_ec_dec *dec, const unsigned char *buf,
165+ uint32_t storage) {
166+ dec->buf = buf;
167+ dec->tell_offs = 10 - (OD_EC_WINDOW_SIZE - 8);
168+ dec->end = buf + storage;
169+ dec->bptr = buf;
170+ dec->dif = ((od_ec_window)1 << (OD_EC_WINDOW_SIZE - 1)) - 1;
171+ dec->rng = 0x8000;
172+ dec->cnt = -15;
173+ dec->error = 0;
174+ od_ec_dec_refill(dec);
175+}
176+
177+/*Decode a single binary value.
178+ f: The probability that the bit is one, scaled by 32768.
179+ Return: The value decoded (0 or 1).*/
180+int od_ec_decode_bool_q15(od_ec_dec *dec, unsigned f) {
181+ od_ec_window dif;
182+ od_ec_window vw;
183+ unsigned r;
184+ unsigned r_new;
185+ unsigned v;
186+ int ret;
187+ assert(0 < f);
188+ assert(f < 32768U);
189+ dif = dec->dif;
190+ r = dec->rng;
191+ assert(dif >> (OD_EC_WINDOW_SIZE - 16) < r);
192+ assert(32768U <= r);
193+ v = ((r >> 8) * (uint32_t)(f >> EC_PROB_SHIFT) >> (7 - EC_PROB_SHIFT));
194+ v += EC_MIN_PROB;
195+ vw = (od_ec_window)v << (OD_EC_WINDOW_SIZE - 16);
196+ ret = 1;
197+ r_new = v;
198+ if (dif >= vw) {
199+ r_new = r - v;
200+ dif -= vw;
201+ ret = 0;
202+ }
203+ return od_ec_dec_normalize(dec, dif, r_new, ret);
204+}
205+
206+/*Decodes a symbol given an inverse cumulative distribution function (CDF)
207+ table in Q15.
208+ icdf: CDF_PROB_TOP minus the CDF, such that symbol s falls in the range
209+ [s > 0 ? (CDF_PROB_TOP - icdf[s - 1]) : 0, CDF_PROB_TOP - icdf[s]).
210+ The values must be monotonically non-increasing, and icdf[nsyms - 1]
211+ must be 0.
212+ nsyms: The number of symbols in the alphabet.
213+ This should be at most 16.
214+ Return: The decoded symbol s.*/
215+int od_ec_decode_cdf_q15(od_ec_dec *dec, const uint16_t *icdf, int nsyms) {
216+ od_ec_window dif;
217+ unsigned r;
218+ unsigned c;
219+ unsigned u;
220+ unsigned v;
221+ int ret;
222+ (void)nsyms;
223+ dif = dec->dif;
224+ r = dec->rng;
225+ const int N = nsyms - 1;
226+
227+ assert(dif >> (OD_EC_WINDOW_SIZE - 16) < r);
228+ assert(icdf[nsyms - 1] == OD_ICDF(CDF_PROB_TOP));
229+ assert(32768U <= r);
230+ assert(7 - EC_PROB_SHIFT - CDF_SHIFT >= 0);
231+ c = (unsigned)(dif >> (OD_EC_WINDOW_SIZE - 16));
232+ v = r;
233+ ret = -1;
234+ do {
235+ u = v;
236+ v = ((r >> 8) * (uint32_t)(icdf[++ret] >> EC_PROB_SHIFT) >>
237+ (7 - EC_PROB_SHIFT - CDF_SHIFT));
238+ v += EC_MIN_PROB * (N - ret);
239+ } while (c < v);
240+ assert(v < u);
241+ assert(u <= r);
242+ r = u - v;
243+ dif -= (od_ec_window)v << (OD_EC_WINDOW_SIZE - 16);
244+ return od_ec_dec_normalize(dec, dif, r, ret);
245+}
246+
247+void msac_init(MsacContext *const c,
248+ const uint8_t *const data, const size_t sz)
249+{
250+ od_ec_dec_init(c, data, sz);
251+}
252+
253+unsigned msac_decode_symbol(MsacContext *const c, const uint16_t *const cdf,
254+ const unsigned n_symbols)
255+{
256+ return od_ec_decode_cdf_q15(c, cdf, n_symbols);
257+}
258+
259+unsigned msac_decode_bool(MsacContext *const c, const unsigned cdf) {
260+ return od_ec_decode_bool_q15(c, cdf);
261+}
262+
263+unsigned msac_decode_bools(MsacContext *const c, const unsigned l) {
264+ int v = 0;
265+ for (int n = (int) l - 1; n >= 0; n--)
266+ v = (v << 1) | msac_decode_bool(c, 128 << 7);
267+ return v;
268+}
269+
270+int msac_decode_subexp(MsacContext *const c, const int ref,
271+ const unsigned n, const unsigned k)
272+{
273+ int i = 0;
274+ int a = 0;
275+ int b = k;
276+ while ((2 << b) < n) {
277+ if (!msac_decode_bool(c, 128 << 7)) break;
278+ b = k + i++;
279+ a = (1 << b);
280+ }
281+ const unsigned v = msac_decode_bools(c, b) + a;
282+ return ref * 2 <= n ? inv_recenter(ref, v) :
283+ n - 1 - inv_recenter(n - 1 - ref, v);
284+}
285+
286+int msac_decode_uniform(MsacContext *const c, const unsigned n) {
287+ assert(n > 0);
288+ const int l = ulog2(n) + 1;
289+ assert(l > 1);
290+ const int m = (1 << l) - n;
291+ const int v = msac_decode_bools(c, l - 1);
292+ return v < m ? v : (v << 1) - m + msac_decode_bool(c, 128 << 7);
293+}
294+
295+void update_cdf(uint16_t *cdf, unsigned val, unsigned nsymbs) {
296+ int rate;
297+ int i, tmp;
298+
299+ static const int nsymbs2speed[17] = {
300+ 0, 0, 1, 1, 2, 2, 2, 2, 2,
301+ 2, 2, 2, 2, 2, 2, 2, 2
302+ };
303+ assert(nsymbs < 17);
304+ rate = 3 + (cdf[nsymbs] > 15) + (cdf[nsymbs] > 31) + nsymbs2speed[nsymbs];
305+ tmp = 32768;
306+
307+ // Single loop (faster)
308+ for (i = 0; i < nsymbs - 1; ++i) {
309+ tmp = (i == val) ? 0 : tmp;
310+ if (tmp < cdf[i]) {
311+ cdf[i] -= ((cdf[i] - tmp) >> rate);
312+ } else {
313+ cdf[i] += ((tmp - cdf[i]) >> rate);
314+ }
315+ }
316+
317+ cdf[nsymbs] += (cdf[nsymbs] < 32);
318+}
src/msac.h+56−0
@@ -0,0 +1,56 @@
1+/*
2+ * Copyright (c) 2001-2016, Alliance for Open Media. All rights reserved
3+ *
4+ * This source code is subject to the terms of the BSD 2 Clause License and
5+ * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6+ * was not distributed with this source code in the LICENSE file, you can
7+ * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8+ * Media Patent License 1.0 was not distributed with this source code in the
9+ * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10+ */
11+
12+#ifndef __DAV1D_SRC_MSAC_H__
13+#define __DAV1D_SRC_MSAC_H__
14+
15+#include <stdint.h>
16+#include <stdlib.h>
17+
18+typedef struct MsacContext {
19+ const uint8_t *buf, *end, *bptr;
20+ int32_t tell_offs;
21+ uint32_t dif;
22+ uint16_t rng;
23+ int16_t cnt;
24+ int error;
25+} MsacContext;
26+
27+void msac_init(MsacContext *c, const uint8_t *data, size_t sz);
28+unsigned msac_decode_symbol(MsacContext *c, const uint16_t *cdf,
29+ const unsigned n_symbols);
30+unsigned msac_decode_bool(MsacContext *c, unsigned cdf);
31+unsigned msac_decode_bools(MsacContext *c, unsigned l);
32+int msac_decode_subexp(MsacContext *c, int ref, unsigned n, unsigned k);
33+int msac_decode_uniform(MsacContext *c, unsigned n);
34+void update_cdf(uint16_t *cdf, unsigned val, unsigned nsymbs);
35+
36+static inline unsigned msac_decode_symbol_adapt(MsacContext *const c,
37+ uint16_t *const cdf,
38+ const unsigned n_symbols)
39+{
40+ const unsigned val = msac_decode_symbol(c, cdf, n_symbols);
41+ update_cdf(cdf, val, n_symbols);
42+ return val;
43+}
44+
45+static inline unsigned msac_decode_bool_adapt(MsacContext *const c,
46+ uint16_t *const cdf)
47+{
48+ const unsigned bit = msac_decode_bool(c, *cdf);
49+ uint16_t bak_cdf[3] = { cdf[0], 0, cdf[1] };
50+ update_cdf(bak_cdf, bit, 2);
51+ cdf[0] = bak_cdf[0];
52+ cdf[1] = bak_cdf[2];
53+ return bit;
54+}
55+
56+#endif /* __DAV1D_SRC_MSAC_H__ */
src/obu.c+1102−0
@@ -0,0 +1,1102 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#include "config.h"
29+
30+#include <assert.h>
31+#include <errno.h>
32+#include <limits.h>
33+#include <stdio.h>
34+
35+#include "dav1d/data.h"
36+
37+#include "common/intops.h"
38+
39+#include "src/decode.h"
40+#include "src/getbits.h"
41+#include "src/levels.h"
42+#include "src/obu.h"
43+#include "src/ref.h"
44+#include "src/warpmv.h"
45+
46+static int parse_seq_hdr(Dav1dContext *const c, GetBits *const gb) {
47+ const uint8_t *const init_ptr = gb->ptr;
48+ Av1SequenceHeader *const hdr = &c->seq_hdr;
49+
50+#define DEBUG_SEQ_HDR 0
51+
52+ hdr->profile = get_bits(gb, 3);
53+ if (hdr->profile > 2U) goto error;
54+#if DEBUG_SEQ_HDR
55+ printf("SEQHDR: post-profile: off=%ld\n",
56+ (gb->ptr - init_ptr) * 8 - gb->bits_left);
57+#endif
58+
59+ hdr->still_picture = get_bits(gb, 1);
60+ hdr->reduced_still_picture_header = get_bits(gb, 1);
61+ if (hdr->reduced_still_picture_header && !hdr->still_picture) goto error;
62+#if DEBUG_SEQ_HDR
63+ printf("SEQHDR: post-stillpicture_flags: off=%ld\n",
64+ (gb->ptr - init_ptr) * 8 - gb->bits_left);
65+#endif
66+
67+ if (hdr->reduced_still_picture_header) {
68+ hdr->timing_info_present = 0;
69+ hdr->decoder_model_info_present = 0;
70+ hdr->display_model_info_present = 0;
71+ hdr->num_operating_points = 1;
72+ hdr->operating_points[0].idc = 0;
73+ hdr->operating_points[0].major_level = get_bits(gb, 3);
74+ hdr->operating_points[0].minor_level = get_bits(gb, 2);
75+ hdr->operating_points[0].tier = 0;
76+ hdr->operating_points[0].decoder_model_param_present = 0;
77+ hdr->operating_points[0].display_model_param_present = 0;
78+ } else {
79+ hdr->timing_info_present = get_bits(gb, 1);
80+ if (hdr->timing_info_present) {
81+ hdr->num_units_in_tick = get_bits(gb, 32);
82+ hdr->time_scale = get_bits(gb, 32);
83+ hdr->equal_picture_interval = get_bits(gb, 1);
84+ if (hdr->equal_picture_interval)
85+ hdr->num_ticks_per_picture = get_vlc(gb) + 1;
86+
87+ hdr->decoder_model_info_present = get_bits(gb, 1);
88+ if (hdr->decoder_model_info_present) {
89+ hdr->bitrate_scale = get_bits(gb, 4);
90+ hdr->buffer_size_scale = get_bits(gb, 4);
91+ hdr->encoder_decoder_buffer_delay_length = get_bits(gb, 5) + 1;
92+ hdr->num_units_in_decoding_tick = get_bits(gb, 32);
93+ hdr->buffer_removal_delay_length = get_bits(gb, 5) + 1;
94+ hdr->frame_presentation_delay_length = get_bits(gb, 5) + 1;
95+ }
96+ } else {
97+ hdr->decoder_model_info_present = 0;
98+ }
99+#if DEBUG_SEQ_HDR
100+ printf("SEQHDR: post-timinginfo: off=%ld\n",
101+ (gb->ptr - init_ptr) * 8 - gb->bits_left);
102+#endif
103+
104+ hdr->display_model_info_present = get_bits(gb, 1);
105+ hdr->num_operating_points = get_bits(gb, 5) + 1;
106+ for (int i = 0; i < c->seq_hdr.num_operating_points; i++) {
107+ struct Av1SequenceHeaderOperatingPoint *const op =
108+ &hdr->operating_points[i];
109+ op->idc = get_bits(gb, 12);
110+ op->major_level = 2 + get_bits(gb, 3);
111+ op->minor_level = get_bits(gb, 2);
112+ op->tier = op->major_level > 3 ? get_bits(gb, 1) : 0;
113+ op->decoder_model_param_present =
114+ hdr->decoder_model_info_present && get_bits(gb, 1);
115+ if (op->decoder_model_param_present) {
116+ op->bitrate = get_vlc(gb) + 1;
117+ op->buffer_size = get_vlc(gb) + 1;
118+ op->cbr = get_bits(gb, 1);
119+ op->decoder_buffer_delay =
120+ get_bits(gb, hdr->encoder_decoder_buffer_delay_length);
121+ op->encoder_buffer_delay =
122+ get_bits(gb, hdr->encoder_decoder_buffer_delay_length);
123+ op->low_delay_mode = get_bits(gb, 1);
124+ }
125+ op->display_model_param_present =
126+ hdr->display_model_info_present && get_bits(gb, 1);
127+ if (op->display_model_param_present) {
128+ op->initial_display_delay = get_bits(gb, 4) + 1;
129+ }
130+ }
131+#if DEBUG_SEQ_HDR
132+ printf("SEQHDR: post-operating-points: off=%ld\n",
133+ (gb->ptr - init_ptr) * 8 - gb->bits_left);
134+#endif
135+ }
136+
137+ hdr->width_n_bits = get_bits(gb, 4) + 1;
138+ hdr->height_n_bits = get_bits(gb, 4) + 1;
139+ hdr->max_width = get_bits(gb, hdr->width_n_bits) + 1;
140+ hdr->max_height = get_bits(gb, hdr->height_n_bits) + 1;
141+#if DEBUG_SEQ_HDR
142+ printf("SEQHDR: post-size: off=%ld\n",
143+ (gb->ptr - init_ptr) * 8 - gb->bits_left);
144+#endif
145+ hdr->frame_id_numbers_present =
146+ hdr->reduced_still_picture_header ? 0 : get_bits(gb, 1);
147+ if (hdr->frame_id_numbers_present) {
148+ hdr->delta_frame_id_n_bits = get_bits(gb, 4) + 2;
149+ hdr->frame_id_n_bits = get_bits(gb, 3) + hdr->delta_frame_id_n_bits + 1;
150+ }
151+#if DEBUG_SEQ_HDR
152+ printf("SEQHDR: post-frame-id-numbers-present: off=%ld\n",
153+ (gb->ptr - init_ptr) * 8 - gb->bits_left);
154+#endif
155+
156+ hdr->sb128 = get_bits(gb, 1);
157+ hdr->filter_intra = get_bits(gb, 1);
158+ hdr->intra_edge_filter = get_bits(gb, 1);
159+ if (hdr->reduced_still_picture_header) {
160+ hdr->inter_intra = 0;
161+ hdr->masked_compound = 0;
162+ hdr->warped_motion = 0;
163+ hdr->dual_filter = 0;
164+ hdr->order_hint = 0;
165+ hdr->jnt_comp = 0;
166+ hdr->ref_frame_mvs = 0;
167+ hdr->order_hint_n_bits = 0;
168+ hdr->screen_content_tools = ADAPTIVE;
169+ hdr->force_integer_mv = ADAPTIVE;
170+ } else {
171+ hdr->inter_intra = get_bits(gb, 1);
172+ hdr->masked_compound = get_bits(gb, 1);
173+ hdr->warped_motion = get_bits(gb, 1);
174+ hdr->dual_filter = get_bits(gb, 1);
175+ hdr->order_hint = get_bits(gb, 1);
176+ if (hdr->order_hint) {
177+ hdr->jnt_comp = get_bits(gb, 1);
178+ hdr->ref_frame_mvs = get_bits(gb, 1);
179+ } else {
180+ hdr->jnt_comp = 0;
181+ hdr->ref_frame_mvs = 0;
182+ hdr->order_hint_n_bits = 0;
183+ }
184+ hdr->screen_content_tools = get_bits(gb, 1) ? ADAPTIVE : get_bits(gb, 1);
185+ #if DEBUG_SEQ_HDR
186+ printf("SEQHDR: post-screentools: off=%ld\n",
187+ (gb->ptr - init_ptr) * 8 - gb->bits_left);
188+ #endif
189+ hdr->force_integer_mv = hdr->screen_content_tools ?
190+ get_bits(gb, 1) ? ADAPTIVE : get_bits(gb, 1) : 2;
191+ if (hdr->order_hint)
192+ hdr->order_hint_n_bits = get_bits(gb, 3) + 1;
193+ }
194+ hdr->super_res = get_bits(gb, 1);
195+ hdr->cdef = get_bits(gb, 1);
196+ hdr->restoration = get_bits(gb, 1);
197+#if DEBUG_SEQ_HDR
198+ printf("SEQHDR: post-featurebits: off=%ld\n",
199+ (gb->ptr - init_ptr) * 8 - gb->bits_left);
200+#endif
201+
202+ const int hbd = get_bits(gb, 1);
203+ hdr->bpc = hdr->profile == 2 && hbd ? 10 + 2 * get_bits(gb, 1): 8 + 2 * hbd;
204+ hdr->hbd = hdr->bpc > 8;
205+ const int monochrome = hdr->profile != 1 ? get_bits(gb, 1) : 0;
206+ hdr->color_description_present = get_bits(gb, 1);
207+ if (hdr->color_description_present) {
208+ hdr->pri = get_bits(gb, 8);
209+ hdr->trc = get_bits(gb, 8);
210+ hdr->mtrx = get_bits(gb, 8);
211+ } else {
212+ hdr->pri = DAV1D_COLOR_PRI_UNKNOWN;
213+ hdr->trc = DAV1D_TRC_UNKNOWN;
214+ hdr->mtrx = DAV1D_MC_UNKNOWN;
215+ }
216+ if (monochrome) {
217+ hdr->color_range = get_bits(gb, 1);
218+ hdr->layout = DAV1D_PIXEL_LAYOUT_I400;
219+ hdr->chr = DAV1D_CHR_UNKNOWN;
220+ hdr->separate_uv_delta_q = 0;
221+ } else if (hdr->pri == DAV1D_COLOR_PRI_BT709 &&
222+ hdr->trc == DAV1D_TRC_SRGB &&
223+ hdr->mtrx == DAV1D_MC_IDENTITY)
224+ {
225+ hdr->layout = DAV1D_PIXEL_LAYOUT_I444;
226+ hdr->color_range = 1;
227+ if (hdr->profile != 1 && !(hdr->profile == 2 && hdr->bpc == 12))
228+ goto error;
229+ } else {
230+ hdr->color_range = get_bits(gb, 1);
231+ switch (hdr->profile) {
232+ case 0: hdr->layout = DAV1D_PIXEL_LAYOUT_I420; break;
233+ case 1: hdr->layout = DAV1D_PIXEL_LAYOUT_I444; break;
234+ case 2:
235+ if (hdr->bpc == 12) {
236+ hdr->layout = get_bits(gb, 1) ?
237+ get_bits(gb, 1) ? DAV1D_PIXEL_LAYOUT_I420 :
238+ DAV1D_PIXEL_LAYOUT_I422 :
239+ DAV1D_PIXEL_LAYOUT_I444;
240+ } else
241+ hdr->layout = DAV1D_PIXEL_LAYOUT_I422;
242+ break;
243+ }
244+ if (hdr->layout == DAV1D_PIXEL_LAYOUT_I420)
245+ hdr->chr = get_bits(gb, 2);
246+ hdr->separate_uv_delta_q = get_bits(gb, 1);
247+ }
248+#if DEBUG_SEQ_HDR
249+ printf("SEQHDR: post-colorinfo: off=%ld\n",
250+ (gb->ptr - init_ptr) * 8 - gb->bits_left);
251+#endif
252+
253+ c->seq_hdr.film_grain_present = get_bits(gb, 1);
254+#if DEBUG_SEQ_HDR
255+ printf("SEQHDR: post-filmgrain: off=%ld\n",
256+ (gb->ptr - init_ptr) * 8 - gb->bits_left);
257+#endif
258+
259+ get_bits(gb, 1); // dummy bit
260+
261+ return flush_get_bits(gb) - init_ptr;
262+
263+error:
264+ fprintf(stderr, "Error parsing sequence header\n");
265+ return -EINVAL;
266+}
267+
268+static int read_frame_size(Dav1dContext *const c, GetBits *const gb,
269+ const int use_ref)
270+{
271+ const Av1SequenceHeader *const seqhdr = &c->seq_hdr;
272+ Av1FrameHeader *const hdr = &c->frame_hdr;
273+
274+ if (use_ref) {
275+ for (int i = 0; i < 7; i++) {
276+ if (get_bits(gb, 1)) {
277+ Dav1dThreadPicture *const ref =
278+ &c->refs[c->frame_hdr.refidx[i]].p;
279+ if (!ref->p.data[0]) return -1;
280+ // FIXME render_* may be wrong
281+ hdr->render_width = hdr->width = ref->p.p.w;
282+ hdr->render_height = hdr->height = ref->p.p.h;
283+ hdr->super_res = 0; // FIXME probably wrong
284+ return 0;
285+ }
286+ }
287+ }
288+
289+ if (hdr->frame_size_override) {
290+ hdr->width = get_bits(gb, seqhdr->width_n_bits) + 1;
291+ hdr->height = get_bits(gb, seqhdr->height_n_bits) + 1;
292+ } else {
293+ hdr->width = seqhdr->max_width;
294+ hdr->height = seqhdr->max_height;
295+ }
296+ hdr->super_res = seqhdr->super_res && get_bits(gb, 1);
297+ if (hdr->super_res) return -1; // FIXME
298+ hdr->have_render_size = get_bits(gb, 1);
299+ if (hdr->have_render_size) {
300+ hdr->render_width = get_bits(gb, seqhdr->width_n_bits) + 1;
301+ hdr->render_height = get_bits(gb, seqhdr->height_n_bits) + 1;
302+ } else {
303+ hdr->render_width = hdr->width;
304+ hdr->render_height = hdr->height;
305+ }
306+ return 0;
307+}
308+
309+static inline int tile_log2(int sz, int tgt) {
310+ int k;
311+ for (k = 0; (sz << k) < tgt; k++) ;
312+ return k;
313+}
314+
315+static const Av1LoopfilterModeRefDeltas default_mode_ref_deltas = {
316+ .mode_delta = { 0, 0 },
317+ .ref_delta = { 1, 0, 0, 0, -1, 0, -1, -1 },
318+};
319+
320+static int parse_frame_hdr(Dav1dContext *const c, GetBits *const gb,
321+ const int have_trailing_bit)
322+{
323+ const uint8_t *const init_ptr = gb->ptr;
324+ const Av1SequenceHeader *const seqhdr = &c->seq_hdr;
325+ Av1FrameHeader *const hdr = &c->frame_hdr;
326+ int res;
327+
328+#define DEBUG_FRAME_HDR 0
329+
330+ hdr->show_existing_frame =
331+ !seqhdr->reduced_still_picture_header && get_bits(gb, 1);
332+#if DEBUG_FRAME_HDR
333+ printf("HDR: post-show_existing_frame: off=%ld\n",
334+ (gb->ptr - init_ptr) * 8 - gb->bits_left);
335+#endif
336+ if (hdr->show_existing_frame) {
337+ hdr->existing_frame_idx = get_bits(gb, 3);
338+ if (seqhdr->frame_id_numbers_present)
339+ hdr->frame_id = get_bits(gb, seqhdr->frame_id_n_bits);
340+ goto end;
341+ }
342+
343+ hdr->frame_type = seqhdr->reduced_still_picture_header ? KEY_FRAME : get_bits(gb, 2);
344+ hdr->show_frame = seqhdr->reduced_still_picture_header || get_bits(gb, 1);
345+ if (!hdr->show_frame)
346+ hdr->showable_frame = get_bits(gb, 1);
347+ hdr->error_resilient_mode =
348+ (hdr->frame_type == KEY_FRAME && hdr->show_frame) ||
349+ hdr->frame_type == S_FRAME ||
350+ seqhdr->reduced_still_picture_header || get_bits(gb, 1);
351+#if DEBUG_FRAME_HDR
352+ printf("HDR: post-frametype_bits: off=%ld\n",
353+ (gb->ptr - init_ptr) * 8 - gb->bits_left);
354+#endif
355+ hdr->disable_cdf_update = get_bits(gb, 1);
356+ hdr->allow_screen_content_tools = seqhdr->screen_content_tools == ADAPTIVE ?
357+ get_bits(gb, 1) : seqhdr->screen_content_tools;
358+ if (hdr->allow_screen_content_tools)
359+ hdr->force_integer_mv = seqhdr->force_integer_mv == ADAPTIVE ?
360+ get_bits(gb, 1) : seqhdr->force_integer_mv;
361+
362+ if (seqhdr->frame_id_numbers_present)
363+ hdr->frame_id = get_bits(gb, seqhdr->frame_id_n_bits);
364+
365+ hdr->frame_size_override = seqhdr->reduced_still_picture_header ? 0 :
366+ hdr->frame_type == S_FRAME ? 1 : get_bits(gb, 1);
367+#if DEBUG_FRAME_HDR
368+ printf("HDR: post-frame_size_override_flag: off=%ld\n",
369+ (gb->ptr - init_ptr) * 8 - gb->bits_left);
370+#endif
371+ hdr->frame_offset = seqhdr->order_hint ?
372+ get_bits(gb, seqhdr->order_hint_n_bits) : 0;
373+ hdr->primary_ref_frame = !hdr->error_resilient_mode && hdr->frame_type & 1 ?
374+ get_bits(gb, 3) : PRIMARY_REF_NONE;
375+
376+ if (hdr->frame_type == KEY_FRAME) {
377+ hdr->refresh_frame_flags = hdr->show_frame ? 0xff : get_bits(gb, 8);
378+ if ((res = read_frame_size(c, gb, 0)) < 0) goto error;
379+ hdr->allow_intrabc = hdr->allow_screen_content_tools &&
380+ /* FIXME: no superres scaling && */ get_bits(gb, 1);
381+ hdr->use_ref_frame_mvs = 0;
382+ } else {
383+ if (hdr->error_resilient_mode && seqhdr->order_hint)
384+ for (int i = 0; i < 8; i++)
385+ get_bits(gb, seqhdr->order_hint_n_bits);
386+
387+ if (hdr->frame_type == INTRAONLY_FRAME) {
388+ hdr->refresh_frame_flags = get_bits(gb, 8);
389+ if ((res = read_frame_size(c, gb, 0)) < 0) goto error;
390+ hdr->allow_intrabc = hdr->allow_screen_content_tools &&
391+ /* FIXME: no superres scaling && */ get_bits(gb, 1);
392+ } else {
393+ hdr->allow_intrabc = 0;
394+ hdr->refresh_frame_flags = hdr->frame_type == S_FRAME ? 0xff :
395+ get_bits(gb, 8);
396+ hdr->frame_ref_short_signaling =
397+ seqhdr->order_hint && get_bits(gb, 1);
398+ if (hdr->frame_ref_short_signaling) goto error; // FIXME
399+ for (int i = 0; i < 7; i++) {
400+ hdr->refidx[i] = get_bits(gb, 3);
401+ if (seqhdr->frame_id_numbers_present)
402+ get_bits(gb, seqhdr->delta_frame_id_n_bits);
403+ }
404+ const int use_ref = !hdr->error_resilient_mode &&
405+ hdr->frame_size_override;
406+ if ((res = read_frame_size(c, gb, use_ref)) < 0) goto error;
407+ hdr->hp = !hdr->force_integer_mv && get_bits(gb, 1);
408+ hdr->subpel_filter_mode = get_bits(gb, 1) ? FILTER_SWITCHABLE :
409+ get_bits(gb, 2);
410+ hdr->switchable_motion_mode = get_bits(gb, 1);
411+ hdr->use_ref_frame_mvs = !hdr->error_resilient_mode &&
412+ seqhdr->ref_frame_mvs && seqhdr->order_hint &&
413+ hdr->frame_type & 1 && get_bits(gb, 1);
414+ }
415+ }
416+#if DEBUG_FRAME_HDR
417+ printf("HDR: post-frametype-specific-bits: off=%ld\n",
418+ (gb->ptr - init_ptr) * 8 - gb->bits_left);
419+#endif
420+
421+ hdr->refresh_context = !seqhdr->reduced_still_picture_header &&
422+ !hdr->disable_cdf_update && !get_bits(gb, 1);
423+#if DEBUG_FRAME_HDR
424+ printf("HDR: post-refresh_context: off=%ld\n",
425+ (gb->ptr - init_ptr) * 8 - gb->bits_left);
426+#endif
427+
428+ // tile data
429+ hdr->tiling.uniform = get_bits(gb, 1);
430+ const int sbsz_min1 = (64 << seqhdr->sb128) - 1;
431+ int sbsz_log2 = 6 + seqhdr->sb128;
432+ int sbw = (hdr->width + sbsz_min1) >> sbsz_log2;
433+ int sbh = (hdr->height + sbsz_min1) >> sbsz_log2;
434+ int max_tile_width_sb = 4096 >> sbsz_log2, max_tile_height_sb;
435+ int max_tile_area_sb = 4096 * 2304 >> (2 * sbsz_log2);
436+ hdr->tiling.min_log2_cols = tile_log2(max_tile_width_sb, sbw);
437+ hdr->tiling.max_log2_cols = tile_log2(1, imin(sbw, 1024));
438+ hdr->tiling.max_log2_rows = tile_log2(1, imin(sbh, 1024));
439+ int min_log2_tiles = imax(tile_log2(max_tile_area_sb, sbw * sbh),
440+ hdr->tiling.min_log2_cols);
441+ if (hdr->tiling.uniform) {
442+ for (hdr->tiling.log2_cols = hdr->tiling.min_log2_cols;
443+ hdr->tiling.log2_cols < hdr->tiling.max_log2_cols && get_bits(gb, 1);
444+ hdr->tiling.log2_cols++) ;
445+ const int tile_w = 1 + ((sbw - 1) >> hdr->tiling.log2_cols);
446+ hdr->tiling.cols = 0;
447+ for (int sbx = 0; sbx < sbw; sbx += tile_w, hdr->tiling.cols++)
448+ hdr->tiling.col_start_sb[hdr->tiling.cols] = sbx;
449+ hdr->tiling.min_log2_rows =
450+ imax(min_log2_tiles - hdr->tiling.log2_cols, 0);
451+ max_tile_height_sb = sbh >> hdr->tiling.min_log2_rows;
452+
453+ for (hdr->tiling.log2_rows = hdr->tiling.min_log2_rows;
454+ hdr->tiling.log2_rows < hdr->tiling.max_log2_rows && get_bits(gb, 1);
455+ hdr->tiling.log2_rows++) ;
456+ const int tile_h = 1 + ((sbh - 1) >> hdr->tiling.log2_rows);
457+ hdr->tiling.rows = 0;
458+ for (int sby = 0; sby < sbh; sby += tile_h, hdr->tiling.rows++)
459+ hdr->tiling.row_start_sb[hdr->tiling.rows] = sby;
460+ } else {
461+ hdr->tiling.cols = 0;
462+ int widest_tile = 0, max_tile_area_sb = sbw * sbh;
463+ for (int sbx = 0; sbx < sbw; hdr->tiling.cols++) {
464+ const int tile_w = get_uniform(gb, imin(sbw - sbx,
465+ max_tile_width_sb));
466+ hdr->tiling.col_start_sb[hdr->tiling.cols] = sbx;
467+ sbx += tile_w;
468+ widest_tile = imax(widest_tile, tile_w);
469+ }
470+ hdr->tiling.log2_cols = tile_log2(1, hdr->tiling.cols);
471+ if (min_log2_tiles) max_tile_area_sb >>= min_log2_tiles + 1;
472+ max_tile_height_sb = imax(max_tile_area_sb / widest_tile, 1);
473+
474+ hdr->tiling.rows = 0;
475+ for (int sby = 0; sby < sbh; hdr->tiling.rows++) {
476+ const int tile_h = get_uniform(gb, imin(sbh - sby,
477+ max_tile_height_sb));
478+ hdr->tiling.row_start_sb[hdr->tiling.rows] = sby;
479+ sby += tile_h;
480+ }
481+ hdr->tiling.log2_rows = tile_log2(1, hdr->tiling.rows);
482+ }
483+ hdr->tiling.col_start_sb[hdr->tiling.cols] = sbw;
484+ hdr->tiling.row_start_sb[hdr->tiling.rows] = sbh;
485+ if (hdr->tiling.log2_cols || hdr->tiling.log2_rows) {
486+ hdr->tiling.update = get_bits(gb, hdr->tiling.log2_cols +
487+ hdr->tiling.log2_rows);
488+ hdr->tiling.n_bytes = get_bits(gb, 2) + 1;
489+ } else {
490+ hdr->tiling.n_bytes = hdr->tiling.update = 0;
491+ }
492+#if DEBUG_FRAME_HDR
493+ printf("HDR: post-tiling: off=%ld\n",
494+ (gb->ptr - init_ptr) * 8 - gb->bits_left);
495+#endif
496+
497+ // quant data
498+ hdr->quant.yac = get_bits(gb, 8);
499+ hdr->quant.ydc_delta = get_bits(gb, 1) ? get_sbits(gb, 6) : 0;
500+ if (seqhdr->layout != DAV1D_PIXEL_LAYOUT_I400) {
501+ hdr->quant.udc_delta = get_bits(gb, 1) ? get_sbits(gb, 6) : 0;
502+ hdr->quant.uac_delta = get_bits(gb, 1) ? get_sbits(gb, 6) : 0;
503+ if (seqhdr->separate_uv_delta_q) {
504+ hdr->quant.vdc_delta = get_bits(gb, 1) ? get_sbits(gb, 6) : 0;
505+ hdr->quant.vac_delta = get_bits(gb, 1) ? get_sbits(gb, 6) : 0;
506+ } else {
507+ hdr->quant.vdc_delta = hdr->quant.udc_delta;
508+ hdr->quant.vac_delta = hdr->quant.uac_delta;
509+ }
510+ }
511+#if DEBUG_FRAME_HDR
512+ printf("HDR: post-quant: off=%ld\n",
513+ (gb->ptr - init_ptr) * 8 - gb->bits_left);
514+#endif
515+ hdr->quant.qm = get_bits(gb, 1);
516+ if (hdr->quant.qm) {
517+ hdr->quant.qm_y = get_bits(gb, 4);
518+ hdr->quant.qm_u = get_bits(gb, 4);
519+ hdr->quant.qm_v = seqhdr->separate_uv_delta_q ? get_bits(gb, 4) :
520+ hdr->quant.qm_u;
521+ }
522+#if DEBUG_FRAME_HDR
523+ printf("HDR: post-qm: off=%ld\n",
524+ (gb->ptr - init_ptr) * 8 - gb->bits_left);
525+#endif
526+
527+ // segmentation data
528+ hdr->segmentation.enabled = get_bits(gb, 1);
529+ if (hdr->segmentation.enabled) {
530+ if (hdr->primary_ref_frame == PRIMARY_REF_NONE) {
531+ hdr->segmentation.update_map = 1;
532+ hdr->segmentation.temporal = 0;
533+ hdr->segmentation.update_data = 1;
534+ } else {
535+ hdr->segmentation.update_map = get_bits(gb, 1);
536+ hdr->segmentation.temporal =
537+ hdr->segmentation.update_map ? get_bits(gb, 1) : 0;
538+ hdr->segmentation.update_data = get_bits(gb, 1);
539+ }
540+
541+ if (hdr->segmentation.update_data) {
542+ hdr->segmentation.seg_data.preskip = 0;
543+ hdr->segmentation.seg_data.last_active_segid = -1;
544+ for (int i = 0; i < NUM_SEGMENTS; i++) {
545+ Av1SegmentationData *const seg =
546+ &hdr->segmentation.seg_data.d[i];
547+ if (get_bits(gb, 1)) {
548+ seg->delta_q = get_sbits(gb, 8);
549+ hdr->segmentation.seg_data.last_active_segid = i;
550+ } else {
551+ seg->delta_q = 0;
552+ }
553+ if (get_bits(gb, 1)) {
554+ seg->delta_lf_y_v = get_sbits(gb, 6);
555+ hdr->segmentation.seg_data.last_active_segid = i;
556+ } else {
557+ seg->delta_lf_y_v = 0;
558+ }
559+ if (get_bits(gb, 1)) {
560+ seg->delta_lf_y_h = get_sbits(gb, 6);
561+ hdr->segmentation.seg_data.last_active_segid = i;
562+ } else {
563+ seg->delta_lf_y_h = 0;
564+ }
565+ if (get_bits(gb, 1)) {
566+ seg->delta_lf_u = get_sbits(gb, 6);
567+ hdr->segmentation.seg_data.last_active_segid = i;
568+ } else {
569+ seg->delta_lf_u = 0;
570+ }
571+ if (get_bits(gb, 1)) {
572+ seg->delta_lf_v = get_sbits(gb, 6);
573+ hdr->segmentation.seg_data.last_active_segid = i;
574+ } else {
575+ seg->delta_lf_v = 0;
576+ }
577+ if (get_bits(gb, 1)) {
578+ seg->ref = get_bits(gb, 3);
579+ hdr->segmentation.seg_data.last_active_segid = i;
580+ hdr->segmentation.seg_data.preskip = 1;
581+ } else {
582+ seg->ref = -1;
583+ }
584+ if ((seg->skip = get_bits(gb, 1))) {
585+ hdr->segmentation.seg_data.last_active_segid = i;
586+ hdr->segmentation.seg_data.preskip = 1;
587+ }
588+ if ((seg->globalmv = get_bits(gb, 1))) {
589+ hdr->segmentation.seg_data.last_active_segid = i;
590+ hdr->segmentation.seg_data.preskip = 1;
591+ }
592+ }
593+ } else {
594+ const int pri_ref = hdr->refidx[hdr->primary_ref_frame];
595+ hdr->segmentation.seg_data = c->refs[pri_ref].seg_data;
596+ }
597+ } else {
598+ const int pri_ref = hdr->refidx[hdr->primary_ref_frame];
599+ hdr->segmentation.seg_data = c->refs[pri_ref].seg_data;
600+ }
601+#if DEBUG_FRAME_HDR
602+ printf("HDR: post-segmentation: off=%ld\n",
603+ (gb->ptr - init_ptr) * 8 - gb->bits_left);
604+#endif
605+
606+ // delta q
607+ hdr->delta_q_present = hdr->quant.yac ? get_bits(gb, 1) : 0;
608+ hdr->delta_q_res_log2 = hdr->delta_q_present ? get_bits(gb, 2) : 0;
609+ hdr->delta_lf_present = hdr->delta_q_present && !hdr->allow_intrabc &&
610+ get_bits(gb, 1);
611+ hdr->delta_lf_res_log2 = hdr->delta_lf_present ? get_bits(gb, 2) : 0;
612+ hdr->delta_lf_multi = hdr->delta_lf_present ? get_bits(gb, 1) : 0;
613+#if DEBUG_FRAME_HDR
614+ printf("HDR: post-delta_q_lf_flags: off=%ld\n",
615+ (gb->ptr - init_ptr) * 8 - gb->bits_left);
616+#endif
617+
618+ // derive lossless flags
619+ const int delta_lossless = !hdr->quant.ydc_delta && !hdr->quant.udc_delta &&
620+ !hdr->quant.uac_delta && !hdr->quant.vdc_delta && !hdr->quant.vac_delta;
621+ hdr->all_lossless = 1;
622+ for (int i = 0; i < NUM_SEGMENTS; i++) {
623+ hdr->segmentation.qidx[i] = hdr->segmentation.enabled ?
624+ iclip_u8(hdr->quant.yac + hdr->segmentation.seg_data.d[i].delta_q) :
625+ hdr->quant.yac;
626+ hdr->segmentation.lossless[i] =
627+ !hdr->segmentation.qidx[i] && delta_lossless;
628+ hdr->all_lossless &= hdr->segmentation.lossless[i];
629+ }
630+
631+ // loopfilter
632+ if (hdr->all_lossless || hdr->allow_intrabc) {
633+ hdr->loopfilter.level_y[0] = hdr->loopfilter.level_y[1] = 0;
634+ hdr->loopfilter.level_u = hdr->loopfilter.level_v = 0;
635+ hdr->loopfilter.sharpness = 0;
636+ hdr->loopfilter.mode_ref_delta_enabled = 1;
637+ hdr->loopfilter.mode_ref_delta_update = 1;
638+ hdr->loopfilter.mode_ref_deltas = default_mode_ref_deltas;
639+ } else {
640+ hdr->loopfilter.level_y[0] = get_bits(gb, 6);
641+ hdr->loopfilter.level_y[1] = get_bits(gb, 6);
642+ if (seqhdr->layout != DAV1D_PIXEL_LAYOUT_I400 &&
643+ (hdr->loopfilter.level_y[0] || hdr->loopfilter.level_y[1]))
644+ {
645+ hdr->loopfilter.level_u = get_bits(gb, 6);
646+ hdr->loopfilter.level_v = get_bits(gb, 6);
647+ }
648+ hdr->loopfilter.sharpness = get_bits(gb, 3);
649+
650+ if (hdr->primary_ref_frame == PRIMARY_REF_NONE) {
651+ hdr->loopfilter.mode_ref_deltas = default_mode_ref_deltas;
652+ } else {
653+ const int ref = hdr->refidx[hdr->primary_ref_frame];
654+ hdr->loopfilter.mode_ref_deltas = c->refs[ref].lf_mode_ref_deltas;
655+ }
656+ hdr->loopfilter.mode_ref_delta_enabled = get_bits(gb, 1);
657+ if (hdr->loopfilter.mode_ref_delta_enabled) {
658+ hdr->loopfilter.mode_ref_delta_update = get_bits(gb, 1);
659+ if (hdr->loopfilter.mode_ref_delta_update) {
660+ for (int i = 0; i < 8; i++)
661+ if (get_bits(gb, 1))
662+ hdr->loopfilter.mode_ref_deltas.ref_delta[i] =
663+ get_sbits(gb, 6);
664+ for (int i = 0; i < 2; i++)
665+ if (get_bits(gb, 1))
666+ hdr->loopfilter.mode_ref_deltas.mode_delta[i] =
667+ get_sbits(gb, 6);
668+ }
669+ }
670+ }
671+#if DEBUG_FRAME_HDR
672+ printf("HDR: post-lpf: off=%ld\n",
673+ (gb->ptr - init_ptr) * 8 - gb->bits_left);
674+#endif
675+
676+ // cdef
677+ if (!hdr->all_lossless && seqhdr->cdef && !hdr->allow_intrabc) {
678+ hdr->cdef.damping = get_bits(gb, 2) + 3;
679+ hdr->cdef.n_bits = get_bits(gb, 2);
680+ for (int i = 0; i < (1 << hdr->cdef.n_bits); i++) {
681+ hdr->cdef.y_strength[i] = get_bits(gb, 6);
682+ if (seqhdr->layout != DAV1D_PIXEL_LAYOUT_I400)
683+ hdr->cdef.uv_strength[i] = get_bits(gb, 6);
684+ }
685+ } else {
686+ hdr->cdef.n_bits = 0;
687+ hdr->cdef.y_strength[0] = 0;
688+ hdr->cdef.uv_strength[0] = 0;
689+ }
690+#if DEBUG_FRAME_HDR
691+ printf("HDR: post-cdef: off=%ld\n",
692+ (gb->ptr - init_ptr) * 8 - gb->bits_left);
693+#endif
694+
695+ // restoration
696+ if (!hdr->all_lossless && seqhdr->restoration && !hdr->allow_intrabc) {
697+ hdr->restoration.type[0] = get_bits(gb, 2);
698+ if (seqhdr->layout != DAV1D_PIXEL_LAYOUT_I400) {
699+ hdr->restoration.type[1] = get_bits(gb, 2);
700+ hdr->restoration.type[2] = get_bits(gb, 2);
701+ }
702+
703+ if (hdr->restoration.type[0] || hdr->restoration.type[1] ||
704+ hdr->restoration.type[2])
705+ {
706+ // Log2 of the restoration unit size.
707+ hdr->restoration.unit_size[0] = 6 + seqhdr->sb128;
708+ if (get_bits(gb, 1)) {
709+ hdr->restoration.unit_size[0]++;
710+ if (!seqhdr->sb128)
711+ hdr->restoration.unit_size[0] += get_bits(gb, 1);
712+ }
713+ hdr->restoration.unit_size[1] = hdr->restoration.unit_size[0];
714+ if ((hdr->restoration.type[1] || hdr->restoration.type[2]) &&
715+ seqhdr->layout == DAV1D_PIXEL_LAYOUT_I420)
716+ {
717+ hdr->restoration.unit_size[1] -= get_bits(gb, 1);
718+ }
719+ } else {
720+ hdr->restoration.unit_size[0] = 8;
721+ }
722+ } else {
723+ hdr->restoration.type[0] = RESTORATION_NONE;
724+ hdr->restoration.type[1] = RESTORATION_NONE;
725+ hdr->restoration.type[2] = RESTORATION_NONE;
726+ }
727+#if DEBUG_FRAME_HDR
728+ printf("HDR: post-restoration: off=%ld\n",
729+ (gb->ptr - init_ptr) * 8 - gb->bits_left);
730+#endif
731+
732+ hdr->txfm_mode = hdr->all_lossless ? TX_4X4_ONLY :
733+ get_bits(gb, 1) ? TX_SWITCHABLE : TX_LARGEST;
734+#if DEBUG_FRAME_HDR
735+ printf("HDR: post-txfmmode: off=%ld\n",
736+ (gb->ptr - init_ptr) * 8 - gb->bits_left);
737+#endif
738+ hdr->switchable_comp_refs = hdr->frame_type & 1 ? get_bits(gb, 1) : 0;
739+#if DEBUG_FRAME_HDR
740+ printf("HDR: post-refmode: off=%ld\n",
741+ (gb->ptr - init_ptr) * 8 - gb->bits_left);
742+#endif
743+ hdr->skip_mode_allowed = 0;
744+ if (hdr->switchable_comp_refs && hdr->frame_type & 1) {
745+ const unsigned poc = hdr->frame_offset;
746+ unsigned off_before[2] = { 0xFFFFFFFF, 0xFFFFFFFF };
747+ int off_after = -1;
748+ int off_before_idx[2], off_after_idx;
749+ for (int i = 0; i < 7; i++) {
750+ const unsigned refpoc = c->refs[hdr->refidx[i]].p.p.poc;
751+
752+ const int diff = get_poc_diff(seqhdr->order_hint_n_bits, refpoc, poc);
753+ if (diff > 0) {
754+ if (off_after == -1 || get_poc_diff(seqhdr->order_hint_n_bits,
755+ off_after, refpoc) > 0)
756+ {
757+ off_after = refpoc;
758+ off_after_idx = i;
759+ }
760+ } else if (diff < 0) {
761+ if (off_before[0] == 0xFFFFFFFFU ||
762+ get_poc_diff(seqhdr->order_hint_n_bits,
763+ refpoc, off_before[0]) > 0)
764+ {
765+ off_before[1] = off_before[0];
766+ off_before[0] = refpoc;
767+ off_before_idx[1] = off_before_idx[0];
768+ off_before_idx[0] = i;
769+ } else if (refpoc != off_before[0] &&
770+ (off_before[1] == 0xFFFFFFFFU ||
771+ get_poc_diff(seqhdr->order_hint_n_bits,
772+ refpoc, off_before[1]) > 0))
773+ {
774+ off_before[1] = refpoc;
775+ off_before_idx[1] = i;
776+ }
777+ }
778+ }
779+
780+ if (off_before[0] != 0xFFFFFFFFU && off_after != -1) {
781+ hdr->skip_mode_refs[0] = off_before_idx[0];
782+ hdr->skip_mode_refs[1] = off_after_idx;
783+ hdr->skip_mode_allowed = 1;
784+ } else if (off_before[0] != 0xFFFFFFFFU &&
785+ off_before[1] != 0xFFFFFFFFU)
786+ {
787+ hdr->skip_mode_refs[0] = off_before_idx[0];
788+ hdr->skip_mode_refs[1] = off_before_idx[1];
789+ hdr->skip_mode_allowed = 1;
790+ }
791+ }
792+ hdr->skip_mode_enabled = hdr->skip_mode_allowed ? get_bits(gb, 1) : 0;
793+#if DEBUG_FRAME_HDR
794+ printf("HDR: post-extskip: off=%ld\n",
795+ (gb->ptr - init_ptr) * 8 - gb->bits_left);
796+#endif
797+ hdr->warp_motion = !hdr->error_resilient_mode && hdr->frame_type & 1 &&
798+ seqhdr->warped_motion && get_bits(gb, 1);
799+#if DEBUG_FRAME_HDR
800+ printf("HDR: post-warpmotionbit: off=%ld\n",
801+ (gb->ptr - init_ptr) * 8 - gb->bits_left);
802+#endif
803+ hdr->reduced_txtp_set = get_bits(gb, 1);
804+#if DEBUG_FRAME_HDR
805+ printf("HDR: post-reducedtxtpset: off=%ld\n",
806+ (gb->ptr - init_ptr) * 8 - gb->bits_left);
807+#endif
808+
809+ for (int i = 0; i < 7; i++)
810+ hdr->gmv[i] = default_wm_params;
811+
812+ if (hdr->frame_type & 1) {
813+ for (int i = 0; i < 7; i++) {
814+ hdr->gmv[i].type = !get_bits(gb, 1) ? WM_TYPE_IDENTITY :
815+ get_bits(gb, 1) ? WM_TYPE_ROT_ZOOM :
816+ get_bits(gb, 1) ? WM_TYPE_TRANSLATION :
817+ WM_TYPE_AFFINE;
818+
819+ if (hdr->gmv[i].type == WM_TYPE_IDENTITY) continue;
820+
821+ const WarpedMotionParams *const ref_gmv =
822+ hdr->primary_ref_frame == PRIMARY_REF_NONE ? &default_wm_params :
823+ &c->refs[hdr->refidx[hdr->primary_ref_frame]].gmv[i];
824+ int32_t *const mat = hdr->gmv[i].matrix;
825+ const int32_t *const ref_mat = ref_gmv->matrix;
826+ int bits, shift;
827+
828+ if (hdr->gmv[i].type >= WM_TYPE_ROT_ZOOM) {
829+ mat[2] = (1 << 16) + 2 *
830+ get_bits_subexp(gb, (ref_mat[2] - (1 << 16)) >> 1, 12);
831+ mat[3] = 2 * get_bits_subexp(gb, ref_mat[3] >> 1, 12);
832+
833+ bits = 12;
834+ shift = 10;
835+ } else {
836+ bits = 9 - !hdr->hp;
837+ shift = 13 + !hdr->hp;
838+ }
839+
840+ if (hdr->gmv[i].type == WM_TYPE_AFFINE) {
841+ mat[4] = 2 * get_bits_subexp(gb, ref_mat[4] >> 1, 12);
842+ mat[5] = (1 << 16) + 2 *
843+ get_bits_subexp(gb, (ref_mat[5] - (1 << 16)) >> 1, 12);
844+ } else {
845+ mat[4] = -mat[3];
846+ mat[5] = mat[2];
847+ }
848+
849+ mat[0] = get_bits_subexp(gb, ref_mat[0] >> shift, bits) * (1 << shift);
850+ mat[1] = get_bits_subexp(gb, ref_mat[1] >> shift, bits) * (1 << shift);
851+
852+ if (get_shear_params(&hdr->gmv[i]))
853+ goto error;
854+ }
855+ }
856+#if DEBUG_FRAME_HDR
857+ printf("HDR: post-gmv: off=%ld\n",
858+ (gb->ptr - init_ptr) * 8 - gb->bits_left);
859+#endif
860+
861+ hdr->film_grain.present = seqhdr->film_grain_present && get_bits(gb, 1);
862+ if (hdr->film_grain.present) {
863+ hdr->film_grain.seed = get_bits(gb, 16);
864+ hdr->film_grain.update = hdr->frame_type != INTER_FRAME || get_bits(gb, 1);
865+ if (!hdr->film_grain.update) {
866+ const int refidx = get_bits(gb, 3);
867+ int i;
868+ for (i = 0; i < 7; i++)
869+ if (hdr->refidx[i] == refidx)
870+ break;
871+ if (i == 7) goto error;
872+ hdr->film_grain.data = c->refs[refidx].film_grain;
873+ } else {
874+ Av1FilmGrainData *const fgd = &hdr->film_grain.data;
875+
876+ fgd->num_y_points = get_bits(gb, 4);
877+ if (fgd->num_y_points > 14) goto error;
878+ for (int i = 0; i < fgd->num_y_points; i++) {
879+ fgd->y_points[i][0] = get_bits(gb, 8);
880+ if (i && fgd->y_points[i - 1][0] >= fgd->y_points[i][0])
881+ goto error;
882+ fgd->y_points[i][1] = get_bits(gb, 8);
883+ }
884+
885+ fgd->chroma_scaling_from_luma =
886+ seqhdr->layout != DAV1D_PIXEL_LAYOUT_I400 && get_bits(gb, 1);
887+ if (seqhdr->layout == DAV1D_PIXEL_LAYOUT_I400 ||
888+ fgd->chroma_scaling_from_luma ||
889+ (seqhdr->layout == DAV1D_PIXEL_LAYOUT_I420 && !fgd->num_y_points))
890+ {
891+ fgd->num_uv_points[0] = fgd->num_uv_points[1] = 0;
892+ } else for (int pl = 0; pl < 2; pl++) {
893+ fgd->num_uv_points[pl] = get_bits(gb, 4);
894+ if (fgd->num_uv_points[pl] > 10) goto error;
895+ for (int i = 0; i < fgd->num_uv_points[pl]; i++) {
896+ fgd->uv_points[pl][i][0] = get_bits(gb, 8);
897+ if (i && fgd->uv_points[pl][i - 1][0] >= fgd->uv_points[pl][i][0])
898+ goto error;
899+ fgd->uv_points[pl][i][1] = get_bits(gb, 8);
900+ }
901+ }
902+
903+ if (seqhdr->layout == DAV1D_PIXEL_LAYOUT_I420 &&
904+ !!fgd->num_uv_points[0] != !!fgd->num_uv_points[1])
905+ {
906+ goto error;
907+ }
908+
909+ fgd->scaling_shift = get_bits(gb, 2) + 8;
910+ fgd->ar_coeff_lag = get_bits(gb, 2);
911+ const int num_y_pos = 2 * fgd->ar_coeff_lag * (fgd->ar_coeff_lag + 1);
912+ if (fgd->num_y_points)
913+ for (int i = 0; i < num_y_pos; i++)
914+ fgd->ar_coeffs_y[i] = get_bits(gb, 8) - 128;
915+ for (int pl = 0; pl < 2; pl++)
916+ if (fgd->num_uv_points[pl] || fgd->chroma_scaling_from_luma) {
917+ const int num_uv_pos = num_y_pos + !!fgd->num_y_points;
918+ for (int i = 0; i < num_uv_pos; i++)
919+ fgd->ar_coeffs_uv[pl][i] = get_bits(gb, 8) - 128;
920+ }
921+ fgd->ar_coeff_shift = get_bits(gb, 2) + 6;
922+ fgd->grain_scale_shift = get_bits(gb, 2);
923+ for (int pl = 0; pl < 2; pl++)
924+ if (fgd->num_uv_points[pl]) {
925+ fgd->uv_mult[pl] = get_bits(gb, 8);
926+ fgd->uv_luma_mult[pl] = get_bits(gb, 8);
927+ fgd->uv_offset[pl] = get_bits(gb, 9);
928+ }
929+ fgd->overlap_flag = get_bits(gb, 1);
930+ fgd->clip_to_restricted_range = get_bits(gb, 1);
931+ }
932+ } else {
933+ memset(&hdr->film_grain.data, 0, sizeof(hdr->film_grain));
934+ }
935+#if DEBUG_FRAME_HDR
936+ printf("HDR: post-filmgrain: off=%ld\n",
937+ (gb->ptr - init_ptr) * 8 - gb->bits_left);
938+#endif
939+
940+end:
941+
942+ if (have_trailing_bit)
943+ get_bits(gb, 1); // dummy bit
944+
945+ return flush_get_bits(gb) - init_ptr;
946+
947+error:
948+ fprintf(stderr, "Error parsing frame header\n");
949+ return -EINVAL;
950+}
951+
952+static int parse_tile_hdr(Dav1dContext *const c, GetBits *const gb) {
953+ const uint8_t *const init_ptr = gb->ptr;
954+
955+ int have_tile_pos = 0;
956+ const int n_bits = c->frame_hdr.tiling.log2_cols +
957+ c->frame_hdr.tiling.log2_rows;
958+ if (n_bits)
959+ have_tile_pos = get_bits(gb, 1);
960+
961+ if (have_tile_pos) {
962+ c->tile[c->n_tile_data].start = get_bits(gb, n_bits);
963+ c->tile[c->n_tile_data].end = get_bits(gb, n_bits);
964+ } else {
965+ c->tile[c->n_tile_data].start = 0;
966+ c->tile[c->n_tile_data].end = (1 << n_bits) - 1;
967+ }
968+
969+ return flush_get_bits(gb) - init_ptr;
970+}
971+
972+int parse_obus(Dav1dContext *const c, Dav1dData *const in) {
973+ GetBits gb;
974+ int res;
975+
976+ init_get_bits(&gb, in->data, in->sz);
977+
978+ // obu header
979+ get_bits(&gb, 1); // obu_forbidden_bit
980+ const enum ObuType type = get_bits(&gb, 4);
981+ const int has_extension = get_bits(&gb, 1);
982+ const int has_length_field = get_bits(&gb, 1);
983+ if (!has_length_field) goto error;
984+ get_bits(&gb, 1); // reserved
985+ if (has_extension) {
986+ get_bits(&gb, 3); // temporal_layer_id
987+ get_bits(&gb, 2); // enhancement_layer_id
988+ get_bits(&gb, 3); // reserved
989+ }
990+
991+ // obu length field
992+ int len = 0, more, i = 0;
993+ do {
994+ more = get_bits(&gb, 1);
995+ len |= get_bits(&gb, 7) << (i * 7);
996+ if (more && ++i == 8) goto error;
997+ } while (more);
998+ if (gb.error) goto error;
999+
1000+ int off = flush_get_bits(&gb) - in->data;
1001+ const int init_off = off;
1002+ if (len > in->sz - off) goto error;
1003+
1004+ switch (type) {
1005+ case OBU_SEQ_HDR:
1006+ if ((res = parse_seq_hdr(c, &gb)) < 0)
1007+ return res;
1008+ if (res != len) goto error;
1009+ c->have_seq_hdr = 1;
1010+ c->have_frame_hdr = 0;
1011+ break;
1012+ case OBU_FRAME:
1013+ case OBU_FRAME_HDR:
1014+ if (!c->have_seq_hdr) goto error;
1015+ if ((res = parse_frame_hdr(c, &gb, type == OBU_FRAME_HDR)) < 0)
1016+ return res;
1017+ c->have_frame_hdr = 1;
1018+ for (int n = 0; n < c->n_tile_data; n++)
1019+ dav1d_data_unref(&c->tile[n].data);
1020+ c->n_tile_data = 0;
1021+ c->tile_mask = 0;
1022+ if (type == OBU_FRAME_HDR) break;
1023+ off += res;
1024+ // fall-through
1025+ case OBU_TILE_GRP:
1026+ if (!c->have_frame_hdr) goto error;
1027+ if (c->n_tile_data >= 256) goto error;
1028+ if ((res = parse_tile_hdr(c, &gb)) < 0)
1029+ return res;
1030+ off += res;
1031+ dav1d_ref_inc(in->ref);
1032+ c->tile[c->n_tile_data].data.ref = in->ref;
1033+ c->tile[c->n_tile_data].data.data = in->data + off;
1034+ c->tile[c->n_tile_data].data.sz = len + init_off - off;
1035+ if (c->tile[c->n_tile_data].start > c->tile[c->n_tile_data].end)
1036+ goto error;
1037+#define mask(a) ((1 << (a)) - 1)
1038+ const unsigned tile_mask = mask(c->tile[c->n_tile_data].end + 1) -
1039+ mask(c->tile[c->n_tile_data].start);
1040+#undef mask
1041+ if (tile_mask & c->tile_mask) goto error; // tile overlap
1042+ c->tile_mask |= tile_mask;
1043+ c->n_tile_data++;
1044+ break;
1045+ case OBU_PADDING:
1046+ case OBU_TD:
1047+ case OBU_METADATA:
1048+ // ignore OBUs we don't care about
1049+ break;
1050+ default:
1051+ fprintf(stderr, "Unknown OBU type %d of size %d\n", type, len);
1052+ return -EINVAL;
1053+ }
1054+
1055+ const int n_tiles = 1 << (c->frame_hdr.tiling.log2_cols +
1056+ c->frame_hdr.tiling.log2_rows);
1057+ if (c->have_seq_hdr && c->have_frame_hdr &&
1058+ c->tile_mask == (1 << n_tiles) - 1)
1059+ {
1060+ assert(c->n_tile_data);
1061+ submit_frame(c);
1062+ assert(!c->n_tile_data);
1063+ c->have_frame_hdr = 0;
1064+ c->tile_mask = 0;
1065+ } else if (c->have_seq_hdr && c->have_frame_hdr &&
1066+ c->frame_hdr.show_existing_frame)
1067+ {
1068+ if (c->n_fc == 1) {
1069+ dav1d_picture_ref(&c->out,
1070+ &c->refs[c->frame_hdr.existing_frame_idx].p.p);
1071+ } else {
1072+ // need to append this to the frame output queue
1073+ const unsigned next = c->frame_thread.next++;
1074+ if (c->frame_thread.next == c->n_fc)
1075+ c->frame_thread.next = 0;
1076+
1077+ Dav1dFrameContext *const f = &c->fc[next];
1078+ pthread_mutex_lock(&f->frame_thread.td.lock);
1079+ while (f->n_tile_data > 0)
1080+ pthread_cond_wait(&f->frame_thread.td.cond,
1081+ &f->frame_thread.td.lock);
1082+ Dav1dThreadPicture *const out_delayed =
1083+ &c->frame_thread.out_delayed[next];
1084+ if (out_delayed->p.data[0]) {
1085+ if (out_delayed->visible)
1086+ dav1d_picture_ref(&c->out, &out_delayed->p);
1087+ dav1d_thread_picture_unref(out_delayed);
1088+ }
1089+ dav1d_thread_picture_ref(out_delayed,
1090+ &c->refs[c->frame_hdr.existing_frame_idx].p);
1091+ out_delayed->visible = 1;
1092+ pthread_mutex_unlock(&f->frame_thread.td.lock);
1093+ }
1094+ c->have_frame_hdr = 0;
1095+ }
1096+
1097+ return len + init_off;
1098+
1099+error:
1100+ fprintf(stderr, "Error parsing OBU data\n");
1101+ return -EINVAL;
1102+}
src/obu.h+36−0
@@ -0,0 +1,36 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __DAV1D_SRC_OBU_H__
29+#define __DAV1D_SRC_OBU_H__
30+
31+#include "dav1d/data.h"
32+#include "src/internal.h"
33+
34+int parse_obus(Dav1dContext *c, Dav1dData *in);
35+
36+#endif /* __DAV1D_SRC_OBU_H__ */
src/picture.c+187−0
@@ -0,0 +1,187 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#include "config.h"
29+
30+#include <assert.h>
31+#include <errno.h>
32+#include <stdio.h>
33+#include <stdlib.h>
34+#include <string.h>
35+
36+#include "common/intops.h"
37+#include "common/mem.h"
38+#include "common/validate.h"
39+
40+#include "src/picture.h"
41+#include "src/ref.h"
42+
43+static int picture_alloc_with_edges(Dav1dPicture *const p,
44+ const int w, const int h,
45+ const enum Dav1dPixelLayout layout,
46+ const int bpc,
47+ const int extra, void **const extra_ptr)
48+{
49+ int aligned_h;
50+
51+ if (p->data[0]) {
52+ fprintf(stderr, "Picture already allocated!\n");
53+ return -1;
54+ }
55+ assert(bpc > 0 && bpc <= 16);
56+
57+ const int hbd = bpc > 8;
58+ const int aligned_w = (w + 127) & ~127;
59+ const int has_chroma = layout != DAV1D_PIXEL_LAYOUT_I400;
60+ const int ss_ver = layout == DAV1D_PIXEL_LAYOUT_I420;
61+ const int ss_hor = layout != DAV1D_PIXEL_LAYOUT_I444;
62+ p->stride[0] = aligned_w << hbd;
63+ p->stride[1] = has_chroma ? (aligned_w >> ss_hor) << hbd : 0;
64+ p->p.w = w;
65+ p->p.h = h;
66+ p->p.pri = DAV1D_COLOR_PRI_UNKNOWN;
67+ p->p.trc = DAV1D_TRC_UNKNOWN;
68+ p->p.mtrx = DAV1D_MC_UNKNOWN;
69+ p->p.chr = DAV1D_CHR_UNKNOWN;
70+ aligned_h = (h + 127) & ~127;
71+ p->p.layout = layout;
72+ p->p.bpc = bpc;
73+ const size_t y_sz = p->stride[0] * aligned_h;
74+ const size_t uv_sz = p->stride[1] * (aligned_h >> ss_ver);
75+ if (!(p->ref = dav1d_ref_create(y_sz + 2 * uv_sz + extra))) {
76+ fprintf(stderr, "Failed to allocate memory of size %zu: %s\n",
77+ y_sz + 2 * uv_sz + extra, strerror(errno));
78+ return -ENOMEM;
79+ }
80+ uint8_t *data = p->ref->data;
81+ p->data[0] = data;
82+ p->data[1] = has_chroma ? data + y_sz : NULL;
83+ p->data[2] = has_chroma ? data + y_sz + uv_sz : NULL;
84+
85+ if (extra)
86+ *extra_ptr = &data[y_sz + uv_sz * 2];
87+
88+ return 0;
89+}
90+
91+int dav1d_thread_picture_alloc(Dav1dThreadPicture *const p,
92+ const int w, const int h,
93+ const enum Dav1dPixelLayout layout, const int bpc,
94+ struct thread_data *const t, const int visible)
95+{
96+ p->t = t;
97+
98+ const int res =
99+ picture_alloc_with_edges(&p->p, w, h, layout, bpc,
100+ t != NULL ? sizeof(atomic_int) * 2 : 0,
101+ (void **) &p->progress);
102+
103+ p->visible = visible;
104+ if (t) {
105+ atomic_init(&p->progress[0], 0);
106+ atomic_init(&p->progress[1], 0);
107+ }
108+ return res;
109+}
110+
111+void dav1d_picture_ref(Dav1dPicture *const dst, const Dav1dPicture *const src) {
112+ validate_input(dst != NULL);
113+ validate_input(dst->data[0] == NULL);
114+ validate_input(src != NULL);
115+
116+ if (src->ref) {
117+ validate_input(src->data[0] != NULL);
118+ dav1d_ref_inc(src->ref);
119+ }
120+ *dst = *src;
121+}
122+
123+void dav1d_thread_picture_ref(Dav1dThreadPicture *dst,
124+ const Dav1dThreadPicture *src)
125+{
126+ dav1d_picture_ref(&dst->p, &src->p);
127+ dst->t = src->t;
128+ dst->visible = src->visible;
129+ dst->progress = src->progress;
130+}
131+
132+void dav1d_picture_unref(Dav1dPicture *const p) {
133+ validate_input(p != NULL);
134+
135+ if (p->ref) {
136+ validate_input(p->data[0] != NULL);
137+ dav1d_ref_dec(p->ref);
138+ }
139+ memset(p, 0, sizeof(*p));
140+}
141+
142+void dav1d_thread_picture_unref(Dav1dThreadPicture *const p) {
143+ dav1d_picture_unref(&p->p);
144+
145+ p->t = NULL;
146+ p->progress = NULL;
147+}
148+
149+void dav1d_thread_picture_wait(const Dav1dThreadPicture *const p,
150+ int y_unclipped, const enum PlaneType plane_type)
151+{
152+ assert(plane_type != PLANE_TYPE_ALL);
153+
154+ if (!p->t)
155+ return;
156+
157+ // convert to luma units; include plane delay from loopfilters; clip
158+ const int ss_ver = p->p.p.layout != DAV1D_PIXEL_LAYOUT_I444;
159+ y_unclipped <<= plane_type & ss_ver; // we rely here on PLANE_TYPE_UV being 1
160+ y_unclipped += (plane_type != PLANE_TYPE_BLOCK) * 8; // delay imposed by loopfilter
161+ const int y = iclip(y_unclipped, 0, p->p.p.h - 1);
162+ atomic_uint *const progress = &p->progress[plane_type != PLANE_TYPE_BLOCK];
163+
164+ if (atomic_load_explicit(progress, memory_order_acquire) >= y)
165+ return;
166+
167+ pthread_mutex_lock(&p->t->lock);
168+ while (atomic_load_explicit(progress, memory_order_relaxed) < y)
169+ pthread_cond_wait(&p->t->cond, &p->t->lock);
170+ pthread_mutex_unlock(&p->t->lock);
171+}
172+
173+void dav1d_thread_picture_signal(const Dav1dThreadPicture *const p,
174+ const int y, // in pixel units
175+ const enum PlaneType plane_type)
176+{
177+ assert(plane_type != PLANE_TYPE_UV);
178+
179+ if (!p->t)
180+ return;
181+
182+ pthread_mutex_lock(&p->t->lock);
183+ if (plane_type != PLANE_TYPE_Y) atomic_store(&p->progress[0], y);
184+ if (plane_type != PLANE_TYPE_BLOCK) atomic_store(&p->progress[1], y);
185+ pthread_cond_broadcast(&p->t->cond);
186+ pthread_mutex_unlock(&p->t->lock);
187+}
src/picture.h+91−0
@@ -0,0 +1,91 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#ifndef __DAV1D_SRC_PICTURE_H__
29+#define __DAV1D_SRC_PICTURE_H__
30+
31+#include <pthread.h>
32+#include <stdatomic.h>
33+
34+#include "dav1d/picture.h"
35+
36+#include "src/thread_data.h"
37+
38+enum PlaneType {
39+ PLANE_TYPE_Y,
40+ PLANE_TYPE_UV,
41+ PLANE_TYPE_BLOCK,
42+ PLANE_TYPE_ALL,
43+};
44+
45+typedef struct Dav1dThreadPicture {
46+ Dav1dPicture p;
47+ int visible;
48+ struct thread_data *t;
49+ // [0] block data (including segmentation map and motion vectors)
50+ // [1] pixel data
51+ atomic_uint *progress;
52+} Dav1dThreadPicture;
53+
54+/*
55+ * Allocate a picture with custom border size.
56+ */
57+int dav1d_thread_picture_alloc(Dav1dThreadPicture *p, int w, int h,
58+ enum Dav1dPixelLayout layout, int bpc,
59+ struct thread_data *t, int visible);
60+
61+/**
62+ * Create a copy of a picture.
63+ */
64+void dav1d_picture_ref(Dav1dPicture *dst, const Dav1dPicture *src);
65+void dav1d_thread_picture_ref(Dav1dThreadPicture *dst,
66+ const Dav1dThreadPicture *src);
67+void dav1d_thread_picture_unref(Dav1dThreadPicture *p);
68+
69+/**
70+ * Wait for picture to reach a certain stage.
71+ *
72+ * y is in full-pixel units. If pt is not UV, this is in luma
73+ * units, else it is in chroma units.
74+ * plane_type is used to determine how many pixels delay are
75+ * introduced by loopfilter processes.
76+ */
77+void dav1d_thread_picture_wait(const Dav1dThreadPicture *p, int y,
78+ enum PlaneType plane_type);
79+
80+/**
81+ * Signal decoding progress.
82+ *
83+ * y is in full-pixel luma units.
84+ * plane_type denotes whether we have completed block data (pass 1;
85+ * PLANE_TYPE_BLOCK), pixel data (pass 2, PLANE_TYPE_Y) or both (no
86+ * 2-pass decoding; PLANE_TYPE_ALL).
87+ */
88+void dav1d_thread_picture_signal(const Dav1dThreadPicture *p, int y,
89+ enum PlaneType plane_type);
90+
91+#endif /* __DAV1D_SRC_PICTURE_H__ */
src/qm.c+3152−0
@@ -0,0 +1,3152 @@
1+/*
2+ * Copyright © 2018, VideoLAN and dav1d authors
3+ * Copyright © 2018, Two Orioles, LLC
4+ * All rights reserved.
5+ *
6+ * Redistribution and use in source and binary forms, with or without
7+ * modification, are permitted provided that the following conditions are met:
8+ *
9+ * 1. Redistributions of source code must retain the above copyright notice, this
10+ * list of conditions and the following disclaimer.
11+ *
12+ * 2. Redistributions in binary form must reproduce the above copyright notice,
13+ * this list of conditions and the following disclaimer in the documentation
14+ * and/or other materials provided with the distribution.
15+ *
16+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
20+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+ */
27+
28+#include "config.h"
29+
30+#include <string.h>
31+
32+#include "src/qm.h"
33+
34+static const uint8_t qm_tbl_4x4_t[][2][10] = {
35+ {
36+ {
37+ 32,
38+ 43, 67,
39+ 73, 94, 137,
40+ 97, 110, 150, 200,
41+ }, {
42+ 35,
43+ 46, 60,
44+ 57, 69, 90,
45+ 66, 71, 90, 109,
46+ },
47+ }, {
48+ {
49+ 32,
50+ 41, 63,
51+ 69, 88, 127,
52+ 92, 103, 140, 184,
53+ }, {
54+ 33,
55+ 45, 58,
56+ 56, 66, 86,
57+ 64, 69, 87, 105,
58+ },
59+ }, {
60+ {
61+ 32,
62+ 38, 56,
63+ 63, 78, 113,
64+ 86, 97, 130, 169,
65+ }, {
66+ 32,
67+ 45, 55,
68+ 53, 62, 80,
69+ 63, 67, 84, 101,
70+ },
71+ }, {
72+ {
73+ 32,
74+ 37, 54,
75+ 58, 72, 102,
76+ 81, 91, 121, 156,
77+ }, {
78+ 32,
79+ 45, 54,
80+ 51, 59, 75,
81+ 61, 65, 81, 97,
82+ },
83+ }, {
84+ {
85+ 32,
86+ 34, 49,
87+ 53, 64, 91,
88+ 75, 81, 112, 140,
89+ }, {
90+ 32,
91+ 46, 53,
92+ 49, 55, 70,
93+ 58, 62, 78, 91,
94+ },
95+ }, {
96+ {
97+ 32,
98+ 34, 48,
99+ 49, 60, 82,
100+ 72, 79, 104, 134,
101+ }, {
102+ 32,
103+ 46, 53,
104+ 47, 54, 66,
105+ 57, 60, 75, 89,
106+ },
107+ }, {
108+ {
109+ 32,
110+ 33, 39,
111+ 45, 51, 71,
112+ 62, 64, 87, 108,
113+ }, {
114+ 31,
115+ 42, 48,
116+ 47, 50, 61,
117+ 53, 54, 67, 78,
118+ },
119+ }, {
120+ {
121+ 32,
122+ 33, 38,
123+ 42, 46, 63,
124+ 55, 57, 75, 92,
125+ }, {
126+ 31,
127+ 41, 48,
128+ 46, 48, 58,
129+ 51, 51, 62, 71,
130+ },
131+ }, {
132+ {
133+ 32,
134+ 32, 35,
135+ 38, 40, 54,
136+ 51, 49, 64, 81,
137+ }, {
138+ 31,
139+ 38, 47,
140+ 47, 46, 54,
141+ 49, 46, 57, 66,
142+ },
143+ }, {
144+ {
145+ 32,
146+ 32, 34,
147+ 35, 37, 48,
148+ 43, 43, 54, 65,
149+ }, {
150+ 31,
151+ 37, 44,
152+ 47, 47, 53,
153+ 47, 45, 53, 59,
154+ },
155+ }, {
156+ {
157+ 32,
158+ 32, 33,
159+ 34, 35, 39,
160+ 38, 39, 45, 54,
161+ }, {
162+ 31,
163+ 34, 39,
164+ 42, 45, 48,
165+ 47, 46, 49, 54,
166+ },
167+ }, {
168+ {
169+ 32,
170+ 32, 32,
171+ 32, 33, 35,
172+ 35, 35, 38, 46,
173+ }, {
174+ 31,
175+ 32, 34,
176+ 38, 41, 47,
177+ 46, 46, 47, 52,
178+ },
179+ }, {
180+ {
181+ 31,
182+ 32, 32,
183+ 32, 32, 33,
184+ 32, 33, 34, 35,
185+ }, {
186+ 31,
187+ 31, 32,
188+ 34, 35, 39,
189+ 38, 40, 43, 47,
190+ },
191+ }, {
192+ {
193+ 31,
194+ 31, 32,
195+ 31, 32, 32,
196+ 32, 32, 32, 33,
197+ }, {
198+ 31,
199+ 31, 31,
200+ 31, 31, 32,
201+ 34, 35, 35, 39,
202+ },
203+ }, {
204+ {
205+ 31,
206+ 31, 32,
207+ 31, 32, 32,
208+ 31, 32, 32, 32,
209+ }, {
210+ 31,
211+ 31, 31,
212+ 31, 31, 31,
213+ 31, 31, 31, 31,
214+ },
215+ },
216+};
217+
218+static const uint8_t qm_tbl_8x4[][2][32] = {
219+ {
220+ {
221+ 32, 33, 37, 49, 65, 80, 91, 104,
222+ 42, 42, 58, 71, 84, 97, 100, 112,
223+ 75, 69, 84, 103, 125, 142, 145, 146,
224+ 91, 86, 91, 110, 128, 152, 178, 190,
225+ }, {
226+ 31, 40, 46, 48, 54, 61, 64, 68,
227+ 47, 45, 56, 61, 65, 69, 68, 71,
228+ 60, 54, 64, 75, 85, 92, 90, 87,
229+ 66, 61, 64, 73, 82, 92, 102, 105,
230+ },
231+ }, {
232+ {
233+ 32, 33, 36, 46, 60, 75, 86, 98,
234+ 42, 42, 56, 67, 79, 92, 95, 105,
235+ 69, 64, 77, 93, 112, 130, 136, 136,
236+ 88, 83, 88, 105, 122, 144, 167, 177,
237+ }, {
238+ 31, 40, 46, 47, 52, 59, 63, 66,
239+ 47, 45, 55, 60, 64, 68, 66, 69,
240+ 57, 52, 61, 70, 79, 87, 88, 85,
241+ 65, 61, 63, 72, 81, 90, 99, 102,
242+ },
243+ }, {
244+ {
245+ 32, 32, 34, 44, 54, 72, 82, 92,
246+ 38, 40, 51, 61, 69, 84, 89, 98,
247+ 62, 58, 68, 85, 98, 118, 129, 127,
248+ 86, 80, 85, 101, 117, 136, 157, 165,
249+ }, {
250+ 31, 38, 46, 46, 50, 57, 61, 65,
251+ 47, 46, 53, 56, 59, 64, 65, 67,
252+ 54, 50, 57, 66, 74, 82, 85, 82,
253+ 64, 60, 62, 71, 79, 88, 97, 99,
254+ },
255+ }, {
256+ {
257+ 32, 32, 34, 41, 51, 65, 75, 86,
258+ 35, 36, 47, 53, 61, 73, 81, 92,
259+ 59, 57, 65, 78, 92, 108, 117, 119,
260+ 83, 78, 82, 97, 111, 129, 148, 154,
261+ }, {
262+ 31, 36, 46, 45, 49, 54, 59, 63,
263+ 47, 47, 52, 53, 55, 58, 61, 65,
264+ 53, 50, 55, 63, 71, 77, 81, 80,
265+ 63, 59, 61, 70, 77, 86, 94, 95,
266+ },
267+ }, {
268+ {
269+ 32, 32, 34, 38, 48, 60, 72, 81,
270+ 35, 36, 42, 51, 59, 68, 79, 86,
271+ 51, 50, 54, 67, 80, 92, 104, 112,
272+ 77, 72, 75, 87, 103, 119, 135, 144,
273+ }, {
274+ 31, 36, 43, 45, 47, 52, 57, 61,
275+ 47, 47, 50, 53, 54, 56, 60, 63,
276+ 50, 47, 50, 58, 66, 70, 75, 77,
277+ 61, 57, 58, 65, 74, 82, 90, 93,
278+ },
279+ }, {
280+ {
281+ 32, 32, 34, 37, 45, 54, 65, 75,
282+ 35, 36, 42, 50, 56, 63, 73, 81,
283+ 51, 50, 54, 65, 76, 87, 97, 106,
284+ 75, 71, 73, 84, 96, 110, 125, 136,
285+ }, {
286+ 31, 36, 43, 46, 46, 50, 54, 59,
287+ 47, 47, 50, 53, 54, 55, 58, 61,
288+ 50, 47, 50, 57, 64, 68, 72, 75,
289+ 60, 56, 57, 64, 71, 78, 85, 90,
290+ },
291+ }, {
292+ {
293+ 32, 32, 33, 35, 41, 49, 57, 66,
294+ 34, 34, 37, 43, 48, 54, 60, 68,
295+ 43, 42, 44, 54, 64, 71, 78, 86,
296+ 62, 59, 58, 68, 79, 91, 101, 111,
297+ }, {
298+ 31, 33, 40, 47, 45, 48, 51, 55,
299+ 42, 44, 47, 50, 49, 50, 52, 55,
300+ 47, 45, 46, 54, 59, 61, 63, 66,
301+ 54, 51, 50, 57, 64, 70, 75, 79,
302+ },
303+ }, {
304+ {
305+ 32, 32, 32, 34, 38, 44, 50, 61,
306+ 32, 33, 35, 37, 40, 45, 50, 58,
307+ 42, 41, 42, 50, 58, 66, 71, 79,
308+ 56, 53, 52, 59, 68, 78, 86, 97,
309+ }, {
310+ 31, 32, 39, 44, 46, 47, 48, 53,
311+ 38, 40, 47, 47, 47, 46, 47, 50,
312+ 47, 45, 45, 51, 56, 59, 61, 64,
313+ 52, 49, 48, 53, 58, 64, 68, 73,
314+ },
315+ }, {
316+ {
317+ 32, 32, 32, 34, 35, 40, 46, 52,
318+ 32, 33, 34, 37, 38, 42, 46, 51,
319+ 37, 36, 38, 44, 49, 55, 59, 64,
320+ 52, 49, 49, 54, 60, 69, 76, 83,
321+ }, {
322+ 31, 31, 36, 42, 47, 46, 48, 50,
323+ 38, 40, 44, 47, 48, 46, 46, 48,
324+ 47, 46, 47, 50, 53, 54, 55, 56,
325+ 50, 48, 47, 50, 54, 60, 64, 67,
326+ },
327+ }, {
328+ {
329+ 31, 32, 32, 32, 34, 37, 42, 46,
330+ 32, 33, 34, 35, 37, 40, 43, 46,
331+ 35, 34, 36, 38, 43, 49, 53, 56,
332+ 43, 41, 42, 42, 49, 56, 63, 67,
333+ }, {
334+ 31, 31, 35, 39, 43, 47, 46, 48,
335+ 38, 40, 43, 47, 47, 47, 46, 46,
336+ 47, 46, 47, 47, 50, 53, 53, 54,
337+ 48, 45, 46, 45, 50, 55, 58, 59,
338+ },
339+ }, {
340+ {
341+ 31, 32, 32, 32, 33, 34, 37, 40,
342+ 32, 32, 33, 33, 34, 36, 38, 40,
343+ 34, 34, 34, 36, 38, 41, 44, 46,
344+ 39, 38, 38, 40, 42, 47, 52, 56,
345+ }, {
346+ 31, 31, 33, 36, 40, 45, 47, 47,
347+ 34, 35, 37, 41, 44, 46, 47, 46,
348+ 42, 42, 44, 46, 48, 49, 50, 49,
349+ 48, 46, 46, 46, 48, 51, 54, 55,
350+ },
351+ }, {
352+ {
353+ 31, 32, 32, 32, 32, 33, 34, 35,
354+ 31, 32, 32, 32, 33, 33, 34, 34,
355+ 32, 32, 33, 34, 35, 36, 37, 38,
356+ 35, 35, 34, 36, 38, 40, 42, 48,
357+ }, {
358+ 31, 31, 31, 34, 37, 39, 42, 48,
359+ 31, 31, 32, 36, 39, 41, 43, 46,
360+ 37, 38, 40, 43, 46, 47, 47, 48,
361+ 48, 47, 46, 47, 47, 48, 50, 53,
362+ },
363+ }, {
364+ {
365+ 31, 31, 32, 32, 32, 32, 32, 33,
366+ 31, 32, 32, 32, 32, 32, 33, 33,
367+ 32, 32, 32, 32, 33, 34, 34, 35,
368+ 32, 32, 32, 33, 34, 34, 35, 36,
369+ }, {
370+ 31, 31, 31, 31, 34, 35, 38, 41,
371+ 31, 31, 32, 32, 36, 37, 40, 42,
372+ 35, 36, 37, 37, 40, 42, 45, 45,
373+ 37, 38, 39, 40, 43, 44, 47, 47,
374+ },
375+ }, {
376+ {
377+ 31, 31, 31, 31, 31, 31, 32, 32,
378+ 31, 32, 32, 32, 32, 32, 32, 32,
379+ 31, 32, 32, 32, 32, 32, 32, 32,
380+ 32, 32, 32, 32, 32, 33, 33, 33,
381+ }, {
382+ 31, 31, 31, 31, 31, 31, 34, 34,
383+ 31, 31, 31, 32, 32, 33, 36, 36,
384+ 31, 31, 31, 32, 32, 33, 36, 36,
385+ 34, 35, 35, 36, 36, 37, 40, 40,
386+ },
387+ }, {
388+ {
389+ 31, 31, 31, 31, 31, 31, 31, 31,
390+ 31, 31, 32, 32, 32, 32, 32, 32,
391+ 31, 31, 32, 32, 32, 32, 32, 32,
392+ 31, 31, 32, 32, 32, 32, 32, 32,
393+ }, {
394+ 31, 31, 31, 31, 31, 31, 31, 30,
395+ 31, 31, 31, 31, 31, 31, 31, 31,
396+ 31, 31, 31, 31, 31, 31, 32, 32,
397+ 31, 31, 31, 31, 31, 31, 32, 32,
398+ },
399+ },
400+};
401+
402+static const uint8_t qm_tbl_8x8_t[][2][36] = {
403+ {
404+ {
405+ 32,
406+ 32, 35,
407+ 38, 40, 54,
408+ 51, 49, 65, 82,
409+ 68, 63, 78, 97, 117,
410+ 84, 76, 91, 111, 134, 152,
411+ 95, 89, 98, 113, 138, 159, 183,
412+ 109, 102, 106, 121, 142, 168, 199, 220,
413+ }, {
414+ 31,
415+ 38, 47,
416+ 47, 46, 54,
417+ 50, 47, 57, 66,
418+ 57, 52, 61, 72, 82,
419+ 63, 57, 66, 77, 88, 96,
420+ 67, 62, 67, 75, 86, 95, 104,
421+ 71, 67, 68, 75, 84, 95, 107, 113,
422+ },
423+ }, {
424+ {
425+ 32,
426+ 32, 35,
427+ 37, 39, 51,
428+ 47, 46, 60, 73,
429+ 62, 58, 71, 87, 105,
430+ 78, 72, 84, 100, 121, 140,
431+ 90, 84, 93, 106, 129, 148, 169,
432+ 102, 96, 100, 113, 132, 155, 183, 201,
433+ }, {
434+ 31,
435+ 38, 47,
436+ 47, 47, 53,
437+ 48, 46, 55, 62,
438+ 54, 50, 58, 67, 76,
439+ 61, 55, 63, 72, 83, 91,
440+ 66, 61, 65, 73, 84, 92, 101,
441+ 69, 65, 66, 73, 82, 92, 103, 109,
442+ },
443+ }, {
444+ {
445+ 32,
446+ 32, 34,
447+ 35, 37, 48,
448+ 46, 45, 56, 70,
449+ 57, 54, 64, 80, 93,
450+ 76, 70, 79, 96, 111, 134,
451+ 85, 79, 87, 100, 121, 138, 156,
452+ 96, 90, 93, 105, 122, 144, 168, 184,
453+ }, {
454+ 31,
455+ 36, 43,
456+ 47, 47, 53,
457+ 48, 46, 54, 61,
458+ 52, 49, 55, 65, 71,
459+ 60, 55, 60, 70, 78, 89,
460+ 64, 59, 63, 71, 81, 89, 97,
461+ 67, 63, 64, 71, 79, 89, 99, 104,
462+ },
463+ }, {
464+ {
465+ 32,
466+ 32, 33,
467+ 35, 36, 46,
468+ 42, 42, 52, 63,
469+ 53, 51, 60, 73, 86,
470+ 68, 64, 72, 84, 100, 117,
471+ 78, 74, 80, 92, 109, 128, 140,
472+ 90, 84, 87, 98, 114, 133, 155, 168,
473+ }, {
474+ 31,
475+ 34, 39,
476+ 46, 47, 52,
477+ 47, 45, 52, 58,
478+ 50, 48, 54, 62, 68,
479+ 57, 53, 58, 65, 73, 82,
480+ 61, 57, 61, 68, 77, 86, 91,
481+ 65, 61, 62, 68, 76, 86, 95, 100,
482+ },
483+ }, {
484+ {
485+ 32,
486+ 32, 33,
487+ 34, 35, 39,
488+ 39, 40, 46, 56,
489+ 50, 48, 53, 65, 78,
490+ 62, 59, 63, 75, 90, 105,
491+ 76, 71, 74, 86, 101, 118, 134,
492+ 84, 79, 81, 92, 106, 123, 142, 153,
493+ }, {
494+ 31,
495+ 34, 39,
496+ 42, 45, 48,
497+ 47, 46, 49, 55,
498+ 49, 47, 50, 58, 65,
499+ 54, 51, 53, 61, 69, 76,
500+ 60, 56, 57, 65, 73, 82, 89,
501+ 64, 59, 60, 66, 74, 83, 92, 96,
502+ },
503+ }, {
504+ {
505+ 32,
506+ 32, 33,
507+ 34, 35, 39,
508+ 38, 39, 45, 54,
509+ 46, 45, 51, 61, 71,
510+ 56, 54, 58, 69, 80, 92,
511+ 68, 64, 68, 78, 90, 103, 117,
512+ 78, 74, 76, 86, 99, 113, 128, 140,
513+ }, {
514+ 31,
515+ 34, 39,
516+ 42, 45, 48,
517+ 47, 46, 49, 54,
518+ 48, 46, 50, 56, 61,
519+ 52, 49, 52, 58, 65, 71,
520+ 57, 53, 55, 61, 68, 75, 82,
521+ 61, 57, 58, 64, 71, 79, 86, 91,
522+ },
523+ }, {
524+ {
525+ 31,
526+ 32, 32,
527+ 32, 33, 35,
528+ 35, 35, 38, 48,
529+ 42, 41, 43, 54, 63,
530+ 51, 49, 49, 59, 71, 81,
531+ 59, 56, 56, 66, 77, 89, 98,
532+ 69, 65, 64, 73, 85, 97, 108, 119,
533+ }, {
534+ 31,
535+ 32, 35,
536+ 38, 42, 47,
537+ 48, 47, 48, 53,
538+ 47, 45, 45, 53, 58,
539+ 50, 47, 47, 54, 61, 66,
540+ 53, 50, 49, 56, 63, 69, 73,
541+ 57, 54, 52, 58, 65, 72, 77, 82,
542+ },
543+ }, {
544+ {
545+ 31,
546+ 32, 32,
547+ 32, 32, 35,
548+ 34, 34, 37, 42,
549+ 38, 37, 40, 47, 54,
550+ 46, 44, 45, 52, 60, 69,
551+ 52, 49, 49, 56, 65, 75, 82,
552+ 63, 59, 58, 65, 73, 84, 92, 105,
553+ }, {
554+ 31,
555+ 31, 32,
556+ 38, 40, 47,
557+ 44, 44, 47, 50,
558+ 47, 45, 46, 51, 54,
559+ 48, 46, 46, 51, 56, 61,
560+ 50, 47, 47, 52, 57, 63, 66,
561+ 55, 52, 50, 54, 60, 66, 70, 76,
562+ },
563+ }, {
564+ {
565+ 31,
566+ 32, 32,
567+ 32, 32, 34,
568+ 34, 33, 35, 39,
569+ 35, 34, 37, 42, 48,
570+ 41, 40, 41, 47, 53, 60,
571+ 47, 44, 45, 51, 57, 65, 71,
572+ 53, 50, 51, 55, 61, 70, 77, 85,
573+ }, {
574+ 31,
575+ 31, 32,
576+ 35, 36, 41,
577+ 42, 42, 45, 48,
578+ 48, 46, 47, 50, 53,
579+ 47, 45, 45, 49, 53, 57,
580+ 49, 46, 46, 50, 54, 59, 61,
581+ 51, 48, 48, 51, 54, 60, 64, 68,
582+ },
583+ }, {
584+ {
585+ 31,
586+ 31, 32,
587+ 32, 32, 33,
588+ 32, 32, 34, 35,
589+ 34, 34, 35, 37, 41,
590+ 37, 36, 38, 39, 45, 51,
591+ 43, 41, 42, 42, 49, 56, 63,
592+ 47, 44, 45, 46, 52, 59, 67, 71,
593+ }, {
594+ 31,
595+ 31, 32,
596+ 34, 35, 39,
597+ 37, 40, 43, 47,
598+ 43, 43, 45, 47, 49,
599+ 48, 46, 46, 47, 50, 53,
600+ 47, 45, 45, 45, 50, 55, 58,
601+ 49, 46, 46, 46, 50, 55, 60, 61,
602+ },
603+ }, {
604+ {
605+ 31,
606+ 31, 32,
607+ 32, 32, 32,
608+ 32, 32, 33, 34,
609+ 33, 33, 34, 35, 37,
610+ 34, 34, 35, 36, 39, 43,
611+ 37, 36, 37, 38, 41, 46, 51,
612+ 41, 39, 40, 41, 44, 49, 54, 58,
613+ }, {
614+ 31,
615+ 31, 31,
616+ 32, 33, 35,
617+ 35, 37, 39, 43,
618+ 39, 41, 42, 45, 47,
619+ 45, 44, 45, 47, 48, 50,
620+ 48, 46, 46, 47, 48, 51, 53,
621+ 48, 46, 45, 46, 47, 51, 54, 56,
622+ },
623+ }, {
624+ {
625+ 31,
626+ 31, 32,
627+ 31, 32, 32,
628+ 32, 32, 32, 33,
629+ 32, 32, 32, 34, 35,
630+ 32, 33, 33, 34, 35, 36,
631+ 34, 34, 33, 35, 36, 38, 39,
632+ 35, 35, 34, 36, 38, 40, 42, 48,
633+ }, {
634+ 31,
635+ 31, 31,
636+ 30, 31, 32,
637+ 34, 34, 35, 39,
638+ 36, 37, 39, 42, 46,
639+ 39, 40, 41, 44, 47, 47,
640+ 42, 42, 42, 45, 47, 48, 48,
641+ 48, 47, 46, 47, 47, 49, 50, 53,
642+ },
643+ }, {
644+ {
645+ 31,
646+ 31, 32,
647+ 31, 32, 32,
648+ 31, 32, 32, 32,
649+ 32, 32, 32, 32, 33,
650+ 32, 32, 32, 32, 33, 34,
651+ 32, 32, 32, 32, 34, 34, 35,
652+ 33, 33, 33, 33, 35, 35, 36, 38,
653+ }, {
654+ 31,
655+ 31, 31,
656+ 31, 31, 31,
657+ 30, 31, 31, 32,
658+ 34, 34, 35, 35, 39,
659+ 35, 35, 36, 36, 40, 41,
660+ 37, 38, 39, 40, 43, 44, 47,
661+ 40, 41, 41, 42, 44, 45, 47, 48,
662+ },
663+ }, {
664+ {
665+ 31,
666+ 31, 32,
667+ 31, 32, 32,
668+ 31, 32, 32, 32,
669+ 31, 32, 32, 32, 32,
670+ 31, 32, 32, 32, 32, 32,
671+ 32, 32, 32, 32, 32, 32, 33,
672+ 32, 32, 32, 32, 32, 32, 33, 33,
673+ }, {
674+ 31,
675+ 31, 31,
676+ 31, 31, 31,
677+ 31, 31, 31, 31,
678+ 30, 31, 31, 31, 32,
679+ 31, 32, 32, 32, 32, 33,
680+ 33, 34, 34, 35, 35, 36, 39,
681+ 33, 34, 34, 35, 35, 36, 39, 39,
682+ },
683+ }, {
684+ {
685+ 31,
686+ 31, 31,
687+ 31, 31, 31,
688+ 31, 31, 32, 32,
689+ 31, 31, 32, 32, 32,
690+ 31, 31, 32, 32, 32, 32,
691+ 31, 31, 32, 32, 32, 32, 32,
692+ 31, 31, 32, 32, 32, 32, 32, 32,
693+ }, {
694+ 31,
695+ 31, 31,
696+ 31, 31, 31,
697+ 31, 31, 31, 31,
698+ 31, 31, 31, 31, 31,
699+ 31, 31, 31, 31, 31, 31,
700+ 31, 31, 31, 31, 31, 31, 31,
701+ 30, 31, 31, 31, 31, 31, 31, 31,
702+ },
703+ },
704+};
705+
706+static const uint8_t qm_tbl_16x4[][2][64] = {
707+ {
708+ {
709+ 31, 32, 32, 34, 34, 41, 45, 54, 60, 72, 75, 83, 88, 94, 101, 108,
710+ 44, 41, 42, 48, 54, 63, 67, 75, 79, 90, 92, 100, 100, 101, 108, 115,
711+ 79, 72, 71, 73, 78, 90, 96, 110, 118, 133, 136, 142, 140, 144, 141, 151,
712+ 96, 90, 86, 83, 89, 95, 102, 111, 123, 135, 149, 160, 173, 180, 188, 197,
713+ }, {
714+ 31, 32, 36, 43, 46, 45, 46, 50, 52, 57, 59, 62, 63, 65, 67, 69,
715+ 49, 45, 46, 49, 53, 58, 59, 62, 64, 67, 68, 71, 69, 68, 70, 72,
716+ 63, 57, 56, 57, 60, 67, 71, 78, 82, 89, 90, 91, 89, 89, 86, 88,
717+ 69, 65, 62, 60, 63, 66, 70, 74, 80, 85, 91, 96, 101, 103, 105, 107,
718+ },
719+ }, {
720+ {
721+ 31, 32, 32, 33, 34, 37, 44, 49, 56, 65, 72, 78, 84, 89, 95, 101,
722+ 44, 41, 42, 44, 54, 58, 66, 71, 77, 84, 90, 95, 95, 95, 101, 108,
723+ 73, 67, 65, 66, 74, 79, 90, 99, 107, 119, 127, 133, 132, 136, 132, 141,
724+ 93, 87, 83, 81, 86, 92, 98, 107, 117, 129, 141, 151, 163, 169, 175, 183,
725+ }, {
726+ 31, 32, 36, 41, 46, 46, 46, 48, 51, 54, 57, 60, 62, 64, 65, 67,
727+ 49, 45, 46, 47, 53, 56, 59, 61, 63, 65, 67, 69, 67, 66, 68, 70,
728+ 61, 55, 54, 54, 59, 62, 68, 73, 77, 82, 86, 88, 86, 87, 83, 86,
729+ 69, 64, 61, 59, 62, 65, 68, 73, 78, 84, 89, 93, 98, 100, 102, 103,
730+ },
731+ }, {
732+ {
733+ 31, 32, 32, 33, 34, 37, 41, 46, 53, 60, 65, 74, 79, 84, 89, 94,
734+ 39, 38, 39, 40, 47, 54, 58, 62, 68, 73, 78, 85, 90, 90, 95, 101,
735+ 65, 60, 59, 58, 65, 73, 79, 86, 97, 105, 111, 120, 125, 128, 124, 131,
736+ 90, 84, 81, 78, 83, 89, 94, 102, 112, 123, 134, 143, 154, 158, 164, 170,
737+ }, {
738+ 31, 32, 36, 40, 44, 46, 45, 47, 49, 52, 54, 58, 60, 62, 64, 65,
739+ 48, 46, 46, 46, 51, 54, 56, 57, 58, 60, 62, 64, 66, 64, 66, 68,
740+ 57, 53, 51, 50, 54, 60, 64, 68, 73, 76, 79, 82, 84, 84, 81, 83,
741+ 68, 63, 60, 58, 61, 64, 67, 71, 77, 82, 87, 91, 95, 97, 99, 100,
742+ },
743+ }, {
744+ {
745+ 31, 32, 32, 33, 34, 34, 39, 44, 49, 54, 60, 68, 75, 79, 84, 88,
746+ 36, 35, 36, 38, 42, 48, 51, 56, 60, 63, 68, 75, 81, 85, 89, 94,
747+ 62, 58, 57, 56, 61, 66, 74, 82, 90, 95, 102, 110, 117, 120, 116, 123,
748+ 88, 82, 79, 76, 81, 85, 91, 98, 107, 117, 127, 135, 145, 148, 153, 159,
749+ }, {
750+ 31, 32, 35, 40, 43, 46, 45, 46, 48, 50, 52, 56, 58, 60, 62, 63,
751+ 48, 46, 47, 47, 50, 53, 53, 54, 54, 55, 56, 59, 61, 63, 64, 66,
752+ 56, 52, 50, 49, 53, 56, 61, 65, 70, 72, 75, 79, 81, 82, 79, 81,
753+ 67, 62, 60, 57, 60, 63, 66, 70, 75, 80, 85, 89, 93, 94, 96, 97,
754+ },
755+ }, {
756+ {
757+ 31, 32, 32, 32, 33, 34, 37, 41, 45, 49, 54, 61, 68, 74, 78, 83,
758+ 36, 35, 35, 37, 41, 48, 50, 53, 56, 60, 63, 69, 75, 80, 84, 88,
759+ 53, 51, 49, 49, 53, 60, 65, 71, 76, 82, 87, 93, 100, 105, 109, 114,
760+ 81, 76, 73, 71, 74, 80, 85, 91, 98, 105, 112, 121, 130, 137, 142, 148,
761+ }, {
762+ 31, 31, 33, 38, 42, 46, 46, 45, 46, 48, 50, 52, 56, 58, 60, 62,
763+ 48, 47, 46, 47, 49, 53, 53, 53, 54, 54, 55, 57, 59, 61, 62, 64,
764+ 52, 49, 48, 47, 50, 54, 57, 61, 64, 66, 68, 71, 73, 75, 76, 78,
765+ 64, 60, 57, 56, 57, 61, 64, 68, 71, 75, 78, 83, 87, 90, 92, 94,
766+ },
767+ }, {
768+ {
769+ 31, 32, 32, 32, 33, 34, 34, 37, 41, 45, 49, 54, 60, 65, 72, 75,
770+ 36, 35, 34, 36, 38, 42, 48, 50, 53, 56, 60, 63, 68, 73, 79, 81,
771+ 53, 51, 49, 50, 49, 54, 60, 65, 71, 76, 82, 87, 92, 97, 104, 106,
772+ 79, 75, 72, 71, 69, 73, 78, 84, 90, 96, 103, 110, 118, 125, 133, 136,
773+ }, {
774+ 31, 31, 32, 36, 40, 43, 46, 46, 45, 46, 48, 50, 52, 54, 57, 59,
775+ 48, 47, 46, 47, 47, 50, 53, 53, 53, 54, 54, 55, 56, 58, 60, 61,
776+ 52, 50, 48, 47, 47, 50, 54, 57, 61, 64, 66, 68, 70, 72, 75, 75,
777+ 63, 60, 57, 56, 54, 57, 60, 64, 67, 71, 75, 78, 82, 85, 89, 90,
778+ },
779+ }, {
780+ {
781+ 31, 32, 32, 32, 32, 34, 34, 36, 39, 42, 45, 50, 54, 60, 66, 73,
782+ 34, 34, 33, 35, 37, 39, 42, 44, 46, 48, 51, 54, 58, 63, 68, 74,
783+ 44, 43, 41, 43, 43, 48, 53, 57, 60, 64, 67, 72, 76, 80, 85, 91,
784+ 65, 62, 59, 59, 58, 63, 67, 71, 76, 81, 85, 92, 98, 105, 111, 118,
785+ }, {
786+ 31, 31, 32, 35, 40, 43, 46, 46, 46, 46, 47, 48, 50, 52, 55, 58,
787+ 42, 42, 42, 45, 47, 48, 50, 50, 49, 49, 50, 50, 52, 53, 55, 58,
788+ 49, 47, 45, 46, 46, 49, 53, 55, 57, 59, 60, 61, 63, 64, 66, 68,
789+ 57, 54, 52, 51, 50, 53, 56, 58, 61, 64, 67, 71, 73, 76, 79, 82,
790+ },
791+ }, {
792+ {
793+ 31, 32, 32, 32, 32, 32, 34, 35, 37, 39, 41, 45, 50, 54, 57, 61,
794+ 32, 32, 33, 34, 34, 35, 37, 38, 40, 41, 43, 46, 50, 53, 56, 58,
795+ 44, 42, 41, 42, 42, 42, 48, 54, 57, 60, 63, 67, 71, 74, 77, 79,
796+ 58, 55, 53, 53, 53, 52, 57, 63, 67, 70, 74, 79, 86, 90, 93, 97,
797+ }, {
798+ 31, 31, 32, 34, 37, 39, 42, 47, 46, 46, 46, 47, 48, 50, 51, 53,
799+ 37, 38, 40, 42, 44, 47, 47, 48, 47, 46, 46, 46, 47, 48, 49, 50,
800+ 49, 47, 45, 45, 45, 45, 49, 53, 55, 57, 58, 59, 61, 62, 63, 64,
801+ 54, 51, 49, 49, 48, 48, 51, 55, 58, 60, 62, 65, 68, 70, 71, 73,
802+ },
803+ }, {
804+ {
805+ 31, 32, 32, 32, 32, 32, 33, 34, 35, 37, 38, 42, 45, 47, 51, 55,
806+ 32, 32, 32, 33, 34, 35, 36, 37, 38, 40, 40, 43, 45, 47, 50, 54,
807+ 38, 37, 36, 36, 38, 39, 41, 44, 49, 51, 52, 56, 58, 60, 63, 67,
808+ 53, 51, 49, 49, 50, 49, 51, 54, 60, 63, 65, 71, 75, 77, 82, 87,
809+ }, {
810+ 31, 31, 31, 32, 35, 39, 40, 42, 47, 47, 46, 46, 47, 48, 49, 51,
811+ 37, 38, 39, 40, 43, 47, 47, 47, 48, 47, 47, 46, 46, 47, 47, 49,
812+ 48, 47, 46, 46, 46, 47, 48, 50, 53, 53, 54, 55, 55, 55, 56, 57,
813+ 52, 50, 48, 48, 47, 47, 48, 50, 54, 56, 57, 61, 63, 64, 66, 68,
814+ },
815+ }, {
816+ {
817+ 31, 32, 32, 32, 32, 32, 32, 33, 34, 35, 35, 38, 40, 42, 45, 46,
818+ 32, 32, 32, 33, 34, 34, 35, 36, 37, 38, 38, 40, 41, 43, 45, 46,
819+ 36, 35, 35, 34, 36, 36, 38, 40, 42, 47, 48, 50, 51, 53, 56, 56,
820+ 44, 42, 41, 41, 42, 42, 42, 44, 48, 52, 54, 58, 60, 63, 66, 67,
821+ }, {
822+ 31, 31, 31, 31, 34, 35, 39, 40, 42, 46, 47, 47, 47, 46, 48, 48,
823+ 37, 38, 39, 40, 42, 43, 47, 47, 47, 48, 48, 47, 46, 46, 46, 46,
824+ 48, 47, 46, 46, 47, 47, 47, 48, 50, 52, 53, 53, 53, 53, 54, 54,
825+ 49, 47, 46, 45, 45, 46, 45, 47, 49, 53, 53, 56, 57, 58, 59, 59,
826+ },
827+ }, {
828+ {
829+ 31, 32, 32, 32, 32, 32, 32, 32, 32, 34, 34, 35, 35, 38, 38, 42,
830+ 32, 32, 32, 32, 32, 33, 33, 34, 34, 35, 35, 36, 36, 39, 39, 42,
831+ 34, 34, 34, 33, 33, 35, 35, 37, 37, 39, 39, 43, 43, 45, 45, 48,
832+ 39, 38, 38, 37, 37, 39, 39, 40, 40, 45, 45, 51, 51, 54, 54, 58,
833+ }, {
834+ 31, 31, 31, 31, 31, 34, 34, 38, 38, 42, 42, 48, 48, 47, 47, 47,
835+ 33, 34, 34, 35, 35, 39, 39, 43, 43, 45, 45, 47, 47, 46, 46, 45,
836+ 42, 42, 42, 42, 42, 45, 45, 47, 47, 48, 48, 50, 50, 50, 50, 49,
837+ 48, 47, 47, 45, 45, 46, 46, 46, 46, 50, 50, 53, 53, 54, 54, 56,
838+ },
839+ }, {
840+ {
841+ 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 34, 34, 35, 35,
842+ 31, 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 34, 34, 34, 34,
843+ 32, 32, 32, 32, 33, 33, 34, 34, 34, 35, 35, 36, 37, 37, 38, 38,
844+ 36, 35, 35, 35, 34, 34, 36, 36, 37, 38, 38, 41, 42, 44, 48, 48,
845+ }, {
846+ 31, 31, 31, 31, 31, 31, 34, 34, 36, 38, 38, 41, 42, 44, 48, 48,
847+ 31, 31, 31, 32, 32, 32, 35, 36, 37, 40, 40, 42, 43, 44, 46, 46,
848+ 37, 38, 38, 39, 40, 40, 42, 43, 44, 47, 47, 47, 47, 47, 48, 48,
849+ 48, 47, 47, 46, 46, 46, 47, 47, 47, 47, 47, 49, 50, 51, 53, 53,
850+ },
851+ }, {
852+ {
853+ 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 34,
854+ 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 34,
855+ 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 33, 34, 34, 34, 35, 36,
856+ 32, 32, 32, 32, 32, 33, 33, 33, 34, 34, 34, 35, 35, 35, 36, 37,
857+ }, {
858+ 31, 31, 31, 31, 31, 31, 31, 31, 33, 34, 34, 36, 38, 38, 39, 42,
859+ 31, 31, 31, 31, 32, 32, 32, 33, 35, 36, 36, 38, 40, 40, 41, 43,
860+ 35, 35, 36, 36, 36, 37, 37, 38, 40, 40, 40, 43, 45, 45, 45, 46,
861+ 37, 38, 38, 38, 39, 40, 40, 40, 42, 43, 43, 45, 47, 47, 47, 47,
862+ },
863+ }, {
864+ {
865+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32,
866+ 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
867+ 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
868+ 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 33, 33,
869+ }, {
870+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 33, 34, 34, 34,
871+ 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 33, 35, 36, 36, 36,
872+ 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 33, 35, 36, 36, 36,
873+ 34, 34, 35, 35, 35, 35, 36, 36, 36, 36, 36, 37, 39, 40, 40, 40,
874+ },
875+ }, {
876+ {
877+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
878+ 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
879+ 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
880+ 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
881+ }, {
882+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 30,
883+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
884+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32,
885+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32,
886+ },
887+ },
888+};
889+
890+static const uint8_t qm_tbl_16x8[][2][128] = {
891+ {
892+ {
893+ 32, 31, 32, 34, 36, 44, 48, 58, 65, 79, 82, 91, 97, 103, 110, 118,
894+ 32, 33, 34, 37, 38, 43, 46, 54, 58, 70, 72, 80, 86, 93, 100, 107,
895+ 36, 34, 36, 42, 48, 53, 56, 63, 68, 79, 81, 88, 94, 98, 101, 105,
896+ 53, 49, 50, 54, 60, 71, 76, 87, 92, 104, 106, 106, 107, 114, 117, 118,
897+ 65, 59, 59, 63, 68, 79, 85, 98, 105, 118, 121, 130, 128, 131, 138, 136,
898+ 87, 78, 77, 79, 84, 95, 102, 116, 124, 141, 144, 148, 157, 150, 161, 157,
899+ 93, 86, 82, 80, 86, 94, 105, 112, 122, 135, 149, 162, 167, 174, 183, 182,
900+ 99, 93, 89, 88, 90, 97, 105, 115, 124, 135, 146, 159, 171, 186, 193, 203,
901+ }, {
902+ 32, 30, 33, 42, 49, 49, 50, 54, 57, 63, 64, 68, 70, 72, 74, 76,
903+ 37, 40, 43, 47, 48, 46, 46, 49, 50, 55, 56, 59, 62, 64, 67, 69,
904+ 48, 46, 47, 50, 53, 53, 54, 55, 56, 60, 61, 64, 66, 66, 66, 67,
905+ 52, 48, 47, 50, 54, 61, 64, 68, 70, 75, 75, 74, 73, 75, 74, 73,
906+ 57, 52, 51, 53, 57, 64, 67, 73, 76, 82, 83, 86, 83, 83, 84, 82,
907+ 66, 60, 59, 60, 62, 69, 73, 80, 84, 92, 93, 94, 96, 92, 94, 91,
908+ 68, 63, 60, 59, 62, 66, 72, 76, 80, 87, 93, 98, 99, 101, 103, 101,
909+ 71, 66, 63, 62, 62, 66, 70, 75, 79, 84, 89, 94, 98, 104, 106, 109,
910+ },
911+ }, {
912+ {
913+ 32, 31, 32, 32, 36, 39, 47, 53, 61, 71, 79, 86, 92, 98, 104, 110,
914+ 32, 32, 34, 35, 37, 40, 45, 50, 56, 64, 70, 76, 82, 88, 94, 100,
915+ 36, 35, 36, 40, 48, 50, 56, 60, 65, 73, 79, 84, 89, 93, 95, 98,
916+ 47, 44, 45, 47, 56, 60, 69, 75, 81, 89, 95, 100, 101, 108, 110, 111,
917+ 65, 60, 59, 60, 68, 73, 84, 92, 100, 111, 118, 124, 121, 124, 129, 127,
918+ 79, 72, 71, 71, 78, 84, 95, 103, 113, 125, 133, 140, 148, 141, 151, 147,
919+ 90, 84, 80, 78, 83, 91, 101, 108, 116, 129, 142, 153, 157, 163, 171, 169,
920+ 96, 90, 87, 85, 87, 94, 101, 110, 118, 129, 138, 150, 161, 174, 181, 188,
921+ }, {
922+ 32, 30, 33, 39, 49, 48, 50, 52, 55, 60, 63, 66, 68, 70, 72, 74,
923+ 35, 38, 41, 46, 48, 46, 46, 47, 49, 53, 55, 58, 60, 62, 65, 67,
924+ 48, 46, 47, 48, 53, 53, 54, 54, 56, 58, 60, 62, 64, 65, 65, 65,
925+ 50, 46, 46, 47, 54, 56, 61, 63, 65, 68, 70, 72, 71, 73, 72, 71,
926+ 57, 52, 51, 51, 57, 60, 66, 71, 74, 79, 82, 84, 81, 81, 82, 79,
927+ 63, 58, 56, 55, 60, 64, 70, 75, 79, 85, 89, 91, 94, 89, 92, 89,
928+ 68, 63, 60, 58, 61, 65, 71, 75, 79, 85, 91, 95, 97, 98, 100, 98,
929+ 70, 65, 63, 61, 61, 65, 69, 74, 78, 82, 87, 91, 96, 101, 103, 105,
930+ },
931+ }, {
932+ {
933+ 32, 31, 32, 32, 34, 39, 44, 49, 57, 65, 71, 81, 87, 92, 98, 103,
934+ 32, 32, 33, 34, 36, 39, 42, 46, 53, 59, 64, 72, 77, 83, 88, 94,
935+ 36, 35, 36, 38, 44, 50, 53, 57, 63, 68, 73, 80, 85, 88, 89, 92,
936+ 44, 41, 42, 42, 50, 58, 63, 67, 74, 79, 84, 91, 96, 102, 103, 103,
937+ 58, 54, 53, 52, 59, 68, 74, 81, 90, 97, 102, 110, 114, 117, 121, 119,
938+ 79, 73, 71, 69, 75, 84, 90, 97, 108, 118, 125, 135, 140, 133, 141, 137,
939+ 88, 81, 78, 76, 81, 88, 97, 104, 111, 123, 135, 145, 148, 153, 160, 158,
940+ 93, 88, 84, 82, 84, 90, 97, 105, 113, 122, 131, 141, 151, 163, 169, 175,
941+ }, {
942+ 32, 31, 33, 37, 44, 48, 49, 51, 54, 57, 60, 64, 66, 68, 70, 72,
943+ 34, 36, 40, 44, 46, 46, 45, 47, 49, 51, 53, 57, 59, 61, 63, 65,
944+ 48, 46, 47, 47, 51, 53, 53, 54, 55, 56, 58, 61, 63, 63, 63, 63,
945+ 49, 46, 46, 45, 51, 56, 58, 60, 62, 64, 65, 68, 69, 71, 70, 69,
946+ 54, 50, 49, 48, 53, 58, 62, 65, 70, 73, 75, 78, 79, 79, 80, 77,
947+ 63, 58, 56, 54, 59, 64, 67, 71, 77, 82, 85, 89, 91, 87, 89, 86,
948+ 67, 62, 59, 57, 60, 64, 70, 73, 77, 83, 89, 93, 94, 96, 97, 95,
949+ 69, 65, 62, 60, 61, 64, 68, 72, 76, 81, 85, 89, 93, 98, 100, 102,
950+ },
951+ }, {
952+ {
953+ 32, 31, 31, 32, 34, 36, 41, 47, 53, 58, 65, 74, 82, 87, 92, 97,
954+ 31, 32, 33, 34, 35, 36, 40, 44, 50, 54, 59, 67, 73, 78, 83, 88,
955+ 35, 34, 35, 37, 41, 46, 49, 53, 57, 61, 66, 73, 79, 83, 84, 86,
956+ 44, 41, 42, 42, 48, 54, 60, 66, 71, 75, 79, 86, 92, 96, 97, 97,
957+ 53, 50, 49, 49, 54, 60, 67, 75, 82, 87, 92, 100, 105, 110, 114, 111,
958+ 65, 61, 59, 58, 63, 68, 76, 84, 92, 98, 105, 113, 120, 125, 132, 128,
959+ 82, 76, 73, 71, 76, 80, 88, 97, 106, 112, 120, 131, 139, 144, 150, 147,
960+ 90, 85, 81, 79, 81, 87, 93, 101, 108, 116, 124, 134, 142, 153, 157, 163,
961+ }, {
962+ 32, 31, 33, 37, 42, 49, 48, 50, 52, 54, 57, 61, 64, 66, 68, 70,
963+ 33, 34, 37, 43, 44, 47, 46, 46, 47, 49, 51, 55, 57, 59, 61, 63,
964+ 45, 45, 46, 47, 49, 52, 51, 52, 53, 54, 55, 58, 60, 61, 61, 61,
965+ 49, 46, 45, 45, 49, 53, 57, 59, 61, 62, 64, 66, 68, 69, 68, 67,
966+ 52, 49, 47, 47, 50, 54, 59, 63, 66, 68, 70, 73, 75, 77, 77, 75,
967+ 57, 53, 51, 50, 53, 57, 61, 66, 71, 73, 76, 80, 83, 84, 86, 83,
968+ 64, 60, 57, 55, 58, 61, 66, 71, 75, 79, 83, 87, 91, 93, 94, 92,
969+ 68, 64, 61, 59, 60, 63, 67, 71, 74, 79, 83, 87, 91, 95, 97, 98,
970+ },
971+ }, {
972+ {
973+ 32, 31, 31, 32, 33, 36, 39, 44, 48, 53, 58, 66, 74, 81, 86, 91,
974+ 31, 32, 32, 33, 34, 35, 38, 41, 45, 49, 54, 60, 67, 73, 78, 82,
975+ 33, 33, 34, 36, 38, 42, 44, 46, 50, 53, 57, 63, 69, 75, 78, 80,
976+ 40, 39, 38, 40, 44, 51, 54, 59, 62, 66, 70, 75, 81, 86, 90, 90,
977+ 51, 49, 47, 48, 52, 58, 63, 69, 74, 79, 84, 90, 97, 102, 106, 103,
978+ 65, 61, 59, 58, 62, 68, 73, 79, 85, 92, 98, 106, 113, 120, 124, 119,
979+ 79, 74, 71, 69, 72, 78, 84, 90, 96, 103, 110, 119, 128, 135, 140, 137,
980+ 87, 82, 79, 77, 78, 84, 89, 96, 103, 111, 118, 126, 134, 143, 147, 151,
981+ }, {
982+ 32, 31, 31, 35, 41, 49, 48, 49, 50, 52, 54, 57, 61, 64, 66, 68,
983+ 32, 33, 35, 39, 43, 47, 46, 45, 46, 48, 50, 52, 55, 58, 59, 61,
984+ 40, 41, 43, 46, 48, 50, 49, 48, 49, 50, 51, 53, 56, 58, 59, 59,
985+ 49, 47, 46, 46, 49, 53, 54, 56, 57, 58, 59, 61, 63, 65, 66, 65,
986+ 51, 49, 47, 47, 49, 54, 57, 61, 63, 65, 67, 69, 72, 73, 75, 72,
987+ 57, 54, 51, 50, 52, 57, 60, 64, 67, 71, 73, 77, 80, 82, 84, 81,
988+ 63, 59, 57, 55, 57, 60, 64, 67, 71, 75, 78, 82, 86, 89, 91, 89,
989+ 67, 63, 60, 58, 59, 62, 65, 69, 73, 77, 81, 85, 88, 92, 94, 95,
990+ },
991+ }, {
992+ {
993+ 32, 31, 31, 32, 32, 34, 36, 39, 44, 48, 53, 58, 65, 71, 79, 82,
994+ 31, 32, 32, 32, 33, 34, 34, 37, 41, 45, 49, 54, 60, 65, 72, 75,
995+ 32, 32, 33, 34, 35, 37, 38, 40, 43, 46, 50, 54, 58, 63, 70, 72,
996+ 36, 35, 34, 36, 38, 42, 48, 50, 53, 56, 60, 63, 68, 73, 79, 81,
997+ 44, 42, 41, 42, 42, 48, 54, 58, 63, 67, 71, 75, 79, 84, 90, 92,
998+ 53, 51, 49, 50, 49, 54, 60, 65, 71, 76, 82, 87, 92, 97, 104, 106,
999+ 65, 62, 59, 59, 58, 63, 68, 73, 79, 85, 92, 98, 105, 111, 118, 121,
1000+ 79, 75, 72, 71, 69, 73, 78, 84, 90, 96, 103, 110, 118, 125, 133, 136,
1001+ }, {
1002+ 32, 31, 30, 33, 37, 42, 49, 48, 49, 50, 52, 54, 57, 60, 63, 64,
1003+ 31, 31, 32, 36, 40, 43, 46, 46, 45, 46, 48, 50, 52, 54, 57, 59,
1004+ 37, 38, 40, 43, 47, 47, 48, 47, 46, 46, 47, 49, 50, 52, 55, 56,
1005+ 48, 47, 46, 47, 47, 50, 53, 53, 53, 54, 54, 55, 56, 58, 60, 61,
1006+ 49, 47, 45, 46, 45, 49, 53, 56, 58, 59, 61, 62, 64, 65, 67, 68,
1007+ 52, 50, 48, 47, 47, 50, 54, 57, 61, 64, 66, 68, 70, 72, 75, 75,
1008+ 57, 54, 52, 51, 50, 53, 57, 60, 64, 67, 71, 73, 76, 79, 82, 83,
1009+ 63, 60, 57, 56, 54, 57, 60, 64, 67, 71, 75, 78, 82, 85, 89, 90,
1010+ },
1011+ }, {
1012+ {
1013+ 32, 31, 31, 32, 32, 34, 35, 38, 41, 44, 48, 53, 58, 65, 71, 79,
1014+ 31, 32, 32, 32, 33, 34, 34, 36, 39, 42, 45, 49, 54, 60, 65, 72,
1015+ 32, 32, 33, 34, 35, 37, 38, 40, 41, 43, 46, 50, 54, 58, 63, 70,
1016+ 36, 35, 34, 36, 38, 42, 47, 49, 51, 54, 56, 60, 63, 68, 73, 79,
1017+ 44, 42, 41, 42, 42, 48, 52, 56, 60, 64, 67, 71, 75, 79, 84, 90,
1018+ 53, 51, 49, 50, 49, 54, 59, 63, 67, 72, 76, 82, 87, 92, 97, 104,
1019+ 62, 59, 57, 57, 56, 61, 65, 69, 74, 79, 83, 90, 95, 102, 108, 115,
1020+ 73, 69, 66, 65, 64, 69, 73, 77, 81, 86, 91, 99, 105, 112, 119, 127,
1021+ }, {
1022+ 32, 31, 30, 33, 37, 42, 47, 48, 48, 49, 50, 52, 54, 57, 60, 63,
1023+ 31, 31, 32, 36, 40, 43, 46, 46, 45, 45, 46, 48, 50, 52, 54, 57,
1024+ 37, 38, 40, 43, 47, 47, 48, 47, 46, 46, 46, 47, 49, 50, 52, 55,
1025+ 48, 47, 46, 47, 47, 50, 52, 53, 53, 53, 54, 54, 55, 56, 58, 60,
1026+ 49, 47, 45, 46, 45, 49, 53, 55, 57, 58, 59, 61, 62, 64, 65, 67,
1027+ 52, 50, 48, 47, 47, 50, 53, 56, 59, 62, 64, 66, 68, 70, 72, 75,
1028+ 56, 53, 51, 50, 49, 53, 55, 58, 61, 64, 66, 70, 72, 75, 77, 80,
1029+ 61, 57, 55, 54, 52, 56, 58, 61, 63, 66, 69, 73, 76, 79, 82, 86,
1030+ },
1031+ }, {
1032+ {
1033+ 32, 31, 31, 31, 32, 32, 34, 36, 38, 41, 44, 48, 53, 57, 61, 65,
1034+ 31, 32, 32, 32, 32, 33, 34, 34, 37, 39, 41, 45, 49, 53, 56, 60,
1035+ 32, 32, 33, 34, 34, 35, 37, 38, 40, 41, 43, 46, 50, 53, 56, 58,
1036+ 35, 35, 34, 35, 36, 37, 41, 46, 47, 49, 51, 54, 57, 60, 63, 66,
1037+ 39, 38, 37, 38, 39, 40, 44, 50, 52, 54, 57, 60, 64, 67, 69, 72,
1038+ 44, 42, 41, 42, 42, 42, 48, 54, 57, 60, 63, 67, 71, 74, 77, 79,
1039+ 53, 51, 49, 49, 49, 49, 54, 60, 64, 67, 71, 76, 82, 86, 89, 92,
1040+ 65, 62, 59, 59, 58, 58, 63, 68, 72, 76, 79, 85, 92, 97, 100, 105,
1041+ }, {
1042+ 32, 31, 30, 33, 35, 37, 42, 49, 48, 48, 49, 50, 52, 54, 55, 57,
1043+ 31, 31, 32, 35, 37, 40, 43, 46, 46, 45, 45, 46, 48, 49, 51, 52,
1044+ 37, 38, 40, 42, 44, 47, 47, 48, 47, 46, 46, 46, 47, 48, 49, 50,
1045+ 45, 45, 44, 46, 46, 47, 49, 52, 51, 51, 51, 52, 53, 54, 54, 55,
1046+ 48, 47, 45, 46, 46, 47, 50, 53, 54, 54, 55, 56, 57, 58, 58, 59,
1047+ 49, 47, 45, 45, 45, 45, 49, 53, 55, 57, 58, 59, 61, 62, 63, 64,
1048+ 52, 50, 48, 47, 47, 47, 50, 54, 57, 59, 61, 64, 66, 68, 69, 70,
1049+ 57, 54, 52, 51, 51, 50, 53, 57, 59, 61, 64, 67, 71, 73, 74, 76,
1050+ },
1051+ }, {
1052+ {
1053+ 32, 31, 31, 31, 32, 32, 32, 34, 36, 38, 39, 44, 47, 49, 53, 58,
1054+ 31, 32, 32, 32, 32, 33, 33, 34, 34, 36, 37, 41, 44, 46, 49, 54,
1055+ 32, 32, 32, 33, 34, 35, 35, 36, 37, 39, 40, 42, 45, 47, 50, 54,
1056+ 32, 33, 33, 33, 34, 36, 36, 38, 40, 41, 42, 45, 47, 48, 51, 55,
1057+ 36, 35, 35, 35, 36, 38, 40, 42, 48, 49, 50, 53, 56, 57, 60, 63,
1058+ 44, 42, 41, 41, 42, 42, 44, 48, 54, 56, 58, 63, 66, 67, 71, 75,
1059+ 47, 45, 44, 44, 45, 45, 47, 50, 56, 58, 60, 66, 69, 71, 75, 79,
1060+ 53, 51, 49, 49, 50, 49, 51, 54, 60, 63, 65, 71, 75, 77, 82, 87,
1061+ }, {
1062+ 32, 31, 30, 31, 33, 37, 39, 42, 49, 48, 48, 49, 50, 51, 52, 54,
1063+ 31, 31, 32, 33, 36, 40, 41, 43, 46, 46, 46, 45, 46, 47, 48, 50,
1064+ 35, 37, 38, 38, 41, 45, 46, 46, 48, 47, 46, 45, 46, 47, 47, 49,
1065+ 38, 40, 40, 41, 44, 47, 47, 48, 49, 48, 48, 47, 48, 48, 48, 50,
1066+ 48, 47, 46, 46, 47, 47, 48, 50, 53, 53, 53, 53, 54, 54, 54, 55,
1067+ 49, 47, 45, 45, 46, 45, 47, 49, 53, 55, 56, 58, 59, 60, 61, 62,
1068+ 50, 48, 46, 46, 46, 46, 47, 50, 54, 55, 56, 59, 61, 61, 63, 65,
1069+ 52, 50, 48, 48, 47, 47, 48, 50, 54, 56, 57, 61, 63, 64, 66, 68,
1070+ },
1071+ }, {
1072+ {
1073+ 32, 31, 31, 31, 31, 32, 32, 32, 34, 35, 36, 39, 41, 44, 47, 48,
1074+ 31, 32, 32, 32, 32, 32, 33, 33, 34, 34, 34, 37, 39, 41, 44, 45,
1075+ 31, 32, 32, 32, 33, 33, 34, 34, 35, 36, 36, 39, 40, 42, 44, 45,
1076+ 32, 32, 32, 33, 34, 34, 35, 36, 37, 38, 38, 40, 41, 43, 45, 46,
1077+ 35, 35, 34, 34, 35, 36, 37, 39, 41, 45, 46, 48, 49, 51, 53, 54,
1078+ 36, 35, 35, 34, 36, 36, 38, 40, 42, 47, 48, 50, 51, 53, 56, 56,
1079+ 44, 42, 41, 41, 42, 42, 42, 44, 48, 52, 54, 58, 60, 63, 66, 67,
1080+ 47, 45, 45, 44, 44, 45, 45, 47, 50, 55, 56, 60, 62, 66, 69, 70,
1081+ }, {
1082+ 32, 31, 31, 30, 33, 33, 37, 39, 42, 47, 49, 48, 48, 49, 50, 50,
1083+ 31, 31, 32, 32, 35, 36, 40, 41, 43, 46, 46, 46, 45, 45, 46, 46,
1084+ 33, 34, 34, 35, 37, 38, 43, 43, 44, 46, 47, 46, 46, 45, 46, 46,
1085+ 37, 38, 39, 40, 42, 43, 47, 47, 47, 48, 48, 47, 46, 46, 46, 46,
1086+ 45, 45, 45, 44, 46, 46, 47, 48, 49, 51, 52, 51, 51, 51, 52, 52,
1087+ 48, 47, 46, 46, 47, 47, 47, 48, 50, 52, 53, 53, 53, 53, 54, 54,
1088+ 49, 47, 46, 45, 45, 46, 45, 47, 49, 53, 53, 56, 57, 58, 59, 59,
1089+ 50, 48, 47, 46, 46, 46, 46, 47, 50, 53, 54, 56, 57, 59, 61, 61,
1090+ },
1091+ }, {
1092+ {
1093+ 32, 31, 31, 31, 31, 32, 32, 32, 32, 34, 34, 36, 36, 39, 39, 44,
1094+ 31, 32, 32, 32, 32, 32, 32, 33, 33, 34, 34, 34, 34, 37, 37, 41,
1095+ 31, 32, 32, 32, 32, 32, 32, 33, 33, 34, 34, 34, 34, 37, 37, 41,
1096+ 32, 32, 32, 33, 33, 34, 34, 35, 35, 37, 37, 38, 38, 40, 40, 43,
1097+ 32, 32, 32, 33, 33, 34, 34, 35, 35, 37, 37, 38, 38, 40, 40, 43,
1098+ 36, 35, 35, 34, 34, 36, 36, 38, 38, 42, 42, 48, 48, 50, 50, 53,
1099+ 36, 35, 35, 34, 34, 36, 36, 38, 38, 42, 42, 48, 48, 50, 50, 53,
1100+ 44, 42, 42, 41, 41, 42, 42, 42, 42, 48, 48, 54, 54, 58, 58, 63,
1101+ }, {
1102+ 32, 31, 31, 30, 30, 33, 33, 37, 37, 42, 42, 49, 49, 48, 48, 49,
1103+ 31, 31, 31, 32, 32, 36, 36, 40, 40, 43, 43, 46, 46, 46, 46, 45,
1104+ 31, 31, 31, 32, 32, 36, 36, 40, 40, 43, 43, 46, 46, 46, 46, 45,
1105+ 37, 38, 38, 40, 40, 43, 43, 47, 47, 47, 47, 48, 48, 47, 47, 46,
1106+ 37, 38, 38, 40, 40, 43, 43, 47, 47, 47, 47, 48, 48, 47, 47, 46,
1107+ 48, 47, 47, 46, 46, 47, 47, 47, 47, 50, 50, 53, 53, 53, 53, 53,
1108+ 48, 47, 47, 46, 46, 47, 47, 47, 47, 50, 50, 53, 53, 53, 53, 53,
1109+ 49, 47, 47, 45, 45, 46, 46, 45, 45, 49, 49, 53, 53, 56, 56, 58,
1110+ },
1111+ }, {
1112+ {
1113+ 32, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 33, 34, 34, 36, 36,
1114+ 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 34, 34, 35, 35,
1115+ 31, 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 34, 34, 34, 34,
1116+ 31, 32, 32, 32, 32, 32, 33, 33, 33, 34, 34, 35, 35, 35, 36, 36,
1117+ 32, 32, 32, 32, 33, 33, 34, 34, 34, 35, 35, 36, 37, 37, 38, 38,
1118+ 32, 32, 32, 32, 33, 33, 34, 34, 34, 35, 35, 36, 37, 37, 38, 38,
1119+ 35, 35, 35, 34, 34, 34, 35, 36, 36, 37, 37, 40, 41, 43, 46, 46,
1120+ 36, 35, 35, 35, 34, 34, 36, 36, 37, 38, 38, 41, 42, 44, 48, 48,
1121+ }, {
1122+ 32, 31, 31, 31, 30, 30, 33, 33, 35, 37, 37, 41, 42, 44, 49, 49,
1123+ 31, 31, 31, 31, 32, 32, 34, 35, 37, 39, 39, 42, 42, 44, 47, 47,
1124+ 31, 31, 31, 32, 32, 32, 35, 36, 37, 40, 40, 42, 43, 44, 46, 46,
1125+ 33, 34, 34, 34, 35, 35, 37, 38, 40, 43, 43, 44, 44, 45, 47, 47,
1126+ 37, 38, 38, 39, 40, 40, 42, 43, 44, 47, 47, 47, 47, 47, 48, 48,
1127+ 37, 38, 38, 39, 40, 40, 42, 43, 44, 47, 47, 47, 47, 47, 48, 48,
1128+ 45, 45, 45, 45, 44, 44, 46, 46, 46, 47, 47, 49, 49, 50, 52, 52,
1129+ 48, 47, 47, 46, 46, 46, 47, 47, 47, 47, 47, 49, 50, 51, 53, 53,
1130+ },
1131+ }, {
1132+ {
1133+ 32, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 34,
1134+ 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 34,
1135+ 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 34,
1136+ 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 34,
1137+ 31, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 33, 34, 34, 34, 35,
1138+ 32, 32, 32, 32, 32, 33, 33, 33, 34, 34, 34, 35, 35, 35, 36, 37,
1139+ 32, 32, 32, 32, 32, 33, 33, 33, 34, 34, 34, 35, 35, 35, 36, 37,
1140+ 32, 33, 33, 33, 33, 33, 33, 33, 34, 34, 34, 35, 36, 36, 36, 38,
1141+ }, {
1142+ 32, 31, 31, 31, 31, 30, 30, 31, 33, 33, 33, 35, 37, 37, 39, 42,
1143+ 31, 31, 31, 31, 31, 31, 31, 32, 34, 35, 35, 37, 39, 39, 40, 42,
1144+ 31, 31, 31, 31, 32, 32, 32, 33, 35, 36, 36, 38, 40, 40, 41, 43,
1145+ 31, 31, 31, 31, 32, 32, 32, 33, 35, 36, 36, 38, 40, 40, 41, 43,
1146+ 33, 33, 34, 34, 34, 35, 35, 35, 37, 38, 38, 41, 43, 43, 43, 44,
1147+ 37, 38, 38, 38, 39, 40, 40, 40, 42, 43, 43, 45, 47, 47, 47, 47,
1148+ 37, 38, 38, 38, 39, 40, 40, 40, 42, 43, 43, 45, 47, 47, 47, 47,
1149+ 38, 39, 40, 40, 40, 41, 41, 41, 43, 44, 44, 46, 47, 47, 47, 48,
1150+ },
1151+ }, {
1152+ {
1153+ 32, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32,
1154+ 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1155+ 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1156+ 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1157+ 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1158+ 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1159+ 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 33, 33,
1160+ 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 34, 34, 34,
1161+ }, {
1162+ 32, 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 31, 33, 33, 33, 33,
1163+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 34, 34, 34, 34,
1164+ 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 33, 34, 35, 35, 35,
1165+ 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 33, 35, 36, 36, 36,
1166+ 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 33, 35, 36, 36, 36,
1167+ 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 33, 35, 36, 36, 36,
1168+ 33, 33, 34, 34, 34, 34, 34, 34, 35, 35, 35, 36, 37, 38, 38, 38,
1169+ 35, 36, 36, 37, 37, 37, 37, 38, 38, 38, 38, 39, 40, 41, 41, 41,
1170+ },
1171+ }, {
1172+ {
1173+ 32, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
1174+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
1175+ 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1176+ 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1177+ 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1178+ 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1179+ 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1180+ 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1181+ }, {
1182+ 32, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 30, 30,
1183+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
1184+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
1185+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
1186+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32,
1187+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32,
1188+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32,
1189+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32,
1190+ },
1191+ },
1192+};
1193+
1194+static const uint8_t qm_tbl_32x8[][2][256] = {
1195+ {
1196+ {
1197+ 32, 31, 31, 31, 32, 32, 34, 35, 36, 39, 44, 46, 48, 53, 58, 61, 65, 71, 79, 81, 82, 88, 91, 94, 97, 100, 103, 107, 110, 114, 118, 122,
1198+ 32, 32, 33, 33, 34, 35, 37, 37, 38, 40, 43, 44, 46, 50, 54, 56, 58, 63, 70, 71, 72, 77, 80, 83, 86, 89, 93, 96, 100, 104, 107, 111,
1199+ 36, 35, 34, 35, 36, 38, 42, 45, 48, 50, 53, 55, 56, 60, 63, 66, 68, 73, 79, 80, 81, 85, 88, 91, 94, 97, 98, 100, 101, 103, 105, 107,
1200+ 53, 51, 49, 49, 50, 49, 54, 57, 60, 65, 71, 73, 76, 82, 87, 89, 92, 97, 104, 105, 106, 108, 106, 105, 107, 111, 114, 117, 117, 117, 118, 119,
1201+ 65, 62, 59, 59, 59, 58, 63, 65, 68, 73, 79, 82, 85, 92, 98, 101, 105, 111, 118, 119, 121, 126, 130, 131, 128, 127, 131, 136, 138, 137, 136, 136,
1202+ 87, 82, 78, 78, 77, 75, 79, 82, 84, 89, 95, 98, 102, 109, 116, 120, 124, 132, 141, 142, 144, 149, 148, 153, 157, 152, 150, 155, 161, 159, 157, 156,
1203+ 93, 88, 86, 84, 82, 82, 80, 84, 86, 91, 94, 98, 105, 107, 112, 119, 122, 130, 135, 140, 149, 153, 162, 165, 167, 173, 174, 177, 183, 185, 182, 179,
1204+ 99, 94, 93, 90, 89, 89, 88, 87, 90, 93, 97, 99, 105, 107, 115, 116, 124, 127, 135, 139, 146, 152, 159, 166, 171, 182, 186, 191, 193, 201, 203, 204,
1205+ }, {
1206+ 32, 31, 30, 32, 33, 37, 42, 45, 49, 48, 49, 49, 50, 52, 54, 55, 57, 60, 63, 64, 64, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
1207+ 37, 38, 40, 41, 43, 47, 47, 47, 48, 47, 46, 46, 46, 47, 49, 49, 50, 52, 55, 55, 56, 58, 59, 60, 62, 63, 64, 65, 67, 68, 69, 70,
1208+ 48, 47, 46, 46, 47, 47, 50, 51, 53, 53, 53, 53, 54, 54, 55, 56, 56, 58, 60, 61, 61, 63, 64, 65, 66, 67, 66, 66, 66, 66, 67, 67,
1209+ 52, 50, 48, 48, 47, 47, 50, 52, 54, 57, 61, 62, 64, 66, 68, 69, 70, 72, 75, 75, 75, 76, 74, 72, 73, 74, 75, 75, 74, 74, 73, 73,
1210+ 57, 54, 52, 51, 51, 50, 53, 55, 57, 60, 64, 65, 67, 71, 73, 75, 76, 79, 82, 82, 83, 85, 86, 85, 83, 82, 83, 84, 84, 83, 82, 81,
1211+ 66, 63, 60, 59, 59, 57, 60, 61, 62, 66, 69, 71, 73, 77, 80, 82, 84, 88, 92, 92, 93, 95, 94, 95, 96, 93, 92, 93, 94, 93, 91, 90,
1212+ 68, 65, 63, 62, 60, 60, 59, 61, 62, 65, 66, 68, 72, 73, 76, 79, 80, 84, 87, 89, 93, 94, 98, 99, 99, 102, 101, 102, 103, 103, 101, 99,
1213+ 71, 67, 66, 64, 63, 62, 62, 61, 62, 64, 66, 67, 70, 71, 75, 76, 79, 81, 84, 86, 89, 91, 94, 97, 98, 102, 104, 106, 106, 109, 109, 108,
1214+ },
1215+ }, {
1216+ {
1217+ 32, 31, 31, 31, 32, 32, 32, 34, 36, 38, 39, 44, 47, 49, 53, 58, 61, 65, 71, 76, 79, 82, 86, 89, 92, 95, 98, 101, 104, 107, 110, 114,
1218+ 32, 32, 32, 33, 34, 35, 35, 36, 37, 39, 40, 42, 45, 47, 50, 54, 56, 59, 64, 68, 70, 73, 76, 79, 82, 85, 88, 91, 94, 97, 100, 104,
1219+ 36, 35, 35, 35, 36, 38, 40, 42, 48, 49, 50, 53, 56, 57, 60, 63, 65, 68, 73, 76, 79, 81, 84, 87, 89, 92, 93, 94, 95, 96, 98, 100,
1220+ 47, 45, 44, 44, 45, 45, 47, 50, 56, 58, 60, 66, 69, 71, 75, 79, 81, 84, 89, 92, 95, 97, 100, 99, 101, 105, 108, 110, 110, 110, 111, 111,
1221+ 65, 62, 60, 59, 59, 58, 60, 63, 68, 71, 73, 79, 84, 86, 92, 98, 100, 105, 111, 115, 118, 121, 124, 124, 121, 120, 124, 128, 129, 128, 127, 127,
1222+ 79, 75, 72, 71, 71, 69, 71, 73, 78, 81, 84, 90, 95, 97, 103, 110, 113, 118, 125, 130, 133, 136, 140, 145, 148, 143, 141, 146, 151, 149, 147, 145,
1223+ 90, 86, 84, 82, 80, 80, 78, 82, 83, 88, 91, 94, 101, 103, 108, 114, 116, 124, 129, 134, 142, 145, 153, 156, 157, 163, 163, 166, 171, 173, 169, 166,
1224+ 96, 91, 90, 87, 87, 86, 85, 84, 87, 90, 94, 96, 101, 102, 110, 111, 118, 121, 129, 132, 138, 144, 150, 156, 161, 171, 174, 179, 181, 188, 188, 190,
1225+ }, {
1226+ 32, 31, 30, 31, 33, 37, 39, 42, 49, 48, 48, 49, 50, 51, 52, 54, 55, 57, 60, 62, 63, 64, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75,
1227+ 35, 37, 38, 38, 41, 45, 46, 46, 48, 47, 46, 45, 46, 47, 47, 49, 49, 50, 53, 54, 55, 56, 58, 59, 60, 61, 62, 64, 65, 66, 67, 68,
1228+ 48, 47, 46, 46, 47, 47, 48, 50, 53, 53, 53, 53, 54, 54, 54, 55, 56, 56, 58, 60, 60, 61, 62, 63, 64, 65, 65, 65, 65, 65, 65, 65,
1229+ 50, 48, 46, 46, 46, 46, 47, 50, 54, 55, 56, 59, 61, 61, 63, 65, 65, 66, 68, 69, 70, 71, 72, 71, 71, 72, 73, 73, 72, 72, 71, 71,
1230+ 57, 54, 52, 52, 51, 50, 51, 53, 57, 58, 60, 64, 66, 68, 71, 73, 74, 76, 79, 81, 82, 83, 84, 83, 81, 80, 81, 82, 82, 81, 79, 78,
1231+ 63, 60, 58, 57, 56, 54, 55, 57, 60, 62, 64, 67, 70, 71, 75, 78, 79, 82, 85, 87, 89, 90, 91, 93, 94, 91, 89, 90, 92, 90, 89, 87,
1232+ 68, 64, 63, 61, 60, 59, 58, 60, 61, 64, 65, 67, 71, 72, 75, 78, 79, 83, 85, 87, 91, 92, 95, 96, 97, 99, 98, 99, 100, 100, 98, 96,
1233+ 70, 66, 65, 63, 63, 62, 61, 60, 61, 63, 65, 66, 69, 70, 74, 74, 78, 79, 82, 84, 87, 89, 91, 94, 96, 100, 101, 103, 103, 105, 105, 105,
1234+ },
1235+ }, {
1236+ {
1237+ 32, 31, 31, 31, 32, 32, 32, 34, 34, 36, 39, 40, 44, 47, 49, 53, 57, 59, 65, 69, 71, 79, 81, 82, 87, 90, 92, 95, 98, 100, 103, 106,
1238+ 32, 32, 32, 32, 33, 34, 34, 35, 36, 37, 39, 40, 42, 45, 46, 50, 53, 54, 59, 62, 64, 71, 72, 73, 77, 80, 83, 85, 88, 91, 94, 97,
1239+ 36, 35, 35, 34, 36, 37, 38, 42, 44, 48, 50, 51, 53, 56, 57, 60, 63, 64, 68, 71, 73, 79, 80, 81, 85, 87, 88, 88, 89, 90, 92, 93,
1240+ 44, 42, 41, 41, 42, 42, 42, 48, 50, 54, 58, 59, 63, 66, 67, 71, 74, 75, 79, 83, 84, 90, 91, 92, 96, 99, 102, 103, 103, 103, 103, 104,
1241+ 58, 55, 54, 53, 53, 53, 52, 57, 59, 63, 68, 70, 74, 79, 81, 86, 90, 91, 97, 100, 102, 109, 110, 111, 114, 113, 117, 120, 121, 120, 119, 118,
1242+ 79, 75, 73, 72, 71, 70, 69, 73, 75, 78, 84, 85, 90, 95, 97, 103, 108, 111, 118, 122, 125, 133, 135, 136, 140, 135, 133, 137, 141, 139, 137, 135,
1243+ 88, 83, 81, 79, 78, 77, 76, 79, 81, 85, 88, 91, 97, 99, 104, 109, 111, 119, 123, 127, 135, 137, 145, 147, 148, 153, 153, 155, 160, 161, 158, 155,
1244+ 93, 88, 88, 84, 84, 83, 82, 81, 84, 86, 90, 92, 97, 98, 105, 106, 113, 115, 122, 125, 131, 136, 141, 147, 151, 160, 163, 168, 169, 175, 175, 176,
1245+ }, {
1246+ 32, 31, 31, 30, 33, 35, 37, 42, 44, 49, 48, 48, 49, 50, 51, 52, 54, 54, 57, 59, 60, 63, 64, 64, 66, 67, 68, 69, 70, 71, 72, 73,
1247+ 34, 35, 36, 36, 40, 42, 44, 45, 46, 47, 46, 46, 45, 46, 47, 47, 49, 49, 51, 52, 53, 56, 57, 57, 59, 60, 61, 62, 63, 64, 65, 66,
1248+ 48, 47, 46, 46, 47, 47, 47, 50, 51, 53, 53, 53, 53, 54, 54, 54, 55, 55, 56, 58, 58, 60, 61, 61, 63, 63, 63, 63, 63, 63, 63, 63,
1249+ 49, 47, 46, 45, 46, 45, 45, 49, 51, 53, 56, 56, 58, 59, 60, 61, 62, 62, 64, 65, 65, 67, 68, 68, 69, 70, 71, 71, 70, 70, 69, 69,
1250+ 54, 51, 50, 49, 49, 48, 48, 51, 53, 55, 58, 59, 62, 65, 65, 68, 70, 70, 73, 74, 75, 77, 78, 78, 79, 78, 79, 80, 80, 78, 77, 76,
1251+ 63, 60, 58, 57, 56, 55, 54, 57, 59, 60, 64, 65, 67, 70, 71, 75, 77, 78, 82, 84, 85, 89, 89, 90, 91, 88, 87, 88, 89, 88, 86, 84,
1252+ 67, 63, 62, 60, 59, 58, 57, 59, 60, 63, 64, 66, 70, 70, 73, 76, 77, 81, 83, 85, 89, 90, 93, 94, 94, 96, 96, 96, 97, 97, 95, 93,
1253+ 69, 65, 65, 62, 62, 61, 60, 59, 61, 62, 64, 65, 68, 68, 72, 73, 76, 77, 81, 82, 85, 87, 89, 92, 93, 97, 98, 100, 100, 102, 102, 101,
1254+ },
1255+ }, {
1256+ {
1257+ 32, 31, 31, 31, 31, 32, 32, 32, 34, 35, 36, 39, 41, 44, 47, 48, 53, 55, 58, 63, 65, 71, 74, 79, 82, 82, 87, 89, 92, 94, 97, 99,
1258+ 31, 32, 32, 32, 33, 33, 34, 34, 35, 36, 36, 39, 40, 42, 44, 45, 50, 51, 54, 58, 59, 64, 67, 71, 73, 74, 78, 81, 83, 85, 88, 91,
1259+ 35, 35, 34, 34, 35, 36, 37, 39, 41, 45, 46, 48, 49, 51, 53, 54, 57, 59, 61, 65, 66, 71, 73, 77, 79, 79, 83, 83, 84, 85, 86, 87,
1260+ 44, 42, 41, 41, 42, 42, 42, 44, 48, 52, 54, 58, 60, 63, 66, 67, 71, 72, 75, 78, 79, 84, 86, 90, 92, 92, 96, 97, 97, 97, 97, 97,
1261+ 53, 51, 50, 49, 49, 50, 49, 51, 54, 59, 60, 65, 67, 71, 75, 76, 82, 84, 87, 91, 92, 97, 100, 104, 105, 106, 110, 113, 114, 112, 111, 110,
1262+ 65, 62, 61, 59, 59, 59, 58, 60, 63, 67, 68, 73, 76, 79, 84, 85, 92, 94, 98, 103, 105, 111, 113, 118, 120, 121, 125, 128, 132, 130, 128, 126,
1263+ 82, 78, 76, 74, 73, 73, 71, 73, 76, 79, 80, 86, 88, 92, 97, 98, 106, 108, 112, 118, 120, 127, 131, 136, 139, 139, 144, 145, 150, 151, 147, 144,
1264+ 90, 86, 85, 82, 81, 80, 79, 78, 81, 83, 87, 88, 93, 94, 101, 101, 108, 110, 116, 119, 124, 129, 134, 139, 142, 150, 153, 157, 157, 163, 163, 163,
1265+ }, {
1266+ 32, 31, 31, 30, 33, 33, 37, 39, 42, 47, 49, 48, 48, 49, 50, 50, 52, 53, 54, 56, 57, 60, 61, 63, 64, 64, 66, 67, 68, 69, 70, 70,
1267+ 33, 34, 34, 35, 37, 38, 43, 43, 44, 46, 47, 46, 46, 45, 46, 46, 47, 48, 49, 51, 51, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64,
1268+ 45, 45, 45, 44, 46, 46, 47, 48, 49, 51, 52, 51, 51, 51, 52, 52, 53, 53, 54, 55, 55, 57, 58, 59, 60, 60, 61, 61, 61, 61, 61, 61,
1269+ 49, 47, 46, 45, 45, 46, 45, 47, 49, 53, 53, 56, 57, 58, 59, 59, 61, 61, 62, 63, 64, 65, 66, 67, 68, 68, 69, 69, 68, 68, 67, 67,
1270+ 52, 50, 49, 48, 47, 47, 47, 48, 50, 53, 54, 57, 59, 61, 63, 64, 66, 67, 68, 70, 70, 72, 73, 75, 75, 75, 77, 78, 77, 76, 75, 74,
1271+ 57, 54, 53, 52, 51, 51, 50, 51, 53, 56, 57, 60, 61, 64, 66, 67, 71, 72, 73, 76, 76, 79, 80, 82, 83, 83, 84, 85, 86, 85, 83, 82,
1272+ 64, 61, 60, 58, 57, 57, 55, 56, 58, 61, 61, 64, 66, 68, 71, 71, 75, 77, 79, 82, 83, 86, 87, 90, 91, 91, 93, 93, 94, 94, 92, 90,
1273+ 68, 64, 64, 61, 61, 60, 59, 58, 60, 61, 63, 64, 67, 67, 71, 71, 74, 75, 79, 80, 83, 85, 87, 89, 91, 94, 95, 97, 97, 99, 98, 98,
1274+ },
1275+ }, {
1276+ {
1277+ 32, 31, 31, 31, 31, 32, 32, 32, 33, 34, 36, 36, 39, 40, 44, 46, 48, 52, 53, 58, 58, 65, 66, 71, 74, 79, 81, 82, 86, 88, 91, 93,
1278+ 31, 32, 32, 32, 32, 33, 33, 33, 34, 34, 35, 35, 38, 39, 41, 43, 45, 48, 49, 53, 54, 59, 60, 65, 67, 72, 73, 74, 78, 80, 82, 85,
1279+ 33, 33, 33, 33, 34, 35, 36, 36, 38, 39, 42, 42, 44, 45, 46, 48, 50, 52, 53, 57, 57, 62, 63, 67, 69, 73, 75, 75, 78, 80, 80, 81,
1280+ 40, 39, 39, 38, 38, 39, 40, 41, 44, 45, 51, 51, 54, 56, 59, 60, 62, 65, 66, 69, 70, 74, 75, 79, 81, 85, 86, 87, 90, 90, 90, 90,
1281+ 51, 49, 49, 47, 47, 48, 48, 48, 52, 53, 58, 59, 63, 65, 69, 72, 74, 78, 79, 83, 84, 89, 90, 94, 97, 101, 102, 103, 106, 105, 103, 103,
1282+ 65, 62, 61, 59, 59, 59, 58, 58, 62, 63, 68, 68, 73, 75, 79, 82, 85, 90, 92, 97, 98, 105, 106, 111, 113, 118, 120, 121, 124, 122, 119, 117,
1283+ 79, 75, 74, 72, 71, 71, 69, 69, 72, 73, 78, 79, 84, 85, 90, 93, 96, 101, 103, 109, 110, 118, 119, 125, 128, 133, 135, 136, 140, 140, 137, 134,
1284+ 87, 83, 82, 79, 79, 78, 77, 75, 78, 80, 84, 85, 89, 90, 96, 97, 103, 105, 111, 113, 118, 122, 126, 131, 134, 141, 143, 147, 147, 152, 151, 152,
1285+ }, {
1286+ 32, 31, 31, 30, 31, 33, 35, 37, 41, 42, 49, 49, 48, 48, 49, 49, 50, 51, 52, 54, 54, 57, 57, 60, 61, 63, 64, 64, 66, 67, 68, 68,
1287+ 32, 33, 33, 33, 35, 37, 39, 41, 43, 43, 47, 47, 46, 46, 45, 46, 46, 47, 48, 49, 50, 52, 52, 54, 55, 57, 58, 58, 59, 60, 61, 62,
1288+ 40, 41, 41, 42, 43, 44, 46, 47, 48, 48, 50, 50, 49, 49, 48, 49, 49, 49, 50, 51, 51, 52, 53, 55, 56, 57, 58, 58, 59, 59, 59, 59,
1289+ 49, 47, 47, 45, 46, 46, 46, 46, 49, 49, 53, 53, 54, 55, 56, 57, 57, 58, 58, 59, 59, 60, 61, 62, 63, 64, 65, 65, 66, 66, 65, 65,
1290+ 51, 49, 49, 47, 47, 47, 47, 46, 49, 50, 54, 54, 57, 58, 61, 62, 63, 64, 65, 67, 67, 69, 69, 71, 72, 73, 73, 74, 75, 74, 72, 71,
1291+ 57, 54, 54, 52, 51, 51, 50, 50, 52, 53, 57, 57, 60, 61, 64, 65, 67, 69, 71, 73, 73, 76, 77, 79, 80, 82, 82, 83, 84, 82, 81, 79,
1292+ 63, 60, 59, 57, 57, 56, 55, 54, 57, 57, 60, 61, 64, 65, 67, 69, 71, 73, 75, 77, 78, 82, 82, 85, 86, 89, 89, 90, 91, 91, 89, 87,
1293+ 67, 63, 63, 60, 60, 59, 58, 57, 59, 60, 62, 63, 65, 66, 69, 70, 73, 74, 77, 78, 81, 83, 85, 87, 88, 92, 92, 94, 94, 96, 95, 95,
1294+ },
1295+ }, {
1296+ {
1297+ 32, 31, 31, 31, 31, 32, 32, 32, 32, 34, 34, 36, 36, 39, 39, 44, 44, 48, 48, 53, 53, 58, 58, 65, 65, 71, 71, 79, 79, 82, 82, 87,
1298+ 31, 32, 32, 32, 32, 32, 32, 33, 33, 34, 34, 34, 34, 37, 37, 41, 41, 45, 45, 49, 49, 54, 54, 60, 60, 65, 65, 72, 72, 75, 75, 79,
1299+ 32, 32, 32, 33, 33, 34, 34, 35, 35, 37, 37, 38, 38, 40, 40, 43, 43, 46, 46, 50, 50, 54, 54, 58, 58, 63, 63, 70, 70, 72, 72, 76,
1300+ 36, 35, 35, 34, 34, 36, 36, 38, 38, 42, 42, 48, 48, 50, 50, 53, 53, 56, 56, 60, 60, 63, 63, 68, 68, 73, 73, 79, 79, 81, 81, 84,
1301+ 44, 42, 42, 41, 41, 42, 42, 42, 42, 48, 48, 54, 54, 58, 58, 63, 63, 67, 67, 71, 71, 75, 75, 79, 79, 84, 84, 90, 90, 92, 92, 96,
1302+ 53, 51, 51, 49, 49, 50, 50, 49, 49, 54, 54, 60, 60, 65, 65, 71, 71, 76, 76, 82, 82, 87, 87, 92, 92, 97, 97, 104, 104, 106, 106, 109,
1303+ 65, 62, 62, 59, 59, 59, 59, 58, 58, 63, 63, 68, 68, 73, 73, 79, 79, 85, 85, 92, 92, 98, 98, 105, 105, 111, 111, 118, 118, 121, 121, 124,
1304+ 79, 75, 75, 72, 72, 71, 71, 69, 69, 73, 73, 78, 78, 84, 84, 90, 90, 96, 96, 103, 103, 110, 110, 118, 118, 125, 125, 133, 133, 136, 136, 141,
1305+ }, {
1306+ 32, 31, 31, 30, 30, 33, 33, 37, 37, 42, 42, 49, 49, 48, 48, 49, 49, 50, 50, 52, 52, 54, 54, 57, 57, 60, 60, 63, 63, 64, 64, 66,
1307+ 31, 31, 31, 32, 32, 36, 36, 40, 40, 43, 43, 46, 46, 46, 46, 45, 45, 46, 46, 48, 48, 50, 50, 52, 52, 54, 54, 57, 57, 59, 59, 60,
1308+ 37, 38, 38, 40, 40, 43, 43, 47, 47, 47, 47, 48, 48, 47, 47, 46, 46, 46, 46, 47, 47, 49, 49, 50, 50, 52, 52, 55, 55, 56, 56, 57,
1309+ 48, 47, 47, 46, 46, 47, 47, 47, 47, 50, 50, 53, 53, 53, 53, 53, 53, 54, 54, 54, 54, 55, 55, 56, 56, 58, 58, 60, 60, 61, 61, 63,
1310+ 49, 47, 47, 45, 45, 46, 46, 45, 45, 49, 49, 53, 53, 56, 56, 58, 58, 59, 59, 61, 61, 62, 62, 64, 64, 65, 65, 67, 67, 68, 68, 69,
1311+ 52, 50, 50, 48, 48, 47, 47, 47, 47, 50, 50, 54, 54, 57, 57, 61, 61, 64, 64, 66, 66, 68, 68, 70, 70, 72, 72, 75, 75, 75, 75, 77,
1312+ 57, 54, 54, 52, 52, 51, 51, 50, 50, 53, 53, 57, 57, 60, 60, 64, 64, 67, 67, 71, 71, 73, 73, 76, 76, 79, 79, 82, 82, 83, 83, 84,
1313+ 63, 60, 60, 57, 57, 56, 56, 54, 54, 57, 57, 60, 60, 64, 64, 67, 67, 71, 71, 75, 75, 78, 78, 82, 82, 85, 85, 89, 89, 90, 90, 92,
1314+ },
1315+ }, {
1316+ {
1317+ 32, 31, 31, 31, 31, 31, 32, 32, 32, 32, 34, 34, 35, 36, 38, 39, 41, 44, 44, 48, 48, 53, 53, 57, 58, 61, 65, 67, 71, 72, 79, 79,
1318+ 31, 32, 32, 32, 32, 32, 32, 32, 33, 33, 34, 34, 34, 34, 36, 37, 39, 41, 42, 45, 45, 49, 49, 52, 54, 57, 60, 61, 65, 66, 72, 72,
1319+ 32, 32, 32, 32, 33, 33, 34, 34, 35, 35, 37, 37, 38, 38, 40, 40, 41, 43, 43, 46, 46, 49, 50, 52, 54, 56, 58, 60, 63, 64, 70, 70,
1320+ 36, 35, 35, 35, 34, 35, 36, 37, 38, 39, 42, 42, 47, 48, 49, 50, 51, 53, 54, 56, 56, 59, 60, 62, 63, 66, 68, 69, 73, 73, 79, 79,
1321+ 44, 42, 42, 41, 41, 41, 42, 42, 42, 43, 48, 48, 52, 54, 56, 58, 60, 63, 64, 67, 67, 71, 71, 74, 75, 77, 79, 81, 84, 85, 90, 90,
1322+ 53, 51, 51, 50, 49, 49, 50, 49, 49, 50, 54, 54, 59, 60, 63, 65, 67, 71, 72, 76, 76, 81, 82, 85, 87, 89, 92, 94, 97, 98, 104, 104,
1323+ 62, 60, 59, 58, 57, 57, 57, 56, 56, 56, 61, 61, 65, 66, 69, 71, 74, 78, 79, 83, 83, 89, 90, 94, 95, 98, 102, 103, 108, 108, 115, 115,
1324+ 73, 70, 69, 67, 66, 66, 65, 65, 64, 64, 69, 69, 73, 74, 77, 79, 81, 85, 86, 91, 91, 98, 99, 103, 105, 108, 112, 114, 119, 119, 127, 127,
1325+ }, {
1326+ 32, 31, 31, 30, 30, 32, 33, 34, 37, 37, 42, 42, 47, 49, 48, 48, 48, 49, 49, 50, 50, 52, 52, 53, 54, 55, 57, 58, 60, 60, 63, 63,
1327+ 31, 31, 31, 32, 32, 34, 36, 37, 40, 40, 43, 43, 46, 46, 46, 46, 45, 45, 45, 46, 46, 48, 48, 49, 50, 51, 52, 53, 54, 55, 57, 57,
1328+ 37, 38, 38, 39, 40, 41, 43, 44, 47, 47, 47, 47, 48, 48, 47, 47, 46, 46, 46, 46, 46, 47, 47, 48, 49, 49, 50, 51, 52, 53, 55, 55,
1329+ 48, 47, 47, 46, 46, 46, 47, 47, 47, 48, 50, 50, 52, 53, 53, 53, 53, 53, 53, 54, 54, 54, 54, 55, 55, 56, 56, 57, 58, 59, 60, 60,
1330+ 49, 47, 47, 46, 45, 45, 46, 45, 45, 46, 49, 49, 53, 53, 55, 56, 57, 58, 58, 59, 59, 61, 61, 62, 62, 63, 64, 64, 65, 65, 67, 67,
1331+ 52, 50, 50, 48, 48, 48, 47, 47, 47, 47, 50, 50, 53, 54, 56, 57, 59, 61, 62, 64, 64, 66, 66, 68, 68, 69, 70, 71, 72, 73, 75, 75,
1332+ 56, 54, 53, 52, 51, 51, 50, 50, 49, 49, 53, 53, 55, 56, 58, 59, 61, 63, 64, 66, 66, 69, 70, 71, 72, 74, 75, 76, 77, 78, 80, 80,
1333+ 61, 58, 57, 56, 55, 54, 54, 53, 52, 53, 56, 56, 58, 59, 61, 62, 63, 66, 66, 69, 69, 72, 73, 75, 76, 78, 79, 80, 82, 83, 86, 86,
1334+ },
1335+ }, {
1336+ {
1337+ 32, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 33, 34, 34, 36, 36, 38, 39, 41, 44, 44, 47, 48, 50, 53, 53, 57, 58, 61, 65, 65, 70,
1338+ 31, 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 34, 34, 34, 34, 37, 37, 39, 41, 41, 44, 45, 46, 49, 49, 53, 54, 56, 60, 60, 64,
1339+ 32, 32, 32, 32, 33, 33, 34, 34, 34, 35, 35, 36, 37, 37, 38, 38, 40, 40, 41, 43, 43, 45, 46, 47, 50, 50, 53, 54, 56, 58, 58, 62,
1340+ 35, 35, 35, 34, 34, 34, 35, 36, 36, 37, 37, 40, 41, 43, 46, 46, 47, 48, 49, 51, 51, 53, 54, 55, 57, 57, 60, 61, 63, 66, 66, 70,
1341+ 39, 38, 38, 37, 37, 37, 38, 38, 39, 40, 40, 43, 44, 46, 50, 50, 52, 53, 54, 57, 57, 59, 60, 61, 64, 64, 67, 68, 69, 72, 72, 76,
1342+ 44, 42, 42, 41, 41, 41, 42, 42, 42, 42, 42, 46, 48, 50, 54, 54, 57, 58, 60, 63, 63, 66, 67, 68, 71, 71, 74, 75, 77, 79, 79, 83,
1343+ 53, 52, 51, 50, 49, 49, 49, 50, 49, 49, 49, 53, 54, 56, 60, 60, 64, 65, 67, 71, 71, 75, 76, 78, 82, 82, 86, 87, 89, 92, 92, 96,
1344+ 65, 63, 62, 61, 59, 59, 59, 59, 58, 58, 58, 62, 63, 65, 68, 68, 72, 73, 76, 79, 79, 84, 85, 88, 92, 92, 97, 98, 100, 105, 105, 109,
1345+ }, {
1346+ 32, 31, 31, 31, 30, 30, 33, 33, 35, 37, 37, 41, 42, 44, 49, 49, 48, 48, 48, 49, 49, 50, 50, 51, 52, 52, 54, 54, 55, 57, 57, 59,
1347+ 31, 31, 31, 32, 32, 32, 35, 36, 37, 40, 40, 42, 43, 44, 46, 46, 46, 46, 45, 45, 45, 46, 46, 47, 48, 48, 49, 50, 51, 52, 52, 54,
1348+ 37, 38, 38, 39, 40, 40, 42, 43, 44, 47, 47, 47, 47, 47, 48, 48, 47, 47, 46, 46, 46, 46, 46, 47, 47, 47, 48, 49, 49, 50, 50, 52,
1349+ 45, 45, 45, 45, 44, 44, 46, 46, 46, 47, 47, 49, 49, 50, 52, 52, 51, 51, 51, 51, 51, 52, 52, 52, 53, 53, 54, 54, 54, 55, 55, 57,
1350+ 48, 47, 47, 46, 45, 45, 46, 46, 46, 47, 47, 49, 50, 51, 53, 53, 54, 54, 54, 55, 55, 56, 56, 56, 57, 57, 58, 58, 58, 59, 59, 61,
1351+ 49, 47, 47, 46, 45, 45, 45, 46, 45, 45, 45, 48, 49, 51, 53, 53, 55, 56, 57, 58, 58, 59, 59, 60, 61, 61, 62, 62, 63, 64, 64, 65,
1352+ 52, 50, 50, 49, 48, 48, 47, 47, 47, 47, 47, 50, 50, 52, 54, 54, 57, 57, 59, 61, 61, 63, 64, 65, 66, 66, 68, 68, 69, 70, 70, 72,
1353+ 57, 55, 54, 53, 52, 52, 51, 51, 51, 50, 50, 52, 53, 54, 57, 57, 59, 60, 61, 64, 64, 66, 67, 68, 71, 71, 73, 73, 74, 76, 76, 78,
1354+ },
1355+ }, {
1356+ {
1357+ 32, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 34, 34, 35, 36, 36, 38, 39, 39, 42, 44, 44, 47, 48, 49, 53, 53, 55, 58, 58,
1358+ 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 34, 34, 34, 34, 34, 36, 37, 37, 40, 41, 41, 44, 45, 46, 49, 49, 51, 54, 54,
1359+ 32, 32, 32, 32, 32, 32, 33, 33, 34, 34, 35, 35, 35, 36, 36, 37, 37, 37, 39, 40, 40, 42, 42, 43, 45, 46, 47, 49, 50, 51, 54, 54,
1360+ 32, 33, 33, 33, 33, 33, 33, 34, 34, 35, 36, 36, 36, 38, 38, 39, 40, 40, 41, 42, 42, 44, 45, 45, 47, 48, 48, 51, 51, 53, 55, 55,
1361+ 36, 35, 35, 35, 35, 34, 35, 36, 36, 37, 38, 38, 40, 42, 42, 45, 48, 48, 49, 50, 50, 52, 53, 54, 56, 56, 57, 59, 60, 61, 63, 63,
1362+ 44, 43, 42, 42, 41, 41, 41, 42, 42, 42, 42, 42, 44, 48, 48, 50, 54, 54, 56, 58, 58, 61, 63, 63, 66, 67, 67, 71, 71, 72, 75, 75,
1363+ 47, 46, 45, 45, 44, 44, 44, 45, 45, 45, 45, 45, 47, 50, 50, 53, 56, 56, 58, 60, 60, 64, 66, 66, 69, 70, 71, 74, 75, 76, 79, 79,
1364+ 53, 52, 51, 51, 49, 49, 49, 49, 50, 49, 49, 49, 51, 54, 54, 57, 60, 60, 63, 65, 65, 69, 71, 72, 75, 76, 77, 81, 82, 83, 87, 87,
1365+ }, {
1366+ 32, 31, 31, 31, 30, 30, 31, 33, 33, 34, 37, 37, 39, 42, 42, 45, 49, 49, 48, 48, 48, 49, 49, 49, 50, 50, 51, 52, 52, 53, 54, 54,
1367+ 31, 31, 31, 31, 32, 32, 33, 35, 36, 37, 40, 40, 41, 43, 43, 44, 46, 46, 46, 46, 46, 45, 45, 45, 46, 46, 47, 48, 48, 48, 50, 50,
1368+ 35, 36, 37, 37, 38, 38, 38, 41, 41, 42, 45, 45, 46, 46, 46, 47, 48, 48, 47, 46, 46, 46, 45, 46, 46, 46, 47, 47, 47, 48, 49, 49,
1369+ 38, 39, 40, 40, 40, 41, 41, 43, 44, 45, 47, 47, 47, 48, 48, 48, 49, 49, 48, 48, 48, 47, 47, 47, 48, 48, 48, 48, 48, 49, 50, 50,
1370+ 48, 47, 47, 47, 46, 46, 46, 47, 47, 47, 47, 47, 48, 50, 50, 51, 53, 53, 53, 53, 53, 53, 53, 53, 54, 54, 54, 54, 54, 54, 55, 55,
1371+ 49, 48, 47, 47, 45, 45, 45, 45, 46, 45, 45, 45, 47, 49, 49, 51, 53, 53, 55, 56, 56, 57, 58, 58, 59, 59, 60, 61, 61, 61, 62, 62,
1372+ 50, 49, 48, 48, 46, 46, 46, 46, 46, 46, 46, 46, 47, 50, 50, 52, 54, 54, 55, 56, 56, 58, 59, 60, 61, 61, 61, 63, 63, 63, 65, 65,
1373+ 52, 50, 50, 50, 48, 48, 48, 47, 47, 47, 47, 47, 48, 50, 50, 52, 54, 54, 56, 57, 57, 60, 61, 61, 63, 64, 64, 66, 66, 67, 68, 68,
1374+ },
1375+ }, {
1376+ {
1377+ 32, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 34, 34, 34, 35, 36, 36, 38, 39, 39, 41, 44, 44, 44, 47, 48, 48, 51,
1378+ 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 34, 34, 34, 34, 34, 34, 36, 37, 37, 39, 41, 41, 42, 44, 45, 45, 47,
1379+ 31, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 33, 34, 34, 34, 35, 35, 35, 36, 36, 36, 37, 39, 39, 40, 42, 42, 42, 44, 45, 45, 48,
1380+ 32, 32, 32, 32, 32, 33, 33, 33, 34, 34, 34, 35, 35, 35, 36, 37, 37, 37, 38, 38, 38, 40, 40, 40, 41, 43, 43, 43, 45, 46, 46, 48,
1381+ 35, 35, 35, 35, 34, 34, 34, 34, 35, 36, 36, 37, 37, 37, 39, 41, 41, 42, 45, 46, 46, 47, 48, 48, 49, 51, 51, 51, 53, 54, 54, 56,
1382+ 36, 35, 35, 35, 35, 34, 34, 35, 36, 36, 36, 37, 38, 38, 40, 42, 42, 43, 47, 48, 48, 49, 50, 50, 51, 53, 53, 54, 56, 56, 56, 58,
1383+ 44, 43, 42, 42, 41, 41, 41, 41, 42, 42, 42, 42, 42, 42, 44, 48, 48, 49, 52, 54, 54, 56, 58, 58, 60, 63, 63, 64, 66, 67, 67, 69,
1384+ 47, 46, 45, 45, 45, 44, 44, 44, 44, 45, 45, 45, 45, 45, 47, 50, 50, 51, 55, 56, 56, 58, 60, 60, 62, 66, 66, 67, 69, 70, 70, 73,
1385+ }, {
1386+ 32, 31, 31, 31, 31, 30, 30, 31, 33, 33, 33, 35, 37, 37, 39, 42, 42, 43, 47, 49, 49, 48, 48, 48, 48, 49, 49, 49, 50, 50, 50, 51,
1387+ 31, 31, 31, 31, 32, 32, 32, 33, 35, 36, 36, 38, 40, 40, 41, 43, 43, 43, 46, 46, 46, 46, 46, 46, 45, 45, 45, 45, 46, 46, 46, 47,
1388+ 33, 33, 34, 34, 34, 35, 35, 35, 37, 38, 38, 41, 43, 43, 43, 44, 44, 45, 46, 47, 47, 46, 46, 46, 46, 45, 45, 45, 46, 46, 46, 47,
1389+ 37, 38, 38, 38, 39, 40, 40, 40, 42, 43, 43, 45, 47, 47, 47, 47, 47, 47, 48, 48, 48, 47, 47, 47, 46, 46, 46, 46, 46, 46, 46, 47,
1390+ 45, 45, 45, 45, 45, 44, 44, 45, 46, 46, 46, 47, 47, 47, 48, 49, 49, 50, 51, 52, 52, 52, 51, 51, 51, 51, 51, 52, 52, 52, 52, 52,
1391+ 48, 47, 47, 47, 46, 46, 46, 46, 47, 47, 47, 47, 47, 47, 48, 50, 50, 50, 52, 53, 53, 53, 53, 53, 53, 53, 53, 53, 54, 54, 54, 54,
1392+ 49, 48, 47, 47, 46, 45, 45, 45, 45, 46, 46, 45, 45, 45, 47, 49, 49, 50, 53, 53, 53, 55, 56, 56, 57, 58, 58, 58, 59, 59, 59, 60,
1393+ 50, 49, 48, 48, 47, 46, 46, 46, 46, 46, 46, 46, 46, 46, 47, 50, 50, 50, 53, 54, 54, 55, 56, 56, 57, 59, 59, 60, 61, 61, 61, 62,
1394+ },
1395+ }, {
1396+ {
1397+ 32, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 33, 34, 34, 34, 35, 36, 36, 36, 37, 39, 39, 39, 41, 44, 44,
1398+ 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 33, 34, 34, 34, 34, 34, 34, 34, 36, 37, 37, 37, 39, 41, 41,
1399+ 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 33, 34, 34, 34, 34, 34, 34, 34, 36, 37, 37, 37, 39, 41, 41,
1400+ 32, 32, 32, 32, 32, 32, 33, 33, 33, 33, 34, 34, 34, 34, 35, 35, 35, 36, 37, 37, 37, 37, 38, 38, 38, 39, 40, 40, 40, 42, 43, 43,
1401+ 32, 32, 32, 32, 32, 32, 33, 33, 33, 33, 34, 34, 34, 34, 35, 35, 35, 36, 37, 37, 37, 37, 38, 38, 38, 39, 40, 40, 40, 42, 43, 43,
1402+ 36, 35, 35, 35, 35, 35, 34, 34, 34, 35, 36, 36, 36, 37, 38, 38, 38, 40, 42, 42, 42, 45, 48, 48, 48, 49, 50, 50, 50, 52, 53, 53,
1403+ 36, 35, 35, 35, 35, 35, 34, 34, 34, 35, 36, 36, 36, 37, 38, 38, 38, 40, 42, 42, 42, 45, 48, 48, 48, 49, 50, 50, 50, 52, 53, 53,
1404+ 44, 43, 42, 42, 42, 41, 41, 41, 41, 41, 42, 42, 42, 42, 42, 42, 42, 45, 48, 48, 48, 50, 54, 54, 54, 56, 58, 58, 58, 60, 63, 63,
1405+ }, {
1406+ 32, 31, 31, 31, 31, 31, 30, 30, 30, 32, 33, 33, 33, 35, 37, 37, 37, 39, 42, 42, 42, 45, 49, 49, 49, 48, 48, 48, 48, 48, 49, 49,
1407+ 31, 31, 31, 31, 31, 32, 32, 32, 32, 34, 36, 36, 36, 38, 40, 40, 40, 41, 43, 43, 43, 44, 46, 46, 46, 46, 46, 46, 46, 45, 45, 45,
1408+ 31, 31, 31, 31, 31, 32, 32, 32, 32, 34, 36, 36, 36, 38, 40, 40, 40, 41, 43, 43, 43, 44, 46, 46, 46, 46, 46, 46, 46, 45, 45, 45,
1409+ 37, 37, 38, 38, 38, 39, 40, 40, 40, 41, 43, 43, 43, 45, 47, 47, 47, 47, 47, 47, 47, 47, 48, 48, 48, 47, 47, 47, 47, 46, 46, 46,
1410+ 37, 37, 38, 38, 38, 39, 40, 40, 40, 41, 43, 43, 43, 45, 47, 47, 47, 47, 47, 47, 47, 47, 48, 48, 48, 47, 47, 47, 47, 46, 46, 46,
1411+ 48, 47, 47, 47, 47, 46, 46, 46, 46, 46, 47, 47, 47, 47, 47, 47, 47, 49, 50, 50, 50, 51, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53,
1412+ 48, 47, 47, 47, 47, 46, 46, 46, 46, 46, 47, 47, 47, 47, 47, 47, 47, 49, 50, 50, 50, 51, 53, 53, 53, 53, 53, 53, 53, 53, 53, 53,
1413+ 49, 48, 47, 47, 47, 46, 45, 45, 45, 45, 46, 46, 46, 45, 45, 45, 45, 47, 49, 49, 49, 51, 53, 53, 53, 54, 56, 56, 56, 57, 58, 58,
1414+ },
1415+ }, {
1416+ {
1417+ 32, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 34, 34, 34, 34, 35, 36, 36, 36, 37,
1418+ 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 34, 34, 34, 34, 34, 35, 35, 35, 36,
1419+ 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 33, 33, 33, 34, 34, 34, 34, 34, 34, 34, 34, 36,
1420+ 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 33, 33, 33, 33, 34, 34, 34, 34, 35, 35, 35, 35, 35, 36, 36, 36, 36, 37,
1421+ 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 33, 34, 34, 34, 34, 34, 35, 35, 35, 35, 36, 36, 37, 37, 37, 37, 38, 38, 38, 38, 39,
1422+ 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 33, 34, 34, 34, 34, 34, 35, 35, 35, 35, 36, 36, 37, 37, 37, 37, 38, 38, 38, 38, 39,
1423+ 35, 35, 35, 35, 35, 35, 34, 34, 34, 34, 34, 35, 35, 36, 36, 36, 36, 37, 37, 37, 37, 39, 40, 41, 41, 41, 43, 45, 46, 46, 46, 46,
1424+ 36, 35, 35, 35, 35, 35, 35, 35, 34, 34, 34, 35, 36, 36, 36, 36, 37, 38, 38, 38, 38, 40, 41, 42, 42, 42, 44, 47, 48, 48, 48, 49,
1425+ }, {
1426+ 32, 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 31, 33, 33, 33, 33, 35, 36, 37, 37, 37, 39, 41, 42, 42, 42, 44, 47, 49, 49, 49, 49,
1427+ 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 33, 34, 35, 35, 35, 37, 38, 39, 39, 39, 40, 42, 42, 42, 42, 44, 46, 47, 47, 47, 47,
1428+ 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 33, 35, 36, 36, 36, 37, 39, 40, 40, 40, 41, 42, 43, 43, 43, 44, 46, 46, 46, 46, 46,
1429+ 33, 33, 34, 34, 34, 34, 34, 34, 35, 35, 35, 36, 37, 38, 38, 38, 40, 42, 43, 43, 43, 43, 44, 44, 44, 44, 45, 46, 47, 47, 47, 47,
1430+ 37, 37, 38, 38, 38, 38, 39, 39, 40, 40, 40, 41, 42, 43, 43, 43, 44, 46, 47, 47, 47, 47, 47, 47, 47, 47, 47, 48, 48, 48, 48, 47,
1431+ 37, 37, 38, 38, 38, 38, 39, 39, 40, 40, 40, 41, 42, 43, 43, 43, 44, 46, 47, 47, 47, 47, 47, 47, 47, 47, 47, 48, 48, 48, 48, 47,
1432+ 45, 45, 45, 45, 45, 45, 45, 44, 44, 44, 44, 45, 46, 46, 46, 46, 46, 47, 47, 47, 47, 48, 49, 49, 49, 49, 50, 51, 52, 52, 52, 52,
1433+ 48, 48, 47, 47, 47, 47, 46, 46, 46, 46, 46, 46, 47, 47, 47, 47, 47, 47, 47, 47, 47, 48, 49, 50, 50, 50, 51, 52, 53, 53, 53, 53,
1434+ },
1435+ }, {
1436+ {
1437+ 32, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 34, 34,
1438+ 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 34, 34,
1439+ 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 33, 33, 33, 33, 34, 34,
1440+ 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 33, 33, 33, 33, 34, 34,
1441+ 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 33, 33, 33, 33, 33, 33, 34, 34, 34, 34, 34, 34, 35, 35,
1442+ 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 33, 33, 33, 34, 34, 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, 36, 36, 37, 37,
1443+ 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 33, 33, 33, 34, 34, 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, 36, 36, 37, 37,
1444+ 32, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 34, 34, 34, 34, 34, 34, 35, 35, 36, 36, 36, 36, 36, 36, 37, 38, 38,
1445+ }, {
1446+ 32, 31, 31, 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 31, 32, 33, 33, 33, 33, 33, 34, 35, 36, 37, 37, 37, 37, 39, 40, 42, 42,
1447+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 33, 34, 35, 35, 35, 35, 36, 37, 38, 39, 39, 39, 39, 40, 41, 42, 42,
1448+ 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 33, 34, 35, 36, 36, 36, 36, 37, 38, 39, 40, 40, 40, 40, 41, 42, 43, 43,
1449+ 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 33, 34, 35, 36, 36, 36, 36, 37, 38, 39, 40, 40, 40, 40, 41, 42, 43, 43,
1450+ 33, 33, 33, 34, 34, 34, 34, 34, 34, 34, 35, 35, 35, 35, 35, 36, 37, 38, 38, 38, 38, 39, 41, 42, 43, 43, 43, 43, 43, 44, 44, 44,
1451+ 37, 37, 38, 38, 38, 38, 38, 38, 39, 39, 40, 40, 40, 40, 40, 41, 42, 43, 43, 43, 43, 44, 45, 47, 47, 47, 47, 47, 47, 47, 47, 47,
1452+ 37, 37, 38, 38, 38, 38, 38, 38, 39, 39, 40, 40, 40, 40, 40, 41, 42, 43, 43, 43, 43, 44, 45, 47, 47, 47, 47, 47, 47, 47, 47, 47,
1453+ 38, 39, 39, 40, 40, 40, 40, 40, 40, 40, 41, 41, 41, 41, 41, 42, 43, 44, 44, 44, 44, 45, 46, 47, 47, 47, 47, 47, 47, 47, 48, 48,
1454+ },
1455+ }, {
1456+ {
1457+ 32, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32,
1458+ 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1459+ 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1460+ 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1461+ 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1462+ 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1463+ 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
1464+ 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 33, 33, 34, 34, 34, 34, 34, 34, 34,
1465+ }, {
1466+ 32, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30, 30, 30, 31, 31, 32, 33, 33, 33, 33, 33, 33, 33, 34,
1467+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 33, 34, 34, 34, 34, 34, 34, 34, 35,
1468+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 33, 34, 34, 35, 35, 35, 35, 35, 35, 36,
1469+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 34, 35, 36, 36, 36, 36, 36, 36, 36,
1470+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 34, 35, 36, 36, 36, 36, 36, 36, 36,
1471+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 33, 33, 34, 35, 36, 36, 36, 36, 36, 36, 36,
1472+ 33, 33, 33, 33, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, 35, 36, 37, 37, 38, 38, 38, 38, 38, 38, 39,
1473+ 35, 35, 36, 36, 36, 37, 37, 37, 37, 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, 38, 38, 38, 39, 40, 40, 41, 41, 41, 41, 41, 41, 42,
1474+ },
1475+ }, {
1476+ {
1477+ 32, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
1478+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
1479+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1480+ 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1481+ 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1482+ 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1483+ 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1484+ 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1485+ }, {
1486+ 32, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 30, 30, 30, 30, 30,
1487+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
1488+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
1489+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31,
1490+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32,
1491+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1492+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1493+ 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32, 32,
1494+ },
1495+ },
1496+};
1497+
1498+static const uint8_t qm_tbl_32x16[][2][512] = {
1499+ {
1500+ {
1501+ 32, 31, 31, 31, 32, 32, 34, 35, 36, 39, 44, 46, 48, 53, 58, 61, 65, 71, 79, 81, 82, 88, 91, 94, 97, 100, 103, 107, 110, 114, 118, 122,
1502+ 31, 32, 32, 32, 32, 33, 34, 34, 34, 37, 41, 43, 45, 49, 54, 57, 60, 65, 72, 74, 75, 80, 83, 85, 88, 91, 94, 97, 101, 104, 108, 111,
1503+ 32, 32, 33, 33, 34, 35, 37, 37, 38, 40, 43, 44, 46, 50, 54, 56, 58, 63, 70, 71, 72, 77, 80, 83, 86, 89, 93, 96, 100, 104, 107, 111,
1504+ 34, 34, 33, 34, 35, 37, 39, 41, 43, 45, 48, 49, 51, 54, 58, 60, 63, 68, 74, 75, 76, 80, 81, 82, 85, 87, 90, 93, 97, 100, 103, 107,
1505+ 36, 35, 34, 35, 36, 38, 42, 45, 48, 50, 53, 55, 56, 60, 63, 66, 68, 73, 79, 80, 81, 85, 88, 91, 94, 97, 98, 100, 101, 103, 105, 107,
1506+ 44, 42, 41, 41, 42, 42, 48, 50, 54, 58, 63, 65, 67, 71, 75, 77, 79, 84, 90, 91, 92, 97, 100, 100, 100, 100, 101, 104, 108, 112, 115, 119,
1507+ 53, 51, 49, 49, 50, 49, 54, 57, 60, 65, 71, 73, 76, 82, 87, 89, 92, 97, 104, 105, 106, 108, 106, 105, 107, 111, 114, 117, 117, 117, 118, 119,
1508+ 59, 56, 54, 54, 54, 53, 58, 61, 64, 69, 75, 78, 80, 87, 92, 95, 98, 103, 110, 112, 113, 115, 114, 118, 123, 121, 120, 119, 123, 127, 131, 136,
1509+ 65, 62, 59, 59, 59, 58, 63, 65, 68, 73, 79, 82, 85, 92, 98, 101, 105, 111, 118, 119, 121, 126, 130, 131, 128, 127, 131, 136, 138, 137, 136, 136,
1510+ 79, 75, 72, 71, 71, 69, 73, 76, 78, 84, 90, 93, 96, 103, 110, 114, 118, 125, 133, 135, 136, 142, 142, 137, 140, 145, 144, 142, 141, 146, 151, 156,
1511+ 87, 82, 78, 78, 77, 75, 79, 82, 84, 89, 95, 98, 102, 109, 116, 120, 124, 132, 141, 142, 144, 149, 148, 153, 157, 152, 150, 155, 161, 159, 157, 156,
1512+ 90, 85, 82, 81, 80, 78, 78, 83, 87, 89, 93, 100, 102, 107, 115, 118, 123, 132, 136, 140, 151, 153, 155, 160, 161, 164, 170, 168, 165, 167, 172, 178,
1513+ 93, 88, 86, 84, 82, 82, 80, 84, 86, 91, 94, 98, 105, 107, 112, 119, 122, 130, 135, 140, 149, 153, 162, 165, 167, 173, 174, 177, 183, 185, 182, 179,
1514+ 96, 91, 90, 87, 86, 86, 83, 84, 89, 91, 95, 100, 102, 110, 111, 118, 123, 128, 135, 138, 149, 152, 160, 167, 173, 178, 180, 187, 188, 190, 197, 203,
1515+ 99, 94, 93, 90, 89, 89, 88, 87, 90, 93, 97, 99, 105, 107, 115, 116, 124, 127, 135, 139, 146, 152, 159, 166, 171, 182, 186, 191, 193, 201, 203, 204,
1516+ 102, 97, 97, 93, 93, 92, 92, 90, 90, 96, 97, 103, 104, 111, 112, 120, 121, 130, 131, 142, 143, 154, 155, 168, 169, 181, 183, 198, 200, 206, 208, 217,
1517+ }, {
1518+ 32, 31, 30, 32, 33, 37, 42, 45, 49, 48, 49, 49, 50, 52, 54, 55, 57, 60, 63, 64, 64, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77,
1519+ 31, 31, 32, 34, 36, 40, 43, 44, 46, 46, 45, 46, 46, 48, 50, 51, 52, 54, 57, 58, 59, 61, 62, 62, 63, 64, 65, 66, 67, 68, 69, 70,
1520+ 37, 38, 40, 41, 43, 47, 47, 47, 48, 47, 46, 46, 46, 47, 49, 49, 50, 52, 55, 55, 56, 58, 59, 60, 62, 63, 64, 65, 67, 68, 69, 70,
1521+ 42, 42, 42, 44, 45, 47, 48, 49, 50, 50, 49, 49, 50, 50, 52, 52, 53, 55, 58, 58, 58, 60, 60, 60, 60, 61, 62, 63, 64, 65, 66, 67,
1522+ 48, 47, 46, 46, 47, 47, 50, 51, 53, 53, 53, 53, 54, 54, 55, 56, 56, 58, 60, 61, 61, 63, 64, 65, 66, 67, 66, 66, 66, 66, 67, 67,
1523+ 49, 47, 45, 45, 46, 45, 49, 51, 53, 56, 58, 59, 59, 61, 62, 63, 64, 65, 67, 68, 68, 69, 71, 70, 69, 68, 68, 69, 70, 71, 72, 73,

1629 more lines aren’t shown here.

src/qm.h+37−0

This diff is large: its 38 lines aren’t shown here.

src/recon.c+1503−0

This diff is large: its 1504 lines aren’t shown here.

src/recon.h+75−0

This diff is large: its 76 lines aren’t shown here.

src/ref.c+60−0

This diff is large: its 61 lines aren’t shown here.

src/ref.h+46−0

This diff is large: its 47 lines aren’t shown here.

src/ref_mvs.c+3550−0

This diff is large: its 3551 lines aren’t shown here.

src/ref_mvs.h+185−0

This diff is large: its 186 lines aren’t shown here.

src/scan.c+527−0

This diff is large: its 528 lines aren’t shown here.

src/scan.h+37−0

This diff is large: its 38 lines aren’t shown here.

src/tables.c+756−0

This diff is large: its 757 lines aren’t shown here.

src/tables.h+84−0

This diff is large: its 85 lines aren’t shown here.

src/thread_data.h+37−0

This diff is large: its 38 lines aren’t shown here.

src/thread_task.c+137−0

This diff is large: its 138 lines aren’t shown here.

src/thread_task.h+39−0

This diff is large: its 40 lines aren’t shown here.

src/warpmv.c+194−0

This diff is large: its 195 lines aren’t shown here.

src/warpmv.h+37−0

This diff is large: its 38 lines aren’t shown here.

src/wedge.c+334−0

This diff is large: its 335 lines aren’t shown here.

src/wedge.h+41−0

This diff is large: its 42 lines aren’t shown here.

tools/dav1d.c+173−0

This diff is large: its 174 lines aren’t shown here.

tools/dav1d_cli_parse.c+160−0

This diff is large: its 161 lines aren’t shown here.

tools/dav1d_cli_parse.h+44−0

This diff is large: its 45 lines aren’t shown here.

tools/input/demuxer.h+44−0

This diff is large: its 45 lines aren’t shown here.

tools/input/input.c+124−0

This diff is large: its 125 lines aren’t shown here.

tools/input/input.h+41−0

This diff is large: its 42 lines aren’t shown here.

tools/input/ivf.c+113−0

This diff is large: its 114 lines aren’t shown here.

tools/output/md5.c+220−0

This diff is large: its 221 lines aren’t shown here.

tools/output/muxer.h+44−0

This diff is large: its 45 lines aren’t shown here.

tools/output/output.c+141−0

This diff is large: its 142 lines aren’t shown here.

tools/output/output.h+41−0

This diff is large: its 42 lines aren’t shown here.

tools/output/y4m2.c+114−0

This diff is large: its 115 lines aren’t shown here.

tools/output/yuv.c+104−0

This diff is large: its 105 lines aren’t shown here.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t