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 virtual bool Invert()
108 {
109 return false;
110 }
111
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
130
132 {
133 updateChecksum();
134 if (!mbChecksumValid)
135 return 0; // back-compat
136 return mnChecksum;
137 }
138
140 {
141 mbChecksumValid = false;
142 }
143
144protected:
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
148 {
149 A8,
150 RGBA,
151 BGRA,
152 LAST = BGRA
153 };
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 );
157
158public:
159 // access to SystemDependentDataHolder, to support overload in derived class(es)
160 virtual const basegfx::SystemDependentDataHolder* accessSystemDependentDataHolder() const;
161
162 // exclusive management op's for SystemDependentData at SalBitmap
163 template<class T>
164 std::shared_ptr<T> getSystemDependentData() const
165 {
166 const basegfx::SystemDependentDataHolder* pDataHolder(accessSystemDependentDataHolder());
167 if(pDataHolder)
168 return std::static_pointer_cast<T>(pDataHolder->getSystemDependentData(typeid(T).hash_code()));
169 return std::shared_ptr<T>();
170 }
171
172 template<class T, class... Args>
173 std::shared_ptr<T> addOrReplaceSystemDependentData(Args&&... args) const
174 {
175 const basegfx::SystemDependentDataHolder* pDataHolder(accessSystemDependentDataHolder());
176 if(!pDataHolder)
177 return std::shared_ptr<T>();
178
179 std::shared_ptr<T> r = std::make_shared<T>(std::forward<Args>(args)...);
180
181 // tdf#129845 only add to buffer if a relevant buffer time is estimated
182 if(r->calculateCombinedHoldCyclesInSeconds() > 0)
183 {
185 const_cast< basegfx::SystemDependentDataHolder* >(pDataHolder)->addOrReplaceSystemDependentData(r2);
186 }
187
188 return r;
189 }
190
191private:
194
195};
196
197#endif
198
199/* 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:192
SalBitmap()
Definition: salbmp.hxx:55
std::shared_ptr< T > getSystemDependentData() const
Definition: salbmp.hxx:164
virtual bool Scale(const double &rScaleX, const double &rScaleY, BmpScaleFlag nScaleFlag)=0
virtual bool Invert()
Definition: salbmp.hxx:107
virtual void Destroy()=0
bool mbChecksumValid
Definition: salbmp.hxx:193
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:139
std::shared_ptr< T > addOrReplaceSystemDependentData(Args &&... args) const
Definition: salbmp.hxx:173
virtual BitmapBuffer * AcquireBuffer(BitmapAccessMode nMode)=0
BitmapChecksum GetChecksum() const
Definition: salbmp.hxx:131
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