~aacid/unity-2d/panel_click_gives_focus_to_maximized_windows

« back to all changes in this revision

Viewing changes to libunity-2d-private/src/gimageutils.cpp

  • Committer: Tarmac
  • Author(s): Albert Astals, Gerry Boland
  • Date: 2012-05-21 16:02:36 UTC
  • mfrom: (1096.1.3 more_24_bit_stuff)
  • Revision ID: tarmac-20120521160236-w84doswbrddq1on6
[lib] Load more types of 24 bit icons correctly, by preventing unnecessary ABGR → ARGB conversion in that case.

To the unit tests added three rgb dots to the existing colormapped image and then check for them. Also added a 24 bit non-colormapped image to check no ABGR → ARGB occurs.. Fixes: https://bugs.launchpad.net/bugs/977262. Approved by Gerry Boland.

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
 
72
72
QImage imageForPixbuf(const GdkPixbuf* pixbuf, const QString &name)
73
73
{
74
 
    QImage image;
 
74
    QImage result;
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);
82
82
    } else {
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;
85
85
        }
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);
91
 
    }
 
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);
92
91
 
93
92
#if Q_BYTE_ORDER == Q_LITTLE_ENDIAN
94
 
    /* ABGR → ARGB */
95
 
    QImage swappedImage = image.rgbSwapped();
 
93
        /* ABGR → ARGB */
 
94
        result = image.rgbSwapped();
96
95
#else
97
 
    /* ABGR → BGRA */
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();
104
 
        while (p < end) {
105
 
            *q = qRgba(qAlpha(*p), qRed(*p), qGreen(*p), qBlue(*p));
106
 
            p++;
107
 
            q++;
 
96
        /* ABGR → BGRA */
 
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();
 
103
            while (p < end) {
 
104
                *q = qRgba(qAlpha(*p), qRed(*p), qGreen(*p), qBlue(*p));
 
105
                p++;
 
106
                q++;
 
107
            }
108
108
        }
109
 
    }
110
109
#endif
 
110
    }
111
111
 
112
 
    return swappedImage;
 
112
    return result;
113
113
}
114
114
 
115
115
} // namespace