mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 08:07:44 +00:00
Everywhere: Split Error::from_string_literal and Error::from_string_view
Error::from_string_literal now takes direct char const*s, while Error::from_string_view does what Error::from_string_literal used to do: taking StringViews. This change will remove the need to insert `sv` after error strings when returning string literal errors once StringView(char const*) is removed. No functional changes.
This commit is contained in:
parent
c70f45ff44
commit
e5f09ea170
51 changed files with 282 additions and 261 deletions
|
@ -1356,13 +1356,13 @@ size_t BMPImageDecoderPlugin::frame_count()
|
|||
ErrorOr<ImageFrameDescriptor> BMPImageDecoderPlugin::frame(size_t index)
|
||||
{
|
||||
if (index > 0)
|
||||
return Error::from_string_literal("BMPImageDecoderPlugin: Invalid frame index"sv);
|
||||
return Error::from_string_literal("BMPImageDecoderPlugin: Invalid frame index");
|
||||
|
||||
if (m_context->state == BMPLoadingContext::State::Error)
|
||||
return Error::from_string_literal("BMPImageDecoderPlugin: Decoding failed"sv);
|
||||
return Error::from_string_literal("BMPImageDecoderPlugin: Decoding failed");
|
||||
|
||||
if (m_context->state < BMPLoadingContext::State::PixelDataDecoded && !decode_bmp_pixel_data(*m_context))
|
||||
return Error::from_string_literal("BMPImageDecoderPlugin: Decoding failed"sv);
|
||||
return Error::from_string_literal("BMPImageDecoderPlugin: Decoding failed");
|
||||
|
||||
VERIFY(m_context->bitmap);
|
||||
return ImageFrameDescriptor { m_context->bitmap, 0 };
|
||||
|
|
|
@ -70,7 +70,7 @@ ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_create(BitmapFormat format, IntSize c
|
|||
ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_create_shareable(BitmapFormat format, IntSize const& size, int scale_factor)
|
||||
{
|
||||
if (size_would_overflow(format, size, scale_factor))
|
||||
return Error::from_string_literal("Gfx::Bitmap::try_create_shareable size overflow"sv);
|
||||
return Error::from_string_literal("Gfx::Bitmap::try_create_shareable size overflow");
|
||||
|
||||
auto const pitch = minimum_pitch(size.width() * scale_factor, format);
|
||||
auto const data_size = size_in_bytes(pitch, size.height() * scale_factor);
|
||||
|
@ -98,7 +98,7 @@ Bitmap::Bitmap(BitmapFormat format, IntSize const& size, int scale_factor, Backi
|
|||
ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_create_wrapper(BitmapFormat format, IntSize const& size, int scale_factor, size_t pitch, void* data)
|
||||
{
|
||||
if (size_would_overflow(format, size, scale_factor))
|
||||
return Error::from_string_literal("Gfx::Bitmap::try_create_wrapper size overflow"sv);
|
||||
return Error::from_string_literal("Gfx::Bitmap::try_create_wrapper size overflow");
|
||||
return adopt_ref(*new Bitmap(format, size, scale_factor, pitch, data));
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,7 @@ ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_load_from_fd_and_close(int fd, String
|
|||
return bitmap.release_nonnull();
|
||||
}
|
||||
|
||||
return Error::from_string_literal("Gfx::Bitmap unable to load from fd"sv);
|
||||
return Error::from_string_literal("Gfx::Bitmap unable to load from fd");
|
||||
}
|
||||
|
||||
Bitmap::Bitmap(BitmapFormat format, IntSize const& size, int scale_factor, size_t pitch, void* data)
|
||||
|
@ -206,22 +206,22 @@ ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_create_from_serialized_byte_buffer(By
|
|||
};
|
||||
|
||||
if (!read(actual_size) || !read(width) || !read(height) || !read(scale_factor) || !read(format) || !read(palette_size))
|
||||
return Error::from_string_literal("Gfx::Bitmap::try_create_from_serialized_byte_buffer: decode failed"sv);
|
||||
return Error::from_string_literal("Gfx::Bitmap::try_create_from_serialized_byte_buffer: decode failed");
|
||||
|
||||
if (format > BitmapFormat::BGRA8888 || format < BitmapFormat::Indexed1)
|
||||
return Error::from_string_literal("Gfx::Bitmap::try_create_from_serialized_byte_buffer: decode failed"sv);
|
||||
return Error::from_string_literal("Gfx::Bitmap::try_create_from_serialized_byte_buffer: decode failed");
|
||||
|
||||
if (!check_size({ width, height }, scale_factor, format, actual_size))
|
||||
return Error::from_string_literal("Gfx::Bitmap::try_create_from_serialized_byte_buffer: decode failed"sv);
|
||||
return Error::from_string_literal("Gfx::Bitmap::try_create_from_serialized_byte_buffer: decode failed");
|
||||
|
||||
palette.ensure_capacity(palette_size);
|
||||
for (size_t i = 0; i < palette_size; ++i) {
|
||||
if (!read(palette[i]))
|
||||
return Error::from_string_literal("Gfx::Bitmap::try_create_from_serialized_byte_buffer: decode failed"sv);
|
||||
return Error::from_string_literal("Gfx::Bitmap::try_create_from_serialized_byte_buffer: decode failed");
|
||||
}
|
||||
|
||||
if (stream.remaining() < actual_size)
|
||||
return Error::from_string_literal("Gfx::Bitmap::try_create_from_serialized_byte_buffer: decode failed"sv);
|
||||
return Error::from_string_literal("Gfx::Bitmap::try_create_from_serialized_byte_buffer: decode failed");
|
||||
|
||||
auto data = stream.bytes().slice(stream.offset(), actual_size);
|
||||
|
||||
|
@ -548,7 +548,7 @@ Gfx::ShareableBitmap Bitmap::to_shareable_bitmap() const
|
|||
ErrorOr<BackingStore> Bitmap::allocate_backing_store(BitmapFormat format, IntSize const& size, int scale_factor)
|
||||
{
|
||||
if (size_would_overflow(format, size, scale_factor))
|
||||
return Error::from_string_literal("Gfx::Bitmap backing store size overflow"sv);
|
||||
return Error::from_string_literal("Gfx::Bitmap backing store size overflow");
|
||||
|
||||
auto const pitch = minimum_pitch(size.width() * scale_factor, format);
|
||||
auto const data_size_in_bytes = size_in_bytes(pitch, size.height() * scale_factor);
|
||||
|
|
|
@ -998,15 +998,15 @@ size_t DDSImageDecoderPlugin::frame_count()
|
|||
ErrorOr<ImageFrameDescriptor> DDSImageDecoderPlugin::frame(size_t index)
|
||||
{
|
||||
if (index > 0)
|
||||
return Error::from_string_literal("DDSImageDecoderPlugin: Invalid frame index"sv);
|
||||
return Error::from_string_literal("DDSImageDecoderPlugin: Invalid frame index");
|
||||
|
||||
if (m_context->state == DDSLoadingContext::State::Error)
|
||||
return Error::from_string_literal("DDSImageDecoderPlugin: Decoding failed"sv);
|
||||
return Error::from_string_literal("DDSImageDecoderPlugin: Decoding failed");
|
||||
|
||||
if (m_context->state < DDSLoadingContext::State::BitmapDecoded) {
|
||||
bool success = decode_dds(*m_context);
|
||||
if (!success)
|
||||
return Error::from_string_literal("DDSImageDecoderPlugin: Decoding failed"sv);
|
||||
return Error::from_string_literal("DDSImageDecoderPlugin: Decoding failed");
|
||||
}
|
||||
|
||||
VERIFY(m_context->bitmap);
|
||||
|
|
|
@ -168,22 +168,22 @@ Optional<Name> Name::from_slice(ReadonlyBytes slice)
|
|||
ErrorOr<Kern> Kern::from_slice(ReadonlyBytes slice)
|
||||
{
|
||||
if (slice.size() < sizeof(u32))
|
||||
return Error::from_string_literal("Invalid kern table header"sv);
|
||||
return Error::from_string_literal("Invalid kern table header");
|
||||
|
||||
// We only support the old (2x u16) version of the header
|
||||
auto version = be_u16(slice.data());
|
||||
auto number_of_subtables = be_u16(slice.offset(sizeof(u16)));
|
||||
if (version != 0)
|
||||
return Error::from_string_literal("Unsupported kern table version"sv);
|
||||
return Error::from_string_literal("Unsupported kern table version");
|
||||
if (number_of_subtables == 0)
|
||||
return Error::from_string_literal("Kern table does not contain any subtables"sv);
|
||||
return Error::from_string_literal("Kern table does not contain any subtables");
|
||||
|
||||
// Read all subtable offsets
|
||||
auto subtable_offsets = TRY(FixedArray<size_t>::try_create(number_of_subtables));
|
||||
size_t offset = 2 * sizeof(u16);
|
||||
for (size_t i = 0; i < number_of_subtables; ++i) {
|
||||
if (slice.size() < offset + Sizes::SubtableHeader)
|
||||
return Error::from_string_literal("Invalid kern subtable header"sv);
|
||||
return Error::from_string_literal("Invalid kern subtable header");
|
||||
|
||||
subtable_offsets[i] = offset;
|
||||
auto subtable_size = be_u16(slice.offset(offset + sizeof(u16)));
|
||||
|
@ -365,22 +365,22 @@ ErrorOr<NonnullRefPtr<Font>> Font::try_load_from_file(String path, unsigned inde
|
|||
ErrorOr<NonnullRefPtr<Font>> Font::try_load_from_externally_owned_memory(ReadonlyBytes buffer, unsigned index)
|
||||
{
|
||||
if (buffer.size() < 4)
|
||||
return Error::from_string_literal("Font file too small"sv);
|
||||
return Error::from_string_literal("Font file too small");
|
||||
|
||||
u32 tag = be_u32(buffer.data());
|
||||
if (tag == tag_from_str("ttcf")) {
|
||||
// It's a font collection
|
||||
if (buffer.size() < (u32)Sizes::TTCHeaderV1 + sizeof(u32) * (index + 1))
|
||||
return Error::from_string_literal("Font file too small"sv);
|
||||
return Error::from_string_literal("Font file too small");
|
||||
|
||||
u32 offset = be_u32(buffer.offset_pointer((u32)Sizes::TTCHeaderV1 + sizeof(u32) * index));
|
||||
return try_load_from_offset(buffer, offset);
|
||||
}
|
||||
if (tag == tag_from_str("OTTO"))
|
||||
return Error::from_string_literal("CFF fonts not supported yet"sv);
|
||||
return Error::from_string_literal("CFF fonts not supported yet");
|
||||
|
||||
if (tag != 0x00010000)
|
||||
return Error::from_string_literal("Not a valid font"sv);
|
||||
return Error::from_string_literal("Not a valid font");
|
||||
|
||||
return try_load_from_offset(buffer, 0);
|
||||
}
|
||||
|
@ -389,10 +389,10 @@ ErrorOr<NonnullRefPtr<Font>> Font::try_load_from_externally_owned_memory(Readonl
|
|||
ErrorOr<NonnullRefPtr<Font>> Font::try_load_from_offset(ReadonlyBytes buffer, u32 offset)
|
||||
{
|
||||
if (Checked<u32>::addition_would_overflow(offset, (u32)Sizes::OffsetTable))
|
||||
return Error::from_string_literal("Invalid offset in font header"sv);
|
||||
return Error::from_string_literal("Invalid offset in font header");
|
||||
|
||||
if (buffer.size() < offset + (u32)Sizes::OffsetTable)
|
||||
return Error::from_string_literal("Font file too small"sv);
|
||||
return Error::from_string_literal("Font file too small");
|
||||
|
||||
Optional<ReadonlyBytes> opt_head_slice = {};
|
||||
Optional<ReadonlyBytes> opt_name_slice = {};
|
||||
|
@ -417,7 +417,7 @@ ErrorOr<NonnullRefPtr<Font>> Font::try_load_from_offset(ReadonlyBytes buffer, u3
|
|||
|
||||
auto num_tables = be_u16(buffer.offset_pointer(offset + (u32)Offsets::NumTables));
|
||||
if (buffer.size() < offset + (u32)Sizes::OffsetTable + num_tables * (u32)Sizes::TableRecord)
|
||||
return Error::from_string_literal("Font file too small"sv);
|
||||
return Error::from_string_literal("Font file too small");
|
||||
|
||||
for (auto i = 0; i < num_tables; i++) {
|
||||
u32 record_offset = offset + (u32)Sizes::OffsetTable + i * (u32)Sizes::TableRecord;
|
||||
|
@ -426,10 +426,10 @@ ErrorOr<NonnullRefPtr<Font>> Font::try_load_from_offset(ReadonlyBytes buffer, u3
|
|||
u32 table_length = be_u32(buffer.offset_pointer(record_offset + (u32)Offsets::TableRecord_Length));
|
||||
|
||||
if (Checked<u32>::addition_would_overflow(table_offset, table_length))
|
||||
return Error::from_string_literal("Invalid table offset or length in font"sv);
|
||||
return Error::from_string_literal("Invalid table offset or length in font");
|
||||
|
||||
if (buffer.size() < table_offset + table_length)
|
||||
return Error::from_string_literal("Font file too small"sv);
|
||||
return Error::from_string_literal("Font file too small");
|
||||
|
||||
auto buffer_here = ReadonlyBytes(buffer.offset_pointer(table_offset), table_length);
|
||||
|
||||
|
@ -458,39 +458,39 @@ ErrorOr<NonnullRefPtr<Font>> Font::try_load_from_offset(ReadonlyBytes buffer, u3
|
|||
}
|
||||
|
||||
if (!opt_head_slice.has_value() || !(opt_head = Head::from_slice(opt_head_slice.value())).has_value())
|
||||
return Error::from_string_literal("Could not load Head"sv);
|
||||
return Error::from_string_literal("Could not load Head");
|
||||
auto head = opt_head.value();
|
||||
|
||||
if (!opt_name_slice.has_value() || !(opt_name = Name::from_slice(opt_name_slice.value())).has_value())
|
||||
return Error::from_string_literal("Could not load Name"sv);
|
||||
return Error::from_string_literal("Could not load Name");
|
||||
auto name = opt_name.value();
|
||||
|
||||
if (!opt_hhea_slice.has_value() || !(opt_hhea = Hhea::from_slice(opt_hhea_slice.value())).has_value())
|
||||
return Error::from_string_literal("Could not load Hhea"sv);
|
||||
return Error::from_string_literal("Could not load Hhea");
|
||||
auto hhea = opt_hhea.value();
|
||||
|
||||
if (!opt_maxp_slice.has_value() || !(opt_maxp = Maxp::from_slice(opt_maxp_slice.value())).has_value())
|
||||
return Error::from_string_literal("Could not load Maxp"sv);
|
||||
return Error::from_string_literal("Could not load Maxp");
|
||||
auto maxp = opt_maxp.value();
|
||||
|
||||
if (!opt_hmtx_slice.has_value() || !(opt_hmtx = Hmtx::from_slice(opt_hmtx_slice.value(), maxp.num_glyphs(), hhea.number_of_h_metrics())).has_value())
|
||||
return Error::from_string_literal("Could not load Hmtx"sv);
|
||||
return Error::from_string_literal("Could not load Hmtx");
|
||||
auto hmtx = opt_hmtx.value();
|
||||
|
||||
if (!opt_cmap_slice.has_value() || !(opt_cmap = Cmap::from_slice(opt_cmap_slice.value())).has_value())
|
||||
return Error::from_string_literal("Could not load Cmap"sv);
|
||||
return Error::from_string_literal("Could not load Cmap");
|
||||
auto cmap = opt_cmap.value();
|
||||
|
||||
if (!opt_loca_slice.has_value() || !(opt_loca = Loca::from_slice(opt_loca_slice.value(), maxp.num_glyphs(), head.index_to_loc_format())).has_value())
|
||||
return Error::from_string_literal("Could not load Loca"sv);
|
||||
return Error::from_string_literal("Could not load Loca");
|
||||
auto loca = opt_loca.value();
|
||||
|
||||
if (!opt_glyf_slice.has_value())
|
||||
return Error::from_string_literal("Could not load Glyf"sv);
|
||||
return Error::from_string_literal("Could not load Glyf");
|
||||
auto glyf = Glyf(opt_glyf_slice.value());
|
||||
|
||||
if (!opt_os2_slice.has_value())
|
||||
return Error::from_string_literal("Could not load OS/2"sv);
|
||||
return Error::from_string_literal("Could not load OS/2");
|
||||
auto os2 = OS2(opt_os2_slice.value());
|
||||
|
||||
Optional<Kern> kern {};
|
||||
|
@ -507,7 +507,7 @@ ErrorOr<NonnullRefPtr<Font>> Font::try_load_from_offset(ReadonlyBytes buffer, u3
|
|||
auto subtable = opt_subtable.value();
|
||||
auto platform = subtable.platform_id();
|
||||
if (!platform.has_value())
|
||||
return Error::from_string_literal("Invalid Platform ID"sv);
|
||||
return Error::from_string_literal("Invalid Platform ID");
|
||||
|
||||
if (platform.value() == Cmap::Subtable::Platform::Windows) {
|
||||
if (subtable.encoding_id() == (u16)Cmap::Subtable::WindowsEncoding::UnicodeFullRepertoire) {
|
||||
|
|
|
@ -60,12 +60,12 @@ ErrorOr<NonnullRefPtr<Font>> Font::try_load_from_externally_owned_memory(Readonl
|
|||
{
|
||||
// https://www.w3.org/TR/WOFF/#WOFFHeader
|
||||
if (buffer.size() < WOFF_HEADER_SIZE)
|
||||
return Error::from_string_literal("WOFF file too small"sv);
|
||||
return Error::from_string_literal("WOFF file too small");
|
||||
|
||||
// The signature field in the WOFF header MUST contain the "magic number" 0x774F4646. If the field does not contain this value, user agents MUST reject the file as invalid.
|
||||
u32 signature = be_u32(buffer.data());
|
||||
if (signature != WOFF_SIGNATURE)
|
||||
return Error::from_string_literal("Invalid WOFF signature"sv);
|
||||
return Error::from_string_literal("Invalid WOFF signature");
|
||||
// The flavor field corresponds to the "sfnt version" field found at the beginning of an sfnt file,
|
||||
// indicating the type of font data contained. Although only fonts of type 0x00010000 (the version number 1.0 as a 16.16 fixed-point value, indicating TrueType glyph data)
|
||||
// and 0x4F54544F (the tag 'OTTO', indicating CFF glyph data) are widely supported at present,
|
||||
|
@ -85,17 +85,17 @@ ErrorOr<NonnullRefPtr<Font>> Font::try_load_from_externally_owned_memory(Readonl
|
|||
u32 priv_offset = be_u32(buffer.offset(36)); // Offset to private data block, from beginning of WOFF file.
|
||||
u32 priv_length = be_u32(buffer.offset(40)); // Length of private data block.
|
||||
if (length > buffer.size())
|
||||
return Error::from_string_literal("Invalid WOFF length"sv);
|
||||
return Error::from_string_literal("Invalid WOFF length");
|
||||
if (reserved != 0)
|
||||
return Error::from_string_literal("Invalid WOFF reserved field"sv);
|
||||
return Error::from_string_literal("Invalid WOFF reserved field");
|
||||
if (meta_length == 0 && meta_offset != 0)
|
||||
return Error::from_string_literal("Invalid WOFF meta block offset"sv);
|
||||
return Error::from_string_literal("Invalid WOFF meta block offset");
|
||||
if (priv_length == 0 && priv_offset != 0)
|
||||
return Error::from_string_literal("Invalid WOFF private block offset"sv);
|
||||
return Error::from_string_literal("Invalid WOFF private block offset");
|
||||
if (WOFF_HEADER_SIZE + num_tables * WOFF_TABLE_SIZE > length)
|
||||
return Error::from_string_literal("Truncated WOFF table directory"sv);
|
||||
return Error::from_string_literal("Truncated WOFF table directory");
|
||||
if (total_sfnt_size > 10 * MiB)
|
||||
return Error::from_string_literal("Uncompressed font is more than 10 MiB"sv);
|
||||
return Error::from_string_literal("Uncompressed font is more than 10 MiB");
|
||||
auto font_buffer = TRY(ByteBuffer::create_zeroed(total_sfnt_size));
|
||||
|
||||
// ISO-IEC 14496-22:2019 4.5.1 Offset table
|
||||
|
@ -116,19 +116,19 @@ ErrorOr<NonnullRefPtr<Font>> Font::try_load_from_externally_owned_memory(Readonl
|
|||
u32 orig_checksum = be_u32(buffer.offset(base_offset + 16));
|
||||
|
||||
if ((size_t)offset + comp_length > length)
|
||||
return Error::from_string_literal("Truncated WOFF table"sv);
|
||||
return Error::from_string_literal("Truncated WOFF table");
|
||||
if (font_buffer_offset + orig_length > font_buffer.size())
|
||||
return Error::from_string_literal("Uncompressed WOFF table too big"sv);
|
||||
return Error::from_string_literal("Uncompressed WOFF table too big");
|
||||
if (comp_length < orig_length) {
|
||||
auto decompressed = Compress::Zlib::decompress_all(buffer.slice(offset, comp_length));
|
||||
if (!decompressed.has_value())
|
||||
return Error::from_string_literal("Could not decompress WOFF table"sv);
|
||||
return Error::from_string_literal("Could not decompress WOFF table");
|
||||
if (orig_length != decompressed->size())
|
||||
return Error::from_string_literal("Invalid decompressed WOFF table length"sv);
|
||||
return Error::from_string_literal("Invalid decompressed WOFF table length");
|
||||
font_buffer.overwrite(font_buffer_offset, decompressed->data(), orig_length);
|
||||
} else {
|
||||
if (comp_length != orig_length)
|
||||
return Error::from_string_literal("Invalid uncompressed WOFF table length"sv);
|
||||
return Error::from_string_literal("Invalid uncompressed WOFF table length");
|
||||
font_buffer.overwrite(font_buffer_offset, buffer.data() + offset, orig_length);
|
||||
}
|
||||
|
||||
|
|
|
@ -695,20 +695,20 @@ size_t GIFImageDecoderPlugin::frame_count()
|
|||
ErrorOr<ImageFrameDescriptor> GIFImageDecoderPlugin::frame(size_t index)
|
||||
{
|
||||
if (m_context->error_state >= GIFLoadingContext::ErrorState::FailedToDecodeAnyFrame) {
|
||||
return Error::from_string_literal("GIFImageDecoderPlugin: Decoding failed"sv);
|
||||
return Error::from_string_literal("GIFImageDecoderPlugin: Decoding failed");
|
||||
}
|
||||
|
||||
if (m_context->state < GIFLoadingContext::State::FrameDescriptorsLoaded) {
|
||||
if (!load_gif_frame_descriptors(*m_context)) {
|
||||
m_context->error_state = GIFLoadingContext::ErrorState::FailedToLoadFrameDescriptors;
|
||||
return Error::from_string_literal("GIFImageDecoderPlugin: Decoding failed"sv);
|
||||
return Error::from_string_literal("GIFImageDecoderPlugin: Decoding failed");
|
||||
}
|
||||
}
|
||||
|
||||
if (m_context->error_state == GIFLoadingContext::ErrorState::NoError && !decode_frame(*m_context, index)) {
|
||||
if (m_context->state < GIFLoadingContext::State::FrameComplete || !decode_frame(*m_context, 0)) {
|
||||
m_context->error_state = GIFLoadingContext::ErrorState::FailedToDecodeAnyFrame;
|
||||
return Error::from_string_literal("GIFImageDecoderPlugin: Decoding failed"sv);
|
||||
return Error::from_string_literal("GIFImageDecoderPlugin: Decoding failed");
|
||||
}
|
||||
m_context->error_state = GIFLoadingContext::ErrorState::FailedToDecodeAllFrames;
|
||||
}
|
||||
|
|
|
@ -342,17 +342,17 @@ size_t ICOImageDecoderPlugin::frame_count()
|
|||
ErrorOr<ImageFrameDescriptor> ICOImageDecoderPlugin::frame(size_t index)
|
||||
{
|
||||
if (index > 0)
|
||||
return Error::from_string_literal("ICOImageDecoderPlugin: Invalid frame index"sv);
|
||||
return Error::from_string_literal("ICOImageDecoderPlugin: Invalid frame index");
|
||||
|
||||
if (m_context->state == ICOLoadingContext::State::Error)
|
||||
return Error::from_string_literal("ICOImageDecoderPlugin: Decoding failed"sv);
|
||||
return Error::from_string_literal("ICOImageDecoderPlugin: Decoding failed");
|
||||
|
||||
if (m_context->state < ICOLoadingContext::State::BitmapDecoded) {
|
||||
// NOTE: This forces the chunk decoding to happen.
|
||||
bool success = load_ico_bitmap(*m_context, {});
|
||||
if (!success) {
|
||||
m_context->state = ICOLoadingContext::State::Error;
|
||||
return Error::from_string_literal("ICOImageDecoderPlugin: Decoding failed"sv);
|
||||
return Error::from_string_literal("ICOImageDecoderPlugin: Decoding failed");
|
||||
}
|
||||
m_context->state = ICOLoadingContext::State::BitmapDecoded;
|
||||
}
|
||||
|
|
|
@ -1285,15 +1285,15 @@ size_t JPGImageDecoderPlugin::frame_count()
|
|||
ErrorOr<ImageFrameDescriptor> JPGImageDecoderPlugin::frame(size_t index)
|
||||
{
|
||||
if (index > 0)
|
||||
return Error::from_string_literal("JPGImageDecoderPlugin: Invalid frame index"sv);
|
||||
return Error::from_string_literal("JPGImageDecoderPlugin: Invalid frame index");
|
||||
|
||||
if (m_context->state == JPGLoadingContext::State::Error)
|
||||
return Error::from_string_literal("JPGImageDecoderPlugin: Decoding failed"sv);
|
||||
return Error::from_string_literal("JPGImageDecoderPlugin: Decoding failed");
|
||||
|
||||
if (m_context->state < JPGLoadingContext::State::BitmapDecoded) {
|
||||
if (!decode_jpg(*m_context)) {
|
||||
m_context->state = JPGLoadingContext::State::Error;
|
||||
return Error::from_string_literal("JPGImageDecoderPlugin: Decoding failed"sv);
|
||||
return Error::from_string_literal("JPGImageDecoderPlugin: Decoding failed");
|
||||
}
|
||||
m_context->state = JPGLoadingContext::State::BitmapDecoded;
|
||||
}
|
||||
|
|
|
@ -407,7 +407,7 @@ NEVER_INLINE FLATTEN static ErrorOr<void> unfilter(PNGLoadingContext& context)
|
|||
for (int i = 0; i < context.width; ++i) {
|
||||
auto& pixel = (Pixel&)context.bitmap->scanline(y)[i];
|
||||
if (palette_index[i] >= context.palette_data.size())
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Palette index out of range"sv);
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Palette index out of range");
|
||||
auto& color = context.palette_data.at((int)palette_index[i]);
|
||||
auto transparency = context.palette_transparency_data.size() >= palette_index[i] + 1u
|
||||
? context.palette_transparency_data.data()[palette_index[i]]
|
||||
|
@ -428,7 +428,7 @@ NEVER_INLINE FLATTEN static ErrorOr<void> unfilter(PNGLoadingContext& context)
|
|||
auto palette_index = (palette_indices[i / pixels_per_byte] >> bit_offset) & mask;
|
||||
auto& pixel = (Pixel&)context.bitmap->scanline(y)[i];
|
||||
if ((size_t)palette_index >= context.palette_data.size())
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Palette index out of range"sv);
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Palette index out of range");
|
||||
auto& color = context.palette_data.at(palette_index);
|
||||
auto transparency = context.palette_transparency_data.size() >= palette_index + 1u
|
||||
? context.palette_transparency_data.data()[palette_index]
|
||||
|
@ -578,23 +578,23 @@ static ErrorOr<void> decode_png_bitmap_simple(PNGLoadingContext& context)
|
|||
PNG::FilterType filter;
|
||||
if (!streamer.read(filter)) {
|
||||
context.state = PNGLoadingContext::State::Error;
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Decoding failed"sv);
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Decoding failed");
|
||||
}
|
||||
|
||||
if (to_underlying(filter) > 4) {
|
||||
context.state = PNGLoadingContext::State::Error;
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Invalid PNG filter"sv);
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Invalid PNG filter");
|
||||
}
|
||||
|
||||
context.scanlines.append({ filter });
|
||||
auto& scanline_buffer = context.scanlines.last().data;
|
||||
auto row_size = context.compute_row_size_for_width(context.width);
|
||||
if (row_size.has_overflow())
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Row size overflow"sv);
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Row size overflow");
|
||||
|
||||
if (!streamer.wrap_bytes(scanline_buffer, row_size.value())) {
|
||||
context.state = PNGLoadingContext::State::Error;
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Decoding failed"sv);
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Decoding failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -673,12 +673,12 @@ static ErrorOr<void> decode_adam7_pass(PNGLoadingContext& context, Streamer& str
|
|||
PNG::FilterType filter;
|
||||
if (!streamer.read(filter)) {
|
||||
context.state = PNGLoadingContext::State::Error;
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Decoding failed"sv);
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Decoding failed");
|
||||
}
|
||||
|
||||
if (to_underlying(filter) > 4) {
|
||||
context.state = PNGLoadingContext::State::Error;
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Invalid PNG filter"sv);
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Invalid PNG filter");
|
||||
}
|
||||
|
||||
subimage_context.scanlines.append({ filter });
|
||||
|
@ -686,10 +686,10 @@ static ErrorOr<void> decode_adam7_pass(PNGLoadingContext& context, Streamer& str
|
|||
|
||||
auto row_size = context.compute_row_size_for_width(subimage_context.width);
|
||||
if (row_size.has_overflow())
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Row size overflow"sv);
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Row size overflow");
|
||||
if (!streamer.wrap_bytes(scanline_buffer, row_size.value())) {
|
||||
context.state = PNGLoadingContext::State::Error;
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Decoding failed"sv);
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Decoding failed");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -718,22 +718,22 @@ static ErrorOr<void> decode_png_bitmap(PNGLoadingContext& context)
|
|||
{
|
||||
if (context.state < PNGLoadingContext::State::ChunksDecoded) {
|
||||
if (!decode_png_chunks(context))
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Decoding failed"sv);
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Decoding failed");
|
||||
}
|
||||
|
||||
if (context.state >= PNGLoadingContext::State::BitmapDecoded)
|
||||
return {};
|
||||
|
||||
if (context.width == -1 || context.height == -1)
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Didn't see an IHDR chunk."sv);
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Didn't see an IHDR chunk.");
|
||||
|
||||
if (context.color_type == PNG::ColorType::IndexedColor && context.palette_data.is_empty())
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Didn't see a PLTE chunk for a palletized image, or it was empty."sv);
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Didn't see a PLTE chunk for a palletized image, or it was empty.");
|
||||
|
||||
auto result = Compress::Zlib::decompress_all(context.compressed_data.span());
|
||||
if (!result.has_value()) {
|
||||
context.state = PNGLoadingContext::State::Error;
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Decompression failed"sv);
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Decompression failed");
|
||||
}
|
||||
context.decompression_buffer = &result.value();
|
||||
context.compressed_data.clear();
|
||||
|
@ -748,7 +748,7 @@ static ErrorOr<void> decode_png_bitmap(PNGLoadingContext& context)
|
|||
break;
|
||||
default:
|
||||
context.state = PNGLoadingContext::State::Error;
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Invalid interlace method"sv);
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Invalid interlace method");
|
||||
}
|
||||
|
||||
context.decompression_buffer = nullptr;
|
||||
|
@ -960,10 +960,10 @@ size_t PNGImageDecoderPlugin::frame_count()
|
|||
ErrorOr<ImageFrameDescriptor> PNGImageDecoderPlugin::frame(size_t index)
|
||||
{
|
||||
if (index > 0)
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Invalid frame index"sv);
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Invalid frame index");
|
||||
|
||||
if (m_context->state == PNGLoadingContext::State::Error)
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Decoding failed"sv);
|
||||
return Error::from_string_literal("PNGImageDecoderPlugin: Decoding failed");
|
||||
|
||||
if (m_context->state < PNGLoadingContext::State::BitmapDecoded) {
|
||||
// NOTE: This forces the chunk decoding to happen.
|
||||
|
|
|
@ -145,15 +145,15 @@ template<typename TContext>
|
|||
ErrorOr<ImageFrameDescriptor> PortableImageDecoderPlugin<TContext>::frame(size_t index)
|
||||
{
|
||||
if (index > 0)
|
||||
return Error::from_string_literal("PortableImageDecoderPlugin: Invalid frame index"sv);
|
||||
return Error::from_string_literal("PortableImageDecoderPlugin: Invalid frame index");
|
||||
|
||||
if (m_context->state == TContext::State::Error)
|
||||
return Error::from_string_literal("PortableImageDecoderPlugin: Decoding failed"sv);
|
||||
return Error::from_string_literal("PortableImageDecoderPlugin: Decoding failed");
|
||||
|
||||
if (m_context->state < TContext::State::Decoded) {
|
||||
bool success = decode(*m_context);
|
||||
if (!success)
|
||||
return Error::from_string_literal("PortableImageDecoderPlugin: Decoding failed"sv);
|
||||
return Error::from_string_literal("PortableImageDecoderPlugin: Decoding failed");
|
||||
}
|
||||
|
||||
VERIFY(m_context->bitmap);
|
||||
|
|
|
@ -26,9 +26,9 @@ static ErrorOr<QOIHeader> decode_qoi_header(InputMemoryStream& stream)
|
|||
QOIHeader header;
|
||||
stream >> Bytes { &header, sizeof(header) };
|
||||
if (stream.handle_any_error())
|
||||
return Error::from_string_literal("Invalid QOI image: end of stream while reading header"sv);
|
||||
return Error::from_string_literal("Invalid QOI image: end of stream while reading header");
|
||||
if (StringView { header.magic, array_size(header.magic) } != QOI_MAGIC)
|
||||
return Error::from_string_literal("Invalid QOI image: incorrect header magic"sv);
|
||||
return Error::from_string_literal("Invalid QOI image: incorrect header magic");
|
||||
header.width = AK::convert_between_host_and_big_endian(header.width);
|
||||
header.height = AK::convert_between_host_and_big_endian(header.height);
|
||||
return header;
|
||||
|
@ -39,7 +39,7 @@ static ErrorOr<Color> decode_qoi_op_rgb(InputMemoryStream& stream, Color pixel)
|
|||
u8 bytes[4];
|
||||
stream >> Bytes { &bytes, array_size(bytes) };
|
||||
if (stream.handle_any_error())
|
||||
return Error::from_string_literal("Invalid QOI image: end of stream while reading QOI_OP_RGB chunk"sv);
|
||||
return Error::from_string_literal("Invalid QOI image: end of stream while reading QOI_OP_RGB chunk");
|
||||
VERIFY(bytes[0] == QOI_OP_RGB);
|
||||
|
||||
// The alpha value remains unchanged from the previous pixel.
|
||||
|
@ -51,7 +51,7 @@ static ErrorOr<Color> decode_qoi_op_rgba(InputMemoryStream& stream)
|
|||
u8 bytes[5];
|
||||
stream >> Bytes { &bytes, array_size(bytes) };
|
||||
if (stream.handle_any_error())
|
||||
return Error::from_string_literal("Invalid QOI image: end of stream while reading QOI_OP_RGBA chunk"sv);
|
||||
return Error::from_string_literal("Invalid QOI image: end of stream while reading QOI_OP_RGBA chunk");
|
||||
VERIFY(bytes[0] == QOI_OP_RGBA);
|
||||
return Color { bytes[1], bytes[2], bytes[3], bytes[4] };
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ static ErrorOr<u8> decode_qoi_op_index(InputMemoryStream& stream)
|
|||
u8 byte;
|
||||
stream >> byte;
|
||||
if (stream.handle_any_error())
|
||||
return Error::from_string_literal("Invalid QOI image: end of stream while reading QOI_OP_INDEX chunk"sv);
|
||||
return Error::from_string_literal("Invalid QOI image: end of stream while reading QOI_OP_INDEX chunk");
|
||||
VERIFY((byte & QOI_MASK_2) == QOI_OP_INDEX);
|
||||
u8 index = byte & ~QOI_MASK_2;
|
||||
VERIFY(index <= 63);
|
||||
|
@ -73,7 +73,7 @@ static ErrorOr<Color> decode_qoi_op_diff(InputMemoryStream& stream, Color pixel)
|
|||
u8 byte;
|
||||
stream >> byte;
|
||||
if (stream.handle_any_error())
|
||||
return Error::from_string_literal("Invalid QOI image: end of stream while reading QOI_OP_DIFF chunk"sv);
|
||||
return Error::from_string_literal("Invalid QOI image: end of stream while reading QOI_OP_DIFF chunk");
|
||||
VERIFY((byte & QOI_MASK_2) == QOI_OP_DIFF);
|
||||
u8 dr = (byte & 0b00110000) >> 4;
|
||||
u8 dg = (byte & 0b00001100) >> 2;
|
||||
|
@ -94,7 +94,7 @@ static ErrorOr<Color> decode_qoi_op_luma(InputMemoryStream& stream, Color pixel)
|
|||
u8 bytes[2];
|
||||
stream >> Bytes { &bytes, array_size(bytes) };
|
||||
if (stream.handle_any_error())
|
||||
return Error::from_string_literal("Invalid QOI image: end of stream while reading QOI_OP_LUMA chunk"sv);
|
||||
return Error::from_string_literal("Invalid QOI image: end of stream while reading QOI_OP_LUMA chunk");
|
||||
VERIFY((bytes[0] & QOI_MASK_2) == QOI_OP_LUMA);
|
||||
u8 diff_green = (bytes[0] & ~QOI_MASK_2);
|
||||
u8 dr_dg = (bytes[1] & 0b11110000) >> 4;
|
||||
|
@ -114,7 +114,7 @@ static ErrorOr<u8> decode_qoi_op_run(InputMemoryStream& stream)
|
|||
u8 byte;
|
||||
stream >> byte;
|
||||
if (stream.handle_any_error())
|
||||
return Error::from_string_literal("Invalid QOI image: end of stream while reading QOI_OP_RUN chunk"sv);
|
||||
return Error::from_string_literal("Invalid QOI image: end of stream while reading QOI_OP_RUN chunk");
|
||||
VERIFY((byte & QOI_MASK_2) == QOI_OP_RUN);
|
||||
u8 run = byte & ~QOI_MASK_2;
|
||||
|
||||
|
@ -123,7 +123,7 @@ static ErrorOr<u8> decode_qoi_op_run(InputMemoryStream& stream)
|
|||
|
||||
// Note that the run-lengths 63 and 64 (b111110 and b111111) are illegal as they are occupied by the QOI_OP_RGB and QOI_OP_RGBA tags.
|
||||
if (run == QOI_OP_RGB || run == QOI_OP_RGBA)
|
||||
return Error::from_string_literal("Invalid QOI image: illegal run length"sv);
|
||||
return Error::from_string_literal("Invalid QOI image: illegal run length");
|
||||
|
||||
VERIFY(run >= 1 && run <= 62);
|
||||
return run;
|
||||
|
@ -134,11 +134,11 @@ static ErrorOr<void> decode_qoi_end_marker(InputMemoryStream& stream)
|
|||
u8 bytes[array_size(END_MARKER)];
|
||||
stream >> Bytes { &bytes, array_size(bytes) };
|
||||
if (stream.handle_any_error())
|
||||
return Error::from_string_literal("Invalid QOI image: end of stream while reading end marker"sv);
|
||||
return Error::from_string_literal("Invalid QOI image: end of stream while reading end marker");
|
||||
if (!stream.eof())
|
||||
return Error::from_string_literal("Invalid QOI image: expected end of stream but more bytes are available"sv);
|
||||
return Error::from_string_literal("Invalid QOI image: expected end of stream but more bytes are available");
|
||||
if (memcmp(&END_MARKER, &bytes, array_size(bytes)) != 0)
|
||||
return Error::from_string_literal("Invalid QOI image: incorrect end marker"sv);
|
||||
return Error::from_string_literal("Invalid QOI image: incorrect end marker");
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -146,9 +146,9 @@ static ErrorOr<NonnullRefPtr<Bitmap>> decode_qoi_image(InputMemoryStream& stream
|
|||
{
|
||||
// FIXME: Why is Gfx::Bitmap's size signed? Makes no sense whatsoever.
|
||||
if (width > NumericLimits<int>::max())
|
||||
return Error::from_string_literal("Cannot create bitmap for QOI image of valid size, width exceeds maximum Gfx::Bitmap width"sv);
|
||||
return Error::from_string_literal("Cannot create bitmap for QOI image of valid size, width exceeds maximum Gfx::Bitmap width");
|
||||
if (height > NumericLimits<int>::max())
|
||||
return Error::from_string_literal("Cannot create bitmap for QOI image of valid size, height exceeds maximum Gfx::Bitmap height"sv);
|
||||
return Error::from_string_literal("Cannot create bitmap for QOI image of valid size, height exceeds maximum Gfx::Bitmap height");
|
||||
|
||||
auto bitmap = TRY(Bitmap::try_create(BitmapFormat::BGRA8888, { width, height }));
|
||||
|
||||
|
@ -163,7 +163,7 @@ static ErrorOr<NonnullRefPtr<Bitmap>> decode_qoi_image(InputMemoryStream& stream
|
|||
if (run == 0) {
|
||||
u8 tag = stream.peek_or_error();
|
||||
if (stream.handle_any_error())
|
||||
return Error::from_string_literal("Invalid QOI image: end of stream while reading chunk tag"sv);
|
||||
return Error::from_string_literal("Invalid QOI image: end of stream while reading chunk tag");
|
||||
if (tag == QOI_OP_RGB)
|
||||
pixel = TRY(decode_qoi_op_rgb(stream, pixel));
|
||||
else if (tag == QOI_OP_RGBA)
|
||||
|
@ -177,7 +177,7 @@ static ErrorOr<NonnullRefPtr<Bitmap>> decode_qoi_image(InputMemoryStream& stream
|
|||
else if ((tag & QOI_MASK_2) == QOI_OP_RUN)
|
||||
run = TRY(decode_qoi_op_run(stream));
|
||||
else
|
||||
return Error::from_string_literal("Invalid QOI image: unknown chunk tag"sv);
|
||||
return Error::from_string_literal("Invalid QOI image: unknown chunk tag");
|
||||
}
|
||||
auto index_position = (pixel.red() * 3 + pixel.green() * 5 + pixel.blue() * 7 + pixel.alpha() * 11) % 64;
|
||||
previous_pixels[index_position] = pixel;
|
||||
|
@ -232,7 +232,7 @@ bool QOIImageDecoderPlugin::sniff()
|
|||
ErrorOr<ImageFrameDescriptor> QOIImageDecoderPlugin::frame(size_t index)
|
||||
{
|
||||
if (index > 0)
|
||||
return Error::from_string_literal("Invalid frame index"sv);
|
||||
return Error::from_string_literal("Invalid frame index");
|
||||
|
||||
if (m_context->state == QOILoadingContext::State::NotDecoded) {
|
||||
InputMemoryStream stream { { m_context->data, m_context->data_size } };
|
||||
|
|
|
@ -56,7 +56,7 @@ ErrorOr<void> decode(Decoder& decoder, Gfx::ShareableBitmap& shareable_bitmap)
|
|||
u32 raw_bitmap_format;
|
||||
TRY(decoder.decode(raw_bitmap_format));
|
||||
if (!Gfx::is_valid_bitmap_format(raw_bitmap_format))
|
||||
return Error::from_string_literal("IPC: Invalid Gfx::ShareableBitmap format"sv);
|
||||
return Error::from_string_literal("IPC: Invalid Gfx::ShareableBitmap format");
|
||||
auto bitmap_format = (Gfx::BitmapFormat)raw_bitmap_format;
|
||||
Vector<Gfx::ARGB32> palette;
|
||||
if (Gfx::Bitmap::is_indexed(bitmap_format)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue