AnimatedBitmapDecodedImageData.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /*
  2. * Copyright (c) 2023, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #include <LibGfx/Bitmap.h>
  7. #include <LibWeb/HTML/AnimatedBitmapDecodedImageData.h>
  8. namespace Web::HTML {
  9. ErrorOr<NonnullRefPtr<AnimatedBitmapDecodedImageData>> AnimatedBitmapDecodedImageData::create(Vector<Frame>&& frames, size_t loop_count, bool animated)
  10. {
  11. return adopt_nonnull_ref_or_enomem(new (nothrow) AnimatedBitmapDecodedImageData(move(frames), loop_count, animated));
  12. }
  13. AnimatedBitmapDecodedImageData::AnimatedBitmapDecodedImageData(Vector<Frame>&& frames, size_t loop_count, bool animated)
  14. : m_frames(move(frames))
  15. , m_loop_count(loop_count)
  16. , m_animated(animated)
  17. {
  18. }
  19. AnimatedBitmapDecodedImageData::~AnimatedBitmapDecodedImageData() = default;
  20. RefPtr<Gfx::Bitmap const> AnimatedBitmapDecodedImageData::bitmap(size_t frame_index, Gfx::IntSize) const
  21. {
  22. if (frame_index >= m_frames.size())
  23. return nullptr;
  24. return m_frames[frame_index].bitmap;
  25. }
  26. int AnimatedBitmapDecodedImageData::frame_duration(size_t frame_index) const
  27. {
  28. if (frame_index >= m_frames.size())
  29. return 0;
  30. return m_frames[frame_index].duration;
  31. }
  32. Optional<CSSPixels> AnimatedBitmapDecodedImageData::intrinsic_width() const
  33. {
  34. return m_frames.first().bitmap->width();
  35. }
  36. Optional<CSSPixels> AnimatedBitmapDecodedImageData::intrinsic_height() const
  37. {
  38. return m_frames.first().bitmap->height();
  39. }
  40. Optional<CSSPixelFraction> AnimatedBitmapDecodedImageData::intrinsic_aspect_ratio() const
  41. {
  42. return CSSPixels(m_frames.first().bitmap->width()) / CSSPixels(m_frames.first().bitmap->height());
  43. }
  44. }