blob: 3c49e500c0cff3b3772bd1309b03affcb23ef016 [file] [log] [blame]
Yaowu Xuc27fc142016-08-22 16:08:15 -07001/*
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07002 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Yaowu Xuc27fc142016-08-22 16:08:15 -07003 *
Yaowu Xu2ab7ff02016-09-02 12:04:54 -07004 * 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 Xuc27fc142016-08-22 16:08:15 -070010 */
11
Yaowu Xuf883b422016-08-30 14:01:10 -070012#ifndef AOM_DSP_INV_TXFM_H_
13#define AOM_DSP_INV_TXFM_H_
Yaowu Xuc27fc142016-08-22 16:08:15 -070014
15#include <assert.h>
16
Yaowu Xuf883b422016-08-30 14:01:10 -070017#include "./aom_config.h"
Yaowu Xuc27fc142016-08-22 16:08:15 -070018#include "aom_dsp/txfm_common.h"
19#include "aom_ports/mem.h"
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
25static INLINE tran_high_t check_range(tran_high_t input) {
26#if CONFIG_COEFFICIENT_RANGE_CHECKING
Yaowu Xuf883b422016-08-30 14:01:10 -070027 // For valid AV1 input streams, intermediate stage coefficients should always
Yaowu Xuc27fc142016-08-22 16:08:15 -070028 // stay within the range of a signed 16 bit integer. Coefficients can go out
Yaowu Xuf883b422016-08-30 14:01:10 -070029 // of this range for invalid/corrupt AV1 streams. However, strictly checking
Yaowu Xuc27fc142016-08-22 16:08:15 -070030 // this range for every intermediate coefficient can burdensome for a decoder,
31 // therefore the following assertion is only enabled when configured with
32 // --enable-coefficient-range-checking.
33 assert(INT16_MIN <= input);
34 assert(input <= INT16_MAX);
35#endif // CONFIG_COEFFICIENT_RANGE_CHECKING
36 return input;
37}
38
39static INLINE tran_high_t dct_const_round_shift(tran_high_t input) {
40 tran_high_t rv = ROUND_POWER_OF_TWO(input, DCT_CONST_BITS);
41 return rv;
42}
43
Yaowu Xuf883b422016-08-30 14:01:10 -070044#if CONFIG_AOM_HIGHBITDEPTH
Yaowu Xuc27fc142016-08-22 16:08:15 -070045static INLINE tran_high_t highbd_check_range(tran_high_t input, int bd) {
46#if CONFIG_COEFFICIENT_RANGE_CHECKING
Yaowu Xuf883b422016-08-30 14:01:10 -070047 // For valid highbitdepth AV1 streams, intermediate stage coefficients will
Yaowu Xuc27fc142016-08-22 16:08:15 -070048 // stay within the ranges:
49 // - 8 bit: signed 16 bit integer
50 // - 10 bit: signed 18 bit integer
51 // - 12 bit: signed 20 bit integer
52 const int32_t int_max = (1 << (7 + bd)) - 1;
53 const int32_t int_min = -int_max - 1;
54 assert(int_min <= input);
55 assert(input <= int_max);
56 (void)int_min;
57#endif // CONFIG_COEFFICIENT_RANGE_CHECKING
58 (void)bd;
59 return input;
60}
61
Yaowu Xuf883b422016-08-30 14:01:10 -070062#endif // CONFIG_AOM_HIGHBITDEPTH
Yaowu Xuc27fc142016-08-22 16:08:15 -070063
64#if CONFIG_EMULATE_HARDWARE
65// When CONFIG_EMULATE_HARDWARE is 1 the transform performs a
66// non-normative method to handle overflows. A stream that causes
67// overflows in the inverse transform is considered invalid,
68// and a hardware implementer is free to choose any reasonable
69// method to handle overflows. However to aid in hardware
70// verification they can use a specific implementation of the
71// WRAPLOW() macro below that is identical to their intended
72// hardware implementation (and also use configure options to trigger
73// the C-implementation of the transform).
74//
75// The particular WRAPLOW implementation below performs strict
76// overflow wrapping to match common hardware implementations.
77// bd of 8 uses trans_low with 16bits, need to remove 16bits
78// bd of 10 uses trans_low with 18bits, need to remove 14bits
79// bd of 12 uses trans_low with 20bits, need to remove 12bits
80// bd of x uses trans_low with 8+x bits, need to remove 24-x bits
81
82#define WRAPLOW(x) ((((int32_t)check_range(x)) << 16) >> 16)
Yaowu Xuf883b422016-08-30 14:01:10 -070083#if CONFIG_AOM_HIGHBITDEPTH
Yaowu Xuc27fc142016-08-22 16:08:15 -070084#define HIGHBD_WRAPLOW(x, bd) \
85 ((((int32_t)highbd_check_range((x), bd)) << (24 - bd)) >> (24 - bd))
Yaowu Xuf883b422016-08-30 14:01:10 -070086#endif // CONFIG_AOM_HIGHBITDEPTH
Yaowu Xuc27fc142016-08-22 16:08:15 -070087
88#else // CONFIG_EMULATE_HARDWARE
89
90#define WRAPLOW(x) ((int32_t)check_range(x))
Yaowu Xuf883b422016-08-30 14:01:10 -070091#if CONFIG_AOM_HIGHBITDEPTH
Yaowu Xuc27fc142016-08-22 16:08:15 -070092#define HIGHBD_WRAPLOW(x, bd) ((int32_t)highbd_check_range((x), bd))
Yaowu Xuf883b422016-08-30 14:01:10 -070093#endif // CONFIG_AOM_HIGHBITDEPTH
Yaowu Xuc27fc142016-08-22 16:08:15 -070094#endif // CONFIG_EMULATE_HARDWARE
95
Luca Barbatof0f98572016-09-03 12:14:15 +020096void aom_idct4_c(const tran_low_t *input, tran_low_t *output);
97void aom_idct8_c(const tran_low_t *input, tran_low_t *output);
98void aom_idct16_c(const tran_low_t *input, tran_low_t *output);
99void aom_idct32_c(const tran_low_t *input, tran_low_t *output);
100void aom_iadst4_c(const tran_low_t *input, tran_low_t *output);
101void aom_iadst8_c(const tran_low_t *input, tran_low_t *output);
102void aom_iadst16_c(const tran_low_t *input, tran_low_t *output);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700103
Yaowu Xuf883b422016-08-30 14:01:10 -0700104#if CONFIG_AOM_HIGHBITDEPTH
105void aom_highbd_idct4_c(const tran_low_t *input, tran_low_t *output, int bd);
106void aom_highbd_idct8_c(const tran_low_t *input, tran_low_t *output, int bd);
107void aom_highbd_idct16_c(const tran_low_t *input, tran_low_t *output, int bd);
108void aom_highbd_idct32_c(const tran_low_t *input, tran_low_t *output, int bd);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700109
Yaowu Xuf883b422016-08-30 14:01:10 -0700110void aom_highbd_iadst4_c(const tran_low_t *input, tran_low_t *output, int bd);
111void aom_highbd_iadst8_c(const tran_low_t *input, tran_low_t *output, int bd);
112void aom_highbd_iadst16_c(const tran_low_t *input, tran_low_t *output, int bd);
Yaowu Xuc27fc142016-08-22 16:08:15 -0700113
114static INLINE uint16_t highbd_clip_pixel_add(uint16_t dest, tran_high_t trans,
115 int bd) {
116 trans = HIGHBD_WRAPLOW(trans, bd);
117 return clip_pixel_highbd(dest + (int)trans, bd);
118}
119#endif
120
121static INLINE uint8_t clip_pixel_add(uint8_t dest, tran_high_t trans) {
122 trans = WRAPLOW(trans);
123 return clip_pixel(dest + (int)trans);
124}
125#ifdef __cplusplus
126} // extern "C"
127#endif
128
Yaowu Xuf883b422016-08-30 14:01:10 -0700129#endif // AOM_DSP_INV_TXFM_H_