frame_generator.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // This file is part of Desktop App Toolkit,
  2. // a set of libraries for developing nice desktop applications.
  3. //
  4. // For license and copyright information please follow this link:
  5. // https://github.com/desktop-app/legal/blob/master/LEGAL
  6. //
  7. #pragma once
  8. #include <QtGui/QImage>
  9. #include <crl/crl_time.h>
  10. namespace Ui {
  11. class FrameGenerator {
  12. public:
  13. virtual ~FrameGenerator() = default;
  14. // 0 means unknown.
  15. [[nodiscard]] virtual int count() = 0;
  16. // 0. means unknown.
  17. [[nodiscard]] virtual double rate() = 0;
  18. struct Frame {
  19. crl::time duration = 0;
  20. QImage image;
  21. bool last = false;
  22. };
  23. [[nodiscard]] virtual Frame renderNext(
  24. QImage storage,
  25. QSize size,
  26. Qt::AspectRatioMode mode = Qt::IgnoreAspectRatio) = 0;
  27. [[nodiscard]] virtual Frame renderCurrent(
  28. QImage storage,
  29. QSize size,
  30. Qt::AspectRatioMode mode = Qt::IgnoreAspectRatio) = 0;
  31. virtual void jumpToStart() = 0;
  32. };
  33. class ImageFrameGenerator final : public Ui::FrameGenerator {
  34. public:
  35. explicit ImageFrameGenerator(const QByteArray &bytes);
  36. explicit ImageFrameGenerator(const QImage &image);
  37. int count() override;
  38. double rate() override;
  39. Frame renderNext(
  40. QImage storage,
  41. QSize size,
  42. Qt::AspectRatioMode mode = Qt::IgnoreAspectRatio) override;
  43. Frame renderCurrent(
  44. QImage storage,
  45. QSize size,
  46. Qt::AspectRatioMode mode = Qt::IgnoreAspectRatio) override;
  47. void jumpToStart() override;
  48. private:
  49. QByteArray _bytes;
  50. QImage _image;
  51. };
  52. [[nodiscard]] bool GoodStorageForFrame(const QImage &storage, QSize size);
  53. [[nodiscard]] QImage CreateFrameStorage(QSize size);
  54. } // namespace Ui