Minor simplifications in the octree algorithm

This commit is contained in:
Gaspar Capello 2021-05-31 13:17:08 -03:00 committed by David Capello
parent e6ec13cc31
commit 59ed2bbe9d

View File

@ -12,7 +12,6 @@
#include "doc/palette.h" #include "doc/palette.h"
#define MID_VALUE_COLOR ((rgba_r_mask / 2) + 1)
#define MIN_LEVEL_OCTREE_DEEP 3 #define MIN_LEVEL_OCTREE_DEEP 3
namespace doc { namespace doc {
@ -62,14 +61,10 @@ void OctreeNode::fillOrphansNodes(const Palette* palette,
continue; continue;
} }
int currentBranchColorAdd = octetToBranchColor(i, level); int currentBranchColorAdd = octetToBranchColor(i, level);
int midColorAdd = MID_VALUE_COLOR >> (level + 1); color_t branchColorMed = rgba_a_mask |
midColorAdd = ((midColorAdd) << rgba_r_shift) upstreamBranchColor |
+ ((midColorAdd) << rgba_g_shift) currentBranchColorAdd |
+ ((midColorAdd) << rgba_b_shift); ((level == 7) ? 0 : (0x00010101 << (6 - level))); // mid color adition
color_t branchColorMed = rgba_a_mask
+ upstreamBranchColor
+ currentBranchColorAdd
+ midColorAdd;
int indexMed = palette->findBestfit2(rgba_getr(branchColorMed), int indexMed = palette->findBestfit2(rgba_getr(branchColorMed),
rgba_getg(branchColorMed), rgba_getg(branchColorMed),
rgba_getb(branchColorMed)); rgba_getb(branchColorMed));
@ -93,11 +88,7 @@ void OctreeNode::fillMostSignificantNodes(int level)
int OctreeNode::mapColor(int r, int g, int b, int level) const int OctreeNode::mapColor(int r, int g, int b, int level) const
{ {
int indexLevel = ( (b >> (7 - level)) & 1) * 4 OctreeNode& child = (*m_children)[getOctet(rgba(r, g, b, 0), level)];
+ ((g >> (7 - level)) & 1) * 2
+ ((r >> (7 - level)) & 1);
OctreeNode& child = (*m_children)[indexLevel];
if (child.hasChildren()) if (child.hasChildren())
return child.mapColor(r, g, b, level+1); return child.mapColor(r, g, b, level+1);
else else
@ -146,20 +137,17 @@ int OctreeNode::removeLeaves(OctreeNodes& auxParentVector,
// static // static
int OctreeNode::getOctet(color_t c, int level) int OctreeNode::getOctet(color_t c, int level)
{ {
int aux = c >> (7 - level); return ((c & (0x00000080 >> level)) ? 1 : 0) |
int octet = aux & 1; ((c & (0x00008000 >> level)) ? 2 : 0) |
aux = aux >> (7); ((c & (0x00800000 >> level)) ? 4 : 0);
octet += (aux & 2);
return octet + ((aux >> 7) & 4);
} }
// static // static
color_t OctreeNode::octetToBranchColor(int octet, int level) color_t OctreeNode::octetToBranchColor(int octet, int level)
{ {
int auxR = (octet & 1) << (7 - level); return ((octet & 1) ? 0x00000080 >> level : 0) |
int auxG = (octet & 2) << (14 - level); ((octet & 2) ? 0x00008000 >> level : 0) |
int auxB = (octet & 4) << (21 - level); ((octet & 4) ? 0x00800000 >> level : 0);
return auxR + auxG + auxB;
} }
////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////
@ -221,7 +209,7 @@ bool OctreeMap::makePalette(Palette* palette,
} }
// End Sort colors. // End Sort colors.
// Blend colors: // Blend colors:
for(;;) { for (;;) {
if (sortedVector.size() <= colorCount) { if (sortedVector.size() <= colorCount) {
for (int k=0; k<sortedVector.size(); k++) for (int k=0; k<sortedVector.size(); k++)
m_leavesVector.push_back(sortedVector[k]); m_leavesVector.push_back(sortedVector[k]);
@ -255,7 +243,7 @@ bool OctreeMap::makePalette(Palette* palette,
int aux = 0; int aux = 0;
if (m_maskColor == 0x00FFFFFF) if (m_maskColor == 0x00FFFFFF)
palette->resize(leafCount); palette->resize(leafCount);
else{ else {
palette->resize(leafCount + 1); palette->resize(leafCount + 1);
palette->setEntry(0, m_maskColor); palette->setEntry(0, m_maskColor);
aux = 1; aux = 1;