Skip to content

Commit 2e652ef

Browse files
committed
feautre/exr added support for exr type
1 parent 44c1dfb commit 2e652ef

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

testdata/test.exr

148 KB
Binary file not shown.

type.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ const (
3232
HEIF
3333
// AVIF represents the AVIF image type.
3434
AVIF
35+
// EXR represents the EXR image type.
36+
EXR
3537
)
3638

3739
var (
@@ -51,6 +53,7 @@ var ImageTypes = map[ImageType]string{
5153
MAGICK: "magick",
5254
HEIF: "heif",
5355
AVIF: "avif",
56+
EXR: "exr",
5457
}
5558

5659
// imageMutex is used to provide thread-safe synchronization

type_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func TestDeterminateImageType(t *testing.T) {
2323
{"test2.heic", HEIF},
2424
{"test3.heic", HEIF},
2525
{"test.avif", AVIF},
26+
{"test.exr", EXR},
2627
}
2728

2829
for _, file := range files {
@@ -53,6 +54,7 @@ func TestDeterminateImageTypeName(t *testing.T) {
5354
// {"test.jp2", "magick"},
5455
{"test.heic", "heif"},
5556
{"test.avif", "avif"},
57+
{"test.exr", "exr"},
5658
}
5759

5860
for _, file := range files {
@@ -106,6 +108,7 @@ func TestIsTypeNameSupported(t *testing.T) {
106108
{"pdf", true},
107109
{"heif", true},
108110
{"avif", true},
111+
{"exr", true},
109112
}
110113

111114
for _, n := range types {

vips.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,9 @@ func VipsIsTypeSupported(t ImageType) bool {
205205
if t == AVIF {
206206
return int(C.vips_type_find_bridge(C.HEIF)) != 0
207207
}
208+
if t == EXR {
209+
return int(C.vips_type_find_bridge(C.MAGICK)) != 0
210+
}
208211
return false
209212
}
210213

@@ -767,6 +770,10 @@ func vipsImageType(buf []byte) ImageType {
767770
buf[8] == 0x61 && buf[9] == 0x76 && buf[10] == 0x69 && buf[11] == 0x66 {
768771
return AVIF
769772
}
773+
if IsTypeSupported(EXR) && buf[0] == 0x76 && buf[1] == 0x2f &&
774+
buf[2] == 0x31 && buf[3] == 0x01 {
775+
return EXR
776+
}
770777

771778
return UNKNOWN
772779
}

0 commit comments

Comments
 (0)