Skip to content

Commit

Permalink
Merge pull request #153 from boosh/black
Browse files Browse the repository at this point in the history
Add black
  • Loading branch information
tonimelisma committed Jan 5, 2021
2 parents e31893b + 9f7e403 commit f87489b
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 0 deletions.
Binary file added resources/jpg-24bit.Black-linux-groovy.golden.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions vips/create.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,8 @@
int xyz(VipsImage **out, int width, int height){
return vips_xyz(out, width, height, NULL);
}

// http://libvips.github.io/libvips/API/current/libvips-create.html#vips-black
int black(VipsImage **out, int width, int height) {
return vips_black(out, width, height, NULL);
}
11 changes: 11 additions & 0 deletions vips/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,14 @@ func vipsXYZ(width int, height int) (*C.VipsImage, error) {

return out, nil
}

// http://libvips.github.io/libvips/API/current/libvips-create.html#vips-black
func vipsBlack(width int, height int) (*C.VipsImage, error) {
var out *C.VipsImage

if err := C.black(&out, C.int(width), C.int(height)); err != 0 {
return nil, handleImageError(out)
}

return out, nil
}
1 change: 1 addition & 0 deletions vips/create.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
#include <vips/foreign.h>

int xyz(VipsImage **out, int width, int height);
int black(VipsImage **out, int width, int height);
6 changes: 6 additions & 0 deletions vips/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ func XYZ(width, height int) (*ImageRef, error) {
return &ImageRef{image: image}, err
}

// Black creates a new black image of the specified size
func Black(width, height int) (*ImageRef, error) {
image, err := vipsBlack(width, height)
return &ImageRef{image: image}, err
}

func newImageRef(vipsImage *C.VipsImage, format ImageType, buf []byte) *ImageRef {
image := &ImageRef{
image: vipsImage,
Expand Down
10 changes: 10 additions & 0 deletions vips/image_golden_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -526,6 +526,16 @@ func TestImage_Tiff(t *testing.T) {
}, nil, nil)
}

func TestImage_Black(t *testing.T) {
Startup(nil)
i, err := Black(10, 20)
require.NoError(t, err)
buf, metadata, err := i.Export(nil)
require.NoError(t, err)

assertGoldenMatch(t, resources+"jpg-24bit.jpg", buf, metadata.Format)
}

func goldenTest(t *testing.T, file string, exec func(img *ImageRef) error, validate func(img *ImageRef), params *ExportParams) []byte {
Startup(nil)

Expand Down

0 comments on commit f87489b

Please sign in to comment.