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.
This commit is contained in:
Nico Weber 2024-05-08 08:57:53 -04:00 committed by Tim Flynn
commit 58cbecbe0c
Notes: sideshowbarker 2024-07-17 07:38:17 +09:00
3 changed files with 53 additions and 74 deletions

View file

@ -13,6 +13,7 @@
#include <LibGfx/ImageFormats/WebPLoader.h>
#include <LibGfx/ImageFormats/WebPLoaderLossless.h>
#include <LibGfx/ImageFormats/WebPLoaderLossy.h>
#include <LibGfx/ImageFormats/WebPShared.h>
#include <LibGfx/Painter.h>
#include <LibRIFF/ChunkID.h>
#include <LibRIFF/RIFF.h>
@ -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."

View file

@ -0,0 +1,51 @@
/*
* Copyright (c) 2024, Nico Weber <thakis@chromium.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Span.h>
#include <AK/Types.h>
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;
};
}

View file

@ -11,6 +11,7 @@
#include <AK/Debug.h>
#include <LibCompress/DeflateTables.h>
#include <LibGfx/Bitmap.h>
#include <LibGfx/ImageFormats/WebPShared.h>
#include <LibGfx/ImageFormats/WebPWriter.h>
#include <LibRIFF/RIFF.h>
@ -189,16 +190,6 @@ static ErrorOr<void> 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<void> 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<void> write_ANMF_chunk(Stream& stream, ANMFChunk const& chunk)
{
if (chunk.frame_width > (1 << 24) || chunk.frame_height > (1 << 24))
@ -510,11 +479,6 @@ ErrorOr<void> WebPAnimationWriter::set_alpha_bit_in_header()
return {};
}
struct ANIMChunk {
u32 background_color { 0 };
u16 loop_count { 0 };
};
static ErrorOr<void> write_ANIM_chunk(Stream& stream, ANIMChunk const& chunk)
{
TRY(write_chunk_header(stream, "ANIM"sv, 6)); // Size of the ANIM chunk.