• API
• FAQ
• Tools
• Archive
daily pastebin goal
70%
SHARE
TWEET

# minmax.lua

a guest Jun 9th, 2016 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. function init()
2.  setName("Min/Max")
3.  setDesc("Sets black and white values")
4.  setSize(100, 24+64+8+8+7+4+18+18+18)
7.  addParameter("Auto","Auto-get white and black values", 24+64+8+8+18, 0, 0, 1 )
8.  addInputParameter("Max", "White Value", 24+64+8+8+18+18, 100, 0, 100, true)
9.  addInputParameter("Min", "Black Value", 24+64+8+8+18+18+18, 0, 0, 100, true)
10. end
11.
12. function apply()
13.  tileSize = getTileSize()
14.  whitemax=0
15.  blackmin=1
16.  if getValue(1,0,0,1)==1 then
17.   autominmax=true
18.   for i=0,tileSize*tileSize-1 do
19.    x = i%tileSize
20.    y = math.floor(i/tileSize)
21.    cr, cg, cb = getValue(0, x, y, 1.0)
22.    whitemax = math.max(whitemax,cr)
23.    whitemax = math.max(whitemax,cg)
24.    whitemax = math.max(whitemax,cb)
25.    blackmin = math.min(blackmin,cr)
26.    blackmin = math.min(blackmin,cg)
27.    blackmin = math.min(blackmin,cb)
28.   end
29.  else
30.   autominmax=false
31.  end
32.
33.  for i=0, tileSize*tileSize-1 do
34.   x = i%tileSize
35.   y = math.floor(i/tileSize)
36.   cr, cg, cb = getValue(0, x, y, 1.0)
37.   if not autominmax then
38.    whitemax = getValue(2, x, y, 100.0)
39.    blackmin = getValue(3, x, y, 100.0)
40.   end
41.   if whitemax==0 then whitemax=0.000001 end
42.   if blackmin>=whitemax then blackmin=whitemax-0.0000001 end
43.   if cr<blackmin then cr=blackmin end
44.   if cg<blackmin then cg=blackmin end
45.   if cb<blackmin then cb=blackmin end
46.   if cr>whitemax then cr=whitemax end
47.   if cg>whitemax then cg=whitemax end
48.   if cb>whitemax then cb=whitemax end
49.   cr=(cr-blackmin)/(whitemax-blackmin)
50.   cg=(cg-blackmin)/(whitemax-blackmin)
51.   cb=(cb-blackmin)/(whitemax-blackmin)
52.   if cr>1 then cr=1 end
53.   if cg>1 then cg=1 end
54.   if cb>1 then cb=1 end
55.   if cr<0 then cr=0 end
56.   if cg<0 then cg=0 end
57.   if cb<0 then cb=0 end
58.   setPixel(0, x, y, cr, cg, cb)
59.  end
60. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top