Skip to content

Commit

Permalink
feautre/exr added support for exr type
Browse files Browse the repository at this point in the history
  • Loading branch information
prOOrc committed Jul 18, 2022
1 parent a8f6d5f commit 06cdc0e
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 0 deletions.
Binary file added testdata/test.exr
Binary file not shown.
3 changes: 3 additions & 0 deletions type.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ const (
HEIF
// AVIF represents the AVIF image type.
AVIF
// EXR represents the EXR image type.
EXR
)

var (
Expand All @@ -51,6 +53,7 @@ var ImageTypes = map[ImageType]string{
MAGICK: "magick",
HEIF: "heif",
AVIF: "avif",
EXR: "exr",
}

// imageMutex is used to provide thread-safe synchronization
Expand Down
3 changes: 3 additions & 0 deletions type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ func TestDeterminateImageType(t *testing.T) {
{"test2.heic", HEIF},
{"test3.heic", HEIF},
{"test.avif", AVIF},
{"test.exr", EXR},
}

for _, file := range files {
Expand Down Expand Up @@ -53,6 +54,7 @@ func TestDeterminateImageTypeName(t *testing.T) {
// {"test.jp2", "magick"},
{"test.heic", "heif"},
{"test.avif", "avif"},
{"test.exr", "exr"},
}

for _, file := range files {
Expand Down Expand Up @@ -106,6 +108,7 @@ func TestIsTypeNameSupported(t *testing.T) {
{"pdf", true},
{"heif", true},
{"avif", true},
{"exr", true},
}

for _, n := range types {
Expand Down
7 changes: 7 additions & 0 deletions vips.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,9 @@ func VipsIsTypeSupported(t ImageType) bool {
if t == AVIF {
return int(C.vips_type_find_bridge(C.HEIF)) != 0
}
if t == EXR {
return int(C.vips_type_find_bridge(C.MAGICK)) != 0
}
return false
}

Expand Down Expand Up @@ -767,6 +770,10 @@ func vipsImageType(buf []byte) ImageType {
buf[8] == 0x61 && buf[9] == 0x76 && buf[10] == 0x69 && buf[11] == 0x66 {
return AVIF
}
if IsTypeSupported(EXR) && buf[0] == 0x76 && buf[1] == 0x2f &&
buf[2] == 0x31 && buf[3] == 0x01 {
return EXR
}

return UNKNOWN
}
Expand Down

0 comments on commit 06cdc0e

Please sign in to comment.