code: def undo_filter(self, filter_type, scanline, previous):
          
  
          # :todo: Would it be better to update scanline in place?
          result = scanline
  
          if filter_type == 0:
              return result
  
          if filter_type not in (1, 2, 3, 4):
              raise FormatError(
                  'Invalid PNG Filter Type.  '
                  'See http://www.w3.org/TR/2003/REC-PNG-20031110/#9Filters .')
  
          # Filter unit.  The stride from one pixel to the corresponding
          # byte from the previous pixel.  Normally this is the pixel
          # size in bytes, but when this is smaller than 1, the previous
          # byte is used instead.
          fu = max(1, self.psize)
  
          # For the first line of a pass, synthesize a dummy previous
          # line.  An alternative approach would be to observe that on the
          # first line 'up' is the same as 'null', 'paeth' is the same
          # as 'sub', with only 'average' requiring any special case.
          if not previous:
              previous = bytearray([0] * len(scanline))
  
          # Call appropriate filter algorithm.  Note that 0 has already
          # been dealt with.
          fn = (None,
                undo_filter_sub,
                undo_filter_up,
                undo_filter_average,
                undo_filter_paeth)[filter_type]
          fn(fu, scanline, previous, result)
          return result
docs: Undo the filter for a scanline.
          `scanline` is a sequence of bytes that
          does not include the initial filter type byte.
          `previous` is decoded previous scanline
          (for straightlaced images this is the previous pixel row,
          but for interlaced images, it is
          the previous scanline in the reduced image,
          which in general is not the previous pixel row in the final image).
          When there is no previous scanline
          (the first row of a straightlaced image,
          or the first row in one of the passes in an interlaced image),
          then this argument should be ``None``.
  
          The scanline will have the effects of filtering removed;
          the result will be returned as a fresh sequence of bytes.