Use inbuilt data-types
This commit is contained in:
parent
d9c301d35a
commit
9aafe98c1d
|
@ -28,35 +28,34 @@ typedef struct dense_TRaster_
|
||||||
|
|
||||||
} dense_TRaster, *dense_PRaster;
|
} dense_TRaster, *dense_PRaster;
|
||||||
|
|
||||||
static RasterFP_Point
|
static FT_Vector
|
||||||
Lerp( float aT, RasterFP_Point aP0, RasterFP_Point aP1 )
|
Lerp( float aT, FT_Vector aP0, FT_Vector aP1 )
|
||||||
{
|
{
|
||||||
RasterFP_Point p;
|
FT_Vector p;
|
||||||
p.m_x = aP0.m_x + aT * ( aP1.m_x - aP0.m_x );
|
p.x = aP0.x + aT * ( aP1.x - aP0.x );
|
||||||
p.m_y = aP0.m_y + aT * ( aP1.m_y - aP0.m_y );
|
p.y = aP0.y + aT * ( aP1.y - aP0.y );
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
dense_move_to( const FT_Vector* to, RasterFP* aRasterFP )
|
dense_move_to( const FT_Vector* to, dense_worker* worker )
|
||||||
{
|
{
|
||||||
TPos x, y;
|
TPos x, y;
|
||||||
|
|
||||||
x = UPSCALE( to->x );
|
x = UPSCALE( to->x );
|
||||||
y = UPSCALE( to->y );
|
y = UPSCALE( to->y );
|
||||||
aRasterFP->prev_x = x;
|
worker->prev_x = x;
|
||||||
aRasterFP->prev_y = y;
|
worker->prev_y = y;
|
||||||
// printf( "last point is {%f, %f}", lp.m_x, lp.m_y );
|
// printf( "last point is {%f, %f}", lp.m_x, lp.m_y );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
dense_line_to( const FT_Vector* to, RasterFP* aRasterFP )
|
dense_line_to( const FT_Vector* to, dense_worker* worker )
|
||||||
{
|
{
|
||||||
printf( "dense_line_to: %d, %d\n", to->x, to->y );
|
// printf( "dense_line_to: %d, %d\n", to->x, to->y );
|
||||||
RasterFP_Point tp = { UPSCALE( to->x ), UPSCALE( to->y ) };
|
dense_render_line( worker, UPSCALE( to->x ), UPSCALE( to->y ) );
|
||||||
RasterFP_DrawLine( aRasterFP, tp.m_x, tp.m_y );
|
dense_move_to( to, worker );
|
||||||
dense_move_to( to, aRasterFP );
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
void
|
void
|
||||||
|
@ -76,18 +75,18 @@ swapold( unsigned char* a, unsigned char* b )
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
RasterFP_DrawLine( RasterFP* aRasterFP, TPos to_x, TPos to_y )
|
dense_render_line( dense_worker* worker, TPos to_x, TPos to_y )
|
||||||
{
|
{
|
||||||
TPos from_x = aRasterFP->prev_x;
|
TPos from_x = worker->prev_x;
|
||||||
TPos from_y = aRasterFP->prev_y;
|
TPos from_y = worker->prev_y;
|
||||||
if ( from_y == to_y )
|
if ( from_y == to_y )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
/* @QUES: What is this code that I commented out, supposed to do?*/
|
/* @QUES: What is this code that I commented out, supposed to do?*/
|
||||||
// aP0.m_x -= aRasterFP->m_origin_x;
|
// aP0.m_x -= worker->m_origin_x;
|
||||||
// aP0.m_y -= aRasterFP->m_origin_y;
|
// aP0.m_y -= worker->m_origin_y;
|
||||||
// aP1.m_x -= aRasterFP->m_origin_x;
|
// aP1.m_x -= worker->m_origin_x;
|
||||||
// aP1.m_y -= aRasterFP->m_origin_y;
|
// aP1.m_y -= worker->m_origin_y;
|
||||||
|
|
||||||
from_x = TRUNC( (int)from_x );
|
from_x = TRUNC( (int)from_x );
|
||||||
from_y = TRUNC( (int)from_y );
|
from_y = TRUNC( (int)from_y );
|
||||||
|
@ -105,7 +104,7 @@ RasterFP_DrawLine( RasterFP* aRasterFP, TPos to_x, TPos to_y )
|
||||||
}
|
}
|
||||||
|
|
||||||
// Clip to the height.
|
// Clip to the height.
|
||||||
if ( from_y >= aRasterFP->m_h || to_y <= 0 )
|
if ( from_y >= worker->m_h || to_y <= 0 )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
float dxdy = ( to_x - from_x ) / (float)( to_y - from_y );
|
float dxdy = ( to_x - from_x ) / (float)( to_y - from_y );
|
||||||
|
@ -114,10 +113,10 @@ RasterFP_DrawLine( RasterFP* aRasterFP, TPos to_x, TPos to_y )
|
||||||
from_x -= from_y * dxdy;
|
from_x -= from_y * dxdy;
|
||||||
from_y = 0;
|
from_y = 0;
|
||||||
}
|
}
|
||||||
if ( to_y > aRasterFP->m_h )
|
if ( to_y > worker->m_h )
|
||||||
{
|
{
|
||||||
to_x -= ( to_y - aRasterFP->m_h ) * dxdy;
|
to_x -= ( to_y - worker->m_h ) * dxdy;
|
||||||
to_y = (float)aRasterFP->m_h;
|
to_y = (float)worker->m_h;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -130,11 +129,11 @@ RasterFP_DrawLine( RasterFP* aRasterFP, TPos to_x, TPos to_y )
|
||||||
asher I have a very strong feeling that this isn't necessary. Since probably
|
asher I have a very strong feeling that this isn't necessary. Since probably
|
||||||
the outline is already fitted in the bounding box. I tested this code a
|
the outline is already fitted in the bounding box. I tested this code a
|
||||||
little, removing it doesn't seem to make any difference*/
|
little, removing it doesn't seem to make any difference*/
|
||||||
RasterFP_Point intersect = { 0, 0 };
|
FT_Vector intersect = { 0, 0 };
|
||||||
int recursive = 0;
|
int recursive = 0;
|
||||||
if ( from_x >= aRasterFP->m_w && to_x >= aRasterFP->m_w )
|
if ( from_x >= worker->m_w && to_x >= worker->m_w )
|
||||||
{
|
{
|
||||||
from_x = to_x = (float)aRasterFP->m_w;
|
from_x = to_x = (float)worker->m_w;
|
||||||
dxdy = 0;
|
dxdy = 0;
|
||||||
}
|
}
|
||||||
else if ( from_x <= 0 && to_x <= 0 )
|
else if ( from_x <= 0 && to_x <= 0 )
|
||||||
|
@ -144,33 +143,33 @@ RasterFP_DrawLine( RasterFP* aRasterFP, TPos to_x, TPos to_y )
|
||||||
}
|
}
|
||||||
else if ( ( from_x < 0 ) != ( to_x < 0 ) )
|
else if ( ( from_x < 0 ) != ( to_x < 0 ) )
|
||||||
{
|
{
|
||||||
intersect.m_x = 0;
|
intersect.x = 0;
|
||||||
intersect.m_y = to_y - to_x / dxdy;
|
intersect.y = to_y - to_x / dxdy;
|
||||||
recursive = 1;
|
recursive = 1;
|
||||||
}
|
}
|
||||||
else if ( ( from_x > aRasterFP->m_w ) != ( to_x > aRasterFP->m_w ) )
|
else if ( ( from_x > worker->m_w ) != ( to_x > worker->m_w ) )
|
||||||
{
|
{
|
||||||
intersect.m_x = (float)aRasterFP->m_w;
|
intersect.x = worker->m_w;
|
||||||
intersect.m_y = from_y + ( aRasterFP->m_w - from_x ) / dxdy;
|
intersect.y = from_y + ( worker->m_w - from_x ) / dxdy;
|
||||||
recursive = 1;
|
recursive = 1;
|
||||||
}
|
}
|
||||||
if ( recursive )
|
if ( recursive )
|
||||||
{
|
{
|
||||||
from_x += aRasterFP->m_origin_x;
|
from_x += worker->m_origin_x;
|
||||||
from_y += aRasterFP->m_origin_y;
|
from_y += worker->m_origin_y;
|
||||||
to_x += aRasterFP->m_origin_x;
|
to_x += worker->m_origin_x;
|
||||||
to_y += aRasterFP->m_origin_y;
|
to_y += worker->m_origin_y;
|
||||||
intersect.m_x += aRasterFP->m_origin_x;
|
intersect.x += worker->m_origin_x;
|
||||||
intersect.m_y += aRasterFP->m_origin_y;
|
intersect.y += worker->m_origin_y;
|
||||||
if ( dir == 1 )
|
if ( dir == 1 )
|
||||||
{
|
{
|
||||||
RasterFP_DrawLine( aRasterFP, intersect.m_x, intersect.m_y );
|
dense_render_line( worker, intersect.x, intersect.y );
|
||||||
RasterFP_DrawLine( aRasterFP, to_x, to_y );
|
dense_render_line( worker, to_x, to_y );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
RasterFP_DrawLine( aRasterFP, intersect.m_x, intersect.m_y );
|
dense_render_line( worker, intersect.x, intersect.y );
|
||||||
RasterFP_DrawLine( aRasterFP, from_x, from_y );
|
dense_render_line( worker, from_x, from_y );
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -179,11 +178,11 @@ RasterFP_DrawLine( RasterFP* aRasterFP, TPos to_x, TPos to_y )
|
||||||
float x = from_x;
|
float x = from_x;
|
||||||
int y0 = (int)from_y;
|
int y0 = (int)from_y;
|
||||||
int y_limit = (int)ceil( to_y );
|
int y_limit = (int)ceil( to_y );
|
||||||
float* m_a = aRasterFP->m_a;
|
float* m_a = worker->m_a;
|
||||||
|
|
||||||
for ( int y = y0; y < y_limit; y++ )
|
for ( int y = y0; y < y_limit; y++ )
|
||||||
{
|
{
|
||||||
int linestart = y * aRasterFP->m_w;
|
int linestart = y * worker->m_w;
|
||||||
float dy = fmin( y + 1.0f, to_y ) - fmax( (float)y, from_y );
|
float dy = fmin( y + 1.0f, to_y ) - fmax( (float)y, from_y );
|
||||||
float xnext = x + dxdy * dy;
|
float xnext = x + dxdy * dy;
|
||||||
float d = dy * dir;
|
float d = dy * dir;
|
||||||
|
@ -244,21 +243,17 @@ RasterFP_DrawLine( RasterFP* aRasterFP, TPos to_x, TPos to_y )
|
||||||
static int
|
static int
|
||||||
dense_conic_to( const FT_Vector* control,
|
dense_conic_to( const FT_Vector* control,
|
||||||
const FT_Vector* to,
|
const FT_Vector* to,
|
||||||
RasterFP* aRasterFP )
|
dense_worker* worker )
|
||||||
{
|
{
|
||||||
// RasterFP_Point controlP = { UPSCALE(control->x), UPSCALE(control->y) };
|
dense_render_quadratic( worker, control, to );
|
||||||
// RasterFP_Point toP = { UPSCALE(to->x), UPSCALE(to->y) };
|
|
||||||
// RasterFP_Point lP = { aRasterFP->prev_x, aRasterFP->prev_y };
|
|
||||||
RasterFP_DrawQuadratic( aRasterFP, control, to );
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
RasterFP_DrawQuadratic( RasterFP* aRasterFP,
|
dense_render_quadratic( dense_worker* worker,
|
||||||
const FT_Vector* control,
|
const FT_Vector* control,
|
||||||
const FT_Vector* to )
|
const FT_Vector* to )
|
||||||
{
|
{
|
||||||
// assert( aRasterFP );
|
|
||||||
/*
|
/*
|
||||||
Calculate devsq as the square of four times the
|
Calculate devsq as the square of four times the
|
||||||
distance from the control point to the midpoint of the curve.
|
distance from the control point to the midpoint of the curve.
|
||||||
|
@ -271,23 +266,21 @@ RasterFP_DrawQuadratic( RasterFP* aRasterFP,
|
||||||
The division by four is omitted to save time.
|
The division by four is omitted to save time.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
RasterFP_Point aP0 = { aRasterFP->prev_x, aRasterFP->prev_y };
|
FT_Vector aP0 = { worker->prev_x, worker->prev_y };
|
||||||
RasterFP_Point aP1 = { UPSCALE( control->x ), UPSCALE( control->y ) };
|
FT_Vector aP1 = { UPSCALE( control->x ), UPSCALE( control->y ) };
|
||||||
RasterFP_Point aP2 = { UPSCALE( to->x ), UPSCALE( to->y ) };
|
FT_Vector aP2 = { UPSCALE( to->x ), UPSCALE( to->y ) };
|
||||||
|
|
||||||
|
float devx = aP0.x - aP1.x - aP1.x + aP2.x;
|
||||||
float devx = aP0.m_x - aP1.m_x - aP1.m_x + aP2.m_x;
|
float devy = aP0.y - aP1.y - aP1.y + aP2.y;
|
||||||
float devy = aP0.m_y - aP1.m_y - aP1.m_y + aP2.m_y;
|
|
||||||
float devsq = devx * devx + devy * devy;
|
float devsq = devx * devx + devy * devy;
|
||||||
|
|
||||||
if ( devsq < 0.333f )
|
if ( devsq < 0.333f )
|
||||||
{
|
{
|
||||||
RasterFP_DrawLine( aRasterFP, aP2.m_x, aP2.m_y );
|
dense_render_line( worker, aP2.x, aP2.y );
|
||||||
aRasterFP->prev_x = aP2.m_x;
|
worker->prev_x = aP2.x;
|
||||||
aRasterFP->prev_y = aP2.m_y;
|
worker->prev_y = aP2.y;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
According to Raph Levien, the reason for the subdivision by n (instead of
|
According to Raph Levien, the reason for the subdivision by n (instead of
|
||||||
|
@ -299,82 +292,78 @@ RasterFP_DrawQuadratic( RasterFP* aRasterFP,
|
||||||
expected to be 33% more in the limit".
|
expected to be 33% more in the limit".
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
const float tol = 3.0f;
|
||||||
const float tol = 3.0f;
|
int n = (int)floor( sqrt( sqrt( tol * devsq ) ) );
|
||||||
int n = (int)floor( sqrt( sqrt( tol * devsq ) ) );
|
FT_Vector p = aP0;
|
||||||
RasterFP_Point p = aP0;
|
float nrecip = 1.0f / ( n + 1.0f );
|
||||||
float nrecip = 1.0f / ( n + 1.0f );
|
float t = 0.0f;
|
||||||
float t = 0.0f;
|
|
||||||
for ( int i = 0; i < n; i++ )
|
for ( int i = 0; i < n; i++ )
|
||||||
{
|
{
|
||||||
t += nrecip;
|
t += nrecip;
|
||||||
RasterFP_Point next = Lerp( t, Lerp( t, aP0, aP1 ), Lerp( t, aP1, aP2 ) );
|
FT_Vector next = Lerp( t, Lerp( t, aP0, aP1 ), Lerp( t, aP1, aP2 ) );
|
||||||
RasterFP_DrawLine( aRasterFP, next.m_x, next.m_y );
|
dense_render_line( worker, next.x, next.y );
|
||||||
aRasterFP->prev_x = next.m_x;
|
worker->prev_x = next.x;
|
||||||
aRasterFP->prev_y = next.m_y;
|
worker->prev_y = next.y;
|
||||||
p = next;
|
p = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
RasterFP_DrawLine(aRasterFP,aP2.m_x,aP2.m_y);
|
dense_render_line( worker, aP2.x, aP2.y );
|
||||||
aRasterFP->prev_x = aP2.m_x;
|
worker->prev_x = aP2.x;
|
||||||
aRasterFP->prev_y = aP2.m_y;
|
worker->prev_y = aP2.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
dense_cubic_to( const FT_Vector* control1,
|
dense_cubic_to( const FT_Vector* control1,
|
||||||
const FT_Vector* control2,
|
const FT_Vector* control2,
|
||||||
const FT_Vector* to,
|
const FT_Vector* to,
|
||||||
RasterFP* aRasterFP )
|
dense_worker* worker )
|
||||||
{
|
{
|
||||||
RasterFP_Point ap1 = { UPSCALE( control1->x ), UPSCALE( control1->y ) };
|
dense_render_cubic( worker, control1, control2, to );
|
||||||
RasterFP_Point ap2 = { UPSCALE( control2->x ), UPSCALE( control2->y ) };
|
|
||||||
RasterFP_Point ap3 = { UPSCALE( to->x ), UPSCALE( to->y ) };
|
|
||||||
|
|
||||||
RasterFP_Point lP = { aRasterFP->prev_x, aRasterFP->prev_y };
|
|
||||||
|
|
||||||
RasterFP_DrawCubic( aRasterFP, lP, ap1, ap2, ap3 );
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
RasterFP_DrawCubic( RasterFP* aRasterFP,
|
dense_render_cubic( dense_worker* worker,
|
||||||
RasterFP_Point aP0,
|
FT_Vector* aP1,
|
||||||
RasterFP_Point aP1,
|
FT_Vector* aP2,
|
||||||
RasterFP_Point aP2,
|
FT_Vector* aP3 )
|
||||||
RasterFP_Point aP3 )
|
|
||||||
{
|
{
|
||||||
// assert( aRasterFP );
|
// assert( worker );
|
||||||
|
FT_Vector aP0 = { worker->prev_x, worker->prev_y };
|
||||||
float devx = aP0.m_x - aP1.m_x - aP1.m_x + aP2.m_x;
|
float devx = aP0.x - aP1->x - aP1->x + aP2->x;
|
||||||
float devy = aP0.m_y - aP1.m_y - aP1.m_y + aP2.m_y;
|
float devy = aP0.y - aP1->y - aP1->y + aP2->y;
|
||||||
float devsq0 = devx * devx + devy * devy;
|
float devsq0 = devx * devx + devy * devy;
|
||||||
devx = aP1.m_x - aP2.m_x - aP2.m_x + aP3.m_x;
|
devx = aP1->x - aP2->x - aP2->x + aP3->x;
|
||||||
devy = aP1.m_y - aP2.m_y - aP2.m_y + aP3.m_y;
|
devy = aP1->y - aP2->y - aP2->y + aP3->y;
|
||||||
float devsq1 = devx * devx + devy * devy;
|
float devsq1 = devx * devx + devy * devy;
|
||||||
float devsq = fmax( devsq0, devsq1 );
|
float devsq = fmax( devsq0, devsq1 );
|
||||||
|
|
||||||
if ( devsq < 0.333f )
|
if ( devsq < 0.333f )
|
||||||
{
|
{
|
||||||
RasterFP_DrawLine( aRasterFP, aP3.m_x, aP3.m_y );
|
dense_render_line( worker, aP3->x, aP3->y );
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const float tol = 3.0f;
|
const float tol = 3.0f;
|
||||||
int n = (int)floor( sqrt( sqrt( tol * devsq ) ) );
|
int n = (int)floor( sqrt( sqrt( tol * devsq ) ) );
|
||||||
RasterFP_Point p = aP0;
|
FT_Vector p = aP0;
|
||||||
float nrecip = 1.0f / ( n + 1.0f );
|
float nrecip = 1.0f / ( n + 1.0f );
|
||||||
float t = 0.0f;
|
float t = 0.0f;
|
||||||
for ( int i = 0; i < n; i++ )
|
for ( int i = 0; i < n; i++ )
|
||||||
{
|
{
|
||||||
t += nrecip;
|
t += nrecip;
|
||||||
RasterFP_Point a = Lerp( t, Lerp( t, aP0, aP1 ), Lerp( t, aP1, aP2 ) );
|
FT_Vector a = Lerp( t, Lerp( t, aP0, *aP1 ), Lerp( t, *aP1, *aP2 ) );
|
||||||
RasterFP_Point b = Lerp( t, Lerp( t, aP1, aP2 ), Lerp( t, aP2, aP3 ) );
|
FT_Vector b = Lerp( t, Lerp( t, *aP1, *aP2 ), Lerp( t, *aP2, *aP3 ) );
|
||||||
RasterFP_Point next = Lerp( t, a, b );
|
FT_Vector next = Lerp( t, a, b );
|
||||||
RasterFP_DrawLine( aRasterFP, next.m_x, next.m_y );
|
dense_render_line( worker, next.x, next.y );
|
||||||
p = next;
|
worker->prev_x = next.x;
|
||||||
|
worker->prev_y = next.y;
|
||||||
|
p = next;
|
||||||
}
|
}
|
||||||
|
|
||||||
RasterFP_DrawLine( aRasterFP, aP3.m_x, aP3.m_y );
|
dense_render_line( worker, aP3->x, aP3->y );
|
||||||
|
worker->prev_x = aP3->x;
|
||||||
|
worker->prev_y = aP3->y;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @QUES: This is the first method called on the module. I suspect
|
/* @QUES: This is the first method called on the module. I suspect
|
||||||
|
@ -389,7 +378,6 @@ dense_raster_new( FT_Memory memory, dense_PRaster* araster )
|
||||||
raster->memory = memory;
|
raster->memory = memory;
|
||||||
|
|
||||||
*araster = raster;
|
*araster = raster;
|
||||||
printf( "dense_raster_new\n" );
|
|
||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -397,7 +385,6 @@ dense_raster_new( FT_Memory memory, dense_PRaster* araster )
|
||||||
static void
|
static void
|
||||||
dense_raster_done( FT_Raster raster )
|
dense_raster_done( FT_Raster raster )
|
||||||
{
|
{
|
||||||
printf( "dense_raster_done\n" );
|
|
||||||
|
|
||||||
FT_Memory memory = (FT_Memory)( (dense_PRaster)raster )->memory;
|
FT_Memory memory = (FT_Memory)( (dense_PRaster)raster )->memory;
|
||||||
|
|
||||||
|
@ -412,7 +399,6 @@ dense_raster_reset( FT_Raster raster,
|
||||||
FT_UNUSED( raster );
|
FT_UNUSED( raster );
|
||||||
FT_UNUSED( pool_base );
|
FT_UNUSED( pool_base );
|
||||||
FT_UNUSED( pool_size );
|
FT_UNUSED( pool_size );
|
||||||
printf( "dense_raster_reset\n" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* @QUES: This methodisnt't called in normal ftlint execution*/
|
/* @QUES: This methodisnt't called in normal ftlint execution*/
|
||||||
|
@ -423,7 +409,6 @@ dense_raster_set_mode( FT_Raster raster, unsigned long mode, void* args )
|
||||||
FT_UNUSED( mode );
|
FT_UNUSED( mode );
|
||||||
FT_UNUSED( args );
|
FT_UNUSED( args );
|
||||||
|
|
||||||
printf( "dense_raster_set_mode\n" );
|
|
||||||
return 0; /* nothing to do */
|
return 0; /* nothing to do */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -439,49 +424,18 @@ FT_DEFINE_OUTLINE_FUNCS( dense_decompose_funcs,
|
||||||
)
|
)
|
||||||
|
|
||||||
/* @QUES: So, this calls FT_Outline_Decompose, that calls the move to,
|
/* @QUES: So, this calls FT_Outline_Decompose, that calls the move to,
|
||||||
line to, conic to, cubic to interface methods. The aRasterFP structure stores
|
line to, conic to, cubic to interface methods. The worker structure stores
|
||||||
the well, stuff in its m_a and finally renders it to the target->buffer*/
|
the well, stuff in its m_a and finally renders it to the target->buffer*/
|
||||||
static int
|
static int
|
||||||
dense_render_glyph( RasterFP* aRasterFP, const FT_Bitmap* target )
|
dense_render_glyph( dense_worker* worker, const FT_Bitmap* target )
|
||||||
{
|
{
|
||||||
FT_Error error = FT_Outline_Decompose( &( aRasterFP->outline ),
|
FT_Error error = FT_Outline_Decompose( &( worker->outline ),
|
||||||
&dense_decompose_funcs, aRasterFP );
|
&dense_decompose_funcs, worker );
|
||||||
// Render into bitmap
|
// Render into bitmap
|
||||||
const float* source = aRasterFP->m_a;
|
const float* source = worker->m_a;
|
||||||
|
|
||||||
// printf( "Outputting bitmap\n" );
|
|
||||||
// for ( int i = 0; i < aRasterFP->m_h; i++ )
|
|
||||||
// {
|
|
||||||
// printf( "\n" );
|
|
||||||
// for ( int j = 0; j < aRasterFP->m_w; j++ )
|
|
||||||
// {
|
|
||||||
// float strength = *( source + ( i * aRasterFP->m_w + j ) );
|
|
||||||
// if ( strength > 0.90 )
|
|
||||||
// {
|
|
||||||
// printf( "@|" );
|
|
||||||
// }
|
|
||||||
// else if ( strength > 0.70 )
|
|
||||||
// {
|
|
||||||
// printf( "#|" );
|
|
||||||
// }
|
|
||||||
// else if ( strength > 0.45 )
|
|
||||||
// {
|
|
||||||
// printf( "+|" );
|
|
||||||
// }
|
|
||||||
// else if ( strength > 0.20 )
|
|
||||||
// {
|
|
||||||
// printf( "*|" );
|
|
||||||
// }
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// printf( ".|" );
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// printf( "\n" );
|
|
||||||
|
|
||||||
unsigned char* dest = target->buffer;
|
unsigned char* dest = target->buffer;
|
||||||
unsigned char* dest_end = target->buffer + aRasterFP->m_w * aRasterFP->m_h;
|
unsigned char* dest_end = target->buffer + worker->m_w * worker->m_h;
|
||||||
float value = 0.0f;
|
float value = 0.0f;
|
||||||
while ( dest < dest_end )
|
while ( dest < dest_end )
|
||||||
{
|
{
|
||||||
|
@ -498,15 +452,14 @@ dense_render_glyph( RasterFP* aRasterFP, const FT_Bitmap* target )
|
||||||
dest++;
|
dest++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for ( int col = 0; col < aRasterFP->m_w; col++ )
|
for ( int col = 0; col < worker->m_w; col++ )
|
||||||
{
|
{
|
||||||
for ( int row = 0; row < aRasterFP->m_h / 2; row++ )
|
for ( int row = 0; row < worker->m_h / 2; row++ )
|
||||||
{
|
{
|
||||||
// printf("Swapping position: %d, %d with %d, %d with rows = %d, cols =
|
// printf("Swapping position: %d, %d with %d, %d with rows = %d, cols =
|
||||||
// %d",row,col, aRasterFP->m_h-row, col, aRasterFP->m_h, aRasterFP->m_w);
|
// %d",row,col, worker->m_h-row, col, worker->m_h, worker->m_w);
|
||||||
swapold( target->buffer + aRasterFP->m_w * row + col,
|
swapold( target->buffer + worker->m_w * row + col,
|
||||||
target->buffer + ( aRasterFP->m_h - row - 1 ) * aRasterFP->m_w +
|
target->buffer + ( worker->m_h - row - 1 ) * worker->m_w + col );
|
||||||
col );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -518,12 +471,12 @@ rendered pixels*/
|
||||||
static int
|
static int
|
||||||
dense_raster_render( FT_Raster raster, const FT_Raster_Params* params )
|
dense_raster_render( FT_Raster raster, const FT_Raster_Params* params )
|
||||||
{
|
{
|
||||||
printf( "dense_raster_render\n" );
|
|
||||||
|
|
||||||
const FT_Outline* outline = (const FT_Outline*)params->source;
|
const FT_Outline* outline = (const FT_Outline*)params->source;
|
||||||
const FT_Bitmap* target_map = params->target;
|
const FT_Bitmap* target_map = params->target;
|
||||||
|
|
||||||
RasterFP* aRasterFP = malloc( sizeof( RasterFP ) );
|
//dense_worker* worker = malloc( sizeof( dense_worker ) );
|
||||||
|
dense_worker worker[1];
|
||||||
|
|
||||||
if ( !raster )
|
if ( !raster )
|
||||||
return FT_THROW( Invalid_Argument );
|
return FT_THROW( Invalid_Argument );
|
||||||
|
@ -531,7 +484,7 @@ dense_raster_render( FT_Raster raster, const FT_Raster_Params* params )
|
||||||
if ( !outline )
|
if ( !outline )
|
||||||
return FT_THROW( Invalid_Outline );
|
return FT_THROW( Invalid_Outline );
|
||||||
|
|
||||||
aRasterFP->outline = *outline;
|
worker->outline = *outline;
|
||||||
|
|
||||||
if ( !target_map )
|
if ( !target_map )
|
||||||
return FT_THROW( Invalid_Argument );
|
return FT_THROW( Invalid_Argument );
|
||||||
|
@ -543,25 +496,24 @@ dense_raster_render( FT_Raster raster, const FT_Raster_Params* params )
|
||||||
if ( !target_map->buffer )
|
if ( !target_map->buffer )
|
||||||
return FT_THROW( Invalid_Argument );
|
return FT_THROW( Invalid_Argument );
|
||||||
|
|
||||||
aRasterFP->m_origin_x = 0;
|
worker->m_origin_x = 0;
|
||||||
aRasterFP->m_origin_y = 0;
|
worker->m_origin_y = 0;
|
||||||
/* @QUES: Why are my bitmaps upsied down 😭*/
|
/* @QUES: Why are my bitmaps upsied down 😭*/
|
||||||
aRasterFP->m_w = target_map->pitch;
|
worker->m_w = target_map->pitch;
|
||||||
aRasterFP->m_h = target_map->rows;
|
worker->m_h = target_map->rows;
|
||||||
|
|
||||||
int size = aRasterFP->m_w * aRasterFP->m_h + 4;
|
int size = worker->m_w * worker->m_h + 4;
|
||||||
|
|
||||||
aRasterFP->m_a = malloc( sizeof( float ) * size );
|
worker->m_a = malloc( sizeof( float ) * size );
|
||||||
aRasterFP->m_a_size = size;
|
worker->m_a_size = size;
|
||||||
|
|
||||||
memset( aRasterFP->m_a, 0, ( sizeof( float ) * size ) );
|
memset( worker->m_a, 0, ( sizeof( float ) * size ) );
|
||||||
/* exit if nothing to do */
|
/* exit if nothing to do */
|
||||||
if ( aRasterFP->m_w <= aRasterFP->m_origin_x ||
|
if ( worker->m_w <= worker->m_origin_x || worker->m_h <= worker->m_origin_y )
|
||||||
aRasterFP->m_h <= aRasterFP->m_origin_y )
|
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
return dense_render_glyph( aRasterFP, target_map );
|
return dense_render_glyph( worker, target_map );
|
||||||
}
|
}
|
||||||
|
|
||||||
FT_DEFINE_RASTER_FUNCS(
|
FT_DEFINE_RASTER_FUNCS(
|
||||||
|
|
|
@ -2,57 +2,12 @@
|
||||||
#ifndef FTDENSE_H_
|
#ifndef FTDENSE_H_
|
||||||
#define FTDENSE_H_
|
#define FTDENSE_H_
|
||||||
|
|
||||||
|
|
||||||
#include <ft2build.h>
|
#include <ft2build.h>
|
||||||
#include FT_CONFIG_CONFIG_H
|
#include FT_CONFIG_CONFIG_H
|
||||||
#include <freetype/ftimage.h>
|
#include <freetype/ftimage.h>
|
||||||
|
|
||||||
FT_BEGIN_HEADER
|
FT_BEGIN_HEADER
|
||||||
|
|
||||||
/**************************************************************************
|
|
||||||
*
|
|
||||||
* @struct:
|
|
||||||
* SDF_Raster_Params
|
|
||||||
*
|
|
||||||
* @description:
|
|
||||||
* This struct must be passed to the raster render function
|
|
||||||
* @FT_Raster_RenderFunc instead of @FT_Raster_Params because the
|
|
||||||
* rasterizer requires some additional information to render properly.
|
|
||||||
*
|
|
||||||
* @fields:
|
|
||||||
* root ::
|
|
||||||
* The native raster parameters structure.
|
|
||||||
*
|
|
||||||
* spread ::
|
|
||||||
* This is an essential parameter/property required by the renderer.
|
|
||||||
* `spread` defines the maximum unsigned value that is present in the
|
|
||||||
* final SDF output. For the default value check file
|
|
||||||
* `ftsdfcommon.h`.
|
|
||||||
*
|
|
||||||
* flip_sign ::
|
|
||||||
* By default positive values indicate positions inside of contours,
|
|
||||||
* i.e., filled by a contour. If this property is true then that
|
|
||||||
* output will be the opposite of the default, i.e., negative values
|
|
||||||
* indicate positions inside of contours.
|
|
||||||
*
|
|
||||||
* flip_y ::
|
|
||||||
* Setting this parameter to true maked the output image flipped
|
|
||||||
* along the y-axis.
|
|
||||||
*
|
|
||||||
* overlaps ::
|
|
||||||
* Set this to true to generate SDF for glyphs having overlapping
|
|
||||||
* contours. The overlapping support is limited to glyphs that do not
|
|
||||||
* have self-intersecting contours. Also, removing overlaps require a
|
|
||||||
* considerable amount of extra memory; additionally, it will not work
|
|
||||||
* if generating SDF from bitmap.
|
|
||||||
*
|
|
||||||
* @note:
|
|
||||||
* All properties are valid for both the 'sdf' and 'bsdf' renderers; the
|
|
||||||
* exception is `overlaps`, which gets ignored by the 'bsdf' renderer.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/* rasterizer to convert outline to SDF */
|
|
||||||
#ifndef FT_EXPORT_VAR
|
#ifndef FT_EXPORT_VAR
|
||||||
#define FT_EXPORT_VAR( x ) extern x
|
#define FT_EXPORT_VAR( x ) extern x
|
||||||
#endif
|
#endif
|
||||||
|
@ -85,12 +40,7 @@ extern "C"
|
||||||
{
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
typedef long TPos;
|
typedef long TPos;
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
float m_x;
|
|
||||||
float m_y;
|
|
||||||
} RasterFP_Point;
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
@ -110,26 +60,21 @@ extern "C"
|
||||||
FT_Pos prev_x, prev_y;
|
FT_Pos prev_x, prev_y;
|
||||||
|
|
||||||
FT_Outline outline;
|
FT_Outline outline;
|
||||||
} RasterFP;
|
} dense_worker;
|
||||||
|
|
||||||
void RasterFP_Create( RasterFP* aRasterFP );
|
void dense_render_line( dense_worker* aRasterFP, TPos to_x, TPos to_y );
|
||||||
void RasterFP_Destroy( RasterFP* aRasterFP );
|
void dense_render_quadratic( dense_worker* aRasterFP,
|
||||||
void RasterFP_DrawLine( RasterFP* aRasterFP, TPos to_x, TPos to_y );
|
const FT_Vector* control,
|
||||||
void RasterFP_DrawQuadratic( RasterFP* aRasterFP,
|
const FT_Vector* to );
|
||||||
const FT_Vector* control,
|
void dense_render_cubic( dense_worker* aRasterFP,
|
||||||
const FT_Vector* to );
|
FT_Vector* aP1,
|
||||||
void RasterFP_DrawCubic( RasterFP* aRasterFP,
|
FT_Vector* aP2,
|
||||||
RasterFP_Point aP0,
|
FT_Vector* aP3 );
|
||||||
RasterFP_Point aP1,
|
|
||||||
RasterFP_Point aP2,
|
|
||||||
RasterFP_Point aP3 );
|
|
||||||
void RasterFP_GetBitmap( RasterFP* aRasterFP, unsigned char* aBitmap );
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
FT_END_HEADER
|
FT_END_HEADER
|
||||||
|
|
||||||
#endif /* FTDENSE_H_ */
|
#endif /* FTDENSE_H_ */
|
||||||
|
|
|
@ -32,7 +32,6 @@ initial properties of the renderer ??? */
|
||||||
static FT_Error
|
static FT_Error
|
||||||
ft_dense_init( FT_Renderer render )
|
ft_dense_init( FT_Renderer render )
|
||||||
{
|
{
|
||||||
printf( "ft_dense_init\n" );
|
|
||||||
return FT_Err_Ok;
|
return FT_Err_Ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,7 +40,6 @@ so, I guess this is unnecessary ??? */
|
||||||
static void
|
static void
|
||||||
ft_dense_done( FT_Renderer render )
|
ft_dense_done( FT_Renderer render )
|
||||||
{
|
{
|
||||||
printf( "ft_dense_done\n" );
|
|
||||||
FT_UNUSED( render );
|
FT_UNUSED( render );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -56,7 +54,6 @@ ft_dense_render( FT_Renderer render,
|
||||||
FT_Render_Mode mode,
|
FT_Render_Mode mode,
|
||||||
const FT_Vector* origin )
|
const FT_Vector* origin )
|
||||||
{
|
{
|
||||||
printf( "ft_dense_render\n" );
|
|
||||||
FT_Error error = FT_Err_Ok;
|
FT_Error error = FT_Err_Ok;
|
||||||
FT_Outline* outline = &slot->outline;
|
FT_Outline* outline = &slot->outline;
|
||||||
FT_Bitmap* bitmap = &slot->bitmap;
|
FT_Bitmap* bitmap = &slot->bitmap;
|
||||||
|
@ -155,7 +152,6 @@ ft_dense_transform( FT_Renderer render,
|
||||||
const FT_Matrix* matrix,
|
const FT_Matrix* matrix,
|
||||||
const FT_Vector* delta )
|
const FT_Vector* delta )
|
||||||
{
|
{
|
||||||
printf( "ft_dense_transform\n" );
|
|
||||||
|
|
||||||
FT_Error error = FT_Err_Ok;
|
FT_Error error = FT_Err_Ok;
|
||||||
|
|
||||||
|
@ -180,7 +176,6 @@ Exit:
|
||||||
static void
|
static void
|
||||||
ft_dense_get_cbox( FT_Renderer render, FT_GlyphSlot slot, FT_BBox* cbox )
|
ft_dense_get_cbox( FT_Renderer render, FT_GlyphSlot slot, FT_BBox* cbox )
|
||||||
{
|
{
|
||||||
printf( "ft_dense_get_cbox\n" );
|
|
||||||
|
|
||||||
FT_ZERO( cbox );
|
FT_ZERO( cbox );
|
||||||
|
|
||||||
|
|
|
@ -876,12 +876,9 @@ typedef ptrdiff_t FT_PtrDist;
|
||||||
TCoord fx1, fy1, fx2, fy2;
|
TCoord fx1, fy1, fx2, fy2;
|
||||||
TCoord ex1, ey1, ex2, ey2;
|
TCoord ex1, ey1, ex2, ey2;
|
||||||
|
|
||||||
// printf( "Line from {%li, %li} to {%li, %li}, with a maximum dimensions of %d by %d\n", ras.x, ras.y, to_x,
|
|
||||||
// to_y, ras.max_ex, ras.max_ey );
|
|
||||||
ey1 = TRUNC( ras.y );
|
ey1 = TRUNC( ras.y );
|
||||||
ey2 = TRUNC( to_y );
|
ey2 = TRUNC( to_y );
|
||||||
|
|
||||||
// printf("Truncation reduced prev y from %ld to %d\n", ras.y, ey1);
|
|
||||||
|
|
||||||
/* perform vertical clipping */
|
/* perform vertical clipping */
|
||||||
if ( ( ey1 >= ras.max_ey && ey2 >= ras.max_ey ) ||
|
if ( ( ey1 >= ras.max_ey && ey2 >= ras.max_ey ) ||
|
||||||
|
@ -1451,7 +1448,6 @@ typedef ptrdiff_t FT_PtrDist;
|
||||||
gray_line_to( const FT_Vector* to,
|
gray_line_to( const FT_Vector* to,
|
||||||
gray_PWorker worker )
|
gray_PWorker worker )
|
||||||
{
|
{
|
||||||
printf("gray_line_to: %d, %d\n", to->x, to->y);
|
|
||||||
gray_render_line( RAS_VAR_ UPSCALE( to->x ), UPSCALE( to->y ) );
|
gray_render_line( RAS_VAR_ UPSCALE( to->x ), UPSCALE( to->y ) );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue