[ptx] RLE encoding images.

Pablo d'Angelo pablo.dangelo at web.de
Tue May 4 11:04:14 BST 2004


On Tue, 04 May 2004, Terje Mathisen wrote:

> ptx-bounces at email-lists.org wrote:
> 
> >On Mon, 03 May 2004, Kai-Uwe Behrmann wrote:
> >
> >
> >>Am 03.05.04, 18:58 +0200 schrieb Pablo d'Angelo:
> >>
> >>
> >>>Ok, I'll save the tiff files like that. Internally I'll use 8 bit alpha
> >>>channels.
> >>
> >>This or the bit approach, You mentioned, seems to be an clever solution
> >>internally.
> >
> >
> >Hmm, bits are clumsy to access in C. However, an even better approach to
> >store most masks would be a run length encoded image (RLE encoding every
> >row separately). For the typical mask the storage would only cost a few
> >bytes for every row.
> >
> >Now we just need vigra::RLEImage.
> 
> I suggest a very simple encoding:
> 
> [count][value] pairs stored as unsigned bytes. This could require a few 
> extra pairs for very long repeat counts, but at 128:1 compression, it 
> really doesn't matter.
> 
> If you want to be fancy, then you use the fact that a repeat count of 
> zero is impossible: Instead, this means that the next byte will be a 
> count of uncompressed bytes following:
> 
> [0][count][a,b,c,d,e,...]
> 
> I.e. you'd use this for graduated masks where the repeat count averages 
> less than two.

Yes, that sounds quite nice. However, I want to stick to the vigra idea and
write a generic RLEImage<PixelType> class that can work with any pixel type,
not just bytes. therefore I plan to use two arrays, one for the pixels and
one for the count's. Then it would be possible to use other image types as
well.

I'd also like to provide iterators, so that I can modify RLE encoded images
directly, without completely decoding. Should be very efficient for
situations where no random access is needed, and even for random access, it
should be quite fast for the typical mask image with huge uniform areas. I
suspect the memory accesses on big images are a real performance killer, so
its probably even faster than the usual bitmap.

But I have to complete the image import with alphachannels first.

After RLEImage and the corresponding interators and accessors have been
implemented. I just need to replace "BImage" with "RLEBImage" at a few
places in the sourcecode. This will be the first time when I can really
benefit from vigra's flexibility, I hope.

ciao
  Pablo


More information about the ptX mailing list