Module: Swiff::HeaderInfo

Included in:
Swiff
Defined in:
lib/swiff/header_info.rb

Constant Summary collapse

COMPRESSED =
"compressed"
UNCOMPRESSED =
"uncompressed"

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#compression_typeObject (readonly)

Returns the value of attribute compression_type.



5
6
7
# File 'lib/swiff/header_info.rb', line 5

def compression_type
  @compression_type
end

#frame_countObject (readonly)

Returns the value of attribute frame_count.



5
6
7
# File 'lib/swiff/header_info.rb', line 5

def frame_count
  @frame_count
end

#frame_rateObject (readonly)

Returns the value of attribute frame_rate.



5
6
7
# File 'lib/swiff/header_info.rb', line 5

def frame_rate
  @frame_rate
end

#heightObject (readonly)

Returns the value of attribute height.



5
6
7
# File 'lib/swiff/header_info.rb', line 5

def height
  @height
end

#nbitsObject (readonly)

Returns the value of attribute nbits.



5
6
7
# File 'lib/swiff/header_info.rb', line 5

def nbits
  @nbits
end

#signatureObject (readonly)

Returns the value of attribute signature.



5
6
7
# File 'lib/swiff/header_info.rb', line 5

def signature
  @signature
end

#sizeObject (readonly)

Returns the value of attribute size.



5
6
7
# File 'lib/swiff/header_info.rb', line 5

def size
  @size
end

#versionObject (readonly)

Returns the value of attribute version.



5
6
7
# File 'lib/swiff/header_info.rb', line 5

def version
  @version
end

#widthObject (readonly)

Returns the value of attribute width.



5
6
7
# File 'lib/swiff/header_info.rb', line 5

def width
  @width
end

#x_maxObject (readonly)

Returns the value of attribute x_max.



5
6
7
# File 'lib/swiff/header_info.rb', line 5

def x_max
  @x_max
end

#y_maxObject (readonly)

Returns the value of attribute y_max.



5
6
7
# File 'lib/swiff/header_info.rb', line 5

def y_max
  @y_max
end

Instance Method Details

#convert_pixels_to_twips(pixels) ⇒ Object



73
74
75
# File 'lib/swiff/header_info.rb', line 73

def convert_pixels_to_twips( pixels )
  return pixels * 20 
end

#convert_twips_to_pixels(twips) ⇒ Object



65
66
67
# File 'lib/swiff/header_info.rb', line 65

def convert_twips_to_pixels(twips)
  twips / 20 
end

#inspectObject



81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/swiff/header_info.rb', line 81

def inspect
  "signature:   "+@signature.to_s+"\n"+
  "version:     "+@version.to_s+"\n"+
  "compression: "+@compression_type.to_s+"\n"+
  "size:        "+@size.to_s+"\n"+
  "nbits:       "+@nbits.to_s+"\n"+
  "xmax:        "+@xmax.to_s+"\n"+
  "ymax:        "+@ymax.to_s+"\n"+
  "width:       "+@width.to_s+"\n"+
  "height:      "+@height.to_s+"\n"+
  "frame_rate:   "+@frame_rate.to_s+"\n"+
  "frame_count:  "+@frame_count.to_s+"\n"
end

#is_swf?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/swiff/header_info.rb', line 35

def is_swf?
  bytes[0,3] =="FWS" || bytes[0,3] == "CWS"
end

#parse_headerObject

TODO: Clean this up



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/swiff/header_info.rb', line 10

def parse_header
  @nbits = ((decompressed_bytes[8]&0xff)>>3)
  pbo = read_packed_bits(decompressed_bytes, 8, 5, @nbits ) 
  pbo2 = read_packed_bits(decompressed_bytes, pbo.nextByteIndex,pbo.nextBitIndex, @nbits) 
  pbo3 = read_packed_bits(decompressed_bytes, pbo2.nextByteIndex,pbo2.nextBitIndex, @nbits) 
  pbo4 = read_packed_bits(decompressed_bytes, pbo3.nextByteIndex,pbo3.nextBitIndex, @nbits) 

  @x_max = pbo2.value
  @y_max = pbo4.value 
  
  @width = convert_twips_to_pixels( @x_max ) 
  @height = convert_twips_to_pixels( @y_max ) 
  
  byte_pointer = pbo4.nextByteIndex + 2 
  
  @frame_rate = decompressed_bytes[byte_pointer]
  byte_pointer += 1
  fc1 = decompressed_bytes[byte_pointer] & 0xFF
  byte_pointer += 1
  
  fc2 = decompressed_bytes[byte_pointer] & 0xFF
  byte_pointer += 1
  @frame_count = (fc2<<8) + fc1 
end

#read_packed_bits(bytes, byte_marker, bit_marker, length) ⇒ Object

TODO: Clean this up



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/swiff/header_info.rb', line 40

def read_packed_bits(bytes,byte_marker,bit_marker,length)
  total = 0
  shift = 7 - bit_marker 
  counter = 0 
  bit_index = bit_marker 
  byte_index = byte_marker 
  while counter<length
   (bit_marker...8).each do |i|
      bit =((bytes[byte_marker] & 0xff ) >> shift ) & 1 
      total = ( total << 1 ) + bit 
      bit_index = i 
      shift -= 1 
      counter += 1 
      if counter == length
        break 
      end
    end
    byte_index = byte_marker 
    byte_marker += 1
    bit_marker = 0 
    shift = 7 
  end
  return PackedBits.new(bit_index, byte_index, total ) 
end

#to_sObject



77
78
79
# File 'lib/swiff/header_info.rb', line 77

def to_s
  inspect
end