version 2.8
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.org/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 TRUE in your gfxconf.h
21  * @pre GFX_USE_GWIN must be set to TRUE in your gfxconf.h
22  * @pre GDISP_NEED_IMAGE must be set to TRUE in your gfxconf.h
23  * @pre GWIN_NEED_IMAGE must be set to TRUE 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  gdispImage image; // The image itself
38  #if GWIN_NEED_IMAGE_ANIMATION
39  GTimer timer; // Timer used for animated images
40  #endif
41 } GImageObject;
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 /**
48  * @brief Create an image widget.
49  * @details Display's a picture.
50  * @return NULL if there is no resultant drawing area, otherwise the widget handle.
51  *
52  * @param[in] g The GDisplay to display this window on
53  * @param[in] widget The image widget structure to initialise. If this is NULL, the structure is dynamically allocated.
54  * @param[in] pInit The initialization parameters to use.
55  *
56  * @note The default background color gets set to the current default one.
57  * @note An image window knows how to redraw.
58  *
59  * @api
60  */
61 GHandle gwinGImageCreate(GDisplay *g, GImageObject *widget, GWindowInit *pInit);
62 #define gwinImageCreate(w, pInit) gwinGImageCreate(GDISP, w, pInit)
63 
64 /**
65  * @brief Opens the image using a GFILE
66  * @return TRUE if the image can be opened
67  *
68  * @param[in] gh The widget (must be an image widget)
69  * @param[in] f The open (for reading) GFILE to use
70  *
71  * @api
72  */
73 bool_t gwinImageOpenGFile(GHandle gh, GFILE *f);
74 
75 /**
76  * @brief Opens the image using the specified filename
77  * @return TRUE if the open succeeds
78  *
79  * @param[in] gh The widget (must be an image widget)
80  * @param[in] filename The filename to open
81  *
82  * @api
83  */
84 #define gwinImageOpenFile(gh, filename) gwinImageOpenGFile((gh), gfileOpen((filename), "rb"))
85 
86  /**
87  * @brief Sets the input routines that support reading the image from memory
88  * in RAM or flash.
89  * @pre GFILE_NEED_MEMFS must be TRUE
90  * @return TRUE if the IO open function succeeds
91  *
92  * @param[in] gh The widget (must be an image widget)
93  * @param[in] ptr A pointer to the image in RAM or Flash
94  *
95  * @api
96  */
97 #define gwinImageOpenMemory(gh, ptr) gwinImageOpenGFile((gh), gfileOpenMemory((void *)(ptr), "rb"))
98 
99 /**
100  * @brief Sets the input routines that support reading the image from a BaseFileStream (eg. an SD-Card).
101  * @return TRUE if the IO open function succeeds
102  * @pre GFILE_NEED_CHIBIOSFS and GFX_USE_OS_CHIBIOS must be TRUE
103  *
104  * @param[in] gh The widget (must be an image widget)
105  * @param[in] streamPtr A pointer to the (open) BaseFileStream object.
106  *
107  * @api
108  */
109 #define gwinImageOpenStream(gh, streamPtr) gwinImageOpenGFile((gh), gfileOpenBaseFIleStream((streamPtr), "rb"))
110 
111 /**
112  * @brief Cache the image.
113  * @details Decodes and caches the current frame into RAM.
114  *
115  * @param[in] gh The widget (must be an image widget)
116  *
117  * @return GDISP_IMAGE_ERR_OK (0) on success or an error code.
118  *
119  * @api
120  */
122 
123 #ifdef __cplusplus
124 }
125 #endif
126 
127 #endif // _GWIN_IMAGE_H
128 /** @} */
129 
The structure to initialise a GWIN.
Definition: gwin.h:75
A GTimer structure.
Definition: gtimer.h:52
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.
The structure for an image.
Definition: gdisp_image.h:59
A window object structure.
Definition: gwin.h:40
bool_t gwinImageOpenGFile(GHandle gh, GFILE *f)
Opens the image using a GFILE.
uint16_t gdispImageError
An image error code.
Definition: gdisp_image.h:37