15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# File 'lib/inlay/adapters.rb', line 15
def convert(object)
pair = @adapters.find { |klass, _| object.is_a?(klass) }
return pair.last.call(object) if pair
return object if defined?(Tessel::Image) && object.is_a?(Tessel::Image)
if defined?(RBGL::Engine::Framebuffer) && object.is_a?(RBGL::Engine::Framebuffer)
return Tessel::Image.from_rgba(object.width, object.height, object.to_rgba_bytes)
end
if defined?(RBGL::Engine::Texture) && object.is_a?(RBGL::Engine::Texture)
bytes = object.data.flat_map { |color| [color.r, color.g, color.b, color.a] }.pack("C*")
return Tessel::Image.from_rgba(object.width, object.height, bytes)
end
if defined?(Inkplot::Chart) && object.is_a?(Inkplot::Chart)
return object.to_inlay
end
nil
end
|