Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(260)

Side by Side Diff: experimental/tools/mskp_parser.py

Issue 2268403003: experimental/tools/mskp_parser.py (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2
3 # Copyright 2016 Google Inc.
4 #
5 # Use of this source code is governed by a BSD-style license that can be
6 # found in the LICENSE file.
7
8 # Experimental Skia Multi-Picture Doc parser.
9
10 from __future__ import print_function
11
12 import fileinput
13 import sys
14 import struct
15
16 if len(sys.argv) < 2:
17 sys.stderr.write('Usage:\n\tpython %s MSKP_FILE [OUTPUT_SKP]\n\n'
18 % sys.argv[0])
19 exit(1)
20
21 mskp_src = sys.argv[1]
22 src = open(mskp_src, 'rb')
23
24 magic_constant = b'Skia Multi-Picture Doc\n\n'
25 magic = src.read(len(magic_constant))
26 if magic != magic_constant:
27 sys.stderr.write('Not a mskp file: "%s"\n' % mskp_src)
28 exit(2)
29
30 version, page_count = struct.unpack('II', src.read(8))[:2]
31 print('MSKP version: ', version)
32 print('page count: ', page_count)
33 if version > 2 or version < 1:
34 #TODO(halcanary): Remove support for version 1.
35 sys.stderr.write('unsupported mskp version\n')
36 exit(3)
37 offsets = []
38 for page in range(page_count):
39 print('page %3d\t' % page, end='')
40 if version == 1:
41 offset, size_x, size_y =struct.unpack('Qff', src.read(16))
42 print('offset = %-7d\t' % offset, end='')
43 offsets.append(offset)
44 elif version == 2:
45 size_x, size_y =struct.unpack('ff', src.read(8))
46 print('size = (%r,%r)' % (size_x, size_y))
47
48 if len(sys.argv) >= 3:
49 with open(sys.argv[2], 'wb') as o:
50 if version == 2 or len(offsets) < 2:
51 while True:
52 file_buffer = src.read(8192)
53 if 0 == len(file_buffer):
54 break
55 o.write(file_buffer)
56 else:
57 o.write(src.read(offsets[1] - offsets[0]))
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698