Permalink
Browse files

[Fixes bug #1064500] Fix off-by-one error when drawing gradients.

The error was actually in the RangeEnumerator class, but I've deleted
that since we can just use Enumerable.Range from the standard library
instead.
  • Loading branch information...
1 parent 563d976 commit 9fe494851654b758757ad9155698c612c63cd786 @cameronwhite cameronwhite committed Oct 10, 2012
Showing with 3 additions and 72 deletions.
  1. +3 −3 Pinta.Core/Classes/GradientRenderer.cs
  2. +0 −69 Pinta.Core/Effects/Utility.cs
@@ -6,8 +6,9 @@
/////////////////////////////////////////////////////////////////////////////////
using System;
-using System.Threading.Tasks;
using System.Collections.Generic;
+using System.Linq;
+using System.Threading.Tasks;
using Cairo;
using Rectangle = Gdk.Rectangle;
@@ -159,8 +160,7 @@ unsafe public void Render (ImageSurface surface, Gdk.Rectangle[] rois)
}
} else {
var mainrect = rect;
- var list = new List<int>(new Utility.RangeEnumerable(rect.Top, rect.GetBottom() + 1));
- Parallel.ForEach(list.ToArray(),
+ Parallel.ForEach(Enumerable.Range (rect.Top, rect.GetBottom () + 1),
(y) => ProcessGradientLine(startAlpha, endAlpha, y, mainrect, surface, src_data_ptr, src_width));
}
}
@@ -637,74 +637,5 @@ public static int FastDivideShortByByte(ushort n, byte d)
0x80808081, 0x00000000, 39 // 255
};
- //enumerable/enumerator that given a range, will give an enumerator.
- //The reason to create it is to make easy accessible Linq (or ParallelLinq)
- //using constructions like: foreach (var x in new RangeEnumerable(3, 6)) { ... } where x will take values {3.4.5}
- public class RangeEnumerable : IEnumerable<int>
- {
- private readonly int _startValue;
- private readonly int _endValue;
-
- public RangeEnumerable(int startValue, int endValue)
- {
- _startValue = startValue;
- _endValue = endValue;
- }
-
- public IEnumerator<int> GetEnumerator()
- {
- return new RangeEnumerator(_startValue, _endValue);
- }
-
- IEnumerator IEnumerable.GetEnumerator()
- {
- return GetEnumerator();
- }
- }
-
- public class RangeEnumerator : IEnumerator<int>
- {
- private int _startValue;
- private int _endValue;
- private int _current;
-
- public RangeEnumerator(int startValue, int endValue)
- {
- Setup(startValue, endValue);
- }
-
- private void Setup(int startValue, int endValue)
- {
- _startValue = startValue;
- _endValue = endValue;
- _current = startValue;
- }
-
- public void Dispose()
- {
- _current = _startValue;
- }
-
- public bool MoveNext()
- {
- _current++;
- return _current < _endValue;
- }
-
- public void Reset()
- {
- _current = _startValue;
- }
-
- public int Current
- {
- get {return _current;}
- }
-
- object IEnumerator.Current
- {
- get {return Current;}
- }
- }
}
}

0 comments on commit 9fe4948

Please sign in to comment.