Sha256: f70d40f4bb8b8884f48f8094e209d6fbb12a3793356084b5bf43d9786584964a

Contents?: true

Size: 827 Bytes

Versions: 32

Compression:

Stored size: 827 Bytes

Contents

require File.dirname(__FILE__) + '/scaler'

# This middleware reformats (scales) the track setup to a specific pixel resolution. Very useful for
# applying proxy tracks to full-res images
class Tracksperanto::Middleware::Reformat < Tracksperanto::Middleware::Base
  
  # To which format we have to scale
  attr_accessor :width, :height
  cast_to_int :width, :height
  
  # Called on export start
  def start_export( img_width, img_height)
    @width ||= img_width # If they be nil
    @height ||= img_height
    
    x_factor, y_factor = (@width / img_width.to_f), (@height / img_height.to_f)  
    
    @stash = @exporter
    @exporter = Tracksperanto::Middleware::Scaler.new(@exporter, :x_factor => x_factor, :y_factor => y_factor)
    super
  end
  
  def end_export
    @exporter = @stash
    @exporter.end_export
  end
end

Version data entries

32 entries across 32 versions & 1 rubygems

Version Path
tracksperanto-1.7.2 lib/middleware/reformat.rb
tracksperanto-1.7.1 lib/middleware/reformat.rb
tracksperanto-1.7.0 lib/middleware/reformat.rb
tracksperanto-1.6.9 lib/middleware/reformat.rb
tracksperanto-1.6.8 lib/middleware/reformat.rb
tracksperanto-1.6.7 lib/middleware/reformat.rb
tracksperanto-1.6.6 lib/middleware/reformat.rb
tracksperanto-1.6.5 lib/middleware/reformat.rb
tracksperanto-1.6.4 lib/middleware/reformat.rb
tracksperanto-1.6.3 lib/middleware/reformat.rb
tracksperanto-1.6.2 lib/middleware/reformat.rb
tracksperanto-1.6.1 lib/middleware/reformat.rb