mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:37:36 +00:00
LibGfx: Skip useless iterations during PNG::FilterType::Sub unfiltering
This commit is contained in:
parent
b19f3b5106
commit
b123309b0d
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) {
|
switch (filter) {
|
||||||
case PNG::FilterType::Sub:
|
case PNG::FilterType::Sub:
|
||||||
for (size_t i = 0; i < scanline_data.size(); ++i) {
|
// This loop starts at bytes_per_complete_pixel because all bytes before that are
|
||||||
u8 left = (i < bytes_per_complete_pixel) ? 0 : scanline_data[i - bytes_per_complete_pixel];
|
// 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;
|
scanline_data[i] += left;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue