2 * Copyright (c) 2015 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
11 #ifndef VPX_DSP_VPX_DSP_COMMON_H_
12 #define VPX_DSP_VPX_DSP_COMMON_H_
14 #include "./vpx_config.h"
15 #include "vpx/vpx_integer.h"
16 #include "vpx_ports/mem.h"
22 #define VPXMIN(x, y) (((x) < (y)) ? (x) : (y))
23 #define VPXMAX(x, y) (((x) > (y)) ? (x) : (y))
25 #define VPX_SWAP(type, a, b) \
32 #if CONFIG_VP9_HIGHBITDEPTH
34 // tran_low_t is the datatype used for final transform coefficients.
35 // tran_high_t is the datatype used for intermediate transform stages.
36 typedef int64_t tran_high_t;
37 typedef int32_t tran_low_t;
40 // tran_low_t is the datatype used for final transform coefficients.
41 // tran_high_t is the datatype used for intermediate transform stages.
42 typedef int32_t tran_high_t;
43 typedef int16_t tran_low_t;
44 #endif // CONFIG_VP9_HIGHBITDEPTH
46 static INLINE uint8_t clip_pixel(int val) {
47 return (val > 255) ? 255 : (val < 0) ? 0 : val;
50 static INLINE int clamp(int value, int low, int high) {
51 return value < low ? low : (value > high ? high : value);
54 static INLINE double fclamp(double value, double low, double high) {
55 return value < low ? low : (value > high ? high : value);
58 #if CONFIG_VP9_HIGHBITDEPTH
59 static INLINE uint16_t clip_pixel_highbd(int val, int bd) {
62 default: return (uint16_t)clamp(val, 0, 255);
63 case 10: return (uint16_t)clamp(val, 0, 1023);
64 case 12: return (uint16_t)clamp(val, 0, 4095);
67 #endif // CONFIG_VP9_HIGHBITDEPTH
73 #endif // VPX_DSP_VPX_DSP_COMMON_H_