mirror of
https://github.com/talgo-cloud/bimg.git
synced 2026-03-07 13:38:16 -08:00
Since AVIF computation was awfully slow, this exposes the CPU effort setting "speed".
This commit is contained in:
parent
2cba482a06
commit
e87ff245c1
6 changed files with 19 additions and 4 deletions
|
|
@ -12,6 +12,7 @@ env:
|
|||
# - LIBVIPS=8.8.4
|
||||
# - LIBVIPS=8.9.2
|
||||
- LIBVIPS=8.10.1
|
||||
- LIBVIPS=8.10.2
|
||||
|
||||
matrix:
|
||||
allow_failures:
|
||||
|
|
|
|||
|
|
@ -226,6 +226,8 @@ type Options struct {
|
|||
OutputICC string
|
||||
InputICC string
|
||||
Palette bool
|
||||
// Speed defines the AVIF encoders CPU effort.
|
||||
Speed int
|
||||
|
||||
// private fields
|
||||
autoRotateOnly bool
|
||||
|
|
|
|||
|
|
@ -187,6 +187,7 @@ func saveImage(image *C.VipsImage, o Options) ([]byte, error) {
|
|||
StripMetadata: o.StripMetadata,
|
||||
Lossless: o.Lossless,
|
||||
Palette: o.Palette,
|
||||
Speed: o.Speed,
|
||||
}
|
||||
// Finally get the resultant buffer
|
||||
return vipsSave(image, saveOptions)
|
||||
|
|
|
|||
4
vips.go
4
vips.go
|
|
@ -45,6 +45,7 @@ type VipsMemoryInfo struct {
|
|||
|
||||
// vipsSaveOptions represents the internal option used to talk with libvips.
|
||||
type vipsSaveOptions struct {
|
||||
Speed int
|
||||
Quality int
|
||||
Compression int
|
||||
Type ImageType
|
||||
|
|
@ -493,6 +494,7 @@ func vipsSave(image *C.VipsImage, o vipsSaveOptions) ([]byte, error) {
|
|||
strip := C.int(boolToInt(o.StripMetadata))
|
||||
lossless := C.int(boolToInt(o.Lossless))
|
||||
palette := C.int(boolToInt(o.Palette))
|
||||
speed := C.int(o.Speed)
|
||||
|
||||
if o.Type != 0 && !IsTypeSupportedSave(o.Type) {
|
||||
return nil, fmt.Errorf("VIPS cannot save to %#v", ImageTypes[o.Type])
|
||||
|
|
@ -508,7 +510,7 @@ func vipsSave(image *C.VipsImage, o vipsSaveOptions) ([]byte, error) {
|
|||
case HEIF:
|
||||
saveErr = C.vips_heifsave_bridge(tmpImage, &ptr, &length, strip, quality, lossless)
|
||||
case AVIF:
|
||||
saveErr = C.vips_avifsave_bridge(tmpImage, &ptr, &length, strip, quality, lossless)
|
||||
saveErr = C.vips_avifsave_bridge(tmpImage, &ptr, &length, strip, quality, lossless, speed)
|
||||
default:
|
||||
saveErr = C.vips_jpegsave_bridge(tmpImage, &ptr, &length, strip, quality, interlace)
|
||||
}
|
||||
|
|
|
|||
13
vips.h
13
vips.h
|
|
@ -369,8 +369,17 @@ vips_tiffsave_bridge(VipsImage *in, void **buf, size_t *len) {
|
|||
}
|
||||
|
||||
int
|
||||
vips_avifsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int quality, int lossless) {
|
||||
#if (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 9))
|
||||
vips_avifsave_bridge(VipsImage *in, void **buf, size_t *len, int strip, int quality, int lossless, int speed) {
|
||||
#if (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION >= 8 && VIPS_MINOR_VERSION > 10) || (VIPS_MAJOR_VERSION >= 8 && VIPS_MINOR_VERSION >= 10 && VIPS_MICRO_VERSION >= 2))
|
||||
return vips_heifsave_buffer(in, buf, len,
|
||||
"strip", INT_TO_GBOOLEAN(strip),
|
||||
"Q", quality,
|
||||
"lossless", INT_TO_GBOOLEAN(lossless),
|
||||
"compression", VIPS_FOREIGN_HEIF_COMPRESSION_AV1,
|
||||
"speed", speed,
|
||||
NULL
|
||||
);
|
||||
#elif (VIPS_MAJOR_VERSION > 8 || (VIPS_MAJOR_VERSION == 8 && VIPS_MINOR_VERSION >= 9))
|
||||
return vips_heifsave_buffer(in, buf, len,
|
||||
"strip", INT_TO_GBOOLEAN(strip),
|
||||
"Q", quality,
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ func TestVipsSave(t *testing.T) {
|
|||
|
||||
for _, typ := range types {
|
||||
image, _, _ := vipsRead(readImage("test.jpg"))
|
||||
options := vipsSaveOptions{Quality: 95, Type: typ, StripMetadata: true}
|
||||
options := vipsSaveOptions{Quality: 95, Type: typ, StripMetadata: true, Speed: 8}
|
||||
|
||||
buf, err := vipsSave(image, options)
|
||||
if err != nil {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue