Andreas Schiffler wrote:
I think you could create a loader that uses for example LZF
http://www.goof.com/pcg/marc/liblzf.html to compress data (faster than
GIF or PNG), but since surface data is organized in memory-aligned lines
(hence the use of pitch), you may not benefit much in terms of speed.
Also, depending on you image data, the compression ratio may be very poor.
Some information that might help with eval of liblzf for your needs:
LZF is very fast, but the last time I looked, it has a fixed
sliding dictionary of 8KB, a block size of 64KB, and rather
inefficient (but fast) literal run encoding. It’s designed for
read/write speed. The trouble is the write speed. LZF must
sacrifice lots of compression size performance for speed.
I assume that a loader should care more about read speed. For
write, in order to be blindingly fast, LZF does a single hash
lookup for each byte position, plus IIRC, optional limited hash
table updates. This is pretty inefficient compression.
For the Canterbury Corpus, LZF with a 16 bit hash is 38% larger
than the worst gzip (gzip -1), or 63% larger than gzip -9. Well,
incidentally I have modified LZF to pick best matches, and the
best it can do is still 23% larger than gzip -1, and 46% versus
gzip -9.
So from the looks of it, LZF will not come remotely close to PNG,
if you are evaluating in terms of compression ratio. What LZF can
give you is, since it is so fast, your loads will be dominated by
I/O performance and the processor load will be low, but which the
average user will probably not notice unless they use a CPU monitor.> Mason Wheeler wrote:
I’d like to try to save images to disc in SDL_surface format for fast
loading. I’ve got most of it figured out, but there are a couple
things I need to know.
- What’s the formula for calculating the total size of the Pixels
member? Would “h * pitch * format.BytesPerPixel” work, or is it more
complicated?
- Are there any fields in the SDL_surface record that don’t need to
be (or shouldn’t be) saved and reloaded at runtime? It looks to me
like the hwdata, blitmap, locked, clip_rect, format_version and
refcount fields are things that should be generated by SDL at runtime,
and format should be checked carefully to make sure it’s compatible
with the pixels you’ve got saved. Are these correct? Anything else?
–
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia