diff options
author | Ryan Liptak <squeek502@hotmail.com> | 2022-08-18 02:29:36 -0700 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-08-18 11:12:59 +0100 |
commit | b123309b0ddedb29f4c9a8087443c1a755b014e8 (patch) | |
tree | be4905288f4c4c8c25c886c390e455bc646d50f5 /Userland/Libraries/LibGfx | |
parent | b19f3b51061e2d9bf86039eb1a5980346e2a8b26 (diff) | |
download | serenity-b123309b0ddedb29f4c9a8087443c1a755b014e8.zip |
LibGfx: Skip useless iterations during PNG::FilterType::Sub unfiltering
Diffstat (limited to 'Userland/Libraries/LibGfx')
-rw-r--r-- | Userland/Libraries/LibGfx/PNGLoader.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Userland/Libraries/LibGfx/PNGLoader.cpp b/Userland/Libraries/LibGfx/PNGLoader.cpp index 7f6c045e7d..e0c8d2be85 100644 --- a/Userland/Libraries/LibGfx/PNGLoader.cpp +++ b/Userland/Libraries/LibGfx/PNGLoader.cpp @@ -183,8 +183,13 @@ static void unfilter_scanline(PNG::FilterType filter, Bytes scanline_data, Reado switch (filter) { case PNG::FilterType::Sub: - for (size_t i = 0; i < scanline_data.size(); ++i) { - u8 left = (i < bytes_per_complete_pixel) ? 0 : scanline_data[i - bytes_per_complete_pixel]; + // This loop starts at bytes_per_complete_pixel because all bytes before that are + // guaranteed to have no valid byte at index (i - bytes_per_complete pixel). + // All such invalid byte indexes should be treated as 0, and adding 0 to the current + // byte would do nothing, so the first bytes_per_complete_pixel bytes can instead + // just be skipped. + for (size_t i = bytes_per_complete_pixel; i < scanline_data.size(); ++i) { + u8 left = scanline_data[i - bytes_per_complete_pixel]; scanline_data[i] += left; } break; |