2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-09-05 17:15:16 +00:00

beautiful sticker blur and selection, document and sticker thumbs fixed, sticker emojis in dialog list display done, send image as doc for bad image size done

This commit is contained in:
John Preston
2015-01-05 23:17:33 +03:00
parent 5d54d48f70
commit 476ffca228
27 changed files with 442 additions and 146 deletions

View File

@@ -31,12 +31,13 @@ LocalImageLoaderPrivate::LocalImageLoaderPrivate(int32 currentUser, LocalImageLo
};
void LocalImageLoaderPrivate::prepareImages() {
QString file, filename, mime;
QString file, filename, mime, stickerMime = qsl("image/webp");
int32 filesize = 0;
QImage img;
QByteArray data;
PeerId peer;
uint64 id, jpeg_id = 0;
uint64 id, thumbId = 0;
QString thumbExt = "jpg";
ToPrepareMediaType type;
bool animated = false;
bool ctrlShiftEnter = false;
@@ -72,12 +73,13 @@ void LocalImageLoaderPrivate::prepareImages() {
type = ToPrepareDocument;
}
}
if (type != ToPrepareAuto && info.size() < MaxUploadPhotoSize) {
img = App::readImage(file, 0, true, &animated);
}
if (type == ToPrepareDocument) {
mime = mimeTypeForFile(info).name();
}
if (type != ToPrepareAuto && info.size() < MaxUploadPhotoSize) {
bool opaque = (mime != stickerMime);
img = App::readImage(file, 0, opaque, &animated);
}
filename = info.fileName();
filesize = info.size();
} else if (!data.isEmpty()) {
@@ -95,10 +97,15 @@ void LocalImageLoaderPrivate::prepareImages() {
if (type == ToPrepareDocument) {
mime = mimeType.name();
}
filename = qsl("Document");
QStringList patterns = mimeType.globPatterns();
if (!patterns.isEmpty()) {
filename = patterns.front().replace('*', filename);
if (mime == "image/jpeg") {
filename = filedialogDefaultName(qsl("image"), qsl(".jpg"), QString(), true);
} else {
QString ext;
QStringList patterns = mimeType.globPatterns();
if (!patterns.isEmpty()) {
ext = patterns.front().replace('*', QString());
}
filename = filedialogDefaultName(qsl("doc"), ext, QString(), true);
}
filesize = data.size();
}
@@ -113,7 +120,15 @@ void LocalImageLoaderPrivate::prepareImages() {
}
filesize = data.size();
} else {
type = ToPreparePhoto; // only photo from QImage
if (img.hasAlphaChannel()) {
QImage solid(img.width(), img.height(), QImage::Format_ARGB32_Premultiplied);
solid.fill(st::white->c);
{
QPainter(&solid).drawImage(0, 0, img);
}
img = solid;
}
type = ToPreparePhoto;
filename = qsl("Untitled.jpg");
filesize = 0;
}
@@ -163,29 +178,32 @@ void LocalImageLoaderPrivate::prepareImages() {
photo = MTP_photo(MTP_long(id), MTP_long(0), MTP_int(user), MTP_int(unixtime()), MTP_string(""), MTP_geoPointEmpty(), MTP_vector<MTPPhotoSize>(photoSizes));
jpeg_id = id;
thumbId = id;
} else if ((type == ToPrepareVideo || type == ToPrepareDocument) && !img.isNull()) {
int32 w = img.width(), h = img.height();
QByteArray thumbFormat = "JPG";
int32 thumbQuality = 87;
if (animated) {
attributes.push_back(MTP_documentAttributeAnimated());
} else if (mime == qsl("image/webp") && w > 0 && h > 0 && filesize < StickerInMemory) {
} else if (mime == stickerMime && w > 0 && h > 0 && w <= StickerMaxSize && h <= StickerMaxSize && filesize < StickerInMemory) {
attributes.push_back(MTP_documentAttributeSticker());
thumbFormat = "webp";
thumbExt = qsl("webp");
}
attributes.push_back(MTP_documentAttributeImageSize(MTP_int(w), MTP_int(h)));
if (w < 20 * h && h < 20 * w) {
QPixmap full = (w > 90 || h > 90) ? QPixmap::fromImage(img.scaled(90, 90, Qt::KeepAspectRatio, Qt::SmoothTransformation), Qt::ColorOnly) : QPixmap::fromImage(img, Qt::ColorOnly);
QPixmap full = (w > 90 || h > 90) ? QPixmap::fromImage(img.scaled(90, 90, Qt::KeepAspectRatio, Qt::SmoothTransformation), Qt::ColorOnly) : QPixmap::fromImage(img, Qt::ColorOnly);
{
QBuffer jpegBuffer(&jpeg);
full.save(&jpegBuffer, thumbFormat, thumbQuality);
}
{
QBuffer jpegBuffer(&jpeg);
full.save(&jpegBuffer, thumbFormat, 87);
photoThumbs.insert('0', full);
thumb = MTP_photoSize(MTP_string(""), MTP_fileLocationUnavailable(MTP_long(0), MTP_int(0), MTP_long(0)), MTP_int(full.width()), MTP_int(full.height()), MTP_int(0));
thumbId = MTP::nonce<uint64>();
}
photoThumbs.insert('0', full);
thumb = MTP_photoSize(MTP_string(""), MTP_fileLocationUnavailable(MTP_long(0), MTP_int(0), MTP_long(0)), MTP_int(full.width()), MTP_int(full.height()), MTP_int(0));
jpeg_id = MTP::nonce<uint64>();
}
if (type == ToPrepareDocument) {
@@ -194,7 +212,7 @@ void LocalImageLoaderPrivate::prepareImages() {
{
QMutexLocker lock(loader->readyMutex());
loader->readyList().push_back(ReadyLocalMedia(type, file, filename, filesize, data, id, jpeg_id, peer, photo, photoThumbs, document, jpeg, ctrlShiftEnter));
loader->readyList().push_back(ReadyLocalMedia(type, file, filename, filesize, data, id, thumbId, thumbExt, peer, photo, photoThumbs, document, jpeg, ctrlShiftEnter));
}
{