Skip to content

Commit 50ea61f

Browse files
authored
Added support for WebP (#400)
Added support for WebP Also: * Moved QOI to Image formats section. * Changed AVI and WAV detectors (`detectavi`, and `detectwav`) to also use `detect_riff`. * Updated version to 1.16.5
1 parent bf42b4f commit 50ea61f

File tree

2 files changed

+29
-22
lines changed

2 files changed

+29
-22
lines changed

Project.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "FileIO"
22
uuid = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
3-
version = "1.16.4"
3+
version = "1.16.5"
44

55
[deps]
66
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"

src/registry.jl

+28-21
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ const idLibSndFile = :LibSndFile => UUID("b13ce0c6-77b0-50c6-a2db-140568b8d1a5")
1717
const idJpegTurbo = :JpegTurbo => UUID("b835a17e-a41a-41e7-81f0-2f016b05efe0")
1818
const idNPZ = :NPZ => UUID("15e1cf62-19b3-5cfa-8e77-841668bca605")
1919

20+
# Cf. https://developers.google.com/speed/webp/docs/riff_container#riff_file_format, and https://learn.microsoft.com/en-us/windows/win32/xaudio2/resource-interchange-file-format--riff-#chunks
21+
function detect_riff(io::IO, expected_magic::AbstractVector{UInt8})
22+
getlength(io) >= 12 || return false
23+
buf = Vector{UInt8}(undef, 4)
24+
fourcc = read!(io, buf)
25+
fourcc == b"RIFF" || return false
26+
seek(io, 8)
27+
magic = read!(io, buf)
28+
return magic == expected_magic
29+
end
30+
2031
### Simple cases
2132

2233
# data formats
@@ -204,6 +215,13 @@ add_format(
204215
".pcx",
205216
[idImageMagick]
206217
)
218+
add_format(
219+
format"QOI",
220+
"qoif",
221+
".qoi",
222+
[:QOI => UUID("4b34888f-f399-49d4-9bb3-47ed5cae4e65")],
223+
[idImageIO]
224+
)
207225
add_format(
208226
format"SVG",
209227
(),
@@ -218,19 +236,18 @@ add_format(
218236
[idImageIO],
219237
[idImageMagick]
220238
)
239+
detect_webp(io) = detect_riff(io, b"WEBP")
240+
add_format(
241+
format"WebP",
242+
detect_webp,
243+
".webp",
244+
[:WebP => UUID("e3aaa7dc-3e4b-44e0-be63-ffb868ccd7c1")],
245+
[idImageIO]
246+
)
221247

222248
# Video formats
223249

224-
# AVI is a subtype of RIFF, as is WAV
225-
function detectavi(io)
226-
getlength(io) >= 12 || return false
227-
magic = read!(io, Vector{UInt8}(undef, 4))
228-
magic == b"RIFF" || return false
229-
seek(io, 8)
230-
submagic = read!(io, Vector{UInt8}(undef, 4))
231-
232-
submagic == b"AVI "
233-
end
250+
detectavi(io) = detect_riff(io, b"AVI ")
234251
add_format(format"AVI", detectavi, ".avi", [idImageMagick], [idVideoIO])
235252

236253
"""
@@ -278,15 +295,7 @@ add_format(format"OUT", "# Bundle file v0.3\n", ".out", [:BundlerIO => UUID("654
278295
add_format(format"GSLIB", (), [".gslib",".sgems"], [:GslibIO => UUID("4610876b-9b01-57c8-9ad9-06315f1a66a5")])
279296

280297
### Audio formats
281-
function detectwav(io)
282-
getlength(io) >= 12 || return false
283-
buf = Vector{UInt8}(undef, 4)
284-
read!(io, buf)
285-
buf == b"RIFF" || return false
286-
seek(io, 8)
287-
read!(io, buf)
288-
buf == b"WAVE"
289-
end
298+
detectwav(io) = detect_riff(io, b"WAVE")
290299
add_format(format"WAV", detectwav, ".wav", [:WAV => UUID("8149f6b0-98f6-5db9-b78f-408fbbb8ef88")], [idLibSndFile])
291300
add_format(format"FLAC", "fLaC", ".flac", [:FLAC => UUID("abae9e3b-a9a0-4778-b5c6-ca109b507d99")], [idLibSndFile])
292301

@@ -542,8 +551,6 @@ add_format(format"HTML", (), [".html", ".htm"], [MimeWriter, SAVE])
542551

543552
add_format(format"MIDI", "MThd", [".mid", ".midi", ".MID"], [:MIDI => UUID("f57c4921-e30c-5f49-b073-3f2f2ada663e")])
544553

545-
add_format(format"QOI", "qoif", ".qoi", [:QOI => UUID("4b34888f-f399-49d4-9bb3-47ed5cae4e65")], [idImageIO])
546-
547554
# Bibliography files.
548555
add_format(format"BIB", (), [".bib"], [:Bibliography => UUID("f1be7e48-bf82-45af-a471-ae754a193061")])
549556

0 commit comments

Comments
 (0)