Skip to content

Add Image.BackgroundColor and use it in rotate/affine/warp_perspective#207

Open
hlindset wants to merge 1 commit into
elixir-image:mainfrom
hlindset:feat/shared-background-color
Open

Add Image.BackgroundColor and use it in rotate/affine/warp_perspective#207
hlindset wants to merge 1 commit into
elixir-image:mainfrom
hlindset:feat/shared-background-color

Conversation

@hlindset

@hlindset hlindset commented Jul 3, 2026

Copy link
Copy Markdown
Contributor
  • Adds a shared utility for resolving :average | Image.Pixel.t() into a concrete color or %Image.Error{} for use in validators, and makes use of it in rotate, affine and warp_perspective.
  • Deterministic band layout: :average case appends an opaque alpha band, if the image has an alpha band, to match to_pixel. Callers needing to drop alpha can then do so unconditionally.
  • Fixes :average erroring on rotate/affine-based ops - a real oversight in my first implementation of :average for affine/rotate, where I patterned it off warp_perspective which flattens it input first. Regression tests added.

Image.embed/4 couldn't make use of this because it has split :background_color/:background_transparency options. Maybe a candidate for a refactor, folding the alpha handling into a single :background option? Discovered a latent bug there, however, and will follow up with a PR for that very soon.

Open question: Is lib/background_color.ex/Image.BackgroundColor the right place for this module? I can move it elsewhere if you'd prefer.

Note that depending on which of this and #206 lands first (if any), the second should be updated to make use of it (or in a short follow-up PR).

@hlindset hlindset force-pushed the feat/shared-background-color branch from 2f928b7 to 60afdf1 Compare July 3, 2026 18:50
@hlindset hlindset force-pushed the feat/shared-background-color branch from 60afdf1 to 6d87ae4 Compare July 3, 2026 18:51
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