1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* Copyright (c) 2026-present Eclipse ThreadX contributors |
4 |
|
|
* |
5 |
|
|
* This program and the accompanying materials are made available under the |
6 |
|
|
* terms of the MIT License which is available at |
7 |
|
|
* https://opensource.org/licenses/MIT. |
8 |
|
|
* |
9 |
|
|
* SPDX-License-Identifier: MIT |
10 |
|
|
**************************************************************************/ |
11 |
|
|
|
12 |
|
|
|
13 |
|
|
/**************************************************************************/ |
14 |
|
|
/**************************************************************************/ |
15 |
|
|
/** */ |
16 |
|
|
/** GUIX Component */ |
17 |
|
|
/** */ |
18 |
|
|
/** Display Management (Display) */ |
19 |
|
|
/** */ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
|
22 |
|
|
#define GX_SOURCE_CODE |
23 |
|
|
|
24 |
|
|
|
25 |
|
|
/* Include necessary system files. */ |
26 |
|
|
|
27 |
|
|
#include "gx_api.h" |
28 |
|
|
#include "gx_system.h" |
29 |
|
|
#include "gx_utility.h" |
30 |
|
|
#include "gx_display.h" |
31 |
|
|
|
32 |
|
|
/**************************************************************************/ |
33 |
|
|
/* */ |
34 |
|
|
/* FUNCTION RELEASE */ |
35 |
|
|
/* */ |
36 |
|
|
/* _gx_display_driver_generic_aliased_circle_draw PORTABLE C */ |
37 |
|
|
/* 6.1 */ |
38 |
|
|
/* AUTHOR */ |
39 |
|
|
/* */ |
40 |
|
|
/* Kenneth Maxwell, Microsoft Corporation */ |
41 |
|
|
/* */ |
42 |
|
|
/* DESCRIPTION */ |
43 |
|
|
/* */ |
44 |
|
|
/* Display driver to draw anti-aliased circle. */ |
45 |
|
|
/* */ |
46 |
|
|
/* INPUT */ |
47 |
|
|
/* */ |
48 |
|
|
/* context Drawing context */ |
49 |
|
|
/* xcenter x-coord of center of circle */ |
50 |
|
|
/* ycenter y-coord of center of circle */ |
51 |
|
|
/* r Radius of circle */ |
52 |
|
|
/* */ |
53 |
|
|
/* OUTPUT */ |
54 |
|
|
/* */ |
55 |
|
|
/* None */ |
56 |
|
|
/* */ |
57 |
|
|
/* CALLS */ |
58 |
|
|
/* */ |
59 |
|
|
/* _gx_utility_rectangle_overlap_detect Detect two rectangles being */ |
60 |
|
|
/* overlap to each other */ |
61 |
|
|
/* [gx_display_driver_pixel_blend] Basic display driver pixel */ |
62 |
|
|
/* blend function */ |
63 |
|
|
/* */ |
64 |
|
|
/* CALLED BY */ |
65 |
|
|
/* */ |
66 |
|
|
/* GUIX Internal Code */ |
67 |
|
|
/* */ |
68 |
|
|
/**************************************************************************/ |
69 |
|
|
#if defined(GX_ARC_DRAWING_SUPPORT) |
70 |
|
|
|
71 |
|
306 |
VOID _gx_display_driver_generic_aliased_circle_draw(GX_DRAW_CONTEXT *context, INT xcenter, INT ycenter, UINT r) |
72 |
|
|
{ |
73 |
|
|
/* The circle draw function is implemented from midpoint circle algorithm. */ |
74 |
|
|
|
75 |
|
|
GX_DISPLAY *display; |
76 |
|
|
GX_RECTANGLE *clip; |
77 |
|
|
GX_BRUSH *brush; |
78 |
|
|
INT x; |
79 |
|
|
INT y; |
80 |
|
|
GX_POINT point; |
81 |
|
306 |
INT sign[4][2] = {{1, 1}, {-1, 1}, {1, -1}, {-1, -1}}; |
82 |
|
|
INT index; |
83 |
|
|
INT error; |
84 |
|
|
INT yi; |
85 |
|
|
GX_UBYTE alpha1; |
86 |
|
|
GX_UBYTE alpha2; |
87 |
|
|
VOID (*blend_func)(GX_DRAW_CONTEXT *context, |
88 |
|
|
INT x, INT y, GX_COLOR color, GX_UBYTE alpha); |
89 |
|
|
|
90 |
|
|
#if defined(GX_BRUSH_ALPHA_SUPPORT) |
91 |
|
|
GX_UBYTE brush_alpha; |
92 |
|
|
|
93 |
|
306 |
brush_alpha = context -> gx_draw_context_brush.gx_brush_alpha; |
94 |
|
|
|
95 |
✓✓ |
306 |
if (brush_alpha == 0) |
96 |
|
|
{ |
97 |
|
|
/* Nothing to draw here. */ |
98 |
|
85 |
return; |
99 |
|
|
} |
100 |
|
|
#endif |
101 |
|
|
|
102 |
|
222 |
display = context -> gx_draw_context_display; |
103 |
|
222 |
clip = context -> gx_draw_context_clip; |
104 |
|
222 |
brush = &context -> gx_draw_context_brush; |
105 |
|
|
|
106 |
|
222 |
blend_func = display -> gx_display_driver_pixel_blend; |
107 |
|
|
|
108 |
✓✓ |
222 |
if (blend_func == GX_NULL) |
109 |
|
|
{ |
110 |
|
1 |
return; |
111 |
|
|
} |
112 |
|
|
|
113 |
|
221 |
x = 0; |
114 |
|
221 |
y = (INT)r; |
115 |
|
221 |
error = 0; |
116 |
|
|
|
117 |
✓✓ |
21140 |
while (x < y) |
118 |
|
|
{ |
119 |
|
20919 |
alpha1 = (GX_UBYTE)(255 - error); |
120 |
|
20919 |
alpha2 = (GX_UBYTE)error; |
121 |
|
|
#if defined(GX_BRUSH_ALPHA_SUPPORT) |
122 |
|
20919 |
alpha1 = (GX_UBYTE)(alpha1 * brush_alpha / 255); |
123 |
|
20919 |
alpha2 = (GX_UBYTE)(alpha2 * brush_alpha / 255); |
124 |
|
|
#endif |
125 |
|
|
|
126 |
✓✓ |
104595 |
for (index = 0; index < 4; index++) |
127 |
|
|
{ |
128 |
|
83676 |
point.gx_point_x = (GX_VALUE)(x * sign[index][0] + xcenter); |
129 |
|
83676 |
point.gx_point_y = (GX_VALUE)(y * sign[index][1] + ycenter); |
130 |
|
|
|
131 |
✓✓ |
83676 |
if (_gx_utility_rectangle_point_detect(clip, point)) |
132 |
|
|
{ |
133 |
|
61872 |
blend_func(context, point.gx_point_x, point.gx_point_y, brush -> gx_brush_line_color, alpha1); |
134 |
|
|
} |
135 |
|
|
|
136 |
|
83676 |
point.gx_point_y = (GX_VALUE)((y - 1) * sign[index][1] + ycenter); |
137 |
|
|
|
138 |
✓✓ |
83676 |
if (_gx_utility_rectangle_point_detect(clip, point)) |
139 |
|
|
{ |
140 |
|
62946 |
blend_func(context, point.gx_point_x, point.gx_point_y, brush -> gx_brush_line_color, alpha2); |
141 |
|
|
} |
142 |
|
|
|
143 |
|
83676 |
point.gx_point_x = (GX_VALUE)(y * sign[index][0] + xcenter); |
144 |
|
83676 |
point.gx_point_y = (GX_VALUE)(x * sign[index][1] + ycenter); |
145 |
|
|
|
146 |
✓✓ |
83676 |
if (_gx_utility_rectangle_point_detect(clip, point)) |
147 |
|
|
{ |
148 |
|
45058 |
blend_func(context, point.gx_point_x, point.gx_point_y, brush -> gx_brush_line_color, alpha1); |
149 |
|
|
} |
150 |
|
|
|
151 |
|
83676 |
point.gx_point_x = (GX_VALUE)((y - 1) * sign[index][0] + xcenter); |
152 |
|
|
|
153 |
✓✓ |
83676 |
if (_gx_utility_rectangle_point_detect(clip, point)) |
154 |
|
|
{ |
155 |
|
45908 |
blend_func(context, point.gx_point_x, point.gx_point_y, brush -> gx_brush_line_color, alpha2); |
156 |
|
|
} |
157 |
|
|
} |
158 |
|
|
|
159 |
|
20919 |
x++; |
160 |
|
|
|
161 |
|
20919 |
yi = (INT)(r * r) - x * x; |
162 |
|
20919 |
error = (y << 8) - (INT)(_gx_utility_math_sqrt((UINT)(yi << 10)) << 3); |
163 |
|
|
|
164 |
✓✓ |
29591 |
while (error >= 255) |
165 |
|
|
{ |
166 |
|
8672 |
error -= 255; |
167 |
|
8672 |
y--; |
168 |
|
|
} |
169 |
|
|
} |
170 |
|
|
|
171 |
|
221 |
alpha1 = (GX_UBYTE)(255 - error); |
172 |
|
|
#if defined(GX_BRUSH_ALPHA_SUPPORT) |
173 |
|
221 |
alpha1 = (GX_UBYTE)(alpha1 * brush_alpha / 255); |
174 |
|
|
#endif |
175 |
|
|
|
176 |
✓✓ |
1105 |
for (index = 0; index < 4; index++) |
177 |
|
|
{ |
178 |
|
884 |
point.gx_point_x = (GX_VALUE)(x * sign[index][0] + xcenter); |
179 |
|
884 |
point.gx_point_y = (GX_VALUE)(y * sign[index][1] + ycenter); |
180 |
|
|
|
181 |
✓✓ |
884 |
if (_gx_utility_rectangle_point_detect(clip, point)) |
182 |
|
|
{ |
183 |
|
870 |
blend_func(context, point.gx_point_x, point.gx_point_y, brush -> gx_brush_line_color, alpha1); |
184 |
|
|
} |
185 |
|
|
} |
186 |
|
|
} |
187 |
|
|
|
188 |
|
|
#endif |
189 |
|
|
|