Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 1 | /* |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 2 | * Copyright (c) 2016, Alliance for Open Media. All rights reserved |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 3 | * |
Yaowu Xu | 2ab7ff0 | 2016-09-02 12:04:54 -0700 | [diff] [blame] | 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. |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 10 | */ |
| 11 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 12 | #ifndef AV1_COMMON_FILTER_H_ |
| 13 | #define AV1_COMMON_FILTER_H_ |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 14 | |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 15 | #include <assert.h> |
| 16 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 17 | #include "./aom_config.h" |
| 18 | #include "aom/aom_integer.h" |
| 19 | #include "aom_dsp/aom_filter.h" |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 20 | #include "aom_ports/mem.h" |
| 21 | |
| 22 | #ifdef __cplusplus |
| 23 | extern "C" { |
| 24 | #endif |
| 25 | |
Yunqing Wang | 3ec11d1 | 2018-01-05 12:45:08 -0800 | [diff] [blame] | 26 | #define MAX_FILTER_TAP 8 |
Jingning Han | b14c179 | 2017-04-20 15:10:29 -0700 | [diff] [blame] | 27 | |
Urvang Joshi | f5f5c84 | 2017-10-19 16:17:54 -0700 | [diff] [blame] | 28 | typedef enum ATTRIBUTE_PACKED { |
Urvang Joshi | a9b174b | 2017-02-17 11:50:12 -0800 | [diff] [blame] | 29 | EIGHTTAP_REGULAR, |
| 30 | EIGHTTAP_SMOOTH, |
Thomas Davies | ec92c11 | 2017-09-25 11:03:58 +0100 | [diff] [blame] | 31 | MULTITAP_SHARP, |
Urvang Joshi | a9b174b | 2017-02-17 11:50:12 -0800 | [diff] [blame] | 32 | BILINEAR, |
Urvang Joshi | a9b174b | 2017-02-17 11:50:12 -0800 | [diff] [blame] | 33 | INTERP_FILTERS_ALL, |
| 34 | SWITCHABLE_FILTERS = BILINEAR, |
| 35 | SWITCHABLE = SWITCHABLE_FILTERS + 1, /* the last switchable one */ |
| 36 | EXTRA_FILTERS = INTERP_FILTERS_ALL - SWITCHABLE_FILTERS, |
Urvang Joshi | a9b174b | 2017-02-17 11:50:12 -0800 | [diff] [blame] | 37 | } InterpFilter; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 38 | |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 39 | // With CONFIG_DUAL_FILTER, pack two InterpFilter's into a uint32_t: since |
| 40 | // there are at most 10 filters, we can use 16 bits for each and have more than |
| 41 | // enough space. This reduces argument passing and unifies the operation of |
| 42 | // setting a (pair of) filters. |
| 43 | // |
| 44 | // Without CONFIG_DUAL_FILTER, |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 45 | typedef uint32_t InterpFilters; |
| 46 | static INLINE InterpFilter av1_extract_interp_filter(InterpFilters filters, |
| 47 | int x_filter) { |
| 48 | return (InterpFilter)((filters >> (x_filter ? 16 : 0)) & 0xffff); |
| 49 | } |
| 50 | |
| 51 | static INLINE InterpFilters av1_make_interp_filters(InterpFilter y_filter, |
| 52 | InterpFilter x_filter) { |
| 53 | uint16_t y16 = y_filter & 0xffff; |
| 54 | uint16_t x16 = x_filter & 0xffff; |
| 55 | return y16 | ((uint32_t)x16 << 16); |
| 56 | } |
| 57 | |
| 58 | static INLINE InterpFilters av1_broadcast_interp_filter(InterpFilter filter) { |
| 59 | return av1_make_interp_filters(filter, filter); |
| 60 | } |
Rupert Swarbrick | 27e9029 | 2017-09-28 17:46:50 +0100 | [diff] [blame] | 61 | |
| 62 | static INLINE InterpFilter av1_unswitchable_filter(InterpFilter filter) { |
| 63 | return filter == SWITCHABLE ? EIGHTTAP_REGULAR : filter; |
| 64 | } |
| 65 | |
Frederic Barbier | 7b35d733e | 2017-07-11 17:32:39 +0200 | [diff] [blame] | 66 | #define LOG_SWITCHABLE_FILTERS \ |
| 67 | 2 /* (1 << LOG_SWITCHABLE_FILTERS) > SWITCHABLE_FILTERS */ |
Frederic Barbier | 7b35d733e | 2017-07-11 17:32:39 +0200 | [diff] [blame] | 68 | |
Frederic Barbier | 7b35d733e | 2017-07-11 17:32:39 +0200 | [diff] [blame] | 69 | #define MAX_SUBPEL_TAPS 12 |
Angie Chiang | 1733f6b | 2017-01-05 09:52:20 -0800 | [diff] [blame] | 70 | #define SWITCHABLE_FILTER_CONTEXTS ((SWITCHABLE_FILTERS + 1) * 4) |
| 71 | #define INTER_FILTER_COMP_OFFSET (SWITCHABLE_FILTERS + 1) |
| 72 | #define INTER_FILTER_DIR_OFFSET ((SWITCHABLE_FILTERS + 1) * 2) |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 73 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 74 | typedef struct InterpFilterParams { |
| 75 | const int16_t *filter_ptr; |
| 76 | uint16_t taps; |
| 77 | uint16_t subpel_shifts; |
Angie Chiang | b9ba5c2 | 2016-10-03 16:39:27 -0700 | [diff] [blame] | 78 | InterpFilter interp_filter; |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 79 | } InterpFilterParams; |
| 80 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 81 | InterpFilterParams av1_get_interp_filter_params( |
James Zern | 7b9407a | 2016-05-18 23:48:05 -0700 | [diff] [blame] | 82 | const InterpFilter interp_filter); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 83 | |
James Zern | 7b9407a | 2016-05-18 23:48:05 -0700 | [diff] [blame] | 84 | const int16_t *av1_get_interp_filter_kernel(const InterpFilter interp_filter); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 85 | |
Zhijie Yang | f02f8ae | 2017-10-26 17:58:29 -0700 | [diff] [blame] | 86 | InterpFilterParams av1_get_interp_filter_params_with_block_size( |
| 87 | const InterpFilter interp_filter, const int w); |
Zhijie Yang | f02f8ae | 2017-10-26 17:58:29 -0700 | [diff] [blame] | 88 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 89 | static INLINE const int16_t *av1_get_interp_filter_subpel_kernel( |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 90 | const InterpFilterParams filter_params, const int subpel) { |
| 91 | return filter_params.filter_ptr + filter_params.taps * subpel; |
| 92 | } |
| 93 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 94 | static INLINE int av1_is_interpolating_filter( |
James Zern | 7b9407a | 2016-05-18 23:48:05 -0700 | [diff] [blame] | 95 | const InterpFilter interp_filter) { |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 96 | const InterpFilterParams ip = av1_get_interp_filter_params(interp_filter); |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 97 | return (ip.filter_ptr[ip.taps / 2 - 1] == 128); |
| 98 | } |
| 99 | |
Yaowu Xu | c27fc14 | 2016-08-22 16:08:15 -0700 | [diff] [blame] | 100 | #ifdef __cplusplus |
| 101 | } // extern "C" |
| 102 | #endif |
| 103 | |
Yaowu Xu | f883b42 | 2016-08-30 14:01:10 -0700 | [diff] [blame] | 104 | #endif // AV1_COMMON_FILTER_H_ |