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/.
10 #ifndef INCLUDED_VCL_BITMAP_TOOLS_HXX
11 #define INCLUDED_VCL_BITMAP_TOOLS_HXX
13 #include <config_cairo_canvas.h>
14 #include <config_wasm_strip.h>
16 #include <vcl/bitmapex.hxx>
17 #include <vcl/ImageTree.hxx>
18 #if ENABLE_CAIRO_CANVAS
19 #include <vcl/cairo.hxx>
21 #include <basegfx/range/b2drectangle.hxx>
23 #include <vcl/RawBitmap.hxx>
26 namespace basegfx
{ class B2DHomMatrix
; }
27 namespace com::sun::star::geometry
{ struct IntegerRectangle2D
; }
29 namespace vcl::bitmap
{
31 #if !ENABLE_WASM_STRIP_PREMULTIPLY
32 typedef std::array
<std::array
<sal_uInt8
, 256>, 256> lookup_table
;
34 lookup_table
const & get_premultiply_table();
35 VCL_DLLPUBLIC lookup_table
const & get_unpremultiply_table();
38 VCL_DLLPUBLIC sal_uInt8
unpremultiply(sal_uInt8 c
, sal_uInt8 a
);
39 VCL_DLLPUBLIC sal_uInt8
premultiply(sal_uInt8 c
, sal_uInt8 a
);
41 BitmapEx VCL_DLLPUBLIC
loadFromName(const OUString
& rFileName
, const ImageLoadFlags eFlags
= ImageLoadFlags::NONE
);
43 void loadFromSvg(SvStream
& rStream
, const OUString
& sPath
, BitmapEx
& rBitmapEx
, double fScaleFactor
);
45 /** Copy block of image data into the bitmap.
46 Assumes that the Bitmap has been constructed with the desired size.
49 The block of data to copy
51 The number of bytes in a scanline, must be >= (width * bitcount / 8)
53 BitmapEx VCL_DLLPUBLIC
CreateFromData(sal_uInt8
const *pData
,
54 sal_Int32 nWidth
, sal_Int32 nHeight
, sal_Int32 nStride
,
55 sal_Int8 nBitsPerPixel
,
56 bool bReversColors
= false, bool bReverseAlpha
= false);
58 void VCL_DLLPUBLIC
fillWithData(sal_uInt8
* pData
, BitmapEx
const& rBitmapEx
);
60 BitmapEx VCL_DLLPUBLIC
CreateFromData( RawBitmap
&& data
);
62 #if ENABLE_CAIRO_CANVAS
63 VCL_DLLPUBLIC BitmapEx
* CreateFromCairoSurface(Size size
, cairo_surface_t
* pSurface
);
66 VCL_DLLPUBLIC BitmapEx
CanvasTransformBitmap( const BitmapEx
& rBitmap
,
67 const ::basegfx::B2DHomMatrix
& rTransform
,
68 ::basegfx::B2DRectangle
const & rDestRect
,
69 ::basegfx::B2DHomMatrix
const & rLocalTransform
);
71 VCL_DLLPUBLIC
void DrawAlphaBitmapAndAlphaGradient(BitmapEx
& rBitmapEx
, bool bFixedTransparence
, float fTransparence
, AlphaMask
& rNewMask
);
73 VCL_DLLPUBLIC
void DrawAndClipBitmap(const Point
& rPos
, const Size
& rSize
, const BitmapEx
& rBitmap
, BitmapEx
& aBmpEx
, basegfx::B2DPolyPolygon
const & rClipPath
);
75 VCL_DLLPUBLIC
css::uno::Sequence
< sal_Int8
> GetMaskDIB(BitmapEx
const & aBmpEx
);
78 * @param data will be filled with alpha data, if xBitmap is alpha/transparent image
79 * @param bHasAlpha will be set to true if resulting surface has alpha
81 VCL_DLLPUBLIC
void CanvasCairoExtractBitmapData( BitmapEx
const & rBmpEx
, Bitmap
& rBitmap
, unsigned char*& data
, bool& bHasAlpha
, tools::Long
& rnWidth
, tools::Long
& rnHeight
);
83 VCL_DLLPUBLIC
css::uno::Sequence
< sal_Int8
> CanvasExtractBitmapData(BitmapEx
const & rBitmapEx
, const css::geometry::IntegerRectangle2D
& rect
);
85 // helper to construct historical 8x8 bitmaps with two colors
87 BitmapEx VCL_DLLPUBLIC
createHistorical8x8FromArray(std::array
<sal_uInt8
,64> const & pArray
, Color aColorPix
, Color aColorBack
);
88 bool VCL_DLLPUBLIC
isHistorical8x8(const BitmapEx
& rBitmapEx
, Color
& o_rBack
, Color
& o_rFront
);
90 VCL_DLLPUBLIC
bool convertBitmap32To24Plus8(BitmapEx
const & rInput
, BitmapEx
& rResult
);
92 /** Retrieve downsampled and cropped bitmap
94 Takes destination size in twips units.
96 @attention This method ignores negative rDstSz values, thus
97 mirroring must happen outside this method (e.g. in DrawBitmap)
99 VCL_DLLPUBLIC Bitmap
GetDownsampledBitmap(Size
const& rDstSizeTwip
, Point
const& rSrcPt
, Size
const& rSrcSz
,
100 Bitmap
const& rBmp
, tools::Long nMaxBmpDPIX
, tools::Long nMaxBmpDPIY
);
102 BitmapColor
premultiply(const BitmapColor c
);
103 BitmapColor
unpremultiply(const BitmapColor c
);
107 #endif // INCLUDED_VCL_BITMAP_TOOLS_HXX
109 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */