Repository navigation
Conversation
Pillow has no "R;16" raw mode for RGB images, so decoding any R16 texture raised "unknown raw mode for given image mode". Use "R;16L" (little-endian, high byte kept), consistent with R8 decoding into the red channel.
This branch has not been deployed
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.
Fixes #393
TF.R16was decoded with the Pillow raw modeR;16for anRGBimage. Pillow has no suchraw mode, so
Texture2D.imageraisedValueError: unknown raw mode for given image modefor every R16 texture.
This changes it to
R;16L(little-endian 16-bit, high byte kept), so the value lands in thered channel at 8 bit, the same as
R8and the same 8-bitRoutput the encoder side(
TF.R16->TF.R8) already assumes.Tests
tests/test_texture2d_r16.pydecodes a 2x2 R16 buffer throughparse_image_dataand checks thered channel equals each value's high byte and G/B are 0. It fails on master with the error above
and passes with this change. I only ran this test file, not the full suite (the repo's samples
are stored with git LFS and were not available where I tested).
Also verified on a real texture (512x512, 10 mips):
decoded red channel equals the high byte of the raw data for every pixel.
Open questions for review
R;16Ldrops the low byte. Decoding to modeI;16(("I;16", "raw", "I;16"))would keep full precision but changes the output image mode from
RGB, which callers ofTexture2D.imagemay not expect. Is 8-bit RGB the intended contract here?R;16L), like the other 16-bit formats; thereal sample matched. Should big-endian platforms (e.g. Xbox 360 /
XBOX_SWAP_FORMATS) be handled separately?set_imageforR16falls into the group that re-encodes asTF.R8withpil_mode = "R"(Texture2DConverter.py~lines 178-185). From reading the code I believe writingan image back to an R16 texture yields 8-bit data; I have not tested this round trip.
Image.frombytescheck fails forR8_SIGNED,R16_SIGNED,RGB24_SIGNED,RGBA32_SIGNED,RGB48_SIGNED,RGBA64_SIGNED,RGBA64,RFloat,RGBAFloat,ARGBFloat(list in the issue). Left out of this PR to keep it focused; happy tohandle them here or separately - which do you prefer?