LibGfx: Skip useless iterations during PNG::FilterType::Sub unfiltering
This commit is contained in:
parent
b19f3b5106
commit
b123309b0d
Notes:
sideshowbarker
2024-07-17 08:09:19 +09:00
Author: https://github.com/squeek502 Commit: https://github.com/SerenityOS/serenity/commit/b123309b0d Pull-request: https://github.com/SerenityOS/serenity/pull/14910 Reviewed-by: https://github.com/linusg ✅
1 changed files with 7 additions and 2 deletions
|
@ -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;
|
||||
|
|
Loading…
Add table
Reference in a new issue