From 4ccdc9f98291fe40c2e32cc9914e327810d845ec Mon Sep 17 00:00:00 2001 From: Alexei Podtelezhnikov Date: Mon, 20 May 2024 18:53:57 -0400 Subject: [PATCH] [cff] Optimize the blend vector computations. * src/cff/cffload.c (cff_blend_build_vector): Use FT_MulDiv and skip multiplying by 1. --- src/cff/cffload.c | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src/cff/cffload.c b/src/cff/cffload.c index a23fa4d12..d4f1ef5ff 100644 --- a/src/cff/cffload.c +++ b/src/cff/cffload.c @@ -1495,44 +1495,41 @@ for ( j = 0; j < lenNDV; j++ ) { CFF_AxisCoords* axis = &varRegion->axisList[j]; - FT_Fixed axisScalar; /* compute the scalar contribution of this axis; */ /* ignore invalid ranges */ if ( axis->startCoord > axis->peakCoord || axis->peakCoord > axis->endCoord ) - axisScalar = FT_FIXED_ONE; + continue; else if ( axis->startCoord < 0 && axis->endCoord > 0 && axis->peakCoord != 0 ) - axisScalar = FT_FIXED_ONE; + continue; /* peak of 0 means ignore this axis */ else if ( axis->peakCoord == 0 ) - axisScalar = FT_FIXED_ONE; + continue; /* ignore this region if coords are out of range */ else if ( NDV[j] < axis->startCoord || NDV[j] > axis->endCoord ) - axisScalar = 0; - - /* calculate a proportional factor */ - else { - if ( NDV[j] == axis->peakCoord ) - axisScalar = FT_FIXED_ONE; - else if ( NDV[j] < axis->peakCoord ) - axisScalar = FT_DivFix( NDV[j] - axis->startCoord, - axis->peakCoord - axis->startCoord ); - else - axisScalar = FT_DivFix( axis->endCoord - NDV[j], - axis->endCoord - axis->peakCoord ); + blend->BV[master] = 0; + break; } - /* take product of all the axis scalars */ - blend->BV[master] = FT_MulFix( blend->BV[master], axisScalar ); + /* adjust proportionally */ + else if ( NDV[j] < axis->peakCoord ) + blend->BV[master] = FT_MulDiv( blend->BV[master], + NDV[j] - axis->startCoord, + axis->peakCoord - axis->startCoord ); + + else if ( NDV[j] > axis->peakCoord ) + blend->BV[master] = FT_MulDiv( blend->BV[master], + axis->endCoord - NDV[j], + axis->endCoord - axis->peakCoord ); } FT_TRACE4(( ", %f ",