1 /*
2 * Copyright (c) 2015 The WebM project authors. All Rights Reserved.
3 *
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.
9 */
10
11 #ifndef VPX_DSP_VPX_DSP_COMMON_H_
12 #define VPX_DSP_VPX_DSP_COMMON_H_
13
14 #include "./vpx_config.h"
15 #include "vpx/vpx_integer.h"
16 #include "vpx_ports/mem.h"
17
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21
22 #define VPXMIN(x, y) (((x) < (y)) ? (x) : (y))
23 #define VPXMAX(x, y) (((x) > (y)) ? (x) : (y))
24
25 #define VPX_SWAP(type, a, b) \
26 do { \
27 type c = (b); \
28 b = a; \
29 a = c; \
30 } while (0)
31
32 #if CONFIG_VP9_HIGHBITDEPTH
33 // Note:
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;
38 #else
39 // Note:
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
45
clip_pixel(int val)46 static INLINE uint8_t clip_pixel(int val) {
47 return (val > 255) ? 255 : (val < 0) ? 0 : val;
48 }
49
clamp(int value,int low,int high)50 static INLINE int clamp(int value, int low, int high) {
51 return value < low ? low : (value > high ? high : value);
52 }
53
fclamp(double value,double low,double high)54 static INLINE double fclamp(double value, double low, double high) {
55 return value < low ? low : (value > high ? high : value);
56 }
57
58 #if CONFIG_VP9_HIGHBITDEPTH
clip_pixel_highbd(int val,int bd)59 static INLINE uint16_t clip_pixel_highbd(int val, int bd) {
60 switch (bd) {
61 case 8:
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);
65 }
66 }
67 #endif // CONFIG_VP9_HIGHBITDEPTH
68
69 #ifdef __cplusplus
70 } // extern "C"
71 #endif
72
73 #endif // VPX_DSP_VPX_DSP_COMMON_H_
74