summaryrefslogtreecommitdiff
path: root/basebmp
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2015-11-24 13:39:42 +0000
committerCaolán McNamara <caolanm@redhat.com>2015-11-24 18:49:04 +0000
commit9b52b8999be86e5c6e5f5901b2640b16f08a2323 (patch)
tree218897a0bf04cb0cca2e0840d53378db16dda8db /basebmp
parentf9588062dd22771395ed8e076f009deb23a0092f (diff)
Resolves: tdf#95962 incorrect scanline stride
we were reusing the stride of the surface we were cloning, but the new surface has a different underlying size. remove the custom stride argument and just change our stride calculation to use the same scheme that cairo and GDI uses, which remove another platform/drawing-system variable Change-Id: I257dac9757b121642e9ccfde7db0911edc9f3fb1 Reviewed-on: https://gerrit.libreoffice.org/20149 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'basebmp')
-rw-r--r--basebmp/source/bitmapdevice.cxx25
-rw-r--r--basebmp/test/basictest.cxx29
-rw-r--r--basebmp/test/bmpmasktest.cxx24
-rw-r--r--basebmp/test/bmptest.cxx12
-rw-r--r--basebmp/test/cliptest.cxx12
-rw-r--r--basebmp/test/filltest.cxx6
-rw-r--r--basebmp/test/linetest.cxx12
-rw-r--r--basebmp/test/masktest.cxx9
-rw-r--r--basebmp/test/polytest.cxx6
9 files changed, 45 insertions, 90 deletions
diff --git a/basebmp/source/bitmapdevice.cxx b/basebmp/source/bitmapdevice.cxx
index 4260edb95bdd..01bfe25fb146 100644
--- a/basebmp/source/bitmapdevice.cxx
+++ b/basebmp/source/bitmapdevice.cxx
@@ -1929,7 +1929,6 @@ namespace
BitmapDeviceSharedPtr createBitmapDeviceImplInner( const basegfx::B2IVector& rSize,
bool bTopDown,
Format nScanlineFormat,
- sal_Int32 nScanlineStride,
boost::shared_array< sal_uInt8 > pMem,
PaletteMemorySharedVector pPal,
const basegfx::B2IBox* pSubset,
@@ -1950,6 +1949,8 @@ BitmapDeviceSharedPtr createBitmapDeviceImplInner( const basegfx::B2IVector&
return BitmapDeviceSharedPtr();
}
+ sal_Int32 nScanlineStride = getBitmapDeviceStrideForWidth(nScanlineFormat, rSize.getX());
+
// factor in bottom-up scanline order case
nScanlineStride *= bTopDown ? 1 : -1;
@@ -2112,14 +2113,13 @@ BitmapDeviceSharedPtr createBitmapDeviceImplInner( const basegfx::B2IVector&
BitmapDeviceSharedPtr createBitmapDeviceImpl( const basegfx::B2IVector& rSize,
bool bTopDown,
Format nScanlineFormat,
- sal_Int32 nScanlineStride,
boost::shared_array< sal_uInt8 > pMem,
PaletteMemorySharedVector pPal,
const basegfx::B2IBox* pSubset,
const IBitmapDeviceDamageTrackerSharedPtr& rDamage,
bool bBlack = true)
{
- BitmapDeviceSharedPtr result( createBitmapDeviceImplInner( rSize, bTopDown, nScanlineFormat, nScanlineStride, pMem, pPal, pSubset, rDamage, bBlack ) );
+ BitmapDeviceSharedPtr result( createBitmapDeviceImplInner( rSize, bTopDown, nScanlineFormat, pMem, pPal, pSubset, rDamage, bBlack ) );
#ifdef SAL_LOG_INFO
std::ostringstream subset;
@@ -2145,24 +2145,20 @@ sal_Int32 getBitmapDeviceStrideForWidth(Format nScanlineFormat, sal_Int32 nWidth
// round up to full 8 bit, divide by 8
sal_Int32 nScanlineStride = (nWidth*nBitsPerPixel + 7) >> 3;
- // rounded up to next full power-of-two number of bytes
- const sal_uInt32 bytesPerPixel = nextPow2(
- (bitsPerPixel[nScanlineFormat] + 7) >> 3);
+ // pixman (cairo) and GDI (windows) pad to multiples of 32bits
+ // so do the same to be easily compatible
+ nScanlineStride = (nScanlineStride + 3) & ~0x3;
- // now make nScanlineStride a multiple of bytesPerPixel
- nScanlineStride = (nScanlineStride + bytesPerPixel - 1) / bytesPerPixel * bytesPerPixel;
return nScanlineStride;
}
BitmapDeviceSharedPtr createBitmapDevice( const basegfx::B2IVector& rSize,
bool bTopDown,
- Format nScanlineFormat,
- sal_Int32 nScanlineStride )
+ Format nScanlineFormat )
{
return createBitmapDeviceImpl( rSize,
bTopDown,
nScanlineFormat,
- nScanlineStride,
boost::shared_array< sal_uInt8 >(),
PaletteMemorySharedVector(),
nullptr,
@@ -2172,13 +2168,11 @@ BitmapDeviceSharedPtr createBitmapDevice( const basegfx::B2IVector& rSize,
BitmapDeviceSharedPtr createBitmapDevice( const basegfx::B2IVector& rSize,
bool bTopDown,
Format nScanlineFormat,
- sal_Int32 nScanlineStride,
const PaletteMemorySharedVector& rPalette )
{
return createBitmapDeviceImpl( rSize,
bTopDown,
nScanlineFormat,
- nScanlineStride,
boost::shared_array< sal_uInt8 >(),
rPalette,
nullptr,
@@ -2188,14 +2182,12 @@ BitmapDeviceSharedPtr createBitmapDevice( const basegfx::B2IVector& rSize
BitmapDeviceSharedPtr createBitmapDevice( const basegfx::B2IVector& rSize,
bool bTopDown,
Format nScanlineFormat,
- sal_Int32 nScanlineStride,
const RawMemorySharedArray& rMem,
const PaletteMemorySharedVector& rPalette )
{
return createBitmapDeviceImpl( rSize,
bTopDown,
nScanlineFormat,
- nScanlineStride,
rMem,
rPalette,
nullptr,
@@ -2208,7 +2200,6 @@ BitmapDeviceSharedPtr createClipDevice( const basegfx::B2IVector& rSize )
createBitmapDeviceImpl( rSize,
false, /* bTopDown */
basebmp::Format::OneBitMsbGrey,
- getBitmapDeviceStrideForWidth(basebmp::Format::OneBitMsbGrey, rSize.getX()),
boost::shared_array< sal_uInt8 >(),
PaletteMemorySharedVector(),
nullptr,
@@ -2224,7 +2215,6 @@ BitmapDeviceSharedPtr subsetBitmapDevice( const BitmapDeviceSharedPtr& rProto,
return createBitmapDeviceImpl( rProto->getSize(),
rProto->isTopDown(),
rProto->getScanlineFormat(),
- rProto->getScanlineStride(),
rProto->getBuffer(),
rProto->getPalette(),
&rSubset,
@@ -2237,7 +2227,6 @@ BitmapDeviceSharedPtr cloneBitmapDevice( const basegfx::B2IVector& rSize,
return createBitmapDeviceImpl( rSize,
rProto->isTopDown(),
rProto->getScanlineFormat(),
- rProto->getScanlineStride(),
boost::shared_array< sal_uInt8 >(),
rProto->getPalette(),
nullptr,
diff --git a/basebmp/test/basictest.cxx b/basebmp/test/basictest.cxx
index ebc1fcb479b4..2751bbfd9de9 100644
--- a/basebmp/test/basictest.cxx
+++ b/basebmp/test/basictest.cxx
@@ -111,16 +111,18 @@ public:
basegfx::B2ISize aSize2(aSize);
BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize,
true,
- Format::OneBitMsbPal,
- basebmp::getBitmapDeviceStrideForWidth(Format::OneBitMsbPal, aSize.getX())));
+ Format::OneBitMsbPal ) );
CPPUNIT_ASSERT_EQUAL_MESSAGE("right size",
aSize2, pDevice->getSize() );
CPPUNIT_ASSERT_MESSAGE("Top down format",
pDevice->isTopDown() );
CPPUNIT_ASSERT_EQUAL_MESSAGE("Scanline format",
Format::OneBitMsbPal, pDevice->getScanlineFormat() );
+ sal_Int32 nExpectedStride = (aSize2.getY() + 7)/8;
+ sal_Int32 nAlign = sizeof(sal_uInt32);
+ nExpectedStride = ((nExpectedStride + nAlign-1) / nAlign) * nAlign;
CPPUNIT_ASSERT_EQUAL_MESSAGE("Scanline len",
- (aSize2.getY() + 7)/8, pDevice->getScanlineStride() );
+ nExpectedStride, pDevice->getScanlineStride() );
CPPUNIT_ASSERT_MESSAGE("Palette existence",
pDevice->getPalette() );
CPPUNIT_ASSERT_EQUAL_MESSAGE("Palette entry 0 is black",
@@ -135,8 +137,7 @@ public:
basegfx::B2ISize aSize2(3,3);
BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize,
true,
- Format::OneBitMsbPal,
- basebmp::getBitmapDeviceStrideForWidth(Format::OneBitMsbPal, aSize.getX())));
+ Format::OneBitMsbPal ) );
BitmapDeviceSharedPtr pClone( cloneBitmapDevice(
aSize2,
@@ -151,8 +152,7 @@ public:
const basegfx::B2ISize aSize(64,64);
BitmapDeviceSharedPtr pDevice( createBitmapDevice( aSize,
true,
- Format::OneBitMsbPal,
- basebmp::getBitmapDeviceStrideForWidth(Format::OneBitMsbPal, aSize.getX())));
+ Format::OneBitMsbPal ) );
const basegfx::B2IPoint aPt(3,3);
CPPUNIT_ASSERT_EQUAL_MESSAGE("getPixelData for virgin device",
@@ -199,8 +199,7 @@ public:
{
pDevice = createBitmapDevice( aSize,
true,
- Format::OneBitLsbPal,
- basebmp::getBitmapDeviceStrideForWidth(Format::OneBitLsbPal, aSize.getX()));
+ Format::OneBitLsbPal );
pDevice->setPixel( aPt2, aCol, DrawMode::Paint );
CPPUNIT_ASSERT_EQUAL_MESSAGE("get/setPixel roundtrip #4",
@@ -225,8 +224,7 @@ public:
{
pDevice = createBitmapDevice( aSize,
true,
- Format::EightBitGrey,
- basebmp::getBitmapDeviceStrideForWidth(Format::EightBitGrey, aSize.getX()));
+ Format::EightBitGrey );
const Color aCol4(0x010101);
pDevice->setPixel( aPt, aCol4, DrawMode::Paint );
@@ -248,8 +246,7 @@ public:
{
pDevice = createBitmapDevice( aSize,
true,
- Format::SixteenBitLsbTcMask,
- basebmp::getBitmapDeviceStrideForWidth(Format::SixteenBitLsbTcMask, aSize.getX()));
+ Format::SixteenBitLsbTcMask );
const Color aCol7(0);
pDevice->clear( aCol7 );
@@ -273,8 +270,7 @@ public:
{
pDevice = createBitmapDevice( aSize,
true,
- Format::TwentyFourBitTcMask,
- basebmp::getBitmapDeviceStrideForWidth(Format::TwentyFourBitTcMask, aSize.getX()));
+ Format::TwentyFourBitTcMask );
const Color aCol4(0x01010101);
pDevice->setPixel( aPt, aCol4, DrawMode::Paint );
@@ -303,8 +299,7 @@ public:
{
pDevice = createBitmapDevice( aSize,
true,
- Format::ThirtyTwoBitTcMaskBGRA,
- basebmp::getBitmapDeviceStrideForWidth(Format::ThirtyTwoBitTcMaskBGRA, aSize.getX()));
+ Format::ThirtyTwoBitTcMaskBGRA );
const Color aCol4(0x01010101);
pDevice->setPixel( aPt, aCol4, DrawMode::Paint );
diff --git a/basebmp/test/bmpmasktest.cxx b/basebmp/test/bmpmasktest.cxx
index 7e4440e22eb6..7f7e9130c3d2 100644
--- a/basebmp/test/bmpmasktest.cxx
+++ b/basebmp/test/bmpmasktest.cxx
@@ -91,26 +91,21 @@ public:
const basegfx::B2ISize aSize(10,10);
mpDevice1bpp = createBitmapDevice( aSize,
true,
- Format::OneBitMsbPal,
- basebmp::getBitmapDeviceStrideForWidth(Format::OneBitMsbPal, aSize.getX()));
+ Format::OneBitMsbPal );
mpDevice32bpp = createBitmapDevice( aSize,
true,
- Format::ThirtyTwoBitTcMaskBGRA,
- basebmp::getBitmapDeviceStrideForWidth(Format::ThirtyTwoBitTcMaskBGRA, aSize.getX()));
+ Format::ThirtyTwoBitTcMaskBGRA );
mpMaskBmp1bpp = createBitmapDevice( aSize,
true,
- Format::OneBitMsbGrey,
- basebmp::getBitmapDeviceStrideForWidth(Format::OneBitMsbGrey, aSize.getX()));
+ Format::OneBitMsbGrey );
mpBmp1bpp = createBitmapDevice( aSize,
true,
- Format::OneBitMsbPal,
- basebmp::getBitmapDeviceStrideForWidth(Format::OneBitMsbPal, aSize.getX()));
+ Format::OneBitMsbPal );
mpBmp32bpp = createBitmapDevice( aSize,
true,
- Format::ThirtyTwoBitTcMaskBGRA,
- basebmp::getBitmapDeviceStrideForWidth(Format::ThirtyTwoBitTcMaskBGRA, aSize.getX()));
+ Format::ThirtyTwoBitTcMaskBGRA );
OUString aSvg( "m 0 0h5v10h5v-5h-10z" );
@@ -169,7 +164,6 @@ public:
// nFormat = Format::OneBitMsbGrey; // FIXME - un-comment me to crash hard.
xMask = createBitmapDevice( aSize, false /* bTopDown */,
nFormat,
- basebmp::getBitmapDeviceStrideForWidth( nFormat, aSize.getX()),
PaletteMemorySharedVector(
new std::vector< basebmp::Color >(aDevPal) ) );
// wipe to copy everything.
@@ -183,17 +177,13 @@ public:
DrawMode::Paint );
xBitmap = createBitmapDevice( aSize, false,
- Format::ThirtyTwoBitTcMaskBGRX,
- basebmp::getBitmapDeviceStrideForWidth(
- Format::ThirtyTwoBitTcMaskBGRX, aSize.getX()) );
+ Format::ThirtyTwoBitTcMaskBGRX );
xBitmap->clear(Color(0x80808080));
}
{ // mpOutput & mpBitmap
const basegfx::B2ISize aSize(9, 9);
xOutput = createBitmapDevice( aSize, false,
- Format::ThirtyTwoBitTcMaskBGRX,
- basebmp::getBitmapDeviceStrideForWidth(
- Format::ThirtyTwoBitTcMaskBGRX, aSize.getX()) );
+ Format::ThirtyTwoBitTcMaskBGRX );
xOutput->clear(Color(0xffffffff));
}
diff --git a/basebmp/test/bmptest.cxx b/basebmp/test/bmptest.cxx
index 7a45a49f5ab7..78783d4fe4e3 100644
--- a/basebmp/test/bmptest.cxx
+++ b/basebmp/test/bmptest.cxx
@@ -148,23 +148,19 @@ public:
void setUp() override
{
const basegfx::B2ISize aSize(10,10);
- sal_Int32 nStride = basebmp::getBitmapDeviceStrideForWidth(Format::OneBitMsbPal, aSize.getX());
mpDevice1bpp = createBitmapDevice( aSize,
true,
- Format::OneBitMsbPal, nStride );
- nStride = basebmp::getBitmapDeviceStrideForWidth(Format::ThirtyTwoBitTcMaskBGRA, aSize.getX());
+ Format::OneBitMsbPal );
mpDevice32bpp = createBitmapDevice( aSize,
true,
- Format::ThirtyTwoBitTcMaskBGRA, nStride );
+ Format::ThirtyTwoBitTcMaskBGRA );
- nStride = basebmp::getBitmapDeviceStrideForWidth(Format::OneBitMsbPal, aSize.getX());
mpBmp1bpp = createBitmapDevice( aSize,
true,
- Format::OneBitMsbPal, nStride );
- nStride = basebmp::getBitmapDeviceStrideForWidth(Format::ThirtyTwoBitTcMaskBGRA, aSize.getX());
+ Format::OneBitMsbPal );
mpBmp32bpp = createBitmapDevice( aSize,
true,
- Format::ThirtyTwoBitTcMaskBGRA, nStride );
+ Format::ThirtyTwoBitTcMaskBGRA );
OUString aSvg( "m 0 0h5v10h5v-5h-10z" );
diff --git a/basebmp/test/cliptest.cxx b/basebmp/test/cliptest.cxx
index c1599147dc0a..fba09576a513 100644
--- a/basebmp/test/cliptest.cxx
+++ b/basebmp/test/cliptest.cxx
@@ -154,10 +154,9 @@ private:
void implTestMaskColorClip(const BitmapDeviceSharedPtr& rDevice)
{
- sal_Int32 nStride = basebmp::getBitmapDeviceStrideForWidth(Format::EightBitGrey, rDevice->getSize().getX());
BitmapDeviceSharedPtr pBmp( createBitmapDevice( rDevice->getSize(),
true,
- Format::EightBitGrey, nStride ));
+ Format::EightBitGrey ));
OUString aSvg( "m 0 0h5v10h5v-5h-10z" );
@@ -189,18 +188,15 @@ public:
void setUp() override
{
const basegfx::B2ISize aSize(11,11);
- sal_Int32 nStride = basebmp::getBitmapDeviceStrideForWidth(Format::OneBitMsbGrey, aSize.getX());
mpClipMask = createBitmapDevice( aSize,
true,
- Format::OneBitMsbGrey, nStride );
- nStride = basebmp::getBitmapDeviceStrideForWidth(Format::OneBitMsbPal, aSize.getX());
+ Format::OneBitMsbGrey );
mpDevice1bpp = createBitmapDevice( aSize,
true,
- Format::OneBitMsbPal, nStride );
- nStride = basebmp::getBitmapDeviceStrideForWidth(Format::ThirtyTwoBitTcMaskBGRA, aSize.getX());
+ Format::OneBitMsbPal );
mpDevice32bpp = createBitmapDevice( aSize,
true,
- Format::ThirtyTwoBitTcMaskBGRA, nStride );
+ Format::ThirtyTwoBitTcMaskBGRA );
OUString aSvg( "m 0 0 h5 l5 5 v5 h-5 l-5-5 z" );
basegfx::B2DPolyPolygon aPoly;
diff --git a/basebmp/test/filltest.cxx b/basebmp/test/filltest.cxx
index 8f2ec81c1f15..cee7de505f9b 100644
--- a/basebmp/test/filltest.cxx
+++ b/basebmp/test/filltest.cxx
@@ -211,12 +211,10 @@ public:
const basegfx::B2ISize aSize(11,11);
mpDevice1bpp = createBitmapDevice( aSize,
true,
- Format::OneBitMsbPal,
- basebmp::getBitmapDeviceStrideForWidth(Format::OneBitMsbPal, aSize.getX()));
+ Format::OneBitMsbPal );
mpDevice32bpp = createBitmapDevice( aSize,
true,
- Format::ThirtyTwoBitTcMaskBGRA,
- basebmp::getBitmapDeviceStrideForWidth(Format::ThirtyTwoBitTcMaskBGRA, aSize.getX()));
+ Format::ThirtyTwoBitTcMaskBGRA );
}
void testRectFill()
diff --git a/basebmp/test/linetest.cxx b/basebmp/test/linetest.cxx
index c83956815312..aa49d91a08b4 100644
--- a/basebmp/test/linetest.cxx
+++ b/basebmp/test/linetest.cxx
@@ -151,12 +151,10 @@ public:
const basegfx::B2ISize aSize(11,11);
mpDevice1bpp = createBitmapDevice( aSize,
true,
- Format::OneBitMsbPal,
- basebmp::getBitmapDeviceStrideForWidth(Format::OneBitMsbPal, aSize.getX()) );
+ Format::OneBitMsbPal );
mpDevice32bpp = createBitmapDevice( aSize,
true,
- Format::ThirtyTwoBitTcMaskBGRA,
- basebmp::getBitmapDeviceStrideForWidth(Format::ThirtyTwoBitTcMaskBGRA, aSize.getX()) );
+ Format::ThirtyTwoBitTcMaskBGRA );
}
void testCornerCases()
@@ -165,8 +163,7 @@ public:
BitmapDeviceSharedPtr pDevice = createBitmapDevice(
aSize,
true,
- Format::OneBitMsbPal,
- basebmp::getBitmapDeviceStrideForWidth(Format::OneBitMsbPal, aSize.getX()) );
+ Format::OneBitMsbPal );
const basegfx::B2IPoint aPt1(0,0);
const basegfx::B2IPoint aPt2(10,10);
@@ -182,8 +179,7 @@ public:
pDevice = createBitmapDevice(
aSize2,
true,
- Format::OneBitMsbPal,
- basebmp::getBitmapDeviceStrideForWidth(Format::OneBitMsbPal, aSize.getX()));
+ Format::OneBitMsbPal );
CPPUNIT_ASSERT_MESSAGE("only pixel cleared",
pDevice->getPixelData(aPt1) == 0);
diff --git a/basebmp/test/masktest.cxx b/basebmp/test/masktest.cxx
index b1556f0e12a5..433a08fe46f8 100644
--- a/basebmp/test/masktest.cxx
+++ b/basebmp/test/masktest.cxx
@@ -104,17 +104,14 @@ public:
const basegfx::B2ISize aSize(10,10);
mpDevice1bpp = createBitmapDevice( aSize,
true,
- Format::OneBitMsbPal,
- basebmp::getBitmapDeviceStrideForWidth(Format::OneBitMsbPal, aSize.getX()) );
+ Format::OneBitMsbPal );
mpDevice32bpp = createBitmapDevice( aSize,
true,
- Format::ThirtyTwoBitTcMaskBGRA,
- basebmp::getBitmapDeviceStrideForWidth(Format::ThirtyTwoBitTcMaskBGRA, aSize.getX()) );
+ Format::ThirtyTwoBitTcMaskBGRA );
mpMask = createBitmapDevice( aSize,
true,
- Format::EightBitGrey,
- basebmp::getBitmapDeviceStrideForWidth(Format::EightBitGrey, aSize.getX()) );
+ Format::EightBitGrey );
OUString aSvg( "m 0 0h5v10h5v-5h-10z" );
diff --git a/basebmp/test/polytest.cxx b/basebmp/test/polytest.cxx
index d027e8ee2501..e0268612626e 100644
--- a/basebmp/test/polytest.cxx
+++ b/basebmp/test/polytest.cxx
@@ -296,12 +296,10 @@ public:
const basegfx::B2ISize aSize(10,10);
mpDevice1bpp = createBitmapDevice( aSize,
true,
- Format::OneBitMsbPal,
- basebmp::getBitmapDeviceStrideForWidth(Format::OneBitMsbPal, aSize.getX()));
+ Format::OneBitMsbPal );
mpDevice32bpp = createBitmapDevice( aSize,
true,
- Format::ThirtyTwoBitTcMaskBGRA,
- basebmp::getBitmapDeviceStrideForWidth(Format::ThirtyTwoBitTcMaskBGRA, aSize.getX()));
+ Format::ThirtyTwoBitTcMaskBGRA );
}
void testEmpty()