Re: Packbits implementation



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.
.



Relevant Pages

  • Re: compression type
    ... from what I understand most compression techniques try to use ... So take for example repeat ... so what happens if you say in geometric area what ... is to draw say a curve in the sphere through each word as what you say ...
    (comp.compression)
  • Re: 100 megaton bombs atop Saturn V rockets
    ... >>since it could be made to work without compression. ... Super" the scheme for a self-sustaining combustion wave in uncompressed ... > Probably not, a) because fusion fuel is pretty light, and b) because ... cryotank of liquid deuterium, like the Saturn upper stage or the Shuttle ...
    (sci.space.history)
  • Re: 100 megaton bombs atop Saturn V rockets
    ... >>since it could be made to work without compression. ... Super" the scheme for a self-sustaining combustion wave in uncompressed ... > Probably not, a) because fusion fuel is pretty light, and b) because ... cryotank of liquid deuterium, like the Saturn upper stage or the Shuttle ...
    (sci.space.policy)
  • Re: 4-level image compression ?
    ... I have my doubts as to how well the coding scheme used by JPEG-LS will ... work with 2bpp images. ... scheme, but it is sounding like it is using rice-coding for the residuals. ... 2-bits per item with 2-bpp input means no compression, or worse, inflation. ...
    (comp.compression)
  • Re: Heres an idea...
    ... used to represent other media. ... diffirent parts of the media tend not to repeat or have LOTs of minor ... affects the compression ratio. ... similar blocks "should" also have similar MDCT blocks (especially if the ...
    (comp.compression)