summaryrefslogtreecommitdiffstats
path: root/chalk/core/tests/kis_image_tester.cpp
blob: f0ebbcb029881f0fbea68722dff4c81445be1d00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
/*
 *  Copyright (c) 2005 Adrian Page <adrian@pagenet.plus.com>
 *
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
 */

#include <tqapplication.h>

#include <tdeunittest/runner.h>
#include <tdeunittest/module.h>

#include "kis_image_tester.h"
#include "kis_image.h"
#include "kis_meta_registry.h"
#include "kis_rgb_colorspace.h"
#include "kis_colorspace_factory_registry.h"
#include "kis_color.h"
#include "kis_paint_layer.h"
#include "kis_group_layer.h"

using namespace KUnitTest;

TDEUNITTEST_MODULE(tdeunittest_kis_image_tester, "KisImage Tester");
TDEUNITTEST_MODULE_REGISTER_TESTER(KisImageTester);

void KisImageTester::allTests()
{
    mergeTests();
}

#define IMAGE_WIDTH 1
#define IMAGE_HEIGHT 1

void KisImageTester::mergeTests()
{
    KisColorSpace * colorSpace = KisMetaRegistry::instance()->csRegistry()->getColorSpace(KisID("RGBA", ""), "");

    KisImageSP image = new KisImage(0, IMAGE_WIDTH, IMAGE_HEIGHT, colorSpace, "merge test");

    KisColor mergedPixel = image->mergedPixel(0, 0);

    TQColor colour;
    TQ_UINT8 opacity;

    mergedPixel.toTQColor(&colour, &opacity);

    CHECK(opacity, OPACITY_TRANSPARENT);

    KisPaintLayer * layer = new KisPaintLayer(image, "layer 1", OPACITY_OPAQUE);
    image->addLayer(layer, image->rootLayer(), 0);

    layer->paintDevice()->setPixel(0, 0, TQColor(255, 128, 64), OPACITY_OPAQUE);

    mergedPixel = image->mergedPixel(0, 0);
    mergedPixel.toTQColor(&colour, &opacity);

    CHECK(opacity, OPACITY_OPAQUE);
    CHECK(colour.red(), 255);
    CHECK(colour.green(), 128);
    CHECK(colour.blue(), 64);

    KisPaintLayer * layer2 = new KisPaintLayer(image, "layer 2", OPACITY_OPAQUE / 2);
    image->addLayer(layer2, image->rootLayer(), layer);

    layer2->paintDevice()->setPixel(0, 0, TQColor(255, 255, 255), OPACITY_OPAQUE);

    mergedPixel = image->mergedPixel(0, 0);
    mergedPixel.toTQColor(&colour, &opacity);

    CHECK(opacity, OPACITY_OPAQUE);
    CHECK(colour.red(), 255);
    CHECK(colour.green(), 128 + ((255 - 128) / 2));
    CHECK(colour.blue(), 64 + ((255 - 64) / 2));
}