office-gobmx/include/vcl/BitmapTools.hxx
Noel Grandin 380da094b0 ofz#6372 fix bitmap decoding of pattern in LwpBackgroundStuff
after
    commit b90e098a35
    use BitmapEx in LwpBackgroundStuff

<caolan> maybe the lotuswordpro original stride is really 4 after all
(as a common stride), with the first byte on each line containing the
8bits for each row

The original code in GetPattern() looked pretty dodgy since it was
copying 32-bytes into an 8 byte buffer.
Assume that the reversing part is right, and that the format is really a
1bit packed 8x8 image.

Also fix the decoding of such a image in CreateFromData to assume packed
format, which is more predictable.

Also fix the bug in createDefaultCross_3x3 which changing the assert
revealed.

Change-Id: I7196ae601429bbe0f842399df61c8b858e022d3e
Reviewed-on: https://gerrit.libreoffice.org/49808
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
2018-02-15 18:34:09 +01:00

81 lines
2.6 KiB
C++

/* -*- 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
#include <config_cairo_canvas.h>
#include <vcl/bitmapex.hxx>
#include <vcl/ImageTree.hxx>
#include <vcl/salbtype.hxx>
#include <tools/stream.hxx>
#if ENABLE_CAIRO_CANVAS
#include <vcl/cairo.hxx>
#endif
namespace vcl {
namespace bitmap {
/**
* Intended to be used to feed into CreateFromData to create a BitmapEx. RGB data format.
*/
class VCL_DLLPUBLIC RawBitmap
{
friend BitmapEx VCL_DLLPUBLIC CreateFromData( RawBitmap&& rawBitmap );
std::unique_ptr<sal_uInt8[]> mpData;
Size maSize;
public:
RawBitmap(Size const & rSize)
: mpData(new sal_uInt8[ rSize.getWidth() * 3 * rSize.getHeight()]),
maSize(rSize)
{
}
void SetPixel(long nY, long nX, Color nColor)
{
long p = (nY * maSize.getWidth() + nX) * 3;
mpData[ p++ ] = nColor.GetRed();
mpData[ p++ ] = nColor.GetGreen();
mpData[ p ] = nColor.GetBlue();
}
Color GetPixel(long nY, long nX) const
{
long p = (nY * maSize.getWidth() + nX) * 3;
return Color( mpData[p], mpData[p+1], mpData[p+2]);
}
// so we don't accidentally leave any code in that uses palette color indexes
void SetPixel(long nY, long nX, BitmapColor nColor) = delete;
long Height() { return maSize.Height(); }
long Width() { return maSize.Width(); }
};
BitmapEx VCL_DLLPUBLIC loadFromName(const OUString& rFileName, const ImageLoadFlags eFlags = ImageLoadFlags::NONE);
void loadFromSvg(SvStream& rStream, const OUString& sPath, BitmapEx& rBitmapEx, double fScaleFactor);
/** 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
The number of bytes in a scanline, must be >= (width * nBitCount / 8)
*/
BitmapEx VCL_DLLPUBLIC CreateFromData( sal_uInt8 const *pData, sal_Int32 nWidth, sal_Int32 nHeight, sal_Int32 nStride, sal_uInt16 nBitCount );
BitmapEx VCL_DLLPUBLIC CreateFromData( RawBitmap && data );
#if ENABLE_CAIRO_CANVAS
VCL_DLLPUBLIC BitmapEx* CreateFromCairoSurface(Size size, cairo_surface_t* pSurface);
#endif
}} // end vcl::bitmap
#endif // INCLUDED_VCL_BITMAP_TOOLS_HXX
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */