From 0d3b62cbb71b9a551307fff79884887adc6f7c20 Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Fri, 21 Apr 2023 20:28:18 -0400 Subject: [PATCH] LibGfx/JPEG: Use more explicit types and add a bunch of `const` --- .../LibGfx/ImageFormats/JPEGLoader.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp index 60a2e1f50f..f7af948a35 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp @@ -1076,27 +1076,25 @@ static ErrorOr read_start_of_frame(Stream& stream, JPEGLoadingContext& con static ErrorOr read_quantization_table(Stream& stream, JPEGLoadingContext& context) { - i32 bytes_to_read = TRY(stream.read_value>()) - 2; + u16 bytes_to_read = TRY(stream.read_value>()) - 2; while (bytes_to_read > 0) { - u8 info_byte = TRY(stream.read_value()); - u8 element_unit_hint = info_byte >> 4; + u8 const info_byte = TRY(stream.read_value()); + u8 const element_unit_hint = info_byte >> 4; if (element_unit_hint > 1) { dbgln_if(JPEG_DEBUG, "Unsupported unit hint in quantization table: {}!", element_unit_hint); return Error::from_string_literal("Unsupported unit hint in quantization table"); } - u8 table_id = info_byte & 0x0F; + u8 const table_id = info_byte & 0x0F; if (table_id > 1) { dbgln_if(JPEG_DEBUG, "Unsupported quantization table id: {}!", table_id); return Error::from_string_literal("Unsupported quantization table id"); } - u32* table = table_id == 0 ? context.luma_table : context.chroma_table; + u32* const table = table_id == 0 ? context.luma_table : context.chroma_table; for (int i = 0; i < 64; i++) { - if (element_unit_hint == 0) { - u8 tmp = TRY(stream.read_value()); - table[zigzag_map[i]] = tmp; - } else { + if (element_unit_hint == 0) + table[zigzag_map[i]] = TRY(stream.read_value()); + else table[zigzag_map[i]] = TRY(stream.read_value>()); - } } bytes_to_read -= 1 + (element_unit_hint == 0 ? 64 : 128);