Class: Vizcore::Renderer::Snapshot
- Inherits:
-
Object
- Object
- Vizcore::Renderer::Snapshot
- Defined in:
- lib/vizcore/renderer/snapshot.rb
Overview
Builds one analyzed scene frame and writes a PNG preview.
Instance Method Summary collapse
-
#initialize(config:, width: SnapshotRenderer::DEFAULT_WIDTH, height: SnapshotRenderer::DEFAULT_HEIGHT) ⇒ Snapshot
constructor
A new instance of Snapshot.
-
#write(out:) ⇒ Hash
Snapshot metadata.
Constructor Details
#initialize(config:, width: SnapshotRenderer::DEFAULT_WIDTH, height: SnapshotRenderer::DEFAULT_HEIGHT) ⇒ Snapshot
Returns a new instance of Snapshot.
12 13 14 15 16 |
# File 'lib/vizcore/renderer/snapshot.rb', line 12 def initialize(config:, width: SnapshotRenderer::DEFAULT_WIDTH, height: SnapshotRenderer::DEFAULT_HEIGHT) @config = config @width = width @height = height end |
Instance Method Details
#write(out:) ⇒ Hash
Returns snapshot metadata.
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/vizcore/renderer/snapshot.rb', line 20 def write(out:) output_path = Pathname.new(out.to_s). frame_source = SceneFrameSource.new(config: @config) frame_source.start frame = frame_source.capture png = SnapshotRenderer.new(width: @width, height: @height).render( scene: frame.fetch(:scene), audio: frame.fetch(:audio) ) FileUtils.mkdir_p(output_path.dirname) File.binwrite(output_path, png) { path: output_path, scene: frame.fetch(:scene_name), width: @width, height: @height } ensure frame_source&.stop end |