govips icon indicating copy to clipboard operation
govips copied to clipboard

implement vips_image_new_from_file

Open cshum opened this issue 2 years ago • 1 comments

This enables creating new image object directly from file path, using vips_image_new_from_file:

Below is the go bench of NewImageFromFile against the master branch. The memory difference B/op is very noticeable. The speed maybe slightly slower, presumably due to disk seek (instead of all loaded in memory).

(base) ➜  govips git:(master) go test -bench=NewImageFromFile -benchtime=30s -benchmem ./examples/thumbnail
goos: darwin
goarch: amd64
pkg: github.com/davidbyttow/govips/v2/examples/thumbnail
cpu: Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
BenchmarkNewImageFromFile-4           91         388221588 ns/op         2600845 B/op        234 allocs/op
PASS
ok      github.com/davidbyttow/govips/v2/examples/thumbnail     36.420s

(base) ➜  govips git:(vips_new_image) go test -bench=NewImageFromFile -benchtime=30s -benchmem ./examples/thumbnail
goos: darwin
goarch: amd64
pkg: github.com/davidbyttow/govips/v2/examples/thumbnail
cpu: Intel(R) Core(TM) i5-7360U CPU @ 2.30GHz
BenchmarkNewImageFromFile-4           90         395057470 ns/op          261382 B/op        201 allocs/op
PASS
ok      github.com/davidbyttow/govips/v2/examples/thumbnail     36.167s

However this relies on libvips's VIPS_META_LOADER to determine image type, instead of govips's DetermineImageType, which potentially introduces different behaviour for edge cases.

Tests passing under Linux, but TestImage_DrawRectRGBA seems to be failing under MacOS I am not sure why.

#289

cshum avatar Jul 04 '22 02:07 cshum

Coverage Status

Coverage increased (+0.2%) to 76.697% when pulling 6ad6e32b961c37524a9fe0258aacc6970648ec28 on cshum:vips_new_image into 810eeb0682be918f2cf5ed42853bf8d3f1b70df1 on davidbyttow:master.

coveralls avatar Jul 04 '22 02:07 coveralls