1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-09 13:22:24 +03:00

0030991: Draw Harness - ViewerTest::ParseColor() defines out-of-range alpha component

ViewerTest::ParseColor() - fixed alpha component defined as 255 for RGB-only input.
Quantity_Color::ColorToHex() now rounds-up float values to closest integer.
Quantity_ColorRGBA::ColorToHex() - added method formatting color into hex with alpha component consistent to Quantity_Color::ColorToHex() for RGB.

vdrawtext command now uses ViewerTest::ParseColor() for parsing color argument, so that it accepts hex.
vreadpixel command now has been extended with -hex argument for printing color in hex format.

Commands XSetColor, XGetColor, XGetShapeColor, XGetAllColors, XAddColor, XRemoveColor, XFindColor,
XUnsetColor, XGetInstanceColor, XSetInstanceColor have been corrected to properly report syntax input errors
and to accept color names and hex (by reusing ViewerTest::ParseColor()).
This commit is contained in:
kgv
2019-09-21 17:10:23 +03:00
committed by bugmaster
parent d537c5e67d
commit 9196ea9d5a
11 changed files with 540 additions and 321 deletions

View File

@@ -202,22 +202,17 @@ namespace
{
const Standard_Integer THE_COLOR_COMPONENT_NOT_PARSED = -1;
Graphic3d_Vec4i anIntegerColor (THE_COLOR_COMPONENT_NOT_PARSED);
if (!parseNumericalColor (theNumberOfColorComponents, theColorComponentStrings, anIntegerColor))
if (!parseNumericalColor (theNumberOfColorComponents, theColorComponentStrings, anIntegerColor)
|| anIntegerColor.maxComp() <= 1)
{
return false;
}
const bool hasColorComponentGreaterThanOne = (anIntegerColor.maxComp() > 1);
if (anIntegerColor.a() == THE_COLOR_COMPONENT_NOT_PARSED)
{
anIntegerColor.a() = THE_MAX_INTEGER_COLOR_COMPONENT;
}
Graphic3d_Vec4 aRealColor (anIntegerColor);
if (hasColorComponentGreaterThanOne)
{
aRealColor /= static_cast<Standard_ShortReal> (THE_MAX_INTEGER_COLOR_COMPONENT);
}
const Graphic3d_Vec4 aRealColor = Graphic3d_Vec4 (anIntegerColor) / static_cast<Standard_ShortReal> (THE_MAX_INTEGER_COLOR_COMPONENT);
theColor = Quantity_ColorRGBA (aRealColor);
return true;
}
@@ -284,11 +279,12 @@ Standard_Integer ViewerTest::parseColor (const Standard_Integer theArgNb,
if (theArgNb >= 3)
{
const Standard_Integer aNumberOfColorComponentsToParse = Min (theArgNb, theToParseAlpha ? 4 : 3);
Standard_Integer aNumberOfColorComponentsParsed = aNumberOfColorComponentsToParse;
Standard_Integer aNumberOfColorComponentsParsed = aNumberOfColorComponentsToParse;
if (parseIntegerColor (aNumberOfColorComponentsParsed, theArgVec, theColor))
{
return aNumberOfColorComponentsParsed;
}
aNumberOfColorComponentsParsed = aNumberOfColorComponentsToParse;
if (parseRealColor (aNumberOfColorComponentsParsed, theArgVec, theColor))
{
return aNumberOfColorComponentsParsed;
@@ -2369,6 +2365,11 @@ static Standard_Integer VAspects (Draw_Interpretor& theDI,
aNames.Remove (aNames.Length());
isOk = Standard_True;
}
else if (Quantity_Color::ColorFromHex (aNames.Last().ToCString(), aChangeSet->Color))
{
aNames.Remove (aNames.Length());
isOk = Standard_True;
}
else if (aNames.Length() >= 3)
{
const char* anArgVec[3] =

View File

@@ -2388,42 +2388,17 @@ static int VDrawText (Draw_Interpretor& theDI,
}
else if (aParam == "-color")
{
if (anArgIt + 1 >= theArgsNb)
Quantity_Color aColor;
Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgsNb - anArgIt - 1,
theArgVec + anArgIt + 1,
aColor);
if (aNbParsed == 0)
{
std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
std::cout << "Syntax error at '" << aParam << "'\n";
return 1;
}
TCollection_AsciiString aColor (theArgVec[anArgIt + 1]);
Quantity_NameOfColor aNameOfColor = Quantity_NOC_BLACK;
if (Quantity_Color::ColorFromName (aColor.ToCString(), aNameOfColor))
{
anArgIt += 1;
aTextPrs->SetColor (aNameOfColor);
continue;
}
else if (anArgIt + 3 >= theArgsNb)
{
std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
return 1;
}
TCollection_AsciiString aGreen (theArgVec[anArgIt + 2]);
TCollection_AsciiString aBlue (theArgVec[anArgIt + 3]);
if (!aColor.IsRealValue()
|| !aGreen.IsRealValue()
|| !aBlue.IsRealValue())
{
std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
return 1;
}
const Graphic3d_Vec3d anRGB (aColor.RealValue(),
aGreen.RealValue(),
aBlue.RealValue());
aTextPrs->SetColor (Quantity_Color (anRGB.r(), anRGB.g(), anRGB.b(), Quantity_TOC_RGB));
anArgIt += 3;
anArgIt += aNbParsed;
aTextPrs->SetColor (aColor);
}
else if (aParam == "-halign")
{
@@ -2598,42 +2573,17 @@ static int VDrawText (Draw_Interpretor& theDI,
else if (aParam == "-subcolor"
|| aParam == "-subtitlecolor")
{
if (anArgIt + 1 >= theArgsNb)
Quantity_Color aColor;
Standard_Integer aNbParsed = ViewerTest::ParseColor (theArgsNb - anArgIt - 1,
theArgVec + anArgIt + 1,
aColor);
if (aNbParsed == 0)
{
std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
std::cout << "Syntax error at '" << aParam << "'\n";
return 1;
}
TCollection_AsciiString aColor (theArgVec[anArgIt + 1]);
Quantity_NameOfColor aNameOfColor = Quantity_NOC_BLACK;
if (Quantity_Color::ColorFromName (aColor.ToCString(), aNameOfColor))
{
anArgIt += 1;
aTextPrs->SetColorSubTitle (aNameOfColor);
continue;
}
else if (anArgIt + 3 >= theArgsNb)
{
std::cout << "Error: wrong number of values for parameter '" << aParam.ToCString() << "'.\n";
return 1;
}
TCollection_AsciiString aGreen (theArgVec[anArgIt + 2]);
TCollection_AsciiString aBlue (theArgVec[anArgIt + 3]);
if (!aColor.IsRealValue()
|| !aGreen.IsRealValue()
|| !aBlue.IsRealValue())
{
std::cout << "Error: wrong syntax at '" << aParam.ToCString() << "'.\n";
return 1;
}
const Graphic3d_Vec3d anRGB (aColor.RealValue(),
aGreen.RealValue(),
aBlue.RealValue());
aTextPrs->SetColorSubTitle (Quantity_Color (anRGB.r(), anRGB.g(), anRGB.b(), Quantity_TOC_RGB));
anArgIt += 3;
anArgIt += aNbParsed;
aTextPrs->SetColorSubTitle (aColor);
}
else if (aParam == "-2d")
{

View File

@@ -7042,8 +7042,7 @@ static int VReadPixel (Draw_Interpretor& theDI,
return 1;
}
Standard_Boolean toShowName = Standard_False;
Standard_Boolean toShowHls = Standard_False;
bool toShowName = false, toShowHls = false, toShowHex = false;
for (Standard_Integer anIter = 3; anIter < theArgNb; ++anIter)
{
TCollection_AsciiString aParam (theArgVec[anIter]);
@@ -7090,9 +7089,15 @@ static int VReadPixel (Draw_Interpretor& theDI,
{
toShowName = Standard_True;
}
else if (aParam == "-hex"
|| aParam == "hex")
{
toShowHex = Standard_True;
}
else
{
std::cout << "Syntax error at '" << aParam << "'\n";
return 1;
}
}
@@ -7130,6 +7135,17 @@ static int VReadPixel (Draw_Interpretor& theDI,
theDI << Quantity_Color::StringName (aColor.GetRGB().Name());
}
}
else if (toShowHex)
{
if (aBufferType == Graphic3d_BT_RGBA)
{
theDI << Quantity_ColorRGBA::ColorToHex (aColor);
}
else
{
theDI << Quantity_Color::ColorToHex (aColor.GetRGB());
}
}
else
{
switch (aBufferType)
@@ -13900,7 +13916,7 @@ void ViewerTest::ViewerCommands(Draw_Interpretor& theCommands)
" with f option returns free memory in bytes",
__FILE__, VMemGpu, group);
theCommands.Add ("vreadpixel",
"vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [-name]"
"vreadpixel xPixel yPixel [{rgb|rgba|depth|hls|rgbf|rgbaf}=rgba] [-name|-hex]"
" : Read pixel value for active view",
__FILE__, VReadPixel, group);
theCommands.Add("diffimage",