lib/import/flame_stabilizer.rb in tracksperanto-1.1.1 vs lib/import/flame_stabilizer.rb in tracksperanto-1.2.0
- old
+ new
@@ -1,16 +1,21 @@
-require 'stringio'
class Tracksperanto::Import::FlameStabilizer < Tracksperanto::Import::Base
- class Kf
- include ::Tracksperanto::Casts
- include ::Tracksperanto::BlockInit
- cast_to_int :frame
- cast_to_float :value
+ # Flame setups contain clear size indications
+ def self.autodetects_size?
+ true
end
+ def self.distinct_file_ext
+ ".stabilizer"
+ end
+
+ def self.human_name
+ "Flame .stabilizer file"
+ end
+
T = ::Tracksperanto::Tracker
K = ::Tracksperanto::Keyframe
class ChannelBlock < Array
include ::Tracksperanto::Casts
@@ -54,29 +59,26 @@
line = io.gets
if line =~ frame_matcher
frame = $1.to_i
elsif line =~ value_matcher
value = $1.to_f
- return Kf.new(:frame => frame, :value => value)
+ return [frame,value]
end
end
raise "Did not detect any keyframes!"
end
end
- def parse(stabilizer_setup_content)
-
- io = StringIO.new(stabilizer_setup_content)
-
+ def parse(io)
self.width, self.height = extract_width_and_height_from_stream(io)
channels = extract_channels_from_stream(io)
raise "The setup contained no channels that we could process" if channels.empty?
raise "A channel was nil" if channels.find{|e| e.nil? }
- trackers = scavenge_trackers_from_channels(channels)
+ scavenge_trackers_from_channels(channels)
end
private
def extract_width_and_height_from_stream(io)
w, h = nil, nil
@@ -95,11 +97,11 @@
return [w, h] if (w && h)
end
end
=begin
- Here's how a Flame channel looks like
+Here's how a Flame channel looks like
The Size will not be present if there are no keyframes
Channel tracker1/ref/x
Extrapolation constant
Value 770.41
@@ -130,11 +132,10 @@
Interpolation constant
End
Colour 50 50 50
End
=end
-
def extract_channels_from_stream(io)
channels = []
channel_matcher = /Channel (.+)\n/
until io.eof?
line = io.gets
@@ -167,12 +168,12 @@
track_y = channels.find{|e| e.name == "#{t.name}/#{REF_CHANNEL}/y" }
shift_x = channels.find{|e| e.name == "#{t.name}/shift/x" }
shift_y = channels.find{|e| e.name == "#{t.name}/shift/y" }
- shift_tuples = zip_channels(shift_x, shift_y)
- track_tuples = zip_channels(track_x, track_y)
+ shift_tuples = zip_curve_tuples(shift_x, shift_y)
+ track_tuples = zip_curve_tuples(track_x, track_y)
base_x, base_y = begin
find_base_x_and_y(track_tuples, shift_tuples)
rescue UseBase
[track_x.base_value, track_y.base_value]
@@ -202,23 +203,7 @@
elsif track_tuples[0]
track_tuples[0][1..2]
else
raise UseBase
end
- end
-
- # Zip two channel objects to tuples of [frame, valuex, valuey]
- # skipping keyframes that do not match in the two
- def zip_channels(a, b)
- tuples = []
-
- a.each do | keyframe |
- tuples[keyframe.frame] = [keyframe.frame, keyframe.value]
- end
-
- b.each do | keyframe |
- tuples[keyframe.frame] = (tuples[keyframe.frame] << keyframe.value) if tuples[keyframe.frame]
- end
-
- tuples.compact
end
end
\ No newline at end of file