Skip to content

Provide defaults for more Pixel methods - #3069

Merged
197g merged 1 commit into
image-rs:mainfrom
RunDevelopment:pixel-trait-defaults
Jul 12, 2026
Merged

197g merged 1 commit into
image-rs:mainfrom
RunDevelopment:pixel-trait-defaults

Conversation

@RunDevelopment

Copy link
Copy Markdown
Member

I thought it would be good idea to provide defaults for Pixel methods that can be implemented in terms of other methods.

This makes it easier to implement Pixel and reduces the complexity of the define_colors macro.

@197g 197g left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

To explicitly rationalize the choice here in favor of defaulting map rather than apply: we require Copy to enable this but contrary to std's iterator conundrum there are scenarios where in-place modification is highly expected and our naming makes this clear. It's usually simpler to write a modifying method as a base case where assignmented and compound assignment operators can be used with numerics of channels.

PS: also speculatively LLVM is sometimes picky, trying to default apply as read-modify-write creates more optimizer pressure. There's already a difference optimizing *lpr++ = v vs *lpr = v; lpr++.

@197g
197g merged commit ebb603f into image-rs:main Jul 12, 2026
31 checks passed
@RunDevelopment
RunDevelopment deleted the pixel-trait-defaults branch July 12, 2026 20: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.

2 participants