summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorJosé Fonseca <jfonseca@vmware.com>2014-11-07 11:33:00 +0000
committerJosé Fonseca <jfonseca@vmware.com>2014-11-07 11:33:00 +0000
commit983407090388198c8e6e48c97f4100727b8af116 (patch)
treefbf83dbccca9b35107f63a9aa6f9cd8e0c832b4a /scripts
parent35905ec389fd2467fb644f3f6428148fbdb98bb5 (diff)
scripts/jsonextractimages: Use the appropriate file extension.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/jsonextractimages.py21
1 files changed, 20 insertions, 1 deletions
diff --git a/scripts/jsonextractimages.py b/scripts/jsonextractimages.py
index c47ffc8c..ea1c927d 100755
--- a/scripts/jsonextractimages.py
+++ b/scripts/jsonextractimages.py
@@ -34,12 +34,31 @@ import base64
import sys
+pngSignature = "\x89\x50\x4E\x47\x0D\x0A\x1A\x0A"
+
+
def dumpSurfaces(state, memberName):
for name, imageObj in state[memberName].iteritems():
data = imageObj['__data__']
data = base64.b64decode(data)
- imageName = '%s.png' % name
+ if data.startswith(pngSignature):
+ extName = 'png'
+ else:
+ magic = data[:2]
+ if magic in ('P1', 'P4'):
+ extName = 'pbm'
+ elif magic in ('P2', 'P5'):
+ extName = 'pgm'
+ elif magic in ('P3', 'P6'):
+ extName = 'ppm'
+ elif magic in ('Pf', 'PF'):
+ extName = 'pfm'
+ else:
+ sys.stderr.write('warning: unsupport Netpbm format %s\n' % magic)
+ continue
+
+ imageName = '%s.%s' % (name, extName)
open(imageName, 'wb').write(data)
sys.stderr.write('Wrote %s\n' % imageName)