1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 /** 17 ****************************************************************************** 18 * @file M4VIFI_Defines.h 19 * @brief Macro Definition 20 * @note This file defines all the macro used in the filter library 21 ****************************************************************************** 22 */ 23 24 #ifndef _M4VIFI_DEFINES_H_ 25 #define _M4VIFI_DEFINES_H_ 26 27 /** 28 ***************************************************************************** 29 * Macros used for color transform RGB565 to YUV 30 ***************************************************************************** 31 */ 32 #define CST_RGB_16_SIZE 2 33 #define Y16(r, g, b) CLIP( ( ( (80593 * r)+(77855 * g)+(30728 * b)) >> 15)) 34 #define U16(r, g, b) CLIP(128+ ( ( -(45483 * r)-(43936 * g)+(134771 * b)) >> 15 )) 35 #define V16(r, g, b) CLIP(128+ ( ( (134771 * r)-(55532 * g)-(21917 * b)) >> 15 )) 36 37 38 /** 39 ***************************************************************************** 40 * Macros used for color transform YUV to RGB 41 * B = 1.164(Y - 16) + 2.018(U - 128) 42 * G = 1.164(Y - 16) - 0.813(V - 128) - 0.391(U - 128) 43 * R = 1.164(Y - 16) + 1.596(V - 128) 44 * Above Conversion Formula is implemented for fixed point operation 45 ***************************************************************************** 46 */ 47 48 #define CST_RGB_24_SIZE 3 49 50 #ifdef __RGB_V1__ 51 #define DEMATRIX(Rx,Gx,Bx,Yx37,Ux,Vx) \ 52 Rx = CLIP(((Yx37 + (Vx * 51) + 16) >> 5) - 223); \ 53 Gx = CLIP(((Yx37 - ((Ux+(Vx<<1)) * 13) +16) >> 5) + 135); \ 54 Bx = CLIP(((Yx37 + (Ux * 65) + 16) >> 5) - 277) 55 #else 56 #define DEMATRIX(Rx,Gx,Bx,Yx2568,Ux,Vx) \ 57 Rx = CLIP(((Yx2568 + (Vx * 0x3343) + (M4VIFI_Int32)0xffe40800) >> 13)); \ 58 Gx = CLIP(((Yx2568 - (Ux * 0x0c92) - (Vx * 0x1a1e) + (M4VIFI_Int32)0x00110180) >> 13)); \ 59 Bx = CLIP(((Yx2568 + (Ux * 0x40cf) + (M4VIFI_Int32)0xffdd4200) >> 13)); 60 #endif /* __RGB_V1__ */ 61 62 /** 63 ***************************************************************************** 64 * Packing and Unpacking is different for little and big endian 65 * r, g, b, Rx, Gx, Bx are 8 bit color value 66 * a, data are 16 bit pixel value 67 ***************************************************************************** 68 */ 69 70 /* Pack computations common for little endian and big endian modes */ 71 #define PACK_BGR24(rgb_ptr,Rx,Gx,Bx) {rgb_ptr[0] = (M4VIFI_UInt8)Bx; rgb_ptr[1] =\ 72 (M4VIFI_UInt8)Gx; rgb_ptr[2] = (M4VIFI_UInt8)Rx;} 73 #define PACK_RGB24(rgb_ptr,Rx,Gx,Bx) {rgb_ptr[0] = (M4VIFI_UInt8)Rx; rgb_ptr[1] =\ 74 (M4VIFI_UInt8)Gx; rgb_ptr[2] = (M4VIFI_UInt8)Bx;} 75 76 #ifdef BIG_ENDIAN 77 #define PACK_RGB565(a, Rx, Gx, Bx) (((Rx >> 3) << (11 + (a)))\ 78 | ((Gx >> 2) << (5 + (a))) | ((Bx >> 3) << (a))) 79 #define PACK_BGR565(a, Rx, Gx, Bx) (((Bx >> 3) << (11 + (a)))\ 80 | ((Gx >> 2) << (5 + (a))) | ((Rx >> 3) << (a))) 81 #define GET_RGB565(r, g, b, data) {b = ((data) & 31); g =\ 82 ((data >> 5) & 63); r = ((data >> 11) & 31);} 83 #define GET_BGR565(b, g, r, data) \ 84 r = ((data) & 31); \ 85 g = ((data >> 5) & 63); \ 86 b = ((data >> 11) & 31 ); 87 #else /* LITTLE endian: 0x12345678 -> 78 56 34 12 */ 88 #define PACK_RGB565(a, Rx, Gx, Bx) (((Bx >> 3) << (8 + (a))) \ 89 | (((Gx >> 2)&0x7) << (13 + (a))) | ((Gx >> 5) << (a)) | ((Rx >> 3) << (3 + a))) 90 #define PACK_BGR565(a, Rx, Gx, Bx) (((Rx >> 3) << (11 + (a))) \ 91 | ((Gx >> 2) << (5 + (a))) | ((Bx >> 3) << (a))) 92 #define GET_RGB565(r, g, b, data) { b = (M4VIFI_UInt8)(((data) & 0x1F00) >> 8); g =\ 93 (M4VIFI_UInt8)((((data) & 0x7) << 3) | (((data) & 0xE000) >> 13)); r =\ 94 (M4VIFI_UInt8)(((data) & 0xF8) >> 3);} 95 #define GET_BGR565(b, g, r, data) \ 96 b = ((data) & 31); \ 97 g = ((data >> 5) & 63); \ 98 r = ((data >> 11) & 31 ); 99 #endif /* BIG_ENDIAN */ 100 101 102 #define CST_RGB_24_SIZE 3 103 #define Y24(r,g,b) CLIP(( ( (19595 * r) + (38470 * g) + (9437 * b) ) >>16)) 104 #define U24(r,g,b) CLIP(128 + ( ( -(11059 * r) - (21709 * g) + (32768 * b)) >>16)) 105 #define V24(r,g,b) CLIP(128 + ( ( (32768 * r) - (27426 * g) - (5329 * b)) >>16)) 106 #define GET_RGB24(r,g,b,s,o) r = s[o]; g = s[o + 1]; b = s[o + 2]; 107 108 /** 109 *********************************************************************************** 110 * Macro for clipping using the clipping matrix for RGB values 111 *********************************************************************************** 112 */ 113 /** Clip function ensures values with range of 0 and 255 */ 114 #define CLIP(x) *(M4VIFI_ClipTable_zero + (x)) 115 #define CLIP_OVF 500 116 #define CLIP_LUT_SIZE (256 + 2 * CLIP_OVF) 117 /** Division table for RGB565 to HLS conversion */ 118 #define DIVCLIP(x) *(M4VIFI_DivTable_zero + (x)) 119 120 /** 121 ***************************************************************************** 122 * Endianness (default configuration is Little Endian) 123 ***************************************************************************** 124 */ 125 #if (!defined(LITTLE_ENDIAN) && !defined(BIG_ENDIAN)) 126 /** Default endian setting */ 127 #define LITTLE_ENDIAN 128 #endif 129 130 /** 131 ***************************************************************************** 132 * Other macros and define 133 ***************************************************************************** 134 */ 135 /** YUV plane index */ 136 #define PLANES 3 137 #define YPlane 0 138 #define UPlane 1 139 #define VPlane 2 140 141 /** Check for value is EVEN */ 142 #ifndef IS_EVEN 143 #define IS_EVEN(a) (!(a & 0x01)) 144 #endif 145 146 /* Used for fixed point implementation */ 147 #ifndef MAX_SHORT 148 #define MAX_SHORT 0x10000 149 #endif 150 151 #endif /* _M4VIFI_DEFINES_H_ */ 152 153 /* End of file M4VIFI_Defines.h */ 154 155