1
0
mirror of https://git.dev.opencascade.org/repos/occt.git synced 2025-08-14 13:30:48 +03:00

0030969: Coding Rules - refactor Quantity_Color.cxx color table definition

The table of named colors has been compressed and moved out
from Quantity_Color.cxx into Quantity_ColorTable.pxx.

Quantity_NameOfColor - grayscale enumeration values have been re-ordered to fix discontinuity.
Duplicating colors has been merged within enumeration:
  CHARTREUSE=CHARTREUSE1, GOLD=GOLD1, GREEN=GREEN1, ORANGE=ORANGE1,
  ORANGERED=ORANGERED1, RED=RED1, TOMATO=TOMATO1, YELLOW=YELLOW1.
Added aliases to several other common colors:
  BLUE=BLUE1, CYAN=CYAN1, LIGHTCYAN=LIGHTCYAN1, MAGENTA=MAGENTA1.

Quantity_Color class definition has been cleaned to follow OCCT coding style.
Quantity_Color now stores NCollection_Vec3<float> as class field instead of separate components.
Removed unused class Quantity_ColorDefinitionError.

New methods Quantity_Color::Convert_LinearRGB_To_sRGB() and Quantity_Color::Convert_sRGB_To_LinearRGB()
converting RGB components from linear to non-linear sRGB colorspace and vice versa.
Image_PixMap::PixelColor() and Image_PixMap::SetPixelColor() methods have been extended
with an optional argument for performing linearization/delinearization of 8-bit sRGB pixel formats.

Draw Harness command AISColor has been corrected to take color name instead of enumeration index.
This commit is contained in:
kgv
2019-09-16 23:06:38 +03:00
committed by apn
parent b008226203
commit aaf8d6a98d
444 changed files with 2134 additions and 5011 deletions

View File

@@ -192,7 +192,8 @@ void Image_PixMap::Clear()
// purpose :
// =======================================================================
Quantity_ColorRGBA Image_PixMap::PixelColor (const Standard_Integer theX,
const Standard_Integer theY) const
const Standard_Integer theY,
const Standard_Boolean theToLinearize) const
{
if (IsEmpty()
|| theX < 0 || (Standard_Size )theX >= SizeX()
@@ -236,32 +237,58 @@ Quantity_ColorRGBA Image_PixMap::PixelColor (const Standard_Integer theX,
case Image_Format_RGBA:
{
const Image_ColorRGBA& aPixel = Value<Image_ColorRGBA> (theY, theX);
return Quantity_ColorRGBA (float(aPixel.r()) / 255.0f, float(aPixel.g()) / 255.0f, float(aPixel.b()) / 255.0f, float(aPixel.a()) / 255.0f);
return theToLinearize
? Quantity_ColorRGBA (Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.r()) / 255.0f),
Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.g()) / 255.0f),
Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.b()) / 255.0f),
float(aPixel.a()) / 255.0f)
: Quantity_ColorRGBA (float(aPixel.r()) / 255.0f, float(aPixel.g()) / 255.0f, float(aPixel.b()) / 255.0f, float(aPixel.a()) / 255.0f);
}
case Image_Format_BGRA:
{
const Image_ColorBGRA& aPixel = Value<Image_ColorBGRA> (theY, theX);
return Quantity_ColorRGBA (float(aPixel.r()) / 255.0f, float(aPixel.g()) / 255.0f, float(aPixel.b()) / 255.0f, float(aPixel.a()) / 255.0f);
return theToLinearize
? Quantity_ColorRGBA (Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.r()) / 255.0f),
Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.g()) / 255.0f),
Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.b()) / 255.0f),
float(aPixel.a()) / 255.0f)
: Quantity_ColorRGBA (float(aPixel.r()) / 255.0f, float(aPixel.g()) / 255.0f, float(aPixel.b()) / 255.0f, float(aPixel.a()) / 255.0f);
}
case Image_Format_RGB32:
{
const Image_ColorRGB32& aPixel = Value<Image_ColorRGB32> (theY, theX);
return Quantity_ColorRGBA (float(aPixel.r()) / 255.0f, float(aPixel.g()) / 255.0f, float(aPixel.b()) / 255.0f, 1.0f); // opaque
return theToLinearize
? Quantity_ColorRGBA (Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.r()) / 255.0f),
Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.g()) / 255.0f),
Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.b()) / 255.0f), 1.0f)
: Quantity_ColorRGBA (float(aPixel.r()) / 255.0f, float(aPixel.g()) / 255.0f, float(aPixel.b()) / 255.0f, 1.0f);
}
case Image_Format_BGR32:
{
const Image_ColorBGR32& aPixel = Value<Image_ColorBGR32> (theY, theX);
return Quantity_ColorRGBA (float(aPixel.r()) / 255.0f, float(aPixel.g()) / 255.0f, float(aPixel.b()) / 255.0f, 1.0f); // opaque
return theToLinearize
? Quantity_ColorRGBA (Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.r()) / 255.0f),
Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.g()) / 255.0f),
Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.b()) / 255.0f), 1.0f)
: Quantity_ColorRGBA (float(aPixel.r()) / 255.0f, float(aPixel.g()) / 255.0f, float(aPixel.b()) / 255.0f, 1.0f);
}
case Image_Format_RGB:
{
const Image_ColorRGB& aPixel = Value<Image_ColorRGB> (theY, theX);
return Quantity_ColorRGBA (float(aPixel.r()) / 255.0f, float(aPixel.g()) / 255.0f, float(aPixel.b()) / 255.0f, 1.0f); // opaque
return theToLinearize
? Quantity_ColorRGBA (Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.r()) / 255.0f),
Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.g()) / 255.0f),
Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.b()) / 255.0f), 1.0f)
: Quantity_ColorRGBA (float(aPixel.r()) / 255.0f, float(aPixel.g()) / 255.0f, float(aPixel.b()) / 255.0f, 1.0f);
}
case Image_Format_BGR:
{
const Image_ColorBGR& aPixel = Value<Image_ColorBGR> (theY, theX);
return Quantity_ColorRGBA (float(aPixel.r()) / 255.0f, float(aPixel.g()) / 255.0f, float(aPixel.b()) / 255.0f, 1.0f); // opaque
return theToLinearize
? Quantity_ColorRGBA (Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.r()) / 255.0f),
Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.g()) / 255.0f),
Quantity_Color::Convert_sRGB_To_LinearRGB (float(aPixel.b()) / 255.0f), 1.0f)
: Quantity_ColorRGBA (float(aPixel.r()) / 255.0f, float(aPixel.g()) / 255.0f, float(aPixel.b()) / 255.0f, 1.0f);
}
case Image_Format_Gray:
{
@@ -289,7 +316,8 @@ Quantity_ColorRGBA Image_PixMap::PixelColor (const Standard_Integer theX,
// =======================================================================
void Image_PixMap::SetPixelColor (const Standard_Integer theX,
const Standard_Integer theY,
const Quantity_ColorRGBA& theColor)
const Quantity_ColorRGBA& theColor,
const Standard_Boolean theToDeLinearize)
{
if (IsEmpty()
|| theX < 0 || Standard_Size(theX) >= SizeX()
@@ -348,53 +376,107 @@ void Image_PixMap::SetPixelColor (const Standard_Integer theX,
case Image_Format_RGBA:
{
Image_ColorRGBA& aPixel = ChangeValue<Image_ColorRGBA> (theY, theX);
aPixel.r() = Standard_Byte(aColor.r() * 255.0f);
aPixel.g() = Standard_Byte(aColor.g() * 255.0f);
aPixel.b() = Standard_Byte(aColor.b() * 255.0f);
if (theToDeLinearize)
{
aPixel.r() = Standard_Byte(Quantity_Color::Convert_LinearRGB_To_sRGB (aColor.r()) * 255.0f);
aPixel.g() = Standard_Byte(Quantity_Color::Convert_LinearRGB_To_sRGB (aColor.g()) * 255.0f);
aPixel.b() = Standard_Byte(Quantity_Color::Convert_LinearRGB_To_sRGB (aColor.b()) * 255.0f);
}
else
{
aPixel.r() = Standard_Byte(aColor.r() * 255.0f);
aPixel.g() = Standard_Byte(aColor.g() * 255.0f);
aPixel.b() = Standard_Byte(aColor.b() * 255.0f);
}
aPixel.a() = Standard_Byte(aColor.a() * 255.0f);
return;
}
case Image_Format_BGRA:
{
Image_ColorBGRA& aPixel = ChangeValue<Image_ColorBGRA> (theY, theX);
aPixel.r() = Standard_Byte(aColor.r() * 255.0f);
aPixel.g() = Standard_Byte(aColor.g() * 255.0f);
aPixel.b() = Standard_Byte(aColor.b() * 255.0f);
if (theToDeLinearize)
{
aPixel.r() = Standard_Byte(Quantity_Color::Convert_LinearRGB_To_sRGB (aColor.r()) * 255.0f);
aPixel.g() = Standard_Byte(Quantity_Color::Convert_LinearRGB_To_sRGB (aColor.g()) * 255.0f);
aPixel.b() = Standard_Byte(Quantity_Color::Convert_LinearRGB_To_sRGB (aColor.b()) * 255.0f);
}
else
{
aPixel.r() = Standard_Byte(aColor.r() * 255.0f);
aPixel.g() = Standard_Byte(aColor.g() * 255.0f);
aPixel.b() = Standard_Byte(aColor.b() * 255.0f);
}
aPixel.a() = Standard_Byte(aColor.a() * 255.0f);
return;
}
case Image_Format_RGB32:
{
Image_ColorRGB32& aPixel = ChangeValue<Image_ColorRGB32> (theY, theX);
aPixel.r() = Standard_Byte(aColor.r() * 255.0f);
aPixel.g() = Standard_Byte(aColor.g() * 255.0f);
aPixel.b() = Standard_Byte(aColor.b() * 255.0f);
if (theToDeLinearize)
{
aPixel.r() = Standard_Byte(Quantity_Color::Convert_LinearRGB_To_sRGB (aColor.r()) * 255.0f);
aPixel.g() = Standard_Byte(Quantity_Color::Convert_LinearRGB_To_sRGB (aColor.g()) * 255.0f);
aPixel.b() = Standard_Byte(Quantity_Color::Convert_LinearRGB_To_sRGB (aColor.b()) * 255.0f);
}
else
{
aPixel.r() = Standard_Byte(aColor.r() * 255.0f);
aPixel.g() = Standard_Byte(aColor.g() * 255.0f);
aPixel.b() = Standard_Byte(aColor.b() * 255.0f);
}
aPixel.a_() = 255;
return;
}
case Image_Format_BGR32:
{
Image_ColorBGR32& aPixel = ChangeValue<Image_ColorBGR32> (theY, theX);
aPixel.r() = Standard_Byte(aColor.r() * 255.0f);
aPixel.g() = Standard_Byte(aColor.g() * 255.0f);
aPixel.b() = Standard_Byte(aColor.b() * 255.0f);
if (theToDeLinearize)
{
aPixel.r() = Standard_Byte(Quantity_Color::Convert_LinearRGB_To_sRGB (aColor.r()) * 255.0f);
aPixel.g() = Standard_Byte(Quantity_Color::Convert_LinearRGB_To_sRGB (aColor.g()) * 255.0f);
aPixel.b() = Standard_Byte(Quantity_Color::Convert_LinearRGB_To_sRGB (aColor.b()) * 255.0f);
}
else
{
aPixel.r() = Standard_Byte(aColor.r() * 255.0f);
aPixel.g() = Standard_Byte(aColor.g() * 255.0f);
aPixel.b() = Standard_Byte(aColor.b() * 255.0f);
}
aPixel.a_() = 255;
return;
}
case Image_Format_RGB:
{
Image_ColorRGB& aPixel = ChangeValue<Image_ColorRGB> (theY, theX);
aPixel.r() = Standard_Byte(aColor.r() * 255.0f);
aPixel.g() = Standard_Byte(aColor.g() * 255.0f);
aPixel.b() = Standard_Byte(aColor.b() * 255.0f);
if (theToDeLinearize)
{
aPixel.r() = Standard_Byte(Quantity_Color::Convert_LinearRGB_To_sRGB (aColor.r()) * 255.0f);
aPixel.g() = Standard_Byte(Quantity_Color::Convert_LinearRGB_To_sRGB (aColor.g()) * 255.0f);
aPixel.b() = Standard_Byte(Quantity_Color::Convert_LinearRGB_To_sRGB (aColor.b()) * 255.0f);
}
else
{
aPixel.r() = Standard_Byte(aColor.r() * 255.0f);
aPixel.g() = Standard_Byte(aColor.g() * 255.0f);
aPixel.b() = Standard_Byte(aColor.b() * 255.0f);
}
return;
}
case Image_Format_BGR:
{
Image_ColorBGR& aPixel = ChangeValue<Image_ColorBGR> (theY, theX);
aPixel.r() = Standard_Byte(aColor.r() * 255.0f);
aPixel.g() = Standard_Byte(aColor.g() * 255.0f);
aPixel.b() = Standard_Byte(aColor.b() * 255.0f);
if (theToDeLinearize)
{
aPixel.r() = Standard_Byte(Quantity_Color::Convert_LinearRGB_To_sRGB (aColor.r()) * 255.0f);
aPixel.g() = Standard_Byte(Quantity_Color::Convert_LinearRGB_To_sRGB (aColor.g()) * 255.0f);
aPixel.b() = Standard_Byte(Quantity_Color::Convert_LinearRGB_To_sRGB (aColor.b()) * 255.0f);
}
else
{
aPixel.r() = Standard_Byte(aColor.r() * 255.0f);
aPixel.g() = Standard_Byte(aColor.g() * 255.0f);
aPixel.b() = Standard_Byte(aColor.b() * 255.0f);
}
return;
}
case Image_Format_Gray:

View File

@@ -102,26 +102,38 @@ public: // high-level API
//! Returns the pixel color. This function is relatively slow.
//! Beware that this method takes coordinates in opposite order in contrast to ::Value() and ::ChangeValue().
//! @param theX column index from left
//! @param theY row index from top
//! @param theX [in] column index from left
//! @param theY [in] row index from top
//! @param theToLinearize [in] when TRUE, the color stored in non-linear color space (e.g. Image_Format_RGB) will be linearized
//! @return the pixel color
Standard_EXPORT Quantity_ColorRGBA PixelColor (const Standard_Integer theX,
const Standard_Integer theY) const;
const Standard_Integer theY,
const Standard_Boolean theToLinearize = Standard_False) const;
//! Sets the pixel color. This function is relatively slow.
//! Beware that this method takes coordinates in opposite order in contrast to ::Value() and ::ChangeValue().
//! @param theX [in] column index from left
//! @param theY [in] row index from top
//! @param theColor [in] color to store
//! @param theToDeLinearize [in] when TRUE, the gamma correction will be applied for storing in non-linear color space (e.g. Image_Format_RGB)
void SetPixelColor (const Standard_Integer theX,
const Standard_Integer theY,
const Quantity_Color& theColor)
const Quantity_Color& theColor,
const Standard_Boolean theToDeLinearize = Standard_False)
{
SetPixelColor (theX, theY, Quantity_ColorRGBA (theColor, 1.0f));
SetPixelColor (theX, theY, Quantity_ColorRGBA (theColor, 1.0f), theToDeLinearize);
}
//! Sets the pixel color. This function is relatively slow.
//! Beware that this method takes coordinates in opposite order in contrast to ::Value() and ::ChangeValue().
//! @param theX [in] column index from left
//! @param theY [in] row index from top
//! @param theColor [in] color to store
//! @param theToDeLinearize [in] when TRUE, the gamma correction will be applied for storing in non-linear color space (e.g. Image_Format_RGB)
Standard_EXPORT void SetPixelColor (const Standard_Integer theX,
const Standard_Integer theY,
const Quantity_ColorRGBA& theColor);
const Quantity_ColorRGBA& theColor,
const Standard_Boolean theToDeLinearize = Standard_False);
//! Initialize image plane as wrapper over alien data.
//! Data will not be copied! Notice that caller should ensure