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/.
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
34 #include <CoreGraphics/CoreGraphics.h>
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
57 , mbChecksumValid(false)
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
,
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()
92 virtual bool InterpretAs8Bit()
97 virtual bool Erase( const Color
& /*color*/ )
101 // Optimized case for AlphaMask::BlendWith().
102 virtual bool AlphaBlendWith( const SalBitmap
& /*rSalBmp*/ )
107 #if defined MACOSX || defined IOS
108 // Related: tdf#146842 Eliminate temporary copies of SkiaSalBitmap when
110 // Commit 9eb732a32023e74c44ac8c3b5af9f5424273bb6c fixed crashing when
111 // printing SkiaSalBitmaps to a non-Skia SalGraphics. However, the fix
112 // almost always makes two copies of the SkiaSalBitmap's bitmap data: the
113 // first copy is made in SkiaSalBitmap::AcquireBuffer() and then
114 // QuartzSalBitmap makes a copy of the first copy.
115 // By making QuartzSalBitmap's methods that return a CGImageRef virtual,
116 // a non-Skia SalGraphics can now create a CGImageRef directly from a
117 // SkiaSalBitmap's Skia bitmap data without copying to any intermediate
119 // Note: these methods are not pure virtual as the SvpSalBitmap class
120 // extends this class directly.
121 virtual CGImageRef
CreateWithMask( const SalBitmap
&, int, int, int, int ) const { return nullptr; }
122 virtual CGImageRef
CreateColorMask( int, int, int, int, Color
) const { return nullptr; }
123 virtual CGImageRef
CreateCroppedImage( int, int, int, int ) const { return nullptr; }
126 BitmapChecksum
GetChecksum() const
129 if (!mbChecksumValid
)
130 return 0; // back-compat
134 void InvalidateChecksum()
136 mbChecksumValid
= false;
140 void updateChecksum() const;
141 // helper function to convert data in 1,2,4 bpp formats to a 8/24/32bpp format
142 enum class BitConvert
149 static std::unique_ptr
< sal_uInt8
[] > convertDataBitCount( const sal_uInt8
* src
,
150 int width
, int height
, int bitCount
, int bytesPerRow
, const BitmapPalette
& palette
,
154 // access to SystemDependentDataHolder, to support overload in derived class(es)
155 virtual const basegfx::SystemDependentDataHolder
* accessSystemDependentDataHolder() const;
157 // exclusive management op's for SystemDependentData at SalBitmap
159 std::shared_ptr
<T
> getSystemDependentData() const
161 const basegfx::SystemDependentDataHolder
* pDataHolder(accessSystemDependentDataHolder());
163 return std::static_pointer_cast
<T
>(pDataHolder
->getSystemDependentData(typeid(T
).hash_code()));
164 return std::shared_ptr
<T
>();
167 template<class T
, class... Args
>
168 std::shared_ptr
<T
> addOrReplaceSystemDependentData(Args
&&... args
) const
170 const basegfx::SystemDependentDataHolder
* pDataHolder(accessSystemDependentDataHolder());
172 return std::shared_ptr
<T
>();
174 std::shared_ptr
<T
> r
= std::make_shared
<T
>(std::forward
<Args
>(args
)...);
176 // tdf#129845 only add to buffer if a relevant buffer time is estimated
177 if(r
->calculateCombinedHoldCyclesInSeconds() > 0)
179 basegfx::SystemDependentData_SharedPtr
r2(r
);
180 const_cast< basegfx::SystemDependentDataHolder
* >(pDataHolder
)->addOrReplaceSystemDependentData(r2
);
187 BitmapChecksum mnChecksum
;
188 bool mbChecksumValid
;
194 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */