Compressing image data (bugs?)
[1/6] from: henrik::webz::dk at: 4-Dec-2003 14:57
Hi, all
Sometimes image handling baffles me a bit. I want to embed a small
2-colored image in the script for use in a button. It would of course be
nice to compress it to a chunk of binary data.
However, I always lose the size of the image when doing something with
it, which is highly impractical. If I have:
>> img: make image! [16x14 #{
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF000000000000FFFFFF
FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF... etc.
or
>> img: load %image.gif
and:
>> to-image decompress compress img
the size is lost, but the binary information remains.
So in order to keep size information, I would have to:
>> img-data: to-binary decompress #{
789CAD90410A003008C3FCFFA7DD6583516CD5CDDC94A688EE1CDB8888E4C5BF
F3E8675D515ECD915BF1B1C3808A7FF6B8EBF88C8EFF7BFFC4FFB23C9B5987F2
959BDDD3A5E22F920B1DFF80030000
}
>> img2: make image! [16x14 img-data]
But, img2 contains just 2 bytes set, and they are random, for each time
I set img2 by the above line. The remaining bytes are zero. It looks
like a bug?
But:
>> length? img2
gives the correct length though.
BTW: Just found by playing around that:
>> to-image to-binary img
Crashes Rebol 1.2.10.3.1, but runs perfectly in 1.2.1.3.1
Regards,
Henrik Mikael Kristensen
[2/6] from: henrik:webz:dk at: 4-Dec-2003 15:18
Henrik Mikael Kristensen wrote:
> Hi, all
> Sometimes image handling baffles me a bit. I want to embed a small
<<quoted lines omitted: 20>>
> I set img2 by the above line. The remaining bytes are zero. It looks
> like a bug?
Sorry, that's a blunder from my side. Of course I should use:
>> img2: make image! reduce [16x14 img-data]
Then it works...
Still, I'd like to know if there's an easier way to contain the image
size with the data.
Regards,
Henrik Mikael Kristensen
[3/6] from: g:santilli:tiscalinet:it at: 4-Dec-2003 15:44
Hi Henrik,
On Thursday, December 4, 2003, 3:18:36 PM, you wrote:
HMK> Still, I'd like to know if there's an easier way to contain the image
HMK> size with the data.
Just keep the image in the original format, i.e.:
image-data: read/binary %img.gif
Then later you can LOAD it:
img: load image-data
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amiga Group Italia sez. L'Aquila --- SOON: http://www.rebol.it/
[4/6] from: rotenca:telvia:it at: 4-Dec-2003 16:37
Hi, Henrik
given a Rebol image, a solution:
do decompress compress mold help.gif
Instead a more secure:
load decompress compress mold/all help.gif
fails for a load bug (Feedback Id #31r704220):
>> load mold/all help.gif
** Syntax Error: Invalid construct -- #[
** Near: (line 522) #[image! 48x48 #{
---
Ciao
Romano
[5/6] from: henrik:webz:dk at: 4-Dec-2003 16:48
Gabriele Santilli wrote:
> Hi Henrik,
> On Thursday, December 4, 2003, 3:18:36 PM, you wrote:
<<quoted lines omitted: 4>>
> Then later you can LOAD it:
> img: load image-data
It works! Never thought of using LOAD that way. Thanks! :-)
Regards,
Henrik Mikael Kristensen
[6/6] from: carl:cybercraft at: 24-Dec-2003 22:50
On 05-Dec-03, Henrik Mikael Kristensen wrote:
> Gabriele Santilli wrote:
>> Hi Henrik,
<<quoted lines omitted: 6>>
>> img: load image-data
> It works! Never thought of using LOAD that way. Thanks! :-)
Also, if you're dealing with an image created by REBOL, you could use
save/png to create a compressed binary of the image. ie...
>> pic: to-image layout [backdrop black box "A picture"]
== make image! [140x140 #{
000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000...
>> length? pic
== 78400
>> save/png shrunk-pic: make binary! [] pic
>> length? shrunk-pic
== 301
>> view layout [image load shrunk-pic]
--
Carl Read
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted