From fa8167b94d13e94a6cb953e7f549a89f155f77c6 Mon Sep 17 00:00:00 2001 From: inmarket Date: Wed, 21 Jan 2015 17:26:24 +1000 Subject: Big file rename to reduce problems with brain-dead IDE's that don't handle project file hierarchies well. Naming is more consistent with the new scheme. May affect some third party drivers (header file renames). --- src/gmisc/gmisc.c | 22 +++ src/gmisc/gmisc.h | 471 +++++++++++++++++++++++++++++++++++++++++++++ src/gmisc/gmisc.mk | 4 + src/gmisc/gmisc_arrayops.c | 8 - src/gmisc/gmisc_gmisc.c | 27 --- src/gmisc/gmisc_matrix2d.c | 4 - src/gmisc/gmisc_options.h | 85 ++++++++ src/gmisc/gmisc_rules.h | 23 +++ src/gmisc/gmisc_trig.c | 8 - src/gmisc/sys_defs.h | 471 --------------------------------------------- src/gmisc/sys_make.mk | 4 - src/gmisc/sys_options.h | 85 -------- src/gmisc/sys_rules.h | 23 --- 13 files changed, 605 insertions(+), 630 deletions(-) create mode 100644 src/gmisc/gmisc.c create mode 100644 src/gmisc/gmisc.h create mode 100644 src/gmisc/gmisc.mk delete mode 100644 src/gmisc/gmisc_gmisc.c create mode 100644 src/gmisc/gmisc_options.h create mode 100644 src/gmisc/gmisc_rules.h delete mode 100644 src/gmisc/sys_defs.h delete mode 100644 src/gmisc/sys_make.mk delete mode 100644 src/gmisc/sys_options.h delete mode 100644 src/gmisc/sys_rules.h (limited to 'src/gmisc') diff --git a/src/gmisc/gmisc.c b/src/gmisc/gmisc.c new file mode 100644 index 00000000..9bcc7bbe --- /dev/null +++ b/src/gmisc/gmisc.c @@ -0,0 +1,22 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +#include "gfx.h" + +#if GFX_USE_GMISC + +void _gmiscInit(void) +{ + +} + +void _gmiscDeinit(void) +{ + +} + +#endif /* GFX_USE_GMISC */ diff --git a/src/gmisc/gmisc.h b/src/gmisc/gmisc.h new file mode 100644 index 00000000..8f858682 --- /dev/null +++ b/src/gmisc/gmisc.h @@ -0,0 +1,471 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file src/gmisc/gmisc.h + * @brief GMISC - Miscellaneous Routines header file. + * + * @addtogroup GMISC + * + * @brief Module which contains different features such as array conversions + * + * @{ + */ + +#ifndef _GMISC_H +#define _GMISC_H + +#include "gfx.h" + +/*===========================================================================*/ +/* Type definitions */ +/*===========================================================================*/ + +// Forward definition +typedef struct point point; + +/** + * @brief Sample data formats + * @note These are defined regardless of whether you use the GMISC module + * or not as they are used in lots of places. + */ +typedef enum ArrayDataFormat_e { + ARRAY_DATA_UNKNOWN = 0, + ARRAY_DATA_4BITUNSIGNED = 4, ARRAY_DATA_4BITSIGNED = 5, + ARRAY_DATA_8BITUNSIGNED = 8, ARRAY_DATA_8BITSIGNED = 9, + ARRAY_DATA_10BITUNSIGNED = 10, ARRAY_DATA_10BITSIGNED = 11, + ARRAY_DATA_12BITUNSIGNED = 12, ARRAY_DATA_12BITSIGNED = 13, + ARRAY_DATA_14BITUNSIGNED = 14, ARRAY_DATA_14BITSIGNED = 15, + ARRAY_DATA_16BITUNSIGNED = 16, ARRAY_DATA_16BITSIGNED = 17, + } ArrayDataFormat; + +/** + * @brief Is the sample data format a "signed" data format? + */ +#define gfxSampleFormatIsSigned(fmt) ((fmt) & 1) + +/** + * @brief How many bits are in the sample data format + */ +#define gfxSampleFormatBits(fmt) ((fmt) & ~1) + +/** + * @brief The type for a fixed point type. + * @details The top 16 bits are the integer component, the bottom 16 bits are the real component. + */ +typedef int32_t fixed; + +/** + * @brief Macros to convert to and from a fixed point. + * @{ + */ +#define FIXED(x) ((fixed)(x)<<16) /* @< integer to fixed */ +#define NONFIXED(x) ((x)>>16) /* @< fixed to integer */ +#define FIXED0_5 32768 /* @< 0.5 as a fixed (used for rounding) */ +#define FP2FIXED(x) ((fixed)((x)*65536.0)) /* @< floating point to fixed */ +#define FIXED2FP(x) ((double)(x)/65536.0) /* @< fixed to floating point */ +#define FIXEDMUL(a,b) ((fixed)((((long long)(a))*(b))>>16)) /* @< fixed,fixed multiplication */ +#define FIXEDMULINT(a,b) ((a)*(b)) /* @< integer,fixed multiplication */ +/** @} */ + +/** + * @brief The famous number pi + */ +#define PI 3.1415926535897932384626433832795028841971693993751 + +/** + * @brief pi as a fixed point + */ +#define FIXED_PI FP2FIXED(PI) + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#if GFX_USE_GMISC || defined(__DOXYGEN__) + +#ifdef __cplusplus +extern "C" { +#endif + +#if GMISC_NEED_ARRAYOPS || defined(__DOXYGEN__) + /** + * @brief Convert from one array format to another array format. + * @pre Requires GFX_USE_GMISC and GMISC_NEED_ARRAYOPS + * + * @param[in] srcfmt The format of the source array + * @param[in] src The source array + * @param[in] dstfmt The format of the destination array + * @param[in] dst The dstination array + * @param[in] cnt The number of array elements to convert + * + * @note Assumes the destination buffer is large enough for the resultant data. + * @note This routine is optimised to perform as fast as possible. + * @note No type checking is performed on the source format. It is assumed to + * have only valid values eg. ARRAY_DATA_4BITSIGNED will have values + * 0000 -> 0111 for positive numbers and 1111 -> 1000 for negative numbers + * Bits 5 -> 8 in the storage byte are treated in an undefined manner. + * @note If srcfmt or dstfmt is an unknown format, this routine does nothing + * with no warning that something is wrong + * + * @api + */ + void gmiscArrayConvert(ArrayDataFormat srcfmt, void *src, ArrayDataFormat dstfmt, void *dst, size_t cnt); + + #if 0 + void gmiscArrayTranslate(ArrayDataFormat fmt, void *src, void *dst, size_t cnt, int trans); + + void gmiscArrayMultiply(ArrayDataFormat fmt, void *src, void *dst, size_t cnt, int mult); + + void gmiscArrayDivide(ArrayDataFormat fmt, void *src, void *dst, size_t cnt, int mdiv); + + void gmiscArrayMultDiv(ArrayDataFormat fmt, void *src, void *dst, size_t cnt, int mult, int div); + + void gmiscArrayAdd(ArrayDataFormat fmt, void *src1, void *src2, void *dst, size_t cnt); + + void gmiscArrayAddNoOverflow(ArrayDataFormat fmt, void *src1, void *src2, void *dst, size_t cnt); + #endif +#endif + +#if GMISC_NEED_FASTTRIG || defined(__DOXYGEN__) + extern const double sintabledouble[]; + + /** + * @brief Fast Table Based Trig functions + * @return A double in the range -1.0 .. 0.0 .. 1.0 + * @pre Requires GFX_USE_GMISC and GMISC_NEED_FASTTRIG + * + * @param[in] degrees The angle in degrees (not radians) + * + * @note These functions use degrees rather than radians to describe the angle. + * + * @api + * @{ + */ + double fsin(int degrees); + double fcos(int degrees); + /** @} + * + * @brief Fast Table Based Trig functions + * @return A double in the range -1.0 .. 0.0 .. 1.0 + * @pre Requires GFX_USE_GMISC and GMISC_NEED_FASTTRIG + * + * @param[in] degrees The angle in degrees 0 .. 359 + * + * @note These functions use degrees rather than radians to describe the angle. + * @note These functions are super fast but require the parameter to be in range. + * Use the lowercase functions if the parameter may not be in range or if a + * required trig function is not supported in this form. + * + * @api + * @{ + */ + #define FSIN(degrees) sintabledouble[degrees]; + /** @} */ +#endif + +#if GMISC_NEED_FIXEDTRIG || defined(__DOXYGEN__) + extern const fixed sintablefixed[]; + + /** + * @brief Fast Table Based Trig functions + * @return A fixed point in the range -1.0 .. 0.0 .. 1.0 + * @pre Requires GFX_USE_GMISC and GMISC_NEED_FIXEDTRIG + * + * @param[in] degrees The angle in degrees (not radians) + * + * @note These functions use degrees rather than radians to describe the angle. + * + * @api + * @{ + */ + fixed ffsin(int degrees); + fixed ffcos(int degrees); + /** @} + * + * @brief Fast Table Based Trig functions + * @return A fixed point in the range -1.0 .. 0.0 .. 1.0 + * @pre Requires GFX_USE_GMISC and GMISC_NEED_FIXEDTRIG + * + * @param[in] degrees The angle in degrees 0 .. 359 + * + * @note These functions use degrees rather than radians to describe the angle. + * @note These functions are super fast but require the parameter to be in range. + * Use the lowercase functions if the parameter may not be in range or if a + * required trig function is not supported in this form. + * + * @api + * @{ + */ + #define FFSIN(degrees) sintablefixed[degrees]; + /** @} */ +#endif + +#if GMISC_NEED_INVSQRT || defined(__DOXYGEN__) + /** + * @brief Fast inverse square root function (x^-1/2) + * @return The approximate inverse square root + * @pre Requires GFX_USE_GMISC and GMISC_NEED_INVSQRT + * + * @param[in] n The number to find the inverse square root of + * + * @note This function generates an approximate result. Higher accuracy (at the expense + * of speed) can be obtained by modifying the source code (the necessary line + * is already there - just commented out). + * @note This function relies on the internal machine format of a float and a long. + * If your machine architecture is very unusual this function may not work. + * + * @api + */ + float invsqrt(float n); +#endif + +#if GMISC_NEED_MATRIXFLOAT2D || defined(__DOXYGEN__) + + /** + * @brief A matrix for doing 2D graphics using floats + * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFLOAT2D + */ + typedef struct MatrixFloat2D { + float a00, a01, a02; + float a10, a11, a12; + float a20, a21, a22; + } MatrixFloat2D; + + /** + * @brief Apply the matrix to a set of points + * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFLOAT2D + * + * @param[in] dst The destination array of points + * @param[in] src The source array of points + * @param[in] m The matrix to apply + * @param[in] cnt How many points are in the array + * + * @note In-place matrix application is allowed ie. dst = src + * + * @api + */ + void gmiscMatrixFloat2DApplyToPoints(point *dst, const point *src, const MatrixFloat2D *m, int cnt); + + /** + * @brief Set the 2D matrix to the identity matrix + * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFLOAT2D + * + * @param[in] m The matrix to set to identity + * + * @api + */ + void gmiscMatrixFloat2DSetIdentity(MatrixFloat2D *m); + + /** + * @brief Multiple two 2D matrixes together + * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFLOAT2D + * + * @param[in] dst The destination matrix + * @param[in] src1 The first source matrix + * @param[in] src2 The second source matrix + * + * @note In-place matrix application is NOT allowed ie. dst != src1, dst != src2 + * + * @api + */ + void gmiscMatrixFloat2DMultiply(MatrixFloat2D *dst, const MatrixFloat2D *src1, const MatrixFloat2D *src2); + + /** + * @brief Add an x,y translation to a matrix + * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFLOAT2D + * + * @param[in] dst The destination matrix + * @param[in] src The source matrix. Can be NULL + * @param[in] tx, ty The x and y translation to apply + * + * @note In-place matrix operation is NOT allowed ie. dst != src + * @note If no source matrix is provided, it is equivalent to applying the operation + * to an identity matrix. It also is a much simpler operation requiring no multiplication. + * + * @api + */ + void gmiscMatrixFloat2DApplyTranslation(MatrixFloat2D *dst, const MatrixFloat2D *src, float tx, float ty); + + /** + * @brief Add x,y scaling to a matrix + * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFLOAT2D + * + * @param[in] dst The destination matrix + * @param[in] src The source matrix. Can be NULL + * @param[in] sx, sy The scaling to apply in the x and y direction. Negative numbers give reflection. + * + * @note In-place matrix operation is NOT allowed ie. dst != src + * @note If no source matrix is provided, it is equivalent to applying the operation + * to an identity matrix. It also is a much simpler operation requiring no multiplication. + * + * @api + */ + void gmiscMatrixFloat2DApplyScale(MatrixFloat2D *dst, const MatrixFloat2D *src, float sx, float sy); + + /** + * @brief Add x,y shear to a matrix + * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFLOAT2D + * + * @param[in] dst The destination matrix + * @param[in] src The source matrix. Can be NULL + * @param[in] sx, sy The shear to apply in the x and y direction. + * + * @note In-place matrix operation is NOT allowed ie. dst != src + * @note If no source matrix is provided, it is equivalent to applying the operation + * to an identity matrix. It also is a much simpler operation requiring no multiplication. + * + * @api + */ + void gmiscMatrixFloat2DApplyShear(MatrixFloat2D *dst, const MatrixFloat2D *src, float sx, float sy); + + /** + * @brief Add rotation to a matrix + * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFLOAT2D + * + * @param[in] dst The destination matrix + * @param[in] src The source matrix. Can be NULL + * @param[in] angle The angle to apply in degrees (not radians). + * + * @note In-place matrix operation is NOT allowed ie. dst != src + * @note If no source matrix is provided, it is equivalent to applying the operation + * to an identity matrix. It also is a much simpler operation. + * @note If GMISC_NEED_FASTTRIG is defined then the fast table sin and cos lookup's will be used + * rather than the C library versions. + * + * @api + */ + void gmiscMatrixFloat2DApplyRotation(MatrixFloat2D *dst, const MatrixFloat2D *src, int angle); +#endif + +#if GMISC_NEED_MATRIXFIXED2D || defined(__DOXYGEN__) + + /** + * @brief A matrix for doing 2D graphics using fixed point maths + * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFIXED2D + */ + typedef struct MatrixFixed2D { + fixed a00, a01, a02; + fixed a10, a11, a12; + fixed a20, a21, a22; + } MatrixFixed2D; + + /** + * @brief Apply the matrix to a set of points + * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFIXED2D + * + * @param[in] dst The destination array of points + * @param[in] src The source array of points + * @param[in] m The matrix to apply + * @param[in] cnt How many points are in the array + * + * @note In-place matrix application is allowed ie. dst = src + * + * @api + */ + void gmiscMatrixFixed2DApplyToPoints(point *dst, const point *src, const MatrixFixed2D *m, int cnt); + + /** + * @brief Set the 2D matrix to the identity matrix + * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFIXED2D + * + * @param[in] m The matrix to set to identity + * + * @api + */ + void gmiscMatrixFixed2DSetIdentity(MatrixFixed2D *m); + + /** + * @brief Multiple two 2D matrixes together + * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFIXED2D + * + * @param[in] dst The destination matrix + * @param[in] src1 The first source matrix + * @param[in] src2 The second source matrix + * + * @note In-place matrix application is NOT allowed ie. dst != src1, dst != src2 + * + * @api + */ + void gmiscMatrixFixed2DMultiply(MatrixFixed2D *dst, const MatrixFixed2D *src1, const MatrixFixed2D *src2); + + /** + * @brief Add an x,y translation to a matrix + * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFIXED2D + * + * @param[in] dst The destination matrix + * @param[in] src The source matrix. Can be NULL + * @param[in] tx, ty The x and y translation to apply + * + * @note In-place matrix operation is NOT allowed ie. dst != src + * @note If no source matrix is provided, it is equivalent to applying the operation + * to an identity matrix. It also is a much simpler operation requiring no multiplication. + * + * @api + */ + void gmiscMatrixFixed2DApplyTranslation(MatrixFixed2D *dst, const MatrixFixed2D *src, fixed tx, fixed ty); + + /** + * @brief Add x,y scaling to a matrix + * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFIXED2D + * + * @param[in] dst The destination matrix + * @param[in] src The source matrix. Can be NULL + * @param[in] sx, sy The scaling to apply in the x and y direction. Negative numbers give reflection. + * + * @note In-place matrix operation is NOT allowed ie. dst != src + * @note If no source matrix is provided, it is equivalent to applying the operation + * to an identity matrix. It also is a much simpler operation requiring no multiplication. + * + * @api + */ + void gmiscMatrixFixed2DApplyScale(MatrixFixed2D *dst, const MatrixFixed2D *src, fixed sx, fixed sy); + + /** + * @brief Add x,y shear to a matrix + * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFIXED2D + * + * @param[in] dst The destination matrix + * @param[in] src The source matrix. Can be NULL + * @param[in] sx, sy The shear to apply in the x and y direction. + * + * @note In-place matrix operation is NOT allowed ie. dst != src + * @note If no source matrix is provided, it is equivalent to applying the operation + * to an identity matrix. It also is a much simpler operation requiring no multiplication. + * + * @api + */ + void gmiscMatrixFixed2DApplyShear(MatrixFixed2D *dst, const MatrixFixed2D *src, fixed sx, fixed sy); + + #if GMISC_NEED_FIXEDTRIG || defined(__DOXYGEN__) + /** + * @brief Add rotation to a matrix + * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFIXED2D and GMISC_NEED_FIXEDTRIG + * + * @param[in] dst The destination matrix + * @param[in] src The source matrix. Can be NULL + * @param[in] angle The angle to apply in degrees (not radians). + * + * @note In-place matrix operation is NOT allowed ie. dst != src + * @note If no source matrix is provided, it is equivalent to applying the operation + * to an identity matrix. It also is a much simpler operation requiring no multiplication. + * + * @api + */ + void gmiscMatrixFixed2DApplyRotation(MatrixFixed2D *dst, const MatrixFixed2D *src, int angle); + #endif +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* GFX_USE_MISC */ + +#endif /* _GMISC_H */ +/** @} */ + diff --git a/src/gmisc/gmisc.mk b/src/gmisc/gmisc.mk new file mode 100644 index 00000000..fa2e382f --- /dev/null +++ b/src/gmisc/gmisc.mk @@ -0,0 +1,4 @@ +GFXSRC += $(GFXLIB)/src/gmisc/gmisc.c \ + $(GFXLIB)/src/gmisc/gmisc_arrayops.c \ + $(GFXLIB)/src/gmisc/gmisc_matrix2d.c \ + $(GFXLIB)/src/gmisc/gmisc_trig.c diff --git a/src/gmisc/gmisc_arrayops.c b/src/gmisc/gmisc_arrayops.c index 6e5442cd..350a787c 100644 --- a/src/gmisc/gmisc_arrayops.c +++ b/src/gmisc/gmisc_arrayops.c @@ -5,13 +5,6 @@ * http://ugfx.org/license.html */ -/** - * @file src/gmisc/gmisc_arrayops.c - * @brief GMISC Array Operations code. - * - * @addtogroup GMISC - * @{ - */ #include "gfx.h" #if GFX_USE_GMISC && GMISC_NEED_ARRAYOPS @@ -223,4 +216,3 @@ void gmiscArrayConvert(ArrayDataFormat srcfmt, void *src, ArrayDataFormat dstfmt } #endif /* GFX_USE_GMISC && GMISC_NEED_ARRAYOPS */ -/** @} */ diff --git a/src/gmisc/gmisc_gmisc.c b/src/gmisc/gmisc_gmisc.c deleted file mode 100644 index 3121182f..00000000 --- a/src/gmisc/gmisc_gmisc.c +++ /dev/null @@ -1,27 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -/** - * @file src/gmisc/gmisc_gmisc.c - * @brief GMISC Functions. - * - */ -#include "gfx.h" - -#if GFX_USE_GMISC - -void _gmiscInit(void) -{ - -} - -void _gmiscDeinit(void) -{ - -} - -#endif /* GFX_USE_GMISC */ diff --git a/src/gmisc/gmisc_matrix2d.c b/src/gmisc/gmisc_matrix2d.c index dd13603e..84b90c23 100644 --- a/src/gmisc/gmisc_matrix2d.c +++ b/src/gmisc/gmisc_matrix2d.c @@ -5,10 +5,6 @@ * http://ugfx.org/license.html */ -/** - * @file src/gmisc/gmisc_matrix2d.c - * @brief GMISC 2D matrix operations code. - */ #include "gfx.h" #if GFX_USE_GMISC diff --git a/src/gmisc/gmisc_options.h b/src/gmisc/gmisc_options.h new file mode 100644 index 00000000..7f175fd7 --- /dev/null +++ b/src/gmisc/gmisc_options.h @@ -0,0 +1,85 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file src/gmisc/gmisc_options.h + * @brief GMISC - Miscellaneous Routines options header file. + * + * @addtogroup GMISC + * @{ + */ + +#ifndef _GMISC_OPTIONS_H +#define _GMISC_OPTIONS_H + +/** + * @name GMISC Functionality to be included + * @{ + */ + /** + * @brief Include array operation functions + * @details Defaults to FALSE + */ + #ifndef GMISC_NEED_ARRAYOPS + #define GMISC_NEED_ARRAYOPS FALSE + #endif + /** + * @brief Include fast floating point trig functions (fsin, fcos) + * @details Defaults to FALSE + */ + #ifndef GMISC_NEED_FASTTRIG + #define GMISC_NEED_FASTTRIG FALSE + #endif + /** + * @brief Include fast fixed point trig functions (ffsin, ffcos) + * @details Defaults to FALSE + */ + #ifndef GMISC_NEED_FIXEDTRIG + #define GMISC_NEED_FIXEDTRIG FALSE + #endif + /** + * @brief Include fast inverse square root (x^-1/2) + * @details Defaults to FALSE + */ + #ifndef GMISC_NEED_INVSQRT + #define GMISC_NEED_INVSQRT FALSE + #endif +/** + * @} + * + * @name GMISC Optional Parameters + * @{ + */ + /** + * @brief Modifies the @p invsqrt() function to assume a different integer to floating point endianness. + * @note Normally the floating point format and the integer format have + * the same endianness. Unfortunately there are some strange + * processors that don't eg. some very early ARM devices. + * For those where the endianness doesn't match you can fix it by + * defining GMISC_INVSQRT_MIXED_ENDIAN. + * @note This still assumes the processor is using an ieee floating point format. + * + * If you have a software floating point that uses a non-standard + * floating point format (or very strange hardware) then define + * GMISC_INVSQRT_REAL_SLOW and it will do it the hard way. + */ + #ifndef GMISC_INVSQRT_MIXED_ENDIAN + #define GMISC_INVSQRT_MIXED_ENDIAN FALSE + #endif + /** + * @brief Modifies the @p invsqrt() function to do things the long slow way. + * @note This causes the @p invsqrt() function to work regardless of the + * processor floating point format. + * @note This makes the @p invsqrt() function very slow. + */ + #ifndef GMISC_INVSQRT_REAL_SLOW + #define GMISC_INVSQRT_REAL_SLOW FALSE + #endif +/** @} */ + +#endif /* _GMISC_OPTIONS_H */ +/** @} */ diff --git a/src/gmisc/gmisc_rules.h b/src/gmisc/gmisc_rules.h new file mode 100644 index 00000000..44a19846 --- /dev/null +++ b/src/gmisc/gmisc_rules.h @@ -0,0 +1,23 @@ +/* + * This file is subject to the terms of the GFX License. If a copy of + * the license was not distributed with this file, you can obtain one at: + * + * http://ugfx.org/license.html + */ + +/** + * @file src/gmisc/gmisc_rules.h + * @brief GMISC safety rules header file. + * + * @addtogroup GMISC + * @{ + */ + +#ifndef _GMISC_RULES_H +#define _GMISC_RULES_H + +#if GFX_USE_GMISC +#endif + +#endif /* _GMISC_RULES_H */ +/** @} */ diff --git a/src/gmisc/gmisc_trig.c b/src/gmisc/gmisc_trig.c index 7314f389..12d06be2 100644 --- a/src/gmisc/gmisc_trig.c +++ b/src/gmisc/gmisc_trig.c @@ -5,13 +5,6 @@ * http://ugfx.org/license.html */ -/** - * @file src/gmisc/gmisc_trig.c - * @brief GMISC Trig Functions. - * - * @addtogroup GMISC - * @{ - */ #include "gfx.h" #if GFX_USE_GMISC @@ -187,4 +180,3 @@ #endif #endif /* GFX_USE_GMISC */ -/** @} */ diff --git a/src/gmisc/sys_defs.h b/src/gmisc/sys_defs.h deleted file mode 100644 index 813fa07e..00000000 --- a/src/gmisc/sys_defs.h +++ /dev/null @@ -1,471 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -/** - * @file src/gmisc/sys_defs.h - * @brief GMISC - Miscellaneous Routines header file. - * - * @addtogroup GMISC - * - * @brief Module which contains different features such as array conversions - * - * @{ - */ - -#ifndef _GMISC_H -#define _GMISC_H - -#include "gfx.h" - -/*===========================================================================*/ -/* Type definitions */ -/*===========================================================================*/ - -// Forward definition -typedef struct point point; - -/** - * @brief Sample data formats - * @note These are defined regardless of whether you use the GMISC module - * or not as they are used in lots of places. - */ -typedef enum ArrayDataFormat_e { - ARRAY_DATA_UNKNOWN = 0, - ARRAY_DATA_4BITUNSIGNED = 4, ARRAY_DATA_4BITSIGNED = 5, - ARRAY_DATA_8BITUNSIGNED = 8, ARRAY_DATA_8BITSIGNED = 9, - ARRAY_DATA_10BITUNSIGNED = 10, ARRAY_DATA_10BITSIGNED = 11, - ARRAY_DATA_12BITUNSIGNED = 12, ARRAY_DATA_12BITSIGNED = 13, - ARRAY_DATA_14BITUNSIGNED = 14, ARRAY_DATA_14BITSIGNED = 15, - ARRAY_DATA_16BITUNSIGNED = 16, ARRAY_DATA_16BITSIGNED = 17, - } ArrayDataFormat; - -/** - * @brief Is the sample data format a "signed" data format? - */ -#define gfxSampleFormatIsSigned(fmt) ((fmt) & 1) - -/** - * @brief How many bits are in the sample data format - */ -#define gfxSampleFormatBits(fmt) ((fmt) & ~1) - -/** - * @brief The type for a fixed point type. - * @details The top 16 bits are the integer component, the bottom 16 bits are the real component. - */ -typedef int32_t fixed; - -/** - * @brief Macros to convert to and from a fixed point. - * @{ - */ -#define FIXED(x) ((fixed)(x)<<16) /* @< integer to fixed */ -#define NONFIXED(x) ((x)>>16) /* @< fixed to integer */ -#define FIXED0_5 32768 /* @< 0.5 as a fixed (used for rounding) */ -#define FP2FIXED(x) ((fixed)((x)*65536.0)) /* @< floating point to fixed */ -#define FIXED2FP(x) ((double)(x)/65536.0) /* @< fixed to floating point */ -#define FIXEDMUL(a,b) ((fixed)((((long long)(a))*(b))>>16)) /* @< fixed,fixed multiplication */ -#define FIXEDMULINT(a,b) ((a)*(b)) /* @< integer,fixed multiplication */ -/** @} */ - -/** - * @brief The famous number pi - */ -#define PI 3.1415926535897932384626433832795028841971693993751 - -/** - * @brief pi as a fixed point - */ -#define FIXED_PI FP2FIXED(PI) - -/*===========================================================================*/ -/* External declarations. */ -/*===========================================================================*/ - -#if GFX_USE_GMISC || defined(__DOXYGEN__) - -#ifdef __cplusplus -extern "C" { -#endif - -#if GMISC_NEED_ARRAYOPS || defined(__DOXYGEN__) - /** - * @brief Convert from one array format to another array format. - * @pre Requires GFX_USE_GMISC and GMISC_NEED_ARRAYOPS - * - * @param[in] srcfmt The format of the source array - * @param[in] src The source array - * @param[in] dstfmt The format of the destination array - * @param[in] dst The dstination array - * @param[in] cnt The number of array elements to convert - * - * @note Assumes the destination buffer is large enough for the resultant data. - * @note This routine is optimised to perform as fast as possible. - * @note No type checking is performed on the source format. It is assumed to - * have only valid values eg. ARRAY_DATA_4BITSIGNED will have values - * 0000 -> 0111 for positive numbers and 1111 -> 1000 for negative numbers - * Bits 5 -> 8 in the storage byte are treated in an undefined manner. - * @note If srcfmt or dstfmt is an unknown format, this routine does nothing - * with no warning that something is wrong - * - * @api - */ - void gmiscArrayConvert(ArrayDataFormat srcfmt, void *src, ArrayDataFormat dstfmt, void *dst, size_t cnt); - - #if 0 - void gmiscArrayTranslate(ArrayDataFormat fmt, void *src, void *dst, size_t cnt, int trans); - - void gmiscArrayMultiply(ArrayDataFormat fmt, void *src, void *dst, size_t cnt, int mult); - - void gmiscArrayDivide(ArrayDataFormat fmt, void *src, void *dst, size_t cnt, int mdiv); - - void gmiscArrayMultDiv(ArrayDataFormat fmt, void *src, void *dst, size_t cnt, int mult, int div); - - void gmiscArrayAdd(ArrayDataFormat fmt, void *src1, void *src2, void *dst, size_t cnt); - - void gmiscArrayAddNoOverflow(ArrayDataFormat fmt, void *src1, void *src2, void *dst, size_t cnt); - #endif -#endif - -#if GMISC_NEED_FASTTRIG || defined(__DOXYGEN__) - extern const double sintabledouble[]; - - /** - * @brief Fast Table Based Trig functions - * @return A double in the range -1.0 .. 0.0 .. 1.0 - * @pre Requires GFX_USE_GMISC and GMISC_NEED_FASTTRIG - * - * @param[in] degrees The angle in degrees (not radians) - * - * @note These functions use degrees rather than radians to describe the angle. - * - * @api - * @{ - */ - double fsin(int degrees); - double fcos(int degrees); - /** @} - * - * @brief Fast Table Based Trig functions - * @return A double in the range -1.0 .. 0.0 .. 1.0 - * @pre Requires GFX_USE_GMISC and GMISC_NEED_FASTTRIG - * - * @param[in] degrees The angle in degrees 0 .. 359 - * - * @note These functions use degrees rather than radians to describe the angle. - * @note These functions are super fast but require the parameter to be in range. - * Use the lowercase functions if the parameter may not be in range or if a - * required trig function is not supported in this form. - * - * @api - * @{ - */ - #define FSIN(degrees) sintabledouble[degrees]; - /** @} */ -#endif - -#if GMISC_NEED_FIXEDTRIG || defined(__DOXYGEN__) - extern const fixed sintablefixed[]; - - /** - * @brief Fast Table Based Trig functions - * @return A fixed point in the range -1.0 .. 0.0 .. 1.0 - * @pre Requires GFX_USE_GMISC and GMISC_NEED_FIXEDTRIG - * - * @param[in] degrees The angle in degrees (not radians) - * - * @note These functions use degrees rather than radians to describe the angle. - * - * @api - * @{ - */ - fixed ffsin(int degrees); - fixed ffcos(int degrees); - /** @} - * - * @brief Fast Table Based Trig functions - * @return A fixed point in the range -1.0 .. 0.0 .. 1.0 - * @pre Requires GFX_USE_GMISC and GMISC_NEED_FIXEDTRIG - * - * @param[in] degrees The angle in degrees 0 .. 359 - * - * @note These functions use degrees rather than radians to describe the angle. - * @note These functions are super fast but require the parameter to be in range. - * Use the lowercase functions if the parameter may not be in range or if a - * required trig function is not supported in this form. - * - * @api - * @{ - */ - #define FFSIN(degrees) sintablefixed[degrees]; - /** @} */ -#endif - -#if GMISC_NEED_INVSQRT || defined(__DOXYGEN__) - /** - * @brief Fast inverse square root function (x^-1/2) - * @return The approximate inverse square root - * @pre Requires GFX_USE_GMISC and GMISC_NEED_INVSQRT - * - * @param[in] n The number to find the inverse square root of - * - * @note This function generates an approximate result. Higher accuracy (at the expense - * of speed) can be obtained by modifying the source code (the necessary line - * is already there - just commented out). - * @note This function relies on the internal machine format of a float and a long. - * If your machine architecture is very unusual this function may not work. - * - * @api - */ - float invsqrt(float n); -#endif - -#if GMISC_NEED_MATRIXFLOAT2D || defined(__DOXYGEN__) - - /** - * @brief A matrix for doing 2D graphics using floats - * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFLOAT2D - */ - typedef struct MatrixFloat2D { - float a00, a01, a02; - float a10, a11, a12; - float a20, a21, a22; - } MatrixFloat2D; - - /** - * @brief Apply the matrix to a set of points - * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFLOAT2D - * - * @param[in] dst The destination array of points - * @param[in] src The source array of points - * @param[in] m The matrix to apply - * @param[in] cnt How many points are in the array - * - * @note In-place matrix application is allowed ie. dst = src - * - * @api - */ - void gmiscMatrixFloat2DApplyToPoints(point *dst, const point *src, const MatrixFloat2D *m, int cnt); - - /** - * @brief Set the 2D matrix to the identity matrix - * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFLOAT2D - * - * @param[in] m The matrix to set to identity - * - * @api - */ - void gmiscMatrixFloat2DSetIdentity(MatrixFloat2D *m); - - /** - * @brief Multiple two 2D matrixes together - * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFLOAT2D - * - * @param[in] dst The destination matrix - * @param[in] src1 The first source matrix - * @param[in] src2 The second source matrix - * - * @note In-place matrix application is NOT allowed ie. dst != src1, dst != src2 - * - * @api - */ - void gmiscMatrixFloat2DMultiply(MatrixFloat2D *dst, const MatrixFloat2D *src1, const MatrixFloat2D *src2); - - /** - * @brief Add an x,y translation to a matrix - * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFLOAT2D - * - * @param[in] dst The destination matrix - * @param[in] src The source matrix. Can be NULL - * @param[in] tx, ty The x and y translation to apply - * - * @note In-place matrix operation is NOT allowed ie. dst != src - * @note If no source matrix is provided, it is equivalent to applying the operation - * to an identity matrix. It also is a much simpler operation requiring no multiplication. - * - * @api - */ - void gmiscMatrixFloat2DApplyTranslation(MatrixFloat2D *dst, const MatrixFloat2D *src, float tx, float ty); - - /** - * @brief Add x,y scaling to a matrix - * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFLOAT2D - * - * @param[in] dst The destination matrix - * @param[in] src The source matrix. Can be NULL - * @param[in] sx, sy The scaling to apply in the x and y direction. Negative numbers give reflection. - * - * @note In-place matrix operation is NOT allowed ie. dst != src - * @note If no source matrix is provided, it is equivalent to applying the operation - * to an identity matrix. It also is a much simpler operation requiring no multiplication. - * - * @api - */ - void gmiscMatrixFloat2DApplyScale(MatrixFloat2D *dst, const MatrixFloat2D *src, float sx, float sy); - - /** - * @brief Add x,y shear to a matrix - * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFLOAT2D - * - * @param[in] dst The destination matrix - * @param[in] src The source matrix. Can be NULL - * @param[in] sx, sy The shear to apply in the x and y direction. - * - * @note In-place matrix operation is NOT allowed ie. dst != src - * @note If no source matrix is provided, it is equivalent to applying the operation - * to an identity matrix. It also is a much simpler operation requiring no multiplication. - * - * @api - */ - void gmiscMatrixFloat2DApplyShear(MatrixFloat2D *dst, const MatrixFloat2D *src, float sx, float sy); - - /** - * @brief Add rotation to a matrix - * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFLOAT2D - * - * @param[in] dst The destination matrix - * @param[in] src The source matrix. Can be NULL - * @param[in] angle The angle to apply in degrees (not radians). - * - * @note In-place matrix operation is NOT allowed ie. dst != src - * @note If no source matrix is provided, it is equivalent to applying the operation - * to an identity matrix. It also is a much simpler operation. - * @note If GMISC_NEED_FASTTRIG is defined then the fast table sin and cos lookup's will be used - * rather than the C library versions. - * - * @api - */ - void gmiscMatrixFloat2DApplyRotation(MatrixFloat2D *dst, const MatrixFloat2D *src, int angle); -#endif - -#if GMISC_NEED_MATRIXFIXED2D || defined(__DOXYGEN__) - - /** - * @brief A matrix for doing 2D graphics using fixed point maths - * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFIXED2D - */ - typedef struct MatrixFixed2D { - fixed a00, a01, a02; - fixed a10, a11, a12; - fixed a20, a21, a22; - } MatrixFixed2D; - - /** - * @brief Apply the matrix to a set of points - * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFIXED2D - * - * @param[in] dst The destination array of points - * @param[in] src The source array of points - * @param[in] m The matrix to apply - * @param[in] cnt How many points are in the array - * - * @note In-place matrix application is allowed ie. dst = src - * - * @api - */ - void gmiscMatrixFixed2DApplyToPoints(point *dst, const point *src, const MatrixFixed2D *m, int cnt); - - /** - * @brief Set the 2D matrix to the identity matrix - * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFIXED2D - * - * @param[in] m The matrix to set to identity - * - * @api - */ - void gmiscMatrixFixed2DSetIdentity(MatrixFixed2D *m); - - /** - * @brief Multiple two 2D matrixes together - * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFIXED2D - * - * @param[in] dst The destination matrix - * @param[in] src1 The first source matrix - * @param[in] src2 The second source matrix - * - * @note In-place matrix application is NOT allowed ie. dst != src1, dst != src2 - * - * @api - */ - void gmiscMatrixFixed2DMultiply(MatrixFixed2D *dst, const MatrixFixed2D *src1, const MatrixFixed2D *src2); - - /** - * @brief Add an x,y translation to a matrix - * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFIXED2D - * - * @param[in] dst The destination matrix - * @param[in] src The source matrix. Can be NULL - * @param[in] tx, ty The x and y translation to apply - * - * @note In-place matrix operation is NOT allowed ie. dst != src - * @note If no source matrix is provided, it is equivalent to applying the operation - * to an identity matrix. It also is a much simpler operation requiring no multiplication. - * - * @api - */ - void gmiscMatrixFixed2DApplyTranslation(MatrixFixed2D *dst, const MatrixFixed2D *src, fixed tx, fixed ty); - - /** - * @brief Add x,y scaling to a matrix - * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFIXED2D - * - * @param[in] dst The destination matrix - * @param[in] src The source matrix. Can be NULL - * @param[in] sx, sy The scaling to apply in the x and y direction. Negative numbers give reflection. - * - * @note In-place matrix operation is NOT allowed ie. dst != src - * @note If no source matrix is provided, it is equivalent to applying the operation - * to an identity matrix. It also is a much simpler operation requiring no multiplication. - * - * @api - */ - void gmiscMatrixFixed2DApplyScale(MatrixFixed2D *dst, const MatrixFixed2D *src, fixed sx, fixed sy); - - /** - * @brief Add x,y shear to a matrix - * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFIXED2D - * - * @param[in] dst The destination matrix - * @param[in] src The source matrix. Can be NULL - * @param[in] sx, sy The shear to apply in the x and y direction. - * - * @note In-place matrix operation is NOT allowed ie. dst != src - * @note If no source matrix is provided, it is equivalent to applying the operation - * to an identity matrix. It also is a much simpler operation requiring no multiplication. - * - * @api - */ - void gmiscMatrixFixed2DApplyShear(MatrixFixed2D *dst, const MatrixFixed2D *src, fixed sx, fixed sy); - - #if GMISC_NEED_FIXEDTRIG || defined(__DOXYGEN__) - /** - * @brief Add rotation to a matrix - * @pre Requires GFX_USE_GMISC and GMISC_NEED_MATRIXFIXED2D and GMISC_NEED_FIXEDTRIG - * - * @param[in] dst The destination matrix - * @param[in] src The source matrix. Can be NULL - * @param[in] angle The angle to apply in degrees (not radians). - * - * @note In-place matrix operation is NOT allowed ie. dst != src - * @note If no source matrix is provided, it is equivalent to applying the operation - * to an identity matrix. It also is a much simpler operation requiring no multiplication. - * - * @api - */ - void gmiscMatrixFixed2DApplyRotation(MatrixFixed2D *dst, const MatrixFixed2D *src, int angle); - #endif -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* GFX_USE_MISC */ - -#endif /* _GMISC_H */ -/** @} */ - diff --git a/src/gmisc/sys_make.mk b/src/gmisc/sys_make.mk deleted file mode 100644 index 203910e6..00000000 --- a/src/gmisc/sys_make.mk +++ /dev/null @@ -1,4 +0,0 @@ -GFXSRC += $(GFXLIB)/src/gmisc/gmisc_gmisc.c \ - $(GFXLIB)/src/gmisc/gmisc_arrayops.c \ - $(GFXLIB)/src/gmisc/gmisc_matrix2d.c \ - $(GFXLIB)/src/gmisc/gmisc_trig.c diff --git a/src/gmisc/sys_options.h b/src/gmisc/sys_options.h deleted file mode 100644 index 9cdf37f6..00000000 --- a/src/gmisc/sys_options.h +++ /dev/null @@ -1,85 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -/** - * @file src/gmisc/sys_options.h - * @brief GMISC - Miscellaneous Routines options header file. - * - * @addtogroup GMISC - * @{ - */ - -#ifndef _GMISC_OPTIONS_H -#define _GMISC_OPTIONS_H - -/** - * @name GMISC Functionality to be included - * @{ - */ - /** - * @brief Include array operation functions - * @details Defaults to FALSE - */ - #ifndef GMISC_NEED_ARRAYOPS - #define GMISC_NEED_ARRAYOPS FALSE - #endif - /** - * @brief Include fast floating point trig functions (fsin, fcos) - * @details Defaults to FALSE - */ - #ifndef GMISC_NEED_FASTTRIG - #define GMISC_NEED_FASTTRIG FALSE - #endif - /** - * @brief Include fast fixed point trig functions (ffsin, ffcos) - * @details Defaults to FALSE - */ - #ifndef GMISC_NEED_FIXEDTRIG - #define GMISC_NEED_FIXEDTRIG FALSE - #endif - /** - * @brief Include fast inverse square root (x^-1/2) - * @details Defaults to FALSE - */ - #ifndef GMISC_NEED_INVSQRT - #define GMISC_NEED_INVSQRT FALSE - #endif -/** - * @} - * - * @name GMISC Optional Parameters - * @{ - */ - /** - * @brief Modifies the @p invsqrt() function to assume a different integer to floating point endianness. - * @note Normally the floating point format and the integer format have - * the same endianness. Unfortunately there are some strange - * processors that don't eg. some very early ARM devices. - * For those where the endianness doesn't match you can fix it by - * defining GMISC_INVSQRT_MIXED_ENDIAN. - * @note This still assumes the processor is using an ieee floating point format. - * - * If you have a software floating point that uses a non-standard - * floating point format (or very strange hardware) then define - * GMISC_INVSQRT_REAL_SLOW and it will do it the hard way. - */ - #ifndef GMISC_INVSQRT_MIXED_ENDIAN - #define GMISC_INVSQRT_MIXED_ENDIAN FALSE - #endif - /** - * @brief Modifies the @p invsqrt() function to do things the long slow way. - * @note This causes the @p invsqrt() function to work regardless of the - * processor floating point format. - * @note This makes the @p invsqrt() function very slow. - */ - #ifndef GMISC_INVSQRT_REAL_SLOW - #define GMISC_INVSQRT_REAL_SLOW FALSE - #endif -/** @} */ - -#endif /* _GMISC_OPTIONS_H */ -/** @} */ diff --git a/src/gmisc/sys_rules.h b/src/gmisc/sys_rules.h deleted file mode 100644 index 6c66907a..00000000 --- a/src/gmisc/sys_rules.h +++ /dev/null @@ -1,23 +0,0 @@ -/* - * This file is subject to the terms of the GFX License. If a copy of - * the license was not distributed with this file, you can obtain one at: - * - * http://ugfx.org/license.html - */ - -/** - * @file src/gmisc/sys_rules.h - * @brief GMISC safety rules header file. - * - * @addtogroup GMISC - * @{ - */ - -#ifndef _GMISC_RULES_H -#define _GMISC_RULES_H - -#if GFX_USE_GMISC -#endif - -#endif /* _GMISC_RULES_H */ -/** @} */ -- cgit v1.2.3