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