Skip to content

Commit

Permalink
FEAT: codecs/bmp/size? function for resolving bmp image size withou…
Browse files Browse the repository at this point in the history
…t need of decoding
  • Loading branch information
Oldes committed Sep 1, 2021
1 parent 1d3e2ce commit 64734d5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
11 changes: 10 additions & 1 deletion src/mezz/codec-image-ext.reb
Original file line number Diff line number Diff line change
Expand Up @@ -158,4 +158,13 @@ if find codecs 'gif [
]
none
]
]
]

if find codecs 'bmp [
extend codecs/bmp 'size? function ["Return BMP image size or none" img [file! url! binary!]][
unless binary? img [img: read/binary/part img 32]
unless find/tail img #{424D} [return none]
try [return to pair! binary/read img [SKIP 18 UI32LE UI32LE]]
none
]
]
10 changes: 9 additions & 1 deletion src/tests/units/codecs-test.r3
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,15 @@ if find codecs 'GIF [
--assert 256x256 = codecs/gif/size? %units/files/flower.gif
--assert none? codecs/gif/size? %units/files/test.aar
===end-group===
]
]

if find codecs 'BMP [
===start-group=== "BMP codec"
--test-- "bmp/size?"
--assert 256x256 = codecs/bmp/size? %units/files/flower.bmp
--assert none? codecs/bmp/size? %units/files/test.aar
===end-group===
]

if find codecs 'XML [
===start-group=== "XML codec"
Expand Down
Binary file added src/tests/units/files/flower.bmp
Binary file not shown.

0 comments on commit 64734d5

Please # to comment.