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_ports/mem.h" 17 18#ifdef __cplusplus 19extern "C" { 20#endif 21 22#define MIN(x, y) (((x) < (y)) ? (x) : (y)) 23#define MAX(x, y) (((x) > (y)) ? (x) : (y)) 24 25#if CONFIG_VP9_HIGHBITDEPTH 26// Note: 27// tran_low_t is the datatype used for final transform coefficients. 28// tran_high_t is the datatype used for intermediate transform stages. 29typedef int64_t tran_high_t; 30typedef int32_t tran_low_t; 31#else 32// Note: 33// tran_low_t is the datatype used for final transform coefficients. 34// tran_high_t is the datatype used for intermediate transform stages. 35typedef int32_t tran_high_t; 36typedef int16_t tran_low_t; 37#endif // CONFIG_VP9_HIGHBITDEPTH 38 39static INLINE uint8_t clip_pixel(int val) { 40 return (val > 255) ? 255 : (val < 0) ? 0 : val; 41} 42 43static INLINE int clamp(int value, int low, int high) { 44 return value < low ? low : (value > high ? high : value); 45} 46 47static INLINE double fclamp(double value, double low, double high) { 48 return value < low ? low : (value > high ? high : value); 49} 50 51#if CONFIG_VP9_HIGHBITDEPTH 52static INLINE uint16_t clip_pixel_highbd(int val, int bd) { 53 switch (bd) { 54 case 8: 55 default: 56 return (uint16_t)clamp(val, 0, 255); 57 case 10: 58 return (uint16_t)clamp(val, 0, 1023); 59 case 12: 60 return (uint16_t)clamp(val, 0, 4095); 61 } 62} 63#endif // CONFIG_VP9_HIGHBITDEPTH 64 65#ifdef __cplusplus 66} // extern "C" 67#endif 68 69#endif // VPX_DSP_COMMON_H_ 70