~npisanti/scriptools

f1560ceb1f25cd6d8943e093a60325b94459671d — Nicola Pisanti a month ago c87fcdc
tweaks framescan
1 files changed, 70 insertions(+), 43 deletions(-)

M framescan/main.lua
M framescan/main.lua => framescan/main.lua +70 -43
@@ 1,6 1,21 @@

require "strict"

--- user settings ---
local tilew = 200
local tileh = 200

local scale = 0.75

local threshold = 0.5
local smooth = 0.1

local camw = 1280 
local camh = 720
local camdev = "/dev/video0"

---------------------

--[[
	KEYS:
		wasd/arrows = move tile


@@ 16,18 31,6 @@ da4 = { button_1=7, button_2=8, button_3=6, button_4=5,
		left_axis_x=0, left_axis_y=1, right_axis_x=2, right_axis_y=3,
		left_axis_press=16, right_axis_press=17 }

local tilew = 200
local tileh = 200

local scale = 0.75

local threshold = 0.5
local smooth = 0.1

local camw = 1280 
local camh = 720
local camdev = "/dev/video0"

-- variables --------
local numsaved = 0
local cx = 0


@@ 36,13 39,14 @@ local lock_cam = false
local preview = 0
local framemem = 0
local clock = 0
local overlay_preview = 0

----------------------------------------------------
window.title( "framescan" )

cam.open( camdev, camw, camh)
cx = (camw-tilew) / 2
cy = (camh-tileh) / 2
cx = (camw-tilew) * 0.5
cy = (camh-tileh) * 0.5

frag.load( "process.frag" ) 



@@ 60,6 64,10 @@ window.size( camw*scale + 40 + tilew, camh*scale + 20 )
layer.create( "default", camw*scale + 20 + tilew, canvash ) 
layer.create( "cam", camw, camh ) 
	layer.hide()
layer.create( "locked", camw, camh) 
	layer.hide()
	local cut_offset_x = 0
	local cut_offset_y = 0 
layer.create( "cut", tilew, tileh )
	layer.hide()



@@ 70,25 78,36 @@ function loop()
	png.align_corner() 
	png.select( "output" )	

	if not lock_cam then 
		layer.select("cam")
		layer.open()
			rl.color( 255, 255, 255, 255 )
			cam.draw( 0, 0 )
		layer.close()
	end

	layer.select("cam")
	layer.open()
		rl.color( 255, 255, 255, 255 )
		cam.draw( 0, 0 )
	layer.close()
	
    frag.select( "process" )
        frag.uniform( "u_low", threshold )
        frag.uniform( "u_high", threshold + smooth )
    frag.apply( "process") 

	if key.pressed( key.q ) 
	or key.pressed( key.l ) 
	or pad.pressed( da4.select ) then
		layer.select("locked")
		layer.open()
			rl.clear( 0, 0, 0, 0 )
			rl.color( 255, 255, 255, 255 )
			layer.draw( "cam", 0, 0 )
			cut_offset_x = 0
			cut_offset_y = 0
		layer.close()
	end

	layer.select("cut")
	layer.open()
		rl.push()
			rl.clear( 0, 0, 0, 0 )
			rl.color( 255, 255, 255, 255 )
			layer.draw( "cam", -cx, -cy )	
			layer.draw( "locked", -cx + cut_offset_x, -cy + cut_offset_y )	
		rl.pop()
	layer.close()



@@ 98,8 117,17 @@ function loop()
		rl.push()
		rl.scale( scale, scale ) 
			layer.draw( "cam", 0, 0 )
			--cam.draw( 0, 0 )
			overlay( cx, cy, tilew, tileh )
		
			if overlay_preview == 1 then
				rl.color(255, 0, 0, 150)
				png.frame( 0 )
				png.draw( cx, cy, 0 )
			elseif overlay_preview == 2 then
				rl.color(255, 0, 0, 150)
				png.frame( png.size()-1 )
				png.draw( cx, cy, 0 )
			end
		rl.pop()

		rl.push()


@@ 133,7 161,7 @@ function loop()
			end
			
			overlay( 0, 0, tilew, tileh )

			
			rl.blend_alpha()

			rl.push()


@@ 165,13 193,6 @@ function overlay( x, y, w, h )
end

function controls()

	if key.pressed( key.q ) 
	or key.pressed( key.l ) 
	or pad.pressed( da4.select ) then
		lock_cam = not lock_cam
	end

	if key.pressed( key.e ) 
	or key.pressed( key.space )
	or key.pressed( key.c ) 


@@ 201,26 222,32 @@ function controls()
		preview = 0
	end

	if key.pressed( key.n5 ) 
	or pad.pressed( da4.left_trigger ) 
	or pad.pressed( da4.right_trigger ) then
		overlay_preview = overlay_preview + 1
		if overlay_preview == 3 then overlay_preview = 0 end 
	end

	local faststep = 4
	if key.is_down( key.a ) then
		cx = cx-faststep
		cut_offset_x = cut_offset_x-faststep
	elseif key.is_down( key.d ) then
		cx = cx+faststep
		cut_offset_x = cut_offset_x+faststep
	elseif key.is_down( key.s ) then
		cy = cy+faststep
		cut_offset_y = cut_offset_y+faststep
	elseif key.is_down( key.w ) then
		cy = cy-faststep
		cut_offset_y = cut_offset_y-faststep
	elseif key.pressed( key.left ) or pad.pressed( da4.pad_left ) then
		cx = cx-1
		cut_offset_x = cut_offset_x-1
	elseif key.pressed( key.right ) or pad.pressed( da4.pad_right ) then
		cx = cx+1
		cut_offset_x = cut_offset_x+1
	elseif key.pressed( key.up ) or pad.pressed( da4.pad_up ) then
		cy = cy-1
		cut_offset_y = cut_offset_y-1
	elseif key.pressed( key.down ) or pad.pressed( da4.pad_down ) then
		cy = cy+1
		cut_offset_y = cut_offset_y+1
	end

	cx = math.floor( cx + pad.axis( da4.left_axis_x ) * 3 )
	cy = math.floor( cy + pad.axis( da4.left_axis_y ) * 3 ) 
	
	cut_offset_x = math.floor( cut_offset_x + pad.axis( da4.left_axis_x ) * 3 )
	cut_offset_y = math.floor( cut_offset_y + pad.axis( da4.left_axis_y ) * 3 ) 
end