Sha256: d01bc31cf2df5d76192dde1cca20f075a84cac2fdf8aa409e32c9ccd803e36c5

Contents?: true

Size: 1.04 KB

Versions: 23

Compression:

Stored size: 1.04 KB

Contents

# Scales the comp being exported by a specific factor, together with the tracker keyframes
class Tracksperanto::Middleware::Scaler < Tracksperanto::Middleware::Base
  DEFAULT_FACTOR = 1
  
  attr_accessor :x_factor, :y_factor
  cast_to_float :x_factor, :y_factor
  
  # Called on export start
  def start_export( img_width, img_height)
    set_residual_factor
    @w, @h = (img_width * x_factor).to_i.abs, (img_height * y_factor).to_i.abs
    super(@w, @h)
  end
  
  def y_factor
    @y_factor || DEFAULT_FACTOR
  end
  
  def x_factor
    @x_factor || DEFAULT_FACTOR
  end
  
  def export_point(frame, float_x, float_y, float_residual)
    return super if @y_factor == DEFAULT_FACTOR && @x_factor == DEFAULT_FACTOR
    
    super(frame,
      x_factor < 0 ? (@w + (float_x * x_factor)) : (float_x * x_factor),
      y_factor < 0 ? (@h + (float_y * y_factor)) : (float_y * y_factor),
      (float_residual * @residual_factor)
    )
  end
  
  private
    def set_residual_factor
      @residual_factor = Math.sqrt((x_factor ** 2) + (y_factor ** 2))
    end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
tracksperanto-2.8.6 lib/middleware/scaler.rb
tracksperanto-2.8.5 lib/middleware/scaler.rb
tracksperanto-2.8.4 lib/middleware/scaler.rb
tracksperanto-2.8.2 lib/middleware/scaler.rb
tracksperanto-2.8.1 lib/middleware/scaler.rb
tracksperanto-2.8.0 lib/middleware/scaler.rb
tracksperanto-2.7.0 lib/middleware/scaler.rb
tracksperanto-2.6.3 lib/middleware/scaler.rb
tracksperanto-2.6.2 lib/middleware/scaler.rb
tracksperanto-2.6.1 lib/middleware/scaler.rb
tracksperanto-2.6.0 lib/middleware/scaler.rb
tracksperanto-2.5.0 lib/middleware/scaler.rb
tracksperanto-2.4.1 lib/middleware/scaler.rb
tracksperanto-2.3.3 lib/middleware/scaler.rb
tracksperanto-2.3.2 lib/middleware/scaler.rb
tracksperanto-2.3.1 lib/middleware/scaler.rb
tracksperanto-2.3.0 lib/middleware/scaler.rb
tracksperanto-2.2.4 lib/middleware/scaler.rb
tracksperanto-2.2.2 lib/middleware/scaler.rb
tracksperanto-2.2.0 lib/middleware/scaler.rb