2018-10-23 09:44:42 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ui/image/image_prepare.h"
|
|
|
|
|
|
|
|
namespace Images {
|
|
|
|
|
2020-04-16 12:37:26 +00:00
|
|
|
[[nodiscard]] QByteArray ExpandInlineBytes(const QByteArray &bytes);
|
2020-04-08 15:09:29 +00:00
|
|
|
[[nodiscard]] QImage FromInlineBytes(const QByteArray &bytes);
|
|
|
|
|
2020-04-16 12:37:26 +00:00
|
|
|
[[nodiscard]] QSize GetSizeForDocument(
|
|
|
|
const QVector<MTPDocumentAttribute> &attributes);
|
|
|
|
|
2018-10-23 09:44:42 +00:00
|
|
|
} // namespace Images
|
|
|
|
|
|
|
|
class Image final {
|
|
|
|
public:
|
2020-05-29 15:10:25 +00:00
|
|
|
explicit Image(const QString &path);
|
|
|
|
explicit Image(const QByteArray &content);
|
|
|
|
explicit Image(QImage &&data);
|
2018-10-23 09:44:42 +00:00
|
|
|
|
2020-05-29 15:10:25 +00:00
|
|
|
[[nodiscard]] static not_null<Image*> Empty(); // 1x1 transparent
|
|
|
|
[[nodiscard]] static not_null<Image*> BlankMedia(); // 1x1 black
|
|
|
|
|
|
|
|
[[nodiscard]] int width() const {
|
|
|
|
return _data.width();
|
|
|
|
}
|
|
|
|
[[nodiscard]] int height() const {
|
|
|
|
return _data.height();
|
|
|
|
}
|
|
|
|
[[nodiscard]] QSize size() const {
|
|
|
|
return { width(), height() };
|
|
|
|
}
|
|
|
|
|
|
|
|
[[nodiscard]] bool isNull() const {
|
|
|
|
return (this == Empty());
|
|
|
|
}
|
2018-10-23 09:44:42 +00:00
|
|
|
|
2020-05-29 15:10:25 +00:00
|
|
|
[[nodiscard]] QImage original() const;
|
2019-01-17 08:18:23 +00:00
|
|
|
|
2020-05-29 15:10:25 +00:00
|
|
|
[[nodiscard]] const QPixmap &pix(int w = 0, int h = 0) const;
|
|
|
|
[[nodiscard]] const QPixmap &pixRounded(
|
|
|
|
int w = 0,
|
|
|
|
int h = 0,
|
2018-10-23 09:44:42 +00:00
|
|
|
ImageRoundRadius radius = ImageRoundRadius::None,
|
|
|
|
RectParts corners = RectPart::AllCorners) const;
|
2020-05-29 15:10:25 +00:00
|
|
|
[[nodiscard]] const QPixmap &pixBlurred(int w = 0, int h = 0) const;
|
|
|
|
[[nodiscard]] const QPixmap &pixColored(style::color add, int w = 0, int h = 0) const;
|
|
|
|
[[nodiscard]] const QPixmap &pixBlurredColored(
|
2018-10-23 09:44:42 +00:00
|
|
|
style::color add,
|
2020-05-29 15:10:25 +00:00
|
|
|
int w = 0,
|
|
|
|
int h = 0) const;
|
|
|
|
[[nodiscard]] const QPixmap &pixSingle(
|
|
|
|
int w,
|
|
|
|
int h,
|
|
|
|
int outerw,
|
|
|
|
int outerh,
|
2018-10-23 09:44:42 +00:00
|
|
|
ImageRoundRadius radius,
|
|
|
|
RectParts corners = RectPart::AllCorners,
|
|
|
|
const style::color *colored = nullptr) const;
|
2020-05-29 15:10:25 +00:00
|
|
|
[[nodiscard]] const QPixmap &pixBlurredSingle(
|
|
|
|
int w,
|
|
|
|
int h,
|
|
|
|
int outerw,
|
|
|
|
int outerh,
|
2018-10-23 09:44:42 +00:00
|
|
|
ImageRoundRadius radius,
|
|
|
|
RectParts corners = RectPart::AllCorners) const;
|
2020-05-29 15:10:25 +00:00
|
|
|
[[nodiscard]] const QPixmap &pixCircled(int w = 0, int h = 0) const;
|
|
|
|
[[nodiscard]] const QPixmap &pixBlurredCircled(int w = 0, int h = 0) const;
|
|
|
|
[[nodiscard]] QPixmap pixNoCache(
|
2018-10-23 09:44:42 +00:00
|
|
|
int w = 0,
|
|
|
|
int h = 0,
|
|
|
|
Images::Options options = 0,
|
|
|
|
int outerw = -1,
|
|
|
|
int outerh = -1,
|
|
|
|
const style::color *colored = nullptr) const;
|
2020-05-29 15:10:25 +00:00
|
|
|
[[nodiscard]] QPixmap pixColoredNoCache(
|
2018-10-23 09:44:42 +00:00
|
|
|
style::color add,
|
2020-05-29 15:10:25 +00:00
|
|
|
int w = 0,
|
|
|
|
int h = 0,
|
2018-10-23 09:44:42 +00:00
|
|
|
bool smooth = false) const;
|
2020-05-29 15:10:25 +00:00
|
|
|
[[nodiscard]] QPixmap pixBlurredColoredNoCache(
|
2018-10-23 09:44:42 +00:00
|
|
|
style::color add,
|
2020-05-29 15:10:25 +00:00
|
|
|
int w,
|
|
|
|
int h = 0) const;
|
2018-10-23 09:44:42 +00:00
|
|
|
|
|
|
|
private:
|
2020-05-29 15:10:25 +00:00
|
|
|
const QImage _data;
|
|
|
|
mutable base::flat_map<uint64, QPixmap> _cache;
|
2018-10-23 09:44:42 +00:00
|
|
|
|
|
|
|
};
|