Class: SwfRuby::Swf::Header

Inherits:
Object
  • Object
show all
Defined in:
lib/swf_ruby/swf/header.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#compressedObject

Returns the value of attribute compressed.



6
7
8
# File 'lib/swf_ruby/swf/header.rb', line 6

def compressed
  @compressed
end

#file_lengthObject

Returns the value of attribute file_length.



8
9
10
# File 'lib/swf_ruby/swf/header.rb', line 8

def file_length
  @file_length
end

#frame_countObject

Returns the value of attribute frame_count.



11
12
13
# File 'lib/swf_ruby/swf/header.rb', line 11

def frame_count
  @frame_count
end

#frame_rateObject

Returns the value of attribute frame_rate.



10
11
12
# File 'lib/swf_ruby/swf/header.rb', line 10

def frame_rate
  @frame_rate
end

#frame_sizeObject

Returns the value of attribute frame_size.



9
10
11
# File 'lib/swf_ruby/swf/header.rb', line 9

def frame_size
  @frame_size
end

#lengthObject

Returns the value of attribute length.



12
13
14
# File 'lib/swf_ruby/swf/header.rb', line 12

def length
  @length
end

#versionObject

Returns the value of attribute version.



7
8
9
# File 'lib/swf_ruby/swf/header.rb', line 7

def version
  @version
end

Class Method Details

.parse(swf) ⇒ Object



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
# File 'lib/swf_ruby/swf/header.rb', line 14

def self.parse(swf)
  header = Header.new
  # check if compressed
  if swf[1].chr == "W" and swf[2].chr == "S"
    if swf[0].chr == "F"
      header.compressed = false
    elsif swf[0].chr == "C"
      header.compressed = true
    end
  end
  # version
  header.version = swf[3].chr.unpack("C").first
  # file size
  header.file_length = swf[4, 4].unpack("V").first

  # Zlib inflate
  if header.compressed
    swf[8..-1] = Zlib::Inflate.inflate(swf[8..-1])
  end

  # frame size
  header.frame_size = Rectangle.new(swf[8..-1])
  # frame rate
  header.frame_rate = (swf[8+header.frame_size.length].chr.unpack("C").first).to_f / 0x100
  header.frame_rate += swf[9+header.frame_size.length].chr.unpack("C").first
  # frame count
  header.frame_count = swf[10+header.frame_size.length, 2].unpack("v").first
  # header length
  header.length = 12+header.frame_size.length

  [header, swf]
end