-
-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rasterizing artifacts when rendering line with DrawLines #15
Comments
Same problem here, workaround is to disable antialiasing |
Might be related to (or actually the same issue as) SixLabors/ImageSharp#572 and SixLabors/Shapes/#42. @tocsoft is my supposition right? |
yeah, looks like its going to be the exact same root issues. |
This is indeed a duplicate of SixLabors/ImageSharp#572. I've verified it now works ok after the fix, see attached image. |
Closing now as in nightlies |
Shouldn't be fixed yet. We still need a PR updating shapes. |
I thought the PR was in no? |
@JimBobSquarePants only in SL.Shapes: SixLabors/Shapes#43 We need to update the reference to have these issues closed. |
Fixed with SixLabors/ImageSharp#596 in beta4. |
Any plans to put fix in a nuget package? |
@jjxtra It was back in May 2018. https://www.nuget.org/packages/SixLabors.ImageSharp/1.0.0-beta0004 Are you still seeing issues with either beta6 or the latest nightly builds from MyGet? |
Yes with beta 6. Rendering us state lines onto an image, I am seeing horizontal gray lines if anti alias is on. |
Code is fairly straightforward, geo-json file... using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using Newtonsoft.Json.Linq;
using SixLabors.Primitives;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using SixLabors.ImageSharp;
using SixLabors.Shapes;
namespace ImageCreator
{
class ImageCreatorApp
{
private static IEnumerable<IReadOnlyList<PointF>> EnumerateLines(JToken geometry)
{
// map the longitude (horizontal) to 0 - 360
// map the latitude (vertical) to 0 - 180
string type = geometry["type"].ToString();
List<PointF> line = new List<PointF>();
if (type.Equals("multipolygon", StringComparison.OrdinalIgnoreCase))
{
foreach (JArray polygonGroup in geometry["coordinates"])
{
foreach (JArray polygon in polygonGroup)
{
foreach (JToken coord in polygon)
{
float lon = coord[0].Value<float>() + 180.0f;
if (lon > 180.0)
{
lon = (360.0f - lon);
}
float lat = coord[1].Value<float>() + 90.0f;
if (lat > 90.0f)
{
lat = (180.0f - lat);
}
line.Add(new PointF(lon, lat));
}
yield return line;
line.Clear();
}
}
}
else if (type.Equals("polygon", StringComparison.OrdinalIgnoreCase))
{
foreach (JArray polygon in geometry["coordinates"])
{
foreach (JToken coord in polygon)
{
float lon = coord[0].Value<float>() + 180.0f;
if (lon > 180.0)
{
lon = (360.0f - lon);
}
float lat = coord[1].Value<float>() + 90.0f;
if (lat > 90.0f)
{
lat = (180.0f - lat);
}
line.Add(new PointF(lon, lat));
}
yield return line;
line.Clear();
}
}
}
public static int Main(string[] args)
{
if (args.Length == 0)
{
Console.WriteLine("Pass geo-json files as arguments");
return -1;
}
// have to acquire the ranges first...
List<JToken> fileTokens = new List<JToken>();
float minLat = float.MaxValue;
float minLon = float.MaxValue;
float maxLat = float.MinValue;
float maxLon = float.MinValue;
foreach (string file in args)
{
JObject token = JObject.Parse(File.ReadAllText(file));
fileTokens.Add(token);
var results = token.Descendants().OfType<JProperty>().Where(t => t.Name == "geometry").Select(t => t.Value);
foreach (JToken geometry in results)
{
foreach (PointF coord in EnumerateLines(geometry).SelectMany(l => l))
{
minLon = Math.Min(minLon, coord.X);
minLat = Math.Min(minLat, coord.Y);
maxLon = Math.Max(maxLon, coord.X);
maxLat = Math.Max(maxLat, coord.Y);
}
}
}
float rangeLon = 1.0f / MathF.Abs(maxLon - minLon);
float rangeLat = 1.0f / MathF.Abs(maxLat - minLat);
float width = 4096.0f;
float height = 2048.0f;
float maxWidth = (width - 1.0f);
float maxHeight = (height - 1.0f);
SixLabors.ImageSharp.Image<Rgba32> img = new SixLabors.ImageSharp.Image<Rgba32>((int)width, (int)height);
img.Mutate(m => m.Fill(Rgba32.Black));
GraphicsOptions options = new GraphicsOptions { Antialias = false };
foreach (JObject fileToken in fileTokens)
{
var results = fileToken.Descendants().OfType<JProperty>().Where(t => t.Name == "geometry").Select(t => t.Value);
foreach (JToken geometry in results)
{
foreach (List<PointF> line in EnumerateLines(geometry))
{
for (int i = 0; i < line.Count; i++)
{
line[i] = new PointF
(
Math.Min(maxWidth, (int)Math.Round(width * (1.0f - (rangeLon * MathF.Abs(maxLon - line[i].X))))),
Math.Min(maxHeight, (int)Math.Round(height * (1.0f - (rangeLat * MathF.Abs(maxLat - line[i].Y)))))
);
}
if (line.Count > 3)
{
img.Mutate(m => m.DrawLines(options, Rgba32.White, 1.0f, line.ToArray()));
}
}
}
}
img.Save(File.OpenWrite(@"image.png"), new SixLabors.ImageSharp.Formats.Png.PngEncoder());
return 0;
}
}
} |
@jjxtra No need to do the additional testing for now. Cause is here. https://github.com/SixLabors/Shapes/issues/44 We can use your information to formulate a fix. |
Awesome, let me know if you need more info. |
Sorry, wrong dll. The latest master branch as of 2019-08-21 still has the anti-alias line issue. |
Closing as Duplicate of #5. |
Description
When plotting a graph using DrawLines, if the curve crosses the same y coordinate multiple times, some unwanted horizontal lines are being rendered.
Steps to Reproduce
Here's code producing the issue displayed in the image below. Artifacts are particularly visible on the bottom right corner.
System Configuration
The text was updated successfully, but these errors were encountered: