µGFX  2.9
version 2.9
gwin_image.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/gwin/gwin_image.h
10  * @brief GWIN image widget header file.
11  *
12  * @defgroup ImageBox ImageBox
13  * @ingroup Widgets
14  *
15  * @brief ImageBox widget. Used to display images within the @p GWIN widget system.
16  *
17  * @details GWIN allos it to create an image widget. The widget
18  * takes no user input.
19  *
20  * @pre GFX_USE_GDISP must be set to GFXON in your gfxconf.h
21  * @pre GFX_USE_GWIN must be set to GFXON in your gfxconf.h
22  * @pre GDISP_NEED_IMAGE must be set to GFXON in your gfxconf.h
23  * @pre GWIN_NEED_IMAGE must be set to GFXON in your gfxconf.h
24  * @pre At least one image type must be enabled in your gfxconf.h
25  *
26  * @{
27  */
28 
29 #ifndef _GWIN_IMAGE_H
30 #define _GWIN_IMAGE_H
31 
32 // This file is included within "src/gwin/gwin.h"
33 
34 // An image window
35 typedef struct GImageObject {
36  GWindowObject g;
37  gImage image; // The image itself
38  #if GWIN_NEED_IMAGE_ANIMATION
39  GTimer timer; // Timer used for animated images
40  #endif
41 } GImageObject;
42 
43 /**
44  * @brief Create an image widget.
45  * @details Display's a picture.
46  * @return NULL if there is no resultant drawing area, otherwise the widget handle.
47  *
48  * @param[in] g The GDisplay to display this window on
49  * @param[in] widget The image widget structure to initialise. If this is NULL, the structure is dynamically allocated.
50  * @param[in] pInit The initialization parameters to use.
51  *
52  * @note The default background color gets set to the current default one.
53  * @note An image window knows how to redraw.
54  *
55  * @api
56  */
57 GHandle gwinGImageCreate(GDisplay *g, GImageObject *widget, GWindowInit *pInit);
58 #define gwinImageCreate(w, pInit) gwinGImageCreate(GDISP, w, pInit)
59 
60 /**
61  * @brief Opens the image using a GFILE
62  * @return gTrue if the image can be opened
63  *
64  * @param[in] gh The widget (must be an image widget)
65  * @param[in] f The open (for reading) GFILE to use
66  *
67  * @api
68  */
70 
71 /**
72  * @brief Opens the image using the specified filename
73  * @return gTrue if the open succeeds
74  *
75  * @param[in] gh The widget (must be an image widget)
76  * @param[in] filename The filename to open
77  *
78  * @api
79  */
80 #define gwinImageOpenFile(gh, filename) gwinImageOpenGFile((gh), gfileOpen((filename), "rb"))
81 
82  /**
83  * @brief Sets the input routines that support reading the image from memory
84  * in RAM or flash.
85  * @pre GFILE_NEED_MEMFS must be GFXON
86  * @return gTrue if the IO open function succeeds
87  *
88  * @param[in] gh The widget (must be an image widget)
89  * @param[in] ptr A pointer to the image in RAM or Flash
90  *
91  * @api
92  */
93 #define gwinImageOpenMemory(gh, ptr) gwinImageOpenGFile((gh), gfileOpenMemory((void *)(ptr), "rb"))
94 
95 /**
96  * @brief Sets the input routines that support reading the image from a BaseFileStream (eg. an SD-Card).
97  * @return gTrue if the IO open function succeeds
98  * @pre GFILE_NEED_CHIBIOSFS and GFX_USE_OS_CHIBIOS must be GFXON
99  *
100  * @param[in] gh The widget (must be an image widget)
101  * @param[in] streamPtr A pointer to the (open) BaseFileStream object.
102  *
103  * @api
104  */
105 #define gwinImageOpenStream(gh, streamPtr) gwinImageOpenGFile((gh), gfileOpenBaseFIleStream((streamPtr), "rb"))
106 
107 /**
108  * @brief Cache the image.
109  * @details Decodes and caches the current frame into RAM.
110  *
111  * @param[in] gh The widget (must be an image widget)
112  *
113  * @return GDISP_IMAGE_ERR_OK (0) on success or an error code.
114  *
115  * @api
116  */
118 
119 #endif // _GWIN_IMAGE_H
120 /** @} */
121 
struct GFILE GFILE
A file pointer.
Definition: gfile.h:34
gdispImageError gwinImageCache(GHandle gh)
Cache the image.
GHandle gwinGImageCreate(GDisplay *g, GImageObject *widget, GWindowInit *pInit)
Create an image widget.
gBool gwinImageOpenGFile(GHandle gh, GFILE *f)
Opens the image using a GFILE.
gU16 gdispImageError
An image error code.
Definition: gdisp_image.h:37
A GTimer structure.
Definition: gtimer.h:52
The structure to initialise a GWIN.
Definition: gwin.h:75
A window object structure.
Definition: gwin.h:40
The structure for an image.
Definition: gdisp_image.h:59