1*11497Sralph /* update.c 4.1 83/03/09 */ 2*11497Sralph /* 3*11497Sralph * update: the key output optimization routine of the whole editor. 4*11497Sralph * The input consists of two bit matrices (mold is what's on the screen, 5*11497Sralph * mnew is what we want to be on the screen) and the coordinates of 6*11497Sralph * the lower left corner on the screen where this matrix is. 7*11497Sralph * This routine does whatever is necessary to get the screen to look 8*11497Sralph * like mnew, assuming that it currently looks like mold. 9*11497Sralph * 10*11497Sralph * (If I could patent this process for bread and other food I 11*11497Sralph * would be a rich man.) 12*11497Sralph */ 13*11497Sralph 14*11497Sralph #include "bit.h" 15*11497Sralph 16*11497Sralph update(mold, mnew, rows, cols, baser, basec) 17*11497Sralph bitmat mold, mnew; 18*11497Sralph int rows, cols, baser, basec; 19*11497Sralph { 20*11497Sralph int irow; 21*11497Sralph register int i, j, k; 22*11497Sralph int r1, r2, c1, c2, nr1, nr2, nc1, nc2; 23*11497Sralph extern int QUIET; 24*11497Sralph 25*11497Sralph #ifdef TRACE 26*11497Sralph if (trace) 27*11497Sralph fprintf(trace, "update(mold=%x, mnew=%x, rows=%d, cols=%d, baser=%d, basec=%d)\n", mold, mnew, rows, cols, baser, basec); 28*11497Sralph #endif 29*11497Sralph 30*11497Sralph if (QUIET) 31*11497Sralph return; 32*11497Sralph aminmax(mold, rows, cols, &r1, &c1, &r2, &c2); 33*11497Sralph aminmax(mnew, rows, cols, &nr1, &nc1, &nr2, &nc2); 34*11497Sralph r1 = min(r1, nr1); r2 = max(r2, nr2); 35*11497Sralph c1 = min(c1, nc1); c2 = max(c2, nc2); 36*11497Sralph 37*11497Sralph dumpmat("mold:", mold, rows, cols); 38*11497Sralph dumpmat("mnew:", mnew, rows, cols); 39*11497Sralph 40*11497Sralph for (i=r1; i<=r2; i++) { 41*11497Sralph irow = baser + rows - i - 1; 42*11497Sralph if (emptyrow(mnew, rows, cols, i)) { 43*11497Sralph if (emptyrow(mold, rows, cols, i)) { 44*11497Sralph continue; /* identically blank. skip. */ 45*11497Sralph } 46*11497Sralph /* 47*11497Sralph * Row i is to be cleared. Look for some more 48*11497Sralph * rows to clear and do it all at once. 49*11497Sralph */ 50*11497Sralph for (j=i+1; j<rows && emptyrow(mnew,rows,cols,j); j++) 51*11497Sralph ; 52*11497Sralph areaclear(baser+rows-j, basec, irow, basec+cols-1); 53*11497Sralph i = j-1; /* skip the others */ 54*11497Sralph } else for (j=c1; j<=c2; j++) { 55*11497Sralph /* 56*11497Sralph * Result row is not all blank. We look for stretches 57*11497Sralph * of bits that have to be changed (in either 58*11497Sralph * direction) and draw an exclusive or line over all 59*11497Sralph * the bits in each stretch. 60*11497Sralph */ 61*11497Sralph if (mat(mold,rows,cols,i,j,1)!=mat(mnew,rows,cols,i,j,2)){ 62*11497Sralph for (k=j+1; k<cols && mat(mold,rows,cols,i,k,3)!= 63*11497Sralph mat(mnew,rows,cols,i,k,4); k++) 64*11497Sralph ; 65*11497Sralph k--; 66*11497Sralph setxor(); 67*11497Sralph line(basec+j, irow, basec+k, irow); 68*11497Sralph j = k; /* skip the others */ 69*11497Sralph } 70*11497Sralph } 71*11497Sralph } 72*11497Sralph } 73