Spec clarifications
Hi, I think this is a quite okay image format and I've been working on a Swift implementation. I have a couple of questions regarding edges cases:
Truncated data In the reference decoder, if there isn't enough data to cover all the pixels it will continue to fill the remainder of the image with the current pixel. So a file with no pixel data, just the header + padding, will be entirely black. The spec doesn't discuss this though, so my question is:
- Should I match the behaviour of the reference decoder here?
- Is it safe for the encoder to deliberately end early when the remainder of the image is the same? I ask because the format is relatively poor for long runs and I can save a significant amount in my use case just by ending early. (Ideally, I would replace the DIFF op code with an extended 14-bit run )
Initial colour and the index
The reference decoder stores pixel results from all op-codes in the index but the encoder does not store pixels for either runs or indexes into the index. For index op-codes this is irrelevant but there's a minor edge case for runs:
If the image starts with black then it will encode a run, as the initial prev pixel is black. If the next pixel is completely different it may then do an RGB/RGBA. If we then have more black, we find the initial black never got put into the index so we have to do another RGB/RGBA.
The spec doesn't explicitly cover this but I can see a couple of possible improvements in the code that could be made here, depending on what's considered valid:
- The encoder could store runs into the index (or just the initial black) for a very minor size optimisation in this edge case. The current decoder will handle this correctly.
- Alternatively, the decoder could assume the initial black never gets indexed and thus safely omit storing both index and run op-codes in the index for a performance boost.
- Both of the above, with the decoder starting by storing the initial black in the index to cover the edge case.
In any case, some clarification in the spec about this would be helpful
Source: phoboslab/qoi