Add support for different bit depths with raw input and output #2762
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.
Fixes #1454 and fixes #1289. I've mostly added just the logic to support input or output raw data in different bit depths for now. If you like it, I'll also adjust the documentation accordingly and ensure test coverage of course.
Raw input example
This generates a green 4x4 .png file with 16 bits per pixel per color.
Raw output example
This takes the above .png file and reads the raw pixels from it as an
Uint16Array
. Note that the raw output still defaults to 8-bit results, so you have to explicitly use{ depth: "ushort" }
. Also,.toColourspace( "rgb16" )
is needed to prevent downsampling earlier on in the pipeline withsharp/src/pipeline.cc
Line 711 in 61640fb
Maybe you have a suggestion on how to do this automatically?
Please let me know your thoughts on this PR, I'd happy to work some more on it to get it merged.