MPLABĀ® Harmony Graphics Suite
legato_image.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_image.h
32 
33  Summary:
34  Defines image assets
35 
36  Description:
37  Image drawing at specified coordinates
38 *******************************************************************************/
39 
46 #ifndef LE_IMAGE_H
47 #define LE_IMAGE_H
48 
50 
54 
55 typedef struct lePalette lePalette;
56 
57 // *****************************************************************************
58 /* Enumeration:
59  leImageFormat
60 
61  Summary:
62  Indicates the image encoding format
63 */
68 typedef enum leImageFormat
69 {
70  LE_IMAGE_FORMAT_RAW = 0,
71  LE_IMAGE_FORMAT_RLE,
72  LE_IMAGE_FORMAT_JPEG,
73  LE_IMAGE_FORMAT_PNG
75 
76 #define LE_IMAGE_FORMAT_COUNT (LE_IMAGE_FORMAT_RLE + 1)
77 
78 // *****************************************************************************
79 /* Enumeration:
80  leImageFlags
81 
82  Summary:
83  A list of flags describing an image asset
84 */
89 typedef enum leImageFlags
90 {
91  LE_IMAGE_USE_MASK_COLOR = 1 << 0,
92  LE_IMAGE_USE_MASK_MAP = 1 << 1,
93  LE_IMAGE_USE_ALPHA_MAP = 1 << 2,
94  LE_IMAGE_INTERNAL_ALLOC = 1 << 3
96 
97 // *****************************************************************************
98 /* Enumeration:
99  leImageFilterMode
100 
101  Summary:
102  A list of flags defining image filtering modes
103 */
108 typedef enum leImageFilterMode
109 {
110  LE_IMAGEFILTER_NONE,
111  LE_IMAGEFILTER_NEAREST_NEIGHBOR,
112  LE_IMAGEFILTER_BILINEAR,
114 
115 // *****************************************************************************
116 /* Structure:
117  struct leImageMap
118 
119  Summary:
120  Structure defining a general image map buffer.
121 */
126 typedef struct leImageMap
127 {
128  leStreamDescriptor header; // standard stream header
129  lePixelBuffer buffer; // the buffer that describes this map
131 
132 // *****************************************************************************
133 /* Structure:
134  leImage
135 
136  Summary:
137  Describes an image asset.
138 
139  header - standard asset header
140  format - the format of the image. this directly affects which decoder
141  is invoked when rendering the image
142  width - the width of the image in pixels
143  height - the height of the image in pixels
144  colorMode - the color mode of the image
145  compType - the compression mode of the image
146  flags - indicates of the mask field is used
147  mask - may contain a masking color for the image. blit operations may
148  reference this value and reject image pixels that match this
149  value. This can either be a single color mode or a pointer to an
150  image map data array.
151 
152  alphaMask - pointer to an array of per-pixel alpha blending values
153 
154  palette - will contain a valid pointer to a palette asset if thie image
155  is an index map instead of a color image
156 
157  leStreamDescriptor header - standard stream header
158  format - the format of the image. this directly affects which decoder
159  is invoked when rendering the image
160  lePixelBuffer buffer - the buffer that describes this image data
161  leImageFlags flags - image descriptor flags
162 
163  union
164  {
165  leColor color; // single masking color
166  leImageMap* map; // color mask map
167  } mask; // defines mask techniques
168 
169  leImageMap* alphaMap; // placeholder for blending mask
170 
171  lePalette* palette; // lookup palette for this image
172 */
177 struct leImage;
178 
179 typedef struct leImage
180 {
181  leStreamDescriptor header;
182  leImageFormat format;
183  lePixelBuffer buffer;
184  leImageFlags flags;
185 
186  union
187  {
188  leColor color;
189  leImageMap* map;
190  } mask;
191 
192  leImageMap* alphaMap;
193 
194  struct leImage* palette;
195 } leImage;
196 
197 // *****************************************************************************
198 /* Function:
199  leResult leImage_Create(leImage* img,
200  uint32_t width,
201  uint32_t height,
202  leColorMode mode,
203  void* data,
204  uint32_t locationID)
205 
206  Summary:
207  Initializes a leImage pointer
208 
209  Description:
210  Initializes a leImage pointer
211 
212  Parameters:
213  leImage* img - the image object to initialize
214  uint32_t width - the width of the image
215  uint32_t height - the height of the image
216  leColorMode mode - the color mode of the image
217  void* data - the data address of the image
218  uint32_t locationID - the location ID of the image
219 
220  Returns:
221 
222  Remarks:
223 */
241 LIB_EXPORT leResult leImage_Create(leImage* img,
242  uint32_t width,
243  uint32_t height,
244  leColorMode mode,
245  void* data,
246  uint32_t locationID);
247 
248 // *****************************************************************************
249 /* Function:
250  leImage* leImage_Allocate(uint32_t width,
251  uint32_t height,
252  leColorMode mode)
253 
254  Summary:
255  Dynamically allocates an image buffer in local memory using the
256  given parameters.
257 
258  Description:
259  Dynamically allocates an image buffer in local memory using the
260  given parameters. This uses the library's internal allocator and
261  memory pools.
262 
263  Parameters:
264  uint32_t width - the width of the image in pixels
265  uint32_t height - the height of the image in pixels
266  leColorMode mode - the color mode of the image
267 
268  Returns:
269  leImage* - a valid image or null if there wasn't enough memory for the
270  allocation
271  Remarks:
272 */
289 LIB_EXPORT leImage* leImage_Allocate(uint32_t width,
290  uint32_t height,
291  leColorMode mode);
292 
293 // *****************************************************************************
294 /* Function:
295  leResult leImage_Free(leImage* img)
296 
297  Summary:
298  Frees an image buffer that was allocated using leImage_Allocate.
299 
300  Description:
301  Frees an image buffer that was allocated using leImage_Allocate.
302 
303  Parameters:
304  leImage* img - the image to free
305 
306  Returns:
307 
308  Remarks:
309 */
321 LIB_EXPORT leResult leImage_Free(leImage* img);
322 
323 // *****************************************************************************
324 /* Structure:
325  struct leImageDecoder
326 
327  Summary:
328  Structure defining a general image decoder object. Specific decoders
329  will implement this in their own way.
330 
331  supportsImage - queries the decoder to see if it supports a given image
332  draw - initializes the decoder to draw an image to the frame buffer
333  copy - intiailizes the decoder to perform an image copy operation
334  render - initializes the decoder to perform a direct image render operation
335  resize - initialies the decoder to perform an direct image resize operation
336  resize - initialies the decoder to perform an image resize operation draw to the frame buffer
337  exec - run the decoder
338  isDone - query the decoder for completion
339  free - frees the decoder to cleanup any allocated resources
340 */
346 typedef struct leImageDecoder
347 {
348  leBool (*supportsImage)(const leImage* img);
349  leResult (*draw)(const leImage* img, const leRect* srcRect, int32_t x, int32_t y, uint32_t a);
350  leResult (*copy)(const leImage* src, const leRect* srcRect, int32_t x, int32_t y, leImage* dst);
351  leResult (*render)(const leImage* src, const leRect* srcRect, int32_t x, int32_t y, leBool ignoreMask, leBool ignoreAlpha, leImage* dst);
352  leResult (*resize)(const leImage* src, const leRect* srcRect, leImageFilterMode mode, uint32_t sizeX, uint32_t sizeY, leImage* dst);
353  leResult (*resizeDraw)(const leImage* src, const leRect* srcRect, leImageFilterMode mode, uint32_t sizeX, uint32_t sizeY, int32_t x, int32_t y, uint32_t a);
354  leResult (*rotate)(const leImage* src, const leRect* srcRect, leImageFilterMode mode, int32_t angle, leImage** dst, leBool alloc);
355  leResult (*rotateDraw)(const leImage* src, const leRect* srcRect, leImageFilterMode mode, int32_t angle, int32_t x, int32_t y, uint32_t a);
356  leResult (*exec)(void);
357  leBool (*isDone)(void);
358  void (*free)(void);
360 
361 // *****************************************************************************
362 /* Function:
363  void leImage_InitDecoders()
364 
365  Summary:
366  Global function to initialize all image decoders. INTERNAL USE ONLY
367 
368  Description:
369  Global function to initialize all image decoders. INTERNAL USE ONLY
370 
371  Parameters:
372 
373  Returns:
374 
375  Remarks:
376 */
386 void leImage_InitDecoders();
387 
388 #if LE_STREAMING_ENABLED == 1
389 // *****************************************************************************
390 /* Structure:
391  struct leImageStreamDecoder
392 
393  Summary:
394  Defines the base implementation for a streaming image decoder.
395 */
396 typedef struct leImageStreamDecoder
397 {
398  leStreamManager base;
399 } leImageStreamDecoder;
400 #endif
401 
402 // *****************************************************************************
403 /* Function:
404  leResult leDrawImage(void);
405 
406  Summary:
407  Draws a portion of the given image at the specified coordinates.
408 
409  Parameters:
410  leImage* img - pointer to the image asset to draw
411  leRect* sourceRect - the source rectangle of the image to blit
412  int32_t x - the x position to draw to
413  int32_t x - the y position to draw to
414  uint32_t a - global alpha amount to apply
415 
416  Returns:
417  leResult
418 */
431 LIB_EXPORT leResult leImage_Draw(const leImage* img,
432  const leRect* sourceRect,
433  int32_t x,
434  int32_t y,
435  uint32_t a);
436 
437 
438 // *****************************************************************************
439 /* Function:
440  leResult leImage_Resize(const leImage* src,
441  const leRect* sourceRect,
442  leImageFilterMode mode,
443  leImage* dst);
444 
445  Summary:
446  Decodes a portion of the given image at the specified coordinates and
447  scales it to the given dimensions using the specified filter mode. The
448  result is stored into the provided destination image pointer.
449 
450  Parameters:
451  leImage* src - pointer to source image asset to draw
452  leRect* sourceRect - the source rectangle of the image to decode
453  leImageFilterMode mode - the filter to use when resizing
454  leImage* dst - pointer to destination image asset
455 
456  Returns:
457  leResult
458 */
472 LIB_EXPORT leResult leImage_Resize(const leImage* src,
473  const leRect* sourceRect,
474  leImageFilterMode mode,
475  uint32_t sizeX,
476  uint32_t sizeY,
477  leImage* target);
478 
479 // *****************************************************************************
480 /* Function:
481  leResult leImage_ResizeDraw(const leImage* src,
482  const leRect* sourceRect,
483  leImageFilterMode mode,
484  const leRect* destRect);
485 
486  Summary:
487  Decodes a portion of the given image at the specified coordinates and
488  scales it to the given dimensions using the specified filter mode. The
489  result is written to the active scratch buffer.
490 
491  Parameters:
492  leImage* src - pointer to source image asset to draw
493  const leRect* sourceRect - the source rectangle of the image to decode
494  leImageFilterMode mode - the filter to use when resizing
495  int32_t x - the X coordinate to draw to
496  int32_t y - the Y coordinate to draw to
497  uint32_t a - the alpha value to use
498 
499  Returns:
500  leResult
501 */
515 LIB_EXPORT leResult leImage_ResizeDraw(const leImage* src,
516  const leRect* sourceRect,
517  leImageFilterMode mode,
518  uint32_t sizeX,
519  uint32_t sizeY,
520  int32_t x,
521  int32_t y,
522  uint32_t a);
523 
524 // *****************************************************************************
525 /* Function:
526  leResult leImage_Copy(const leImage* src,
527  const leRect* sourceRect,
528  int32_t x,
529  int32_t y,
530  leImage* dst);
531 
532  Summary:
533  Copies the data from one image to another.
534 
535  Parameters:
536  leImage* src - pointer to source image asset to draw
537  const leRect* sourceRect - the source rectangle of the image to decode
538  int32_t x - the x position of the destination image to write to
539  int32_t y - the y position of the desgination image to write to,
540  leImage* dst - the destination image to fill
541 
542  Returns:
543  leResult
544 */
565 LIB_EXPORT leResult leImage_Copy(const leImage* src,
566  const leRect* sourceRect,
567  int32_t x,
568  int32_t y,
569  leImage* dst);
570 
571 // *****************************************************************************
572 /* Function:
573  leResult leImage_Render(const leImage* src,
574  const leRect* sourceRect,
575  int32_t x,
576  int32_t y,
577  leBool ignoreMask,
578  leBool ignoreAlpha,
579  leImage* dst);
580 
581  Summary:
582  Renders an image into another image. Source data will be decoded,
583  transformed, and written into the destination image. The source image
584  mask and alpha data may be optionally ignored.
585 
586  Parameters:
587  leImage* src - pointer to source image asset to draw
588  const leRect* sourceRect - the source rectangle of the image to decode
589  int32_t x - the x position of the destination image to write to
590  int32_t y - the y position of the desgination image to write to
591  leBool ignoreMask - set to true to skip the mask stage for the source image
592  leBool ignoreAlpha - set to true to skip the blend stage for the source image
593  leImage* dst - the destination image to fill
594 
595  Returns:
596  leResult
597 */
619 LIB_EXPORT leResult leImage_Render(const leImage* src,
620  const leRect* sourceRect,
621  int32_t x,
622  int32_t y,
623  leBool ignoreMask,
624  leBool ignoreAlpha,
625  leImage* dst);
626 
647 leResult leImage_Rotate(const leImage* src,
648  const leRect* sourceRect,
649  leImageFilterMode mode,
650  int32_t angle,
651  leImage** dst,
652  leBool alloc);
653 
654 // *****************************************************************************
655 /* Function:
656  leResult leImage_Rotate(const leImage* src,
657  const leRect* sourceRect,
658  leImageFilterMode mode,
659  int32_t angle,
660  int32_t x,
661  int32_t y,
662  uint32_t a);
663 
664  Summary:
665  Decodes a portion of the given image at the specified coordinates and
666  rotates it by the given angle in degrees, around the origin point,
667  using the specified filter mode.
668 
669  The result is rendered directly into the frame buffer.
670 
671  Parameters:
672  leImage* src - pointer to source image asset to draw
673  leRect* sourceRect - the source rectangle of the image to decode
674  leImageFilterMode mode - the filter to use when rotating
675  int32_t angle - the angle (degrees) to rotate by
676  int32_t x - the X coordinate to draw to
677  int32_t y - the Y coordinate to draw to
678  uint32_t a - the alpha value to use
679 
680  Returns:
681  leResult
682 */
702  const leRect* sourceRect,
703  leImageFilterMode mode,
704  int32_t angle,
705  int32_t x,
706  int32_t y,
707  uint32_t a);
708 
709 
710 #endif /* LE_IMAGE_H */
leColorModeInfo::size
uint32_t size
Definition: legato_color.h:215
leResult
leResult
This enum represents function call results.
Definition: legato_common.h:134
leImageDecoder
This struct represents an image decoder.
Definition: legato_image.h:347
leColorMode
leColorMode
This enum represents the supported RGB color formats.
Definition: legato_color.h:146
leRect
This struct represents a rectangle.
Definition: legato_common.h:405
legato_color.h
Color definitions and functions.
legato_image.h
Image functions and defintions.
legato_pixelbuffer.h
Pixel Buffer functions and definitions.
legato_memory.h
Memory functions and definitions.
leImage
Definition: legato_image.h:180
legato_renderer.h
leSize::width
int32_t width
Definition: legato_common.h:382
leImage_Free
LIB_EXPORT leResult leImage_Free(leImage *img)
Free image buffer.
Definition: legato_image.c:120
leImageFormat
leImageFormat
This enum represents an image format.
Definition: legato_image.h:69
leImage_Create
LIB_EXPORT leResult leImage_Create(leImage *img, uint32_t width, uint32_t height, leColorMode mode, void *data, uint32_t locationID)
Create an image.
Definition: legato_image.c:51
leStreamDescriptor::location
uint32_t location
Definition: legato_stream.h:58
leImageFlags
leImageFlags
This enum represents image flags.
Definition: legato_image.h:90
LE_STREAM_LOCATION_ID_INTERNAL
#define LE_STREAM_LOCATION_ID_INTERNAL
leEventResult
Definition: legato_stream.h:67
leBool
leBool
This enum represents booleans.
Definition: legato_common.h:157
leImage_InitDecoders
void leImage_InitDecoders()
Get Event Count.
Definition: legato_image.c:42
legato_stream.h
Defines a common header for all stream operations.
leStreamDescriptor::size
uint32_t size
Definition: legato_stream.h:60
leImageDecoder
struct leImageDecoder leImageDecoder
This struct represents an image decoder.
leImageMap
This struct represents an image map.
Definition: legato_image.h:127
leImageFilterMode
leImageFilterMode
This enum represents image filter modes.
Definition: legato_image.h:109
leImage_Resize
LIB_EXPORT leResult leImage_Resize(const leImage *src, const leRect *sourceRect, leImageFilterMode mode, uint32_t sizeX, uint32_t sizeY, leImage *target)
Resize image.
Definition: legato_image.c:166
leImage_Draw
LIB_EXPORT leResult leImage_Draw(const leImage *img, const leRect *sourceRect, int32_t x, int32_t y, uint32_t a)
Draw an Image.
Definition: legato_image.c:131
leImageMap
struct leImageMap leImageMap
This struct represents an image map.
lePalette
This struct represents a palette asset.
Definition: legato_palette.h:70
legato_rect.h
Rectangle functions and definitions.
leImage_Copy
LIB_EXPORT leResult leImage_Copy(const leImage *src, const leRect *sourceRect, int32_t x, int32_t y, leImage *dst)
Copy image.
Definition: legato_image.c:248
leImage_ResizeDraw
LIB_EXPORT leResult leImage_ResizeDraw(const leImage *src, const leRect *sourceRect, leImageFilterMode mode, uint32_t sizeX, uint32_t sizeY, int32_t x, int32_t y, uint32_t a)
Resize draw image.
Definition: legato_image.c:211
leStreamDescriptor
This struct represents a stream descriptor.
Definition: legato_stream.h:57
leImage_RotateDraw
leResult leImage_RotateDraw(const leImage *src, const leRect *sourceRect, leImageFilterMode mode, int32_t angle, int32_t x, int32_t y, uint32_t a)
Rotate draw image.
Definition: legato_image.c:347
leImage_Rotate
leResult leImage_Rotate(const leImage *src, const leRect *sourceRect, leImageFilterMode mode, int32_t angle, leImage **dst, leBool alloc)
Rotate image.
Definition: legato_image.c:314
LE_TRUE
@ LE_TRUE
Definition: legato_common.h:159
leImage_Render
LIB_EXPORT leResult leImage_Render(const leImage *src, const leRect *sourceRect, int32_t x, int32_t y, leBool ignoreMask, leBool ignoreAlpha, leImage *dst)
Render image.
Definition: legato_image.c:279
legato_common.h
Common macros and definitions used by Legato.
leImage_Allocate
LIB_EXPORT leImage * leImage_Allocate(uint32_t width, uint32_t height, leColorMode mode)
Allocate an image buffer.
Definition: legato_image.c:79
leStreamDescriptor::address
void * address
Definition: legato_stream.h:59
leSize::height
int32_t height
Definition: legato_common.h:383
leColorInfoTable
const leColorModeInfo leColorInfoTable[]
This array represents information reference table.
Definition: legato_color.c:29
lePixelBuffer
Definition: legato_pixelbuffer.h:91