Fix ArrayWriter palette mapping for transparent/last colors and add tests#16
Open
midstreeeam wants to merge 1 commit into
Open
Fix ArrayWriter palette mapping for transparent/last colors and add tests#16midstreeeam wants to merge 1 commit into
midstreeeam wants to merge 1 commit into
Conversation
### Motivation - Prevent transparent RGBA pixels (`[0,0,0,0]`) from being serialized as occupied voxels when exporting arrays to `.vox` format. - Ensure the full range of parsed VOX palette indices (1..255) can be mapped back to color indices during writing so index `255` is not dropped. ### Description - Update `ArrayWriter.mapping` in `src/midvoxio/writer.py` to build a safe palette from `self.rgba.palette_arr` and prepend an explicit empty color (`UNSET`) for index `0`. - Create a stable byte->index lookup that preserves the first seen mapping and explicitly forces the transparent byte value to map to index `0` so empty space remains empty. - Add regression tests in `tests/test_writer.py` covering transparent palette handling and exporting the final parsed palette color as index `255`. ### Testing - Ran `python -m compileall src tests` which completed successfully and verified the code compiles. - Attempted `PYTHONPATH=src python -m pytest tests/test_writer.py` but test collection failed because `numpy` (and other native deps) are not installed in this environment and package installation is blocked, so the tests could not be executed here.
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.
Motivation
Description
ArrayWriter.mappingto coerceself.rgba.palette_arrtonp.uint8, keep at most the first 255 palette colors and prependUNSETas color index0.setdefaultso the first occurrence of a color is preserved, and explicitly map the transparentUNSETbyte to index0.np.frombufferas before but ensure sentinel removal and stable mapping.tests/test_writer.pywith three tests:test_transparent_palette_color_is_written_as_empty_space,test_issue_15_roundtrip_does_not_export_empty_cell_as_voxel, andtest_last_parsed_palette_color_can_be_writtento cover transparent mapping, round-trip export, and the last-palette-color case.Testing
pytestwhich executed the three added tests.Codex Task