DecodedImageData.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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/DecodedImageData.h>
  8. namespace Web::HTML {
  9. ErrorOr<NonnullRefPtr<DecodedImageData>> DecodedImageData::create(Vector<Frame>&& frames, size_t loop_count, bool animated)
  10. {
  11. return adopt_nonnull_ref_or_enomem(new (nothrow) DecodedImageData(move(frames), loop_count, animated));
  12. }
  13. DecodedImageData::DecodedImageData(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. DecodedImageData::~DecodedImageData() = default;
  20. RefPtr<Gfx::Bitmap const> DecodedImageData::bitmap(size_t frame_index) const
  21. {
  22. if (frame_index >= m_frames.size())
  23. return nullptr;
  24. return m_frames[frame_index].bitmap;
  25. }
  26. int DecodedImageData::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<int> DecodedImageData::natural_width() const
  33. {
  34. return m_frames.first().bitmap->width();
  35. }
  36. Optional<int> DecodedImageData::natural_height() const
  37. {
  38. return m_frames.first().bitmap->height();
  39. }
  40. }