Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qcolor.cpp File Reference

(4012ab8234e86ba69d66e15155410c6c91ce4673)

#include "qcolor.h"
#include "qcolor_p.h"
#include "qdrawhelper_p.h"
#include "qfloat16.h"
#include "qnamespace.h"
#include "qdatastream.h"
#include "qvariant.h"
#include "qdebug.h"
#include "private/qtools_p.h"
#include <algorithm>
#include <QtCore/q26numeric.h>
#include <optional>
#include <QtCore/q20utility.h>
#include <stdio.h>
#include <limits.h>
Include dependency graph for qcolor.cpp:

Go to the source code of this file.

Classes

struct  RGBData

Namespaces

namespace  QColorConstants
 \inmodule QtGui

Macros

#define rgb(r, g, b)
#define QRGB(r, g, b)
#define QRGBA(r, g, b, a)

Enumerations

enum class  QColorRgbFValidity : quint8 {
  Rgb , ExtendedRgb , Invalid , Rgb ,
  ExtendedRgb , Invalid
}
enum class  QColorHueLimit : bool { None , Degrees , None , Degrees }
enum class  QColorRgbFValidity : quint8 {
  Rgb , ExtendedRgb , Invalid , Rgb ,
  ExtendedRgb , Invalid
}
enum class  QColorHueLimit : bool { None , Degrees , None , Degrees }

Functions

static int hex2int (const char *s, int n)
static std::optional< QRgba64get_hex_rgb (const char *name, size_t len)
std::optional< QRgbqt_get_hex_rgb (const char *name)
static std::optional< QRgba64get_hex_rgb (const QChar *str, size_t len)
static std::optional< QRgba64get_hex_rgb (QAnyStringView name)
bool operator< (const char *name, const RGBData &data)
bool operator< (const RGBData &data, const char *name)
static std::optional< QRgbget_named_rgb_no_space (const char *name_no_space)
static std::optional< QRgbget_named_rgb (QAnyStringView name)
static QStringList get_colornames ()
static constexpr bool qColorComponentIsInIntRange (int value) noexcept
static constexpr bool qColorHueIsInIntRange (int hue, QColorHueLimit upperLimit) noexcept
static constexpr bool qColorComponentIsInFloatRange (float value) noexcept
static constexpr bool qColorHueIsInFloatRange (float hue) noexcept
static constexpr bool qColorIsFloatNaN (float value) noexcept
Q_DECL_COLD_FUNCTION void qColorWarnInvalidInt (int value, const char *fn)
Q_DECL_COLD_FUNCTION void qColorWarnInvalidFloat (float value, const char *fn)
Q_DECL_COLD_FUNCTION void qColorWarnParametersOutOfRange (const char *name, const char *fn)
static auto qColorClampToIntRange (int value, const char *fn)
static auto qColorClampToFloatRange (float value, const char *fn)
static auto qColorClampNaNToNull (float value, const char *fn)
static bool qColorCheckRgbValidity (int r, int g, int b, int a, const char *fn)
static bool qColorCheckHsxValidity (int h, int s, int x, int a, const char *fn, const char *name, QColorHueLimit hLimit)
static bool qColorCheckHslValidity (int h, int s, int l, int a, const char *fn, QColorHueLimit hLimit)
static bool qColorCheckHsvValidity (int h, int s, int v, int a, const char *fn, QColorHueLimit hLimit)
static bool qColorCheckCmykValidity (int c, int m, int y, int k, int a, const char *fn)
static QColorRgbFValidity qColorCheckRgbFValidity (float r, float g, float b, float a, QColor::Spec cspec, const char *fn)
static bool qColorCheckHsxFValidity (float h, float s, float x, float a, const char *fn, const char *name)
static bool qColorCheckHslFValidity (float h, float s, float l, float a, const char *fn)
static bool qColorCheckHsvFValidity (float h, float s, float v, float a, const char *fn)
static bool qColorCheckCmykFValidity (float c, float m, float y, float k, float a, const char *fn)
static qfloat16castF16 (quint16 &v)
static const qfloat16castF16 (const quint16 &v)
QDebug operator<< (QDebug dbg, const QColor &c)
QDataStreamoperator<< (QDataStream &stream, const QColor &color)
QDataStreamoperator>> (QDataStream &stream, QColor &color)

Variables

 QT_BEGIN_NAMESPACE
static constexpr struct RGBData rgbTbl []
static const int rgbTblSize = sizeof(rgbTbl) / sizeof(RGBData)
const uint qt_inv_premul_factor [256]

Macro Definition Documentation

◆ QRGB

#define QRGB ( r,
g,
b )
Value:
QRgb(((0xffu << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff)))
GLboolean GLboolean GLboolean b
GLboolean r
GLboolean GLboolean g
QT_BEGIN_NAMESPACE typedef unsigned int QRgb
Definition qrgb.h:14

◆ QRGBA

#define QRGBA ( r,
g,
b,
a )
Value:
QRgb(((a & 0xff) << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff))
GLboolean GLboolean GLboolean GLboolean a

◆ rgb

#define rgb ( r,
g,
b )
Value:
(0xff000000 | (r << 16) | (g << 8) | b)

Definition at line 127 of file qcolor.cpp.

Enumeration Type Documentation

◆ QColorHueLimit [1/2]

enum class QColorHueLimit : bool
strong
Enumerator
None 
Degrees 
None 
Degrees 

Definition at line 356 of file qcolor.cpp.

◆ QColorHueLimit [2/2]

enum class QColorHueLimit : bool
strong
Enumerator
None 
Degrees 
None 
Degrees 

Definition at line 356 of file qcolor.cpp.

◆ QColorRgbFValidity [1/2]

enum class QColorRgbFValidity : quint8
strong
Enumerator
Rgb 
ExtendedRgb 
Invalid 
Rgb 
ExtendedRgb 
Invalid 

Definition at line 347 of file qcolor.cpp.

◆ QColorRgbFValidity [2/2]

enum class QColorRgbFValidity : quint8
strong
Enumerator
Rgb 
ExtendedRgb 
Invalid 
Rgb 
ExtendedRgb 
Invalid 

Definition at line 347 of file qcolor.cpp.

Function Documentation

◆ castF16() [1/2]

const qfloat16 & castF16 ( const quint16 & v)
inlinestatic

Definition at line 1407 of file qcolor.cpp.

◆ castF16() [2/2]

qfloat16 & castF16 ( quint16 & v)
inlinestatic

Definition at line 1401 of file qcolor.cpp.

◆ get_colornames()

QStringList get_colornames ( )
static

Definition at line 336 of file qcolor.cpp.

References RGBData::name, and rgbTblSize.

◆ get_hex_rgb() [1/3]

std::optional< QRgba64 > get_hex_rgb ( const char * name,
size_t len )
static

Definition at line 51 of file qcolor.cpp.

◆ get_hex_rgb() [2/3]

std::optional< QRgba64 > get_hex_rgb ( const QChar * str,
size_t len )
static

Definition at line 100 of file qcolor.cpp.

◆ get_hex_rgb() [3/3]

std::optional< QRgba64 > get_hex_rgb ( QAnyStringView name)
static

Definition at line 111 of file qcolor.cpp.

◆ get_named_rgb()

std::optional< QRgb > get_named_rgb ( QAnyStringView name)
static

Definition at line 317 of file qcolor.cpp.

◆ get_named_rgb_no_space()

std::optional< QRgb > get_named_rgb_no_space ( const char * name_no_space)
static

Definition at line 303 of file qcolor.cpp.

References operator<(), rgbTblSize, and RGBData::value.

Here is the call graph for this function:

◆ hex2int()

int hex2int ( const char * s,
int n )
inlinestatic

If s[0..n] is a valid hex number, returns its integer value, otherwise returns -1.

Definition at line 36 of file qcolor.cpp.

◆ operator<() [1/2]

bool operator< ( const char * name,
const RGBData & data )
inline

Definition at line 298 of file qcolor.cpp.

References RGBData::name.

Referenced by get_named_rgb_no_space().

Here is the caller graph for this function:

◆ operator<() [2/2]

bool operator< ( const RGBData & data,
const char * name )
inline

Definition at line 300 of file qcolor.cpp.

References RGBData::name.

◆ operator<<() [1/2]

QDataStream & operator<< ( QDataStream & stream,
const QColor & color )

Definition at line 3114 of file qcolor.cpp.

◆ operator<<() [2/2]

QDebug operator<< ( QDebug dbg,
const QColor & c )

Definition at line 3084 of file qcolor.cpp.

◆ operator>>()

QDataStream & operator>> ( QDataStream & stream,
QColor & color )

Definition at line 3150 of file qcolor.cpp.

◆ qColorCheckCmykFValidity()

bool qColorCheckCmykFValidity ( float c,
float m,
float y,
float k,
float a,
const char * fn )
static

Definition at line 528 of file qcolor.cpp.

References qColorComponentIsInFloatRange(), and qColorWarnParametersOutOfRange().

Here is the call graph for this function:

◆ qColorCheckCmykValidity()

bool qColorCheckCmykValidity ( int c,
int m,
int y,
int k,
int a,
const char * fn )
static

Definition at line 467 of file qcolor.cpp.

References qColorComponentIsInIntRange(), and qColorWarnParametersOutOfRange().

Here is the call graph for this function:

◆ qColorCheckHslFValidity()

bool qColorCheckHslFValidity ( float h,
float s,
float l,
float a,
const char * fn )
static

Definition at line 518 of file qcolor.cpp.

References qColorCheckHsxFValidity().

Here is the call graph for this function:

◆ qColorCheckHslValidity()

bool qColorCheckHslValidity ( int h,
int s,
int l,
int a,
const char * fn,
QColorHueLimit hLimit )
static

Definition at line 455 of file qcolor.cpp.

References qColorCheckHsxValidity().

Here is the call graph for this function:

◆ qColorCheckHsvFValidity()

bool qColorCheckHsvFValidity ( float h,
float s,
float v,
float a,
const char * fn )
static

Definition at line 523 of file qcolor.cpp.

References qColorCheckHsxFValidity().

Here is the call graph for this function:

◆ qColorCheckHsvValidity()

bool qColorCheckHsvValidity ( int h,
int s,
int v,
int a,
const char * fn,
QColorHueLimit hLimit )
static

Definition at line 461 of file qcolor.cpp.

References qColorCheckHsxValidity().

Here is the call graph for this function:

◆ qColorCheckHsxFValidity()

bool qColorCheckHsxFValidity ( float h,
float s,
float x,
float a,
const char * fn,
const char * name )
static

Definition at line 504 of file qcolor.cpp.

References qColorComponentIsInFloatRange(), qColorHueIsInFloatRange(), and qColorWarnParametersOutOfRange().

Referenced by qColorCheckHslFValidity(), and qColorCheckHsvFValidity().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ qColorCheckHsxValidity()

bool qColorCheckHsxValidity ( int h,
int s,
int x,
int a,
const char * fn,
const char * name,
QColorHueLimit hLimit )
static

Definition at line 441 of file qcolor.cpp.

References qColorComponentIsInIntRange(), qColorHueIsInIntRange(), and qColorWarnParametersOutOfRange().

Referenced by qColorCheckHslValidity(), and qColorCheckHsvValidity().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ qColorCheckRgbFValidity()

QColorRgbFValidity qColorCheckRgbFValidity ( float r,
float g,
float b,
float a,
QColor::Spec cspec,
const char * fn )
static

Definition at line 481 of file qcolor.cpp.

References ExtendedRgb, Invalid, qColorComponentIsInFloatRange(), qColorIsFloatNaN(), qColorWarnInvalidFloat(), qColorWarnParametersOutOfRange(), and Rgb.

Here is the call graph for this function:

◆ qColorCheckRgbValidity()

bool qColorCheckRgbValidity ( int r,
int g,
int b,
int a,
const char * fn )
static

Definition at line 428 of file qcolor.cpp.

References qColorComponentIsInIntRange(), and qColorWarnParametersOutOfRange().

Here is the call graph for this function:

◆ qColorClampNaNToNull()

auto qColorClampNaNToNull ( float value,
const char * fn )
static

Definition at line 420 of file qcolor.cpp.

References qColorIsFloatNaN(), and qColorWarnInvalidFloat().

Here is the call graph for this function:

◆ qColorClampToFloatRange()

auto qColorClampToFloatRange ( float value,
const char * fn )
static

Definition at line 412 of file qcolor.cpp.

References qColorComponentIsInFloatRange(), qColorIsFloatNaN(), and qColorWarnInvalidFloat().

Here is the call graph for this function:

◆ qColorClampToIntRange()

auto qColorClampToIntRange ( int value,
const char * fn )
static

Definition at line 404 of file qcolor.cpp.

References qColorWarnInvalidInt().

Here is the call graph for this function:

◆ qColorComponentIsInFloatRange()

constexpr bool qColorComponentIsInFloatRange ( float value)
staticconstexprnoexcept

Definition at line 372 of file qcolor.cpp.

Referenced by qColorCheckCmykFValidity(), qColorCheckHsxFValidity(), qColorCheckRgbFValidity(), qColorClampToFloatRange(), and qColorHueIsInFloatRange().

Here is the caller graph for this function:

◆ qColorComponentIsInIntRange()

constexpr bool qColorComponentIsInIntRange ( int value)
staticconstexprnoexcept

Definition at line 362 of file qcolor.cpp.

Referenced by qColorCheckCmykValidity(), qColorCheckHsxValidity(), and qColorCheckRgbValidity().

Here is the caller graph for this function:

◆ qColorHueIsInFloatRange()

constexpr bool qColorHueIsInFloatRange ( float hue)
staticconstexprnoexcept

Definition at line 378 of file qcolor.cpp.

References qColorComponentIsInFloatRange().

Referenced by qColorCheckHsxFValidity().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ qColorHueIsInIntRange()

constexpr bool qColorHueIsInIntRange ( int hue,
QColorHueLimit upperLimit )
staticconstexprnoexcept

Definition at line 367 of file qcolor.cpp.

References Degrees.

Referenced by qColorCheckHsxValidity().

Here is the caller graph for this function:

◆ qColorIsFloatNaN()

constexpr bool qColorIsFloatNaN ( float value)
staticconstexprnoexcept

Definition at line 384 of file qcolor.cpp.

Referenced by qColorCheckRgbFValidity(), qColorClampNaNToNull(), and qColorClampToFloatRange().

Here is the caller graph for this function:

◆ qColorWarnInvalidFloat()

Q_DECL_COLD_FUNCTION void qColorWarnInvalidFloat ( float value,
const char * fn )

Definition at line 394 of file qcolor.cpp.

Referenced by qColorCheckRgbFValidity(), qColorClampNaNToNull(), and qColorClampToFloatRange().

Here is the caller graph for this function:

◆ qColorWarnInvalidInt()

Q_DECL_COLD_FUNCTION void qColorWarnInvalidInt ( int value,
const char * fn )

Definition at line 389 of file qcolor.cpp.

Referenced by qColorClampToIntRange().

Here is the caller graph for this function:

◆ qColorWarnParametersOutOfRange()

Q_DECL_COLD_FUNCTION void qColorWarnParametersOutOfRange ( const char * name,
const char * fn )

Definition at line 399 of file qcolor.cpp.

Referenced by qColorCheckCmykFValidity(), qColorCheckCmykValidity(), qColorCheckHsxFValidity(), qColorCheckHsxValidity(), qColorCheckRgbFValidity(), and qColorCheckRgbValidity().

Here is the caller graph for this function:

◆ qt_get_hex_rgb()

std::optional< QRgb > qt_get_hex_rgb ( const char * name)

Definition at line 93 of file qcolor.cpp.

Variable Documentation

◆ QT_BEGIN_NAMESPACE

QT_BEGIN_NAMESPACE
related

Definition at line 28 of file qcolor.cpp.

◆ qt_inv_premul_factor

const uint qt_inv_premul_factor

Definition at line 3186 of file qcolor.cpp.

◆ rgbTbl

constexpr struct RGBData rgbTbl
static

◆ rgbTblSize

const int rgbTblSize = sizeof(rgbTbl) / sizeof(RGBData)
static

Definition at line 284 of file qcolor.cpp.

Referenced by get_colornames(), and get_named_rgb_no_space().