forked from rebolsource/r3
-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
FEAT: added a simple codec for decoding/encoding ICO files
(cherry picked from commit fd67a59)
- Loading branch information
Showing
9 changed files
with
132 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
REBOL [ | ||
title: "REBOL 3 codec for ICO files" | ||
name: 'codec-ico | ||
author: rights: "Oldes" | ||
version: 0.0.1 | ||
history: [6-Mar-2021 "Oldes" {Initial version}] | ||
] | ||
|
||
system/options/log/ico: 2 | ||
register-codec [ | ||
name: 'ico | ||
title: "Windows icon or cursor file" | ||
suffixes: [%.ico %.cur] | ||
|
||
decode: function [ | ||
{Extract content of the ICO file} | ||
data [binary! file! url!] | ||
][ | ||
unless binary? data [ data: read data ] | ||
sys/log/info 'ICO ["^[[1;32mDecode ICO data^[[m (^[[1m" length? data "^[[mbytes )"] | ||
bin: binary data | ||
;- ICONDIR: | ||
binary/read bin [ tmp: UI16LE type: UI16LE num: UI16LE ] | ||
unless all [tmp = 0 any [type = 1 type = 2] ] [return none] | ||
icons: copy [] | ||
repeat n num [ | ||
binary/read bin [ | ||
width: UI8 | ||
height: UI8 | ||
colors: UI8 | ||
UI8 | ||
planes: UI16LE | ||
bpp: UI16LE | ||
size: UI32LE | ||
ofs: UI32LE | ||
] | ||
binary/read bin [ | ||
pos: INDEX | ||
ATz :ofs | ||
data: BYTES :size | ||
AT :pos | ||
] | ||
if width = 0 [width: 256] | ||
if height = 0 [height: 256] | ||
sys/log/more 'ICO ["Image^[[1;33m" n "^[[0;36mbpp:^[[33m" bpp "^[[36mcolors:^[[33m" colors "^[[36msize:^[[33m" as-pair width height] | ||
append/only icons reduce [width bpp data] | ||
] | ||
icons | ||
] | ||
encode: function [ | ||
data [block!] | ||
][ | ||
out: binary 30000 | ||
images: copy [] | ||
parse data [ | ||
some [ | ||
set file: file! ( | ||
bin: read/binary file | ||
if size: codecs/png/size? bin [ | ||
append/only images reduce ['png to integer! size/1 32 bin] | ||
] | ||
) | ||
] | ||
] | ||
imgs: length? images | ||
offset: 6 + (imgs * 16) | ||
img-data: clear #{} | ||
binary/write out [UI16LE 0 UI16LE 1 UI16LE :imgs] | ||
|
||
forall images [ | ||
set [type: size: bpp: bin:] images/1 | ||
bytes: length? bin | ||
if size = 256 [size: 0] | ||
binary/write out [ | ||
UI8 :size | ||
UI8 :size | ||
UI16LE 0 ;colors | ||
UI16LE 0 ;planes | ||
UI16LE :bpp | ||
UI32LE :bytes | ||
UI32LE :offset | ||
] | ||
append img-data bin | ||
offset: offset + length? bin | ||
] | ||
binary/write out img-data | ||
copy out/buffer | ||
] | ||
|
||
identify: function [data [binary!]][ | ||
parse b [#{0000} [#{0100} | #{0200}] to end] ;.ico or .cur | ||
] | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.