Line | Source Code | Coverage |
---|
1 | | - |
2 | | - |
3 | | - |
4 | namespace | - |
5 | { | - |
6 | enum FillHDir | - |
7 | { | - |
8 | LeftToRight, | - |
9 | RightToLeft | - |
10 | }; | - |
11 | | - |
12 | enum FillVDir | - |
13 | { | - |
14 | TopDown, | - |
15 | BottomUp | - |
16 | }; | - |
17 | | - |
18 | enum FillClip | - |
19 | { | - |
20 | NoClip, | - |
21 | Clip | - |
22 | }; | - |
23 | } | - |
24 | | - |
25 | template <FillClip clip, FillHDir dir> | - |
26 | inline void fillLine(qint32 *, int, int, int, qint32, qint32) | - |
27 | { | - |
28 | } | - |
29 | | - |
30 | template <> | - |
31 | inline void fillLine<Clip, LeftToRight>(qint32 *line, int width, int lx, int rx, qint32 d, qint32 dd) | - |
32 | { | - |
33 | int fromX = qMax(0, lx >> 8); | - |
34 | int toX = qMin(width, rx >> 8); | - |
35 | int x = toX - fromX; | - |
36 | if (x <= 0) | 0 |
37 | return; | 0 |
38 | qint32 val = d + (((fromX << 8) + 0xff - lx) * dd >> 8); | - |
39 | line += fromX; | - |
40 | do { | - |
41 | *line = abs(val) < abs(*line) ? val : *line; never evaluated: abs(val) < abs(*line) | 0 |
42 | val += dd; | - |
43 | ++line; | - |
44 | } while (--x); | 0 |
45 | } | 0 |
46 | | - |
47 | template <> | - |
48 | inline void fillLine<Clip, RightToLeft>(qint32 *line, int width, int lx, int rx, qint32 d, qint32 dd) | - |
49 | { | - |
50 | int fromX = qMax(0, lx >> 8); | - |
51 | int toX = qMin(width, rx >> 8); | - |
52 | int x = toX - fromX; | - |
53 | if (x <= 0) | 0 |
54 | return; | 0 |
55 | qint32 val = d + (((toX << 8) + 0xff - rx) * dd >> 8); | - |
56 | line += toX; | - |
57 | do { | - |
58 | val -= dd; | - |
59 | --line; | - |
60 | *line = abs(val) < abs(*line) ? val : *line; never evaluated: abs(val) < abs(*line) | 0 |
61 | } while (--x); | 0 |
62 | } | 0 |
63 | | - |
64 | template <> | - |
65 | inline void fillLine<NoClip, LeftToRight>(qint32 *line, int, int lx, int rx, qint32 d, qint32 dd) | - |
66 | { | - |
67 | int fromX = lx >> 8; | - |
68 | int toX = rx >> 8; | - |
69 | int x = toX - fromX; | - |
70 | if (x <= 0) | 0 |
71 | return; | 0 |
72 | qint32 val = d + ((~lx & 0xff) * dd >> 8); | - |
73 | line += fromX; | - |
74 | do { | - |
75 | *line = abs(val) < abs(*line) ? val : *line; never evaluated: abs(val) < abs(*line) | 0 |
76 | val += dd; | - |
77 | ++line; | - |
78 | } while (--x); | 0 |
79 | } | 0 |
80 | | - |
81 | template <> | - |
82 | inline void fillLine<NoClip, RightToLeft>(qint32 *line, int, int lx, int rx, qint32 d, qint32 dd) | - |
83 | { | - |
84 | int fromX = lx >> 8; | - |
85 | int toX = rx >> 8; | - |
86 | int x = toX - fromX; | - |
87 | if (x <= 0) | 0 |
88 | return; | 0 |
89 | qint32 val = d + ((~rx & 0xff) * dd >> 8); | - |
90 | line += toX; | - |
91 | do { | - |
92 | val -= dd; | - |
93 | --line; | - |
94 | *line = abs(val) < abs(*line) ? val : *line; never evaluated: abs(val) < abs(*line) | 0 |
95 | } while (--x); | 0 |
96 | } | 0 |
97 | | - |
98 | template <FillClip clip, FillVDir vDir, FillHDir hDir> | - |
99 | inline void fillLines(qint32 *bits, int width, int height, int upperY, int lowerY, | - |
100 | int &lx, int ldx, int &rx, int rdx, qint32 &d, qint32 ddy, qint32 ddx) | - |
101 | { | - |
102 | (void)height;; | - |
103 | qt_noop(); | - |
104 | int y = lowerY - upperY; | - |
105 | if (vDir == TopDown) { never evaluated: vDir == TopDown | 0 |
106 | qint32 *line = bits + upperY * width; | - |
107 | do { | - |
108 | fillLine<clip, hDir>(line, width, lx, rx, d, ddx); | - |
109 | lx += ldx; | - |
110 | d += ddy; | - |
111 | rx += rdx; | - |
112 | line += width; | - |
113 | } while (--y); | 0 |
114 | } else { | 0 |
115 | qint32 *line = bits + lowerY * width; | - |
116 | do { | - |
117 | lx -= ldx; | - |
118 | d -= ddy; | - |
119 | rx -= rdx; | - |
120 | line -= width; | - |
121 | fillLine<clip, hDir>(line, width, lx, rx, d, ddx); | - |
122 | } while (--y); | 0 |
123 | } | 0 |
124 | } | - |
125 | | - |
126 | template <FillClip clip> | - |
127 | void drawTriangle(qint32 *bits, int width, int height, const QPoint *center, | - |
128 | const QPoint *v1, const QPoint *v2, qint32 value) | - |
129 | { | - |
130 | const int y1 = clip == Clip ? qBound(0, v1->y() >> 8, height) : v1->y() >> 8; never evaluated: clip == Clip | 0 |
131 | const int y2 = clip == Clip ? qBound(0, v2->y() >> 8, height) : v2->y() >> 8; never evaluated: clip == Clip | 0 |
132 | const int yC = clip == Clip ? qBound(0, center->y() >> 8, height) : center->y() >> 8; never evaluated: clip == Clip | 0 |
133 | | - |
134 | const int v1Frac = clip == Clip ? (y1 << 8) + 0xff - v1->y() : ~v2->y() & 0xff; never evaluated: clip == Clip | 0 |
135 | const int v2Frac = clip == Clip ? (y2 << 8) + 0xff - v2->y() : ~v1->y() & 0xff; never evaluated: clip == Clip | 0 |
136 | const int centerFrac = clip == Clip ? (yC << 8) + 0xff - center->y() : ~center->y() & 0xff; never evaluated: clip == Clip | 0 |
137 | | - |
138 | int dx1 = 0, x1 = 0, dx2 = 0, x2 = 0; | - |
139 | qint32 dd1, d1, dd2, d2; | - |
140 | if (v1->y() != center->y()) { never evaluated: v1->y() != center->y() | 0 |
141 | dx1 = ((v1->x() - center->x()) << 8) / (v1->y() - center->y()); | - |
142 | x1 = center->x() + centerFrac * (v1->x() - center->x()) / (v1->y() - center->y()); | - |
143 | } | 0 |
144 | if (v2->y() != center->y()) { never evaluated: v2->y() != center->y() | 0 |
145 | dx2 = ((v2->x() - center->x()) << 8) / (v2->y() - center->y()); | - |
146 | x2 = center->x() + centerFrac * (v2->x() - center->x()) / (v2->y() - center->y()); | - |
147 | } | 0 |
148 | | - |
149 | const qint32 div = (v2->x() - center->x()) * (v1->y() - center->y()) | - |
150 | - (v2->y() - center->y()) * (v1->x() - center->x()); | - |
151 | const qint32 dd = div ? qint32((qint64(value * (v1->y() - v2->y())) << 8) / div) : 0; | 0 |
152 | | - |
153 | if (y2 < yC) { | 0 |
154 | if (y1 < yC) { | 0 |
155 | | - |
156 | if (y2 < y1) { | 0 |
157 | | - |
158 | | - |
159 | d1 = centerFrac * value / (v1->y() - center->y()); | - |
160 | dd1 = ((value << 8) / (v1->y() - center->y())); | - |
161 | fillLines<clip, BottomUp, LeftToRight>(bits, width, height, y1, yC, x1, dx1, | - |
162 | x2, dx2, d1, dd1, dd); | - |
163 | dx1 = ((v1->x() - v2->x()) << 8) / (v1->y() - v2->y()); | - |
164 | x1 = v1->x() + v1Frac * (v1->x() - v2->x()) / (v1->y() - v2->y()); | - |
165 | fillLines<clip, BottomUp, LeftToRight>(bits, width, height, y2, y1, x1, dx1, | - |
166 | x2, dx2, value, 0, dd); | - |
167 | } else { | 0 |
168 | | - |
169 | | - |
170 | d2 = centerFrac * value / (v2->y() - center->y()); | - |
171 | dd2 = ((value << 8) / (v2->y() - center->y())); | - |
172 | fillLines<clip, BottomUp, RightToLeft>(bits, width, height, y2, yC, x1, dx1, | - |
173 | x2, dx2, d2, dd2, dd); | - |
174 | if (y1 != y2) { never evaluated: y1 != y2 | 0 |
175 | dx2 = ((v1->x() - v2->x()) << 8) / (v1->y() - v2->y()); | - |
176 | x2 = v2->x() + v2Frac * (v1->x() - v2->x()) / (v1->y() - v2->y()); | - |
177 | fillLines<clip, BottomUp, RightToLeft>(bits, width, height, y1, y2, x1, dx1, | - |
178 | x2, dx2, value, 0, dd); | - |
179 | } | 0 |
180 | } | 0 |
181 | } else { | - |
182 | | - |
183 | | - |
184 | int dx = ((v1->x() - v2->x()) << 8) / (v1->y() - v2->y()); | - |
185 | int xUp, xDn; | - |
186 | xUp = xDn = v2->x() + (clip == Clip ? (yC << 8) + 0xff - v2->y() never evaluated: clip == Clip | 0 |
187 | : (center->y() | 0xff) - v2->y()) | - |
188 | * (v1->x() - v2->x()) / (v1->y() - v2->y()); | - |
189 | fillLines<clip, BottomUp, LeftToRight>(bits, width, height, y2, yC, xUp, dx, | - |
190 | x2, dx2, value, 0, dd); | - |
191 | if (yC != y1) never evaluated: yC != y1 | 0 |
192 | fillLines<clip, TopDown, LeftToRight>(bits, width, height, yC, y1, xDn, dx, | 0 |
193 | x1, dx1, value, 0, dd); never executed: fillLines<clip, TopDown, LeftToRight>(bits, width, height, yC, y1, xDn, dx, x1, dx1, value, 0, dd); | 0 |
194 | } | 0 |
195 | } else { | - |
196 | if (y1 < yC) { | 0 |
197 | | - |
198 | | - |
199 | int dx = ((v1->x() - v2->x()) << 8) / (v1->y() - v2->y()); | - |
200 | int xUp, xDn; | - |
201 | xUp = xDn = v1->x() + (clip == Clip ? (yC << 8) + 0xff - v1->y() never evaluated: clip == Clip | 0 |
202 | : (center->y() | 0xff) - v1->y()) | - |
203 | * (v1->x() - v2->x()) / (v1->y() - v2->y()); | - |
204 | fillLines<clip, BottomUp, RightToLeft>(bits, width, height, y1, yC, x1, dx1, | - |
205 | xUp, dx, value, 0, dd); | - |
206 | if (yC != y2) never evaluated: yC != y2 | 0 |
207 | fillLines<clip, TopDown, RightToLeft>(bits, width, height, yC, y2, x2, dx2, | 0 |
208 | xDn, dx, value, 0, dd); never executed: fillLines<clip, TopDown, RightToLeft>(bits, width, height, yC, y2, x2, dx2, xDn, dx, value, 0, dd); | 0 |
209 | } else { | 0 |
210 | | - |
211 | if (y2 < y1) { | 0 |
212 | | - |
213 | | - |
214 | if (yC != y2) { never evaluated: yC != y2 | 0 |
215 | d2 = centerFrac * value / (v2->y() - center->y()); | - |
216 | dd2 = ((value << 8) / (v2->y() - center->y())); | - |
217 | fillLines<clip, TopDown, LeftToRight>(bits, width, height, yC, y2, x2, dx2, | - |
218 | x1, dx1, d2, dd2, dd); | - |
219 | } | 0 |
220 | dx2 = ((v1->x() - v2->x()) << 8) / (v1->y() - v2->y()); | - |
221 | x2 = v2->x() + v2Frac * (v1->x() - v2->x()) / (v1->y() - v2->y()); | - |
222 | fillLines<clip, TopDown, LeftToRight>(bits, width, height, y2, y1, x2, dx2, | - |
223 | x1, dx1, value, 0, dd); | - |
224 | } else { | 0 |
225 | | - |
226 | | - |
227 | if (yC != y1) { never evaluated: yC != y1 | 0 |
228 | d1 = centerFrac * value / (v1->y() - center->y()); | - |
229 | dd1 = ((value << 8) / (v1->y() - center->y())); | - |
230 | fillLines<clip, TopDown, RightToLeft>(bits, width, height, yC, y1, x2, dx2, | - |
231 | x1, dx1, d1, dd1, dd); | - |
232 | } | 0 |
233 | if (y1 != y2) { never evaluated: y1 != y2 | 0 |
234 | dx1 = ((v1->x() - v2->x()) << 8) / (v1->y() - v2->y()); | - |
235 | x1 = v1->x() + v1Frac * (v1->x() - v2->x()) / (v1->y() - v2->y()); | - |
236 | fillLines<clip, TopDown, RightToLeft>(bits, width, height, y1, y2, x2, dx2, | - |
237 | x1, dx1, value, 0, dd); | - |
238 | } | 0 |
239 | } | 0 |
240 | } | - |
241 | } | - |
242 | } | - |
243 | | - |
244 | template <FillClip clip> | - |
245 | void drawRectangle(qint32 *bits, int width, int height, | - |
246 | const QPoint *int1, const QPoint *center1, const QPoint *ext1, | - |
247 | const QPoint *int2, const QPoint *center2, const QPoint *ext2, | - |
248 | qint32 extValue) | - |
249 | { | - |
250 | if (center1->y() > center2->y()) { never evaluated: center1->y() > center2->y() | 0 |
251 | qSwap(center1, center2); | - |
252 | qSwap(int1, ext2); | - |
253 | qSwap(ext1, int2); | - |
254 | extValue = -extValue; | - |
255 | } | 0 |
256 | | - |
257 | qt_noop(); | - |
258 | qt_noop(); | - |
259 | qt_noop(); | - |
260 | qt_noop(); | - |
261 | | - |
262 | const int yc1 = clip == Clip ? qBound(0, center1->y() >> 8, height) : center1->y() >> 8; never evaluated: clip == Clip | 0 |
263 | const int yc2 = clip == Clip ? qBound(0, center2->y() >> 8, height) : center2->y() >> 8; never evaluated: clip == Clip | 0 |
264 | const int yi1 = clip == Clip ? qBound(0, int1->y() >> 8, height) : int1->y() >> 8; never evaluated: clip == Clip | 0 |
265 | const int yi2 = clip == Clip ? qBound(0, int2->y() >> 8, height) : int2->y() >> 8; never evaluated: clip == Clip | 0 |
266 | const int ye1 = clip == Clip ? qBound(0, ext1->y() >> 8, height) : ext1->y() >> 8; never evaluated: clip == Clip | 0 |
267 | const int ye2 = clip == Clip ? qBound(0, ext2->y() >> 8, height) : ext2->y() >> 8; never evaluated: clip == Clip | 0 |
268 | | - |
269 | const int center1Frac = clip == Clip ? (yc1 << 8) + 0xff - center1->y() : ~center1->y() & 0xff; never evaluated: clip == Clip | 0 |
270 | const int center2Frac = clip == Clip ? (yc2 << 8) + 0xff - center2->y() : ~center2->y() & 0xff; never evaluated: clip == Clip | 0 |
271 | const int int1Frac = clip == Clip ? (yi1 << 8) + 0xff - int1->y() : ~int1->y() & 0xff; never evaluated: clip == Clip | 0 |
272 | const int ext1Frac = clip == Clip ? (ye1 << 8) + 0xff - ext1->y() : ~ext1->y() & 0xff; never evaluated: clip == Clip | 0 |
273 | | - |
274 | int dxC = 0, dxE = 0; | - |
275 | qint32 ddC = 0; | - |
276 | if (ext1->y() != int1->y()) { never evaluated: ext1->y() != int1->y() | 0 |
277 | dxC = ((ext1->x() - int1->x()) << 8) / (ext1->y() - int1->y()); | - |
278 | ddC = (extValue << 9) / (ext1->y() - int1->y()); | - |
279 | } | 0 |
280 | if (ext1->y() != ext2->y()) never evaluated: ext1->y() != ext2->y() | 0 |
281 | dxE = ((ext1->x() - ext2->x()) << 8) / (ext1->y() - ext2->y()); never executed: dxE = ((ext1->x() - ext2->x()) << 8) / (ext1->y() - ext2->y()); | 0 |
282 | | - |
283 | const qint32 div = (ext1->x() - int1->x()) * (ext2->y() - int1->y()) | - |
284 | - (ext1->y() - int1->y()) * (ext2->x() - int1->x()); | - |
285 | const qint32 dd = div ? qint32((qint64(extValue * (ext2->y() - ext1->y())) << 9) / div) : 0; | 0 |
286 | | - |
287 | int xe1, xe2, xc1, xc2; | - |
288 | qint32 d; | - |
289 | | - |
290 | qint32 intValue = -extValue; | - |
291 | | - |
292 | if (center2->x() < center1->x()) { never evaluated: center2->x() < center1->x() | 0 |
293 | | - |
294 | if (int1->y() < ext2->y()) { never evaluated: int1->y() < ext2->y() | 0 |
295 | | - |
296 | qt_noop(); | - |
297 | xe1 = ext1->x() + ext1Frac * (ext1->x() - ext2->x()) / (ext1->y() - ext2->y()); | - |
298 | xe2 = int1->x() + int1Frac * (ext1->x() - ext2->x()) / (ext1->y() - ext2->y()); | - |
299 | if (ye1 != yi1) { never evaluated: ye1 != yi1 | 0 |
300 | xc2 = center1->x() + center1Frac * (ext1->x() - int1->x()) / (ext1->y() - int1->y()); | - |
301 | xc2 += (ye1 - yc1) * dxC; | - |
302 | fillLines<clip, TopDown, LeftToRight>(bits, width, height, ye1, yi1, xe1, dxE, | - |
303 | xc2, dxC, extValue, 0, dd); | - |
304 | } | 0 |
305 | if (yi1 != ye2) never evaluated: yi1 != ye2 | 0 |
306 | fillLines<clip, TopDown, LeftToRight>(bits, width, height, yi1, ye2, xe1, dxE, | 0 |
307 | xe2, dxE, extValue, 0, dd); never executed: fillLines<clip, TopDown, LeftToRight>(bits, width, height, yi1, ye2, xe1, dxE, xe2, dxE, extValue, 0, dd); | 0 |
308 | if (ye2 != yi2) { never evaluated: ye2 != yi2 | 0 |
309 | xc1 = center2->x() + center2Frac * (ext1->x() - int1->x()) / (ext1->y() - int1->y()); | - |
310 | xc1 += (ye2 - yc2) * dxC; | - |
311 | fillLines<clip, TopDown, RightToLeft>(bits, width, height, ye2, yi2, xc1, dxC, | - |
312 | xe2, dxE, intValue, 0, dd); | - |
313 | } | 0 |
314 | } else { | 0 |
315 | | - |
316 | qt_noop(); | - |
317 | xc1 = center2->x() + center2Frac * (ext1->x() - int1->x()) / (ext1->y() - int1->y()); | - |
318 | xc2 = center1->x() + center1Frac * (ext1->x() - int1->x()) / (ext1->y() - int1->y()); | - |
319 | xc1 += (ye2 - yc2) * dxC; | - |
320 | xc2 += (ye1 - yc1) * dxC; | - |
321 | if (ye1 != ye2) { never evaluated: ye1 != ye2 | 0 |
322 | xe1 = ext1->x() + ext1Frac * (ext1->x() - ext2->x()) / (ext1->y() - ext2->y()); | - |
323 | fillLines<clip, TopDown, LeftToRight>(bits, width, height, ye1, ye2, xe1, dxE, | - |
324 | xc2, dxC, extValue, 0, dd); | - |
325 | } | 0 |
326 | if (ye2 != yi1) { never evaluated: ye2 != yi1 | 0 |
327 | d = (clip == Clip ? (ye2 << 8) + 0xff - center2->y() never evaluated: clip == Clip | 0 |
328 | : (ext2->y() | 0xff) - center2->y()) | - |
329 | * 2 * extValue / (ext1->y() - int1->y()); | - |
330 | fillLines<clip, TopDown, LeftToRight>(bits, width, height, ye2, yi1, xc1, dxC, | - |
331 | xc2, dxC, d, ddC, dd); | - |
332 | } | 0 |
333 | if (yi1 != yi2) { never evaluated: yi1 != yi2 | 0 |
334 | xe2 = int1->x() + int1Frac * (ext1->x() - ext2->x()) / (ext1->y() - ext2->y()); | - |
335 | fillLines<clip, TopDown, RightToLeft>(bits, width, height, yi1, yi2, xc1, dxC, | - |
336 | xe2, dxE, intValue, 0, dd); | - |
337 | } | 0 |
338 | } | 0 |
339 | } else { | - |
340 | | - |
341 | if (ext1->y() < int2->y()) { never evaluated: ext1->y() < int2->y() | 0 |
342 | | - |
343 | qt_noop(); | - |
344 | xe1 = ext1->x() + ext1Frac * (ext1->x() - ext2->x()) / (ext1->y() - ext2->y()); | - |
345 | xe2 = int1->x() + int1Frac * (ext1->x() - ext2->x()) / (ext1->y() - ext2->y()); | - |
346 | if (yi1 != ye1) { never evaluated: yi1 != ye1 | 0 |
347 | xc1 = center1->x() + center1Frac * (ext1->x() - int1->x()) / (ext1->y() - int1->y()); | - |
348 | xc1 += (yi1 - yc1) * dxC; | - |
349 | fillLines<clip, TopDown, RightToLeft>(bits, width, height, yi1, ye1, xc1, dxC, | - |
350 | xe2, dxE, intValue, 0, dd); | - |
351 | } | 0 |
352 | if (ye1 != yi2) never evaluated: ye1 != yi2 | 0 |
353 | fillLines<clip, TopDown, RightToLeft>(bits, width, height, ye1, yi2, xe1, dxE, | 0 |
354 | xe2, dxE, intValue, 0, dd); never executed: fillLines<clip, TopDown, RightToLeft>(bits, width, height, ye1, yi2, xe1, dxE, xe2, dxE, intValue, 0, dd); | 0 |
355 | if (yi2 != ye2) { never evaluated: yi2 != ye2 | 0 |
356 | xc2 = center2->x() + center2Frac * (ext1->x() - int1->x()) / (ext1->y() - int1->y()); | - |
357 | xc2 += (yi2 - yc2) * dxC; | - |
358 | fillLines<clip, TopDown, LeftToRight>(bits, width, height, yi2, ye2, xe1, dxE, | - |
359 | xc2, dxC, extValue, 0, dd); | - |
360 | } | 0 |
361 | } else { | 0 |
362 | | - |
363 | qt_noop(); | - |
364 | xc1 = center1->x() + center1Frac * (ext1->x() - int1->x()) / (ext1->y() - int1->y()); | - |
365 | xc2 = center2->x() + center2Frac * (ext1->x() - int1->x()) / (ext1->y() - int1->y()); | - |
366 | xc1 += (yi1 - yc1) * dxC; | - |
367 | xc2 += (yi2 - yc2) * dxC; | - |
368 | if (yi1 != yi2) { never evaluated: yi1 != yi2 | 0 |
369 | xe2 = int1->x() + int1Frac * (ext1->x() - ext2->x()) / (ext1->y() - ext2->y()); | - |
370 | fillLines<clip, TopDown, RightToLeft>(bits, width, height, yi1, yi2, xc1, dxC, | - |
371 | xe2, dxE, intValue, 0, dd); | - |
372 | } | 0 |
373 | if (yi2 != ye1) { never evaluated: yi2 != ye1 | 0 |
374 | d = (clip == Clip ? (yi2 << 8) + 0xff - center2->y() never evaluated: clip == Clip | 0 |
375 | : (int2->y() | 0xff) - center2->y()) | - |
376 | * 2 * extValue / (ext1->y() - int1->y()); | - |
377 | fillLines<clip, TopDown, RightToLeft>(bits, width, height, yi2, ye1, xc1, dxC, | - |
378 | xc2, dxC, d, ddC, dd); | - |
379 | } | 0 |
380 | if (ye1 != ye2) { never evaluated: ye1 != ye2 | 0 |
381 | xe1 = ext1->x() + ext1Frac * (ext1->x() - ext2->x()) / (ext1->y() - ext2->y()); | - |
382 | fillLines<clip, TopDown, LeftToRight>(bits, width, height, ye1, ye2, xe1, dxE, | - |
383 | xc2, dxC, extValue, 0, dd); | - |
384 | } | 0 |
385 | } | 0 |
386 | } | - |
387 | } | - |
388 | | - |
389 | static void drawPolygons(qint32 *bits, int width, int height, const QPoint *vertices, | - |
390 | const quint32 *indices, int indexCount, qint32 value) | - |
391 | { | - |
392 | qt_noop(); | - |
393 | qt_noop(); | - |
394 | QVarLengthArray<quint8, 16> scans[128]; | - |
395 | int first = 0; | - |
396 | for (int i = 1; i < indexCount; ++i) { never evaluated: i < indexCount | 0 |
397 | quint32 idx1 = indices[i - 1]; | - |
398 | quint32 idx2 = indices[i]; | - |
399 | qt_noop(); | - |
400 | if (idx2 == quint32(-1)) { never evaluated: idx2 == quint32(-1) | 0 |
401 | idx2 = indices[first]; | - |
402 | qt_noop(); | - |
403 | first = ++i; | - |
404 | } | 0 |
405 | const QPoint *v1 = &vertices[idx1]; | - |
406 | const QPoint *v2 = &vertices[idx2]; | - |
407 | if (v2->y() < v1->y()) never evaluated: v2->y() < v1->y() | 0 |
408 | qSwap(v1, v2); never executed: qSwap(v1, v2); | 0 |
409 | int fromY = qMax(0, v1->y() >> 8); | - |
410 | int toY = qMin(height, v2->y() >> 8); | - |
411 | if (fromY >= toY) never evaluated: fromY >= toY | 0 |
412 | continue; never executed: continue; | 0 |
413 | int dx = ((v2->x() - v1->x()) << 8) / (v2->y() - v1->y()); | - |
414 | int x = v1->x() + ((fromY << 8) + 0xff - v1->y()) * (v2->x() - v1->x()) / (v2->y() - v1->y()); | - |
415 | for (int y = fromY; y < toY; ++y) { | 0 |
416 | quint32 c = quint32(x >> 8); | - |
417 | if (c < quint32(width)) never evaluated: c < quint32(width) | 0 |
418 | scans[y].append(quint8(c)); never executed: scans[y].append(quint8(c)); | 0 |
419 | x += dx; | - |
420 | } | 0 |
421 | } | 0 |
422 | for (int i = 0; i < height; ++i) { never evaluated: i < height | 0 |
423 | quint8 *scanline = scans[i].data(); | - |
424 | int size = scans[i].size(); | - |
425 | for (int j = 1; j < size; ++j) { never evaluated: j < size | 0 |
426 | int k = j; | - |
427 | quint8 value = scanline[k]; | - |
428 | for (; k != 0 && value < scanline[k - 1]; --k) never evaluated: value < scanline[k - 1] | 0 |
429 | scanline[k] = scanline[k - 1]; never executed: scanline[k] = scanline[k - 1]; | 0 |
430 | scanline[k] = value; | - |
431 | } | 0 |
432 | qint32 *line = bits + i * width; | - |
433 | int j = 0; | - |
434 | for (; j + 1 < size; j += 2) { never evaluated: j + 1 < size | 0 |
435 | for (quint8 x = scanline[j]; x < scanline[j + 1]; ++x) never evaluated: x < scanline[j + 1] | 0 |
436 | line[x] = value; never executed: line[x] = value; | 0 |
437 | } | 0 |
438 | if (j < size) { never evaluated: j < size | 0 |
439 | for (int x = scanline[j]; x < width; ++x) never evaluated: x < width | 0 |
440 | line[x] = value; never executed: line[x] = value; | 0 |
441 | } | 0 |
442 | } | 0 |
443 | } | 0 |
444 | | - |
445 | static QImage makeDistanceField(int imgWidth, int imgHeight, const QPainterPath &path, int dfScale, int offs) | - |
446 | { | - |
447 | QImage image(imgWidth, imgHeight, QImage::Format_Indexed8); | - |
448 | | - |
449 | if (path.isEmpty()) { never evaluated: path.isEmpty() | 0 |
450 | image.fill(0); | - |
451 | return image; never executed: return image; | 0 |
452 | } | - |
453 | | - |
454 | QTransform transform; | - |
455 | transform.translate(offs, offs); | - |
456 | transform.scale(qreal(1) / dfScale, qreal(1) / dfScale); | - |
457 | | - |
458 | QDataBuffer<quint32> pathIndices(0); | - |
459 | QDataBuffer<QPoint> pathVertices(0); | - |
460 | qSimplifyPath(path, pathVertices, pathIndices, transform); | - |
461 | | - |
462 | const qint32 interiorColor = -0x7f80; | - |
463 | const qint32 exteriorColor = 0x7f80; | - |
464 | | - |
465 | QScopedArrayPointer<qint32> bits(new qint32[imgWidth * imgHeight]); | - |
466 | for (int i = 0; i < imgWidth * imgHeight; ++i) never evaluated: i < imgWidth * imgHeight | 0 |
467 | bits[i] = exteriorColor; never executed: bits[i] = exteriorColor; | 0 |
468 | | - |
469 | const qreal angleStep = qreal(15 * 3.141592653589793238 / 180); | - |
470 | const QPoint rotation(qRound(cos(angleStep) * 0x4000), | - |
471 | qRound(sin(angleStep) * 0x4000)); | - |
472 | | - |
473 | const quint32 *indices = pathIndices.data(); | - |
474 | QVarLengthArray<QPoint> normals; | - |
475 | QVarLengthArray<QPoint> vertices; | - |
476 | QVarLengthArray<bool> isConvex; | - |
477 | QVarLengthArray<bool> needsClipping; | - |
478 | | - |
479 | drawPolygons(bits.data(), imgWidth, imgHeight, pathVertices.data(), indices, pathIndices.size(), | - |
480 | interiorColor); | - |
481 | | - |
482 | int index = 0; | - |
483 | | - |
484 | while (index < pathIndices.size()) { never evaluated: index < pathIndices.size() | 0 |
485 | normals.clear(); | - |
486 | vertices.clear(); | - |
487 | needsClipping.clear(); | - |
488 | | - |
489 | | - |
490 | int end = index; | - |
491 | while (indices[end] != quint32(-1)) never evaluated: indices[end] != quint32(-1) | 0 |
492 | ++end; | 0 |
493 | | - |
494 | | - |
495 | for (int next = index, prev = end - 1; next < end; prev = next++) { never evaluated: next < end | 0 |
496 | quint32 fromVertexIndex = indices[prev]; | - |
497 | quint32 toVertexIndex = indices[next]; | - |
498 | | - |
499 | const QPoint &from = pathVertices.at(fromVertexIndex); | - |
500 | const QPoint &to = pathVertices.at(toVertexIndex); | - |
501 | | - |
502 | QPoint n(to.y() - from.y(), from.x() - to.x()); | - |
503 | if (n.x() == 0 && n.y() == 0) never evaluated: n.x() == 0 never evaluated: n.y() == 0 | 0 |
504 | continue; never executed: continue; | 0 |
505 | int scale = qRound((offs << 16) / sqrt(qreal(n.x() * n.x() + n.y() * n.y()))); | - |
506 | n.rx() = n.x() * scale >> 8; | - |
507 | n.ry() = n.y() * scale >> 8; | - |
508 | normals.append(n); | - |
509 | QPoint v(to.x() + 0x7f, to.y() + 0x7f); | - |
510 | vertices.append(v); | - |
511 | needsClipping.append((to.x() < offs << 8) || (to.x() >= (imgWidth - offs) << 8) | - |
512 | || (to.y() < offs << 8) || (to.y() >= (imgHeight - offs) << 8)); | - |
513 | } | 0 |
514 | | - |
515 | isConvex.resize(normals.count()); | - |
516 | for (int next = 0, prev = normals.count() - 1; next < normals.count(); prev = next++) { never evaluated: next < normals.count() | 0 |
517 | isConvex[prev] = normals.at(prev).x() * normals.at(next).y() | - |
518 | - normals.at(prev).y() * normals.at(next).x() < 0; | - |
519 | } | 0 |
520 | | - |
521 | | - |
522 | for (int next = 0, prev = normals.count() - 1; next < normals.count(); prev = next++) { never evaluated: next < normals.count() | 0 |
523 | QPoint n = normals.at(next); | - |
524 | QPoint intPrev = vertices.at(prev); | - |
525 | QPoint extPrev = vertices.at(prev); | - |
526 | QPoint intNext = vertices.at(next); | - |
527 | QPoint extNext = vertices.at(next); | - |
528 | | - |
529 | extPrev.rx() -= n.x(); | - |
530 | extPrev.ry() -= n.y(); | - |
531 | intPrev.rx() += n.x(); | - |
532 | intPrev.ry() += n.y(); | - |
533 | extNext.rx() -= n.x(); | - |
534 | extNext.ry() -= n.y(); | - |
535 | intNext.rx() += n.x(); | - |
536 | intNext.ry() += n.y(); | - |
537 | | - |
538 | if (needsClipping[prev] || needsClipping[next]) { never evaluated: needsClipping[prev] never evaluated: needsClipping[next] | 0 |
539 | drawRectangle<Clip>(bits.data(), imgWidth, imgHeight, | - |
540 | &intPrev, &vertices.at(prev), &extPrev, | - |
541 | &intNext, &vertices.at(next), &extNext, | - |
542 | exteriorColor); | - |
543 | } else { | 0 |
544 | drawRectangle<NoClip>(bits.data(), imgWidth, imgHeight, | - |
545 | &intPrev, &vertices.at(prev), &extPrev, | - |
546 | &intNext, &vertices.at(next), &extNext, | - |
547 | exteriorColor); | - |
548 | } | 0 |
549 | | - |
550 | if (isConvex.at(prev)) { never evaluated: isConvex.at(prev) | 0 |
551 | QPoint p = extPrev; | - |
552 | if (needsClipping[prev]) { never evaluated: needsClipping[prev] | 0 |
553 | for (;;) { | - |
554 | QPoint rn((n.x() * rotation.x() - n.y() * rotation.y()) >> 14, | - |
555 | (n.y() * rotation.x() + n.x() * rotation.y()) >> 14); | - |
556 | n = rn; | - |
557 | if (n.x() * normals.at(prev).y() - n.y() * normals.at(prev).x() <= 0) { never evaluated: n.x() * normals.at(prev).y() - n.y() * normals.at(prev).x() <= 0 | 0 |
558 | p.rx() = vertices.at(prev).x() - normals.at(prev).x(); | - |
559 | p.ry() = vertices.at(prev).y() - normals.at(prev).y(); | - |
560 | drawTriangle<Clip>(bits.data(), imgWidth, imgHeight, &vertices.at(prev), | - |
561 | &extPrev, &p, exteriorColor); | - |
562 | break; | 0 |
563 | } | - |
564 | | - |
565 | p.rx() = vertices.at(prev).x() - n.x(); | - |
566 | p.ry() = vertices.at(prev).y() - n.y(); | - |
567 | drawTriangle<Clip>(bits.data(), imgWidth, imgHeight, &vertices.at(prev), | - |
568 | &extPrev, &p, exteriorColor); | - |
569 | extPrev = p; | - |
570 | } | 0 |
571 | } else { | 0 |
572 | for (;;) { | - |
573 | QPoint rn((n.x() * rotation.x() - n.y() * rotation.y()) >> 14, | - |
574 | (n.y() * rotation.x() + n.x() * rotation.y()) >> 14); | - |
575 | n = rn; | - |
576 | if (n.x() * normals.at(prev).y() - n.y() * normals.at(prev).x() <= 0) { never evaluated: n.x() * normals.at(prev).y() - n.y() * normals.at(prev).x() <= 0 | 0 |
577 | p.rx() = vertices.at(prev).x() - normals.at(prev).x(); | - |
578 | p.ry() = vertices.at(prev).y() - normals.at(prev).y(); | - |
579 | drawTriangle<NoClip>(bits.data(), imgWidth, imgHeight, &vertices.at(prev), | - |
580 | &extPrev, &p, exteriorColor); | - |
581 | break; | 0 |
582 | } | - |
583 | | - |
584 | p.rx() = vertices.at(prev).x() - n.x(); | - |
585 | p.ry() = vertices.at(prev).y() - n.y(); | - |
586 | drawTriangle<NoClip>(bits.data(), imgWidth, imgHeight, &vertices.at(prev), | - |
587 | &extPrev, &p, exteriorColor); | - |
588 | extPrev = p; | - |
589 | } | 0 |
590 | } | 0 |
591 | } else { | - |
592 | QPoint p = intPrev; | - |
593 | if (needsClipping[prev]) { never evaluated: needsClipping[prev] | 0 |
594 | for (;;) { | - |
595 | QPoint rn((n.x() * rotation.x() + n.y() * rotation.y()) >> 14, | - |
596 | (n.y() * rotation.x() - n.x() * rotation.y()) >> 14); | - |
597 | n = rn; | - |
598 | if (n.x() * normals.at(prev).y() - n.y() * normals.at(prev).x() >= 0) { never evaluated: n.x() * normals.at(prev).y() - n.y() * normals.at(prev).x() >= 0 | 0 |
599 | p.rx() = vertices.at(prev).x() + normals.at(prev).x(); | - |
600 | p.ry() = vertices.at(prev).y() + normals.at(prev).y(); | - |
601 | drawTriangle<Clip>(bits.data(), imgWidth, imgHeight, &vertices.at(prev), | - |
602 | &p, &intPrev, interiorColor); | - |
603 | break; | 0 |
604 | } | - |
605 | | - |
606 | p.rx() = vertices.at(prev).x() + n.x(); | - |
607 | p.ry() = vertices.at(prev).y() + n.y(); | - |
608 | drawTriangle<Clip>(bits.data(), imgWidth, imgHeight, &vertices.at(prev), | - |
609 | &p, &intPrev, interiorColor); | - |
610 | intPrev = p; | - |
611 | } | 0 |
612 | } else { | 0 |
613 | for (;;) { | - |
614 | QPoint rn((n.x() * rotation.x() + n.y() * rotation.y()) >> 14, | - |
615 | (n.y() * rotation.x() - n.x() * rotation.y()) >> 14); | - |
616 | n = rn; | - |
617 | if (n.x() * normals.at(prev).y() - n.y() * normals.at(prev).x() >= 0) { never evaluated: n.x() * normals.at(prev).y() - n.y() * normals.at(prev).x() >= 0 | 0 |
618 | p.rx() = vertices.at(prev).x() + normals.at(prev).x(); | - |
619 | p.ry() = vertices.at(prev).y() + normals.at(prev).y(); | - |
620 | drawTriangle<NoClip>(bits.data(), imgWidth, imgHeight, &vertices.at(prev), | - |
621 | &p, &intPrev, interiorColor); | - |
622 | break; | 0 |
623 | } | - |
624 | | - |
625 | p.rx() = vertices.at(prev).x() + n.x(); | - |
626 | p.ry() = vertices.at(prev).y() + n.y(); | - |
627 | drawTriangle<NoClip>(bits.data(), imgWidth, imgHeight, &vertices.at(prev), | - |
628 | &p, &intPrev, interiorColor); | - |
629 | intPrev = p; | - |
630 | } | 0 |
631 | } | 0 |
632 | } | - |
633 | } | - |
634 | | - |
635 | index = end + 1; | - |
636 | } | 0 |
637 | | - |
638 | const qint32 *inLine = bits.data(); | - |
639 | uchar *outLine = image.bits(); | - |
640 | int padding = image.bytesPerLine() - image.width(); | - |
641 | for (int y = 0; y < imgHeight; ++y) { never evaluated: y < imgHeight | 0 |
642 | for (int x = 0; x < imgWidth; ++x, ++inLine, ++outLine) never evaluated: x < imgWidth | 0 |
643 | *outLine = uchar((0x7f80 - *inLine) >> 8); never executed: *outLine = uchar((0x7f80 - *inLine) >> 8); | 0 |
644 | outLine += padding; | - |
645 | } | 0 |
646 | | - |
647 | return image; never executed: return image; | 0 |
648 | } | - |
649 | | - |
650 | static bool imageHasNarrowOutlines(const QImage &im) | - |
651 | { | - |
652 | if (im.isNull()) never evaluated: im.isNull() | 0 |
653 | return false; never executed: return false; | 0 |
654 | | - |
655 | int minHThick = 999; | - |
656 | int minVThick = 999; | - |
657 | | - |
658 | int thick = 0; | - |
659 | bool in = false; | - |
660 | int y = (im.height() + 1) / 2; | - |
661 | for (int x = 0; x < im.width(); ++x) { never evaluated: x < im.width() | 0 |
662 | int a = qAlpha(im.pixel(x, y)); | - |
663 | if (a > 127) { | 0 |
664 | in = true; | - |
665 | ++thick; | - |
666 | } else if (in) { | 0 |
667 | in = false; | - |
668 | minHThick = qMin(minHThick, thick); | - |
669 | thick = 0; | - |
670 | } | 0 |
671 | } | - |
672 | | - |
673 | thick = 0; | - |
674 | in = false; | - |
675 | int x = (im.width() + 1) / 2; | - |
676 | for (int y = 0; y < im.height(); ++y) { never evaluated: y < im.height() | 0 |
677 | int a = qAlpha(im.pixel(x, y)); | - |
678 | if (a > 127) { | 0 |
679 | in = true; | - |
680 | ++thick; | - |
681 | } else if (in) { | 0 |
682 | in = false; | - |
683 | minVThick = qMin(minVThick, thick); | - |
684 | thick = 0; | - |
685 | } | 0 |
686 | } | - |
687 | | - |
688 | return minHThick == 1 || minVThick == 1; never executed: return minHThick == 1 || minVThick == 1; | 0 |
689 | } | - |
690 | | - |
691 | bool qt_fontHasNarrowOutlines(QFontEngine *fontEngine) | - |
692 | { | - |
693 | QFontEngine *fe = fontEngine->cloneWithSize(54); | - |
694 | if (!fe) | 0 |
695 | return false; never executed: return false; | 0 |
696 | | - |
697 | QGlyphLayout glyphs; | - |
698 | glyph_t glyph; | - |
699 | glyphs.glyphs = &glyph; | - |
700 | glyphs.numGlyphs = 1; | - |
701 | int numGlyphs = 1; | - |
702 | QChar uc = QLatin1Char('O'); | - |
703 | fe->stringToCMap(&uc, 1, &glyphs, &numGlyphs, QFontEngine::GlyphIndicesOnly); | - |
704 | QImage im = fe->alphaMapForGlyph(glyph, QFixed(), QTransform()); | - |
705 | | - |
706 | qt_noop(); | - |
707 | delete fe; | - |
708 | | - |
709 | return imageHasNarrowOutlines(im); never executed: return imageHasNarrowOutlines(im); | 0 |
710 | } | - |
711 | | - |
712 | bool qt_fontHasNarrowOutlines(const QRawFont &f) | - |
713 | { | - |
714 | QRawFont font = f; | - |
715 | font.setPixelSize(54); | - |
716 | if (!font.isValid()) never evaluated: !font.isValid() | 0 |
717 | return false; never executed: return false; | 0 |
718 | | - |
719 | QVector<quint32> glyphIndices = font.glyphIndexesForString(QLatin1String("O")); | - |
720 | if (glyphIndices.size() < 1) never evaluated: glyphIndices.size() < 1 | 0 |
721 | return false; never executed: return false; | 0 |
722 | | - |
723 | return imageHasNarrowOutlines(font.alphaMapForGlyph(glyphIndices.at(0), | 0 |
724 | QRawFont::PixelAntialiasing)); never executed: return imageHasNarrowOutlines(font.alphaMapForGlyph(glyphIndices.at(0), QRawFont::PixelAntialiasing)); | 0 |
725 | } | - |
726 | | - |
727 | static QImage renderDistanceFieldPath(const QPainterPath &path, bool doubleResolution) | - |
728 | { | - |
729 | int dfMargin = (doubleResolution ? 80 / 2 : 80) / (doubleResolution ? 16 / 2 : 16); never evaluated: doubleResolution never evaluated: doubleResolution | 0 |
730 | int glyphWidth = qCeil(path.boundingRect().width() / (doubleResolution ? 16 / 2 : 16)) + dfMargin * 2; | - |
731 | | - |
732 | QImage im = makeDistanceField(glyphWidth, | - |
733 | (doubleResolution ? 64 * 2 : 64), | - |
734 | path, | - |
735 | (doubleResolution ? 16 / 2 : 16), | - |
736 | (doubleResolution ? 80 / 2 : 80) / (doubleResolution ? 16 / 2 : 16)); | - |
737 | return im; never executed: return im; | 0 |
738 | } | - |
739 | | - |
740 | QImage qt_renderDistanceFieldGlyph(QFontEngine *fe, glyph_t glyph, bool doubleResolution) | - |
741 | { | - |
742 | QFixedPoint position; | - |
743 | QPainterPath path; | - |
744 | fe->addGlyphsToPath(&glyph, &position, 1, &path, 0); | - |
745 | path.translate(-path.boundingRect().topLeft()); | - |
746 | path.setFillRule(Qt::WindingFill); | - |
747 | | - |
748 | return renderDistanceFieldPath(path, doubleResolution); never executed: return renderDistanceFieldPath(path, doubleResolution); | 0 |
749 | } | - |
750 | | - |
751 | QImage qt_renderDistanceFieldGlyph(const QRawFont &font, glyph_t glyph, bool doubleResolution) | - |
752 | { | - |
753 | QRawFont renderFont = font; | - |
754 | renderFont.setPixelSize((doubleResolution ? 54 * 2 : 54) * (doubleResolution ? 16 / 2 : 16)); | - |
755 | | - |
756 | QPainterPath path = renderFont.pathForGlyph(glyph); | - |
757 | path.translate(-path.boundingRect().topLeft()); | - |
758 | path.setFillRule(Qt::WindingFill); | - |
759 | | - |
760 | return renderDistanceFieldPath(path, doubleResolution); never executed: return renderDistanceFieldPath(path, doubleResolution); | 0 |
761 | } | - |
762 | | - |
763 | | - |
764 | | - |
| | |