/src/xpdf-4.06/splash/SplashXPathScanner.cc
Line | Count | Source |
1 | | //======================================================================== |
2 | | // |
3 | | // SplashXPathScanner.cc |
4 | | // |
5 | | // Copyright 2003-2013 Glyph & Cog, LLC |
6 | | // |
7 | | //======================================================================== |
8 | | |
9 | | #include <aconf.h> |
10 | | |
11 | | #include <stdlib.h> |
12 | | #include <string.h> |
13 | | #if HAVE_STD_SORT |
14 | | #include <algorithm> |
15 | | #endif |
16 | | #include "gmem.h" |
17 | | #include "gmempp.h" |
18 | | #include "GList.h" |
19 | | #include "SplashMath.h" |
20 | | #include "SplashXPath.h" |
21 | | #include "SplashXPathScanner.h" |
22 | | |
23 | | //------------------------------------------------------------------------ |
24 | | |
25 | | #if ANTIALIAS_256 |
26 | | |
27 | | #define aaVert 15 |
28 | | #define aaHoriz 17 |
29 | | |
30 | | #else |
31 | | |
32 | 79.4M | #define aaVert 4 |
33 | 9.77M | #define aaHoriz 4 |
34 | | |
35 | | // 4x4 oversampling tends to generate alpha (coverage) values that are |
36 | | // too high, so we reduce them here. (Yes, this is a kludge.) |
37 | | static Guchar map16to255[17] = { |
38 | | 0, |
39 | | 16 / 2, |
40 | | 32 / 2, |
41 | | 48 / 2, |
42 | | 64 - 32, |
43 | | 80 - 32, |
44 | | 96 - 32, |
45 | | 112 - 32, |
46 | | 128 - 32, |
47 | | 143 - 32, |
48 | | 159 - 32, |
49 | | 175 - 32, |
50 | | 191 - 32, |
51 | | 207 - 32, |
52 | | 223 - 32, |
53 | | 239 - 32, |
54 | | 255 |
55 | | }; |
56 | | |
57 | | #endif |
58 | | |
59 | | //------------------------------------------------------------------------ |
60 | | |
61 | | SplashXPathScanner::SplashXPathScanner(SplashXPath *xPathA, GBool eo, |
62 | 107k | int yMinA, int yMaxA) { |
63 | 107k | xPath = xPathA; |
64 | 107k | eoMask = eo ? 1 : 0xffffffff; |
65 | 107k | yMin = yMinA; |
66 | 107k | yMax = yMaxA; |
67 | 107k | if (xPath->isRect) { |
68 | 23.9k | rectX0I = splashFloor(xPath->rectX0); |
69 | 23.9k | rectY0I = splashFloor(xPath->rectY0); |
70 | 23.9k | rectX1I = splashFloor(xPath->rectX1); |
71 | 23.9k | rectY1I = splashFloor(xPath->rectY1); |
72 | 23.9k | } |
73 | | |
74 | 107k | pre = &preSeg; |
75 | 107k | post = &postSeg; |
76 | 107k | pre->mx = xPath->xMin - 1; |
77 | 107k | post->mx = xPath->xMax + 1; |
78 | | |
79 | 107k | resetDone = gFalse; |
80 | 107k | resetAA = gFalse; |
81 | 107k | } |
82 | | |
83 | 107k | SplashXPathScanner::~SplashXPathScanner() { |
84 | 107k | } |
85 | | |
86 | | void SplashXPathScanner::insertSegmentBefore(SplashXPathSeg *s, |
87 | 2.52M | SplashXPathSeg *sNext) { |
88 | 2.52M | SplashXPathSeg *sPrev; |
89 | | |
90 | 2.52M | sPrev = sNext->prev; |
91 | 2.52M | sPrev->next = s; |
92 | 2.52M | s->prev = sPrev; |
93 | 2.52M | s->next = sNext; |
94 | 2.52M | sNext->prev = s; |
95 | 2.52M | } |
96 | | |
97 | 1.28M | void SplashXPathScanner::removeSegment(SplashXPathSeg *s) { |
98 | 1.28M | SplashXPathSeg *sPrev, *sNext; |
99 | | |
100 | 1.28M | sPrev = s->prev; |
101 | 1.28M | sNext = s->next; |
102 | 1.28M | sPrev->next = sNext; |
103 | 1.28M | sNext->prev = sPrev; |
104 | 1.28M | s->prev = s->next = NULL; |
105 | 1.28M | } |
106 | | |
107 | | void SplashXPathScanner::moveSegmentAfter(SplashXPathSeg *s, |
108 | 239k | SplashXPathSeg *sPrev) { |
109 | 239k | SplashXPathSeg *sNext; |
110 | | |
111 | 239k | s->prev->next = s->next; |
112 | 239k | s->next->prev = s->prev; |
113 | | |
114 | 239k | sNext = sPrev->next; |
115 | 239k | sPrev->next = s; |
116 | 239k | s->prev = sPrev; |
117 | 239k | s->next = sNext; |
118 | 239k | sNext->prev = s; |
119 | 239k | } |
120 | | |
121 | 44.9k | void SplashXPathScanner::reset(GBool aa, GBool aaChanged) { |
122 | 44.9k | SplashXPathSeg *seg; |
123 | 44.9k | SplashCoord y; |
124 | 44.9k | int i; |
125 | | |
126 | | //--- initialize segment parameters |
127 | 51.8M | for (i = 0; i < xPath->length; ++i) { |
128 | 51.8M | seg = &xPath->segs[i]; |
129 | 51.8M | if (aa) { |
130 | 41.7M | if (aaChanged) { |
131 | 37.3M | seg->iy = splashFloor(seg->y0 * aaVert); |
132 | 37.3M | } |
133 | 41.7M | y = (SplashCoord)(seg->iy + 1) / (SplashCoord)aaVert; |
134 | 41.7M | } else { |
135 | 10.1M | if (aaChanged) { |
136 | 2.52M | seg->iy = splashFloor(seg->y0); |
137 | 2.52M | } |
138 | 10.1M | y = (SplashCoord)(seg->iy + 1); |
139 | 10.1M | } |
140 | 51.8M | seg->sx0 = seg->x0; |
141 | 51.8M | if (seg->y1 <= y) { |
142 | 29.0M | seg->sx1 = seg->x1; |
143 | 29.0M | } else { |
144 | 22.7M | seg->sx1 = seg->x0 + (y - seg->y0) * seg->dxdy; |
145 | 22.7M | } |
146 | 51.8M | seg->mx = (seg->sx0 <= seg->sx1) ? seg->sx0 : seg->sx1; |
147 | 51.8M | seg->prev = seg->next = NULL; |
148 | 51.8M | } |
149 | | |
150 | | //--- sort the inactive segments by iy, mx |
151 | 44.9k | if (aaChanged) { |
152 | 33.9k | #if HAVE_STD_SORT |
153 | 33.9k | std::sort(xPath->segs, xPath->segs + xPath->length, &SplashXPathSeg::cmpMX); |
154 | | #else |
155 | | qsort(xPath->segs, xPath->length, sizeof(SplashXPathSeg), |
156 | | &SplashXPathSeg::cmpMX); |
157 | | #endif |
158 | 33.9k | } |
159 | | |
160 | | //--- initialize the active list |
161 | 44.9k | pre->prev = NULL; |
162 | 44.9k | pre->next = post; |
163 | 44.9k | post->prev = pre; |
164 | 44.9k | post->next = NULL; |
165 | | |
166 | | //--- initialize the scan state |
167 | 44.9k | nextSeg = 0; |
168 | 44.9k | if (xPath->length) { |
169 | 41.8k | yBottomI = xPath->segs[0].iy; |
170 | 41.8k | if (aa) { |
171 | 35.8k | yBottomI -= yBottomI % aaVert; |
172 | 35.8k | } |
173 | 41.8k | } else { |
174 | 3.05k | yBottomI = 0; |
175 | 3.05k | } |
176 | 44.9k | yTopI = yBottomI - 1; |
177 | 44.9k | if (aa) { |
178 | 38.9k | yTop = (SplashCoord)yTopI / (SplashCoord)aaVert; |
179 | 38.9k | yBottom = (SplashCoord)yBottomI / (SplashCoord)aaVert; |
180 | 38.9k | } else { |
181 | 5.96k | yTop = (SplashCoord)yTopI; |
182 | 5.96k | yBottom = (SplashCoord)yBottomI; |
183 | 5.96k | } |
184 | | |
185 | 44.9k | resetDone = gTrue; |
186 | 44.9k | resetAA = aa; |
187 | 44.9k | } |
188 | | |
189 | 24.1k | void SplashXPathScanner::skip(int newYBottomI, GBool aa) { |
190 | 24.1k | SplashXPathSeg *s0, *s1,*s2; |
191 | 24.1k | int iy; |
192 | | |
193 | 24.1k | yTopI = newYBottomI - 1; |
194 | 24.1k | yBottomI = newYBottomI; |
195 | 24.1k | if (aa) { |
196 | 18.5k | yTop = (SplashCoord)yTopI / (SplashCoord)aaVert; |
197 | 18.5k | yBottom = (SplashCoord)yBottomI / (SplashCoord)aaVert; |
198 | 18.5k | } else { |
199 | 5.58k | yTop = (SplashCoord)yTopI; |
200 | 5.58k | yBottom = (SplashCoord)yBottomI; |
201 | 5.58k | } |
202 | | |
203 | | //--- remove finished segments; update sx0, sx1, mx for active segments |
204 | 24.1k | s0 = pre->next; |
205 | 24.1k | while (s0 != post) { |
206 | 0 | s1 = s0->next; |
207 | | |
208 | | // check for a finished segment |
209 | 0 | if (s0->y1 < yTop) { |
210 | 0 | removeSegment(s0); |
211 | | |
212 | | // compute sx0, sx1, mx |
213 | 0 | } else { |
214 | 0 | if (s0->y0 >= yTop) { |
215 | 0 | s0->sx0 = s0->x0; |
216 | 0 | } else { |
217 | 0 | s0->sx0 = s0->x0 + (yTop - s0->y0) * s0->dxdy; |
218 | 0 | } |
219 | 0 | if (s0->y1 <= yBottom) { |
220 | 0 | s0->sx1 = s0->x1; |
221 | 0 | } else { |
222 | 0 | s0->sx1 = s0->x0 + (yBottom - s0->y0) * s0->dxdy; |
223 | 0 | } |
224 | 0 | s0->mx = (s0->sx0 <= s0->sx1) ? s0->sx0 : s0->sx1; |
225 | 0 | } |
226 | |
|
227 | 0 | s0 = s1; |
228 | 0 | } |
229 | | |
230 | | //--- check for intersections |
231 | 24.1k | s0 = pre->next; |
232 | 24.1k | if (s0 != post) { |
233 | 0 | s1 = s0->next; |
234 | 0 | while (s1 != post) { |
235 | 0 | if (s1->mx < s0->mx) { |
236 | 0 | for (s2 = s0->prev; s1->mx < s2->mx; s2 = s2->prev) ; |
237 | 0 | moveSegmentAfter(s1, s2); |
238 | 0 | } else { |
239 | 0 | s0 = s1; |
240 | 0 | } |
241 | 0 | s1 = s0->next; |
242 | 0 | } |
243 | 0 | } |
244 | | |
245 | | //--- insert new segments with a merge sort |
246 | | // - this has to be done one (sub)scanline at a time, because the |
247 | | // inactive list is bin-sorted by (sub)scanline |
248 | 8.80M | while (nextSeg < xPath->length && xPath->segs[nextSeg].iy <= yTopI) { |
249 | | // the first inactive segment determines the next scanline to process |
250 | 8.77M | iy = xPath->segs[nextSeg].iy; |
251 | 8.77M | s0 = pre->next; |
252 | 22.0M | do { |
253 | 22.0M | s1 = &xPath->segs[nextSeg]; |
254 | 22.0M | ++nextSeg; |
255 | 22.0M | if (s1->y1 < yTop) { |
256 | 20.8M | continue; |
257 | 20.8M | } |
258 | 1.21M | if (s1->y0 >= yTop) { |
259 | 2.20k | s1->sx0 = s1->x0; |
260 | 1.21M | } else { |
261 | 1.21M | s1->sx0 = s1->x0 + (yTop - s1->y0) * s1->dxdy; |
262 | 1.21M | } |
263 | 1.21M | if (s1->y1 <= yBottom) { |
264 | 13.3k | s1->sx1 = s1->x1; |
265 | 1.20M | } else { |
266 | 1.20M | s1->sx1 = s1->x0 + (yBottom - s1->y0) * s1->dxdy; |
267 | 1.20M | } |
268 | 1.21M | s1->mx = (s1->sx0 <= s1->sx1) ? s1->sx0 : s1->sx1; |
269 | 1.21M | insertSegmentBefore(s1, s0); |
270 | 22.0M | } while (nextSeg < xPath->length && xPath->segs[nextSeg].iy <= iy); |
271 | 8.77M | } |
272 | 24.1k | } |
273 | | |
274 | 100k | void SplashXPathScanner::advance(GBool aa) { |
275 | 100k | SplashXPathSeg *s, *sNext, *s1; |
276 | | |
277 | 100k | yTopI = yBottomI; |
278 | 100k | yTop = yBottom; |
279 | 100k | yBottomI = yTopI + 1; |
280 | 100k | if (aa) { |
281 | 94.9k | yBottom = (SplashCoord)yBottomI / (SplashCoord)aaVert; |
282 | 94.9k | } else { |
283 | 5.96k | yBottom = (SplashCoord)yBottomI; |
284 | 5.96k | } |
285 | | |
286 | 100k | s = pre->next; |
287 | 6.14M | while (s != post) { |
288 | 6.04M | sNext = s->next; |
289 | | |
290 | | // check for a finished segment |
291 | 6.04M | if (s->y1 < yTop) { |
292 | 1.28M | removeSegment(s); |
293 | | |
294 | 4.76M | } else { |
295 | | |
296 | | // compute sx0, sx1, mx |
297 | 4.76M | s->sx0 = s->sx1; |
298 | 4.76M | if (s->y1 <= yBottom) { |
299 | 11.6k | s->sx1 = s->x1; |
300 | 4.75M | } else { |
301 | 4.75M | s->sx1 = s->x0 + (yBottom - s->y0) * s->dxdy; |
302 | 4.75M | } |
303 | 4.76M | s->mx = (s->sx0 <= s->sx1) ? s->sx0 : s->sx1; |
304 | | |
305 | | // check for intersection |
306 | 4.76M | if (s->mx < s->prev->mx) { |
307 | 65.7M | for (s1 = s->prev->prev; s->mx < s1->mx; s1 = s1->prev) ; |
308 | 239k | moveSegmentAfter(s, s1); |
309 | 239k | } |
310 | 4.76M | } |
311 | | |
312 | 6.04M | s = sNext; |
313 | 6.04M | } |
314 | | |
315 | | // insert new segments |
316 | 100k | s = pre->next; |
317 | 1.41M | while (nextSeg < xPath->length && xPath->segs[nextSeg].iy <= yTopI) { |
318 | 1.31M | s1 = &xPath->segs[nextSeg]; |
319 | 1.31M | ++nextSeg; |
320 | 1.33M | while (s1->mx > s->mx) { |
321 | 15.5k | s = s->next; |
322 | 15.5k | } |
323 | 1.31M | insertSegmentBefore(s1, s); |
324 | 1.31M | } |
325 | 100k | } |
326 | | |
327 | | void SplashXPathScanner::generatePixels(int x0, int x1, Guchar *line, |
328 | 94.9k | int *xMin, int *xMax) { |
329 | 94.9k | SplashXPathSeg *s; |
330 | 94.9k | int fillCount, x, xEnd, ix0, ix1, t; |
331 | | |
332 | 94.9k | fillCount = 0; |
333 | 94.9k | x = x0 * aaHoriz; |
334 | 94.9k | xEnd = (x1 + 1) * aaHoriz; |
335 | 2.45M | for (s = pre->next; s != post && x < xEnd; s = s->next) { |
336 | 2.36M | ix0 = splashFloor(s->sx0 * aaHoriz); |
337 | 2.36M | ix1 = splashFloor(s->sx1 * aaHoriz); |
338 | 2.36M | if (ix0 > ix1) { |
339 | 800k | t = ix0; ix0 = ix1; ix1 = t; |
340 | 800k | } |
341 | 2.36M | if (!(fillCount & eoMask)) { |
342 | 848k | if (ix0 > x) { |
343 | 17.1k | x = ix0; |
344 | 17.1k | } |
345 | 848k | } |
346 | 2.36M | if (ix1 >= xEnd) { |
347 | 23.9k | ix1 = xEnd - 1; |
348 | 23.9k | } |
349 | 2.36M | if (x / aaHoriz < *xMin) { |
350 | 18.7k | *xMin = x / aaHoriz; |
351 | 18.7k | } |
352 | 2.36M | if (ix1 / aaHoriz > *xMax) { |
353 | 19.0k | *xMax = ix1 / aaHoriz; |
354 | 19.0k | } |
355 | 2.45M | for (; x <= ix1; ++x) { |
356 | 93.5k | ++line[x / aaHoriz]; |
357 | 93.5k | } |
358 | 2.36M | if (s->y0 <= yTop && s->y1 > yTop) { |
359 | 1.80M | fillCount += s->count; |
360 | 1.80M | } |
361 | 2.36M | } |
362 | 94.9k | } |
363 | | |
364 | | void SplashXPathScanner::generatePixelsBinary(int x0, int x1, Guchar *line, |
365 | 5.96k | int *xMin, int *xMax) { |
366 | 5.96k | SplashXPathSeg *s; |
367 | 5.96k | int fillCount, x, xEnd, ix0, ix1, t; |
368 | | |
369 | 5.96k | fillCount = 0; |
370 | 5.96k | x = x0; |
371 | 5.96k | xEnd = x1 + 1; |
372 | 17.8k | for (s = pre->next; s != post && x < xEnd; s = s->next) { |
373 | 11.9k | ix0 = splashFloor(s->sx0); |
374 | 11.9k | ix1 = splashFloor(s->sx1); |
375 | 11.9k | if (ix0 > ix1) { |
376 | 1.82k | t = ix0; ix0 = ix1; ix1 = t; |
377 | 1.82k | } |
378 | 11.9k | if (!(fillCount & eoMask)) { |
379 | 6.85k | if (ix0 > x) { |
380 | 46 | x = ix0; |
381 | 46 | } |
382 | 6.85k | } |
383 | 11.9k | if (ix1 >= xEnd) { |
384 | 2.49k | ix1 = xEnd - 1; |
385 | 2.49k | } |
386 | 11.9k | if (x < *xMin) { |
387 | 5.85k | *xMin = x; |
388 | 5.85k | } |
389 | 11.9k | if (ix1 > *xMax) { |
390 | 5.70k | *xMax = ix1; |
391 | 5.70k | } |
392 | 17.5k | for (; x <= ix1; ++x) { |
393 | 5.65k | line[x] = 255; |
394 | 5.65k | } |
395 | 11.9k | if (s->y0 <= yTop && s->y1 > yTop) { |
396 | 9.16k | fillCount += s->count; |
397 | 9.16k | } |
398 | 11.9k | } |
399 | 5.96k | } |
400 | | |
401 | | void SplashXPathScanner::drawRectangleSpan(Guchar *line, int y, |
402 | | int x0, int x1, |
403 | 15.2k | int *xMin, int *xMax) { |
404 | 15.2k | SplashCoord edge; |
405 | 15.2k | Guchar pix; |
406 | 15.2k | int xe, x; |
407 | | |
408 | 15.2k | if (rectX0I > x1 || rectX1I < x0) { |
409 | 185 | return; |
410 | 185 | } |
411 | | |
412 | 15.0k | *xMin = x0 <= rectX0I ? rectX0I : x0; |
413 | 15.0k | *xMax = rectX1I <= x1 ? rectX1I : x1; |
414 | | |
415 | | //--- upper edge |
416 | 15.0k | if (y == rectY0I) { |
417 | | |
418 | | // handle a rectangle less than one pixel high |
419 | 2.98k | if (rectY0I == rectY1I) { |
420 | 2.35k | edge = xPath->rectY1 - xPath->rectY0; |
421 | 2.35k | } else { |
422 | 635 | edge = (SplashCoord)1 - (xPath->rectY0 - rectY0I); |
423 | 635 | } |
424 | | |
425 | | // upper left corner |
426 | 2.98k | if (x0 <= rectX0I) { |
427 | 2.91k | pix = (Guchar)splashCeil(edge |
428 | 2.91k | * ((SplashCoord)1 - (xPath->rectX0 - rectX0I)) |
429 | 2.91k | * 255); |
430 | 2.91k | if (pix < 16) { |
431 | 2.29k | pix = 16; |
432 | 2.29k | } |
433 | 2.91k | line[rectX0I] = pix; |
434 | 2.91k | x = rectX0I + 1; |
435 | 2.91k | } else { |
436 | 68 | x = x0; |
437 | 68 | } |
438 | | |
439 | | // upper right corner |
440 | 2.98k | if (rectX1I <= x1) { |
441 | 2.89k | pix = (Guchar)splashCeil(edge * (xPath->rectX1 - rectX1I) * 255); |
442 | 2.89k | if (pix < 16) { |
443 | 2.88k | pix = 16; |
444 | 2.88k | } |
445 | 2.89k | line[rectX1I] = pix; |
446 | 2.89k | xe = rectX1I - 1; |
447 | 2.89k | } else { |
448 | 91 | xe = x1; |
449 | 91 | } |
450 | | |
451 | | // upper edge |
452 | 2.98k | pix = (Guchar)splashCeil(edge * 255); |
453 | 2.98k | if (pix < 16) { |
454 | 2.35k | pix = 16; |
455 | 2.35k | } |
456 | 3.05k | for (; x <= xe; ++x) { |
457 | 68 | line[x] = pix; |
458 | 68 | } |
459 | | |
460 | | //--- lower edge |
461 | 12.0k | } else if (y == rectY1I) { |
462 | 274 | edge = xPath->rectY1 - rectY1I; |
463 | | |
464 | | // lower left corner |
465 | 274 | if (x0 <= rectX0I) { |
466 | 274 | pix = (Guchar)splashCeil(edge |
467 | 274 | * ((SplashCoord)1 - (xPath->rectX0 - rectX0I)) |
468 | 274 | * 255); |
469 | 274 | if (pix < 16) { |
470 | 267 | pix = 16; |
471 | 267 | } |
472 | 274 | line[rectX0I] = pix; |
473 | 274 | x = rectX0I + 1; |
474 | 274 | } else { |
475 | 0 | x = x0; |
476 | 0 | } |
477 | | |
478 | | // lower right corner |
479 | 274 | if (rectX1I <= x1) { |
480 | 274 | pix = (Guchar)splashCeil(edge * (xPath->rectX1 - rectX1I) * 255); |
481 | 274 | if (pix < 16) { |
482 | 274 | pix = 16; |
483 | 274 | } |
484 | 274 | line[rectX1I] = pix; |
485 | 274 | xe = rectX1I - 1; |
486 | 274 | } else { |
487 | 0 | xe = x1; |
488 | 0 | } |
489 | | |
490 | | // lower edge |
491 | 274 | pix = (Guchar)splashCeil(edge * 255); |
492 | 274 | if (pix < 16) { |
493 | 267 | pix = 16; |
494 | 267 | } |
495 | 274 | for (; x <= xe; ++x) { |
496 | 0 | line[x] = pix; |
497 | 0 | } |
498 | | |
499 | | //--- between the upper and lower edges |
500 | 11.7k | } else if (y > rectY0I && y < rectY1I) { |
501 | | |
502 | | // left edge |
503 | 11.4k | if (x0 <= rectX0I) { |
504 | 10.3k | pix = (Guchar)splashCeil(((SplashCoord)1 - (xPath->rectX0 - rectX0I)) |
505 | 10.3k | * 255); |
506 | 10.3k | if (pix < 16) { |
507 | 0 | pix = 16; |
508 | 0 | } |
509 | 10.3k | line[rectX0I] = pix; |
510 | 10.3k | x = rectX0I + 1; |
511 | 10.3k | } else { |
512 | 1.08k | x = x0; |
513 | 1.08k | } |
514 | | |
515 | | // right edge |
516 | 11.4k | if (rectX1I <= x1) { |
517 | 6.82k | pix = (Guchar)splashCeil((xPath->rectX1 - rectX1I) * 255); |
518 | 6.82k | if (pix < 16) { |
519 | 6.77k | pix = 16; |
520 | 6.77k | } |
521 | 6.82k | line[rectX1I] = pix; |
522 | 6.82k | xe = rectX1I - 1; |
523 | 6.82k | } else { |
524 | 4.66k | xe = x1; |
525 | 4.66k | } |
526 | | |
527 | | // middle |
528 | 12.5k | for (; x <= xe; ++x) { |
529 | 1.08k | line[x] = 255; |
530 | 1.08k | } |
531 | 11.4k | } |
532 | 15.0k | } |
533 | | |
534 | | void SplashXPathScanner::drawRectangleSpanBinary(Guchar *line, int y, |
535 | | int x0, int x1, |
536 | 0 | int *xMin, int *xMax) { |
537 | 0 | int xe, x; |
538 | |
|
539 | 0 | if (y >= rectY0I && y <= rectY1I) { |
540 | 0 | if (x0 <= rectX0I) { |
541 | 0 | x = rectX0I; |
542 | 0 | } else { |
543 | 0 | x = x0; |
544 | 0 | } |
545 | 0 | *xMin = x; |
546 | 0 | if (rectX1I <= x1) { |
547 | 0 | xe = rectX1I; |
548 | 0 | } else { |
549 | 0 | xe = x1; |
550 | 0 | } |
551 | 0 | *xMax = xe; |
552 | 0 | for (; x <= xe; ++x) { |
553 | 0 | line[x] = 255; |
554 | 0 | } |
555 | 0 | } |
556 | 0 | } |
557 | | |
558 | | void SplashXPathScanner::getSpan(Guchar *line, int y, int x0, int x1, |
559 | 38.9k | int *xMin, int *xMax) { |
560 | 38.9k | int iy, x, k; |
561 | | |
562 | 38.9k | iy = y * aaVert; |
563 | 38.9k | if (!resetDone || !resetAA) { |
564 | 32.6k | reset(gTrue, gTrue); |
565 | 32.6k | } else if (yBottomI > iy) { |
566 | 6.28k | reset(gTrue, gFalse); |
567 | 6.28k | } |
568 | 38.9k | memset(line + x0, 0, x1 - x0 + 1); |
569 | | |
570 | 38.9k | *xMin = x1 + 1; |
571 | 38.9k | *xMax = x0 - 1; |
572 | | |
573 | 38.9k | if (xPath->isRect) { |
574 | 15.2k | drawRectangleSpan(line, y, x0, x1, xMin, xMax); |
575 | 15.2k | return; |
576 | 15.2k | } |
577 | | |
578 | 23.7k | if (yBottomI < iy) { |
579 | 18.5k | skip(iy, gTrue); |
580 | 18.5k | } |
581 | 118k | for (k = 0; k < aaVert; ++k, ++iy) { |
582 | 94.9k | advance(gTrue); |
583 | 94.9k | generatePixels(x0, x1, line, xMin, xMax); |
584 | 94.9k | } |
585 | | |
586 | 23.7k | #if !ANTIALIAS_256 |
587 | 41.1k | for (x = *xMin; x <= *xMax; ++x) { |
588 | 17.3k | line[x] = map16to255[line[x]]; |
589 | 17.3k | } |
590 | 23.7k | #endif |
591 | 23.7k | } |
592 | | |
593 | | void SplashXPathScanner::getSpanBinary(Guchar *line, int y, int x0, int x1, |
594 | 5.96k | int *xMin, int *xMax) { |
595 | 5.96k | int iy; |
596 | | |
597 | 5.96k | iy = y; |
598 | 5.96k | if (!resetDone || resetAA) { |
599 | 1.29k | reset(gFalse, gTrue); |
600 | 4.67k | } else if (yBottomI > iy) { |
601 | 4.67k | reset(gFalse, gFalse); |
602 | 4.67k | } |
603 | 5.96k | memset(line + x0, 0, x1 - x0 + 1); |
604 | | |
605 | 5.96k | *xMin = x1 + 1; |
606 | 5.96k | *xMax = x0 - 1; |
607 | | |
608 | 5.96k | if (xPath->isRect) { |
609 | 0 | drawRectangleSpanBinary(line, y, x0, x1, xMin, xMax); |
610 | 0 | return; |
611 | 0 | } |
612 | | |
613 | 5.96k | if (yBottomI < iy) { |
614 | 5.58k | skip(iy, gFalse); |
615 | 5.58k | } |
616 | 5.96k | advance(gFalse); |
617 | 5.96k | generatePixelsBinary(x0, x1, line, xMin, xMax); |
618 | 5.96k | } |