Skip to content

Speed up decoder pixel-buffer conversion in decode.rs - #164

Open
nikosavola wants to merge 1 commit into
Isotr0py:mainfrom
nikosavola:perf-decode-pixels
Open

Speed up decoder pixel-buffer conversion in decode.rs#164
nikosavola wants to merge 1 commit into
Isotr0py:mainfrom
nikosavola:perf-decode-pixels

Conversation

@nikosavola

Copy link
Copy Markdown

pixels_to_bytes (the non-narrowing path, used for I;16/F modes) pushed output bytes one at a time in a loop. Replace the Uint16 and Float arms with a single bulk bytemuck::cast_slice reinterpret. Float16 stays a per-element loop (half::f16 isn't asserted Pod/Zeroable here) but is now pre-sized with with_capacity.

pixels_to_bytes_8bit's Uint16 arm does a lossy >> 8 narrowing downsample, not a reinterpret, so it intentionally keeps its per-element loop. Only added reserve() there for fewer reallocations.

Added unit tests asserting the bulk-cast output is byte-identical to the old per-element construction (including empty-vector inputs), that the Float16 upcast-and-reinterpret path is correct, and that the >> 8 narrowing still behaves correctly.

Note that tests fail until the Cargo.toml change from #163 is merged.

`pixels_to_bytes` (the non-narrowing path, used for I;16/F modes) pushed output bytes one at a time in a loop. Replace the Uint16 and Float arms with a single bulk `bytemuck::cast_slice reinterpret`. Float16 stays a per-element loop (half::f16 isn't asserted Pod/Zeroable here) but is now pre-sized with with_capacity.

`pixels_to_bytes_8bit`'s Uint16 arm does a lossy >> 8 narrowing downsample, not a reinterpret, so it intentionally keeps its per-element loop. Only added reserve() there for fewer reallocations.

Added unit tests asserting the bulk-cast output is byte-identical to the old per-element construction (including empty-vector inputs), that the Float16 upcast-and-reinterpret path is correct, and that the >> 8 narrowing still behaves correctly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant