github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

dokai / hexagonit-swfheader

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 1
    • 0
  • Source
  • Commits
  • Network (0)
  • Issues (0)
  • Downloads (0)
  • Wiki (1)
  • Graphs
  • Tree: cfb013b

click here to add a description

click here to add a homepage

  • Branches (1)
    • master
  • Tags (0)
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Python parser for SWF metadata — Read more

  cancel

http://pypi.python.org/pypi/hexagonit.swfheader

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

PyFlakes fix 
dokai (author)
Wed May 28 07:17:46 -0700 2008
commit  cfb013b30d3a6c96366991b92939e52cfcb225df
tree    02a1ef67078600ad70ab35272126aeb4c79fa75c
parent  fb0e5717c0d6418767ee9967ef984c3fdc2096ee
hexagonit-swfheader / hexagonit / swfheader / __init__.py hexagonit/swfheader/__init__.py
100644 92 lines (70 sloc) 2.752 kb
edit raw blame history
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
import zlib
import struct
 
def parse(input):
    """Parses the header information from an SWF file."""
    if hasattr(input, 'read'):
        input.seek(0)
    else:
        input = open(input, 'rb')
 
    def read_ui8(c):
        return struct.unpack('<B', c)[0]
    def read_ui16(c):
        return struct.unpack('<H', c)[0]
    def read_ui32(c):
        return struct.unpack('<I', c)[0]
 
    header = {}
 
    # Read the 3-byte signature field
    signature = ''.join(struct.unpack('<3c', input.read(3)))
    if signature not in ('FWS', 'CWS'):
        raise ValueError('Invalid SWF signature: %s' % signature)
 
    # Compression
    header['compressed'] = signature.startswith('C')
 
    # Version
    header['version'] = read_ui8(input.read(1))
 
    # File size (stored as a 32-bit integer)
    header['size'] = read_ui32(input.read(4))
 
    # Payload
    buffer = input.read(header['size'])
    if header['compressed']:
        # Unpack the zlib compression
        buffer = zlib.decompress(buffer)
 
    # Containing rectangle (struct RECT)
 
    # The number of bits used to store the each of the RECT values are
    # stored in first five bits of the first byte.
    nbits = read_ui8(buffer[0]) >> 3
 
    current_byte, buffer = read_ui8(buffer[0]), buffer[1:]
    bit_cursor = 5
 
    for item in 'xmin', 'xmax', 'ymin', 'ymax':
        value = 0
        for value_bit in range(nbits-1, -1, -1): # == reversed(range(nbits))
            if (current_byte << bit_cursor) & 0x80:
                value |= 1 << value_bit
            # Advance the bit cursor to the next bit
            bit_cursor += 1
 
            if bit_cursor > 7:
                # We've exhausted the current byte, consume the next one
                # from the buffer.
                current_byte, buffer = read_ui8(buffer[0]), buffer[1:]
                bit_cursor = 0
 
        # Convert value from TWIPS to a pixel value
        header[item] = value / 20
 
    header['width'] = header['xmax'] - header['xmin']
    header['height'] = header['ymax'] - header['ymin']
    
    header['frames'] = read_ui16(buffer[0:2])
    header['fps'] = read_ui16(buffer[2:4])
 
    input.close()
    return header
 
 
def main():
    import sys
 
    if len(sys.argv) < 2:
        print 'Usage: %s [SWF file]' % sys.argv[0]
        sys.exit(1)
 
    header = parse(sys.argv[1])
    print 'SWF header'
    print '----------'
    print 'Version: %s' % header['version']
    print 'Compression: %s' % header['compressed']
    print 'Dimensions: %s x %s' % (header['width'], header['height'])
    print 'Bounding box: (%s, %s, %s, %s)' % (header['xmin'], header['xmax'], header['ymin'], header['ymax'])
    print 'Frames: %s' % header['frames']
    print 'FPS: %s' % header['fps']
 
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server