Skip to content

Commit 5d46d68

Browse files
Merge pull request #204 from SixLabors/sw/subpixel-dirty-flag
Prevent a subpixel being able to reset dirty flag
2 parents 6b6c60f + d090e0a commit 5d46d68

5 files changed

Lines changed: 63 additions & 6 deletions

File tree

src/ImageSharp.Drawing/Shapes/Rasterization/RasterizerExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ private static void ScanCurrentSubpixelLineInto(this ref PolygonScanner scanner,
4545
float subpixelWidth = (startX + 1 - scanStart) / scanner.SubpixelDistance;
4646

4747
scanline[startX] += subpixelWidth * scanner.SubpixelArea;
48-
scanlineDirty = subpixelWidth > 0;
48+
scanlineDirty |= subpixelWidth > 0;
4949
}
5050

5151
if (endX >= 0 && endX < scanline.Length)
@@ -54,7 +54,7 @@ private static void ScanCurrentSubpixelLineInto(this ref PolygonScanner scanner,
5454
float subpixelWidth = (scanEnd - endX) / scanner.SubpixelDistance;
5555

5656
scanline[endX] += subpixelWidth * scanner.SubpixelArea;
57-
scanlineDirty = subpixelWidth > 0;
57+
scanlineDirty |= subpixelWidth > 0;
5858
}
5959

6060
int nextX = startX + 1;
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// Copyright (c) Six Labors.
2+
// Licensed under the Apache License, Version 2.0.
3+
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Text;
7+
using SixLabors.Fonts;
8+
using SixLabors.ImageSharp.Drawing.Processing;
9+
using SixLabors.ImageSharp.Drawing.Shapes.Rasterization;
10+
using SixLabors.ImageSharp.Drawing.Tests.TestUtilities.ImageComparison;
11+
using SixLabors.ImageSharp.Memory;
12+
using SixLabors.ImageSharp.PixelFormats;
13+
using SixLabors.ImageSharp.Processing;
14+
using Xunit;
15+
16+
namespace SixLabors.ImageSharp.Drawing.Tests.Shapes.Scan
17+
{
18+
public class RasterizerExtensionsTests
19+
{
20+
[Fact]
21+
public void DoesNotOverwriteIsDirtyFlagWhenOnlyFillingSubpixels()
22+
{
23+
var scanner = PolygonScanner.Create(new RectangularPolygon(0.3f, 0.2f, 0.7f, 1.423f), 0, 20, 1, IntersectionRule.OddEven, MemoryAllocator.Default);
24+
25+
float[] buffer = new float[12];
26+
27+
scanner.MoveToNextPixelLine(); // offset
28+
29+
bool isDirty = scanner.ScanCurrentPixelLineInto(0, 0, buffer.AsSpan());
30+
31+
Assert.True(isDirty);
32+
}
33+
34+
[Theory]
35+
[WithSolidFilledImages(400, 75, "White", PixelTypes.Rgba32)]
36+
public void AntialiasingIsAntialiased<TPixel>(TestImageProvider<TPixel> provider)
37+
where TPixel : unmanaged, IPixel<TPixel>
38+
{
39+
Font font36 = TestFontUtilities.GetFont(TestFonts.OpenSans, 20);
40+
var textOpt = new TextOptions(font36)
41+
{
42+
Dpi = 96,
43+
Origin = new PointF(0, 0)
44+
};
45+
46+
var comparer = ImageComparer.TolerantPercentage(0.001f);
47+
provider.RunValidatingProcessorTest(
48+
x => x
49+
.SetGraphicsOptions(o => o.Antialias = false)
50+
.DrawText(textOpt, "Hello, World!", Color.Black),
51+
comparer: comparer);
52+
}
53+
}
54+
}
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 2 additions & 2 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)