From 1efed9d436706353fd4b9f25dfd5e42a5bc98a52 Mon Sep 17 00:00:00 2001 From: defnax Date: Tue, 29 Aug 2023 14:28:18 +0200 Subject: [PATCH 1/3] Fix transparency for channel post thumbnails --- .../src/gui/gxschannels/CreateGxsChannelMsg.cpp | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp b/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp index 05ce9bda6..f00d31539 100644 --- a/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp +++ b/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp @@ -35,6 +35,7 @@ #include "util/rsdir.h" #include "util/qtthreadsutils.h" #include "util/RichTextEdit.h" +#include "util/imageutil.h" #include @@ -610,8 +611,10 @@ bool CreateGxsChannelMsg::setThumbNail(const std::string& path, int frame){ QImage tNail(imageBuffer, width, height, QImage::Format_RGB32); QByteArray ba; QBuffer buffer(&ba); + bool has_transparency = ImageUtil::hasAlphaContent(tNail.toImage()); + buffer.open(QIODevice::WriteOnly); - tNail.save(&buffer, "JPG"); + tNail.save(&buffer, has_transparency?"PNG":"JPG"); QPixmap img; img.loadFromData(ba, "PNG"); img = img.scaled(thumbnail_label->width(), thumbnail_label->height(), Qt::KeepAspectRatio, Qt::SmoothTransformation); @@ -797,15 +800,16 @@ void CreateGxsChannelMsg::sendMessage(const std::string &subject, const std::str QByteArray ba; QBuffer buffer(&ba); - RsGxsImage image; + RsGxsImage image; + bool has_transparency = ImageUtil::hasAlphaContent(picture.toImage()); if(!picture.isNull()) { // send chan image buffer.open(QIODevice::WriteOnly); - preview_W->getCroppedScaledPicture().save(&buffer, "JPG"); // writes image into ba in PNG format - image.copy((uint8_t *) ba.data(), ba.size()); + preview_W->getCroppedScaledPicture().save(&buffer, has_transparency?"PNG":"JPG"); // writes image into ba in PNG format + image.copy((uint8_t *) ba.data(), ba.size()); } std::string error_string; From 43afcf3f98c41fa578c9bbc2e545c776ce092955 Mon Sep 17 00:00:00 2001 From: defnax Date: Tue, 5 Sep 2023 21:10:38 +0200 Subject: [PATCH 2/3] Fix to use RGBA32 --- retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp b/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp index f00d31539..66311d6fa 100644 --- a/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp +++ b/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp @@ -608,7 +608,7 @@ bool CreateGxsChannelMsg::setThumbNail(const std::string& path, int frame){ if(imageBuffer == NULL) return false; - QImage tNail(imageBuffer, width, height, QImage::Format_RGB32); + QImage tNail(imageBuffer, width, height, QImage::Format_RGBA32); QByteArray ba; QBuffer buffer(&ba); bool has_transparency = ImageUtil::hasAlphaContent(tNail.toImage()); From d5088caac6a70b3a7dbf5cc9bb763b07f8c0131b Mon Sep 17 00:00:00 2001 From: defnax Date: Mon, 11 Sep 2023 21:54:54 +0200 Subject: [PATCH 3/3] fix second part for transparency check --- retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp b/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp index 66311d6fa..bc2f5d960 100644 --- a/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp +++ b/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp @@ -801,7 +801,10 @@ void CreateGxsChannelMsg::sendMessage(const std::string &subject, const std::str QBuffer buffer(&ba); RsGxsImage image; - bool has_transparency = ImageUtil::hasAlphaContent(picture.toImage()); + QPixmap pixmap; + pixmap = preview_W->getCroppedScaledPicture(); + QImage qimg = pixmap.toImage(); + bool has_transparency = ImageUtil::hasAlphaContent(qimg); if(!picture.isNull()) {