docs: def _filter_scanline(self, filter_type, line, result):
          """
          Apply a scanline filter to a scanline.
  
          `filter_type` specifies the filter type (0 to 4)
          'line` specifies the current (unfiltered) scanline as a sequence
          of bytes;
          """
          assert 0 <= filter_type < 5
          if self.prev is None:
              # We're on the first line.  Some of the filters can be reduced
              # to simpler cases which makes handling the line "off the top"
              # of the image simpler.  "up" becomes "none"; "paeth" becomes
              # "left" (non-trivial, but true). "average" needs to be handled
              # specially.
              if filter_type == 2:  # "up"
                  filter_type = 0
              elif filter_type == 3:
                  self.prev = newBarray(len(line))
              elif filter_type == 4:  # "paeth"
                  filter_type = 1
  
          if filter_type == 1:
              self.__do_filter_sub(line, result)
          elif filter_type == 2:
              self.__do_filter_up(line, result)
          elif filter_type == 3:
              self.__do_filter_average(line, result)
          elif filter_type == 4:
              self.__do_filter_paeth(line, result)