From 58cbecbe0ca490b9047b2147a61e0c729f6647fd Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Wed, 8 May 2024 08:57:53 -0400 Subject: [PATCH] LibGfx/WebP: Move some code shared by loader and writer to WebPShared.h Has (no-op) the effect of adding a few missing default-initializers for the copy in WebPLoader.cpp. No behavior change. --- .../LibGfx/ImageFormats/WebPLoader.cpp | 38 +------------- .../LibGfx/ImageFormats/WebPShared.h | 51 +++++++++++++++++++ .../LibGfx/ImageFormats/WebPWriter.cpp | 38 +------------- 3 files changed, 53 insertions(+), 74 deletions(-) create mode 100644 Userland/Libraries/LibGfx/ImageFormats/WebPShared.h diff --git a/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp index e7b1eb1d1f2..4b7e85243ce 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/WebPLoader.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -24,43 +25,6 @@ namespace Gfx { namespace { -struct VP8XHeader { - bool has_icc; - bool has_alpha; - bool has_exif; - bool has_xmp; - bool has_animation; - u32 width; - u32 height; -}; - -struct ANIMChunk { - u32 background_color; - u16 loop_count; -}; - -struct ANMFChunk { - u32 frame_x; - u32 frame_y; - u32 frame_width; - u32 frame_height; - u32 frame_duration_in_milliseconds; - - enum class BlendingMethod { - UseAlphaBlending = 0, - DoNotBlend = 1, - }; - BlendingMethod blending_method; - - enum class DisposalMethod { - DoNotDispose = 0, - DisposeToBackgroundColor = 1, - }; - DisposalMethod disposal_method; - - ReadonlyBytes frame_data; -}; - // "For a still image, the image data consists of a single frame, which is made up of: // An optional alpha subchunk. // A bitstream subchunk." diff --git a/Userland/Libraries/LibGfx/ImageFormats/WebPShared.h b/Userland/Libraries/LibGfx/ImageFormats/WebPShared.h new file mode 100644 index 00000000000..a56d6b36ab1 --- /dev/null +++ b/Userland/Libraries/LibGfx/ImageFormats/WebPShared.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2024, Nico Weber + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +namespace Gfx { + +struct VP8XHeader { + bool has_icc { false }; + bool has_alpha { false }; + bool has_exif { false }; + bool has_xmp { false }; + bool has_animation { false }; + u32 width { 0 }; + u32 height { 0 }; +}; + +struct ANIMChunk { + u32 background_color { 0 }; + u16 loop_count { 0 }; +}; + +struct ANMFChunk { + u32 frame_x { 0 }; + u32 frame_y { 0 }; + u32 frame_width { 0 }; + u32 frame_height { 0 }; + u32 frame_duration_in_milliseconds { 0 }; + + enum class BlendingMethod { + UseAlphaBlending = 0, + DoNotBlend = 1, + }; + BlendingMethod blending_method { BlendingMethod::UseAlphaBlending }; + + enum class DisposalMethod { + DoNotDispose = 0, + DisposeToBackgroundColor = 1, + }; + DisposalMethod disposal_method { DisposalMethod::DoNotDispose }; + + ReadonlyBytes frame_data; +}; + +} diff --git a/Userland/Libraries/LibGfx/ImageFormats/WebPWriter.cpp b/Userland/Libraries/LibGfx/ImageFormats/WebPWriter.cpp index 9697c096337..ce46f652ef7 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/WebPWriter.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/WebPWriter.cpp @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -189,16 +190,6 @@ static ErrorOr write_VP8L_image_data(Stream& stream, Bitmap const& bitmap) return {}; } -struct VP8XHeader { - bool has_icc { false }; - bool has_alpha { false }; - bool has_exif { false }; - bool has_xmp { false }; - bool has_animation { false }; - u32 width { 0 }; - u32 height { 0 }; -}; - static u8 vp8x_flags_from_header(VP8XHeader const& header) { u8 flags = 0; @@ -362,28 +353,6 @@ static ErrorOr align_to_two(SeekableStream& stream) return {}; } -struct ANMFChunk { - u32 frame_x { 0 }; - u32 frame_y { 0 }; - u32 frame_width { 0 }; - u32 frame_height { 0 }; - u32 frame_duration_in_milliseconds { 0 }; - - enum class BlendingMethod { - UseAlphaBlending = 0, - DoNotBlend = 1, - }; - BlendingMethod blending_method { BlendingMethod::UseAlphaBlending }; - - enum class DisposalMethod { - DoNotDispose = 0, - DisposeToBackgroundColor = 1, - }; - DisposalMethod disposal_method { DisposalMethod::DoNotDispose }; - - ReadonlyBytes frame_data; -}; - static ErrorOr write_ANMF_chunk(Stream& stream, ANMFChunk const& chunk) { if (chunk.frame_width > (1 << 24) || chunk.frame_height > (1 << 24)) @@ -510,11 +479,6 @@ ErrorOr WebPAnimationWriter::set_alpha_bit_in_header() return {}; } -struct ANIMChunk { - u32 background_color { 0 }; - u16 loop_count { 0 }; -}; - static ErrorOr write_ANIM_chunk(Stream& stream, ANIMChunk const& chunk) { TRY(write_chunk_header(stream, "ANIM"sv, 6)); // Size of the ANIM chunk.