From c99506da7deb3940aea20a368a27b3aa9b704219 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Sat, 23 Mar 2024 10:25:28 -0400 Subject: [PATCH] LibGfx/JBIG2: Initialize POD members And use Array<> instead of C-style arrays. --- .../LibGfx/ImageFormats/JBIG2Loader.cpp | 38 +++++++++---------- .../LibGfx/ImageFormats/JBIG2Loader.h | 14 +++---- 2 files changed, 26 insertions(+), 26 deletions(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/JBIG2Loader.cpp b/Userland/Libraries/LibGfx/ImageFormats/JBIG2Loader.cpp index 5f398a061f4..3afbb887f46 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/JBIG2Loader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/JBIG2Loader.cpp @@ -259,13 +259,13 @@ enum class Organization { }; struct SegmentHeader { - u32 segment_number; - SegmentType type; + u32 segment_number { 0 }; + SegmentType type { SegmentType::Extension }; Vector referred_to_segment_numbers; // 7.2.6 Segment page association // "The first page must be numbered "1". This field may contain a value of zero; this value indicates that this segment is not associated with any page." - u32 page_association; + u32 page_association { 0 }; Optional data_length; }; @@ -289,9 +289,9 @@ private: BitBuffer(ByteBuffer, size_t width, size_t height, size_t pitch); ByteBuffer m_bits; - size_t m_width; - size_t m_height; - size_t m_pitch; + size_t m_width { 0 }; + size_t m_height { 0 }; + size_t m_pitch { 0 }; }; ErrorOr> BitBuffer::create(size_t width, size_t height) @@ -369,7 +369,7 @@ enum class CombinationOperator { struct Page { IntSize size; - CombinationOperator default_combination_operator; + CombinationOperator default_combination_operator { CombinationOperator::Or }; OwnPtr bits; }; @@ -695,18 +695,19 @@ static ErrorOr warn_about_multiple_pages(JBIG2LoadingContext& context) // 6.2.2 Input parameters struct GenericRegionDecodingInputParameters { - bool is_modified_modified_read; // "MMR" in spec. - u32 region_width; // "GBW" in spec. - u32 region_height; // "GBH" in spec. - u8 gb_template; - bool is_typical_prediction_used; // "TPGDON" in spec. - bool is_extended_reference_template_used; // "EXTTEMPLATE" in spec. - Optional> skip_pattern; // "USESKIP", "SKIP" in spec. + bool is_modified_modified_read { false }; // "MMR" in spec. + u32 region_width { 0 }; // "GBW" in spec. + u32 region_height { 0 }; // "GBH" in spec. + u8 gb_template { 0 }; + bool is_typical_prediction_used { false }; // "TPGDON" in spec. + bool is_extended_reference_template_used { false }; // "EXTTEMPLATE" in spec. + Optional> skip_pattern; // "USESKIP", "SKIP" in spec. struct AdaptiveTemplatePixel { - i8 x, y; + i8 x { 0 }; + i8 y { 0 }; }; - AdaptiveTemplatePixel adaptive_template_pixels[12]; // "GBATX" / "GBATY" in spec. + Array adaptive_template_pixels; // "GBATX" / "GBATY" in spec. // FIXME: GBCOLS, GBCOMBOP, COLEXTFLAG }; @@ -876,7 +877,7 @@ static ErrorOr decode_immediate_generic_region(JBIG2LoadingContext& contex data = data.slice(sizeof(flags)); // 7.4.6.3 Generic region segment AT flags - GenericRegionDecodingInputParameters::AdaptiveTemplatePixel adaptive_template_pixels[12] = {}; + Array adaptive_template_pixels {}; if (!uses_mmr) { dbgln_if(JBIG2_DEBUG, "Non-MMR generic region, GBTEMPLATE={} TPGDON={} EXTTEMPLATE={}", arithmetic_coding_template, typical_prediction_generic_decoding_on, uses_extended_reference_template); @@ -911,8 +912,7 @@ static ErrorOr decode_immediate_generic_region(JBIG2LoadingContext& contex inputs.is_typical_prediction_used = typical_prediction_generic_decoding_on; inputs.is_extended_reference_template_used = uses_extended_reference_template; inputs.skip_pattern = OptionalNone {}; - static_assert(sizeof(inputs.adaptive_template_pixels) == sizeof(adaptive_template_pixels)); - memcpy(inputs.adaptive_template_pixels, adaptive_template_pixels, sizeof(adaptive_template_pixels)); + inputs.adaptive_template_pixels = adaptive_template_pixels; auto result = TRY(generic_region_decoding_procedure(inputs, data)); // 8.2 Page image composition step 5) diff --git a/Userland/Libraries/LibGfx/ImageFormats/JBIG2Loader.h b/Userland/Libraries/LibGfx/ImageFormats/JBIG2Loader.h index af538923d57..9e77f662f9c 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/JBIG2Loader.h +++ b/Userland/Libraries/LibGfx/ImageFormats/JBIG2Loader.h @@ -22,8 +22,8 @@ namespace JBIG2 { class ArithmeticDecoder { public: struct Context { - u8 I; // Index I stored for context CX (E.2.4) - u8 is_mps; // "More probable symbol" (E.1.1). 0 or 1. + u8 I { 0 }; // Index I stored for context CX (E.2.4) + u8 is_mps { 0 }; // "More probable symbol" (E.1.1). 0 or 1. }; static ErrorOr initialize(ReadonlyBytes data); @@ -55,15 +55,15 @@ private: void BYTEIN(); u8 B(size_t offset = 0) const; // Byte pointed to by BP. - size_t BP; // Pointer into compressed data. + size_t BP { 0 }; // Pointer into compressed data. // E.3.1 Decoder code register conventions - u32 C; // Consists of u16 C_high, C_low. - u16 A; // Current value of the fraction. Fixed precision; 0x8000 is equivalent to 0.75. + u32 C { 0 }; // Consists of u16 C_high, C_low. + u16 A { 0 }; // Current value of the fraction. Fixed precision; 0x8000 is equivalent to 0.75. - u8 CT; // Count of the number of bits in C. + u8 CT { 0 }; // Count of the number of bits in C. - Context* CX; + Context* CX { nullptr }; static u8& I(Context* cx) { return cx->I; } static u8& MPS(Context* cx) { return cx->is_mps; } static u16 Qe(u16);