diff --git a/resources/jxl-isobmff.jxl b/resources/jxl-isobmff.jxl new file mode 100644 index 00000000..f76e917a Binary files /dev/null and b/resources/jxl-isobmff.jxl differ diff --git a/vips/foreign.go b/vips/foreign.go index 695617f5..80f643b4 100644 --- a/vips/foreign.go +++ b/vips/foreign.go @@ -257,10 +257,14 @@ func isJP2K(buf []byte) bool { return bytes.HasPrefix(buf, jp2kHeader) } +// As a 'naked' codestream var jxlHeader = []byte("\xff\x0a") +// As an ISOBMFF-based container: 0x0000000C 4A584C20 0D0A870A +var jxlHeaderISOBMFF = []byte("\x00\x00\x00\x0C\x4A\x58\x4C\x20\x0D\x0A\x87\x0A") + func isJXL(buf []byte) bool { - return bytes.HasPrefix(buf, jxlHeader) + return bytes.HasPrefix(buf, jxlHeader) || bytes.HasPrefix(buf, jxlHeaderISOBMFF) } func vipsLoadFromBuffer(buf []byte, params *ImportParams) (*C.VipsImage, ImageType, ImageType, error) { diff --git a/vips/foreign_test.go b/vips/foreign_test.go index ce9b7e0a..38a40d32 100644 --- a/vips/foreign_test.go +++ b/vips/foreign_test.go @@ -149,3 +149,14 @@ func Test_DetermineImageType__JXL(t *testing.T) { imageType := DetermineImageType(buf) assert.Equal(t, ImageTypeJXL, imageType) } + +func Test_DetermineImageType__JXL_ISOBMFF(t *testing.T) { + Startup(&Config{}) + + buf, err := os.ReadFile(resources + "jxl-isobmff.jxl") + assert.NoError(t, err) + assert.NotNil(t, buf) + + imageType := DetermineImageType(buf) + assert.Equal(t, ImageTypeJXL, imageType) +}