Move the NX components out of libc and into its own library, libnx

This commit is contained in:
Gregory Nutt
2013-12-28 08:40:03 -06:00
parent 090a18f863
commit a457105a0b
76 changed files with 632 additions and 94 deletions
+54
View File
@@ -0,0 +1,54 @@
############################################################################
# libnx/nxglib/Make.defs
#
# Copyright (C) 2013 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in
# the documentation and/or other materials provided with the
# distribution.
# 3. Neither the name NuttX nor the names of its contributors may be
# used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
# COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
# BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
# OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
# AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
# ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
#
############################################################################
# Expose NXGL interfaces to applications
ifeq ($(CONFIG_NX),y)
CSRCS += nxglib_circlepts.c nxglib_circletraps.c nxglib_colorcopy.c
CSRCS += nxglib_intersecting.c nxglib_nonintersecting.c nxglib_nullrect.c
CSRCS += nxglib_rectadd.c nxglib_rectcopy.c nxglib_rectinside.c
CSRCS += nxglib_rectintersect.c nxglib_rectoffset.c nxglib_rectoverlap.c
CSRCS += nxglib_rectsize.c nxglib_rectunion.c nxglib_rgb2yuv.c
CSRCS += nxglib_runcopy.c nxglib_runoffset.c nxglib_splitline.c
CSRCS += nxglib_trapcopy.c nxglib_trapoffset.c nxglib_vectoradd.c
CSRCS += nxglib_vectsubtract.c nxglib_yuv2rgb.c
# Add the nxglib/ directory to the build
DEPPATH += --dep-path nxglib
VPATH += :nxglib
endif
+171
View File
@@ -0,0 +1,171 @@
/****************************************************************************
* graphics/nxglib/nxglib_circlepts.c
*
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <string.h>
#include <errno.h>
#include <fixedmath.h>
#include <nuttx/nx/nxglib.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/* Trigonometry */
#define SIN_0p0 0 /* sin(0) = 0 */
#define COS_0p0 1 /* cos(0) = 1 */
#define SIN_22p5 25080 /* sin(22.5) = 25080 / 65536 */
#define COS_22p5 60547 /* cos(22.5) = 60547 / 65536 */
#define SIN_45p0 46341 /* sin(45) = 46341 / 65536 */
#define COS_45p0 SIN_45p0 /* cos(45) = sin(45) */
/* Named indices into the 16 circle points generated by nxgl_circlepts */
#define POINT_0p0 0
#define POINT_22p5 1
#define POINT_45p0 2
#define POINT_67p5 3
#define POINT_90p0 4
#define POINT_112p5 5
#define POINT_135p0 6
#define POINT_157p5 7
#define POINT_180p0 8
#define POINT_202p5 9
#define POINT_225p0 10
#define POINT_247p5 11
#define POINT_270p0 12
#define POINT_292p5 13
#define POINT_315p0 14
#define POINT_337p5 15
#define NCIRCLE_POINTS 16
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxgl_circlepts
*
* Description:
* Given a description of a circle, return a set of 16 points on the
* circumference of the circle. These points may then be used by
* nx_drawcircle() or related APIs to draw a circle outline.
*
* Input parameters:
* center - A pointer to the point that is the center of the circle
* radius - The radius of the circle in pixels.
* circle - A pointer the first entry in an array of 16 points where the
* circle points will be returned.
*
* Returned value:
* None
*
****************************************************************************/
void nxgl_circlepts(FAR const struct nxgl_point_s *center, nxgl_coord_t radius,
FAR struct nxgl_point_s *circle)
{
nxgl_coord_t xoffs;
nxgl_coord_t yoffs;
/* 0, 90, 180, and 270 degrees are the easiest */
circle[POINT_0p0].x = center->x + radius;
circle[POINT_0p0].y = center->y;
circle[POINT_90p0].x = center->x;
circle[POINT_90p0].y = center->y + radius;
circle[POINT_180p0].x = center->x - radius;
circle[POINT_180p0].y = center->y;
circle[POINT_270p0].x = center->x;
circle[POINT_270p0].y = center->y - radius;
/* Now 22.5, 67.5, 112.5, 157.5, 202.5, 247.5, 292.5, and 337.5 */
xoffs = b16toi(b16muli(COS_22p5, radius) + b16HALF);
yoffs = b16toi(b16muli(SIN_22p5, radius) + b16HALF);
circle[POINT_22p5].x = center->x + xoffs;
circle[POINT_22p5].y = center->y + yoffs;
circle[POINT_157p5].x = center->x - xoffs;
circle[POINT_157p5].y = center->y + yoffs;
circle[POINT_202p5].x = center->x - xoffs;
circle[POINT_202p5].y = center->y - yoffs;
circle[POINT_337p5].x = center->x + xoffs;
circle[POINT_337p5].y = center->y - yoffs;
circle[POINT_67p5].x = center->x + yoffs;
circle[POINT_67p5].y = center->y + xoffs;
circle[POINT_112p5].x = center->x - yoffs;
circle[POINT_112p5].y = center->y + xoffs;
circle[POINT_247p5].x = center->x - yoffs;
circle[POINT_247p5].y = center->y - xoffs;
circle[POINT_292p5].x = center->x + yoffs;
circle[POINT_292p5].y = center->y - xoffs;
/* Finally, 45.0, 135.0, 225.0, 315.0 */
xoffs = b16toi(b16muli(COS_45p0, radius) + b16HALF);
circle[POINT_45p0].x = center->x + xoffs;
circle[POINT_45p0].y = center->y + xoffs;
circle[POINT_135p0].x = center->x - xoffs;
circle[POINT_135p0].y = center->y + xoffs;
circle[POINT_225p0].x = center->x - xoffs;
circle[POINT_225p0].y = center->y - xoffs;
circle[POINT_315p0].x = center->x + xoffs;
circle[POINT_315p0].y = center->y - xoffs;
}
+176
View File
@@ -0,0 +1,176 @@
/****************************************************************************
* graphics/nxglib/nxglib_circletraps.c
*
* Copyright (C) 2011 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <string.h>
#include <errno.h>
#include <fixedmath.h>
#include <nuttx/nx/nxglib.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/* Trigonometry */
#define SIN_0p0 0 /* sin(0) = 0 */
#define COS_0p0 1 /* cos(0) = 1 */
#define SIN_22p5 25080 /* sin(22.5) = 25080 / 65536 */
#define COS_22p5 60547 /* cos(22.5) = 60547 / 65536 */
#define SIN_45p0 46341 /* sin(45) = 46341 / 65536 */
#define COS_45p0 SIN_45p0 /* cos(45) = sin(45) */
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxgl_circletraps
*
* Description:
* Given a description of a a circle, return 8 trapezoids that can be
* used to fill the circle by nx_fillcircle() and other interfaces.
*
* Input parameters:
* center - A pointer to the point that is the center of the circle
* radius - The radius of the circle in pixels.
* circle - A pointer the first entry in an array of 8 trapezoids where
* the circle description will be returned.
*
* Returned value:
* None
*
****************************************************************************/
void nxgl_circletraps(FAR const struct nxgl_point_s *center, nxgl_coord_t radius,
FAR struct nxgl_trapezoid_s *circle)
{
nxgl_coord_t xoffs;
nxgl_coord_t yoffs;
circle[0].top.x1 = itob16(center->x);
circle[0].top.x2 = circle[0].top.x1;
circle[0].top.y = center->y - radius;
circle[7].bot.x1 = circle[0].top.x1;
circle[7].bot.x2 = circle[0].top.x1;
circle[7].bot.y = center->y + radius;
circle[3].bot.x1 = itob16(center->x - radius);
circle[3].bot.x2 = itob16(center->x + radius);
circle[3].bot.y = center->y;
circle[4].top.x1 = circle[3].bot.x1;
circle[4].top.x2 = circle[3].bot.x2;
circle[4].top.y = circle[3].bot.y;
/* Now 22.5, 67.5, 112.5, 157.5, 202.5, 247.5, 292.5, and 337.5 */
xoffs = b16toi(b16muli(COS_22p5, radius) + b16HALF);
yoffs = b16toi(b16muli(SIN_22p5, radius) + b16HALF);
circle[2].bot.x1 = itob16(center->x - xoffs);
circle[2].bot.x2 = itob16(center->x + xoffs);
circle[2].bot.y = center->y - yoffs;
circle[3].top.x1 = circle[2].bot.x1;
circle[3].top.x2 = circle[2].bot.x2;
circle[3].top.y = circle[2].bot.y;
circle[4].bot.x1 = circle[2].bot.x1;
circle[4].bot.x2 = circle[2].bot.x2;
circle[4].bot.y = center->y + yoffs;
circle[5].top.x1 = circle[4].bot.x1;
circle[5].top.x2 = circle[4].bot.x2;
circle[5].top.y = circle[4].bot.y;
circle[0].bot.x1 = itob16(center->x - yoffs);
circle[0].bot.x2 = itob16(center->x + yoffs);
circle[0].bot.y = center->y - xoffs;
circle[1].top.x1 = circle[0].bot.x1;
circle[1].top.x2 = circle[0].bot.x2;
circle[1].top.y = circle[0].bot.y;
circle[6].bot.x1 = circle[1].top.x1;
circle[6].bot.x2 = circle[1].top.x2;
circle[6].bot.y = center->y + xoffs;
circle[7].top.x1 = circle[6].bot.x1;
circle[7].top.x2 = circle[6].bot.x2;
circle[7].top.y = circle[6].bot.y;
/* Finally, 45.0, 135.0, 225.0, 315.0 */
xoffs = b16toi(b16muli(COS_45p0, radius) + b16HALF);
circle[1].bot.x1 = itob16(center->x - xoffs);
circle[1].bot.x2 = itob16(center->x + xoffs);
circle[1].bot.y = center->y - xoffs;
circle[2].top.x1 = circle[1].bot.x1;
circle[2].top.x2 = circle[1].bot.x2;
circle[2].top.y = circle[1].bot.y;
circle[5].bot.x1 = circle[1].bot.x1;
circle[5].bot.x2 = circle[1].bot.x2;
circle[5].bot.y = center->y + xoffs;
circle[6].top.x1 = circle[5].bot.x1;
circle[6].top.x2 = circle[5].bot.x2;
circle[6].top.y = circle[5].bot.y;
}
+87
View File
@@ -0,0 +1,87 @@
/****************************************************************************
* libnx/nxglib/nxglib_colorcopy.c
*
* Copyright (C) 2008-2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/nx/nxglib.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxgl_colorcopy
*
* Description:
* This is essentially memcpy for colors. This does very little for us
* other than hide all of the conditional compilation for planar colors
* in one place.
*
****************************************************************************/
void nxgl_colorcopy(nxgl_mxpixel_t dest[CONFIG_NX_NPLANES],
const nxgl_mxpixel_t src[CONFIG_NX_NPLANES])
{
int i;
for (i = 0; i < CONFIG_NX_NPLANES; i++)
{
dest[i] = src[i];
}
}
+83
View File
@@ -0,0 +1,83 @@
/****************************************************************************
* libnx/nxglib/nxglib_intersecting.c
*
* Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdbool.h>
#include <nuttx/nx/nxglib.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxgl_intersecting
*
* Description:
* Return true if the rectangles intersect.
*
****************************************************************************/
bool nxgl_intersecting(FAR const struct nxgl_rect_s *rect1,
FAR const struct nxgl_rect_s *rect2)
{
return ((rect1->pt2.x > rect2->pt1.x) && (rect1->pt2.y > rect2->pt1.y) &&
(rect1->pt1.x < rect2->pt2.x) && (rect1->pt1.y < rect2->pt1.y));
}
+149
View File
@@ -0,0 +1,149 @@
/****************************************************************************
* libnx/nxglib/nxglib_rectnonintersecting.c
*
* Copyright (C) 2008-2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/nx/nxglib.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxgl_nonintersecting
*
* Description:
* Return the regions of rectangle rect 1 that do not intersect with
* rect2. This may be up to founr rectangles some of which may be
* degenerate (and can be picked off with nxgl_nullrect)
*
****************************************************************************/
void nxgl_nonintersecting(FAR struct nxgl_rect_s result[4],
FAR const struct nxgl_rect_s *rect1,
FAR const struct nxgl_rect_s *rect2)
{
struct nxgl_rect_s intersection;
/* Get the intersection of the two rectangles */
nxgl_rectintersect(&intersection, rect1, rect2);
/* Then return the four rectangles representing the regions NON included
* in the intersection. Some of these rectangles may be invalid (zero
* area), but those can be picked off using nxgl_nullrect()
*
* rect1.pt1
* +-------------------------+
* | rect2.pt1 |
* | int.pt1 |
* | +-------------------------+
* | | | |
* | | | |
* +-------------------------+ |
* | rect1.pt2 |
* | int.pt2 |
* +-------------------------+
* rect2.pt2
* rect1.pt1
* +-------------------------+
* rect2.pt1 |int.pt1 |
* +---------+---------------+ |
* | | | |
* | | | |
* | | |int.pt2 |
* | +---------------+---------+
* | | rect1.pt2
* +-------------------------+
* rect2.pt2
* rect2.pt1
* +-------------------------+
* | rect1.pt1 |
* | int.pt1 |
* | +-------------------------+
* | | | |
* | | | |
* | | | |
* +---------+---------------+ |
* | rect2.pt2 |
* | int.pt2 |
* +-------------------------+
* rect1.pt2
*/
result[NX_TOP_NDX].pt1.x = rect1->pt1.x;
result[NX_TOP_NDX].pt1.y = rect1->pt1.y;
result[NX_TOP_NDX].pt2.x = rect1->pt2.x;
result[NX_TOP_NDX].pt2.y = intersection.pt1.y - 1;
result[NX_BOTTOM_NDX].pt1.x = rect1->pt1.x;
result[NX_BOTTOM_NDX].pt1.y = intersection.pt2.y + 1;
result[NX_BOTTOM_NDX].pt2.x = rect1->pt2.x;
result[NX_BOTTOM_NDX].pt2.y = rect1->pt2.y;
result[NX_LEFT_NDX].pt1.x = rect1->pt1.x;
result[NX_LEFT_NDX].pt1.y = intersection.pt1.y;
result[NX_LEFT_NDX].pt2.x = intersection.pt1.x - 1;
result[NX_LEFT_NDX].pt2.y = intersection.pt2.y;
result[NX_RIGHT_NDX].pt1.x = intersection.pt2.x + 1;
result[NX_RIGHT_NDX].pt1.y = intersection.pt1.y;
result[NX_RIGHT_NDX].pt2.x = rect1->pt2.x;
result[NX_RIGHT_NDX].pt2.y = intersection.pt2.y;
}
+81
View File
@@ -0,0 +1,81 @@
/****************************************************************************
* libnx/nxglib/nxglib_nullrect.c
*
* Copyright (C) 2008-2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdbool.h>
#include <nuttx/nx/nxglib.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxgl_nullrect
*
* Description:
* Return true if the area of the retangle is <= 0.
*
****************************************************************************/
bool nxgl_nullrect(FAR const struct nxgl_rect_s *rect)
{
return (rect->pt1.x > rect->pt2.x || rect->pt1.y > rect->pt2.y);
}
+84
View File
@@ -0,0 +1,84 @@
/****************************************************************************
* libnx/nxglib/nxglib_rectadd.c
*
* Copyright (C) 2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/nx/nxglib.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxgl_rectadd
*
* Description:
* Return the rectangle that contains exactly two other rectanges.
*
****************************************************************************/
void nxgl_rectadd(FAR struct nxgl_rect_s *dest,
FAR const struct nxgl_rect_s *src1,
FAR const struct nxgl_rect_s *src2)
{
dest->pt1.x = ngl_min(src1->pt1.x, src2->pt1.x);
dest->pt1.y = ngl_min(src1->pt1.y, src2->pt1.y);
dest->pt2.x = ngl_max(src1->pt2.x, src2->pt2.x);
dest->pt2.y = ngl_max(src1->pt2.y, src2->pt2.y);
}
+84
View File
@@ -0,0 +1,84 @@
/****************************************************************************
* libnx/nxglib/nxglib_rectcopy.c
*
* Copyright (C) 2008-2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/nx/nxglib.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxgl_rectcopy
*
* Description:
* This is essentially memcpy for rectangles. We don't do structure
* assignments because some compilers are not good at that.
*
****************************************************************************/
void nxgl_rectcopy(FAR struct nxgl_rect_s *dest,
FAR const struct nxgl_rect_s *src)
{
dest->pt1.x = src->pt1.x;
dest->pt1.y = src->pt1.y;
dest->pt2.x = src->pt2.x;
dest->pt2.y = src->pt2.y;
}
+83
View File
@@ -0,0 +1,83 @@
/****************************************************************************
* libnx/nxglib/nxglib_rectinside.c
*
* Copyright (C) 2008-2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdbool.h>
#include <nuttx/nx/nxglib.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxgl_rectinside
*
* Description:
* Return true if the point pt lies within rect.
*
****************************************************************************/
bool nxgl_rectinside(FAR const struct nxgl_rect_s *rect,
FAR const struct nxgl_point_s *pt)
{
return (pt->x >= rect->pt1.x && pt->x <= rect->pt2.x &&
pt->y >= rect->pt1.y && pt->y <= rect->pt2.y);
}
+84
View File
@@ -0,0 +1,84 @@
/****************************************************************************
* libnx/nxglib/nxglib_rectintersect.c
*
* Copyright (C) 2008-2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/nx/nxglib.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxgl_rectintersect
*
* Description:
* Return the rectangle representing the intersection of the two rectangles.
*
****************************************************************************/
void nxgl_rectintersect(FAR struct nxgl_rect_s *dest,
FAR const struct nxgl_rect_s *src1,
FAR const struct nxgl_rect_s *src2)
{
dest->pt1.x = ngl_max(src1->pt1.x, src2->pt1.x);
dest->pt1.y = ngl_max(src1->pt1.y, src2->pt1.y);
dest->pt2.x = ngl_min(src1->pt2.x, src2->pt2.x);
dest->pt2.y = ngl_min(src1->pt2.y, src2->pt2.y);
}
+84
View File
@@ -0,0 +1,84 @@
/****************************************************************************
* lbic/nxglib/nxglib_rectoffset.c
*
* Copyright (C) 2008-2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/nx/nxglib.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxgl_rectoffset
*
* Description:
* Offset the rectangle position by the specified dx, dy values.
*
****************************************************************************/
void nxgl_rectoffset(FAR struct nxgl_rect_s *dest,
FAR const struct nxgl_rect_s *src,
nxgl_coord_t dx, nxgl_coord_t dy)
{
dest->pt1.x = src->pt1.x + dx;
dest->pt1.y = src->pt1.y + dy;
dest->pt2.x = src->pt2.x + dx;
dest->pt2.y = src->pt2.y + dy;
}
+89
View File
@@ -0,0 +1,89 @@
/****************************************************************************
* libnx/nxglib/nxglib_nulloverlap.c
*
* Copyright (C) 2008-2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdbool.h>
#include <nuttx/nx/nxglib.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxgl_rectoverlap
*
* Description:
* Return true if the two rectangles overlap
*
****************************************************************************/
bool nxgl_rectoverlap(FAR struct nxgl_rect_s *rect1,
FAR struct nxgl_rect_s *rect2)
{
/* The neither is wholly above, below, right, or left of the other, then
* the two rectangles overlap in some fashion.
*/
return (rect1->pt1.x <= rect2->pt2.x) && /* false: rect1 is wholly to the right */
(rect2->pt1.x <= rect1->pt2.x) && /* false: rect2 is wholly to the right */
(rect1->pt1.y <= rect2->pt2.y) && /* false: rect1 is wholly below rect2 */
(rect2->pt1.y <= rect1->pt2.y); /* false: rect2 is wholly below rect1 */
}
+81
View File
@@ -0,0 +1,81 @@
/****************************************************************************
* libnx/nxglib/nxglib_rectsize.c
*
* Copyright (C) 2008-2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/nx/nxglib.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxgl_rectsize
*
* Description:
* Return the size of the specified rectangle.
*
****************************************************************************/
void nxgl_rectsize(FAR struct nxgl_size_s *size,
FAR const struct nxgl_rect_s *rect)
{
size->w = rect->pt2.x - rect->pt1.x + 1;
size->h = rect->pt2.y - rect->pt1.y + 1;
}
+85
View File
@@ -0,0 +1,85 @@
/****************************************************************************
* libnx/nxglib/nxglib_rectunion.c
*
* Copyright (C) 2008-2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/nx/nxglib.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxgl_rectunion
*
* Description:
* Given two rectanges, src1 and src2, return the larger rectangle that
* contains both, dest.
*
****************************************************************************/
void nxgl_rectunion(FAR struct nxgl_rect_s *dest,
FAR const struct nxgl_rect_s *src1,
FAR const struct nxgl_rect_s *src2)
{
dest->pt1.x = ngl_min(src1->pt1.x, src2->pt1.x);
dest->pt1.y = ngl_min(src1->pt1.y, src2->pt1.y);
dest->pt2.x = ngl_max(src1->pt2.x, src2->pt2.x);
dest->pt2.y = ngl_max(src1->pt2.y, src2->pt2.y);
}
+103
View File
@@ -0,0 +1,103 @@
/****************************************************************************
* libnx/nxglib/nxglib_rgb2yuv.c
*
* Copyright (C) 2008, 2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <debug.h>
#include <fixedmath.h>
#include <nuttx/nx/nxglib.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
#define b16_P0813 0x000014d0 /* 0.0813 */
#define b16_P1140 0x00001d2f /* 0.1140 */
#define b16_P1687 0x00002b30 /* 0.1687 */
#define b16_P2990 0x00004c8b /* 0.2990 */
#define b16_P3313 0x000054d0 /* 0.3313 */
#define b16_P4187 0x00006b30 /* 0.4187 */
#define b16_P5000 0x00008000 /* 0.5000 */
#define b16_P5870 0x00009646 /* 0.5870 */
#define b16_128P0 0x00800000 /* 128.0 */
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxgl_rgb2yuv
*
* Description:
* Convert 8-bit RGB triplet to 8-bit YUV triplet
*
****************************************************************************/
void nxgl_rgb2yuv(uint8_t r, uint8_t g, uint8_t b,
uint8_t *y, uint8_t *u, uint8_t *v)
{
/* Per the JFIF specification:
*
* Y = (0.2990 * R) + (0.5870 * G) + (0.1140 * B)
* U = 128 - (0.1687 * R) - (0.3313 * G) + (0.5000 * B)
* V = 128 + (0.5000 * R) - (0.4187 * G) - (0.0813 * B);
*/
*y = (uint8_t)b16toi(b16muli(b16_P2990, r) + b16muli(b16_P5870, g) + b16muli(b16_P1140, b));
*u = (uint8_t)b16toi(b16_128P0 - b16muli(b16_P1687, r) - b16muli(b16_P3313, g) + b16muli(b16_P5000, b));
*v = (uint8_t)b16toi(b16_128P0 + b16muli(b16_P5000, r) - b16muli(b16_P4187, g) - b16muli(b16_P0813, b));
}
+82
View File
@@ -0,0 +1,82 @@
/****************************************************************************
* libnx/nxglib/nxglib_runcopy.c
*
* Copyright (C) 2008-2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/nx/nxglib.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxgl_runcopy
*
* Description:
* This is essentially memcpy for runs. We don't do structure assignments
* because some compilers are not good at that.
*
****************************************************************************/
void nxgl_runcopy(FAR struct nxgl_run_s *dest, FAR const struct nxgl_run_s *src)
{
dest->x1 = src->x1;
dest->x2 = src->x2;
dest->y = src->y;
}
+85
View File
@@ -0,0 +1,85 @@
/****************************************************************************
* libnx/nxglib/nxglib_runoffset.c
*
* Copyright (C) 2008-2009, 2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <fixedmath.h>
#include <nuttx/nx/nxglib.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxgl_runoffset
*
* Description:
* Offset the run position by the specified (integer) dx, dy values.
*
****************************************************************************/
void nxgl_runoffset(FAR struct nxgl_run_s *dest,
FAR const struct nxgl_run_s *src,
nxgl_coord_t dx, nxgl_coord_t dy)
{
b16_t b16dx = itob16(dx);
dest->x1 = src->x1 + b16dx;
dest->x2 = src->x2 + b16dx;
dest->y = src->y + dy;
}
File diff suppressed because it is too large Load Diff
+82
View File
@@ -0,0 +1,82 @@
/****************************************************************************
* libnx/nxglib/nxglib_trapcopy.c
*
* Copyright (C) 2008-2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/nx/nxglib.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxgl_trapcopy
*
* Description:
* This is essentially memcpy for trapezoids. We don't do structure
* assignments because some compilers are not good at that.
*
****************************************************************************/
void nxgl_trapcopy(FAR struct nxgl_trapezoid_s *dest,
FAR const struct nxgl_trapezoid_s *src)
{
nxgl_runcopy(&dest->top, &src->top);
nxgl_runcopy(&dest->bot, &src->bot);
}
+82
View File
@@ -0,0 +1,82 @@
/****************************************************************************
* libnx/nxglib/nxglib_trapoffset.c
*
* Copyright (C) 2008-2009, 2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/nx/nxglib.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxgl_trapoffset
*
* Description:
* Offset the trapezoid position by the specified dx, dy values.
*
****************************************************************************/
void nxgl_trapoffset(FAR struct nxgl_trapezoid_s *dest,
FAR const struct nxgl_trapezoid_s *src,
nxgl_coord_t dx, nxgl_coord_t dy)
{
nxgl_runoffset(&dest->top, &src->top, dx, dy);
nxgl_runoffset(&dest->bot, &src->bot, dx, dy);
}
+82
View File
@@ -0,0 +1,82 @@
/****************************************************************************
* libnx/nxglib/nxglib_vectoradd.c
*
* Copyright (C) 2008-2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/nx/nxglib.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxgl_vectoradd
*
* Description:
* Add two 2x1 vectors and save the result to a third.
*
****************************************************************************/
void nxgl_vectoradd(FAR struct nxgl_point_s *dest,
FAR const struct nxgl_point_s *v1,
FAR const struct nxgl_point_s *v2)
{
dest->x = v1->x + v2->x;
dest->y = v1->y + v2->y;
}
+82
View File
@@ -0,0 +1,82 @@
/****************************************************************************
* libnx/nxglib/nxglib_vectorsubtract.c
*
* Copyright (C) 2008-2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <nuttx/nx/nxglib.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Public Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxgl_vectsubtract
*
* Description:
* Add subtract vector v2 from vector v1 and return the result in vector dest
*
****************************************************************************/
void nxgl_vectsubtract(FAR struct nxgl_point_s *dest,
FAR const struct nxgl_point_s *v1,
FAR const struct nxgl_point_s *v2)
{
dest->x = v1->x - v2->x;
dest->y = v1->y - v2->y;
}
+102
View File
@@ -0,0 +1,102 @@
/****************************************************************************
* libnx/nxglib/nxglib_yuv2rgb.c
*
* Copyright (C) 2008-2009, 2011, 2013 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <debug.h>
#include <fixedmath.h>
#include <nuttx/nx/nxglib.h>
/****************************************************************************
* Pre-Processor Definitions
****************************************************************************/
#define b16_P3441 0x0000581a /* 0.344147 */
#define b16_P7141 0x0000b6d2 /* 0.714142 */
#define b16_1P402 0x000166ea /* 1.402008 */
#define b16_1P772 0x0001c5a2 /* 1.722003 */
#define b16_128P0 0x00800000 /* 128.000000 */
/****************************************************************************
* Private Types
****************************************************************************/
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
/****************************************************************************
* Private Data
****************************************************************************/
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: nxgl_yuv2rgb
*
* Description:
* Convert 8-bit RGB triplet to 8-bit YUV triplet
*
****************************************************************************/
void nxgl_yuv2rgb(uint8_t y, uint8_t u, uint8_t v,
uint8_t *r, uint8_t *g, uint8_t *b)
{
b16_t vm128 = itob16(v) - b16_128P0;
b16_t um128 = itob16(u) - b16_128P0;
/* Per the JFIF specification:
*
* R = Y + 1.40200 * (V - 128.0)
* G = Y - 0.34414 * (U - 128.0) - 0.71414 * (V - 128.0)
* B = Y + 1.77200 * (U - 128.0)
*/
*r = (uint8_t)b16toi(itob16(y) + b16muli(b16_1P402, vm128));
*g = (uint8_t)b16toi(itob16(y) - b16muli(b16_P3441, um128) - b16muli(b16_P7141, vm128));
*b = (uint8_t)b16toi(itob16(y) + b16muli(b16_1P772, um128));
}