D-Bus tray icons: make endian conversion work again
Endian conversion needs to be done on aligned data, but the data is stored unaligned in the QByteArray. So the new qFromUnaligned() function is needed. Change-Id: I12f9e52cea81d06129b306709bb9d2cd004f04e1 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
5facb0ce90
commit
e20a8c69a7
@ -93,14 +93,13 @@ QXdgDBusImageVector iconToQXdgDBusImageVector(const QIcon &icon)
|
||||
painter.drawImage((maxSize - im.width()) / 2, (maxSize - im.height()) / 2, im);
|
||||
im = padded;
|
||||
}
|
||||
QXdgDBusImageStruct kim;
|
||||
kim.width = im.width();
|
||||
kim.height = im.height();
|
||||
kim.data = QByteArray(reinterpret_cast<const char*>(im.constBits()), im.byteCount());
|
||||
if (QSysInfo::ByteOrder == QSysInfo::LittleEndian) {
|
||||
for (char *ptr = kim.data.begin(); ptr < kim.data.end(); ptr += 4)
|
||||
qToUnaligned(qToBigEndian<quint32>(*ptr), reinterpret_cast<uchar *>(ptr));
|
||||
}
|
||||
// copy and endian-convert
|
||||
QXdgDBusImageStruct kim(im.width(), im.height());
|
||||
const uchar *end = im.constBits() + im.byteCount();
|
||||
uchar *dest = reinterpret_cast<uchar *>(kim.data.data());
|
||||
for (const uchar *src = im.constBits(); src < end; src += 4, dest += 4)
|
||||
qToUnaligned(qToBigEndian<quint32>(qFromUnaligned<quint32>(src)), dest);
|
||||
|
||||
ret << kim;
|
||||
}
|
||||
return ret;
|
||||
|
@ -49,6 +49,9 @@ QT_BEGIN_NAMESPACE
|
||||
// Custom message type to send icons across D-Bus
|
||||
struct QXdgDBusImageStruct
|
||||
{
|
||||
QXdgDBusImageStruct() { }
|
||||
QXdgDBusImageStruct(int w, int h)
|
||||
: width(w), height(h), data(width * height * 4, 0) { }
|
||||
int width;
|
||||
int height;
|
||||
QByteArray data;
|
||||
|
Loading…
Reference in New Issue
Block a user