just calculate the scanline positions
rather than generating a big offset table to dramatically reduce the amount of memory loading graphics takes Change-Id: I8a4b1dc5cbcb686d6b8570f2eeef61ee0fe25515 Reviewed-on: https://gerrit.libreoffice.org/35005 Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
This commit is contained in:
@@ -115,7 +115,6 @@ protected:
|
||||
FncSetPixel mFncSetPixel;
|
||||
|
||||
SAL_DLLPRIVATE void ImplInitScanBuffer( Bitmap& rBitmap );
|
||||
SAL_DLLPRIVATE void ImplClearScanBuffer();
|
||||
SAL_DLLPRIVATE bool ImplSetAccessPointers( ScanlineFormat nFormat );
|
||||
|
||||
public:
|
||||
@@ -303,13 +302,11 @@ inline const BitmapColor& BitmapInfoAccess::GetPaletteColor( sal_uInt16 nColor )
|
||||
return mpBuffer->maPalette[nColor];
|
||||
}
|
||||
|
||||
|
||||
inline const BitmapColor& BitmapInfoAccess::GetBestPaletteColor(const BitmapColor& rBitmapColor) const
|
||||
{
|
||||
return GetPaletteColor(GetBestPaletteIndex(rBitmapColor));
|
||||
}
|
||||
|
||||
|
||||
inline ColorMask& BitmapInfoAccess::GetColorMask() const
|
||||
{
|
||||
assert(mpBuffer && "Access is not valid!");
|
||||
@@ -317,7 +314,6 @@ inline ColorMask& BitmapInfoAccess::GetColorMask() const
|
||||
return mpBuffer->maColorMask;
|
||||
}
|
||||
|
||||
|
||||
inline Scanline BitmapReadAccess::GetBuffer() const
|
||||
{
|
||||
assert(mpBuffer && "Access is not valid!");
|
||||
@@ -325,32 +321,32 @@ inline Scanline BitmapReadAccess::GetBuffer() const
|
||||
return mpBuffer ? mpBuffer->mpBits : nullptr;
|
||||
}
|
||||
|
||||
|
||||
inline Scanline BitmapReadAccess::GetScanline(long nY) const
|
||||
{
|
||||
assert(mpBuffer && mpScanBuf && "Access is not valid!");
|
||||
assert(mpBuffer && "Access is not valid!");
|
||||
assert(nY < mpBuffer->mnHeight && "y-coordinate out of range!");
|
||||
|
||||
return mpScanBuf[nY];
|
||||
if (mpBuffer->mnFormat & ScanlineFormat::TopDown)
|
||||
{
|
||||
return mpBuffer->mpBits + (nY * mpBuffer->mnScanlineSize);
|
||||
}
|
||||
return mpBuffer->mpBits + ((mpBuffer->mnHeight - 1 - nY) * mpBuffer->mnScanlineSize);
|
||||
}
|
||||
|
||||
|
||||
inline BitmapColor BitmapReadAccess::GetPixel(long nY, long nX) const
|
||||
{
|
||||
assert(mpBuffer && mpScanBuf && "Access is not valid!");
|
||||
assert(mpBuffer && "Access is not valid!");
|
||||
assert(nX < mpBuffer->mnWidth && "x-coordinate out of range!");
|
||||
assert(nY < mpBuffer->mnHeight && "y-coordinate out of range!");
|
||||
|
||||
return mFncGetPixel(mpScanBuf[nY], nX, maColorMask );
|
||||
return mFncGetPixel(GetScanline(nY), nX, maColorMask );
|
||||
}
|
||||
|
||||
|
||||
inline sal_uInt8 BitmapReadAccess::GetPixelIndex(long nY, long nX) const
|
||||
{
|
||||
return GetPixel(nY, nX).GetBlueOrIndex();
|
||||
}
|
||||
|
||||
|
||||
inline BitmapColor BitmapReadAccess::GetPixelFromData(const sal_uInt8* pData, long nX) const
|
||||
{
|
||||
assert(pData && "Access is not valid!");
|
||||
@@ -358,7 +354,6 @@ inline BitmapColor BitmapReadAccess::GetPixelFromData(const sal_uInt8* pData, lo
|
||||
return mFncGetPixel( pData, nX, maColorMask );
|
||||
}
|
||||
|
||||
|
||||
inline void BitmapReadAccess::SetPixelOnData(sal_uInt8* pData, long nX, const BitmapColor& rBitmapColor)
|
||||
{
|
||||
assert(pData && "Access is not valid!");
|
||||
@@ -413,7 +408,7 @@ inline void BitmapWriteAccess::SetPixel(long nY, long nX, const BitmapColor& rBi
|
||||
assert(nX < mpBuffer->mnWidth && "x-coordinate out of range!");
|
||||
assert(nY < mpBuffer->mnHeight && "y-coordinate out of range!");
|
||||
|
||||
mFncSetPixel(mpScanBuf[nY], nX, rBitmapColor, maColorMask);
|
||||
mFncSetPixel(GetScanline(nY), nX, rBitmapColor, maColorMask);
|
||||
}
|
||||
|
||||
|
||||
|
@@ -102,7 +102,6 @@ sal_uInt16 BitmapInfoAccess::GetBestPaletteIndex( const BitmapColor& rBitmapColo
|
||||
|
||||
BitmapReadAccess::BitmapReadAccess( Bitmap& rBitmap, BitmapAccessMode nMode ) :
|
||||
BitmapInfoAccess( rBitmap, nMode ),
|
||||
mpScanBuf ( nullptr ),
|
||||
mFncGetPixel ( nullptr ),
|
||||
mFncSetPixel ( nullptr )
|
||||
{
|
||||
@@ -111,7 +110,6 @@ BitmapReadAccess::BitmapReadAccess( Bitmap& rBitmap, BitmapAccessMode nMode ) :
|
||||
|
||||
BitmapReadAccess::BitmapReadAccess( Bitmap& rBitmap ) :
|
||||
BitmapInfoAccess( rBitmap, BitmapAccessMode::Read ),
|
||||
mpScanBuf ( nullptr ),
|
||||
mFncGetPixel ( nullptr ),
|
||||
mFncSetPixel ( nullptr )
|
||||
{
|
||||
@@ -120,7 +118,6 @@ BitmapReadAccess::BitmapReadAccess( Bitmap& rBitmap ) :
|
||||
|
||||
BitmapReadAccess::~BitmapReadAccess()
|
||||
{
|
||||
ImplClearScanBuffer();
|
||||
}
|
||||
|
||||
void BitmapReadAccess::ImplInitScanBuffer( Bitmap& rBitmap )
|
||||
@@ -134,45 +131,15 @@ void BitmapReadAccess::ImplInitScanBuffer( Bitmap& rBitmap )
|
||||
|
||||
maColorMask = mpBuffer->maColorMask;
|
||||
|
||||
bool bOk(true);
|
||||
const long nHeight = mpBuffer->mnHeight;
|
||||
Scanline pTmpLine = mpBuffer->mpBits;
|
||||
try
|
||||
{
|
||||
mpScanBuf = new Scanline[ nHeight ];
|
||||
if( mpBuffer->mnFormat & ScanlineFormat::TopDown )
|
||||
{
|
||||
for( long nY = 0; nY < nHeight; nY++, pTmpLine += mpBuffer->mnScanlineSize )
|
||||
mpScanBuf[ nY ] = pTmpLine;
|
||||
}
|
||||
else
|
||||
{
|
||||
for( long nY = nHeight - 1; nY >= 0; nY--, pTmpLine += mpBuffer->mnScanlineSize )
|
||||
mpScanBuf[ nY ] = pTmpLine;
|
||||
}
|
||||
bOk = ImplSetAccessPointers(RemoveScanline(mpBuffer->mnFormat));
|
||||
}
|
||||
catch (const std::bad_alloc&)
|
||||
{
|
||||
bOk = false;
|
||||
}
|
||||
bool bOk = ImplSetAccessPointers(RemoveScanline(mpBuffer->mnFormat));
|
||||
|
||||
if (!bOk)
|
||||
{
|
||||
delete[] mpScanBuf;
|
||||
mpScanBuf = nullptr;
|
||||
|
||||
xImpBmp->ImplReleaseBuffer( mpBuffer, mnAccessMode );
|
||||
mpBuffer = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
void BitmapReadAccess::ImplClearScanBuffer()
|
||||
{
|
||||
delete[] mpScanBuf;
|
||||
mpScanBuf = nullptr;
|
||||
}
|
||||
|
||||
bool BitmapReadAccess::ImplSetAccessPointers( ScanlineFormat nFormat )
|
||||
{
|
||||
bool bRet = true;
|
||||
@@ -405,7 +372,7 @@ void BitmapWriteAccess::CopyScanline( long nY, const BitmapReadAccess& rReadAcc
|
||||
if( ( GetScanlineFormat() == rReadAcc.GetScanlineFormat() ) &&
|
||||
( GetScanlineSize() >= rReadAcc.GetScanlineSize() ) )
|
||||
{
|
||||
memcpy( mpScanBuf[ nY ], rReadAcc.GetScanline( nY ), rReadAcc.GetScanlineSize() );
|
||||
memcpy(GetScanline(nY), rReadAcc.GetScanline(nY), rReadAcc.GetScanlineSize());
|
||||
}
|
||||
else
|
||||
// TODO: use fastbmp infrastructure
|
||||
@@ -428,7 +395,7 @@ void BitmapWriteAccess::CopyScanline( long nY, ConstScanline aSrcScanline,
|
||||
if( nCount )
|
||||
{
|
||||
if( GetScanlineFormat() == RemoveScanline( nSrcScanlineFormat ) )
|
||||
memcpy( mpScanBuf[ nY ], aSrcScanline, nCount );
|
||||
memcpy(GetScanline(nY), aSrcScanline, nCount);
|
||||
else
|
||||
{
|
||||
DBG_ASSERT( nFormat != ScanlineFormat::N8BitTcMask &&
|
||||
|
Reference in New Issue
Block a user