-
Notifications
You must be signed in to change notification settings - Fork 17.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
proposal: image: add (*Uniform).SubImage
#71463
Comments
Related Issues (Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.) |
CC @nigeltao |
ping? /CC @dmitshur |
This is on the list for the proposal review committee to take a look. It would help if you could write out the exact API that would be added to the image package: the new method and its doc comment. Thanks. |
// SubImage returns an image representing the portion of the image p visible through r. The returned value shares pixels with the original image.
func (p *Uniform) SubImage(r Rectangle) Image The implementation will be like this type Uniform struct {
C color.Color
bounds image.Rectangle
useBounds bool
}
func (p *Uniform) Bounds() image.Rectangle {
if p.useBounds {
return p.bounds
}
return Rectangle{Point{-1e9, -1e9}, Point{1e9, 1e9}}
}
func (p *Uniform) SubImage(r Rectangle) Image {
return &Uniform{
C: p.C,
bounds: p.Bounds().Inetrsect(r),
useBounds: true,
}
} |
The If we changed the API like you suggested then that assumption breaks. We would have to update the But we'd also have to update the But, if we want to avoid breaking anyone (along the lines of Go 1.x compat promise), in terms of semantics and not just "it still compiles", we'd also have to update any other third party code that have forked
But I'm not convinced yet that we need an
But really, I'd just do this (again, with no stdlib changes needed):
|
It should be obvious from my previous comment that I'm not in favor of this proposal. But for the record, see also that |
Hmm, ok, thank you for elaborating! |
Proposal Details
I propose to add
SubImage
method toimage.Uniform
, like other image types.SubImage
takes a rectangle as a bound and returns animage.Image
value. The underlying value of the returned value is aUniform
image with bounds, so we would need to add a (hidden) new member representing bounds toUniform
.This is useful when I want to create a color-filled image and encode this as a PNG image for example.
The text was updated successfully, but these errors were encountered: