Browse Source

trying to improve Opacity out of range propagation.

For some reason, FillRegionProcessor and DrawTextProcessor where overshooting opacity over 1
af/merge-core
Vicente Penades 8 years ago
parent
commit
681df46c2d
  1. 20
      src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor.cs
  2. 12
      src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor.cs
  3. 15
      src/ImageSharp.Drawing/Processing/SolidBrush{TPixel}.cs

20
src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor.cs

@ -139,9 +139,11 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing
{
for (float x = scanStart; x < startX + 1; x += subpixelFraction)
{
scanline[startX] += subpixelFractionPoint;
scanlineDirty = true;
}
scanline[startX] += subpixelFractionPoint;
scanlineDirty = true;
}
if (scanline[startX] > 1) { scanline[startX] = 1; }
}
if (endX >= 0 && endX < scanline.Length)
@ -149,8 +151,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing
for (float x = endX; x < scanEnd; x += subpixelFraction)
{
scanline[endX] += subpixelFractionPoint;
scanlineDirty = true;
}
scanlineDirty = true;
}
if (scanline[endX] > 1) { scanline[endX] = 1; }
}
int nextX = startX + 1;
@ -158,8 +162,10 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing
nextX = Math.Max(nextX, 0);
for (int x = nextX; x < endX; x++)
{
scanline[x] += subpixelFraction;
scanlineDirty = true;
scanline[x] += subpixelFraction;
scanlineDirty = true;
if (scanline[x] > 1) { scanline[x] = 1; }
}
}
}

12
src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor.cs

@ -386,7 +386,9 @@ namespace SixLabors.ImageSharp.Processing.Processors.Text
{
scanline[startX] += subpixelFractionPoint;
scanlineDirty = true;
}
}
if (scanline[startX] > 1) { scanline[startX] = 1; }
}
if (endX >= 0 && endX < scanline.Length)
@ -395,7 +397,9 @@ namespace SixLabors.ImageSharp.Processing.Processors.Text
{
scanline[endX] += subpixelFractionPoint;
scanlineDirty = true;
}
}
if (scanline[endX] > 1) { scanline[endX] = 1; }
}
int nextX = startX + 1;
@ -404,7 +408,9 @@ namespace SixLabors.ImageSharp.Processing.Processors.Text
for (int x = nextX; x < endX; x++)
{
scanline[x] += subpixelFraction;
scanlineDirty = true;
scanlineDirty = true;
if (scanline[x] > 1) { scanline[x] = 1; }
}
}
}

15
src/ImageSharp.Drawing/Processing/SolidBrush{TPixel}.cs

@ -91,9 +91,18 @@ namespace SixLabors.ImageSharp.Processing
{
Span<TPixel> destinationRow = this.Target.GetPixelRowSpan(y).Slice(x, scanline.Length);
MemoryAllocator memoryAllocator = this.Target.MemoryAllocator;
MemoryAllocator memoryAllocator = this.Target.MemoryAllocator;
#if DEBUG
for (int i = 0; i < scanline.Length; i++)
{
Guard.MustBeBetweenOrEqualTo(scanline[i], 0, 1, nameof(scanline));
}
#endif
float opacity = this.Options.BlendPercentage.Clamp(0, 1);
if (this.Options.BlendPercentage == 1f)
if (opacity == 1f)
{
this.Blender.Blend(memoryAllocator, destinationRow, destinationRow, this.Colors.GetSpan(), scanline);
}
@ -105,7 +114,7 @@ namespace SixLabors.ImageSharp.Processing
for (int i = 0; i < scanline.Length; i++)
{
amountSpan[i] = scanline[i] * this.Options.BlendPercentage;
amountSpan[i] = scanline[i] * opacity;
}
this.Blender.Blend(memoryAllocator, destinationRow, destinationRow, this.Colors.GetSpan(), amountSpan);

Loading…
Cancel
Save