From 0a8f4b1b6e771de88ff9f4259a59e66c851cdbbd Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 16 Jan 2023 19:53:20 +0100 Subject: [PATCH 1/6] switched all image outputs to jpeg format instead of png --- retroshare-gui/src/gui/Identity/IdEditDialog.cpp | 4 ++-- retroshare-gui/src/gui/PhotoShare/AlbumGroupDialog.cpp | 2 +- retroshare-gui/src/gui/PhotoShare/AlbumItem.cpp | 2 +- retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.cpp | 2 +- retroshare-gui/src/gui/Posted/PostedGroupDialog.cpp | 2 +- retroshare-gui/src/gui/TheWire/WireGroupDialog.cpp | 2 +- retroshare-gui/src/gui/chat/ChatWidget.cpp | 2 +- retroshare-gui/src/gui/common/AvatarDialog.cpp | 2 +- retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp | 4 ++-- retroshare-gui/src/gui/gxschannels/GxsChannelGroupDialog.cpp | 2 +- .../src/gui/gxschannels/GxsChannelPostThumbnail.cpp | 2 +- .../src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp | 2 +- retroshare-gui/src/util/imageutil.cpp | 2 +- retroshare-gui/src/util/misc.cpp | 2 +- 14 files changed, 16 insertions(+), 16 deletions(-) diff --git a/retroshare-gui/src/gui/Identity/IdEditDialog.cpp b/retroshare-gui/src/gui/Identity/IdEditDialog.cpp index 4b5095fb3..ad46cc19b 100644 --- a/retroshare-gui/src/gui/Identity/IdEditDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdEditDialog.cpp @@ -577,7 +577,7 @@ void IdEditDialog::createId() QBuffer buffer(&ba); buffer.open(QIODevice::WriteOnly); - mAvatar.save(&buffer, "PNG"); // writes image into ba in PNG format + mAvatar.save(&buffer, "JPG"); // writes image into ba in PNG format params.mImage.copy((uint8_t *) ba.data(), ba.size()); } @@ -649,7 +649,7 @@ void IdEditDialog::updateId() QBuffer buffer(&ba); buffer.open(QIODevice::WriteOnly); - mAvatar.save(&buffer, "PNG"); // writes image into ba in PNG format + mAvatar.save(&buffer, "JPG"); // writes image into ba in PNG format mEditGroup.mImage.copy((uint8_t *) ba.data(), ba.size()); } diff --git a/retroshare-gui/src/gui/PhotoShare/AlbumGroupDialog.cpp b/retroshare-gui/src/gui/PhotoShare/AlbumGroupDialog.cpp index 2900ad674..dd0c725b7 100644 --- a/retroshare-gui/src/gui/PhotoShare/AlbumGroupDialog.cpp +++ b/retroshare-gui/src/gui/PhotoShare/AlbumGroupDialog.cpp @@ -115,7 +115,7 @@ void AlbumGroupDialog::prepareAlbumGroup(RsPhotoAlbum &group, const RsGroupMetaD QBuffer buffer(&ba); buffer.open(QIODevice::WriteOnly); - pixmap.save(&buffer, "PNG"); // writes image into ba in PNG format + pixmap.save(&buffer, "JPG"); // writes image into ba in PNG format group.mThumbnail.copy((uint8_t *) ba.data(), ba.size()); } else { diff --git a/retroshare-gui/src/gui/PhotoShare/AlbumItem.cpp b/retroshare-gui/src/gui/PhotoShare/AlbumItem.cpp index a28b500e5..fea04adbc 100644 --- a/retroshare-gui/src/gui/PhotoShare/AlbumItem.cpp +++ b/retroshare-gui/src/gui/PhotoShare/AlbumItem.cpp @@ -47,7 +47,7 @@ void AlbumItem::setUp() if(mAlbum.mThumbnail.mSize != 0) { QPixmap qtn; - qtn.loadFromData(mAlbum.mThumbnail.mData, mAlbum.mThumbnail.mSize, "PNG"); + qtn.loadFromData(mAlbum.mThumbnail.mData, mAlbum.mThumbnail.mSize, "JPG"); ui->label_Thumbnail->setPixmap(qtn); } else diff --git a/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.cpp b/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.cpp index da47d7596..8209b5d1b 100644 --- a/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.cpp +++ b/retroshare-gui/src/gui/Posted/BoardPostDisplayWidget.cpp @@ -330,7 +330,7 @@ void BoardPostDisplayWidget_compact::setup() #ifdef DEBUG_BOARDPOSTDISPLAYWIDGET std::cerr << "Got pixmap of size " << pixmap.width() << " x " << pixmap.height() << std::endl; std::cerr << "Saving to pix.png" << std::endl; - pixmap.save("pix.png","PNG"); + pixmap.save("pix.png","JPG"); #endif ui->pictureLabel->setPicture(pixmap); diff --git a/retroshare-gui/src/gui/Posted/PostedGroupDialog.cpp b/retroshare-gui/src/gui/Posted/PostedGroupDialog.cpp index 6414db7cd..b4791f5ca 100644 --- a/retroshare-gui/src/gui/Posted/PostedGroupDialog.cpp +++ b/retroshare-gui/src/gui/Posted/PostedGroupDialog.cpp @@ -105,7 +105,7 @@ void PostedGroupDialog::preparePostedGroup(RsPostedGroup &group, const RsGroupMe QBuffer buffer(&ba); buffer.open(QIODevice::WriteOnly); - pixmap.save(&buffer, "PNG"); // writes image into ba in PNG format + pixmap.save(&buffer, "JPG"); // writes image into ba in PNG format group.mGroupImage.copy((uint8_t *) ba.data(), ba.size()); } else { diff --git a/retroshare-gui/src/gui/TheWire/WireGroupDialog.cpp b/retroshare-gui/src/gui/TheWire/WireGroupDialog.cpp index 1be0c9a2c..29cba1d5c 100644 --- a/retroshare-gui/src/gui/TheWire/WireGroupDialog.cpp +++ b/retroshare-gui/src/gui/TheWire/WireGroupDialog.cpp @@ -109,7 +109,7 @@ void WireGroupDialog::prepareWireGroup(RsWireGroup &group, const RsGroupMetaData QBuffer buffer(&ba); buffer.open(QIODevice::WriteOnly); - pixmap.save(&buffer, "PNG"); // writes image into ba in PNG format + pixmap.save(&buffer, "JPG"); // writes image into ba in PNG format group.mHeadshot.copy((uint8_t *) ba.data(), ba.size()); } else { diff --git a/retroshare-gui/src/gui/chat/ChatWidget.cpp b/retroshare-gui/src/gui/chat/ChatWidget.cpp index ab198fa33..868b6f150 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.cpp +++ b/retroshare-gui/src/gui/chat/ChatWidget.cpp @@ -1094,7 +1094,7 @@ void ChatWidget::addChatMsg(bool incoming, const QString &name, const RsGxsId gx QImage image(icon.pixmap(height,height).toImage()); QByteArray byteArray; QBuffer buffer(&byteArray); - image.save(&buffer, "PNG"); // writes the image in PNG format inside the buffer + image.save(&buffer, "JPG"); // writes the image in PNG format inside the buffer QString iconBase64 = QString::fromLatin1(byteArray.toBase64().data()); strPreName = QString("\"[unsigned]\"").arg(iconBase64); } diff --git a/retroshare-gui/src/gui/common/AvatarDialog.cpp b/retroshare-gui/src/gui/common/AvatarDialog.cpp index 632fa2948..4da8b3b76 100644 --- a/retroshare-gui/src/gui/common/AvatarDialog.cpp +++ b/retroshare-gui/src/gui/common/AvatarDialog.cpp @@ -141,7 +141,7 @@ void AvatarDialog::getAvatar(QByteArray &avatar) QBuffer buffer(&avatar); buffer.open(QIODevice::WriteOnly); - pixmap.save(&buffer, "PNG"); // writes image into ba in PNG format + pixmap.save(&buffer, "JPG"); // writes image into ba in PNG format } void AvatarDialog::load() diff --git a/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp b/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp index e8f34d1eb..c834ae3da 100644 --- a/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp +++ b/retroshare-gui/src/gui/gxschannels/CreateGxsChannelMsg.cpp @@ -611,7 +611,7 @@ bool CreateGxsChannelMsg::setThumbNail(const std::string& path, int frame){ QByteArray ba; QBuffer buffer(&ba); buffer.open(QIODevice::WriteOnly); - tNail.save(&buffer, "PNG"); + tNail.save(&buffer, "JPG"); QPixmap img; img.loadFromData(ba, "PNG"); img = img.scaled(thumbnail_label->width(), thumbnail_label->height(), Qt::KeepAspectRatio, Qt::SmoothTransformation); @@ -814,7 +814,7 @@ void CreateGxsChannelMsg::sendMessage(const std::string &subject, const std::str // send chan image buffer.open(QIODevice::WriteOnly); - preview_W->getCroppedScaledPicture().save(&buffer, "PNG"); // writes image into ba in PNG format + preview_W->getCroppedScaledPicture().save(&buffer, "JPG"); // writes image into ba in PNG format post.mThumbnail.copy((uint8_t *) ba.data(), ba.size()); } diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelGroupDialog.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelGroupDialog.cpp index a98e9016a..e82795abf 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelGroupDialog.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelGroupDialog.cpp @@ -120,7 +120,7 @@ void GxsChannelGroupDialog::prepareChannelGroup(RsGxsChannelGroup &group, const QBuffer buffer(&ba); buffer.open(QIODevice::WriteOnly); - pixmap.save(&buffer, "PNG"); // writes image into ba in PNG format + pixmap.save(&buffer, "JPG"); // writes image into ba in PNG format group.mImage.copy((uint8_t *) ba.data(), ba.size()); } else { diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostThumbnail.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostThumbnail.cpp index ee40e1465..16cf96195 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostThumbnail.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostThumbnail.cpp @@ -350,7 +350,7 @@ void ZoomableLabel::updateView() std::cerr << " Image size: " << mFullImage.width() << " x " << mFullImage.height() << ", window size: " << width() << " x " << height() << std::endl; std::cerr << " cropped image: " << rect.left() << "," << rect.top() << "+" << rect.width() << "+" << rect.height() << std::endl; std::cerr << " saving crop to pix2.png" << std::endl; - mFullImage.copy(rect).save("pix2.png","PNG"); + mFullImage.copy(rect).save("pix2.png","JPG"); #endif QLabel::setPixmap(mFullImage.copy(rect)); } diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp index fbf09350a..1d8de3f89 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelPostsWidgetWithModel.cpp @@ -164,7 +164,7 @@ void ChannelPostDelegate::paint(QPainter * painter, const QStyleOptionViewItem & // { // QFile file("yourFile.png"); // file.open(QIODevice::WriteOnly); -// pixmap.save(&file, "PNG"); +// pixmap.save(&file, "JPG"); // file.close(); // } diff --git a/retroshare-gui/src/util/imageutil.cpp b/retroshare-gui/src/util/imageutil.cpp index 47029505e..92ce05f70 100644 --- a/retroshare-gui/src/util/imageutil.cpp +++ b/retroshare-gui/src/util/imageutil.cpp @@ -166,7 +166,7 @@ int ImageUtil::checkSize(QByteArray &bytearray, const QImage &img) //std::cout << QString("Trying image: format PNG, size %1x%2, colors %3\n").arg(img.width()).arg(img.height()).arg(img.colorCount()).toStdString(); if (buffer.open(QIODevice::WriteOnly)) { - if (img.save(&buffer, "PNG", 0)) { + if (img.save(&buffer, "JPG", 0)) { size = bytearray.length(); } else { std::cerr << "ImageUtil: image can't be saved to buffer" << std::endl; diff --git a/retroshare-gui/src/util/misc.cpp b/retroshare-gui/src/util/misc.cpp index 2f6337d1b..dce286e60 100644 --- a/retroshare-gui/src/util/misc.cpp +++ b/retroshare-gui/src/util/misc.cpp @@ -291,7 +291,7 @@ bool misc::getOpenAvatarPicture(QWidget *parent, QByteArray &image_data) // save image in QByteArray QBuffer buffer(&image_data); buffer.open(QIODevice::WriteOnly); - picture.save(&buffer, "PNG"); // writes image into ba in PNG format + picture.save(&buffer, "JPG"); // writes image into ba in JPG format return true; } From 31bdd6c226fcd18c3d7c4343a43cd24da2873da1 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 16 Jan 2023 20:16:44 +0100 Subject: [PATCH 2/6] keep PNG for avatars --- retroshare-gui/src/gui/Identity/IdEditDialog.cpp | 4 ++-- retroshare-gui/src/gui/Posted/PostedGroupDialog.cpp | 2 +- retroshare-gui/src/gui/TheWire/WireGroupDialog.cpp | 2 +- retroshare-gui/src/gui/chat/ChatWidget.cpp | 2 +- retroshare-gui/src/gui/common/AvatarDialog.cpp | 2 +- retroshare-gui/src/gui/gxschannels/GxsChannelGroupDialog.cpp | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/retroshare-gui/src/gui/Identity/IdEditDialog.cpp b/retroshare-gui/src/gui/Identity/IdEditDialog.cpp index ad46cc19b..5b7991c6f 100644 --- a/retroshare-gui/src/gui/Identity/IdEditDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdEditDialog.cpp @@ -577,7 +577,7 @@ void IdEditDialog::createId() QBuffer buffer(&ba); buffer.open(QIODevice::WriteOnly); - mAvatar.save(&buffer, "JPG"); // writes image into ba in PNG format + mAvatar.save(&buffer, "PNG"); // writes image into ba in PNG format params.mImage.copy((uint8_t *) ba.data(), ba.size()); } @@ -649,7 +649,7 @@ void IdEditDialog::updateId() QBuffer buffer(&ba); buffer.open(QIODevice::WriteOnly); - mAvatar.save(&buffer, "JPG"); // writes image into ba in PNG format + mAvatar.save(&buffer, "PNG"); // writes image into ba in PNG format mEditGroup.mImage.copy((uint8_t *) ba.data(), ba.size()); } diff --git a/retroshare-gui/src/gui/Posted/PostedGroupDialog.cpp b/retroshare-gui/src/gui/Posted/PostedGroupDialog.cpp index b4791f5ca..b4b544810 100644 --- a/retroshare-gui/src/gui/Posted/PostedGroupDialog.cpp +++ b/retroshare-gui/src/gui/Posted/PostedGroupDialog.cpp @@ -105,7 +105,7 @@ void PostedGroupDialog::preparePostedGroup(RsPostedGroup &group, const RsGroupMe QBuffer buffer(&ba); buffer.open(QIODevice::WriteOnly); - pixmap.save(&buffer, "JPG"); // writes image into ba in PNG format + pixmap.save(&buffer, "PNG"); // writes image into ba in PNG format group.mGroupImage.copy((uint8_t *) ba.data(), ba.size()); } else { diff --git a/retroshare-gui/src/gui/TheWire/WireGroupDialog.cpp b/retroshare-gui/src/gui/TheWire/WireGroupDialog.cpp index 29cba1d5c..139961640 100644 --- a/retroshare-gui/src/gui/TheWire/WireGroupDialog.cpp +++ b/retroshare-gui/src/gui/TheWire/WireGroupDialog.cpp @@ -109,7 +109,7 @@ void WireGroupDialog::prepareWireGroup(RsWireGroup &group, const RsGroupMetaData QBuffer buffer(&ba); buffer.open(QIODevice::WriteOnly); - pixmap.save(&buffer, "JPG"); // writes image into ba in PNG format + pixmap.save(&buffer, "PNG"); // writes image into ba in PNG format group.mHeadshot.copy((uint8_t *) ba.data(), ba.size()); } else { diff --git a/retroshare-gui/src/gui/chat/ChatWidget.cpp b/retroshare-gui/src/gui/chat/ChatWidget.cpp index 868b6f150..880b5a640 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.cpp +++ b/retroshare-gui/src/gui/chat/ChatWidget.cpp @@ -1094,7 +1094,7 @@ void ChatWidget::addChatMsg(bool incoming, const QString &name, const RsGxsId gx QImage image(icon.pixmap(height,height).toImage()); QByteArray byteArray; QBuffer buffer(&byteArray); - image.save(&buffer, "JPG"); // writes the image in PNG format inside the buffer + image.save(&buffer, "PNG"); // writes the image in PNG format inside the buffer QString iconBase64 = QString::fromLatin1(byteArray.toBase64().data()); strPreName = QString("\"[unsigned]\"").arg(iconBase64); } diff --git a/retroshare-gui/src/gui/common/AvatarDialog.cpp b/retroshare-gui/src/gui/common/AvatarDialog.cpp index 4da8b3b76..a657d2a1a 100644 --- a/retroshare-gui/src/gui/common/AvatarDialog.cpp +++ b/retroshare-gui/src/gui/common/AvatarDialog.cpp @@ -141,7 +141,7 @@ void AvatarDialog::getAvatar(QByteArray &avatar) QBuffer buffer(&avatar); buffer.open(QIODevice::WriteOnly); - pixmap.save(&buffer, "JPG"); // writes image into ba in PNG format + pixmap.save(&buffer, "PNG"); // writes image into ba in PNG format } void AvatarDialog::load() diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelGroupDialog.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelGroupDialog.cpp index e82795abf..8b9d8d881 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelGroupDialog.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelGroupDialog.cpp @@ -120,7 +120,7 @@ void GxsChannelGroupDialog::prepareChannelGroup(RsGxsChannelGroup &group, const QBuffer buffer(&ba); buffer.open(QIODevice::WriteOnly); - pixmap.save(&buffer, "JPG"); // writes image into ba in PNG format + pixmap.save(&buffer, "PNG"); // writes image into ba in PNG format group.mImage.copy((uint8_t *) ba.data(), ba.size()); } else { From 516e4f7c12bb6fcce088b1d4ef163e3cedd6c450 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 16 Jan 2023 21:11:18 +0100 Subject: [PATCH 3/6] added parameter to specify format to optimizeImageSize() --- .../src/gui/PhotoShare/AlbumGroupDialog.cpp | 2 +- .../src/gui/Posted/PostedCreatePostDialog.cpp | 2 +- .../src/gui/TheWire/WireGroupDialog.cpp | 2 +- retroshare-gui/src/gui/chat/ChatWidget.cpp | 2 +- .../src/gui/gxsforums/GxsForumModel.cpp | 2 +- retroshare-gui/src/util/HandleRichText.cpp | 4 ++-- retroshare-gui/src/util/HandleRichText.h | 2 +- retroshare-gui/src/util/imageutil.cpp | 18 +++++++++--------- retroshare-gui/src/util/imageutil.h | 6 +++--- retroshare-gui/src/util/misc.cpp | 2 +- 10 files changed, 21 insertions(+), 21 deletions(-) diff --git a/retroshare-gui/src/gui/PhotoShare/AlbumGroupDialog.cpp b/retroshare-gui/src/gui/PhotoShare/AlbumGroupDialog.cpp index dd0c725b7..2900ad674 100644 --- a/retroshare-gui/src/gui/PhotoShare/AlbumGroupDialog.cpp +++ b/retroshare-gui/src/gui/PhotoShare/AlbumGroupDialog.cpp @@ -115,7 +115,7 @@ void AlbumGroupDialog::prepareAlbumGroup(RsPhotoAlbum &group, const RsGroupMetaD QBuffer buffer(&ba); buffer.open(QIODevice::WriteOnly); - pixmap.save(&buffer, "JPG"); // writes image into ba in PNG format + pixmap.save(&buffer, "PNG"); // writes image into ba in PNG format group.mThumbnail.copy((uint8_t *) ba.data(), ba.size()); } else { diff --git a/retroshare-gui/src/gui/Posted/PostedCreatePostDialog.cpp b/retroshare-gui/src/gui/Posted/PostedCreatePostDialog.cpp index c1e0ce5ad..aace423f8 100644 --- a/retroshare-gui/src/gui/Posted/PostedCreatePostDialog.cpp +++ b/retroshare-gui/src/gui/Posted/PostedCreatePostDialog.cpp @@ -224,7 +224,7 @@ void PostedCreatePostDialog::addPicture() } QImage opt; - if(ImageUtil::optimizeSizeBytes(imagebytes, image, opt, 640*480, MAXMESSAGESIZE - 2000)) { //Leave space for other stuff + if(ImageUtil::optimizeSizeBytes(imagebytes, image, opt,"JPG", 640*480, MAXMESSAGESIZE - 2000)) { //Leave space for other stuff ui->imageLabel->setPixmap(QPixmap::fromImage(opt)); ui->stackedWidgetPicture->setCurrentIndex(IMG_PICTURE); ui->removeButton->show(); diff --git a/retroshare-gui/src/gui/TheWire/WireGroupDialog.cpp b/retroshare-gui/src/gui/TheWire/WireGroupDialog.cpp index 139961640..e13cd4f8f 100644 --- a/retroshare-gui/src/gui/TheWire/WireGroupDialog.cpp +++ b/retroshare-gui/src/gui/TheWire/WireGroupDialog.cpp @@ -126,7 +126,7 @@ void WireGroupDialog::prepareWireGroup(RsWireGroup &group, const RsGroupMetaData QBuffer buffer(&ba); buffer.open(QIODevice::WriteOnly); - pixmap.save(&buffer, "JPG"); + pixmap.save(&buffer, "PNG"); group.mMasthead.copy((uint8_t *) ba.data(), ba.size()); } else { diff --git a/retroshare-gui/src/gui/chat/ChatWidget.cpp b/retroshare-gui/src/gui/chat/ChatWidget.cpp index 880b5a640..72e2db1d8 100644 --- a/retroshare-gui/src/gui/chat/ChatWidget.cpp +++ b/retroshare-gui/src/gui/chat/ChatWidget.cpp @@ -1677,7 +1677,7 @@ void ChatWidget::addExtraPicture() if (misc::getOpenFileName(window(), RshareSettings::LASTDIR_IMAGES, tr("Load Picture File"), "Pictures (*.png *.xpm *.jpg *.jpeg *.gif *.webp )", file)) { QString encodedImage; uint32_t maxMessageSize = this->maxMessageSize(); - if (RsHtml::makeEmbeddedImage(file, encodedImage, 640*480, maxMessageSize - 200)) { //-200 for the html stuff + if (RsHtml::makeEmbeddedImage(file, encodedImage, 640*480, maxMessageSize - 200)) { //-200 for the html stuff QTextDocumentFragment fragment = QTextDocumentFragment::fromHtml(encodedImage); ui->chatTextEdit->textCursor().insertFragment(fragment); } diff --git a/retroshare-gui/src/gui/gxsforums/GxsForumModel.cpp b/retroshare-gui/src/gui/gxsforums/GxsForumModel.cpp index 07d44ca1b..77292dadf 100644 --- a/retroshare-gui/src/gui/gxsforums/GxsForumModel.cpp +++ b/retroshare-gui/src/gui/gxsforums/GxsForumModel.cpp @@ -566,7 +566,7 @@ QVariant RsGxsForumModel::toolTipRole(const ForumModelPostEntry& fmpe,int column QImage pix( (*icons.begin()).pixmap(QSize(5*S,5*S)).toImage()); QString embeddedImage; - if(RsHtml::makeEmbeddedImage(pix.scaled(QSize(5*S,5*S), Qt::KeepAspectRatio, Qt::SmoothTransformation), embeddedImage, -1)) + if(RsHtml::makeEmbeddedImage(pix.scaled(QSize(5*S,5*S), Qt::KeepAspectRatio, Qt::SmoothTransformation), embeddedImage, -1)) { embeddedImage.insert(embeddedImage.indexOf("src="), "style=\"float:left\" "); comment = "
" + embeddedImage + "" + comment + "
"; diff --git a/retroshare-gui/src/util/HandleRichText.cpp b/retroshare-gui/src/util/HandleRichText.cpp index bba7c03af..6f6eec750 100644 --- a/retroshare-gui/src/util/HandleRichText.cpp +++ b/retroshare-gui/src/util/HandleRichText.cpp @@ -1216,7 +1216,7 @@ bool RsHtml::makeEmbeddedImage(const QString &fileName, QString &embeddedImage, fprintf (stderr, "RsHtml::makeEmbeddedImage() - image \"%s\" can't be load\n", fileName.toLatin1().constData()); return false; } - return RsHtml::makeEmbeddedImage(image, embeddedImage, maxPixels, maxBytes); + return RsHtml::makeEmbeddedImage(image, embeddedImage, maxPixels, maxBytes); } /** Converts image to embedded image HTML fragment **/ @@ -1224,7 +1224,7 @@ bool RsHtml::makeEmbeddedImage(const QImage &originalImage, QString &embeddedIma { rstime::RsScopeTimer s("Embed image"); QImage opt; - return ImageUtil::optimizeSizeHtml(embeddedImage, originalImage, opt, maxPixels, maxBytes); + return ImageUtil::optimizeSizeHtml(embeddedImage, originalImage, opt, maxPixels, maxBytes); } QString RsHtml::plainText(const QString &text) diff --git a/retroshare-gui/src/util/HandleRichText.h b/retroshare-gui/src/util/HandleRichText.h index 9462ba865..3e98ea21c 100644 --- a/retroshare-gui/src/util/HandleRichText.h +++ b/retroshare-gui/src/util/HandleRichText.h @@ -70,7 +70,7 @@ public: static QString toHtml(QString text, bool realHtml = true); static bool makeEmbeddedImage(const QString &fileName, QString &embeddedImage, const int maxPixels, const int maxBytes = -1); - static bool makeEmbeddedImage(const QImage &originalImage, QString &embeddedImage, const int maxPixels, const int maxBytes = -1); + static bool makeEmbeddedImage(const QImage &originalImage, QString &embeddedImage, const int maxPixels, const int maxBytes = -1); static QString plainText(const QString &text); static QString plainText(const std::string &text); diff --git a/retroshare-gui/src/util/imageutil.cpp b/retroshare-gui/src/util/imageutil.cpp index 92ce05f70..ca87f534f 100644 --- a/retroshare-gui/src/util/imageutil.cpp +++ b/retroshare-gui/src/util/imageutil.cpp @@ -68,12 +68,12 @@ void ImageUtil::extractImage(QWidget *window, QTextCursor cursor, QString file) } } -bool ImageUtil::optimizeSizeBytes(QByteArray &bytearray, const QImage &original, QImage &optimized, int maxPixels, int maxBytes) +bool ImageUtil::optimizeSizeBytes(QByteArray &bytearray, const QImage &original, QImage &optimized, const char *format, int maxPixels, int maxBytes) { //nothing to do if it fits into the limits optimized = original; if ((maxPixels <= 0) || (optimized.width()*optimized.height() <= maxPixels)) { - int s = checkSize(bytearray, optimized); + int s = checkSize(bytearray, optimized,format); if((maxBytes <= 0) || (s <= maxBytes)) { return true; } @@ -92,7 +92,7 @@ bool ImageUtil::optimizeSizeBytes(QByteArray &bytearray, const QImage &original, //if maxBytes not defined, do not reduce color space, just downscale if(maxBytes <= 0) { - checkSize(bytearray, optimized = original.scaledToWidth(maxwidth, Qt::SmoothTransformation)); + checkSize(bytearray, optimized = original.scaledToWidth(maxwidth, Qt::SmoothTransformation),format); return true; } @@ -100,9 +100,9 @@ bool ImageUtil::optimizeSizeBytes(QByteArray &bytearray, const QImage &original, quantization(original, ct); //Use binary search to find a suitable image size + linear regression to guess the file size - double maxsize = (double)checkSize(bytearray, optimized = original.scaledToWidth(maxwidth, Qt::SmoothTransformation).convertToFormat(QImage::Format_Indexed8, ct, Qt::ThresholdDither)); + double maxsize = (double)checkSize(bytearray, optimized = original.scaledToWidth(maxwidth, Qt::SmoothTransformation).convertToFormat(QImage::Format_Indexed8, ct, Qt::ThresholdDither),format); if(maxsize <= maxBytes) return true; //success - double minsize = (double)checkSize(bytearray, optimized = original.scaledToWidth(minwidth, Qt::SmoothTransformation).convertToFormat(QImage::Format_Indexed8, ct, Qt::ThresholdDither)); + double minsize = (double)checkSize(bytearray, optimized = original.scaledToWidth(minwidth, Qt::SmoothTransformation).convertToFormat(QImage::Format_Indexed8, ct, Qt::ThresholdDither),format); if(minsize > maxBytes) return false; //impossible // std::cout << "maxS: " << maxsize << " minS: " << minsize << std::endl; @@ -115,7 +115,7 @@ bool ImageUtil::optimizeSizeBytes(QByteArray &bytearray, const QImage &original, double b = maxsize - m * ((double)maxwidth * (double)maxwidth / whratio); double a = ((double)(maxBytes - region/2) - b) / m; //maxBytes - region/2 target the center of the accepted region int nextwidth = (int)sqrt(a * whratio); - int nextsize = checkSize(bytearray, optimized = original.scaledToWidth(nextwidth, Qt::SmoothTransformation).convertToFormat(QImage::Format_Indexed8, ct, Qt::ThresholdDither)); + int nextsize = checkSize(bytearray, optimized = original.scaledToWidth(nextwidth, Qt::SmoothTransformation).convertToFormat(QImage::Format_Indexed8, ct, Qt::ThresholdDither),format); if(nextsize <= maxBytes) { minsize = nextsize; minwidth = nextwidth; @@ -145,7 +145,7 @@ bool ImageUtil::optimizeSizeHtml(QString &html, const QImage& original, QImage & if(maxBytes < 1) maxBytes = 1; } - if(optimizeSizeBytes(bytearray, original, optimized, maxPixels, maxBytes)) + if(optimizeSizeBytes(bytearray, original, optimized,"PNG",maxPixels, maxBytes)) { QByteArray encodedByteArray = bytearray.toBase64(); html = "& palette); static void quantization(QList::iterator begin, QList::iterator end, int depth, QVector& palette); static void avgbucket(QList::iterator begin, QList::iterator end, QVector& palette); diff --git a/retroshare-gui/src/util/misc.cpp b/retroshare-gui/src/util/misc.cpp index dce286e60..84c408de3 100644 --- a/retroshare-gui/src/util/misc.cpp +++ b/retroshare-gui/src/util/misc.cpp @@ -291,7 +291,7 @@ bool misc::getOpenAvatarPicture(QWidget *parent, QByteArray &image_data) // save image in QByteArray QBuffer buffer(&image_data); buffer.open(QIODevice::WriteOnly); - picture.save(&buffer, "JPG"); // writes image into ba in JPG format + picture.save(&buffer, "PNG"); // writes image into ba in PNG format return true; } From de1b8f08d20020aeefad72947a39607a42f50082 Mon Sep 17 00:00:00 2001 From: csoler Date: Mon, 16 Jan 2023 21:24:16 +0100 Subject: [PATCH 4/6] added auto-chose of image format if there is no transparency --- retroshare-gui/src/util/imageutil.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/retroshare-gui/src/util/imageutil.cpp b/retroshare-gui/src/util/imageutil.cpp index ca87f534f..7fcd1915e 100644 --- a/retroshare-gui/src/util/imageutil.cpp +++ b/retroshare-gui/src/util/imageutil.cpp @@ -145,7 +145,19 @@ bool ImageUtil::optimizeSizeHtml(QString &html, const QImage& original, QImage & if(maxBytes < 1) maxBytes = 1; } - if(optimizeSizeBytes(bytearray, original, optimized,"PNG",maxPixels, maxBytes)) + // check for transparency + bool has_transparency = false; + + if(original.hasAlphaChannel()) + for(int i=0;i Date: Mon, 16 Jan 2023 22:11:44 +0100 Subject: [PATCH 5/6] added auto-choose of image format when transparency is present --- .../src/gui/Identity/IdEditDialog.cpp | 15 ++++++---- .../src/gui/Posted/PostedGroupDialog.cpp | 9 ++++-- .../src/gui/common/AvatarDialog.cpp | 6 ++-- .../gui/gxschannels/GxsChannelGroupDialog.cpp | 9 ++++-- retroshare-gui/src/util/imageutil.cpp | 30 ++++++++++++------- retroshare-gui/src/util/imageutil.h | 1 + 6 files changed, 47 insertions(+), 23 deletions(-) diff --git a/retroshare-gui/src/gui/Identity/IdEditDialog.cpp b/retroshare-gui/src/gui/Identity/IdEditDialog.cpp index 5b7991c6f..ac9965d2a 100644 --- a/retroshare-gui/src/gui/Identity/IdEditDialog.cpp +++ b/retroshare-gui/src/gui/Identity/IdEditDialog.cpp @@ -31,9 +31,10 @@ #include "util/misc.h" #include "gui/notifyqt.h" -#include -#include +#include "retroshare/rsidentity.h" +#include "retroshare/rspeers.h" #include "gui/common/FilesDefs.h" +#include "util/imageutil.h" #include @@ -576,8 +577,10 @@ void IdEditDialog::createId() QByteArray ba; QBuffer buffer(&ba); + bool has_transparency = ImageUtil::hasAlphaContent(mAvatar.toImage()); + buffer.open(QIODevice::WriteOnly); - mAvatar.save(&buffer, "PNG"); // writes image into ba in PNG format + mAvatar.save(&buffer, has_transparency?"PNG":"JPG"); // writes image into ba in PNG format params.mImage.copy((uint8_t *) ba.data(), ba.size()); } @@ -648,8 +651,10 @@ void IdEditDialog::updateId() QByteArray ba; QBuffer buffer(&ba); - buffer.open(QIODevice::WriteOnly); - mAvatar.save(&buffer, "PNG"); // writes image into ba in PNG format + bool has_transparency = ImageUtil::hasAlphaContent(mAvatar.toImage()); + + buffer.open(QIODevice::WriteOnly); + mAvatar.save(&buffer, has_transparency?"PNG":"JPG"); // writes image into ba in PNG format mEditGroup.mImage.copy((uint8_t *) ba.data(), ba.size()); } diff --git a/retroshare-gui/src/gui/Posted/PostedGroupDialog.cpp b/retroshare-gui/src/gui/Posted/PostedGroupDialog.cpp index b4b544810..f2b011adb 100644 --- a/retroshare-gui/src/gui/Posted/PostedGroupDialog.cpp +++ b/retroshare-gui/src/gui/Posted/PostedGroupDialog.cpp @@ -22,8 +22,9 @@ #include "PostedGroupDialog.h" #include "gui/gxs/GxsIdDetails.h" #include "gui/common/FilesDefs.h" +#include "util/imageutil.h" -#include +#include "retroshare/rswiki.h" #include const uint32_t PostedCreateEnabledFlags = ( @@ -104,8 +105,10 @@ void PostedGroupDialog::preparePostedGroup(RsPostedGroup &group, const RsGroupMe QByteArray ba; QBuffer buffer(&ba); - buffer.open(QIODevice::WriteOnly); - pixmap.save(&buffer, "PNG"); // writes image into ba in PNG format + bool has_transparency = ImageUtil::hasAlphaContent(pixmap.toImage()); + + buffer.open(QIODevice::WriteOnly); + pixmap.save(&buffer, has_transparency?"PNG":"JPG"); // writes image into ba in PNG format group.mGroupImage.copy((uint8_t *) ba.data(), ba.size()); } else { diff --git a/retroshare-gui/src/gui/common/AvatarDialog.cpp b/retroshare-gui/src/gui/common/AvatarDialog.cpp index a657d2a1a..dd302b570 100644 --- a/retroshare-gui/src/gui/common/AvatarDialog.cpp +++ b/retroshare-gui/src/gui/common/AvatarDialog.cpp @@ -40,6 +40,7 @@ #include "util/misc.h" #include "gui/common/FilesDefs.h" #include "util/HandleRichText.h" +#include "util/imageutil.h" #include "retroshare/rsinit.h" #define ICONNAME "groupicon.png" @@ -138,10 +139,11 @@ void AvatarDialog::getAvatar(QByteArray &avatar) return; } - QBuffer buffer(&avatar); + bool has_transparency = ImageUtil::hasAlphaContent(pixmap.toImage()); + QBuffer buffer(&avatar); buffer.open(QIODevice::WriteOnly); - pixmap.save(&buffer, "PNG"); // writes image into ba in PNG format + pixmap.save(&buffer, has_transparency?"PNG":"JPG"); // writes image into ba in PNG format } void AvatarDialog::load() diff --git a/retroshare-gui/src/gui/gxschannels/GxsChannelGroupDialog.cpp b/retroshare-gui/src/gui/gxschannels/GxsChannelGroupDialog.cpp index 8b9d8d881..0af2631c5 100644 --- a/retroshare-gui/src/gui/gxschannels/GxsChannelGroupDialog.cpp +++ b/retroshare-gui/src/gui/gxschannels/GxsChannelGroupDialog.cpp @@ -21,10 +21,11 @@ #include #include "gui/gxs/GxsIdDetails.h" +#include "util/imageutil.h" #include "gui/common/FilesDefs.h" #include "GxsChannelGroupDialog.h" -#include +#include "retroshare/rsgxschannels.h" #include // To start with we only have open forums - with distribution controls. @@ -119,8 +120,10 @@ void GxsChannelGroupDialog::prepareChannelGroup(RsGxsChannelGroup &group, const QByteArray ba; QBuffer buffer(&ba); - buffer.open(QIODevice::WriteOnly); - pixmap.save(&buffer, "PNG"); // writes image into ba in PNG format + bool has_transparency = ImageUtil::hasAlphaContent(pixmap.toImage()); + + buffer.open(QIODevice::WriteOnly); + pixmap.save(&buffer, has_transparency?"PNG":"JPG"); // writes image into ba in PNG format group.mImage.copy((uint8_t *) ba.data(), ba.size()); } else { diff --git a/retroshare-gui/src/util/imageutil.cpp b/retroshare-gui/src/util/imageutil.cpp index 7fcd1915e..7553f7c14 100644 --- a/retroshare-gui/src/util/imageutil.cpp +++ b/retroshare-gui/src/util/imageutil.cpp @@ -137,6 +137,25 @@ bool ImageUtil::optimizeSizeBytes(QByteArray &bytearray, const QImage &original, //std::cout << html.toStdString() << std::endl; } +bool ImageUtil::hasAlphaContent(const QImage& image) +{ + if(!image.hasAlphaChannel()) + { + std::cerr << "Image of size " << image.width() << " x " << image.height() << ": No transparency content detected." << std::endl; + return false; + } + + for(int i=0;i Date: Mon, 16 Jan 2023 22:23:58 +0100 Subject: [PATCH 6/6] fixed bug in quality of html-embedded images --- retroshare-gui/src/util/imageutil.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/retroshare-gui/src/util/imageutil.cpp b/retroshare-gui/src/util/imageutil.cpp index 7553f7c14..d710a9ae3 100644 --- a/retroshare-gui/src/util/imageutil.cpp +++ b/retroshare-gui/src/util/imageutil.cpp @@ -188,7 +188,7 @@ int ImageUtil::checkSize(QByteArray &bytearray, const QImage &img,const char *fo //std::cout << QString("Trying image: format PNG, size %1x%2, colors %3\n").arg(img.width()).arg(img.height()).arg(img.colorCount()).toStdString(); if (buffer.open(QIODevice::WriteOnly)) { - if (img.save(&buffer, format, 0)) { + if (img.save(&buffer, format, 85)) { size = bytearray.length(); } else { std::cerr << "ImageUtil: image can't be saved to buffer" << std::endl;