From da0df57563e44e19045b5fe8f1593bf8cab48bd3 Mon Sep 17 00:00:00 2001 From: John Preston Date: Sat, 20 Sep 2014 14:35:46 -0700 Subject: [PATCH] prepared win version sign, saving compress image checkbox state, not loaded images blur added --- Telegram/SourceFiles/app.cpp | 7 ++ Telegram/SourceFiles/boxes/contactsbox.cpp | 3 - Telegram/SourceFiles/boxes/photosendbox.cpp | 14 ++- Telegram/SourceFiles/config.h | 2 +- Telegram/SourceFiles/gui/images.cpp | 133 ++++++++++++++------ Telegram/SourceFiles/settings.cpp | 1 + Telegram/SourceFiles/settings.h | 1 + Telegram/SourceFiles/types.h | 1 + 8 files changed, 116 insertions(+), 46 deletions(-) diff --git a/Telegram/SourceFiles/app.cpp b/Telegram/SourceFiles/app.cpp index ddf2545b4..92fffe790 100644 --- a/Telegram/SourceFiles/app.cpp +++ b/Telegram/SourceFiles/app.cpp @@ -1565,6 +1565,7 @@ namespace App { stream << quint32(dbiNotifyView) << qint32(cNotifyView()); stream << quint32(dbiAskDownloadPath) << qint32(cAskDownloadPath()); stream << quint32(dbiDownloadPath) << (cAskDownloadPath() ? QString() : cDownloadPath()); + stream << quint32(dbiCompressPastedImage) << qint32(cCompressPastedImage()); stream << quint32(dbiEmojiTab) << qint32(cEmojiTab()); RecentEmojiPreload v; @@ -1747,6 +1748,12 @@ namespace App { cSetDownloadPath(v); } break; + case dbiCompressPastedImage: { + qint32 v; + stream >> v; + cSetCompressPastedImage(v == 1); + } break; + case dbiEmojiTab: { qint32 v; stream >> v; diff --git a/Telegram/SourceFiles/boxes/contactsbox.cpp b/Telegram/SourceFiles/boxes/contactsbox.cpp index a6ded1e79..f7a31bfce 100644 --- a/Telegram/SourceFiles/boxes/contactsbox.cpp +++ b/Telegram/SourceFiles/boxes/contactsbox.cpp @@ -478,9 +478,6 @@ void ContactsBox::paintEvent(QPaintEvent *e) { // paint shadows p.fillRect(0, _addContact.height(), _width, st::scrollDef.topsh, st::scrollDef.shColor->b); - // paint button sep - p.fillRect(st::btnSelectCancel.width, size().height() - st::btnSelectCancel.height, st::lineWidth, st::btnSelectCancel.height, st::btnSelectSep->b); - // draw box title / text p.setPen(st::black->p); p.setFont(st::addContactTitleFont->f); diff --git a/Telegram/SourceFiles/boxes/photosendbox.cpp b/Telegram/SourceFiles/boxes/photosendbox.cpp index cdf22a1c1..ad45e6584 100644 --- a/Telegram/SourceFiles/boxes/photosendbox.cpp +++ b/Telegram/SourceFiles/boxes/photosendbox.cpp @@ -25,7 +25,7 @@ Copyright (c) 2014 John Preston, https://tdesktop.com PhotoSendBox::PhotoSendBox(const ReadyLocalMedia &img) : _img(new ReadyLocalMedia(img)), _thumbx(0), _thumby(0), _thumbw(0), _thumbh(0), _namew(0), _textw(0), - _compressed(this, lang(lng_send_image_compressed), true), + _compressed(this, lang(lng_send_image_compressed), cCompressPastedImage()), _sendButton(this, lang(lng_send_button), st::btnSelectDone), _cancelButton(this, lang(lng_cancel), st::btnSelectCancel), a_opacity(0, 1) { @@ -203,10 +203,16 @@ void PhotoSendBox::animStep(float64 ms) { void PhotoSendBox::onSend() { if (!_img) { if (App::main()) App::main()->confirmShareContact(_phone, _fname, _lname); - } else if (_compressed.isHidden() || _compressed.checked()) { - if (App::main()) App::main()->confirmSendImage(*_img); } else { - if (App::main()) App::main()->confirmSendImageUncompressed(); + if (!_compressed.isHidden()) { + cSetCompressPastedImage(_compressed.checked()); + App::writeUserConfig(); + } + if (_compressed.isHidden() || _compressed.checked()) { + if (App::main()) App::main()->confirmSendImage(*_img); + } else { + if (App::main()) App::main()->confirmSendImageUncompressed(); + } } emit closed(); } diff --git a/Telegram/SourceFiles/config.h b/Telegram/SourceFiles/config.h index fd8a7782a..10a582bd3 100644 --- a/Telegram/SourceFiles/config.h +++ b/Telegram/SourceFiles/config.h @@ -121,7 +121,7 @@ static const BuiltInDc _builtInDcs[] = { { 2, "149.154.167.50", 443 }, { 3, "174.140.142.6", 443 }, { 4, "149.154.167.90", 443 }, - { 5, "116.51.22.2", 443 } + { 5, "149.154.171.5", 443 } }; static const BuiltInDc _builtInTestDcs[] = { diff --git a/Telegram/SourceFiles/gui/images.cpp b/Telegram/SourceFiles/gui/images.cpp index 02319baea..e6cda4ecd 100644 --- a/Telegram/SourceFiles/gui/images.cpp +++ b/Telegram/SourceFiles/gui/images.cpp @@ -101,20 +101,20 @@ const QPixmap &Image::pixBlurred(int32 w, int32 h) const { return i.value(); } +namespace { + static inline uint64 _blurGetColors(const uchar *p) { + return p[0] + (p[1] << 16) + ((uint64)p[2] << 32); + } +} + QPixmap Image::pixBlurredNoCache(int32 w, int32 h) const { - return pixNoCache(w, h); restore(); loaded(); const QPixmap &p(pixData()); if (p.isNull()) return blank()->pix(); - QImage img; - if (h <= 0) { - img = p.toImage().scaledToWidth(w, Qt::SmoothTransformation); - } else { - img = p.toImage().scaled(w, h, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); - } + QImage img = p.toImage(); QImage::Format fmt = img.format(); if (fmt != QImage::Format_RGB32 && fmt != QImage::Format_ARGB32 && fmt != QImage::Format_ARGB32_Premultiplied) { QImage tmp(img.width(), img.height(), QImage::Format_ARGB32); @@ -124,43 +124,100 @@ QPixmap Image::pixBlurredNoCache(int32 w, int32 h) const { } img = tmp; } - QImage fromimg = img; - uchar *bits = img.bits(); - const uchar *from = fromimg.bits(); - if (bits && from) { - int width = img.width(), height = img.height(); - for (int i = 0; i < width; ++i) { - for (int j = 0; j < height; ++j) { - uint32 a = 0, b = 0, c = 0; - for (int index = i - 32; index < i + 32; ++index) { - int fullindex = 4 * (j * width + ((index < 0) ? 0 : (index >= width ? (width - 1) : index))), coef = 4; - a += from[fullindex + 1] * coef; - b += from[fullindex + 2] * coef; - c += from[fullindex + 3] * coef; + uchar *pix = img.bits(); + if (pix) { + const int w = img.width(), h = img.height(), stride = w * 4; + const int radius = 7; + const int r1 = radius + 1; + const int div = radius * 2 + 1; + + if (radius < 16 && div < w && div < h && stride <= w * 4) { + uint64 *rgb = new uint64[w * h]; + + int x, y, i; + + int yw = 0; + const int we = w - r1; + for (y = 0; y < h; y++) { + uint64 cur = _blurGetColors(&pix[yw]); + uint64 rgballsum = -radius * cur; + uint64 rgbsum = cur * ((r1 * (r1 + 1)) >> 1); + + for (i = 1; i <= radius; i++) { + uint64 cur = _blurGetColors(&pix[yw + i * 4]); + rgbsum += cur * (r1 - i); + rgballsum += cur; } - int fullindex = 4 * (j * width + i); - bits[fullindex + 1] = uchar(a >> 8); - bits[fullindex + 2] = uchar(b >> 8); - bits[fullindex + 3] = uchar(c >> 8); - } - } - for (int i = 0; i < width; ++i) { - for (int j = 0; j < height; ++j) { - uint32 a = 0, b = 0, c = 0; - for (int index = j - 32; index < j + 32; ++index) { - int fullindex = 4 * (((index < 0) ? 0 : (index >= height ? (height - 1) : index)) * width + i), coef = 4; - a += from[fullindex + 1] * coef; - b += from[fullindex + 2] * coef; - c += from[fullindex + 3] * coef; + + x = 0; + +#define update(start, middle, end) \ + rgb[y * w + x] = (rgbsum >> 6) & 0x00FF00FF00FF00FFLL; \ + rgballsum += _blurGetColors(&pix[yw + (start) * 4]) - 2 * _blurGetColors(&pix[yw + (middle) * 4]) + _blurGetColors(&pix[yw + (end) * 4]); \ + rgbsum += rgballsum; \ + x++; + + while (x < r1) { + update(0, x, x + r1); } - int fullindex = 4 * (j * width + i); - bits[fullindex + 1] = uchar(a >> 8); - bits[fullindex + 2] = uchar(b >> 8); - bits[fullindex + 3] = uchar(c >> 8); + while (x < we) { + update(x - r1, x, x + r1); + } + while (x < w) { + update(x - r1, x, w - 1); + } + +#undef update + + yw += stride; } + + const int he = h - r1; + for (x = 0; x < w; x++) { + uint64 rgballsum = -radius * rgb[x]; + uint64 rgbsum = rgb[x] * ((r1 * (r1 + 1)) >> 1); + for (i = 1; i <= radius; i++) { + rgbsum += rgb[i * w + x] * (r1 - i); + rgballsum += rgb[i * w + x]; + } + + y = 0; + int yi = x * 4; + +#define update(start, middle, end) \ + uint64 res = rgbsum >> 6; \ + pix[yi] = res & 0xFF; \ + pix[yi + 1] = (res >> 16) & 0xFF; \ + pix[yi + 2] = (res >> 32) & 0xFF; \ + rgballsum += rgb[x + (start) * w] - 2 * rgb[x + (middle) * w] + rgb[x + (end) * w]; \ + rgbsum += rgballsum; \ + y++; \ + yi += stride; + + while (y < r1) { + update(0, y, y + r1); + } + while (y < he) { + update(y - r1, y, y + r1); + } + while (y < h) { + update(y - r1, y, h - 1); + } + +#undef update + } + + delete[] rgb; } } + + if (h <= 0) { + img = img.scaledToWidth(w, Qt::SmoothTransformation); + } else { + img = img.scaled(w, h, Qt::IgnoreAspectRatio, Qt::SmoothTransformation); + } + return QPixmap::fromImage(img); } diff --git a/Telegram/SourceFiles/settings.cpp b/Telegram/SourceFiles/settings.cpp index e70a3c25f..ae6144e0a 100644 --- a/Telegram/SourceFiles/settings.cpp +++ b/Telegram/SourceFiles/settings.cpp @@ -62,6 +62,7 @@ QString gLoggedPhoneNumber; QByteArray gLocalSalt; DBIScale gRealScale = dbisAuto, gScreenScale = dbisOne, gConfigScale = dbisAuto; +bool gCompressPastedImage = true; DBIEmojiTab gEmojiTab = dbietPeople; RecentEmojiPack gRecentEmojis; diff --git a/Telegram/SourceFiles/settings.h b/Telegram/SourceFiles/settings.h index ca1ffd73d..02ca13fb4 100644 --- a/Telegram/SourceFiles/settings.h +++ b/Telegram/SourceFiles/settings.h @@ -102,6 +102,7 @@ DeclareSetting(QByteArray, LocalSalt); DeclareSetting(DBIScale, RealScale); DeclareSetting(DBIScale, ScreenScale); DeclareSetting(DBIScale, ConfigScale); +DeclareSetting(bool, CompressPastedImage); inline DBIScale cEvalScale(DBIScale scale) { return (scale == dbisAuto) ? cScreenScale() : scale; diff --git a/Telegram/SourceFiles/types.h b/Telegram/SourceFiles/types.h index 460eb034f..cc0741f7a 100644 --- a/Telegram/SourceFiles/types.h +++ b/Telegram/SourceFiles/types.h @@ -222,6 +222,7 @@ enum DataBlockId { // 27 reserved dbiNotifyView = 28, dbiSendToMenu = 29, + dbiCompressPastedImage = 30, dbiEncryptedWithSalt = 333, dbiEncrypted = 444,