sw a11y: clang-format SidebarWinAccessible code
[LibreOffice.git] / vcl / inc / salbmp.hxx
blob7d4fceb4397e2c93fb8963934a43333e622a1f66
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_VCL_INC_SALBMP_HXX
21 #define INCLUDED_VCL_INC_SALBMP_HXX
23 #include <tools/gen.hxx>
24 #include <tools/solar.h>
25 #include <vcl/checksum.hxx>
26 #include <vcl/BitmapAccessMode.hxx>
27 #include <vcl/BitmapBuffer.hxx>
28 #include <vcl/bitmap/BitmapTypes.hxx>
29 #include <com/sun/star/rendering/XBitmapCanvas.hpp>
30 #include <basegfx/utils/systemdependentdata.hxx>
32 #if defined MACOSX || defined IOS
33 #include <premac.h>
34 #include <CoreGraphics/CoreGraphics.h>
35 #include <postmac.h>
36 #endif
38 struct BitmapBuffer;
39 class Color;
40 class SalGraphics;
41 class BitmapPalette;
42 struct BitmapSystemData;
43 enum class BmpScaleFlag;
45 extern const sal_uLong nVCLRLut[ 6 ];
46 extern const sal_uLong nVCLGLut[ 6 ];
47 extern const sal_uLong nVCLBLut[ 6 ];
48 extern const sal_uLong nVCLDitherLut[ 256 ];
49 extern const sal_uLong nVCLLut[ 256 ];
51 class VCL_PLUGIN_PUBLIC SalBitmap
53 public:
55 SalBitmap()
56 : mnChecksum(0)
57 , mbChecksumValid(false)
61 virtual ~SalBitmap();
63 virtual bool Create( const Size& rSize,
64 vcl::PixelFormat ePixelFormat,
65 const BitmapPalette& rPal ) = 0;
66 virtual bool Create( const SalBitmap& rSalBmp ) = 0;
67 virtual bool Create( const SalBitmap& rSalBmp,
68 SalGraphics* pGraphics ) = 0;
69 virtual bool Create( const SalBitmap& rSalBmp,
70 vcl::PixelFormat eNewPixelFormat) = 0;
71 virtual bool Create( const css::uno::Reference< css::rendering::XBitmapCanvas >& rBitmapCanvas,
72 Size& rSize,
73 bool bMask = false ) = 0;
74 virtual void Destroy() = 0;
75 virtual Size GetSize() const = 0;
76 virtual sal_uInt16 GetBitCount() const = 0;
78 virtual BitmapBuffer* AcquireBuffer( BitmapAccessMode nMode ) = 0;
79 virtual void ReleaseBuffer( BitmapBuffer* pBuffer, BitmapAccessMode nMode ) = 0;
80 virtual bool GetSystemData( BitmapSystemData& rData ) = 0;
82 virtual bool ScalingSupported() const = 0;
83 virtual bool Scale( const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag ) = 0;
84 void DropScaledCache();
86 virtual bool Replace( const Color& rSearchColor, const Color& rReplaceColor, sal_uInt8 nTol ) = 0;
88 virtual bool ConvertToGreyscale()
90 return false;
92 virtual bool InterpretAs8Bit()
94 return false;
97 virtual bool Erase( const Color& /*color*/ )
99 return false;
101 // Optimized case for AlphaMask::BlendWith().
102 virtual bool AlphaBlendWith( const SalBitmap& /*rSalBmp*/ )
104 return false;
107 virtual bool Invert()
109 return false;
112 #if defined MACOSX || defined IOS
113 // Related: tdf#146842 Eliminate temporary copies of SkiaSalBitmap when
114 // printing
115 // Commit 9eb732a32023e74c44ac8c3b5af9f5424273bb6c fixed crashing when
116 // printing SkiaSalBitmaps to a non-Skia SalGraphics. However, the fix
117 // almost always makes two copies of the SkiaSalBitmap's bitmap data: the
118 // first copy is made in SkiaSalBitmap::AcquireBuffer() and then
119 // QuartzSalBitmap makes a copy of the first copy.
120 // By making QuartzSalBitmap's methods that return a CGImageRef virtual,
121 // a non-Skia SalGraphics can now create a CGImageRef directly from a
122 // SkiaSalBitmap's Skia bitmap data without copying to any intermediate
123 // buffers.
124 // Note: these methods are not pure virtual as the SvpSalBitmap class
125 // extends this class directly.
126 virtual CGImageRef CreateWithMask( const SalBitmap&, int, int, int, int ) const { return nullptr; }
127 virtual CGImageRef CreateColorMask( int, int, int, int, Color ) const { return nullptr; }
128 virtual CGImageRef CreateCroppedImage( int, int, int, int ) const { return nullptr; }
129 #endif
131 BitmapChecksum GetChecksum() const
133 updateChecksum();
134 if (!mbChecksumValid)
135 return 0; // back-compat
136 return mnChecksum;
139 void InvalidateChecksum()
141 mbChecksumValid = false;
144 protected:
145 void updateChecksum() const;
146 // helper function to convert data in 1,2,4 bpp formats to a 8/24/32bpp format
147 enum class BitConvert
150 RGBA,
151 BGRA,
152 LAST = BGRA
154 static std::unique_ptr< sal_uInt8[] > convertDataBitCount( const sal_uInt8* src,
155 int width, int height, int bitCount, int bytesPerRow, const BitmapPalette& palette,
156 BitConvert type );
158 public:
159 // access to SystemDependentDataHolder, to support overload in derived class(es)
160 virtual const basegfx::SystemDependentDataHolder* accessSystemDependentDataHolder() const;
162 // exclusive management op's for SystemDependentData at SalBitmap
163 template<class T>
164 std::shared_ptr<T> getSystemDependentData(basegfx::SDD_Type aType) const
166 const basegfx::SystemDependentDataHolder* pDataHolder(accessSystemDependentDataHolder());
167 if(pDataHolder)
168 return std::static_pointer_cast<T>(pDataHolder->getSystemDependentData(aType));
169 return std::shared_ptr<T>();
172 template<class T, class... Args>
173 std::shared_ptr<T> addOrReplaceSystemDependentData(Args&&... args) const
175 const basegfx::SystemDependentDataHolder* pDataHolder(accessSystemDependentDataHolder());
176 if(!pDataHolder)
177 return std::shared_ptr<T>();
179 std::shared_ptr<T> r = std::make_shared<T>(std::forward<Args>(args)...);
181 // tdf#129845 only add to buffer if a relevant buffer time is estimated
182 if(r->calculateCombinedHoldCyclesInSeconds() > 0)
184 basegfx::SystemDependentData_SharedPtr r2(r);
185 const_cast< basegfx::SystemDependentDataHolder* >(pDataHolder)->addOrReplaceSystemDependentData(r2);
188 return r;
191 private:
192 BitmapChecksum mnChecksum;
193 bool mbChecksumValid;
197 #endif
199 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */