mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 17:27:35 +00:00
LibGfx: Add initial ISO BMFF parsing and a utility to print file info
Currently, the `isobmff` utility will only print the media file type info from the FileTypeBox (major brand and compatible brands), as well as the names and sizes of top-level boxes.
This commit is contained in:
parent
9caa0bda7d
commit
66c9696687
13 changed files with 510 additions and 0 deletions
48
Userland/Libraries/LibGfx/ImageFormats/ISOBMFF/BoxStream.h
Normal file
48
Userland/Libraries/LibGfx/ImageFormats/ISOBMFF/BoxStream.h
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Gregory Bertilson <Zaggy1024@gmail.com>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Stream.h>
|
||||
|
||||
namespace Gfx::ISOBMFF {
|
||||
|
||||
class BoxStream final : public Stream {
|
||||
public:
|
||||
explicit BoxStream(Stream& stream, size_t size)
|
||||
: m_stream(stream)
|
||||
, m_data_left(size)
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool is_eof() const override { return m_stream.is_eof() || remaining() == 0; }
|
||||
virtual bool is_open() const override { return m_stream.is_open(); }
|
||||
virtual void close() override { m_stream.close(); }
|
||||
virtual ErrorOr<Bytes> read_some(Bytes bytes) override
|
||||
{
|
||||
auto read_bytes = TRY(m_stream.read_some(bytes));
|
||||
m_data_left -= min(read_bytes.size(), m_data_left);
|
||||
return read_bytes;
|
||||
}
|
||||
|
||||
virtual ErrorOr<size_t> write_some(ReadonlyBytes) override { VERIFY_NOT_REACHED(); }
|
||||
virtual ErrorOr<void> write_until_depleted(ReadonlyBytes) override { VERIFY_NOT_REACHED(); }
|
||||
|
||||
size_t remaining() const
|
||||
{
|
||||
return m_data_left;
|
||||
}
|
||||
ErrorOr<void> discard_remaining()
|
||||
{
|
||||
return discard(remaining());
|
||||
}
|
||||
|
||||
private:
|
||||
Stream& m_stream;
|
||||
size_t m_data_left;
|
||||
};
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue