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 "aom_ports/system_state.h"
15
16 #include "av1/common/av1_common_int.h"
17 #include "av1/common/blockd.h"
18
av1_left_block_mode(const MB_MODE_INFO * left_mi)19 PREDICTION_MODE av1_left_block_mode(const MB_MODE_INFO *left_mi) {
20 if (!left_mi) return DC_PRED;
21 assert(!is_inter_block(left_mi) || is_intrabc_block(left_mi));
22 return left_mi->mode;
23 }
24
av1_above_block_mode(const MB_MODE_INFO * above_mi)25 PREDICTION_MODE av1_above_block_mode(const MB_MODE_INFO *above_mi) {
26 if (!above_mi) return DC_PRED;
27 assert(!is_inter_block(above_mi) || is_intrabc_block(above_mi));
28 return above_mi->mode;
29 }
30
av1_set_entropy_contexts(const MACROBLOCKD * xd,struct macroblockd_plane * pd,int plane,BLOCK_SIZE plane_bsize,TX_SIZE tx_size,int has_eob,int aoff,int loff)31 void av1_set_entropy_contexts(const MACROBLOCKD *xd,
32 struct macroblockd_plane *pd, int plane,
33 BLOCK_SIZE plane_bsize, TX_SIZE tx_size,
34 int has_eob, int aoff, int loff) {
35 ENTROPY_CONTEXT *const a = pd->above_entropy_context + aoff;
36 ENTROPY_CONTEXT *const l = pd->left_entropy_context + loff;
37 const int txs_wide = tx_size_wide_unit[tx_size];
38 const int txs_high = tx_size_high_unit[tx_size];
39
40 // above
41 if (has_eob && xd->mb_to_right_edge < 0) {
42 const int blocks_wide = max_block_wide(xd, plane_bsize, plane);
43 const int above_contexts = AOMMIN(txs_wide, blocks_wide - aoff);
44 memset(a, has_eob, sizeof(*a) * above_contexts);
45 memset(a + above_contexts, 0, sizeof(*a) * (txs_wide - above_contexts));
46 } else {
47 memset(a, has_eob, sizeof(*a) * txs_wide);
48 }
49
50 // left
51 if (has_eob && xd->mb_to_bottom_edge < 0) {
52 const int blocks_high = max_block_high(xd, plane_bsize, plane);
53 const int left_contexts = AOMMIN(txs_high, blocks_high - loff);
54 memset(l, has_eob, sizeof(*l) * left_contexts);
55 memset(l + left_contexts, 0, sizeof(*l) * (txs_high - left_contexts));
56 } else {
57 memset(l, has_eob, sizeof(*l) * txs_high);
58 }
59 }
av1_reset_entropy_context(MACROBLOCKD * xd,BLOCK_SIZE bsize,const int num_planes)60 void av1_reset_entropy_context(MACROBLOCKD *xd, BLOCK_SIZE bsize,
61 const int num_planes) {
62 assert(bsize < BLOCK_SIZES_ALL);
63 const int nplanes = 1 + (num_planes - 1) * xd->is_chroma_ref;
64 for (int i = 0; i < nplanes; i++) {
65 struct macroblockd_plane *const pd = &xd->plane[i];
66 const BLOCK_SIZE plane_bsize =
67 get_plane_block_size(bsize, pd->subsampling_x, pd->subsampling_y);
68 const int txs_wide = mi_size_wide[plane_bsize];
69 const int txs_high = mi_size_high[plane_bsize];
70 memset(pd->above_entropy_context, 0, sizeof(ENTROPY_CONTEXT) * txs_wide);
71 memset(pd->left_entropy_context, 0, sizeof(ENTROPY_CONTEXT) * txs_high);
72 }
73 }
74
av1_reset_loop_filter_delta(MACROBLOCKD * xd,int num_planes)75 void av1_reset_loop_filter_delta(MACROBLOCKD *xd, int num_planes) {
76 xd->delta_lf_from_base = 0;
77 const int frame_lf_count =
78 num_planes > 1 ? FRAME_LF_COUNT : FRAME_LF_COUNT - 2;
79 for (int lf_id = 0; lf_id < frame_lf_count; ++lf_id) xd->delta_lf[lf_id] = 0;
80 }
81
av1_reset_loop_restoration(MACROBLOCKD * xd,const int num_planes)82 void av1_reset_loop_restoration(MACROBLOCKD *xd, const int num_planes) {
83 for (int p = 0; p < num_planes; ++p) {
84 set_default_wiener(xd->wiener_info + p);
85 set_default_sgrproj(xd->sgrproj_info + p);
86 }
87 }
88
av1_setup_block_planes(MACROBLOCKD * xd,int ss_x,int ss_y,const int num_planes)89 void av1_setup_block_planes(MACROBLOCKD *xd, int ss_x, int ss_y,
90 const int num_planes) {
91 int i;
92
93 for (i = 0; i < num_planes; i++) {
94 xd->plane[i].plane_type = get_plane_type(i);
95 xd->plane[i].subsampling_x = i ? ss_x : 0;
96 xd->plane[i].subsampling_y = i ? ss_y : 0;
97 }
98 for (i = num_planes; i < MAX_MB_PLANE; i++) {
99 xd->plane[i].subsampling_x = 1;
100 xd->plane[i].subsampling_y = 1;
101 }
102 }
103