/* This file is part of Telegram Desktop, the official desktop version of Telegram messaging app, see https://telegram.org Telegram Desktop is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. It is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. In addition, as a special exception, the copyright holders give permission to link the code of portions of this program with the OpenSSL library. Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org */ #pragma once class FileLoader; class mtpFileLoader; enum LoadFromCloudSetting { LoadFromCloudOrLocal, LoadFromLocalOnly, }; enum LoadToCacheSetting { LoadToFileOnly, LoadToCacheAsWell, }; enum class ImageRoundRadius { None, Large, Small, Ellipse, }; enum class ImageRoundCorner { None = 0x00, TopLeft = 0x01, TopRight = 0x02, BottomLeft = 0x04, BottomRight = 0x08, All = 0x0f, }; using ImageRoundCorners = QFlags; Q_DECLARE_OPERATORS_FOR_FLAGS(ImageRoundCorners); inline uint32 packInt(int32 a) { return (a < 0) ? uint32(int64(a) + 0x100000000LL) : uint32(a); } inline int32 unpackInt(uint32 a) { return (a > 0x7FFFFFFFU) ? int32(int64(a) - 0x100000000LL) : int32(a); } inline uint64 packUIntUInt(uint32 a, uint32 b) { return (uint64(a) << 32) | uint64(b); } inline uint64 packUIntInt(uint32 a, int32 b) { return packUIntUInt(a, packInt(b)); } inline uint64 packIntUInt(int32 a, uint32 b) { return packUIntUInt(packInt(a), b); } inline uint64 packIntInt(int32 a, int32 b) { return packUIntUInt(packInt(a), packInt(b)); } inline uint32 unpackUIntFirst(uint64 v) { return uint32(v >> 32); } inline int32 unpackIntFirst(uint64 v) { return unpackInt(unpackUIntFirst(v)); } inline uint32 unpackUIntSecond(uint64 v) { return uint32(v & 0xFFFFFFFFULL); } inline int32 unpackIntSecond(uint64 v) { return unpackInt(unpackUIntSecond(v)); } class StorageImageLocation { public: StorageImageLocation() = default; StorageImageLocation(int32 width, int32 height, int32 dc, const uint64 &volume, int32 local, const uint64 &secret) : _widthheight(packIntInt(width, height)), _dclocal(packIntInt(dc, local)), _volume(volume), _secret(secret) { } StorageImageLocation(int32 width, int32 height, const MTPDfileLocation &location) : _widthheight(packIntInt(width, height)), _dclocal(packIntInt(location.vdc_id.v, location.vlocal_id.v)), _volume(location.vvolume_id.v), _secret(location.vsecret.v) { } bool isNull() const { return !_dclocal; } int32 width() const { return unpackIntFirst(_widthheight); } int32 height() const { return unpackIntSecond(_widthheight); } void setSize(int32 width, int32 height) { _widthheight = packIntInt(width, height); } int32 dc() const { return unpackIntFirst(_dclocal); } uint64 volume() const { return _volume; } int32 local() const { return unpackIntSecond(_dclocal); } uint64 secret() const { return _secret; } static StorageImageLocation Null; private: uint64 _widthheight = 0; uint64 _dclocal = 0; uint64 _volume = 0; uint64 _secret = 0; friend inline bool operator==(const StorageImageLocation &a, const StorageImageLocation &b) { return (a._dclocal == b._dclocal) && (a._volume == b._volume) && (a._secret == b._secret); } }; inline bool operator!=(const StorageImageLocation &a, const StorageImageLocation &b) { return !(a == b); } class WebFileImageLocation { public: WebFileImageLocation() = default; WebFileImageLocation(int32 width, int32 height, int32 dc, const QByteArray &url, uint64 accessHash) : _widthheight(packIntInt(width, height)), _accessHash(accessHash), _url(url), _dc(dc) { } bool isNull() const { return !_dc; } int32 width() const { return unpackIntFirst(_widthheight); } int32 height() const { return unpackIntSecond(_widthheight); } void setSize(int32 width, int32 height) { _widthheight = packIntInt(width, height); } int32 dc() const { return _dc; } uint64 accessHash() const { return _accessHash; } const QByteArray &url() const { return _url; } static WebFileImageLocation Null; private: uint64 _widthheight = 0; uint64 _accessHash = 0; QByteArray _url; int32 _dc = 0; friend inline bool operator==(const WebFileImageLocation &a, const WebFileImageLocation &b) { return (a._dc == b._dc) && (a._accessHash == b._accessHash) && (a._url == b._url); } }; inline bool operator!=(const WebFileImageLocation &a, const WebFileImageLocation &b) { return !(a == b); } namespace Images { QImage prepareBlur(QImage image); void prepareRound(QImage &image, ImageRoundRadius radius, ImageRoundCorners corners = ImageRoundCorner::All); void prepareRound(QImage &image, QImage *cornerMasks, ImageRoundCorners corners = ImageRoundCorner::All); void prepareCircle(QImage &image); QImage prepareColored(style::color add, QImage image); QImage prepareOpaque(QImage image); enum class Option { None = 0x000, Smooth = 0x001, Blurred = 0x002, Circled = 0x004, RoundedLarge = 0x008, RoundedSmall = 0x010, RoundedTopLeft = 0x020, RoundedTopRight = 0x040, RoundedBottomLeft = 0x080, RoundedBottomRight = 0x100, Colored = 0x200, TransparentBackground = 0x400, }; using Options = QFlags