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