aom_dsp_common.h 2.08 KB
Newer Older
Jingning Han's avatar
Jingning Han committed
1
/*
2
 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
Jingning Han's avatar
Jingning Han committed
3
 *
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 12 13 14
 */

#ifndef VPX_DSP_COMMON_H_
#define VPX_DSP_COMMON_H_

Adrian Grange's avatar
Adrian Grange committed
15 16 17
#include "./aom_config.h"
#include "aom/aom_integer.h"
#include "aom_dsp/aom_dsp_common.h"
Yaowu Xu's avatar
Yaowu Xu committed
18
#include "aom_ports/mem.h"
Jingning Han's avatar
Jingning Han committed
19 20 21 22 23

#ifdef __cplusplus
extern "C" {
#endif

24 25
#define VPXMIN(x, y) (((x) < (y)) ? (x) : (y))
#define VPXMAX(x, y) (((x) > (y)) ? (x) : (y))
Jingning Han's avatar
Jingning Han committed
26

27 28 29 30 31
#if CONFIG_AOM_QM
typedef uint16_t qm_val_t;
#define AOM_QM_BITS 6
#endif

32
#if CONFIG_AOM_HIGHBITDEPTH
33 34 35 36 37 38 39 40 41 42 43
// Note:
// tran_low_t  is the datatype used for final transform coefficients.
// tran_high_t is the datatype used for intermediate transform stages.
typedef int64_t tran_high_t;
typedef int32_t tran_low_t;
#else
// Note:
// tran_low_t  is the datatype used for final transform coefficients.
// tran_high_t is the datatype used for intermediate transform stages.
typedef int32_t tran_high_t;
typedef int16_t tran_low_t;
44
#endif  // CONFIG_AOM_HIGHBITDEPTH
45

Jingning Han's avatar
Jingning Han committed
46 47 48 49 50 51 52 53 54 55 56 57
static INLINE uint8_t clip_pixel(int val) {
  return (val > 255) ? 255 : (val < 0) ? 0 : val;
}

static INLINE int clamp(int value, int low, int high) {
  return value < low ? low : (value > high ? high : value);
}

static INLINE double fclamp(double value, double low, double high) {
  return value < low ? low : (value > high ? high : value);
}

58
#if CONFIG_AOM_HIGHBITDEPTH
59 60 61
static INLINE uint16_t clip_pixel_highbd(int val, int bd) {
  switch (bd) {
    case 8:
clang-format's avatar
clang-format committed
62 63 64
    default: return (uint16_t)clamp(val, 0, 255);
    case 10: return (uint16_t)clamp(val, 0, 1023);
    case 12: return (uint16_t)clamp(val, 0, 4095);
65 66
  }
}
67
#endif  // CONFIG_AOM_HIGHBITDEPTH
68

Jingning Han's avatar
Jingning Han committed
69 70 71 72 73
#ifdef __cplusplus
}  // extern "C"
#endif

#endif  // VPX_DSP_COMMON_H_