Skip to content

Possible edge case in decoder when very first OP is QOI_OP_RUN #258

@phoboslab

Description

@phoboslab

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:

Each pixel that is seen by the encoder and decoder is put into this array at the position formed by a hash function of the color value.

... 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions