* @param state
     * @throws java.io.IOException
     */
    static void resetRuns(BitStream outb, G4State state) throws IOException {
        //System.err.println("EOL! "+state.a0);
        state.white = true;
        addRun(0, state, outb);
        if (state.a0 != state.width) {
            //System.out.println( (state.a0 < state.width ? "Premature EOL" : "Line length mismatch") );
            while (state.a0 > state.width)
                state.a0 -= state.cur[--state.curIndex];
            if (state.a0 < state.width) {
                if (state.a0 < 0)
                    state.a0 = 0;
                if ((state.curIndex & 0x1) != 0)
                    addRun(0, state, outb);
                addRun(state.width - state.a0, state, outb);
            } else if (state.a0 > state.width) {
                addRun(state.width, state, outb);
                addRun(0, state, outb);
            }
        }
        int tmp[] = state.ref;
        state.ref = state.cur;
        state.cur = tmp;
        //now zero out extra spots for runs
        for (int i = state.curIndex; i < state.width; i++)
            state.ref[i] = 0;
        for (int i = 0; i < state.width; i++)
            state.cur[i] = 0;
        state.runLength = 0;
        state.a0 = 0;
        state.b1 = state.ref[0];
        state.refIndex = 1;
        state.curIndex = 0;

        outb.close();
    }