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 #include "../lv_core/lv_obj.h" 21 #include "../lv_misc/lv_fs.h" 22 #include "lv_label.h" 23 #include "../lv_draw/lv_draw.h" 24 25 /********************* 26 * DEFINES 27 *********************/ 28 29 /********************** 30 * TYPEDEFS 31 **********************/ 32 /*Data of image*/ 33 typedef struct { 34 /*No inherited ext. because inherited from the base object*/ /*Ext. of ancestor*/ 35 /*New data for this type */ 36 const void * src; /*Image source: Pointer to an array or a file or a symbol*/ 37 lv_point_t offset; 38 lv_coord_t w; /*Width of the image (Handled by the library)*/ 39 lv_coord_t h; /*Height of the image (Handled by the library)*/ 40 uint16_t angle; /*rotation angle of the image*/ 41 lv_point_t pivot; /*rotation center of the image*/ 42 uint16_t zoom; /*256 means no zoom, 512 double size, 128 half size*/ 43 uint8_t src_type : 2; /*See: lv_img_src_t*/ 44 uint8_t auto_size : 1; /*1: automatically set the object size to the image size*/ 45 uint8_t cf : 5; /*Color format from `lv_img_color_format_t`*/ 46 uint8_t antialias : 1; /*Apply anti-aliasing in transformations (rotate, zoom)*/ 47 } lv_img_ext_t; 48 49 /*Image parts*/ 50 enum { 51 LV_IMG_PART_MAIN, 52 }; 53 typedef uint8_t lv_img_part_t; 54 55 /********************** 56 * GLOBAL PROTOTYPES 57 **********************/ 58 59 /** 60 * Create an image objects 61 * @param par pointer to an object, it will be the parent of the new button 62 * @param copy pointer to a image object, if not NULL then the new object will be copied from it 63 * @return pointer to the created image 64 */ 65 lv_obj_t * lv_img_create(lv_obj_t * par, const lv_obj_t * copy); 66 67 /*===================== 68 * Setter functions 69 *====================*/ 70 71 /** 72 * Set the pixel map to display by the image 73 * @param img pointer to an image object 74 * @param data the image data 75 */ 76 void lv_img_set_src(lv_obj_t * img, const void * src_img); 77 78 /** 79 * Enable the auto size feature. 80 * If enabled the object size will be same as the picture size. 81 * @param img pointer to an image 82 * @param en true: auto size enable, false: auto size disable 83 */ 84 void lv_img_set_auto_size(lv_obj_t * img, bool autosize_en); 85 86 /** 87 * Set an offset for the source of an image. 88 * so the image will be displayed from the new origin. 89 * @param img pointer to an image 90 * @param x: the new offset along x axis. 91 */ 92 void lv_img_set_offset_x(lv_obj_t * img, lv_coord_t x); 93 94 /** 95 * Set an offset for the source of an image. 96 * so the image will be displayed from the new origin. 97 * @param img pointer to an image 98 * @param y: the new offset along y axis. 99 */ 100 void lv_img_set_offset_y(lv_obj_t * img, lv_coord_t y); 101 102 /** 103 * Set the rotation center of the image. 104 * The image will be rotated around this point 105 * @param img pointer to an image object 106 * @param pivot_x rotation center x of the image 107 * @param pivot_y rotation center y of the image 108 */ 109 void lv_img_set_pivot(lv_obj_t * img, lv_coord_t pivot_x, lv_coord_t pivot_y); 110 111 /** 112 * Set the rotation angle of the image. 113 * The image will be rotated around the set pivot set by `lv_img_set_pivot()` 114 * @param img pointer to an image object 115 * @param angle rotation angle in degree with 0.1 degree resolution (0..3600: clock wise) 116 */ 117 void lv_img_set_angle(lv_obj_t * img, int16_t angle); 118 119 /** 120 * Set the zoom factor of the image. 121 * @param img pointer to an image object 122 * @param zoom the zoom factor. 123 * - 256 or LV_ZOOM_IMG_NONE for no zoom 124 * - <256: scale down 125 * - >256 scale up 126 * - 128 half size 127 * - 512 double size 128 */ 129 void lv_img_set_zoom(lv_obj_t * img, uint16_t zoom); 130 131 /** 132 * Enable/disable anti-aliasing for the transformations (rotate, zoom) or not 133 * @param img pointer to an image object 134 * @param antialias true: anti-aliased; false: not anti-aliased 135 */ 136 void lv_img_set_antialias(lv_obj_t * img, bool antialias); 137 138 /*===================== 139 * Getter functions 140 *====================*/ 141 142 /** 143 * Get the source of the image 144 * @param img pointer to an image object 145 * @return the image source (symbol, file name or C array) 146 */ 147 const void * lv_img_get_src(lv_obj_t * img); 148 149 /** 150 * Get the name of the file set for an image 151 * @param img pointer to an image 152 * @return file name 153 */ 154 const char * lv_img_get_file_name(const lv_obj_t * img); 155 156 /** 157 * Get the auto size enable attribute 158 * @param img pointer to an image 159 * @return true: auto size is enabled, false: auto size is disabled 160 */ 161 bool lv_img_get_auto_size(const lv_obj_t * img); 162 163 /** 164 * Get the offset.x attribute of the img object. 165 * @param img pointer to an image 166 * @return offset.x value. 167 */ 168 lv_coord_t lv_img_get_offset_x(lv_obj_t * img); 169 170 /** 171 * Get the offset.y attribute of the img object. 172 * @param img pointer to an image 173 * @return offset.y value. 174 */ 175 lv_coord_t lv_img_get_offset_y(lv_obj_t * img); 176 177 /** 178 * Get the rotation angle of the image. 179 * @param img pointer to an image object 180 * @return rotation angle in degree (0..359) 181 */ 182 uint16_t lv_img_get_angle(lv_obj_t * img); 183 184 /** 185 * Get the rotation center of the image. 186 * @param img pointer to an image object 187 * @param center rotation center of the image 188 */ 189 void lv_img_get_pivot(lv_obj_t * img, lv_point_t * center); 190 191 /** 192 * Get the zoom factor of the image. 193 * @param img pointer to an image object 194 * @return zoom factor (256: no zoom) 195 */ 196 uint16_t lv_img_get_zoom(lv_obj_t * img); 197 198 /** 199 * Get whether the transformations (rotate, zoom) are anti-aliased or not 200 * @param img pointer to an image object 201 * @return true: anti-aliased; false: not anti-aliased 202 */ 203 bool lv_img_get_antialias(lv_obj_t * img); 204 205 /********************** 206 * MACROS 207 **********************/ 208 209 /*Use this macro to declare an image in a c file*/ 210 #define LV_IMG_DECLARE(var_name) extern const lv_img_dsc_t var_name; 211 212 #endif /*LV_USE_IMG*/ 213 214 #ifdef __cplusplus 215 } /* extern "C" */ 216 #endif 217 218 #endif /*LV_IMG_H*/ 219