mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-12-26 07:59:35 -05:00
Merge pull request #2669 from csoler/v0.6-ImprovedGUI2
switched all image outputs to jpeg format instead of png
This commit is contained in:
commit
a0de2e76db
@ -31,9 +31,10 @@
|
||||
#include "util/misc.h"
|
||||
#include "gui/notifyqt.h"
|
||||
|
||||
#include <retroshare/rsidentity.h>
|
||||
#include <retroshare/rspeers.h>
|
||||
#include "retroshare/rsidentity.h"
|
||||
#include "retroshare/rspeers.h"
|
||||
#include "gui/common/FilesDefs.h"
|
||||
#include "util/imageutil.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
@ -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);
|
||||
|
||||
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
|
||||
|
||||
mEditGroup.mImage.copy((uint8_t *) ba.data(), ba.size());
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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();
|
||||
|
@ -22,8 +22,9 @@
|
||||
#include "PostedGroupDialog.h"
|
||||
#include "gui/gxs/GxsIdDetails.h"
|
||||
#include "gui/common/FilesDefs.h"
|
||||
#include "util/imageutil.h"
|
||||
|
||||
#include <retroshare/rswiki.h>
|
||||
#include "retroshare/rswiki.h"
|
||||
#include <iostream>
|
||||
|
||||
const uint32_t PostedCreateEnabledFlags = (
|
||||
@ -104,8 +105,10 @@ void PostedGroupDialog::preparePostedGroup(RsPostedGroup &group, const RsGroupMe
|
||||
QByteArray ba;
|
||||
QBuffer buffer(&ba);
|
||||
|
||||
bool has_transparency = ImageUtil::hasAlphaContent(pixmap.toImage());
|
||||
|
||||
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
|
||||
|
||||
group.mGroupImage.copy((uint8_t *) ba.data(), ba.size());
|
||||
} else {
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
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()
|
||||
|
@ -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());
|
||||
}
|
||||
|
||||
|
@ -21,10 +21,11 @@
|
||||
#include <QBuffer>
|
||||
|
||||
#include "gui/gxs/GxsIdDetails.h"
|
||||
#include "util/imageutil.h"
|
||||
#include "gui/common/FilesDefs.h"
|
||||
#include "GxsChannelGroupDialog.h"
|
||||
|
||||
#include <retroshare/rsgxschannels.h>
|
||||
#include "retroshare/rsgxschannels.h"
|
||||
#include <iostream>
|
||||
|
||||
// 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);
|
||||
|
||||
bool has_transparency = ImageUtil::hasAlphaContent(pixmap.toImage());
|
||||
|
||||
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
|
||||
|
||||
group.mImage.copy((uint8_t *) ba.data(), ba.size());
|
||||
} else {
|
||||
|
@ -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));
|
||||
}
|
||||
|
@ -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();
|
||||
// }
|
||||
|
||||
|
@ -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;
|
||||
@ -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<image.width();++i)
|
||||
for(int j=0;j<image.height();++j)
|
||||
if(qAlpha(image.pixel(i,j)) < 255)
|
||||
{
|
||||
std::cerr << "Image of size " << image.width() << " x " << image.height() << ": Transparency content detected." << std::endl;
|
||||
return true;
|
||||
}
|
||||
|
||||
std::cerr << "Image of size " << image.width() << " x " << image.height() << ": No transparency content detected." << std::endl;
|
||||
return false;
|
||||
}
|
||||
bool ImageUtil::optimizeSizeHtml(QString &html, const QImage& original, QImage &optimized, int maxPixels, int maxBytes)
|
||||
{
|
||||
QByteArray bytearray;
|
||||
@ -145,7 +164,10 @@ bool ImageUtil::optimizeSizeHtml(QString &html, const QImage& original, QImage &
|
||||
if(maxBytes < 1) maxBytes = 1;
|
||||
}
|
||||
|
||||
if(optimizeSizeBytes(bytearray, original, optimized, maxPixels, maxBytes))
|
||||
// check for transparency
|
||||
bool has_transparency = hasAlphaContent(original);
|
||||
|
||||
if(optimizeSizeBytes(bytearray, original, optimized,has_transparency?"PNG":"JPG",maxPixels, maxBytes))
|
||||
{
|
||||
QByteArray encodedByteArray = bytearray.toBase64();
|
||||
html = "<img src=\"data:image/png;base64,";
|
||||
@ -156,7 +178,7 @@ bool ImageUtil::optimizeSizeHtml(QString &html, const QImage& original, QImage &
|
||||
return false;
|
||||
}
|
||||
|
||||
int ImageUtil::checkSize(QByteArray &bytearray, const QImage &img)
|
||||
int ImageUtil::checkSize(QByteArray &bytearray, const QImage &img,const char *format)
|
||||
{
|
||||
rstime::RsScopeTimer st("Check size");
|
||||
|
||||
@ -166,7 +188,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, format, 85)) {
|
||||
size = bytearray.length();
|
||||
} else {
|
||||
std::cerr << "ImageUtil: image can't be saved to buffer" << std::endl;
|
||||
|
@ -33,10 +33,11 @@ public:
|
||||
|
||||
static void extractImage(QWidget *window, QTextCursor cursor, QString file = "");
|
||||
static bool optimizeSizeHtml(QString &html, const QImage& original, QImage &optimized, int maxPixels = -1, int maxBytes = -1);
|
||||
static bool optimizeSizeBytes(QByteArray &bytearray, const QImage& original, QImage &optimized, int maxPixels = -1, int maxBytes = -1);
|
||||
static bool optimizeSizeBytes(QByteArray &bytearray, const QImage &original, QImage &optimized, const char *format, int maxPixels, int maxBytes);
|
||||
static bool hasAlphaContent(const QImage& image);
|
||||
|
||||
private:
|
||||
static int checkSize(QByteArray& embeddedImage, const QImage& img);
|
||||
static int checkSize(QByteArray& embeddedImage, const QImage& img, const char *format);
|
||||
static void quantization(const QImage& img, QVector<QRgb>& palette);
|
||||
static void quantization(QList<QRgb>::iterator begin, QList<QRgb>::iterator end, int depth, QVector<QRgb>& palette);
|
||||
static void avgbucket(QList<QRgb>::iterator begin, QList<QRgb>::iterator end, QVector<QRgb>& palette);
|
||||
|
Loading…
Reference in New Issue
Block a user