summaryrefslogtreecommitdiff
path: root/nuttx/graphics/nxglib/nxglib_filltrapezoid.c
diff options
context:
space:
mode:
Diffstat (limited to 'nuttx/graphics/nxglib/nxglib_filltrapezoid.c')
-rw-r--r--nuttx/graphics/nxglib/nxglib_filltrapezoid.c60
1 files changed, 42 insertions, 18 deletions
diff --git a/nuttx/graphics/nxglib/nxglib_filltrapezoid.c b/nuttx/graphics/nxglib/nxglib_filltrapezoid.c
index 2343a4680..a4ea25e51 100644
--- a/nuttx/graphics/nxglib/nxglib_filltrapezoid.c
+++ b/nuttx/graphics/nxglib/nxglib_filltrapezoid.c
@@ -79,20 +79,24 @@
*
* Descripton:
* Fill a trapezoidal region in the framebuffer memory with a fixed color.
- * This is useful for drawing complex shape -- (most) complex shapes can be
- * broken into a set of trapezoids.
+ * Clip the trapezoid to lie within a boundng box. This is useful for
+ * drawing complex shapes that can be broken into a set of trapezoids.
*
****************************************************************************/
-void NXGL_FUNCNAME(nxglib_filltrapezoid,NXGLIB_SUFFIX)
-(FAR struct fb_videoinfo_s *vinfo, FAR struct fb_planeinfo_s *pinfo,
- FAR const struct nxgl_trapezoid_s *trap, nxgl_mxpixel_t color)
+void NXGL_FUNCNAME(nxgl_filltrapezoid,NXGLIB_SUFFIX)(
+ FAR struct fb_planeinfo_s *pinfo,
+ FAR const struct nxgl_trapezoid_s *trap,
+ FAR const struct nxgl_rect_s *bounds,
+ nxgl_mxpixel_t color)
{
unsigned int stride;
ubyte *line;
int nrows;
b16_t x1;
b16_t x2;
+ nxgl_coord_t y1;
+ nxgl_coord_t y2;
b16_t dx1dy;
b16_t dx2dy;
@@ -102,18 +106,38 @@ void NXGL_FUNCNAME(nxglib_filltrapezoid,NXGLIB_SUFFIX)
/* Get the top run position and the number of rows to draw */
- x1 = trap->top.x1;
- x2 = trap->top.x2;
- nrows = trap->bot.y - trap->top.y + 1;
+ x1 = trap->top.x1;
+ x2 = trap->top.x2;
- /* Get the address of the first byte on the first line */
+ /* Calculate the slope of the left and right side of the trapezoid */
- line = pinfo->fbmem + trap->top.y * stride ;
+ dx1dy = b16divi((trap->bot.x1 - x1), nrows);
+ dx2dy = b16divi((trap->bot.x2 - x2), nrows);
- /* Calculate the slope of the left and right side of the trapezoid */
+ /* Perform vertical clipping */
+
+ y1 = trap->top.y;
+ if (y1 < bounds->pt1.y)
+ {
+ int dy = bounds->pt1.y - y1;
+ x1 += dy * dx1dy;
+ x2 += dy * dx2dy;
+ y1 = bounds->pt1.y;
+ }
+
+ y2 = trap->bot.y;
+ if (y2 > bounds->pt2.y)
+ {
+ y2 = bounds->pt2.y;
+ }
+
+ /* Then calculate the number of rows to render */
+
+ nrows = y2 - y1 + 1;
+
+ /* Get the address of the first byte on the first line */
- dx1dy = b16divi((trap->bot.x1 - x1), nrows);
- dx2dy = b16divi((trap->bot.x2 - x2), nrows);
+ line = pinfo->fbmem + y1 * stride ;
/* Then fill the trapezoid line-by-line */
@@ -140,17 +164,17 @@ void NXGL_FUNCNAME(nxglib_filltrapezoid,NXGLIB_SUFFIX)
* always draw at least one pixel.
*/
- if (x1 > x2 || ix2 < 0 || ix1 > vinfo->yres)
+ if (x1 > x2 || ix2 < bounds->pt1.x || ix1 > bounds->pt2.x)
{
- /* Get a clipped copies of the startingand ending X positions. This
+ /* Get a clipped copies of the starting and ending X positions. This
* clipped truncates "down" and gives the quantized pixel holding the
* fractional X position
*/
- ix1 = ngl_clipl(ix1, 0);
- ix2 = ngl_clipr(ix2, vinfo->yres);
+ ix1 = ngl_clipl(ix1, bounds->pt1.x);
+ ix2 = ngl_clipr(ix2, bounds->pt2.x);
- /* Then draw the run from (line + clipx1) to (line + clipx2) */
+ /* Then draw the run from (line + ix1) to (line + ix2) */
NXGL_MEMSET(line + NXGL_SCALEX(ix1), (NXGL_PIXEL_T)color, ix2 - ix1 + 1);
}