def testUnfilterScanlinePaeth(self): """This tests more edge cases in the paeth unfilter""" scanprev = array('B', [2, 0, 0, 0, 9, 11]) scanline = array('B', [4, 6, 10, 9, 100, 101, 102]) filter_ = png.Filter(24, prev=scanprev) out = filter_.undo_filter(scanline[0], scanline[1:]) self.assertEqual(list(out), [8, 10, 9, 108, 111, 113]) # paeth
def testFilterScanline(self): """Test filtering with previous line""" prev = array('B', [20, 21, 22, 210, 211, 212]) line = array('B', [30, 32, 34, 230, 233, 236]) filter_ = png.Filter(24, prev=prev) res = filter_.filter_all(line) # None self.assertEqual(list(res[0]), [0, 30, 32, 34, 230, 233, 236]) # sub self.assertEqual(list(res[1]), [1, 30, 32, 34, 200, 201, 202]) # up self.assertEqual(list(res[2]), [2, 10, 11, 12, 20, 22, 24]) # average self.assertEqual(list(res[3]), [3, 20, 22, 23, 110, 112, 113]) # paeth self.assertEqual(list(res[4]), [ 4, self.paeth(30, 0, 20, 0), self.paeth(32, 0, 21, 0), self.paeth(34, 0, 22, 0), self.paeth(230, 30, 210, 20), self.paeth(233, 32, 211, 21), self.paeth(236, 34, 212, 22) ])
def testFilterScanlineFirstLine(self): """Test filter without previous line""" line = array('B', [30, 31, 32, 230, 231, 232]) filter_ = png.Filter(24, prev=None) res = filter_.filter_all(line) # none self.assertEqual(list(res[0]), [0, 30, 31, 32, 230, 231, 232]) # sub self.assertEqual(list(res[1]), [1, 30, 31, 32, 200, 200, 200]) # up self.assertEqual(list(res[2]), [2, 30, 31, 32, 230, 231, 232]) # average self.assertEqual(list(res[3]), [3, 30, 31, 32, 215, 216, 216]) # paeth self.assertEqual(list(res[4]), [ 4, self.paeth(30, 0, 0, 0), self.paeth(31, 0, 0, 0), self.paeth(32, 0, 0, 0), self.paeth(230, 30, 0, 0), self.paeth(231, 31, 0, 0), self.paeth(232, 32, 0, 0) ])
def undo_filter(filter_type, line, prev): """undoing filter""" filter_ = png.Filter(24, prev=prev) line = array('B', line) return filter_.undo_filter(filter_type, line)