2008-11-26 18:58:31 +01:00
|
|
|
/****************************************************************************
|
2010-04-17 03:46:15 +02:00
|
|
|
* graphics/nxglib/fb/nxglib_fillrectangle.c
|
2008-11-26 18:58:31 +01:00
|
|
|
*
|
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
|
2008-11-26 18:58:31 +01:00
|
|
|
*
|
2021-02-05 11:12:53 +01:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2008-11-26 18:58:31 +01: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.
|
2008-11-26 18:58:31 +01:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
2009-12-15 19:12:29 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2013-12-10 16:23:54 +01:00
|
|
|
#include <nuttx/video/fb.h>
|
2011-07-24 22:49:01 +02:00
|
|
|
#include <nuttx/nx/nxglib.h>
|
2008-11-26 18:58:31 +01:00
|
|
|
|
|
|
|
#include "nxglib_bitblit.h"
|
|
|
|
|
|
|
|
/****************************************************************************
|
2015-04-08 16:32:05 +02:00
|
|
|
* Pre-processor Definitions
|
2008-11-26 18:58:31 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef NXGLIB_SUFFIX
|
|
|
|
# error "NXGLIB_SUFFIX must be defined before including this header file"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2008-11-26 20:39:54 +01:00
|
|
|
* Name: nxgl_fillrectangle_*bpp
|
2008-11-26 18:58:31 +01:00
|
|
|
*
|
2018-02-01 19:03:55 +01:00
|
|
|
* Description:
|
2008-11-26 18:58:31 +01:00
|
|
|
* Fill a rectangle region in the framebuffer memory with a fixed color
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2015-10-08 17:10:22 +02:00
|
|
|
void NXGL_FUNCNAME(nxgl_fillrectangle, NXGLIB_SUFFIX)
|
2021-02-05 09:05:48 +01:00
|
|
|
(
|
|
|
|
FAR struct fb_planeinfo_s *pinfo,
|
|
|
|
FAR const struct nxgl_rect_s *rect,
|
|
|
|
NXGL_PIXEL_T color)
|
2008-11-26 18:58:31 +01:00
|
|
|
{
|
2009-12-15 19:12:29 +01:00
|
|
|
FAR uint8_t *line;
|
2008-11-26 18:58:31 +01:00
|
|
|
unsigned int width;
|
|
|
|
unsigned int stride;
|
2008-12-02 13:41:05 +01:00
|
|
|
int rows;
|
2008-11-28 19:01:10 +01:00
|
|
|
|
|
|
|
#if NXGLIB_BITSPERPIXEL < 8
|
2009-12-15 19:12:29 +01:00
|
|
|
FAR uint8_t *dest;
|
|
|
|
uint8_t mpixel = NXGL_MULTIPIXEL(color);
|
|
|
|
uint8_t leadmask;
|
|
|
|
uint8_t tailmask;
|
|
|
|
uint8_t mask;
|
2008-12-02 13:41:05 +01:00
|
|
|
int lnlen;
|
2008-11-28 19:01:10 +01:00
|
|
|
#endif
|
2008-11-26 18:58:31 +01:00
|
|
|
|
|
|
|
/* Get the width of the framebuffer in bytes */
|
|
|
|
|
|
|
|
stride = pinfo->stride;
|
|
|
|
|
2020-02-23 09:50:23 +01:00
|
|
|
/* Get the dimensions of the rectangle to fill in pixels */
|
2008-11-26 18:58:31 +01:00
|
|
|
|
2008-12-02 21:02:59 +01:00
|
|
|
width = rect->pt2.x - rect->pt1.x + 1;
|
|
|
|
rows = rect->pt2.y - rect->pt1.y + 1;
|
2008-11-26 18:58:31 +01:00
|
|
|
|
|
|
|
/* Get the address of the first byte in the first line to write */
|
|
|
|
|
2008-11-26 20:39:54 +01:00
|
|
|
line = pinfo->fbmem + rect->pt1.y * stride + NXGL_SCALEX(rect->pt1.x);
|
2008-11-26 18:58:31 +01:00
|
|
|
|
2008-11-28 19:01:10 +01:00
|
|
|
#if NXGLIB_BITSPERPIXEL < 8
|
2008-12-05 15:04:37 +01:00
|
|
|
# ifdef CONFIG_NX_PACKEDMSFIRST
|
2008-11-28 19:01:10 +01:00
|
|
|
|
|
|
|
/* Get the mask for pixels that are ordered so that they pack from the
|
|
|
|
* MS byte down.
|
|
|
|
*/
|
|
|
|
|
2009-12-15 19:12:29 +01:00
|
|
|
leadmask = (uint8_t)(0xff >> (8 - NXGL_REMAINDERX(rect->pt1.x)));
|
2021-02-05 09:05:48 +01:00
|
|
|
tailmask = (uint8_t)(0xff << (8 - NXGL_REMAINDERX(rect->pt2.x - 1)));
|
2008-11-28 19:01:10 +01:00
|
|
|
# else
|
|
|
|
/* Get the mask for pixels that are ordered so that they pack from the
|
|
|
|
* LS byte up.
|
|
|
|
*/
|
|
|
|
|
2009-12-15 19:12:29 +01:00
|
|
|
leadmask = (uint8_t)(0xff << (8 - NXGL_REMAINDERX(rect->pt1.x)));
|
2021-02-05 09:05:48 +01:00
|
|
|
tailmask = (uint8_t)(0xff >> (8 - NXGL_REMAINDERX(rect->pt1.x - 1)));
|
2008-11-28 19:01:10 +01:00
|
|
|
# endif
|
|
|
|
#endif
|
|
|
|
|
2008-11-26 18:58:31 +01:00
|
|
|
/* Then fill the rectangle line-by-line */
|
|
|
|
|
2008-11-28 19:01:10 +01:00
|
|
|
while (rows-- > 0)
|
2008-11-26 18:58:31 +01:00
|
|
|
{
|
2008-11-28 19:01:10 +01:00
|
|
|
#if NXGLIB_BITSPERPIXEL < 8
|
2021-02-05 09:05:48 +01:00
|
|
|
/* Handle masking of the fractional initial byte */
|
2008-11-28 19:01:10 +01:00
|
|
|
|
2021-02-05 09:05:48 +01:00
|
|
|
mask = leadmask;
|
|
|
|
dest = line;
|
|
|
|
lnlen = width;
|
2008-11-28 19:01:10 +01:00
|
|
|
|
2021-02-05 09:05:48 +01:00
|
|
|
if (lnlen > 1 && mask)
|
2008-11-28 19:01:10 +01:00
|
|
|
{
|
|
|
|
dest[0] = (dest[0] & ~mask) | (mpixel & mask);
|
|
|
|
mask = 0xff;
|
|
|
|
dest++;
|
|
|
|
lnlen--;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle masking of the fractional final byte */
|
|
|
|
|
|
|
|
mask &= tailmask;
|
|
|
|
if (lnlen > 0 && mask)
|
|
|
|
{
|
2021-02-05 09:05:48 +01:00
|
|
|
dest[lnlen - 1] = (dest[lnlen - 1] & ~mask) | (mpixel & mask);
|
|
|
|
lnlen--;
|
2008-11-28 19:01:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Handle all of the unmasked bytes in-between */
|
|
|
|
|
|
|
|
if (lnlen > 0)
|
|
|
|
{
|
|
|
|
NXGL_MEMSET(dest, (NXGL_PIXEL_T)color, lnlen);
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
/* Draw the entire raster line */
|
|
|
|
|
2008-11-27 00:42:51 +01:00
|
|
|
NXGL_MEMSET(line, (NXGL_PIXEL_T)color, width);
|
2008-11-28 19:01:10 +01:00
|
|
|
#endif
|
2008-11-26 18:58:31 +01:00
|
|
|
line += stride;
|
|
|
|
}
|
|
|
|
}
|