mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:27:46 +00:00
LibGfx: Keep alpha value of previous pixel for QOI_OP_RGB chunk
I accidentally skipped this part of the spec in the QOI decoder: > The alpha value remains unchanged from the previous pixel. This led to incorrect rendering of some images with transparency, visible in form of a horizontal line of non-transparent pixels (that shouldn't exist), e.g. for the following chunk sequence: - QOI_OP_RGBA with alpha = 0 - QOI_OP_RGB - QOI_OP_RUN The QOI_OP_RGB should 'inherit' the alpha value of the previous QOI_OP_RGBA chunk, instead of always setting it to 255. I'm unsure why the encoder added the QOI_OP_RGB chunk to the specific image where the bug was noticed in the first place - they effectively both had fully transparent color values.
This commit is contained in:
parent
b6d921f682
commit
e4bba2fab9
1 changed files with 5 additions and 3 deletions
|
@ -34,14 +34,16 @@ static ErrorOr<QOIHeader> decode_qoi_header(InputMemoryStream& stream)
|
|||
return header;
|
||||
}
|
||||
|
||||
static ErrorOr<Color> decode_qoi_op_rgb(InputMemoryStream& stream)
|
||||
static ErrorOr<Color> decode_qoi_op_rgb(InputMemoryStream& stream, Color pixel)
|
||||
{
|
||||
u8 bytes[4];
|
||||
stream >> Bytes { &bytes, array_size(bytes) };
|
||||
if (stream.handle_any_error())
|
||||
return Error::from_string_literal("Invalid QOI image: end of stream while reading QOI_OP_RGB chunk"sv);
|
||||
VERIFY(bytes[0] == QOI_OP_RGB);
|
||||
return Color { bytes[1], bytes[2], bytes[3] };
|
||||
|
||||
// The alpha value remains unchanged from the previous pixel.
|
||||
return Color { bytes[1], bytes[2], bytes[3], pixel.alpha() };
|
||||
}
|
||||
|
||||
static ErrorOr<Color> decode_qoi_op_rgba(InputMemoryStream& stream)
|
||||
|
@ -163,7 +165,7 @@ static ErrorOr<NonnullRefPtr<Bitmap>> decode_qoi_image(InputMemoryStream& stream
|
|||
if (stream.handle_any_error())
|
||||
return Error::from_string_literal("Invalid QOI image: end of stream while reading chunk tag"sv);
|
||||
if (tag == QOI_OP_RGB)
|
||||
pixel = TRY(decode_qoi_op_rgb(stream));
|
||||
pixel = TRY(decode_qoi_op_rgb(stream, pixel));
|
||||
else if (tag == QOI_OP_RGBA)
|
||||
pixel = TRY(decode_qoi_op_rgba(stream));
|
||||
else if ((tag & QOI_MASK_2) == QOI_OP_INDEX)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue