xref: /aosp_15_r20/external/libaom/av1/common/blockd.c (revision 77c1e3ccc04c968bd2bc212e87364f250e820521)
1*77c1e3ccSAndroid Build Coastguard Worker /*
2*77c1e3ccSAndroid Build Coastguard Worker  * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
3*77c1e3ccSAndroid Build Coastguard Worker  *
4*77c1e3ccSAndroid Build Coastguard Worker  * This source code is subject to the terms of the BSD 2 Clause License and
5*77c1e3ccSAndroid Build Coastguard Worker  * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6*77c1e3ccSAndroid Build Coastguard Worker  * was not distributed with this source code in the LICENSE file, you can
7*77c1e3ccSAndroid Build Coastguard Worker  * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8*77c1e3ccSAndroid Build Coastguard Worker  * Media Patent License 1.0 was not distributed with this source code in the
9*77c1e3ccSAndroid Build Coastguard Worker  * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10*77c1e3ccSAndroid Build Coastguard Worker  */
11*77c1e3ccSAndroid Build Coastguard Worker 
12*77c1e3ccSAndroid Build Coastguard Worker #include <math.h>
13*77c1e3ccSAndroid Build Coastguard Worker 
14*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/av1_common_int.h"
15*77c1e3ccSAndroid Build Coastguard Worker #include "av1/common/blockd.h"
16*77c1e3ccSAndroid Build Coastguard Worker 
av1_left_block_mode(const MB_MODE_INFO * left_mi)17*77c1e3ccSAndroid Build Coastguard Worker PREDICTION_MODE av1_left_block_mode(const MB_MODE_INFO *left_mi) {
18*77c1e3ccSAndroid Build Coastguard Worker   if (!left_mi) return DC_PRED;
19*77c1e3ccSAndroid Build Coastguard Worker   assert(!is_inter_block(left_mi) || is_intrabc_block(left_mi));
20*77c1e3ccSAndroid Build Coastguard Worker   return left_mi->mode;
21*77c1e3ccSAndroid Build Coastguard Worker }
22*77c1e3ccSAndroid Build Coastguard Worker 
av1_above_block_mode(const MB_MODE_INFO * above_mi)23*77c1e3ccSAndroid Build Coastguard Worker PREDICTION_MODE av1_above_block_mode(const MB_MODE_INFO *above_mi) {
24*77c1e3ccSAndroid Build Coastguard Worker   if (!above_mi) return DC_PRED;
25*77c1e3ccSAndroid Build Coastguard Worker   assert(!is_inter_block(above_mi) || is_intrabc_block(above_mi));
26*77c1e3ccSAndroid Build Coastguard Worker   return above_mi->mode;
27*77c1e3ccSAndroid Build Coastguard Worker }
28*77c1e3ccSAndroid Build Coastguard Worker 
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)29*77c1e3ccSAndroid Build Coastguard Worker void av1_set_entropy_contexts(const MACROBLOCKD *xd,
30*77c1e3ccSAndroid Build Coastguard Worker                               struct macroblockd_plane *pd, int plane,
31*77c1e3ccSAndroid Build Coastguard Worker                               BLOCK_SIZE plane_bsize, TX_SIZE tx_size,
32*77c1e3ccSAndroid Build Coastguard Worker                               int has_eob, int aoff, int loff) {
33*77c1e3ccSAndroid Build Coastguard Worker   ENTROPY_CONTEXT *const a = pd->above_entropy_context + aoff;
34*77c1e3ccSAndroid Build Coastguard Worker   ENTROPY_CONTEXT *const l = pd->left_entropy_context + loff;
35*77c1e3ccSAndroid Build Coastguard Worker   const int txs_wide = tx_size_wide_unit[tx_size];
36*77c1e3ccSAndroid Build Coastguard Worker   const int txs_high = tx_size_high_unit[tx_size];
37*77c1e3ccSAndroid Build Coastguard Worker 
38*77c1e3ccSAndroid Build Coastguard Worker   // above
39*77c1e3ccSAndroid Build Coastguard Worker   if (has_eob && xd->mb_to_right_edge < 0) {
40*77c1e3ccSAndroid Build Coastguard Worker     const int blocks_wide = max_block_wide(xd, plane_bsize, plane);
41*77c1e3ccSAndroid Build Coastguard Worker     const int above_contexts = AOMMIN(txs_wide, blocks_wide - aoff);
42*77c1e3ccSAndroid Build Coastguard Worker     memset(a, has_eob, sizeof(*a) * above_contexts);
43*77c1e3ccSAndroid Build Coastguard Worker     memset(a + above_contexts, 0, sizeof(*a) * (txs_wide - above_contexts));
44*77c1e3ccSAndroid Build Coastguard Worker   } else {
45*77c1e3ccSAndroid Build Coastguard Worker     memset(a, has_eob, sizeof(*a) * txs_wide);
46*77c1e3ccSAndroid Build Coastguard Worker   }
47*77c1e3ccSAndroid Build Coastguard Worker 
48*77c1e3ccSAndroid Build Coastguard Worker   // left
49*77c1e3ccSAndroid Build Coastguard Worker   if (has_eob && xd->mb_to_bottom_edge < 0) {
50*77c1e3ccSAndroid Build Coastguard Worker     const int blocks_high = max_block_high(xd, plane_bsize, plane);
51*77c1e3ccSAndroid Build Coastguard Worker     const int left_contexts = AOMMIN(txs_high, blocks_high - loff);
52*77c1e3ccSAndroid Build Coastguard Worker     memset(l, has_eob, sizeof(*l) * left_contexts);
53*77c1e3ccSAndroid Build Coastguard Worker     memset(l + left_contexts, 0, sizeof(*l) * (txs_high - left_contexts));
54*77c1e3ccSAndroid Build Coastguard Worker   } else {
55*77c1e3ccSAndroid Build Coastguard Worker     memset(l, has_eob, sizeof(*l) * txs_high);
56*77c1e3ccSAndroid Build Coastguard Worker   }
57*77c1e3ccSAndroid Build Coastguard Worker }
av1_reset_entropy_context(MACROBLOCKD * xd,BLOCK_SIZE bsize,const int num_planes)58*77c1e3ccSAndroid Build Coastguard Worker void av1_reset_entropy_context(MACROBLOCKD *xd, BLOCK_SIZE bsize,
59*77c1e3ccSAndroid Build Coastguard Worker                                const int num_planes) {
60*77c1e3ccSAndroid Build Coastguard Worker   assert(bsize < BLOCK_SIZES_ALL);
61*77c1e3ccSAndroid Build Coastguard Worker   const int nplanes = 1 + (num_planes - 1) * xd->is_chroma_ref;
62*77c1e3ccSAndroid Build Coastguard Worker   for (int i = 0; i < nplanes; i++) {
63*77c1e3ccSAndroid Build Coastguard Worker     struct macroblockd_plane *const pd = &xd->plane[i];
64*77c1e3ccSAndroid Build Coastguard Worker     const BLOCK_SIZE plane_bsize =
65*77c1e3ccSAndroid Build Coastguard Worker         get_plane_block_size(bsize, pd->subsampling_x, pd->subsampling_y);
66*77c1e3ccSAndroid Build Coastguard Worker     const int txs_wide = mi_size_wide[plane_bsize];
67*77c1e3ccSAndroid Build Coastguard Worker     const int txs_high = mi_size_high[plane_bsize];
68*77c1e3ccSAndroid Build Coastguard Worker     memset(pd->above_entropy_context, 0, sizeof(ENTROPY_CONTEXT) * txs_wide);
69*77c1e3ccSAndroid Build Coastguard Worker     memset(pd->left_entropy_context, 0, sizeof(ENTROPY_CONTEXT) * txs_high);
70*77c1e3ccSAndroid Build Coastguard Worker   }
71*77c1e3ccSAndroid Build Coastguard Worker }
72*77c1e3ccSAndroid Build Coastguard Worker 
av1_reset_loop_filter_delta(MACROBLOCKD * xd,int num_planes)73*77c1e3ccSAndroid Build Coastguard Worker void av1_reset_loop_filter_delta(MACROBLOCKD *xd, int num_planes) {
74*77c1e3ccSAndroid Build Coastguard Worker   xd->delta_lf_from_base = 0;
75*77c1e3ccSAndroid Build Coastguard Worker   const int frame_lf_count =
76*77c1e3ccSAndroid Build Coastguard Worker       num_planes > 1 ? FRAME_LF_COUNT : FRAME_LF_COUNT - 2;
77*77c1e3ccSAndroid Build Coastguard Worker   for (int lf_id = 0; lf_id < frame_lf_count; ++lf_id) xd->delta_lf[lf_id] = 0;
78*77c1e3ccSAndroid Build Coastguard Worker }
79*77c1e3ccSAndroid Build Coastguard Worker 
av1_reset_loop_restoration(MACROBLOCKD * xd,const int num_planes)80*77c1e3ccSAndroid Build Coastguard Worker void av1_reset_loop_restoration(MACROBLOCKD *xd, const int num_planes) {
81*77c1e3ccSAndroid Build Coastguard Worker   for (int p = 0; p < num_planes; ++p) {
82*77c1e3ccSAndroid Build Coastguard Worker     set_default_wiener(xd->wiener_info + p);
83*77c1e3ccSAndroid Build Coastguard Worker     set_default_sgrproj(xd->sgrproj_info + p);
84*77c1e3ccSAndroid Build Coastguard Worker   }
85*77c1e3ccSAndroid Build Coastguard Worker }
86*77c1e3ccSAndroid Build Coastguard Worker 
av1_setup_block_planes(MACROBLOCKD * xd,int ss_x,int ss_y,const int num_planes)87*77c1e3ccSAndroid Build Coastguard Worker void av1_setup_block_planes(MACROBLOCKD *xd, int ss_x, int ss_y,
88*77c1e3ccSAndroid Build Coastguard Worker                             const int num_planes) {
89*77c1e3ccSAndroid Build Coastguard Worker   int i;
90*77c1e3ccSAndroid Build Coastguard Worker 
91*77c1e3ccSAndroid Build Coastguard Worker   for (i = 0; i < num_planes; i++) {
92*77c1e3ccSAndroid Build Coastguard Worker     xd->plane[i].plane_type = get_plane_type(i);
93*77c1e3ccSAndroid Build Coastguard Worker     xd->plane[i].subsampling_x = i ? ss_x : 0;
94*77c1e3ccSAndroid Build Coastguard Worker     xd->plane[i].subsampling_y = i ? ss_y : 0;
95*77c1e3ccSAndroid Build Coastguard Worker   }
96*77c1e3ccSAndroid Build Coastguard Worker   for (i = num_planes; i < MAX_MB_PLANE; i++) {
97*77c1e3ccSAndroid Build Coastguard Worker     xd->plane[i].subsampling_x = 1;
98*77c1e3ccSAndroid Build Coastguard Worker     xd->plane[i].subsampling_y = 1;
99*77c1e3ccSAndroid Build Coastguard Worker   }
100*77c1e3ccSAndroid Build Coastguard Worker }
101