[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[freetype2-demos] master 918300b: [ftbench] Permit reverse order of indi
From: |
Alexei Podtelezhnikov |
Subject: |
[freetype2-demos] master 918300b: [ftbench] Permit reverse order of indices. |
Date: |
Thu, 17 Sep 2020 01:03:25 -0400 (EDT) |
branch: master
commit 918300b80e1908d633f5ce7ee615e8ca431ec671
Author: Alexei Podtelezhnikov <apodtele@gmail.com>
Commit: Alexei Podtelezhnikov <apodtele@gmail.com>
[ftbench] Permit reverse order of indices.
Some compressed streams are really bad in rewinding.
* src/ftbench.c (FOREACH): General loop in either direction.
(test_*): Use it.
(main): Parse forward and reverse index ranges.
(usage): Document it.
* man/ftbench.1: Ditto.
---
ChangeLog | 12 +++++++
man/ftbench.1 | 13 ++------
src/ftbench.c | 101 ++++++++++++++++++++++++++++++----------------------------
3 files changed, 68 insertions(+), 58 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index ff110a9..71fc470 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2020-09-17 Alexei Podtelezhnikov <apodtele@gmail.com>
+
+ [ftbench] Permit reverse order of indices.
+
+ Some compressed streams are really bad in rewinding.
+
+ * src/ftbench.c (FOREACH): General loop in either direction.
+ (test_*): Use it.
+ (main): Parse forward and reverse index ranges.
+ (usage): Document it.
+ * man/ftbench.1: Ditto.
+
2020-09-16 Alexei Podtelezhnikov <apodtele@gmail.com>
* src/*: Fix some -Wformat-signedness warnings.
diff --git a/man/ftbench.1 b/man/ftbench.1
index 801c624..7eafe42 100644
--- a/man/ftbench.1
+++ b/man/ftbench.1
@@ -100,16 +100,9 @@ call
without an argument to get the actual list.
.
.TP
-.BI \-i \ idx
-Start with glyph index
-.I idx
-(default is 0).
-.
-.TP
-.BI \-j \ idx
-End with glyph index
-.I idx
-(default is the number of glyphs minus one).
+.BI \-i \ I-J
+Forward or reverse range of glyph indices to use
+(default is from 0 to the number of glyphs minus one).
.
.TP
.BI \-m \ m
diff --git a/src/ftbench.c b/src/ftbench.c
index e7d3e4a..69c1db6 100644
--- a/src/ftbench.c
+++ b/src/ftbench.c
@@ -129,7 +129,7 @@
"get glyph bbox (FT_Outline_Get_BBox)",
"get glyph cbox (FT_Glyph_Get_CBox)",
- "open face and load glyph",
+ "open face and load glyphs",
NULL
};
@@ -139,6 +139,12 @@
static unsigned int first_index = 0U;
static unsigned int last_index = ~0U;
+ static int incr_index = 1;
+
+#define FOREACH( i ) for ( i = first_index ; \
+ ( first_index <= i && i <= last_index ) || \
+ ( first_index >= i && i >= last_index ) ; \
+ i += incr_index )
static FT_Render_Mode render_mode = FT_RENDER_MODE_NORMAL;
static FT_Int32 load_flags = FT_LOAD_DEFAULT;
@@ -274,7 +280,7 @@
TIMER_START( timer );
- for ( i = first_index; i <= last_index; i++ )
+ FOREACH( i )
{
if ( !FT_Load_Glyph( face, i, load_flags ) )
done++;
@@ -294,19 +300,26 @@
int done = 0;
FT_Fixed* advances;
FT_ULong flags = *((FT_ULong*)user_data);
+ FT_UInt start, count;
+
+ if ( incr_index > 0 )
+ {
+ start = first_index;
+ count = last_index - first_index + 1;
+ }
+ else
+ {
+ start = last_index;
+ count = first_index - last_index + 1;
+ }
- advances = (FT_Fixed *)calloc( sizeof ( FT_Fixed ),
- (size_t)face->num_glyphs );
+ advances = (FT_Fixed *)calloc( sizeof ( FT_Fixed ), (size_t)count );
TIMER_START( timer );
- FT_Get_Advances( face,
- first_index,
- last_index - first_index + 1,
- (FT_Int32)flags,
- advances );
- done += (int)( last_index - first_index ) + 1;
+ FT_Get_Advances( face, start, count, (FT_Int32)flags, advances );
+ done += (int)count;
TIMER_STOP( timer );
@@ -327,7 +340,7 @@
FT_UNUSED( user_data );
- for ( i = first_index; i <= last_index; i++ )
+ FOREACH( i )
{
if ( FT_Load_Glyph( face, i, load_flags ) )
continue;
@@ -353,7 +366,7 @@
FT_UNUSED( user_data );
- for ( i = first_index; i <= last_index; i++ )
+ FOREACH( i )
{
if ( FT_Load_Glyph( face, i, load_flags ) )
continue;
@@ -387,7 +400,7 @@
FT_STROKER_LINEJOIN_ROUND,
0 );
- for ( i = first_index; i <= last_index; i++ )
+ FOREACH( i )
{
if ( FT_Load_Glyph( face, i, load_flags ) )
continue;
@@ -419,7 +432,7 @@
FT_UNUSED( user_data );
- for ( i = first_index; i <= last_index; i++ )
+ FOREACH( i )
{
if ( FT_Load_Glyph( face, i, load_flags ) )
continue;
@@ -450,7 +463,7 @@
FT_UNUSED( user_data );
- for ( i = first_index; i <= last_index; i++ )
+ FOREACH( i )
{
if ( FT_Load_Glyph( face, i, load_flags ) )
continue;
@@ -483,7 +496,7 @@
FT_UNUSED( user_data );
- for ( i = first_index; i <= last_index; i++ )
+ FOREACH( i )
{
FT_Outline* outline;
@@ -585,7 +598,7 @@
TIMER_START( timer );
- for ( i = first_index; i <= last_index; i++ )
+ FOREACH( i )
{
if ( !FTC_ImageCache_Lookup( image_cache,
&font_type,
@@ -622,7 +635,7 @@
TIMER_START( timer );
- for ( i = first_index; i <= last_index; i++ )
+ FOREACH( i )
{
if ( !FTC_SBitCache_Lookup( sbit_cache,
&font_type,
@@ -701,7 +714,7 @@
if ( !get_face( &bench_face ) )
{
- for ( i = first_index; i <= last_index; i++ )
+ FOREACH( i )
{
if ( !FT_Load_Glyph( bench_face, i, load_flags ) )
done++;
@@ -726,7 +739,7 @@
{
FT_ULong charcode;
FT_UInt gindex;
- int i;
+ int i = 0;
charset->code = (FT_ULong*)calloc( (size_t)face->num_glyphs,
@@ -736,7 +749,6 @@
if ( face->charmap )
{
- i = 0;
charcode = FT_Get_First_Char( face, &gindex );
/* certain fonts contain a broken charmap that will map character */
@@ -744,7 +756,8 @@
/* */
while ( gindex && i < face->num_glyphs )
{
- if ( gindex >= first_index && gindex <= last_index )
+ if ( ( first_index <= gindex && gindex <= last_index ) ||
+ ( first_index >= gindex && gindex >= last_index ) )
charset->code[i++] = charcode;
charcode = FT_Get_Next_Char( face, charcode, &gindex );
}
@@ -755,8 +768,8 @@
/* no charmap, do an identity mapping */
- for ( i = 0, j = first_index; j <= last_index; i++, j++ )
- charset->code[i] = j;
+ FOREACH( j )
+ charset->code[i++] = j;
}
charset->size = i;
@@ -873,8 +886,8 @@
" Available versions are %s; default is `%s'.\n"
" -I VER Use TT interpreter version VER.\n"
" Available versions are %s; default is version %u.\n"
- " -i IDX Start with index IDX (default is 0).\n"
- " -j IDX End with index IDX (default is number of glyphs minus
one).\n"
+ " -i I-J Forward or reverse range of glyph indices to use\n"
+ " (default is from 0 to the number of glyphs minus one).\n"
" -l N Set LCD filter to N\n"
" 0: none, 1: default, 2: light, 16: legacy\n"
" -m M Set maximum cache size to M KiByte (default is %d).\n",
@@ -999,7 +1012,7 @@
int opt;
- opt = getopt( argc, argv, "b:Cc:f:H:I:i:j:l:m:pr:s:t:v" );
+ opt = getopt( argc, argv, "b:Cc:f:H:I:i:l:m:pr:s:t:v" );
if ( opt == -1 )
break;
@@ -1070,21 +1083,13 @@
case 'i':
{
- int fi = atoi( optarg );
-
-
- if ( fi > 0 )
- first_index = (unsigned int)fi;
- }
- break;
-
- case 'j':
- {
- int li = atoi( optarg );
-
+ unsigned int fi, li;
- if ( li > 0 )
- last_index = (unsigned int)li;
+ if ( sscanf( optarg, "%u%*[,:-]%u", &fi, &li ) == 2 )
+ {
+ first_index = fi;
+ last_index = li;
+ }
}
break;
@@ -1182,10 +1187,11 @@
if ( get_face( &face ) )
goto Exit;
- if ( last_index >= (unsigned int)face->num_glyphs )
- last_index = (unsigned int)face->num_glyphs - 1;
- if ( last_index < first_index )
- last_index = first_index;
+ if ( first_index >= (unsigned int)face->num_glyphs )
+ first_index = (unsigned int)face->num_glyphs - 1;
+ if ( last_index >= (unsigned int)face->num_glyphs )
+ last_index = (unsigned int)face->num_glyphs - 1;
+ incr_index = last_index > first_index ? 1 : -1;
if ( size )
{
@@ -1243,8 +1249,7 @@
max_time );
printf( "\n"
- "first glyph index: %u\n"
- "last glyph index: %u\n"
+ "glyph indices: from %u to %u\n"
"face size: %uppem\n"
"font preloading into memory: %s\n",
first_index,
@@ -1413,7 +1418,7 @@
break;
case FT_BENCH_NEW_FACE_AND_LOAD_GLYPH:
- test.title = "Create face & load glyph(s)";
+ test.title = "New_Face & load glyph(s)";
test.bench = test_new_face_and_load_glyph;
benchmark( face, &test, max_iter, max_time );
break;
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [freetype2-demos] master 918300b: [ftbench] Permit reverse order of indices.,
Alexei Podtelezhnikov <=