Skip to content

Commit

Permalink
Release 6.1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
yuxin-azrtos committed Apr 3, 2021
1 parent 6701d07 commit 391dc70
Show file tree
Hide file tree
Showing 288 changed files with 261,275 additions and 391 deletions.
2 changes: 1 addition & 1 deletion common/inc/gx_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ extern "C" {
#define AZURE_RTOS_GUIX
#define GUIX_MAJOR_VERSION 6
#define GUIX_MINOR_VERSION 1
#define GUIX_PATCH_VERSION 5
#define GUIX_PATCH_VERSION 6

/* The following symbols are defined for backward compatibility reasons.*/
#define __PRODUCT_GUIX__
Expand Down
55 changes: 40 additions & 15 deletions common/src/gx_display_driver_generic_ellipse_draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
/* FUNCTION RELEASE */
/* */
/* _gx_display_driver_generic_ellipse_draw PORTABLE C */
/* 6.1 */
/* 6.1.6 */
/* AUTHOR */
/* */
/* Kenneth Maxwell, Microsoft Corporation */
Expand Down Expand Up @@ -74,6 +74,9 @@
/* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */
/* 09-30-2020 Kenneth Maxwell Modified comment(s), */
/* resulting in version 6.1 */
/* 04-02-2021 Kenneth Maxwell Modified comment(s), */
/* improved precision, */
/* resulting in version 6.1.6 */
/* */
/**************************************************************************/
VOID _gx_display_driver_generic_ellipse_draw(GX_DRAW_CONTEXT *context, INT xcenter, INT ycenter, INT a, INT b)
Expand Down Expand Up @@ -110,15 +113,33 @@ GX_UBYTE brush_alpha = brush -> gx_brush_alpha;
}
#endif

/* The ellipse is split into 2 regions, region I with dx > dy and resion II with dx <= dy.
In region I, the midpoint between (x + 1, y) and (x + 1, y - 1) is used to select next point that is closer to the ellipse,
d(x + 1, y - 0.5) is the distance from the midpoint to the ellipse center,
if the decision < 0, the midpoint is inside the ellipse, point (x + 1, y - 1) is closer to the ellipse, and be selected for drawing.
otherwise, (x + 1, y) is selected.
In region II, the midpoint between (x, y - 1) and (x + 1, y - 1) is used to select next point that is closer to the ellipse,
d(x + 0.5, y - 1) is the distance from the midpoint to ellipse center,
if the decision < 0, the midpoint is inside the ellipse, point(x + 1, y - 1) is closer to the ellipse, and be selected for drawing,
otherwise, (x, y - 1) is selected.
Ellipse equation is f(x, y) = sqr(b * x) + sqr(a * y) - sqr(a * b).
First, we assume ellipse is centered at the origin(0, 0), and the first point is (0, b).
Set initial decision value for region I as d = f(1, b - 0.5) = sqr(b) + sqr(a) * (-b + 0.25).
*/

aa = a * a;
bb = b * b;
x = 0;
y = b;
d = (bb << 2) + aa * (1 - (b << 1));

/* Decision is enlarged by 4 to avoid floating point. */
d = (bb << 2) + aa * (1 - (b << 2));

#if defined(GX_BRUSH_ALPHA_SUPPORT)
if (brush_alpha != 0xff)
{

/* Region I of the first quarter of the ellipse. */
while ((bb << 1) * (x + 1) < aa * (2 * y - 1))
{
Expand All @@ -135,17 +156,17 @@ GX_UBYTE brush_alpha = brush -> gx_brush_alpha;

if (d < 0)
{
d += (bb << 1) * ((x << 1) + 3);
d += (bb << 2) * ((x << 1) + 3);
}
else
{
d += (bb << 1) * ((x << 1) + 3) + (aa << 2) * (1 - y);
d += (bb << 2) * ((x << 1) + 3) + (aa << 3) * (1 - y);
y--;
}
x++;
}

d = bb * x * (x + 1) + aa * y * (y - 1) - aa * bb;
d = bb * ((x << 1) + 1) * ((x << 1) + 1) + (aa << 2) * (y - 1) * (y - 1) - (aa << 2) * bb;

/* Region II of the first quarter of the ellipse. */
while (y >= 0)
Expand All @@ -161,16 +182,17 @@ GX_UBYTE brush_alpha = brush -> gx_brush_alpha;
}
}

y--;
if (d < 0)
{
d += (bb << 3) * (x + 1) + (aa << 2) * (3 - (y << 1));
x++;
d += (bb << 1) * (x + 1) - aa * (1 + (y << 1));
}
else
{
d += aa * (-1 - (y << 1));
d += (aa << 2) * (3 - (y << 1));
}

y--;
}
}
else
Expand All @@ -192,17 +214,20 @@ GX_UBYTE brush_alpha = brush -> gx_brush_alpha;

if (d < 0)
{
d += (bb << 1) * ((x << 1) + 3);
d += (bb << 2) * ((x << 1) + 3);
}
else
{
d += (bb << 1) * ((x << 1) + 3) + (aa << 2) * (1 - y);
d += (bb << 2) * ((x << 1) + 3) + (aa << 3) * (1 - y);
y--;
}
x++;
}

d = bb * x * (x + 1) + aa * y * (y - 1) - aa * bb;
/* Set initial decision value for region II as d = f(x + 0.5, y - 1) = sqr(b * (x + 0.5) + sqr(a * (y - 1)) - sqr(a * b).
Enlarge the decision by 4 to avoid float calculation. */

d = bb * ((x << 1) + 1) * ((x << 1) + 1) + (aa << 2) * (y - 1) * (y - 1) - (aa << 2) * bb;

/* Region II of the first quarter of the ellipse. */
while (y >= 0)
Expand All @@ -218,17 +243,17 @@ GX_UBYTE brush_alpha = brush -> gx_brush_alpha;
}
}

y--;

if (d < 0)
{
d += (bb << 3) * (x + 1) + (aa << 2) * (3 - (y << 1));
x++;
d += (bb << 1) * (x + 1) - aa * (1 + (y << 1));
}
else
{
d += aa * (-1 - (y << 1));
d += (aa << 2) * (3 - (y << 1));
}

y--;
}
#if defined(GX_BRUSH_ALPHA_SUPPORT)
}
Expand Down
64 changes: 39 additions & 25 deletions common/src/gx_display_driver_generic_ellipse_fill.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
/* FUNCTION RELEASE */
/* */
/* _gx_display_driver_generic_ellipse_fill PORTABLE C */
/* 6.1 */
/* 6.1.6 */
/* AUTHOR */
/* */
/* Kenneth Maxwell, Microsoft Corporation */
Expand Down Expand Up @@ -78,11 +78,16 @@
/* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */
/* 09-30-2020 Kenneth Maxwell Modified comment(s), */
/* resulting in version 6.1 */
/* 04-02-2021 Kenneth Maxwell Modified comment(s), */
/* modified algorithm to make */
/* it fit one-width antialiaed */
/* ellipse outline, */
/* resulting in version 6.1.6 */
/* */
/**************************************************************************/
VOID _gx_display_driver_generic_ellipse_fill(GX_DRAW_CONTEXT *context, INT xcenter, INT ycenter, INT a, INT b)
{
/* The ellipse fill function follows Bresenham ellipse algorithm while
/* The ellipse fill function follows midpoint ellipse algorithm while
connecting the two point that symmetric with respect to y-axis. */

GX_DISPLAY *display;
Expand All @@ -93,7 +98,6 @@ INT x1;
INT x;
INT y;
INT y1;
INT d;
INT sign[2] = {1, -1};
INT *pLineEnds;
INT index;
Expand All @@ -109,6 +113,8 @@ GX_PIXELMAP *pixelmap = GX_NULL;
GX_VALUE format;
GX_COLOR fill_color;
GX_FILL_PIXELMAP_INFO info;
INT error;
INT realval;


display = context -> gx_draw_context_display;
Expand Down Expand Up @@ -202,11 +208,24 @@ GX_FILL_PIXELMAP_INFO info;
bb = b * b;
x = 0;
y = b;
d = (bb << 2) + aa * (1 - (b << 1));
error = 0;

/* Region I of the first quarter of the ellipse. */
while (2 * bb * (x + 1) < aa * (2 * y - 1))
{
/* calculate error of next pixel. */
realval = bb - bb * (x + 1) * (x + 1) / aa;
error = (y << 8) - (INT)(_gx_utility_math_sqrt((UINT)(realval << 10)) << 3);

if (error >= 510)
{
/* The slope in point(x + 1, y) is greater than -1,
make point(x, y) the delimit pixel, break here. */
realval = bb - bb * x * x / aa;
error = (y << 8) - (INT)(_gx_utility_math_sqrt((UINT)(realval << 10)) << 3);
break;
}

x0 = xcenter - x;
x1 = xcenter + x;

Expand All @@ -222,7 +241,7 @@ GX_FILL_PIXELMAP_INFO info;

for (index = 0; index < 2; index++)
{
y1 = y * sign[index] + ycenter;
y1 = (y - 1) * sign[index] + ycenter;

if ((y1 >= ymin) && (y1 <= ymax))
{
Expand All @@ -232,23 +251,29 @@ GX_FILL_PIXELMAP_INFO info;
}
}

if (d < 0)
if (error >= 255)
{
d += (bb << 1) * ((x << 1) + 3);
}
else
{
d += (bb << 1) * ((x << 1) + 3) + (aa << 2) * (1 - y);
error -= 255;
y--;
}

x++;
}

d = bb * x * (x + 1) + aa * y * (y - 1) - aa * bb;

/* Region II of the first quarter of the ellipse. */
while (y >= 0)
while (y > 0)
{
y--;

realval = aa - aa * y * y / bb;
error = (INT)(_gx_utility_math_sqrt((UINT)(realval << 10)) << 3) - (x << 8);

while (error >= 255)
{
error -= 255;
x++;
}

x0 = xcenter - x;
x1 = xcenter + x;

Expand All @@ -273,17 +298,6 @@ GX_FILL_PIXELMAP_INFO info;
pLineEnds[Index + 1] = x1;
}
}
y--;

if (d < 0)
{
x++;
d += (bb << 1) * (x + 1) - aa * (1 + (y << 1));
}
else
{
d += aa * (-1 - (y << 1));
}
}

Index = 0;
Expand Down
Loading

0 comments on commit 391dc70

Please sign in to comment.