2015-11-08 23:00:14 +01:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef INCLUDED_VCL_BITMAP_TOOLS_HXX
|
|
|
|
#define INCLUDED_VCL_BITMAP_TOOLS_HXX
|
|
|
|
|
2018-02-14 14:27:12 +02:00
|
|
|
#include <config_cairo_canvas.h>
|
2015-11-08 23:00:14 +01:00
|
|
|
#include <vcl/bitmapex.hxx>
|
2016-12-18 14:31:14 +01:00
|
|
|
#include <vcl/ImageTree.hxx>
|
2019-04-16 22:44:21 +09:00
|
|
|
#include <vcl/BitmapColor.hxx>
|
2018-02-14 14:27:12 +02:00
|
|
|
#if ENABLE_CAIRO_CANVAS
|
|
|
|
#include <vcl/cairo.hxx>
|
|
|
|
#endif
|
2018-03-13 14:26:54 +02:00
|
|
|
#include <basegfx/range/b2drectangle.hxx>
|
2018-04-04 17:05:46 +01:00
|
|
|
#include <o3tl/safeint.hxx>
|
2018-08-21 16:07:55 +02:00
|
|
|
#include <array>
|
2016-10-27 18:18:23 +02:00
|
|
|
|
2018-11-15 22:04:54 +01:00
|
|
|
class SvStream;
|
|
|
|
namespace basegfx { class B2DHomMatrix; }
|
|
|
|
namespace com { namespace sun { namespace star { namespace geometry { struct IntegerRectangle2D; } } } }
|
|
|
|
|
2016-12-09 23:27:54 +01:00
|
|
|
namespace vcl {
|
|
|
|
namespace bitmap {
|
2015-11-08 23:00:14 +01:00
|
|
|
|
2018-12-05 13:09:46 +01:00
|
|
|
typedef sal_uInt8 (*lookup_table)[256];
|
2018-12-01 19:41:15 +00:00
|
|
|
|
2018-12-05 13:09:46 +01:00
|
|
|
lookup_table VCL_DLLPUBLIC get_premultiply_table();
|
|
|
|
lookup_table VCL_DLLPUBLIC get_unpremultiply_table();
|
2018-12-01 19:41:15 +00:00
|
|
|
|
2019-02-15 13:14:32 +01:00
|
|
|
VCL_DLLPUBLIC sal_uInt8 unpremultiply(sal_uInt8 c, sal_uInt8 a);
|
|
|
|
VCL_DLLPUBLIC sal_uInt8 premultiply(sal_uInt8 c, sal_uInt8 a);
|
|
|
|
|
2018-02-09 16:27:35 +02:00
|
|
|
/**
|
2018-02-12 15:31:18 +02:00
|
|
|
* Intended to be used to feed into CreateFromData to create a BitmapEx. RGB data format.
|
2018-02-09 16:27:35 +02:00
|
|
|
*/
|
|
|
|
class VCL_DLLPUBLIC RawBitmap
|
|
|
|
{
|
|
|
|
friend BitmapEx VCL_DLLPUBLIC CreateFromData( RawBitmap&& rawBitmap );
|
|
|
|
std::unique_ptr<sal_uInt8[]> mpData;
|
2018-09-13 13:08:33 +02:00
|
|
|
Size const maSize;
|
|
|
|
sal_uInt8 const mnBitCount;
|
2018-02-09 16:27:35 +02:00
|
|
|
public:
|
2018-03-01 12:00:24 +02:00
|
|
|
RawBitmap(Size const & rSize, sal_uInt8 nBitCount)
|
2018-04-04 17:05:46 +01:00
|
|
|
: maSize(rSize),
|
2018-03-01 12:00:24 +02:00
|
|
|
mnBitCount(nBitCount)
|
2018-02-09 16:27:35 +02:00
|
|
|
{
|
2018-03-01 12:00:24 +02:00
|
|
|
assert(nBitCount == 24 || nBitCount == 32);
|
2018-04-04 17:05:46 +01:00
|
|
|
sal_Int32 nRowSize, nDataSize;
|
|
|
|
if (o3tl::checked_multiply<sal_Int32>(rSize.getWidth(), nBitCount/8, nRowSize) ||
|
|
|
|
o3tl::checked_multiply<sal_Int32>(nRowSize, rSize.getHeight(), nDataSize))
|
|
|
|
{
|
|
|
|
throw std::bad_alloc();
|
|
|
|
}
|
|
|
|
mpData.reset(new sal_uInt8[nDataSize]);
|
2018-02-09 16:27:35 +02:00
|
|
|
}
|
2018-02-12 14:07:24 +02:00
|
|
|
void SetPixel(long nY, long nX, Color nColor)
|
2018-02-09 16:27:35 +02:00
|
|
|
{
|
2018-03-01 12:00:24 +02:00
|
|
|
long p = (nY * maSize.getWidth() + nX) * (mnBitCount/8);
|
2018-02-09 16:27:35 +02:00
|
|
|
mpData[ p++ ] = nColor.GetRed();
|
|
|
|
mpData[ p++ ] = nColor.GetGreen();
|
2018-03-01 12:00:24 +02:00
|
|
|
mpData[ p++ ] = nColor.GetBlue();
|
|
|
|
if (mnBitCount == 32)
|
|
|
|
mpData[ p ] = nColor.GetTransparency();
|
2018-02-09 16:27:35 +02:00
|
|
|
}
|
2018-02-12 15:29:10 +02:00
|
|
|
Color GetPixel(long nY, long nX) const
|
|
|
|
{
|
2018-03-01 12:00:24 +02:00
|
|
|
long p = (nY * maSize.getWidth() + nX) * mnBitCount/8;
|
|
|
|
if (mnBitCount == 24)
|
|
|
|
return Color( mpData[p], mpData[p+1], mpData[p+2]);
|
|
|
|
else
|
|
|
|
return Color( mpData[p+3], mpData[p], mpData[p+1], mpData[p+2]);
|
2018-02-12 15:29:10 +02:00
|
|
|
}
|
2018-02-12 14:07:24 +02:00
|
|
|
// so we don't accidentally leave any code in that uses palette color indexes
|
|
|
|
void SetPixel(long nY, long nX, BitmapColor nColor) = delete;
|
2018-02-12 10:48:13 +02:00
|
|
|
long Height() { return maSize.Height(); }
|
|
|
|
long Width() { return maSize.Width(); }
|
2018-03-01 12:00:24 +02:00
|
|
|
sal_uInt8 GetBitCount() { return mnBitCount; }
|
2018-02-09 16:27:35 +02:00
|
|
|
};
|
|
|
|
|
2016-12-09 23:27:54 +01:00
|
|
|
BitmapEx VCL_DLLPUBLIC loadFromName(const OUString& rFileName, const ImageLoadFlags eFlags = ImageLoadFlags::NONE);
|
2016-10-27 17:42:36 +02:00
|
|
|
|
2017-11-28 16:29:28 +02:00
|
|
|
void loadFromSvg(SvStream& rStream, const OUString& sPath, BitmapEx& rBitmapEx, double fScaleFactor);
|
2016-10-27 17:42:36 +02:00
|
|
|
|
2018-02-06 12:00:16 +02:00
|
|
|
/** Copy block of image data into the bitmap.
|
|
|
|
Assumes that the Bitmap has been constructed with the desired size.
|
|
|
|
|
|
|
|
@param pData
|
|
|
|
The block of data to copy
|
|
|
|
@param nStride
|
2018-02-15 13:27:30 +02:00
|
|
|
The number of bytes in a scanline, must be >= (width * nBitCount / 8)
|
2018-02-06 12:00:16 +02:00
|
|
|
*/
|
|
|
|
BitmapEx VCL_DLLPUBLIC CreateFromData( sal_uInt8 const *pData, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int32 nStride, sal_uInt16 nBitCount );
|
|
|
|
|
2018-02-09 16:27:35 +02:00
|
|
|
BitmapEx VCL_DLLPUBLIC CreateFromData( RawBitmap && data );
|
2018-02-06 12:00:16 +02:00
|
|
|
|
2018-02-14 14:27:12 +02:00
|
|
|
#if ENABLE_CAIRO_CANVAS
|
|
|
|
VCL_DLLPUBLIC BitmapEx* CreateFromCairoSurface(Size size, cairo_surface_t* pSurface);
|
|
|
|
#endif
|
|
|
|
|
2018-03-13 14:26:54 +02:00
|
|
|
VCL_DLLPUBLIC BitmapEx CanvasTransformBitmap( const BitmapEx& rBitmap,
|
|
|
|
const ::basegfx::B2DHomMatrix& rTransform,
|
|
|
|
::basegfx::B2DRectangle const & rDestRect,
|
|
|
|
::basegfx::B2DHomMatrix const & rLocalTransform );
|
|
|
|
|
2018-03-14 17:13:42 +02:00
|
|
|
VCL_DLLPUBLIC void DrawAlphaBitmapAndAlphaGradient(BitmapEx & rBitmapEx, bool bFixedTransparence, float fTransparence, AlphaMask & rNewMask);
|
|
|
|
|
2018-03-15 09:06:49 +02:00
|
|
|
VCL_DLLPUBLIC void DrawAndClipBitmap(const Point& rPos, const Size& rSize, const BitmapEx& rBitmap, BitmapEx & aBmpEx, basegfx::B2DPolyPolygon const & rClipPath);
|
|
|
|
|
2018-03-16 09:51:44 +02:00
|
|
|
VCL_DLLPUBLIC css::uno::Sequence< sal_Int8 > GetMaskDIB(BitmapEx const & aBmpEx);
|
|
|
|
|
2018-03-16 14:58:59 +02:00
|
|
|
/**
|
|
|
|
* @param data will be filled with alpha data, if xBitmap is alpha/transparent image
|
|
|
|
* @param bHasAlpha will be set to true if resulting surface has alpha
|
|
|
|
**/
|
2018-04-12 10:04:35 +02:00
|
|
|
VCL_DLLPUBLIC void CanvasCairoExtractBitmapData( BitmapEx const & rBmpEx, Bitmap & rBitmap, unsigned char*& data, bool& bHasAlpha, long& rnWidth, long& rnHeight );
|
2018-03-16 14:58:59 +02:00
|
|
|
|
2018-04-12 10:04:35 +02:00
|
|
|
VCL_DLLPUBLIC css::uno::Sequence< sal_Int8 > CanvasExtractBitmapData(BitmapEx const & rBitmapEx, const css::geometry::IntegerRectangle2D& rect);
|
2018-03-16 15:40:29 +02:00
|
|
|
|
2018-08-21 16:07:55 +02:00
|
|
|
// helper to construct historical 8x8 bitmaps with two colors
|
|
|
|
|
|
|
|
BitmapEx VCL_DLLPUBLIC createHistorical8x8FromArray(std::array<sal_uInt8,64> const & pArray, Color aColorPix, Color aColorBack);
|
2019-04-09 09:58:27 +09:00
|
|
|
bool VCL_DLLPUBLIC isHistorical8x8(const BitmapEx& rBitmapEx, Color& o_rBack, Color& o_rFront);
|
2018-08-21 16:07:55 +02:00
|
|
|
|
2019-02-15 13:14:32 +01:00
|
|
|
VCL_DLLPUBLIC bool convertBitmap32To24Plus8(BitmapEx const & rInput, BitmapEx & rResult);
|
|
|
|
|
2016-12-09 23:27:54 +01:00
|
|
|
}} // end vcl::bitmap
|
2015-11-08 23:00:14 +01:00
|
|
|
|
|
|
|
#endif // INCLUDED_VCL_BITMAP_TOOLS_HXX
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|