µGFX  2.9
version 2.9
gdisp_colors.h
Go to the documentation of this file.
1 /*
2  * This file is subject to the terms of the GFX License. If a copy of
3  * the license was not distributed with this file, you can obtain one at:
4  *
5  * http://ugfx.io/license.html
6  */
7 
8 /**
9  * @file src/gdisp/gdisp_colors.h
10  *
11  * @defgroup Colors Colors
12  * @ingroup GDISP
13  *
14  * @brief Sub-Module for color handling.
15  *
16  * @{
17  */
18 
19 #ifndef _GDISP_COLORS_H
20 #define _GDISP_COLORS_H
21 
22 #include "../../gfx.h"
23 
24 #if GFX_USE_GDISP || defined(__DOXYGEN__)
25 
26 typedef gU16 gColorformat;
27 
28 /**
29  * @name Color system masks
30  *
31  * @details For pixel formats we do some assignment of codes to enable
32  * format auto-calculation. (Undocumented).
33  * 0x2RGB TRUECOLOR RGB format, R = red bits, G = green bits, B = blue bits
34  * 0x3RGB TRUECOLOR BGR format, R = red bits, G = green bits, B = blue bits
35  * 0x40XX GRAYSCALE XX = bits
36  * 0x60XX PALLETTE XX = bits
37  * 0x8XXX CUSTOM format.
38  * @{
39  */
40 #define GDISP_COLORSYSTEM_MASK 0xF000
41 #define GDISP_COLORSYSTEM_RGB 0x2000
42 #define GDISP_COLORSYSTEM_BGR 0x3000
43 /** @} */
44 
45 /**
46  * @name Color Type Constants
47  * @{
48  */
49 #define GDISP_COLORSYSTEM_TRUECOLOR 0x2000
50 #define GDISP_COLORSYSTEM_GRAYSCALE 0x4000
51 #define GDISP_COLORSYSTEM_PALETTE 0x6000
52 /** @} */
53 
54 /**
55  * @name Pixel Format Constants
56  * @{
57  */
58 #define GDISP_PIXELFORMAT_MONO (GDISP_COLORSYSTEM_GRAYSCALE|0x0001)
59 #define GDISP_PIXELFORMAT_GRAY4 (GDISP_COLORSYSTEM_GRAYSCALE|0x0002)
60 #define GDISP_PIXELFORMAT_GRAY16 (GDISP_COLORSYSTEM_GRAYSCALE|0x0004)
61 #define GDISP_PIXELFORMAT_GRAY256 (GDISP_COLORSYSTEM_GRAYSCALE|0x0008)
62 #define GDISP_PIXELFORMAT_RGB565 (GDISP_COLORSYSTEM_RGB|0x0565)
63 #define GDISP_PIXELFORMAT_BGR565 (GDISP_COLORSYSTEM_BGR|0x0565)
64 #define GDISP_PIXELFORMAT_RGB555 (GDISP_COLORSYSTEM_RGB|0x0555)
65 #define GDISP_PIXELFORMAT_BGR555 (GDISP_COLORSYSTEM_BGR|0x0555)
66 #define GDISP_PIXELFORMAT_RGB888 (GDISP_COLORSYSTEM_RGB|0x0888)
67 #define GDISP_PIXELFORMAT_BGR888 (GDISP_COLORSYSTEM_BGR|0x0888)
68 #define GDISP_PIXELFORMAT_RGB444 (GDISP_COLORSYSTEM_RGB|0x0444)
69 #define GDISP_PIXELFORMAT_BGR444 (GDISP_COLORSYSTEM_BGR|0x0444)
70 #define GDISP_PIXELFORMAT_RGB332 (GDISP_COLORSYSTEM_RGB|0x0332)
71 #define GDISP_PIXELFORMAT_BGR332 (GDISP_COLORSYSTEM_BGR|0x0233)
72 #define GDISP_PIXELFORMAT_RGB233 (GDISP_COLORSYSTEM_RGB|0x0233)
73 #define GDISP_PIXELFORMAT_BGR233 (GDISP_COLORSYSTEM_BGR|0x0332)
74 #define GDISP_PIXELFORMAT_RGB666 (GDISP_COLORSYSTEM_RGB|0x0666)
75 #define GDISP_PIXELFORMAT_BGR666 (GDISP_COLORSYSTEM_BGR|0x0666)
76 #define GDISP_PIXELFORMAT_ERROR 0x0000
77 /** @} */
78 
79 /**
80  * @name Some basic colors
81  * @{
82  */
83 #define GFX_WHITE HTML2COLOR(0xFFFFFF)
84 #define GFX_BLACK HTML2COLOR(0x000000)
85 #define GFX_GRAY HTML2COLOR(0x808080)
86 #define GFX_GREY GFX_GRAY
87 #define GFX_BLUE HTML2COLOR(0x0000FF)
88 #define GFX_RED HTML2COLOR(0xFF0000)
89 #define GFX_FUCHSIA HTML2COLOR(0xFF00FF)
90 #define GFX_MAGENTA GFX_FUCHSIA
91 #define GFX_GREEN HTML2COLOR(0x008000)
92 #define GFX_YELLOW HTML2COLOR(0xFFFF00)
93 #define GFX_AQUA HTML2COLOR(0x00FFFF)
94 #define GFX_CYAN GFX_AQUA
95 #define GFX_LIME HTML2COLOR(0x00FF00)
96 #define GFX_MAROON HTML2COLOR(0x800000)
97 #define GFX_NAVY HTML2COLOR(0x000080)
98 #define GFX_OLIVE HTML2COLOR(0x808000)
99 #define GFX_PURPLE HTML2COLOR(0x800080)
100 #define GFX_SILVER HTML2COLOR(0xC0C0C0)
101 #define GFX_TEAL HTML2COLOR(0x008080)
102 #define GFX_ORANGE HTML2COLOR(0xFFA500)
103 #define GFX_PINK HTML2COLOR(0xFFC0CB)
104 #define GFX_SKYBLUE HTML2COLOR(0x87CEEB)
105 /** @} */
106 
107 #if GFX_COMPAT_V2 && GFX_COMPAT_OLDCOLORS
108  #define White GFX_WHITE
109  #define Black GFX_BLACK
110  #define Gray GFX_GRAY
111  #define Grey GFX_GREY
112  #define Blue GFX_BLUE
113  #define Red GFX_RED
114  #define Fuchsia GFX_FUCHSIA
115  #define Magenta GFX_MAGENTA
116  #define Green GFX_GREEN
117  #define Yellow GFX_YELLOW
118  #define Aqua GFX_AQUA
119  #define Cyan GFX_CYAN
120  #define Lime GFX_LIME
121  #define Maroon GFX_MAROON
122  #define Navy GFX_NAVY
123  #define Olive GFX_OLIVE
124  #define Purple GFX_PURPLE
125  #define Silver GFX_SILVER
126  #define Teal GFX_TEAL
127  #define Orange GFX_ORANGE
128  #define Pink GFX_PINK
129  #define SkyBlue GFX_SKYBLUE
130 #endif
131 
132 #if defined(__DOXYGEN__)
133  /**
134  * @brief The color system (grayscale, palette or truecolor)
135  */
136  #define COLOR_SYSTEM GDISP_COLORSYSTEM_TRUECOLOR
137 
138  /**
139  * @brief The number of bits in a color value
140  */
141  #define COLOR_BITS 16
142 
143  /**
144  * @name Color bits
145  * @brief The number of bits for each of red, green and blue
146  * @{
147  */
148  #define COLOR_BITS_R 5
149  #define COLOR_BITS_G 6
150  #define COLOR_BITS_B 5
151  /** @} */
152 
153  /**
154  * @name Color bit shifts
155  * @brief The number of bits to shift each of red, green and blue to put it in the correct place in the color
156  * @{
157  */
158  #define COLOR_SHIFT_R 11
159  #define COLOR_SHIFT_G 5
160  #define COLOR_SHIFT_B 0
161  /** @} */
162 
163  /**
164  * @brief Does the color need masking to remove invalid bits
165  */
166  #define COLOR_NEEDS_MASK GFXOFF
167 
168  /**
169  * @brief If the color needs masking to remove invalid bits, this is the mask
170  */
171  #define COLOR_MASK 0xFFFF
172 
173  /**
174  * @brief The color type
175  */
176  #define COLOR_TYPE gU16
177 
178  /**
179  * @brief The number of bits in the color type (not necessarily the same as COLOR_BITS).
180  */
181  #define COLOR_TYPE_BITS 16
182 
183  /**
184  * @brief Convert a luminance (0 to 255) into a color value.
185  * @note The word "Luma" is used instead of grey or gray due to the spelling ambiguities of the word grey
186  * @note This is not a weighted luminance conversion in the color tv style.
187  * @note @p LUMA2COLOR() uses a linear conversion (0.33R + 0.33G + 0.33B). Note this is different to color
188  * tv luminance (0.26126R + 0.7152G + 0.0722B), digital tv luminance of (0.299R + 0.587G + 0.114B), or
189  * @p LUMA_OF() which uses (0.25R + 0.5G + 0.25B).
190  */
191  #define LUMA2COLOR(l) ((gColor)((((l) & 0xF8)<<8) | (((l) & 0xFC)<<3) | (((l) & 0xF8)>>3)))
192 
193  /**
194  * @brief Convert red, green, blue (each 0 to 255) into a color value.
195  */
196  #define RGB2COLOR(r,g,b) ((gColor)((((r) & 0xF8)<<8) | (((g) & 0xFC)<<3) | (((b) & 0xF8)>>3)))
197 
198  /**
199  * @brief Convert a 6 digit HTML code (hex) into a color value.
200  */
201  #define HTML2COLOR(h) ((gColor)((((h) & 0xF80000)>>8) | (((h) & 0x00FC00)>>5) | (((h) & 0x0000F8)>>3)))
202 
203  /**
204  * @name Extraction macros (quick)
205  *
206  * @brief Extract the luma/red/green/blue component (0 to 255) of a color value.
207  * @note This uses quick and dirty bit shifting. If you want more exact colors
208  * use @p EXACT_RED_OF() etc which uses multiplies and divides. For constant
209  * colors using @p EXACT_RED_OF() is no more expensive because the compiler
210  * evaluates the arithmetic.
211  * @note @p LUMA_OF() returns a roughly weighted luminance (0.25R + 0.5G + 0.25B). Note this is
212  * different to @p LUMA2COLOR() which uses a linear conversion (0.33R + 0.33G + 0.33B) and
213  * color tv luminance of (0.26126R + 0.7152G + 0.0722B) and digital tv luminance of (0.299R + 0.587G + 0.114B).
214  * @note A 5 bit color component maximum value (0x1F) converts to 0xF8 (slightly off-color)
215  * @{
216  */
217  #define LUMA_OF(c) ((RED_OF(c)+((gU16)GREEN_OF(c)<<1)+BLUE_OF(c))>>2)
218  #define RED_OF(c) (((c) & 0xF800)>>8)
219  #define GREEN_OF(c) (((c)&0x07E0)>>3)
220  #define BLUE_OF(c) (((c)&0x001F)<<3)
221  /** @} */
222 
223  /**
224  * @name Extraction macros (precise)
225  *
226  * @brief Extract the exact luma/red/green/blue component (0 to 255) of a color value.
227  * @note This uses multiplies and divides rather than bit shifting.
228  * This gives exact equivalent colors at the expense of more cpu intensive
229  * operations. Note for constants this is no more expensive than @p REF_OF()
230  * because the compiler evaluates the arithmetic.
231  * @note @p EXACT_LUMA_OF() returns a roughly weighted luminance (0.25R + 0.5G + 0.25B). Note this is
232  * different to @p LUMA2COLOR() which uses a linear conversion (0.33R + 0.33G + 0.33B) and
233  * color tv luminance of (0.26126R + 0.7152G + 0.0722B) and digital tv luminance of (0.299R + 0.587G + 0.114B).
234  * @note A 5 bit color component maximum value (0x1F) converts to 0xFF (the true equivalent color)
235  * @{
236  */
237  #define EXACT_LUMA_OF(c) ((EXACT_RED_OF(c)+((gU16)EXACT_GREEN_OF(c)<<1)+EXACT_BLUE_OF(c))>>2)
238  #define EXACT_RED_OF(c) (((((c)>>11)&0x1F)*255)/31)
239  #define EXACT_GREEN_OF(c) (((((c)>>5)&0x3F)*255)/63)
240  #define EXACT_BLUE_OF(c) (((((c)>>0)&0x1F)*255)/31)
241  /** @} */
242 #endif
243 
244 /*
245  * We use this big mess of macros to calculate all the components
246  * to prevent user errors in the color definitions. It greatly simplifies
247  * the above definitions and ensures a consistent implementation.
248  */
249 
250 //-------------------------
251 // True-Color color system
252 //-------------------------
253 #if GDISP_PIXELFORMAT & GDISP_COLORSYSTEM_TRUECOLOR
254  #define COLOR_SYSTEM GDISP_COLORSYSTEM_TRUECOLOR
255 
256  // Calculate the number of bits
257  #define COLOR_BITS_R ((GDISP_PIXELFORMAT>>8) & 0x0F)
258  #define COLOR_BITS_G ((GDISP_PIXELFORMAT>>4) & 0x0F)
259  #define COLOR_BITS_B ((GDISP_PIXELFORMAT>>0) & 0x0F)
260  #define COLOR_BITS (COLOR_BITS_R + COLOR_BITS_G + COLOR_BITS_B)
261 
262  // From the number of bits determine COLOR_TYPE, COLOR_TYPE_BITS and masking
263  #if COLOR_BITS <= 8
264  #define COLOR_TYPE gU8
265  #define COLOR_TYPE_BITS 8
266  #elif COLOR_BITS <= 16
267  #define COLOR_TYPE gU16
268  #define COLOR_TYPE_BITS 16
269  #elif COLOR_BITS <= 32
270  #define COLOR_TYPE gU32
271  #define COLOR_TYPE_BITS 32
272  #else
273  #error "GDISP: Cannot define color types with more than 32 bits"
274  #endif
275  #if COLOR_TYPE_BITS == COLOR_BITS
276  #define COLOR_NEEDS_MASK GFXOFF
277  #else
278  #define COLOR_NEEDS_MASK GFXON
279  #endif
280  #define COLOR_MASK() ((1 << COLOR_BITS)-1)
281 
282  // Calculate the component bit shifts
283  #if (GDISP_PIXELFORMAT & GDISP_COLORSYSTEM_MASK) == GDISP_COLORSYSTEM_RGB
284  #define COLOR_SHIFT_R (COLOR_BITS_B+COLOR_BITS_G)
285  #define COLOR_SHIFT_G COLOR_BITS_B
286  #define COLOR_SHIFT_B 0
287  #else
288  #define COLOR_SHIFT_B (COLOR_BITS_R+COLOR_BITS_G)
289  #define COLOR_SHIFT_G COLOR_BITS_R
290  #define COLOR_SHIFT_R 0
291  #endif
292 
293  // Calculate RED_OF, GREEN_OF, BLUE_OF and RGB2COLOR
294  #if COLOR_BITS_R + COLOR_SHIFT_R == 8
295  #define RED_OF(c) ((c) & (((1<<COLOR_BITS_R)-1) << COLOR_SHIFT_R))
296  #define RGB2COLOR_R(r) ((COLOR_TYPE)((r) & (0xFF & ~((1<<(8-COLOR_BITS_R))-1))))
297  #elif COLOR_BITS_R + COLOR_SHIFT_R > 8
298  #define RED_OF(c) (((c) & (((1<<COLOR_BITS_R)-1) << COLOR_SHIFT_R)) >> (COLOR_BITS_R+COLOR_SHIFT_R-8))
299  #define RGB2COLOR_R(r) (((COLOR_TYPE)((r) & (0xFF & ~((1<<(8-COLOR_BITS_R))-1)))) << (COLOR_BITS_R+COLOR_SHIFT_R-8))
300  #else // COLOR_BITS_R + COLOR_SHIFT_R < 8
301  #define RED_OF(c) (((c) & (((1<<COLOR_BITS_R)-1) << COLOR_SHIFT_R)) << (8-(COLOR_BITS_R+COLOR_SHIFT_R)))
302  #define RGB2COLOR_R(r) (((COLOR_TYPE)((r) & (0xFF & ~((1<<(8-COLOR_BITS_R))-1)))) >> (8-(COLOR_BITS_R+COLOR_SHIFT_R)))
303  #endif
304  #if COLOR_BITS_G + COLOR_SHIFT_G == 8
305  #define GREEN_OF(c) ((c) & (((1<<COLOR_BITS_G)-1) << COLOR_SHIFT_G))
306  #define RGB2COLOR_G(g) ((COLOR_TYPE)((g) & (0xFF & ~((1<<(8-COLOR_BITS_G))-1))))
307  #elif COLOR_BITS_G + COLOR_SHIFT_G > 8
308  #define GREEN_OF(c) (((c) & (((1<<COLOR_BITS_G)-1) << COLOR_SHIFT_G)) >> (COLOR_BITS_G+COLOR_SHIFT_G-8))
309  #define RGB2COLOR_G(g) (((COLOR_TYPE)((g) & (0xFF & ~((1<<(8-COLOR_BITS_G))-1)))) << (COLOR_BITS_G+COLOR_SHIFT_G-8))
310  #else // COLOR_BITS_G + COLOR_SHIFT_G < 8
311  #define GREEN_OF(c) (((c) & (((1<<COLOR_BITS_G)-1) << COLOR_SHIFT_G)) << (8-(COLOR_BITS_G+COLOR_SHIFT_G)))
312  #define RGB2COLOR_G(g) (((COLOR_TYPE)((g) & (0xFF & ~((1<<(8-COLOR_BITS_G))-1)))) >> (8-(COLOR_BITS_G+COLOR_SHIFT_G)))
313  #endif
314  #if COLOR_BITS_B + COLOR_SHIFT_B == 8
315  #define BLUE_OF(c) ((c) & (((1<<COLOR_BITS_B)-1) << COLOR_SHIFT_B))
316  #define RGB2COLOR_B(b) ((COLOR_TYPE)((b) & (0xFF & ~((1<<(8-COLOR_BITS_B))-1))))
317  #elif COLOR_BITS_B + COLOR_SHIFT_B > 8
318  #define BLUE_OF(c) (((c) & (((1<<COLOR_BITS_B)-1) << COLOR_SHIFT_B)) >> (COLOR_BITS_B+COLOR_SHIFT_B-8))
319  #define RGB2COLOR_B(b) (((COLOR_TYPE)((b) & (0xFF & ~((1<<(8-COLOR_BITS_B))-1)))) << (COLOR_BITS_B+COLOR_SHIFT_B-8))
320  #else // COLOR_BITS_B + COLOR_SHIFT_B < 8
321  #define BLUE_OF(c) (((c) & (((1<<COLOR_BITS_B)-1) << COLOR_SHIFT_B)) << (8-(COLOR_BITS_B+COLOR_SHIFT_B)))
322  #define RGB2COLOR_B(b) (((COLOR_TYPE)((b) & (0xFF & ~((1<<(8-COLOR_BITS_B))-1)))) >> (8-(COLOR_BITS_B+COLOR_SHIFT_B)))
323  #endif
324  #define LUMA_OF(c) ((RED_OF(c)+((gU16)GREEN_OF(c)<<1)+BLUE_OF(c))>>2)
325  #define EXACT_RED_OF(c) (((gU16)(((c)>>COLOR_SHIFT_R)&((1<<COLOR_BITS_R)-1))*255)/((1<<COLOR_BITS_R)-1))
326  #define EXACT_GREEN_OF(c) (((gU16)(((c)>>COLOR_SHIFT_G)&((1<<COLOR_BITS_G)-1))*255)/((1<<COLOR_BITS_G)-1))
327  #define EXACT_BLUE_OF(c) (((gU16)(((c)>>COLOR_SHIFT_B)&((1<<COLOR_BITS_B)-1))*255)/((1<<COLOR_BITS_B)-1))
328  #define EXACT_LUMA_OF(c) ((EXACT_RED_OF(c)+((gU16)EXACT_GREEN_OF(c)<<1)+EXACT_BLUE_OF(c))>>2)
329  #define LUMA2COLOR(l) (RGB2COLOR_R(l) | RGB2COLOR_G(l) | RGB2COLOR_B(l))
330  #define RGB2COLOR(r,g,b) (RGB2COLOR_R(r) | RGB2COLOR_G(g) | RGB2COLOR_B(b))
331 
332  // Calculate HTML2COLOR
333  #if COLOR_BITS_R + COLOR_SHIFT_R == 24
334  #define HTML2COLOR_R(h) ((h) & ((0xFFL & ~((1<<(8-COLOR_BITS_R))-1))<<16))
335  #elif COLOR_BITS_R + COLOR_SHIFT_R > 24
336  #define HTML2COLOR_R(h) (((h) & ((0xFFL & ~((1<<(8-COLOR_BITS_R))-1))<<16)) << (COLOR_BITS_R+COLOR_SHIFT_R-24))
337  #else // COLOR_BITS_R + COLOR_SHIFT_R < 24
338  #define HTML2COLOR_R(h) (((h) & ((0xFFL & ~((1<<(8-COLOR_BITS_R))-1))<<16)) >> (24-(COLOR_BITS_R+COLOR_SHIFT_R)))
339  #endif
340  #if COLOR_BITS_G + COLOR_SHIFT_G == 16
341  #define HTML2COLOR_G(h) ((h) & ((0xFFL & ~((1<<(8-COLOR_BITS_G))-1))<<8))
342  #elif COLOR_BITS_G + COLOR_SHIFT_G > 16
343  #define HTML2COLOR_G(h) (((h) & ((0xFFL & ~((1<<(8-COLOR_BITS_G))-1))<<8)) << (COLOR_BITS_G+COLOR_SHIFT_G-16))
344  #else // COLOR_BITS_G + COLOR_SHIFT_G < 16
345  #define HTML2COLOR_G(h) (((h) & ((0xFFL & ~((1<<(8-COLOR_BITS_G))-1))<<8)) >> (16-(COLOR_BITS_G+COLOR_SHIFT_G)))
346  #endif
347  #if COLOR_BITS_B + COLOR_SHIFT_B == 8
348  #define HTML2COLOR_B(h) ((h) & (0xFFL & ~((1<<(8-COLOR_BITS_B))-1)))
349  #elif COLOR_BITS_B + COLOR_SHIFT_B > 8
350  #define HTML2COLOR_B(h) (((h) & (0xFFL & ~((1<<(8-COLOR_BITS_B))-1))) << (COLOR_BITS_B+COLOR_SHIFT_B-8))
351  #else // COLOR_BITS_B + COLOR_SHIFT_B < 8
352  #define HTML2COLOR_B(h) (((h) & (0xFFL & ~((1<<(8-COLOR_BITS_B))-1))) >> (8-(COLOR_BITS_B+COLOR_SHIFT_B)))
353  #endif
354  #define HTML2COLOR(h) ((COLOR_TYPE)(HTML2COLOR_R(h) | HTML2COLOR_G(h) | HTML2COLOR_B(h)))
355 
356  // Special hack to allow alpha on RGB888
357  #if GDISP_PIXELFORMAT == GDISP_PIXELFORMAT_RGB888
358  #define COLOR_BITS_A 8
359  #define COLOR_SHIFT_A 24
360  #define ALPHA_OF(c) (((c)>>24) ^ 0xFF)
361  #define EXACT_ALPHA_OF(c) ALPHA_OF((c))
362  #define AHTML2COLOR(h) ((h) ^ 0xFF000000)
363  #define RGB2COLOR_A(a) (((COLOR_TYPE)(((a) ^ 0xFF) & 0xFF)) << 24)
364  #define ARGB2COLOR(a,r,g,b) (RGB2COLOR_A(a) | RGB2COLOR_R(r) | RGB2COLOR_G(g) | RGB2COLOR_B(b))
365  #define GFXTRANSPARENT (0xFF000000)
366  #endif
367 
368 //-------------------------
369 // Gray-scale color system
370 //-------------------------
371 #elif (GDISP_PIXELFORMAT & GDISP_COLORSYSTEM_MASK) == GDISP_COLORSYSTEM_GRAYSCALE
372  #define COLOR_SYSTEM GDISP_COLORSYSTEM_GRAYSCALE
373 
374  // Calculate the number of bits and shifts
375  #define COLOR_BITS (GDISP_PIXELFORMAT & 0xFF)
376  #define COLOR_BITS_R COLOR_BITS
377  #define COLOR_BITS_G COLOR_BITS
378  #define COLOR_BITS_B COLOR_BITS
379  #define COLOR_SHIFT_R 0
380  #define COLOR_SHIFT_G 0
381  #define COLOR_SHIFT_B 0
382 
383  // From the number of bits determine COLOR_TYPE, COLOR_TYPE_BITS and masking
384  #if COLOR_BITS <= 8
385  #define COLOR_TYPE gU8
386  #define COLOR_TYPE_BITS 8
387  #else
388  #error "GDISP: Cannot define gray-scale color types with more than 8 bits"
389  #endif
390  #if COLOR_TYPE_BITS == COLOR_BITS
391  #define COLOR_NEEDS_MASK GFXOFF
392  #else
393  #define COLOR_NEEDS_MASK GFXON
394  #endif
395  #define COLOR_MASK() ((1 << COLOR_BITS)-1)
396 
397  #if COLOR_BITS == 1
398  #define RGB2COLOR(r,g,b) (((r)|(g)|(b)) ? 1 : 0)
399  #define LUMA2COLOR(l) ((l) ? 1 : 0)
400  #define HTML2COLOR(h) ((h) ? 1 : 0)
401  #define LUMA_OF(c) ((c) ? 255 : 0)
402  #define EXACT_LUMA_OF(c) LUMA_OF(c)
403  #else
404  // They eye is more sensitive to green
405  #define RGB2COLOR(r,g,b) ((COLOR_TYPE)(((gU16)(r)+(g)+(g)+(b)) >> (10-COLOR_BITS)))
406  #define LUMA2COLOR(l) ((COLOR_TYPE)((l)>>(8-COLOR_BITS)))
407  #define HTML2COLOR(h) ((COLOR_TYPE)(((((h)&0xFF0000)>>16)+(((h)&0x00FF00)>>7)+((h)&0x0000FF)) >> (10-COLOR_BITS)))
408  #define LUMA_OF(c) (((c) & ((1<<COLOR_BITS)-1)) << (8-COLOR_BITS))
409  #define EXACT_LUMA_OF(c) ((((gU16)(c) & ((1<<COLOR_BITS)-1))*255)/((1<<COLOR_BITS)-1))
410  #endif
411 
412  #define RED_OF(c) LUMA_OF(c)
413  #define GREEN_OF(c) LUMA_OF(c)
414  #define BLUE_OF(c) LUMA_OF(c)
415  #define EXACT_RED_OF(c) EXACT_LUMA_OF(c)
416  #define EXACT_GREEN_OF(c) EXACT_LUMA_OF(c)
417  #define EXACT_BLUE_OF(c) EXACT_LUMA_OF(c)
418 
419 //-------------------------
420 // Palette color system
421 //-------------------------
422 #elif (GDISP_PIXELFORMAT & GDISP_COLORSYSTEM_MASK) == GDISP_COLORSYSTEM_PALETTE
423  #define COLOR_SYSTEM GDISP_COLORSYSTEM_PALETTE
424 
425  #error "GDISP: A palette color system is not currently supported"
426 
427 //-------------------------
428 // Some other color system
429 //-------------------------
430 #else
431  #error "GDISP: Unsupported color system"
432 #endif
433 
434 /**
435  * @brief The color type definition
436  */
438 
439 #endif /* GFX_USE_GDISP */
440 
441 #endif /* _GDISP_COLORS_H */
442 /** @} */
COLOR_TYPE gColor
The color type definition.
Definition: gdisp_colors.h:437
#define COLOR_TYPE
The color type.
Definition: gdisp_colors.h:176