Camera-Extension/main/main.script
Mathias Westerdahl 73f8212c14 Improved on the performance on Android
Rotated/flipped the image to match the subject
2018-05-16 21:17:37 +02:00

54 lines
1.7 KiB
Plaintext

function init(self)
local logosize = 128
local screen_width = sys.get_config("display.width", 600)
local screen_height = sys.get_config("display.height", 800)
local scale_width = screen_width / logosize
local scale_height = screen_height / logosize
go.set("#sprite", "scale", vmath.vector3(scale_width, scale_height, 1) )
if camera ~= nil then
local sysinfo = sys.get_sys_info()
local quality = camera.CAPTURE_QUALITY_HIGH
local type = camera.CAMERA_TYPE_FRONT
if sysinfo.system_name == 'iPhone OS' or sysinfo.system_name == 'Android' then
type = camera.CAMERA_TYPE_BACK
quality = camera.CAPTURE_QUALITY_MEDIUM
end
if camera.start_capture(type, quality) then
self.cameraframe = camera.get_frame()
self.camerainfo = camera.get_info()
print("Initialized camera")
pprint(self.camerainfo)
self.cameratextureheader = {width=self.camerainfo.width,
height=self.camerainfo.height,
type=resource.TEXTURE_TYPE_2D,
format=resource.TEXTURE_FORMAT_RGB,
num_mip_maps=1 }
end
else
print("could not start camera capture")
end
end
function final(self)
if self.cameraframe ~= nil then
camera.stop_capture()
end
end
function update(self, dt)
if self.cameraframe then
local pathmodelcamera = go.get("#sprite", "texture0")
resource.set_texture(pathmodelcamera, self.cameratextureheader, self.cameraframe)
end
end