DecodedImageData.h 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*
  2. * Copyright (c) 2023, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/RefCounted.h>
  8. #include <LibGfx/Forward.h>
  9. #include <LibJS/Heap/Cell.h>
  10. namespace Web::HTML {
  11. // https://html.spec.whatwg.org/multipage/images.html#img-req-data
  12. class DecodedImageData final : public RefCounted<DecodedImageData> {
  13. public:
  14. struct Frame {
  15. RefPtr<Gfx::Bitmap const> bitmap;
  16. int duration { 0 };
  17. };
  18. static ErrorOr<NonnullRefPtr<DecodedImageData>> create(Vector<Frame>&&, size_t loop_count, bool animated);
  19. ~DecodedImageData();
  20. RefPtr<Gfx::Bitmap const> bitmap(size_t frame_index) const;
  21. int frame_duration(size_t frame_index) const;
  22. size_t frame_count() const { return m_frames.size(); }
  23. size_t loop_count() const { return m_loop_count; }
  24. bool is_animated() const { return m_animated; }
  25. Optional<int> natural_width() const;
  26. Optional<int> natural_height() const;
  27. private:
  28. DecodedImageData(Vector<Frame>&&, size_t loop_count, bool animated);
  29. Vector<Frame> m_frames;
  30. size_t m_loop_count { 0 };
  31. bool m_animated { false };
  32. };
  33. }