LibGfx: Make sure we use unique class names

Previously there were different definitions for classes with the
same name. This is a violation of the C++ ODR.
This commit is contained in:
Gunnar Beutner 2021-05-28 07:01:52 +02:00 committed by Andreas Kling
parent 1f57cc5957
commit 5e1c1eb840
Notes: sideshowbarker 2024-07-18 17:17:17 +09:00
4 changed files with 35 additions and 35 deletions

View File

@ -185,9 +185,9 @@ RefPtr<Gfx::Bitmap> load_bmp_from_memory(const u8* data, size_t length)
return bitmap;
}
class Streamer {
class InputStreamer {
public:
Streamer(const u8* data, size_t size)
InputStreamer(const u8* data, size_t size)
: m_data_ptr(data)
, m_size_remaining(size)
{
@ -411,7 +411,7 @@ static bool check_for_invalid_bitmask_combinations(BMPLoadingContext& context)
return true;
}
static bool set_dib_bitmasks(BMPLoadingContext& context, Streamer& streamer)
static bool set_dib_bitmasks(BMPLoadingContext& context, InputStreamer& streamer)
{
if (!check_for_invalid_bitmask_combinations(context))
return false;
@ -456,7 +456,7 @@ static bool decode_bmp_header(BMPLoadingContext& context)
return false;
}
Streamer streamer(context.file_bytes, bmp_header_size);
InputStreamer streamer(context.file_bytes, bmp_header_size);
u16 header = streamer.read_u16();
if (header != 0x4d42) {
@ -490,7 +490,7 @@ static bool decode_bmp_header(BMPLoadingContext& context)
return true;
}
static bool decode_bmp_core_dib(BMPLoadingContext& context, Streamer& streamer)
static bool decode_bmp_core_dib(BMPLoadingContext& context, InputStreamer& streamer)
{
auto& core = context.dib.core;
@ -551,7 +551,7 @@ ALWAYS_INLINE static bool is_supported_compression_format(BMPLoadingContext& con
|| compression == Compression::RLE4 || (compression == Compression::RLE24 && context.dib_type <= DIBType::OSV2);
}
static bool decode_bmp_osv2_dib(BMPLoadingContext& context, Streamer& streamer, bool short_variant = false)
static bool decode_bmp_osv2_dib(BMPLoadingContext& context, InputStreamer& streamer, bool short_variant = false)
{
auto& core = context.dib.core;
@ -636,7 +636,7 @@ static bool decode_bmp_osv2_dib(BMPLoadingContext& context, Streamer& streamer,
return true;
}
static bool decode_bmp_info_dib(BMPLoadingContext& context, Streamer& streamer)
static bool decode_bmp_info_dib(BMPLoadingContext& context, InputStreamer& streamer)
{
if (!decode_bmp_core_dib(context, streamer))
return false;
@ -676,7 +676,7 @@ static bool decode_bmp_info_dib(BMPLoadingContext& context, Streamer& streamer)
return true;
}
static bool decode_bmp_v2_dib(BMPLoadingContext& context, Streamer& streamer)
static bool decode_bmp_v2_dib(BMPLoadingContext& context, InputStreamer& streamer)
{
if (!decode_bmp_info_dib(context, streamer))
return false;
@ -694,7 +694,7 @@ static bool decode_bmp_v2_dib(BMPLoadingContext& context, Streamer& streamer)
return true;
}
static bool decode_bmp_v3_dib(BMPLoadingContext& context, Streamer& streamer)
static bool decode_bmp_v3_dib(BMPLoadingContext& context, InputStreamer& streamer)
{
if (!decode_bmp_v2_dib(context, streamer))
return false;
@ -719,7 +719,7 @@ static bool decode_bmp_v3_dib(BMPLoadingContext& context, Streamer& streamer)
return true;
}
static bool decode_bmp_v4_dib(BMPLoadingContext& context, Streamer& streamer)
static bool decode_bmp_v4_dib(BMPLoadingContext& context, InputStreamer& streamer)
{
if (!decode_bmp_v3_dib(context, streamer))
return false;
@ -742,7 +742,7 @@ static bool decode_bmp_v4_dib(BMPLoadingContext& context, Streamer& streamer)
return true;
}
static bool decode_bmp_v5_dib(BMPLoadingContext& context, Streamer& streamer)
static bool decode_bmp_v5_dib(BMPLoadingContext& context, InputStreamer& streamer)
{
if (!decode_bmp_v4_dib(context, streamer))
return false;
@ -775,7 +775,7 @@ static bool decode_bmp_dib(BMPLoadingContext& context)
if (context.file_size < bmp_header_size + 4)
return false;
Streamer streamer(context.file_bytes + bmp_header_size, 4);
InputStreamer streamer(context.file_bytes + bmp_header_size, 4);
u32 dib_size = streamer.read_u32();
if (context.file_size < bmp_header_size + dib_size)
@ -785,7 +785,7 @@ static bool decode_bmp_dib(BMPLoadingContext& context)
return false;
}
streamer = Streamer(context.file_bytes + bmp_header_size + 4, context.data_offset - bmp_header_size - 4);
streamer = InputStreamer(context.file_bytes + bmp_header_size + 4, context.data_offset - bmp_header_size - 4);
dbgln_if(BMP_DEBUG, "BMP dib size: {}", dib_size);
@ -888,7 +888,7 @@ static bool decode_bmp_color_table(BMPLoadingContext& context)
}
}
Streamer streamer(context.file_bytes + bmp_header_size + context.dib_size(), size_of_color_table);
InputStreamer streamer(context.file_bytes + bmp_header_size + context.dib_size(), size_of_color_table);
for (u32 i = 0; !streamer.at_end() && i < max_colors; ++i) {
if (bytes_per_color == 4) {
if (!streamer.has_u32())
@ -922,7 +922,7 @@ static bool uncompress_bmp_rle_data(BMPLoadingContext& context, ByteBuffer& buff
return false;
}
Streamer streamer(context.file_bytes + context.data_offset, context.file_size - context.data_offset);
InputStreamer streamer(context.file_bytes + context.data_offset, context.file_size - context.data_offset);
auto compression = context.dib.info.compression;
@ -1201,7 +1201,7 @@ static bool decode_bmp_pixel_data(BMPLoadingContext& context)
bytes = rle_buffer.bytes();
}
Streamer streamer(bytes.data(), bytes.size());
InputStreamer streamer(bytes.data(), bytes.size());
auto process_row = [&](u32 row) -> bool {
u32 space_remaining_before_consuming_row = streamer.remaining();

View File

@ -16,9 +16,9 @@ constexpr int bytes_per_pixel = 3;
#define IMAGE_INFORMATION_SIZE 40
#define PIXEL_DATA_OFFSET FILE_HEADER_SIZE + IMAGE_INFORMATION_SIZE
class Streamer {
class OutputStreamer {
public:
Streamer(u8* data)
OutputStreamer(u8* data)
: m_data(data)
{
}
@ -88,7 +88,7 @@ ByteBuffer BMPWriter::dump(const RefPtr<Bitmap> bitmap)
pixel_data = compress_pixel_data(pixel_data, m_compression);
int file_size = PIXEL_DATA_OFFSET + pixel_data.size();
Streamer streamer(buffer.data());
OutputStreamer streamer(buffer.data());
streamer.write_u8('B');
streamer.write_u8('M');
streamer.write_u32(file_size);

View File

@ -23,7 +23,7 @@ namespace Gfx {
static const int INTERLACE_ROW_STRIDES[] = { 8, 8, 4, 2 };
static const int INTERLACE_ROW_OFFSETS[] = { 0, 4, 2, 1 };
struct ImageDescriptor {
struct GIFImageDescriptor {
u16 x { 0 };
u16 y { 0 };
u16 width { 0 };
@ -77,7 +77,7 @@ struct GIFLoadingContext {
size_t data_size { 0 };
LogicalScreen logical_screen {};
u8 background_color_index { 0 };
NonnullOwnPtrVector<ImageDescriptor> images {};
NonnullOwnPtrVector<GIFImageDescriptor> images {};
size_t loops { 1 };
RefPtr<Gfx::Bitmap> frame_buffer;
size_t current_frame { 0 };
@ -312,26 +312,26 @@ static bool decode_frame(GIFLoadingContext& context, size_t frame_index)
for (size_t i = start_frame; i <= frame_index; ++i) {
auto& image = context.images.at(i);
const auto previous_image_disposal_method = i > 0 ? context.images.at(i - 1).disposal_method : ImageDescriptor::DisposalMethod::None;
const auto previous_image_disposal_method = i > 0 ? context.images.at(i - 1).disposal_method : GIFImageDescriptor::DisposalMethod::None;
if (i == 0) {
context.frame_buffer->fill(Color::Transparent);
} else if (i > 0 && image.disposal_method == ImageDescriptor::DisposalMethod::RestorePrevious
&& previous_image_disposal_method != ImageDescriptor::DisposalMethod::RestorePrevious) {
} else if (i > 0 && image.disposal_method == GIFImageDescriptor::DisposalMethod::RestorePrevious
&& previous_image_disposal_method != GIFImageDescriptor::DisposalMethod::RestorePrevious) {
// This marks the start of a run of frames that once disposed should be restored to the
// previous underlying image contents. Therefore we make a copy of the current frame
// buffer so that it can be restored later.
copy_frame_buffer(*context.prev_frame_buffer, *context.frame_buffer);
}
if (previous_image_disposal_method == ImageDescriptor::DisposalMethod::RestoreBackground) {
if (previous_image_disposal_method == GIFImageDescriptor::DisposalMethod::RestoreBackground) {
// Note: RestoreBackground could be interpreted either as restoring the underlying
// background of the entire image (e.g. container element's background-color), or the
// background color of the GIF itself. It appears that all major browsers and most other
// GIF decoders adhere to the former interpretation, therefore we will do the same by
// clearing the entire frame buffer to transparent.
clear_rect(*context.frame_buffer, context.images.at(i - 1).rect(), Color::Transparent);
} else if (i > 0 && previous_image_disposal_method == ImageDescriptor::DisposalMethod::RestorePrevious) {
} else if (i > 0 && previous_image_disposal_method == GIFImageDescriptor::DisposalMethod::RestorePrevious) {
// Previous frame indicated that once disposed, it should be restored to *its* previous
// underlying image contents, therefore we restore the saved previous frame buffer.
copy_frame_buffer(*context.frame_buffer, *context.prev_frame_buffer);
@ -460,7 +460,7 @@ static bool load_gif_frame_descriptors(GIFLoadingContext& context)
if (stream.handle_any_error())
return false;
NonnullOwnPtr<ImageDescriptor> current_image = make<ImageDescriptor>();
NonnullOwnPtr<GIFImageDescriptor> current_image = make<GIFImageDescriptor>();
for (;;) {
u8 sentinel = 0;
stream >> sentinel;
@ -503,7 +503,7 @@ static bool load_gif_frame_descriptors(GIFLoadingContext& context)
}
u8 disposal_method = (sub_block[0] & 0x1C) >> 2;
current_image->disposal_method = (ImageDescriptor::DisposalMethod)disposal_method;
current_image->disposal_method = (GIFImageDescriptor::DisposalMethod)disposal_method;
u8 user_input = (sub_block[0] & 0x2) >> 1;
current_image->user_input = user_input == 1;
@ -600,7 +600,7 @@ static bool load_gif_frame_descriptors(GIFLoadingContext& context)
}
}
current_image = make<ImageDescriptor>();
current_image = make<GIFImageDescriptor>();
continue;
}

View File

@ -71,7 +71,7 @@ struct [[gnu::packed]] BMP_ARGB {
};
static_assert(sizeof(BMP_ARGB) == 4);
struct ImageDescriptor {
struct ICOImageDescriptor {
u16 width;
u16 height;
size_t offset;
@ -89,7 +89,7 @@ struct ICOLoadingContext {
State state { NotDecoded };
const u8* data { nullptr };
size_t data_size { 0 };
Vector<ImageDescriptor> images;
Vector<ICOImageDescriptor> images;
size_t largest_index;
};
@ -126,14 +126,14 @@ static Optional<size_t> decode_ico_header(InputMemoryStream& stream)
return { header.image_count };
}
static Optional<ImageDescriptor> decode_ico_direntry(InputMemoryStream& stream)
static Optional<ICOImageDescriptor> decode_ico_direntry(InputMemoryStream& stream)
{
ICONDIRENTRY entry;
stream >> Bytes { &entry, sizeof(entry) };
if (stream.handle_any_error())
return {};
ImageDescriptor desc = { entry.width, entry.height, entry.offset, entry.size, nullptr };
ICOImageDescriptor desc = { entry.width, entry.height, entry.offset, entry.size, nullptr };
if (desc.width == 0)
desc.width = 256;
if (desc.height == 0)
@ -192,7 +192,7 @@ static bool load_ico_directory(ICOLoadingContext& context)
return true;
}
static bool load_ico_bmp(ICOLoadingContext& context, ImageDescriptor& desc)
static bool load_ico_bmp(ICOLoadingContext& context, ICOImageDescriptor& desc)
{
BITMAPINFOHEADER info;
if (desc.size < sizeof(info))
@ -293,7 +293,7 @@ static bool load_ico_bitmap(ICOLoadingContext& context, Optional<size_t> index)
return false;
}
ImageDescriptor& desc = context.images[real_index];
ICOImageDescriptor& desc = context.images[real_index];
PNGImageDecoderPlugin png_decoder(context.data + desc.offset, desc.size);
if (png_decoder.sniff()) {