code: def undo_filter_average(filter_unit, scanline, previous, result):
      
  
      ai = -filter_unit
      for i in range(len(result)):
          x = scanline[i]
          if ai < 0:
              a = 0
          else:
              a = result[ai]
          b = previous[i]
          result[i] = (x + ((a + b) >> 1)) & 0xff
          ai += 1
docs: Undo up filter.