Skip to content

Fix Image.Pixel.to_pixel/3 returning gamma encoded colors and 0..255 greys for scRGB images - #230

Merged
hlindset merged 1 commit into
elixir-image:mainfrom
hlindset:fix/scrgb-pixel-encoding
Aug 9, 2026
Merged

Fix Image.Pixel.to_pixel/3 returning gamma encoded colors and 0..255 greys for scRGB images#230
hlindset merged 1 commit into
elixir-image:mainfrom
hlindset:fix/scrgb-pixel-encoding

Conversation

@hlindset

@hlindset hlindset commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

Breaking

Returns linear light for an :scrgb image. scRGB is linear, but the pixel was resolved with Color.SRGB, so every color between black and white came out too bright and desaturated. It now resolves with Color.RGB in the :SRGB working space. Affects every function that resolves a color against an scRGB image.

Before fix. rebeccapurple came out as [170, 124, 203] (in sRGB) after being read back:
image

After fix. Reads back as [102, 51, 153]:
image

Returns relative luminance for a single band :scrgb image. Single band scRGB images were given a 0..255 integer. :white resolved to 255 instead of 1.0, and "#808080" to 137 instead of 0.216. They now resolve to CIE Y, matching how libvips collapses color to grey1.

Footnotes

  1. https://www.libvips.org/API/current/libvips-colour.html

@kipcole9

kipcole9 commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator

Nice catch. Should we use Color.RGB which is the correct linear model?

@hlindset

hlindset commented Aug 8, 2026

Copy link
Copy Markdown
Collaborator Author

Nice catch. Should we use Color.RGB which is the correct linear model?

That's what it does now: :scrgb resolves colors with Color.RGB in the :SRGB working space. My bad, forgot to include that in the PR body!

@hlindset
hlindset merged commit f883295 into elixir-image:main Aug 9, 2026
10 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.

2 participants