mirror of
https://github.com/RGBCube/serenity
synced 2025-05-25 18:05:07 +00:00
LibGfx: Fix BMP mask detection off-by-one
Also, since the loops can be replaced by a little bit-twiddling, call ctz() directly. This might be a bit faster, or it might not.
This commit is contained in:
parent
6be9b6349d
commit
36daeee34f
1 changed files with 9 additions and 23 deletions
|
@ -343,7 +343,7 @@ static void populate_dib_mask_info(BMPLoadingContext& context)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Mask shift is the number of right shifts needed to align the MSb of the
|
// Mask shift is the number of right shifts needed to align the MSb of the
|
||||||
// mask to the MSb of the LSB.
|
// mask to the MSb of the LSB. Note that this can be a negative number.
|
||||||
// Mask size is the number of set bits in the mask. This is required for
|
// Mask size is the number of set bits in the mask. This is required for
|
||||||
// color scaling (for example, ensuring that a 4-bit color value spans the
|
// color scaling (for example, ensuring that a 4-bit color value spans the
|
||||||
// entire 256 value color spectrum.
|
// entire 256 value color spectrum.
|
||||||
|
@ -361,29 +361,15 @@ static void populate_dib_mask_info(BMPLoadingContext& context)
|
||||||
|
|
||||||
for (size_t i = 0; i < masks.size(); ++i) {
|
for (size_t i = 0; i < masks.size(); ++i) {
|
||||||
u32 mask = masks[i];
|
u32 mask = masks[i];
|
||||||
u8 shift = 0;
|
if (!mask) {
|
||||||
u8 size = 0;
|
|
||||||
bool found_set_bit = false;
|
|
||||||
|
|
||||||
while (shift <= 32) {
|
|
||||||
u8 bit = (mask >> shift) & 0x1;
|
|
||||||
if (found_set_bit)
|
|
||||||
size++;
|
|
||||||
if (!found_set_bit && bit) {
|
|
||||||
found_set_bit = true;
|
|
||||||
} else if (found_set_bit && !bit) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
shift++;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (shift > 32) {
|
|
||||||
mask_shifts.append(0);
|
mask_shifts.append(0);
|
||||||
mask_sizes.append(0);
|
mask_sizes.append(0);
|
||||||
} else {
|
continue;
|
||||||
mask_shifts.append(shift - 8);
|
|
||||||
mask_sizes.append(size);
|
|
||||||
}
|
}
|
||||||
|
int trailing_zeros = count_trailing_zeroes_32(mask);
|
||||||
|
int size = count_trailing_zeroes_32(~(mask >> trailing_zeros));
|
||||||
|
mask_shifts.append(trailing_zeros - 8);
|
||||||
|
mask_sizes.append(size);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue