File indexing completed on 2025-03-09 04:10:11

0001 /*
0002  *  SPDX-FileCopyrightText: 2020 Ashwin Dhakaita <ashwingpdhakaita@gmail.com>
0003  *
0004  *  SPDX-License-Identifier: GPL-2.0-or-later
0005  */
0006 
0007 #include <simpletest.h>
0008 #include <QImageReader>
0009 #include <QtTest/QtTest>
0010 #include <qimage_based_test.h>
0011 
0012 #include <kis_image.h>
0013 #include <kis_node_facade.h>
0014 #include <kis_group_layer.h>
0015 #include <kis_paintop_preset.h>
0016 #include <stroke_testing_utils.h>
0017 #include <kis_paint_information.h>
0018 #include <kis_random_accessor_ng.h>
0019 #include <KisGlobalResourcesInterface.h>
0020 
0021 #include "kis_mypaintop_test.h"
0022 #include "MyPaintPaintOp.h"
0023 #include "MyPaintSurface.h"
0024 #include "MyPaintPaintOpSettings.h"
0025 
0026 #include <qimage_test_util.h>
0027 
0028 class KisMyPaintOpSettings;
0029 KisMyPaintOpTest::KisMyPaintOpTest(): TestUtil::QImageBasedTest("MyPaintOp")
0030 {
0031 
0032 }
0033 
0034 void KisMyPaintOpTest::testDab() {
0035 
0036     KisPaintDeviceSP dst = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb8());
0037     KisPainter painter(dst);
0038 
0039     mypaint_brush_new();
0040 
0041     QScopedPointer<KisMyPaintSurface> surface(new KisMyPaintSurface(&painter, dst));
0042 
0043     surface->draw_dab(surface->surface(), 250, 250, 100, 0, 0, 1, 1, 0.8, 1, 1, 90, 0, 0);
0044 
0045     QImage img = dst->convertToQImage(0, dst->exactBounds().x(), dst->exactBounds().y(), dst->exactBounds().width(), dst->exactBounds().height());
0046     QImage source(QString(FILES_DATA_DIR) + QDir::separator() + "draw_dab.png");
0047 
0048     QPoint errpoint;
0049     if (!TestUtil::compareQImages(errpoint, source, img)) {
0050         img.save("mypaint_test_draw_dab.png");
0051         QFAIL(QString("Failed to create identical image, first different pixel: %1,%2 \n").arg(errpoint.x()).arg(errpoint.y()).toLatin1());
0052     }
0053 
0054 }
0055 
0056 void KisMyPaintOpTest::testGetColor() {
0057 
0058     KisPaintDeviceSP dst = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb8());
0059 
0060     QImage source(QString(FILES_DATA_DIR) + QDir::separator() + "draw_dab.png");
0061     dst->convertFromQImage(source, 0);
0062 
0063     KisPainter painter(dst);
0064 
0065     QScopedPointer<KisMyPaintSurface> surface(new KisMyPaintSurface(&painter, dst));
0066 
0067     surface->draw_dab(surface->surface(), 250, 250, 100, 0, 0, 1, 1, 0.8, 1, 1, 90, 0, 0);
0068 
0069     float r = 0.0f;
0070     float g = 0.0f;
0071     float b = 0.0f;
0072     float a = 0.0f;
0073 
0074     surface->get_color(surface->surface(), 250, 250, 100, &r, &g, &b, &a);
0075 
0076     QVERIFY(qFuzzyCompare((float)qRound(r), 0.0L));
0077     QVERIFY(qFuzzyCompare((float)qRound(g), 0.0L));
0078     QVERIFY(qFuzzyCompare((float)qRound(b), 1.0L));
0079     QVERIFY(qFuzzyCompare((float)qRound(a), 1.0L));
0080 }
0081 
0082 void KisMyPaintOpTest::testLoading() {
0083 
0084     QScopedPointer<KisMyPaintPaintOpPreset> brush (new KisMyPaintPaintOpPreset(QString(FILES_DATA_DIR) + QDir::separator() + "basic.myb"));
0085     brush->load(KisGlobalResourcesInterface::instance());
0086     QVERIFY(brush->valid());
0087 }
0088 
0089 SIMPLE_TEST_MAIN(KisMyPaintOpTest)