From: José Fonseca Date: Tue, 30 Oct 2012 15:54:04 +0000 (+0000) Subject: Support grayscale PNM in retracediff.py X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=0ee878906f76cfe44ea6206112179600501efe52;p=apitrace Support grayscale PNM in retracediff.py --- diff --git a/scripts/retracediff.py b/scripts/retracediff.py index 8a0837a..d665c76 100755 --- a/scripts/retracediff.py +++ b/scripts/retracediff.py @@ -98,7 +98,15 @@ def read_pnm(stream): magic = stream.readline() if not magic: return None, None - assert magic.rstrip() == 'P6' + magic = magic.rstrip() + if magic == 'P5': + channels = 1 + mode = 'L' + elif magic == 'P6': + channels = 3 + mode = 'RGB' + else: + raise Exception('Unsupported magic `%s`' % magic) comment = '' line = stream.readline() while line.startswith('#'): @@ -107,8 +115,8 @@ def read_pnm(stream): width, height = map(int, line.strip().split()) maximum = int(stream.readline().strip()) assert maximum == 255 - data = stream.read(height * width * 3) - image = Image.frombuffer('RGB', (width, height), data, 'raw', 'RGB', 0, 1) + data = stream.read(height * width * channels) + image = Image.frombuffer(mode, (width, height), data, 'raw', mode, 0, 1) return image, comment