[comp.dcom.fax] Looking for fax encoding/decoding source

gstiehl@convex.com (Greg Stiehl) (12/21/90)

I'm looking for source (or algorithms) for fax run-length encoding 
and decoding.  I would be interested in both C and assembly.  Does
anyone have source that they don't mind sharing?

Thanks,

Greg Stiehl (gstiehl@convex.com)
Convex Computer Corp.
Richardson, TX

hatandog@medusainformatik.uni-erlangen.de (Hakan 'Elric' Tandogan) (12/21/90)

gstiehl@convex.com (Greg Stiehl) writes:


>I'm looking for source (or algorithms) for fax run-length encoding 
>and decoding.  I would be interested in both C and assembly.  Does
>anyone have source that they don't mind sharing?

Sorry about this, but I just *have* to include the
-----------most obvious and well-known---------------


	   M  E    T  O   O  !

	   cry...

	   bye ;)

raymond@cosc.canterbury.ac.nz (cantva) (05/06/91)

gstiehl@convex.com (Greg Stiehl) writes:
 
>I'm looking for source (or algorithms) for fax run-length encoding 
>and decoding.  I would be interested in both C and assembly.  Does
>anyone have source that they don't mind sharing?

A simple algorithm can be whipped up very quickly:

[1] Decide on size of counter for run lengths (say 8 bits) 

[2] Decide on which bit to start with (say 0 (white space))

[3] Set current colour to that set in [2]

[4] Read fax image (scanning bitwise) counting bits of the current colour
    until you encounter a different one or get to 256 bits or encounter
    the end of the fax

[5] Write out the number arrived at in 4

[6] Invert the current colour (ie 1->0, 0->1)

[7] If not at end of file go to [4].

To decode do the following:

[1] Take starting colour to be the same as taken when encoding, and the
    size of the counter to be that used when encoding

[2] read a number from the file

[3] Write that many *bits* of that colour

[4] Invert current colour

[5] If not at end of file go to [2].


This is, admittedly, primitive but quick and easy to implement.

Now if you want real compression use adaptive arithmetic coding. This rather
more tricky to code but miles better compression.

In fact, I seem to have such a program I wrote a while ago that does this
very well indeed (better than Group 4).  Let me know if you are interested. 

Raymond.

--
Raymond Wilson.	email:	raymond@cosc.canterbury.ac.nz
		snail:	c/- Computer Science Department,
			University of Canterbury,
			New Zealand.