Add affine, translate and shear transforms#202
Merged
kipcole9 merged 3 commits intoJun 30, 2026
Conversation
Collaborator
|
Thank you again. Fabulous work and very thorough. |
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.
Adds an affine transform primitive, and two thin convenience wrappers:
Image.affine/3/Image.affine!/3: applies an affine transform from a flat[a, b, c, d]matrix mapping(x, y) → (a*x + b*y, c*x + d*y), built onVix.Vips.Operation.affine.Image.translate/4/Image.translate!/4: shifts content within a same-size canvas, clipping overflow.Image.shear/4/Image.shear!/4: horizontal/vertical shear.They share the same options, validated by
Image.Options.Affine::idx/:idy/:odx/:ody(input/output displacements),:interpolate(:nearest,:bilinear(default),:bicubic,:lbb,:nohalo,:vsqbs),:background(sent throughImage.Pixel.to_pixel/2, or:average),:extend_mode, and:output_area.A fused affine avoids the per-pass resampling loss of chaining named ops.
Is this something you want in the library?
N.B. I grouped these functions under the "Distortion" docs category. Do you agree with that? Or should it be listed under "Operations"?
Out of scope discoveries made:
warp_perspective/straighten_perspective::extend_modeis silently dropped, becauseOptions.WarpPerspectivepasses it tomapim/3under the key:extend_mode, but the op's option is:extend, so the value never takes effect. Even once that's fixed,mapim's extend (likeaffine's) is only applied to the thin antialiased fringe at the resampled edges, not the uncovered canvas (which is filled by:background), so the docs are inaccurate wrt. region fillsImage.rotate/3'sbackgrounddoes not currently make use ofImage.Pixel.to_pixeland does not support 4-element (RGBA) colorsImage.rotate/3does not expose aninterpolateoption (supported by vix/libvips)I'll submit PRs for those findings soon