From ea8384219f25d323d8ceb1a1175a06e0ba190bc8 Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Wed, 26 Jul 2023 18:10:12 -0400 Subject: [PATCH] LibGfx/JPEGXL: Perform size computation in a floating point type The computation was copied from the spec, but I forgot that they mention that every "/" should be performed without truncation or rounding. Let's use `double`s instead of integers. --- .../Libraries/LibGfx/ImageFormats/JPEGXLLoader.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/JPEGXLLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/JPEGXLLoader.cpp index 71b7b1eb84..55075bd06f 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/JPEGXLLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/JPEGXLLoader.cpp @@ -1561,8 +1561,8 @@ static ErrorOr read_frame(LittleEndianInputBitStream& stream, } if (frame.frame_header.upsampling > 1) { - frame.width = ceil(frame.width / frame.frame_header.upsampling); - frame.height = ceil(frame.height / frame.frame_header.upsampling); + frame.width = ceil(static_cast(frame.width) / frame.frame_header.upsampling); + frame.height = ceil(static_cast(frame.height) / frame.frame_header.upsampling); } if (frame.frame_header.lf_level > 0) @@ -1571,8 +1571,10 @@ static ErrorOr read_frame(LittleEndianInputBitStream& stream, // F.2 - FrameHeader auto const group_dim = 128 << frame.frame_header.group_size_shift; - frame.num_groups = ceil(frame.width / group_dim) * ceil(frame.height / group_dim); - frame.num_lf_groups = ceil(frame.width / (group_dim * 8)) * ceil(frame.height / (group_dim * 8)); + auto const frame_width = static_cast(frame.width); + auto const frame_height = static_cast(frame.height); + frame.num_groups = ceil(frame_width / group_dim) * ceil(frame_height / group_dim); + frame.num_lf_groups = ceil(frame_width / (group_dim * 8)) * ceil(frame_height / (group_dim * 8)); frame.toc = TRY(read_toc(stream, frame.frame_header, frame.num_groups, frame.num_lf_groups));