mericson-swf-info 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Matthew Ericson
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,7 @@
1
+ = swf-info
2
+
3
+ Description goes here.
4
+
5
+ == Copyright
6
+
7
+ Copyright (c) 2009 Matthew Ericson. See LICENSE for details.
@@ -0,0 +1,57 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "swf-info"
8
+ gem.summary = %Q{TODO}
9
+ gem.email = "mericson@ericson.net"
10
+ gem.homepage = "http://github.com/mericson/swf-info"
11
+ gem.authors = ["Matthew Ericson"]
12
+ gem.add_dependency 'bindata'
13
+
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ rescue LoadError
17
+ puts "Jeweler not available. Install it with: sudo gem install technicalpickles-jeweler -s http://gems.github.com"
18
+ end
19
+
20
+ require 'rake/testtask'
21
+ Rake::TestTask.new(:test) do |test|
22
+ test.libs << 'lib' << 'test'
23
+ test.pattern = 'test/**/*_test.rb'
24
+ test.verbose = true
25
+ end
26
+
27
+ begin
28
+ require 'rcov/rcovtask'
29
+ Rcov::RcovTask.new do |test|
30
+ test.libs << 'test'
31
+ test.pattern = 'test/**/*_test.rb'
32
+ test.verbose = true
33
+ end
34
+ rescue LoadError
35
+ task :rcov do
36
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
37
+ end
38
+ end
39
+
40
+
41
+ task :default => :test
42
+
43
+ require 'rake/rdoctask'
44
+ Rake::RDocTask.new do |rdoc|
45
+ if File.exist?('VERSION.yml')
46
+ config = YAML.load(File.read('VERSION.yml'))
47
+ version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
48
+ else
49
+ version = ""
50
+ end
51
+
52
+ rdoc.rdoc_dir = 'rdoc'
53
+ rdoc.title = "swf-info #{version}"
54
+ rdoc.rdoc_files.include('README*')
55
+ rdoc.rdoc_files.include('lib/**/*.rb')
56
+ end
57
+
@@ -0,0 +1,4 @@
1
+ ---
2
+ :minor: 1
3
+ :patch: 0
4
+ :major: 0
@@ -0,0 +1,103 @@
1
+ class SwfInfo
2
+
3
+ require 'rubygems'
4
+ require 'bindata'
5
+ require 'open-uri'
6
+ require 'zlib'
7
+
8
+ attr_reader :path, :compressed, :version, :file_length, :width, :height
9
+
10
+ def initialize( file )
11
+
12
+ @path = file
13
+
14
+ ##puts "Opening #{file}"
15
+
16
+ open file do |f|
17
+
18
+ sig = Sig.read( f )
19
+ ##puts "Compressed flag is #{sig.compressed_flag}"
20
+ ##puts "Version is #{sig.version}"
21
+ ##puts "File length is #{sig.file_length}"
22
+
23
+ if sig.compressed_flag == 'C'
24
+ rest = CompressedData.read( f )
25
+ swf = Zlib::Inflate.inflate( rest.rest )
26
+
27
+ else
28
+ rest = UncompressedData.read( f )
29
+ swf = rest.rest
30
+
31
+ end
32
+
33
+ ##i = 0
34
+ ##swf.each_byte do |b|
35
+
36
+ ## puts sprintf( "%02d: %08b %8d %2x %s", i, b, b, b, b.chr )
37
+ ## break if i >= 20
38
+
39
+ ## i += 1
40
+
41
+ ##end
42
+
43
+ size = PackedRect.read( swf )
44
+ rect = Rect.new( size.nbits, size.bit_array.collect { |q| q } )
45
+
46
+ ##puts "Rect legnth is #{size.nbits}"
47
+ ##puts "Size is #{a[0]/20}, #{a[2]/20} - #{a[1]/20}, #{a[3]/20}"
48
+
49
+ @path = file
50
+ @compressed = (sig.compressed_flag == 'C' )
51
+ @version = sig.version
52
+ @file_length = sig.file_length
53
+
54
+ @width = rect.values[1] / 20
55
+ @height = rect.values[3] / 20
56
+ end
57
+ end
58
+
59
+ class SwfInfo::Sig < BinData::MultiValue
60
+ endian :little
61
+
62
+ string :compressed_flag, :read_length => 1
63
+ string :remainder_sig, :read_length => 2
64
+ uint8 :version
65
+ uint32 :file_length
66
+ end
67
+
68
+ class SwfInfo::CompressedData < BinData::MultiValue
69
+ rest :rest
70
+ end
71
+
72
+ class SwfInfo::UncompressedData < BinData::MultiValue
73
+ rest :rest
74
+ end
75
+
76
+ class SwfInfo::PackedRect < BinData::MultiValue
77
+ bit5 :nbits
78
+ array :bit_array, :type => :bit1, :initial_length => lambda { nbits * 4 }
79
+ array :filler, :type => :bit1, :initial_length => lambda {
80
+ skip_bits = ( nbits * 4 ) % 8 == 0 ? 0 : 8 - ( (nbits * 4) % 8 )
81
+ }
82
+
83
+ end
84
+
85
+ class SwfInfo::Rect
86
+
87
+ attr_reader :values
88
+
89
+ def initialize( nbits, data, field_map = {} )
90
+ @values = []
91
+
92
+ ( data.length / nbits ).times do |i|
93
+ sum = 0
94
+ nbits.downto( 1 ) do |n|
95
+ exp = n - 1
96
+ sum += data.shift * (2 ** exp)
97
+ end
98
+ @values << sum
99
+ end
100
+ end
101
+ end
102
+ end
103
+
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ require 'swf_info.rb'
4
+
5
+ class SwfInfoTest < Test::Unit::TestCase
6
+
7
+ context "Stadiums swf" do
8
+ setup do
9
+ @swf = SwfInfo.new( 'http://graphics8.nytimes.com/packages/flash/newsgraphics/2009/0402-ny-stadiums-hp/BasicProject.swf' )
10
+ end
11
+
12
+ should "be compressed" do
13
+ assert_equal true, @swf.compressed
14
+ end
15
+
16
+ should "be 337 pixels wide" do
17
+ assert_equal 337, @swf.width
18
+ end
19
+
20
+ should "be 290 pixels tall" do
21
+ assert_equal 290, @swf.height
22
+ end
23
+
24
+ end
25
+
26
+
27
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'swf_info'
8
+
9
+ class Test::Unit::TestCase
10
+ end
metadata ADDED
@@ -0,0 +1,70 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mericson-swf-info
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Ericson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-04-15 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: bindata
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description:
26
+ email: mericson@ericson.net
27
+ executables: []
28
+
29
+ extensions: []
30
+
31
+ extra_rdoc_files:
32
+ - LICENSE
33
+ - README.rdoc
34
+ files:
35
+ - LICENSE
36
+ - README.rdoc
37
+ - Rakefile
38
+ - VERSION.yml
39
+ - lib/swf_info.rb
40
+ - test/swf_info_test.rb
41
+ - test/test_helper.rb
42
+ has_rdoc: true
43
+ homepage: http://github.com/mericson/swf-info
44
+ post_install_message:
45
+ rdoc_options:
46
+ - --charset=UTF-8
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: "0"
60
+ version:
61
+ requirements: []
62
+
63
+ rubyforge_project:
64
+ rubygems_version: 1.2.0
65
+ signing_key:
66
+ specification_version: 2
67
+ summary: TODO
68
+ test_files:
69
+ - test/swf_info_test.rb
70
+ - test/test_helper.rb