Skip to content

Commit 5bf90d8

Browse files
committed
FEAT: codecs/dds/size? function for resolving dds image size without need of decoding
1 parent 64734d5 commit 5bf90d8

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

src/mezz/codec-image-ext.reb

+10-1
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,17 @@ if find codecs 'gif [
163163
if find codecs 'bmp [
164164
extend codecs/bmp 'size? function ["Return BMP image size or none" img [file! url! binary!]][
165165
unless binary? img [img: read/binary/part img 32]
166-
unless find/tail img #{424D} [return none]
166+
unless find/match img #{424D} [return none]
167167
try [return to pair! binary/read img [SKIP 18 UI32LE UI32LE]]
168168
none
169169
]
170170
]
171+
172+
if find codecs 'dds [
173+
extend codecs/dds 'size? function ["Return DDS image size or none" img [file! url! binary!]][
174+
unless binary? img [img: read/binary/part img 32]
175+
unless find/match img #{444453207C000000} [return none]
176+
try [return to pair! reverse binary/read img [SKIP 12 UI32LE UI32LE]]
177+
none
178+
]
179+
]

src/mezz/codec-image-win.reb

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ register-codec [
2929

3030
decode: func [data [binary!]][lib/image/load/as data 'DDS]
3131
encode: func [data [image! ]][lib/image/save/as none data 'DDS]
32-
identify: func [data [binary!]][parse data [#{444453} to end]]
32+
identify: func [data [binary!]][parse data [#{444453207C000000} to end]]
3333
]
3434

3535
register-codec [

src/tests/units/codecs-test.r3

+8
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,14 @@ if find codecs 'BMP [
430430
===end-group===
431431
]
432432

433+
if find codecs 'DDS [
434+
===start-group=== "DDS codec"
435+
--test-- "dds/size?"
436+
--assert 256x256 = codecs/dds/size? %units/files/flower.dds
437+
--assert none? codecs/dds/size? %units/files/test.aar
438+
===end-group===
439+
]
440+
433441
if find codecs 'XML [
434442
===start-group=== "XML codec"
435443
--test-- "XML decode test1"

src/tests/units/files/flower.dds

64.1 KB
Binary file not shown.

0 commit comments

Comments
 (0)