Line data Source code
1 : /*
2 : * Copyright (c) 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 <math.h>
13 :
14 : #include "./av1_rtcd.h"
15 : #include "./aom_config.h"
16 : #include "./aom_dsp_rtcd.h"
17 : #include "aom_ports/system_state.h"
18 :
19 : #if CONFIG_HIGHBITDEPTH
20 : #include "aom_dsp/aom_dsp_common.h"
21 : #endif // CONFIG_HIGHBITDEPTH
22 : #include "aom_mem/aom_mem.h"
23 : #include "aom_ports/mem.h"
24 : #include "aom_ports/aom_once.h"
25 : #include "av1/common/reconintra.h"
26 : #include "av1/common/onyxc_int.h"
27 : #if CONFIG_CFL
28 : #include "av1/common/cfl.h"
29 : #endif
30 :
31 : enum {
32 : NEED_LEFT = 1 << 1,
33 : NEED_ABOVE = 1 << 2,
34 : NEED_ABOVERIGHT = 1 << 3,
35 : NEED_ABOVELEFT = 1 << 4,
36 : NEED_BOTTOMLEFT = 1 << 5,
37 : };
38 :
39 : static const uint8_t extend_modes[INTRA_MODES] = {
40 : NEED_ABOVE | NEED_LEFT, // DC
41 : NEED_ABOVE, // V
42 : NEED_LEFT, // H
43 : NEED_ABOVE | NEED_ABOVERIGHT, // D45
44 : NEED_LEFT | NEED_ABOVE | NEED_ABOVELEFT, // D135
45 : NEED_LEFT | NEED_ABOVE | NEED_ABOVELEFT, // D117
46 : NEED_LEFT | NEED_ABOVE | NEED_ABOVELEFT, // D153
47 : NEED_LEFT | NEED_BOTTOMLEFT, // D207
48 : NEED_ABOVE | NEED_ABOVERIGHT, // D63
49 : #if CONFIG_ALT_INTRA
50 : NEED_LEFT | NEED_ABOVE, // SMOOTH
51 : #if CONFIG_SMOOTH_HV
52 : NEED_LEFT | NEED_ABOVE, // SMOOTH_V
53 : NEED_LEFT | NEED_ABOVE, // SMOOTH_H
54 : #endif // CONFIG_SMOOTH_HV
55 : #endif // CONFIG_ALT_INTRA
56 : NEED_LEFT | NEED_ABOVE | NEED_ABOVELEFT, // TM
57 : };
58 :
59 : static const uint16_t orders_128x128[1] = { 0 };
60 : static const uint16_t orders_128x64[2] = { 0, 1 };
61 : static const uint16_t orders_64x128[2] = { 0, 1 };
62 : static const uint16_t orders_64x64[4] = {
63 : 0, 1, 2, 3,
64 : };
65 : static const uint16_t orders_64x32[8] = {
66 : 0, 2, 1, 3, 4, 6, 5, 7,
67 : };
68 : static const uint16_t orders_32x64[8] = {
69 : 0, 1, 2, 3, 4, 5, 6, 7,
70 : };
71 : static const uint16_t orders_32x32[16] = {
72 : 0, 1, 4, 5, 2, 3, 6, 7, 8, 9, 12, 13, 10, 11, 14, 15,
73 : };
74 : static const uint16_t orders_32x16[32] = {
75 : 0, 2, 8, 10, 1, 3, 9, 11, 4, 6, 12, 14, 5, 7, 13, 15,
76 : 16, 18, 24, 26, 17, 19, 25, 27, 20, 22, 28, 30, 21, 23, 29, 31,
77 : };
78 : static const uint16_t orders_16x32[32] = {
79 : 0, 1, 2, 3, 8, 9, 10, 11, 4, 5, 6, 7, 12, 13, 14, 15,
80 : 16, 17, 18, 19, 24, 25, 26, 27, 20, 21, 22, 23, 28, 29, 30, 31,
81 : };
82 : static const uint16_t orders_16x16[64] = {
83 : 0, 1, 4, 5, 16, 17, 20, 21, 2, 3, 6, 7, 18, 19, 22, 23,
84 : 8, 9, 12, 13, 24, 25, 28, 29, 10, 11, 14, 15, 26, 27, 30, 31,
85 : 32, 33, 36, 37, 48, 49, 52, 53, 34, 35, 38, 39, 50, 51, 54, 55,
86 : 40, 41, 44, 45, 56, 57, 60, 61, 42, 43, 46, 47, 58, 59, 62, 63,
87 : };
88 :
89 : #if CONFIG_CB4X4 || CONFIG_EXT_PARTITION
90 : static const uint16_t orders_16x8[128] = {
91 : 0, 2, 8, 10, 32, 34, 40, 42, 1, 3, 9, 11, 33, 35, 41, 43,
92 : 4, 6, 12, 14, 36, 38, 44, 46, 5, 7, 13, 15, 37, 39, 45, 47,
93 : 16, 18, 24, 26, 48, 50, 56, 58, 17, 19, 25, 27, 49, 51, 57, 59,
94 : 20, 22, 28, 30, 52, 54, 60, 62, 21, 23, 29, 31, 53, 55, 61, 63,
95 : 64, 66, 72, 74, 96, 98, 104, 106, 65, 67, 73, 75, 97, 99, 105, 107,
96 : 68, 70, 76, 78, 100, 102, 108, 110, 69, 71, 77, 79, 101, 103, 109, 111,
97 : 80, 82, 88, 90, 112, 114, 120, 122, 81, 83, 89, 91, 113, 115, 121, 123,
98 : 84, 86, 92, 94, 116, 118, 124, 126, 85, 87, 93, 95, 117, 119, 125, 127,
99 : };
100 : static const uint16_t orders_8x16[128] = {
101 : 0, 1, 2, 3, 8, 9, 10, 11, 32, 33, 34, 35, 40, 41, 42, 43,
102 : 4, 5, 6, 7, 12, 13, 14, 15, 36, 37, 38, 39, 44, 45, 46, 47,
103 : 16, 17, 18, 19, 24, 25, 26, 27, 48, 49, 50, 51, 56, 57, 58, 59,
104 : 20, 21, 22, 23, 28, 29, 30, 31, 52, 53, 54, 55, 60, 61, 62, 63,
105 : 64, 65, 66, 67, 72, 73, 74, 75, 96, 97, 98, 99, 104, 105, 106, 107,
106 : 68, 69, 70, 71, 76, 77, 78, 79, 100, 101, 102, 103, 108, 109, 110, 111,
107 : 80, 81, 82, 83, 88, 89, 90, 91, 112, 113, 114, 115, 120, 121, 122, 123,
108 : 84, 85, 86, 87, 92, 93, 94, 95, 116, 117, 118, 119, 124, 125, 126, 127,
109 : };
110 : static const uint16_t orders_8x8[256] = {
111 : 0, 1, 4, 5, 16, 17, 20, 21, 64, 65, 68, 69, 80, 81, 84,
112 : 85, 2, 3, 6, 7, 18, 19, 22, 23, 66, 67, 70, 71, 82, 83,
113 : 86, 87, 8, 9, 12, 13, 24, 25, 28, 29, 72, 73, 76, 77, 88,
114 : 89, 92, 93, 10, 11, 14, 15, 26, 27, 30, 31, 74, 75, 78, 79,
115 : 90, 91, 94, 95, 32, 33, 36, 37, 48, 49, 52, 53, 96, 97, 100,
116 : 101, 112, 113, 116, 117, 34, 35, 38, 39, 50, 51, 54, 55, 98, 99,
117 : 102, 103, 114, 115, 118, 119, 40, 41, 44, 45, 56, 57, 60, 61, 104,
118 : 105, 108, 109, 120, 121, 124, 125, 42, 43, 46, 47, 58, 59, 62, 63,
119 : 106, 107, 110, 111, 122, 123, 126, 127, 128, 129, 132, 133, 144, 145, 148,
120 : 149, 192, 193, 196, 197, 208, 209, 212, 213, 130, 131, 134, 135, 146, 147,
121 : 150, 151, 194, 195, 198, 199, 210, 211, 214, 215, 136, 137, 140, 141, 152,
122 : 153, 156, 157, 200, 201, 204, 205, 216, 217, 220, 221, 138, 139, 142, 143,
123 : 154, 155, 158, 159, 202, 203, 206, 207, 218, 219, 222, 223, 160, 161, 164,
124 : 165, 176, 177, 180, 181, 224, 225, 228, 229, 240, 241, 244, 245, 162, 163,
125 : 166, 167, 178, 179, 182, 183, 226, 227, 230, 231, 242, 243, 246, 247, 168,
126 : 169, 172, 173, 184, 185, 188, 189, 232, 233, 236, 237, 248, 249, 252, 253,
127 : 170, 171, 174, 175, 186, 187, 190, 191, 234, 235, 238, 239, 250, 251, 254,
128 : 255,
129 : };
130 :
131 : #if CONFIG_CB4X4 && CONFIG_EXT_PARTITION
132 : static const uint16_t orders_4x8[512] = {
133 : 0, 1, 2, 3, 8, 9, 10, 11, 32, 33, 34, 35, 40, 41, 42,
134 : 43, 128, 129, 130, 131, 136, 137, 138, 139, 160, 161, 162, 163, 168, 169,
135 : 170, 171, 4, 5, 6, 7, 12, 13, 14, 15, 36, 37, 38, 39, 44,
136 : 45, 46, 47, 132, 133, 134, 135, 140, 141, 142, 143, 164, 165, 166, 167,
137 : 172, 173, 174, 175, 16, 17, 18, 19, 24, 25, 26, 27, 48, 49, 50,
138 : 51, 56, 57, 58, 59, 144, 145, 146, 147, 152, 153, 154, 155, 176, 177,
139 : 178, 179, 184, 185, 186, 187, 20, 21, 22, 23, 28, 29, 30, 31, 52,
140 : 53, 54, 55, 60, 61, 62, 63, 148, 149, 150, 151, 156, 157, 158, 159,
141 : 180, 181, 182, 183, 188, 189, 190, 191, 64, 65, 66, 67, 72, 73, 74,
142 : 75, 96, 97, 98, 99, 104, 105, 106, 107, 192, 193, 194, 195, 200, 201,
143 : 202, 203, 224, 225, 226, 227, 232, 233, 234, 235, 68, 69, 70, 71, 76,
144 : 77, 78, 79, 100, 101, 102, 103, 108, 109, 110, 111, 196, 197, 198, 199,
145 : 204, 205, 206, 207, 228, 229, 230, 231, 236, 237, 238, 239, 80, 81, 82,
146 : 83, 88, 89, 90, 91, 112, 113, 114, 115, 120, 121, 122, 123, 208, 209,
147 : 210, 211, 216, 217, 218, 219, 240, 241, 242, 243, 248, 249, 250, 251, 84,
148 : 85, 86, 87, 92, 93, 94, 95, 116, 117, 118, 119, 124, 125, 126, 127,
149 : 212, 213, 214, 215, 220, 221, 222, 223, 244, 245, 246, 247, 252, 253, 254,
150 : 255, 256, 257, 258, 259, 264, 265, 266, 267, 288, 289, 290, 291, 296, 297,
151 : 298, 299, 384, 385, 386, 387, 392, 393, 394, 395, 416, 417, 418, 419, 424,
152 : 425, 426, 427, 260, 261, 262, 263, 268, 269, 270, 271, 292, 293, 294, 295,
153 : 300, 301, 302, 303, 388, 389, 390, 391, 396, 397, 398, 399, 420, 421, 422,
154 : 423, 428, 429, 430, 431, 272, 273, 274, 275, 280, 281, 282, 283, 304, 305,
155 : 306, 307, 312, 313, 314, 315, 400, 401, 402, 403, 408, 409, 410, 411, 432,
156 : 433, 434, 435, 440, 441, 442, 443, 276, 277, 278, 279, 284, 285, 286, 287,
157 : 308, 309, 310, 311, 316, 317, 318, 319, 404, 405, 406, 407, 412, 413, 414,
158 : 415, 436, 437, 438, 439, 444, 445, 446, 447, 320, 321, 322, 323, 328, 329,
159 : 330, 331, 352, 353, 354, 355, 360, 361, 362, 363, 448, 449, 450, 451, 456,
160 : 457, 458, 459, 480, 481, 482, 483, 488, 489, 490, 491, 324, 325, 326, 327,
161 : 332, 333, 334, 335, 356, 357, 358, 359, 364, 365, 366, 367, 452, 453, 454,
162 : 455, 460, 461, 462, 463, 484, 485, 486, 487, 492, 493, 494, 495, 336, 337,
163 : 338, 339, 344, 345, 346, 347, 368, 369, 370, 371, 376, 377, 378, 379, 464,
164 : 465, 466, 467, 472, 473, 474, 475, 496, 497, 498, 499, 504, 505, 506, 507,
165 : 340, 341, 342, 343, 348, 349, 350, 351, 372, 373, 374, 375, 380, 381, 382,
166 : 383, 468, 469, 470, 471, 476, 477, 478, 479, 500, 501, 502, 503, 508, 509,
167 : 510, 511,
168 : };
169 :
170 : static const uint16_t orders_8x4[512] = {
171 : 0, 2, 8, 10, 32, 34, 40, 42, 128, 130, 136, 138, 160, 162, 168,
172 : 170, 1, 3, 9, 11, 33, 35, 41, 43, 129, 131, 137, 139, 161, 163,
173 : 169, 171, 4, 6, 12, 14, 36, 38, 44, 46, 132, 134, 140, 142, 164,
174 : 166, 172, 174, 5, 7, 13, 15, 37, 39, 45, 47, 133, 135, 141, 143,
175 : 165, 167, 173, 175, 16, 18, 24, 26, 48, 50, 56, 58, 144, 146, 152,
176 : 154, 176, 178, 184, 186, 17, 19, 25, 27, 49, 51, 57, 59, 145, 147,
177 : 153, 155, 177, 179, 185, 187, 20, 22, 28, 30, 52, 54, 60, 62, 148,
178 : 150, 156, 158, 180, 182, 188, 190, 21, 23, 29, 31, 53, 55, 61, 63,
179 : 149, 151, 157, 159, 181, 183, 189, 191, 64, 66, 72, 74, 96, 98, 104,
180 : 106, 192, 194, 200, 202, 224, 226, 232, 234, 65, 67, 73, 75, 97, 99,
181 : 105, 107, 193, 195, 201, 203, 225, 227, 233, 235, 68, 70, 76, 78, 100,
182 : 102, 108, 110, 196, 198, 204, 206, 228, 230, 236, 238, 69, 71, 77, 79,
183 : 101, 103, 109, 111, 197, 199, 205, 207, 229, 231, 237, 239, 80, 82, 88,
184 : 90, 112, 114, 120, 122, 208, 210, 216, 218, 240, 242, 248, 250, 81, 83,
185 : 89, 91, 113, 115, 121, 123, 209, 211, 217, 219, 241, 243, 249, 251, 84,
186 : 86, 92, 94, 116, 118, 124, 126, 212, 214, 220, 222, 244, 246, 252, 254,
187 : 85, 87, 93, 95, 117, 119, 125, 127, 213, 215, 221, 223, 245, 247, 253,
188 : 255, 256, 258, 264, 266, 288, 290, 296, 298, 384, 386, 392, 394, 416, 418,
189 : 424, 426, 257, 259, 265, 267, 289, 291, 297, 299, 385, 387, 393, 395, 417,
190 : 419, 425, 427, 260, 262, 268, 270, 292, 294, 300, 302, 388, 390, 396, 398,
191 : 420, 422, 428, 430, 261, 263, 269, 271, 293, 295, 301, 303, 389, 391, 397,
192 : 399, 421, 423, 429, 431, 272, 274, 280, 282, 304, 306, 312, 314, 400, 402,
193 : 408, 410, 432, 434, 440, 442, 273, 275, 281, 283, 305, 307, 313, 315, 401,
194 : 403, 409, 411, 433, 435, 441, 443, 276, 278, 284, 286, 308, 310, 316, 318,
195 : 404, 406, 412, 414, 436, 438, 444, 446, 277, 279, 285, 287, 309, 311, 317,
196 : 319, 405, 407, 413, 415, 437, 439, 445, 447, 320, 322, 328, 330, 352, 354,
197 : 360, 362, 448, 450, 456, 458, 480, 482, 488, 490, 321, 323, 329, 331, 353,
198 : 355, 361, 363, 449, 451, 457, 459, 481, 483, 489, 491, 324, 326, 332, 334,
199 : 356, 358, 364, 366, 452, 454, 460, 462, 484, 486, 492, 494, 325, 327, 333,
200 : 335, 357, 359, 365, 367, 453, 455, 461, 463, 485, 487, 493, 495, 336, 338,
201 : 344, 346, 368, 370, 376, 378, 464, 466, 472, 474, 496, 498, 504, 506, 337,
202 : 339, 345, 347, 369, 371, 377, 379, 465, 467, 473, 475, 497, 499, 505, 507,
203 : 340, 342, 348, 350, 372, 374, 380, 382, 468, 470, 476, 478, 500, 502, 508,
204 : 510, 341, 343, 349, 351, 373, 375, 381, 383, 469, 471, 477, 479, 501, 503,
205 : 509, 511,
206 : };
207 :
208 : static const uint16_t orders_4x4[1024] = {
209 : 0, 1, 4, 5, 16, 17, 20, 21, 64, 65, 68, 69, 80,
210 : 81, 84, 85, 256, 257, 260, 261, 272, 273, 276, 277, 320, 321,
211 : 324, 325, 336, 337, 340, 341, 2, 3, 6, 7, 18, 19, 22,
212 : 23, 66, 67, 70, 71, 82, 83, 86, 87, 258, 259, 262, 263,
213 : 274, 275, 278, 279, 322, 323, 326, 327, 338, 339, 342, 343, 8,
214 : 9, 12, 13, 24, 25, 28, 29, 72, 73, 76, 77, 88, 89,
215 : 92, 93, 264, 265, 268, 269, 280, 281, 284, 285, 328, 329, 332,
216 : 333, 344, 345, 348, 349, 10, 11, 14, 15, 26, 27, 30, 31,
217 : 74, 75, 78, 79, 90, 91, 94, 95, 266, 267, 270, 271, 282,
218 : 283, 286, 287, 330, 331, 334, 335, 346, 347, 350, 351, 32, 33,
219 : 36, 37, 48, 49, 52, 53, 96, 97, 100, 101, 112, 113, 116,
220 : 117, 288, 289, 292, 293, 304, 305, 308, 309, 352, 353, 356, 357,
221 : 368, 369, 372, 373, 34, 35, 38, 39, 50, 51, 54, 55, 98,
222 : 99, 102, 103, 114, 115, 118, 119, 290, 291, 294, 295, 306, 307,
223 : 310, 311, 354, 355, 358, 359, 370, 371, 374, 375, 40, 41, 44,
224 : 45, 56, 57, 60, 61, 104, 105, 108, 109, 120, 121, 124, 125,
225 : 296, 297, 300, 301, 312, 313, 316, 317, 360, 361, 364, 365, 376,
226 : 377, 380, 381, 42, 43, 46, 47, 58, 59, 62, 63, 106, 107,
227 : 110, 111, 122, 123, 126, 127, 298, 299, 302, 303, 314, 315, 318,
228 : 319, 362, 363, 366, 367, 378, 379, 382, 383, 128, 129, 132, 133,
229 : 144, 145, 148, 149, 192, 193, 196, 197, 208, 209, 212, 213, 384,
230 : 385, 388, 389, 400, 401, 404, 405, 448, 449, 452, 453, 464, 465,
231 : 468, 469, 130, 131, 134, 135, 146, 147, 150, 151, 194, 195, 198,
232 : 199, 210, 211, 214, 215, 386, 387, 390, 391, 402, 403, 406, 407,
233 : 450, 451, 454, 455, 466, 467, 470, 471, 136, 137, 140, 141, 152,
234 : 153, 156, 157, 200, 201, 204, 205, 216, 217, 220, 221, 392, 393,
235 : 396, 397, 408, 409, 412, 413, 456, 457, 460, 461, 472, 473, 476,
236 : 477, 138, 139, 142, 143, 154, 155, 158, 159, 202, 203, 206, 207,
237 : 218, 219, 222, 223, 394, 395, 398, 399, 410, 411, 414, 415, 458,
238 : 459, 462, 463, 474, 475, 478, 479, 160, 161, 164, 165, 176, 177,
239 : 180, 181, 224, 225, 228, 229, 240, 241, 244, 245, 416, 417, 420,
240 : 421, 432, 433, 436, 437, 480, 481, 484, 485, 496, 497, 500, 501,
241 : 162, 163, 166, 167, 178, 179, 182, 183, 226, 227, 230, 231, 242,
242 : 243, 246, 247, 418, 419, 422, 423, 434, 435, 438, 439, 482, 483,
243 : 486, 487, 498, 499, 502, 503, 168, 169, 172, 173, 184, 185, 188,
244 : 189, 232, 233, 236, 237, 248, 249, 252, 253, 424, 425, 428, 429,
245 : 440, 441, 444, 445, 488, 489, 492, 493, 504, 505, 508, 509, 170,
246 : 171, 174, 175, 186, 187, 190, 191, 234, 235, 238, 239, 250, 251,
247 : 254, 255, 426, 427, 430, 431, 442, 443, 446, 447, 490, 491, 494,
248 : 495, 506, 507, 510, 511, 512, 513, 516, 517, 528, 529, 532, 533,
249 : 576, 577, 580, 581, 592, 593, 596, 597, 768, 769, 772, 773, 784,
250 : 785, 788, 789, 832, 833, 836, 837, 848, 849, 852, 853, 514, 515,
251 : 518, 519, 530, 531, 534, 535, 578, 579, 582, 583, 594, 595, 598,
252 : 599, 770, 771, 774, 775, 786, 787, 790, 791, 834, 835, 838, 839,
253 : 850, 851, 854, 855, 520, 521, 524, 525, 536, 537, 540, 541, 584,
254 : 585, 588, 589, 600, 601, 604, 605, 776, 777, 780, 781, 792, 793,
255 : 796, 797, 840, 841, 844, 845, 856, 857, 860, 861, 522, 523, 526,
256 : 527, 538, 539, 542, 543, 586, 587, 590, 591, 602, 603, 606, 607,
257 : 778, 779, 782, 783, 794, 795, 798, 799, 842, 843, 846, 847, 858,
258 : 859, 862, 863, 544, 545, 548, 549, 560, 561, 564, 565, 608, 609,
259 : 612, 613, 624, 625, 628, 629, 800, 801, 804, 805, 816, 817, 820,
260 : 821, 864, 865, 868, 869, 880, 881, 884, 885, 546, 547, 550, 551,
261 : 562, 563, 566, 567, 610, 611, 614, 615, 626, 627, 630, 631, 802,
262 : 803, 806, 807, 818, 819, 822, 823, 866, 867, 870, 871, 882, 883,
263 : 886, 887, 552, 553, 556, 557, 568, 569, 572, 573, 616, 617, 620,
264 : 621, 632, 633, 636, 637, 808, 809, 812, 813, 824, 825, 828, 829,
265 : 872, 873, 876, 877, 888, 889, 892, 893, 554, 555, 558, 559, 570,
266 : 571, 574, 575, 618, 619, 622, 623, 634, 635, 638, 639, 810, 811,
267 : 814, 815, 826, 827, 830, 831, 874, 875, 878, 879, 890, 891, 894,
268 : 895, 640, 641, 644, 645, 656, 657, 660, 661, 704, 705, 708, 709,
269 : 720, 721, 724, 725, 896, 897, 900, 901, 912, 913, 916, 917, 960,
270 : 961, 964, 965, 976, 977, 980, 981, 642, 643, 646, 647, 658, 659,
271 : 662, 663, 706, 707, 710, 711, 722, 723, 726, 727, 898, 899, 902,
272 : 903, 914, 915, 918, 919, 962, 963, 966, 967, 978, 979, 982, 983,
273 : 648, 649, 652, 653, 664, 665, 668, 669, 712, 713, 716, 717, 728,
274 : 729, 732, 733, 904, 905, 908, 909, 920, 921, 924, 925, 968, 969,
275 : 972, 973, 984, 985, 988, 989, 650, 651, 654, 655, 666, 667, 670,
276 : 671, 714, 715, 718, 719, 730, 731, 734, 735, 906, 907, 910, 911,
277 : 922, 923, 926, 927, 970, 971, 974, 975, 986, 987, 990, 991, 672,
278 : 673, 676, 677, 688, 689, 692, 693, 736, 737, 740, 741, 752, 753,
279 : 756, 757, 928, 929, 932, 933, 944, 945, 948, 949, 992, 993, 996,
280 : 997, 1008, 1009, 1012, 1013, 674, 675, 678, 679, 690, 691, 694, 695,
281 : 738, 739, 742, 743, 754, 755, 758, 759, 930, 931, 934, 935, 946,
282 : 947, 950, 951, 994, 995, 998, 999, 1010, 1011, 1014, 1015, 680, 681,
283 : 684, 685, 696, 697, 700, 701, 744, 745, 748, 749, 760, 761, 764,
284 : 765, 936, 937, 940, 941, 952, 953, 956, 957, 1000, 1001, 1004, 1005,
285 : 1016, 1017, 1020, 1021, 682, 683, 686, 687, 698, 699, 702, 703, 746,
286 : 747, 750, 751, 762, 763, 766, 767, 938, 939, 942, 943, 954, 955,
287 : 958, 959, 1002, 1003, 1006, 1007, 1018, 1019, 1022, 1023,
288 : };
289 : #endif
290 : #endif // CONFIG_CB4X4 || CONFIG_EXT_PARTITION
291 :
292 : #if CONFIG_EXT_PARTITION
293 : /* clang-format off */
294 : static const uint16_t *const orders[BLOCK_SIZES] = {
295 : #if CONFIG_CB4X4
296 : // 2X2, 2X4, 4X2
297 : orders_4x4, orders_4x4, orders_4x4,
298 : // 4X4
299 : orders_4x4,
300 : // 4X8, 8X4, 8X8
301 : orders_4x8, orders_8x4, orders_8x8,
302 : #else
303 : // 4X4
304 : orders_8x8,
305 : // 4X8, 8X4, 8X8
306 : orders_8x8, orders_8x8, orders_8x8,
307 : #endif
308 : // 8X16, 16X8, 16X16
309 : orders_8x16, orders_16x8, orders_16x16,
310 : // 16X32, 32X16, 32X32
311 : orders_16x32, orders_32x16, orders_32x32,
312 : // 32X64, 64X32, 64X64
313 : orders_32x64, orders_64x32, orders_64x64,
314 : // 64x128, 128x64, 128x128
315 : orders_64x128, orders_128x64, orders_128x128
316 : };
317 : /* clang-format on */
318 : #else
319 : /* clang-format off */
320 : static const uint16_t *const orders[BLOCK_SIZES] = {
321 : #if CONFIG_CB4X4
322 : // 2X2, 2X4, 4X2
323 : orders_8x8, orders_8x8, orders_8x8,
324 : // 4X4
325 : orders_8x8,
326 : // 4X8, 8X4, 8X8
327 : orders_8x16, orders_16x8, orders_16x16,
328 : #else
329 : // 4X4
330 : orders_16x16,
331 : // 4X8, 8X4, 8X8
332 : orders_16x16, orders_16x16, orders_16x16,
333 : #endif
334 : // 8X16, 16X8, 16X16
335 : orders_16x32, orders_32x16, orders_32x32,
336 : // 16X32, 32X16, 32X32
337 : orders_32x64, orders_64x32, orders_64x64,
338 : // 32X64, 64X32, 64X64
339 : orders_64x128, orders_128x64, orders_128x128
340 : };
341 : /* clang-format on */
342 : #endif // CONFIG_EXT_PARTITION
343 :
344 : #if CONFIG_EXT_PARTITION_TYPES
345 : static const uint16_t orders_verta_64x64[4] = {
346 : 0, 2, 1, 2,
347 : };
348 : static const uint16_t orders_verta_32x32[16] = {
349 : 0, 2, 4, 6, 1, 2, 5, 6, 8, 10, 12, 14, 9, 10, 13, 14,
350 : };
351 : static const uint16_t orders_verta_16x16[64] = {
352 : 0, 2, 4, 6, 16, 18, 20, 22, 1, 2, 5, 6, 17, 18, 21, 22,
353 : 8, 10, 12, 14, 24, 26, 28, 30, 9, 10, 13, 14, 25, 26, 29, 30,
354 : 32, 34, 36, 38, 48, 50, 52, 54, 33, 34, 37, 38, 49, 50, 53, 54,
355 : 40, 42, 44, 46, 56, 58, 60, 62, 41, 42, 45, 46, 57, 58, 61, 62,
356 : };
357 : #if CONFIG_EXT_PARTITION || CONFIG_CB4X4
358 : static const uint16_t orders_verta_8x8[256] = {
359 : 0, 2, 4, 6, 16, 18, 20, 22, 64, 66, 68, 70, 80, 82, 84,
360 : 86, 1, 2, 5, 6, 17, 18, 21, 22, 65, 66, 69, 70, 81, 82,
361 : 85, 86, 8, 10, 12, 14, 24, 26, 28, 30, 72, 74, 76, 78, 88,
362 : 90, 92, 94, 9, 10, 13, 14, 25, 26, 29, 30, 73, 74, 77, 78,
363 : 89, 90, 93, 94, 32, 34, 36, 38, 48, 50, 52, 54, 96, 98, 100,
364 : 102, 112, 114, 116, 118, 33, 34, 37, 38, 49, 50, 53, 54, 97, 98,
365 : 101, 102, 113, 114, 117, 118, 40, 42, 44, 46, 56, 58, 60, 62, 104,
366 : 106, 108, 110, 120, 122, 124, 126, 41, 42, 45, 46, 57, 58, 61, 62,
367 : 105, 106, 109, 110, 121, 122, 125, 126, 128, 130, 132, 134, 144, 146, 148,
368 : 150, 192, 194, 196, 198, 208, 210, 212, 214, 129, 130, 133, 134, 145, 146,
369 : 149, 150, 193, 194, 197, 198, 209, 210, 213, 214, 136, 138, 140, 142, 152,
370 : 154, 156, 158, 200, 202, 204, 206, 216, 218, 220, 222, 137, 138, 141, 142,
371 : 153, 154, 157, 158, 201, 202, 205, 206, 217, 218, 221, 222, 160, 162, 164,
372 : 166, 176, 178, 180, 182, 224, 226, 228, 230, 240, 242, 244, 246, 161, 162,
373 : 165, 166, 177, 178, 181, 182, 225, 226, 229, 230, 241, 242, 245, 246, 168,
374 : 170, 172, 174, 184, 186, 188, 190, 232, 234, 236, 238, 248, 250, 252, 254,
375 : 169, 170, 173, 174, 185, 186, 189, 190, 233, 234, 237, 238, 249, 250, 253,
376 : 254,
377 : };
378 : #endif // CONFIG_EXT_PARTITION || CONFIG_CB4X4
379 :
380 : #if CONFIG_EXT_PARTITION
381 : /* clang-format off */
382 : static const uint16_t *const orders_verta[BLOCK_SIZES] = {
383 : #if CONFIG_CB4X4
384 : // 2X2, 2X4, 4X2
385 : orders_4x4, orders_4x4, orders_4x4,
386 : #endif
387 : // 4X4
388 : orders_verta_8x8,
389 : // 4X8, 8X4, 8X8
390 : orders_verta_8x8, orders_verta_8x8, orders_verta_8x8,
391 : // 8X16, 16X8, 16X16
392 : orders_8x16, orders_16x8, orders_verta_16x16,
393 : // 16X32, 32X16, 32X32
394 : orders_16x32, orders_32x16, orders_verta_32x32,
395 : // 32X64, 64X32, 64X64
396 : orders_32x64, orders_64x32, orders_verta_64x64,
397 : // 64x128, 128x64, 128x128
398 : orders_64x128, orders_128x64, orders_128x128
399 : };
400 : /* clang-format on */
401 : #else
402 : /* clang-format off */
403 : static const uint16_t *const orders_verta[BLOCK_SIZES] = {
404 : #if CONFIG_CB4X4
405 : // 2X2, 2X4, 4X2
406 : orders_verta_8x8, orders_verta_8x8, orders_verta_8x8,
407 : // 4X4
408 : orders_verta_8x8,
409 : // 4X8, 8X4, 8X8
410 : orders_verta_8x8, orders_verta_8x8, orders_verta_16x16,
411 : #else
412 : // 4X4
413 : orders_verta_16x16,
414 : // 4X8, 8X4, 8X8
415 : orders_verta_16x16, orders_verta_16x16, orders_verta_16x16,
416 : #endif
417 : // 8X16, 16X8, 16X16
418 : orders_16x32, orders_32x16, orders_verta_32x32,
419 : // 16X32, 32X16, 32X32
420 : orders_32x64, orders_64x32, orders_verta_64x64,
421 : // 32X64, 64X32, 64X64
422 : orders_64x128, orders_128x64, orders_128x128
423 : };
424 : /* clang-format on */
425 : #endif // CONFIG_EXT_PARTITION
426 : #endif // CONFIG_EXT_PARTITION_TYPES
427 :
428 0 : static int has_top_right(BLOCK_SIZE bsize, int mi_row, int mi_col,
429 : int top_available, int right_available,
430 : #if CONFIG_EXT_PARTITION_TYPES
431 : PARTITION_TYPE partition,
432 : #endif
433 : TX_SIZE txsz, int row_off, int col_off, int ss_x) {
434 0 : if (!top_available || !right_available) return 0;
435 :
436 : #if !CONFIG_CB4X4
437 : // TODO(bshacklett, huisu): Currently the RD loop traverses 4X8 blocks in
438 : // inverted N order while in the bitstream the subblocks are stored in Z
439 : // order. This discrepancy makes this function incorrect when considering 4X8
440 : // blocks in the RD loop, so we disable the extended right edge for these
441 : // blocks. The correct solution is to change the bitstream to store these
442 : // blocks in inverted N order, and then update this function appropriately.
443 : if (bsize == BLOCK_4X8 && row_off == 1) return 0;
444 : #endif
445 :
446 0 : const int bw_unit = block_size_wide[bsize] >> tx_size_wide_log2[0];
447 0 : const int plane_bw_unit = AOMMAX(bw_unit >> ss_x, 1);
448 0 : const int top_right_count_unit = tx_size_wide_unit[txsz];
449 :
450 : #if !CONFIG_CB4X4
451 : // Special handling for block sizes 4x8 and 4x4.
452 : if (ss_x == 0 && bw_unit < 2 && col_off == 0) return 1;
453 : #endif
454 :
455 0 : if (row_off > 0) { // Just need to check if enough pixels on the right.
456 0 : return col_off + top_right_count_unit < plane_bw_unit;
457 : } else {
458 : // All top-right pixels are in the block above, which is already available.
459 0 : if (col_off + top_right_count_unit < plane_bw_unit) return 1;
460 :
461 0 : const int bw_in_mi_log2 = mi_width_log2_lookup[bsize];
462 0 : const int bh_in_mi_log2 = mi_height_log2_lookup[bsize];
463 0 : const int blk_row_in_sb = (mi_row & MAX_MIB_MASK) >> bh_in_mi_log2;
464 0 : const int blk_col_in_sb = (mi_col & MAX_MIB_MASK) >> bw_in_mi_log2;
465 :
466 : // Top row of superblock: so top-right pixels are in the top and/or
467 : // top-right superblocks, both of which are already available.
468 0 : if (blk_row_in_sb == 0) return 1;
469 :
470 : // Rightmost column of superblock (and not the top row): so top-right pixels
471 : // fall in the right superblock, which is not available yet.
472 0 : if (((blk_col_in_sb + 1) << bw_in_mi_log2) >= MAX_MIB_SIZE) return 0;
473 :
474 : // General case (neither top row nor rightmost column): check if the
475 : // top-right block is coded before the current block.
476 0 : const uint16_t *const order =
477 : #if CONFIG_EXT_PARTITION_TYPES
478 : (partition == PARTITION_VERT_A) ? orders_verta[bsize] :
479 : #endif // CONFIG_EXT_PARTITION_TYPES
480 0 : orders[bsize];
481 0 : const int this_blk_index =
482 0 : ((blk_row_in_sb + 0) << (MAX_MIB_SIZE_LOG2 - bw_in_mi_log2)) +
483 : blk_col_in_sb + 0;
484 0 : const uint16_t this_blk_order = order[this_blk_index];
485 0 : const int tr_blk_index =
486 0 : ((blk_row_in_sb - 1) << (MAX_MIB_SIZE_LOG2 - bw_in_mi_log2)) +
487 : blk_col_in_sb + 1;
488 0 : const uint16_t tr_blk_order = order[tr_blk_index];
489 0 : return tr_blk_order < this_blk_order;
490 : }
491 : }
492 :
493 0 : static int has_bottom_left(BLOCK_SIZE bsize, int mi_row, int mi_col,
494 : int bottom_available, int left_available,
495 : TX_SIZE txsz, int row_off, int col_off, int ss_y) {
496 0 : if (!bottom_available || !left_available) return 0;
497 :
498 0 : if (col_off > 0) {
499 : // Bottom-left pixels are in the bottom-left block, which is not available.
500 0 : return 0;
501 : } else {
502 0 : const int bh_unit = block_size_high[bsize] >> tx_size_high_log2[0];
503 0 : const int plane_bh_unit = AOMMAX(bh_unit >> ss_y, 1);
504 0 : const int bottom_left_count_unit = tx_size_high_unit[txsz];
505 :
506 : #if !CONFIG_CB4X4
507 : // Special handling for block sizes 8x4 and 4x4.
508 : if (ss_y == 0 && bh_unit < 2 && row_off == 0) return 1;
509 : #endif
510 :
511 : // All bottom-left pixels are in the left block, which is already available.
512 0 : if (row_off + bottom_left_count_unit < plane_bh_unit) return 1;
513 :
514 0 : const int bw_in_mi_log2 = mi_width_log2_lookup[bsize];
515 0 : const int bh_in_mi_log2 = mi_height_log2_lookup[bsize];
516 0 : const int blk_row_in_sb = (mi_row & MAX_MIB_MASK) >> bh_in_mi_log2;
517 0 : const int blk_col_in_sb = (mi_col & MAX_MIB_MASK) >> bw_in_mi_log2;
518 :
519 : // Leftmost column of superblock: so bottom-left pixels maybe in the left
520 : // and/or bottom-left superblocks. But only the left superblock is
521 : // available, so check if all required pixels fall in that superblock.
522 0 : if (blk_col_in_sb == 0) {
523 0 : const int blk_start_row_off = blk_row_in_sb
524 0 : << (bh_in_mi_log2 + MI_SIZE_LOG2 -
525 0 : tx_size_wide_log2[0]) >>
526 : ss_y;
527 0 : const int row_off_in_sb = blk_start_row_off + row_off;
528 0 : const int sb_height_unit =
529 0 : MAX_MIB_SIZE << (MI_SIZE_LOG2 - tx_size_wide_log2[0]) >> ss_y;
530 0 : return row_off_in_sb + bottom_left_count_unit < sb_height_unit;
531 : }
532 :
533 : // Bottom row of superblock (and not the leftmost column): so bottom-left
534 : // pixels fall in the bottom superblock, which is not available yet.
535 0 : if (((blk_row_in_sb + 1) << bh_in_mi_log2) >= MAX_MIB_SIZE) return 0;
536 :
537 : // General case (neither leftmost column nor bottom row): check if the
538 : // bottom-left block is coded before the current block.
539 0 : const uint16_t *const order = orders[bsize];
540 0 : const int this_blk_index =
541 0 : ((blk_row_in_sb + 0) << (MAX_MIB_SIZE_LOG2 - bw_in_mi_log2)) +
542 : blk_col_in_sb + 0;
543 0 : const uint16_t this_blk_order = order[this_blk_index];
544 0 : const int bl_blk_index =
545 0 : ((blk_row_in_sb + 1) << (MAX_MIB_SIZE_LOG2 - bw_in_mi_log2)) +
546 : blk_col_in_sb - 1;
547 0 : const uint16_t bl_blk_order = order[bl_blk_index];
548 0 : return bl_blk_order < this_blk_order;
549 : }
550 : }
551 :
552 : typedef void (*intra_pred_fn)(uint8_t *dst, ptrdiff_t stride,
553 : const uint8_t *above, const uint8_t *left);
554 :
555 : static intra_pred_fn pred[INTRA_MODES][TX_SIZES];
556 : static intra_pred_fn dc_pred[2][2][TX_SIZES];
557 :
558 : #if CONFIG_HIGHBITDEPTH
559 : typedef void (*intra_high_pred_fn)(uint16_t *dst, ptrdiff_t stride,
560 : const uint16_t *above, const uint16_t *left,
561 : int bd);
562 : static intra_high_pred_fn pred_high[INTRA_MODES][TX_SIZES];
563 : static intra_high_pred_fn dc_pred_high[2][2][TX_SIZES];
564 : #endif // CONFIG_HIGHBITDEPTH
565 :
566 0 : static void av1_init_intra_predictors_internal(void) {
567 : #if CONFIG_EXT_INTRA
568 : assert(NELEMENTS(mode_to_angle_map) == INTRA_MODES);
569 : #endif // CONFIG_EXT_INTRA
570 : #if CONFIG_TX64X64
571 : #define INIT_NO_4X4(p, type) \
572 : p[TX_8X8] = aom_##type##_predictor_8x8; \
573 : p[TX_16X16] = aom_##type##_predictor_16x16; \
574 : p[TX_32X32] = aom_##type##_predictor_32x32; \
575 : p[TX_64X64] = aom_##type##_predictor_64x64
576 : #else
577 : #define INIT_NO_4X4(p, type) \
578 : p[TX_8X8] = aom_##type##_predictor_8x8; \
579 : p[TX_16X16] = aom_##type##_predictor_16x16; \
580 : p[TX_32X32] = aom_##type##_predictor_32x32
581 : #endif // CONFIG_TX64X64
582 :
583 : #if CONFIG_CHROMA_2X2
584 : #define INIT_ALL_SIZES(p, type) \
585 : p[TX_2X2] = aom_##type##_predictor_2x2; \
586 : p[TX_4X4] = aom_##type##_predictor_4x4; \
587 : INIT_NO_4X4(p, type)
588 : #else
589 : #define INIT_ALL_SIZES(p, type) \
590 : p[TX_4X4] = aom_##type##_predictor_4x4; \
591 : INIT_NO_4X4(p, type)
592 : #endif
593 :
594 0 : INIT_ALL_SIZES(pred[V_PRED], v);
595 0 : INIT_ALL_SIZES(pred[H_PRED], h);
596 0 : INIT_ALL_SIZES(pred[D207_PRED], d207e);
597 0 : INIT_ALL_SIZES(pred[D45_PRED], d45e);
598 0 : INIT_ALL_SIZES(pred[D63_PRED], d63e);
599 0 : INIT_ALL_SIZES(pred[D117_PRED], d117);
600 0 : INIT_ALL_SIZES(pred[D135_PRED], d135);
601 0 : INIT_ALL_SIZES(pred[D153_PRED], d153);
602 :
603 : #if CONFIG_ALT_INTRA
604 0 : INIT_ALL_SIZES(pred[TM_PRED], paeth);
605 0 : INIT_ALL_SIZES(pred[SMOOTH_PRED], smooth);
606 : #if CONFIG_SMOOTH_HV
607 : INIT_ALL_SIZES(pred[SMOOTH_V_PRED], smooth_v);
608 : INIT_ALL_SIZES(pred[SMOOTH_H_PRED], smooth_h);
609 : #endif // CONFIG_SMOOTH_HV
610 : #else
611 : INIT_ALL_SIZES(pred[TM_PRED], tm);
612 : #endif // CONFIG_ALT_INTRA
613 :
614 0 : INIT_ALL_SIZES(dc_pred[0][0], dc_128);
615 0 : INIT_ALL_SIZES(dc_pred[0][1], dc_top);
616 0 : INIT_ALL_SIZES(dc_pred[1][0], dc_left);
617 0 : INIT_ALL_SIZES(dc_pred[1][1], dc);
618 :
619 : #if CONFIG_HIGHBITDEPTH
620 0 : INIT_ALL_SIZES(pred_high[V_PRED], highbd_v);
621 0 : INIT_ALL_SIZES(pred_high[H_PRED], highbd_h);
622 0 : INIT_ALL_SIZES(pred_high[D207_PRED], highbd_d207e);
623 0 : INIT_ALL_SIZES(pred_high[D45_PRED], highbd_d45e);
624 0 : INIT_ALL_SIZES(pred_high[D63_PRED], highbd_d63e);
625 0 : INIT_ALL_SIZES(pred_high[D117_PRED], highbd_d117);
626 0 : INIT_ALL_SIZES(pred_high[D135_PRED], highbd_d135);
627 0 : INIT_ALL_SIZES(pred_high[D153_PRED], highbd_d153);
628 :
629 : #if CONFIG_ALT_INTRA
630 0 : INIT_ALL_SIZES(pred_high[TM_PRED], highbd_paeth);
631 0 : INIT_ALL_SIZES(pred_high[SMOOTH_PRED], highbd_smooth);
632 : #if CONFIG_SMOOTH_HV
633 : INIT_ALL_SIZES(pred_high[SMOOTH_V_PRED], highbd_smooth_v);
634 : INIT_ALL_SIZES(pred_high[SMOOTH_H_PRED], highbd_smooth_h);
635 : #endif // CONFIG_SMOOTH_HV
636 : #else
637 : INIT_ALL_SIZES(pred_high[TM_PRED], highbd_tm);
638 : #endif // CONFIG_ALT_INTRA
639 :
640 0 : INIT_ALL_SIZES(dc_pred_high[0][0], highbd_dc_128);
641 0 : INIT_ALL_SIZES(dc_pred_high[0][1], highbd_dc_top);
642 0 : INIT_ALL_SIZES(dc_pred_high[1][0], highbd_dc_left);
643 0 : INIT_ALL_SIZES(dc_pred_high[1][1], highbd_dc);
644 : #endif // CONFIG_HIGHBITDEPTH
645 :
646 : #undef intra_pred_allsizes
647 0 : }
648 :
649 : #if CONFIG_EXT_INTRA
650 : #if CONFIG_INTRA_INTERP
651 : static int intra_subpel_interp(int base, int shift, const uint8_t *ref,
652 : int ref_start_idx, int ref_end_idx,
653 : INTRA_FILTER filter_type) {
654 : int val, k, idx, filter_idx = 0;
655 : const int16_t *filter = NULL;
656 :
657 : if (filter_type == INTRA_FILTER_LINEAR) {
658 : val = ref[base] * (256 - shift) + ref[base + 1] * shift;
659 : val = ROUND_POWER_OF_TWO(val, 8);
660 : } else {
661 : filter_idx = ROUND_POWER_OF_TWO(shift, 8 - SUBPEL_BITS);
662 : filter = av1_intra_filter_kernels[filter_type][filter_idx];
663 :
664 : if (filter_idx < (1 << SUBPEL_BITS)) {
665 : val = 0;
666 : for (k = 0; k < SUBPEL_TAPS; ++k) {
667 : idx = base + 1 - (SUBPEL_TAPS / 2) + k;
668 : idx = AOMMAX(AOMMIN(idx, ref_end_idx), ref_start_idx);
669 : val += ref[idx] * filter[k];
670 : }
671 : val = ROUND_POWER_OF_TWO(val, FILTER_BITS);
672 : } else {
673 : val = ref[base + 1];
674 : }
675 : }
676 :
677 : return val;
678 : }
679 : #endif // CONFIG_INTRA_INTERP
680 :
681 : // Directional prediction, zone 1: 0 < angle < 90
682 0 : static void dr_prediction_z1(uint8_t *dst, ptrdiff_t stride, int bs,
683 : const uint8_t *above, const uint8_t *left,
684 : #if CONFIG_INTRA_INTERP
685 : INTRA_FILTER filter_type,
686 : #endif // CONFIG_INTRA_INTERP
687 : int dx, int dy) {
688 : int r, c, x, base, shift, val;
689 :
690 : (void)left;
691 : (void)dy;
692 0 : assert(dy == 1);
693 0 : assert(dx > 0);
694 :
695 : #if CONFIG_INTRA_INTERP
696 : if (filter_type != INTRA_FILTER_LINEAR) {
697 : const int pad_size = SUBPEL_TAPS >> 1;
698 : int len;
699 : DECLARE_ALIGNED(16, uint8_t, buf[SUBPEL_SHIFTS][MAX_SB_SIZE]);
700 : DECLARE_ALIGNED(16, uint8_t, src[MAX_SB_SIZE + SUBPEL_TAPS]);
701 : uint8_t flags[SUBPEL_SHIFTS];
702 :
703 : memset(flags, 0, SUBPEL_SHIFTS * sizeof(flags[0]));
704 : memset(src, above[0], pad_size * sizeof(above[0]));
705 : memcpy(src + pad_size, above, 2 * bs * sizeof(above[0]));
706 : memset(src + pad_size + 2 * bs, above[2 * bs - 1],
707 : pad_size * sizeof(above[0]));
708 : flags[0] = 1;
709 : x = dx;
710 : for (r = 0; r < bs; ++r, dst += stride, x += dx) {
711 : base = x >> 8;
712 : shift = x & 0xFF;
713 : shift = ROUND_POWER_OF_TWO(shift, 8 - SUBPEL_BITS);
714 : if (shift == SUBPEL_SHIFTS) {
715 : base += 1;
716 : shift = 0;
717 : }
718 : len = AOMMIN(bs, 2 * bs - 1 - base);
719 : if (len <= 0) {
720 : int i;
721 : for (i = r; i < bs; ++i) {
722 : memset(dst, above[2 * bs - 1], bs * sizeof(dst[0]));
723 : dst += stride;
724 : }
725 : return;
726 : }
727 :
728 : if (len <= (bs >> 1) && !flags[shift]) {
729 : base = x >> 8;
730 : shift = x & 0xFF;
731 : for (c = 0; c < len; ++c) {
732 : val = intra_subpel_interp(base, shift, above, 0, 2 * bs - 1,
733 : filter_type);
734 : dst[c] = clip_pixel(val);
735 : ++base;
736 : }
737 : } else {
738 : if (!flags[shift]) {
739 : const int16_t *filter = av1_intra_filter_kernels[filter_type][shift];
740 : aom_convolve8_horiz(src + pad_size, 2 * bs, buf[shift], 2 * bs,
741 : filter, 16, NULL, 16, 2 * bs,
742 : 2 * bs < 16 ? 2 : 1);
743 : flags[shift] = 1;
744 : }
745 : memcpy(dst, shift == 0 ? src + pad_size + base : &buf[shift][base],
746 : len * sizeof(dst[0]));
747 : }
748 :
749 : if (len < bs)
750 : memset(dst + len, above[2 * bs - 1], (bs - len) * sizeof(dst[0]));
751 : }
752 : return;
753 : }
754 : #endif // CONFIG_INTRA_INTERP
755 :
756 0 : x = dx;
757 0 : for (r = 0; r < bs; ++r, dst += stride, x += dx) {
758 0 : base = x >> 8;
759 0 : shift = x & 0xFF;
760 :
761 0 : if (base >= 2 * bs - 1) {
762 : int i;
763 0 : for (i = r; i < bs; ++i) {
764 0 : memset(dst, above[2 * bs - 1], bs * sizeof(dst[0]));
765 0 : dst += stride;
766 : }
767 0 : return;
768 : }
769 :
770 0 : for (c = 0; c < bs; ++c, ++base) {
771 0 : if (base < 2 * bs - 1) {
772 0 : val = above[base] * (256 - shift) + above[base + 1] * shift;
773 0 : val = ROUND_POWER_OF_TWO(val, 8);
774 0 : dst[c] = clip_pixel(val);
775 : } else {
776 0 : dst[c] = above[2 * bs - 1];
777 : }
778 : }
779 : }
780 : }
781 :
782 : // Directional prediction, zone 2: 90 < angle < 180
783 0 : static void dr_prediction_z2(uint8_t *dst, ptrdiff_t stride, int bs,
784 : const uint8_t *above, const uint8_t *left,
785 : #if CONFIG_INTRA_INTERP
786 : INTRA_FILTER filter_type,
787 : #endif // CONFIG_INTRA_INTERP
788 : int dx, int dy) {
789 : int r, c, x, y, shift1, shift2, val, base1, base2;
790 :
791 0 : assert(dx > 0);
792 0 : assert(dy > 0);
793 :
794 0 : x = -dx;
795 0 : for (r = 0; r < bs; ++r, x -= dx, dst += stride) {
796 0 : base1 = x >> 8;
797 0 : y = (r << 8) - dy;
798 0 : for (c = 0; c < bs; ++c, ++base1, y -= dy) {
799 0 : if (base1 >= -1) {
800 0 : shift1 = x & 0xFF;
801 : #if CONFIG_INTRA_INTERP
802 : val =
803 : intra_subpel_interp(base1, shift1, above, -1, bs - 1, filter_type);
804 : #else
805 0 : val = above[base1] * (256 - shift1) + above[base1 + 1] * shift1;
806 0 : val = ROUND_POWER_OF_TWO(val, 8);
807 : #endif // CONFIG_INTRA_INTERP
808 : } else {
809 0 : base2 = y >> 8;
810 0 : assert(base2 >= -1);
811 0 : shift2 = y & 0xFF;
812 : #if CONFIG_INTRA_INTERP
813 : val = intra_subpel_interp(base2, shift2, left, -1, bs - 1, filter_type);
814 : #else
815 0 : val = left[base2] * (256 - shift2) + left[base2 + 1] * shift2;
816 0 : val = ROUND_POWER_OF_TWO(val, 8);
817 : #endif // CONFIG_INTRA_INTERP
818 : }
819 0 : dst[c] = clip_pixel(val);
820 : }
821 : }
822 0 : }
823 :
824 : // Directional prediction, zone 3: 180 < angle < 270
825 0 : static void dr_prediction_z3(uint8_t *dst, ptrdiff_t stride, int bs,
826 : const uint8_t *above, const uint8_t *left,
827 : #if CONFIG_INTRA_INTERP
828 : INTRA_FILTER filter_type,
829 : #endif // CONFIG_INTRA_INTERP
830 : int dx, int dy) {
831 : int r, c, y, base, shift, val;
832 :
833 : (void)above;
834 : (void)dx;
835 :
836 0 : assert(dx == 1);
837 0 : assert(dy > 0);
838 :
839 : #if CONFIG_INTRA_INTERP
840 : if (filter_type != INTRA_FILTER_LINEAR) {
841 : const int pad_size = SUBPEL_TAPS >> 1;
842 : int len, i;
843 : DECLARE_ALIGNED(16, uint8_t, buf[MAX_SB_SIZE][4 * SUBPEL_SHIFTS]);
844 : DECLARE_ALIGNED(16, uint8_t, src[(MAX_SB_SIZE + SUBPEL_TAPS) * 4]);
845 : uint8_t flags[SUBPEL_SHIFTS];
846 :
847 : memset(flags, 0, SUBPEL_SHIFTS * sizeof(flags[0]));
848 : for (i = 0; i < pad_size; ++i) src[4 * i] = left[0];
849 : for (i = 0; i < 2 * bs; ++i) src[4 * (i + pad_size)] = left[i];
850 : for (i = 0; i < pad_size; ++i)
851 : src[4 * (i + 2 * bs + pad_size)] = left[2 * bs - 1];
852 : flags[0] = 1;
853 : y = dy;
854 : for (c = 0; c < bs; ++c, y += dy) {
855 : base = y >> 8;
856 : shift = y & 0xFF;
857 : shift = ROUND_POWER_OF_TWO(shift, 8 - SUBPEL_BITS);
858 : if (shift == SUBPEL_SHIFTS) {
859 : base += 1;
860 : shift = 0;
861 : }
862 : len = AOMMIN(bs, 2 * bs - 1 - base);
863 :
864 : if (len <= 0) {
865 : for (r = 0; r < bs; ++r) {
866 : dst[r * stride + c] = left[2 * bs - 1];
867 : }
868 : continue;
869 : }
870 :
871 : if (len <= (bs >> 1) && !flags[shift]) {
872 : base = y >> 8;
873 : shift = y & 0xFF;
874 : for (r = 0; r < len; ++r) {
875 : val = intra_subpel_interp(base, shift, left, 0, 2 * bs - 1,
876 : filter_type);
877 : dst[r * stride + c] = clip_pixel(val);
878 : ++base;
879 : }
880 : } else {
881 : if (!flags[shift]) {
882 : const int16_t *filter = av1_intra_filter_kernels[filter_type][shift];
883 : aom_convolve8_vert(src + 4 * pad_size, 4, buf[0] + 4 * shift,
884 : 4 * SUBPEL_SHIFTS, NULL, 16, filter, 16,
885 : 2 * bs < 16 ? 4 : 4, 2 * bs);
886 : flags[shift] = 1;
887 : }
888 :
889 : if (shift == 0) {
890 : for (r = 0; r < len; ++r) {
891 : dst[r * stride + c] = left[r + base];
892 : }
893 : } else {
894 : for (r = 0; r < len; ++r) {
895 : dst[r * stride + c] = buf[r + base][4 * shift];
896 : }
897 : }
898 : }
899 :
900 : if (len < bs) {
901 : for (r = len; r < bs; ++r) {
902 : dst[r * stride + c] = left[2 * bs - 1];
903 : }
904 : }
905 : }
906 : return;
907 : }
908 : #endif // CONFIG_INTRA_INTERP
909 :
910 0 : y = dy;
911 0 : for (c = 0; c < bs; ++c, y += dy) {
912 0 : base = y >> 8;
913 0 : shift = y & 0xFF;
914 :
915 0 : for (r = 0; r < bs; ++r, ++base) {
916 0 : if (base < 2 * bs - 1) {
917 0 : val = left[base] * (256 - shift) + left[base + 1] * shift;
918 0 : val = ROUND_POWER_OF_TWO(val, 8);
919 0 : dst[r * stride + c] = clip_pixel(val);
920 : } else {
921 0 : for (; r < bs; ++r) dst[r * stride + c] = left[2 * bs - 1];
922 0 : break;
923 : }
924 : }
925 : }
926 0 : }
927 :
928 : // Get the shift (up-scaled by 256) in X w.r.t a unit change in Y.
929 : // If angle > 0 && angle < 90, dx = -((int)(256 / t));
930 : // If angle > 90 && angle < 180, dx = (int)(256 / t);
931 : // If angle > 180 && angle < 270, dx = 1;
932 0 : static INLINE int get_dx(int angle) {
933 0 : if (angle > 0 && angle < 90) {
934 0 : return dr_intra_derivative[angle];
935 0 : } else if (angle > 90 && angle < 180) {
936 0 : return dr_intra_derivative[180 - angle];
937 : } else {
938 : // In this case, we are not really going to use dx. We may return any value.
939 0 : return 1;
940 : }
941 : }
942 :
943 : // Get the shift (up-scaled by 256) in Y w.r.t a unit change in X.
944 : // If angle > 0 && angle < 90, dy = 1;
945 : // If angle > 90 && angle < 180, dy = (int)(256 * t);
946 : // If angle > 180 && angle < 270, dy = -((int)(256 * t));
947 0 : static INLINE int get_dy(int angle) {
948 0 : if (angle > 90 && angle < 180) {
949 0 : return dr_intra_derivative[angle - 90];
950 0 : } else if (angle > 180 && angle < 270) {
951 0 : return dr_intra_derivative[270 - angle];
952 : } else {
953 : // In this case, we are not really going to use dy. We may return any value.
954 0 : return 1;
955 : }
956 : }
957 :
958 0 : static void dr_predictor(uint8_t *dst, ptrdiff_t stride, TX_SIZE tx_size,
959 : const uint8_t *above, const uint8_t *left,
960 : #if CONFIG_INTRA_INTERP
961 : INTRA_FILTER filter_type,
962 : #endif // CONFIG_INTRA_INTERP
963 : int angle) {
964 0 : const int dx = get_dx(angle);
965 0 : const int dy = get_dy(angle);
966 0 : const int bs = tx_size_wide[tx_size];
967 0 : assert(angle > 0 && angle < 270);
968 :
969 0 : if (angle > 0 && angle < 90) {
970 0 : dr_prediction_z1(dst, stride, bs, above, left,
971 : #if CONFIG_INTRA_INTERP
972 : filter_type,
973 : #endif // CONFIG_INTRA_INTERP
974 : dx, dy);
975 0 : } else if (angle > 90 && angle < 180) {
976 0 : dr_prediction_z2(dst, stride, bs, above, left,
977 : #if CONFIG_INTRA_INTERP
978 : filter_type,
979 : #endif // CONFIG_INTRA_INTERP
980 : dx, dy);
981 0 : } else if (angle > 180 && angle < 270) {
982 0 : dr_prediction_z3(dst, stride, bs, above, left,
983 : #if CONFIG_INTRA_INTERP
984 : filter_type,
985 : #endif // CONFIG_INTRA_INTERP
986 : dx, dy);
987 0 : } else if (angle == 90) {
988 0 : pred[V_PRED][tx_size](dst, stride, above, left);
989 0 : } else if (angle == 180) {
990 0 : pred[H_PRED][tx_size](dst, stride, above, left);
991 : }
992 0 : }
993 :
994 : #if CONFIG_HIGHBITDEPTH
995 : #if CONFIG_INTRA_INTERP
996 : static int highbd_intra_subpel_interp(int base, int shift, const uint16_t *ref,
997 : int ref_start_idx, int ref_end_idx,
998 : INTRA_FILTER filter_type) {
999 : int val, k, idx, filter_idx = 0;
1000 : const int16_t *filter = NULL;
1001 :
1002 : if (filter_type == INTRA_FILTER_LINEAR) {
1003 : val = ref[base] * (256 - shift) + ref[base + 1] * shift;
1004 : val = ROUND_POWER_OF_TWO(val, 8);
1005 : } else {
1006 : filter_idx = ROUND_POWER_OF_TWO(shift, 8 - SUBPEL_BITS);
1007 : filter = av1_intra_filter_kernels[filter_type][filter_idx];
1008 :
1009 : if (filter_idx < (1 << SUBPEL_BITS)) {
1010 : val = 0;
1011 : for (k = 0; k < SUBPEL_TAPS; ++k) {
1012 : idx = base + 1 - (SUBPEL_TAPS / 2) + k;
1013 : idx = AOMMAX(AOMMIN(idx, ref_end_idx), ref_start_idx);
1014 : val += ref[idx] * filter[k];
1015 : }
1016 : val = ROUND_POWER_OF_TWO(val, FILTER_BITS);
1017 : } else {
1018 : val = ref[base + 1];
1019 : }
1020 : }
1021 :
1022 : return val;
1023 : }
1024 : #endif // CONFIG_INTRA_INTERP
1025 :
1026 : // Directional prediction, zone 1: 0 < angle < 90
1027 0 : static void highbd_dr_prediction_z1(uint16_t *dst, ptrdiff_t stride, int bs,
1028 : const uint16_t *above, const uint16_t *left,
1029 : #if CONFIG_INTRA_INTERP
1030 : INTRA_FILTER filter_type,
1031 : #endif // CONFIG_INTRA_INTERP
1032 : int dx, int dy, int bd) {
1033 : int r, c, x, base, shift, val;
1034 :
1035 : (void)left;
1036 : (void)dy;
1037 0 : assert(dy == 1);
1038 0 : assert(dx > 0);
1039 :
1040 0 : x = dx;
1041 0 : for (r = 0; r < bs; ++r, dst += stride, x += dx) {
1042 0 : base = x >> 8;
1043 0 : shift = x & 0xFF;
1044 :
1045 0 : if (base >= 2 * bs - 1) {
1046 : int i;
1047 0 : for (i = r; i < bs; ++i) {
1048 0 : aom_memset16(dst, above[2 * bs - 1], bs);
1049 0 : dst += stride;
1050 : }
1051 0 : return;
1052 : }
1053 :
1054 0 : for (c = 0; c < bs; ++c, ++base) {
1055 0 : if (base < 2 * bs - 1) {
1056 : #if CONFIG_INTRA_INTERP
1057 : val = highbd_intra_subpel_interp(base, shift, above, 0, 2 * bs - 1,
1058 : filter_type);
1059 : #else
1060 0 : val = above[base] * (256 - shift) + above[base + 1] * shift;
1061 0 : val = ROUND_POWER_OF_TWO(val, 8);
1062 : #endif // CONFIG_INTRA_INTERP
1063 0 : dst[c] = clip_pixel_highbd(val, bd);
1064 : } else {
1065 0 : dst[c] = above[2 * bs - 1];
1066 : }
1067 : }
1068 : }
1069 : }
1070 :
1071 : // Directional prediction, zone 2: 90 < angle < 180
1072 0 : static void highbd_dr_prediction_z2(uint16_t *dst, ptrdiff_t stride, int bs,
1073 : const uint16_t *above, const uint16_t *left,
1074 : #if CONFIG_INTRA_INTERP
1075 : INTRA_FILTER filter_type,
1076 : #endif // CONFIG_INTRA_INTERP
1077 : int dx, int dy, int bd) {
1078 : int r, c, x, y, shift, val, base;
1079 :
1080 0 : assert(dx > 0);
1081 0 : assert(dy > 0);
1082 :
1083 0 : for (r = 0; r < bs; ++r) {
1084 0 : for (c = 0; c < bs; ++c) {
1085 0 : y = r + 1;
1086 0 : x = (c << 8) - y * dx;
1087 0 : base = x >> 8;
1088 0 : if (base >= -1) {
1089 0 : shift = x & 0xFF;
1090 : #if CONFIG_INTRA_INTERP
1091 : val = highbd_intra_subpel_interp(base, shift, above, -1, bs - 1,
1092 : filter_type);
1093 : #else
1094 0 : val = above[base] * (256 - shift) + above[base + 1] * shift;
1095 0 : val = ROUND_POWER_OF_TWO(val, 8);
1096 : #endif // CONFIG_INTRA_INTERP
1097 : } else {
1098 0 : x = c + 1;
1099 0 : y = (r << 8) - x * dy;
1100 0 : base = y >> 8;
1101 0 : shift = y & 0xFF;
1102 : #if CONFIG_INTRA_INTERP
1103 : val = highbd_intra_subpel_interp(base, shift, left, -1, bs - 1,
1104 : filter_type);
1105 : #else
1106 0 : val = left[base] * (256 - shift) + left[base + 1] * shift;
1107 0 : val = ROUND_POWER_OF_TWO(val, 8);
1108 : #endif // CONFIG_INTRA_INTERP
1109 : }
1110 0 : dst[c] = clip_pixel_highbd(val, bd);
1111 : }
1112 0 : dst += stride;
1113 : }
1114 0 : }
1115 :
1116 : // Directional prediction, zone 3: 180 < angle < 270
1117 0 : static void highbd_dr_prediction_z3(uint16_t *dst, ptrdiff_t stride, int bs,
1118 : const uint16_t *above, const uint16_t *left,
1119 : #if CONFIG_INTRA_INTERP
1120 : INTRA_FILTER filter_type,
1121 : #endif // CONFIG_INTRA_INTERP
1122 : int dx, int dy, int bd) {
1123 : int r, c, y, base, shift, val;
1124 :
1125 : (void)above;
1126 : (void)dx;
1127 0 : assert(dx == 1);
1128 0 : assert(dy > 0);
1129 :
1130 0 : y = dy;
1131 0 : for (c = 0; c < bs; ++c, y += dy) {
1132 0 : base = y >> 8;
1133 0 : shift = y & 0xFF;
1134 :
1135 0 : for (r = 0; r < bs; ++r, ++base) {
1136 0 : if (base < 2 * bs - 1) {
1137 : #if CONFIG_INTRA_INTERP
1138 : val = highbd_intra_subpel_interp(base, shift, left, 0, 2 * bs - 1,
1139 : filter_type);
1140 : #else
1141 0 : val = left[base] * (256 - shift) + left[base + 1] * shift;
1142 0 : val = ROUND_POWER_OF_TWO(val, 8);
1143 : #endif // CONFIG_INTRA_INTERP
1144 0 : dst[r * stride + c] = clip_pixel_highbd(val, bd);
1145 : } else {
1146 0 : for (; r < bs; ++r) dst[r * stride + c] = left[2 * bs - 1];
1147 0 : break;
1148 : }
1149 : }
1150 : }
1151 0 : }
1152 :
1153 0 : static INLINE void highbd_v_predictor(uint16_t *dst, ptrdiff_t stride, int bs,
1154 : const uint16_t *above,
1155 : const uint16_t *left, int bd) {
1156 : int r;
1157 : (void)left;
1158 : (void)bd;
1159 0 : for (r = 0; r < bs; r++) {
1160 0 : memcpy(dst, above, bs * sizeof(uint16_t));
1161 0 : dst += stride;
1162 : }
1163 0 : }
1164 :
1165 0 : static INLINE void highbd_h_predictor(uint16_t *dst, ptrdiff_t stride, int bs,
1166 : const uint16_t *above,
1167 : const uint16_t *left, int bd) {
1168 : int r;
1169 : (void)above;
1170 : (void)bd;
1171 0 : for (r = 0; r < bs; r++) {
1172 0 : aom_memset16(dst, left[r], bs);
1173 0 : dst += stride;
1174 : }
1175 0 : }
1176 :
1177 0 : static void highbd_dr_predictor(uint16_t *dst, ptrdiff_t stride, int bs,
1178 : const uint16_t *above, const uint16_t *left,
1179 : #if CONFIG_INTRA_INTERP
1180 : INTRA_FILTER filter,
1181 : #endif // CONFIG_INTRA_INTERP
1182 : int angle, int bd) {
1183 0 : const int dx = get_dx(angle);
1184 0 : const int dy = get_dy(angle);
1185 0 : assert(angle > 0 && angle < 270);
1186 :
1187 0 : if (angle > 0 && angle < 90) {
1188 0 : highbd_dr_prediction_z1(dst, stride, bs, above, left,
1189 : #if CONFIG_INTRA_INTERP
1190 : filter,
1191 : #endif // CONFIG_INTRA_INTERP
1192 : dx, dy, bd);
1193 0 : } else if (angle > 90 && angle < 180) {
1194 0 : highbd_dr_prediction_z2(dst, stride, bs, above, left,
1195 : #if CONFIG_INTRA_INTERP
1196 : filter,
1197 : #endif // CONFIG_INTRA_INTERP
1198 : dx, dy, bd);
1199 0 : } else if (angle > 180 && angle < 270) {
1200 0 : highbd_dr_prediction_z3(dst, stride, bs, above, left,
1201 : #if CONFIG_INTRA_INTERP
1202 : filter,
1203 : #endif // CONFIG_INTRA_INTERP
1204 : dx, dy, bd);
1205 0 : } else if (angle == 90) {
1206 0 : highbd_v_predictor(dst, stride, bs, above, left, bd);
1207 0 : } else if (angle == 180) {
1208 0 : highbd_h_predictor(dst, stride, bs, above, left, bd);
1209 : }
1210 0 : }
1211 : #endif // CONFIG_HIGHBITDEPTH
1212 : #endif // CONFIG_EXT_INTRA
1213 :
1214 : #if CONFIG_FILTER_INTRA
1215 : #if USE_3TAP_INTRA_FILTER
1216 : static int filter_intra_taps_3[TX_SIZES][FILTER_INTRA_MODES][3] = {
1217 : #if CONFIG_CHROMA_2X2
1218 : {
1219 : { 697, 836, -509 },
1220 : { 993, 513, -482 },
1221 : { 381, 984, -341 },
1222 : { 642, 1169, -787 },
1223 : { 590, 553, -119 },
1224 : { 762, 385, -123 },
1225 : { 358, 687, -21 },
1226 : { 411, 1083, -470 },
1227 : { 912, 814, -702 },
1228 : { 883, 902, -761 },
1229 : },
1230 : #endif
1231 : {
1232 : { 697, 836, -509 },
1233 : { 993, 513, -482 },
1234 : { 381, 984, -341 },
1235 : { 642, 1169, -787 },
1236 : { 590, 553, -119 },
1237 : { 762, 385, -123 },
1238 : { 358, 687, -21 },
1239 : { 411, 1083, -470 },
1240 : { 912, 814, -702 },
1241 : { 883, 902, -761 },
1242 : },
1243 : {
1244 : { 659, 816, -451 },
1245 : { 980, 625, -581 },
1246 : { 558, 962, -496 },
1247 : { 681, 888, -545 },
1248 : { 591, 613, 180 },
1249 : { 778, 399, -153 },
1250 : { 495, 641, -112 },
1251 : { 671, 937, -584 },
1252 : { 745, 940, -661 },
1253 : { 839, 911, -726 },
1254 : },
1255 : {
1256 : { 539, 927, -442 },
1257 : { 1003, 714, -693 },
1258 : { 349, 1271, -596 },
1259 : { 820, 764, -560 },
1260 : { 524, 816, -316 },
1261 : { 780, 681, -437 },
1262 : { 586, 795, -357 },
1263 : { 551, 1135, -663 },
1264 : { 593, 1061, -630 },
1265 : { 974, 970, -920 },
1266 : },
1267 : {
1268 : { 595, 919, -490 },
1269 : { 945, 668, -579 },
1270 : { 495, 962, -433 },
1271 : { 385, 1551, -912 },
1272 : { 455, 554, 15 },
1273 : { 852, 478, -306 },
1274 : { 177, 760, -87 },
1275 : { -65, 1611, -522 },
1276 : { 815, 894, -685 },
1277 : { 846, 1010, -832 },
1278 : },
1279 : #if CONFIG_TX64X64
1280 : {
1281 : { 595, 919, -490 },
1282 : { 945, 668, -579 },
1283 : { 495, 962, -433 },
1284 : { 385, 1551, -912 },
1285 : { 455, 554, 15 },
1286 : { 852, 478, -306 },
1287 : { 177, 760, -87 },
1288 : { -65, 1611, -522 },
1289 : { 815, 894, -685 },
1290 : { 846, 1010, -832 },
1291 : },
1292 : #endif // CONFIG_TX64X64
1293 : };
1294 : #else
1295 : static int filter_intra_taps_4[TX_SIZES][FILTER_INTRA_MODES][4] = {
1296 : #if CONFIG_CHROMA_2X2
1297 : {
1298 : { 735, 881, -537, -54 },
1299 : { 1005, 519, -488, -11 },
1300 : { 383, 990, -343, -6 },
1301 : { 442, 805, -542, 319 },
1302 : { 658, 616, -133, -116 },
1303 : { 875, 442, -141, -151 },
1304 : { 386, 741, -23, -80 },
1305 : { 390, 1027, -446, 51 },
1306 : { 679, 606, -523, 262 },
1307 : { 903, 922, -778, -23 },
1308 : },
1309 : #endif
1310 : {
1311 : { 735, 881, -537, -54 },
1312 : { 1005, 519, -488, -11 },
1313 : { 383, 990, -343, -6 },
1314 : { 442, 805, -542, 319 },
1315 : { 658, 616, -133, -116 },
1316 : { 875, 442, -141, -151 },
1317 : { 386, 741, -23, -80 },
1318 : { 390, 1027, -446, 51 },
1319 : { 679, 606, -523, 262 },
1320 : { 903, 922, -778, -23 },
1321 : },
1322 : {
1323 : { 648, 803, -444, 16 },
1324 : { 972, 620, -576, 7 },
1325 : { 561, 967, -499, -5 },
1326 : { 585, 762, -468, 144 },
1327 : { 596, 619, -182, -9 },
1328 : { 895, 459, -176, -153 },
1329 : { 557, 722, -126, -129 },
1330 : { 601, 839, -523, 105 },
1331 : { 562, 709, -499, 251 },
1332 : { 803, 872, -695, 43 },
1333 : },
1334 : {
1335 : { 423, 728, -347, 111 },
1336 : { 963, 685, -665, 23 },
1337 : { 281, 1024, -480, 216 },
1338 : { 640, 596, -437, 78 },
1339 : { 429, 669, -259, 99 },
1340 : { 740, 646, -415, 23 },
1341 : { 568, 771, -346, 40 },
1342 : { 404, 833, -486, 209 },
1343 : { 398, 712, -423, 307 },
1344 : { 939, 935, -887, 17 },
1345 : },
1346 : {
1347 : { 477, 737, -393, 150 },
1348 : { 881, 630, -546, 67 },
1349 : { 506, 984, -443, -20 },
1350 : { 114, 459, -270, 528 },
1351 : { 433, 528, 14, 3 },
1352 : { 837, 470, -301, -30 },
1353 : { 181, 777, 89, -107 },
1354 : { -29, 716, -232, 259 },
1355 : { 589, 646, -495, 255 },
1356 : { 740, 884, -728, 77 },
1357 : },
1358 : #if CONFIG_TX64X64
1359 : {
1360 : { 477, 737, -393, 150 },
1361 : { 881, 630, -546, 67 },
1362 : { 506, 984, -443, -20 },
1363 : { 114, 459, -270, 528 },
1364 : { 433, 528, 14, 3 },
1365 : { 837, 470, -301, -30 },
1366 : { 181, 777, 89, -107 },
1367 : { -29, 716, -232, 259 },
1368 : { 589, 646, -495, 255 },
1369 : { 740, 884, -728, 77 },
1370 : },
1371 : #endif // CONFIG_TX64X64
1372 : };
1373 : #endif
1374 :
1375 : static INLINE TX_SIZE get_txsize_from_blocklen(int bs) {
1376 : switch (bs) {
1377 : case 4: return TX_4X4;
1378 : case 8: return TX_8X8;
1379 : case 16: return TX_16X16;
1380 : case 32: return TX_32X32;
1381 : #if CONFIG_TX64X64
1382 : case 64: return TX_64X64;
1383 : #endif // CONFIG_TX64X64
1384 : default: assert(0); return TX_INVALID;
1385 : }
1386 : }
1387 :
1388 : #if USE_3TAP_INTRA_FILTER
1389 : static void filter_intra_predictors_3tap(uint8_t *dst, ptrdiff_t stride, int bs,
1390 : const uint8_t *above,
1391 : const uint8_t *left, int mode) {
1392 : int k, r, c;
1393 : int mean, ipred;
1394 : #if CONFIG_TX64X64
1395 : int buffer[65][65];
1396 : #else
1397 : int buffer[33][33];
1398 : #endif // CONFIG_TX64X64
1399 : const TX_SIZE tx_size = get_txsize_from_blocklen(bs);
1400 : const int c0 = filter_intra_taps_3[tx_size][mode][0];
1401 : const int c1 = filter_intra_taps_3[tx_size][mode][1];
1402 : const int c2 = filter_intra_taps_3[tx_size][mode][2];
1403 :
1404 : k = 0;
1405 : mean = 0;
1406 : while (k < bs) {
1407 : mean = mean + (int)left[k];
1408 : mean = mean + (int)above[k];
1409 : k++;
1410 : }
1411 : mean = (mean + bs) / (2 * bs);
1412 :
1413 : for (r = 0; r < bs; ++r) buffer[r + 1][0] = (int)left[r] - mean;
1414 :
1415 : for (c = 0; c < bs + 1; ++c) buffer[0][c] = (int)above[c - 1] - mean;
1416 :
1417 : for (r = 1; r < bs + 1; ++r)
1418 : for (c = 1; c < bs + 1; ++c) {
1419 : ipred = c0 * buffer[r - 1][c] + c1 * buffer[r][c - 1] +
1420 : c2 * buffer[r - 1][c - 1];
1421 : buffer[r][c] = ROUND_POWER_OF_TWO_SIGNED(ipred, FILTER_INTRA_PREC_BITS);
1422 : buffer[r][c] = clip_pixel(buffer[r][c] + mean) - mean;
1423 : }
1424 :
1425 : for (r = 0; r < bs; ++r) {
1426 : for (c = 0; c < bs; ++c) dst[c] = clip_pixel(buffer[r + 1][c + 1] + mean);
1427 : dst += stride;
1428 : }
1429 : }
1430 : #else
1431 : static void filter_intra_predictors_4tap(uint8_t *dst, ptrdiff_t stride, int bs,
1432 : const uint8_t *above,
1433 : const uint8_t *left, int mode) {
1434 : int k, r, c;
1435 : int mean, ipred;
1436 : #if CONFIG_TX64X64
1437 : int buffer[65][129];
1438 : #else
1439 : int buffer[33][65];
1440 : #endif // CONFIG_TX64X64
1441 : const TX_SIZE tx_size = get_txsize_from_blocklen(bs);
1442 : const int c0 = filter_intra_taps_4[tx_size][mode][0];
1443 : const int c1 = filter_intra_taps_4[tx_size][mode][1];
1444 : const int c2 = filter_intra_taps_4[tx_size][mode][2];
1445 : const int c3 = filter_intra_taps_4[tx_size][mode][3];
1446 :
1447 : k = 0;
1448 : mean = 0;
1449 : while (k < bs) {
1450 : mean = mean + (int)left[k];
1451 : mean = mean + (int)above[k];
1452 : k++;
1453 : }
1454 : mean = (mean + bs) / (2 * bs);
1455 :
1456 : for (r = 0; r < bs; ++r) buffer[r + 1][0] = (int)left[r] - mean;
1457 :
1458 : for (c = 0; c < 2 * bs + 1; ++c) buffer[0][c] = (int)above[c - 1] - mean;
1459 :
1460 : for (r = 1; r < bs + 1; ++r)
1461 : for (c = 1; c < 2 * bs + 1 - r; ++c) {
1462 : ipred = c0 * buffer[r - 1][c] + c1 * buffer[r][c - 1] +
1463 : c2 * buffer[r - 1][c - 1] + c3 * buffer[r - 1][c + 1];
1464 : buffer[r][c] = ROUND_POWER_OF_TWO_SIGNED(ipred, FILTER_INTRA_PREC_BITS);
1465 : buffer[r][c] = clip_pixel(buffer[r][c] + mean) - mean;
1466 : }
1467 :
1468 : for (r = 0; r < bs; ++r) {
1469 : for (c = 0; c < bs; ++c) dst[c] = clip_pixel(buffer[r + 1][c + 1] + mean);
1470 : dst += stride;
1471 : }
1472 : }
1473 : #endif
1474 :
1475 : void av1_dc_filter_predictor_c(uint8_t *dst, ptrdiff_t stride, int bs,
1476 : const uint8_t *above, const uint8_t *left) {
1477 : #if USE_3TAP_INTRA_FILTER
1478 : filter_intra_predictors_3tap(dst, stride, bs, above, left, FILTER_DC_PRED);
1479 : #else
1480 : filter_intra_predictors_4tap(dst, stride, bs, above, left, FILTER_DC_PRED);
1481 : #endif
1482 : }
1483 :
1484 : void av1_v_filter_predictor_c(uint8_t *dst, ptrdiff_t stride, int bs,
1485 : const uint8_t *above, const uint8_t *left) {
1486 : #if USE_3TAP_INTRA_FILTER
1487 : filter_intra_predictors_3tap(dst, stride, bs, above, left, FILTER_V_PRED);
1488 : #else
1489 : filter_intra_predictors_4tap(dst, stride, bs, above, left, FILTER_V_PRED);
1490 : #endif
1491 : }
1492 :
1493 : void av1_h_filter_predictor_c(uint8_t *dst, ptrdiff_t stride, int bs,
1494 : const uint8_t *above, const uint8_t *left) {
1495 : #if USE_3TAP_INTRA_FILTER
1496 : filter_intra_predictors_3tap(dst, stride, bs, above, left, FILTER_H_PRED);
1497 : #else
1498 : filter_intra_predictors_4tap(dst, stride, bs, above, left, FILTER_H_PRED);
1499 : #endif
1500 : }
1501 :
1502 : void av1_d45_filter_predictor_c(uint8_t *dst, ptrdiff_t stride, int bs,
1503 : const uint8_t *above, const uint8_t *left) {
1504 : #if USE_3TAP_INTRA_FILTER
1505 : filter_intra_predictors_3tap(dst, stride, bs, above, left, FILTER_D45_PRED);
1506 : #else
1507 : filter_intra_predictors_4tap(dst, stride, bs, above, left, FILTER_D45_PRED);
1508 : #endif
1509 : }
1510 :
1511 : void av1_d135_filter_predictor_c(uint8_t *dst, ptrdiff_t stride, int bs,
1512 : const uint8_t *above, const uint8_t *left) {
1513 : #if USE_3TAP_INTRA_FILTER
1514 : filter_intra_predictors_3tap(dst, stride, bs, above, left, FILTER_D135_PRED);
1515 : #else
1516 : filter_intra_predictors_4tap(dst, stride, bs, above, left, FILTER_D135_PRED);
1517 : #endif
1518 : }
1519 :
1520 : void av1_d117_filter_predictor_c(uint8_t *dst, ptrdiff_t stride, int bs,
1521 : const uint8_t *above, const uint8_t *left) {
1522 : #if USE_3TAP_INTRA_FILTER
1523 : filter_intra_predictors_3tap(dst, stride, bs, above, left, FILTER_D117_PRED);
1524 : #else
1525 : filter_intra_predictors_4tap(dst, stride, bs, above, left, FILTER_D117_PRED);
1526 : #endif
1527 : }
1528 :
1529 : void av1_d153_filter_predictor_c(uint8_t *dst, ptrdiff_t stride, int bs,
1530 : const uint8_t *above, const uint8_t *left) {
1531 : #if USE_3TAP_INTRA_FILTER
1532 : filter_intra_predictors_3tap(dst, stride, bs, above, left, FILTER_D153_PRED);
1533 : #else
1534 : filter_intra_predictors_4tap(dst, stride, bs, above, left, FILTER_D153_PRED);
1535 : #endif
1536 : }
1537 :
1538 : void av1_d207_filter_predictor_c(uint8_t *dst, ptrdiff_t stride, int bs,
1539 : const uint8_t *above, const uint8_t *left) {
1540 : #if USE_3TAP_INTRA_FILTER
1541 : filter_intra_predictors_3tap(dst, stride, bs, above, left, FILTER_D207_PRED);
1542 : #else
1543 : filter_intra_predictors_4tap(dst, stride, bs, above, left, FILTER_D207_PRED);
1544 : #endif
1545 : }
1546 :
1547 : void av1_d63_filter_predictor_c(uint8_t *dst, ptrdiff_t stride, int bs,
1548 : const uint8_t *above, const uint8_t *left) {
1549 : #if USE_3TAP_INTRA_FILTER
1550 : filter_intra_predictors_3tap(dst, stride, bs, above, left, FILTER_D63_PRED);
1551 : #else
1552 : filter_intra_predictors_4tap(dst, stride, bs, above, left, FILTER_D63_PRED);
1553 : #endif
1554 : }
1555 :
1556 : void av1_tm_filter_predictor_c(uint8_t *dst, ptrdiff_t stride, int bs,
1557 : const uint8_t *above, const uint8_t *left) {
1558 : #if USE_3TAP_INTRA_FILTER
1559 : filter_intra_predictors_3tap(dst, stride, bs, above, left, FILTER_TM_PRED);
1560 : #else
1561 : filter_intra_predictors_4tap(dst, stride, bs, above, left, FILTER_TM_PRED);
1562 : #endif
1563 : }
1564 :
1565 : static void filter_intra_predictors(FILTER_INTRA_MODE mode, uint8_t *dst,
1566 : ptrdiff_t stride, int bs,
1567 : const uint8_t *above, const uint8_t *left) {
1568 : switch (mode) {
1569 : case FILTER_DC_PRED:
1570 : av1_dc_filter_predictor(dst, stride, bs, above, left);
1571 : break;
1572 : case FILTER_V_PRED:
1573 : av1_v_filter_predictor(dst, stride, bs, above, left);
1574 : break;
1575 : case FILTER_H_PRED:
1576 : av1_h_filter_predictor(dst, stride, bs, above, left);
1577 : break;
1578 : case FILTER_D45_PRED:
1579 : av1_d45_filter_predictor(dst, stride, bs, above, left);
1580 : break;
1581 : case FILTER_D135_PRED:
1582 : av1_d135_filter_predictor(dst, stride, bs, above, left);
1583 : break;
1584 : case FILTER_D117_PRED:
1585 : av1_d117_filter_predictor(dst, stride, bs, above, left);
1586 : break;
1587 : case FILTER_D153_PRED:
1588 : av1_d153_filter_predictor(dst, stride, bs, above, left);
1589 : break;
1590 : case FILTER_D207_PRED:
1591 : av1_d207_filter_predictor(dst, stride, bs, above, left);
1592 : break;
1593 : case FILTER_D63_PRED:
1594 : av1_d63_filter_predictor(dst, stride, bs, above, left);
1595 : break;
1596 : case FILTER_TM_PRED:
1597 : av1_tm_filter_predictor(dst, stride, bs, above, left);
1598 : break;
1599 : default: assert(0);
1600 : }
1601 : }
1602 : #if CONFIG_HIGHBITDEPTH
1603 : #if USE_3TAP_INTRA_FILTER
1604 : static void highbd_filter_intra_predictors_3tap(uint16_t *dst, ptrdiff_t stride,
1605 : int bs, const uint16_t *above,
1606 : const uint16_t *left, int mode,
1607 : int bd) {
1608 : int k, r, c;
1609 : int mean, ipred;
1610 : #if CONFIG_TX64X64
1611 : int preds[65][65];
1612 : #else
1613 : int preds[33][33];
1614 : #endif // CONFIG_TX64X64
1615 : const TX_SIZE tx_size = get_txsize_from_blocklen(bs);
1616 : const int c0 = filter_intra_taps_3[tx_size][mode][0];
1617 : const int c1 = filter_intra_taps_3[tx_size][mode][1];
1618 : const int c2 = filter_intra_taps_3[tx_size][mode][2];
1619 :
1620 : k = 0;
1621 : mean = 0;
1622 : while (k < bs) {
1623 : mean = mean + (int)left[k];
1624 : mean = mean + (int)above[k];
1625 : k++;
1626 : }
1627 : mean = (mean + bs) / (2 * bs);
1628 :
1629 : for (r = 0; r < bs; ++r) preds[r + 1][0] = (int)left[r] - mean;
1630 :
1631 : for (c = 0; c < bs + 1; ++c) preds[0][c] = (int)above[c - 1] - mean;
1632 :
1633 : for (r = 1; r < bs + 1; ++r)
1634 : for (c = 1; c < bs + 1; ++c) {
1635 : ipred = c0 * preds[r - 1][c] + c1 * preds[r][c - 1] +
1636 : c2 * preds[r - 1][c - 1];
1637 : preds[r][c] = ROUND_POWER_OF_TWO_SIGNED(ipred, FILTER_INTRA_PREC_BITS);
1638 : preds[r][c] = clip_pixel_highbd(preds[r][c] + mean, bd) - mean;
1639 : }
1640 :
1641 : for (r = 0; r < bs; ++r) {
1642 : for (c = 0; c < bs; ++c)
1643 : dst[c] = clip_pixel_highbd(preds[r + 1][c + 1] + mean, bd);
1644 : dst += stride;
1645 : }
1646 : }
1647 : #else
1648 : static void highbd_filter_intra_predictors_4tap(uint16_t *dst, ptrdiff_t stride,
1649 : int bs, const uint16_t *above,
1650 : const uint16_t *left, int mode,
1651 : int bd) {
1652 : int k, r, c;
1653 : int mean, ipred;
1654 : #if CONFIG_TX64X64
1655 : int preds[65][129];
1656 : #else
1657 : int preds[33][65];
1658 : #endif // CONFIG_TX64X64
1659 : const TX_SIZE tx_size = get_txsize_from_blocklen(bs);
1660 : const int c0 = filter_intra_taps_4[tx_size][mode][0];
1661 : const int c1 = filter_intra_taps_4[tx_size][mode][1];
1662 : const int c2 = filter_intra_taps_4[tx_size][mode][2];
1663 : const int c3 = filter_intra_taps_4[tx_size][mode][3];
1664 :
1665 : k = 0;
1666 : mean = 0;
1667 : while (k < bs) {
1668 : mean = mean + (int)left[k];
1669 : mean = mean + (int)above[k];
1670 : k++;
1671 : }
1672 : mean = (mean + bs) / (2 * bs);
1673 :
1674 : for (r = 0; r < bs; ++r) preds[r + 1][0] = (int)left[r] - mean;
1675 :
1676 : for (c = 0; c < 2 * bs + 1; ++c) preds[0][c] = (int)above[c - 1] - mean;
1677 :
1678 : for (r = 1; r < bs + 1; ++r)
1679 : for (c = 1; c < 2 * bs + 1 - r; ++c) {
1680 : ipred = c0 * preds[r - 1][c] + c1 * preds[r][c - 1] +
1681 : c2 * preds[r - 1][c - 1] + c3 * preds[r - 1][c + 1];
1682 : preds[r][c] = ROUND_POWER_OF_TWO_SIGNED(ipred, FILTER_INTRA_PREC_BITS);
1683 : preds[r][c] = clip_pixel_highbd(preds[r][c] + mean, bd) - mean;
1684 : }
1685 :
1686 : for (r = 0; r < bs; ++r) {
1687 : for (c = 0; c < bs; ++c)
1688 : dst[c] = clip_pixel_highbd(preds[r + 1][c + 1] + mean, bd);
1689 : dst += stride;
1690 : }
1691 : }
1692 : #endif
1693 :
1694 : void av1_highbd_dc_filter_predictor_c(uint16_t *dst, ptrdiff_t stride, int bs,
1695 : const uint16_t *above,
1696 : const uint16_t *left, int bd) {
1697 : #if USE_3TAP_INTRA_FILTER
1698 : highbd_filter_intra_predictors_3tap(dst, stride, bs, above, left,
1699 : FILTER_DC_PRED, bd);
1700 : #else
1701 : highbd_filter_intra_predictors_4tap(dst, stride, bs, above, left,
1702 : FILTER_DC_PRED, bd);
1703 : #endif
1704 : }
1705 :
1706 : void av1_highbd_v_filter_predictor_c(uint16_t *dst, ptrdiff_t stride, int bs,
1707 : const uint16_t *above,
1708 : const uint16_t *left, int bd) {
1709 : #if USE_3TAP_INTRA_FILTER
1710 : highbd_filter_intra_predictors_3tap(dst, stride, bs, above, left,
1711 : FILTER_V_PRED, bd);
1712 : #else
1713 : highbd_filter_intra_predictors_4tap(dst, stride, bs, above, left,
1714 : FILTER_V_PRED, bd);
1715 : #endif
1716 : }
1717 :
1718 : void av1_highbd_h_filter_predictor_c(uint16_t *dst, ptrdiff_t stride, int bs,
1719 : const uint16_t *above,
1720 : const uint16_t *left, int bd) {
1721 : #if USE_3TAP_INTRA_FILTER
1722 : highbd_filter_intra_predictors_3tap(dst, stride, bs, above, left,
1723 : FILTER_H_PRED, bd);
1724 : #else
1725 : highbd_filter_intra_predictors_4tap(dst, stride, bs, above, left,
1726 : FILTER_H_PRED, bd);
1727 : #endif
1728 : }
1729 :
1730 : void av1_highbd_d45_filter_predictor_c(uint16_t *dst, ptrdiff_t stride, int bs,
1731 : const uint16_t *above,
1732 : const uint16_t *left, int bd) {
1733 : #if USE_3TAP_INTRA_FILTER
1734 : highbd_filter_intra_predictors_3tap(dst, stride, bs, above, left,
1735 : FILTER_D45_PRED, bd);
1736 : #else
1737 : highbd_filter_intra_predictors_4tap(dst, stride, bs, above, left,
1738 : FILTER_D45_PRED, bd);
1739 : #endif
1740 : }
1741 :
1742 : void av1_highbd_d135_filter_predictor_c(uint16_t *dst, ptrdiff_t stride, int bs,
1743 : const uint16_t *above,
1744 : const uint16_t *left, int bd) {
1745 : #if USE_3TAP_INTRA_FILTER
1746 : highbd_filter_intra_predictors_3tap(dst, stride, bs, above, left,
1747 : FILTER_D135_PRED, bd);
1748 : #else
1749 : highbd_filter_intra_predictors_4tap(dst, stride, bs, above, left,
1750 : FILTER_D135_PRED, bd);
1751 : #endif
1752 : }
1753 :
1754 : void av1_highbd_d117_filter_predictor_c(uint16_t *dst, ptrdiff_t stride, int bs,
1755 : const uint16_t *above,
1756 : const uint16_t *left, int bd) {
1757 : #if USE_3TAP_INTRA_FILTER
1758 : highbd_filter_intra_predictors_3tap(dst, stride, bs, above, left,
1759 : FILTER_D117_PRED, bd);
1760 : #else
1761 : highbd_filter_intra_predictors_4tap(dst, stride, bs, above, left,
1762 : FILTER_D117_PRED, bd);
1763 : #endif
1764 : }
1765 :
1766 : void av1_highbd_d153_filter_predictor_c(uint16_t *dst, ptrdiff_t stride, int bs,
1767 : const uint16_t *above,
1768 : const uint16_t *left, int bd) {
1769 : #if USE_3TAP_INTRA_FILTER
1770 : highbd_filter_intra_predictors_3tap(dst, stride, bs, above, left,
1771 : FILTER_D153_PRED, bd);
1772 : #else
1773 : highbd_filter_intra_predictors_4tap(dst, stride, bs, above, left,
1774 : FILTER_D153_PRED, bd);
1775 : #endif
1776 : }
1777 :
1778 : void av1_highbd_d207_filter_predictor_c(uint16_t *dst, ptrdiff_t stride, int bs,
1779 : const uint16_t *above,
1780 : const uint16_t *left, int bd) {
1781 : #if USE_3TAP_INTRA_FILTER
1782 : highbd_filter_intra_predictors_3tap(dst, stride, bs, above, left,
1783 : FILTER_D207_PRED, bd);
1784 : #else
1785 : highbd_filter_intra_predictors_4tap(dst, stride, bs, above, left,
1786 : FILTER_D207_PRED, bd);
1787 : #endif
1788 : }
1789 :
1790 : void av1_highbd_d63_filter_predictor_c(uint16_t *dst, ptrdiff_t stride, int bs,
1791 : const uint16_t *above,
1792 : const uint16_t *left, int bd) {
1793 : #if USE_3TAP_INTRA_FILTER
1794 : highbd_filter_intra_predictors_3tap(dst, stride, bs, above, left,
1795 : FILTER_D63_PRED, bd);
1796 : #else
1797 : highbd_filter_intra_predictors_4tap(dst, stride, bs, above, left,
1798 : FILTER_D63_PRED, bd);
1799 : #endif
1800 : }
1801 :
1802 : void av1_highbd_tm_filter_predictor_c(uint16_t *dst, ptrdiff_t stride, int bs,
1803 : const uint16_t *above,
1804 : const uint16_t *left, int bd) {
1805 : #if USE_3TAP_INTRA_FILTER
1806 : highbd_filter_intra_predictors_3tap(dst, stride, bs, above, left,
1807 : FILTER_TM_PRED, bd);
1808 : #else
1809 : highbd_filter_intra_predictors_4tap(dst, stride, bs, above, left,
1810 : FILTER_TM_PRED, bd);
1811 : #endif
1812 : }
1813 :
1814 : static void highbd_filter_intra_predictors(FILTER_INTRA_MODE mode,
1815 : uint16_t *dst, ptrdiff_t stride,
1816 : int bs, const uint16_t *above,
1817 : const uint16_t *left, int bd) {
1818 : switch (mode) {
1819 : case FILTER_DC_PRED:
1820 : av1_highbd_dc_filter_predictor(dst, stride, bs, above, left, bd);
1821 : break;
1822 : case FILTER_V_PRED:
1823 : av1_highbd_v_filter_predictor(dst, stride, bs, above, left, bd);
1824 : break;
1825 : case FILTER_H_PRED:
1826 : av1_highbd_h_filter_predictor(dst, stride, bs, above, left, bd);
1827 : break;
1828 : case FILTER_D45_PRED:
1829 : av1_highbd_d45_filter_predictor(dst, stride, bs, above, left, bd);
1830 : break;
1831 : case FILTER_D135_PRED:
1832 : av1_highbd_d135_filter_predictor(dst, stride, bs, above, left, bd);
1833 : break;
1834 : case FILTER_D117_PRED:
1835 : av1_highbd_d117_filter_predictor(dst, stride, bs, above, left, bd);
1836 : break;
1837 : case FILTER_D153_PRED:
1838 : av1_highbd_d153_filter_predictor(dst, stride, bs, above, left, bd);
1839 : break;
1840 : case FILTER_D207_PRED:
1841 : av1_highbd_d207_filter_predictor(dst, stride, bs, above, left, bd);
1842 : break;
1843 : case FILTER_D63_PRED:
1844 : av1_highbd_d63_filter_predictor(dst, stride, bs, above, left, bd);
1845 : break;
1846 : case FILTER_TM_PRED:
1847 : av1_highbd_tm_filter_predictor(dst, stride, bs, above, left, bd);
1848 : break;
1849 : default: assert(0);
1850 : }
1851 : }
1852 : #endif // CONFIG_HIGHBITDEPTH
1853 : #endif // CONFIG_FILTER_INTRA
1854 :
1855 : #if CONFIG_INTRA_EDGE
1856 : static int intra_edge_filter_strength(int bsz, int delta) {
1857 : const int d = abs(delta);
1858 : int strength = 0;
1859 :
1860 : if (bsz == 8) {
1861 : if (d < 8) {
1862 : strength = 0;
1863 : } else if (d < 32) {
1864 : strength = 1;
1865 : } else if (d < 90) {
1866 : strength = 3;
1867 : }
1868 : } else if (bsz == 16) {
1869 : if (d < 4) {
1870 : strength = 0;
1871 : } else if (d < 16) {
1872 : strength = 1;
1873 : } else if (d < 90) {
1874 : strength = 3;
1875 : }
1876 : } else if (bsz == 32) {
1877 : if (d < 16) {
1878 : strength = 2;
1879 : } else if (d < 90) {
1880 : strength = 3;
1881 : }
1882 : }
1883 :
1884 : return strength;
1885 : }
1886 :
1887 : static void filter_intra_edge(uint8_t *p, int sz, int strength) {
1888 : if (!strength) return;
1889 :
1890 : const int kernel[3][5] = {
1891 : { 0, 4, 8, 4, 0 }, { 0, 5, 6, 5, 0 }, { 2, 4, 4, 4, 2 }
1892 : };
1893 : const int filt = strength - 1;
1894 : uint8_t edge[129];
1895 :
1896 : memcpy(edge, p, sz * sizeof(*p));
1897 : for (int i = 1; i < sz - 1; i++) {
1898 : int s = 0;
1899 : for (int j = 0; j < 5; j++) {
1900 : int k = i - 2 + j;
1901 : k = (k < 0) ? 0 : k;
1902 : k = (k > sz - 1) ? sz - 1 : k;
1903 : s += edge[k] * kernel[filt][j];
1904 : }
1905 : s = (s + 8) >> 4;
1906 : p[i] = s;
1907 : }
1908 : }
1909 :
1910 : #if CONFIG_HIGHBITDEPTH
1911 : static void filter_intra_edge_high(uint16_t *p, int sz, int strength) {
1912 : if (!strength) return;
1913 :
1914 : const int kernel[3][5] = {
1915 : { 0, 4, 8, 4, 0 }, { 0, 5, 6, 5, 0 }, { 2, 4, 4, 4, 2 }
1916 : };
1917 : const int filt = strength - 1;
1918 : uint16_t edge[129];
1919 :
1920 : memcpy(edge, p, sz * sizeof(*p));
1921 : for (int i = 1; i < sz - 1; i++) {
1922 : int s = 0;
1923 : for (int j = 0; j < 5; j++) {
1924 : int k = i - 2 + j;
1925 : k = (k < 0) ? 0 : k;
1926 : k = (k > sz - 1) ? sz - 1 : k;
1927 : s += edge[k] * kernel[filt][j];
1928 : }
1929 : s = (s + 8) >> 4;
1930 : p[i] = s;
1931 : }
1932 : }
1933 : #endif // CONFIG_INTRA_EDGE
1934 : #endif // CONFIG_HIGHBITDEPTH
1935 :
1936 : #if CONFIG_HIGHBITDEPTH
1937 0 : static void build_intra_predictors_high(
1938 : const MACROBLOCKD *xd, const uint8_t *ref8, int ref_stride, uint8_t *dst8,
1939 : int dst_stride, PREDICTION_MODE mode, TX_SIZE tx_size, int n_top_px,
1940 : int n_topright_px, int n_left_px, int n_bottomleft_px, int plane) {
1941 : int i;
1942 0 : uint16_t *dst = CONVERT_TO_SHORTPTR(dst8);
1943 0 : uint16_t *ref = CONVERT_TO_SHORTPTR(ref8);
1944 : DECLARE_ALIGNED(16, uint16_t, left_data[MAX_TX_SIZE * 2 + 16]);
1945 : DECLARE_ALIGNED(16, uint16_t, above_data[MAX_TX_SIZE * 2 + 16]);
1946 0 : uint16_t *const above_row = above_data + 16;
1947 0 : uint16_t *const left_col = left_data + 16;
1948 0 : const int bs = tx_size_wide[tx_size];
1949 0 : int need_left = extend_modes[mode] & NEED_LEFT;
1950 0 : int need_above = extend_modes[mode] & NEED_ABOVE;
1951 0 : int need_above_left = extend_modes[mode] & NEED_ABOVELEFT;
1952 0 : const uint16_t *above_ref = ref - ref_stride;
1953 : #if CONFIG_EXT_INTRA
1954 0 : int p_angle = 0;
1955 0 : const int is_dr_mode = av1_is_directional_mode(mode, xd->mi[0]->mbmi.sb_type);
1956 : #endif // CONFIG_EXT_INTRA
1957 : #if CONFIG_FILTER_INTRA
1958 : const FILTER_INTRA_MODE_INFO *filter_intra_mode_info =
1959 : &xd->mi[0]->mbmi.filter_intra_mode_info;
1960 : const FILTER_INTRA_MODE filter_intra_mode =
1961 : filter_intra_mode_info->filter_intra_mode[plane != 0];
1962 : #endif // CONFIG_FILTER_INTRA
1963 0 : int base = 128 << (xd->bd - 8);
1964 0 : assert(tx_size_wide[tx_size] == tx_size_high[tx_size]);
1965 :
1966 : // base-1 base-1 base-1 .. base-1 base-1 base-1 base-1 base-1 base-1
1967 : // base+1 A B .. Y Z
1968 : // base+1 C D .. W X
1969 : // base+1 E F .. U V
1970 : // base+1 G H .. S T T T T T
1971 0 : aom_memset16(left_data, base + 1, sizeof(left_data) / sizeof(*left_data));
1972 :
1973 : #if CONFIG_EXT_INTRA
1974 0 : if (is_dr_mode) {
1975 0 : p_angle = mode_to_angle_map[mode] +
1976 0 : xd->mi[0]->mbmi.angle_delta[plane != 0] * ANGLE_STEP;
1977 0 : if (p_angle <= 90)
1978 0 : need_above = 1, need_left = 0, need_above_left = 1;
1979 0 : else if (p_angle < 180)
1980 0 : need_above = 1, need_left = 1, need_above_left = 1;
1981 : else
1982 0 : need_above = 0, need_left = 1, need_above_left = 1;
1983 : }
1984 : #endif // CONFIG_EXT_INTRA
1985 : #if CONFIG_FILTER_INTRA
1986 : if (filter_intra_mode_info->use_filter_intra_mode[plane != 0])
1987 : need_left = need_above = need_above_left = 1;
1988 : #endif // CONFIG_FILTER_INTRA
1989 :
1990 : (void)plane;
1991 0 : assert(n_top_px >= 0);
1992 0 : assert(n_topright_px >= 0);
1993 0 : assert(n_left_px >= 0);
1994 0 : assert(n_bottomleft_px >= 0);
1995 :
1996 0 : if ((!need_above && n_left_px == 0) || (!need_left && n_top_px == 0)) {
1997 : #if CONFIG_INTRA_EDGE
1998 : int val;
1999 : if (need_left) {
2000 : val = (n_top_px > 0) ? above_ref[0] : base + 1;
2001 : } else {
2002 : val = (n_left_px > 0) ? ref[-1] : base - 1;
2003 : }
2004 : #else
2005 0 : const int val = need_left ? base + 1 : base - 1;
2006 : #endif
2007 0 : for (i = 0; i < bs; ++i) {
2008 0 : aom_memset16(dst, val, bs);
2009 0 : dst += dst_stride;
2010 : }
2011 0 : return;
2012 : }
2013 :
2014 : // NEED_LEFT
2015 0 : if (need_left) {
2016 : #if CONFIG_EXT_INTRA || CONFIG_FILTER_INTRA
2017 0 : int need_bottom = !!(extend_modes[mode] & NEED_BOTTOMLEFT);
2018 : #if CONFIG_FILTER_INTRA
2019 : if (filter_intra_mode_info->use_filter_intra_mode[plane != 0])
2020 : need_bottom = 0;
2021 : #endif // CONFIG_FILTER_INTRA
2022 : #if CONFIG_EXT_INTRA
2023 0 : if (is_dr_mode) need_bottom = p_angle > 180;
2024 : #endif // CONFIG_EXT_INTRA
2025 : #else
2026 : const int need_bottom = !!(extend_modes[mode] & NEED_BOTTOMLEFT);
2027 : #endif // CONFIG_EXT_INTRA || CONFIG_FILTER_INTRA
2028 0 : i = 0;
2029 0 : if (n_left_px > 0) {
2030 0 : for (; i < n_left_px; i++) left_col[i] = ref[i * ref_stride - 1];
2031 0 : if (need_bottom && n_bottomleft_px > 0) {
2032 0 : assert(i == bs);
2033 0 : for (; i < bs + n_bottomleft_px; i++)
2034 0 : left_col[i] = ref[i * ref_stride - 1];
2035 : }
2036 0 : if (i < (bs << need_bottom))
2037 0 : aom_memset16(&left_col[i], left_col[i - 1], (bs << need_bottom) - i);
2038 : } else {
2039 : #if CONFIG_INTRA_EDGE
2040 : if (n_top_px > 0) {
2041 : aom_memset16(left_col, above_ref[0], bs << need_bottom);
2042 : } else {
2043 : #endif
2044 0 : aom_memset16(left_col, base + 1, bs << need_bottom);
2045 : #if CONFIG_INTRA_EDGE
2046 : }
2047 : #endif
2048 : }
2049 : }
2050 :
2051 : // NEED_ABOVE
2052 0 : if (need_above) {
2053 : #if CONFIG_EXT_INTRA || CONFIG_FILTER_INTRA
2054 0 : int need_right = !!(extend_modes[mode] & NEED_ABOVERIGHT);
2055 : #if CONFIG_FILTER_INTRA
2056 : if (filter_intra_mode_info->use_filter_intra_mode[plane != 0])
2057 : need_right = 1;
2058 : #endif // CONFIG_FILTER_INTRA
2059 : #if CONFIG_EXT_INTRA
2060 0 : if (is_dr_mode) need_right = p_angle < 90;
2061 : #endif // CONFIG_EXT_INTRA
2062 : #else
2063 : const int need_right = !!(extend_modes[mode] & NEED_ABOVERIGHT);
2064 : #endif // CONFIG_EXT_INTRA || CONFIG_FILTER_INTRA
2065 0 : if (n_top_px > 0) {
2066 0 : memcpy(above_row, above_ref, n_top_px * sizeof(above_ref[0]));
2067 0 : i = n_top_px;
2068 0 : if (need_right && n_topright_px > 0) {
2069 0 : assert(n_top_px == bs);
2070 0 : memcpy(above_row + bs, above_ref + bs,
2071 : n_topright_px * sizeof(above_ref[0]));
2072 0 : i += n_topright_px;
2073 : }
2074 0 : if (i < (bs << need_right))
2075 0 : aom_memset16(&above_row[i], above_row[i - 1], (bs << need_right) - i);
2076 : } else {
2077 : #if CONFIG_INTRA_EDGE
2078 : if (n_left_px > 0) {
2079 : aom_memset16(above_row, ref[-1], bs << need_right);
2080 : } else {
2081 : #endif
2082 0 : aom_memset16(above_row, base - 1, bs << need_right);
2083 : #if CONFIG_INTRA_EDGE
2084 : }
2085 : #endif
2086 : }
2087 : }
2088 :
2089 0 : if (need_above_left) {
2090 : #if CONFIG_INTRA_EDGE
2091 : if (n_top_px > 0 && n_left_px > 0) {
2092 : above_row[-1] = above_ref[-1];
2093 : } else if (n_top_px > 0) {
2094 : above_row[-1] = above_ref[0];
2095 : } else if (n_left_px > 0) {
2096 : above_row[-1] = ref[-1];
2097 : } else {
2098 : above_row[-1] = base;
2099 : }
2100 : #else
2101 0 : above_row[-1] =
2102 0 : n_top_px > 0 ? (n_left_px > 0 ? above_ref[-1] : base + 1) : base - 1;
2103 : #endif
2104 0 : left_col[-1] = above_row[-1];
2105 : }
2106 :
2107 : #if CONFIG_EXT_INTRA && CONFIG_INTRA_EDGE
2108 : if (is_dr_mode && p_angle != 90 && p_angle != 180) {
2109 : const int ab_le = need_above_left ? 1 : 0;
2110 : if (need_above && n_top_px > 0) {
2111 : const int strength = intra_edge_filter_strength(bs, p_angle - 90);
2112 : const int need_right = p_angle < 90;
2113 : const int n_px = n_top_px + ab_le + (need_right ? n_topright_px : 0);
2114 : filter_intra_edge_high(above_row - ab_le, n_px, strength);
2115 : }
2116 : if (need_left && n_left_px > 0) {
2117 : const int strength = intra_edge_filter_strength(bs, p_angle - 180);
2118 : const int need_bottom = p_angle > 180;
2119 : const int n_px = n_left_px + ab_le + (need_bottom ? n_bottomleft_px : 0);
2120 : filter_intra_edge_high(left_col - ab_le, n_px, strength);
2121 : }
2122 : }
2123 : #endif
2124 :
2125 : #if CONFIG_FILTER_INTRA
2126 : if (filter_intra_mode_info->use_filter_intra_mode[plane != 0]) {
2127 : highbd_filter_intra_predictors(filter_intra_mode, dst, dst_stride, bs,
2128 : above_row, left_col, xd->bd);
2129 : return;
2130 : }
2131 : #endif // CONFIG_FILTER_INTRA
2132 :
2133 : #if CONFIG_EXT_INTRA
2134 0 : if (is_dr_mode) {
2135 : #if CONFIG_INTRA_INTERP
2136 : INTRA_FILTER filter = INTRA_FILTER_LINEAR;
2137 : if (plane == 0 && av1_is_intra_filter_switchable(p_angle))
2138 : filter = xd->mi[0]->mbmi.intra_filter;
2139 : #endif // CONFIG_INTRA_INTERP
2140 0 : highbd_dr_predictor(dst, dst_stride, bs, above_row, left_col,
2141 : #if CONFIG_INTRA_INTERP
2142 : filter,
2143 : #endif // CONFIG_INTRA_INTERP
2144 : p_angle, xd->bd);
2145 0 : return;
2146 : }
2147 : #endif // CONFIG_EXT_INTRA
2148 :
2149 : // predict
2150 0 : if (mode == DC_PRED) {
2151 0 : dc_pred_high[n_left_px > 0][n_top_px > 0][tx_size](
2152 : dst, dst_stride, above_row, left_col, xd->bd);
2153 : } else {
2154 0 : pred_high[mode][tx_size](dst, dst_stride, above_row, left_col, xd->bd);
2155 : }
2156 : }
2157 : #endif // CONFIG_HIGHBITDEPTH
2158 :
2159 0 : static void build_intra_predictors(const MACROBLOCKD *xd, const uint8_t *ref,
2160 : int ref_stride, uint8_t *dst, int dst_stride,
2161 : PREDICTION_MODE mode, TX_SIZE tx_size,
2162 : int n_top_px, int n_topright_px,
2163 : int n_left_px, int n_bottomleft_px,
2164 : int plane) {
2165 : int i;
2166 0 : const uint8_t *above_ref = ref - ref_stride;
2167 : DECLARE_ALIGNED(16, uint8_t, left_data[MAX_TX_SIZE * 2 + 16]);
2168 : DECLARE_ALIGNED(16, uint8_t, above_data[MAX_TX_SIZE * 2 + 16]);
2169 0 : uint8_t *const above_row = above_data + 16;
2170 0 : uint8_t *const left_col = left_data + 16;
2171 0 : const int bs = tx_size_wide[tx_size];
2172 0 : int need_left = extend_modes[mode] & NEED_LEFT;
2173 0 : int need_above = extend_modes[mode] & NEED_ABOVE;
2174 0 : int need_above_left = extend_modes[mode] & NEED_ABOVELEFT;
2175 : #if CONFIG_EXT_INTRA
2176 0 : int p_angle = 0;
2177 0 : const MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
2178 0 : const int is_dr_mode = av1_is_directional_mode(mode, mbmi->sb_type);
2179 : #endif // CONFIG_EXT_INTRA
2180 : #if CONFIG_FILTER_INTRA
2181 : const FILTER_INTRA_MODE_INFO *filter_intra_mode_info =
2182 : &xd->mi[0]->mbmi.filter_intra_mode_info;
2183 : const FILTER_INTRA_MODE filter_intra_mode =
2184 : filter_intra_mode_info->filter_intra_mode[plane != 0];
2185 : #endif // CONFIG_FILTER_INTRA
2186 0 : assert(tx_size_wide[tx_size] == tx_size_high[tx_size]);
2187 :
2188 : // 127 127 127 .. 127 127 127 127 127 127
2189 : // 129 A B .. Y Z
2190 : // 129 C D .. W X
2191 : // 129 E F .. U V
2192 : // 129 G H .. S T T T T T
2193 : // ..
2194 0 : memset(left_data, 129, sizeof(left_data));
2195 :
2196 : #if CONFIG_EXT_INTRA
2197 0 : if (is_dr_mode) {
2198 0 : p_angle = mode_to_angle_map[mode] +
2199 0 : xd->mi[0]->mbmi.angle_delta[plane != 0] * ANGLE_STEP;
2200 0 : if (p_angle <= 90)
2201 0 : need_above = 1, need_left = 0, need_above_left = 1;
2202 0 : else if (p_angle < 180)
2203 0 : need_above = 1, need_left = 1, need_above_left = 1;
2204 : else
2205 0 : need_above = 0, need_left = 1, need_above_left = 1;
2206 : }
2207 : #endif // CONFIG_EXT_INTRA
2208 : #if CONFIG_FILTER_INTRA
2209 : if (filter_intra_mode_info->use_filter_intra_mode[plane != 0])
2210 : need_left = need_above = need_above_left = 1;
2211 : #endif // CONFIG_FILTER_INTRA
2212 :
2213 : (void)xd;
2214 : (void)plane;
2215 0 : assert(n_top_px >= 0);
2216 0 : assert(n_topright_px >= 0);
2217 0 : assert(n_left_px >= 0);
2218 0 : assert(n_bottomleft_px >= 0);
2219 :
2220 0 : if ((!need_above && n_left_px == 0) || (!need_left && n_top_px == 0)) {
2221 : #if CONFIG_INTRA_EDGE
2222 : int val;
2223 : if (need_left) {
2224 : val = (n_top_px > 0) ? above_ref[0] : 129;
2225 : } else {
2226 : val = (n_left_px > 0) ? ref[-1] : 127;
2227 : }
2228 : #else
2229 0 : const int val = need_left ? 129 : 127;
2230 : #endif
2231 0 : for (i = 0; i < bs; ++i) {
2232 0 : memset(dst, val, bs);
2233 0 : dst += dst_stride;
2234 : }
2235 0 : return;
2236 : }
2237 :
2238 : // NEED_LEFT
2239 0 : if (need_left) {
2240 : #if CONFIG_EXT_INTRA || CONFIG_FILTER_INTRA
2241 0 : int need_bottom = !!(extend_modes[mode] & NEED_BOTTOMLEFT);
2242 : #if CONFIG_FILTER_INTRA
2243 : if (filter_intra_mode_info->use_filter_intra_mode[plane != 0])
2244 : need_bottom = 0;
2245 : #endif // CONFIG_FILTER_INTRA
2246 : #if CONFIG_EXT_INTRA
2247 0 : if (is_dr_mode) need_bottom = p_angle > 180;
2248 : #endif // CONFIG_EXT_INTRA
2249 : #else
2250 : const int need_bottom = !!(extend_modes[mode] & NEED_BOTTOMLEFT);
2251 : #endif // CONFIG_EXT_INTRA || CONFIG_FILTER_INTRA
2252 0 : i = 0;
2253 0 : if (n_left_px > 0) {
2254 0 : for (; i < n_left_px; i++) left_col[i] = ref[i * ref_stride - 1];
2255 0 : if (need_bottom && n_bottomleft_px > 0) {
2256 0 : assert(i == bs);
2257 0 : for (; i < bs + n_bottomleft_px; i++)
2258 0 : left_col[i] = ref[i * ref_stride - 1];
2259 : }
2260 0 : if (i < (bs << need_bottom))
2261 0 : memset(&left_col[i], left_col[i - 1], (bs << need_bottom) - i);
2262 : } else {
2263 : #if CONFIG_INTRA_EDGE
2264 : if (n_top_px > 0) {
2265 : memset(left_col, above_ref[0], bs << need_bottom);
2266 : } else {
2267 : #endif
2268 0 : memset(left_col, 129, bs << need_bottom);
2269 : #if CONFIG_INTRA_EDGE
2270 : }
2271 : #endif
2272 : }
2273 : }
2274 :
2275 : // NEED_ABOVE
2276 0 : if (need_above) {
2277 : #if CONFIG_EXT_INTRA || CONFIG_FILTER_INTRA
2278 0 : int need_right = !!(extend_modes[mode] & NEED_ABOVERIGHT);
2279 : #if CONFIG_FILTER_INTRA
2280 : if (filter_intra_mode_info->use_filter_intra_mode[plane != 0])
2281 : need_right = 1;
2282 : #endif // CONFIG_FILTER_INTRA
2283 : #if CONFIG_EXT_INTRA
2284 0 : if (is_dr_mode) need_right = p_angle < 90;
2285 : #endif // CONFIG_EXT_INTRA
2286 : #else
2287 : const int need_right = !!(extend_modes[mode] & NEED_ABOVERIGHT);
2288 : #endif // CONFIG_EXT_INTRA || CONFIG_FITLER_INTRA
2289 0 : if (n_top_px > 0) {
2290 0 : memcpy(above_row, above_ref, n_top_px);
2291 0 : i = n_top_px;
2292 0 : if (need_right && n_topright_px > 0) {
2293 0 : assert(n_top_px == bs);
2294 0 : memcpy(above_row + bs, above_ref + bs, n_topright_px);
2295 0 : i += n_topright_px;
2296 : }
2297 0 : if (i < (bs << need_right))
2298 0 : memset(&above_row[i], above_row[i - 1], (bs << need_right) - i);
2299 : } else {
2300 : #if CONFIG_INTRA_EDGE
2301 : if (n_left_px > 0) {
2302 : memset(above_row, ref[-1], bs << need_right);
2303 : } else {
2304 : #endif
2305 0 : memset(above_row, 127, bs << need_right);
2306 : #if CONFIG_INTRA_EDGE
2307 : }
2308 : #endif
2309 : }
2310 : }
2311 :
2312 0 : if (need_above_left) {
2313 : #if CONFIG_INTRA_EDGE
2314 : if (n_top_px > 0 && n_left_px > 0) {
2315 : above_row[-1] = above_ref[-1];
2316 : } else if (n_top_px > 0) {
2317 : above_row[-1] = above_ref[0];
2318 : } else if (n_left_px > 0) {
2319 : above_row[-1] = ref[-1];
2320 : } else {
2321 : above_row[-1] = 128;
2322 : }
2323 : #else
2324 0 : above_row[-1] = n_top_px > 0 ? (n_left_px > 0 ? above_ref[-1] : 129) : 127;
2325 : #endif
2326 0 : left_col[-1] = above_row[-1];
2327 : }
2328 :
2329 : #if CONFIG_EXT_INTRA && CONFIG_INTRA_EDGE
2330 : if (is_dr_mode && p_angle != 90 && p_angle != 180) {
2331 : const int ab_le = need_above_left ? 1 : 0;
2332 : if (need_above && n_top_px > 0) {
2333 : const int strength = intra_edge_filter_strength(bs, p_angle - 90);
2334 : const int need_right = p_angle < 90;
2335 : const int n_px = n_top_px + ab_le + (need_right ? n_topright_px : 0);
2336 : filter_intra_edge(above_row - ab_le, n_px, strength);
2337 : }
2338 : if (need_left && n_left_px > 0) {
2339 : const int strength = intra_edge_filter_strength(bs, p_angle - 180);
2340 : const int need_bottom = p_angle > 180;
2341 : const int n_px = n_left_px + ab_le + (need_bottom ? n_bottomleft_px : 0);
2342 : filter_intra_edge(left_col - ab_le, n_px, strength);
2343 : }
2344 : }
2345 : #endif
2346 :
2347 : #if CONFIG_FILTER_INTRA
2348 : if (filter_intra_mode_info->use_filter_intra_mode[plane != 0]) {
2349 : filter_intra_predictors(filter_intra_mode, dst, dst_stride, bs, above_row,
2350 : left_col);
2351 : return;
2352 : }
2353 : #endif // CONFIG_FILTER_INTRA
2354 : #if CONFIG_EXT_INTRA
2355 0 : if (is_dr_mode) {
2356 : #if CONFIG_INTRA_INTERP
2357 : INTRA_FILTER filter = INTRA_FILTER_LINEAR;
2358 : if (plane == 0 && av1_is_intra_filter_switchable(p_angle))
2359 : filter = xd->mi[0]->mbmi.intra_filter;
2360 : #endif // CONFIG_INTRA_INTERP
2361 0 : dr_predictor(dst, dst_stride, tx_size, above_row, left_col,
2362 : #if CONFIG_INTRA_INTERP
2363 : filter,
2364 : #endif // CONFIG_INTRA_INTERP
2365 : p_angle);
2366 0 : return;
2367 : }
2368 : #endif // CONFIG_EXT_INTRA
2369 :
2370 : // predict
2371 0 : if (mode == DC_PRED) {
2372 : #if CONFIG_CFL
2373 : // CFL predict its own DC_PRED for Chromatic planes
2374 : if (plane == AOM_PLANE_Y) {
2375 : #endif
2376 0 : dc_pred[n_left_px > 0][n_top_px > 0][tx_size](dst, dst_stride, above_row,
2377 : left_col);
2378 : #if CONFIG_CFL
2379 : }
2380 : #endif
2381 :
2382 : } else {
2383 0 : pred[mode][tx_size](dst, dst_stride, above_row, left_col);
2384 : }
2385 : }
2386 :
2387 0 : static void predict_square_intra_block(const MACROBLOCKD *xd, int wpx, int hpx,
2388 : TX_SIZE tx_size, PREDICTION_MODE mode,
2389 : const uint8_t *ref, int ref_stride,
2390 : uint8_t *dst, int dst_stride,
2391 : int col_off, int row_off, int plane) {
2392 0 : BLOCK_SIZE bsize = xd->mi[0]->mbmi.sb_type;
2393 0 : const struct macroblockd_plane *const pd = &xd->plane[plane];
2394 0 : const int txw = tx_size_wide_unit[tx_size];
2395 : #if CONFIG_CB4X4 && CONFIG_CHROMA_SUB8X8
2396 0 : const int have_top = row_off || (pd->subsampling_y ? xd->chroma_up_available
2397 0 : : xd->up_available);
2398 0 : const int have_left =
2399 0 : col_off ||
2400 0 : (pd->subsampling_x ? xd->chroma_left_available : xd->left_available);
2401 : #else
2402 : const int have_top = row_off || xd->up_available;
2403 : const int have_left = col_off || xd->left_available;
2404 : #endif
2405 0 : const int x = col_off << tx_size_wide_log2[0];
2406 0 : const int y = row_off << tx_size_high_log2[0];
2407 0 : const int mi_row = -xd->mb_to_top_edge >> (3 + MI_SIZE_LOG2);
2408 0 : const int mi_col = -xd->mb_to_left_edge >> (3 + MI_SIZE_LOG2);
2409 0 : const int txwpx = tx_size_wide[tx_size];
2410 0 : const int txhpx = tx_size_high[tx_size];
2411 : #if CONFIG_CB4X4 && !CONFIG_CHROMA_2X2
2412 0 : const int xr_chr_offset = (pd->subsampling_x && bsize < BLOCK_8X8) ? 2 : 0;
2413 0 : const int yd_chr_offset = (pd->subsampling_y && bsize < BLOCK_8X8) ? 2 : 0;
2414 : #else
2415 : const int xr_chr_offset = 0;
2416 : const int yd_chr_offset = 0;
2417 : #endif
2418 :
2419 : // Distance between the right edge of this prediction block to
2420 : // the frame right edge
2421 0 : const int xr = (xd->mb_to_right_edge >> (3 + pd->subsampling_x)) +
2422 0 : (wpx - x - txwpx) - xr_chr_offset;
2423 : // Distance between the bottom edge of this prediction block to
2424 : // the frame bottom edge
2425 0 : const int yd = (xd->mb_to_bottom_edge >> (3 + pd->subsampling_y)) +
2426 0 : (hpx - y - txhpx) - yd_chr_offset;
2427 0 : const int right_available = mi_col + ((col_off + txw) << pd->subsampling_x >>
2428 0 : (MI_SIZE_LOG2 - tx_size_wide_log2[0])) <
2429 0 : xd->tile.mi_col_end;
2430 0 : const int bottom_available = (yd > 0);
2431 : #if CONFIG_EXT_PARTITION_TYPES
2432 : const PARTITION_TYPE partition = xd->mi[0]->mbmi.partition;
2433 : #endif
2434 :
2435 : #if CONFIG_CB4X4 && !CONFIG_CHROMA_2X2
2436 : // force 4x4 chroma component block size.
2437 0 : bsize = scale_chroma_bsize(bsize, pd->subsampling_x, pd->subsampling_y);
2438 : #endif
2439 :
2440 0 : const int have_top_right =
2441 0 : has_top_right(bsize, mi_row, mi_col, have_top, right_available,
2442 : #if CONFIG_EXT_PARTITION_TYPES
2443 : partition,
2444 : #endif
2445 : tx_size, row_off, col_off, pd->subsampling_x);
2446 0 : const int have_bottom_left =
2447 0 : has_bottom_left(bsize, mi_row, mi_col, bottom_available, have_left,
2448 : tx_size, row_off, col_off, pd->subsampling_y);
2449 0 : assert(txwpx == txhpx);
2450 :
2451 : #if CONFIG_PALETTE
2452 0 : if (xd->mi[0]->mbmi.palette_mode_info.palette_size[plane != 0] > 0) {
2453 0 : const int bs = tx_size_wide[tx_size];
2454 0 : const int stride = wpx;
2455 : int r, c;
2456 0 : const uint8_t *const map = xd->plane[plane != 0].color_index_map;
2457 0 : uint16_t *palette = xd->mi[0]->mbmi.palette_mode_info.palette_colors +
2458 : plane * PALETTE_MAX_SIZE;
2459 :
2460 : #if CONFIG_HIGHBITDEPTH
2461 0 : if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
2462 0 : uint16_t *dst16 = CONVERT_TO_SHORTPTR(dst);
2463 0 : for (r = 0; r < bs; ++r) {
2464 0 : for (c = 0; c < bs; ++c) {
2465 0 : dst16[r * dst_stride + c] = palette[map[(r + y) * stride + c + x]];
2466 : }
2467 : }
2468 : } else {
2469 : #endif // CONFIG_HIGHBITDEPTH
2470 0 : for (r = 0; r < bs; ++r) {
2471 0 : for (c = 0; c < bs; ++c) {
2472 0 : dst[r * dst_stride + c] =
2473 0 : (uint8_t)palette[map[(r + y) * stride + c + x]];
2474 : }
2475 : }
2476 : #if CONFIG_HIGHBITDEPTH
2477 : }
2478 : #endif // CONFIG_HIGHBITDEPTH
2479 0 : return;
2480 : }
2481 : #endif // CONFIG_PALETTE
2482 :
2483 : #if CONFIG_HIGHBITDEPTH
2484 0 : if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
2485 0 : build_intra_predictors_high(
2486 : xd, ref, ref_stride, dst, dst_stride, mode, tx_size,
2487 0 : have_top ? AOMMIN(txwpx, xr + txwpx) : 0,
2488 : have_top_right ? AOMMIN(txwpx, xr) : 0,
2489 0 : have_left ? AOMMIN(txhpx, yd + txhpx) : 0,
2490 : have_bottom_left ? AOMMIN(txhpx, yd) : 0, plane);
2491 0 : return;
2492 : }
2493 : #endif
2494 0 : build_intra_predictors(xd, ref, ref_stride, dst, dst_stride, mode, tx_size,
2495 0 : have_top ? AOMMIN(txwpx, xr + txwpx) : 0,
2496 : have_top_right ? AOMMIN(txwpx, xr) : 0,
2497 0 : have_left ? AOMMIN(txhpx, yd + txhpx) : 0,
2498 : have_bottom_left ? AOMMIN(txhpx, yd) : 0, plane);
2499 : }
2500 :
2501 0 : void av1_predict_intra_block_facade(MACROBLOCKD *xd, int plane, int block_idx,
2502 : int blk_col, int blk_row, TX_SIZE tx_size) {
2503 0 : struct macroblockd_plane *const pd = &xd->plane[plane];
2504 0 : const int dst_stride = pd->dst.stride;
2505 0 : uint8_t *dst =
2506 0 : &pd->dst.buf[(blk_row * dst_stride + blk_col) << tx_size_wide_log2[0]];
2507 0 : const MB_MODE_INFO *const mbmi = &xd->mi[0]->mbmi;
2508 0 : const int block_raster_idx =
2509 0 : av1_block_index_to_raster_order(tx_size, block_idx);
2510 0 : const PREDICTION_MODE mode =
2511 0 : (plane == 0) ? get_y_mode(xd->mi[0], block_raster_idx) : mbmi->uv_mode;
2512 0 : av1_predict_intra_block(xd, pd->width, pd->height, txsize_to_bsize[tx_size],
2513 : mode, dst, dst_stride, dst, dst_stride, blk_col,
2514 : blk_row, plane);
2515 : #if CONFIG_CFL
2516 : if (plane != AOM_PLANE_Y && mbmi->uv_mode == DC_PRED) {
2517 : if (plane == AOM_PLANE_U && blk_col == 0 && blk_row == 0) {
2518 : // Compute the block-level DC_PRED for both chromatic planes prior to
2519 : // processing the first chromatic plane in order to compute alpha_cb and
2520 : // alpha_cr. Note: This is not required on the decoder side because alpha
2521 : // is signaled.
2522 : cfl_dc_pred(xd, get_plane_block_size(block_idx, pd), tx_size);
2523 : }
2524 :
2525 : cfl_predict_block(
2526 : xd->cfl, dst, pd->dst.stride, blk_row, blk_col, tx_size,
2527 : xd->cfl->dc_pred[plane - 1],
2528 : cfl_idx_to_alpha(mbmi->cfl_alpha_idx, mbmi->cfl_alpha_signs[plane - 1],
2529 : plane - 1));
2530 : }
2531 : #endif
2532 0 : }
2533 :
2534 0 : void av1_predict_intra_block(const MACROBLOCKD *xd, int wpx, int hpx,
2535 : BLOCK_SIZE bsize, PREDICTION_MODE mode,
2536 : const uint8_t *ref, int ref_stride, uint8_t *dst,
2537 : int dst_stride, int col_off, int row_off,
2538 : int plane) {
2539 0 : const int block_width = block_size_wide[bsize];
2540 0 : const int block_height = block_size_high[bsize];
2541 0 : TX_SIZE tx_size = max_txsize_lookup[bsize];
2542 0 : assert(tx_size < TX_SIZES);
2543 0 : if (block_width == block_height) {
2544 0 : predict_square_intra_block(xd, wpx, hpx, tx_size, mode, ref, ref_stride,
2545 : dst, dst_stride, col_off, row_off, plane);
2546 : } else {
2547 : #if (CONFIG_RECT_TX && (CONFIG_VAR_TX || CONFIG_EXT_TX)) || (CONFIG_EXT_INTER)
2548 : #if CONFIG_HIGHBITDEPTH
2549 : uint16_t tmp16[MAX_SB_SIZE];
2550 : #endif
2551 : uint8_t tmp[MAX_SB_SIZE];
2552 0 : assert((block_width == wpx && block_height == hpx) ||
2553 : (block_width == (wpx >> 1) && block_height == hpx) ||
2554 : (block_width == wpx && block_height == (hpx >> 1)));
2555 :
2556 0 : if (block_width < block_height) {
2557 0 : assert(block_height == (block_width << 1));
2558 : // Predict the top square sub-block.
2559 0 : predict_square_intra_block(xd, wpx, hpx, tx_size, mode, ref, ref_stride,
2560 : dst, dst_stride, col_off, row_off, plane);
2561 : {
2562 0 : const int half_block_height = block_height >> 1;
2563 0 : const int half_block_height_unit =
2564 0 : half_block_height >> tx_size_wide_log2[0];
2565 : // Cast away const to modify 'ref' temporarily; will be restored later.
2566 0 : uint8_t *src_2 = (uint8_t *)ref + half_block_height * ref_stride;
2567 0 : uint8_t *dst_2 = dst + half_block_height * dst_stride;
2568 0 : const int row_off_2 = row_off + half_block_height_unit;
2569 : // Save the last row of top square sub-block as 'above' row for bottom
2570 : // square sub-block.
2571 0 : if (src_2 != dst_2 || ref_stride != dst_stride) {
2572 : #if CONFIG_HIGHBITDEPTH
2573 0 : if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
2574 0 : uint16_t *src_2_16 = CONVERT_TO_SHORTPTR(src_2);
2575 0 : uint16_t *dst_2_16 = CONVERT_TO_SHORTPTR(dst_2);
2576 0 : memcpy(tmp16, src_2_16 - ref_stride,
2577 : block_width * sizeof(*src_2_16));
2578 0 : memcpy(src_2_16 - ref_stride, dst_2_16 - dst_stride,
2579 : block_width * sizeof(*src_2_16));
2580 : } else {
2581 : #endif // CONFIG_HIGHBITDEPTH
2582 0 : memcpy(tmp, src_2 - ref_stride, block_width * sizeof(*src_2));
2583 0 : memcpy(src_2 - ref_stride, dst_2 - dst_stride,
2584 : block_width * sizeof(*src_2));
2585 : #if CONFIG_HIGHBITDEPTH
2586 : }
2587 : #endif // CONFIG_HIGHBITDEPTH
2588 : }
2589 : // Predict the bottom square sub-block.
2590 0 : predict_square_intra_block(xd, wpx, hpx, tx_size, mode, src_2,
2591 : ref_stride, dst_2, dst_stride, col_off,
2592 : row_off_2, plane);
2593 : // Restore the last row of top square sub-block.
2594 0 : if (src_2 != dst_2 || ref_stride != dst_stride) {
2595 : #if CONFIG_HIGHBITDEPTH
2596 0 : if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
2597 0 : uint16_t *src_2_16 = CONVERT_TO_SHORTPTR(src_2);
2598 0 : memcpy(src_2_16 - ref_stride, tmp16,
2599 : block_width * sizeof(*src_2_16));
2600 : } else {
2601 : #endif // CONFIG_HIGHBITDEPTH
2602 0 : memcpy(src_2 - ref_stride, tmp, block_width * sizeof(*src_2));
2603 : #if CONFIG_HIGHBITDEPTH
2604 : }
2605 : #endif // CONFIG_HIGHBITDEPTH
2606 : }
2607 : }
2608 : } else { // block_width > block_height
2609 0 : assert(block_width == (block_height << 1));
2610 : // Predict the left square sub-block
2611 0 : predict_square_intra_block(xd, wpx, hpx, tx_size, mode, ref, ref_stride,
2612 : dst, dst_stride, col_off, row_off, plane);
2613 : {
2614 : int i;
2615 0 : const int half_block_width = block_width >> 1;
2616 0 : const int half_block_width_unit =
2617 0 : half_block_width >> tx_size_wide_log2[0];
2618 : // Cast away const to modify 'ref' temporarily; will be restored later.
2619 0 : uint8_t *src_2 = (uint8_t *)ref + half_block_width;
2620 0 : uint8_t *dst_2 = dst + half_block_width;
2621 0 : const int col_off_2 = col_off + half_block_width_unit;
2622 : // Save the last column of left square sub-block as 'left' column for
2623 : // right square sub-block.
2624 0 : const int save_src = src_2 != dst_2 || ref_stride != dst_stride;
2625 0 : if (save_src) {
2626 : #if CONFIG_HIGHBITDEPTH
2627 0 : if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
2628 0 : uint16_t *src_2_16 = CONVERT_TO_SHORTPTR(src_2);
2629 0 : uint16_t *dst_2_16 = CONVERT_TO_SHORTPTR(dst_2);
2630 0 : for (i = 0; i < block_height; ++i) {
2631 0 : tmp16[i] = src_2_16[i * ref_stride - 1];
2632 0 : src_2_16[i * ref_stride - 1] = dst_2_16[i * dst_stride - 1];
2633 : }
2634 : } else {
2635 : #endif // CONFIG_HIGHBITDEPTH
2636 0 : for (i = 0; i < block_height; ++i) {
2637 0 : tmp[i] = src_2[i * ref_stride - 1];
2638 0 : src_2[i * ref_stride - 1] = dst_2[i * dst_stride - 1];
2639 : }
2640 : #if CONFIG_HIGHBITDEPTH
2641 : }
2642 : #endif // CONFIG_HIGHBITDEPTH
2643 : }
2644 : // Predict the right square sub-block.
2645 0 : predict_square_intra_block(xd, wpx, hpx, tx_size, mode, src_2,
2646 : ref_stride, dst_2, dst_stride, col_off_2,
2647 : row_off, plane);
2648 : // Restore the last column of left square sub-block.
2649 0 : if (save_src) {
2650 : #if CONFIG_HIGHBITDEPTH
2651 0 : if (xd->cur_buf->flags & YV12_FLAG_HIGHBITDEPTH) {
2652 0 : uint16_t *src_2_16 = CONVERT_TO_SHORTPTR(src_2);
2653 0 : for (i = 0; i < block_height; ++i) {
2654 0 : src_2_16[i * ref_stride - 1] = tmp16[i];
2655 : }
2656 : } else {
2657 : #endif // CONFIG_HIGHBITDEPTH
2658 0 : for (i = 0; i < block_height; ++i) {
2659 0 : src_2[i * ref_stride - 1] = tmp[i];
2660 : }
2661 : #if CONFIG_HIGHBITDEPTH
2662 : }
2663 : #endif // CONFIG_HIGHBITDEPTH
2664 : }
2665 : }
2666 : }
2667 : #else
2668 : assert(0);
2669 : #endif // (CONFIG_RECT_TX && (CONFIG_VAR_TX || CONFIG_EXT_TX)) ||
2670 : // (CONFIG_EXT_INTER)
2671 : }
2672 0 : }
2673 :
2674 0 : void av1_init_intra_predictors(void) {
2675 0 : once(av1_init_intra_predictors_internal);
2676 0 : }
|