MPLABĀ® Harmony Graphics Suite  GFX v3.13.0
Legato API Documentation
legato_color.h
Go to the documentation of this file.
1 /*******************************************************************************
2 * Copyright (C) 2020 Microchip Technology Inc. and its subsidiaries.
3 *
4 * Subject to your compliance with these terms, you may use Microchip software
5 * and any derivatives exclusively with Microchip products. It is your
6 * responsibility to comply with third party license terms applicable to your
7 * use of third party software (including open source software) that may
8 * accompany Microchip software.
9 *
10 * THIS SOFTWARE IS SUPPLIED BY MICROCHIP "AS IS". NO WARRANTIES, WHETHER
11 * EXPRESS, IMPLIED OR STATUTORY, APPLY TO THIS SOFTWARE, INCLUDING ANY IMPLIED
12 * WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, AND FITNESS FOR A
13 * PARTICULAR PURPOSE.
14 *
15 * IN NO EVENT WILL MICROCHIP BE LIABLE FOR ANY INDIRECT, SPECIAL, PUNITIVE,
16 * INCIDENTAL OR CONSEQUENTIAL LOSS, DAMAGE, COST OR EXPENSE OF ANY KIND
17 * WHATSOEVER RELATED TO THE SOFTWARE, HOWEVER CAUSED, EVEN IF MICROCHIP HAS
18 * BEEN ADVISED OF THE POSSIBILITY OR THE DAMAGES ARE FORESEEABLE. TO THE
19 * FULLEST EXTENT ALLOWED BY LAW, MICROCHIP'S TOTAL LIABILITY ON ALL CLAIMS IN
20 * ANY WAY RELATED TO THIS SOFTWARE WILL NOT EXCEED THE AMOUNT OF FEES, IF ANY,
21 * THAT YOU HAVE PAID DIRECTLY TO MICROCHIP FOR THIS SOFTWARE.
22 *******************************************************************************/
23 
24 /*******************************************************************************
25  Module for Microchip Graphics Library - Legato User Interface Library
26 
27  Company:
28  Microchip Technology Inc.
29 
30  File Name:
31  legato_color.h
32 
33  Summary:
34  Contains functions for color information and manipulation operations
35 
36  Description:
37  Color conversion and color channel management
38 *******************************************************************************/
39 
47 #ifndef LE_COLOR_H
48 #define LE_COLOR_H
49 
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
53 
55 
59 typedef uint32_t leColor;
60 
61 #define LE_COLOR_MAX_SIZE 4
62 
63 #define RGB_8_BITS 255
64 #define RGB_6_BITS 63
65 #define RGB_5_BITS 31
66 #define RGB_3_BITS 7
67 #define RGB_2_BITS 2
68 
69 #define RGB_332_RED_MASK 0xE0
70 #define RGB_332_GREEN_MASK 0x1C
71 #define RGB_332_BLUE_MASK 0x3
72 
73 #define RGB_565_RED_MASK 0xF800
74 #define RGB_565_GREEN_MASK 0x7E0
75 #define RGB_565_BLUE_MASK 0x1F
76 
77 #define RGBA_5551_RED_MASK 0xF800
78 #define RGBA_5551_GREEN_MASK 0x7C0
79 #define RGBA_5551_BLUE_MASK 0x3E
80 #define RGBA_5551_ALPHA_MASK 0x1
81 
82 #define RGB_888_RED_MASK 0xFF0000
83 #define RGB_888_GREEN_MASK 0xFF00
84 #define RGB_888_BLUE_MASK 0xFF
85 
86 #define RGBA_8888_RED_MASK 0xFF000000
87 #define RGBA_8888_GREEN_MASK 0xFF0000
88 #define RGBA_8888_BLUE_MASK 0xFF00
89 #define RGBA_8888_ALPHA_MASK 0xFF
90 
91 #define ARGB_8888_RED_MASK 0xFF0000
92 #define ARGB_8888_GREEN_MASK 0xFF00
93 #define ARGB_8888_BLUE_MASK 0xFF
94 #define ARGB_8888_ALPHA_MASK 0xFF000000
95 
99 // *****************************************************************************
100 // *****************************************************************************
101 // Section: Data Types and Constants
102 // *****************************************************************************
103 // *****************************************************************************
104 
105 // *****************************************************************************
106 /* Enumeration:
107  leColorMask
108 
109  Summary:
110  Maskable list of color valies.
111 
112 */
117 typedef enum leColorMask
118 {
119  LE_COLOR_MASK_GS_8 = 0x1,
120  LE_COLOR_MASK_PALETTE = 0x1,
121  LE_COLOR_MASK_RGB_332 = 0x4,
122  LE_COLOR_MASK_RGB_565 = 0x8,
123  LE_COLOR_MASK_RGBA_5551 = 0x10,
124  LE_COLOR_MASK_RGB_888 = 0x20,
125  LE_COLOR_MASK_RGBA_8888 = 0x40,
126  LE_COLOR_MASK_ARGB_8888 = 0x80,
127  LE_COLOR_MASK_ALL = LE_COLOR_MASK_GS_8 |
128  LE_COLOR_MASK_RGB_332 |
129  LE_COLOR_MASK_RGB_565 |
130  LE_COLOR_MASK_RGBA_5551 |
131  LE_COLOR_MASK_RGB_888 |
132  LE_COLOR_MASK_RGBA_8888 |
133  LE_COLOR_MASK_ARGB_8888
134 } leColorMask;
135 
136 // *****************************************************************************
137 /* Enumeration:
138  leColorMode
139 
140  Summary:
141  List of available color modes.
142 */
148 typedef enum leColorMode
149 {
150  LE_COLOR_MODE_GS_8 = 0,
151  LE_COLOR_MODE_RGB_332 = 1,
152  LE_COLOR_MODE_RGB_565 = 2,
153  LE_COLOR_MODE_RGBA_5551 = 3,
154  LE_COLOR_MODE_RGB_888 = 4,
155  LE_COLOR_MODE_RGBA_8888 = 5,
156  LE_COLOR_MODE_ARGB_8888 = 6,
157  LE_COLOR_MODE_INDEX_1 = 7,
158  LE_COLOR_MODE_INDEX_4 = 8,
159  LE_COLOR_MODE_INDEX_8 = 9,
160  LE_COLOR_MODE_PALETTE = LE_COLOR_MODE_INDEX_8,
161  LE_COLOR_MODE_MONOCHROME = 10
162 } leColorMode;
163 
164 #define LE_COLOR_MODE_LAST_COLOR (LE_COLOR_MODE_MONOCHROME)
165 #define LE_COLOR_MODE_COUNT (LE_COLOR_MODE_LAST_COLOR + 1)
166 
167 #define LE_COLOR_MODE_IS_PIXEL(mode) ((mode >= LE_COLOR_MODE_GS_8) && (mode <= LE_COLOR_MODE_ARGB_8888))
168 #define LE_COLOR_MODE_IS_INDEX(mode) ((mode >= LE_COLOR_MODE_INDEX_1) && (mode <= LE_COLOR_MODE_INDEX_8))
169 
170 #define LE_COLOR_MODE_IS_ALPHA(mode) ((mode == LE_COLOR_MODE_RGBA_5551) || (mode == LE_COLOR_MODE_RGBA_8888) || (mode == LE_COLOR_MODE_ARGB_8888))
171 
172 // *****************************************************************************
173 /* Enumeration:
174  leBitsPerPixel
175 
176  Summary:
177  List of available bits-per-pixel sizes.
178 */
185 typedef enum leBitsPerPixel
186 {
187  LE_BPP1,
188  LE_BPP4,
189  LE_BPP8,
190  LE_BPP16,
191  LE_BPP24,
192  LE_BPP32
194 
195 // *****************************************************************************
196 /* Structure:
197  leColorModeInfo
198 
199  Summary:
200  Struct that provides information about a color mode.
201 
202  Description:
203  size - size in bytes
204  bpp - bpp value
205  bppOrdinal - bpp enum value
206  masks - the masks used for extracting individual color channel information
207 
208  Remarks:
209  None.
210 */
216 typedef struct leColorModeInfo
217 {
218  uint32_t size;
219  uint32_t bpp;
220  leBitsPerPixel bppOrdinal;
222  struct
223  {
224  uint32_t red;
225  uint32_t green;
226  uint32_t blue;
227  uint32_t alpha;
228  } mask;
230  struct
231  {
232  uint8_t red;
233  uint8_t green;
234  uint8_t blue;
235  uint8_t alpha;
236  } shift;
237 
239 
240 // *****************************************************************************
241 /* Data Table:
242  leColorInfoTable
243 
244  Summary:
245  Color information reference table
246 */
251 extern const leColorModeInfo leColorInfoTable[];
252 
253 // *****************************************************************************
254 /* Structure:
255  leColorName
256 
257  Summary:
258  Color name reference table
259 */
264 typedef enum leColorName
265 {
266  LE_COLOR_BLACK,
267  LE_COLOR_WHITE,
268  LE_COLOR_RED,
269  LE_COLOR_LIME,
270  LE_COLOR_BLUE,
271  LE_COLOR_YELLOW,
272  LE_COLOR_CYAN,
273  LE_COLOR_MAGENTA,
274  LE_COLOR_SILVER,
275  LE_COLOR_DARKGRAY,
276  LE_COLOR_GRAY,
277  LE_COLOR_LIGHTGRAY,
278  LE_COLOR_MAROON,
279  LE_COLOR_OLIVE,
280  LE_COLOR_GREEN,
281  LE_COLOR_PURPLE,
282  LE_COLOR_TEAL,
283  LE_COLOR_NAVY,
284  LE_COLOR_LAST
285 } leColorName;
286 
293 typedef struct leBlendLookupTable
294 {
295  leColor foreground;
296  leColor background;
299  const void* data;
301 
302 // *****************************************************************************
303 // *****************************************************************************
304 // Section: Routines
305 // *****************************************************************************
306 // *****************************************************************************
307 
308 // *****************************************************************************
309 /* Function:
310  leColor leColorValue(leColorMode mode, leColorName name)
311 
312  Summary:
313  Used for getting a color value by name.
314 
315  Parameters:
316  leColorMode - the color mode for the return type
317  leColorName - the name of the color to retrieve
318 
319  Returns:
320  leColor - the color value of the given name in the specified format
321 
322  Remarks:
323 
324 */
338 leColor leColorValue(leColorMode mode, leColorName name);
339 
340 // *****************************************************************************
341 /* Function:
342  uint32_t leColorChannelRed(leColor clr, leColorMode mode)
343 
344  Summary:
345  Used for getting the red color channel of a given color value.
346 
347  Description:
348 
349 
350  Parameters:
351  leColor - the source color value
352  leColorMode - the source color mode
353 
354  Returns:
355  uint32_t - the red color channel
356 
357  Remarks:
358 
359 */
373 uint32_t leColorChannelRed(leColor clr, leColorMode mode);
374 
375 // *****************************************************************************
376 /* Function:
377  uint32_t leColorChannelGreen(leColor clr, leColorMode mode)
378 
379  Summary:
380  Used for getting the green color channel of a given color value.
381 
382  Description:
383 
384 
385  Parameters:
386  leColor - the source color value
387  leColorMode - the source color mode
388 
389  Returns:
390  uint32_t - the green color channel
391 
392  Remarks:
393 
394 */
408 uint32_t leColorChannelGreen(leColor clr, leColorMode mode);
409 
410 // *****************************************************************************
411 /* Function:
412  uint32_t leColorChannelBlue(leColor clr, leColorMode mode)
413 
414  Summary:
415  Used for getting the blue color channel of a given color value.
416 
417  Description:
418 
419 
420  Parameters:
421  leColor - the source color value
422  leColorMode - the source color mode
423 
424  Returns:
425  uint32_t - the blue color channel
426 
427  Remarks:
428 
429 */
443 uint32_t leColorChannelBlue(leColor clr, leColorMode mode);
444 
445 // *****************************************************************************
446 /* Function:
447  uint32_t leColorChannelAlpha(leColor clr, leColorMode mode)
448 
449  Summary:
450  Used for getting the alpha color channel of a given color value.
451 
452  Description:
453 
454 
455  Parameters:
456  leColor - the source color value
457  leColorMode - the source color mode
458 
459  Returns:
460  uint32_t - the alpha color channel
461 
462  Remarks:
463 
464 */
478 uint32_t leColorChannelAlpha(leColor clr, leColorMode mode);
479 
480 // *****************************************************************************
481 /* Function:
482  leColor leColorConvert(leColorMode mode_in,
483  leColorMode mode_out,
484  leColor color)
485 
486  Summary:
487  Converts a color value from one mode to another
488 
489 
490  Parameters:
491  leColorMode - the input color mode
492  leColorMode - the output color mode
493  leColor - the source color
494 
495  Returns:
496  leColor - the result color
497 
498  Remarks:
499 
500 */
517 leColor leColorConvert(leColorMode mode_in,
518  leColorMode mode_out,
519  leColor color);
520 
521 // *****************************************************************************
522 /* Function:
523  leColor leColorBlend_RGBA_8888(leColor fore, leColor back)
524 
525  Summary:
526  Blends two RGBA8888 colors together using their alpha channel values.
527 
528  Description:
529 
530 
531  Parameters:
532  leColor - the foreground color
533  leColor - the background color
534 
535  Returns:
536  leColor - the blended result color
537 
538  Remarks:
539 
540 */
554 leColor leColorBlend_RGBA_8888(leColor fore, leColor back);
555 
556 // *****************************************************************************
557 /* Function:
558  leColor leColorBlend_ARGB_8888(leColor fore, leColor back)
559 
560  Summary:
561  Blends two ARGB8888 colors together using their alpha channel values.
562 
563  Description:
564 
565 
566  Parameters:
567  leColor - the foreground color
568  leColor - the background color
569 
570  Returns:
571  leColor - the blended result color
572 
573  Remarks:
574 
575 */
589 leColor leColorBlend_ARGB_8888(leColor fore, leColor back);
590 
591 // *****************************************************************************
592 /* Function:
593  leColor leColorLerp(leColor l,
594  leColor r,
595  uint32_t percent,
596  leColorMode mode)
597 
598  Summary:
599  Linear interpolation between two colors
600 
601  Parameters:
602  leColor - first color input
603  leColor - second color input
604  uint32_t - percentage of interpolation [0-100]
605  leColorMode - input color mode
606 
607  Returns:
608  leColor - the result color
609 
610  Remarks:
611 
612 */
632 leColor leColorLerp(leColor l,
633  leColor r,
634  uint32_t percent,
635  leColorMode mode);
636 
637 // *****************************************************************************
638 /* Function:
639  leColor leColorBilerp(leColor c00,
640  leColor c01,
641  leColor c10,
642  leColor c11,
643  uint32_t xper,
644  uint32_t yper,
645  leColorMode mode)
646 
647  Summary:
648  Calculates bilinear interpolation between four colors
649 
650  Parameters:
651  leColor c00 - top left color input
652  leColor c01 - top right color input
653  leColor c10 - bottom left color input
654  leColor c11 - bottom right color input
655  uint32_t xper - percentage of interpolation in x [0-100]
656  uint32_t yper - percentage of interpolation in y [0-100]
657  leColorMode - input color mode
658 
659  Returns:
660  leColor - the result color
661 
662  Remarks:
663 
664 */
686 leColor leColorBilerp(leColor c00,
687  leColor c01,
688  leColor c10,
689  leColor c11,
690  uint32_t xper,
691  uint32_t yper,
692  leColorMode mode);
693 
704 leColor leColorSwap(leColor clr,
705  leColorMode mode);
706 
707 #ifdef __cplusplus
708 }
709 #endif
710 
711 #endif /* LE_COLOR_H */
leColorMode mode
Definition: legato_color.h:297
uint32_t leColorChannelGreen(leColor clr, leColorMode mode)
Get green color channel.
Definition: legato_color.c:49
leColor leColorSwap(leColor clr, leColorMode mode)
Swaps the red and blue channels for a given color value.
Definition: legato_color.c:69
Common macros and definitions used by Legato.
leColor leColorBilerp(leColor c00, leColor c01, leColor c10, leColor c11, uint32_t xper, uint32_t yper, leColorMode mode)
Get color from bi-linear interpolation of four colors.
Definition: legato_color_lerp.c:301
leColor foreground
Definition: legato_color.h:295
This struct represents color mode information.
Definition: legato_color.h:216
leColorName
This enum represents predefined color options.
Definition: legato_color.h:264
leColorMask
This enum represents the color masks for color modes.
Definition: legato_color.h:117
const leColorModeInfo leColorInfoTable[]
This array represents information reference table.
Definition: legato_color.c:29
leColor leColorBlend_ARGB_8888(leColor fore, leColor back)
Get color from ARGB blend.
Definition: legato_color_blend.c:116
struct leColorModeInfo leColorModeInfo
This struct represents color mode information.
const void * data
Definition: legato_color.h:299
uint32_t leColorChannelBlue(leColor clr, leColorMode mode)
Get blue color channel.
Definition: legato_color.c:54
leColor leColorLerp(leColor l, leColor r, uint32_t percent, leColorMode mode)
Get color from linear interpolate of two colors.
Definition: legato_color_lerp.c:284
leColor background
Definition: legato_color.h:296
uint32_t size
Definition: legato_color.h:218
This struct represents a blend color lookup table.
Definition: legato_color.h:293
struct leColorModeInfo::@22 mask
leColor leColorConvert(leColorMode mode_in, leColorMode mode_out, leColor color)
Convert to color value.
Definition: legato_color_convert.c:589
leColorMode
This enum represents the supported RGB color formats.
Definition: legato_color.h:148
struct leBlendLookupTable leBlendLookupTable
This struct represents a blend color lookup table.
leColor leColorBlend_RGBA_8888(leColor fore, leColor back)
Get color from RGBA blend.
Definition: legato_color_blend.c:56
uint32_t bpp
Definition: legato_color.h:219
uint32_t leColorChannelRed(leColor clr, leColorMode mode)
Get red color channel.
Definition: legato_color.c:44
leColor leColorValue(leColorMode mode, leColorName name)
Get color by name and mode.
Definition: legato_color_value.c:51
leBitsPerPixel bppOrdinal
Definition: legato_color.h:220
uint32_t leColorChannelAlpha(leColor clr, leColorMode mode)
Get alpha color channel.
Definition: legato_color.c:59
leBitsPerPixel
This enum represents the bits per pixel (bpp) options.
Definition: legato_color.h:185