xref: /csrg-svn/old/lib2648/update.c (revision 18789)
111497Sralph /*
2*18789Sdist  * Copyright (c) 1980 Regents of the University of California.
3*18789Sdist  * All rights reserved.  The Berkeley software License Agreement
4*18789Sdist  * specifies the terms and conditions for redistribution.
5*18789Sdist  */
6*18789Sdist 
7*18789Sdist #ifndef lint
8*18789Sdist static char sccsid[] = "@(#)update.c	5.1 (Berkeley) 04/26/85";
9*18789Sdist #endif not lint
10*18789Sdist 
11*18789Sdist /*
1211497Sralph  * update: the key output optimization routine of the whole editor.
1311497Sralph  * The input consists of two bit matrices (mold is what's on the screen,
1411497Sralph  * mnew is what we want to be on the screen) and the coordinates of
1511497Sralph  * the lower left corner on the screen where this matrix is.
1611497Sralph  * This routine does whatever is necessary to get the screen to look
1711497Sralph  * like mnew, assuming that it currently looks like mold.
1811497Sralph  *
1911497Sralph  * (If I could patent this process for bread and other food I
2011497Sralph  * would be a rich man.)
2111497Sralph  */
2211497Sralph 
2311497Sralph #include "bit.h"
2411497Sralph 
update(mold,mnew,rows,cols,baser,basec)2511497Sralph update(mold, mnew, rows, cols, baser, basec)
2611497Sralph bitmat mold, mnew;
2711497Sralph int rows, cols, baser, basec;
2811497Sralph {
2911497Sralph 	int irow;
3011497Sralph 	register int i, j, k;
3111497Sralph 	int r1, r2, c1, c2, nr1, nr2, nc1, nc2;
3211497Sralph 	extern int QUIET;
3311497Sralph 
3411497Sralph #ifdef TRACE
3511497Sralph 	if (trace)
3611497Sralph 		fprintf(trace, "update(mold=%x, mnew=%x, rows=%d, cols=%d, baser=%d, basec=%d)\n", mold, mnew, rows, cols, baser, basec);
3711497Sralph #endif
3811497Sralph 
3911497Sralph 	if (QUIET)
4011497Sralph 		return;
4111497Sralph 	aminmax(mold, rows, cols, &r1, &c1, &r2, &c2);
4211497Sralph 	aminmax(mnew, rows, cols, &nr1, &nc1, &nr2, &nc2);
4311497Sralph 	r1 = min(r1, nr1); r2 = max(r2, nr2);
4411497Sralph 	c1 = min(c1, nc1); c2 = max(c2, nc2);
4511497Sralph 
4611497Sralph 	dumpmat("mold:", mold, rows, cols);
4711497Sralph 	dumpmat("mnew:", mnew, rows, cols);
4811497Sralph 
4911497Sralph 	for (i=r1; i<=r2; i++) {
5011497Sralph 		irow = baser + rows - i - 1;
5111497Sralph 		if (emptyrow(mnew, rows, cols, i)) {
5211497Sralph 			if (emptyrow(mold, rows, cols, i)) {
5311497Sralph 				continue;	/* identically blank. skip. */
5411497Sralph 			}
5511497Sralph 			/*
5611497Sralph 			 * Row i is to be cleared.  Look for some more
5711497Sralph 			 * rows to clear and do it all at once.
5811497Sralph 			 */
5911497Sralph 			for (j=i+1; j<rows && emptyrow(mnew,rows,cols,j); j++)
6011497Sralph 				;
6111497Sralph 			areaclear(baser+rows-j, basec, irow, basec+cols-1);
6211497Sralph 			i = j-1;	/* skip the others */
6311497Sralph 		} else for (j=c1; j<=c2; j++) {
6411497Sralph 			/*
6511497Sralph 			 * Result row is not all blank.  We look for stretches
6611497Sralph 			 * of bits that have to be changed (in either
6711497Sralph 			 * direction) and draw an exclusive or line over all
6811497Sralph 			 * the bits in each stretch.
6911497Sralph 			 */
7011497Sralph 			if (mat(mold,rows,cols,i,j,1)!=mat(mnew,rows,cols,i,j,2)){
7111497Sralph 				for (k=j+1; k<cols && mat(mold,rows,cols,i,k,3)!=
7211497Sralph 					mat(mnew,rows,cols,i,k,4); k++)
7311497Sralph 					;
7411497Sralph 				k--;
7511497Sralph 				setxor();
7611497Sralph 				line(basec+j, irow, basec+k, irow);
7711497Sralph 				j = k;	/* skip the others */
7811497Sralph 			}
7911497Sralph 		}
8011497Sralph 	}
8111497Sralph }
82