Changeset View
Changeset View
Standalone View
Standalone View
imagelib/kpPainter.cpp
Show First 20 Lines • Show All 101 Lines • ▼ Show 20 Line(s) | 79 | #define SHOULD_DRAW() (probabilityTimes1000 == 1000/*avoid ::RandomNumberFrom0to999() call*/ || \ | |||
---|---|---|---|---|---|
102 | 102 | | |||
103 | // Plot location | 103 | // Plot location | ||
104 | int plotx = x1; | 104 | int plotx = x1; | ||
105 | int ploty = y1; | 105 | int ploty = y1; | ||
106 | 106 | | |||
107 | int x = 0; | 107 | int x = 0; | ||
108 | int y = 0; | 108 | int y = 0; | ||
109 | 109 | | |||
110 | if (SHOULD_DRAW ()) | 110 | if (SHOULD_DRAW ()) { | ||
111 | ret.append (QPoint (plotx, ploty)); | 111 | ret.append (QPoint (plotx, ploty)); | ||
112 | } | ||||
112 | 113 | | |||
113 | 114 | | |||
114 | for (int i = 0; i <= inc; i++) | 115 | for (int i = 0; i <= inc; i++) | ||
115 | { | 116 | { | ||
116 | // oldplotx is equally as valid but would look different | 117 | // oldplotx is equally as valid but would look different | ||
117 | // (but nobody will notice which one it is) | 118 | // (but nobody will notice which one it is) | ||
118 | const int oldploty = ploty; | 119 | const int oldploty = ploty; | ||
119 | int plot = 0; | 120 | int plot = 0; | ||
120 | 121 | | |||
121 | x += ix; | 122 | x += ix; | ||
122 | y += iy; | 123 | y += iy; | ||
123 | 124 | | |||
124 | if (x > inc) | 125 | if (x > inc) | ||
125 | { | 126 | { | ||
126 | plot++; | 127 | plot++; | ||
127 | x -= inc; | 128 | x -= inc; | ||
128 | 129 | | |||
129 | if (dx < 0) | 130 | if (dx < 0) { | ||
130 | plotx--; | 131 | plotx--; | ||
131 | else | 132 | } | ||
133 | else { | ||||
132 | plotx++; | 134 | plotx++; | ||
133 | } | 135 | } | ||
136 | } | ||||
134 | 137 | | |||
135 | if (y > inc) | 138 | if (y > inc) | ||
136 | { | 139 | { | ||
137 | plot++; | 140 | plot++; | ||
138 | y -= inc; | 141 | y -= inc; | ||
139 | 142 | | |||
140 | if (dy < 0) | 143 | if (dy < 0) { | ||
141 | ploty--; | 144 | ploty--; | ||
142 | else | 145 | } | ||
146 | else { | ||||
143 | ploty++; | 147 | ploty++; | ||
144 | } | 148 | } | ||
149 | } | ||||
145 | 150 | | |||
146 | if (plot) | 151 | if (plot) | ||
147 | { | 152 | { | ||
148 | if (cardinalAdjacency && plot == 2) | 153 | if (cardinalAdjacency && plot == 2) | ||
149 | { | 154 | { | ||
150 | // MODIFIED: Every point is | 155 | // MODIFIED: Every point is | ||
151 | // horizontally or vertically adjacent to another point (if there | 156 | // horizontally or vertically adjacent to another point (if there | ||
152 | // is more than 1 point, of course). This is in contrast to the | 157 | // is more than 1 point, of course). This is in contrast to the | ||
153 | // ordinary line algorithm which can create diagonal adjacencies. | 158 | // ordinary line algorithm which can create diagonal adjacencies. | ||
154 | 159 | | |||
155 | if (SHOULD_DRAW ()) | 160 | if (SHOULD_DRAW ()) { | ||
156 | ret.append (QPoint (plotx, oldploty)); | 161 | ret.append (QPoint (plotx, oldploty)); | ||
157 | } | 162 | } | ||
163 | } | ||||
158 | 164 | | |||
159 | if (SHOULD_DRAW ()) | 165 | if (SHOULD_DRAW ()) { | ||
160 | ret.append (QPoint (plotx, ploty)); | 166 | ret.append (QPoint (plotx, ploty)); | ||
161 | } | 167 | } | ||
162 | } | 168 | } | ||
169 | } | ||||
163 | 170 | | |||
164 | #undef SHOULD_DRAW | 171 | #undef SHOULD_DRAW | ||
165 | 172 | | |||
166 | return ret; | 173 | return ret; | ||
167 | } | 174 | } | ||
168 | 175 | | |||
169 | //--------------------------------------------------------------------- | 176 | //--------------------------------------------------------------------- | ||
170 | 177 | | |||
▲ Show 20 Lines • Show All 64 Lines • ▼ Show 20 Line(s) | 237 | { | |||
235 | { | 242 | { | ||
236 | fprintf (stderr, "y=%i x=%i colorAtPixel=%08X colorToReplace=%08X ... ", | 243 | fprintf (stderr, "y=%i x=%i colorAtPixel=%08X colorToReplace=%08X ... ", | ||
237 | y, x, | 244 | y, x, | ||
238 | kpPixmapFX::getColorAtPixel (image, QPoint (x, y)).toQRgb (), | 245 | kpPixmapFX::getColorAtPixel (image, QPoint (x, y)).toQRgb (), | ||
239 | colorToReplace.toQRgb ()); | 246 | colorToReplace.toQRgb ()); | ||
240 | if (kpPixmapFX::getColorAtPixel (image, QPoint (x, y)).isSimilarTo (colorToReplace, processedColorSimilarity)) | 247 | if (kpPixmapFX::getColorAtPixel (image, QPoint (x, y)).isSimilarTo (colorToReplace, processedColorSimilarity)) | ||
241 | { | 248 | { | ||
242 | fprintf (stderr, "similar\n"); | 249 | fprintf (stderr, "similar\n"); | ||
243 | if (startDrawX < 0) | 250 | if (startDrawX < 0) { | ||
244 | startDrawX = x; | 251 | startDrawX = x; | ||
245 | } | 252 | } | ||
253 | } | ||||
246 | else | 254 | else | ||
247 | { | 255 | { | ||
248 | fprintf (stderr, "different\n"); | 256 | fprintf (stderr, "different\n"); | ||
249 | if (startDrawX >= 0) | 257 | if (startDrawX >= 0) { | ||
250 | FLUSH_LINE (); | 258 | FLUSH_LINE (); | ||
251 | } | 259 | } | ||
252 | } | 260 | } | ||
261 | } | ||||
253 | 262 | | |||
254 | if (startDrawX >= 0) | 263 | if (startDrawX >= 0) { | ||
255 | FLUSH_LINE (); | 264 | FLUSH_LINE (); | ||
256 | } | 265 | } | ||
266 | } | ||||
257 | 267 | | |||
258 | #undef FLUSH_LINE | 268 | #undef FLUSH_LINE | ||
259 | 269 | | |||
260 | return didSomething; | 270 | return didSomething; | ||
261 | } | 271 | } | ||
262 | 272 | | |||
263 | //--------------------------------------------------------------------- | 273 | //--------------------------------------------------------------------- | ||
264 | 274 | | |||
265 | struct WashPack | 275 | struct WashPack | ||
266 | { | 276 | { | ||
267 | QPoint startPoint, endPoint; | 277 | QPoint startPoint, endPoint; | ||
268 | kpColor color; | 278 | kpColor color; | ||
269 | int penWidth, penHeight; | 279 | int penWidth{}, penHeight{}; | ||
270 | kpColor colorToReplace; | 280 | kpColor colorToReplace; | ||
271 | int processedColorSimilarity; | 281 | int processedColorSimilarity{}; | ||
272 | 282 | | |||
273 | QRect readableImageRect; | 283 | QRect readableImageRect; | ||
274 | QImage readableImage; | 284 | QImage readableImage; | ||
275 | }; | 285 | }; | ||
276 | 286 | | |||
277 | //--------------------------------------------------------------------- | 287 | //--------------------------------------------------------------------- | ||
278 | 288 | | |||
279 | static QRect Wash (kpImage *image, | 289 | static QRect Wash (kpImage *image, | ||
Show All 27 Lines | |||||
307 | } | 317 | } | ||
308 | 318 | | |||
309 | //--------------------------------------------------------------------- | 319 | //--------------------------------------------------------------------- | ||
310 | 320 | | |||
311 | void WashHelperSetup (QPainter *rgbPainter, const WashPack *pack) | 321 | void WashHelperSetup (QPainter *rgbPainter, const WashPack *pack) | ||
312 | { | 322 | { | ||
313 | // Set the drawing colors for the painters. | 323 | // Set the drawing colors for the painters. | ||
314 | 324 | | |||
315 | if (rgbPainter) | 325 | if (rgbPainter) { | ||
316 | rgbPainter->setPen (pack->color.toQColor()); | 326 | rgbPainter->setPen (pack->color.toQColor()); | ||
317 | } | 327 | } | ||
328 | } | ||||
318 | 329 | | |||
319 | //--------------------------------------------------------------------- | 330 | //--------------------------------------------------------------------- | ||
320 | 331 | | |||
321 | static QRect WashLineHelper (QPainter *rgbPainter, void *data) | 332 | static QRect WashLineHelper (QPainter *rgbPainter, void *data) | ||
322 | { | 333 | { | ||
323 | WashPack *pack = static_cast <WashPack *> (data); | 334 | auto *pack = static_cast <WashPack *> (data); | ||
324 | 335 | | |||
325 | // Setup painters. | 336 | // Setup painters. | ||
326 | ::WashHelperSetup (rgbPainter, pack); | 337 | ::WashHelperSetup (rgbPainter, pack); | ||
327 | 338 | | |||
328 | bool didSomething = false; | 339 | bool didSomething = false; | ||
329 | 340 | | |||
330 | QList <QPoint> points = kpPainter::interpolatePoints (pack->startPoint, pack->endPoint); | 341 | QList <QPoint> points = kpPainter::interpolatePoints (pack->startPoint, pack->endPoint); | ||
331 | for (QList <QPoint>::const_iterator pit = points.constBegin (); | 342 | for (QList <QPoint>::const_iterator pit = points.constBegin (); | ||
Show All 39 Lines | 378 | return ::Wash (image, | |||
371 | processedColorSimilarity, | 382 | processedColorSimilarity, | ||
372 | &::WashLineHelper); | 383 | &::WashLineHelper); | ||
373 | } | 384 | } | ||
374 | 385 | | |||
375 | //--------------------------------------------------------------------- | 386 | //--------------------------------------------------------------------- | ||
376 | 387 | | |||
377 | static QRect WashRectHelper (QPainter *rgbPainter, void *data) | 388 | static QRect WashRectHelper (QPainter *rgbPainter, void *data) | ||
378 | { | 389 | { | ||
379 | WashPack *pack = static_cast <WashPack *> (data); | 390 | auto *pack = static_cast <WashPack *> (data); | ||
380 | 391 | | |||
381 | // Setup painters. | 392 | // Setup painters. | ||
382 | ::WashHelperSetup (rgbPainter, pack); | 393 | ::WashHelperSetup (rgbPainter, pack); | ||
383 | 394 | | |||
384 | 395 | | |||
385 | const QRect drawRect (pack->startPoint, pack->endPoint); | 396 | const QRect drawRect (pack->startPoint, pack->endPoint); | ||
386 | 397 | | |||
387 | bool didSomething = false; | 398 | bool didSomething = false; | ||
▲ Show 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | 437 | { | |||
429 | 440 | | |||
430 | QPainter painter(image); | 441 | QPainter painter(image); | ||
431 | const int radius = spraycanSize / 2; | 442 | const int radius = spraycanSize / 2; | ||
432 | 443 | | |||
433 | // Set the drawing colors for the painters. | 444 | // Set the drawing colors for the painters. | ||
434 | 445 | | |||
435 | painter.setPen(color.toQColor()); | 446 | painter.setPen(color.toQColor()); | ||
436 | 447 | | |||
437 | foreach (const QPoint &p, points) | 448 | for (const auto &p : points) | ||
438 | { | 449 | { | ||
439 | for (int i = 0; i < 10; i++) | 450 | for (int i = 0; i < 10; i++) | ||
440 | { | 451 | { | ||
441 | const int dx = (KRandom::random () % spraycanSize) - radius; | 452 | const int dx = (KRandom::random () % spraycanSize) - radius; | ||
442 | const int dy = (KRandom::random () % spraycanSize) - radius; | 453 | const int dy = (KRandom::random () % spraycanSize) - radius; | ||
443 | 454 | | |||
444 | // Make it look circular. | 455 | // Make it look circular. | ||
445 | // TODO: Can be done better by doing a random vector angle & length | 456 | // TODO: Can be done better by doing a random vector angle & length | ||
446 | // but would sin and cos be too slow? | 457 | // but would sin and cos be too slow? | ||
447 | if ((dx * dx) + (dy * dy) > (radius * radius)) | 458 | if ((dx * dx) + (dy * dy) > (radius * radius)) { | ||
448 | continue; | 459 | continue; | ||
460 | } | ||||
449 | 461 | | |||
450 | const QPoint p2 (p.x () + dx, p.y () + dy); | 462 | const QPoint p2 (p.x () + dx, p.y () + dy); | ||
451 | 463 | | |||
452 | painter.drawPoint(p2); | 464 | painter.drawPoint(p2); | ||
453 | } | 465 | } | ||
454 | } | 466 | } | ||
455 | } | 467 | } | ||
456 | 468 | | |||
457 | //--------------------------------------------------------------------- | 469 | //--------------------------------------------------------------------- |