Commit aae6defd authored by Pope Kim's avatar Pope Kim
Browse files

changed rounding behavior of float to int color conversion from floor() to round().

This is huge especially for the low values because human eyes distinguish darker colors much better.
parent 32319fd1
...@@ -63,20 +63,20 @@ namespace Svg ...@@ -63,20 +63,20 @@ namespace Svg
if (alphaDecimal <= 1) if (alphaDecimal <= 1)
{ {
alphaValue = (int)(alphaDecimal * 255); alphaValue = (int)Math.Round(alphaDecimal * 255);
} }
else else
{ {
alphaValue = (int)alphaDecimal; alphaValue = (int)Math.Round(alphaDecimal);
} }
} }
Color colorpart; Color colorpart;
if (values[0].Trim().EndsWith("%")) if (values[0].Trim().EndsWith("%"))
{ {
colorpart = System.Drawing.Color.FromArgb(alphaValue, (int)(255 * float.Parse(values[0].Trim().TrimEnd('%')) / 100f), colorpart = System.Drawing.Color.FromArgb(alphaValue, (int)Math.Round(255 * float.Parse(values[0].Trim().TrimEnd('%')) / 100f),
(int)(255 * float.Parse(values[1].Trim().TrimEnd('%')) / 100f), (int)Math.Round(255 * float.Parse(values[1].Trim().TrimEnd('%')) / 100f),
(int)(255 * float.Parse(values[2].Trim().TrimEnd('%')) / 100f)); (int)Math.Round(255 * float.Parse(values[2].Trim().TrimEnd('%')) / 100f));
} }
else else
{ {
...@@ -260,7 +260,7 @@ namespace Svg ...@@ -260,7 +260,7 @@ namespace Svg
break; break;
} }
} }
Color rgb = Color.FromArgb( (int)( r * 255.0 ), (int)( g * 255.0 ), (int)( b * 255.0f ) ); Color rgb = Color.FromArgb( (int)Math.Round( r * 255.0 ), (int)Math.Round( g * 255.0 ), (int)Math.Round( b * 255.0 ) );
return rgb; return rgb;
} }
......
...@@ -40,7 +40,7 @@ namespace Svg ...@@ -40,7 +40,7 @@ namespace Svg
//is none? //is none?
if (this == SvgPaintServer.None) return new SolidBrush(System.Drawing.Color.Transparent); if (this == SvgPaintServer.None) return new SolidBrush(System.Drawing.Color.Transparent);
int alpha = (int)((opacity * (this.Colour.A/255.0f) ) * 255); int alpha = (int)Math.Round((opacity * (this.Colour.A/255.0) ) * 255);
Color colour = System.Drawing.Color.FromArgb(alpha, this.Colour); Color colour = System.Drawing.Color.FromArgb(alpha, this.Colour);
return new SolidBrush(colour); return new SolidBrush(colour);
......
...@@ -185,7 +185,7 @@ namespace Svg ...@@ -185,7 +185,7 @@ namespace Svg
radial radial
? 1 - (currentStop.Offset.ToDeviceValue(renderer, UnitRenderingType.Horizontal, this) / boundWidth) ? 1 - (currentStop.Offset.ToDeviceValue(renderer, UnitRenderingType.Horizontal, this) / boundWidth)
: (currentStop.Offset.ToDeviceValue(renderer, UnitRenderingType.Horizontal, this) / boundWidth); : (currentStop.Offset.ToDeviceValue(renderer, UnitRenderingType.Horizontal, this) / boundWidth);
colour = System.Drawing.Color.FromArgb((int)(mergedOpacity * 255), currentStop.GetColor(this)); colour = System.Drawing.Color.FromArgb((int)Math.Round(mergedOpacity * 255), currentStop.GetColor(this));
actualStops++; actualStops++;
......
...@@ -87,7 +87,7 @@ namespace Svg ...@@ -87,7 +87,7 @@ namespace Svg
if (this.Stops.Count == 1) if (this.Stops.Count == 1)
{ {
var stopColor = this.Stops[0].GetColor(renderingElement); var stopColor = this.Stops[0].GetColor(renderingElement);
int alpha = (int)((opacity * (stopColor.A/255.0f) ) * 255); int alpha = (int)Math.Round((opacity * (stopColor.A/255.0f) ) * 255);
Color colour = System.Drawing.Color.FromArgb(alpha, stopColor); Color colour = System.Drawing.Color.FromArgb(alpha, stopColor);
return new SolidBrush(colour); return new SolidBrush(colour);
} }
......
...@@ -147,7 +147,7 @@ namespace Svg ...@@ -147,7 +147,7 @@ namespace Svg
{ {
var stop = Stops.Last(); var stop = Stops.Last();
var origColor = stop.GetColor(renderingElement); var origColor = stop.GetColor(renderingElement);
var renderColor = System.Drawing.Color.FromArgb((int)(opacity * stop.Opacity * 255), origColor); var renderColor = System.Drawing.Color.FromArgb((int)Math.Round(opacity * stop.Opacity * 255), origColor);
var origClip = renderer.GetClip(); var origClip = renderer.GetClip();
try try
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment