28 #ifndef SYSTEM_LIBRARIES_INC_OC_COLOR_H_ 29 #define SYSTEM_LIBRARIES_INC_OC_COLOR_H_ 40 #define _________________________________________TYPES_SECTION______________________________________________________________________________ 44 oC_Color_White = 0xffffff ,
45 oC_Color_Black = 0x000000 ,
46 oC_Color_Red = 0xff0000 ,
47 oC_Color_Green = 0x00ff00 ,
48 oC_Color_Blue = 0x0000ff ,
49 oC_Color_Yellow = 0xffff00 ,
50 oC_Color_Purple = 0xff00ff ,
55 oC_ColorFormat_Unknown = 0 ,
56 oC_ColorFormat_ARGB8888 = ( 8 << 12 ) | ( 8 << 8 ) | ( 8 << 4 ) | ( 8 << 0 ),
57 oC_ColorFormat_RGB888 = ( 0 << 12 ) | ( 8 << 8 ) | ( 8 << 4 ) | ( 8 << 0 ),
58 oC_ColorFormat_RGB565 = ( 0 << 12 ) | ( 5 << 8 ) | ( 6 << 4 ) | ( 5 << 0 ),
61 #undef _________________________________________TYPES_SECTION______________________________________________________________________________ 68 #define _________________________________________MACROS_SECTION_____________________________________________________________________________ 70 #define oC_ColorFormat_IsCorrect(ColorFormat) ( (ColorFormat) != 0 ) 71 #define oC_ColorFormat_GetNoAlphaBits(ColorFormat) ( ((ColorFormat) & 0xF000) >> 12 ) 72 #define oC_ColorFormat_GetNoRedBits(ColorFormat) ( ((ColorFormat) & 0x0F00) >> 8 ) 73 #define oC_ColorFormat_GetNoGreenBits(ColorFormat) ( ((ColorFormat) & 0x00F0) >> 4 ) 74 #define oC_ColorFormat_GetNoBlueBits(ColorFormat) ( ((ColorFormat) & 0x000F) >> 0 ) 75 #define oC_Color_IsCorrect(Color) ( (Color) <= 0xFFFFFFFF && (Color) >= 0 ) 76 #define oC_Color_FormatSize(ColorFormat) ((oC_ColorFormat_GetNoAlphaBits(ColorFormat) + \ 77 oC_ColorFormat_GetNoRedBits(ColorFormat) + \ 78 oC_ColorFormat_GetNoGreenBits(ColorFormat) + \ 79 oC_ColorFormat_GetNoBlueBits(ColorFormat)) / 8 ) 81 #undef _________________________________________MACROS_SECTION_____________________________________________________________________________ 88 #define _________________________________________STATIC_INLINE_SECTION______________________________________________________________________ 90 static inline oC_UInt_t oC_Color_GetFormatSize( oC_ColorFormat_t ColorFormat )
92 return (oC_Color_FormatSize(ColorFormat));
95 static inline oC_Color_t oC_Color_ConvertToFormat( oC_Color_t Color , oC_ColorFormat_t FormatIn , oC_ColorFormat_t FormatOut )
97 oC_Color_t convertedColor = 0;
99 if(FormatIn != FormatOut)
101 uint32_t formatMask = 0xF;
102 uint8_t componentStartBitIndexIn = 0;
103 uint8_t componentStartBitIndexOut = 0;
105 for(uint8_t colorComponentIndex = 0;colorComponentIndex<4;colorComponentIndex++)
107 uint8_t formatStartBitIndex = colorComponentIndex * 4;
108 uint8_t bitsIn = (uint8_t)((FormatIn & formatMask) >> formatStartBitIndex);
109 uint8_t bitsOut = (uint8_t)((FormatOut & formatMask) >> formatStartBitIndex);
110 uint8_t componentEndBitIndexIn = componentStartBitIndexIn + bitsIn - 1;
111 uint8_t componentEndBitIndexOut= componentStartBitIndexOut + bitsOut - 1;
112 uint32_t componentIn = (bitsIn > 0) ?
oC_Bits_GetValueU32(Color, componentStartBitIndexIn , componentEndBitIndexIn) : 0;
113 uint32_t componentOut = (bitsOut > 0) ?
oC_Bits_GetValueU32(componentIn , 0 , bitsOut - 1) : 0;
115 oC_Bits_SetValueU32((uint32_t*)(&convertedColor),componentOut,componentStartBitIndexOut,componentEndBitIndexOut);
117 componentStartBitIndexIn = (bitsIn > 0) ? componentEndBitIndexIn + 1 : componentStartBitIndexIn;
118 componentStartBitIndexOut = (bitsOut > 0) ? componentEndBitIndexOut + 1 : componentStartBitIndexOut;
120 formatMask = formatMask << 4;
125 convertedColor = Color;
128 return convertedColor;
131 #undef _________________________________________STATIC_INLINE_SECTION______________________________________________________________________ static uint32_t oC_Bits_SetValueU32(uint32_t *outVariable, uint32_t Value, uint8_t StartBitNr, uint8_t EndBitNr)
static uint32_t oC_Bits_GetValueU32(uint32_t Variable, uint8_t StartBitNr, uint8_t EndBitNr)
The file with functions for the bits operation.