LibreOffice Module vcl (master) 1
salbmp.hxx
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#ifndef INCLUDED_VCL_INC_SALBMP_HXX
21#define INCLUDED_VCL_INC_SALBMP_HXX
22
23#include <tools/gen.hxx>
24#include <tools/solar.h>
25#include <vcl/checksum.hxx>
27#include <vcl/BitmapBuffer.hxx>
29#include <com/sun/star/rendering/XBitmapCanvas.hpp>
31
32#if defined MACOSX || defined IOS
33#include <premac.h>
34#include <CoreGraphics/CoreGraphics.h>
35#include <postmac.h>
36#endif
37
38struct BitmapBuffer;
39class Color;
40class SalGraphics;
41class BitmapPalette;
42struct BitmapSystemData;
43enum class BmpScaleFlag;
44
45extern const sal_uLong nVCLRLut[ 6 ];
46extern const sal_uLong nVCLGLut[ 6 ];
47extern const sal_uLong nVCLBLut[ 6 ];
48extern const sal_uLong nVCLDitherLut[ 256 ];
49extern const sal_uLong nVCLLut[ 256 ];
50
52{
53public:
54
56 : mnChecksum(0)
57 , mbChecksumValid(false)
58 {
59 }
60
61 virtual ~SalBitmap();
62
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;
77
79 virtual void ReleaseBuffer( BitmapBuffer* pBuffer, BitmapAccessMode nMode ) = 0;
80 virtual bool GetSystemData( BitmapSystemData& rData ) = 0;
81
82 virtual bool ScalingSupported() const = 0;
83 virtual bool Scale( const double& rScaleX, const double& rScaleY, BmpScaleFlag nScaleFlag ) = 0;
84 void DropScaledCache();
85
86 virtual bool Replace( const Color& rSearchColor, const Color& rReplaceColor, sal_uInt8 nTol ) = 0;
87
88 virtual bool ConvertToGreyscale()
89 {
90 return false;
91 }
92 virtual bool InterpretAs8Bit()
93 {
94 return false;
95 }
96
97 virtual bool Erase( const Color& /*color*/ )
98 {
99 return false;
100 }
101 // Optimized case for AlphaMask::BlendWith().
102 virtual bool AlphaBlendWith( const SalBitmap& /*rSalBmp*/ )
103 {
104 return false;
105 }
106
107#if defined MACOSX || defined IOS
108 // Related: tdf#146842 Eliminate temporary copies of SkiaSalBitmap when
109 // printing
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
118 // buffers.
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; }
124#endif
125
127 {
128 updateChecksum();
129 if (!mbChecksumValid)
130 return 0; // back-compat
131 return mnChecksum;
132 }
133
135 {
136 mbChecksumValid = false;
137 }
138
139protected:
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
143 {
144 A8,
145 RGBA,
146 BGRA,
147 LAST = BGRA
148 };
149 static std::unique_ptr< sal_uInt8[] > convertDataBitCount( const sal_uInt8* src,
150 int width, int height, int bitCount, int bytesPerRow, const BitmapPalette& palette,
151 BitConvert type );
152
153public:
154 // access to SystemDependentDataHolder, to support overload in derived class(es)
155 virtual const basegfx::SystemDependentDataHolder* accessSystemDependentDataHolder() const;
156
157 // exclusive management op's for SystemDependentData at SalBitmap
158 template<class T>
159 std::shared_ptr<T> getSystemDependentData() const
160 {
161 const basegfx::SystemDependentDataHolder* pDataHolder(accessSystemDependentDataHolder());
162 if(pDataHolder)
163 return std::static_pointer_cast<T>(pDataHolder->getSystemDependentData(typeid(T).hash_code()));
164 return std::shared_ptr<T>();
165 }
166
167 template<class T, class... Args>
168 std::shared_ptr<T> addOrReplaceSystemDependentData(Args&&... args) const
169 {
170 const basegfx::SystemDependentDataHolder* pDataHolder(accessSystemDependentDataHolder());
171 if(!pDataHolder)
172 return std::shared_ptr<T>();
173
174 std::shared_ptr<T> r = std::make_shared<T>(std::forward<Args>(args)...);
175
176 // tdf#129845 only add to buffer if a relevant buffer time is estimated
177 if(r->calculateCombinedHoldCyclesInSeconds() > 0)
178 {
180 const_cast< basegfx::SystemDependentDataHolder* >(pDataHolder)->addOrReplaceSystemDependentData(r2);
181 }
182
183 return r;
184 }
185
186private:
189
190};
191
192#endif
193
194/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
BitmapAccessMode
sal_uInt64 BitmapChecksum
Definition: checksum.hxx:30
virtual bool Erase(const Color &)
Definition: salbmp.hxx:97
BitmapChecksum mnChecksum
Definition: salbmp.hxx:187
SalBitmap()
Definition: salbmp.hxx:55
std::shared_ptr< T > getSystemDependentData() const
Definition: salbmp.hxx:159
virtual bool Scale(const double &rScaleX, const double &rScaleY, BmpScaleFlag nScaleFlag)=0
virtual void Destroy()=0
bool mbChecksumValid
Definition: salbmp.hxx:188
virtual sal_uInt16 GetBitCount() const =0
virtual bool ConvertToGreyscale()
Definition: salbmp.hxx:88
virtual bool InterpretAs8Bit()
Definition: salbmp.hxx:92
virtual bool Replace(const Color &rSearchColor, const Color &rReplaceColor, sal_uInt8 nTol)=0
virtual void ReleaseBuffer(BitmapBuffer *pBuffer, BitmapAccessMode nMode)=0
virtual bool AlphaBlendWith(const SalBitmap &)
Definition: salbmp.hxx:102
virtual bool GetSystemData(BitmapSystemData &rData)=0
virtual Size GetSize() const =0
virtual bool Create(const SalBitmap &rSalBmp)=0
void InvalidateChecksum()
Definition: salbmp.hxx:134
std::shared_ptr< T > addOrReplaceSystemDependentData(Args &&... args) const
Definition: salbmp.hxx:168
virtual BitmapBuffer * AcquireBuffer(BitmapAccessMode nMode)=0
BitmapChecksum GetChecksum() const
Definition: salbmp.hxx:126
virtual bool ScalingSupported() const =0
virtual bool Create(const css::uno::Reference< css::rendering::XBitmapCanvas > &rBitmapCanvas, Size &rSize, bool bMask=false)=0
virtual bool Create(const Size &rSize, vcl::PixelFormat ePixelFormat, const BitmapPalette &rPal)=0
virtual bool Create(const SalBitmap &rSalBmp, SalGraphics *pGraphics)=0
virtual bool Create(const SalBitmap &rSalBmp, vcl::PixelFormat eNewPixelFormat)=0
SystemDependentData_SharedPtr getSystemDependentData(size_t hash_code) const
#define VCL_PLUGIN_PUBLIC
Definition: dllapi.h:40
std::shared_ptr< SystemDependentData > SystemDependentData_SharedPtr
args
PixelFormat
Pixel format of the bitmap in bits per pixel.
Definition: BitmapTypes.hxx:20
const sal_uLong nVCLLut[256]
const sal_uLong nVCLBLut[6]
const sal_uLong nVCLGLut[6]
const sal_uLong nVCLRLut[6]
const sal_uLong nVCLDitherLut[256]
sal_uIntPtr sal_uLong
unsigned char sal_uInt8