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_VPX_DSP_VPX_DSP_COMMON_H_
12 #define VPX_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
46 typedef int16_t tran_coef_t;
47
clip_pixel(int val)48 static INLINE uint8_t clip_pixel(int val) {
49 return (val > 255) ? 255 : (val < 0) ? 0 : val;
50 }
51
clamp(int value,int low,int high)52 static INLINE int clamp(int value, int low, int high) {
53 return value < low ? low : (value > high ? high : value);
54 }
55
fclamp(double value,double low,double high)56 static INLINE double fclamp(double value, double low, double high) {
57 return value < low ? low : (value > high ? high : value);
58 }
59
lclamp(int64_t value,int64_t low,int64_t high)60 static INLINE int64_t lclamp(int64_t value, int64_t low, int64_t high) {
61 return value < low ? low : (value > high ? high : value);
62 }
63
clip_pixel_highbd(int val,int bd)64 static INLINE uint16_t clip_pixel_highbd(int val, int bd) {
65 switch (bd) {
66 case 8:
67 default: return (uint16_t)clamp(val, 0, 255);
68 case 10: return (uint16_t)clamp(val, 0, 1023);
69 case 12: return (uint16_t)clamp(val, 0, 4095);
70 }
71 }
72
73 #ifdef __cplusplus
74 } // extern "C"
75 #endif
76
77 #endif // VPX_VPX_DSP_VPX_DSP_COMMON_H_
78