-
Notifications
You must be signed in to change notification settings - Fork 329
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible edge case in decoder when very first OP is QOI_OP_RUN #258
Comments
If the encoded data starts with |
Not sure I understand the question correctly. Per the spec, the 64 elements of the index are zero-initialized. I.e. all colors in the index are initially transparent black. If the very first decode is |
|
Another solution is to look-ahead |
Yes, this is somewhat unfortunate and maybe could have been solved with some more thought about the initial values for previous pixel and the index... For what it's worth, this implementation here only sets the index at the start of a run; it doesn't calculate the hash when emitting pixels within a run. I assume the performance impact is negligible. |
Would it work if you always inserted the initial opaque black into the array and not just if the first chunk is a run? |
That would break |
There is |
As recently pointed out by @andrews05, there is an edge in QOI files that could be handled differently by different decoders.
This edge case can produce a transparent background when fully opaque black was intended. This may happen, when decoding to RGBA (4 channels) and the very first OP of a QOI file is a
QOI_OP_RUN
, that repeats the initial opaque black pixel.Some decoders omit putting the initial black pixel into the index in this case. Later in the image the decoder may refer to this to the index position where the opaque black should have been stored, but that instead is empty – i.e. just the initial transparent black that comes from the zero initialized index.
As the spec points out, admittedly not very clearly:
... this must include the initial opaque black when the very first OP is a
QOI_OP_RUN
.I have updated the qoi_test_images.zip to include an image where this edge-case is present, aptly named
edgecase.qoi
.As further pointed out by @andrews05, the reference encoder in this repository does not produce QOI images that have this edge-case (it never starts a QOI file with a
QOI_OP_RUN
), but other encoders might.After going through the decoders listed in this readme, I have identified a few implementations where this edge case is not handled according to the spec – again, mea culpa, it's not the clearest wording. I will notify those implementations now.
Thanks again to @andrews05 for pointing it out.
The text was updated successfully, but these errors were encountered: