mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-21 10:13:43 +03:00
0032955: Draw Harness, ViewerTest - extend vcolorconvert command to print color in hex format
This commit is contained in:
parent
d2c11b791c
commit
cb6c7c458c
@ -13644,61 +13644,116 @@ static int VViewCube (Draw_Interpretor& ,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//! Parse color type argument.
|
||||||
|
static bool parseColorType (const char* theString,
|
||||||
|
Quantity_TypeOfColor& theType)
|
||||||
|
{
|
||||||
|
TCollection_AsciiString aType (theString);
|
||||||
|
aType.LowerCase();
|
||||||
|
if (aType == "rgb") { theType = Quantity_TOC_RGB; }
|
||||||
|
else if (aType == "srgb") { theType = Quantity_TOC_sRGB; }
|
||||||
|
else if (aType == "hex") { theType = Quantity_TOC_sRGB; }
|
||||||
|
else if (aType == "name") { theType = Quantity_TOC_sRGB; }
|
||||||
|
else if (aType == "hls") { theType = Quantity_TOC_HLS; }
|
||||||
|
else if (aType == "lab") { theType = Quantity_TOC_CIELab; }
|
||||||
|
else if (aType == "lch") { theType = Quantity_TOC_CIELch; }
|
||||||
|
else { return false; }
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
//===============================================================================================
|
//===============================================================================================
|
||||||
//function : VColorConvert
|
//function : VColorConvert
|
||||||
//purpose :
|
//purpose :
|
||||||
//===============================================================================================
|
//===============================================================================================
|
||||||
static int VColorConvert (Draw_Interpretor& theDI, Standard_Integer theNbArgs, const char** theArgVec)
|
static int VColorConvert (Draw_Interpretor& theDI, Standard_Integer theNbArgs, const char** theArgVec)
|
||||||
{
|
{
|
||||||
if (theNbArgs != 6)
|
Quantity_TypeOfColor aTypeFrom = Quantity_TOC_RGB, aTypeTo = Quantity_TOC_RGB;
|
||||||
|
double anInput[4] = {};
|
||||||
|
Quantity_ColorRGBA aColor (0.0f, 0.0f, 0.0f, 1.0f);
|
||||||
|
bool toPrintHex = false, toPrintName = false, hasAlpha = false;
|
||||||
|
for (int anArgIter = 1; anArgIter < theNbArgs; ++anArgIter)
|
||||||
{
|
{
|
||||||
std::cerr << "Error: command syntax is incorrect, see help" << std::endl;
|
TCollection_AsciiString anArgCase (theArgVec[anArgIter]);
|
||||||
return 1;
|
anArgCase.LowerCase();
|
||||||
|
if ((anArgCase == "-from"
|
||||||
|
|| anArgCase == "from")
|
||||||
|
&& anArgIter + 1 < theNbArgs
|
||||||
|
&& parseColorType (theArgVec[anArgIter + 1], aTypeFrom))
|
||||||
|
{
|
||||||
|
++anArgIter;
|
||||||
}
|
}
|
||||||
|
else if ((anArgCase == "-to"
|
||||||
Standard_Boolean convertFrom = (! strcasecmp (theArgVec[1], "from"));
|
|| anArgCase == "to")
|
||||||
if (! convertFrom && strcasecmp (theArgVec[1], "to"))
|
&& anArgIter + 1 < theNbArgs
|
||||||
|
&& parseColorType (theArgVec[anArgIter + 1], aTypeTo))
|
||||||
{
|
{
|
||||||
std::cerr << "Error: first argument must be either \"to\" or \"from\"" << std::endl;
|
TCollection_AsciiString aToStr (theArgVec[++anArgIter]);
|
||||||
return 1;
|
aToStr.LowerCase();
|
||||||
|
toPrintHex = (aToStr == "hex");
|
||||||
|
toPrintName = (aToStr == "name");
|
||||||
}
|
}
|
||||||
|
else if (Quantity_ColorRGBA::ColorFromHex (theArgVec[anArgIter], aColor))
|
||||||
const char* aTypeStr = theArgVec[2];
|
|
||||||
Quantity_TypeOfColor aType = Quantity_TOC_RGB;
|
|
||||||
if (! strcasecmp (aTypeStr, "srgb"))
|
|
||||||
{
|
{
|
||||||
aType = Quantity_TOC_sRGB;
|
hasAlpha = anArgCase.Length() >= 8;
|
||||||
}
|
}
|
||||||
else if (! strcasecmp (aTypeStr, "hls"))
|
else if (Quantity_Color::ColorFromName (theArgVec[anArgIter], aColor.ChangeRGB()))
|
||||||
{
|
{
|
||||||
aType = Quantity_TOC_HLS;
|
//
|
||||||
}
|
}
|
||||||
else if (! strcasecmp (aTypeStr, "lab"))
|
else if (anArgIter + 2 < theNbArgs
|
||||||
|
&& Draw::ParseReal (theArgVec[anArgIter + 0], anInput[0])
|
||||||
|
&& Draw::ParseReal (theArgVec[anArgIter + 1], anInput[1])
|
||||||
|
&& Draw::ParseReal (theArgVec[anArgIter + 2], anInput[2]))
|
||||||
{
|
{
|
||||||
aType = Quantity_TOC_CIELab;
|
if (anArgIter + 3 < theNbArgs
|
||||||
|
&& Draw::ParseReal (theArgVec[anArgIter + 3], anInput[3]))
|
||||||
|
{
|
||||||
|
anArgIter += 1;
|
||||||
|
aColor.SetAlpha ((float )anInput[3]);
|
||||||
|
hasAlpha = true;
|
||||||
}
|
}
|
||||||
else if (! strcasecmp (aTypeStr, "lch"))
|
anArgIter += 2;
|
||||||
{
|
aColor.ChangeRGB().SetValues (anInput[0], anInput[1], anInput[2], aTypeFrom);
|
||||||
aType = Quantity_TOC_CIELch;
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cerr << "Error: unknown colorspace type: " << aTypeStr << std::endl;
|
theDI << "Syntax error: unknown argument '" << theArgVec[anArgIter] << "'";
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
double aC1 = Draw::Atof (theArgVec[3]);
|
if (toPrintHex)
|
||||||
double aC2 = Draw::Atof (theArgVec[4]);
|
{
|
||||||
double aC3 = Draw::Atof (theArgVec[5]);
|
if (hasAlpha || aColor.Alpha() < 1.0f)
|
||||||
|
{
|
||||||
Quantity_Color aColor (aC1, aC2, aC3, convertFrom ? aType : Quantity_TOC_RGB);
|
theDI << Quantity_ColorRGBA::ColorToHex (aColor);
|
||||||
aColor.Values (aC1, aC2, aC3, convertFrom ? Quantity_TOC_RGB : aType);
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
theDI << Quantity_Color::ColorToHex (aColor.GetRGB());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (toPrintName)
|
||||||
|
{
|
||||||
|
theDI << Quantity_Color::StringName (aColor.GetRGB().Name());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
double anOutput[3] = {};
|
||||||
|
aColor.GetRGB().Values (anOutput[0], anOutput[1], anOutput[2], aTypeTo);
|
||||||
|
|
||||||
// print values with 6 decimal digits
|
// print values with 6 decimal digits
|
||||||
char buffer[1024];
|
char aBuffer[1024];
|
||||||
Sprintf (buffer, "%.6f %.6f %.6f", aC1, aC2, aC3);
|
if (hasAlpha || aColor.Alpha() < 1.0f)
|
||||||
theDI << buffer;
|
{
|
||||||
|
Sprintf (aBuffer, "%.6f %.6f %.6f %.6f", anOutput[0], anOutput[1], anOutput[2], aColor.Alpha());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Sprintf (aBuffer, "%.6f %.6f %.6f", anOutput[0], anOutput[1], anOutput[2]);
|
||||||
|
}
|
||||||
|
theDI << aBuffer;
|
||||||
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -14799,10 +14854,11 @@ Displays interactive view manipulation object. Options:
|
|||||||
)" /* [vviewcube] */);
|
)" /* [vviewcube] */);
|
||||||
|
|
||||||
addCmd ("vcolorconvert", VColorConvert, /* [vcolorconvert] */ R"(
|
addCmd ("vcolorconvert", VColorConvert, /* [vcolorconvert] */ R"(
|
||||||
vcolorconvert {from|to} type C1 C2 C2
|
vcolorconvert [-from {sRGB|HLS|Lab|Lch|RGB}]=RGB [-to {sRGB|HLS|Lab|Lch|RGB|hex|name}]=RGB C1 C2 C2
|
||||||
vcolorconvert from type C1 C2 C2 : Converts color from specified color space to linear RGB
|
To convert color from specified color space to linear RGB:
|
||||||
vcolorconvert to type R G B : Converts linear RGB color to specified color space
|
vcolorconvert -from {sRGB|HLS|Lab|Lch|RGB} C1 C2 C2
|
||||||
Type can be sRGB, HLS, Lab, or Lch.
|
To convert linear RGB color to specified color space:
|
||||||
|
vcolorconvert -to {sRGB|HLS|Lab|Lch|RGB|hex|name} R G B
|
||||||
)" /* [vcolorconvert] */);
|
)" /* [vcolorconvert] */);
|
||||||
|
|
||||||
addCmd ("vcolordiff", VColorDiff, /* [vcolordiff] */ R"(
|
addCmd ("vcolordiff", VColorDiff, /* [vcolordiff] */ R"(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user