1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
11 #include <test/outputdevice.hxx>
12 #include <vcl/bitmapex.hxx>
13 #include <basegfx/matrix/b2dhommatrix.hxx>
14 #include <vcl/BitmapWriteAccess.hxx>
18 Bitmap
OutputDeviceTestBitmap::setupDrawTransformedBitmap(vcl::PixelFormat aBitmapFormat
,bool isBitmapGreyScale
)
20 Size
aBitmapSize(9, 9);
21 Bitmap
aBitmap(aBitmapSize
, aBitmapFormat
);
23 BitmapScopedWriteAccess
aWriteAccess(aBitmap
);
24 aWriteAccess
->Erase(constFillColor
);
25 aWriteAccess
->SetLineColor(COL_YELLOW
);
26 aWriteAccess
->DrawRect(tools::Rectangle(0, 0, 8, 8));
27 aWriteAccess
->DrawRect(tools::Rectangle(2, 2, 6, 6));
30 if (isBitmapGreyScale
)
31 aBitmap
.Convert(BmpConversion::N8BitGreys
);
33 initialSetup(13, 13, constBackgroundColor
);
35 basegfx::B2DHomMatrix aTransform
;
36 aTransform
.scale(aBitmapSize
.Width(), aBitmapSize
.Height());
37 aTransform
.translate((maVDRectangle
.GetWidth() / 2.0) - (aBitmapSize
.Width() / 2.0),
38 (maVDRectangle
.GetHeight() / 2.0) - (aBitmapSize
.Height() / 2.0));
40 mpVirtualDevice
->DrawTransformedBitmapEx(aTransform
, BitmapEx(aBitmap
));
42 return mpVirtualDevice
->GetBitmap(maVDRectangle
.TopLeft(), maVDRectangle
.GetSize());
46 Bitmap
OutputDeviceTestBitmap::setupComplexDrawTransformedBitmap(vcl::PixelFormat aBitmapFormat
,bool isBitmapGreyScale
)
48 Size
aBitmapSize(6, 6);
49 Bitmap
aBitmap(aBitmapSize
, aBitmapFormat
);
50 aBitmap
.Erase(constFillColor
);
52 if (isBitmapGreyScale
)
53 aBitmap
.Convert(BmpConversion::N8BitGreys
);
55 initialSetup(17, 14, constBackgroundColor
);
57 basegfx::B2DHomMatrix aTransform
;
58 aTransform
.shearX(0.25);
59 aTransform
.scale(aBitmapSize
.Width() * 2, aBitmapSize
.Height() * 2);
60 aTransform
.translate(1, 1);
62 mpVirtualDevice
->DrawTransformedBitmapEx(aTransform
, BitmapEx(aBitmap
));
64 return mpVirtualDevice
->GetBitmap(maVDRectangle
.TopLeft(), maVDRectangle
.GetSize());
68 Bitmap
OutputDeviceTestBitmap::setupDrawBitmap(vcl::PixelFormat aBitmapFormat
,bool isBitmapGreyScale
)
70 Size
aBitmapSize(9, 9);
71 Bitmap
aBitmap(aBitmapSize
, aBitmapFormat
);
73 BitmapScopedWriteAccess
aWriteAccess(aBitmap
);
74 aWriteAccess
->Erase(constFillColor
);
75 aWriteAccess
->SetLineColor(COL_YELLOW
);
76 aWriteAccess
->DrawRect(tools::Rectangle(0, 0, 8, 8));
77 aWriteAccess
->DrawRect(tools::Rectangle(2, 2, 6, 6));
80 if (isBitmapGreyScale
)
81 aBitmap
.Convert(BmpConversion::N8BitGreys
);
83 initialSetup(13, 13, constBackgroundColor
);
85 Point
aPoint((maVDRectangle
.GetWidth() / 2.0) - (aBitmapSize
.Width() / 2.0),
86 (maVDRectangle
.GetHeight() / 2.0) - (aBitmapSize
.Height() / 2.0));
88 mpVirtualDevice
->DrawBitmapEx(aPoint
, BitmapEx(aBitmap
));
90 return mpVirtualDevice
->GetBitmap(maVDRectangle
.TopLeft(), maVDRectangle
.GetSize());
93 Bitmap
OutputDeviceTestBitmap::setupDrawBitmapExWithAlpha(vcl::PixelFormat aBitmapFormat
)
95 Size
aBitmapSize(9, 9);
96 Bitmap
aBitmap(aBitmapSize
, aBitmapFormat
);
98 BitmapScopedWriteAccess
aWriteAccess(aBitmap
);
99 aWriteAccess
->Erase(COL_WHITE
);
100 aWriteAccess
->SetLineColor(Color(0xFF, 0xFF, 0x00));
101 aWriteAccess
->DrawRect(tools::Rectangle(0, 0, 8, 8));
102 aWriteAccess
->DrawRect(tools::Rectangle(3, 3, 5, 5));
105 AlphaMask
aAlpha(aBitmapSize
);
107 BitmapScopedWriteAccess
aWriteAccess(aAlpha
);
108 aWriteAccess
->Erase(COL_ALPHA_TRANSPARENT
);
109 aWriteAccess
->SetLineColor(Color(0xBB, 0xBB, 0xBB));
110 aWriteAccess
->DrawRect(tools::Rectangle(0, 0, 8, 8));
111 aWriteAccess
->DrawRect(tools::Rectangle(3, 3, 5, 5));
114 initialSetup(13, 13, constBackgroundColor
);
116 Point
aPoint(alignToCenter(maVDRectangle
, tools::Rectangle(Point(), aBitmapSize
)).TopLeft());
118 mpVirtualDevice
->DrawBitmapEx(aPoint
, BitmapEx(aBitmap
, aAlpha
));
120 return mpVirtualDevice
->GetBitmap(maVDRectangle
.TopLeft(), maVDRectangle
.GetSize());
123 Bitmap
OutputDeviceTestBitmap::setupDrawMask(vcl::PixelFormat aBitmapFormat
)
125 Size
aBitmapSize(9, 9);
126 Bitmap
aBitmap(aBitmapSize
, aBitmapFormat
);
128 BitmapScopedWriteAccess
aWriteAccess(aBitmap
);
129 aWriteAccess
->Erase(COL_WHITE
);
130 aWriteAccess
->SetLineColor(COL_BLACK
);
131 aWriteAccess
->DrawRect(tools::Rectangle(0, 0, 8, 8));
132 aWriteAccess
->DrawRect(tools::Rectangle(3, 3, 5, 5));
135 initialSetup(13, 13, constBackgroundColor
);
137 mpVirtualDevice
->DrawMask(Point(2, 2), aBitmap
, constLineColor
);
139 return mpVirtualDevice
->GetBitmap(maVDRectangle
.TopLeft(), maVDRectangle
.GetSize());
142 BitmapEx
OutputDeviceTestBitmap::setupDrawBlend(vcl::PixelFormat aBitmapFormat
)
144 Size
aBitmapSize(9, 9);
145 Bitmap
aBitmap(aBitmapSize
, aBitmapFormat
);
147 BitmapScopedWriteAccess
aWriteAccess(aBitmap
);
148 aWriteAccess
->Erase(COL_WHITE
);
149 aWriteAccess
->SetLineColor(Color(0xFF, 0xFF, 0x00));
150 aWriteAccess
->DrawRect(tools::Rectangle(0, 0, 8, 8));
151 aWriteAccess
->DrawRect(tools::Rectangle(3, 3, 5, 5));
154 AlphaMask
aAlpha(aBitmapSize
);
156 BitmapScopedWriteAccess
aWriteAccess(aAlpha
);
157 aWriteAccess
->Erase(COL_ALPHA_TRANSPARENT
);
158 aWriteAccess
->SetLineColor(Color(0xBB, 0xBB, 0xBB));
159 aWriteAccess
->DrawRect(tools::Rectangle(0, 0, 8, 8));
160 aWriteAccess
->DrawRect(tools::Rectangle(3, 3, 5, 5));
163 initialSetup(13, 13, COL_TRANSPARENT
, false, true);
164 mpVirtualDevice
->SetFillColor(constBackgroundColor
);
165 mpVirtualDevice
->SetLineColor(constBackgroundColor
);
166 // Leave the outer part of the device transparent, the inner part set to the background color.
167 // This will test blending of VirtualDevice's "alpha" device (outer yellow rectangle
168 // will be blended with transparent background, inner with the grey one).
169 mpVirtualDevice
->DrawRect( tools::Rectangle( Point( 3, 3 ), Size( 7, 7 )));
171 Point
aPoint(alignToCenter(maVDRectangle
, tools::Rectangle(Point(), aBitmapSize
)).TopLeft());
173 mpVirtualDevice
->DrawBitmapEx(aPoint
, BitmapEx(aBitmap
, aAlpha
));
175 return mpVirtualDevice
->GetBitmapEx(maVDRectangle
.TopLeft(), maVDRectangle
.GetSize());
178 } // end namespace vcl::test
180 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */