Re: Packbits implementation
- From: sicklittlemonkey <Nick.Westgate@xxxxxxxxx>
- Date: Sat, 7 Feb 2009 06:28:50 -0800 (PST)
On Feb 7, 12:38 pm, "Anton Treuenfels" <atreuenf...@xxxxxxxxxxxxx>
wrote:
"BLuRry" <brendan.rob...@xxxxxxxxx> wrote in message
news:1223fa52-6cea-4775-b2ef-8b2960b4b768@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
I managed to get 15%-50% compression on hi-res images with the
following packbits-based scheme:
Fetch byte N
If zero, we're done
If positive (0-127), store N bytes as-is directly
If negative (128-255), strip hi-bit from N and read bytes A and B
next, then repeat AB a total of N+2 times.
I picked repeating 2-byte patterns to get as much compression on solid-
color regions as possible, and most hi-res bit patterns repeat every 2
bytes, not every byte.
Simplicity is good, but with only a minor increase in complexity you could
make that a little more general by checking more than one possible pattern
type (on the compression side), such as every byte, byte pairs, triplets,
whatever, and including a single header byte to inform the decompressor
which one gave the best compression.
I did a similar scheme once that checked not successive bytes, but every
byte, then every second byte, every fourth and every eighth (but then
graphics memory is organized differently on a C64).
Turns out most of the images in the set I was compressing became smallest
with every second byte (IIRC), but every so often one of the others would be
picked.
- Anton Treuenfels
That's a good suggestion for a general purpose scheme. But Brendan is
coding for Apple II hires, which repeats solid colours in byte pairs
(double hires needs 4 bytes) and it's to be immediately piped over a
serial connection so speed is of the essence.
For general cases, LZ compression is a better choice as it dynamically
adapts in the same way that the multiple testing you suggest does, and
the decompressor is not much more compilcated.
Cheers,
Nick.
.
- References:
- Packbits implementation
- From: BLuRry
- Re: Packbits implementation
- From: Anton Treuenfels
- Packbits implementation
- Prev by Date: Re: Packbits implementation
- Next by Date: Re: Packbits implementation
- Previous by thread: Re: Packbits implementation
- Next by thread: Re: Packbits implementation
- Index(es):
Relevant Pages
|