added the new "smooth" anti-aliaser

(see the file "demos/src/ftgrays.c"),

and modified "ftview" and "fttimer" to use it..

Note that this thing is still under heavy beta..
This commit is contained in:
David Turner 2000-03-08 14:14:55 +00:00
parent e98e4af73c
commit 291afa0992
5 changed files with 1656 additions and 10 deletions

View File

@ -182,6 +182,9 @@ else
$(OBJ_)ftlint.$O: $(SRC_DIR_)ftlint.c
$(COMPILE) $T$@ $<
$(OBJ_)ftgrays.$O: $(SRC_DIR_)ftgrays.c
$(COMPILE) $T$@ $<
$(OBJ_)fttry.$O: $(SRC_DIR_)fttry.c
$(COMPILE) $T$@ $<
@ -243,11 +246,11 @@ else
$(LINK)
$(BIN_)ftview$E: $(OBJ_)ftview.$O $(FTLIB) $(GRAPH_LIB) $(COMMON_OBJ)
$(GRAPH_LINK)
$(BIN_)ftview$E: $(OBJ_)ftview.$O $(FTLIB) $(GRAPH_LIB) $(COMMON_OBJ) $(OBJ_)ftgrays.$O
$(GRAPH_LINK) $(OBJ_)ftgrays.$O
$(BIN_)fttimer$E: $(OBJ_)fttimer.$O $(FTLIB) $(GRAPH_LIB) $(COMMON_OBJ)
$(GRAPH_LINK)
$(BIN_)fttimer$E: $(OBJ_)fttimer.$O $(FTLIB) $(GRAPH_LIB) $(COMMON_OBJ) $(OBJ_)ftgrays.$O
$(GRAPH_LINK) $(OBJ_)ftgrays.$O
endif

1526
demos/src/ftgrays.c Normal file

File diff suppressed because it is too large Load Diff

78
demos/src/ftgrays.h Normal file
View File

@ -0,0 +1,78 @@
#ifndef FTGRAYS_H
#define FTGRAYS_H
typedef int TScan;
typedef long TPos;
typedef float TDist;
#define FT_MAX_GRAY_SPANS 32
typedef struct FT_GraySpan_
{
short x;
short len;
unsigned char coverage;
} FT_GraySpan;
typedef int (*FT_GraySpan_Func)( int y,
int count,
FT_GraySpan* spans,
void* user );
typedef struct TCell_
{
TScan x;
TScan y;
int area;
int cover;
} TCell, *PCell;
typedef struct TRaster_
{
PCell cells;
int max_cells;
int num_cells;
TScan min_ex, max_ex;
TScan min_ey, max_ey;
int area;
int cover;
int invalid;
TScan ex, ey;
TScan cx, cy;
TPos x, y;
TScan last_ey;
FT_Vector bez_stack[32*3];
int lev_stack[32];
FT_Outline outline;
FT_Bitmap target;
FT_GraySpan gray_spans[ FT_MAX_GRAY_SPANS ];
int num_gray_spans;
FT_GraySpan_Func render_span;
void* render_span_closure;
int span_y;
} TRaster, *PRaster;
extern
int grays_raster_render( TRaster* raster,
FT_Outline* outline,
FT_Bitmap* target_map );
extern
int grays_raster_init( FT_Raster raster,
const char* pool_base,
long pool_size );
#endif

View File

@ -28,6 +28,7 @@
#include <time.h> /* for clock() */
#include "graph.h"
#include "ftgrays.h"
/* SunOS 4.1.* does not define CLOCKS_PER_SEC, so include <sys/param.h> */
/* to get the HZ macro which is the equivalent. */
@ -66,6 +67,7 @@
int pixel_size = CHARSIZE;
int repeat_count = 1;
int use_grays = 0;
FT_Bitmap Bit;
grBitmap bit;
@ -79,6 +81,11 @@
short gray_render; /* smooth fonts with gray levels */
short force_low;
TRaster raster;
#define RASTER_BUFF_SIZE 128000
char raster_buff[ RASTER_BUFF_SIZE ];
static void Clear_Buffer();
@ -212,7 +219,10 @@
FT_Error ConvertRaster( int index )
{
outlines[index].outline_flags |= ~ft_outline_single_pass;
return FT_Get_Outline_Bitmap( library, &outlines[index], &Bit );
if (use_grays)
return grays_raster_render( &raster, &outlines[index], &Bit );
else
return FT_Get_Outline_Bitmap( library, &outlines[index], &Bit );
}
@ -226,6 +236,7 @@
fprintf( stderr, " -s : character pixel size (default is 600)\n" );
fprintf( stderr, " -v : display results..\n" );
fprintf( stderr, " -g : render anti-aliased glyphs\n" );
fprintf( stderr, " -a : use smooth anti-aliaser\n" );
fprintf( stderr, " -l : force low quality even at small sizes\n" );
exit(1);
}
@ -256,6 +267,10 @@
gray_render = 1;
break;
case 'a':
use_grays = 1;
break;
case 'l':
force_low = 1;
break;
@ -318,6 +333,9 @@
if ( (error = FT_Init_FreeType( &library )) )
Panic( "Error while initializing engine" );
error = grays_raster_init( (FT_Raster)&raster, (const char*)raster_buff, RASTER_BUFF_SIZE );
if (error) Panic( "Could not initialize smooth anti-aliasing renderer" );
/* Load face */
error = FT_New_Face( library, filename, 0, &face );

View File

@ -27,6 +27,8 @@
#include "graph.h"
#include "grfont.h"
#include "ftgrays.h"
#define DIM_X 500
#define DIM_Y 400
@ -71,6 +73,12 @@
int graph_init = 0;
int render_mode = 1;
int use_grays = 1;
TRaster raster;
#define RASTER_BUFF_SIZE 32768
char raster_buff[ RASTER_BUFF_SIZE ];
#define DEBUGxxx
@ -137,7 +145,7 @@
static
char bit_buffer[ MAX_BUFFER ];
/* Render a single glyph */
/* Render a single glyph with the "grays" component */
static FT_Error Render_Glyph( int x_offset,
int y_offset )
{
@ -182,8 +190,11 @@
if (low_prec)
glyph->outline.outline_flags &= ~ft_outline_high_precision;
FT_Get_Outline_Bitmap( library, &glyph->outline, &bit2 );
if (use_grays & gray_render)
error = grays_raster_render( &raster, &glyph->outline, &bit2 );
else
error = FT_Get_Outline_Bitmap( library, &glyph->outline, &bit2 );
}
else
{
@ -207,7 +218,6 @@
return 0;
}
static FT_Error Reset_Scale( int pointSize )
{
FT_Error error;
@ -258,7 +268,7 @@
i = first_glyph;
while ( i < num_glyphs )
while ( i < num_glyphs )
{
if ( !(error = LoadChar( i, hinted )) )
{
@ -381,6 +391,7 @@
grWriteln(" h : toggle outline hinting" );
grWriteln(" b : toggle embedded bitmaps" );
grWriteln(" l : toggle low precision rendering" );
grWriteln(" g : toggle between 'smooth' and 'standard' anti-aliaser" );
grWriteln(" space : toggle rendering mode" );
grLn();
grWriteln(" Up : increase pointsize by 1 unit" );
@ -434,6 +445,13 @@
case grKEY('p'):
return (int)event->key;
case grKEY('g'):
use_grays = !use_grays;
new_header = ( use_grays
? "now using the smooth anti-aliaser"
: "now using the standard anti-aliaser" );
break;
case grKEY('l'):
low_prec = !low_prec;
new_header = ( low_prec
@ -579,6 +597,9 @@
error = FT_Init_FreeType( &library );
if (error) PanicZ( "Could not initialise FreeType library" );
error = grays_raster_init( (FT_Raster)&raster, (const char*)raster_buff, RASTER_BUFF_SIZE );
if (error) PanicZ( "Could not initialize anti-aliasing renderer" );
/* FT_Set_Raster_Palette( library, 17, palette_17 ); */
NewFile: