From 24aa302e88c96d8c690d83308a348b72e6499132 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Thu, 1 Jun 2023 08:10:30 -0400 Subject: [PATCH] WebP/Lossy: Reduce size of MacroblockMetadata from 80 to 20 bytes For a 1024x1024 image, saves about a quarter MB of memory use while decoding (compared to the decompressed image data itself needing 4 MiB). Not a huge win, but also very easy to do, so might as well. No behavior change, no measurable performance impact. --- Userland/Libraries/LibGfx/ImageFormats/WebPLoaderLossy.cpp | 2 +- .../Libraries/LibGfx/ImageFormats/WebPLoaderLossyTables.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/WebPLoaderLossy.cpp b/Userland/Libraries/LibGfx/ImageFormats/WebPLoaderLossy.cpp index 55583449ad..0714f94e57 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/WebPLoaderLossy.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/WebPLoaderLossy.cpp @@ -405,7 +405,7 @@ ErrorOr tree_decode(BooleanDecoder& decoder, ReadonlySpan tree, R struct MacroblockMetadata { // https://datatracker.ietf.org/doc/html/rfc6386#section-10 "Segment-Based Feature Adjustments" // Read only if `update_mb_segmentation_map` is set. - int segment_id { 0 }; // 0, 1, 2, or 3. Fits in two bits. + u8 segment_id { 0 }; // 0, 1, 2, or 3. Fits in two bits. // https://datatracker.ietf.org/doc/html/rfc6386#section-11.1 "mb_skip_coeff" bool skip_coefficients { false }; diff --git a/Userland/Libraries/LibGfx/ImageFormats/WebPLoaderLossyTables.h b/Userland/Libraries/LibGfx/ImageFormats/WebPLoaderLossyTables.h index c396ad84aa..75e105599e 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/WebPLoaderLossyTables.h +++ b/Userland/Libraries/LibGfx/ImageFormats/WebPLoaderLossyTables.h @@ -22,7 +22,7 @@ const TreeIndex MACROBLOCK_SEGMENT_TREE[2 * (4 - 1)] = { // https://datatracker.ietf.org/doc/html/rfc6386#section-8.2 "Tree Coding Example" // Repeated in https://datatracker.ietf.org/doc/html/rfc6386#section-11.2 "Luma Modes" -enum IntraMacroblockMode { +enum IntraMacroblockMode : u8 { DC_PRED, /* predict DC using row above and column to the left */ V_PRED, /* predict rows using row above */ H_PRED, /* predict columns using column to the left */ @@ -45,7 +45,7 @@ static TreeIndex constexpr KEYFRAME_YMODE_TREE[2 * (num_ymodes - 1)] = { static Prob constexpr KEYFRAME_YMODE_PROBABILITIES[num_ymodes - 1] = { 145, 156, 163, 128 }; // https://datatracker.ietf.org/doc/html/rfc6386#section-11.2 "Luma Modes" -enum IntraBlockMode { +enum IntraBlockMode : u8 { B_DC_PRED, /* predict DC using row above and column to the left */ B_TM_PRED, /* propagate second differences a la