Fixed a bug on white balance. now it works fine.

This commit is contained in:
Paolo Cignoni 2008-07-18 13:07:10 +00:00
parent 4842e38c94
commit 19bb932a8f
1 changed files with 11 additions and 7 deletions

View File

@ -696,8 +696,8 @@ static int ValueEqualize(int cdfValue, int cdfMin, int cdfMax)
static int WhiteBalance(UpdateMeshType &m, const bool ProcessSelected=false) static int WhiteBalance(UpdateMeshType &m, const bool ProcessSelected=false)
{ {
int unbalancedWhite = 0; Color4b unbalancedWhite;
int counter=0; int lightness = 0, counter=0;
VertexIterator vi; VertexIterator vi;
for(vi=m.vert.begin();vi!=m.vert.end();++vi) //scan all the vertex... for(vi=m.vert.begin();vi!=m.vert.end();++vi) //scan all the vertex...
{ {
@ -705,7 +705,11 @@ static int WhiteBalance(UpdateMeshType &m, const bool ProcessSelected=false)
{ {
if(!ProcessSelected || (*vi).IsS()) //if this vertex has been selected, do transormation if(!ProcessSelected || (*vi).IsS()) //if this vertex has been selected, do transormation
{ {
unbalancedWhite = (int)math::Max(ComputeLightness((*vi).C()), float(unbalancedWhite)); int v = ComputeLightness((*vi).C());
if( v > lightness){
lightness = v;
unbalancedWhite = (*vi).C();
}
} }
} }
} }
@ -724,12 +728,12 @@ static int WhiteBalance(UpdateMeshType &m, const bool ProcessSelected=false)
return counter; return counter;
} }
static Color4b ColorWhiteBalance(Color4b c, int unbalancedWhite) static Color4b ColorWhiteBalance(Color4b c, Color4b unbalancedWhite)
{ {
return Color4b( return Color4b(
math::Clamp<int>((int)(c[0]*(255.0f/unbalancedWhite)), 0, 255), math::Clamp<int>((int)(c[0]*(255.0f/unbalancedWhite[0])), 0, 255),
math::Clamp<int>((int)(c[1]*(255.0f/unbalancedWhite)), 0, 255), math::Clamp<int>((int)(c[1]*(255.0f/unbalancedWhite[1])), 0, 255),
math::Clamp<int>((int)(c[2]*(255.0f/unbalancedWhite)), 0, 255), math::Clamp<int>((int)(c[2]*(255.0f/unbalancedWhite[2])), 0, 255),
255); 255);
} }