lottie_common.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  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 "base/basic_types.h"
  9. #include <QSize>
  10. #include <QColor>
  11. #include <QImage>
  12. #include <crl/crl_time.h>
  13. #include <vector>
  14. #include <optional>
  15. namespace Lottie {
  16. inline constexpr auto kTimeUnknown = std::numeric_limits<crl::time>::min();
  17. inline constexpr auto kMaxFileSize = 2 * 1024 * 1024;
  18. constexpr auto kImageFormat = QImage::Format_ARGB32_Premultiplied;
  19. class Animation;
  20. struct Information {
  21. QSize size;
  22. int frameRate = 0;
  23. int framesCount = 0;
  24. };
  25. enum class Error {
  26. ParseFailed,
  27. NotSupported,
  28. };
  29. struct FrameRequest {
  30. QSize box;
  31. QColor colored = QColor(0, 0, 0, 0);
  32. bool mirrorHorizontal = false;
  33. [[nodiscard]] bool empty() const {
  34. return box.isEmpty();
  35. }
  36. [[nodiscard]] QSize size(
  37. const QSize &original,
  38. int sizeRounding) const;
  39. [[nodiscard]] bool operator==(const FrameRequest &other) const {
  40. return (box == other.box)
  41. && (colored == other.colored)
  42. && (mirrorHorizontal == other.mirrorHorizontal);
  43. }
  44. [[nodiscard]] bool operator!=(const FrameRequest &other) const {
  45. return !(*this == other);
  46. }
  47. };
  48. enum class Quality : char {
  49. Default,
  50. High,
  51. Synchronous
  52. };
  53. enum class SkinModifier {
  54. None,
  55. Color1,
  56. Color2,
  57. Color3,
  58. Color4,
  59. Color5,
  60. };
  61. struct ColorReplacements {
  62. std::vector<std::pair<std::uint32_t, std::uint32_t>> replacements;
  63. SkinModifier modifier = SkinModifier::None;
  64. uint8 tag = 0;
  65. };
  66. [[nodiscard]] QByteArray ReadContent(
  67. const QByteArray &data,
  68. const QString &filepath);
  69. [[nodiscard]] std::string ReadUtf8(const QByteArray &data);
  70. [[nodiscard]] bool GoodStorageForFrame(const QImage &storage, QSize size);
  71. [[nodiscard]] QImage CreateFrameStorage(QSize size);
  72. enum class FrameRenderResult {
  73. Ok,
  74. NotReady,
  75. BadCacheSize,
  76. Failed,
  77. };
  78. } // namespace Lottie