72
72
QImage imageForPixbuf(const GdkPixbuf* pixbuf, const QString &name)
75
75
if (gdk_pixbuf_get_n_channels(pixbuf) == 3 && gdk_pixbuf_get_bits_per_sample(pixbuf) == 8 && !gdk_pixbuf_get_has_alpha(pixbuf)) {
76
image = QImage(gdk_pixbuf_get_pixels(pixbuf),
77
gdk_pixbuf_get_width(pixbuf),
78
gdk_pixbuf_get_height(pixbuf),
79
gdk_pixbuf_get_rowstride(pixbuf),
80
QImage::QImage::Format_RGB888);
81
image = image.convertToFormat(QImage::Format_ARGB32);
76
const QImage image = QImage(gdk_pixbuf_get_pixels(pixbuf),
77
gdk_pixbuf_get_width(pixbuf),
78
gdk_pixbuf_get_height(pixbuf),
79
gdk_pixbuf_get_rowstride(pixbuf),
80
QImage::QImage::Format_RGB888);
81
result = image.convertToFormat(QImage::Format_ARGB32);
83
83
if (gdk_pixbuf_get_n_channels(pixbuf) != 4 || gdk_pixbuf_get_bits_per_sample(pixbuf) != 8 || !gdk_pixbuf_get_has_alpha(pixbuf)) {
84
84
UQ_WARNING << "Pixbuf is not in the expected format. Trying to load it anyway, will most likely fail" << name;
86
image = QImage(gdk_pixbuf_get_pixels(pixbuf),
87
gdk_pixbuf_get_width(pixbuf),
88
gdk_pixbuf_get_height(pixbuf),
89
gdk_pixbuf_get_rowstride(pixbuf),
90
QImage::Format_ARGB32);
86
const QImage image = QImage(gdk_pixbuf_get_pixels(pixbuf),
87
gdk_pixbuf_get_width(pixbuf),
88
gdk_pixbuf_get_height(pixbuf),
89
gdk_pixbuf_get_rowstride(pixbuf),
90
QImage::Format_ARGB32);
93
92
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
95
QImage swappedImage = image.rgbSwapped();
94
result = image.rgbSwapped();
98
/* Reference: https://bugs.launchpad.net/unity-2d/+bug/758782 */
99
QImage swappedImage(image.size(), image.format());
100
for (int i = 0; i < swappedImage.height(); ++i) {
101
QRgb* p = (QRgb*) image.constScanLine(i);
102
QRgb* q = (QRgb*) swappedImage.scanLine(i);
103
QRgb* end = p + image.width();
105
*q = qRgba(qAlpha(*p), qRed(*p), qGreen(*p), qBlue(*p));
97
/* Reference: https://bugs.launchpad.net/unity-2d/+bug/758782 */
98
result = QImage(image.size(), image.format());
99
for (int i = 0; i < swappedImage.height(); ++i) {
100
QRgb* p = (QRgb*) image.constScanLine(i);
101
QRgb* q = (QRgb*) swappedImage.scanLine(i);
102
QRgb* end = p + image.width();
104
*q = qRgba(qAlpha(*p), qRed(*p), qGreen(*p), qBlue(*p));