65
66
for (i = (start); i < (start) + (length); i++) \
66
67
if (!IS_INTRA(-1, i)) \
67
68
ptr[i] = ptr[i - 1]
68
HEVCLocalContext *lc = &s->HEVClc;
69
HEVCLocalContext *lc = s->HEVClc;
70
71
int hshift = s->sps->hshift[c_idx];
71
72
int vshift = s->sps->vshift[c_idx];
72
73
int size = (1 << log2_size);
73
74
int size_in_luma = size << hshift;
74
int size_in_tbs = size_in_luma >> s->sps->log2_min_transform_block_size;
75
int size_in_tbs = size_in_luma >> s->sps->log2_min_tb_size;
75
76
int x = x0 >> hshift;
76
77
int y = y0 >> vshift;
77
int x_tb = x0 >> s->sps->log2_min_transform_block_size;
78
int y_tb = y0 >> s->sps->log2_min_transform_block_size;
78
int x_tb = x0 >> s->sps->log2_min_tb_size;
79
int y_tb = y0 >> s->sps->log2_min_tb_size;
79
80
int cur_tb_addr = MIN_TB_ADDR_ZS(x_tb, y_tb);
81
82
ptrdiff_t stride = s->frame->linesize[c_idx] / sizeof(pixel);
82
83
pixel *src = (pixel*)s->frame->data[c_idx] + x + y * stride;
84
int pic_width_in_min_pu = PU(s->sps->width);
85
int min_pu_width = s->sps->min_pu_width;
86
87
enum IntraPredMode mode = c_idx ? lc->pu.intra_pred_mode_c :
87
88
lc->tu.cur_intra_pred_mode;
92
93
pixel filtered_top_array[2 * MAX_TB_SIZE + 1];
94
95
pixel *left = left_array + 1;
95
pixel *top = top_array + 1;
96
pixel *top = top_array + 1;
96
97
pixel *filtered_left = filtered_left_array + 1;
97
pixel *filtered_top = filtered_top_array + 1;
98
pixel *filtered_top = filtered_top_array + 1;
99
100
int cand_bottom_left = lc->na.cand_bottom_left && cur_tb_addr > MIN_TB_ADDR_ZS(x_tb - 1, y_tb + size_in_tbs);
100
101
int cand_left = lc->na.cand_left;
110
111
if (s->pps->constrained_intra_pred_flag == 1) {
111
112
int size_in_luma_pu = PU(size_in_luma);
112
int on_pu_edge_x = !(x0 & ((1 << s->sps->log2_min_pu_size) - 1));
113
int on_pu_edge_y = !(y0 & ((1 << s->sps->log2_min_pu_size) - 1));
113
int on_pu_edge_x = !(x0 & ((1 << s->sps->log2_min_pu_size) - 1));
114
int on_pu_edge_y = !(y0 & ((1 << s->sps->log2_min_pu_size) - 1));
115
if (!size_in_luma_pu)
115
116
size_in_luma_pu++;
116
117
if (cand_bottom_left == 1 && on_pu_edge_x) {
117
118
int x_left_pu = PU(x0 - 1);
118
119
int y_bottom_pu = PU(y0 + size_in_luma);
120
int max = FFMIN(size_in_luma_pu, s->sps->min_pu_height - y_bottom_pu);
119
121
cand_bottom_left = 0;
120
for(i = 0; i < size_in_luma_pu; i++)
122
for (i = 0; i < max; i++)
121
123
cand_bottom_left |= MVF(x_left_pu, y_bottom_pu + i).is_intra;
123
125
if (cand_left == 1 && on_pu_edge_x) {
124
126
int x_left_pu = PU(x0 - 1);
125
127
int y_left_pu = PU(y0);
128
int max = FFMIN(size_in_luma_pu, s->sps->min_pu_height - y_left_pu);
127
for(i = 0; i < size_in_luma_pu; i++)
130
for (i = 0; i < max; i++)
128
131
cand_left |= MVF(x_left_pu, y_left_pu + i).is_intra;
130
133
if (cand_up_left == 1) {
135
138
if (cand_up == 1 && on_pu_edge_y) {
136
139
int x_top_pu = PU(x0);
137
140
int y_top_pu = PU(y0 - 1);
141
int max = FFMIN(size_in_luma_pu, s->sps->min_pu_width - x_top_pu);
139
for(i = 0; i < size_in_luma_pu; i++)
143
for (i = 0; i < max; i++)
140
144
cand_up |= MVF(x_top_pu + i, y_top_pu).is_intra;
142
146
if (cand_up_right == 1 && on_pu_edge_y) {
143
147
int y_top_pu = PU(y0 - 1);
144
148
int x_right_pu = PU(x0 + size_in_luma);
149
int max = FFMIN(size_in_luma_pu, s->sps->min_pu_width - x_right_pu);
145
150
cand_up_right = 0;
146
for(i = 0; i < size_in_luma_pu; i++)
151
for (i = 0; i < max; i++)
147
152
cand_up_right |= MVF(x_right_pu + i, y_top_pu).is_intra;
149
154
for (i = 0; i < 2 * MAX_TB_SIZE; i++) {
154
159
if (cand_bottom_left) {
155
160
for (i = size + bottom_left_size; i < (size << 1); i++)
156
if (IS_INTRA(-1, size + bottom_left_size - 1) || !s->pps->constrained_intra_pred_flag)
161
if (IS_INTRA(-1, size + bottom_left_size - 1) ||
162
!s->pps->constrained_intra_pred_flag)
157
163
left[i] = POS(-1, size + bottom_left_size - 1);
158
164
for (i = size + bottom_left_size - 1; i >= size; i--)
159
165
if (IS_INTRA(-1, i) || !s->pps->constrained_intra_pred_flag)
174
180
top[i] = POS(i, -1);
175
181
if (cand_up_right) {
176
182
for (i = size + top_right_size; i < (size << 1); i++)
177
if (IS_INTRA(size + top_right_size - 1, -1) || !s->pps->constrained_intra_pred_flag)
183
if (IS_INTRA(size + top_right_size - 1, -1) ||
184
!s->pps->constrained_intra_pred_flag)
178
185
top[i] = POS(size + top_right_size - 1, -1);
179
186
for (i = size + top_right_size - 1; i >= size; i--)
180
187
if (IS_INTRA(i, -1) || !s->pps->constrained_intra_pred_flag)
197
204
size : (s->sps->height - y0) >> vshift;
199
206
if (cand_bottom_left || cand_left || cand_up_left) {
200
while (j>-1 && !IS_INTRA(-1, j)) j--;
207
while (j > -1 && !IS_INTRA(-1, j))
201
209
if (!IS_INTRA(-1, j)) {
203
while(j < size_max_x && !IS_INTRA(j, -1)) j++;
204
EXTEND_LEFT_CIP(top, j, j+1);
211
while (j < size_max_x && !IS_INTRA(j, -1))
213
EXTEND_LEFT_CIP(top, j, j + 1);
205
214
left[-1] = top[-1];
210
while (j < size_max_x && !IS_INTRA(j, -1)) j++;
219
while (j < size_max_x && !IS_INTRA(j, -1))
212
EXTEND_LEFT_CIP(top, j, j+1);
223
EXTEND_LEFT_CIP(top, j, j + 1);
225
EXTEND_LEFT_CIP(top, j, j);
213
228
left[-1] = top[-1];
216
231
if (cand_bottom_left || cand_left) {
217
EXTEND_DOWN_CIP(left, j, size_max_y-j);
232
EXTEND_DOWN_CIP(left, j, size_max_y - j);
219
234
if (!cand_left) {
220
235
EXTEND_DOWN(left, 0, size);
225
240
if (x0 != 0 && y0 != 0) {
226
241
EXTEND_UP_CIP(left, size_max_y - 1, size_max_y);
227
} else if( x0 == 0) {
242
} else if (x0 == 0) {
228
243
EXTEND_UP_CIP_0(left, size_max_y - 1, size_max_y);
230
EXTEND_UP_CIP(left, size_max_y - 1, size_max_y-1);
245
EXTEND_UP_CIP(left, size_max_y - 1, size_max_y - 1);
232
247
top[-1] = left[-1];
246
261
left[-1] = top[0];
247
262
EXTEND_DOWN(left, 0, 2 * size);
248
263
cand_up_left = 1;
250
265
} else if (cand_up_right) {
251
266
EXTEND_LEFT(top, size, size);
252
267
left[-1] = top[0];
253
EXTEND_DOWN(left ,0 , 2 * size);
268
EXTEND_DOWN(left, 0, 2 * size);
255
270
cand_up_left = 1;
257
272
} else { // No samples available
258
273
top[0] = left[-1] = (1 << (BIT_DEPTH - 1));
259
274
EXTEND_RIGHT(top, 1, 2 * size - 1);
278
293
top[-1] = left[-1];
280
#undef EXTEND_LEFT_CIP
281
#undef EXTEND_RIGHT_CIP
283
#undef EXTEND_DOWN_CIP
292
#undef MIN_TB_ADDR_ZS
294
295
// Filtering process
295
296
if (c_idx == 0 && mode != INTRA_DC && size != 4) {
296
297
int intra_hor_ver_dist_thresh[] = { 7, 1, 0 };
297
int min_dist_vert_hor = FFMIN(FFABS((int)mode - 26),
298
FFABS((int)mode - 10));
298
int min_dist_vert_hor = FFMIN(FFABS((int)(mode - 26U)),
299
FFABS((int)(mode - 10U)));
299
300
if (min_dist_vert_hor > intra_hor_ver_dist_thresh[log2_size - 3]) {
300
301
int threshold = 1 << (BIT_DEPTH - 5);
301
302
if (s->sps->sps_strong_intra_smoothing_enable_flag &&
302
303
log2_size == 5 &&
303
FFABS(top[-1] + top[63] - 2 * top[31]) < threshold &&
304
FFABS(top[-1] + top[63] - 2 * top[31]) < threshold &&
304
305
FFABS(left[-1] + left[63] - 2 * left[31]) < threshold) {
305
306
// We can't just overwrite values in top because it could be
306
307
// a pointer into src
335
335
case INTRA_PLANAR:
336
s->hpc.pred_planar[log2_size - 2]((uint8_t*)src, (uint8_t*)top,
337
(uint8_t*)left, stride);
336
s->hpc.pred_planar[log2_size - 2]((uint8_t *)src, (uint8_t *)top,
337
(uint8_t *)left, stride);
340
s->hpc.pred_dc((uint8_t*)src, (uint8_t*)top,
341
(uint8_t*)left, stride, log2_size, c_idx);
340
s->hpc.pred_dc((uint8_t *)src, (uint8_t *)top,
341
(uint8_t *)left, stride, log2_size, c_idx);
344
s->hpc.pred_angular[log2_size - 2]((uint8_t*)src, (uint8_t*)top,
345
(uint8_t*)left, stride, c_idx, mode);
344
s->hpc.pred_angular[log2_size - 2]((uint8_t *)src, (uint8_t *)top,
345
(uint8_t *)left, stride, c_idx,
352
353
ptrdiff_t stride)
355
pixel *src = (pixel*)_src;
356
const pixel *top = (const pixel*)_top;
357
const pixel *left = (const pixel*)_left;
356
pixel *src = (pixel *)_src;
357
const pixel *top = (const pixel *)_top;
358
const pixel *left = (const pixel *)_left;
358
359
for (y = 0; y < 4; y++)
359
360
for (x = 0; x < 4; x++)
360
POS(x, y) = ((3 - x) * left[y] + (x + 1) * top[4] +
361
(3 - y) * top[x] + (y + 1) * left[4] + 4) >> 3;
361
POS(x, y) = ((3 - x) * left[y] + (x + 1) * top[4] +
362
(3 - y) * top[x] + (y + 1) * left[4] + 4) >> 3;
364
365
static void FUNC(pred_planar_1)(uint8_t *_src, const uint8_t *_top,
365
366
const uint8_t *_left, ptrdiff_t stride)
368
pixel *src = (pixel*)_src;
369
const pixel *top = (const pixel*)_top;
370
const pixel *left = (const pixel*)_left;
369
pixel *src = (pixel *)_src;
370
const pixel *top = (const pixel *)_top;
371
const pixel *left = (const pixel *)_left;
371
372
for (y = 0; y < 8; y++)
372
373
for (x = 0; x < 8; x++)
373
POS(x, y) = ((7 - x) * left[y] + (x + 1) * top[8] +
374
(7 - y) * top[x] + (y + 1) * left[8] + 8) >> 4;
374
POS(x, y) = ((7 - x) * left[y] + (x + 1) * top[8] +
375
(7 - y) * top[x] + (y + 1) * left[8] + 8) >> 4;
377
378
static void FUNC(pred_planar_2)(uint8_t *_src, const uint8_t *_top,
378
379
const uint8_t *_left, ptrdiff_t stride)
381
pixel *src = (pixel*)_src;
382
const pixel *top = (const pixel*)_top;
383
const pixel *left = (const pixel*)_left;
382
pixel *src = (pixel *)_src;
383
const pixel *top = (const pixel *)_top;
384
const pixel *left = (const pixel *)_left;
384
385
for (y = 0; y < 16; y++)
385
386
for (x = 0; x < 16; x++)
386
POS(x, y) = ((15 - x) * left[y] + (x + 1) * top[16] +
387
(15 - y) * top[x] + (y + 1) * left[16] + 16) >> 5;
387
POS(x, y) = ((15 - x) * left[y] + (x + 1) * top[16] +
388
(15 - y) * top[x] + (y + 1) * left[16] + 16) >> 5;
390
391
static void FUNC(pred_planar_3)(uint8_t *_src, const uint8_t *_top,
391
392
const uint8_t *_left, ptrdiff_t stride)
394
pixel *src = (pixel*)_src;
395
const pixel *top = (const pixel*)_top;
396
const pixel *left = (const pixel*)_left;
395
pixel *src = (pixel *)_src;
396
const pixel *top = (const pixel *)_top;
397
const pixel *left = (const pixel *)_left;
397
398
for (y = 0; y < 32; y++)
398
399
for (x = 0; x < 32; x++)
399
POS(x, y) = ((31 - x) * left[y] + (x + 1) * top[32] +
400
(31 - y) * top[x] + (y + 1) * left[32] + 32) >> 6;
400
POS(x, y) = ((31 - x) * left[y] + (x + 1) * top[32] +
401
(31 - y) * top[x] + (y + 1) * left[32] + 32) >> 6;
403
404
static void FUNC(pred_dc)(uint8_t *_src, const uint8_t *_top,
405
406
ptrdiff_t stride, int log2_size, int c_idx)
408
int size = (1 << log2_size);
409
pixel *src = (pixel*)_src;
410
const pixel *top = (const pixel*)_top;
411
const pixel *left = (const pixel*)_left;
409
int size = (1 << log2_size);
410
pixel *src = (pixel *)_src;
411
const pixel *top = (const pixel *)_top;
412
const pixel *left = (const pixel *)_left;
414
415
for (i = 0; i < size; i++)
415
416
dc += left[i] + top[i];
423
424
AV_WN4PA(&POS(j * 4, i), a);
425
426
if (c_idx == 0 && size < 32) {
426
POS(0, 0) = (left[0] + 2 * dc + top[0] + 2) >> 2;
427
POS(0, 0) = (left[0] + 2 * dc + top[0] + 2) >> 2;
427
428
for (x = 1; x < size; x++)
428
429
POS(x, 0) = (top[x] + 3 * dc + 2) >> 2;
429
430
for (y = 1; y < size; y++)
438
439
int mode, int size)
441
pixel *src = (pixel*)_src;
442
const pixel *top = (const pixel*)_top;
443
const pixel *left = (const pixel*)_left;
442
pixel *src = (pixel *)_src;
443
const pixel *top = (const pixel *)_top;
444
const pixel *left = (const pixel *)_left;
445
446
static const int intra_pred_angle[] = {
446
32, 26, 21, 17, 13, 9, 5, 2, 0, -2, -5, -9, -13, -17, -21, -26, -32,
447
-26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32
447
32, 26, 21, 17, 13, 9, 5, 2, 0, -2, -5, -9, -13, -17, -21, -26, -32,
448
-26, -21, -17, -13, -9, -5, -2, 0, 2, 5, 9, 13, 17, 21, 26, 32
449
450
static const int inv_angle[] = {
450
451
-4096, -1638, -910, -630, -482, -390, -315, -256, -315, -390, -482,