Skip to content

Commit 77a4122

Browse files
committed
FEAT: extend PNG codec with size? function (returning image size of the binary)
1 parent 1739683 commit 77a4122

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

src/mezz/codec-image-ext.reb

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
REBOL [
2+
title: "REBOL 3 image codecs extensions"
3+
name: 'codec-image-ext
4+
author: "Oldes"
5+
version: 0.1.0
6+
date: 10-Nov-2020
7+
history: [
8+
0.1.0 10-Nov-2020 "Oldes" {Extend native PNG codec with `size?` function}
9+
]
10+
]
11+
12+
if find codecs 'png [
13+
extend codecs/png 'size2? func ["Return PNG image size or none" bin [binary!]][
14+
if all [
15+
parse bin [
16+
#{89504E470D0A1A0A} ;- PNG magic number
17+
thru #{49484452} ;- IHDR chunk
18+
bin: to end
19+
]
20+
8 <= length? bin
21+
][
22+
to pair! binary/read bin [UI32 UI32]
23+
]
24+
]
25+
]
26+
27+
28+
29+
30+
31+
32+
33+
34+
35+
36+
37+
38+
39+
40+
41+

src/tests/units/codecs-test.r3

+8
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,14 @@ if find codecs 'JSON [
283283
===end-group===
284284
]
285285

286+
if find codecs 'PNG [
287+
===start-group=== "PNG codec"
288+
--test-- "png/size?"
289+
--assert 24x24 = codecs/png/size? read %units/files/r3.png
290+
--assert none? codecs/png/size? read %units/files/test.aar
291+
===end-group===
292+
]
293+
286294
if find codecs 'XML [
287295
===start-group=== "XML codec"
288296
--test-- "XML decode test1"

src/tools/make-boot.reb

+1
Original file line numberDiff line numberDiff line change
@@ -993,6 +993,7 @@ if product = 'view [
993993
]
994994
]
995995
]
996+
append mezz-files/3 %codec-image-ext.reb
996997

997998
foreach section [boot-base boot-sys boot-mezz] [
998999
set section make block! 200

0 commit comments

Comments
 (0)