[REBOL] do %image.png
From: jasonic:panix at: 14-Nov-2001 14:47
My objective is to implement a roundtrip toolkit with /Core and /View
interfaces for embedding, extracting and running REBOL scripts embedded in
images. Then the real fun can begin!
I have made a little progess:
A tiny hardcoded test is now working :-)
buddha.png is a PNG image file with a REBOL script embedded in it.
I used TweakPNG (Win32only) to learn about PNG and inset my REBOL script.
By design I insert a special keyword "REBOLscript" after the "tEXt" chunk to
help parsing. Also, a special REBOL end of script marker ";EOF" at the end
of test script itself. The helps parsing the REBOL script end from other
data or padding in the PNG file.
It takes about 6 seconds to store 29kb image file as a string on a 500Mhz
PIII Win98se Vaio laptop.
Lots of features and funtions to implement.
But first I need some basic advice:
Q1. How can I improve the time to load PNG into a rebol string?
Q2. What other approach do you suggest than the one I am following?
thanks for any feedback
REBOL [ File: %buddha.r]
;download or read from http://www.postcardscience/rebol/buddha.png
buddha: read/binary %buddha.png
b: "" for i 1 length? buddha 1 [append b to-char buddha/:i]
; 7 seconds for 29Kb image on 500MhzPIII
; head b ; make sure we are at the beginning when debugging in REBOL shell
search-key: "tEXtREBOLscript" ; better than just looking for "REBOL"
header-key: "REBOL " ; space after REBOL should mean it's the
tail-key: ";EOF" ; by design, this marks end of REBBOl
; later probably will want to include #!path-to-rebol and find those first
b: find next b search-key ; start of our tEXt chunk containing REBOL
b: find next b header-key ; start of the script
start-mark: length? b ; how many bytes to end of PNG file
bend: find next b tail-key ; end of script
end-mark: length? bend ; how many bytes to chop off
script-length: start-mark - end-mark ; how many bytes to use of 'script
for i 1 script-length 1 [append script b/:i] ; chop the end off so we have
write %buddha-script.r script ; save it to file
do %buddha-script.r ; test it!