1 /**
2  * @file lv_image.h
3  *
4  */
5 
6 #ifndef LV_IMAGE_H
7 #define LV_IMAGE_H
8 
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 /*********************
14  *      INCLUDES
15  *********************/
16 #include "../../lv_conf_internal.h"
17 
18 #if LV_USE_IMAGE != 0
19 
20 /*Testing of dependencies*/
21 #if LV_USE_LABEL == 0
22 #error "lv_img: lv_label is required. Enable it in lv_conf.h (LV_USE_LABEL 1)"
23 #endif
24 
25 #include "../../core/lv_obj.h"
26 #include "../../misc/lv_fs.h"
27 #include "../../draw/lv_draw.h"
28 
29 /*********************
30  *      DEFINES
31  *********************/
32 
33 /**********************
34  *      TYPEDEFS
35  **********************/
36 
37 LV_ATTRIBUTE_EXTERN_DATA extern const lv_obj_class_t lv_image_class;
38 
39 /**
40  * Image size mode, when image size and object size is different
41  */
42 typedef enum {
43     LV_IMAGE_ALIGN_DEFAULT = 0,
44     LV_IMAGE_ALIGN_TOP_LEFT,
45     LV_IMAGE_ALIGN_TOP_MID,
46     LV_IMAGE_ALIGN_TOP_RIGHT,
47     LV_IMAGE_ALIGN_BOTTOM_LEFT,
48     LV_IMAGE_ALIGN_BOTTOM_MID,
49     LV_IMAGE_ALIGN_BOTTOM_RIGHT,
50     LV_IMAGE_ALIGN_LEFT_MID,
51     LV_IMAGE_ALIGN_RIGHT_MID,
52     LV_IMAGE_ALIGN_CENTER,
53     LV_IMAGE_ALIGN_AUTO_TRANSFORM,
54     LV_IMAGE_ALIGN_STRETCH,
55     LV_IMAGE_ALIGN_TILE,
56 } lv_image_align_t;
57 
58 #if LV_USE_OBJ_PROPERTY
59 enum {
60     LV_PROPERTY_ID(IMAGE, SRC,          LV_PROPERTY_TYPE_IMGSRC,    0),
61     LV_PROPERTY_ID(IMAGE, OFFSET_X,     LV_PROPERTY_TYPE_INT,       1),
62     LV_PROPERTY_ID(IMAGE, OFFSET_Y,     LV_PROPERTY_TYPE_INT,       2),
63     LV_PROPERTY_ID(IMAGE, ROTATION,     LV_PROPERTY_TYPE_INT,       3),
64     LV_PROPERTY_ID(IMAGE, PIVOT,        LV_PROPERTY_TYPE_POINT,     4),
65     LV_PROPERTY_ID(IMAGE, SCALE,        LV_PROPERTY_TYPE_INT,       5),
66     LV_PROPERTY_ID(IMAGE, SCALE_X,      LV_PROPERTY_TYPE_INT,       6),
67     LV_PROPERTY_ID(IMAGE, SCALE_Y,      LV_PROPERTY_TYPE_INT,       7),
68     LV_PROPERTY_ID(IMAGE, BLEND_MODE,   LV_PROPERTY_TYPE_INT,       8),
69     LV_PROPERTY_ID(IMAGE, ANTIALIAS,    LV_PROPERTY_TYPE_INT,       9),
70     LV_PROPERTY_ID(IMAGE, INNER_ALIGN,  LV_PROPERTY_TYPE_INT,       10),
71     LV_PROPERTY_IMAGE_END,
72 };
73 #endif
74 
75 /**********************
76  * GLOBAL PROTOTYPES
77  **********************/
78 
79 /**
80  * Create an image object
81  * @param parent pointer to an object, it will be the parent of the new image
82  * @return pointer to the created image
83  */
84 lv_obj_t * lv_image_create(lv_obj_t * parent);
85 
86 /*=====================
87  * Setter functions
88  *====================*/
89 
90 /**
91  * Set the image data to display on the object
92  * @param obj       pointer to an image object
93  * @param src       1) pointer to an ::lv_image_dsc_t descriptor (converted by LVGL's image converter) (e.g. &my_img) or
94  *                  2) path to an image file (e.g. "S:/dir/img.bin")or
95  *                  3) a SYMBOL (e.g. LV_SYMBOL_OK)
96  */
97 void lv_image_set_src(lv_obj_t * obj, const void * src);
98 
99 /**
100  * Set an offset for the source of an image so the image will be displayed from the new origin.
101  * @param obj       pointer to an image
102  * @param x         the new offset along x axis.
103  */
104 void lv_image_set_offset_x(lv_obj_t * obj, int32_t x);
105 
106 /**
107  * Set an offset for the source of an image.
108  * so the image will be displayed from the new origin.
109  * @param obj       pointer to an image
110  * @param y         the new offset along y axis.
111  */
112 void lv_image_set_offset_y(lv_obj_t * obj, int32_t y);
113 
114 /**
115  * Set the rotation angle of the image.
116  * The image will be rotated around the set pivot set by `lv_image_set_pivot()`
117  * Note that indexed and alpha only images can't be transformed.
118  * @param obj       pointer to an image object
119  * @param angle     rotation in degree with 0.1 degree resolution (0..3600: clock wise)
120  * @note            if image_align is `LV_IMAGE_ALIGN_STRETCH` or `LV_IMAGE_ALIGN_FIT`
121  *                  rotation will be set to 0 automatically.
122  *
123  */
124 void lv_image_set_rotation(lv_obj_t * obj, int32_t angle);
125 
126 /**
127  * Set the rotation center of the image.
128  * The image will be rotated around this point.
129  * x, y can be set with value of LV_PCT, lv_image_get_pivot will return the true pixel coordinate of pivot in this case.
130  * @param obj       pointer to an image object
131  * @param x         rotation center x of the image
132  * @param y         rotation center y of the image
133  */
134 void lv_image_set_pivot(lv_obj_t * obj, int32_t x, int32_t y);
135 
136 /**
137  * Set the zoom factor of the image.
138  * Note that indexed and alpha only images can't be transformed.
139  * @param obj       pointer to an image object
140  * @param zoom      the zoom factor.  Example values:
141  *                      - 256 or LV_ZOOM_IMAGE_NONE:  no zoom
142  *                      - <256:  scale down
143  *                      - >256:  scale up
144  *                      - 128:  half size
145  *                      - 512:  double size
146  */
147 void lv_image_set_scale(lv_obj_t * obj, uint32_t zoom);
148 
149 /**
150  * Set the horizontal zoom factor of the image.
151  * Note that indexed and alpha only images can't be transformed.
152  * @param obj       pointer to an image object
153  * @param zoom      the zoom factor.  Example values:
154  *                      - 256 or LV_ZOOM_IMAGE_NONE:  no zoom
155  *                      - <256:  scale down
156  *                      - >256:  scale up
157  *                      - 128:  half size
158  *                      - 512:  double size
159  */
160 void lv_image_set_scale_x(lv_obj_t * obj, uint32_t zoom);
161 
162 /**
163  * Set the vertical zoom factor of the image.
164  * Note that indexed and alpha only images can't be transformed.
165  * @param obj       pointer to an image object
166  * @param zoom      the zoom factor.  Example values:
167  *                      - 256 or LV_ZOOM_IMAGE_NONE:  no zoom
168  *                      - <256:  scale down
169  *                      - >256:  scale up
170  *                      - 128:  half size
171  *                      - 512:  double size
172  */
173 void lv_image_set_scale_y(lv_obj_t * obj, uint32_t zoom);
174 
175 /**
176  * Set the blend mode of an image.
177  * @param obj           pointer to an image object
178  * @param blend_mode    the new blend mode
179  */
180 void lv_image_set_blend_mode(lv_obj_t * obj, lv_blend_mode_t blend_mode);
181 
182 /**
183  * Enable/disable anti-aliasing for the transformations (rotate, zoom) or not.
184  * The quality is better with anti-aliasing looks better but slower.
185  * @param obj       pointer to an image object
186  * @param antialias true: anti-aliased; false: not anti-aliased
187  */
188 void lv_image_set_antialias(lv_obj_t * obj, bool antialias);
189 
190 /**
191  * Set the image object size mode.
192  * @param obj       pointer to an image object
193  * @param align     the new align mode.
194  * @note            if image_align is `LV_IMAGE_ALIGN_STRETCH` or `LV_IMAGE_ALIGN_FIT`
195  *                  rotation, scale and pivot will be overwritten and controlled internally.
196  */
197 void lv_image_set_inner_align(lv_obj_t * obj, lv_image_align_t align);
198 
199 /**
200  * Set an A8 bitmap mask for the image.
201  * @param obj       pointer to an image object
202  * @param src       an lv_image_dsc_t bitmap mask source.
203  */
204 void lv_image_set_bitmap_map_src(lv_obj_t * obj, const lv_image_dsc_t * src);
205 
206 /*=====================
207  * Getter functions
208  *====================*/
209 
210 /**
211  * Get the source of the image
212  * @param obj       pointer to an image object
213  * @return          the image source (symbol, file name or ::lv-img_dsc_t for C arrays)
214  */
215 const void * lv_image_get_src(lv_obj_t * obj);
216 
217 /**
218  * Get the offset's x attribute of the image object.
219  * @param obj       pointer to an image
220  * @return          offset X value.
221  */
222 int32_t lv_image_get_offset_x(lv_obj_t * obj);
223 
224 /**
225  * Get the offset's y attribute of the image object.
226  * @param obj       pointer to an image
227  * @return          offset Y value.
228  */
229 int32_t lv_image_get_offset_y(lv_obj_t * obj);
230 
231 /**
232  * Get the rotation of the image.
233  * @param obj       pointer to an image object
234  * @return          rotation in 0.1 degrees (0..3600)
235  * @note            if image_align is `LV_IMAGE_ALIGN_STRETCH` or  `LV_IMAGE_ALIGN_FIT`
236  *                  rotation will be set to 0 automatically.
237  */
238 int32_t lv_image_get_rotation(lv_obj_t * obj);
239 
240 /**
241  * Get the pivot (rotation center) of the image.
242  * If pivot is set with LV_PCT, convert it to px before return.
243  * @param obj       pointer to an image object
244  * @param pivot     store the rotation center here
245  */
246 void lv_image_get_pivot(lv_obj_t * obj, lv_point_t * pivot);
247 
248 /**
249  * Get the zoom factor of the image.
250  * @param obj       pointer to an image object
251  * @return          zoom factor (256: no zoom)
252  */
253 int32_t lv_image_get_scale(lv_obj_t * obj);
254 
255 /**
256  * Get the horizontal zoom factor of the image.
257  * @param obj       pointer to an image object
258  * @return          zoom factor (256: no zoom)
259  */
260 int32_t lv_image_get_scale_x(lv_obj_t * obj);
261 
262 /**
263  * Get the vertical zoom factor of the image.
264  * @param obj       pointer to an image object
265  * @return          zoom factor (256: no zoom)
266  */
267 int32_t lv_image_get_scale_y(lv_obj_t * obj);
268 
269 /**
270  * Get the current blend mode of the image
271  * @param obj       pointer to an image object
272  * @return          the current blend mode
273  */
274 lv_blend_mode_t lv_image_get_blend_mode(lv_obj_t * obj);
275 
276 /**
277  * Get whether the transformations (rotate, zoom) are anti-aliased or not
278  * @param obj       pointer to an image object
279  * @return          true: anti-aliased; false: not anti-aliased
280  */
281 bool lv_image_get_antialias(lv_obj_t * obj);
282 
283 /**
284  * Get the size mode of the image
285  * @param obj       pointer to an image object
286  * @return          element of `lv_image_align_t`
287  */
288 lv_image_align_t lv_image_get_inner_align(lv_obj_t * obj);
289 
290 /**
291  * Get the bitmap mask source.
292  * @param obj       pointer to an image object
293  * @return          an lv_image_dsc_t bitmap mask source.
294  */
295 const lv_image_dsc_t * lv_image_get_bitmap_map_src(lv_obj_t * obj);
296 
297 /**********************
298  *      MACROS
299  **********************/
300 
301 /** Use this macro to declare an image in a C file*/
302 #define LV_IMAGE_DECLARE(var_name) extern const lv_image_dsc_t var_name
303 
304 #endif /*LV_USE_IMAGE*/
305 
306 #ifdef __cplusplus
307 } /*extern "C"*/
308 #endif
309 
310 #endif /*LV_IMAGE_H*/
311