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 19extern "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. 36typedef int64_t tran_high_t; 37typedef 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. 42typedef int32_t tran_high_t; 43typedef int16_t tran_low_t; 44#endif // CONFIG_VP9_HIGHBITDEPTH 45 46typedef int16_t tran_coef_t; 47 48static INLINE uint8_t clip_pixel(int val) { 49 return (val > 255) ? 255 : (val < 0) ? 0 : val; 50} 51 52static INLINE int clamp(int value, int low, int high) { 53 return value < low ? low : (value > high ? high : value); 54} 55 56static INLINE double fclamp(double value, double low, double high) { 57 return value < low ? low : (value > high ? high : value); 58} 59 60static INLINE uint16_t clip_pixel_highbd(int val, int bd) { 61 switch (bd) { 62 case 8: 63 default: return (uint16_t)clamp(val, 0, 255); 64 case 10: return (uint16_t)clamp(val, 0, 1023); 65 case 12: return (uint16_t)clamp(val, 0, 4095); 66 } 67} 68 69#ifdef __cplusplus 70} // extern "C" 71#endif 72 73#endif // VPX_DSP_VPX_DSP_COMMON_H_ 74