/* * Copyright (c) 2022, Gregory Bertilson * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once #include #include #include #include #include #include #include namespace Video { class VideoFrame { public: virtual ~VideoFrame() { } virtual DecoderErrorOr output_to_bitmap(Gfx::Bitmap& bitmap) = 0; virtual DecoderErrorOr> to_bitmap() { auto bitmap = DECODER_TRY_ALLOC(Gfx::Bitmap::try_create(Gfx::BitmapFormat::BGRx8888, m_size)); TRY(output_to_bitmap(bitmap)); return bitmap; } inline Gfx::IntSize size() { return m_size; } inline size_t width() { return size().width(); } inline size_t height() { return size().height(); } inline u8 bit_depth() { return m_bit_depth; } inline CodingIndependentCodePoints& cicp() { return m_cicp; } protected: VideoFrame(Gfx::IntSize size, u8 bit_depth, CodingIndependentCodePoints cicp) : m_size(size) , m_bit_depth(bit_depth) , m_cicp(cicp) { } Gfx::IntSize m_size; u8 m_bit_depth; CodingIndependentCodePoints m_cicp; }; class SubsampledYUVFrame : public VideoFrame { public: static ErrorOr> try_create( Gfx::IntSize size, u8 bit_depth, CodingIndependentCodePoints cicp, bool subsampling_horizontal, bool subsampling_vertical, Span plane_y, Span plane_u, Span plane_v); SubsampledYUVFrame( Gfx::IntSize size, u8 bit_depth, CodingIndependentCodePoints cicp, bool subsampling_horizontal, bool subsampling_vertical, FixedArray& plane_y, FixedArray& plane_u, FixedArray& plane_v) : VideoFrame(size, bit_depth, cicp) , m_subsampling_horizontal(subsampling_horizontal) , m_subsampling_vertical(subsampling_vertical) , m_plane_y(move(plane_y)) , m_plane_u(move(plane_u)) , m_plane_v(move(plane_v)) { } DecoderErrorOr output_to_bitmap(Gfx::Bitmap& bitmap) override; protected: bool m_subsampling_horizontal; bool m_subsampling_vertical; FixedArray m_plane_y; FixedArray m_plane_u; FixedArray m_plane_v; }; }