2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #include "./vpx_config.h"
12 #include "./vpx_dsp_rtcd.h"
13 #include "vp10/common/loopfilter.h"
14 #include "vp10/common/onyxc_int.h"
15 #include "vp10/common/reconinter.h"
16 #include "vpx_dsp/vpx_dsp_common.h"
17 #include "vpx_mem/vpx_mem.h"
18 #include "vpx_ports/mem.h"
20 #include "vp10/common/seg_common.h"
22 // 64 bit masks for left transform size. Each 1 represents a position where
23 // we should apply a loop filter across the left border of an 8x8 block
26 // In the case of TX_16X16-> ( in low order byte first we end up with
27 // a mask that looks like this
38 // A loopfilter should be applied to every other 8x8 horizontally.
39 static const uint64_t left_64x64_txform_mask[TX_SIZES]= {
40 0xffffffffffffffffULL, // TX_4X4
41 0xffffffffffffffffULL, // TX_8x8
42 0x5555555555555555ULL, // TX_16x16
43 0x1111111111111111ULL, // TX_32x32
46 // 64 bit masks for above transform size. Each 1 represents a position where
47 // we should apply a loop filter across the top border of an 8x8 block
50 // In the case of TX_32x32 -> ( in low order byte first we end up with
51 // a mask that looks like this
62 // A loopfilter should be applied to every other 4 the row vertically.
63 static const uint64_t above_64x64_txform_mask[TX_SIZES]= {
64 0xffffffffffffffffULL, // TX_4X4
65 0xffffffffffffffffULL, // TX_8x8
66 0x00ff00ff00ff00ffULL, // TX_16x16
67 0x000000ff000000ffULL, // TX_32x32
70 // 64 bit masks for prediction sizes (left). Each 1 represents a position
71 // where left border of an 8x8 block. These are aligned to the right most
72 // appropriate bit, and then shifted into place.
74 // In the case of TX_16x32 -> ( low order byte first ) we end up with
75 // a mask that looks like this :
85 static const uint64_t left_prediction_mask[BLOCK_SIZES] = {
86 0x0000000000000001ULL, // BLOCK_4X4,
87 0x0000000000000001ULL, // BLOCK_4X8,
88 0x0000000000000001ULL, // BLOCK_8X4,
89 0x0000000000000001ULL, // BLOCK_8X8,
90 0x0000000000000101ULL, // BLOCK_8X16,
91 0x0000000000000001ULL, // BLOCK_16X8,
92 0x0000000000000101ULL, // BLOCK_16X16,
93 0x0000000001010101ULL, // BLOCK_16X32,
94 0x0000000000000101ULL, // BLOCK_32X16,
95 0x0000000001010101ULL, // BLOCK_32X32,
96 0x0101010101010101ULL, // BLOCK_32X64,
97 0x0000000001010101ULL, // BLOCK_64X32,
98 0x0101010101010101ULL, // BLOCK_64X64
101 // 64 bit mask to shift and set for each prediction size.
102 static const uint64_t above_prediction_mask[BLOCK_SIZES] = {
103 0x0000000000000001ULL, // BLOCK_4X4
104 0x0000000000000001ULL, // BLOCK_4X8
105 0x0000000000000001ULL, // BLOCK_8X4
106 0x0000000000000001ULL, // BLOCK_8X8
107 0x0000000000000001ULL, // BLOCK_8X16,
108 0x0000000000000003ULL, // BLOCK_16X8
109 0x0000000000000003ULL, // BLOCK_16X16
110 0x0000000000000003ULL, // BLOCK_16X32,
111 0x000000000000000fULL, // BLOCK_32X16,
112 0x000000000000000fULL, // BLOCK_32X32,
113 0x000000000000000fULL, // BLOCK_32X64,
114 0x00000000000000ffULL, // BLOCK_64X32,
115 0x00000000000000ffULL, // BLOCK_64X64
117 // 64 bit mask to shift and set for each prediction size. A bit is set for
118 // each 8x8 block that would be in the left most block of the given block
119 // size in the 64x64 block.
120 static const uint64_t size_mask[BLOCK_SIZES] = {
121 0x0000000000000001ULL, // BLOCK_4X4
122 0x0000000000000001ULL, // BLOCK_4X8
123 0x0000000000000001ULL, // BLOCK_8X4
124 0x0000000000000001ULL, // BLOCK_8X8
125 0x0000000000000101ULL, // BLOCK_8X16,
126 0x0000000000000003ULL, // BLOCK_16X8
127 0x0000000000000303ULL, // BLOCK_16X16
128 0x0000000003030303ULL, // BLOCK_16X32,
129 0x0000000000000f0fULL, // BLOCK_32X16,
130 0x000000000f0f0f0fULL, // BLOCK_32X32,
131 0x0f0f0f0f0f0f0f0fULL, // BLOCK_32X64,
132 0x00000000ffffffffULL, // BLOCK_64X32,
133 0xffffffffffffffffULL, // BLOCK_64X64
136 // These are used for masking the left and above borders.
137 static const uint64_t left_border = 0x1111111111111111ULL;
138 static const uint64_t above_border = 0x000000ff000000ffULL;
140 // 16 bit masks for uv transform sizes.
141 static const uint16_t left_64x64_txform_mask_uv[TX_SIZES]= {
148 static const uint16_t above_64x64_txform_mask_uv[TX_SIZES]= {
155 // 16 bit left mask to shift and set for each uv prediction size.
156 static const uint16_t left_prediction_mask_uv[BLOCK_SIZES] = {
157 0x0001, // BLOCK_4X4,
158 0x0001, // BLOCK_4X8,
159 0x0001, // BLOCK_8X4,
160 0x0001, // BLOCK_8X8,
161 0x0001, // BLOCK_8X16,
162 0x0001, // BLOCK_16X8,
163 0x0001, // BLOCK_16X16,
164 0x0011, // BLOCK_16X32,
165 0x0001, // BLOCK_32X16,
166 0x0011, // BLOCK_32X32,
167 0x1111, // BLOCK_32X64
168 0x0011, // BLOCK_64X32,
169 0x1111, // BLOCK_64X64
171 // 16 bit above mask to shift and set for uv each prediction size.
172 static const uint16_t above_prediction_mask_uv[BLOCK_SIZES] = {
177 0x0001, // BLOCK_8X16,
178 0x0001, // BLOCK_16X8
179 0x0001, // BLOCK_16X16
180 0x0001, // BLOCK_16X32,
181 0x0003, // BLOCK_32X16,
182 0x0003, // BLOCK_32X32,
183 0x0003, // BLOCK_32X64,
184 0x000f, // BLOCK_64X32,
185 0x000f, // BLOCK_64X64
188 // 64 bit mask to shift and set for each uv prediction size
189 static const uint16_t size_mask_uv[BLOCK_SIZES] = {
194 0x0001, // BLOCK_8X16,
195 0x0001, // BLOCK_16X8
196 0x0001, // BLOCK_16X16
197 0x0011, // BLOCK_16X32,
198 0x0003, // BLOCK_32X16,
199 0x0033, // BLOCK_32X32,
200 0x3333, // BLOCK_32X64,
201 0x00ff, // BLOCK_64X32,
202 0xffff, // BLOCK_64X64
204 static const uint16_t left_border_uv = 0x1111;
205 static const uint16_t above_border_uv = 0x000f;
207 static const int mode_lf_lut[MB_MODE_COUNT] = {
208 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // INTRA_MODES
209 1, 1, 0, 1 // INTER_MODES (ZEROMV == 0)
212 static void update_sharpness(loop_filter_info_n *lfi, int sharpness_lvl) {
215 // For each possible value for the loop filter fill out limits
216 for (lvl = 0; lvl <= MAX_LOOP_FILTER; lvl++) {
217 // Set loop filter parameters that control sharpness.
218 int block_inside_limit = lvl >> ((sharpness_lvl > 0) + (sharpness_lvl > 4));
220 if (sharpness_lvl > 0) {
221 if (block_inside_limit > (9 - sharpness_lvl))
222 block_inside_limit = (9 - sharpness_lvl);
225 if (block_inside_limit < 1)
226 block_inside_limit = 1;
228 memset(lfi->lfthr[lvl].lim, block_inside_limit, SIMD_WIDTH);
229 memset(lfi->lfthr[lvl].mblim, (2 * (lvl + 2) + block_inside_limit),
234 static uint8_t get_filter_level(const loop_filter_info_n *lfi_n,
235 const MB_MODE_INFO *mbmi) {
236 return lfi_n->lvl[mbmi->segment_id][mbmi->ref_frame[0]]
237 [mode_lf_lut[mbmi->mode]];
240 void vp10_loop_filter_init(VP10_COMMON *cm) {
241 loop_filter_info_n *lfi = &cm->lf_info;
242 struct loopfilter *lf = &cm->lf;
245 // init limits for given sharpness
246 update_sharpness(lfi, lf->sharpness_level);
247 lf->last_sharpness_level = lf->sharpness_level;
249 // init hev threshold const vectors
250 for (lvl = 0; lvl <= MAX_LOOP_FILTER; lvl++)
251 memset(lfi->lfthr[lvl].hev_thr, (lvl >> 4), SIMD_WIDTH);
254 void vp10_loop_filter_frame_init(VP10_COMMON *cm, int default_filt_lvl) {
256 // n_shift is the multiplier for lf_deltas
257 // the multiplier is 1 for when filter_lvl is between 0 and 31;
258 // 2 when filter_lvl is between 32 and 63
259 const int scale = 1 << (default_filt_lvl >> 5);
260 loop_filter_info_n *const lfi = &cm->lf_info;
261 struct loopfilter *const lf = &cm->lf;
262 const struct segmentation *const seg = &cm->seg;
264 // update limits if sharpness has changed
265 if (lf->last_sharpness_level != lf->sharpness_level) {
266 update_sharpness(lfi, lf->sharpness_level);
267 lf->last_sharpness_level = lf->sharpness_level;
270 for (seg_id = 0; seg_id < MAX_SEGMENTS; seg_id++) {
271 int lvl_seg = default_filt_lvl;
272 if (segfeature_active(seg, seg_id, SEG_LVL_ALT_LF)) {
273 const int data = get_segdata(seg, seg_id, SEG_LVL_ALT_LF);
274 lvl_seg = clamp(seg->abs_delta == SEGMENT_ABSDATA ?
275 data : default_filt_lvl + data,
279 if (!lf->mode_ref_delta_enabled) {
280 // we could get rid of this if we assume that deltas are set to
281 // zero when not in use; encoder always uses deltas
282 memset(lfi->lvl[seg_id], lvl_seg, sizeof(lfi->lvl[seg_id]));
285 const int intra_lvl = lvl_seg + lf->ref_deltas[INTRA_FRAME] * scale;
286 lfi->lvl[seg_id][INTRA_FRAME][0] = clamp(intra_lvl, 0, MAX_LOOP_FILTER);
288 for (ref = LAST_FRAME; ref < MAX_REF_FRAMES; ++ref) {
289 for (mode = 0; mode < MAX_MODE_LF_DELTAS; ++mode) {
290 const int inter_lvl = lvl_seg + lf->ref_deltas[ref] * scale
291 + lf->mode_deltas[mode] * scale;
292 lfi->lvl[seg_id][ref][mode] = clamp(inter_lvl, 0, MAX_LOOP_FILTER);
299 static void filter_selectively_vert_row2(int subsampling_factor,
300 uint8_t *s, int pitch,
301 unsigned int mask_16x16_l,
302 unsigned int mask_8x8_l,
303 unsigned int mask_4x4_l,
304 unsigned int mask_4x4_int_l,
305 const loop_filter_info_n *lfi_n,
306 const uint8_t *lfl) {
307 const int mask_shift = subsampling_factor ? 4 : 8;
308 const int mask_cutoff = subsampling_factor ? 0xf : 0xff;
309 const int lfl_forward = subsampling_factor ? 4 : 8;
311 unsigned int mask_16x16_0 = mask_16x16_l & mask_cutoff;
312 unsigned int mask_8x8_0 = mask_8x8_l & mask_cutoff;
313 unsigned int mask_4x4_0 = mask_4x4_l & mask_cutoff;
314 unsigned int mask_4x4_int_0 = mask_4x4_int_l & mask_cutoff;
315 unsigned int mask_16x16_1 = (mask_16x16_l >> mask_shift) & mask_cutoff;
316 unsigned int mask_8x8_1 = (mask_8x8_l >> mask_shift) & mask_cutoff;
317 unsigned int mask_4x4_1 = (mask_4x4_l >> mask_shift) & mask_cutoff;
318 unsigned int mask_4x4_int_1 = (mask_4x4_int_l >> mask_shift) & mask_cutoff;
321 for (mask = mask_16x16_0 | mask_8x8_0 | mask_4x4_0 | mask_4x4_int_0 |
322 mask_16x16_1 | mask_8x8_1 | mask_4x4_1 | mask_4x4_int_1;
324 const loop_filter_thresh *lfi0 = lfi_n->lfthr + *lfl;
325 const loop_filter_thresh *lfi1 = lfi_n->lfthr + *(lfl + lfl_forward);
327 // TODO(yunqingwang): count in loopfilter functions should be removed.
329 if ((mask_16x16_0 | mask_16x16_1) & 1) {
330 if ((mask_16x16_0 & mask_16x16_1) & 1) {
331 vpx_lpf_vertical_16_dual(s, pitch, lfi0->mblim, lfi0->lim,
333 } else if (mask_16x16_0 & 1) {
334 vpx_lpf_vertical_16(s, pitch, lfi0->mblim, lfi0->lim,
337 vpx_lpf_vertical_16(s + 8 *pitch, pitch, lfi1->mblim,
338 lfi1->lim, lfi1->hev_thr);
342 if ((mask_8x8_0 | mask_8x8_1) & 1) {
343 if ((mask_8x8_0 & mask_8x8_1) & 1) {
344 vpx_lpf_vertical_8_dual(s, pitch, lfi0->mblim, lfi0->lim,
345 lfi0->hev_thr, lfi1->mblim, lfi1->lim,
347 } else if (mask_8x8_0 & 1) {
348 vpx_lpf_vertical_8(s, pitch, lfi0->mblim, lfi0->lim, lfi0->hev_thr);
350 vpx_lpf_vertical_8(s + 8 * pitch, pitch, lfi1->mblim, lfi1->lim,
355 if ((mask_4x4_0 | mask_4x4_1) & 1) {
356 if ((mask_4x4_0 & mask_4x4_1) & 1) {
357 vpx_lpf_vertical_4_dual(s, pitch, lfi0->mblim, lfi0->lim,
358 lfi0->hev_thr, lfi1->mblim, lfi1->lim,
360 } else if (mask_4x4_0 & 1) {
361 vpx_lpf_vertical_4(s, pitch, lfi0->mblim, lfi0->lim, lfi0->hev_thr);
363 vpx_lpf_vertical_4(s + 8 * pitch, pitch, lfi1->mblim, lfi1->lim,
368 if ((mask_4x4_int_0 | mask_4x4_int_1) & 1) {
369 if ((mask_4x4_int_0 & mask_4x4_int_1) & 1) {
370 vpx_lpf_vertical_4_dual(s + 4, pitch, lfi0->mblim, lfi0->lim,
371 lfi0->hev_thr, lfi1->mblim, lfi1->lim,
373 } else if (mask_4x4_int_0 & 1) {
374 vpx_lpf_vertical_4(s + 4, pitch, lfi0->mblim, lfi0->lim,
377 vpx_lpf_vertical_4(s + 8 * pitch + 4, pitch, lfi1->mblim, lfi1->lim,
388 mask_4x4_int_0 >>= 1;
392 mask_4x4_int_1 >>= 1;
396 #if CONFIG_VP9_HIGHBITDEPTH
397 static void highbd_filter_selectively_vert_row2(int subsampling_factor,
398 uint16_t *s, int pitch,
399 unsigned int mask_16x16_l,
400 unsigned int mask_8x8_l,
401 unsigned int mask_4x4_l,
402 unsigned int mask_4x4_int_l,
403 const loop_filter_info_n *lfi_n,
404 const uint8_t *lfl, int bd) {
405 const int mask_shift = subsampling_factor ? 4 : 8;
406 const int mask_cutoff = subsampling_factor ? 0xf : 0xff;
407 const int lfl_forward = subsampling_factor ? 4 : 8;
409 unsigned int mask_16x16_0 = mask_16x16_l & mask_cutoff;
410 unsigned int mask_8x8_0 = mask_8x8_l & mask_cutoff;
411 unsigned int mask_4x4_0 = mask_4x4_l & mask_cutoff;
412 unsigned int mask_4x4_int_0 = mask_4x4_int_l & mask_cutoff;
413 unsigned int mask_16x16_1 = (mask_16x16_l >> mask_shift) & mask_cutoff;
414 unsigned int mask_8x8_1 = (mask_8x8_l >> mask_shift) & mask_cutoff;
415 unsigned int mask_4x4_1 = (mask_4x4_l >> mask_shift) & mask_cutoff;
416 unsigned int mask_4x4_int_1 = (mask_4x4_int_l >> mask_shift) & mask_cutoff;
419 for (mask = mask_16x16_0 | mask_8x8_0 | mask_4x4_0 | mask_4x4_int_0 |
420 mask_16x16_1 | mask_8x8_1 | mask_4x4_1 | mask_4x4_int_1;
422 const loop_filter_thresh *lfi0 = lfi_n->lfthr + *lfl;
423 const loop_filter_thresh *lfi1 = lfi_n->lfthr + *(lfl + lfl_forward);
425 // TODO(yunqingwang): count in loopfilter functions should be removed.
427 if ((mask_16x16_0 | mask_16x16_1) & 1) {
428 if ((mask_16x16_0 & mask_16x16_1) & 1) {
429 vpx_highbd_lpf_vertical_16_dual(s, pitch, lfi0->mblim, lfi0->lim,
431 } else if (mask_16x16_0 & 1) {
432 vpx_highbd_lpf_vertical_16(s, pitch, lfi0->mblim, lfi0->lim,
435 vpx_highbd_lpf_vertical_16(s + 8 *pitch, pitch, lfi1->mblim,
436 lfi1->lim, lfi1->hev_thr, bd);
440 if ((mask_8x8_0 | mask_8x8_1) & 1) {
441 if ((mask_8x8_0 & mask_8x8_1) & 1) {
442 vpx_highbd_lpf_vertical_8_dual(s, pitch, lfi0->mblim, lfi0->lim,
443 lfi0->hev_thr, lfi1->mblim, lfi1->lim,
445 } else if (mask_8x8_0 & 1) {
446 vpx_highbd_lpf_vertical_8(s, pitch, lfi0->mblim, lfi0->lim,
447 lfi0->hev_thr, 1, bd);
449 vpx_highbd_lpf_vertical_8(s + 8 * pitch, pitch, lfi1->mblim,
450 lfi1->lim, lfi1->hev_thr, 1, bd);
454 if ((mask_4x4_0 | mask_4x4_1) & 1) {
455 if ((mask_4x4_0 & mask_4x4_1) & 1) {
456 vpx_highbd_lpf_vertical_4_dual(s, pitch, lfi0->mblim, lfi0->lim,
457 lfi0->hev_thr, lfi1->mblim, lfi1->lim,
459 } else if (mask_4x4_0 & 1) {
460 vpx_highbd_lpf_vertical_4(s, pitch, lfi0->mblim, lfi0->lim,
461 lfi0->hev_thr, 1, bd);
463 vpx_highbd_lpf_vertical_4(s + 8 * pitch, pitch, lfi1->mblim,
464 lfi1->lim, lfi1->hev_thr, 1, bd);
468 if ((mask_4x4_int_0 | mask_4x4_int_1) & 1) {
469 if ((mask_4x4_int_0 & mask_4x4_int_1) & 1) {
470 vpx_highbd_lpf_vertical_4_dual(s + 4, pitch, lfi0->mblim, lfi0->lim,
471 lfi0->hev_thr, lfi1->mblim, lfi1->lim,
473 } else if (mask_4x4_int_0 & 1) {
474 vpx_highbd_lpf_vertical_4(s + 4, pitch, lfi0->mblim, lfi0->lim,
475 lfi0->hev_thr, 1, bd);
477 vpx_highbd_lpf_vertical_4(s + 8 * pitch + 4, pitch, lfi1->mblim,
478 lfi1->lim, lfi1->hev_thr, 1, bd);
488 mask_4x4_int_0 >>= 1;
492 mask_4x4_int_1 >>= 1;
495 #endif // CONFIG_VP9_HIGHBITDEPTH
497 static void filter_selectively_horiz(uint8_t *s, int pitch,
498 unsigned int mask_16x16,
499 unsigned int mask_8x8,
500 unsigned int mask_4x4,
501 unsigned int mask_4x4_int,
502 const loop_filter_info_n *lfi_n,
503 const uint8_t *lfl) {
507 for (mask = mask_16x16 | mask_8x8 | mask_4x4 | mask_4x4_int;
508 mask; mask >>= count) {
509 const loop_filter_thresh *lfi = lfi_n->lfthr + *lfl;
513 if (mask_16x16 & 1) {
514 if ((mask_16x16 & 3) == 3) {
515 vpx_lpf_horizontal_16(s, pitch, lfi->mblim, lfi->lim,
519 vpx_lpf_horizontal_16(s, pitch, lfi->mblim, lfi->lim,
522 } else if (mask_8x8 & 1) {
523 if ((mask_8x8 & 3) == 3) {
524 // Next block's thresholds.
525 const loop_filter_thresh *lfin = lfi_n->lfthr + *(lfl + 1);
527 vpx_lpf_horizontal_8_dual(s, pitch, lfi->mblim, lfi->lim,
528 lfi->hev_thr, lfin->mblim, lfin->lim,
531 if ((mask_4x4_int & 3) == 3) {
532 vpx_lpf_horizontal_4_dual(s + 4 * pitch, pitch, lfi->mblim,
533 lfi->lim, lfi->hev_thr, lfin->mblim,
534 lfin->lim, lfin->hev_thr);
536 if (mask_4x4_int & 1)
537 vpx_lpf_horizontal_4(s + 4 * pitch, pitch, lfi->mblim, lfi->lim,
539 else if (mask_4x4_int & 2)
540 vpx_lpf_horizontal_4(s + 8 + 4 * pitch, pitch, lfin->mblim,
541 lfin->lim, lfin->hev_thr, 1);
545 vpx_lpf_horizontal_8(s, pitch, lfi->mblim, lfi->lim, lfi->hev_thr, 1);
547 if (mask_4x4_int & 1)
548 vpx_lpf_horizontal_4(s + 4 * pitch, pitch, lfi->mblim, lfi->lim,
551 } else if (mask_4x4 & 1) {
552 if ((mask_4x4 & 3) == 3) {
553 // Next block's thresholds.
554 const loop_filter_thresh *lfin = lfi_n->lfthr + *(lfl + 1);
556 vpx_lpf_horizontal_4_dual(s, pitch, lfi->mblim, lfi->lim,
557 lfi->hev_thr, lfin->mblim, lfin->lim,
559 if ((mask_4x4_int & 3) == 3) {
560 vpx_lpf_horizontal_4_dual(s + 4 * pitch, pitch, lfi->mblim,
561 lfi->lim, lfi->hev_thr, lfin->mblim,
562 lfin->lim, lfin->hev_thr);
564 if (mask_4x4_int & 1)
565 vpx_lpf_horizontal_4(s + 4 * pitch, pitch, lfi->mblim, lfi->lim,
567 else if (mask_4x4_int & 2)
568 vpx_lpf_horizontal_4(s + 8 + 4 * pitch, pitch, lfin->mblim,
569 lfin->lim, lfin->hev_thr, 1);
573 vpx_lpf_horizontal_4(s, pitch, lfi->mblim, lfi->lim, lfi->hev_thr, 1);
575 if (mask_4x4_int & 1)
576 vpx_lpf_horizontal_4(s + 4 * pitch, pitch, lfi->mblim, lfi->lim,
579 } else if (mask_4x4_int & 1) {
580 vpx_lpf_horizontal_4(s + 4 * pitch, pitch, lfi->mblim, lfi->lim,
586 mask_16x16 >>= count;
589 mask_4x4_int >>= count;
593 #if CONFIG_VP9_HIGHBITDEPTH
594 static void highbd_filter_selectively_horiz(uint16_t *s, int pitch,
595 unsigned int mask_16x16,
596 unsigned int mask_8x8,
597 unsigned int mask_4x4,
598 unsigned int mask_4x4_int,
599 const loop_filter_info_n *lfi_n,
600 const uint8_t *lfl, int bd) {
604 for (mask = mask_16x16 | mask_8x8 | mask_4x4 | mask_4x4_int;
605 mask; mask >>= count) {
606 const loop_filter_thresh *lfi = lfi_n->lfthr + *lfl;
610 if (mask_16x16 & 1) {
611 if ((mask_16x16 & 3) == 3) {
612 vpx_highbd_lpf_horizontal_16(s, pitch, lfi->mblim, lfi->lim,
613 lfi->hev_thr, 2, bd);
616 vpx_highbd_lpf_horizontal_16(s, pitch, lfi->mblim, lfi->lim,
617 lfi->hev_thr, 1, bd);
619 } else if (mask_8x8 & 1) {
620 if ((mask_8x8 & 3) == 3) {
621 // Next block's thresholds.
622 const loop_filter_thresh *lfin = lfi_n->lfthr + *(lfl + 1);
624 vpx_highbd_lpf_horizontal_8_dual(s, pitch, lfi->mblim, lfi->lim,
625 lfi->hev_thr, lfin->mblim, lfin->lim,
628 if ((mask_4x4_int & 3) == 3) {
629 vpx_highbd_lpf_horizontal_4_dual(s + 4 * pitch, pitch, lfi->mblim,
630 lfi->lim, lfi->hev_thr,
631 lfin->mblim, lfin->lim,
634 if (mask_4x4_int & 1) {
635 vpx_highbd_lpf_horizontal_4(s + 4 * pitch, pitch, lfi->mblim,
636 lfi->lim, lfi->hev_thr, 1, bd);
637 } else if (mask_4x4_int & 2) {
638 vpx_highbd_lpf_horizontal_4(s + 8 + 4 * pitch, pitch, lfin->mblim,
639 lfin->lim, lfin->hev_thr, 1, bd);
644 vpx_highbd_lpf_horizontal_8(s, pitch, lfi->mblim, lfi->lim,
645 lfi->hev_thr, 1, bd);
647 if (mask_4x4_int & 1) {
648 vpx_highbd_lpf_horizontal_4(s + 4 * pitch, pitch, lfi->mblim,
649 lfi->lim, lfi->hev_thr, 1, bd);
652 } else if (mask_4x4 & 1) {
653 if ((mask_4x4 & 3) == 3) {
654 // Next block's thresholds.
655 const loop_filter_thresh *lfin = lfi_n->lfthr + *(lfl + 1);
657 vpx_highbd_lpf_horizontal_4_dual(s, pitch, lfi->mblim, lfi->lim,
658 lfi->hev_thr, lfin->mblim, lfin->lim,
660 if ((mask_4x4_int & 3) == 3) {
661 vpx_highbd_lpf_horizontal_4_dual(s + 4 * pitch, pitch, lfi->mblim,
662 lfi->lim, lfi->hev_thr,
663 lfin->mblim, lfin->lim,
666 if (mask_4x4_int & 1) {
667 vpx_highbd_lpf_horizontal_4(s + 4 * pitch, pitch, lfi->mblim,
668 lfi->lim, lfi->hev_thr, 1, bd);
669 } else if (mask_4x4_int & 2) {
670 vpx_highbd_lpf_horizontal_4(s + 8 + 4 * pitch, pitch, lfin->mblim,
671 lfin->lim, lfin->hev_thr, 1, bd);
676 vpx_highbd_lpf_horizontal_4(s, pitch, lfi->mblim, lfi->lim,
677 lfi->hev_thr, 1, bd);
679 if (mask_4x4_int & 1) {
680 vpx_highbd_lpf_horizontal_4(s + 4 * pitch, pitch, lfi->mblim,
681 lfi->lim, lfi->hev_thr, 1, bd);
684 } else if (mask_4x4_int & 1) {
685 vpx_highbd_lpf_horizontal_4(s + 4 * pitch, pitch, lfi->mblim, lfi->lim,
686 lfi->hev_thr, 1, bd);
691 mask_16x16 >>= count;
694 mask_4x4_int >>= count;
697 #endif // CONFIG_VP9_HIGHBITDEPTH
699 // This function ors into the current lfm structure, where to do loop
700 // filters for the specific mi we are looking at. It uses information
701 // including the block_size_type (32x16, 32x32, etc.), the transform size,
702 // whether there were any coefficients encoded, and the loop filter strength
703 // block we are currently looking at. Shift is used to position the
705 // TODO(JBB) Need another function for different resolution color..
706 static void build_masks(const loop_filter_info_n *const lfi_n,
707 const MODE_INFO *mi, const int shift_y,
709 LOOP_FILTER_MASK *lfm) {
710 const MB_MODE_INFO *mbmi = &mi->mbmi;
711 const BLOCK_SIZE block_size = mbmi->sb_type;
712 const TX_SIZE tx_size_y = mbmi->tx_size;
713 const TX_SIZE tx_size_uv = get_uv_tx_size_impl(tx_size_y, block_size, 1, 1);
714 const int filter_level = get_filter_level(lfi_n, mbmi);
715 uint64_t *const left_y = &lfm->left_y[tx_size_y];
716 uint64_t *const above_y = &lfm->above_y[tx_size_y];
717 uint64_t *const int_4x4_y = &lfm->int_4x4_y;
718 uint16_t *const left_uv = &lfm->left_uv[tx_size_uv];
719 uint16_t *const above_uv = &lfm->above_uv[tx_size_uv];
720 #if CONFIG_MISC_FIXES
721 uint16_t *const int_4x4_uv = &lfm->left_int_4x4_uv;
723 uint16_t *const int_4x4_uv = &lfm->int_4x4_uv;
727 // If filter level is 0 we don't loop filter.
731 const int w = num_8x8_blocks_wide_lookup[block_size];
732 const int h = num_8x8_blocks_high_lookup[block_size];
734 for (i = 0; i < h; i++) {
735 memset(&lfm->lfl_y[index], filter_level, w);
740 // These set 1 in the current block size for the block size edges.
741 // For instance if the block size is 32x16, we'll set:
747 // NOTE : In this example the low bit is left most ( 1000 ) is stored as
750 // U and V set things on a 16 bit scale.
752 *above_y |= above_prediction_mask[block_size] << shift_y;
753 *above_uv |= above_prediction_mask_uv[block_size] << shift_uv;
754 *left_y |= left_prediction_mask[block_size] << shift_y;
755 *left_uv |= left_prediction_mask_uv[block_size] << shift_uv;
757 // If the block has no coefficients and is not intra we skip applying
758 // the loop filter on block edges.
759 #if CONFIG_MISC_FIXES
760 if ((mbmi->skip || mbmi->has_no_coeffs) && is_inter_block(mbmi))
763 if (mbmi->skip && is_inter_block(mbmi))
767 // Here we are adding a mask for the transform size. The transform
768 // size mask is set to be correct for a 64x64 prediction block size. We
769 // mask to match the size of the block we are working on and then shift it
771 *above_y |= (size_mask[block_size] &
772 above_64x64_txform_mask[tx_size_y]) << shift_y;
773 *above_uv |= (size_mask_uv[block_size] &
774 above_64x64_txform_mask_uv[tx_size_uv]) << shift_uv;
776 *left_y |= (size_mask[block_size] &
777 left_64x64_txform_mask[tx_size_y]) << shift_y;
778 *left_uv |= (size_mask_uv[block_size] &
779 left_64x64_txform_mask_uv[tx_size_uv]) << shift_uv;
781 // Here we are trying to determine what to do with the internal 4x4 block
782 // boundaries. These differ from the 4x4 boundaries on the outside edge of
783 // an 8x8 in that the internal ones can be skipped and don't depend on
784 // the prediction block size.
785 if (tx_size_y == TX_4X4)
786 *int_4x4_y |= (size_mask[block_size] & 0xffffffffffffffffULL) << shift_y;
788 if (tx_size_uv == TX_4X4)
789 *int_4x4_uv |= (size_mask_uv[block_size] & 0xffff) << shift_uv;
792 // This function does the same thing as the one above with the exception that
793 // it only affects the y masks. It exists because for blocks < 16x16 in size,
794 // we only update u and v masks on the first block.
795 static void build_y_mask(const loop_filter_info_n *const lfi_n,
796 const MODE_INFO *mi, const int shift_y,
797 LOOP_FILTER_MASK *lfm) {
798 const MB_MODE_INFO *mbmi = &mi->mbmi;
799 const BLOCK_SIZE block_size = mbmi->sb_type;
800 const TX_SIZE tx_size_y = mbmi->tx_size;
801 const int filter_level = get_filter_level(lfi_n, mbmi);
802 uint64_t *const left_y = &lfm->left_y[tx_size_y];
803 uint64_t *const above_y = &lfm->above_y[tx_size_y];
804 uint64_t *const int_4x4_y = &lfm->int_4x4_y;
810 const int w = num_8x8_blocks_wide_lookup[block_size];
811 const int h = num_8x8_blocks_high_lookup[block_size];
813 for (i = 0; i < h; i++) {
814 memset(&lfm->lfl_y[index], filter_level, w);
819 *above_y |= above_prediction_mask[block_size] << shift_y;
820 *left_y |= left_prediction_mask[block_size] << shift_y;
822 #if CONFIG_MISC_FIXES
823 if ((mbmi->skip || mbmi->has_no_coeffs) && is_inter_block(mbmi))
826 if (mbmi->skip && is_inter_block(mbmi))
830 *above_y |= (size_mask[block_size] &
831 above_64x64_txform_mask[tx_size_y]) << shift_y;
833 *left_y |= (size_mask[block_size] &
834 left_64x64_txform_mask[tx_size_y]) << shift_y;
836 if (tx_size_y == TX_4X4)
837 *int_4x4_y |= (size_mask[block_size] & 0xffffffffffffffffULL) << shift_y;
840 // This function sets up the bit masks for the entire 64x64 region represented
841 // by mi_row, mi_col.
842 // TODO(JBB): This function only works for yv12.
843 void vp10_setup_mask(VP10_COMMON *const cm, const int mi_row, const int mi_col,
844 MODE_INFO **mi, const int mode_info_stride,
845 LOOP_FILTER_MASK *lfm) {
846 int idx_32, idx_16, idx_8;
847 const loop_filter_info_n *const lfi_n = &cm->lf_info;
848 MODE_INFO **mip = mi;
849 MODE_INFO **mip2 = mi;
851 // These are offsets to the next mi in the 64x64 block. It is what gets
852 // added to the mi ptr as we go through each loop. It helps us to avoid
853 // setting up special row and column counters for each index. The last step
854 // brings us out back to the starting position.
855 const int offset_32[] = {4, (mode_info_stride << 2) - 4, 4,
856 -(mode_info_stride << 2) - 4};
857 const int offset_16[] = {2, (mode_info_stride << 1) - 2, 2,
858 -(mode_info_stride << 1) - 2};
859 const int offset[] = {1, mode_info_stride - 1, 1, -mode_info_stride - 1};
861 // Following variables represent shifts to position the current block
862 // mask over the appropriate block. A shift of 36 to the left will move
863 // the bits for the final 32 by 32 block in the 64x64 up 4 rows and left
864 // 4 rows to the appropriate spot.
865 const int shift_32_y[] = {0, 4, 32, 36};
866 const int shift_16_y[] = {0, 2, 16, 18};
867 const int shift_8_y[] = {0, 1, 8, 9};
868 const int shift_32_uv[] = {0, 2, 8, 10};
869 const int shift_16_uv[] = {0, 1, 4, 5};
871 const int max_rows = (mi_row + MI_BLOCK_SIZE > cm->mi_rows ?
872 cm->mi_rows - mi_row : MI_BLOCK_SIZE);
873 const int max_cols = (mi_col + MI_BLOCK_SIZE > cm->mi_cols ?
874 cm->mi_cols - mi_col : MI_BLOCK_SIZE);
877 assert(mip[0] != NULL);
879 // TODO(jimbankoski): Try moving most of the following code into decode
880 // loop and storing lfm in the mbmi structure so that we don't have to go
881 // through the recursive loop structure multiple times.
882 switch (mip[0]->mbmi.sb_type) {
884 build_masks(lfi_n, mip[0] , 0, 0, lfm);
887 build_masks(lfi_n, mip[0], 0, 0, lfm);
888 mip2 = mip + mode_info_stride * 4;
891 build_masks(lfi_n, mip2[0], 32, 8, lfm);
894 build_masks(lfi_n, mip[0], 0, 0, lfm);
898 build_masks(lfi_n, mip2[0], 4, 2, lfm);
901 for (idx_32 = 0; idx_32 < 4; mip += offset_32[idx_32], ++idx_32) {
902 const int shift_y = shift_32_y[idx_32];
903 const int shift_uv = shift_32_uv[idx_32];
904 const int mi_32_col_offset = ((idx_32 & 1) << 2);
905 const int mi_32_row_offset = ((idx_32 >> 1) << 2);
906 if (mi_32_col_offset >= max_cols || mi_32_row_offset >= max_rows)
908 switch (mip[0]->mbmi.sb_type) {
910 build_masks(lfi_n, mip[0], shift_y, shift_uv, lfm);
913 build_masks(lfi_n, mip[0], shift_y, shift_uv, lfm);
914 if (mi_32_row_offset + 2 >= max_rows)
916 mip2 = mip + mode_info_stride * 2;
917 build_masks(lfi_n, mip2[0], shift_y + 16, shift_uv + 4, lfm);
920 build_masks(lfi_n, mip[0], shift_y, shift_uv, lfm);
921 if (mi_32_col_offset + 2 >= max_cols)
924 build_masks(lfi_n, mip2[0], shift_y + 2, shift_uv + 1, lfm);
927 for (idx_16 = 0; idx_16 < 4; mip += offset_16[idx_16], ++idx_16) {
928 const int shift_y = shift_32_y[idx_32] + shift_16_y[idx_16];
929 const int shift_uv = shift_32_uv[idx_32] + shift_16_uv[idx_16];
930 const int mi_16_col_offset = mi_32_col_offset +
932 const int mi_16_row_offset = mi_32_row_offset +
933 ((idx_16 >> 1) << 1);
935 if (mi_16_col_offset >= max_cols || mi_16_row_offset >= max_rows)
938 switch (mip[0]->mbmi.sb_type) {
940 build_masks(lfi_n, mip[0], shift_y, shift_uv, lfm);
943 build_masks(lfi_n, mip[0], shift_y, shift_uv, lfm);
944 if (mi_16_row_offset + 1 >= max_rows)
946 mip2 = mip + mode_info_stride;
947 build_y_mask(lfi_n, mip2[0], shift_y+8, lfm);
950 build_masks(lfi_n, mip[0], shift_y, shift_uv, lfm);
951 if (mi_16_col_offset +1 >= max_cols)
954 build_y_mask(lfi_n, mip2[0], shift_y+1, lfm);
957 const int shift_y = shift_32_y[idx_32] +
960 build_masks(lfi_n, mip[0], shift_y, shift_uv, lfm);
962 for (idx_8 = 1; idx_8 < 4; mip += offset[idx_8], ++idx_8) {
963 const int shift_y = shift_32_y[idx_32] +
966 const int mi_8_col_offset = mi_16_col_offset +
968 const int mi_8_row_offset = mi_16_row_offset +
971 if (mi_8_col_offset >= max_cols ||
972 mi_8_row_offset >= max_rows)
974 build_y_mask(lfi_n, mip[0], shift_y, lfm);
985 // The largest loopfilter we have is 16x16 so we use the 16x16 mask
986 // for 32x32 transforms also.
987 lfm->left_y[TX_16X16] |= lfm->left_y[TX_32X32];
988 lfm->above_y[TX_16X16] |= lfm->above_y[TX_32X32];
989 lfm->left_uv[TX_16X16] |= lfm->left_uv[TX_32X32];
990 lfm->above_uv[TX_16X16] |= lfm->above_uv[TX_32X32];
992 // We do at least 8 tap filter on every 32x32 even if the transform size
993 // is 4x4. So if the 4x4 is set on a border pixel add it to the 8x8 and
994 // remove it from the 4x4.
995 lfm->left_y[TX_8X8] |= lfm->left_y[TX_4X4] & left_border;
996 lfm->left_y[TX_4X4] &= ~left_border;
997 lfm->above_y[TX_8X8] |= lfm->above_y[TX_4X4] & above_border;
998 lfm->above_y[TX_4X4] &= ~above_border;
999 lfm->left_uv[TX_8X8] |= lfm->left_uv[TX_4X4] & left_border_uv;
1000 lfm->left_uv[TX_4X4] &= ~left_border_uv;
1001 lfm->above_uv[TX_8X8] |= lfm->above_uv[TX_4X4] & above_border_uv;
1002 lfm->above_uv[TX_4X4] &= ~above_border_uv;
1004 // We do some special edge handling.
1005 if (mi_row + MI_BLOCK_SIZE > cm->mi_rows) {
1006 const uint64_t rows = cm->mi_rows - mi_row;
1008 // Each pixel inside the border gets a 1,
1009 const uint64_t mask_y = (((uint64_t) 1 << (rows << 3)) - 1);
1010 const uint16_t mask_uv = (((uint16_t) 1 << (((rows + 1) >> 1) << 2)) - 1);
1012 // Remove values completely outside our border.
1013 for (i = 0; i < TX_32X32; i++) {
1014 lfm->left_y[i] &= mask_y;
1015 lfm->above_y[i] &= mask_y;
1016 lfm->left_uv[i] &= mask_uv;
1017 lfm->above_uv[i] &= mask_uv;
1019 lfm->int_4x4_y &= mask_y;
1020 #if CONFIG_MISC_FIXES
1021 lfm->above_int_4x4_uv = lfm->left_int_4x4_uv & mask_uv;
1023 lfm->int_4x4_uv &= mask_uv;
1026 // We don't apply a wide loop filter on the last uv block row. If set
1027 // apply the shorter one instead.
1029 lfm->above_uv[TX_8X8] |= lfm->above_uv[TX_16X16];
1030 lfm->above_uv[TX_16X16] = 0;
1033 lfm->above_uv[TX_8X8] |= lfm->above_uv[TX_16X16] & 0xff00;
1034 lfm->above_uv[TX_16X16] &= ~(lfm->above_uv[TX_16X16] & 0xff00);
1038 if (mi_col + MI_BLOCK_SIZE > cm->mi_cols) {
1039 const uint64_t columns = cm->mi_cols - mi_col;
1041 // Each pixel inside the border gets a 1, the multiply copies the border
1042 // to where we need it.
1043 const uint64_t mask_y = (((1 << columns) - 1)) * 0x0101010101010101ULL;
1044 const uint16_t mask_uv = ((1 << ((columns + 1) >> 1)) - 1) * 0x1111;
1046 // Internal edges are not applied on the last column of the image so
1047 // we mask 1 more for the internal edges
1048 const uint16_t mask_uv_int = ((1 << (columns >> 1)) - 1) * 0x1111;
1050 // Remove the bits outside the image edge.
1051 for (i = 0; i < TX_32X32; i++) {
1052 lfm->left_y[i] &= mask_y;
1053 lfm->above_y[i] &= mask_y;
1054 lfm->left_uv[i] &= mask_uv;
1055 lfm->above_uv[i] &= mask_uv;
1057 lfm->int_4x4_y &= mask_y;
1058 #if CONFIG_MISC_FIXES
1059 lfm->left_int_4x4_uv &= mask_uv_int;
1061 lfm->int_4x4_uv &= mask_uv_int;
1064 // We don't apply a wide loop filter on the last uv column. If set
1065 // apply the shorter one instead.
1067 lfm->left_uv[TX_8X8] |= lfm->left_uv[TX_16X16];
1068 lfm->left_uv[TX_16X16] = 0;
1071 lfm->left_uv[TX_8X8] |= (lfm->left_uv[TX_16X16] & 0xcccc);
1072 lfm->left_uv[TX_16X16] &= ~(lfm->left_uv[TX_16X16] & 0xcccc);
1075 // We don't apply a loop filter on the first column in the image, mask that
1078 for (i = 0; i < TX_32X32; i++) {
1079 lfm->left_y[i] &= 0xfefefefefefefefeULL;
1080 lfm->left_uv[i] &= 0xeeee;
1084 // Assert if we try to apply 2 different loop filters at the same position.
1085 assert(!(lfm->left_y[TX_16X16] & lfm->left_y[TX_8X8]));
1086 assert(!(lfm->left_y[TX_16X16] & lfm->left_y[TX_4X4]));
1087 assert(!(lfm->left_y[TX_8X8] & lfm->left_y[TX_4X4]));
1088 assert(!(lfm->int_4x4_y & lfm->left_y[TX_16X16]));
1089 assert(!(lfm->left_uv[TX_16X16]&lfm->left_uv[TX_8X8]));
1090 assert(!(lfm->left_uv[TX_16X16] & lfm->left_uv[TX_4X4]));
1091 assert(!(lfm->left_uv[TX_8X8] & lfm->left_uv[TX_4X4]));
1092 #if CONFIG_MISC_FIXES
1093 assert(!(lfm->left_int_4x4_uv & lfm->left_uv[TX_16X16]));
1095 assert(!(lfm->int_4x4_uv & lfm->left_uv[TX_16X16]));
1097 assert(!(lfm->above_y[TX_16X16] & lfm->above_y[TX_8X8]));
1098 assert(!(lfm->above_y[TX_16X16] & lfm->above_y[TX_4X4]));
1099 assert(!(lfm->above_y[TX_8X8] & lfm->above_y[TX_4X4]));
1100 assert(!(lfm->int_4x4_y & lfm->above_y[TX_16X16]));
1101 assert(!(lfm->above_uv[TX_16X16] & lfm->above_uv[TX_8X8]));
1102 assert(!(lfm->above_uv[TX_16X16] & lfm->above_uv[TX_4X4]));
1103 assert(!(lfm->above_uv[TX_8X8] & lfm->above_uv[TX_4X4]));
1104 #if CONFIG_MISC_FIXES
1105 assert(!(lfm->above_int_4x4_uv & lfm->above_uv[TX_16X16]));
1107 assert(!(lfm->int_4x4_uv & lfm->above_uv[TX_16X16]));
1111 static void filter_selectively_vert(uint8_t *s, int pitch,
1112 unsigned int mask_16x16,
1113 unsigned int mask_8x8,
1114 unsigned int mask_4x4,
1115 unsigned int mask_4x4_int,
1116 const loop_filter_info_n *lfi_n,
1117 const uint8_t *lfl) {
1120 for (mask = mask_16x16 | mask_8x8 | mask_4x4 | mask_4x4_int;
1122 const loop_filter_thresh *lfi = lfi_n->lfthr + *lfl;
1125 if (mask_16x16 & 1) {
1126 vpx_lpf_vertical_16(s, pitch, lfi->mblim, lfi->lim, lfi->hev_thr);
1127 } else if (mask_8x8 & 1) {
1128 vpx_lpf_vertical_8(s, pitch, lfi->mblim, lfi->lim, lfi->hev_thr);
1129 } else if (mask_4x4 & 1) {
1130 vpx_lpf_vertical_4(s, pitch, lfi->mblim, lfi->lim, lfi->hev_thr);
1133 if (mask_4x4_int & 1)
1134 vpx_lpf_vertical_4(s + 4, pitch, lfi->mblim, lfi->lim, lfi->hev_thr);
1144 #if CONFIG_VP9_HIGHBITDEPTH
1145 static void highbd_filter_selectively_vert(uint16_t *s, int pitch,
1146 unsigned int mask_16x16,
1147 unsigned int mask_8x8,
1148 unsigned int mask_4x4,
1149 unsigned int mask_4x4_int,
1150 const loop_filter_info_n *lfi_n,
1151 const uint8_t *lfl, int bd) {
1154 for (mask = mask_16x16 | mask_8x8 | mask_4x4 | mask_4x4_int;
1156 const loop_filter_thresh *lfi = lfi_n->lfthr + *lfl;
1159 if (mask_16x16 & 1) {
1160 vpx_highbd_lpf_vertical_16(s, pitch, lfi->mblim, lfi->lim,
1162 } else if (mask_8x8 & 1) {
1163 vpx_highbd_lpf_vertical_8(s, pitch, lfi->mblim, lfi->lim,
1164 lfi->hev_thr, 1, bd);
1165 } else if (mask_4x4 & 1) {
1166 vpx_highbd_lpf_vertical_4(s, pitch, lfi->mblim, lfi->lim,
1167 lfi->hev_thr, 1, bd);
1170 if (mask_4x4_int & 1)
1171 vpx_highbd_lpf_vertical_4(s + 4, pitch, lfi->mblim, lfi->lim,
1172 lfi->hev_thr, 1, bd);
1181 #endif // CONFIG_VP9_HIGHBITDEPTH
1183 void vp10_filter_block_plane_non420(VP10_COMMON *cm,
1184 struct macroblockd_plane *plane,
1186 int mi_row, int mi_col) {
1187 const int ss_x = plane->subsampling_x;
1188 const int ss_y = plane->subsampling_y;
1189 const int row_step = 1 << ss_y;
1190 const int col_step = 1 << ss_x;
1191 const int row_step_stride = cm->mi_stride * row_step;
1192 struct buf_2d *const dst = &plane->dst;
1193 uint8_t* const dst0 = dst->buf;
1194 unsigned int mask_16x16[MI_BLOCK_SIZE] = {0};
1195 unsigned int mask_8x8[MI_BLOCK_SIZE] = {0};
1196 unsigned int mask_4x4[MI_BLOCK_SIZE] = {0};
1197 unsigned int mask_4x4_int[MI_BLOCK_SIZE] = {0};
1198 uint8_t lfl[MI_BLOCK_SIZE * MI_BLOCK_SIZE];
1201 for (r = 0; r < MI_BLOCK_SIZE && mi_row + r < cm->mi_rows; r += row_step) {
1202 unsigned int mask_16x16_c = 0;
1203 unsigned int mask_8x8_c = 0;
1204 unsigned int mask_4x4_c = 0;
1205 unsigned int border_mask;
1207 // Determine the vertical edges that need filtering
1208 for (c = 0; c < MI_BLOCK_SIZE && mi_col + c < cm->mi_cols; c += col_step) {
1209 const MODE_INFO *mi = mi_8x8[c];
1210 const BLOCK_SIZE sb_type = mi[0].mbmi.sb_type;
1211 const int skip_this = mi[0].mbmi.skip && is_inter_block(&mi[0].mbmi);
1212 // left edge of current unit is block/partition edge -> no skip
1213 const int block_edge_left = (num_4x4_blocks_wide_lookup[sb_type] > 1) ?
1214 !(c & (num_8x8_blocks_wide_lookup[sb_type] - 1)) : 1;
1215 const int skip_this_c = skip_this && !block_edge_left;
1216 // top edge of current unit is block/partition edge -> no skip
1217 const int block_edge_above = (num_4x4_blocks_high_lookup[sb_type] > 1) ?
1218 !(r & (num_8x8_blocks_high_lookup[sb_type] - 1)) : 1;
1219 const int skip_this_r = skip_this && !block_edge_above;
1220 const TX_SIZE tx_size = (plane->plane_type == PLANE_TYPE_UV)
1221 ? get_uv_tx_size(&mi[0].mbmi, plane)
1222 : mi[0].mbmi.tx_size;
1223 const int skip_border_4x4_c = ss_x && mi_col + c == cm->mi_cols - 1;
1224 const int skip_border_4x4_r = ss_y && mi_row + r == cm->mi_rows - 1;
1226 // Filter level can vary per MI
1227 if (!(lfl[(r << 3) + (c >> ss_x)] =
1228 get_filter_level(&cm->lf_info, &mi[0].mbmi)))
1231 // Build masks based on the transform size of each block
1232 if (tx_size == TX_32X32) {
1233 if (!skip_this_c && ((c >> ss_x) & 3) == 0) {
1234 if (!skip_border_4x4_c)
1235 mask_16x16_c |= 1 << (c >> ss_x);
1237 mask_8x8_c |= 1 << (c >> ss_x);
1239 if (!skip_this_r && ((r >> ss_y) & 3) == 0) {
1240 if (!skip_border_4x4_r)
1241 mask_16x16[r] |= 1 << (c >> ss_x);
1243 mask_8x8[r] |= 1 << (c >> ss_x);
1245 } else if (tx_size == TX_16X16) {
1246 if (!skip_this_c && ((c >> ss_x) & 1) == 0) {
1247 if (!skip_border_4x4_c)
1248 mask_16x16_c |= 1 << (c >> ss_x);
1250 mask_8x8_c |= 1 << (c >> ss_x);
1252 if (!skip_this_r && ((r >> ss_y) & 1) == 0) {
1253 if (!skip_border_4x4_r)
1254 mask_16x16[r] |= 1 << (c >> ss_x);
1256 mask_8x8[r] |= 1 << (c >> ss_x);
1259 // force 8x8 filtering on 32x32 boundaries
1261 if (tx_size == TX_8X8 || ((c >> ss_x) & 3) == 0)
1262 mask_8x8_c |= 1 << (c >> ss_x);
1264 mask_4x4_c |= 1 << (c >> ss_x);
1268 if (tx_size == TX_8X8 || ((r >> ss_y) & 3) == 0)
1269 mask_8x8[r] |= 1 << (c >> ss_x);
1271 mask_4x4[r] |= 1 << (c >> ss_x);
1274 if (!skip_this && tx_size < TX_8X8 && !skip_border_4x4_c)
1275 mask_4x4_int[r] |= 1 << (c >> ss_x);
1279 // Disable filtering on the leftmost column
1280 border_mask = ~(mi_col == 0);
1281 #if CONFIG_VP9_HIGHBITDEPTH
1282 if (cm->use_highbitdepth) {
1283 highbd_filter_selectively_vert(CONVERT_TO_SHORTPTR(dst->buf),
1285 mask_16x16_c & border_mask,
1286 mask_8x8_c & border_mask,
1287 mask_4x4_c & border_mask,
1289 &cm->lf_info, &lfl[r << 3],
1290 (int)cm->bit_depth);
1292 filter_selectively_vert(dst->buf, dst->stride,
1293 mask_16x16_c & border_mask,
1294 mask_8x8_c & border_mask,
1295 mask_4x4_c & border_mask,
1297 &cm->lf_info, &lfl[r << 3]);
1300 filter_selectively_vert(dst->buf, dst->stride,
1301 mask_16x16_c & border_mask,
1302 mask_8x8_c & border_mask,
1303 mask_4x4_c & border_mask,
1305 &cm->lf_info, &lfl[r << 3]);
1306 #endif // CONFIG_VP9_HIGHBITDEPTH
1307 dst->buf += 8 * dst->stride;
1308 mi_8x8 += row_step_stride;
1311 // Now do horizontal pass
1313 for (r = 0; r < MI_BLOCK_SIZE && mi_row + r < cm->mi_rows; r += row_step) {
1314 const int skip_border_4x4_r = ss_y && mi_row + r == cm->mi_rows - 1;
1315 const unsigned int mask_4x4_int_r = skip_border_4x4_r ? 0 : mask_4x4_int[r];
1317 unsigned int mask_16x16_r;
1318 unsigned int mask_8x8_r;
1319 unsigned int mask_4x4_r;
1321 if (mi_row + r == 0) {
1326 mask_16x16_r = mask_16x16[r];
1327 mask_8x8_r = mask_8x8[r];
1328 mask_4x4_r = mask_4x4[r];
1330 #if CONFIG_VP9_HIGHBITDEPTH
1331 if (cm->use_highbitdepth) {
1332 highbd_filter_selectively_horiz(CONVERT_TO_SHORTPTR(dst->buf),
1338 &cm->lf_info, &lfl[r << 3],
1339 (int)cm->bit_depth);
1341 filter_selectively_horiz(dst->buf, dst->stride,
1346 &cm->lf_info, &lfl[r << 3]);
1349 filter_selectively_horiz(dst->buf, dst->stride,
1354 &cm->lf_info, &lfl[r << 3]);
1355 #endif // CONFIG_VP9_HIGHBITDEPTH
1356 dst->buf += 8 * dst->stride;
1360 void vp10_filter_block_plane_ss00(VP10_COMMON *const cm,
1361 struct macroblockd_plane *const plane,
1363 LOOP_FILTER_MASK *lfm) {
1364 struct buf_2d *const dst = &plane->dst;
1365 uint8_t *const dst0 = dst->buf;
1367 uint64_t mask_16x16 = lfm->left_y[TX_16X16];
1368 uint64_t mask_8x8 = lfm->left_y[TX_8X8];
1369 uint64_t mask_4x4 = lfm->left_y[TX_4X4];
1370 uint64_t mask_4x4_int = lfm->int_4x4_y;
1372 assert(plane->subsampling_x == 0 && plane->subsampling_y == 0);
1374 // Vertical pass: do 2 rows at one time
1375 for (r = 0; r < MI_BLOCK_SIZE && mi_row + r < cm->mi_rows; r += 2) {
1376 unsigned int mask_16x16_l = mask_16x16 & 0xffff;
1377 unsigned int mask_8x8_l = mask_8x8 & 0xffff;
1378 unsigned int mask_4x4_l = mask_4x4 & 0xffff;
1379 unsigned int mask_4x4_int_l = mask_4x4_int & 0xffff;
1381 // Disable filtering on the leftmost column.
1382 #if CONFIG_VP9_HIGHBITDEPTH
1383 if (cm->use_highbitdepth) {
1384 highbd_filter_selectively_vert_row2(
1385 plane->subsampling_x, CONVERT_TO_SHORTPTR(dst->buf), dst->stride,
1386 mask_16x16_l, mask_8x8_l, mask_4x4_l, mask_4x4_int_l, &cm->lf_info,
1387 &lfm->lfl_y[r << 3], (int)cm->bit_depth);
1389 filter_selectively_vert_row2(
1390 plane->subsampling_x, dst->buf, dst->stride, mask_16x16_l, mask_8x8_l,
1391 mask_4x4_l, mask_4x4_int_l, &cm->lf_info, &lfm->lfl_y[r << 3]);
1394 filter_selectively_vert_row2(
1395 plane->subsampling_x, dst->buf, dst->stride, mask_16x16_l, mask_8x8_l,
1396 mask_4x4_l, mask_4x4_int_l, &cm->lf_info, &lfm->lfl_y[r << 3]);
1397 #endif // CONFIG_VP9_HIGHBITDEPTH
1398 dst->buf += 16 * dst->stride;
1402 mask_4x4_int >>= 16;
1407 mask_16x16 = lfm->above_y[TX_16X16];
1408 mask_8x8 = lfm->above_y[TX_8X8];
1409 mask_4x4 = lfm->above_y[TX_4X4];
1410 mask_4x4_int = lfm->int_4x4_y;
1412 for (r = 0; r < MI_BLOCK_SIZE && mi_row + r < cm->mi_rows; r++) {
1413 unsigned int mask_16x16_r;
1414 unsigned int mask_8x8_r;
1415 unsigned int mask_4x4_r;
1417 if (mi_row + r == 0) {
1422 mask_16x16_r = mask_16x16 & 0xff;
1423 mask_8x8_r = mask_8x8 & 0xff;
1424 mask_4x4_r = mask_4x4 & 0xff;
1427 #if CONFIG_VP9_HIGHBITDEPTH
1428 if (cm->use_highbitdepth) {
1429 highbd_filter_selectively_horiz(
1430 CONVERT_TO_SHORTPTR(dst->buf), dst->stride, mask_16x16_r, mask_8x8_r,
1431 mask_4x4_r, mask_4x4_int & 0xff, &cm->lf_info, &lfm->lfl_y[r << 3],
1432 (int)cm->bit_depth);
1434 filter_selectively_horiz(dst->buf, dst->stride, mask_16x16_r, mask_8x8_r,
1435 mask_4x4_r, mask_4x4_int & 0xff, &cm->lf_info,
1436 &lfm->lfl_y[r << 3]);
1439 filter_selectively_horiz(dst->buf, dst->stride, mask_16x16_r, mask_8x8_r,
1440 mask_4x4_r, mask_4x4_int & 0xff, &cm->lf_info,
1441 &lfm->lfl_y[r << 3]);
1442 #endif // CONFIG_VP9_HIGHBITDEPTH
1444 dst->buf += 8 * dst->stride;
1452 void vp10_filter_block_plane_ss11(VP10_COMMON *const cm,
1453 struct macroblockd_plane *const plane,
1455 LOOP_FILTER_MASK *lfm) {
1456 struct buf_2d *const dst = &plane->dst;
1457 uint8_t *const dst0 = dst->buf;
1460 uint16_t mask_16x16 = lfm->left_uv[TX_16X16];
1461 uint16_t mask_8x8 = lfm->left_uv[TX_8X8];
1462 uint16_t mask_4x4 = lfm->left_uv[TX_4X4];
1463 #if CONFIG_MISC_FIXES
1464 uint16_t mask_4x4_int = lfm->left_int_4x4_uv;
1466 uint16_t mask_4x4_int = lfm->int_4x4_uv;
1469 assert(plane->subsampling_x == 1 && plane->subsampling_y == 1);
1471 // Vertical pass: do 2 rows at one time
1472 for (r = 0; r < MI_BLOCK_SIZE && mi_row + r < cm->mi_rows; r += 4) {
1473 if (plane->plane_type == 1) {
1474 for (c = 0; c < (MI_BLOCK_SIZE >> 1); c++) {
1475 lfm->lfl_uv[(r << 1) + c] = lfm->lfl_y[(r << 3) + (c << 1)];
1476 lfm->lfl_uv[((r + 2) << 1) + c] = lfm->lfl_y[((r + 2) << 3) + (c << 1)];
1481 unsigned int mask_16x16_l = mask_16x16 & 0xff;
1482 unsigned int mask_8x8_l = mask_8x8 & 0xff;
1483 unsigned int mask_4x4_l = mask_4x4 & 0xff;
1484 unsigned int mask_4x4_int_l = mask_4x4_int & 0xff;
1486 // Disable filtering on the leftmost column.
1487 #if CONFIG_VP9_HIGHBITDEPTH
1488 if (cm->use_highbitdepth) {
1489 highbd_filter_selectively_vert_row2(
1490 plane->subsampling_x, CONVERT_TO_SHORTPTR(dst->buf), dst->stride,
1491 mask_16x16_l, mask_8x8_l, mask_4x4_l, mask_4x4_int_l, &cm->lf_info,
1492 &lfm->lfl_uv[r << 1], (int)cm->bit_depth);
1494 filter_selectively_vert_row2(
1495 plane->subsampling_x, dst->buf, dst->stride,
1496 mask_16x16_l, mask_8x8_l, mask_4x4_l, mask_4x4_int_l, &cm->lf_info,
1497 &lfm->lfl_uv[r << 1]);
1500 filter_selectively_vert_row2(
1501 plane->subsampling_x, dst->buf, dst->stride,
1502 mask_16x16_l, mask_8x8_l, mask_4x4_l, mask_4x4_int_l, &cm->lf_info,
1503 &lfm->lfl_uv[r << 1]);
1504 #endif // CONFIG_VP9_HIGHBITDEPTH
1506 dst->buf += 16 * dst->stride;
1516 mask_16x16 = lfm->above_uv[TX_16X16];
1517 mask_8x8 = lfm->above_uv[TX_8X8];
1518 mask_4x4 = lfm->above_uv[TX_4X4];
1519 #if CONFIG_MISC_FIXES
1520 mask_4x4_int = lfm->above_int_4x4_uv;
1522 mask_4x4_int = lfm->int_4x4_uv;
1525 for (r = 0; r < MI_BLOCK_SIZE && mi_row + r < cm->mi_rows; r += 2) {
1526 const int skip_border_4x4_r = mi_row + r == cm->mi_rows - 1;
1527 const unsigned int mask_4x4_int_r =
1528 skip_border_4x4_r ? 0 : (mask_4x4_int & 0xf);
1529 unsigned int mask_16x16_r;
1530 unsigned int mask_8x8_r;
1531 unsigned int mask_4x4_r;
1533 if (mi_row + r == 0) {
1538 mask_16x16_r = mask_16x16 & 0xf;
1539 mask_8x8_r = mask_8x8 & 0xf;
1540 mask_4x4_r = mask_4x4 & 0xf;
1543 #if CONFIG_VP9_HIGHBITDEPTH
1544 if (cm->use_highbitdepth) {
1545 highbd_filter_selectively_horiz(CONVERT_TO_SHORTPTR(dst->buf),
1546 dst->stride, mask_16x16_r, mask_8x8_r,
1547 mask_4x4_r, mask_4x4_int_r, &cm->lf_info,
1548 &lfm->lfl_uv[r << 1], (int)cm->bit_depth);
1550 filter_selectively_horiz(dst->buf, dst->stride, mask_16x16_r, mask_8x8_r,
1551 mask_4x4_r, mask_4x4_int_r, &cm->lf_info,
1552 &lfm->lfl_uv[r << 1]);
1555 filter_selectively_horiz(dst->buf, dst->stride, mask_16x16_r, mask_8x8_r,
1556 mask_4x4_r, mask_4x4_int_r, &cm->lf_info,
1557 &lfm->lfl_uv[r << 1]);
1558 #endif // CONFIG_VP9_HIGHBITDEPTH
1560 dst->buf += 8 * dst->stride;
1568 void vp10_loop_filter_rows(YV12_BUFFER_CONFIG *frame_buffer,
1570 struct macroblockd_plane planes[MAX_MB_PLANE],
1571 int start, int stop, int y_only) {
1572 const int num_planes = y_only ? 1 : MAX_MB_PLANE;
1574 LOOP_FILTER_MASK lfm;
1579 else if (planes[1].subsampling_y == 1 && planes[1].subsampling_x == 1)
1581 else if (planes[1].subsampling_y == 0 && planes[1].subsampling_x == 0)
1584 path = LF_PATH_SLOW;
1586 for (mi_row = start; mi_row < stop; mi_row += MI_BLOCK_SIZE) {
1587 MODE_INFO **mi = cm->mi_grid_visible + mi_row * cm->mi_stride;
1589 for (mi_col = 0; mi_col < cm->mi_cols; mi_col += MI_BLOCK_SIZE) {
1592 vp10_setup_dst_planes(planes, frame_buffer, mi_row, mi_col);
1594 // TODO(JBB): Make setup_mask work for non 420.
1595 vp10_setup_mask(cm, mi_row, mi_col, mi + mi_col, cm->mi_stride,
1598 vp10_filter_block_plane_ss00(cm, &planes[0], mi_row, &lfm);
1599 for (plane = 1; plane < num_planes; ++plane) {
1602 vp10_filter_block_plane_ss11(cm, &planes[plane], mi_row, &lfm);
1605 vp10_filter_block_plane_ss00(cm, &planes[plane], mi_row, &lfm);
1608 vp10_filter_block_plane_non420(cm, &planes[plane], mi + mi_col,
1617 void vp10_loop_filter_frame(YV12_BUFFER_CONFIG *frame,
1618 VP10_COMMON *cm, MACROBLOCKD *xd,
1619 int frame_filter_level,
1620 int y_only, int partial_frame) {
1621 int start_mi_row, end_mi_row, mi_rows_to_filter;
1622 if (!frame_filter_level) return;
1624 mi_rows_to_filter = cm->mi_rows;
1625 if (partial_frame && cm->mi_rows > 8) {
1626 start_mi_row = cm->mi_rows >> 1;
1627 start_mi_row &= 0xfffffff8;
1628 mi_rows_to_filter = VPXMAX(cm->mi_rows / 8, 8);
1630 end_mi_row = start_mi_row + mi_rows_to_filter;
1631 vp10_loop_filter_frame_init(cm, frame_filter_level);
1632 vp10_loop_filter_rows(frame, cm, xd->plane,
1633 start_mi_row, end_mi_row,
1637 void vp10_loop_filter_data_reset(
1638 LFWorkerData *lf_data, YV12_BUFFER_CONFIG *frame_buffer,
1639 struct VP10Common *cm,
1640 const struct macroblockd_plane planes[MAX_MB_PLANE]) {
1641 lf_data->frame_buffer = frame_buffer;
1645 lf_data->y_only = 0;
1646 memcpy(lf_data->planes, planes, sizeof(lf_data->planes));
1649 int vp10_loop_filter_worker(LFWorkerData *const lf_data, void *unused) {
1651 vp10_loop_filter_rows(lf_data->frame_buffer, lf_data->cm, lf_data->planes,
1652 lf_data->start, lf_data->stop, lf_data->y_only);