MPLABĀ® Harmony Graphics Suite
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 
51 
55 typedef uint32_t leColor;
56 
57 
58 #define LE_COLOR_MAX_SIZE 4
59 
60 #define RGB_8_BITS 255
61 #define RGB_6_BITS 63
62 #define RGB_5_BITS 31
63 #define RGB_3_BITS 7
64 #define RGB_2_BITS 2
65 
66 #define RGB_332_RED_MASK 0xE0
67 #define RGB_332_GREEN_MASK 0x1C
68 #define RGB_332_BLUE_MASK 0x3
69 
70 #define RGB_565_RED_MASK 0xF800
71 #define RGB_565_GREEN_MASK 0x7E0
72 #define RGB_565_BLUE_MASK 0x1F
73 
74 #define RGBA_5551_RED_MASK 0xF800
75 #define RGBA_5551_GREEN_MASK 0x7C0
76 #define RGBA_5551_BLUE_MASK 0x3E
77 #define RGBA_5551_ALPHA_MASK 0x1
78 
79 #define RGB_888_RED_MASK 0xFF0000
80 #define RGB_888_GREEN_MASK 0xFF00
81 #define RGB_888_BLUE_MASK 0xFF
82 
83 #define RGBA_8888_RED_MASK 0xFF000000
84 #define RGBA_8888_GREEN_MASK 0xFF0000
85 #define RGBA_8888_BLUE_MASK 0xFF00
86 #define RGBA_8888_ALPHA_MASK 0xFF
87 
88 #define ARGB_8888_RED_MASK 0xFF0000
89 #define ARGB_8888_GREEN_MASK 0xFF00
90 #define ARGB_8888_BLUE_MASK 0xFF
91 #define ARGB_8888_ALPHA_MASK 0xFF000000
92 
96 // *****************************************************************************
97 // *****************************************************************************
98 // Section: Data Types and Constants
99 // *****************************************************************************
100 // *****************************************************************************
101 
102 // *****************************************************************************
103 /* Enumeration:
104  leColorMask
105 
106  Summary:
107  Maskable list of color valies.
108 
109 */
114 typedef enum leColorMask
115 {
116  LE_COLOR_MASK_GS_8 = 0x1,
117  LE_COLOR_MASK_PALETTE = 0x1,
118  LE_COLOR_MASK_RGB_332 = 0x4,
119  LE_COLOR_MASK_RGB_565 = 0x8,
120  LE_COLOR_MASK_RGBA_5551 = 0x10,
121  LE_COLOR_MASK_RGB_888 = 0x20,
122  LE_COLOR_MASK_RGBA_8888 = 0x40,
123  LE_COLOR_MASK_ARGB_8888 = 0x80,
124  LE_COLOR_MASK_ALL = LE_COLOR_MASK_GS_8 |
125  LE_COLOR_MASK_RGB_332 |
126  LE_COLOR_MASK_RGB_565 |
127  LE_COLOR_MASK_RGBA_5551 |
128  LE_COLOR_MASK_RGB_888 |
129  LE_COLOR_MASK_RGBA_8888 |
130  LE_COLOR_MASK_ARGB_8888
132 
133 // *****************************************************************************
134 /* Enumeration:
135  leColorMode
136 
137  Summary:
138  List of available color modes.
139 */
145 typedef enum leColorMode
146 {
147  LE_COLOR_MODE_GS_8 = 0x0,
148  LE_COLOR_MODE_PALETTE = LE_COLOR_MODE_GS_8,
149  LE_COLOR_MODE_RGB_332 = 0x1,
150  LE_COLOR_MODE_RGB_565 = 0x2,
151  LE_COLOR_MODE_RGBA_5551 = 0x3,
152  LE_COLOR_MODE_RGB_888 = 0x4,
153  LE_COLOR_MODE_RGBA_8888 = 0x5,
154  LE_COLOR_MODE_ARGB_8888 = 0x6,
155  LE_COLOR_MODE_INDEX_1 = 0x7,
156  LE_COLOR_MODE_INDEX_4 = 0x8,
157  LE_COLOR_MODE_INDEX_8 = 0x9,
158  LE_COLOR_MODE_LAST = LE_COLOR_MODE_INDEX_8
160 
161 #define LE_COLOR_MODE_LAST_COLOR (LE_COLOR_MODE_ARGB_8888)
162 #define LE_COLOR_MODE_COUNT (LE_COLOR_MODE_LAST + 1)
163 
164 #define LE_COLOR_MODE_IS_PIXEL(mode) ((mode >= LE_COLOR_MODE_GS_8) && (mode <= LE_COLOR_MODE_ARGB_8888))
165 #define LE_COLOR_MODE_IS_INDEX(mode) ((mode >= LE_COLOR_MODE_INDEX_1) && (mode <= LE_COLOR_MODE_INDEX_8))
166 
167 #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))
168 
169 // *****************************************************************************
170 /* Enumeration:
171  leBitsPerPixel
172 
173  Summary:
174  List of available bits-per-pixel sizes.
175 */
182 typedef enum leBitsPerPixel
183 {
184  LE_BPP1,
185  LE_BPP4,
186  LE_BPP8,
187  LE_BPP16,
188  LE_BPP24,
189  LE_BPP32
191 
192 // *****************************************************************************
193 /* Structure:
194  leColorModeInfo
195 
196  Summary:
197  Struct that provides information about a color mode.
198 
199  Description:
200  size - size in bytes
201  bpp - bpp value
202  bppOrdinal - bpp enum value
203  masks - the masks used for extracting individual color channel information
204 
205  Remarks:
206  None.
207 */
213 typedef struct leColorModeInfo
214 {
215  uint32_t size;
216  uint32_t bpp;
219  struct
220  {
221  uint32_t red;
222  uint32_t green;
223  uint32_t blue;
224  uint32_t alpha;
225  } mask;
227  struct
228  {
229  uint8_t red;
230  uint8_t green;
231  uint8_t blue;
232  uint8_t alpha;
233  } shift;
234 
236 
237 // *****************************************************************************
238 /* Data Table:
239  leColorInfoTable
240 
241  Summary:
242  Color information reference table
243 */
248 extern const leColorModeInfo leColorInfoTable[];
249 
250 // *****************************************************************************
251 /* Structure:
252  leColorName
253 
254  Summary:
255  Color name reference table
256 */
261 typedef enum leColorName
262 {
263  LE_COLOR_BLACK,
264  LE_COLOR_WHITE,
265  LE_COLOR_RED,
266  LE_COLOR_LIME,
267  LE_COLOR_BLUE,
268  LE_COLOR_YELLOW,
269  LE_COLOR_CYAN,
270  LE_COLOR_MAGENTA,
271  LE_COLOR_SILVER,
272  LE_COLOR_DARKGRAY,
273  LE_COLOR_GRAY,
274  LE_COLOR_LIGHTGRAY,
275  LE_COLOR_MAROON,
276  LE_COLOR_OLIVE,
277  LE_COLOR_GREEN,
278  LE_COLOR_PURPLE,
279  LE_COLOR_TEAL,
280  LE_COLOR_NAVY,
281  LE_COLOR_LAST
283 
284 // *****************************************************************************
285 // *****************************************************************************
286 // Section: Routines
287 // *****************************************************************************
288 // *****************************************************************************
289 
290 // *****************************************************************************
291 /* Function:
292  leColor leColorValue(leColorMode mode, leColorName name)
293 
294  Summary:
295  Used for getting a color value by name.
296 
297  Parameters:
298  leColorMode - the color mode for the return type
299  leColorName - the name of the color to retrieve
300 
301  Returns:
302  leColor - the color value of the given name in the specified format
303 
304  Remarks:
305 
306 */
320 LIB_EXPORT leColor leColorValue(leColorMode mode, leColorName name);
321 
322 // *****************************************************************************
323 /* Function:
324  uint32_t leColorChannelRed(leColor clr, leColorMode mode)
325 
326  Summary:
327  Used for getting the red color channel of a given color value.
328 
329  Description:
330 
331 
332  Parameters:
333  leColor - the source color value
334  leColorMode - the source color mode
335 
336  Returns:
337  uint32_t - the red color channel
338 
339  Remarks:
340 
341 */
355 LIB_EXPORT uint32_t leColorChannelRed(leColor clr, leColorMode mode);
356 
357 // *****************************************************************************
358 /* Function:
359  uint32_t leColorChannelGreen(leColor clr, leColorMode mode)
360 
361  Summary:
362  Used for getting the green color channel of a given color value.
363 
364  Description:
365 
366 
367  Parameters:
368  leColor - the source color value
369  leColorMode - the source color mode
370 
371  Returns:
372  uint32_t - the green color channel
373 
374  Remarks:
375 
376 */
390 LIB_EXPORT uint32_t leColorChannelGreen(leColor clr, leColorMode mode);
391 
392 // *****************************************************************************
393 /* Function:
394  uint32_t leColorChannelBlue(leColor clr, leColorMode mode)
395 
396  Summary:
397  Used for getting the blue color channel of a given color value.
398 
399  Description:
400 
401 
402  Parameters:
403  leColor - the source color value
404  leColorMode - the source color mode
405 
406  Returns:
407  uint32_t - the blue color channel
408 
409  Remarks:
410 
411 */
425 LIB_EXPORT uint32_t leColorChannelBlue(leColor clr, leColorMode mode);
426 
427 // *****************************************************************************
428 /* Function:
429  uint32_t leColorChannelAlpha(leColor clr, leColorMode mode)
430 
431  Summary:
432  Used for getting the alpha color channel of a given color value.
433 
434  Description:
435 
436 
437  Parameters:
438  leColor - the source color value
439  leColorMode - the source color mode
440 
441  Returns:
442  uint32_t - the alpha color channel
443 
444  Remarks:
445 
446 */
460 LIB_EXPORT uint32_t leColorChannelAlpha(leColor clr, leColorMode mode);
461 
462 // *****************************************************************************
463 /* Function:
464  leColor leColorConvert(leColorMode mode_in,
465  leColorMode mode_out,
466  leColor color)
467 
468  Summary:
469  Converts a color value from one mode to another
470 
471 
472  Parameters:
473  leColorMode - the input color mode
474  leColorMode - the output color mode
475  leColor - the source color
476 
477  Returns:
478  leColor - the result color
479 
480  Remarks:
481 
482 */
499 LIB_EXPORT leColor leColorConvert(leColorMode mode_in,
500  leColorMode mode_out,
501  leColor color);
502 
503 // *****************************************************************************
504 /* Function:
505  leColor leColorBlend_RGBA_8888(leColor fore, leColor back)
506 
507  Summary:
508  Blends two RGBA8888 colors together using their alpha channel values.
509 
510  Description:
511 
512 
513  Parameters:
514  leColor - the foreground color
515  leColor - the background color
516 
517  Returns:
518  leColor - the blended result color
519 
520  Remarks:
521 
522 */
536 LIB_EXPORT leColor leColorBlend_RGBA_8888(leColor fore, leColor back);
537 
538 // *****************************************************************************
539 /* Function:
540  leColor leColorBlend_ARGB_8888(leColor fore, leColor back)
541 
542  Summary:
543  Blends two ARGB8888 colors together using their alpha channel values.
544 
545  Description:
546 
547 
548  Parameters:
549  leColor - the foreground color
550  leColor - the background color
551 
552  Returns:
553  leColor - the blended result color
554 
555  Remarks:
556 
557 */
571 LIB_EXPORT leColor leColorBlend_ARGB_8888(leColor fore, leColor back);
572 
573 // *****************************************************************************
574 /* Function:
575  leColor leColorLerp(leColor l,
576  leColor r,
577  uint32_t percent,
578  leColorMode mode)
579 
580  Summary:
581  Linear interpolation between two colors
582 
583  Parameters:
584  leColor - first color input
585  leColor - second color input
586  uint32_t - percentage of interpolation [0-100]
587  leColorMode - input color mode
588 
589  Returns:
590  leColor - the result color
591 
592  Remarks:
593 
594 */
614 LIB_EXPORT leColor leColorLerp(leColor l,
615  leColor r,
616  uint32_t percent,
617  leColorMode mode);
618 
619 // *****************************************************************************
620 /* Function:
621  leColor leColorBilerp(leColor c00,
622  leColor c01,
623  leColor c10,
624  leColor c11,
625  uint32_t xper,
626  uint32_t yper,
627  leColorMode mode)
628 
629  Summary:
630  Calculates bilinear interpolation between four colors
631 
632  Parameters:
633  leColor c00 - top left color input
634  leColor c01 - top right color input
635  leColor c10 - bottom left color input
636  leColor c11 - bottom right color input
637  uint32_t xper - percentage of interpolation in x [0-100]
638  uint32_t yper - percentage of interpolation in y [0-100]
639  leColorMode - input color mode
640 
641  Returns:
642  leColor - the result color
643 
644  Remarks:
645 
646 */
668 LIB_EXPORT leColor leColorBilerp(leColor c00,
669  leColor c01,
670  leColor c10,
671  leColor c11,
672  uint32_t xper,
673  uint32_t yper,
674  leColorMode mode);
675 
676 leColor leColorSwap(leColor clr,
677  leColorMode mode);
678 
679 #endif /* LE_COLOR_H */
widget.WidgetDefault
Definition: widget.py:1
generate.File.name
name
Definition: generate.py:28
widget.WidgetDefault.right
right
Definition: widget.py:11
leColorModeInfo::size
uint32_t size
Definition: legato_color.h:215
widget.WidgetDefault.left
left
Definition: widget.py:9
screen.RadialMenuItem
Definition: screen.py:19
leColorChannelGreen
LIB_EXPORT uint32_t leColorChannelGreen(leColor clr, leColorMode mode)
Get green color channel.
Definition: legato_color.c:49
leColorMode
leColorMode
This enum represents the supported RGB color formats.
Definition: legato_color.h:146
legato_color.h
Color definitions and functions.
assetbatch.AssetBatch
Definition: assetbatch.py:4
leColorChannelAlpha
LIB_EXPORT uint32_t leColorChannelAlpha(leColor clr, leColorMode mode)
Get alpha color channel.
Definition: legato_color.c:59
leColorModeInfo::mask
struct leColorModeInfo::@6 mask
leColorName
leColorName
This enum represents predefined color options.
Definition: legato_color.h:262
screen.RadialMenuItem.name
name
Definition: screen.py:21
assetheader.PaletteDef.checksum
checksum
Definition: assetheader.py:25
assetheader.PaletteDef.colorCount
colorCount
Definition: assetheader.py:26
leColorModeInfo
struct leColorModeInfo leColorModeInfo
This struct represents color mode information.
widget.WidgetDefault.border
border
Definition: widget.py:5
widget.WidgetDefault.valign
valign
Definition: widget.py:8
widget.WidgetDefault.background
background
Definition: widget.py:6
leColorLerp
LIB_EXPORT 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
generate.File.handle
handle
Definition: generate.py:30
screen.RadialMenu
Definition: screen.py:23
screen.RadialMenu.items
items
Definition: screen.py:26
leColorBlend_RGBA_8888
LIB_EXPORT leColor leColorBlend_RGBA_8888(leColor fore, leColor back)
Get color from RGBA blend.
Definition: legato_color_blend.c:77
assetbatch.AssetBatch.name
name
Definition: assetbatch.py:6
assetbatch.AssetBatch.type
type
Definition: assetbatch.py:7
leBitsPerPixel
leBitsPerPixel
This enum represents the bits per pixel (bpp) options.
Definition: legato_color.h:183
generate.File
Definition: generate.py:26
leColorModeInfo::bpp
uint32_t bpp
Definition: legato_color.h:216
screen.RadioButtonGroup
Definition: screen.py:1
leColorBlend_ARGB_8888
LIB_EXPORT leColor leColorBlend_ARGB_8888(leColor fore, leColor back)
Get color from ARGB blend.
Definition: legato_color_blend.c:125
widget.WidgetDefault.height
height
Definition: widget.py:4
leColorModeInfo::bppOrdinal
leBitsPerPixel bppOrdinal
Definition: legato_color.h:217
getRadius
virtual uint32_t getRadius(const leArcWidget *_this)
Get radius of an arc.
assetheader.PaletteDef.generated
generated
Definition: assetheader.py:27
leColorMask
leColorMask
This enum represents the color masks for color modes.
Definition: legato_color.h:115
assetheader.PaletteDef.name
name
Definition: assetheader.py:23
screen.RadioButtonGroup.id
id
Definition: screen.py:3
generate.File.description
description
Definition: generate.py:32
getThickness
virtual uint32_t getThickness(const leArcWidget *_this)
Get thickness of an arc.
widget.WidgetDefault.bottom
bottom
Definition: widget.py:12
leColorChannelBlue
LIB_EXPORT uint32_t leColorChannelBlue(leColor clr, leColorMode mode)
Get blue color channel.
Definition: legato_color.c:54
assetheader.PaletteDef.object
object
Definition: assetheader.py:24
generate.File.summary
summary
Definition: generate.py:31
assetheader.PaletteDef
Definition: assetheader.py:19
widget.WidgetDefault.width
width
Definition: widget.py:3
screen.RadioButtonGroup.selectedButton
selectedButton
Definition: screen.py:5
assetbatch.AssetBatch.fileName
fileName
Definition: assetbatch.py:8
generate.File.path
path
Definition: generate.py:29
leColorConvert
LIB_EXPORT leColor leColorConvert(leColorMode mode_in, leColorMode mode_out, leColor color)
Convert to color value.
Definition: legato_color_convert.c:579
widget.WidgetDefault.top
top
Definition: widget.py:10
leColorModeInfo
This struct represents color mode information.
Definition: legato_color.h:214
assetbatch.AssetBatch.assets
assets
Definition: assetbatch.py:10
append
virtual leResult append(leString *_this, const struct leString *val)
Append string.
leColorValue
LIB_EXPORT leColor leColorValue(leColorMode mode, leColorName name)
Get color by name and mode.
Definition: legato_color_value.c:51
legato_common.h
Common macros and definitions used by Legato.
widget.WidgetDefault.halign
halign
Definition: widget.py:7
screen.RadialMenu.menu
menu
Definition: screen.py:25
leColorChannelRed
LIB_EXPORT uint32_t leColorChannelRed(leColor clr, leColorMode mode)
Get red color channel.
Definition: legato_color.c:44
leColorInfoTable
const leColorModeInfo leColorInfoTable[]
This array represents information reference table.
Definition: legato_color.c:29
screen.RadioButtonGroup.buttons
buttons
Definition: screen.py:4
leColorBilerp
LIB_EXPORT 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