Better fix for #94

dev-mp
Piotr Dziwinski 2014-11-22 13:30:05 +01:00
parent d11a2f37f9
commit f30592bf56
2 changed files with 65 additions and 60 deletions

View File

@ -2439,14 +2439,18 @@ bool CEngine::ChangeTextureColor(const std::string& texName,
m_texBlacklist.insert(texName); m_texBlacklist.insert(texName);
return false; return false;
} }
bool changeColorsNeeded = true;
if (colorRef1.r == colorNew1.r && if (colorRef1.r == colorNew1.r &&
colorRef1.g == colorNew1.g && colorRef1.g == colorNew1.g &&
colorRef1.b == colorNew1.b && colorRef1.b == colorNew1.b &&
colorRef2.r == colorNew2.r && colorRef2.r == colorNew2.r &&
colorRef2.g == colorNew2.g && colorRef2.g == colorNew2.g &&
colorRef2.b == colorNew2.b) colorRef2.b == colorNew2.b)
return true; {
changeColorsNeeded = false;
}
int dx = img.GetSize().x; int dx = img.GetSize().x;
@ -2464,66 +2468,69 @@ bool CEngine::ChangeTextureColor(const std::string& texName,
ColorHSV cr2 = RGB2HSV(colorRef2); ColorHSV cr2 = RGB2HSV(colorRef2);
ColorHSV cn2 = RGB2HSV(colorNew2); ColorHSV cn2 = RGB2HSV(colorNew2);
for (int y = sy; y < ey; y++) if (changeColorsNeeded)
{ {
for (int x = sx; x < ex; x++) for (int y = sy; y < ey; y++)
{ {
if (exclude != nullptr && IsExcludeColor(exclude, x,y) ) for (int x = sx; x < ex; x++)
continue;
Color color = img.GetPixel(Math::IntPoint(x, y));
if (hsv)
{ {
ColorHSV c = RGB2HSV(color); if (exclude != nullptr && IsExcludeColor(exclude, x,y) )
if (c.s > 0.01f && fabs(c.h - cr1.h) < tolerance1) continue;
Color color = img.GetPixel(Math::IntPoint(x, y));
if (hsv)
{ {
c.h += cn1.h - cr1.h; ColorHSV c = RGB2HSV(color);
c.s += cn1.s - cr1.s; if (c.s > 0.01f && fabs(c.h - cr1.h) < tolerance1)
c.v += cn1.v - cr1.v; {
if (c.h < 0.0f) c.h -= 1.0f; c.h += cn1.h - cr1.h;
if (c.h > 1.0f) c.h += 1.0f; c.s += cn1.s - cr1.s;
color = HSV2RGB(c); c.v += cn1.v - cr1.v;
color.r = Math::Norm(color.r + shift); if (c.h < 0.0f) c.h -= 1.0f;
color.g = Math::Norm(color.g + shift); if (c.h > 1.0f) c.h += 1.0f;
color.b = Math::Norm(color.b + shift); color = HSV2RGB(c);
img.SetPixel(Math::IntPoint(x, y), color); color.r = Math::Norm(color.r + shift);
color.g = Math::Norm(color.g + shift);
color.b = Math::Norm(color.b + shift);
img.SetPixel(Math::IntPoint(x, y), color);
}
else if (tolerance2 != -1.0f &&
c.s > 0.01f && fabs(c.h - cr2.h) < tolerance2)
{
c.h += cn2.h - cr2.h;
c.s += cn2.s - cr2.s;
c.v += cn2.v - cr2.v;
if (c.h < 0.0f) c.h -= 1.0f;
if (c.h > 1.0f) c.h += 1.0f;
color = HSV2RGB(c);
color.r = Math::Norm(color.r + shift);
color.g = Math::Norm(color.g + shift);
color.b = Math::Norm(color.b + shift);
img.SetPixel(Math::IntPoint(x, y), color);
}
} }
else if (tolerance2 != -1.0f && else
c.s > 0.01f && fabs(c.h - cr2.h) < tolerance2)
{ {
c.h += cn2.h - cr2.h; if ( fabs(color.r - colorRef1.r) +
c.s += cn2.s - cr2.s; fabs(color.g - colorRef1.g) +
c.v += cn2.v - cr2.v; fabs(color.b - colorRef1.b) < tolerance1 * 3.0f)
if (c.h < 0.0f) c.h -= 1.0f; {
if (c.h > 1.0f) c.h += 1.0f; color.r = Math::Norm(colorNew1.r + color.r - colorRef1.r + shift);
color = HSV2RGB(c); color.g = Math::Norm(colorNew1.g + color.g - colorRef1.g + shift);
color.r = Math::Norm(color.r + shift); color.b = Math::Norm(colorNew1.b + color.b - colorRef1.b + shift);
color.g = Math::Norm(color.g + shift); img.SetPixel(Math::IntPoint(x, y), color);
color.b = Math::Norm(color.b + shift); }
img.SetPixel(Math::IntPoint(x, y), color); else if (tolerance2 != -1 &&
} fabs(color.r - colorRef2.r) +
} fabs(color.g - colorRef2.g) +
else fabs(color.b - colorRef2.b) < tolerance2 * 3.0f)
{ {
if ( fabs(color.r - colorRef1.r) + color.r = Math::Norm(colorNew2.r + color.r - colorRef2.r + shift);
fabs(color.g - colorRef1.g) + color.g = Math::Norm(colorNew2.g + color.g - colorRef2.g + shift);
fabs(color.b - colorRef1.b) < tolerance1 * 3.0f) color.b = Math::Norm(colorNew2.b + color.b - colorRef2.b + shift);
{ img.SetPixel(Math::IntPoint(x, y), color);
color.r = Math::Norm(colorNew1.r + color.r - colorRef1.r + shift); }
color.g = Math::Norm(colorNew1.g + color.g - colorRef1.g + shift);
color.b = Math::Norm(colorNew1.b + color.b - colorRef1.b + shift);
img.SetPixel(Math::IntPoint(x, y), color);
}
else if (tolerance2 != -1 &&
fabs(color.r - colorRef2.r) +
fabs(color.g - colorRef2.g) +
fabs(color.b - colorRef2.b) < tolerance2 * 3.0f)
{
color.r = Math::Norm(colorNew2.r + color.r - colorRef2.r + shift);
color.g = Math::Norm(colorNew2.g + color.g - colorRef2.g + shift);
color.b = Math::Norm(colorNew2.b + color.b - colorRef2.b + shift);
img.SetPixel(Math::IntPoint(x, y), color);
} }
} }
} }

View File

@ -3660,9 +3660,7 @@ void CRobotMain::ScenePerso()
iMan->Flush(CLASS_PYRO); iMan->Flush(CLASS_PYRO);
CObjectManager::GetInstancePointer()->Flush(); CObjectManager::GetInstancePointer()->Flush();
ChangeColor();
m_dialog->SetSceneName("perso"); m_dialog->SetSceneName("perso");
m_dialog->SetSceneRank(0); m_dialog->SetSceneRank(0);
try { try {
@ -4743,7 +4741,7 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
g_build |= BUILD_FLAG; g_build |= BUILD_FLAG;
} }
if (!resetObject && !fixScene) if (!resetObject)
{ {
ChangeColor(); // changes the colors of texture ChangeColor(); // changes the colors of texture
m_short->SetMode(false); // vehicles? m_short->SetMode(false); // vehicles?