Skip to content

Commit f1ff754

Browse files
author
volker
committed
For the function 'colorize-image' make the parameter 'contrast_color'
optional.
1 parent 8abac2a commit f1ff754

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

src/com/inet/lib/less/CustomFunctionColorizeImage.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ class CustomFunctionColorizeImage implements CustomLessFunction {
5151
@Override
5252
@SuppressFBWarnings( value = "URLCONNECTION_SSRF_FD", justification = "Caller of JLessC must check this" )
5353
public void appendTo( CssFormatter formatter, List<Expression> parameters ) throws IOException {
54-
if( parameters.size() < 4 ) {
55-
throw new LessException( "error evaluating function colorize-image expects url, main_color, contrast_color " );
54+
if( parameters.size() < 3 ) {
55+
throw new LessException( "error evaluating function 'colorize-image' expects parameters: url, main_color, contrast_color " );
5656
}
5757

5858
String relativeURL = parameters.get( 0 ).stringValue( formatter );
@@ -61,7 +61,6 @@ public void appendTo( CssFormatter formatter, List<Expression> parameters ) thro
6161
String urlStr = UrlUtils.removeQuote( urlString );
6262
url = new URL( url, urlStr );
6363
int mainColor = ColorUtils.argb( ColorUtils.getColor( parameters.get( 2 ), formatter ) );
64-
int contrastColor = ColorUtils.argb( ColorUtils.getColor( parameters.get( 3 ), formatter ) );
6564

6665
BufferedImage loadedImage = ImageIO.read( url.openStream() );
6766

@@ -74,7 +73,13 @@ public void appendTo( CssFormatter formatter, List<Expression> parameters ) thro
7473
bGr.dispose();
7574

7675
final float[] mainColorHsb = Color.RGBtoHSB( (mainColor >> 16) & 0xFF, (mainColor >> 8) & 0xFF, mainColor & 0xFF, null );
77-
final float[] contrastColorHsb = Color.RGBtoHSB( (contrastColor >> 16) & 0xFF, (contrastColor >> 8) & 0xFF, contrastColor & 0xFF, null );
76+
final float[] contrastColorHsb;
77+
if( parameters.size() > 3 ) {
78+
int contrastColor = ColorUtils.argb( ColorUtils.getColor( parameters.get( 3 ), formatter ) );
79+
contrastColorHsb = Color.RGBtoHSB( (contrastColor >> 16) & 0xFF, (contrastColor >> 8) & 0xFF, contrastColor & 0xFF, null );
80+
} else {
81+
contrastColorHsb = mainColorHsb;
82+
}
7883

7984
// get the pixel data
8085
WritableRaster raster = image.getRaster();

0 commit comments

Comments
 (0)