Qt 6.x
The Qt SDK
Loading...
Searching...
No Matches
qcolor.cpp File Reference
#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 <optional>
#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)   (0xff000000 | (r << 16) | (g << 8) | b)
 
#define QCOLOR_INT_RANGE_CHECK(fn, var)
 
#define QCOLOR_REAL_RANGE_CHECK(fn, var)
 
#define QRGB(r, g, b)    QRgb(((0xffu << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff)))
 
#define QRGBA(r, g, b, a)    QRgb(((a & 0xff) << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff))
 
#define Q_MAX_3(a, b, c)   ( ( a > b && a > c) ? a : (b > c ? b : c) )
 
#define Q_MIN_3(a, b, c)   ( ( a < b && a < c) ? a : (b < c ? b : c) )
 

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 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

◆ Q_MAX_3

#define Q_MAX_3 (   a,
  b,
  c 
)    ( ( a > b && a > c) ? a : (b > c ? b : c) )

Definition at line 2179 of file qcolor.cpp.

◆ Q_MIN_3

#define Q_MIN_3 (   a,
  b,
  c 
)    ( ( a < b && a < c) ? a : (b < c ? b : c) )

Definition at line 2180 of file qcolor.cpp.

◆ QCOLOR_INT_RANGE_CHECK

#define QCOLOR_INT_RANGE_CHECK (   fn,
  var 
)
Value:
do { \
if (var < 0 || var > 255) { \
qWarning(#fn": invalid value %d", var); \
var = qMax(0, qMin(var, 255)); \
} \
} while (0)
constexpr const T & qMin(const T &a, const T &b)
Definition qminmax.h:40
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42

Definition at line 581 of file qcolor.cpp.

◆ QCOLOR_REAL_RANGE_CHECK

#define QCOLOR_REAL_RANGE_CHECK (   fn,
  var 
)
Value:
do { \
if (var < 0.0f || var > 1.0f) { \
qWarning(#fn": invalid value %g", var); \
var = qMax(0.0f, qMin(var, 1.0f)); \
} \
} while (0)

Definition at line 589 of file qcolor.cpp.

◆ QRGB

#define QRGB (   r,
  g,
  b 
)     QRgb(((0xffu << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff)))

◆ QRGBA

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

◆ rgb

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

Definition at line 124 of file qcolor.cpp.

Function Documentation

◆ castF16() [1/2]

static const qfloat16 & castF16 ( const quint16 v)
inlinestatic

Definition at line 1237 of file qcolor.cpp.

◆ castF16() [2/2]

static qfloat16 & castF16 ( quint16 v)
inlinestatic

Definition at line 1231 of file qcolor.cpp.

Referenced by QColor::alpha(), QColor::alphaF(), QColor::blueF(), QColor::fromRgbF(), QColor::getRgbF(), QColor::greenF(), QColor::redF(), QColor::setAlpha(), QColor::setAlphaF(), QColor::setBlueF(), QColor::setGreenF(), QColor::setRedF(), QColor::setRgbF(), QColor::toExtendedRgb(), and QColor::toRgb().

+ Here is the caller graph for this function:

◆ get_colornames()

static QStringList get_colornames ( )
static

Definition at line 333 of file qcolor.cpp.

References i, rgbTbl, and rgbTblSize.

Referenced by QColor::colorNames().

+ Here is the caller graph for this function:

◆ get_hex_rgb() [1/3]

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

Definition at line 48 of file qcolor.cpp.

References hex2int(), and qRgba64().

Referenced by QColor::fromString(), get_hex_rgb(), get_hex_rgb(), and qt_get_hex_rgb().

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

◆ get_hex_rgb() [2/3]

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

Definition at line 97 of file qcolor.cpp.

References get_hex_rgb(), i, and str.

+ Here is the call graph for this function:

◆ get_hex_rgb() [3/3]

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

Definition at line 108 of file qcolor.cpp.

References get_hex_rgb().

+ Here is the call graph for this function:

◆ get_named_rgb()

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

Definition at line 314 of file qcolor.cpp.

References get_named_rgb_no_space(), pos, and QtMiscUtils::toAsciiLower().

Referenced by QColor::fromString().

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

◆ get_named_rgb_no_space()

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

Definition at line 300 of file qcolor.cpp.

References rgbTbl, and rgbTblSize.

Referenced by get_named_rgb().

+ Here is the caller graph for this function:

◆ hex2int()

static 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 33 of file qcolor.cpp.

References QtMiscUtils::fromHex().

Referenced by get_hex_rgb().

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

◆ operator<() [1/2]

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

Definition at line 295 of file qcolor.cpp.

References qstrcmp().

+ Here is the call graph for this function:

◆ operator<() [2/2]

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

Definition at line 297 of file qcolor.cpp.

References qstrcmp().

+ Here is the call graph for this function:

◆ operator<<() [1/2]

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

Definition at line 2977 of file qcolor.cpp.

References rgb.

◆ operator<<() [2/2]

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

Definition at line 2947 of file qcolor.cpp.

References QColor::Cmyk, QColor::ExtendedRgb, QColor::Hsl, QColor::Hsv, and QColor::Rgb.

◆ operator>>()

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

Definition at line 3013 of file qcolor.cpp.

References rgb.

◆ qt_get_hex_rgb()

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

Definition at line 90 of file qcolor.cpp.

References get_hex_rgb(), and qstrlen().

Referenced by read_xpm_body().

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

Variable Documentation

◆ QT_BEGIN_NAMESPACE

QT_BEGIN_NAMESPACE
related

Definition at line 25 of file qcolor.cpp.

◆ qt_inv_premul_factor

const uint qt_inv_premul_factor[256]

Definition at line 3049 of file qcolor.cpp.

Referenced by QColor::qUnpremultiply().

◆ rgbTbl

constexpr struct RGBData rgbTbl[]
static

◆ rgbTblSize

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

Definition at line 281 of file qcolor.cpp.

Referenced by get_colornames(), and get_named_rgb_no_space().