From a1185e31ce65f8f7ca46c2b65c565d37ce2cc524 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Tue, 4 Aug 2020 20:02:01 +0300 Subject: [PATCH] convert endianess from runtime to build checks Signed-off-by: Ivailo Monev --- src/core/kernel/qtranslator.cpp | 7 ++++--- src/core/tools/qlocale_tools_p.h | 10 ++++------ src/gui/image/qimage.cpp | 31 +++++++++++++++++++------------ src/gui/image/qpixmap_x11.cpp | 22 ++++++++++------------ src/shared/linguist/qm.cpp | 9 +++++---- 5 files changed, 42 insertions(+), 37 deletions(-) diff --git a/src/core/kernel/qtranslator.cpp b/src/core/kernel/qtranslator.cpp index 3164b3224..ad7a79201 100644 --- a/src/core/kernel/qtranslator.cpp +++ b/src/core/kernel/qtranslator.cpp @@ -739,10 +739,11 @@ static QString getMessage(const uchar *m, const uchar *end, const char *context, if (!tn) return QString(); QString str = QString((const QChar *)tn, tn_length/2); - if (QSysInfo::ByteOrder == QSysInfo::LittleEndian) { - for (int i = 0; i < str.length(); ++i) - str[i] = QChar((str.at(i).unicode() >> 8) + ((str.at(i).unicode() << 8) & 0xff00)); +#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN + for (int i = 0; i < str.length(); ++i) { + str[i] = QChar((str.at(i).unicode() >> 8) + ((str.at(i).unicode() << 8) & 0xff00)); } +#endif return str; } diff --git a/src/core/tools/qlocale_tools_p.h b/src/core/tools/qlocale_tools_p.h index f89e97b84..bfb7a51e2 100644 --- a/src/core/tools/qlocale_tools_p.h +++ b/src/core/tools/qlocale_tools_p.h @@ -74,13 +74,11 @@ static inline bool qIsZero(double d) { uchar *ch = (uchar *)&d; #ifdef QT_ARMFPA - return !(ch[3] & 0x7F || ch[2] || ch[1] || ch[0] || ch[7] || ch[6] || ch[5] || ch[4]); + return !(ch[3] & 0x7F || ch[2] || ch[1] || ch[0] || ch[7] || ch[6] || ch[5] || ch[4]); +#elif Q_BYTE_ORDER == Q_BIG_ENDIAN + return !(ch[0] & 0x7F || ch[1] || ch[2] || ch[3] || ch[4] || ch[5] || ch[6] || ch[7]); #else - if (QSysInfo::ByteOrder == QSysInfo::BigEndian) { - return !(ch[0] & 0x7F || ch[1] || ch[2] || ch[3] || ch[4] || ch[5] || ch[6] || ch[7]); - } else { - return !(ch[7] & 0x7F || ch[6] || ch[5] || ch[4] || ch[3] || ch[2] || ch[1] || ch[0]); - } + return !(ch[7] & 0x7F || ch[6] || ch[5] || ch[4] || ch[3] || ch[2] || ch[1] || ch[0]); #endif } diff --git a/src/gui/image/qimage.cpp b/src/gui/image/qimage.cpp index c63dc45c9..978f250ca 100644 --- a/src/gui/image/qimage.cpp +++ b/src/gui/image/qimage.cpp @@ -2403,7 +2403,6 @@ static void convert_RGB_to_Indexed8(QImageData *dst, const QImageData *src, Qt:: pv[1] = lineBuffer.data() + src->width * 7; pv[2] = lineBuffer.data() + src->width * 8; - int endian = (QSysInfo::ByteOrder == QSysInfo::BigEndian); for (int y = 0; y < src->height; y++) { const uchar* q = src_data; const uchar* q2 = y < src->height - 1 ? q + src->bytes_per_line : src->data; @@ -2412,12 +2411,22 @@ static void convert_RGB_to_Indexed8(QImageData *dst, const QImageData *src, Qt:: int *l1 = (y&1) ? line2[chan] : line1[chan]; int *l2 = (y&1) ? line1[chan] : line2[chan]; if (y == 0) { - for (int i = 0; i < src->width; i++) - l1[i] = q[i*4+chan+endian]; + for (int i = 0; i < src->width; i++) { +#if Q_BYTE_ORDER == Q_BIG_ENDIAN + l1[i] = q[i*4+chan+1]; +#else + l1[i] = q[i*4+chan]; +#endif + } } if (y+1 < src->height) { - for (int i = 0; i < src->width; i++) + for (int i = 0; i < src->width; i++) { +#if Q_BYTE_ORDER == Q_BIG_ENDIAN l2[i] = q2[i*4+chan+endian]; +#else + l2[i] = q2[i*4+chan]; +#endif + } } // Bi-directional error diffusion if (y&1) { @@ -2452,14 +2461,12 @@ static void convert_RGB_to_Indexed8(QImageData *dst, const QImageData *src, Qt:: } } } - if (endian) { - for (int x = 0; x < src->width; x++) { - *b++ = INDEXOF(pv[0][x],pv[1][x],pv[2][x]); - } - } else { - for (int x = 0; x < src->width; x++) { - *b++ = INDEXOF(pv[2][x],pv[1][x],pv[0][x]); - } + for (int x = 0; x < src->width; x++) { +#if Q_BYTE_ORDER == Q_BIG_ENDIAN + *b++ = INDEXOF(pv[0][x],pv[1][x],pv[2][x]); +#else + *b++ = INDEXOF(pv[2][x],pv[1][x],pv[0][x]); +#endif } src_data += src->bytes_per_line; dest_data += dst->bytes_per_line; diff --git a/src/gui/image/qpixmap_x11.cpp b/src/gui/image/qpixmap_x11.cpp index d948b46e1..0aeea1e05 100644 --- a/src/gui/image/qpixmap_x11.cpp +++ b/src/gui/image/qpixmap_x11.cpp @@ -863,18 +863,16 @@ void QX11PixmapData::fromImage(const QImage &img, break; case BPP24_888: CYCLE( - if (QSysInfo::ByteOrder == QSysInfo::BigEndian) { - for (int x=0; x> 8) + - ((str.at(i).unicode() << 8) & 0xff00)); +#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN + for (int i = 0; i < str.length(); ++i) { + str[i] = QChar((str.at(i).unicode() >> 8) + + ((str.at(i).unicode() << 8) & 0xff00)); } +#endif translations << str; m += len; break;