Skip to content

Commit

Permalink
Fix anti-aliasing when drawing event
Browse files Browse the repository at this point in the history
Issue #300 Fix anti-aliasing problem and then fix unit tests for the drawing of events.
  • Loading branch information
towsey authored and atruskie committed Mar 20, 2020
1 parent 8a5a6f0 commit af4813e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 20 deletions.
11 changes: 5 additions & 6 deletions src/AudioAnalysisTools/AcousticEvent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace AudioAnalysisTools
using SixLabors.ImageSharp.PixelFormats;
using SixLabors.ImageSharp.Processing;
using TowseyLibrary;
using static Acoustics.Shared.ImageSharp.Drawing;

public class AcousticEvent : EventBase
{
Expand Down Expand Up @@ -461,10 +462,7 @@ public void DrawEvent<T>(Image<T> imageToReturn, double framesPerSecond, double
t2 = this.Oblong.RowBottom;
}

// rectangle width = t2 - t1 + 1
// rectangle height = y2 - y1 + 1
imageToReturn.Mutate(g => g.DrawRectangle(borderPen, t1, y1, t2 - t1 + 1, y2 - y1 + 1));

imageToReturn.Mutate(g => g.NoAA().DrawRectangle(borderPen, t1, y1, t2, y2));
if (this.HitElements != null)
{
foreach (var hitElement in this.HitElements)
Expand All @@ -478,8 +476,9 @@ public void DrawEvent<T>(Image<T> imageToReturn, double framesPerSecond, double
int scoreHt = (int)Math.Round(eventHeight * this.ScoreNormalised);
imageToReturn.Mutate(g =>
{
g.DrawLine(scorePen, t1, y2 - scoreHt, t1, y2);
g.DrawTextSafe(this.Name, Drawing.Tahoma6, Color.Black, new PointF(t1, y1 - 4));
g.NoAA().DrawLine(scorePen, t1, y2 - scoreHt, t1, y2 + 1);
//g.DrawTextSafe(this.Name, Drawing.Tahoma6, Color.Black, new PointF(t1, y1 - 5));
g.DrawTextSafe(this.Name, Drawing.Arial8, Color.Black, new PointF(t1, y1 - 5));
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,23 +108,21 @@ public void TestSonogramWithEventsOverlay()
ev.DrawEvent(substituteSonogram, framesPerSecond, freqBinWidth, height);
}

var redPixel1 = new Argb32(110, 10, 30);
var expectedRed1 = new Color(redPixel1);
var redPixel2 = new Argb32(124, 11, 34);
var expectedRed2 = new Color(redPixel2);
var greenPixel = new Argb32(55, 133, 15);
substituteSonogram.Save("C:\\temp\\image.png");

var redPixel = new Argb32(220, 20, 60);
var expectedRed = new Color(redPixel);
var greenPixel = new Argb32(0, 255, 0);
var expectedGreen = new Color(greenPixel);

//var actualColor = substituteSonogram[0, height - 1];
Assert.AreEqual<Color>(expectedRed1, substituteSonogram[61, 119]);
Assert.AreEqual<Color>(expectedRed1, substituteSonogram[70, 122]);
Assert.AreEqual<Color>(expectedRed1, substituteSonogram[91, 181]);
Assert.AreEqual<Color>(expectedRed2, substituteSonogram[36, 233]);
Assert.AreEqual<Color>(expectedRed1, substituteSonogram[56, 69]);
Assert.AreEqual<Color>(expectedRed, substituteSonogram[60, 119]);
Assert.AreEqual<Color>(expectedRed, substituteSonogram[70, 122]);
Assert.AreEqual<Color>(expectedRed, substituteSonogram[90, 181]);
Assert.AreEqual<Color>(expectedRed, substituteSonogram[36, 232]);
Assert.AreEqual<Color>(expectedRed, substituteSonogram[56, 69]);

//actualColor = substituteSonogram[9, 72];
Assert.AreEqual<Color>(expectedGreen, substituteSonogram[9, 72]);
Assert.AreEqual<Color>(expectedGreen, substituteSonogram[69, 217]);
Assert.AreEqual<Color>(expectedGreen, substituteSonogram[10, 72]);
Assert.AreEqual<Color>(expectedGreen, substituteSonogram[70, 217]);
}
}
}

0 comments on commit af4813e

Please sign in to comment.