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

AK: Move Stream and SeekableStream from LibCore

`Stream` will be qualified as `AK::Stream` until we remove the
`Core::Stream` namespace. `IODevice` now reuses the `SeekMode` that is
defined by `SeekableStream`, since defining its own would require us to
qualify it with `AK::SeekMode` everywhere.
This commit is contained in:
Tim Schumacher 2023-01-22 05:09:11 +01:00 committed by Andrew Kaster
parent 5f2ea31816
commit 8464da1439
96 changed files with 620 additions and 586 deletions

View file

@ -89,7 +89,7 @@ enum class GIFFormat {
GIF89a,
};
static ErrorOr<GIFFormat> decode_gif_header(Core::Stream::Stream& stream)
static ErrorOr<GIFFormat> decode_gif_header(AK::Stream& stream)
{
static auto valid_header_87 = "GIF87a"sv;
static auto valid_header_89 = "GIF89a"sv;

View file

@ -459,7 +459,7 @@ static inline bool is_valid_marker(const Marker marker)
return false;
}
static inline ErrorOr<Marker> read_marker_at_cursor(Core::Stream::Stream& stream)
static inline ErrorOr<Marker> read_marker_at_cursor(AK::Stream& stream)
{
u16 marker = TRY(stream.read_value<BigEndian<u16>>());
if (is_valid_marker(marker))
@ -476,7 +476,7 @@ static inline ErrorOr<Marker> read_marker_at_cursor(Core::Stream::Stream& stream
return is_valid_marker(marker) ? marker : JPG_INVALID;
}
static ErrorOr<void> read_start_of_scan(Core::Stream::SeekableStream& stream, JPGLoadingContext& context)
static ErrorOr<void> read_start_of_scan(AK::SeekableStream& stream, JPGLoadingContext& context)
{
if (context.state < JPGLoadingContext::State::FrameDecoded) {
dbgln_if(JPG_DEBUG, "{}: SOS found before reading a SOF!", TRY(stream.tell()));
@ -537,7 +537,7 @@ static ErrorOr<void> read_start_of_scan(Core::Stream::SeekableStream& stream, JP
return {};
}
static ErrorOr<void> read_reset_marker(Core::Stream::SeekableStream& stream, JPGLoadingContext& context)
static ErrorOr<void> read_reset_marker(AK::SeekableStream& stream, JPGLoadingContext& context)
{
u16 bytes_to_read = TRY(stream.read_value<BigEndian<u16>>()) - 2;
if (bytes_to_read != 2) {
@ -548,7 +548,7 @@ static ErrorOr<void> read_reset_marker(Core::Stream::SeekableStream& stream, JPG
return {};
}
static ErrorOr<void> read_huffman_table(Core::Stream::SeekableStream& stream, JPGLoadingContext& context)
static ErrorOr<void> read_huffman_table(AK::SeekableStream& stream, JPGLoadingContext& context)
{
i32 bytes_to_read = TRY(stream.read_value<BigEndian<u16>>());
TRY(ensure_bounds_okay(TRY(stream.tell()), bytes_to_read, context.data_size));
@ -600,7 +600,7 @@ static ErrorOr<void> read_huffman_table(Core::Stream::SeekableStream& stream, JP
return {};
}
static ErrorOr<void> read_icc_profile(Core::Stream::SeekableStream& stream, JPGLoadingContext& context, int bytes_to_read)
static ErrorOr<void> read_icc_profile(SeekableStream& stream, JPGLoadingContext& context, int bytes_to_read)
{
if (bytes_to_read <= 2)
return Error::from_string_literal("icc marker too small");
@ -658,7 +658,7 @@ static ErrorOr<void> read_icc_profile(Core::Stream::SeekableStream& stream, JPGL
return {};
}
static ErrorOr<void> read_app_marker(Core::Stream::SeekableStream& stream, JPGLoadingContext& context, int app_marker_number)
static ErrorOr<void> read_app_marker(SeekableStream& stream, JPGLoadingContext& context, int app_marker_number)
{
i32 bytes_to_read = TRY(stream.read_value<BigEndian<u16>>());
TRY(ensure_bounds_okay(TRY(stream.tell()), bytes_to_read, context.data_size));
@ -718,7 +718,7 @@ static inline void set_macroblock_metadata(JPGLoadingContext& context)
context.mblock_meta.total = context.mblock_meta.hcount * context.mblock_meta.vcount;
}
static ErrorOr<void> read_start_of_frame(Core::Stream::SeekableStream& stream, JPGLoadingContext& context)
static ErrorOr<void> read_start_of_frame(AK::SeekableStream& stream, JPGLoadingContext& context)
{
if (context.state == JPGLoadingContext::FrameDecoded) {
dbgln_if(JPG_DEBUG, "{}: SOF repeated!", TRY(stream.tell()));
@ -802,7 +802,7 @@ static ErrorOr<void> read_start_of_frame(Core::Stream::SeekableStream& stream, J
return {};
}
static ErrorOr<void> read_quantization_table(Core::Stream::SeekableStream& stream, JPGLoadingContext& context)
static ErrorOr<void> read_quantization_table(AK::SeekableStream& stream, JPGLoadingContext& context)
{
i32 bytes_to_read = TRY(stream.read_value<BigEndian<u16>>()) - 2;
TRY(ensure_bounds_okay(TRY(stream.tell()), bytes_to_read, context.data_size));
@ -838,7 +838,7 @@ static ErrorOr<void> read_quantization_table(Core::Stream::SeekableStream& strea
return {};
}
static ErrorOr<void> skip_marker_with_length(Core::Stream::Stream& stream)
static ErrorOr<void> skip_marker_with_length(AK::Stream& stream)
{
u16 bytes_to_skip = TRY(stream.read_value<BigEndian<u16>>()) - 2;
TRY(stream.discard(bytes_to_skip));
@ -1086,7 +1086,7 @@ static ErrorOr<void> compose_bitmap(JPGLoadingContext& context, Vector<Macrobloc
return {};
}
static ErrorOr<void> parse_header(Core::Stream::SeekableStream& stream, JPGLoadingContext& context)
static ErrorOr<void> parse_header(AK::SeekableStream& stream, JPGLoadingContext& context)
{
auto marker = TRY(read_marker_at_cursor(stream));
if (marker != JPG_SOI) {
@ -1163,7 +1163,7 @@ static ErrorOr<void> parse_header(Core::Stream::SeekableStream& stream, JPGLoadi
VERIFY_NOT_REACHED();
}
static ErrorOr<void> scan_huffman_stream(Core::Stream::SeekableStream& stream, JPGLoadingContext& context)
static ErrorOr<void> scan_huffman_stream(AK::SeekableStream& stream, JPGLoadingContext& context)
{
u8 last_byte;
u8 current_byte = TRY(stream.read_value<u8>());

View file

@ -21,7 +21,7 @@ static constexpr u8 QOI_OP_RUN = 0b11000000;
static constexpr u8 QOI_MASK_2 = 0b11000000;
static constexpr u8 END_MARKER[] = { 0, 0, 0, 0, 0, 0, 0, 1 };
static ErrorOr<QOIHeader> decode_qoi_header(Core::Stream::Stream& stream)
static ErrorOr<QOIHeader> decode_qoi_header(AK::Stream& stream)
{
auto header = TRY(stream.read_value<QOIHeader>());
if (StringView { header.magic, array_size(header.magic) } != QOI_MAGIC)
@ -31,7 +31,7 @@ static ErrorOr<QOIHeader> decode_qoi_header(Core::Stream::Stream& stream)
return header;
}
static ErrorOr<Color> decode_qoi_op_rgb(Core::Stream::Stream& stream, u8 first_byte, Color pixel)
static ErrorOr<Color> decode_qoi_op_rgb(AK::Stream& stream, u8 first_byte, Color pixel)
{
VERIFY(first_byte == QOI_OP_RGB);
u8 bytes[3];
@ -41,7 +41,7 @@ static ErrorOr<Color> decode_qoi_op_rgb(Core::Stream::Stream& stream, u8 first_b
return Color { bytes[0], bytes[1], bytes[2], pixel.alpha() };
}
static ErrorOr<Color> decode_qoi_op_rgba(Core::Stream::Stream& stream, u8 first_byte)
static ErrorOr<Color> decode_qoi_op_rgba(AK::Stream& stream, u8 first_byte)
{
VERIFY(first_byte == QOI_OP_RGBA);
u8 bytes[4];
@ -49,7 +49,7 @@ static ErrorOr<Color> decode_qoi_op_rgba(Core::Stream::Stream& stream, u8 first_
return Color { bytes[0], bytes[1], bytes[2], bytes[3] };
}
static ErrorOr<u8> decode_qoi_op_index(Core::Stream::Stream&, u8 first_byte)
static ErrorOr<u8> decode_qoi_op_index(AK::Stream&, u8 first_byte)
{
VERIFY((first_byte & QOI_MASK_2) == QOI_OP_INDEX);
u8 index = first_byte & ~QOI_MASK_2;
@ -57,7 +57,7 @@ static ErrorOr<u8> decode_qoi_op_index(Core::Stream::Stream&, u8 first_byte)
return index;
}
static ErrorOr<Color> decode_qoi_op_diff(Core::Stream::Stream&, u8 first_byte, Color pixel)
static ErrorOr<Color> decode_qoi_op_diff(AK::Stream&, u8 first_byte, Color pixel)
{
VERIFY((first_byte & QOI_MASK_2) == QOI_OP_DIFF);
u8 dr = (first_byte & 0b00110000) >> 4;
@ -74,7 +74,7 @@ static ErrorOr<Color> decode_qoi_op_diff(Core::Stream::Stream&, u8 first_byte, C
};
}
static ErrorOr<Color> decode_qoi_op_luma(Core::Stream::Stream& stream, u8 first_byte, Color pixel)
static ErrorOr<Color> decode_qoi_op_luma(AK::Stream& stream, u8 first_byte, Color pixel)
{
VERIFY((first_byte & QOI_MASK_2) == QOI_OP_LUMA);
auto byte = TRY(stream.read_value<u8>());
@ -91,7 +91,7 @@ static ErrorOr<Color> decode_qoi_op_luma(Core::Stream::Stream& stream, u8 first_
};
}
static ErrorOr<u8> decode_qoi_op_run(Core::Stream::Stream&, u8 first_byte)
static ErrorOr<u8> decode_qoi_op_run(AK::Stream&, u8 first_byte)
{
VERIFY((first_byte & QOI_MASK_2) == QOI_OP_RUN);
u8 run = first_byte & ~QOI_MASK_2;
@ -107,7 +107,7 @@ static ErrorOr<u8> decode_qoi_op_run(Core::Stream::Stream&, u8 first_byte)
return run;
}
static ErrorOr<void> decode_qoi_end_marker(Core::Stream::Stream& stream)
static ErrorOr<void> decode_qoi_end_marker(AK::Stream& stream)
{
u8 bytes[array_size(END_MARKER)];
TRY(stream.read_entire_buffer({ &bytes, array_size(bytes) }));
@ -118,7 +118,7 @@ static ErrorOr<void> decode_qoi_end_marker(Core::Stream::Stream& stream)
return {};
}
static ErrorOr<NonnullRefPtr<Bitmap>> decode_qoi_image(Core::Stream::Stream& stream, u32 width, u32 height)
static ErrorOr<NonnullRefPtr<Bitmap>> decode_qoi_image(AK::Stream& stream, u32 width, u32 height)
{
// FIXME: Why is Gfx::Bitmap's size signed? Makes no sense whatsoever.
if (width > NumericLimits<int>::max())
@ -162,7 +162,7 @@ static ErrorOr<NonnullRefPtr<Bitmap>> decode_qoi_image(Core::Stream::Stream& str
return { move(bitmap) };
}
QOIImageDecoderPlugin::QOIImageDecoderPlugin(NonnullOwnPtr<Core::Stream::Stream> stream)
QOIImageDecoderPlugin::QOIImageDecoderPlugin(NonnullOwnPtr<AK::Stream> stream)
{
m_context = make<QOILoadingContext>();
m_context->stream = move(stream);
@ -234,7 +234,7 @@ ErrorOr<ImageFrameDescriptor> QOIImageDecoderPlugin::frame(size_t index)
return *m_context->error;
}
ErrorOr<void> QOIImageDecoderPlugin::decode_header_and_update_context(Core::Stream::Stream& stream)
ErrorOr<void> QOIImageDecoderPlugin::decode_header_and_update_context(AK::Stream& stream)
{
VERIFY(m_context->state < QOILoadingContext::State::HeaderDecoded);
auto error_or_header = decode_qoi_header(stream);
@ -248,7 +248,7 @@ ErrorOr<void> QOIImageDecoderPlugin::decode_header_and_update_context(Core::Stre
return {};
}
ErrorOr<void> QOIImageDecoderPlugin::decode_image_and_update_context(Core::Stream::Stream& stream)
ErrorOr<void> QOIImageDecoderPlugin::decode_image_and_update_context(AK::Stream& stream)
{
VERIFY(m_context->state < QOILoadingContext::State::ImageDecoded);
auto error_or_bitmap = decode_qoi_image(stream, m_context->header.width, m_context->header.height);

View file

@ -32,7 +32,7 @@ struct QOILoadingContext {
Error,
};
State state { State::NotDecoded };
OwnPtr<Core::Stream::Stream> stream {};
OwnPtr<AK::Stream> stream {};
QOIHeader header {};
RefPtr<Bitmap> bitmap;
Optional<Error> error;
@ -56,10 +56,10 @@ public:
virtual ErrorOr<Optional<ReadonlyBytes>> icc_data() override;
private:
ErrorOr<void> decode_header_and_update_context(Core::Stream::Stream&);
ErrorOr<void> decode_image_and_update_context(Core::Stream::Stream&);
ErrorOr<void> decode_header_and_update_context(AK::Stream&);
ErrorOr<void> decode_image_and_update_context(AK::Stream&);
QOIImageDecoderPlugin(NonnullOwnPtr<Core::Stream::Stream>);
QOIImageDecoderPlugin(NonnullOwnPtr<AK::Stream>);
OwnPtr<QOILoadingContext> m_context;
};