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>
This commit is contained in:
parent
0b803993e7
commit
7163c286e4
@ -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;
|
||||
|
Loading…
x
Reference in New Issue
Block a user