no need to call Width/Height on every iteration of loop

Change-Id: If4615e004ad78936cfbafcad66e78dd66051d32f
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184664
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin
2025-04-26 19:01:07 +02:00
parent 59f8fd6a5c
commit 07a3dd72f3
9 changed files with 31 additions and 31 deletions
+2 -2
View File
@@ -1004,9 +1004,9 @@ namespace emfio
if ( !aBmp.IsEmpty() )
{
BitmapScopedReadAccess pBmp(aBmp);
for ( tools::Long y = 0; y < pBmp->Height(); y++ )
for ( tools::Long y = 0, nHeight = pBmp->Height(); y < nHeight; y++ )
{
for ( tools::Long x = 0; x < pBmp->Width(); x++ )
for ( tools::Long x = 0, nWidth = pBmp->Width(); x < nWidth; x++ )
{
const BitmapColor aColor( pBmp->GetColor( y, x ) );
+2 -2
View File
@@ -1304,11 +1304,11 @@ void BitmapEx::ChangeColorAlpha( sal_uInt8 cIndexFrom, sal_Int8 nAlphaTo )
if ( !(pReadAccess.get() && pAlphaWriteAccess.get()) )
return;
for ( tools::Long nY = 0; nY < pReadAccess->Height(); nY++ )
for ( tools::Long nY = 0, nHeight = pReadAccess->Height(); nY < nHeight; nY++ )
{
Scanline pScanline = pAlphaWriteAccess->GetScanline( nY );
Scanline pScanlineRead = pReadAccess->GetScanline( nY );
for ( tools::Long nX = 0; nX < pReadAccess->Width(); nX++ )
for ( tools::Long nX = 0, nWidth = pReadAccess->Width(); nX < nWidth; nX++ )
{
const sal_uInt8 cIndex = pReadAccess->GetPixelFromData( pScanlineRead, nX ).GetIndex();
if ( cIndex == cIndexFrom )
+2 -2
View File
@@ -20,11 +20,11 @@ BitmapEx BitmapShadowFilter::execute(BitmapEx const& rBitmapEx) const
if (!pWriteAccess)
return rBitmapEx;
for (sal_Int32 y(0); y < sal_Int32(pWriteAccess->Height()); y++)
for (sal_Int32 y(0), nHeight(pWriteAccess->Height()); y < nHeight; y++)
{
Scanline pScanline = pWriteAccess->GetScanline(y);
for (sal_Int32 x(0); x < sal_Int32(pWriteAccess->Width()); x++)
for (sal_Int32 x(0), nWidth(pWriteAccess->Width()); x < nWidth; x++)
{
const BitmapColor aColor = pWriteAccess->GetColor(y, x);
sal_uInt16 nLuminance(static_cast<sal_uInt16>(aColor.GetLuminance()) + 1);
+8 -8
View File
@@ -299,12 +299,12 @@ void fillWithData(sal_uInt8* pData, BitmapEx const& rBitmapEx)
sal_uInt8* p = pData;
for (tools::Long y = 0; y < aReadAccessBitmap->Height(); ++y)
for (tools::Long y = 0, nHeight = aReadAccessBitmap->Height(); y < nHeight; ++y)
{
Scanline dataBitmap = aReadAccessBitmap->GetScanline(y);
Scanline dataAlpha = aReadAccessAlpha ? aReadAccessAlpha->GetScanline(y) : nullptr;
for (tools::Long x = 0; x < aReadAccessBitmap->Width(); ++x)
for (tools::Long x = 0, nWidth = aReadAccessBitmap->Width(); x < nWidth; ++x)
{
BitmapColor aColor = aReadAccessBitmap->GetPixelFromData(dataBitmap, x);
sal_uInt8 aAlpha = dataAlpha ? aReadAccessAlpha->GetPixelFromData(dataAlpha, x).GetBlue() : 255;
@@ -564,10 +564,10 @@ void DrawAlphaBitmapAndAlphaGradient(BitmapEx & rBitmapEx, bool bFixedTransparen
{
const double fOpNew(1.0 - fTransparence);
for(tools::Long y(0); y < pOld->Height(); y++)
for(tools::Long y(0),nHeight(pOld->Height()); y < nHeight; y++)
{
Scanline pScanline = pOld->GetScanline( y );
for(tools::Long x(0); x < pOld->Width(); x++)
for(tools::Long x(0),nWidth(pOld->Width()); x < nWidth; x++)
{
const double fOpOld(pOld->GetIndexFromData(pScanline, x) * fFactor);
const sal_uInt8 aCol(basegfx::fround((fOpOld * fOpNew) * 255.0));
@@ -585,10 +585,10 @@ void DrawAlphaBitmapAndAlphaGradient(BitmapEx & rBitmapEx, bool bFixedTransparen
assert(pOld->Width() == pNew->Width() && pOld->Height() == pNew->Height() &&
"Alpha masks have different sizes (!)");
for(tools::Long y(0); y < pOld->Height(); y++)
for(tools::Long y(0),nHeight(pOld->Height()); y < nHeight; y++)
{
Scanline pScanline = pOld->GetScanline( y );
for(tools::Long x(0); x < pOld->Width(); x++)
for(tools::Long x(0),nWidth(pOld->Width()); x < nWidth; x++)
{
const double fOpOld(pOld->GetIndexFromData(pScanline, x) * fFactor);
const double fOpNew(pNew->GetIndexFromData(pScanline, x) * fFactor);
@@ -1122,8 +1122,8 @@ void CanvasCairoExtractBitmapData( BitmapEx const & aBmpEx, const Bitmap & aBitm
BitmapScopedReadAccess access(aBitmap);
o_rBack = access->GetColor(0,0);
bool foundSecondColor = false;;
for(tools::Long y = 0; y < access->Height(); ++y)
for(tools::Long x = 0; x < access->Width(); ++x)
for(tools::Long y = 0, nHeight = access->Height(); y < nHeight; ++y)
for(tools::Long x = 0, nWidth = access->Width(); x < nWidth; ++x)
{
if(!foundSecondColor)
{
+1 -1
View File
@@ -1358,7 +1358,7 @@ void Bitmap::AdaptBitCount(Bitmap& rNew) const
static void shiftColors(sal_Int32* pColorArray, const BitmapScopedReadAccess& pReadAcc)
{
Scanline pScanlineRead = pReadAcc->GetScanline(0); // Why always 0?
for (tools::Long n = 0; n < pReadAcc->Width(); ++n)
for (tools::Long n = 0, nWidth = pReadAcc->Width(); n < nWidth; ++n)
{
const BitmapColor aColor = pReadAcc->GetColorFromData(pScanlineRead, n);
*pColorArray++ = static_cast<sal_Int32>(aColor.GetBlue()) << 12;
+1 -1
View File
@@ -220,7 +220,7 @@ bool JPEGWriter::Write( const Graphic& rGraphic )
bool bIsGrey = true;
tools::Long nWidth = mpReadAccess->Width();
for ( tools::Long nY = 0; bIsGrey && ( nY < mpReadAccess->Height() ); nY++ )
for ( tools::Long nY = 0, nHeight = mpReadAccess->Height(); bIsGrey && ( nY < nHeight ); nY++ )
{
BitmapColor aColor;
Scanline pScanlineRead = mpReadAccess->GetScanline( nY );
+7 -7
View File
@@ -222,7 +222,7 @@ static bool readWebp(SvStream& stream, Graphic& graphic)
std::vector<char> tmp;
const sal_uInt32 lineSize = access->GetScanlineSize();
tmp.resize(lineSize);
for (tools::Long y = 0; y < access->Height() / 2; ++y)
for (tools::Long y = 0, nHeight = access->Height(); y < nHeight / 2; ++y)
{
tools::Long otherY = access->Height() - 1 - y;
memcpy(tmp.data(), access->GetScanline(y), lineSize);
@@ -236,12 +236,12 @@ static bool readWebp(SvStream& stream, Graphic& graphic)
{
// Split to normal and alpha bitmaps.
BitmapScopedWriteAccess accessAlpha(bitmapAlpha);
for (tools::Long y = 0; y < access->Height(); ++y)
for (tools::Long y = 0, nHeight = access->Height(); y < nHeight; ++y)
{
const unsigned char* src = tmpRgbaData.data() + width * 4 * y;
unsigned char* dstB = access->GetScanline(y);
unsigned char* dstA = accessAlpha->GetScanline(y);
for (tools::Long x = 0; x < access->Width(); ++x)
for (tools::Long x = 0, nWidth = access->Width(); x < nWidth; ++x)
{
memcpy(dstB, src, 3);
*dstA = *(src + 3);
@@ -254,10 +254,10 @@ static bool readWebp(SvStream& stream, Graphic& graphic)
}
case PixelMode::SetPixel:
{
for (tools::Long y = 0; y < access->Height(); ++y)
for (tools::Long y = 0, nHeight = access->Height(); y < nHeight; ++y)
{
const unsigned char* src = tmpRgbaData.data() + width * 4 * y;
for (tools::Long x = 0; x < access->Width(); ++x)
for (tools::Long x = 0, nWidth = access->Width(); x < nWidth; ++x)
{
sal_uInt8 r = src[0];
sal_uInt8 g = src[1];
@@ -270,10 +270,10 @@ static bool readWebp(SvStream& stream, Graphic& graphic)
if (!bitmapAlpha.IsEmpty())
{
BitmapScopedWriteAccess accessAlpha(bitmapAlpha);
for (tools::Long y = 0; y < accessAlpha->Height(); ++y)
for (tools::Long y = 0, nHeight = accessAlpha->Height(); y < nHeight; ++y)
{
const unsigned char* src = tmpRgbaData.data() + width * 4 * y;
for (tools::Long x = 0; x < accessAlpha->Width(); ++x)
for (tools::Long x = 0, nWidth = accessAlpha->Width(); x < nWidth; ++x)
{
sal_uInt8 a = src[3];
accessAlpha->SetPixelIndex(y, x, a);
+4 -4
View File
@@ -140,12 +140,12 @@ static bool writeWebp(SvStream& rStream, const BitmapEx& bitmapEx, bool lossless
data.resize(width * height * bpp);
if (!bitmapAlpha.IsEmpty())
{
for (tools::Long y = 0; y < access->Height(); ++y)
for (tools::Long y = 0, nHeight = access->Height(); y < nHeight; ++y)
{
unsigned char* dst = data.data() + width * bpp * y;
const sal_uInt8* srcB = access->GetScanline(y);
const sal_uInt8* srcA = accessAlpha->GetScanline(y);
for (tools::Long x = 0; x < access->Width(); ++x)
for (tools::Long x = 0, nWidth = access->Width(); x < nWidth; ++x)
{
BitmapColor color = access->GetPixelFromData(srcB, x);
BitmapColor alpha = accessAlpha->GetPixelFromData(srcA, x);
@@ -160,11 +160,11 @@ static bool writeWebp(SvStream& rStream, const BitmapEx& bitmapEx, bool lossless
}
else
{
for (tools::Long y = 0; y < access->Height(); ++y)
for (tools::Long y = 0, nHeight = access->Height(); y < nHeight; ++y)
{
unsigned char* dst = data.data() + width * bpp * y;
const sal_uInt8* src = access->GetScanline(y);
for (tools::Long x = 0; x < access->Width(); ++x)
for (tools::Long x = 0, nWidth = access->Width(); x < nWidth; ++x)
{
Color color = access->GetPixelFromData(src, x);
dst[0] = color.GetRed();
+4 -4
View File
@@ -9748,7 +9748,7 @@ bool PDFWriterImpl::writeBitmapObject( const BitmapEmit& rObject )
//With PDF bitmaps, each row is padded to a BYTE boundary (multiple of 8 bits).
const int nScanLineBytes = ((pAccess->GetBitCount() * pAccess->Width()) + 7U) / 8U;
for( tools::Long i = 0; i < pAccess->Height(); i++ )
for( tools::Long i = 0, nHeight = pAccess->Height(); i < nHeight; i++ )
{
if (!writeBufferBytes(pAccess->GetScanline(i), nScanLineBytes))
return false;
@@ -9758,9 +9758,9 @@ bool PDFWriterImpl::writeBitmapObject( const BitmapEmit& rObject )
{
const int nScanLineBytes = pAccess->Width()*3;
std::unique_ptr<sal_uInt8[]> xCol(new sal_uInt8[nScanLineBytes]);
for( tools::Long y = 0; y < pAccess->Height(); y++ )
for( tools::Long y = 0, nHeight = pAccess->Height(); y < nHeight; y++ )
{
for( tools::Long x = 0; x < pAccess->Width(); x++ )
for( tools::Long x = 0, nWidth = pAccess->Width(); x < nWidth; x++ )
{
BitmapColor aColor = pAccess->GetColor( y, x );
xCol[3*x+0] = aColor.GetRed();
@@ -9856,7 +9856,7 @@ bool PDFWriterImpl::writeBitmapMaskObject( sal_Int32 nMaskObject, const AlphaMas
const int nScanLineBytes = ((pAccess->GetBitCount() * pAccess->Width()) + 7U) / 8U;
// we have alpha, but we want to output transparency, so we need to invert the data
std::unique_ptr<sal_uInt8[]> pInvertedBytes = std::make_unique<sal_uInt8[]>(nScanLineBytes);
for( tools::Long i = 0; i < pAccess->Height(); i++ )
for( tools::Long i = 0, nHeight = pAccess->Height(); i < nHeight; i++ )
{
const Scanline pScanline = pAccess->GetScanline(i);
std::copy(pScanline, pScanline + nScanLineBytes, pInvertedBytes.get());