Skip to content

Document the internal image distinctness constraints - #9752

Merged
radarhere merged 5 commits into
python-pillow:mainfrom
akx:ldocs
Sep 16, 2026
Merged

radarhere merged 5 commits into
python-pillow:mainfrom
akx:ldocs

Conversation

@akx

@akx akx commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Follows up on #9649, #9675, #9736, #9737, #9738, #9739, #9740.

#9743 will do this internally.

Adds documentation comments to the touched functions to document the distinctness-or-lack-thereof requirements for the image data.

Comment thread src/libImaging/Bands.c Outdated
Comment thread src/libImaging/Bands.c Outdated
akx and others added 2 commits September 13, 2026 22:54
Co-authored-by: Andrew Murray <3112309+radarhere@users.noreply.github.com>
@akx

akx commented Sep 13, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, good points! I noticed #9988 would invalidate some of the comments added here - would you prefer this be merged first or that API change and then this? I'm fine rebasing/fixing either way.

Comment thread src/libImaging/Histo.c Outdated
}

/**
* Accumulate a histogram over `im`, optionally restricted to imMask.

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.

'accumulate' makes it sound like this is a cumulative histogram, which it isn't?

Comment thread src/libImaging/Histo.c
/**
* Accumulate a histogram over `im`, optionally restricted to imMask.
*
* Contract: Both im and imMask are read-only.

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.

Why is this the contract? I expect that is how it is used, but I don't see any use of restrict in here.

@akx akx Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I didn't get this far in the optimization series, looks like 😄
But this documents the contract nevertheless, that was never going to change with the series.

EDIT: See #10005. Turns out I had half-written optimizations but didn't push them before.

Comment thread src/libImaging/Quant.c
* Quantize `im` down to at most `colors` palette entries,
* returning a newly allocated result.
*
* Contract: im is read-only.

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.

Again, I don't see any restrict here.

@akx akx Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Same here as above: this still documents the contract. Quantize was touched a bit in #9740, though not with restrict bits.

@radarhere
radarhere merged commit acc5db5 into python-pillow:main Sep 16, 2026
86 of 91 checks passed
@akx

akx commented Sep 16, 2026

Copy link
Copy Markdown
Contributor Author

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants