Skip to content

Commit

Permalink
Add support for JXL images which are formatted as an ISOBMFF-based co…
Browse files Browse the repository at this point in the history
…ntainer (for example used by Adobe when embedding DNG preview/thumbnail files). (#434)

See https://github.com/ImageMagick/jpeg-xl/blob/main/doc/format_overview.md#file-format for more information.
  • Loading branch information
jhdrn authored Jun 7, 2024
1 parent 85f409a commit 0c98a28
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Binary file added resources/jxl-isobmff.jxl
Binary file not shown.
6 changes: 5 additions & 1 deletion vips/foreign.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions vips/foreign_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 0c98a28

Please sign in to comment.