Skip to content
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

add ExtractBandToImage #324

Merged
merged 3 commits into from
Nov 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions vips/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -1060,6 +1060,15 @@ func (r *ImageRef) ExtractBand(band int, num int) error {
return nil
}

// ExtractBandToImage extracts one or more bands out of the image to a new image
func (r *ImageRef) ExtractBandToImage(band int, num int) (*ImageRef, error) {
out, err := vipsExtractBand(r.image, band, num)
if err != nil {
return nil, err
}
return &ImageRef{image: out}, nil
}

// BandJoin joins a set of images together, bandwise.
func (r *ImageRef) BandJoin(images ...*ImageRef) error {
vipsImages := []*C.VipsImage{r.image}
Expand Down
7 changes: 7 additions & 0 deletions vips/image_golden_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -745,6 +745,13 @@ func TestImage_ExtractBand(t *testing.T) {
}, nil, nil)
}

func TestImage_ExtractBandToImage(t *testing.T) {
goldenTest(t, resources+"with_alpha.png", func(img *ImageRef) error {
_, err := img.ExtractBandToImage(2, 1)
return err
}, nil, nil)
}

func TestImage_Flatten(t *testing.T) {
goldenTest(t, resources+"with_alpha.png", func(img *ImageRef) error {
return img.Flatten(&Color{R: 32, G: 64, B: 128})
Expand Down