1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 03:47:34 +00:00

LibRIFF: Rework to match LibGfx needs

There's now two namespaces, RIFF (little-endian) and IFF (big-endian)
which (for the most part) contain the same kinds of structures for
handling similar data in both formats. (They also share almost all of
their implementation) The main types are ChunkHeader and (Owned)Chunk.
While Chunk has no ownership over the data it accesses (and can only be
constructed from a byte view), OwnedChunk has ownership over this data
and is aimed at reading from streams.

OwnedList, implementing the standard RIFF LIST type, is currently only
implemented for RIFF due to its only user being WAV, but it may be
generalized in the future for use by IFF.

Co-authored-by: Timothy Flynn <trflynn89@pm.me>
This commit is contained in:
kleines Filmröllchen 2023-10-12 22:36:23 +02:00 committed by Andrew Kaster
parent d125d16287
commit 64598473cc
11 changed files with 366 additions and 145 deletions

View file

@ -0,0 +1,28 @@
/*
* Copyright (c) 2023, kleines Filmröllchen <filmroellchen@serenityos.org>
* Copyright (c) 2023, Nicolas Ramz <nicolas.ramz@gmail.com>
* Copyright (c) 2023, Nico Weber <thakis@chromium.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Stream.h>
#include <LibRIFF/ChunkID.h>
#include <LibRIFF/RIFF.h>
ErrorOr<RIFF::ChunkID> RIFF::ChunkID::read_from_stream(Stream& stream)
{
Array<u8, chunk_id_size> id;
TRY(stream.read_until_filled(id.span()));
return ChunkID { id };
}
ErrorOr<RIFF::OwnedList> RIFF::OwnedList::read_from_stream(Stream& stream)
{
auto type = TRY(stream.read_value<ChunkID>());
Vector<RIFF::OwnedChunk> chunks;
while (!stream.is_eof())
TRY(chunks.try_append(TRY(stream.read_value<RIFF::OwnedChunk>())));
return RIFF::OwnedList { .type = type, .chunks = move(chunks) };
}