Ningow

Brightness.Lua

Nov 3rd, 2020 (edited)
52
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function init()
  2.     setName("Brightness")
  3.     setDesc("Change the Brightness")
  4.     setSize(80, 88+8*10+7+4)
  5.     addOutput(24+32)
  6.     addInput("Texture", 88+8*2)
  7.     addInputParameter("Mode","Brighten modes\n(0=Add 1=Multiply 2=Range)",88+8*4,0,0,2)
  8.     addInputParameter("Factor","Brightness Factor", 88+8*6,50,0, 100,true)
  9.     addInputParameter("min","Only for Range mode",88+8*8,0,0,255)
  10.     addInputParameter("max","Only for Range mode",88+8*10,255,0,255)
  11. end
  12.  
  13. function apply()
  14.     tileSize = getTileSize()
  15.     mode = getValue(1, 0, 0, 1)
  16.     factor = getValue(2, x, y, 100.0)
  17.     min = getValue(3,x,y,255)
  18.     max = getValue(4,x,y,255)
  19.  
  20.     for i=0, tileSize*tileSize-1 do
  21.         x = i%tileSize
  22.         y = math.floor(i/tileSize)
  23.         ar, ag, ab = getValue(0, x, y, 1)
  24.         factor = getValue(2, x, y, 100.0)
  25.         if mode==0 then --add
  26.             fr = ar+(factor*2-1)
  27.             fg = ag+(factor*2-1)
  28.             fb = ab+(factor*2-1)
  29.             setPixel(0, x, y, math.min(math.max(fr,0),1), math.min(math.max(fg,0),1), math.min(math.max(fb,0),1))
  30.         elseif mode==1 then --multiply
  31.             fr = ar*(factor*2)
  32.             fg = ag*(factor*2)
  33.             fb = ab*(factor*2)
  34.             setPixel(0, x, y, math.min(math.max(fr,0),1), math.min(math.max(fg,0),1), math.min(math.max(fb,0),1))
  35.         elseif mode==2 then --range
  36.             fr = math.min(ar*1/(max - min)-min/(max-min),1)*(factor*2)
  37.             fg = math.min(ag*1/(max - min)-min/(max-min),1)*(factor*2)
  38.             fb = math.min(ab*1/(max - min)-min/(max-min),1)*(factor*2)
  39.             setPixel(0, x, y, math.min(math.max(fr,0),1), math.min(math.max(fg,0),1), math.min(math.max(fb,0),1))
  40.         end
  41.     end
  42. end
RAW Paste Data