Changeset View
Changeset View
Standalone View
Standalone View
benchmarks/kis_stroke_benchmark.cpp
Show First 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | |||||
47 | #define GMP_IMAGE_WIDTH 3274 | 47 | #define GMP_IMAGE_WIDTH 3274 | ||
48 | #define GMP_IMAGE_HEIGHT 2067 | 48 | #define GMP_IMAGE_HEIGHT 2067 | ||
49 | #include <kis_painter.h> | 49 | #include <kis_painter.h> | ||
50 | #include <brushengine/kis_paintop_registry.h> | 50 | #include <brushengine/kis_paintop_registry.h> | ||
51 | 51 | | |||
52 | //#define SAVE_OUTPUT | 52 | //#define SAVE_OUTPUT | ||
53 | 53 | | |||
54 | static const int LINES = 20; | 54 | static const int LINES = 20; | ||
55 | static const int RECTANGLES = 20; | ||||
55 | const QString OUTPUT_FORMAT = ".png"; | 56 | const QString OUTPUT_FORMAT = ".png"; | ||
56 | 57 | | |||
57 | void KisStrokeBenchmark::initTestCase() | 58 | void KisStrokeBenchmark::initTestCase() | ||
58 | { | 59 | { | ||
59 | m_dataPath = QString(FILES_DATA_DIR) + QDir::separator(); | 60 | m_dataPath = QString(FILES_DATA_DIR) + QDir::separator(); | ||
60 | m_outputPath = QString(FILES_OUTPUT_DIR) + QDir::separator(); | 61 | m_outputPath = QString(FILES_OUTPUT_DIR) + QDir::separator(); | ||
61 | 62 | | |||
62 | m_colorSpace = KoColorSpaceRegistry::instance()->rgb8(); | 63 | m_colorSpace = KoColorSpaceRegistry::instance()->rgb8(); | ||
63 | m_color = KoColor(m_colorSpace); | 64 | m_color = KoColor(m_colorSpace); | ||
64 | 65 | | |||
65 | int width = TEST_IMAGE_WIDTH; | 66 | int width = TEST_IMAGE_WIDTH; | ||
66 | int height = TEST_IMAGE_HEIGHT; | 67 | int height = TEST_IMAGE_HEIGHT; | ||
67 | 68 | | |||
68 | m_image = new KisImage(0, width, height, m_colorSpace, "stroke sample image"); | 69 | m_image = new KisImage(0, width, height, m_colorSpace, "stroke sample image"); | ||
69 | m_layer = new KisPaintLayer(m_image, "temporary for stroke sample", OPACITY_OPAQUE_U8, m_colorSpace); | 70 | m_layer = new KisPaintLayer(m_image, "temporary for stroke sample", OPACITY_OPAQUE_U8, m_colorSpace); | ||
70 | 71 | | |||
71 | 72 | | |||
72 | m_painter = new KisPainter(m_layer->paintDevice()); | 73 | m_painter = new KisPainter(m_layer->paintDevice()); | ||
73 | m_painter->setPaintColor(KoColor(Qt::black, m_colorSpace)); | 74 | m_painter->setPaintColor(KoColor(Qt::black, m_colorSpace)); | ||
74 | 75 | | |||
75 | // for bezier curve test | 76 | // for bezier curve test | ||
76 | initCurvePoints(width, height); | 77 | initCurvePoints(width, height); | ||
77 | // for the lines test | 78 | // for the lines test | ||
78 | initLines(width,height); | 79 | initLines(width,height); | ||
80 | // for the rectangles test | ||||
81 | initRectangles(width, height); | ||||
79 | } | 82 | } | ||
80 | 83 | | |||
81 | void KisStrokeBenchmark::init() | 84 | void KisStrokeBenchmark::init() | ||
82 | { | 85 | { | ||
83 | KoColor white(m_colorSpace); | 86 | KoColor white(m_colorSpace); | ||
84 | white.fromQColor(Qt::white); | 87 | white.fromQColor(Qt::white); | ||
85 | m_layer->paintDevice()->fill(0,0, m_image->width(), m_image->height(),white.data()); | 88 | m_layer->paintDevice()->fill(0,0, m_image->width(), m_image->height(),white.data()); | ||
86 | } | 89 | } | ||
Show All 22 Lines | 110 | for (int i = 0; i < LINES; i++){ | |||
109 | qreal sy = rand() / qreal(RAND_MAX - 1); | 112 | qreal sy = rand() / qreal(RAND_MAX - 1); | ||
110 | m_startPoints.append(QPointF(sx * width,sy * height)); | 113 | m_startPoints.append(QPointF(sx * width,sy * height)); | ||
111 | qreal ex = rand() / qreal(RAND_MAX - 1); | 114 | qreal ex = rand() / qreal(RAND_MAX - 1); | ||
112 | qreal ey = rand() / qreal(RAND_MAX - 1); | 115 | qreal ey = rand() / qreal(RAND_MAX - 1); | ||
113 | m_endPoints.append(QPointF(ex * width,ey * height)); | 116 | m_endPoints.append(QPointF(ex * width,ey * height)); | ||
114 | } | 117 | } | ||
115 | } | 118 | } | ||
116 | 119 | | |||
120 | void KisStrokeBenchmark::initRectangles(int width, int height) | ||||
121 | { | ||||
122 | qreal margin = 0.5; | ||||
123 | qreal skip = 0.01; | ||||
124 | | ||||
125 | qreal marginWidth = margin*width; | ||||
126 | qreal marginHeight = margin*height; | ||||
127 | | ||||
128 | qreal skipWidth = skip*width >= 1 ? skip*width : 1; | ||||
129 | qreal skipHeight = skip*width >= 1 ? skip*width : 1; | ||||
130 | | ||||
131 | // "concentric" rectangles | ||||
132 | | ||||
133 | for (int i = 0; i < RECTANGLES; i++){ | ||||
134 | QPoint corner1 = QPoint(marginWidth + i*skipWidth, marginHeight + i*skipHeight); | ||||
135 | QPoint corner2 = QPoint(width - marginWidth - i*skipWidth, height - marginHeight - i*skipHeight); | ||||
136 | | ||||
137 | if(corner1.x() < corner2.x() && corner1.y() < corner2.y()) { | ||||
138 | // if the rectangle is not empty | ||||
139 | m_rectangleLeftLowerCorners.append(corner1); | ||||
140 | m_rectangleRightUpperCorners.append(corner2); | ||||
141 | } | ||||
142 | } | ||||
143 | } | ||||
144 | | ||||
145 | | ||||
117 | 146 | | |||
118 | void KisStrokeBenchmark::cleanupTestCase() | 147 | void KisStrokeBenchmark::cleanupTestCase() | ||
119 | { | 148 | { | ||
120 | delete m_painter; | 149 | delete m_painter; | ||
121 | } | 150 | } | ||
122 | 151 | | |||
123 | void KisStrokeBenchmark::deformBrush() | 152 | void KisStrokeBenchmark::deformBrush() | ||
124 | { | 153 | { | ||
▲ Show 20 Lines • Show All 197 Lines • ▼ Show 20 Line(s) | |||||
322 | } | 351 | } | ||
323 | 352 | | |||
324 | void KisStrokeBenchmark::colorsmudgeRL() | 353 | void KisStrokeBenchmark::colorsmudgeRL() | ||
325 | { | 354 | { | ||
326 | QString presetFileName = "colorsmudge.kpp"; | 355 | QString presetFileName = "colorsmudge.kpp"; | ||
327 | benchmarkStroke(presetFileName); | 356 | benchmarkStroke(presetFileName); | ||
328 | } | 357 | } | ||
329 | 358 | | |||
359 | | ||||
360 | void KisStrokeBenchmark::roundMarker() | ||||
361 | { | ||||
362 | // Quick Brush engine ( b) Basic - 1 brush, size 40px) | ||||
363 | QString presetFileName = "roundmarker40px.kpp"; | ||||
364 | benchmarkStroke(presetFileName); | ||||
365 | } | ||||
366 | | ||||
367 | void KisStrokeBenchmark::roundMarkerRandomLines() | ||||
368 | { | ||||
369 | // Quick Brush engine ( b) Basic - 1 brush, size 40px) | ||||
370 | QString presetFileName = "roundmarker40px.kpp"; | ||||
371 | benchmarkRandomLines(presetFileName); | ||||
372 | } | ||||
373 | | ||||
374 | void KisStrokeBenchmark::roundMarkerRectangle() | ||||
375 | { | ||||
376 | // Quick Brush engine ( b) Basic - 1 brush, size 40px) | ||||
377 | QString presetFileName = "roundmarker40px.kpp"; | ||||
378 | benchmarkStroke(presetFileName); | ||||
379 | } | ||||
380 | | ||||
381 | | ||||
382 | void KisStrokeBenchmark::roundMarkerHalfPixel() | ||||
383 | { | ||||
384 | // Quick Brush engine ( b) Basic - 1 brush, size 0.5px) | ||||
385 | QString presetFileName = "roundmarker05px.kpp"; | ||||
386 | benchmarkStroke(presetFileName); | ||||
387 | } | ||||
388 | | ||||
389 | void KisStrokeBenchmark::roundMarkerRandomLinesHalfPixel() | ||||
390 | { | ||||
391 | // Quick Brush engine ( b) Basic - 1 brush, size 0.5px) | ||||
392 | QString presetFileName = "roundmarker05px.kpp"; | ||||
393 | benchmarkRandomLines(presetFileName); | ||||
394 | } | ||||
395 | | ||||
396 | void KisStrokeBenchmark::roundMarkerRectangleHalfPixel() | ||||
397 | { | ||||
398 | // Quick Brush engine ( b) Basic - 1 brush, size 0.5px) | ||||
399 | QString presetFileName = "roundmarker05px.kpp"; | ||||
400 | benchmarkStroke(presetFileName); | ||||
401 | } | ||||
402 | | ||||
403 | | ||||
404 | | ||||
330 | /* | 405 | /* | ||
331 | void KisStrokeBenchmark::predefinedBrush() | 406 | void KisStrokeBenchmark::predefinedBrush() | ||
332 | { | 407 | { | ||
333 | QString presetFileName = "deevad-slow-brush1.kpp"; | 408 | QString presetFileName = "deevad-slow-brush1.kpp"; | ||
334 | benchmarkLine(presetFileName); | 409 | benchmarkLine(presetFileName); | ||
335 | } | 410 | } | ||
336 | 411 | | |||
337 | void KisStrokeBenchmark::predefinedBrushRL() | 412 | void KisStrokeBenchmark::predefinedBrushRL() | ||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Line(s) | 526 | QBENCHMARK{ | |||
457 | } | 532 | } | ||
458 | } | 533 | } | ||
459 | 534 | | |||
460 | #ifdef SAVE_OUTPUT | 535 | #ifdef SAVE_OUTPUT | ||
461 | m_layer->paintDevice()->convertToQImage(0).save(m_outputPath + presetFileName + "_randomLines" + OUTPUT_FORMAT); | 536 | m_layer->paintDevice()->convertToQImage(0).save(m_outputPath + presetFileName + "_randomLines" + OUTPUT_FORMAT); | ||
462 | #endif | 537 | #endif | ||
463 | } | 538 | } | ||
464 | 539 | | |||
540 | | ||||
541 | | ||||
542 | void KisStrokeBenchmark::benchmarkRectangle(QString presetFileName) | ||||
543 | { | ||||
544 | KisPaintOpPresetSP preset = new KisPaintOpPreset(m_dataPath + presetFileName); | ||||
545 | bool loadedOk = preset->load(); | ||||
546 | if (!loadedOk){ | ||||
547 | dbgKrita << "The preset was not loaded correctly. Done."; | ||||
548 | return; | ||||
549 | }else{ | ||||
550 | dbgKrita << "preset : " << presetFileName; | ||||
551 | } | ||||
552 | m_painter->setPaintOpPreset(preset, m_layer, m_image); | ||||
553 | | ||||
554 | int rectangleNumber = m_rectangleLeftLowerCorners.size(); // see initRectangles | ||||
555 | | ||||
556 | QBENCHMARK{ | ||||
557 | KisDistanceInformation currentDistance; | ||||
558 | for (int i = 0; i < rectangleNumber; i++){ | ||||
559 | QPainterPath path; | ||||
560 | QRect rect = QRect(m_rectangleLeftLowerCorners[i], m_rectangleRightUpperCorners[i]); | ||||
561 | path.addRect(rect); | ||||
562 | m_painter->paintPainterPath(path); | ||||
563 | } | ||||
564 | } | ||||
565 | | ||||
566 | #ifdef SAVE_OUTPUT | ||||
567 | m_layer->paintDevice()->convertToQImage(0).save(m_outputPath + presetFileName + "_rectangle" + OUTPUT_FORMAT); | ||||
568 | #endif | ||||
569 | } | ||||
570 | | ||||
465 | void KisStrokeBenchmark::benchmarkStroke(QString presetFileName) | 571 | void KisStrokeBenchmark::benchmarkStroke(QString presetFileName) | ||
466 | { | 572 | { | ||
467 | KisPaintOpPresetSP preset = new KisPaintOpPreset(m_dataPath + presetFileName); | 573 | KisPaintOpPresetSP preset = new KisPaintOpPreset(m_dataPath + presetFileName); | ||
468 | bool loadedOk = preset->load(); | 574 | bool loadedOk = preset->load(); | ||
469 | if (!loadedOk){ | 575 | if (!loadedOk){ | ||
470 | dbgKrita << "The preset was not loaded correctly. Done."; | 576 | dbgKrita << "The preset was not loaded correctly. Done."; | ||
471 | return; | 577 | return; | ||
472 | } else { | 578 | } else { | ||
▲ Show 20 Lines • Show All 56 Lines • Show Last 20 Lines |