Support RGB native frames in GetImage - #386
Open
ChrisJr404 wants to merge 1 commit into
Open
Conversation
GetImage only handled single-sample (grayscale) frames and returned ErrUnsupportedSamplesPerPixel for anything else. Frames with 3 samples per pixel are now rendered as an image.RGBA64 by reading the interleaved R, G, B samples for each pixel, while grayscale frames keep returning an image.Gray16 exactly as before. Fixes suyashkumar#336
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This adds RGB support to
NativeFrame.GetImageas requested in #336, so color native images can be turned into a Go image instead of erroring out.Right now
GetImageonly handles frames with a single sample per pixel and returnsErrUnsupportedSamplesPerPixelfor everything else, so anything with color just fails. Following your pointer in the issue, a frame with 3 samples per pixel is now treated as RGB: it reads the interleaved R, G, B samples for each pixel (the same layoutGetPixel/GetSamplealready assume) and builds animage.RGBA64, usinguint16channels the way the grayscale path already casts intoimage.Gray16. Grayscale frames are untouched and still come back asimage.Gray16, and other sample counts keep returningErrUnsupportedSamplesPerPixel.Since the samples are read straight through without scaling, this matches the existing "basic, does not autoscale" behavior of the grayscale path rather than adding any window/level handling. Planar configuration (all R, then all G, then all B) isn't handled here — it would need to be dealt with at parse time — so this sticks to the interleaved layout that's assumed elsewhere in the frame.
dicomutilalready encodes whateverGetImagereturns withpng.Encode, so it now writes color PNGs for RGB native frames without any change. I added table tests covering the RGB path alongside the existing grayscale ones.Closes #336