LibreOffice Module vcl (master) 1
mask.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#include <vcl/metaact.hxx>
21#include <vcl/virdev.hxx>
22
23#include <salgdi.hxx>
24#include <salbmp.hxx>
25
26#include <cassert>
27
28void OutputDevice::DrawMask( const Point& rDestPt,
29 const Bitmap& rBitmap, const Color& rMaskColor )
30{
32
33 const Size aSizePix( rBitmap.GetSizePixel() );
34 DrawMask( rDestPt, PixelToLogic( aSizePix ), Point(), aSizePix, rBitmap, rMaskColor, MetaActionType::MASK );
35}
36
37void OutputDevice::DrawMask( const Point& rDestPt, const Size& rDestSize,
38 const Bitmap& rBitmap, const Color& rMaskColor )
39{
41
42 DrawMask( rDestPt, rDestSize, Point(), rBitmap.GetSizePixel(), rBitmap, rMaskColor, MetaActionType::MASKSCALE );
43}
44
45void OutputDevice::DrawMask( const Point& rDestPt, const Size& rDestSize,
46 const Point& rSrcPtPixel, const Size& rSrcSizePixel,
47 const Bitmap& rBitmap, const Color& rMaskColor)
48{
49
51
52 DrawMask( rDestPt, rDestSize, rSrcPtPixel, rSrcSizePixel, rBitmap, rMaskColor, MetaActionType::MASKSCALEPART );
53}
54
55void OutputDevice::DrawMask( const Point& rDestPt, const Size& rDestSize,
56 const Point& rSrcPtPixel, const Size& rSrcSizePixel,
57 const Bitmap& rBitmap, const Color& rMaskColor,
58 const MetaActionType nAction )
59{
61
62 if( ImplIsRecordLayout() )
63 return;
64
66 {
67 DrawRect( tools::Rectangle( rDestPt, rDestSize ) );
68 return;
69 }
70
71 if ( mpMetaFile )
72 {
73 switch( nAction )
74 {
76 mpMetaFile->AddAction( new MetaMaskAction( rDestPt,
77 rBitmap, rMaskColor ) );
78 break;
79
82 rDestSize, rBitmap, rMaskColor ) );
83 break;
84
86 mpMetaFile->AddAction( new MetaMaskScalePartAction( rDestPt, rDestSize,
87 rSrcPtPixel, rSrcSizePixel, rBitmap, rMaskColor ) );
88 break;
89
90 default: break;
91 }
92 }
93
95 return;
96
97 if ( !mpGraphics && !AcquireGraphics() )
98 return;
99
100 if ( mbInitClipRegion )
102
103 if ( mbOutputClipped )
104 return;
105
106 DrawDeviceMask( rBitmap, rMaskColor, rDestPt, rDestSize, rSrcPtPixel, rSrcSizePixel );
107
108}
109
110void OutputDevice::DrawDeviceMask( const Bitmap& rMask, const Color& rMaskColor,
111 const Point& rDestPt, const Size& rDestSize,
112 const Point& rSrcPtPixel, const Size& rSrcSizePixel )
113{
114 assert(!is_double_buffered_window());
115
116 const std::shared_ptr<SalBitmap>& xImpBmp = rMask.ImplGetSalBitmap();
117 if (xImpBmp)
118 {
119 SalTwoRect aPosAry(rSrcPtPixel.X(), rSrcPtPixel.Y(), rSrcSizePixel.Width(), rSrcSizePixel.Height(),
120 ImplLogicXToDevicePixel(rDestPt.X()), ImplLogicYToDevicePixel(rDestPt.Y()),
123
124 // we don't want to mirror via coordinates
125 const BmpMirrorFlags nMirrFlags = AdjustTwoRect( aPosAry, xImpBmp->GetSize() );
126
127 // check if output is necessary
128 if( aPosAry.mnSrcWidth && aPosAry.mnSrcHeight && aPosAry.mnDestWidth && aPosAry.mnDestHeight )
129 {
130
131 if( nMirrFlags != BmpMirrorFlags::NONE )
132 {
133 Bitmap aTmp( rMask );
134 aTmp.Mirror( nMirrFlags );
135 mpGraphics->DrawMask( aPosAry, *aTmp.ImplGetSalBitmap(),
136 rMaskColor, *this);
137 }
138 else
139 mpGraphics->DrawMask( aPosAry, *xImpBmp, rMaskColor, *this );
140
141 }
142 }
143
144 // TODO: Use mask here
145 if( !mpAlphaVDev )
146 return;
147
148 const Bitmap& rAlphaMask( rMask.CreateMask( rMaskColor ) );
149
150 // #i25167# Restrict mask painting to _opaque_ areas
151 // of the mask, otherwise we spoil areas where no
152 // bitmap content was ever visible. Interestingly
153 // enough, this can be achieved by taking the mask as
154 // the transparency mask of itself
155 mpAlphaVDev->DrawBitmapEx( rDestPt,
156 rDestSize,
157 rSrcPtPixel,
158 rSrcSizePixel,
159 BitmapEx( rAlphaMask, rMask ) );
160}
161
162/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const std::shared_ptr< SalBitmap > & ImplGetSalBitmap() const
Bitmap CreateMask(const Color &rTransColor, sal_uInt8 nTol=0) const
Create on-off mask from bitmap.
Size GetSizePixel() const
bool Mirror(BmpMirrorFlags nMirrorFlags)
Mirror the bitmap.
void AddAction(const rtl::Reference< MetaAction > &pAction)
Definition: gdimtf.cxx:581
virtual void InitClipRegion()
SAL_DLLPRIVATE tools::Long ImplLogicYToDevicePixel(tools::Long nY) const
Convert a logical Y coordinate to a device pixel's Y coordinate.
Definition: map.cxx:284
void DrawBitmapEx(const Point &rDestPt, const BitmapEx &rBitmapEx)
Definition: bitmapex.cxx:33
SAL_DLLPRIVATE bool is_double_buffered_window() const
bool mbOutputClipped
Definition: outdev.hxx:246
virtual bool AcquireGraphics() const =0
Acquire a graphics device that the output device uses to draw on.
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
Definition: map.cxx:1123
SAL_DLLPRIVATE bool ImplIsRecordLayout() const
Definition: outdev.cxx:708
void DrawRect(const tools::Rectangle &rRect)
Definition: rect.cxx:50
GDIMetaFile * mpMetaFile
Definition: outdev.hxx:186
SAL_DLLPRIVATE tools::Long ImplLogicHeightToDevicePixel(tools::Long nHeight) const
Convert a logical height to a height in units of device pixels.
Definition: map.cxx:301
SAL_DLLPRIVATE tools::Long ImplLogicWidthToDevicePixel(tools::Long nWidth) const
Convert a logical width to a width in units of device pixels.
Definition: map.cxx:293
SalGraphics * mpGraphics
Graphics context to draw on.
Definition: outdev.hxx:183
void DrawMask(const Point &rDestPt, const Bitmap &rBitmap, const Color &rMaskColor)
Definition: mask.cxx:28
bool mbInitClipRegion
Definition: outdev.hxx:253
RasterOp meRasterOp
Definition: outdev.hxx:233
bool IsDeviceOutputNecessary() const
Definition: outdev.hxx:482
VclPtr< VirtualDevice > mpAlphaVDev
Definition: outdev.hxx:197
virtual void DrawDeviceMask(const Bitmap &rMask, const Color &rMaskColor, const Point &rDestPt, const Size &rDestSize, const Point &rSrcPtPixel, const Size &rSrcSizePixel)
Definition: mask.cxx:110
SAL_DLLPRIVATE tools::Long ImplLogicXToDevicePixel(tools::Long nX) const
Convert a logical X coordinate to a device pixel's X coordinate.
Definition: map.cxx:275
void DrawMask(const SalTwoRect &rPosAry, const SalBitmap &rSalBitmap, Color nMaskColor, const OutputDevice &rOutDev)
constexpr tools::Long Height() const
constexpr tools::Long Width() const
BmpMirrorFlags
MetaActionType
BmpMirrorFlags AdjustTwoRect(SalTwoRect &rTwoRect, const Size &rSizePix)
Definition: rect.cxx:340
tools::Long mnDestWidth
Definition: salgtype.hxx:46
tools::Long mnSrcHeight
Definition: salgtype.hxx:43
tools::Long mnSrcWidth
Definition: salgtype.hxx:42
tools::Long mnDestHeight
Definition: salgtype.hxx:47