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
qrgb.h
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3// Qt-Security score:significant reason:default
4
5#ifndef QRGB_H
6#define QRGB_H
7
8#include <QtGui/qtguiglobal.h>
9#include <QtCore/qprocessordetection.h>
10
12
13
14typedef unsigned int QRgb; // RGB triplet
15
16// non-namespaced Qt global variable
17 inline constexpr QRgb RGB_MASK = 0x00ffffff; // masks RGB values
18
19inline constexpr int qRed(QRgb rgb) // get red part of RGB
20{ return ((rgb >> 16) & 0xff); }
21
22inline constexpr int qGreen(QRgb rgb) // get green part of RGB
23{ return ((rgb >> 8) & 0xff); }
24
25inline constexpr int qBlue(QRgb rgb) // get blue part of RGB
26{ return (rgb & 0xff); }
27
28inline constexpr int qAlpha(QRgb rgb) // get alpha part of RGBA
29{ return rgb >> 24; }
30
31inline constexpr QRgb qRgb(int r, int g, int b) // set RGB value
32{ return (0xffu << 24) | ((r & 0xffu) << 16) | ((g & 0xffu) << 8) | (b & 0xffu); }
33
34inline constexpr QRgb qRgba(int r, int g, int b, int a) // set RGBA value
35{ return ((a & 0xffu) << 24) | ((r & 0xffu) << 16) | ((g & 0xffu) << 8) | (b & 0xffu); }
36
37inline constexpr int qGray(int r, int g, int b) // convert R,G,B to gray 0..255
38{ return (r*11+g*16+b*5)/32; }
39
40inline constexpr int qGray(QRgb rgb) // convert RGB to gray 0..255
41{ return qGray(qRed(rgb), qGreen(rgb), qBlue(rgb)); }
42
43inline constexpr bool qIsGray(QRgb rgb)
44{ return qRed(rgb) == qGreen(rgb) && qRed(rgb) == qBlue(rgb); }
45
46inline constexpr QRgb qPremultiply(QRgb x)
47{
48 const uint a = qAlpha(x);
49 uint t = (x & 0xff00ff) * a;
50 t = (t + ((t >> 8) & 0xff00ff) + 0x800080) >> 8;
51 t &= 0xff00ff;
52
53 x = ((x >> 8) & 0xff) * a;
54 x = (x + ((x >> 8) & 0xff) + 0x80);
55 x &= 0xff00;
56 return x | t | (a << 24);
57}
58
59Q_GUI_EXPORT extern const uint qt_inv_premul_factor[];
60
62{
63 const uint alpha = qAlpha(p);
64 // Alpha 255 and 0 are the two most common values, which makes them beneficial to short-cut.
65 if (alpha == 255)
66 return p;
67 if (alpha == 0)
68 return 0;
69 // (p*(0x00ff00ff/alpha)) >> 16 == (p*255)/alpha for all p and alpha <= 256.
70 const uint invAlpha = qt_inv_premul_factor[alpha];
71 // We add 0x8000 to get even rounding. The rounding also ensures that qPremultiply(qUnpremultiply(p)) == p for all p.
72 return qRgba((qRed(p)*invAlpha + 0x8000)>>16, (qGreen(p)*invAlpha + 0x8000)>>16, (qBlue(p)*invAlpha + 0x8000)>>16, alpha);
73}
74
75QT_END_NAMESPACE
76
77#endif // QRGB_H
The QOpenGLFunctions class provides cross-platform access to the OpenGL ES 2.0 API.
void freeResource(QOpenGLContext *context) override
QOpenGLGlyphTexture(QOpenGLContext *ctx)
The QOpenGLVertexArrayObject class wraps an OpenGL Vertex Array Object.
Combined button and popup list for selecting options.
static void load_glyph_image_region_to_texture(QOpenGLContext *ctx, const QImage &srcImg, int x, int y, int w, int h, GLuint texture, int tx, int ty)
static void load_glyph_image_to_texture(QOpenGLContext *ctx, QImage &img, GLuint texture, int tx, int ty)
static QT_BEGIN_NAMESPACE int next_qopengltextureglyphcache_serial_number()
constexpr int qGray(QRgb rgb)
Definition qrgb.h:40
constexpr bool qIsGray(QRgb rgb)
Definition qrgb.h:43
QT_BEGIN_NAMESPACE typedef unsigned int QRgb
Definition qrgb.h:14
constexpr QRgb qRgb(int r, int g, int b)
Definition qrgb.h:31
constexpr int qRed(QRgb rgb)
Definition qrgb.h:19
constexpr int qGreen(QRgb rgb)
Definition qrgb.h:22
constexpr int qGray(int r, int g, int b)
Definition qrgb.h:37
QRgb qUnpremultiply(QRgb p)
Definition qrgb.h:61
constexpr QRgb qRgba(int r, int g, int b, int a)
Definition qrgb.h:34
constexpr int qBlue(QRgb rgb)
Definition qrgb.h:25
constexpr QRgb RGB_MASK
Definition qrgb.h:17
constexpr QRgb qPremultiply(QRgb x)
Definition qrgb.h:46
constexpr int qAlpha(QRgb rgb)
Definition qrgb.h:28