diff options
author | Johan Klokkhammer Helsing <johan.helsing@qt.io> | 2019-08-16 12:54:56 +0200 |
---|---|---|
committer | Johan Klokkhammer Helsing <johan.helsing@qt.io> | 2019-08-17 09:06:07 +0200 |
commit | 2838c7f33a0b2f40b026d00b3e00139f94c358e7 (patch) | |
tree | be3e74489ef1f13de32934406759dbfde091b6f1 | |
parent | 86b0d64b6c44fd8c3c3dd133bf52239f5520e524 (diff) | |
download | qtwayland-2838c7f33a0b2f40b026d00b3e00139f94c358e7.tar.gz |
Fix incorrect conversion to straight alpha pixel formats
Previously, QWaylandSharedMemoryFormatHelper::fromWaylandShmFormat(WL_SHM_FORMAT_ARGB8888) would
return Format_ARGB32, i.e. the non-premultiplied version, while, according to the wayland-devel
mailing list (https://lists.freedesktop.org/archives/wayland-devel/2017-August/034791.html), all
Wayland RGB-based pixel formats with alpha should have premultiplied alpha.
This patch makes sure we return the premultiplied variants for ARGB8888, as well as for ABGR8888.
Using a switch instead of the array also allows us more freedom to choose the preferred format in
other cases where multiple QImage formats map to the same wl_shm format.
While being wrapped and exported as QtWaylandClient::QWaylandShm::fromFormat (private API), this
conversion function doesn't seem to be used anywhere, so this patch shouldn't cause any changes in
behavior for projects that only use public API.
Change-Id: Ie09f9a339b4540dd0383a72b3c951eb8c93e3ab4
Reviewed-by: Pier Luigi Fiorini <pierluigi.fiorini@liri.io>
-rw-r--r-- | src/shared/qwaylandsharedmemoryformathelper_p.h | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/src/shared/qwaylandsharedmemoryformathelper_p.h b/src/shared/qwaylandsharedmemoryformathelper_p.h index 85905c02..72cc8401 100644 --- a/src/shared/qwaylandsharedmemoryformathelper_p.h +++ b/src/shared/qwaylandsharedmemoryformathelper_p.h @@ -51,7 +51,26 @@ class QWaylandSharedMemoryFormatHelper { public: static inline wl_shm_format fromQImageFormat(QImage::Format format); - static inline QImage::Format fromWaylandShmFormat(wl_shm_format format); + static inline QImage::Format fromWaylandShmFormat(wl_shm_format format) + { + switch (format) { + case WL_SHM_FORMAT_XRGB8888: return QImage::Format_RGB32; + case WL_SHM_FORMAT_ARGB8888: return QImage::Format_ARGB32_Premultiplied; + case WL_SHM_FORMAT_RGB565: return QImage::Format_RGB16; + case WL_SHM_FORMAT_XRGB1555: return QImage::Format_RGB555; + case WL_SHM_FORMAT_RGB888: return QImage::Format_RGB888; + case WL_SHM_FORMAT_XRGB4444: return QImage::Format_RGB444; + case WL_SHM_FORMAT_ARGB4444: return QImage::Format_ARGB4444_Premultiplied; + case WL_SHM_FORMAT_XBGR8888: return QImage::Format_RGBX8888; + case WL_SHM_FORMAT_ABGR8888: return QImage::Format_RGBA8888_Premultiplied; + case WL_SHM_FORMAT_XBGR2101010: return QImage::Format_BGR30; + case WL_SHM_FORMAT_ABGR2101010: return QImage::Format_A2BGR30_Premultiplied; + case WL_SHM_FORMAT_XRGB2101010: return QImage::Format_RGB30; + case WL_SHM_FORMAT_ARGB2101010: return QImage::Format_A2RGB30_Premultiplied; + case WL_SHM_FORMAT_C8: return QImage::Format_Alpha8; + default: return QImage::Format_Invalid; + } + } static inline QVector<wl_shm_format> supportedWaylandFormats(); private: @@ -108,16 +127,6 @@ wl_shm_format QWaylandSharedMemoryFormatHelper::fromQImageFormat(QImage::Format return array.data[format]; } -QImage::Format QWaylandSharedMemoryFormatHelper::fromWaylandShmFormat(wl_shm_format format) -{ - Array array = getData(); - for (size_t i = 0; i < array.size; i++) { - if (array.data[i] == format) - return QImage::Format(i); - } - return QImage::Format_Invalid; -} - QVector<wl_shm_format> QWaylandSharedMemoryFormatHelper::supportedWaylandFormats() { QVector<wl_shm_format> retFormats; |