Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/libs/lvgl/lv_draw/lv_draw.c
1476 views
1
/**
2
* @file lv_draw.c
3
*
4
*/
5
6
/*********************
7
* INCLUDES
8
*********************/
9
10
#include <stdio.h>
11
#include "lv_draw.h"
12
#include "lv_draw_rbasic.h"
13
#include "lv_draw_vbasic.h"
14
#include "../lv_misc/lv_fs.h"
15
#include "../lv_misc/lv_math.h"
16
#include "../lv_misc/lv_ufs.h"
17
#include "../lv_objx/lv_img.h"
18
19
/*********************
20
* DEFINES
21
*********************/
22
23
/**********************
24
* TYPEDEFS
25
**********************/
26
27
/**********************
28
* STATIC PROTOTYPES
29
**********************/
30
31
/**********************
32
* STATIC VARIABLES
33
**********************/
34
35
#if LV_VDB_SIZE != 0
36
void (*const px_fp)(lv_coord_t x, lv_coord_t y, const lv_area_t * mask, lv_color_t color, lv_opa_t opa) = lv_vpx;
37
void (*const fill_fp)(const lv_area_t * coords, const lv_area_t * mask, lv_color_t color, lv_opa_t opa) = lv_vfill;
38
void (*const letter_fp)(const lv_point_t * pos_p, const lv_area_t * mask, const lv_font_t * font_p, uint32_t letter, lv_color_t color, lv_opa_t opa) = lv_vletter;
39
void (*const map_fp)(const lv_area_t * cords_p, const lv_area_t * mask_p,
40
const uint8_t * map_p, lv_opa_t opa, bool chroma_key, bool alpha_byte,
41
lv_color_t recolor, lv_opa_t recolor_opa) = lv_vmap;
42
#else
43
void (*const px_fp)(lv_coord_t x, lv_coord_t y, const lv_area_t * mask, lv_color_t color, lv_opa_t opa) = lv_rpx;
44
void (*const fill_fp)(const lv_area_t * coords, const lv_area_t * mask, lv_color_t color, lv_opa_t opa) = lv_rfill;
45
void (*const letter_fp)(const lv_point_t * pos_p, const lv_area_t * mask, const lv_font_t * font_p, uint32_t letter, lv_color_t color, lv_opa_t opa) = lv_rletter;
46
void (*const map_fp)(const lv_area_t * cords_p, const lv_area_t * mask_p,
47
const uint8_t * map_p, lv_opa_t opa, bool chroma_key, bool alpha_byte,
48
lv_color_t recolor, lv_opa_t recolor_opa) = lv_rmap;
49
#endif
50
51
/**********************
52
* MACROS
53
**********************/
54
55
/**********************
56
* GLOBAL FUNCTIONS
57
**********************/
58
59
/**********************
60
* STATIC FUNCTIONS
61
**********************/
62
63
#if LV_ANTIALIAS != 0
64
65
/**
66
* Get the opacity of a pixel based it's position in a line segment
67
* @param seg segment length
68
* @param px_id position of of a pixel which opacity should be get [0..seg-1]
69
* @param base_opa the base opacity
70
* @return the opacity of the given pixel
71
*/
72
lv_opa_t lv_draw_aa_get_opa(lv_coord_t seg, lv_coord_t px_id, lv_opa_t base_opa)
73
{
74
/* How to calculate the opacity of pixels on the edges which makes the anti-aliasing?
75
* For example we have a line like this (y = -0.5 * x):
76
*
77
* | _ _
78
* * * |
79
*
80
* Anti-aliased pixels come to the '*' characters
81
* Calculate what percentage of the pixels should be covered if real line (not rasterized) would be drawn:
82
* 1. A real line should start on (0;0) and end on (2;1)
83
* 2. So the line intersection coordinates on the first pixel: (0;0) (1;0.5) -> 25% covered pixel in average
84
* 3. For the second pixel: (1;0.5) (2;1) -> 75% covered pixel in average
85
* 4. The equation: (px_id * 2 + 1) / (segment_width * 2)
86
* segment_width: the line segment which is being anti-aliased (was 2 in the example)
87
* px_id: pixel ID from 0 to (segment_width - 1)
88
* result: [0..1] coverage of the pixel
89
*/
90
91
/*Accelerate the common segment sizes to avoid division*/
92
static const lv_opa_t seg1[1] = {128};
93
static const lv_opa_t seg2[2] = {64, 192};
94
static const lv_opa_t seg3[3] = {42, 128, 212};
95
static const lv_opa_t seg4[4] = {32, 96, 159, 223};
96
static const lv_opa_t seg5[5] = {26, 76, 128, 178, 230};
97
static const lv_opa_t seg6[6] = {21, 64, 106, 148, 191, 234};
98
static const lv_opa_t seg7[7] = {18, 55, 91, 128, 164, 200, 237};
99
static const lv_opa_t seg8[8] = {16, 48, 80, 112, 143, 175, 207, 239};
100
101
static const lv_opa_t * seg_map[] = {seg1, seg2, seg3, seg4,
102
seg5, seg6, seg7, seg8
103
};
104
105
if(seg == 0) return LV_OPA_TRANSP;
106
else if(seg < 8) return (uint32_t)((uint32_t)seg_map[seg - 1][px_id] * base_opa) >> 8;
107
else {
108
return ((px_id * 2 + 1) * base_opa) / (2 * seg);
109
}
110
111
}
112
113
/**
114
* Add a vertical anti-aliasing segment (pixels with decreasing opacity)
115
* @param x start point x coordinate
116
* @param y start point y coordinate
117
* @param length length of segment (negative value to start from 0 opacity)
118
* @param mask draw only in this area
119
* @param color color of pixels
120
* @param opa maximum opacity
121
*/
122
void lv_draw_aa_ver_seg(lv_coord_t x, lv_coord_t y, lv_coord_t length, const lv_area_t * mask, lv_color_t color, lv_opa_t opa)
123
{
124
bool aa_inv = false;
125
if(length < 0) {
126
aa_inv = true;
127
length = -length;
128
}
129
130
lv_coord_t i;
131
for(i = 0; i < length; i++) {
132
lv_opa_t px_opa = lv_draw_aa_get_opa(length, i, opa);
133
if(aa_inv) px_opa = opa - px_opa;
134
px_fp(x, y + i, mask, color, px_opa);
135
}
136
}
137
138
/**
139
* Add a horizontal anti-aliasing segment (pixels with decreasing opacity)
140
* @param x start point x coordinate
141
* @param y start point y coordinate
142
* @param length length of segment (negative value to start from 0 opacity)
143
* @param mask draw only in this area
144
* @param color color of pixels
145
* @param opa maximum opacity
146
*/
147
void lv_draw_aa_hor_seg(lv_coord_t x, lv_coord_t y, lv_coord_t length, const lv_area_t * mask, lv_color_t color, lv_opa_t opa)
148
{
149
bool aa_inv = false;
150
if(length < 0) {
151
aa_inv = true;
152
length = -length;
153
}
154
155
lv_coord_t i;
156
for(i = 0; i < length; i++) {
157
lv_opa_t px_opa = lv_draw_aa_get_opa(length, i, opa);
158
if(aa_inv) px_opa = opa - px_opa;
159
px_fp(x + i, y, mask, color, px_opa);
160
}
161
}
162
163
#endif
164
165