2010-04-17 05:52:05 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* graphics/nxglib/lcd/nxglib_filltrapezoid.c
|
|
|
|
*
|
2021-02-05 11:12:53 +01:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2010-04-17 05:52:05 +02:00
|
|
|
*
|
2021-02-05 11:12:53 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2010-04-17 05:52:05 +02:00
|
|
|
*
|
2021-02-05 11:12:53 +01:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2010-04-17 05:52:05 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <fixedmath.h>
|
|
|
|
|
2010-12-04 02:56:50 +01:00
|
|
|
#include <nuttx/lcd/lcd.h>
|
2011-07-24 22:49:01 +02:00
|
|
|
#include <nuttx/nx/nxglib.h>
|
2010-04-17 05:52:05 +02:00
|
|
|
|
|
|
|
#include "nxglib_bitblit.h"
|
2010-04-17 20:08:39 +02:00
|
|
|
#include "nxglib_fillrun.h"
|
2010-04-17 05:52:05 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
2015-04-08 16:32:05 +02:00
|
|
|
* Pre-processor Definitions
|
2010-04-17 05:52:05 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef NXGLIB_SUFFIX
|
|
|
|
# error "NXGLIB_SUFFIX must be defined before including this header file"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: nxglib_filltrapezoid_*bpp
|
|
|
|
*
|
2018-02-01 19:03:55 +01:00
|
|
|
* Description:
|
2010-04-17 20:59:12 +02:00
|
|
|
* Fill a trapezoidal region in the LCD memory with a fixed color.
|
2010-04-17 05:52:05 +02:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-10-08 17:10:22 +02:00
|
|
|
void NXGL_FUNCNAME(nxgl_filltrapezoid, NXGLIB_SUFFIX)
|
2021-02-05 09:05:48 +01:00
|
|
|
(
|
|
|
|
FAR struct lcd_planeinfo_s *pinfo,
|
|
|
|
FAR const struct nxgl_trapezoid_s *trap,
|
|
|
|
FAR const struct nxgl_rect_s *bounds,
|
|
|
|
NXGL_PIXEL_T color)
|
2010-04-17 05:52:05 +02:00
|
|
|
{
|
2010-04-17 20:08:39 +02:00
|
|
|
unsigned int ncols;
|
|
|
|
unsigned int topy;
|
|
|
|
unsigned int boty;
|
|
|
|
unsigned int row;
|
|
|
|
unsigned int botw;
|
|
|
|
b16_t topx1;
|
|
|
|
b16_t topx2;
|
|
|
|
b16_t botx1;
|
|
|
|
b16_t botx2;
|
|
|
|
b16_t dx1dy;
|
|
|
|
b16_t dx2dy;
|
2011-08-04 03:25:58 +02:00
|
|
|
int dy;
|
2010-04-17 20:08:39 +02:00
|
|
|
int ix1;
|
|
|
|
int ix2;
|
|
|
|
|
|
|
|
/* Get the top run endpoints */
|
|
|
|
|
|
|
|
topx1 = trap->top.x1;
|
|
|
|
topx2 = trap->top.x2;
|
2010-04-17 05:52:05 +02:00
|
|
|
|
2010-04-17 20:08:39 +02:00
|
|
|
/* Calculate the number of rows to render */
|
2010-04-17 05:52:05 +02:00
|
|
|
|
2010-04-17 20:08:39 +02:00
|
|
|
topy = trap->top.y;
|
|
|
|
boty = trap->bot.y;
|
2010-04-17 05:52:05 +02:00
|
|
|
|
2010-04-17 20:08:39 +02:00
|
|
|
/* Get the bottom run endpoints */
|
2010-04-17 05:52:05 +02:00
|
|
|
|
2010-04-17 20:08:39 +02:00
|
|
|
botx1 = trap->bot.x1;
|
|
|
|
botx2 = trap->bot.x2;
|
2010-04-17 05:52:05 +02:00
|
|
|
|
|
|
|
/* Calculate the slope of the left and right side of the trapezoid */
|
|
|
|
|
2012-06-06 20:07:49 +02:00
|
|
|
dy = boty - topy;
|
|
|
|
if (dy > 0)
|
|
|
|
{
|
|
|
|
dx1dy = b16divi((botx1 - topx1), dy);
|
|
|
|
dx2dy = b16divi((botx2 - topx2), dy);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* The trapezoid is a run! Use the average width. */
|
|
|
|
|
|
|
|
topx1 = (topx1 + botx1) >> 1;
|
|
|
|
topx2 = (topx2 + botx2) >> 1;
|
|
|
|
botx1 = topx1;
|
|
|
|
botx2 = topx2;
|
|
|
|
dx1dy = 0;
|
|
|
|
dx2dy = 0;
|
|
|
|
}
|
2010-04-17 05:52:05 +02:00
|
|
|
|
|
|
|
/* Perform vertical clipping */
|
|
|
|
|
2010-04-17 20:08:39 +02:00
|
|
|
if (topy < bounds->pt1.y)
|
2010-04-17 05:52:05 +02:00
|
|
|
{
|
2011-08-03 18:04:48 +02:00
|
|
|
/* Is the entire trapezoid "above" the clipping window? */
|
|
|
|
|
|
|
|
if (boty < bounds->pt1.y)
|
|
|
|
{
|
|
|
|
/* Yes.. then do nothing */
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-17 05:52:05 +02:00
|
|
|
/* Calculate the x values for the new top run */
|
|
|
|
|
2010-04-17 20:08:39 +02:00
|
|
|
dy = bounds->pt1.y - topy;
|
|
|
|
topx1 += dy * dx1dy;
|
|
|
|
topx2 += dy * dx2dy;
|
2010-04-17 05:52:05 +02:00
|
|
|
|
2010-04-17 20:08:39 +02:00
|
|
|
/* Clip the top row to render */
|
2010-04-17 05:52:05 +02:00
|
|
|
|
2010-04-17 20:08:39 +02:00
|
|
|
topy = bounds->pt1.y;
|
2010-04-17 05:52:05 +02:00
|
|
|
}
|
|
|
|
|
2010-04-17 20:08:39 +02:00
|
|
|
if (boty > bounds->pt2.y)
|
2010-04-17 05:52:05 +02:00
|
|
|
{
|
2011-08-03 18:04:48 +02:00
|
|
|
/* Is the entire trapezoid "below" the clipping window? */
|
|
|
|
|
|
|
|
if (topy > bounds->pt2.y)
|
|
|
|
{
|
|
|
|
/* Yes.. then do nothing */
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-04-17 20:08:39 +02:00
|
|
|
/* Calculate the x values for the new bottom run */
|
2010-04-17 05:52:05 +02:00
|
|
|
|
2010-04-17 20:08:39 +02:00
|
|
|
dy = boty - bounds->pt2.y;
|
|
|
|
botx1 -= dy * dx1dy;
|
|
|
|
botx2 -= dy * dx2dy;
|
|
|
|
|
|
|
|
/* Clip the bottom row to render */
|
|
|
|
|
|
|
|
boty = bounds->pt2.y;
|
2010-04-17 05:52:05 +02:00
|
|
|
}
|
|
|
|
|
2010-04-17 20:08:39 +02:00
|
|
|
/* Handle the special case where the sides cross (as in an hourglass) */
|
|
|
|
|
|
|
|
if (botx1 > botx2)
|
|
|
|
{
|
|
|
|
b16_t tmp;
|
|
|
|
ngl_swap(botx1, botx2, tmp);
|
|
|
|
}
|
2010-04-17 05:52:05 +02:00
|
|
|
|
2010-04-17 20:08:39 +02:00
|
|
|
/* Fill the run buffer for the maximum run that we will need */
|
|
|
|
|
2011-08-03 23:49:31 +02:00
|
|
|
ix1 = b16toi(topx1);
|
|
|
|
ix1 = ngl_clipl(ix1, bounds->pt1.x);
|
|
|
|
ix2 = b16toi(topx2);
|
|
|
|
ix2 = ngl_clipr(ix2, bounds->pt2.x);
|
2010-04-17 20:08:39 +02:00
|
|
|
ncols = ix2 - ix1 + 1;
|
|
|
|
|
2011-08-03 23:49:31 +02:00
|
|
|
ix1 = b16toi(botx1);
|
|
|
|
ix1 = ngl_clipl(ix1, bounds->pt1.x);
|
|
|
|
ix2 = b16toi(botx2);
|
|
|
|
ix2 = ngl_clipr(ix2, bounds->pt2.x);
|
2010-04-17 20:08:39 +02:00
|
|
|
botw = ix2 - ix1 + 1;
|
|
|
|
|
|
|
|
if (ncols < botw)
|
2010-04-17 05:52:05 +02:00
|
|
|
{
|
2010-04-17 20:08:39 +02:00
|
|
|
ncols = botw;
|
|
|
|
}
|
2010-04-17 05:52:05 +02:00
|
|
|
|
2021-02-05 09:05:48 +01:00
|
|
|
NXGL_FUNCNAME(nxgl_fillrun, NXGLIB_SUFFIX)((NXGLIB_RUNTYPE *)pinfo->buffer,
|
|
|
|
color,
|
|
|
|
ncols);
|
2010-04-17 20:08:39 +02:00
|
|
|
|
2011-08-03 23:49:31 +02:00
|
|
|
/* Then fill the trapezoid row-by-row */
|
2010-04-17 20:08:39 +02:00
|
|
|
|
|
|
|
for (row = topy; row <= boty; row++)
|
|
|
|
{
|
2010-04-17 05:52:05 +02:00
|
|
|
/* Handle the special case where the sides cross (as in an hourglass) */
|
|
|
|
|
2010-04-17 20:08:39 +02:00
|
|
|
if (topx1 > topx2)
|
2010-04-17 05:52:05 +02:00
|
|
|
{
|
|
|
|
b16_t tmp;
|
2010-04-17 20:08:39 +02:00
|
|
|
ngl_swap(topx1, topx2, tmp);
|
2010-04-17 05:52:05 +02:00
|
|
|
ngl_swap(dx1dy, dx2dy, tmp);
|
|
|
|
}
|
|
|
|
|
2011-08-03 23:49:31 +02:00
|
|
|
/* Convert the positions to integer and get the run width, clipping to
|
|
|
|
* fit within the bounding box.
|
2010-04-17 20:08:39 +02:00
|
|
|
*/
|
2010-04-17 05:52:05 +02:00
|
|
|
|
2011-08-03 23:49:31 +02:00
|
|
|
ix1 = b16toi(topx1);
|
|
|
|
ix1 = ngl_clipl(ix1, bounds->pt1.x);
|
|
|
|
ix2 = b16toi(topx2);
|
|
|
|
ix2 = ngl_clipr(ix2, bounds->pt2.x);
|
2010-04-17 05:52:05 +02:00
|
|
|
|
|
|
|
/* Handle some corner cases where we draw nothing. Otherwise, we will
|
|
|
|
* always draw at least one pixel.
|
|
|
|
*/
|
|
|
|
|
2010-04-17 20:08:39 +02:00
|
|
|
if (ix1 <= ix2)
|
2010-04-17 05:52:05 +02:00
|
|
|
{
|
2010-04-17 20:08:39 +02:00
|
|
|
/* Then draw the run from ix1 to ix2 at row */
|
2010-04-17 05:52:05 +02:00
|
|
|
|
2010-04-17 20:08:39 +02:00
|
|
|
ncols = ix2 - ix1 + 1;
|
2020-01-02 17:49:34 +01:00
|
|
|
pinfo->putrun(row, ix1, pinfo->buffer, ncols);
|
2010-04-17 05:52:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Add the dx/dy value to get the run positions on the next row */
|
|
|
|
|
2010-04-17 20:08:39 +02:00
|
|
|
topx1 += dx1dy;
|
|
|
|
topx2 += dx2dy;
|
2010-04-17 05:52:05 +02:00
|
|
|
}
|
|
|
|
}
|