1 package gnu
.java
.awt
.java2d
;
4 * Stores and handles the pixel converage for a scanline. The pixel coverage
5 * is stored as sorted list of buckets, each of which holds information about
6 * the coverage for the X and Y axis. This is utilized to compute the actual
7 * coverage for each pixel on the scanline and finding chunks of pixels with
10 final class PixelCoverage
14 * One bucket in the list.
16 private static final class Bucket
19 * The X coordinate on the scanline to which this bucket belongs.
34 * Implements a linked list. This points to the next element of the list.
39 * Implements a linked list. This points to the previous element of the
46 * The head of the sorted list of buckets.
51 * The current bucket. We make use of the fact that the scanline converter
52 * always scans the scanline (and thus this list) from left to right to
53 * quickly find buckets or insertion points.
55 private Bucket current
;
58 * The bucket after the last valid bucket. Unused buckets are not thrown
59 * away and garbage collected. Instead, we keep them at the tail of the list
60 * and reuse them when necessary.
65 * Indicates the the next scan of the scanline begins and that the next
66 * request will be at the beginning of this list. This makes searching and
67 * sorting of this list very quick.
75 * Clears the list. This does not throw away the old buckets but only
76 * resets the end-pointer of the list to the first element. All buckets are
77 * then unused and are reused when the list is filled again.
85 * This adds the specified x and y coverage to the pixel at the specified
88 * @param x the X position
89 * @param xc the x coverage
90 * @param yc the y coverage
92 void add(int x
, int xc
, int yc
)
94 Bucket bucket
= findOrInsert(x
);
100 * Finds the bucket in the list with the specified X coordinate.
101 * If no such bucket is found, then a new one is fetched (either a cached
102 * bucket from the end of the list or a newly allocated one) inserted at the
103 * correct position and returned.
105 * @param x the X coordinate
107 * @return a bucket to hold the coverage data
109 private Bucket
findOrInsert(int x
)
111 // First search for a matching bucket.
114 // Special case: the list is still empty.
120 // This performs a linear search, starting from the current bucket.
121 // This is reasonably efficient because access to this list is always done
122 // in a linear fashion and we are not more then 1 or 2 buckets away from
123 // the one we're looking for.
124 Bucket match
= current
;
125 while (match
!= null && match
.xPos
!= x
)