-
Notifications
You must be signed in to change notification settings - Fork 18k
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
proposal: image/jpeg: support color channels other than 8 bits, eg Gray16 #51904
Comments
cc @nigeltao |
At the wire format level, Extended or Progressive (as opposed to Baseline) JPEG can still only represent 12 bit depth, not the full 16. Would you still consider that "encoded incorrectly" if the least significant 4 bits are still discarded silently?
An alternative to adding encoder options is to detect Having said all that, if you're talking about medical imaging, you're probably talking about Lossless JPEG (which does allow 16 bit depth). Go's image/jpeg decoder (let alone its encoder) currently does not support LJPEG. I'll copy/paste here in full what I wrote on the #22535 "support LJPEG" feature request:
Back to this issue (encoding, not decoding), the same applies: "it's a valid feature request... [but] I really don't have any spare time to work on this myself." |
Go version: All recent, including 1.18.
OS: Linux / AMD64
In (e.g) image/jpeg/writer.go:620 , the encoder switches on the underlying image type (
case *image.Gray:
).However, it has no check for color.Grey16, leading to that format being encoded incorrectly (the least significant 8 bits are discarded silently).
While many viewers elect not to implement it, the jpeg format supports wider color channels than 8 bit.
Specifying the number of color components and their size in the encoder options would allow the implementation to be used for e.g. medical imaging & scientific instrument data.
I propose that when the size or number of components is set to 0, the existing detection code is used instead (no change when not using the new options), unless you are encoding an image in the
Grey16
color space.The text was updated successfully, but these errors were encountered: