-- Sharpen_Luminance
-- NOT OPTIMIZED!
-- MEDIUM!
-- apply a sharpening convolution to the value channel.
-- author: Dan Ritchie
-- modified for Pixopedia by Siniša Petrić http://www.sigmapi-design.com, 2014  

-- create images/process objects
imgA = TLuaImageWrap(inputImage)
imgB = TLuaImageWrap(outputImage)
proC = TLuaProcessWrap(procObj)


kernel = { { -1, -1,  -1},
           { -1,  12,  -1},
           { -1, -1,  -1} }
divisor = 4
offset = 0


function filter (x,y)
   local i, j, sum, v2 , dummy1, dummy2
   sum = 0

   for i=-1,1 do
      for j=-1,1 do
         dummy1,dummy2,v2= imgA:GetImageHSV(x+i, y+j)
         sum = sum + (kernel[j+2][i+2] * v2)
      end
   end
   return (sum / divisor) + offset
end

--main routine

eos = false
x = 0            
y = 0
iWidth, iHeight = imgA:GetImageSize()
total = iHeight   
done = 0   
while (not eos) do
   h,s,v = imgA:GetScanHSV()   
   v = filter (x,y)   
   imgB:SetScanHSV(h, s, v)
   imgA:ScanNext()
   eos, x, y = imgB:ScanNext()
   if (y > done) then
      proC:ShowProgress(y, total)
      done = y
   end
end 
