filter.h 4.68 KB
Newer Older
Jingning Han's avatar
Jingning Han committed
1
/*
Yaowu Xu's avatar
Yaowu Xu committed
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Jingning Han's avatar
Jingning Han committed
3
 *
Yaowu Xu's avatar
Yaowu Xu committed
4 5 6 7 8 9
 * This source code is subject to the terms of the BSD 2 Clause License and
 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
 * was not distributed with this source code in the LICENSE file, you can
 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
 * Media Patent License 1.0 was not distributed with this source code in the
 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
Jingning Han's avatar
Jingning Han committed
10 11
 */

Yaowu Xu's avatar
Yaowu Xu committed
12 13
#ifndef AV1_COMMON_FILTER_H_
#define AV1_COMMON_FILTER_H_
Jingning Han's avatar
Jingning Han committed
14

15 16
#include <assert.h>

Yaowu Xu's avatar
Yaowu Xu committed
17 18 19
#include "./aom_config.h"
#include "aom/aom_integer.h"
#include "aom_dsp/aom_filter.h"
20
#include "aom_ports/mem.h"
Jingning Han's avatar
Jingning Han committed
21 22 23 24 25

#ifdef __cplusplus
extern "C" {
#endif

26
#define USE_TEMPORALFILTER_12TAP 1
27
#define MAX_FILTER_TAP 12
28

Jingning Han's avatar
Jingning Han committed
29
#define USE_12TAP_FILTER 0
30
#define USE_EXTRA_FILTER 0
Jingning Han's avatar
Jingning Han committed
31

32
typedef enum {
33 34
  EIGHTTAP_REGULAR,
  EIGHTTAP_SMOOTH,
35
#if USE_EXTRA_FILTER
36
  EIGHTTAP_SMOOTH2,
37
#endif  // USE_EXTRA_FILTER
38
  MULTITAP_SHARP,
39
  BILINEAR,
40
#if USE_EXTRA_FILTER
41 42 43 44 45
  EIGHTTAP_SHARP,
  FILTER_REGULAR_UV,
  FILTER_SMOOTH_UV,
  FILTER_SHARP_UV,
  FILTER_SMOOTH2_UV,
46
#endif  // USE_EXTRA_FILTER
47 48 49 50 51 52 53 54
  INTERP_FILTERS_ALL,
  SWITCHABLE_FILTERS = BILINEAR,
  SWITCHABLE = SWITCHABLE_FILTERS + 1, /* the last switchable one */
  EXTRA_FILTERS = INTERP_FILTERS_ALL - SWITCHABLE_FILTERS,
#if USE_TEMPORALFILTER_12TAP
  TEMPORALFILTER_12TAP = SWITCHABLE_FILTERS + EXTRA_FILTERS,
#endif
} InterpFilter;
55

56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
// With CONFIG_DUAL_FILTER, pack two InterpFilter's into a uint32_t: since
// there are at most 10 filters, we can use 16 bits for each and have more than
// enough space. This reduces argument passing and unifies the operation of
// setting a (pair of) filters.
//
// Without CONFIG_DUAL_FILTER,
#if CONFIG_DUAL_FILTER
typedef uint32_t InterpFilters;
static INLINE InterpFilter av1_extract_interp_filter(InterpFilters filters,
                                                     int x_filter) {
  return (InterpFilter)((filters >> (x_filter ? 16 : 0)) & 0xffff);
}

static INLINE InterpFilters av1_make_interp_filters(InterpFilter y_filter,
                                                    InterpFilter x_filter) {
  uint16_t y16 = y_filter & 0xffff;
  uint16_t x16 = x_filter & 0xffff;
  return y16 | ((uint32_t)x16 << 16);
}

static INLINE InterpFilters av1_broadcast_interp_filter(InterpFilter filter) {
  return av1_make_interp_filters(filter, filter);
}
#else
typedef InterpFilter InterpFilters;
static INLINE InterpFilter av1_extract_interp_filter(InterpFilters filters,
                                                     int x_filter) {
83 84 85
#ifdef NDEBUG
  (void)x_filter;
#endif
86 87 88 89 90 91 92 93 94 95 96 97 98
  assert(!x_filter);
  return filters;
}

static INLINE InterpFilters av1_broadcast_interp_filter(InterpFilter filter) {
  return filter;
}
#endif

static INLINE InterpFilter av1_unswitchable_filter(InterpFilter filter) {
  return filter == SWITCHABLE ? EIGHTTAP_REGULAR : filter;
}

Frederic Barbier's avatar
Frederic Barbier committed
99
#if USE_EXTRA_FILTER
100 101
#define LOG_SWITCHABLE_FILTERS \
  3 /* (1 << LOG_SWITCHABLE_FILTERS) > SWITCHABLE_FILTERS */
Frederic Barbier's avatar
Frederic Barbier committed
102 103 104 105 106 107 108
#else
#define LOG_SWITCHABLE_FILTERS \
  2 /* (1 << LOG_SWITCHABLE_FILTERS) > SWITCHABLE_FILTERS */
#endif

#if CONFIG_DUAL_FILTER
#define MAX_SUBPEL_TAPS 12
109 110 111 112 113 114
#define SWITCHABLE_FILTER_CONTEXTS ((SWITCHABLE_FILTERS + 1) * 4)
#define INTER_FILTER_COMP_OFFSET (SWITCHABLE_FILTERS + 1)
#define INTER_FILTER_DIR_OFFSET ((SWITCHABLE_FILTERS + 1) * 2)
#else  // CONFIG_DUAL_FILTER
#define SWITCHABLE_FILTER_CONTEXTS (SWITCHABLE_FILTERS + 1)
#endif  // CONFIG_DUAL_FILTER
115

116
#if CONFIG_EXT_INTRA
hui su's avatar
hui su committed
117
#if CONFIG_INTRA_INTERP
118 119 120 121 122 123 124 125
typedef enum {
  INTRA_FILTER_LINEAR,
  INTRA_FILTER_8TAP,
  INTRA_FILTER_8TAP_SHARP,
  INTRA_FILTER_8TAP_SMOOTH,
  INTRA_FILTERS,
} INTRA_FILTER;

Yaowu Xu's avatar
Yaowu Xu committed
126
extern const InterpKernel *av1_intra_filter_kernels[INTRA_FILTERS];
hui su's avatar
hui su committed
127
#endif  // CONFIG_INTRA_INTERP
128 129
#endif  // CONFIG_EXT_INTRA

130
typedef struct InterpFilterParams {
clang-format's avatar
clang-format committed
131
  const int16_t *filter_ptr;
132
  uint16_t taps;
133
  uint16_t subpel_shifts;
134
  InterpFilter interp_filter;
135 136
} InterpFilterParams;

Yaowu Xu's avatar
Yaowu Xu committed
137
InterpFilterParams av1_get_interp_filter_params(
James Zern's avatar
James Zern committed
138
    const InterpFilter interp_filter);
139

James Zern's avatar
James Zern committed
140
const int16_t *av1_get_interp_filter_kernel(const InterpFilter interp_filter);
141

Yaowu Xu's avatar
Yaowu Xu committed
142
static INLINE const int16_t *av1_get_interp_filter_subpel_kernel(
143
    const InterpFilterParams filter_params, const int subpel) {
144 145 146
  return filter_params.filter_ptr + filter_params.taps * subpel;
}

Yaowu Xu's avatar
Yaowu Xu committed
147
static INLINE int av1_is_interpolating_filter(
James Zern's avatar
James Zern committed
148
    const InterpFilter interp_filter) {
Yaowu Xu's avatar
Yaowu Xu committed
149
  const InterpFilterParams ip = av1_get_interp_filter_params(interp_filter);
150
  return (ip.filter_ptr[ip.taps / 2 - 1] == 128);
151
}
152

153 154 155 156
#if CONFIG_DUAL_FILTER
InterpFilter av1_get_plane_interp_filter(InterpFilter interp_filter, int plane);
#endif

Jingning Han's avatar
Jingning Han committed
157 158 159 160
#ifdef __cplusplus
}  // extern "C"
#endif

Yaowu Xu's avatar
Yaowu Xu committed
161
#endif  // AV1_COMMON_FILTER_H_