Browse Source

trying to improve Opacity out of range propagation.

For some reason, FillRegionProcessor and DrawTextProcessor where overshooting opacity over 1
pull/686/head
Vicente Penades 8 years ago
parent
commit
029b35cd0c
  1. 6
      src/ImageSharp.Drawing/Processing/Processors/Drawing/FillRegionProcessor.cs
  2. 6
      src/ImageSharp.Drawing/Processing/Processors/Text/DrawTextProcessor.cs
  3. 13
      src/ImageSharp.Drawing/Processing/SolidBrush{TPixel}.cs

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

@ -142,6 +142,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing
scanline[startX] += subpixelFractionPoint; scanline[startX] += subpixelFractionPoint;
scanlineDirty = true; scanlineDirty = true;
} }
if (scanline[startX] > 1) { scanline[startX] = 1; }
} }
if (endX >= 0 && endX < scanline.Length) if (endX >= 0 && endX < scanline.Length)
@ -151,6 +153,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing
scanline[endX] += subpixelFractionPoint; scanline[endX] += subpixelFractionPoint;
scanlineDirty = true; scanlineDirty = true;
} }
if (scanline[endX] > 1) { scanline[endX] = 1; }
} }
int nextX = startX + 1; int nextX = startX + 1;
@ -160,6 +164,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Drawing
{ {
scanline[x] += subpixelFraction; scanline[x] += subpixelFraction;
scanlineDirty = true; scanlineDirty = true;
if (scanline[x] > 1) { scanline[x] = 1; }
} }
} }
} }

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

@ -387,6 +387,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Text
scanline[startX] += subpixelFractionPoint; scanline[startX] += subpixelFractionPoint;
scanlineDirty = true; scanlineDirty = true;
} }
if (scanline[startX] > 1) { scanline[startX] = 1; }
} }
if (endX >= 0 && endX < scanline.Length) if (endX >= 0 && endX < scanline.Length)
@ -396,6 +398,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Text
scanline[endX] += subpixelFractionPoint; scanline[endX] += subpixelFractionPoint;
scanlineDirty = true; scanlineDirty = true;
} }
if (scanline[endX] > 1) { scanline[endX] = 1; }
} }
int nextX = startX + 1; int nextX = startX + 1;
@ -405,6 +409,8 @@ namespace SixLabors.ImageSharp.Processing.Processors.Text
{ {
scanline[x] += subpixelFraction; scanline[x] += subpixelFraction;
scanlineDirty = true; scanlineDirty = true;
if (scanline[x] > 1) { scanline[x] = 1; }
} }
} }
} }

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

@ -93,7 +93,16 @@ namespace SixLabors.ImageSharp.Processing
MemoryAllocator memoryAllocator = this.Target.MemoryAllocator; MemoryAllocator memoryAllocator = this.Target.MemoryAllocator;
if (this.Options.BlendPercentage == 1f) #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 (opacity == 1f)
{ {
this.Blender.Blend(memoryAllocator, destinationRow, destinationRow, this.Colors.GetSpan(), scanline); 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++) 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); this.Blender.Blend(memoryAllocator, destinationRow, destinationRow, this.Colors.GetSpan(), amountSpan);

Loading…
Cancel
Save