diff options
author | Tomaž Vajngerl <tomaz.vajngerl@collabora.co.uk> | 2019-04-14 15:34:03 +0900 |
---|---|---|
committer | Tomaž Vajngerl <quikee@gmail.com> | 2019-04-14 14:19:03 +0200 |
commit | f441b7c74d9074b0b29eabfbf35f47a1df7cea9c (patch) | |
tree | 17a65e3051b454490fca7c110d740def4c7fb8e4 /vcl | |
parent | 8db9363c8ef6138d2420366cc4f42ca1d662bdd7 (diff) |
put Octree classes out of formatting blacklist
Need to do this so it is at least somewhat formatted sanely before
refactoring to the data structures.
Change-Id: I136a539a190c2f53aa05cc9a26872a5606f81888
Reviewed-on: https://gerrit.libreoffice.org/70727
Tested-by: Jenkins
Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/inc/bitmap/Octree.hxx | 88 | ||||
-rw-r--r-- | vcl/inc/bitmap/impoctree.hxx | 89 | ||||
-rw-r--r-- | vcl/source/bitmap/Octree.cxx | 202 |
3 files changed, 189 insertions, 190 deletions
diff --git a/vcl/inc/bitmap/Octree.hxx b/vcl/inc/bitmap/Octree.hxx index cec8e4171494..3e54826a9313 100644 --- a/vcl/inc/bitmap/Octree.hxx +++ b/vcl/inc/bitmap/Octree.hxx @@ -23,20 +23,20 @@ #include <vcl/salbtype.hxx> #include <vcl/dllapi.h> -#define OCTREE_BITS 5 -#define OCTREE_BITS_1 10 +#define OCTREE_BITS 5 +#define OCTREE_BITS_1 10 struct OctreeNode { - sal_uLong nCount; - sal_uLong nRed; - sal_uLong nGreen; - sal_uLong nBlue; - OctreeNode* pChild[ 8 ]; - OctreeNode* pNext; - OctreeNode* pNextInCache; - sal_uInt16 nPalIndex; - bool bLeaf; + sal_uLong nCount; + sal_uLong nRed; + sal_uLong nGreen; + sal_uLong nBlue; + OctreeNode* pChild[8]; + OctreeNode* pNext; + OctreeNode* pNextInCache; + sal_uInt16 nPalIndex; + bool bLeaf; }; class ImpNodeCache; @@ -45,73 +45,69 @@ class BitmapReadAccess; class VCL_PLUGIN_PUBLIC Octree { private: - void CreatePalette( OctreeNode* pNode ); - void GetPalIndex( OctreeNode* pNode ); - - SAL_DLLPRIVATE void ImplDeleteOctree( OctreeNode** ppNode ); - SAL_DLLPRIVATE void ImplAdd( OctreeNode** ppNode ); - SAL_DLLPRIVATE void ImplReduce(); - - - BitmapPalette aPal; - sal_uLong nLeafCount; - sal_uLong nLevel; - OctreeNode* pTree; - OctreeNode* pReduce[ OCTREE_BITS + 1 ]; - BitmapColor const * pColor; + void CreatePalette(OctreeNode* pNode); + void GetPalIndex(OctreeNode* pNode); + + SAL_DLLPRIVATE void ImplDeleteOctree(OctreeNode** ppNode); + SAL_DLLPRIVATE void ImplAdd(OctreeNode** ppNode); + SAL_DLLPRIVATE void ImplReduce(); + + BitmapPalette aPal; + sal_uLong nLeafCount; + sal_uLong nLevel; + OctreeNode* pTree; + OctreeNode* pReduce[OCTREE_BITS + 1]; + BitmapColor const* pColor; std::unique_ptr<ImpNodeCache> pNodeCache; - const BitmapReadAccess* pAcc; - sal_uInt16 nPalIndex; + const BitmapReadAccess* pAcc; + sal_uInt16 nPalIndex; public: - - Octree( const BitmapReadAccess& rReadAcc, sal_uLong nColors ); - ~Octree(); + Octree(const BitmapReadAccess& rReadAcc, sal_uLong nColors); + ~Octree(); inline const BitmapPalette& GetPalette(); - inline sal_uInt16 GetBestPaletteIndex( const BitmapColor& rColor ); + inline sal_uInt16 GetBestPaletteIndex(const BitmapColor& rColor); }; inline const BitmapPalette& Octree::GetPalette() { - aPal.SetEntryCount( static_cast<sal_uInt16>(nLeafCount) ); + aPal.SetEntryCount(static_cast<sal_uInt16>(nLeafCount)); nPalIndex = 0; - CreatePalette( pTree ); + CreatePalette(pTree); return aPal; } -inline sal_uInt16 Octree::GetBestPaletteIndex( const BitmapColor& rColor ) +inline sal_uInt16 Octree::GetBestPaletteIndex(const BitmapColor& rColor) { pColor = &rColor; nPalIndex = 65535; nLevel = 0; - GetPalIndex( pTree ); + GetPalIndex(pTree); return nPalIndex; } class VCL_PLUGIN_PUBLIC InverseColorMap { private: - std::unique_ptr<sal_uInt8[]> pBuffer; std::unique_ptr<sal_uInt8[]> pMap; - static constexpr sal_uLong gnBits = 8 -OCTREE_BITS; + static constexpr sal_uLong gnBits = 8 - OCTREE_BITS; - SAL_DLLPRIVATE void ImplCreateBuffers( const sal_uLong nMax ); + SAL_DLLPRIVATE void ImplCreateBuffers(const sal_uLong nMax); public: + explicit InverseColorMap(const BitmapPalette& rPal); + ~InverseColorMap(); - explicit InverseColorMap( const BitmapPalette& rPal ); - ~InverseColorMap(); - - inline sal_uInt16 GetBestPaletteIndex( const BitmapColor& rColor ); + inline sal_uInt16 GetBestPaletteIndex(const BitmapColor& rColor); }; -inline sal_uInt16 InverseColorMap::GetBestPaletteIndex( const BitmapColor& rColor ) +inline sal_uInt16 InverseColorMap::GetBestPaletteIndex(const BitmapColor& rColor) { - return pMap[ ( ( static_cast<sal_uLong>(rColor.GetRed()) >> gnBits ) << OCTREE_BITS_1 ) | - ( ( static_cast<sal_uLong>(rColor.GetGreen()) >> gnBits ) << OCTREE_BITS ) | - ( static_cast<sal_uLong>(rColor.GetBlue()) >> gnBits ) ]; + return pMap[((static_cast<sal_uLong>(rColor.GetRed()) >> gnBits) << OCTREE_BITS_1) + | ((static_cast<sal_uLong>(rColor.GetGreen()) >> gnBits) << OCTREE_BITS) + | (static_cast<sal_uLong>(rColor.GetBlue()) >> gnBits)]; } #endif // INCLUDED_VCL_INC_OCTREE_HXX diff --git a/vcl/inc/bitmap/impoctree.hxx b/vcl/inc/bitmap/impoctree.hxx index b2f05b351c5a..0ade7b7bcc3b 100644 --- a/vcl/inc/bitmap/impoctree.hxx +++ b/vcl/inc/bitmap/impoctree.hxx @@ -29,7 +29,6 @@ class ImpErrorQuad long nBlue; public: - ImpErrorQuad() : nRed(0) , nGreen(0) @@ -37,93 +36,93 @@ public: { } - ImpErrorQuad( const BitmapColor& rColor ) - : nRed( static_cast<long>(rColor.GetRed()) << 5 ) - , nGreen( static_cast<long>(rColor.GetGreen()) << 5 ) - , nBlue( static_cast<long>(rColor.GetBlue()) << 5 ) + ImpErrorQuad(const BitmapColor& rColor) + : nRed(static_cast<long>(rColor.GetRed()) << 5) + , nGreen(static_cast<long>(rColor.GetGreen()) << 5) + , nBlue(static_cast<long>(rColor.GetBlue()) << 5) { } - inline void operator=( const BitmapColor& rColor ); - inline ImpErrorQuad& operator-=( const BitmapColor& rColor ); + inline void operator=(const BitmapColor& rColor); + inline ImpErrorQuad& operator-=(const BitmapColor& rColor); - inline void ImplAddColorError1( const ImpErrorQuad& rErrQuad ); - inline void ImplAddColorError3( const ImpErrorQuad& rErrQuad ); - inline void ImplAddColorError5( const ImpErrorQuad& rErrQuad ); - inline void ImplAddColorError7( const ImpErrorQuad& rErrQuad ); + inline void ImplAddColorError1(const ImpErrorQuad& rErrQuad); + inline void ImplAddColorError3(const ImpErrorQuad& rErrQuad); + inline void ImplAddColorError5(const ImpErrorQuad& rErrQuad); + inline void ImplAddColorError7(const ImpErrorQuad& rErrQuad); - inline BitmapColor ImplGetColor(); + inline BitmapColor ImplGetColor(); }; -inline void ImpErrorQuad::operator=( const BitmapColor& rColor ) +inline void ImpErrorQuad::operator=(const BitmapColor& rColor) { nRed = static_cast<long>(rColor.GetRed()) << 5; nGreen = static_cast<long>(rColor.GetGreen()) << 5; nBlue = static_cast<long>(rColor.GetBlue()) << 5; } -inline ImpErrorQuad& ImpErrorQuad::operator-=( const BitmapColor& rColor ) +inline ImpErrorQuad& ImpErrorQuad::operator-=(const BitmapColor& rColor) { - nRed -= ( static_cast<long>(rColor.GetRed()) << 5 ); - nGreen -= ( static_cast<long>(rColor.GetGreen()) << 5 ); - nBlue -= ( static_cast<long>(rColor.GetBlue()) << 5 ); + nRed -= (static_cast<long>(rColor.GetRed()) << 5); + nGreen -= (static_cast<long>(rColor.GetGreen()) << 5); + nBlue -= (static_cast<long>(rColor.GetBlue()) << 5); return *this; } -inline void ImpErrorQuad::ImplAddColorError1( const ImpErrorQuad& rErrQuad ) +inline void ImpErrorQuad::ImplAddColorError1(const ImpErrorQuad& rErrQuad) { - nRed += ( rErrQuad.nRed >> 4 ); - nGreen += ( rErrQuad.nGreen >> 4 ); - nBlue += ( rErrQuad.nBlue >> 4 ); + nRed += (rErrQuad.nRed >> 4); + nGreen += (rErrQuad.nGreen >> 4); + nBlue += (rErrQuad.nBlue >> 4); } -inline void ImpErrorQuad::ImplAddColorError3( const ImpErrorQuad& rErrQuad ) +inline void ImpErrorQuad::ImplAddColorError3(const ImpErrorQuad& rErrQuad) { - nRed += ( rErrQuad.nRed * 3L >> 4 ); - nGreen += ( rErrQuad.nGreen * 3L >> 4 ); - nBlue += ( rErrQuad.nBlue * 3L >> 4 ); + nRed += (rErrQuad.nRed * 3L >> 4); + nGreen += (rErrQuad.nGreen * 3L >> 4); + nBlue += (rErrQuad.nBlue * 3L >> 4); } -inline void ImpErrorQuad::ImplAddColorError5( const ImpErrorQuad& rErrQuad ) +inline void ImpErrorQuad::ImplAddColorError5(const ImpErrorQuad& rErrQuad) { - nRed += ( rErrQuad.nRed * 5L >> 4 ); - nGreen += ( rErrQuad.nGreen * 5L >> 4 ); - nBlue += ( rErrQuad.nBlue * 5L >> 4 ); + nRed += (rErrQuad.nRed * 5L >> 4); + nGreen += (rErrQuad.nGreen * 5L >> 4); + nBlue += (rErrQuad.nBlue * 5L >> 4); } -inline void ImpErrorQuad::ImplAddColorError7( const ImpErrorQuad& rErrQuad ) +inline void ImpErrorQuad::ImplAddColorError7(const ImpErrorQuad& rErrQuad) { - nRed += ( rErrQuad.nRed * 7L >> 4 ); - nGreen += ( rErrQuad.nGreen * 7L >> 4 ); - nBlue += ( rErrQuad.nBlue *7L >> 4 ); + nRed += (rErrQuad.nRed * 7L >> 4); + nGreen += (rErrQuad.nGreen * 7L >> 4); + nBlue += (rErrQuad.nBlue * 7L >> 4); } inline BitmapColor ImpErrorQuad::ImplGetColor() { - return BitmapColor( static_cast<sal_uInt8>( ( nRed < 0 ? 0L : nRed > 8160 ? 8160L : nRed ) >> 5 ), - static_cast<sal_uInt8>( ( nGreen < 0 ? 0L : nGreen > 8160 ? 8160L : nGreen ) >> 5 ), - static_cast<sal_uInt8>( ( nBlue < 0 ? 0L : nBlue > 8160 ? 8160L : nBlue ) >> 5 ) ); + return BitmapColor( + static_cast<sal_uInt8>((nRed < 0 ? 0L : nRed > 8160 ? 8160L : nRed) >> 5), + static_cast<sal_uInt8>((nGreen < 0 ? 0L : nGreen > 8160 ? 8160L : nGreen) >> 5), + static_cast<sal_uInt8>((nBlue < 0 ? 0L : nBlue > 8160 ? 8160L : nBlue) >> 5)); } class ImpNodeCache { - OctreeNode* pActNode; + OctreeNode* pActNode; public: + ImpNodeCache(const sal_uLong nInitSize); + ~ImpNodeCache(); - ImpNodeCache( const sal_uLong nInitSize ); - ~ImpNodeCache(); - - inline OctreeNode* ImplGetFreeNode(); - inline void ImplReleaseNode( OctreeNode* pNode ); + inline OctreeNode* ImplGetFreeNode(); + inline void ImplReleaseNode(OctreeNode* pNode); }; inline OctreeNode* ImpNodeCache::ImplGetFreeNode() { OctreeNode* pNode; - if ( !pActNode ) + if (!pActNode) { pActNode = new OctreeNode; pActNode->pNextInCache = nullptr; @@ -131,12 +130,12 @@ inline OctreeNode* ImpNodeCache::ImplGetFreeNode() pNode = pActNode; pActNode = pNode->pNextInCache; - memset( pNode, 0, sizeof( OctreeNode ) ); + memset(pNode, 0, sizeof(OctreeNode)); return pNode; } -inline void ImpNodeCache::ImplReleaseNode( OctreeNode* pNode ) +inline void ImpNodeCache::ImplReleaseNode(OctreeNode* pNode) { pNode->pNextInCache = pActNode; pActNode = pNode; diff --git a/vcl/source/bitmap/Octree.cxx b/vcl/source/bitmap/Octree.cxx index 64914f76385e..6650e52d0692 100644 --- a/vcl/source/bitmap/Octree.cxx +++ b/vcl/source/bitmap/Octree.cxx @@ -27,12 +27,12 @@ static const sal_uInt8 pImplMask[8] = { 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01 }; -ImpNodeCache::ImpNodeCache( const sal_uLong nInitSize ) : - pActNode( nullptr ) +ImpNodeCache::ImpNodeCache(const sal_uLong nInitSize) + : pActNode(nullptr) { const sal_uLong nSize = nInitSize + 4; - for( sal_uLong i = 0; i < nSize; i++ ) + for (sal_uLong i = 0; i < nSize; i++) { OctreeNode* pNewNode = new OctreeNode; @@ -43,7 +43,7 @@ ImpNodeCache::ImpNodeCache( const sal_uLong nInitSize ) : ImpNodeCache::~ImpNodeCache() { - while( pActNode ) + while (pActNode) { OctreeNode* pNode = pActNode; @@ -61,26 +61,26 @@ Octree::Octree(const BitmapReadAccess& rReadAcc, sal_uLong nColors) , nPalIndex(0) { sal_uLong nMax(nColors); - pNodeCache.reset( new ImpNodeCache( nColors ) ); - memset( pReduce, 0, ( OCTREE_BITS + 1 ) * sizeof( OctreeNode* ) ); + pNodeCache.reset(new ImpNodeCache(nColors)); + memset(pReduce, 0, (OCTREE_BITS + 1) * sizeof(OctreeNode*)); - if( !!*pAcc ) + if (!!*pAcc) { - const long nWidth = pAcc->Width(); - const long nHeight = pAcc->Height(); + const long nWidth = pAcc->Width(); + const long nHeight = pAcc->Height(); - if( pAcc->HasPalette() ) + if (pAcc->HasPalette()) { - for( long nY = 0; nY < nHeight; nY++ ) + for (long nY = 0; nY < nHeight; nY++) { - Scanline pScanline = pAcc->GetScanline( nY ); - for( long nX = 0; nX < nWidth; nX++ ) + Scanline pScanline = pAcc->GetScanline(nY); + for (long nX = 0; nX < nWidth; nX++) { - pColor = &pAcc->GetPaletteColor( pAcc->GetIndexFromData( pScanline, nX ) ); + pColor = &pAcc->GetPaletteColor(pAcc->GetIndexFromData(pScanline, nX)); nLevel = 0; - ImplAdd( &pTree ); + ImplAdd(&pTree); - while( nLeafCount > nMax ) + while (nLeafCount > nMax) ImplReduce(); } } @@ -91,16 +91,16 @@ Octree::Octree(const BitmapReadAccess& rReadAcc, sal_uLong nColors) pColor = &aColor; - for( long nY = 0; nY < nHeight; nY++ ) + for (long nY = 0; nY < nHeight; nY++) { - Scanline pScanline = pAcc->GetScanline( nY ); - for( long nX = 0; nX < nWidth; nX++ ) + Scanline pScanline = pAcc->GetScanline(nY); + for (long nX = 0; nX < nWidth; nX++) { - aColor = pAcc->GetPixelFromData( pScanline, nX ); + aColor = pAcc->GetPixelFromData(pScanline, nX); nLevel = 0; - ImplAdd( &pTree ); + ImplAdd(&pTree); - while( nLeafCount > nMax ) + while (nLeafCount > nMax) ImplReduce(); } } @@ -110,40 +110,40 @@ Octree::Octree(const BitmapReadAccess& rReadAcc, sal_uLong nColors) Octree::~Octree() { - ImplDeleteOctree( &pTree ); + ImplDeleteOctree(&pTree); pNodeCache.reset(); } -void Octree::ImplDeleteOctree( OctreeNode** ppNode ) +void Octree::ImplDeleteOctree(OctreeNode** ppNode) { for (OctreeNode* i : (*ppNode)->pChild) { - if ( i ) - ImplDeleteOctree( &i ); + if (i) + ImplDeleteOctree(&i); } - pNodeCache->ImplReleaseNode( *ppNode ); + pNodeCache->ImplReleaseNode(*ppNode); *ppNode = nullptr; } -void Octree::ImplAdd( OctreeNode** ppNode ) +void Octree::ImplAdd(OctreeNode** ppNode) { // possibly generate new nodes - if( !*ppNode ) + if (!*ppNode) { *ppNode = pNodeCache->ImplGetFreeNode(); - (*ppNode)->bLeaf = ( OCTREE_BITS == nLevel ); + (*ppNode)->bLeaf = (OCTREE_BITS == nLevel); - if( (*ppNode)->bLeaf ) + if ((*ppNode)->bLeaf) nLeafCount++; else { - (*ppNode)->pNext = pReduce[ nLevel ]; - pReduce[ nLevel ] = *ppNode; + (*ppNode)->pNext = pReduce[nLevel]; + pReduce[nLevel] = *ppNode; } } - if( (*ppNode)->bLeaf ) + if ((*ppNode)->bLeaf) { (*ppNode)->nCount++; (*ppNode)->nRed += pColor->GetRed(); @@ -153,43 +153,45 @@ void Octree::ImplAdd( OctreeNode** ppNode ) else { const sal_uLong nShift = 7 - nLevel; - const sal_uInt8 cMask = pImplMask[ nLevel ]; - const sal_uLong nIndex = ( ( ( pColor->GetRed() & cMask ) >> nShift ) << 2 ) | - ( ( ( pColor->GetGreen() & cMask ) >> nShift ) << 1 ) | - ( ( pColor->GetBlue() & cMask ) >> nShift ); + const sal_uInt8 cMask = pImplMask[nLevel]; + const sal_uLong nIndex = (((pColor->GetRed() & cMask) >> nShift) << 2) + | (((pColor->GetGreen() & cMask) >> nShift) << 1) + | ((pColor->GetBlue() & cMask) >> nShift); nLevel++; - ImplAdd( &(*ppNode)->pChild[ nIndex ] ); + ImplAdd(&(*ppNode)->pChild[nIndex]); } } void Octree::ImplReduce() { - sal_uLong i; + sal_uLong i; OctreeNode* pNode; - sal_uLong nRedSum = 0; - sal_uLong nGreenSum = 0; - sal_uLong nBlueSum = 0; - sal_uLong nChildren = 0; + sal_uLong nRedSum = 0; + sal_uLong nGreenSum = 0; + sal_uLong nBlueSum = 0; + sal_uLong nChildren = 0; - for ( i = OCTREE_BITS - 1; i && !pReduce[i]; i-- ) {} + for (i = OCTREE_BITS - 1; i && !pReduce[i]; i--) + { + } - pNode = pReduce[ i ]; - pReduce[ i ] = pNode->pNext; + pNode = pReduce[i]; + pReduce[i] = pNode->pNext; - for ( i = 0; i < 8; i++ ) + for (i = 0; i < 8; i++) { - if ( pNode->pChild[ i ] ) + if (pNode->pChild[i]) { - OctreeNode* pChild = pNode->pChild[ i ]; + OctreeNode* pChild = pNode->pChild[i]; nRedSum += pChild->nRed; nGreenSum += pChild->nGreen; nBlueSum += pChild->nBlue; pNode->nCount += pChild->nCount; - pNodeCache->ImplReleaseNode( pNode->pChild[ i ] ); - pNode->pChild[ i ] = nullptr; + pNodeCache->ImplReleaseNode(pNode->pChild[i]); + pNode->pChild[i] = nullptr; nChildren++; } } @@ -201,75 +203,79 @@ void Octree::ImplReduce() nLeafCount -= --nChildren; } -void Octree::CreatePalette( OctreeNode* pNode ) +void Octree::CreatePalette(OctreeNode* pNode) { - if( pNode->bLeaf ) + if (pNode->bLeaf) { pNode->nPalIndex = nPalIndex; - aPal[ nPalIndex++ ] = BitmapColor( static_cast<sal_uInt8>( static_cast<double>(pNode->nRed) / pNode->nCount ), - static_cast<sal_uInt8>( static_cast<double>(pNode->nGreen) / pNode->nCount ), - static_cast<sal_uInt8>( static_cast<double>(pNode->nBlue) / pNode->nCount ) ); + aPal[nPalIndex++] = BitmapColor( + static_cast<sal_uInt8>(static_cast<double>(pNode->nRed) / pNode->nCount), + static_cast<sal_uInt8>(static_cast<double>(pNode->nGreen) / pNode->nCount), + static_cast<sal_uInt8>(static_cast<double>(pNode->nBlue) / pNode->nCount)); } - else for(OctreeNode* i : pNode->pChild) - if( i ) - CreatePalette( i ); - + else + for (OctreeNode* i : pNode->pChild) + { + if (i) + CreatePalette(i); + } } -void Octree::GetPalIndex( OctreeNode* pNode ) +void Octree::GetPalIndex(OctreeNode* pNode) { - if ( pNode->bLeaf ) + if (pNode->bLeaf) nPalIndex = pNode->nPalIndex; else { const sal_uLong nShift = 7 - nLevel; - const sal_uInt8 cMask = pImplMask[ nLevel++ ]; - const sal_uLong nIndex = ( ( ( pColor->GetRed() & cMask ) >> nShift ) << 2 ) | - ( ( ( pColor->GetGreen() & cMask ) >> nShift ) << 1 ) | - ( ( pColor->GetBlue() & cMask ) >> nShift ); + const sal_uInt8 cMask = pImplMask[nLevel++]; + const sal_uLong nIndex = (((pColor->GetRed() & cMask) >> nShift) << 2) + | (((pColor->GetGreen() & cMask) >> nShift) << 1) + | ((pColor->GetBlue() & cMask) >> nShift); - GetPalIndex( pNode->pChild[ nIndex ] ); + GetPalIndex(pNode->pChild[nIndex]); } } -InverseColorMap::InverseColorMap( const BitmapPalette& rPal ) +InverseColorMap::InverseColorMap(const BitmapPalette& rPal) { - const int nColorMax = 1 << OCTREE_BITS; - const unsigned long xsqr = 1 << ( gnBits << 1 ); + const int nColorMax = 1 << OCTREE_BITS; + const unsigned long xsqr = 1 << (gnBits << 1); const unsigned long xsqr2 = xsqr << 1; - const int nColors = rPal.GetEntryCount(); - const long x = 1 << gnBits; - const long x2 = x >> 1; - sal_uLong r, g, b; - long rxx, gxx, bxx; + const int nColors = rPal.GetEntryCount(); + const long x = 1 << gnBits; + const long x2 = x >> 1; + sal_uLong r, g, b; + long rxx, gxx, bxx; - ImplCreateBuffers( nColorMax ); + ImplCreateBuffers(nColorMax); - for( int nIndex = 0; nIndex < nColors; nIndex++ ) + for (int nIndex = 0; nIndex < nColors; nIndex++) { - const BitmapColor& rColor = rPal[ static_cast<sal_uInt16>(nIndex) ]; - const long cRed = rColor.GetRed(); - const long cGreen = rColor.GetGreen(); - const long cBlue = rColor.GetBlue(); + const BitmapColor& rColor = rPal[static_cast<sal_uInt16>(nIndex)]; + const long cRed = rColor.GetRed(); + const long cGreen = rColor.GetGreen(); + const long cBlue = rColor.GetBlue(); long rdist = cRed - x2; long gdist = cGreen - x2; long bdist = cBlue - x2; - rdist = rdist*rdist + gdist*gdist + bdist*bdist; + rdist = rdist * rdist + gdist * gdist + bdist * bdist; - const long crinc = ( xsqr - ( cRed << gnBits ) ) << 1; - const long cginc = ( xsqr - ( cGreen << gnBits ) ) << 1; - const long cbinc = ( xsqr - ( cBlue << gnBits ) ) << 1; + const long crinc = (xsqr - (cRed << gnBits)) << 1; + const long cginc = (xsqr - (cGreen << gnBits)) << 1; + const long cbinc = (xsqr - (cBlue << gnBits)) << 1; sal_uLong* cdp = reinterpret_cast<sal_uLong*>(pBuffer.get()); sal_uInt8* crgbp = pMap.get(); - for( r = 0, rxx = crinc; r < nColorMax; rdist += rxx, r++, rxx += xsqr2 ) + for (r = 0, rxx = crinc; r < nColorMax; rdist += rxx, r++, rxx += xsqr2) { - for( g = 0, gdist = rdist, gxx = cginc; g < nColorMax; gdist += gxx, g++, gxx += xsqr2 ) + for (g = 0, gdist = rdist, gxx = cginc; g < nColorMax; gdist += gxx, g++, gxx += xsqr2) { - for( b = 0, bdist = gdist, bxx = cbinc; b < nColorMax; bdist += bxx, b++, cdp++, crgbp++, bxx += xsqr2 ) - if ( !nIndex || static_cast<long>(*cdp) > bdist ) + for (b = 0, bdist = gdist, bxx = cbinc; b < nColorMax; + bdist += bxx, b++, cdp++, crgbp++, bxx += xsqr2) + if (!nIndex || static_cast<long>(*cdp) > bdist) { *cdp = bdist; *crgbp = static_cast<sal_uInt8>(nIndex); @@ -279,20 +285,18 @@ InverseColorMap::InverseColorMap( const BitmapPalette& rPal ) } } -InverseColorMap::~InverseColorMap() -{ -} +InverseColorMap::~InverseColorMap() {} -void InverseColorMap::ImplCreateBuffers( const sal_uLong nMax ) +void InverseColorMap::ImplCreateBuffers(const sal_uLong nMax) { const sal_uLong nCount = nMax * nMax * nMax; - const sal_uLong nSize = nCount * sizeof( sal_uLong ); + const sal_uLong nSize = nCount * sizeof(sal_uLong); - pMap.reset(new sal_uInt8[ nCount ]); - memset( pMap.get(), 0x00, nCount ); + pMap.reset(new sal_uInt8[nCount]); + memset(pMap.get(), 0x00, nCount); - pBuffer.reset(new sal_uInt8[ nSize ]); - memset( pBuffer.get(), 0xff, nSize ); + pBuffer.reset(new sal_uInt8[nSize]); + memset(pBuffer.get(), 0xff, nSize); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |