[comp.sys.amiga] Run length encoding for hp paintjet.

rminnich@metropolis.super.org (Ronald G Minnich) (08/09/88)

Well i got the paintjet driver from swan.ulowell.edu (Thanks bob!)
and it works great. One thing that it does not do, however, from 
what i can see: run length encoding. Maybe the author(s) thought
it was too complicated. Well, it is so simple that even I could write
it, so here is an excerpt from something i wrote* that does run-length
encoding. The win is a big one, like at least a factor of four, maybe
more in print speed.

* well, really, someone else wrote it and i did RLE

Here we go:

/* tell the paintjet to go to graphics, and tell it we will send RLE data */
   fprintf(printer, "\033*r0A\033*b1M") ;
/* OK, this loop is copying from p to q, p uncompressed, q is rle, 
 * and p ends at 'endrow' */
    while(p < endrow)  
/* the run-count state machine */
/* the following by ron minnich for paintjet mode 1.
 * IT is not the tightest code in the universe, but is designed
 * for clarity. THe tradeoff is ok, since run-coding buys at least
 * a factor of two in output time, so hot code is not a big deal.
 */
start:
/* p, q, and old are char *; i is an int; real clear names, huh?
 * and i even have a goto!
 */
	old = q++;
	i = 0;
        *old = 0;
        *q = *p++;
rleloop:
	if (p >= endrow)
		continue;
	if (i > 255)
		goto newcode;	
	if (*p != *q)
		goto newcode;
	*old = ++i;
	p++;
	goto rleloop;
newcode:
	q++;
	/* let the for-loop code check p < endrow */
	}
      q++;
/*
 *   Now we actually write the stuff to the printer.
 */
      fprintf(printer, "\033*b%dW", q-row) ;
/* i omited an fwrite by mistake, but i think it looks like: */
      fwrite(q, 1, q-row, file);
/* or something like that. You get my drift */
ron
P.S. I am going to see if it is worth adding an RLE packet type to DNET.
might be a win