Skip to content

Commit 1d3e2ce

Browse files
committed
FEAT: codecs/gif/size? function for resolving gif image size without need of decoding
1 parent cf86e55 commit 1d3e2ce

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

src/mezz/codec-image-ext.reb

+13
Original file line numberDiff line numberDiff line change
@@ -146,3 +146,16 @@ if find codecs 'jpeg [
146146
none
147147
]
148148
]
149+
150+
151+
if find codecs 'gif [
152+
extend codecs/gif 'size? function ["Return GIF image size or none" img [file! url! binary!]][
153+
unless binary? img [img: read/binary/part img 16]
154+
parse img [
155+
["GIF87a" | "GIF89a"] img: (
156+
return to pair! binary/read img [UI16LE UI16LE]
157+
)
158+
]
159+
none
160+
]
161+
]

src/tests/units/codecs-test.r3

+9-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,15 @@ if find codecs 'JPEG [
412412
--assert 256x256 = codecs/jpeg/size? %units/files/flower-tiny.jpg
413413
--assert none? codecs/jpeg/size? %units/files/test.aar
414414
===end-group===
415-
]
415+
]
416+
417+
if find codecs 'GIF [
418+
===start-group=== "GIF codec"
419+
--test-- "gif/size?"
420+
--assert 256x256 = codecs/gif/size? %units/files/flower.gif
421+
--assert none? codecs/gif/size? %units/files/test.aar
422+
===end-group===
423+
]
416424

417425
if find codecs 'XML [
418426
===start-group=== "XML codec"

src/tests/units/files/flower.gif

53.5 KB
Loading

0 commit comments

Comments
 (0)