]> granicus.if.org Git - libvpx/blob - vpx_dsp/vpx_dsp_common.h
vpx_dsp/*.[hc]: add missing vpx_dsp_rtcd.h include
[libvpx] / vpx_dsp / vpx_dsp_common.h
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_COMMON_H_
12 #define VPX_DSP_COMMON_H_
13
14 #include "./vpx_config.h"
15 #include "vpx/vpx_integer.h"
16 #include "vpx_dsp/vpx_dsp_common.h"
17 #include "vpx_ports/mem.h"
18
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22
23 #define VPXMIN(x, y) (((x) < (y)) ? (x) : (y))
24 #define VPXMAX(x, y) (((x) > (y)) ? (x) : (y))
25
26 #if CONFIG_VP9_HIGHBITDEPTH
27 // Note:
28 // tran_low_t  is the datatype used for final transform coefficients.
29 // tran_high_t is the datatype used for intermediate transform stages.
30 typedef int64_t tran_high_t;
31 typedef int32_t tran_low_t;
32 #else
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 int32_t tran_high_t;
37 typedef int16_t tran_low_t;
38 #endif  // CONFIG_VP9_HIGHBITDEPTH
39
40 static INLINE uint8_t clip_pixel(int val) {
41   return (val > 255) ? 255 : (val < 0) ? 0 : val;
42 }
43
44 static INLINE int clamp(int value, int low, int high) {
45   return value < low ? low : (value > high ? high : value);
46 }
47
48 static INLINE double fclamp(double value, double low, double high) {
49   return value < low ? low : (value > high ? high : value);
50 }
51
52 #if CONFIG_VP9_HIGHBITDEPTH
53 static INLINE uint16_t clip_pixel_highbd(int val, int bd) {
54   switch (bd) {
55     case 8:
56     default:
57       return (uint16_t)clamp(val, 0, 255);
58     case 10:
59       return (uint16_t)clamp(val, 0, 1023);
60     case 12:
61       return (uint16_t)clamp(val, 0, 4095);
62   }
63 }
64 #endif  // CONFIG_VP9_HIGHBITDEPTH
65
66 #ifdef __cplusplus
67 }  // extern "C"
68 #endif
69
70 #endif  // VPX_DSP_COMMON_H_