[cff] Optimize the blend vector computations.

* src/cff/cffload.c (cff_blend_build_vector): Use FT_MulDiv and skip
multiplying by 1.
This commit is contained in:
Alexei Podtelezhnikov 2024-05-20 18:53:57 -04:00
parent b25265fe55
commit 4ccdc9f982
1 changed files with 15 additions and 18 deletions

View File

@ -1495,44 +1495,41 @@
for ( j = 0; j < lenNDV; j++ ) for ( j = 0; j < lenNDV; j++ )
{ {
CFF_AxisCoords* axis = &varRegion->axisList[j]; CFF_AxisCoords* axis = &varRegion->axisList[j];
FT_Fixed axisScalar;
/* compute the scalar contribution of this axis; */ /* compute the scalar contribution of this axis; */
/* ignore invalid ranges */ /* ignore invalid ranges */
if ( axis->startCoord > axis->peakCoord || if ( axis->startCoord > axis->peakCoord ||
axis->peakCoord > axis->endCoord ) axis->peakCoord > axis->endCoord )
axisScalar = FT_FIXED_ONE; continue;
else if ( axis->startCoord < 0 && else if ( axis->startCoord < 0 &&
axis->endCoord > 0 && axis->endCoord > 0 &&
axis->peakCoord != 0 ) axis->peakCoord != 0 )
axisScalar = FT_FIXED_ONE; continue;
/* peak of 0 means ignore this axis */ /* peak of 0 means ignore this axis */
else if ( axis->peakCoord == 0 ) else if ( axis->peakCoord == 0 )
axisScalar = FT_FIXED_ONE; continue;
/* ignore this region if coords are out of range */ /* ignore this region if coords are out of range */
else if ( NDV[j] < axis->startCoord || else if ( NDV[j] < axis->startCoord ||
NDV[j] > axis->endCoord ) NDV[j] > axis->endCoord )
axisScalar = 0;
/* calculate a proportional factor */
else
{ {
if ( NDV[j] == axis->peakCoord ) blend->BV[master] = 0;
axisScalar = FT_FIXED_ONE; break;
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 );
} }
/* take product of all the axis scalars */ /* adjust proportionally */
blend->BV[master] = FT_MulFix( blend->BV[master], axisScalar ); 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 ", FT_TRACE4(( ", %f ",