qskExtractedGradientStops fixed (

https://github.com/uwerat/qskinny/issues/374 )
This commit is contained in:
Uwe Rathmann 2024-02-01 10:02:49 +01:00
parent 59c2e8ca33
commit 2e34bfd4c6
1 changed files with 48 additions and 25 deletions

View File

@ -293,44 +293,67 @@ QColor qskInterpolatedColorAt( const QskGradientStops& stops, qreal pos ) noexce
} }
QskGradientStops qskExtractedGradientStops( QskGradientStops qskExtractedGradientStops(
const QskGradientStops& stops, qreal from, qreal to ) const QskGradientStops& gradientStops, qreal from, qreal to )
{ {
if ( ( from > to ) || ( from > 1.0 ) || stops.isEmpty() ) if ( ( from > to ) || ( from > 1.0 ) || gradientStops.isEmpty() )
return QskGradientStops(); return QskGradientStops();
if ( ( from <= 0.0 ) && ( to >= 1.0 ) ) if ( ( from <= 0.0 ) && ( to >= 1.0 ) )
return stops; return gradientStops;
from = qMax( from, 0.0 ); from = qMax( from, 0.0 );
to = qMin( to, 1.0 ); to = qMin( to, 1.0 );
QVector< QskGradientStop > extracted; QVector< QskGradientStop > stops1 = gradientStops;
extracted.reserve( stops.count() );
#if 1
// not the most efficient implementation - maybe later TODO ...
if ( stops1.first().position() > 0.0 )
stops1.prepend( QskGradientStop( 0.0, stops1.first().color() ) );
if ( stops1.last().position() < 1.0 )
stops1.append( QskGradientStop( 1.0, stops1.last().color() ) );
#endif
QVector< QskGradientStop > stops2;
stops2.reserve( stops1.count() );
if ( stops1.count() == 2 )
{
const auto rgb1 = stops1.first().rgb();
const auto rgb2 = stops1.last().rgb();
stops2 += QskGradientStop( 0.0, QskRgb::interpolated( rgb1, rgb2, from ) );
stops2 += QskGradientStop( 1.0, QskRgb::interpolated( rgb1, rgb2, to ) );
}
else
{
int i = 0; int i = 0;
for ( ; i < stops.count(); i++ ) for ( ; i < stops1.count(); i++ )
{ {
if ( stops[i].position() > from ) if ( stops1[i].position() > from )
break; break;
} }
extracted += QskGradientStop( 0.0, stops2 += QskGradientStop( 0.0,
qskInterpolatedColor( stops, i - 1, i, from ) ); qskInterpolatedColor( stops1, i - 1, i, from ) );
for ( ; i < stops.count(); i++ ) for ( ; i < stops1.count(); i++ )
{ {
if ( stops[i].position() >= to ) if ( stops1[i].position() >= to )
break; break;
const auto pos = ( stops[i].position() - from ) / ( to - from ); const auto pos = ( stops1[i].position() - from ) / ( to - from );
extracted += QskGradientStop( pos, stops[i].color() ); stops2 += QskGradientStop( pos, stops1[i].color() );
} }
extracted += QskGradientStop( 1.0, stops2 += QskGradientStop( 1.0,
qskInterpolatedColor( stops, i, i + 1, to ) ); qskInterpolatedColor( stops1, i, i + 1, to ) );
}
return extracted; return stops2;
} }
QskGradientStops qskRevertedGradientStops( const QskGradientStops& stops ) QskGradientStops qskRevertedGradientStops( const QskGradientStops& stops )