]> git.cworth.org Git - apitrace/blobdiff - scripts/retracediff.py
d2d: Eliminate custom tracers.
[apitrace] / scripts / retracediff.py
index ee5730ab4988178dba51e6f9a6feb1a6dac647e5..d665c7601b7acf7a91ef3708fd521c4165e0891f 100755 (executable)
@@ -37,7 +37,7 @@ import sys
 from PIL import Image
 
 from snapdiff import Comparer
-from highlight import Highlighter
+from highlight import AutoHighlighter
 import jsondiff
 
 
@@ -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
 
 
@@ -178,7 +186,7 @@ def main():
     else:
         output = sys.stdout
 
-    highligher = Highlighter(output)
+    highligher = AutoHighlighter(output)
 
     highligher.write('call\tprecision\n')