docs: def do_filter(self, filter_type, line):
          """
          Applying filter, caring about prev line, interlacing etc.
  
          `filter_type` may be integer to apply basic filter or
          adaptive strategy with dict
          (`name` is reqired field, others may tune strategy)
          """
          # Recall that filtering algorithms are applied to bytes,
          # not to pixels, regardless of the bit depth or colour type
          # of the image.
  
          line = bytearray(line)
          if isinstance(filter_type, int):
              res = bytearray(line)
              self._filter_scanline(filter_type, line, res)
              res.insert(0, filter_type)  # Add filter type as the first byte
          else:
              res = self.adaptive_filter(filter_type, line)
          self.prev = line
          if self.restarts:
              self.restarts[0] -= 1
              if self.restarts[0] == 0:
                  del self.restarts[0]
                  self.prev = None
          return res