Adds AVIF support

* This adds a new type AVIF to the supported type list if libvips >= 8.9.0
 * Calls libheif through libvips with the AV1 compression set to save AVIF images.
This commit is contained in:
Lars Fronius 2020-10-10 10:59:35 +02:00
parent 4f683f98d8
commit 83c14048e0
No known key found for this signature in database
GPG key ID: 9799DF92255C2D0C
9 changed files with 86 additions and 9 deletions

View file

@ -22,6 +22,7 @@ func TestDeterminateImageType(t *testing.T) {
{"test.heic", HEIF},
{"test2.heic", HEIF},
{"test3.heic", HEIF},
{"test.avif", AVIF},
}
for _, file := range files {
@ -51,12 +52,16 @@ func TestDeterminateImageTypeName(t *testing.T) {
{"test.svg", "svg"},
// {"test.jp2", "magick"},
{"test.heic", "heif"},
{"test.avif", "avif"},
}
for _, file := range files {
if file.expected == "heif" && VipsMajorVersion <= 8 && VipsMinorVersion < 8 {
continue
}
if file.expected == "avif" && VipsMajorVersion <= 8 && VipsMinorVersion < 9 {
continue
}
img, _ := os.Open(path.Join("testdata", file.name))
buf, _ := ioutil.ReadAll(img)
@ -73,13 +78,16 @@ func TestIsTypeSupported(t *testing.T) {
types := []struct {
name ImageType
}{
{JPEG}, {PNG}, {WEBP}, {GIF}, {PDF}, {HEIF},
{JPEG}, {PNG}, {WEBP}, {GIF}, {PDF}, {HEIF}, {AVIF},
}
for _, n := range types {
if n.name == HEIF && VipsMajorVersion <= 8 && VipsMinorVersion < 8 {
continue
}
if n.name == AVIF && VipsMajorVersion <= 8 && VipsMinorVersion < 9 {
continue
}
if IsTypeSupported(n.name) == false {
t.Fatalf("Image type %s is not valid", ImageTypes[n.name])
}
@ -97,12 +105,16 @@ func TestIsTypeNameSupported(t *testing.T) {
{"gif", true},
{"pdf", true},
{"heif", true},
{"avif", true},
}
for _, n := range types {
if n.name == "heif" && VipsMajorVersion <= 8 && VipsMinorVersion < 8 {
continue
}
if n.name == "avif" && VipsMajorVersion <= 8 && VipsMinorVersion < 9 {
continue
}
if IsTypeNameSupported(n.name) != n.expected {
t.Fatalf("Image type %s is not valid", n.name)
}
@ -121,6 +133,9 @@ func TestIsTypeSupportedSave(t *testing.T) {
if VipsVersion >= "8.8.0" {
types = append(types, struct{ name ImageType }{HEIF})
}
if VipsVersion >= "8.9.0" {
types = append(types, struct{ name ImageType }{AVIF})
}
for _, n := range types {
if IsTypeSupportedSave(n.name) == false {
@ -141,6 +156,7 @@ func TestIsTypeNameSupportedSave(t *testing.T) {
{"pdf", false},
{"tiff", VipsVersion >= "8.5.0"},
{"heif", VipsVersion >= "8.8.0"},
{"avif", VipsVersion >= "8.9.0"},
}
for _, n := range types {