protected void doAverageLine(byte[] curLine, byte[] prevLine) {
         // get the number of bytes per sample
        int sub = (int) Math.ceil((getBitsPerComponent() * getColors()) / 8.0); 
        
        for (int i = 0; i < curLine.length; i++) {
            int raw = 0;
            int prior = 0;
            
            // get the last value of this color
            int prevIdx = i - sub;
            if (prevIdx >= 0) {
                raw = curLine[prevIdx] & 0xff;
            }
            
            // get the value on the previous line
            if (prevLine != null) {
                prior = prevLine[i] & 0xff;
            }
            
            // add the average
            curLine[i] += (byte) Math.floor((raw + prior) / 2);
        }      
    }