Choco OS  V.0.16.9.0
Join to the chocolate world
oc_color.h
Go to the documentation of this file.
1 
28 #ifndef SYSTEM_LIBRARIES_INC_OC_COLOR_H_
29 #define SYSTEM_LIBRARIES_INC_OC_COLOR_H_
30 
31 #include <stdint.h>
32 #include <oc_bits.h>
33 #include <oc_stdtypes.h>
34 
40 #define _________________________________________TYPES_SECTION______________________________________________________________________________
41 
42 typedef enum
43 {
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 ,
51 } oC_Color_t;
52 
53 typedef enum
54 {
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 ),
59 } oC_ColorFormat_t;
60 
61 #undef _________________________________________TYPES_SECTION______________________________________________________________________________
62 
68 #define _________________________________________MACROS_SECTION_____________________________________________________________________________
69 
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 )
80 
81 #undef _________________________________________MACROS_SECTION_____________________________________________________________________________
82 
88 #define _________________________________________STATIC_INLINE_SECTION______________________________________________________________________
89 
90 static inline oC_UInt_t oC_Color_GetFormatSize( oC_ColorFormat_t ColorFormat )
91 {
92  return (oC_Color_FormatSize(ColorFormat));
93 }
94 
95 static inline oC_Color_t oC_Color_ConvertToFormat( oC_Color_t Color , oC_ColorFormat_t FormatIn , oC_ColorFormat_t FormatOut )
96 {
97  oC_Color_t convertedColor = 0;
98 
99  if(FormatIn != FormatOut)
100  {
101  uint32_t formatMask = 0xF;
102  uint8_t componentStartBitIndexIn = 0;
103  uint8_t componentStartBitIndexOut = 0;
104 
105  for(uint8_t colorComponentIndex = 0;colorComponentIndex<4;colorComponentIndex++)
106  {
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;
114 
115  oC_Bits_SetValueU32((uint32_t*)(&convertedColor),componentOut,componentStartBitIndexOut,componentEndBitIndexOut);
116 
117  componentStartBitIndexIn = (bitsIn > 0) ? componentEndBitIndexIn + 1 : componentStartBitIndexIn;
118  componentStartBitIndexOut = (bitsOut > 0) ? componentEndBitIndexOut + 1 : componentStartBitIndexOut;
119 
120  formatMask = formatMask << 4;
121  }
122  }
123  else
124  {
125  convertedColor = Color;
126  }
127 
128  return convertedColor;
129 }
130 
131 #undef _________________________________________STATIC_INLINE_SECTION______________________________________________________________________
132 
133 
134 #endif /* SYSTEM_LIBRARIES_INC_OC_COLOR_H_ */
static uint32_t oC_Bits_SetValueU32(uint32_t *outVariable, uint32_t Value, uint8_t StartBitNr, uint8_t EndBitNr)
Definition: oc_bits.h:308
static uint32_t oC_Bits_GetValueU32(uint32_t Variable, uint8_t StartBitNr, uint8_t EndBitNr)
Definition: oc_bits.h:395
The file with functions for the bits operation.
FILE__DESCRIPTION