Skip to content

Commit

Permalink
QPixelLayout: remove explicit array sizes
Browse files Browse the repository at this point in the history
For qPixelLayouts, there's a static_assert right below it that checks
that the array has a specific size, as a guard for extending
QImage::NImageFormats without also extending the array. Giving an
explicit size to qPixelLayouts defeats the entire purpose.

For the other arrays of function pointers, drop the sizing and add the
missing static_asserts.

Use std::size as a drive-by.

This work has been kindly sponsored by the QGIS project
(https://qgis.org/).

Change-Id: Ic791a706a8ae964e3aee482f23b7eeeedf97bdc6
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
  • Loading branch information
dangelog committed Feb 10, 2024
1 parent 7dec8f7 commit f221ac0
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
21 changes: 15 additions & 6 deletions src/gui/painting/qpixellayout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1661,7 +1661,7 @@ static const QRgba64 *QT_FASTCALL fetchRGBA32FPMToRGBA64PM(QRgba64 *buffer, cons
// convertToArgb32() assumes that no color channel is less than 4 bits.
// storeRGBFromARGB32PM() assumes that no color channel is more than 8 bits.
// QImage::rgbSwapped() assumes that the red and blue color channels have the same number of bits.
QPixelLayout qPixelLayouts[QImage::NImageFormats] = {
QPixelLayout qPixelLayouts[] = {
{ false, false, QPixelLayout::BPPNone, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr, nullptr }, // Format_Invalid
{ false, false, QPixelLayout::BPP1MSB, nullptr,
convertIndexedToARGB32PM, convertIndexedTo<QRgba64>,
Expand Down Expand Up @@ -1781,7 +1781,7 @@ QPixelLayout qPixelLayouts[QImage::NImageFormats] = {
storeRGB32FFromRGB32, storeRGB32FFromRGB32 }, // Format_RGBA32FPx4_Premultiplied
};

static_assert(sizeof(qPixelLayouts) / sizeof(*qPixelLayouts) == QImage::NImageFormats);
static_assert(std::size(qPixelLayouts) == QImage::NImageFormats);

static void QT_FASTCALL convertFromRgb64(uint *dest, const QRgba64 *src, int length)
{
Expand Down Expand Up @@ -1916,7 +1916,7 @@ static void QT_FASTCALL storeRGBA32FPMFromRGBA64PM(uchar *dest, const QRgba64 *s
d[i] = qConvertRgb64ToRgbaF32(src[i]);
}

ConvertAndStorePixelsFunc64 qStoreFromRGBA64PM[QImage::NImageFormats] = {
ConvertAndStorePixelsFunc64 qStoreFromRGBA64PM[] = {
nullptr,
nullptr,
nullptr,
Expand Down Expand Up @@ -1955,6 +1955,8 @@ ConvertAndStorePixelsFunc64 qStoreFromRGBA64PM[QImage::NImageFormats] = {
storeRGBA32FPMFromRGBA64PM,
};

static_assert(std::size(qStoreFromRGBA64PM) == QImage::NImageFormats);

#if QT_CONFIG(raster_fp)
static void QT_FASTCALL convertToRgbaF32(QRgbaFloat32 *dest, const uint *src, int length)
{
Expand Down Expand Up @@ -2000,7 +2002,7 @@ static const QRgbaFloat32 * QT_FASTCALL convertRGB30ToRGBA32F(QRgbaFloat32 *buff
return buffer;
}

ConvertToFPFunc qConvertToRGBA32F[QImage::NImageFormats] = {
ConvertToFPFunc qConvertToRGBA32F[] = {
nullptr,
convertIndexedTo<QRgbaFloat32>,
convertIndexedTo<QRgbaFloat32>,
Expand Down Expand Up @@ -2039,6 +2041,8 @@ ConvertToFPFunc qConvertToRGBA32F[QImage::NImageFormats] = {
nullptr,
};

static_assert(std::size(qConvertToRGBA32F) == QImage::NImageFormats);

static const QRgbaFloat32 *QT_FASTCALL fetchRGBX64ToRGBA32F(QRgbaFloat32 *buffer, const uchar *src, int index, int count,
const QList<QRgb> *, QDitherInfo *)
{
Expand Down Expand Up @@ -2103,7 +2107,7 @@ static const QRgbaFloat32 *QT_FASTCALL fetchRGBA32F(QRgbaFloat32 *, const uchar
return s;
}

FetchAndConvertPixelsFuncFP qFetchToRGBA32F[QImage::NImageFormats] = {
FetchAndConvertPixelsFuncFP qFetchToRGBA32F[] = {
nullptr,
fetchIndexedToRGBA32F<QPixelLayout::BPP1MSB>,
fetchIndexedToRGBA32F<QPixelLayout::BPP1LSB>,
Expand Down Expand Up @@ -2142,6 +2146,8 @@ FetchAndConvertPixelsFuncFP qFetchToRGBA32F[QImage::NImageFormats] = {
fetchRGBA32F,
};

static_assert(std::size(qFetchToRGBA32F) == QImage::NImageFormats);

static void QT_FASTCALL convertFromRgba32f(uint *dest, const QRgbaFloat32 *src, int length)
{
for (int i = 0; i < length; ++i)
Expand Down Expand Up @@ -2278,7 +2284,7 @@ static void QT_FASTCALL storeRGBA32FPMFromRGBA32F(uchar *dest, const QRgbaFloat3
}
}

ConvertAndStorePixelsFuncFP qStoreFromRGBA32F[QImage::NImageFormats] = {
ConvertAndStorePixelsFuncFP qStoreFromRGBA32F[] = {
nullptr,
nullptr,
nullptr,
Expand Down Expand Up @@ -2316,6 +2322,9 @@ ConvertAndStorePixelsFuncFP qStoreFromRGBA32F[QImage::NImageFormats] = {
storeRGBA32FFromRGBA32F,
storeRGBA32FPMFromRGBA32F,
};

static_assert(std::size(qStoreFromRGBA32F) == QImage::NImageFormats);

#endif // QT_CONFIG(raster_fp)

QT_END_NAMESPACE
8 changes: 4 additions & 4 deletions src/gui/painting/qpixellayout_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,12 @@ struct QPixelLayout
extern ConvertAndStorePixelsFunc64 qStoreFromRGBA64PM[QImage::NImageFormats];

#if QT_CONFIG(raster_fp)
extern ConvertToFPFunc qConvertToRGBA32F[QImage::NImageFormats];
extern FetchAndConvertPixelsFuncFP qFetchToRGBA32F[QImage::NImageFormats];
extern ConvertAndStorePixelsFuncFP qStoreFromRGBA32F[QImage::NImageFormats];
extern ConvertToFPFunc qConvertToRGBA32F[];
extern FetchAndConvertPixelsFuncFP qFetchToRGBA32F[];
extern ConvertAndStorePixelsFuncFP qStoreFromRGBA32F[];
#endif

extern QPixelLayout qPixelLayouts[QImage::NImageFormats];
extern QPixelLayout qPixelLayouts[];

extern MemRotateFunc qMemRotateFunctions[QPixelLayout::BPPCount][3];

Expand Down

0 comments on commit f221ac0

Please sign in to comment.