summaryrefslogtreecommitdiff
path: root/vcl/source/bitmap
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2022-01-17 21:47:48 +0100
committerStephan Bergmann <sbergman@redhat.com>2022-01-17 22:38:13 +0100
commit5db574727f4564238a54159a1a0673eaa2884b69 (patch)
tree8807c2002503443bd2d3043efcb89c76b856e63a /vcl/source/bitmap
parent911b10395433d1e3c11e92ef7b2720bf2dc2e3d8 (diff)
Avoid -Werror=dangling-pointer=
> vcl/source/bitmap/Octree.cxx: In constructor ‘Octree::Octree(const BitmapReadAccess&, sal_uLong)’: > vcl/source/bitmap/Octree.cxx:69:17: error: storing the address of local variable ‘aColor’ in ‘*this.Octree::mpColor’ [-Werror=dangling-pointer=] > 69 | mpColor = &aColor; > | ~~~~~~~~^~~~~~~~~ > vcl/source/bitmap/Octree.cxx:67:21: note: ‘aColor’ declared here > 67 | BitmapColor aColor; > | ^~~~~~ > vcl/source/bitmap/Octree.cxx:67:21: note: ‘<unknown>’ declared here (new with GCC 12) Change-Id: I5b1ffa15b92f2c41dbe51dfa843eb6bab3a4b449 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/128517 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'vcl/source/bitmap')
-rw-r--r--vcl/source/bitmap/Octree.cxx40
1 files changed, 16 insertions, 24 deletions
diff --git a/vcl/source/bitmap/Octree.cxx b/vcl/source/bitmap/Octree.cxx
index fab0c8374ca8..98ad8c9fcf5d 100644
--- a/vcl/source/bitmap/Octree.cxx
+++ b/vcl/source/bitmap/Octree.cxx
@@ -34,7 +34,6 @@ Octree::Octree(const BitmapReadAccess& rReadAcc, sal_uLong nColors)
: mnLeafCount(0)
, mnLevel(0)
, mpReduce(OCTREE_BITS + 1, nullptr)
- , mpColor(nullptr)
, mnPalIndex(0)
{
const BitmapReadAccess* pAccess = &rReadAcc;
@@ -53,9 +52,8 @@ Octree::Octree(const BitmapReadAccess& rReadAcc, sal_uLong nColors)
Scanline pScanline = pAccess->GetScanline(nY);
for (tools::Long nX = 0; nX < nWidth; nX++)
{
- mpColor = &pAccess->GetPaletteColor(pAccess->GetIndexFromData(pScanline, nX));
mnLevel = 0;
- add(pTree);
+ add(pTree, pAccess->GetPaletteColor(pAccess->GetIndexFromData(pScanline, nX)));
while (mnLeafCount > nMax)
reduce();
@@ -64,18 +62,13 @@ Octree::Octree(const BitmapReadAccess& rReadAcc, sal_uLong nColors)
}
else
{
- BitmapColor aColor;
-
- mpColor = &aColor;
-
for (tools::Long nY = 0; nY < nHeight; nY++)
{
Scanline pScanline = pAccess->GetScanline(nY);
for (tools::Long nX = 0; nX < nWidth; nX++)
{
- aColor = pAccess->GetPixelFromData(pScanline, nX);
mnLevel = 0;
- add(pTree);
+ add(pTree, pAccess->GetPixelFromData(pScanline, nX));
while (mnLeafCount > nMax)
reduce();
@@ -86,7 +79,7 @@ Octree::Octree(const BitmapReadAccess& rReadAcc, sal_uLong nColors)
Octree::~Octree() {}
-void Octree::add(std::unique_ptr<OctreeNode>& rpNode)
+void Octree::add(std::unique_ptr<OctreeNode>& rpNode, BitmapColor const& color)
{
// possibly generate new nodes
if (!rpNode)
@@ -106,20 +99,20 @@ void Octree::add(std::unique_ptr<OctreeNode>& rpNode)
if (rpNode->bLeaf)
{
rpNode->nCount++;
- rpNode->nRed += mpColor->GetRed();
- rpNode->nGreen += mpColor->GetGreen();
- rpNode->nBlue += mpColor->GetBlue();
+ rpNode->nRed += color.GetRed();
+ rpNode->nGreen += color.GetGreen();
+ rpNode->nBlue += color.GetBlue();
}
else
{
const sal_uLong nShift = 7 - mnLevel;
const sal_uInt8 cMask = 0x80 >> mnLevel;
- const sal_uLong nIndex = (((mpColor->GetRed() & cMask) >> nShift) << 2)
- | (((mpColor->GetGreen() & cMask) >> nShift) << 1)
- | ((mpColor->GetBlue() & cMask) >> nShift);
+ const sal_uLong nIndex = (((color.GetRed() & cMask) >> nShift) << 2)
+ | (((color.GetGreen() & cMask) >> nShift) << 1)
+ | ((color.GetBlue() & cMask) >> nShift);
mnLevel++;
- add(rpNode->pChild[nIndex]);
+ add(rpNode->pChild[nIndex], color);
}
}
@@ -184,7 +177,7 @@ void Octree::CreatePalette(OctreeNode* pNode)
}
}
-void Octree::GetPalIndex(const OctreeNode* pNode)
+void Octree::GetPalIndex(const OctreeNode* pNode, BitmapColor const& color)
{
if (pNode->bLeaf)
mnPalIndex = pNode->nPalIndex;
@@ -193,11 +186,11 @@ void Octree::GetPalIndex(const OctreeNode* pNode)
const sal_uLong nShift = 7 - mnLevel;
const sal_uInt8 cMask = 0x80 >> mnLevel;
mnLevel++;
- const sal_uLong nIndex = (((mpColor->GetRed() & cMask) >> nShift) << 2)
- | (((mpColor->GetGreen() & cMask) >> nShift) << 1)
- | ((mpColor->GetBlue() & cMask) >> nShift);
+ const sal_uLong nIndex = (((color.GetRed() & cMask) >> nShift) << 2)
+ | (((color.GetGreen() & cMask) >> nShift) << 1)
+ | ((color.GetBlue() & cMask) >> nShift);
- GetPalIndex(pNode->pChild[nIndex].get());
+ GetPalIndex(pNode->pChild[nIndex].get(), color);
}
}
@@ -211,10 +204,9 @@ const BitmapPalette& Octree::GetPalette()
sal_uInt16 Octree::GetBestPaletteIndex(const BitmapColor& rColor)
{
- mpColor = &rColor;
mnPalIndex = 65535;
mnLevel = 0;
- GetPalIndex(pTree.get());
+ GetPalIndex(pTree.get(), rColor);
return mnPalIndex;
}