1 /****************************************************************************** 2 * 3 * Copyright (C) 2015 The Android Open Source Project 4 * 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at: 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 * 17 ***************************************************************************** 18 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore 19 */ 20 21 /** 22 ********************************************************************************** 23 * @file 24 * ih264_macros.h 25 * 26 * @brief 27 * Macro definitions used in the codec 28 * 29 * @author 30 * ittiam 31 * 32 * @remarks 33 * none 34 * 35 ******************************************************************************* 36 */ 37 38 #ifndef _IH264_MACROS_H_ 39 #define _IH264_MACROS_H_ 40 41 /*****************************************************************************/ 42 /* Function Macros */ 43 /*****************************************************************************/ 44 #define RETURN_IF(cond, retval) if(cond) {return (retval);} 45 #define UNUSED(x) ((void)(x)) 46 47 #define ALIGN128(x) ((((x) + 127) >> 7) << 7) 48 #define ALIGN64(x) ((((x) + 63) >> 6) << 6) 49 #define ALIGN32(x) ((((x) + 31) >> 5) << 5) 50 #define ALIGN16(x) ((((x) + 15) >> 4) << 4) 51 #define ALIGN8(x) ((((x) + 7) >> 3) << 3) 52 #define ALIGN4(x) ((((x) + 3) >> 2) << 2) 53 #define ALIGN2(x) ((((x) + 1) >> 1) << 1) 54 55 /** 56 ****************************************************************************** 57 * @brief Min, Max 58 ****************************************************************************** 59 */ 60 #define MAX(a,b) ((a > b)?(a):(b)) 61 #define MIN(a,b) ((a < b)?(a):(b)) 62 #define MIN3(a,b,c) ((a) < (b)) ? (((a) < (c)) ? (a) : (c)) : (((b) < (c)) ? (b) : (c)) 63 #define MAX3(a,b,c) ((a) > (b)) ? (((a) > (c)) ? (a) : (c)) : (((b) > (c)) ? (b) : (c)) 64 /** 65 ****************************************************************************** 66 * @brief Div, Mod 67 ****************************************************************************** 68 */ 69 #define MOD(x,y) ((x)%(y)) 70 #define DIV(x,y) ((x)/(y)) 71 72 /** 73 ****************************************************************************** 74 * @brief Clip 75 ****************************************************************************** 76 */ 77 #define CLIP3(miny, maxy, y) (((y) < (miny))?(miny):(((y) > (maxy))?(maxy):(y))) 78 79 /** 80 ****************************************************************************** 81 * @brief True, False 82 ****************************************************************************** 83 */ 84 #define BOOLEAN(x) (!!(x)) 85 86 /** 87 ****************************************************************************** 88 * @brief Frequently used multiplications x2. x3, and x4 89 ****************************************************************************** 90 */ 91 #define X2(a) ((a) << 1) 92 #define X3(a) (((a) << 1) + (a)) 93 #define X4(a) ((a) << 2) 94 95 /** 96 ****************************************************************************** 97 * @brief Misc 98 ****************************************************************************** 99 */ 100 #define ABS(x) ((x) < 0 ? (-(x)) : (x)) 101 #define SIGNXY(x,y) (((y) < 0) ? (-1 * (x)) : (x)) 102 103 #define SIGN(x) (((x) >= 0) ? (((x) > 0) ? 1 : 0) : -1) 104 105 #define RESET_BIT(x, pos) (x) = (x) & ~(1 << pos); 106 #define SET_BIT(x, pos) (x) = (x) | (1 << pos); 107 #define GET_BIT(x, pos) ((x) >> (pos)) & 0x1 108 109 #define INSERT_BIT(x, pos, bit) { RESET_BIT(x, pos); (x) = (x) | (bit << pos); } 110 111 #endif /*_IH264_MACROS_H_ */ 112 113 114