1 /**
2  * @file lv_img.h
3  *
4  */
5 
6 #ifndef LV_IMG_H
7 #define LV_IMG_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_IMG != 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 /**
38  * Data of image
39  */
40 typedef struct {
41     lv_obj_t obj;
42     const void * src; /*Image source: Pointer to an array or a file or a symbol*/
43     lv_point_t offset;
44     lv_coord_t w;          /*Width of the image (Handled by the library)*/
45     lv_coord_t h;          /*Height of the image (Handled by the library)*/
46     uint16_t angle;    /*rotation angle of the image*/
47     lv_point_t pivot;     /*rotation center of the image*/
48     uint16_t zoom;         /*256 means no zoom, 512 double size, 128 half size*/
49     uint8_t src_type : 2;  /*See: lv_img_src_t*/
50     uint8_t cf : 5;        /*Color format from `lv_img_color_format_t`*/
51     uint8_t antialias : 1; /*Apply anti-aliasing in transformations (rotate, zoom)*/
52     uint8_t obj_size_mode: 2; /*Image size mode when image size and object size is different.*/
53 } lv_img_t;
54 
55 extern const lv_obj_class_t lv_img_class;
56 
57 /**
58  * Image size mode, when image size and object size is different
59  */
60 enum {
61     /** Zoom doesn't affect the coordinates of the object,
62      *  however if zoomed in the image is drawn out of the its coordinates.
63      *  The layout's won't change on zoom */
64     LV_IMG_SIZE_MODE_VIRTUAL = 0,
65 
66     /** If the object size is set to SIZE_CONTENT, then object size equals zoomed image size.
67      *  It causes layout recalculation.
68      *  If the object size is set explicitly, the image will be cropped when zoomed in.*/
69     LV_IMG_SIZE_MODE_REAL,
70 };
71 
72 typedef uint8_t lv_img_size_mode_t;
73 
74 /**********************
75  * GLOBAL PROTOTYPES
76  **********************/
77 
78 /**
79  * Create an image object
80  * @param parent pointer to an object, it will be the parent of the new image
81  * @return pointer to the created image
82  */
83 lv_obj_t * lv_img_create(lv_obj_t * parent);
84 
85 /*=====================
86  * Setter functions
87  *====================*/
88 
89 /**
90  * Set the image data to display on the object
91  * @param obj       pointer to an image object
92  * @param src_img   1) pointer to an ::lv_img_dsc_t descriptor (converted by LVGL's image converter) (e.g. &my_img) or
93  *                  2) path to an image file (e.g. "S:/dir/img.bin")or
94  *                  3) a SYMBOL (e.g. LV_SYMBOL_OK)
95  */
96 void lv_img_set_src(lv_obj_t * obj, const void * src);
97 
98 /**
99  * Set an offset for the source of an image so the image will be displayed from the new origin.
100  * @param obj       pointer to an image
101  * @param x         the new offset along x axis.
102  */
103 void lv_img_set_offset_x(lv_obj_t * obj, lv_coord_t x);
104 
105 /**
106  * Set an offset for the source of an image.
107  * so the image will be displayed from the new origin.
108  * @param obj       pointer to an image
109  * @param y         the new offset along y axis.
110  */
111 void lv_img_set_offset_y(lv_obj_t * obj, lv_coord_t y);
112 
113 
114 /**
115  * Set the rotation angle of the image.
116  * The image will be rotated around the set pivot set by `lv_img_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 angle in degree with 0.1 degree resolution (0..3600: clock wise)
120  */
121 void lv_img_set_angle(lv_obj_t * obj, int16_t angle);
122 
123 /**
124  * Set the rotation center of the image.
125  * The image will be rotated around this point.
126  * @param obj       pointer to an image object
127  * @param x         rotation center x of the image
128  * @param y         rotation center y of the image
129  */
130 void lv_img_set_pivot(lv_obj_t * obj, lv_coord_t x, lv_coord_t y);
131 
132 
133 /**
134  * Set the zoom factor of the image.
135  * Note that indexed and alpha only images can't be transformed.
136  * @param img       pointer to an image object
137  * @param zoom      the zoom factor.
138  * @example 256 or LV_ZOOM_IMG_NONE for no zoom
139  * @example <256: scale down
140  * @example >256 scale up
141  * @example 128 half size
142  * @example 512 double size
143  */
144 void lv_img_set_zoom(lv_obj_t * obj, uint16_t zoom);
145 
146 /**
147  * Enable/disable anti-aliasing for the transformations (rotate, zoom) or not.
148  * The quality is better with anti-aliasing looks better but slower.
149  * @param obj       pointer to an image object
150  * @param antialias true: anti-aliased; false: not anti-aliased
151  */
152 void lv_img_set_antialias(lv_obj_t * obj, bool antialias);
153 
154 /**
155  * Set the image object size mode.
156  *
157  * @param obj       pointer to an image object
158  * @param mode      the new size mode.
159  */
160 void lv_img_set_size_mode(lv_obj_t * obj, lv_img_size_mode_t mode);
161 /*=====================
162  * Getter functions
163  *====================*/
164 
165 /**
166  * Get the source of the image
167  * @param obj       pointer to an image object
168  * @return          the image source (symbol, file name or ::lv-img_dsc_t for C arrays)
169  */
170 const void * lv_img_get_src(lv_obj_t * obj);
171 
172 /**
173  * Get the offset's x attribute of the image object.
174  * @param img       pointer to an image
175  * @return          offset X value.
176  */
177 lv_coord_t lv_img_get_offset_x(lv_obj_t * obj);
178 
179 /**
180  * Get the offset's y attribute of the image object.
181  * @param obj       pointer to an image
182  * @return          offset Y value.
183  */
184 lv_coord_t lv_img_get_offset_y(lv_obj_t * obj);
185 
186 /**
187  * Get the rotation angle of the image.
188  * @param obj       pointer to an image object
189  * @return      rotation angle in 0.1 degrees (0..3600)
190  */
191 uint16_t lv_img_get_angle(lv_obj_t * obj);
192 
193 /**
194  * Get the pivot (rotation center) of the image.
195  * @param img       pointer to an image object
196  * @param pivot     store the rotation center here
197  */
198 void lv_img_get_pivot(lv_obj_t * obj, lv_point_t * pivot);
199 
200 /**
201  * Get the zoom factor of the image.
202  * @param obj       pointer to an image object
203  * @return          zoom factor (256: no zoom)
204  */
205 uint16_t lv_img_get_zoom(lv_obj_t * obj);
206 
207 /**
208  * Get whether the transformations (rotate, zoom) are anti-aliased or not
209  * @param obj       pointer to an image object
210  * @return          true: anti-aliased; false: not anti-aliased
211  */
212 bool lv_img_get_antialias(lv_obj_t * obj);
213 
214 /**
215  * Get the size mode of the image
216  * @param obj       pointer to an image object
217  * @return          element of @ref lv_img_size_mode_t
218  */
219 lv_img_size_mode_t lv_img_get_size_mode(lv_obj_t * obj);
220 
221 /**********************
222  *      MACROS
223  **********************/
224 
225 /** Use this macro to declare an image in a C file*/
226 #define LV_IMG_DECLARE(var_name) extern const lv_img_dsc_t var_name;
227 
228 #endif /*LV_USE_IMG*/
229 
230 #ifdef __cplusplus
231 } /*extern "C"*/
232 #endif
233 
234 #endif /*LV_IMG_H*/
235