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>
This commit is contained in:
parent
911b103954
commit
5db574727f
2 changed files with 18 additions and 27 deletions
|
@ -42,9 +42,9 @@ class VCL_PLUGIN_PUBLIC Octree
|
|||
{
|
||||
private:
|
||||
void CreatePalette(OctreeNode* pNode);
|
||||
void GetPalIndex(const OctreeNode* pNode);
|
||||
void GetPalIndex(const OctreeNode* pNode, BitmapColor const& color);
|
||||
|
||||
SAL_DLLPRIVATE void add(std::unique_ptr<OctreeNode>& rpNode);
|
||||
SAL_DLLPRIVATE void add(std::unique_ptr<OctreeNode>& rpNode, BitmapColor const& color);
|
||||
SAL_DLLPRIVATE void reduce();
|
||||
|
||||
BitmapPalette maPalette;
|
||||
|
@ -52,7 +52,6 @@ private:
|
|||
sal_uLong mnLevel;
|
||||
std::unique_ptr<OctreeNode> pTree;
|
||||
std::vector<OctreeNode*> mpReduce;
|
||||
BitmapColor const* mpColor;
|
||||
sal_uInt16 mnPalIndex;
|
||||
|
||||
public:
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue