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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <unotest/filters-test.hxx>
#include <test/bootstrapfixture.hxx>
#include <vcl/virdev.hxx>
#include <vcl/salbtype.hxx>
#include <vcl/bitmapaccess.hxx>
#include <vcl/wrkwin.hxx>
#include <tools/stream.hxx>
#include <vcl/pngwrite.hxx>
#include <vcl/graphicfilter.hxx>
static OUString const gaDataUrl = "/vcl/qa/cppunit/bitmaprender/data/";
class BitmapRenderTest : public test::BootstrapFixture
{
OUString getFullUrl(const OUString& sFileName)
{
return m_directories.getURLFromSrc(gaDataUrl) + sFileName;
}
public:
BitmapRenderTest()
: BootstrapFixture(true, false)
{
}
void testTdf104141();
void testTdf113918();
CPPUNIT_TEST_SUITE(BitmapRenderTest);
CPPUNIT_TEST(testTdf104141);
CPPUNIT_TEST(testTdf113918);
CPPUNIT_TEST_SUITE_END();
};
void BitmapRenderTest::testTdf104141()
{
ScopedVclPtrInstance<VirtualDevice> pVDev;
pVDev->SetOutputSizePixel(Size(400, 400));
pVDev->SetBackground(Wallpaper(COL_GREEN));
pVDev->Erase();
// Load animated GIF and draw it on green background
GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
Graphic aGraphic;
const OUString aURL(getFullUrl("tdf104141.gif"));
SvFileStream aFileStream(aURL, StreamMode::READ);
ErrCode bResult = rFilter.ImportGraphic(aGraphic, aURL, aFileStream);
CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, bResult);
BitmapEx aBitmap = aGraphic.GetBitmapEx();
pVDev->DrawBitmapEx(Point(20, 20), aBitmap);
// Check drawing results: ensure that it contains transparent
// (greenish) pixels
#if !defined MACOSX //TODO: on Mac colors are drifted, so exact compare fails
const Color aColor = pVDev->GetPixel(Point(21, 21));
CPPUNIT_ASSERT(aColor.GetGreen() > 10 * aColor.GetRed()
&& aColor.GetGreen() > 10 * aColor.GetBlue());
#endif
}
void BitmapRenderTest::testTdf113918()
{
ScopedVclPtrInstance<VirtualDevice> pVDev;
pVDev->SetOutputSizePixel(Size(2480, 3508));
pVDev->SetBackground(Wallpaper(COL_GREEN));
pVDev->Erase();
GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter();
Graphic aGraphic;
const OUString aURL(getFullUrl("tdf113918.png"));
SvFileStream aFileStream(aURL, StreamMode::READ);
ErrCode bResult = rFilter.ImportGraphic(aGraphic, aURL, aFileStream);
CPPUNIT_ASSERT_EQUAL(ERRCODE_NONE, bResult);
BitmapEx aBitmap = aGraphic.GetBitmapEx();
pVDev->DrawBitmapEx(Point(0, 0), aBitmap);
// Ensure that image is drawn with white background color from palette
CPPUNIT_ASSERT_EQUAL(COL_WHITE, pVDev->GetPixel(Point(21, 21)));
// Ensure that image is drawn with gray text color from palette
const Color aColor = pVDev->GetPixel(Point(1298, 1368));
CPPUNIT_ASSERT(aColor.GetGreen() == aColor.GetRed() && aColor.GetGreen() == aColor.GetBlue());
CPPUNIT_ASSERT(aColor.GetGreen() > 100);
}
CPPUNIT_TEST_SUITE_REGISTRATION(BitmapRenderTest);
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|