forked from minhngoc25a/freetype2
[sdf,bsdf] Put common propertied and functions in one file.
* src/sdf/ftsdfcommon.h: Added new file which contains common function, macros, properties for both `sdf' and `bsdf' renderer. * src/sdf/ftsdf.c, src/sdf/ftsdf.h, src/sdf/ftbsdf.c: Remove common properties and include `ftsdfcommon.h'. * src/sdf/rules.mk (SDF_DRV_H): Add the new `ftsdfcommon.h' file to include list.
This commit is contained in:
parent
aed19e1524
commit
f2553d89b2
|
@ -1,3 +1,17 @@
|
||||||
|
2020-07-30 Anuj Verma <anujv@iitbhilai.ac.in>
|
||||||
|
|
||||||
|
[sdf,bsdf] Put common propertied and functions in one file.
|
||||||
|
|
||||||
|
* src/sdf/ftsdfcommon.h: Added new file which contains
|
||||||
|
common function, macros, properties for both `sdf' and
|
||||||
|
`bsdf' renderer.
|
||||||
|
|
||||||
|
* src/sdf/ftsdf.c, src/sdf/ftsdf.h, src/sdf/ftbsdf.c:
|
||||||
|
Remove common properties and include `ftsdfcommon.h'.
|
||||||
|
|
||||||
|
* src/sdf/rules.mk (SDF_DRV_H): Add the new `ftsdfcommon.h'
|
||||||
|
file to include list.
|
||||||
|
|
||||||
2020-07-30 Anuj Verma <anujv@iitbhilai.ac.in>
|
2020-07-30 Anuj Verma <anujv@iitbhilai.ac.in>
|
||||||
|
|
||||||
* src/sdf/ftbsdf.c (compute_gradient): Use root(2)
|
* src/sdf/ftbsdf.c (compute_gradient): Use root(2)
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#include "ftsdf.h"
|
#include "ftsdf.h"
|
||||||
#include "ftsdferrs.h"
|
#include "ftsdferrs.h"
|
||||||
|
#include "ftsdfcommon.h"
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
*
|
*
|
||||||
|
@ -13,28 +14,8 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Convenient macro which calls the function */
|
|
||||||
/* and returns if any error occurs. */
|
|
||||||
#define FT_CALL( x ) do \
|
|
||||||
{ \
|
|
||||||
error = ( x ); \
|
|
||||||
if ( error != FT_Err_Ok ) \
|
|
||||||
goto Exit; \
|
|
||||||
} while ( 0 )
|
|
||||||
|
|
||||||
#define ONE 65536 /* 1 in 16.16 */
|
#define ONE 65536 /* 1 in 16.16 */
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
*
|
|
||||||
* typedefs
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
typedef FT_Vector FT_16D16_Vec; /* with 16.16 fixed point components */
|
|
||||||
|
|
||||||
typedef FT_Short FT_6D10; /* 6.10 fixed point representation */
|
|
||||||
typedef FT_Fixed FT_16D16; /* 16.16 fixed point representation */
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
*
|
*
|
||||||
* structs
|
* structs
|
||||||
|
@ -170,9 +151,6 @@
|
||||||
|
|
||||||
#undef CHECK_NEIGHBOR
|
#undef CHECK_NEIGHBOR
|
||||||
|
|
||||||
static FT_16D16
|
|
||||||
square_root( FT_16D16 val );
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
*
|
*
|
||||||
* @Function:
|
* @Function:
|
||||||
|
|
|
@ -118,14 +118,6 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* If it is defined to 1 then the rasterizer will use squared distances */
|
|
||||||
/* for computation. It can greatly improve the performance but there is */
|
|
||||||
/* a chance of overflow and artifacts. You can safely use it upto a */
|
|
||||||
/* pixel size of 128. */
|
|
||||||
#ifndef USE_SQUARED_DISTANCES
|
|
||||||
# define USE_SQUARED_DISTANCES 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* If it is defined to 1 then the rasterizer will use Newton-Raphson's */
|
/* If it is defined to 1 then the rasterizer will use Newton-Raphson's */
|
||||||
/* method for finding shortest distance from a point to a conic curve. */
|
/* method for finding shortest distance from a point to a conic curve. */
|
||||||
/* The other method is an analytical method which find the roots of a */
|
/* The other method is an analytical method which find the roots of a */
|
||||||
|
@ -159,25 +151,6 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* convert int to 26.6 fixed point */
|
|
||||||
#define FT_INT_26D6( x ) ( x * 64 )
|
|
||||||
|
|
||||||
/* convert int to 16.16 fixed point */
|
|
||||||
#define FT_INT_16D16( x ) ( x * 65536 )
|
|
||||||
|
|
||||||
/* convert 26.6 to 16.16 fixed point */
|
|
||||||
#define FT_26D6_16D16( x ) ( x * 1024 )
|
|
||||||
|
|
||||||
|
|
||||||
/* Convenient macro which calls the function */
|
|
||||||
/* and returns if any error occurs. */
|
|
||||||
#define FT_CALL( x ) do \
|
|
||||||
{ \
|
|
||||||
error = ( x ); \
|
|
||||||
if ( error != FT_Err_Ok ) \
|
|
||||||
goto Exit; \
|
|
||||||
} while ( 0 )
|
|
||||||
|
|
||||||
#define MUL_26D6( a, b ) ( ( a * b ) / 64 )
|
#define MUL_26D6( a, b ) ( ( a * b ) / 64 )
|
||||||
#define VEC_26D6_DOT( p, q ) ( MUL_26D6( p.x, q.x ) + \
|
#define VEC_26D6_DOT( p, q ) ( MUL_26D6( p.x, q.x ) + \
|
||||||
MUL_26D6( p.y, q.y ) )
|
MUL_26D6( p.y, q.y ) )
|
||||||
|
@ -195,20 +168,6 @@
|
||||||
# define VECTOR_LENGTH_16D16( v ) FT_Vector_Length( &v )
|
# define VECTOR_LENGTH_16D16( v ) FT_Vector_Length( &v )
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
*
|
|
||||||
* typedefs
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
typedef FT_Vector FT_26D6_Vec; /* with 26.6 fixed point components */
|
|
||||||
typedef FT_Vector FT_16D16_Vec; /* with 16.16 fixed point components */
|
|
||||||
|
|
||||||
typedef FT_Fixed FT_16D16; /* 16.16 fixed point representation */
|
|
||||||
typedef FT_Fixed FT_26D6; /* 26.6 fixed point representation */
|
|
||||||
|
|
||||||
typedef FT_BBox FT_CBox; /* control box of a curve */
|
|
||||||
|
|
||||||
/**************************************************************************
|
/**************************************************************************
|
||||||
*
|
*
|
||||||
* structures and enums
|
* structures and enums
|
||||||
|
@ -1164,32 +1123,6 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Original Algorithm: https://github.com/chmike/fpsqrt */
|
|
||||||
static FT_16D16
|
|
||||||
square_root( FT_16D16 val )
|
|
||||||
{
|
|
||||||
FT_ULong t, q, b, r;
|
|
||||||
|
|
||||||
|
|
||||||
r = val;
|
|
||||||
b = 0x40000000;
|
|
||||||
q = 0;
|
|
||||||
while( b > 0x40 )
|
|
||||||
{
|
|
||||||
t = q + b;
|
|
||||||
if( r >= t )
|
|
||||||
{
|
|
||||||
r -= t;
|
|
||||||
q = t + b;
|
|
||||||
}
|
|
||||||
r <<= 1;
|
|
||||||
b >>= 1;
|
|
||||||
}
|
|
||||||
q >>= 8;
|
|
||||||
|
|
||||||
return q;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if !USE_NEWTON_FOR_CONIC
|
#if !USE_NEWTON_FOR_CONIC
|
||||||
|
|
||||||
/* [NOTE]: All the functions below down until rasterizer */
|
/* [NOTE]: All the functions below down until rasterizer */
|
||||||
|
|
|
@ -6,17 +6,11 @@
|
||||||
#include FT_CONFIG_CONFIG_H
|
#include FT_CONFIG_CONFIG_H
|
||||||
#include <freetype/ftimage.h>
|
#include <freetype/ftimage.h>
|
||||||
|
|
||||||
|
/* common properties and function */
|
||||||
|
#include "ftsdfcommon.h"
|
||||||
|
|
||||||
FT_BEGIN_HEADER
|
FT_BEGIN_HEADER
|
||||||
|
|
||||||
/* default spread value */
|
|
||||||
#define DEFAULT_SPREAD 8
|
|
||||||
|
|
||||||
/* minimum spread supported by the rasterizer. */
|
|
||||||
#define MIN_SPREAD 2
|
|
||||||
|
|
||||||
/* maximum spread supported by the rasterizer. */
|
|
||||||
#define MAX_SPREAD 32
|
|
||||||
|
|
||||||
/* TEMPORARY */
|
/* TEMPORARY */
|
||||||
typedef enum Optimizations_ {
|
typedef enum Optimizations_ {
|
||||||
OPTIMIZATION_NONE = 0, /* default: check all points against all edges */
|
OPTIMIZATION_NONE = 0, /* default: check all points against all edges */
|
||||||
|
|
|
@ -0,0 +1,122 @@
|
||||||
|
|
||||||
|
/****************************************************
|
||||||
|
*
|
||||||
|
* This file contain common function and properties
|
||||||
|
* for both `sdf' and `bsdf' renderer.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef FTSDFCOMMON_H_
|
||||||
|
#define FTSDFCOMMON_H_
|
||||||
|
|
||||||
|
#include <ft2build.h>
|
||||||
|
#include FT_CONFIG_CONFIG_H
|
||||||
|
#include <freetype/freetype.h>
|
||||||
|
|
||||||
|
FT_BEGIN_HEADER
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
*
|
||||||
|
* default values (cannot be set individually for each renderer)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* default spread value */
|
||||||
|
#define DEFAULT_SPREAD 8
|
||||||
|
|
||||||
|
/* minimum spread supported by the renderer. */
|
||||||
|
#define MIN_SPREAD 2
|
||||||
|
|
||||||
|
/* maximum spread supported by the renderer. */
|
||||||
|
#define MAX_SPREAD 32
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
*
|
||||||
|
* common definitions (cannot be set individually for each renderer)
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* If it is defined to 1 then the rasterizer will use squared distances */
|
||||||
|
/* for computation. It can greatly improve the performance but there is */
|
||||||
|
/* a chance of overflow and artifacts. You can safely use it upto a */
|
||||||
|
/* pixel size of 128. */
|
||||||
|
#ifndef USE_SQUARED_DISTANCES
|
||||||
|
# define USE_SQUARED_DISTANCES 0
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
*
|
||||||
|
* common macros
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* convert int to 26.6 fixed point */
|
||||||
|
#define FT_INT_26D6( x ) ( x * 64 )
|
||||||
|
|
||||||
|
/* convert int to 16.16 fixed point */
|
||||||
|
#define FT_INT_16D16( x ) ( x * 65536 )
|
||||||
|
|
||||||
|
/* convert 26.6 to 16.16 fixed point */
|
||||||
|
#define FT_26D6_16D16( x ) ( x * 1024 )
|
||||||
|
|
||||||
|
/* Convenient macro which calls the function */
|
||||||
|
/* and returns if any error occurs. */
|
||||||
|
#define FT_CALL( x ) do \
|
||||||
|
{ \
|
||||||
|
error = ( x ); \
|
||||||
|
if ( error != FT_Err_Ok ) \
|
||||||
|
goto Exit; \
|
||||||
|
} while ( 0 )
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
*
|
||||||
|
* common typedefs
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef FT_Vector FT_26D6_Vec; /* with 26.6 fixed point components */
|
||||||
|
typedef FT_Vector FT_16D16_Vec; /* with 16.16 fixed point components */
|
||||||
|
|
||||||
|
typedef FT_Fixed FT_16D16; /* 16.16 fixed point representation */
|
||||||
|
typedef FT_Fixed FT_26D6; /* 26.6 fixed point representation */
|
||||||
|
typedef FT_Short FT_6D10; /* 6.10 fixed point representation */
|
||||||
|
|
||||||
|
typedef FT_BBox FT_CBox; /* control box of a curve */
|
||||||
|
|
||||||
|
/**************************************************************************
|
||||||
|
*
|
||||||
|
* common functions
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
/* Original Algorithm: https://github.com/chmike/fpsqrt */
|
||||||
|
static FT_16D16
|
||||||
|
square_root( FT_16D16 val )
|
||||||
|
{
|
||||||
|
FT_ULong t, q, b, r;
|
||||||
|
|
||||||
|
|
||||||
|
r = val;
|
||||||
|
b = 0x40000000;
|
||||||
|
q = 0;
|
||||||
|
while( b > 0x40 )
|
||||||
|
{
|
||||||
|
t = q + b;
|
||||||
|
if( r >= t )
|
||||||
|
{
|
||||||
|
r -= t;
|
||||||
|
q = t + b;
|
||||||
|
}
|
||||||
|
r <<= 1;
|
||||||
|
b >>= 1;
|
||||||
|
}
|
||||||
|
q >>= 8;
|
||||||
|
|
||||||
|
return q;
|
||||||
|
}
|
||||||
|
|
||||||
|
FT_END_HEADER
|
||||||
|
|
||||||
|
#endif /* FTSDFCOMMON_H_ */
|
||||||
|
|
||||||
|
/* END */
|
|
@ -24,7 +24,8 @@ SDF_DRV_SRC := $(SDF_DIR)/ftsdfrend.c \
|
||||||
#
|
#
|
||||||
SDF_DRV_H := $(SDF_DIR)/ftsdfrend.h \
|
SDF_DRV_H := $(SDF_DIR)/ftsdfrend.h \
|
||||||
$(SDF_DIR)/ftsdf.h \
|
$(SDF_DIR)/ftsdf.h \
|
||||||
$(SDF_DIR)/ftsdferrs.h
|
$(SDF_DIR)/ftsdferrs.h \
|
||||||
|
$(SDF_DIR)/ftsdfcommon.h
|
||||||
|
|
||||||
|
|
||||||
# sdf driver object(s)
|
# sdf driver object(s)
|
||||||
|
|
Loading…
Reference in New Issue