What error variant are encoders supposed to return when they don't support the given color type?
I'm working on integrating the new DDS de/encoder, so I have to handle the case where the encoder doesn't support the ExtendedColorType given by the user. I have to return an error, but which one?
My question is: what error variant am I supposed to return?
I tried looking at what other encoders are doing, but it's a colorful mix. There are 3 main categories:
avif,jpeg,tga,webp,farbfeld,gif, andtiffreturnImageError::UnsupportedwithUnsupportedErrorKind::Color.hdr,openexr, andqoireturnImageError::Encodingwith a simple string error (message).- And the weird ones...
bmpreturnsImageError::IoErrorwithio::ErrorKind::InvalidInput. (It even creates a newstd::io::Errorfor it...)pnmreturns eitherImageError::UnsupportedwithUnsupportedErrorKind::ColorORImageError::Parameter.pngreturns eitherImageError::UnsupportedwithUnsupportedErrorKind::ColorORImageError::Encodingwith its customBadPngRepresentation::ColorTypeerror.
(As for the formats not included above: ico uses the PNG encoder under the hood, and dds and pcx didn't have encoders.)
If I had to guess how this came to be, I'd say that ImageError::Unsupported with UnsupportedErrorKind::Color was the indented error, but then PNG came along with its BadPngRepresentation and that influenced the formats that came after it to use ImageError::Encoding. Oh, and BMP is just weird.
If ImageError::Unsupported with UnsupportedErrorKind::Color really is the intended error, I'm willing to make a PR that (1) documents this fact and (2) changes all encoders to use this error. Just let me know.
I think that UnsupportedErrorKind::Color is probably best. Though I've also been meaning to double check what the actual printed message from that looks like. I think I recall the output being a bit confusing (not specifying whether encoding or decoding was happening, whether the encoder or the format itself is to blame for lack of support, etc.)