Sebastien Alaiwan | 20dadea | 2017-11-22 17:38:31 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2017, 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 <stdlib.h> |
| 13 | |
| 14 | #include "./aom_config.h" |
| 15 | #include "./aom_dsp_rtcd.h" |
| 16 | |
| 17 | #include "aom/aom_integer.h" |
| 18 | #include "aom_ports/mem.h" |
| 19 | #include "aom_dsp/blend.h" |
| 20 | |
| 21 | #if CONFIG_AV1 |
| 22 | static INLINE unsigned int masked_sad(const uint8_t *src, int src_stride, |
| 23 | const uint8_t *a, int a_stride, |
| 24 | const uint8_t *b, int b_stride, |
| 25 | const uint8_t *m, int m_stride, int width, |
| 26 | int height) { |
| 27 | int y, x; |
| 28 | unsigned int sad = 0; |
| 29 | for (y = 0; y < height; y++) { |
| 30 | for (x = 0; x < width; x++) { |
| 31 | const int16_t pred = AOM_BLEND_A64(m[x], a[x], b[x]); |
| 32 | sad += abs(pred - src[x]); |
| 33 | } |
| 34 | src += src_stride; |
| 35 | a += a_stride; |
| 36 | b += b_stride; |
| 37 | m += m_stride; |
| 38 | } |
| 39 | sad = (sad + 31) >> 6; |
| 40 | return sad; |
| 41 | } |
| 42 | |
| 43 | #define MASKSADMxN(m, n) \ |
| 44 | unsigned int aom_masked_sad##m##x##n##_c( \ |
| 45 | const uint8_t *src, int src_stride, const uint8_t *ref, int ref_stride, \ |
| 46 | const uint8_t *second_pred, const uint8_t *msk, int msk_stride, \ |
| 47 | int invert_mask) { \ |
| 48 | if (!invert_mask) \ |
| 49 | return masked_sad(src, src_stride, ref, ref_stride, second_pred, m, msk, \ |
| 50 | msk_stride, m, n); \ |
| 51 | else \ |
| 52 | return masked_sad(src, src_stride, second_pred, m, ref, ref_stride, msk, \ |
| 53 | msk_stride, m, n); \ |
| 54 | } |
| 55 | |
| 56 | /* clang-format off */ |
Sebastien Alaiwan | 20dadea | 2017-11-22 17:38:31 +0100 | [diff] [blame] | 57 | MASKSADMxN(128, 128) |
| 58 | MASKSADMxN(128, 64) |
| 59 | MASKSADMxN(64, 128) |
Sebastien Alaiwan | 20dadea | 2017-11-22 17:38:31 +0100 | [diff] [blame] | 60 | MASKSADMxN(64, 64) |
| 61 | MASKSADMxN(64, 32) |
| 62 | MASKSADMxN(32, 64) |
| 63 | MASKSADMxN(32, 32) |
| 64 | MASKSADMxN(32, 16) |
| 65 | MASKSADMxN(16, 32) |
| 66 | MASKSADMxN(16, 16) |
| 67 | MASKSADMxN(16, 8) |
| 68 | MASKSADMxN(8, 16) |
| 69 | MASKSADMxN(8, 8) |
| 70 | MASKSADMxN(8, 4) |
| 71 | MASKSADMxN(4, 8) |
| 72 | MASKSADMxN(4, 4) |
| 73 | |
Sebastien Alaiwan | 20dadea | 2017-11-22 17:38:31 +0100 | [diff] [blame] | 74 | MASKSADMxN(4, 16) |
| 75 | MASKSADMxN(16, 4) |
| 76 | MASKSADMxN(8, 32) |
| 77 | MASKSADMxN(32, 8) |
| 78 | MASKSADMxN(16, 64) |
| 79 | MASKSADMxN(64, 16) |
| 80 | MASKSADMxN(32, 128) |
| 81 | MASKSADMxN(128, 32) |
Debargha Mukherjee | 1687085 | 2018-02-28 10:00:17 -0800 | [diff] [blame] | 82 | |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 83 | /* clang-format on */ |
Sebastien Alaiwan | 20dadea | 2017-11-22 17:38:31 +0100 | [diff] [blame] | 84 | |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 85 | static INLINE |
Sebastien Alaiwan | 20dadea | 2017-11-22 17:38:31 +0100 | [diff] [blame] | 86 | unsigned int highbd_masked_sad(const uint8_t *src8, int src_stride, |
| 87 | const uint8_t *a8, int a_stride, |
| 88 | const uint8_t *b8, int b_stride, |
| 89 | const uint8_t *m, int m_stride, int width, |
| 90 | int height) { |
| 91 | int y, x; |
| 92 | unsigned int sad = 0; |
| 93 | const uint16_t *src = CONVERT_TO_SHORTPTR(src8); |
| 94 | const uint16_t *a = CONVERT_TO_SHORTPTR(a8); |
| 95 | const uint16_t *b = CONVERT_TO_SHORTPTR(b8); |
| 96 | |
| 97 | for (y = 0; y < height; y++) { |
| 98 | for (x = 0; x < width; x++) { |
| 99 | const uint16_t pred = AOM_BLEND_A64(m[x], a[x], b[x]); |
| 100 | sad += abs(pred - src[x]); |
| 101 | } |
| 102 | |
| 103 | src += src_stride; |
| 104 | a += a_stride; |
| 105 | b += b_stride; |
| 106 | m += m_stride; |
| 107 | } |
| 108 | sad = (sad + 31) >> 6; |
| 109 | |
| 110 | return sad; |
| 111 | } |
| 112 | |
| 113 | #define HIGHBD_MASKSADMXN(m, n) \ |
| 114 | unsigned int aom_highbd_masked_sad##m##x##n##_c( \ |
| 115 | const uint8_t *src8, int src_stride, const uint8_t *ref8, \ |
| 116 | int ref_stride, const uint8_t *second_pred8, const uint8_t *msk, \ |
| 117 | int msk_stride, int invert_mask) { \ |
| 118 | if (!invert_mask) \ |
| 119 | return highbd_masked_sad(src8, src_stride, ref8, ref_stride, \ |
| 120 | second_pred8, m, msk, msk_stride, m, n); \ |
| 121 | else \ |
| 122 | return highbd_masked_sad(src8, src_stride, second_pred8, m, ref8, \ |
| 123 | ref_stride, msk, msk_stride, m, n); \ |
| 124 | } |
| 125 | |
Sebastien Alaiwan | 20dadea | 2017-11-22 17:38:31 +0100 | [diff] [blame] | 126 | HIGHBD_MASKSADMXN(128, 128) |
| 127 | HIGHBD_MASKSADMXN(128, 64) |
| 128 | HIGHBD_MASKSADMXN(64, 128) |
Sebastien Alaiwan | 20dadea | 2017-11-22 17:38:31 +0100 | [diff] [blame] | 129 | HIGHBD_MASKSADMXN(64, 64) |
| 130 | HIGHBD_MASKSADMXN(64, 32) |
| 131 | HIGHBD_MASKSADMXN(32, 64) |
| 132 | HIGHBD_MASKSADMXN(32, 32) |
| 133 | HIGHBD_MASKSADMXN(32, 16) |
| 134 | HIGHBD_MASKSADMXN(16, 32) |
| 135 | HIGHBD_MASKSADMXN(16, 16) |
| 136 | HIGHBD_MASKSADMXN(16, 8) |
| 137 | HIGHBD_MASKSADMXN(8, 16) |
| 138 | HIGHBD_MASKSADMXN(8, 8) |
| 139 | HIGHBD_MASKSADMXN(8, 4) |
| 140 | HIGHBD_MASKSADMXN(4, 8) |
| 141 | HIGHBD_MASKSADMXN(4, 4) |
| 142 | |
Debargha Mukherjee | 1687085 | 2018-02-28 10:00:17 -0800 | [diff] [blame] | 143 | #if CONFIG_AV1 |
Sebastien Alaiwan | 20dadea | 2017-11-22 17:38:31 +0100 | [diff] [blame] | 144 | HIGHBD_MASKSADMXN(4, 16) |
| 145 | HIGHBD_MASKSADMXN(16, 4) |
| 146 | HIGHBD_MASKSADMXN(8, 32) |
| 147 | HIGHBD_MASKSADMXN(32, 8) |
| 148 | HIGHBD_MASKSADMXN(16, 64) |
| 149 | HIGHBD_MASKSADMXN(64, 16) |
| 150 | HIGHBD_MASKSADMXN(32, 128) |
| 151 | HIGHBD_MASKSADMXN(128, 32) |
| 152 | #endif |
Sebastien Alaiwan | 20dadea | 2017-11-22 17:38:31 +0100 | [diff] [blame] | 153 | |
| 154 | // pre: predictor being evaluated |
| 155 | // wsrc: target weighted prediction (has been *4096 to keep precision) |
| 156 | // mask: 2d weights (scaled by 4096) |
| 157 | static INLINE unsigned int obmc_sad(const uint8_t *pre, int pre_stride, |
| 158 | const int32_t *wsrc, const int32_t *mask, |
| 159 | int width, int height) { |
| 160 | int y, x; |
| 161 | unsigned int sad = 0; |
| 162 | |
| 163 | for (y = 0; y < height; y++) { |
| 164 | for (x = 0; x < width; x++) |
| 165 | sad += ROUND_POWER_OF_TWO(abs(wsrc[x] - pre[x] * mask[x]), 12); |
| 166 | |
| 167 | pre += pre_stride; |
| 168 | wsrc += width; |
| 169 | mask += width; |
| 170 | } |
| 171 | |
| 172 | return sad; |
| 173 | } |
| 174 | |
| 175 | #define OBMCSADMxN(m, n) \ |
| 176 | unsigned int aom_obmc_sad##m##x##n##_c(const uint8_t *ref, int ref_stride, \ |
| 177 | const int32_t *wsrc, \ |
| 178 | const int32_t *mask) { \ |
| 179 | return obmc_sad(ref, ref_stride, wsrc, mask, m, n); \ |
| 180 | } |
| 181 | |
| 182 | /* clang-format off */ |
Sebastien Alaiwan | 20dadea | 2017-11-22 17:38:31 +0100 | [diff] [blame] | 183 | OBMCSADMxN(128, 128) |
| 184 | OBMCSADMxN(128, 64) |
| 185 | OBMCSADMxN(64, 128) |
Sebastien Alaiwan | 20dadea | 2017-11-22 17:38:31 +0100 | [diff] [blame] | 186 | OBMCSADMxN(64, 64) |
| 187 | OBMCSADMxN(64, 32) |
| 188 | OBMCSADMxN(32, 64) |
| 189 | OBMCSADMxN(32, 32) |
| 190 | OBMCSADMxN(32, 16) |
| 191 | OBMCSADMxN(16, 32) |
| 192 | OBMCSADMxN(16, 16) |
| 193 | OBMCSADMxN(16, 8) |
| 194 | OBMCSADMxN(8, 16) |
| 195 | OBMCSADMxN(8, 8) |
| 196 | OBMCSADMxN(8, 4) |
| 197 | OBMCSADMxN(4, 8) |
| 198 | OBMCSADMxN(4, 4) |
| 199 | |
Debargha Mukherjee | 1687085 | 2018-02-28 10:00:17 -0800 | [diff] [blame] | 200 | #if CONFIG_AV1 |
Sebastien Alaiwan | 20dadea | 2017-11-22 17:38:31 +0100 | [diff] [blame] | 201 | OBMCSADMxN(4, 16) |
| 202 | OBMCSADMxN(16, 4) |
| 203 | OBMCSADMxN(8, 32) |
| 204 | OBMCSADMxN(32, 8) |
| 205 | OBMCSADMxN(16, 64) |
| 206 | OBMCSADMxN(64, 16) |
| 207 | OBMCSADMxN(32, 128) |
| 208 | OBMCSADMxN(128, 32) |
| 209 | #endif |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 210 | /* clang-format on */ |
Sebastien Alaiwan | 20dadea | 2017-11-22 17:38:31 +0100 | [diff] [blame] | 211 | |
Yaowu Xu | d3e7c68 | 2017-12-21 14:08:25 -0800 | [diff] [blame] | 212 | static INLINE |
Sebastien Alaiwan | 20dadea | 2017-11-22 17:38:31 +0100 | [diff] [blame] | 213 | unsigned int highbd_obmc_sad(const uint8_t *pre8, int pre_stride, |
| 214 | const int32_t *wsrc, const int32_t *mask, |
| 215 | int width, int height) { |
| 216 | int y, x; |
| 217 | unsigned int sad = 0; |
| 218 | const uint16_t *pre = CONVERT_TO_SHORTPTR(pre8); |
| 219 | |
| 220 | for (y = 0; y < height; y++) { |
| 221 | for (x = 0; x < width; x++) |
| 222 | sad += ROUND_POWER_OF_TWO(abs(wsrc[x] - pre[x] * mask[x]), 12); |
| 223 | |
| 224 | pre += pre_stride; |
| 225 | wsrc += width; |
| 226 | mask += width; |
| 227 | } |
| 228 | |
| 229 | return sad; |
| 230 | } |
| 231 | |
| 232 | #define HIGHBD_OBMCSADMXN(m, n) \ |
| 233 | unsigned int aom_highbd_obmc_sad##m##x##n##_c( \ |
| 234 | const uint8_t *ref, int ref_stride, const int32_t *wsrc, \ |
| 235 | const int32_t *mask) { \ |
| 236 | return highbd_obmc_sad(ref, ref_stride, wsrc, mask, m, n); \ |
| 237 | } |
| 238 | |
| 239 | /* clang-format off */ |
Sebastien Alaiwan | 20dadea | 2017-11-22 17:38:31 +0100 | [diff] [blame] | 240 | HIGHBD_OBMCSADMXN(128, 128) |
| 241 | HIGHBD_OBMCSADMXN(128, 64) |
| 242 | HIGHBD_OBMCSADMXN(64, 128) |
Sebastien Alaiwan | 20dadea | 2017-11-22 17:38:31 +0100 | [diff] [blame] | 243 | HIGHBD_OBMCSADMXN(64, 64) |
| 244 | HIGHBD_OBMCSADMXN(64, 32) |
| 245 | HIGHBD_OBMCSADMXN(32, 64) |
| 246 | HIGHBD_OBMCSADMXN(32, 32) |
| 247 | HIGHBD_OBMCSADMXN(32, 16) |
| 248 | HIGHBD_OBMCSADMXN(16, 32) |
| 249 | HIGHBD_OBMCSADMXN(16, 16) |
| 250 | HIGHBD_OBMCSADMXN(16, 8) |
| 251 | HIGHBD_OBMCSADMXN(8, 16) |
| 252 | HIGHBD_OBMCSADMXN(8, 8) |
| 253 | HIGHBD_OBMCSADMXN(8, 4) |
| 254 | HIGHBD_OBMCSADMXN(4, 8) |
| 255 | HIGHBD_OBMCSADMXN(4, 4) |
| 256 | |
Debargha Mukherjee | 1687085 | 2018-02-28 10:00:17 -0800 | [diff] [blame] | 257 | #if CONFIG_AV1 |
Sebastien Alaiwan | 20dadea | 2017-11-22 17:38:31 +0100 | [diff] [blame] | 258 | HIGHBD_OBMCSADMXN(4, 16) |
| 259 | HIGHBD_OBMCSADMXN(16, 4) |
| 260 | HIGHBD_OBMCSADMXN(8, 32) |
| 261 | HIGHBD_OBMCSADMXN(32, 8) |
| 262 | HIGHBD_OBMCSADMXN(16, 64) |
| 263 | HIGHBD_OBMCSADMXN(64, 16) |
| 264 | HIGHBD_OBMCSADMXN(32, 128) |
| 265 | HIGHBD_OBMCSADMXN(128, 32) |
| 266 | #endif |
| 267 | /* clang-format on */ |
Sebastien Alaiwan | 20dadea | 2017-11-22 17:38:31 +0100 | [diff] [blame] | 268 | #endif // CONFIG_AV1 |