-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
vips_thumbnail from file and optimizations (#237)
* implement VipsSize * DetermineImageTypeFromFields * handle bmp compatibility * refactor bmp to png sequence * implement ImageType based on vips-loader metadata, added DetermineImageTypeFromLoader * implement vipsThumbnailFromFile, use native vips function for NewThumbnailFromFile * add benchmark script * update namespace * update namespace * add constant * vipsDetermineImageTypeFromMetaLoader * add back test coverage * vipsImageGetMetaLoader
- Loading branch information
Showing
12 changed files
with
378 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package thumbnail | ||
|
||
import ( | ||
"fmt" | ||
"github.com/davidbyttow/govips/v2/vips" | ||
"io/ioutil" | ||
"testing" | ||
) | ||
|
||
var file = "../../resources/jpg-24bit-icc-iec.jpg" | ||
|
||
func init() { | ||
vips.LoggingSettings(func(domain string, level vips.LogLevel, msg string) { | ||
fmt.Println(domain, level, msg) | ||
}, vips.LogLevelError) | ||
vips.Startup(nil) | ||
} | ||
|
||
func BenchmarkNewImageFromFile(b *testing.B) { | ||
resizeToTest := func(size int) { | ||
image, err := vips.NewImageFromFile(file) | ||
if err != nil { | ||
panic(err) | ||
} | ||
if err := image.Thumbnail(size*100, size*100, vips.InterestingCentre); err != nil { | ||
panic(err) | ||
} | ||
if err := image.Flip(vips.DirectionVertical); err != nil { | ||
panic(err) | ||
} | ||
if _, _, err = image.ExportNative(); err != nil { | ||
panic(err) | ||
} | ||
} | ||
for i := 0; i < b.N; i++ { | ||
resizeToTest(1) | ||
resizeToTest(2) | ||
resizeToTest(3) | ||
resizeToTest(4) | ||
resizeToTest(5) | ||
} | ||
} | ||
|
||
func BenchmarkNewImageFromBuffer(b *testing.B) { | ||
resizeToTest := func(size int) { | ||
buf, err := ioutil.ReadFile(file) | ||
if err != nil { | ||
panic(err) | ||
} | ||
image, err := vips.NewImageFromBuffer(buf) | ||
if err != nil { | ||
panic(err) | ||
} | ||
if err := image.Thumbnail(size*100, size*100, vips.InterestingCentre); err != nil { | ||
panic(err) | ||
} | ||
if err := image.Flip(vips.DirectionVertical); err != nil { | ||
panic(err) | ||
} | ||
if _, _, err = image.ExportNative(); err != nil { | ||
panic(err) | ||
} | ||
} | ||
for i := 0; i < b.N; i++ { | ||
resizeToTest(1) | ||
resizeToTest(2) | ||
resizeToTest(3) | ||
resizeToTest(4) | ||
resizeToTest(5) | ||
} | ||
} | ||
|
||
func BenchmarkNewThumbnailFromFile(b *testing.B) { | ||
resizeToTest := func(size int) { | ||
image, err := vips.NewThumbnailFromFile(file, size*100, size*100, vips.InterestingCentre) | ||
if err != nil { | ||
panic(err) | ||
} | ||
if err := image.Flip(vips.DirectionVertical); err != nil { | ||
panic(err) | ||
} | ||
if _, _, err = image.ExportNative(); err != nil { | ||
panic(err) | ||
} | ||
} | ||
for i := 0; i < b.N; i++ { | ||
resizeToTest(1) | ||
resizeToTest(2) | ||
resizeToTest(3) | ||
resizeToTest(4) | ||
resizeToTest(5) | ||
} | ||
} | ||
|
||
func BenchmarkNewThumbnailFromBuffer(b *testing.B) { | ||
resizeToTest := func(size int) { | ||
buf, err := ioutil.ReadFile(file) | ||
if err != nil { | ||
panic(err) | ||
} | ||
image, err := vips.NewThumbnailFromBuffer(buf, size*100, size*100, vips.InterestingCentre) | ||
if err != nil { | ||
panic(err) | ||
} | ||
if err := image.Flip(vips.DirectionVertical); err != nil { | ||
panic(err) | ||
} | ||
if _, _, err = image.ExportNative(); err != nil { | ||
panic(err) | ||
} | ||
} | ||
for i := 0; i < b.N; i++ { | ||
resizeToTest(1) | ||
resizeToTest(2) | ||
resizeToTest(3) | ||
resizeToTest(4) | ||
resizeToTest(5) | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+84.1 KB
resources/jpg-8bit-grey-icc-dot-gain.TestThumbnail_NoUpscale-macos-11.golden.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+3.36 KB
resources/png-24bit.TestThumbnail_PNG_CropCentered-macos-11.golden.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.