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

LibGfx: use Gfx::Color instead of local struct for GIF colour map

This commit is contained in:
Peter Nelson 2020-08-30 08:47:56 +01:00 committed by Andreas Kling
parent c8eccc00b1
commit b742d593dd

View file

@ -36,12 +36,6 @@
namespace Gfx { namespace Gfx {
struct RGB {
u8 r;
u8 g;
u8 b;
};
// Row strides and offsets for each interlace pass. // Row strides and offsets for each interlace pass.
static const int INTERLACE_ROW_STRIDES[] = { 8, 8, 4, 2 }; static const int INTERLACE_ROW_STRIDES[] = { 8, 8, 4, 2 };
static const int INTERLACE_ROW_OFFSETS[] = { 0, 4, 2, 1 }; static const int INTERLACE_ROW_OFFSETS[] = { 0, 4, 2, 1 };
@ -53,7 +47,7 @@ struct ImageDescriptor {
u16 height { 0 }; u16 height { 0 };
bool use_global_color_map { true }; bool use_global_color_map { true };
bool interlaced { false }; bool interlaced { false };
RGB color_map[256]; Color color_map[256];
u8 lzw_min_code_size { 0 }; u8 lzw_min_code_size { 0 };
Vector<u8> lzw_encoded_bytes; Vector<u8> lzw_encoded_bytes;
@ -74,7 +68,7 @@ struct ImageDescriptor {
struct LogicalScreen { struct LogicalScreen {
u16 width; u16 width;
u16 height; u16 height;
RGB color_map[256]; Color color_map[256];
}; };
struct GIFLoadingContext { struct GIFLoadingContext {
@ -296,8 +290,7 @@ static bool decode_frame(GIFLoadingContext& context, size_t frame_index)
auto& color_map = image.use_global_color_map ? context.logical_screen.color_map : image.color_map; auto& color_map = image.use_global_color_map ? context.logical_screen.color_map : image.color_map;
auto background_rgb = color_map[context.background_color_index]; auto background_color = color_map[context.background_color_index];
Color background_color = Color(background_rgb.r, background_rgb.g, background_rgb.b);
if (i == 0) { if (i == 0) {
context.frame_buffer->fill(background_color); context.frame_buffer->fill(background_color);
@ -332,13 +325,11 @@ static bool decode_frame(GIFLoadingContext& context, size_t frame_index)
auto colors = decoder.get_output(); auto colors = decoder.get_output();
for (const auto& color : colors) { for (const auto& color : colors) {
auto rgb = color_map[color]; auto c = color_map[color];
int x = pixel_index % image.width + image.x; int x = pixel_index % image.width + image.x;
int y = row + image.y; int y = row + image.y;
Color c = Color(rgb.r, rgb.g, rgb.b);
if (image.transparent && color == image.transparency_index) { if (image.transparent && color == image.transparency_index) {
c.set_alpha(0); c.set_alpha(0);
} }
@ -423,17 +414,17 @@ static bool load_gif_frame_descriptors(GIFLoadingContext& context)
printf("color_map_entry_count: %d\n", color_map_entry_count); printf("color_map_entry_count: %d\n", color_map_entry_count);
for (int i = 0; i < color_map_entry_count; ++i) { for (int i = 0; i < color_map_entry_count; ++i) {
stream >> context.logical_screen.color_map[i].r; u8 r, g, b;
stream >> context.logical_screen.color_map[i].g; stream >> r >> g >> b;
stream >> context.logical_screen.color_map[i].b; context.logical_screen.color_map[i] = { r, g, b };
} }
if (stream.handle_read_failure()) if (stream.handle_read_failure())
return false; return false;
for (int i = 0; i < color_map_entry_count; ++i) { for (int i = 0; i < color_map_entry_count; ++i) {
auto& rgb = context.logical_screen.color_map[i]; auto& color = context.logical_screen.color_map[i];
printf("[%02x]: %s\n", i, Color(rgb.r, rgb.g, rgb.b).to_string().characters()); printf("[%02x]: %s\n", i, color.to_string().characters());
} }
NonnullOwnPtr<ImageDescriptor> current_image = make<ImageDescriptor>(); NonnullOwnPtr<ImageDescriptor> current_image = make<ImageDescriptor>();
@ -531,9 +522,9 @@ static bool load_gif_frame_descriptors(GIFLoadingContext& context)
size_t local_color_table_size = pow(2, (packed_fields & 7) + 1); size_t local_color_table_size = pow(2, (packed_fields & 7) + 1);
for (size_t i = 0; i < local_color_table_size; ++i) { for (size_t i = 0; i < local_color_table_size; ++i) {
stream >> image.color_map[i].r; u8 r, g, b;
stream >> image.color_map[i].g; stream >> r >> g >> b;
stream >> image.color_map[i].b; image.color_map[i] = { r, g, b };
} }
} }