ACF $AcfVersion:0$
Public Types | Public Member Functions | List of all members
icmm::CLab Class Reference

Primitive for representation of CIE Lab color values. More...

#include <CLab.h>

Inheritance diagram for icmm::CLab:
icmm::TComposedColor< 3 > imath::TVector< Size, Element > iser::ISerializable istd::IChangeable istd::IPolymorphic

Public Types

enum  ComponentIndex { CI_L , CI_A , CI_B }
 
typedef TComposedColor< 3 > BaseClass
 
- Public Types inherited from icmm::TComposedColor< 3 >
typedef imath::TVector< Size > BaseClass
 
typedef BaseClass::Elements Elements
 
- Public Types inherited from imath::TVector< Size, Element >
typedef Element ElementType
 
typedef Element Elements[Size]
 
- Public Types inherited from istd::IChangeable
enum  ChangeFlags {
  CF_ACF_INTERNAL = 0 , CF_ALL_DATA , CF_ANY , CF_DESTROYING ,
  CF_DELEGATED , CF_NO_UNDO
}
 Data model change notification flags. More...
 
enum  SupportedOperations {
  SO_NONE = 0 , SO_OBSERVE = 1 << 0 , SO_COPY = 1 << 1 , SO_CLONE = 1 << 2 ,
  SO_COMPARE = 1 << 3 , SO_RESET = 1 << 4
}
 Flags for supported operations. More...
 
enum  CompatibilityMode { CM_STRICT , CM_WITHOUT_REFS , CM_WITH_REFS , CM_CONVERT }
 Control how relationship betweeen objects are interpreted. More...
 
typedef QMultiMap< QByteArray, QVariant > ChangeInfoMap
 

Public Member Functions

 CLab (double l=0.0, double a=0.0, double b=0.0)
 
 CLab (const CLab &color)
 
double GetL () const
 
void SetL (double value)
 
double GetA () const
 
void SetA (double value)
 
double GetB () const
 
void SetB (double value)
 
virtual bool Serialize (iser::IArchive &archive) override
 Load or store state of this object as a archive stream.
 
double GetDeltaE (const CLab &lab) const
 
CLab operator+ (const CLab &color) const
 
CLab operator- (const CLab &color) const
 
CLab operator* (const CLab &color) const
 
CLab operator/ (const CLab &color) const
 
CLab operator* (double value) const
 
CLab operator/ (double value) const
 
CLaboperator= (const CLab &color)
 
const CLaboperator+= (const CLab &color)
 
const CLaboperator-= (const CLab &color)
 
const CLaboperator*= (const CLab &color)
 
const CLaboperator/= (const CLab &color)
 
const CLaboperator*= (double value)
 
const CLaboperator/= (double value)
 
- Public Member Functions inherited from icmm::TComposedColor< 3 >
 TComposedColor ()
 
 TComposedColor (const BaseClass &value)
 
 TComposedColor (const imath::CVarVector &vector)
 
 TComposedColor (const TComposedColor< Size > &color)=default
 
void GetRounded (const imath::IDoubleManip &manipulator, TComposedColor< Size > &result)
 Get color after components value rounding with specified precision.
 
bool IsRoundedEqual (const TComposedColor< Size > &color, const imath::IDoubleManip &manipulator) const
 Check if two values are equal after rounding.
 
bool IsSimilar (const TComposedColor< Size > &color, double tolerance=I_BIG_EPSILON) const
 Allows to compare two colors with tolerance.
 
bool IsNormalized () const
 Check if this color value is normalized.
 
void Normalize ()
 Make this color to be normalized.
 
void GetNormalized (TComposedColor< Size > &result) const
 Get normalized color.
 
TComposedColor< Size > operator+ (const TComposedColor< Size > &color) const
 
TComposedColor< Size > operator- (const TComposedColor< Size > &color) const
 
TComposedColor< Size > operator* (const TComposedColor< Size > &color) const
 
TComposedColor< Size > operator* (double value) const
 
TComposedColor< Size > operator/ (const TComposedColor< Size > &color) const
 
TComposedColor< Size > operator/ (double value) const
 
const TComposedColor< Size > & operator= (const TComposedColor< Size > &color)
 
const TComposedColor< Size > & operator= (double colorValue)
 
const TComposedColor< Size > & operator+= (const TComposedColor< Size > &color)
 
const TComposedColor< Size > & operator-= (const TComposedColor< Size > &color)
 
const TComposedColor< Size > & operator*= (const TComposedColor< Size > &color)
 
const TComposedColor< Size > & operator*= (double value)
 
const TComposedColor< Size > & operator/= (const TComposedColor< Size > &color)
 
const TComposedColor< Size > & operator/= (double value)
 
- Public Member Functions inherited from imath::TVector< Size, Element >
 TVector ()
 Creates an uninitialized vector.
 
 TVector (const TVector< Size, Element > &vector)
 Creates a copy of another vector.
 
 TVector (std::initializer_list< Element > values)
 Creates a vector from an initializer list.
 
const Element & GetElement (int i) const
 Gets the element at the specified index (read-only).
 
Element & GetElementRef (int i)
 Gets a reference to the element at the specified index (read-write).
 
void SetElement (int i, const Element &value)
 Sets the element at the specified index.
 
void SetAllElements (const Element &value)
 Sets all elements to the same value.
 
void Reset ()
 Sets all coordinates to zero.
 
void Clear ()
 Sets all coordinates to zero.
 
const TVector< Size, Element >::ElementsGetElements () const
 Get read-only access to internal element container.
 
TVector< Size, Element >::ElementsGetElementsRef ()
 Get access to internal element container.
 
void Translate (const TVector< Size, Element > &vector)
 Translates (adds) another vector to this vector.
 
TVector< Size, Element > GetTranslated (const TVector< Size, Element > &vector)
 Returns a new vector that is the translation of this vector.
 
void GetTranslated (const TVector< Size, Element > &vector, TVector< Size, Element > &result)
 Computes the translated vector and stores it in the result parameter.
 
void ScaledCumulate (const TVector< Size, Element > &vector, Element scale)
 Adds a scaled vector to this vector.
 
bool IsNull (Element tolerance=I_BIG_EPSILON) const
 Checks if this vector is null (all elements approximately zero).
 
Element GetDotProduct (const TVector< Size, Element > &vector) const
 Calculates the dot product with another vector.
 
Element GetLength2 () const
 Calculates the squared Euclidean length of the vector.
 
Element GetLength () const
 Calculates the Euclidean length (magnitude) of the vector.
 
Element GetDistance2 (const TVector< Size, Element > &vector) const
 Calculates the squared distance to another vector.
 
Element GetDistance (const TVector< Size, Element > &vector) const
 Calculates the Euclidean distance to another vector.
 
Element GetElementsSum () const
 Calculates the sum of all vector elements.
 
bool Normalize (Element length=1.0)
 Normalizes the vector to a specified length.
 
bool GetNormalized (TVector< Size, Element > &result, Element length=1.0) const
 Returns a normalized copy of this vector with specified length.
 
void GetMinimal (const TVector< Size, Element > &vector, TVector< Size, Element > &result) const
 Get vector with minimal elements values.
 
void GetMaximal (const TVector< Size, Element > &vector, TVector< Size, Element > &result) const
 Get vector with maximal elements values.
 
bool Serialize (iser::IArchive &archive)
 Serialize this vector to specified archive.
 
bool operator== (const TVector< Size, Element > &vector) const
 
bool operator!= (const TVector< Size, Element > &vector) const
 
bool operator< (const TVector< Size, Element > &vector) const
 
bool operator> (const TVector< Size, Element > &vector) const
 
bool operator<= (const TVector< Size, Element > &vector) const
 
bool operator>= (const TVector< Size, Element > &vector) const
 
TVector< Size, Element > & operator= (const TVector< Size, Element > &vector)=default
 
TVector< Size, Element > operator- () const
 
TVector< Size, Element > operator+ (const TVector< Size, Element > &vector) const
 
TVector< Size, Element > operator- (const TVector< Size, Element > &vector) const
 
TVector< Size, Element > operator* (Element scalar) const
 
TVector< Size, Element > operator/ (Element scalar) const
 
TVector< Size, Element > & operator+= (const TVector< Size, Element > &vector)
 
TVector< Size, Element > & operator-= (const TVector< Size, Element > &vector)
 
TVector< Size, Element > & operator*= (Element scalar)
 
TVector< Size, Element > & operator/= (Element scalar)
 
const Element & operator[] (int i) const
 
Element & operator[] (int i)
 
- Public Member Functions inherited from iser::ISerializable
virtual quint32 GetMinimalVersion (int versionId) const
 Get minimal needed version to correct storing of this data.
 
- Public Member Functions inherited from istd::IChangeable
virtual int GetSupportedOperations () const
 Get set of flags for supported operations.
 
virtual bool CopyFrom (const IChangeable &object, CompatibilityMode mode=CM_WITHOUT_REFS)
 Copy this object from another one.
 
virtual bool IsEqual (const IChangeable &object) const
 Compare this object with another object.
 
virtual istd::TUniqueInterfacePtr< istd::IChangeableCloneMe (CompatibilityMode mode=CM_WITHOUT_REFS) const
 Make a copy of this object.
 
virtual bool ResetData (CompatibilityMode mode=CM_WITHOUT_REFS)
 Reset data to its default state.
 
virtual void BeginChanges (const ChangeSet &changeSet)
 Starts the change transaction.
 
virtual void EndChanges (const ChangeSet &changeSet)
 Ends the change transaction.
 
virtual void BeginChangeGroup (const ChangeSet &changeSet)
 Starts group of changes.
 
virtual void EndChangeGroup (const ChangeSet &changeSet)
 Ends group of changes.
 
- Public Member Functions inherited from istd::IPolymorphic
virtual ~IPolymorphic ()
 

Additional Inherited Members

- Static Public Member Functions inherited from imath::TVector< Size, Element >
static int GetElementsCount ()
 Get number of elements.
 
static bool SetElementsCount (int count)
 Set number of elements.
 
static const TVector< Size, Element > & GetZero ()
 Get vector with all coordinates set to 0.
 
- Static Public Member Functions inherited from istd::IChangeable
static const ChangeSetGetNoChanges ()
 Get empty set of changes.
 
static const ChangeSetGetAnyChange ()
 Get anonymous change set.
 
static const ChangeSetGetAllChanges ()
 Get anonymous change set.
 
static const ChangeSetGetDelegatedChanges ()
 Get delegated change set.
 
- Protected Member Functions inherited from istd::IChangeable
virtual void OnBeginChanges ()
 Callback function for begin change event.
 
virtual void OnEndChanges (const ChangeSet &changeSet)
 Callback function for end change event.
 
- Protected Attributes inherited from imath::TVector< Size, Element >
Elements m_elements
 

Detailed Description

Primitive for representation of CIE Lab color values.

Purpose

CLab represents colors in the CIE L*a*b* color space, a device-independent, perceptually uniform color model designed to approximate human vision. Unlike RGB or CMYK, Lab is designed so that the numerical difference between two colors corresponds to the perceptual difference seen by humans. This makes it ideal for color comparison, color correction, and gamut mapping.

CIE Lab Color Space

Lab consists of three coordinates:

The a* and b* axes represent opponent color dimensions:

Lab Advantages

Perceptual Uniformity:**

Usage Examples

// Example 1: Creating Lab colors
icmm::CLab white(100.0, 0.0, 0.0); // L=100, neutral
icmm::CLab black(0.0, 0.0, 0.0); // L=0, neutral
icmm::CLab midGray(50.0, 0.0, 0.0); // L=50, neutral
icmm::CLab red(53.0, 80.0, 67.0); // Typical red
icmm::CLab green(88.0, -86.0, 83.0); // Typical green
icmm::CLab blue(32.0, 79.0, -108.0); // Typical blue
// Example 2: Component access
icmm::CLab color;
color.SetL(75.0); // Lightness
color.SetA(25.0); // Red direction
color.SetB(-30.0); // Blue direction
double lightness = color.GetL();
double a = color.GetA();
double b = color.GetB();
// Example 3: Calculating color difference (DeltaE)
double CompareColors(const icmm::CLab& color1, const icmm::CLab& color2)
{
// DeltaE76 formula (CIE 1976)
double deltaE = color1.GetDeltaE(color2);
// Interpretation of DeltaE:
// < 1.0: Imperceptible difference
// 1-2: Perceptible by close observation
// 2-10: Perceptible at a glance
// 11-49: Colors are more similar than opposite
// 100: Colors are exact opposites
return deltaE;
}
icmm::CLab lab1(50.0, 10.0, 20.0);
icmm::CLab lab2(52.0, 12.0, 18.0);
double difference = CompareColors(lab1, lab2); // Small difference
// Example 4: Finding closest color in palette
icmm::CLab FindClosestColor(const icmm::CLab& target,
const QList<icmm::CLab>& palette)
{
if (palette.isEmpty()) return icmm::CLab();
icmm::CLab closest = palette[0];
double minDeltaE = target.GetDeltaE(closest);
for (const icmm::CLab& color : palette) {
double deltaE = target.GetDeltaE(color);
if (deltaE < minDeltaE) {
minDeltaE = deltaE;
closest = color;
}
}
return closest;
}
// Example 5: Adjusting lightness
icmm::CLab AdjustLightness(const icmm::CLab& color, double factor)
{
icmm::CLab result = color;
double newL = color.GetL() * factor;
result.SetL(qBound(0.0, newL, 100.0)); // Clamp to valid range
return result;
}
icmm::CLab dark = AdjustLightness(original, 0.7); // Darker
icmm::CLab light = AdjustLightness(original, 1.3); // Lighter
// Example 6: Checking if color is neutral (gray)
bool IsNeutral(const icmm::CLab& color, double tolerance = 5.0)
{
// Neutral colors have a* and b* near zero
return (qAbs(color.GetA()) < tolerance &&
qAbs(color.GetB()) < tolerance);
}
// Example 7: Color quality control
struct ColorTolerance {
double maxDeltaE;
bool isAcceptable;
};
ColorTolerance CheckColorAccuracy(const icmm::CLab& reference,
const icmm::CLab& sample,
double tolerance = 2.0)
{
ColorTolerance result;
result.maxDeltaE = reference.GetDeltaE(sample);
result.isAcceptable = (result.maxDeltaE <= tolerance);
return result;
}
// Example 8: Gamut mapping - checking if color is displayable
bool IsInSRgbGamut(const icmm::CLab& labColor)
{
// Convert to RGB (via transformation)
// Check if RGB components are in [0, 1]
// This is simplified - actual implementation uses transformations
icmm::CRgb rgb = ConvertLabToRgb(labColor);
return (rgb.GetRed() >= 0.0 && rgb.GetRed() <= 1.0 &&
rgb.GetGreen() >= 0.0 && rgb.GetGreen() <= 1.0 &&
rgb.GetBlue() >= 0.0 && rgb.GetBlue() <= 1.0);
}
// Example 9: Perceptual color blending
icmm::CLab BlendLabColors(const icmm::CLab& a,
const icmm::CLab& b,
double t) // 0 to 1
{
// Linear interpolation in Lab space gives perceptual blending
return icmm::CLab(
a.GetL() * (1.0 - t) + b.GetL() * t,
a.GetA() * (1.0 - t) + b.GetA() * t,
a.GetB() * (1.0 - t) + b.GetB() * t
);
}
Primitive for representation of CIE Lab color values.
Definition CLab.h:215
double GetA() const
Definition CLab.h:292
double GetB() const
Definition CLab.h:304
double GetL() const
Definition CLab.h:280
void SetL(double value)
Definition CLab.h:286
void SetB(double value)
Definition CLab.h:310
double GetDeltaE(const CLab &lab) const
void SetA(double value)
Definition CLab.h:298
Primitive for representation of RGB color values.
Definition CRgb.h:168
double GetBlue() const
Definition CRgb.h:256
double GetGreen() const
Definition CRgb.h:244
double GetRed() const
Definition CRgb.h:232

Delta E (DeltaE) Color Difference

The DeltaE value quantifies the perceptual difference between two colors:

DeltaE76 (CIE 1976):**

Common Applications

Best Practices

Note
In ACF, component values are normalized to [0, 1] range internally, but represent the actual Lab ranges (L: 0-100, a: -128 to +127, b: -128 to +127)
See also
icmm::TComposedColor, icmm::CCieLabColorModel, icmm::CXyzToCieLabTransformation, icmm::CCieLabColor

Definition at line 214 of file CLab.h.

Member Typedef Documentation

◆ BaseClass

Definition at line 217 of file CLab.h.

Member Enumeration Documentation

◆ ComponentIndex

Enumerator
CI_L 
CI_A 
CI_B 

Definition at line 219 of file CLab.h.

Constructor & Destructor Documentation

◆ CLab() [1/2]

icmm::CLab::CLab ( double  l = 0.0,
double  a = 0.0,
double  b = 0.0 
)
inline

Definition at line 264 of file CLab.h.

References CI_A, CI_B, CI_L, and imath::TVector< Size, Element >::SetElement().

◆ CLab() [2/2]

icmm::CLab::CLab ( const CLab color)
inline

Definition at line 272 of file CLab.h.

Member Function Documentation

◆ GetA()

double icmm::CLab::GetA ( ) const
inline

Definition at line 292 of file CLab.h.

References CI_A, and imath::TVector< Size, Element >::GetElement().

◆ GetB()

double icmm::CLab::GetB ( ) const
inline

Definition at line 304 of file CLab.h.

References CI_B, and imath::TVector< Size, Element >::GetElement().

◆ GetDeltaE()

double icmm::CLab::GetDeltaE ( const CLab lab) const

◆ GetL()

double icmm::CLab::GetL ( ) const
inline

Definition at line 280 of file CLab.h.

References CI_L, and imath::TVector< Size, Element >::GetElement().

◆ operator*() [1/2]

CLab icmm::CLab::operator* ( const CLab color) const
inline

Definition at line 338 of file CLab.h.

◆ operator*() [2/2]

CLab icmm::CLab::operator* ( double  value) const
inline

Definition at line 358 of file CLab.h.

◆ operator*=() [1/2]

const CLab & icmm::CLab::operator*= ( const CLab color)
inline

Definition at line 402 of file CLab.h.

References icmm::TComposedColor< 3 >::operator*=().

◆ operator*=() [2/2]

const CLab & icmm::CLab::operator*= ( double  value)
inline

Definition at line 418 of file CLab.h.

References icmm::TComposedColor< 3 >::operator*=().

◆ operator+()

CLab icmm::CLab::operator+ ( const CLab color) const
inline

Definition at line 318 of file CLab.h.

◆ operator+=()

const CLab & icmm::CLab::operator+= ( const CLab color)
inline

Definition at line 386 of file CLab.h.

References icmm::TComposedColor< 3 >::operator+=().

◆ operator-()

CLab icmm::CLab::operator- ( const CLab color) const
inline

Definition at line 328 of file CLab.h.

◆ operator-=()

const CLab & icmm::CLab::operator-= ( const CLab color)
inline

Definition at line 394 of file CLab.h.

References icmm::TComposedColor< 3 >::operator-=().

◆ operator/() [1/2]

CLab icmm::CLab::operator/ ( const CLab color) const
inline

Definition at line 348 of file CLab.h.

◆ operator/() [2/2]

CLab icmm::CLab::operator/ ( double  value) const
inline

Definition at line 368 of file CLab.h.

◆ operator/=() [1/2]

const CLab & icmm::CLab::operator/= ( const CLab color)
inline

Definition at line 410 of file CLab.h.

References icmm::TComposedColor< 3 >::operator/=().

◆ operator/=() [2/2]

const CLab & icmm::CLab::operator/= ( double  value)
inline

Definition at line 426 of file CLab.h.

References icmm::TComposedColor< 3 >::operator/=().

◆ operator=()

CLab & icmm::CLab::operator= ( const CLab color)
inline

Definition at line 378 of file CLab.h.

References icmm::TComposedColor< 3 >::operator=().

◆ Serialize()

virtual bool icmm::CLab::Serialize ( iser::IArchive archive)
overridevirtual

Load or store state of this object as a archive stream.

Type of operation is depending on archive type.

See also
iser::IArchive

Reimplemented from icmm::TComposedColor< 3 >.

◆ SetA()

void icmm::CLab::SetA ( double  value)
inline

Definition at line 298 of file CLab.h.

References CI_A, and imath::TVector< Size, Element >::SetElement().

◆ SetB()

void icmm::CLab::SetB ( double  value)
inline

Definition at line 310 of file CLab.h.

References CI_B, and imath::TVector< Size, Element >::SetElement().

◆ SetL()

void icmm::CLab::SetL ( double  value)
inline

Definition at line 286 of file CLab.h.

References CI_L, and imath::TVector< Size, Element >::SetElement().


The documentation for this class was generated from the following file: