[DGD] PNG construction

Par Winzell zell at skotos.net
Fri Apr 5 21:44:19 CEST 2002


>>private inherit "/lib/string";
> 
> 
> Is spaces() the only thing you use from /lib/string.c?  Not that it's
> hard to guess for others what it does... ;-)

[snipped source] Thanks, forgot about that. That's also one of those things 
that a real implementation would want to optimize... most of those blocks 
could be allocated just once and re-used automatically with DGD's copy- 
on-write behaviour, I guess.

> I noticed the 'compress' flag being 0, this means that a 32 x 32 image
> of 8 bit grayscale will be 1024 bytes in size.  Not too bad for
> generating small images but might get a little bit out of hand for,
> for instance, generating game maps or graphs on the fly that contain a
> lot of background colour.

It's not quite that simple. The compress byte is not a flag, but the method 
used -- '0' is the only one currently implemented, and it's the 'deflate' 
method of 'zlib'. However, the zlib stream -does- have an 'uncompressed' 
scheme, so the blocks are raw data. The other two choices are 'deflate with 
dynamic Huffman' and 'deflate with static Huffman'. Both implement more or 
less the 'gzip' algorithm -- the Lempel-Ziv (spelling?) algorithm from '77 
or so.

I wrote an implementation of that myself in my distant youth, and while I'm 
sure I could do it five times as fast now, it's still a non-trivial project 
-- figure at least a day's work to write and another to debug. I also don't 
think LPC is suited to quite that level of bit-fiddling -- it'd probably at 
least quadruple the amount of time it'd take to generate an image.

I do wish the PNG implementation had come with an uncompressed option, and 
also a simpler compression scheme, for exactly this kind of thing. Even a 
run-length encoding of the scanlines would've been nice.

Of course, any serious use of generated images in DGD should offload the 
task to a standalone server -- should be quite trivial to build one -- one 
that accepts incoming requests like 'construct an image using this binary 
data: blah blah blah' and gets in return a PNG data stream, or perhaps more 
pragmatic, a URL to a .png file it just created that's reachable by Apache 
running on the same machine.

Zell

_________________________________________________________________
List config page:  http://list.imaginary.com/mailman/listinfo/dgd



More information about the DGD mailing list