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 <cassert>
21 
22 #include <vcl/gdimtf.hxx>
23 #include <vcl/metaact.hxx>
24 #include <vcl/outdev.hxx>
25 #include <vcl/virdev.hxx>
26 
27 #include <salgdi.hxx>
28 #include <salbmp.hxx>
29 
30 void OutputDevice::DrawMask( const Point& rDestPt,
31  const Bitmap& rBitmap, const Color& rMaskColor )
32 {
33  assert(!is_double_buffered_window());
34 
35  const Size aSizePix( rBitmap.GetSizePixel() );
36  DrawMask( rDestPt, PixelToLogic( aSizePix ), Point(), aSizePix, rBitmap, rMaskColor, MetaActionType::MASK );
37 }
38 
39 void OutputDevice::DrawMask( const Point& rDestPt, const Size& rDestSize,
40  const Bitmap& rBitmap, const Color& rMaskColor )
41 {
42  assert(!is_double_buffered_window());
43 
44  DrawMask( rDestPt, rDestSize, Point(), rBitmap.GetSizePixel(), rBitmap, rMaskColor, MetaActionType::MASKSCALE );
45 }
46 
47 void OutputDevice::DrawMask( const Point& rDestPt, const Size& rDestSize,
48  const Point& rSrcPtPixel, const Size& rSrcSizePixel,
49  const Bitmap& rBitmap, const Color& rMaskColor)
50 {
51 
52  assert(!is_double_buffered_window());
53 
54  DrawMask( rDestPt, rDestSize, rSrcPtPixel, rSrcSizePixel, rBitmap, rMaskColor, MetaActionType::MASKSCALEPART );
55 }
56 
57 void OutputDevice::DrawMask( const Point& rDestPt, const Size& rDestSize,
58  const Point& rSrcPtPixel, const Size& rSrcSizePixel,
59  const Bitmap& rBitmap, const Color& rMaskColor,
60  const MetaActionType nAction )
61 {
62  assert(!is_double_buffered_window());
63 
64  if( ImplIsRecordLayout() )
65  return;
66 
68  {
69  DrawRect( tools::Rectangle( rDestPt, rDestSize ) );
70  return;
71  }
72 
73  if ( mpMetaFile )
74  {
75  switch( nAction )
76  {
78  mpMetaFile->AddAction( new MetaMaskAction( rDestPt,
79  rBitmap, rMaskColor ) );
80  break;
81 
84  rDestSize, rBitmap, rMaskColor ) );
85  break;
86 
88  mpMetaFile->AddAction( new MetaMaskScalePartAction( rDestPt, rDestSize,
89  rSrcPtPixel, rSrcSizePixel, rBitmap, rMaskColor ) );
90  break;
91 
92  default: break;
93  }
94  }
95 
96  if ( !IsDeviceOutputNecessary() )
97  return;
98 
99  if ( !mpGraphics && !AcquireGraphics() )
100  return;
101 
102  if ( mbInitClipRegion )
103  InitClipRegion();
104 
105  if ( mbOutputClipped )
106  return;
107 
108  DrawDeviceMask( rBitmap, rMaskColor, rDestPt, rDestSize, rSrcPtPixel, rSrcSizePixel );
109 
110 }
111 
112 void OutputDevice::DrawDeviceMask( const Bitmap& rMask, const Color& rMaskColor,
113  const Point& rDestPt, const Size& rDestSize,
114  const Point& rSrcPtPixel, const Size& rSrcSizePixel )
115 {
116  assert(!is_double_buffered_window());
117 
118  const std::shared_ptr<SalBitmap>& xImpBmp = rMask.ImplGetSalBitmap();
119  if (xImpBmp)
120  {
121  SalTwoRect aPosAry(rSrcPtPixel.X(), rSrcPtPixel.Y(), rSrcSizePixel.Width(), rSrcSizePixel.Height(),
122  ImplLogicXToDevicePixel(rDestPt.X()), ImplLogicYToDevicePixel(rDestPt.Y()),
123  ImplLogicWidthToDevicePixel(rDestSize.Width()),
124  ImplLogicHeightToDevicePixel(rDestSize.Height()));
125 
126  // we don't want to mirror via coordinates
127  const BmpMirrorFlags nMirrFlags = AdjustTwoRect( aPosAry, xImpBmp->GetSize() );
128 
129  // check if output is necessary
130  if( aPosAry.mnSrcWidth && aPosAry.mnSrcHeight && aPosAry.mnDestWidth && aPosAry.mnDestHeight )
131  {
132 
133  if( nMirrFlags != BmpMirrorFlags::NONE )
134  {
135  Bitmap aTmp( rMask );
136  aTmp.Mirror( nMirrFlags );
137  mpGraphics->DrawMask( aPosAry, *aTmp.ImplGetSalBitmap(),
138  rMaskColor, *this);
139  }
140  else
141  mpGraphics->DrawMask( aPosAry, *xImpBmp, rMaskColor, *this );
142 
143  }
144  }
145 
146  // TODO: Use mask here
147  if( !mpAlphaVDev )
148  return;
149 
150  const Bitmap& rAlphaMask( rMask.CreateMask( rMaskColor ) );
151 
152  // #i25167# Restrict mask painting to _opaque_ areas
153  // of the mask, otherwise we spoil areas where no
154  // bitmap content was ever visible. Interestingly
155  // enough, this can be achieved by taking the mask as
156  // the transparency mask of itself
157  mpAlphaVDev->DrawBitmapEx( rDestPt,
158  rDestSize,
159  rSrcPtPixel,
160  rSrcSizePixel,
161  BitmapEx( rAlphaMask, rMask ) );
162 }
163 
164 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPRIVATE bool ImplIsRecordLayout() const
Definition: outdev.cxx:702
void DrawBitmapEx(const Point &rDestPt, const BitmapEx &rBitmapEx)
Definition: bitmapex.cxx:33
const std::shared_ptr< SalBitmap > & ImplGetSalBitmap() const
BmpMirrorFlags AdjustTwoRect(SalTwoRect &rTwoRect, const Size &rSizePix)
Definition: rect.cxx:341
bool mbOutputClipped
Definition: outdev.hxx:244
SAL_DLLPRIVATE bool is_double_buffered_window() const
tools::Long mnSrcHeight
Definition: salgtype.hxx:43
tools::Long mnSrcWidth
Definition: salgtype.hxx:42
Size GetSizePixel() const
void DrawMask(const Point &rDestPt, const Bitmap &rBitmap, const Color &rMaskColor)
Definition: mask.cxx:30
virtual void DrawDeviceMask(const Bitmap &rMask, const Color &rMaskColor, const Point &rDestPt, const Size &rDestSize, const Point &rSrcPtPixel, const Size &rSrcSizePixel)
Definition: mask.cxx:112
tools::Long mnDestWidth
Definition: salgtype.hxx:46
constexpr tools::Long Width() const
bool Mirror(BmpMirrorFlags nMirrorFlags)
Mirror the bitmap.
void DrawMask(const SalTwoRect &rPosAry, const SalBitmap &rSalBitmap, Color nMaskColor, const OutputDevice &rOutDev)
SAL_DLLPRIVATE tools::Long ImplLogicXToDevicePixel(tools::Long nX) const
Convert a logical X coordinate to a device pixel's X coordinate.
Definition: map.cxx:306
MetaActionType
void DrawRect(const tools::Rectangle &rRect)
Definition: rect.cxx:51
SalGraphics * mpGraphics
Graphics context to draw on.
Definition: outdev.hxx:181
tools::Long mnDestHeight
Definition: salgtype.hxx:47
virtual bool AcquireGraphics() const =0
Acquire a graphics device that the output device uses to draw on.
SAL_DLLPRIVATE tools::Long ImplLogicWidthToDevicePixel(tools::Long nWidth) const
Convert a logical width to a width in units of device pixels.
Definition: map.cxx:324
RasterOp meRasterOp
Definition: outdev.hxx:231
SAL_WARN_UNUSED_RESULT Point PixelToLogic(const Point &rDevicePt) const
Definition: map.cxx:1109
VclPtr< VirtualDevice > mpAlphaVDev
Definition: outdev.hxx:195
constexpr tools::Long Height() const
void AddAction(const rtl::Reference< MetaAction > &pAction)
Definition: gdimtf.cxx:562
bool mbInitClipRegion
Definition: outdev.hxx:251
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:315
bool IsDeviceOutputNecessary() const
Definition: outdev.hxx:477
SAL_DLLPRIVATE tools::Long ImplLogicHeightToDevicePixel(tools::Long nHeight) const
Convert a logical height to a height in units of device pixels.
Definition: map.cxx:332
Bitmap CreateMask(const Color &rTransColor, sal_uInt8 nTol=0) const
Create on-off mask from bitmap.
GDIMetaFile * mpMetaFile
Definition: outdev.hxx:184
BmpMirrorFlags