Skip to content

Commit

Permalink
convert endianess from runtime to build checks
Browse files Browse the repository at this point in the history
Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
  • Loading branch information
fluxer committed Aug 4, 2020
1 parent 6d8b5f4 commit a1185e3
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 37 deletions.
7 changes: 4 additions & 3 deletions src/core/kernel/qtranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
10 changes: 4 additions & 6 deletions src/core/tools/qlocale_tools_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
31 changes: 19 additions & 12 deletions src/gui/image/qimage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down
22 changes: 10 additions & 12 deletions src/gui/image/qpixmap_x11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<w; x++) {
*dst++ = qRed (*p);
*dst++ = qGreen(*p);
*dst++ = qBlue (*p++);
}
} else {
for (int x=0; x<w; x++) {
*dst++ = qBlue (*p);
*dst++ = qGreen(*p);
*dst++ = qRed (*p++);
}
for (int x=0; x<w; x++) {
#if Q_BYTE_ORDER == Q_BIG_ENDIAN
*dst++ = qRed (*p);
*dst++ = qGreen(*p);
*dst++ = qBlue (*p++);
#else
*dst++ = qBlue (*p);
*dst++ = qGreen(*p);
*dst++ = qRed (*p++);
#endif
}
)
break;
Expand Down
9 changes: 5 additions & 4 deletions src/shared/linguist/qm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -570,11 +570,12 @@ bool loadQM(Translator &translator, QIODevice &dev, ConversionData &cd)
}
m += 4;
QString str = QString((const QChar *)m, len/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
translations << str;
m += len;
break;
Expand Down

0 comments on commit a1185e3

Please sign in to comment.