Skip to content

Commit

Permalink
Updated dependencies, removed patches, add new ones
Browse files Browse the repository at this point in the history
- Updated to .NET 5
- Updated ImageSharp.Drawing. Some bugs have been fixed, others introduced.
- Fixed score drawing bugs and faulty event asset
  • Loading branch information
atruskie committed Nov 30, 2020
1 parent c97268f commit 3bdb893
Show file tree
Hide file tree
Showing 25 changed files with 239 additions and 142 deletions.
1 change: 1 addition & 0 deletions AudioAnalysis.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
Directory.Build.props = Directory.Build.props
build\download_ap.ps1 = build\download_ap.ps1
src\git_version.ps1 = src\git_version.ps1
global.json = global.json
README.md = README.md
style.ruleset = style.ruleset
stylecop.json = stylecop.json
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"sdk": {
"version": "3.1.201",
"version": "5.0.100",
"rollForward": "feature"
}
}
10 changes: 8 additions & 2 deletions src/AED/AED.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
<PackageReference Include="FSharp.Core" Version="5.0.0" />
<PackageReference Include="MathNet.Numerics.FSharp" Version="4.12.0" />
<PackageReference Include="SixLabors.Fonts" Version="1.0.0-unstable0058" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.2" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-unstable0456" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.3-alpha.0.7" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta11" />
</ItemGroup>
<ItemGroup>
<Compile Include="Util.fs" />
Expand All @@ -26,4 +26,10 @@
<ProjectReference Include="..\Acoustics.Shared.FSharp\Acoustics.Shared.FSharp.fsproj" />
<ProjectReference Include="..\TowseyLibrary\TowseyLibrary.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Update="StyleCop.Analyzers" Version="1.2.0-beta.261">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
2 changes: 1 addition & 1 deletion src/AcousticWorkbench/AcousticWorkbench.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.164">
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.261">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
6 changes: 6 additions & 0 deletions src/Acoustics.Shared.FSharp/Acoustics.Shared.FSharp.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,10 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<PackageReference Update="StyleCop.Analyzers" Version="1.2.0-beta.261">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
</Project>
20 changes: 10 additions & 10 deletions src/Acoustics.Shared/Acoustics.Shared.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyTitle>Acoustics.Shared</AssemblyTitle>
Expand All @@ -15,7 +15,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="ConsoleTools" Version="0.5.4" />
<PackageReference Include="CsvHelper" Version="16.0.0" />
<PackageReference Include="CsvHelper" Version="16.2.0" />
<PackageReference Include="FastMember" Version="1.5.0" />
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" />
<PackageReference Include="log4net" Version="2.0.12" />
Expand All @@ -24,23 +24,23 @@
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="3.1.6" />
<PackageReference Include="Microsoft.DotNet.PlatformAbstractions" Version="5.0.0-preview.5.20278.1" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="3.1.9" />
<PackageReference Include="Mono.Posix.NETStandard" Version="1.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="5.0.0" />
<PackageReference Include="Mono.Posix.NETStandard" Version="5.20.1-preview" />
<PackageReference Include="morelinq" Version="3.3.2" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.3" />
<PackageReference Include="ObjectCloner" Version="2.2.2" />
<PackageReference Include="ObjectCloner.Extensions" Version="2.0.1" />
<PackageReference Include="SixLabors.Fonts" Version="1.0.0-unstable0058" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.2" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-unstable0456" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.3-alpha.0.7" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta11" />
<PackageReference Include="SQLitePCLRaw.bundle_green" Version="2.0.4" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.164">
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.261">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="System.IO.Abstractions" Version="12.2.24" />
<PackageReference Include="YamlDotNet" Version="8.1.2" />
<PackageReference Include="System.IO.Abstractions" Version="13.2.1" />
<PackageReference Include="YamlDotNet" Version="9.1.0" />
</ItemGroup>
</Project>
143 changes: 93 additions & 50 deletions src/Acoustics.Shared/ImageSharp/Drawing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Acoustics.Shared.ImageSharp
using System.Linq;
using SixLabors.Fonts;
using SixLabors.ImageSharp;
using SixLabors.ImageSharp.Drawing;
using SixLabors.ImageSharp.Drawing.Processing;
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
Expand Down Expand Up @@ -47,12 +48,15 @@ public static class Drawing
GraphicsOptions = new GraphicsOptions()
{
Antialias = false,
BlendPercentage = 1,
ColorBlendingMode = PixelColorBlendingMode.Normal,
AntialiasSubpixelDepth = 0,
//BlendPercentage = 1,
//ColorBlendingMode = PixelColorBlendingMode.Normal,
//AntialiasSubpixelDepth = 0,

},
ShapeOptions = new ShapeOptions()
{
//IntersectionRule = SixLabors.ImageSharp.Drawing.IntersectionRule.Nonzero,
},

//IntersectionRule = IntersectionRule.OddEven,
};

/// <summary>
Expand Down Expand Up @@ -182,6 +186,32 @@ public static GlyphMetric[] MeasureCharacters(string text, Font font, PointF loc
/// </summary>
public class NoAA
{
/// <summary>
/// Defines behaviour for where to draw stroke relative to the true real line
/// defined by a path.
/// </summary>
//public enum Basis
//{
// /// <summary>
// /// Draws the line pixels either left of or above the target line.
// /// Essentially on the side of the line that is closer to canvas origin.
// /// </summary>
// LeftTop = -1,

// /// <summary>
// /// Draws the line using the default ImageSharp method, which splits stroke
// /// evenly over either side of the middle line.
// /// </summary>
// Straddle = 0,

// /// <summary>
// /// Draws the line pixels either right of or below the target line.
// /// Essentially on the side of the line that is further from the canvas origin.
// /// </summary>
// RightBottom = 1,
//}

// // AT 2020-11: Update bug seems to be fixed.
public static readonly PointF Bug28Offset = new PointF(0.0f, 0.5f);

private readonly IImageProcessingContext context;
Expand All @@ -193,31 +223,45 @@ public NoAA(IImageProcessingContext context)

public void DrawLine(IPen pen, int x1, int y1, int x2, int y2)
{
this.DrawLines(pen, new Point(x1, y1), new Point(x2, y2));
this.DrawLines(pen, new PointF(x1, y1), new PointF(x2, y2));
}

//public void DrawLine(IPen pen, int x1, int y1, int x2, int y2, Basis basis)
//{
// if (basis is not Basis.Straddle)
// {
// basis = basis switch {

// }
// }
//}

public void DrawLines(IPen pen, params PointF[] points)
{
// i've no idea why, but repeating the first point and last point
// and adding random offsets in reduces visual errors in line drawing!
var slope = points[0].Y.CompareTo(points[^1].Y) switch
{
-1 => 0.0f,
0 => 0,
1 => 0.5f,
_ => throw new NotImplementedException(),
};
var offset = new PointF(slope, Bug28Offset.Y);
// https://github.com/SixLabors/ImageSharp.Drawing/issues/108
var strokeBugOffset = pen.StrokeWidth / 2f;
int strokeBugEncountered = 0;
var offset = new PointF(0, PenOffset(pen.StrokeWidth));
var modifiedPoints = points
.Select(p => p + offset)
.Prepend(points[0] + Bug28Offset)
.Append(points[^1] + Bug28Offset)
.Select(p =>
{
if ((p.Y - strokeBugOffset) < 0)
{
strokeBugEncountered++;
return new PointF(p.X, 0f + MathF.Round(strokeBugOffset / 2f));
}

return p;
})
.ToArray();

this.context.DrawLines(
NoAntiAlias,
pen,
modifiedPoints);
if (strokeBugEncountered > points.Length - 1)
{
pen = new Pen(pen.StrokeFill, MathF.Max(1, MathF.Round(strokeBugOffset)), pen.StrokePattern.ToArray());
}

this.context.DrawLines(NoAntiAlias, pen, modifiedPoints);
}

public void DrawLines(Color color, float thickness, params PointF[] points)
Expand All @@ -228,8 +272,8 @@ public void DrawLines(Color color, float thickness, params PointF[] points)
public void DrawRectangle(Pen pen, int x1, int y1, int x2, int y2)
{
var r = RectangleF.FromLTRB(x1, y1, x2, y2);
r.Offset(Bug28Offset);
this.context.Draw(Drawing.NoAntiAlias, pen, r);
//r.Offset(Bug28Offset);
this.context.Draw(NoAntiAlias, pen, r);
}

/// <summary>
Expand All @@ -239,14 +283,14 @@ public void DrawRectangle(Pen pen, int x1, int y1, int x2, int y2)
public void DrawRectangle(Color color, int x1, int y1, int x2, int y2, float thickness = 1f)
{
var r = RectangleF.FromLTRB(x1, y1, x2, y2);
r.Offset(Bug28Offset);
this.context.Draw(Drawing.NoAntiAlias, color, thickness, r);
//r.Offset(Bug28Offset);
this.context.Draw(NoAntiAlias, color, thickness, r);
}

public void DrawRectangle(Pen border, RectangleF rectangle)
{
rectangle.Offset(Bug28Offset);
this.context.Draw(Drawing.NoAntiAlias, border, rectangle);
//rectangle.Offset(Bug28Offset);
this.context.Draw(NoAntiAlias, border, rectangle);
}

/// <summary>
Expand All @@ -258,44 +302,43 @@ public void DrawRectangle(Pen border, RectangleF rectangle)
/// ImageSharp's Draw Rectangle is unpredictable and buggy, especially for
/// non-antialiased operations. See <c>Acoustics.Test.Shared.Drawing.RectangleCornerBugTest</c>.
/// This method instead draws four lines as the border.
/// // AT 2020-11: Update bug seems to be fixed.
/// </remarks>
public void DrawBorderInset(Pen border, RectangleF rectangle)
{
// rounder border thickness
border = new Pen(
border.StrokeFill,
MathF.Round(border.StrokeWidth),
MathF.Floor(border.StrokeWidth),
border.StrokePattern.ToArray());

// first round rectangle to nice coordinates
var rect = Rectangle.Round(rectangle);

// construct point coordinats, offset by pen width inset into rectangle.
var penOffset = MathF.Floor(border.StrokeWidth / 2f);

// empircally found to satisfy tests - i have no idea why it works
var widthAdjustment = ((int)border.StrokeWidth % 2) == 0 ? 0.0f : -0.5f;

float left = rect.Left + penOffset + 0.0f;
float top = rect.Top + penOffset + +Bug28Offset.Y;
float right = rect.Right - penOffset + widthAdjustment;
float bottom = rect.Bottom - penOffset + Bug28Offset.Y + widthAdjustment;

this.context.DrawPolygon(
NoAntiAlias,
border,
new PointF(left, top),
new PointF(right, top),
new PointF(right, bottom),
new PointF(left, bottom),
new PointF(left, top));
// construct point coordinates, offset by pen width inset into rectangle.
// the offset wiggle by 0.5 of a pixel defeats the ImageSharp method of straddling a border over
// the imaginary centerline of the segment. Without this a border of 2px will be rendered with round
// corners and 3px wide.
var penOffset = MathF.Floor(border.StrokeWidth / 2.0f) + PenOffset(border.StrokeWidth);

float left = rect.Left + penOffset;
float top = rect.Top + penOffset;
float right = rect.Right - penOffset - 1;
float bottom = rect.Bottom - penOffset - 1;

this.context.Draw(NoAntiAlias, border, RectangleF.FromLTRB(left, top, right, bottom));
}

public void FillRectangle(IBrush brush, int x1, int y1, int x2, int y2)
{
var r = RectangleF.FromLTRB(x1, y1, x2, y2);
r.Offset(Bug28Offset);
this.context.Fill(Drawing.NoAntiAlias, brush, r);
//r.Offset(Bug28Offset);
this.context.Fill(NoAntiAlias, brush, r);
}

private static float PenOffset(float strokeWidth)
{
return (strokeWidth % 2f == 0) ? -0.5f : 0;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Acoustics.Tools/Acoustics.Tools.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="MathNet.Numerics" Version="4.12.0" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.164">
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.261">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
2 changes: 1 addition & 1 deletion src/AnalysisBase/AnalysisBase.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<Compile Remove="ProgressReporter.cs" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.164">
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.261">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
8 changes: 4 additions & 4 deletions src/AnalysisPrograms/AnalysisPrograms.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<ProductVersion>9.0.30729</ProductVersion>
<OutputType>Exe</OutputType>
Expand Down Expand Up @@ -63,9 +63,9 @@
<ItemGroup>
<PackageReference Include="McMaster.Extensions.CommandLineUtils" Version="3.0.0" />
<PackageReference Include="SixLabors.Fonts" Version="1.0.0-unstable0058" />
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.2" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-unstable0456" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.164">
<PackageReference Include="SixLabors.ImageSharp" Version="1.0.3-alpha.0.7" />
<PackageReference Include="SixLabors.ImageSharp.Drawing" Version="1.0.0-beta11" />
<PackageReference Include="StyleCop.Analyzers" Version="1.2.0-beta.261">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
Expand Down
6 changes: 3 additions & 3 deletions src/AudioAnalysisTools/AcousticEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ public void DrawEvent<T>(Image<T> imageToReturn, double framesPerSecond, double

imageToReturn.Mutate(g => g.NoAA().DrawRectangle(borderPen, t1, y1, t2, y2));

//draw on the elements from the hit matrix
// draw on the elements from the hit matrix
if (this.HitElements != null)
{
foreach (var hitElement in this.HitElements)
Expand All @@ -450,12 +450,12 @@ public void DrawEvent<T>(Image<T> imageToReturn, double framesPerSecond, double
}
}

//draw the score bar to indicate relative score
// draw the score bar to indicate relative score
var eventHeight = y2 - y1 + 1;
int scoreHt = (int)Math.Round(eventHeight * this.ScoreNormalised);
imageToReturn.Mutate(g =>
{
g.NoAA().DrawLine(scorePen, t1, y2 - scoreHt, t1, y2 + 1);
g.NoAA().DrawLine(scorePen, t1, y2 - scoreHt + 1, t1, y2);
g.DrawTextSafe(this.Name, Drawing.Tahoma6, Color.Black, new PointF(t1, y1 - 4));
});
}
Expand Down
Loading

0 comments on commit 3bdb893

Please sign in to comment.