Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qpixellayout_p.h
Go to the documentation of this file.
1// Copyright (C) 2020 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
4#ifndef QPIXELLAYOUT_P_H
5#define QPIXELLAYOUT_P_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtCore/qlist.h>
19#include <QtGui/qimage.h>
20#include <QtGui/qrgba64.h>
21#include <QtGui/qrgbafloat.h>
22#include <QtCore/private/qglobal_p.h>
23
25
30
31template<enum QtPixelOrder> inline uint qConvertArgb32ToA2rgb30(QRgb);
32
33template<enum QtPixelOrder> inline uint qConvertRgb32ToRgb30(QRgb);
34
35template<enum QtPixelOrder> inline QRgb qConvertA2rgb30ToArgb32(uint c);
36
37// A combined unpremultiply and premultiply with new simplified alpha.
38// Needed when alpha loses precision relative to other colors during conversion (ARGB32 -> A2RGB30).
39template<unsigned int Shift>
41{
42 const uint alpha = qAlpha(p);
43 if (alpha == 255 || alpha == 0)
44 return p;
46 constexpr uint mult = 255 / (255 >> Shift);
47 const uint newAlpha = mult * (alpha >> Shift);
48 p = (p & ~0xff000000) | (newAlpha<<24);
49 return qPremultiply(p);
50}
51
52template<unsigned int Shift>
54{
55 const uint alpha = p.alpha();
56 if (alpha == 65535 || alpha == 0)
57 return p;
58 p = p.unpremultiplied();
59 constexpr uint mult = 65535 / (65535 >> Shift);
60 p.setAlpha(mult * (alpha >> Shift));
61 return p.premultiplied();
62}
63
64template<>
66{
67 c = qRepremultiply<6>(c);
68 return (c & 0xc0000000)
69 | (((c << 22) & 0x3fc00000) | ((c << 14) & 0x00300000))
70 | (((c << 4) & 0x000ff000) | ((c >> 4) & 0x00000c00))
71 | (((c >> 14) & 0x000003fc) | ((c >> 22) & 0x00000003));
72}
73
74template<>
76{
77 c = qRepremultiply<6>(c);
78 return (c & 0xc0000000)
79 | (((c << 6) & 0x3fc00000) | ((c >> 2) & 0x00300000))
80 | (((c << 4) & 0x000ff000) | ((c >> 4) & 0x00000c00))
81 | (((c << 2) & 0x000003fc) | ((c >> 6) & 0x00000003));
82}
83
84template<>
86{
87 return 0xc0000000
88 | (((c << 22) & 0x3fc00000) | ((c << 14) & 0x00300000))
89 | (((c << 4) & 0x000ff000) | ((c >> 4) & 0x00000c00))
90 | (((c >> 14) & 0x000003fc) | ((c >> 22) & 0x00000003));
91}
92
93template<>
95{
96 return 0xc0000000
97 | (((c << 6) & 0x3fc00000) | ((c >> 2) & 0x00300000))
98 | (((c << 4) & 0x000ff000) | ((c >> 4) & 0x00000c00))
99 | (((c << 2) & 0x000003fc) | ((c >> 6) & 0x00000003));
100}
101
102template<>
104{
105 uint a = c >> 30;
106 a |= a << 2;
107 a |= a << 4;
108 return (a << 24)
109 | ((c << 14) & 0x00ff0000)
110 | ((c >> 4) & 0x0000ff00)
111 | ((c >> 22) & 0x000000ff);
112}
113
114template<>
116{
117 uint a = c >> 30;
118 a |= a << 2;
119 a |= a << 4;
120 return (a << 24)
121 | ((c >> 6) & 0x00ff0000)
122 | ((c >> 4) & 0x0000ff00)
123 | ((c >> 2) & 0x000000ff);
124}
125
126template<enum QtPixelOrder> inline QRgba64 qConvertA2rgb30ToRgb64(uint rgb);
127
128template<>
130{
131 quint16 alpha = rgb >> 30;
132 quint16 blue = (rgb >> 20) & 0x3ff;
133 quint16 green = (rgb >> 10) & 0x3ff;
134 quint16 red = rgb & 0x3ff;
135 // Expand the range.
136 alpha |= (alpha << 2);
137 alpha |= (alpha << 4);
138 alpha |= (alpha << 8);
139 red = (red << 6) | (red >> 4);
140 green = (green << 6) | (green >> 4);
141 blue = (blue << 6) | (blue >> 4);
142 return qRgba64(red, green, blue, alpha);
143}
144
145template<>
147{
148 quint16 alpha = rgb >> 30;
149 quint16 red = (rgb >> 20) & 0x3ff;
150 quint16 green = (rgb >> 10) & 0x3ff;
151 quint16 blue = rgb & 0x3ff;
152 // Expand the range.
153 alpha |= (alpha << 2);
154 alpha |= (alpha << 4);
155 alpha |= (alpha << 8);
156 red = (red << 6) | (red >> 4);
157 green = (green << 6) | (green >> 4);
158 blue = (blue << 6) | (blue >> 4);
159 return qRgba64(red, green, blue, alpha);
160}
161
162template<enum QtPixelOrder> inline unsigned int qConvertRgb64ToRgb30(QRgba64);
163
164template<>
166{
167 c = qRepremultiply<14>(c);
168 const uint a = c.alpha() >> 14;
169 const uint r = c.red() >> 6;
170 const uint g = c.green() >> 6;
171 const uint b = c.blue() >> 6;
172 return (a << 30) | (b << 20) | (g << 10) | r;
173}
174
175template<>
177{
178 c = qRepremultiply<14>(c);
179 const uint a = c.alpha() >> 14;
180 const uint r = c.red() >> 6;
181 const uint g = c.green() >> 6;
182 const uint b = c.blue() >> 6;
183 return (a << 30) | (r << 20) | (g << 10) | b;
184}
185
187{
188 return QRgbaFloat16::fromRgba64(c.red(), c.green(), c.blue(), c.alpha());
189}
190
192{
193 return QRgbaFloat32::fromRgba64(c.red(), c.green(), c.blue(), c.alpha());
194}
195
197{
198 const uint ag = c & 0xc00ffc00;
199 const uint rb = c & 0x3ff003ff;
200 return ag | (rb << 20) | (rb >> 20);
201}
202
203#if Q_BYTE_ORDER == Q_BIG_ENDIAN
204static inline quint32 RGBA2ARGB(quint32 x) {
205 quint32 rgb = x >> 8;
206 quint32 a = x << 24;
207 return a | rgb;
208}
209
210static inline quint32 ARGB2RGBA(quint32 x) {
211 quint32 rgb = x << 8;
212 quint32 a = x >> 24;
213 return a | rgb;
214}
215#else
216static inline quint32 RGBA2ARGB(quint32 x) {
217 // RGBA8888 is ABGR32 on little endian.
218 quint32 ag = x & 0xff00ff00;
219 quint32 rg = x & 0x00ff00ff;
220 return ag | (rg << 16) | (rg >> 16);
221}
222
223static inline quint32 ARGB2RGBA(quint32 x) {
224 return RGBA2ARGB(x);
225}
226#endif
227
228// We manually unalias the variables to make sure the compiler
229// fully optimizes both aliased and unaliased cases.
230#define UNALIASED_CONVERSION_LOOP(buffer, src, count, conversion) \
231 if (src == buffer) { \
232 for (int i = 0; i < count; ++i) \
233 buffer[i] = conversion(buffer[i]); \
234 } else { \
235 for (int i = 0; i < count; ++i) \
236 buffer[i] = conversion(src[i]); \
237 }
238
239
245
247{
249 return buffer;
250}
251
252template<bool RGBA> void qt_convertRGBA64ToARGB32(uint *dst, const QRgba64 *src, int count);
253
255 int x;
256 int y;
257};
258
260 int index, int count,
261 const QList<QRgb> *clut,
262 QDitherInfo *dither);
264 int count, const QList<QRgb> *clut,
265 QDitherInfo *dither);
266
268 int index, int count,
269 const QList<QRgb> *clut,
270 QDitherInfo *dither);
272 int count, const QList<QRgb> *clut,
273 QDitherInfo *dither);
274
276 const QList<QRgb> *clut, QDitherInfo *dither);
278 const QList<QRgb> *clut, QDitherInfo *dither);
279typedef void (QT_FASTCALL *ConvertFunc)(uint *buffer, int count, const QList<QRgb> *clut);
283
285 const QList<QRgb> *clut, QDitherInfo *dither);
287 const QList<QRgb> *clut, QDitherInfo *dither);
288typedef void (QT_FASTCALL *RbSwapFunc)(uchar *dst, const uchar *src, int count);
289
290typedef void (*MemRotateFunc)(const uchar *srcPixels, int w, int h, int sbpl, uchar *destPixels, int dbpl);
291
320
322
323#if QT_CONFIG(raster_fp)
324extern ConvertToFPFunc qConvertToRGBA32F[];
325extern FetchAndConvertPixelsFuncFP qFetchToRGBA32F[];
326extern ConvertAndStorePixelsFuncFP qStoreFromRGBA32F[];
327#endif
328
330
332
334
335#endif // QPIXELLAYOUT_P_H
@ NImageFormats
Definition qimage.h:80
constexpr quint16 alpha() const
Definition qrgba64.h:73
static constexpr QRgbaFloat fromRgba64(quint16 red, quint16 green, quint16 blue, quint16 alpha)
Definition qrgbafloat.h:35
Combined button and popup list for selecting options.
#define rgb(r, g, b)
Definition qcolor.cpp:124
#define QT_FASTCALL
DBusConnection const char DBusError DBusBusType DBusError return DBusConnection DBusHandleMessageFunction void DBusFreeFunction return DBusConnection return DBusConnection return const char DBusError return DBusConnection DBusMessage dbus_uint32_t return DBusConnection dbus_bool_t DBusConnection DBusAddWatchFunction DBusRemoveWatchFunction DBusWatchToggledFunction void DBusFreeFunction return DBusConnection DBusDispatchStatusFunction void DBusFreeFunction DBusTimeout return DBusTimeout return DBusWatch return DBusWatch unsigned int return DBusError const DBusError return const DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessage return DBusMessageIter int const void return DBusMessageIter DBusMessageIter return DBusMessageIter void DBusMessageIter void int return DBusMessage DBusMessageIter return DBusMessageIter return DBusMessageIter DBusMessageIter const char const char const char const char return DBusMessage return DBusMessage const char return DBusMessage dbus_bool_t return DBusMessage dbus_uint32_t return DBusMessage void
GLboolean GLboolean GLboolean b
GLint GLint GLint GLint GLint x
[0]
GLfloat GLfloat GLfloat w
[0]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLuint index
[2]
GLboolean r
[2]
GLenum GLenum GLsizei count
GLenum src
GLenum GLuint buffer
GLenum GLenum dst
GLboolean GLboolean g
GLfloat GLfloat GLfloat GLfloat h
GLdouble s
[6]
Definition qopenglext.h:235
GLbyte GLbyte blue
Definition qopenglext.h:385
const GLubyte * c
GLfloat GLfloat p
[1]
GLfloat GLfloat GLfloat alpha
Definition qopenglext.h:418
GLbyte green
Definition qopenglext.h:385
void(QT_FASTCALL * Convert64Func)(QRgba64 *buffer, int count)
QRgba64 qConvertA2rgb30ToRgb64< PixelOrderBGR >(uint rgb)
void(QT_FASTCALL * ConvertFunc)(uint *buffer, int count, const QList< QRgb > *clut)
unsigned int qConvertRgb64ToRgb30< PixelOrderBGR >(QRgba64 c)
QRgb qConvertA2rgb30ToArgb32< PixelOrderBGR >(uint c)
constexpr QRgbaFloat32 qConvertRgb64ToRgbaF32(QRgba64 c)
const uint * qt_convertRGBA8888ToARGB32PM(uint *buffer, const uint *src, int count)
const QRgbaFloat32 *(QT_FASTCALL * ConvertToFPFunc)(QRgbaFloat32 *buffer, const uint *src, int count, const QList< QRgb > *clut, QDitherInfo *dither)
void(QT_FASTCALL * RbSwapFunc)(uchar *dst, const uchar *src, int count)
static quint32 RGBA2ARGB(quint32 x)
#define UNALIASED_CONVERSION_LOOP(buffer, src, count, conversion)
ConvertAndStorePixelsFunc64 qStoreFromRGBA64PM[QImage::NImageFormats]
uint qConvertRgb32ToRgb30< PixelOrderRGB >(QRgb c)
const uint *(QT_FASTCALL * FetchAndConvertPixelsFunc)(uint *buffer, const uchar *src, int index, int count, const QList< QRgb > *clut, QDitherInfo *dither)
const QRgba64 *(QT_FASTCALL * FetchAndConvertPixelsFunc64)(QRgba64 *buffer, const uchar *src, int index, int count, const QList< QRgb > *clut, QDitherInfo *dither)
void(QT_FASTCALL * ConvertFPFunc)(QRgbaFloat32 *buffer, int count)
QtPixelOrder
@ PixelOrderRGB
@ PixelOrderBGR
QRgba64 qConvertA2rgb30ToRgb64< PixelOrderRGB >(uint rgb)
uint qConvertArgb32ToA2rgb30(QRgb)
void(QT_FASTCALL * Convert64ToFPFunc)(QRgbaFloat32 *buffer, const quint64 *src, int count)
uint qConvertArgb32ToA2rgb30< PixelOrderBGR >(QRgb c)
uint qConvertRgb32ToRgb30< PixelOrderBGR >(QRgb c)
MemRotateFunc qMemRotateFunctions[QPixelLayout::BPPCount][3]
QRgb qConvertA2rgb30ToArgb32< PixelOrderRGB >(uint c)
constexpr QRgbaFloat16 qConvertRgb64ToRgbaF16(QRgba64 c)
void qt_convertRGBA64ToARGB32(uint *dst, const QRgba64 *src, int count)
static quint32 ARGB2RGBA(quint32 x)
unsigned int qConvertRgb64ToRgb30< PixelOrderRGB >(QRgba64 c)
QRgb qConvertA2rgb30ToArgb32(uint c)
const QRgba64 *(QT_FASTCALL * ConvertTo64Func)(QRgba64 *buffer, const uint *src, int count, const QList< QRgb > *clut, QDitherInfo *dither)
void(QT_FASTCALL * ConvertAndStorePixelsFuncFP)(uchar *dest, const QRgbaFloat32 *src, int index, int count, const QList< QRgb > *clut, QDitherInfo *dither)
const QRgbaFloat32 *(QT_FASTCALL * FetchAndConvertPixelsFuncFP)(QRgbaFloat32 *buffer, const uchar *src, int index, int count, const QList< QRgb > *clut, QDitherInfo *dither)
void(* MemRotateFunc)(const uchar *srcPixels, int w, int h, int sbpl, uchar *destPixels, int dbpl)
unsigned int qConvertRgb64ToRgb30(QRgba64)
uint qConvertArgb32ToA2rgb30< PixelOrderRGB >(QRgb c)
QRgba64 qConvertA2rgb30ToRgb64(uint rgb)
QRgb qRepremultiply(QRgb p)
QPixelLayout qPixelLayouts[]
const uint * qt_convertARGB32ToARGB32PM(uint *buffer, const uint *src, int count)
void(QT_FASTCALL * ConvertAndStorePixelsFunc)(uchar *dest, const uint *src, int index, int count, const QList< QRgb > *clut, QDitherInfo *dither)
void(QT_FASTCALL * ConvertAndStorePixelsFunc64)(uchar *dest, const QRgba64 *src, int index, int count, const QList< QRgb > *clut, QDitherInfo *dither)
uint qRgbSwapRgb30(uint c)
uint qConvertRgb32ToRgb30(QRgb)
QT_BEGIN_NAMESPACE typedef unsigned int QRgb
Definition qrgb.h:13
QRgb qUnpremultiply(QRgb p)
Definition qrgb.h:60
constexpr QRgb qPremultiply(QRgb x)
Definition qrgb.h:45
constexpr int qAlpha(QRgb rgb)
Definition qrgb.h:27
constexpr QRgba64 qRgba64(quint16 r, quint16 g, quint16 b, quint16 a)
Definition qrgba64.h:180
unsigned int quint32
Definition qtypes.h:50
unsigned char uchar
Definition qtypes.h:32
unsigned short quint16
Definition qtypes.h:48
unsigned long long quint64
Definition qtypes.h:61
unsigned int uint
Definition qtypes.h:34
QGraphicsSvgItem * red
ConvertFunc convertToARGB32PM
ConvertAndStorePixelsFunc storeFromARGB32PM
ConvertTo64Func convertToRGBA64PM
FetchAndConvertPixelsFunc64 fetchToRGBA64PM
FetchAndConvertPixelsFunc fetchToARGB32PM
ConvertAndStorePixelsFunc storeFromRGB32
RbSwapFunc rbSwap