Skip to content
This repository has been archived by the owner on Jul 23, 2020. It is now read-only.

Commit

Permalink
QGtkHelpers: Fix QImage -> GdkPixmap conversion for all cases
Browse files Browse the repository at this point in the history
If this isn't in one of the two correct formats, make it so. Also check
that the image actually has alpha before telling GdkPixmap it does.

This fixes copying images in some cases having a whacky color in
Telegram Desktop.
  • Loading branch information
rburchell committed Sep 25, 2017
1 parent 7f72dbc commit 0b04afa
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions src/qgtkhelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,26 @@

#include "qgtkhelpers.h"

QGtkRefPtr<GdkPixbuf> qt_imageToPixbuf(const QImage &image)
QGtkRefPtr<GdkPixbuf> qt_imageToPixbuf(const QImage &cimage)
{
if (image.isNull())
if (cimage.isNull())
return 0;
QImage image = cimage;
if (image.hasAlphaChannel()) {
if (image.format() != QImage::Format_RGBA8888) {
image = image.convertToFormat(QImage::Format_RGBA8888);
}
} else {
if (image.format() != QImage::Format_RGB888) {
image = image.convertToFormat(QImage::Format_RGB888);
}
}
guchar *buf = (guchar*)malloc(image.byteCount());
memcpy(buf, image.constBits(), image.byteCount());
QGtkRefPtr<GdkPixbuf> gpb = gdk_pixbuf_new_from_data(
buf,
GDK_COLORSPACE_RGB,
true, // ### assert image is in RGBA
image.hasAlphaChannel(),
8,
image.width(),
image.height(),
Expand Down

0 comments on commit 0b04afa

Please sign in to comment.