Skip to content

Fix expanding bit depth in AVIF#2983

Merged
197g merged 1 commit into
image-rs:mainfrom
awxkee:expand_bit_depth
May 24, 2026
Merged

Fix expanding bit depth in AVIF#2983
197g merged 1 commit into
image-rs:mainfrom
awxkee:expand_bit_depth

Conversation

@awxkee
Copy link
Copy Markdown
Contributor

@awxkee awxkee commented May 24, 2026

Rotate left replicates bits, with assumption that our data is 16 bit, by amount shifted left, so for 10 bit it shift left by 6 and it replicates 0 bits to the lower half, but we need 6.
Hence rotate left is (value << n) | (value >> (16 - n)) but we need (value << n) | (value >> (bit_depth - n)).

Copy link
Copy Markdown
Member

@RunDevelopment RunDevelopment left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Using bitshifts only approximates a proper unorm conversion, but it should be good enough here. The conversion from 8 bits is exact, and the maximum absolute error for 10 and 12 bits is 1 bit (or $2^{-16}$).

@197g 197g merged commit 97f0a4d into image-rs:main May 24, 2026
31 checks passed
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.

3 participants