image_source.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #include "ui/image/image_source.h"
  8. #include "storage/cache/storage_cache_database.h"
  9. #include "storage/file_download_mtproto.h"
  10. #include "storage/file_download_web.h"
  11. #include "data/data_session.h"
  12. #include "data/data_file_origin.h"
  13. #include "history/history_item.h"
  14. #include "history/history.h"
  15. #include "main/main_session.h"
  16. #include "app.h"
  17. #include <QtCore/QBuffer>
  18. namespace Images {
  19. namespace {
  20. [[nodiscard]] QByteArray ReadContent(const QString &path) {
  21. auto file = QFile(path);
  22. const auto good = (file.size() <= App::kImageSizeLimit)
  23. && file.open(QIODevice::ReadOnly);
  24. return good ? file.readAll() : QByteArray();
  25. }
  26. [[nodiscard]] QImage ReadImage(const QByteArray &content) {
  27. return App::readImage(content, nullptr, false, nullptr);
  28. }
  29. } // namespace
  30. ImageSource::ImageSource(const QString &path)
  31. : ImageSource(ReadContent(path)) {
  32. }
  33. ImageSource::ImageSource(const QByteArray &content)
  34. : ImageSource(ReadImage(content)) {
  35. }
  36. ImageSource::ImageSource(QImage &&data) : _data(std::move(data)) {
  37. }
  38. void ImageSource::load() {
  39. }
  40. QImage ImageSource::takeLoaded() {
  41. return _data;
  42. }
  43. int ImageSource::width() {
  44. return _data.width();
  45. }
  46. int ImageSource::height() {
  47. return _data.height();
  48. }
  49. } // namespace Images