LibreOffice Module vcl (master)  1
pixel.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 
29 Color OutputDevice::GetPixel(const Point& rPoint) const
30 {
31  Color aColor;
32 
33  if (mpGraphics || AcquireGraphics())
34  {
35  assert(mpGraphics);
36  if (mbInitClipRegion)
37  const_cast<OutputDevice*>(this)->InitClipRegion();
38 
39  if (!mbOutputClipped)
40  {
41  const tools::Long nX = ImplLogicXToDevicePixel(rPoint.X());
42  const tools::Long nY = ImplLogicYToDevicePixel(rPoint.Y());
43  aColor = mpGraphics->GetPixel(nX, nY, *this);
44 
45  if (mpAlphaVDev)
46  {
47  Color aAlphaColor = mpAlphaVDev->GetPixel(rPoint);
48  aColor.SetAlpha(255 - aAlphaColor.GetBlue());
49  }
50  }
51  }
52  return aColor;
53 }
54 
55 void OutputDevice::DrawPixel( const Point& rPt )
56 {
57  assert(!is_double_buffered_window());
58 
59  if ( mpMetaFile )
60  mpMetaFile->AddAction( new MetaPointAction( rPt ) );
61 
63  return;
64 
65  Point aPt = ImplLogicToDevicePixel( rPt );
66 
67  if ( !mpGraphics && !AcquireGraphics() )
68  return;
69  assert(mpGraphics);
70 
71  if ( mbInitClipRegion )
73 
74  if ( mbOutputClipped )
75  return;
76 
77  if ( mbInitLineColor )
78  InitLineColor();
79 
80  mpGraphics->DrawPixel( aPt.X(), aPt.Y(), *this );
81 
82  if( mpAlphaVDev )
83  mpAlphaVDev->DrawPixel( rPt );
84 }
85 
86 void OutputDevice::DrawPixel( const Point& rPt, const Color& rColor )
87 {
88  assert(!is_double_buffered_window());
89 
90  Color aColor = ImplDrawModeToColor( rColor );
91 
92  if ( mpMetaFile )
93  mpMetaFile->AddAction( new MetaPixelAction( rPt, aColor ) );
94 
96  return;
97 
98  Point aPt = ImplLogicToDevicePixel( rPt );
99 
100  if ( !mpGraphics && !AcquireGraphics() )
101  return;
102  assert(mpGraphics);
103 
104  if ( mbInitClipRegion )
105  InitClipRegion();
106 
107  if ( mbOutputClipped )
108  return;
109 
110  mpGraphics->DrawPixel( aPt.X(), aPt.Y(), aColor, *this );
111 
112  if (mpAlphaVDev)
113  {
114  Color aAlphaColor(255 - rColor.GetAlpha(), 255 - rColor.GetAlpha(), 255 - rColor.GetAlpha());
115  mpAlphaVDev->DrawPixel(rPt, aAlphaColor);
116  }
117 }
118 
119 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void DrawPixel(tools::Long nX, tools::Long nY, const OutputDevice &rOutDev)
sal_uInt8 GetAlpha() const
void SetAlpha(sal_uInt8 nAlpha)
SAL_DLLPRIVATE bool ImplIsRecordLayout() const
Definition: outdev.cxx:651
long Long
bool mbOutputClipped
Definition: outdev.hxx:241
SAL_DLLPRIVATE bool is_double_buffered_window() const
SAL_DLLPRIVATE Color ImplDrawModeToColor(const Color &rColor) const
Definition: transparent.cxx:77
SAL_DLLPRIVATE void InitLineColor()
SAL_DLLPRIVATE tools::Long ImplLogicXToDevicePixel(tools::Long nX) const
Convert a logical X coordinate to a device pixel's X coordinate.
Definition: map.cxx:296
sal_uInt8 GetBlue() const
SalGraphics * mpGraphics
Graphics context to draw on.
Definition: outdev.hxx:175
virtual bool AcquireGraphics() const =0
Acquire a graphics device that the output device uses to draw on.
bool mbInitLineColor
Definition: outdev.hxx:244
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:162
bool mbLineColor
Definition: outdev.hxx:242
void DrawPixel(const Point &rPt)
Definition: pixel.cxx:55
VclPtr< VirtualDevice > mpAlphaVDev
Definition: outdev.hxx:192
void AddAction(const rtl::Reference< MetaAction > &pAction)
Definition: gdimtf.cxx:563
bool mbInitClipRegion
Definition: outdev.hxx:248
virtual void InitClipRegion()
SAL_DLLPRIVATE tools::Rectangle ImplLogicToDevicePixel(const tools::Rectangle &rLogicRect) const
Convert a logical rectangle to a rectangle in physical device pixel units.
Definition: map.cxx:376
SAL_DLLPRIVATE tools::Long ImplLogicYToDevicePixel(tools::Long nY) const
Convert a logical Y coordinate to a device pixel's Y coordinate.
Definition: map.cxx:305
Color GetPixel(tools::Long nX, tools::Long nY, const OutputDevice &rOutDev)
Color GetPixel(const Point &rPt) const
Definition: pixel.cxx:29
bool IsDeviceOutputNecessary() const
Definition: outdev.hxx:475
GDIMetaFile * mpMetaFile
Definition: outdev.hxx:178