Class: Tracksperanto::Middleware::Reformat

Inherits:
Scaler
  • Object
show all
Defined in:
lib/middleware/reformat.rb

Overview

This middleware reformats (scales) the track setup to a specific pixel resolution. Very useful for applying proxy tracks to full-res images

Constant Summary

Constants inherited from Scaler

Scaler::DEFAULT_FACTOR

Instance Attribute Summary collapse

Attributes inherited from Scaler

#x_factor, #y_factor

Instance Method Summary collapse

Methods inherited from Scaler

#export_point

Methods inherited from Base

#end_export, #end_tracker_segment, #export_point, #initialize, #start_tracker_segment

Methods included from BlockInit

#initialize

Methods included from Casts

#cast_to_float, #cast_to_int, #cast_to_string, included

Constructor Details

This class inherits a constructor from Tracksperanto::Middleware::Base

Instance Attribute Details

#heightObject

To which format we have to scale



8
9
10
# File 'lib/middleware/reformat.rb', line 8

def height
  @height
end

#widthObject

To which format we have to scale



8
9
10
# File 'lib/middleware/reformat.rb', line 8

def width
  @width
end

Instance Method Details

#start_export(img_width, img_height) ⇒ Object

Called on export start



14
15
16
17
18
19
20
21
22
# File 'lib/middleware/reformat.rb', line 14

def start_export( img_width, img_height)
  @width ||= img_width
  @height ||= img_height
  
  self.x_factor, self.y_factor = (@width / img_width.to_f), (@height / img_height.to_f)  
  set_residual_factor
  # Do not call super since it scales by itself :-)
  @exporter.start_export(@width, @height)
end