Transform an image by applying a function to every pixel.
This function is a higher order function. It takes another function as a parameter, and calls it once for each pixel in the ImageData.
The passed function is called with six parameters for each pixel in turn. The parameters are numbers that represent the x and y coordinates of the pixel and its red, green, blue and alpha values. The function should return the new red, green, blue, and alpha values for that pixel.
function pixelFunction(x, y, r, g, b, a) -- template for defining your own pixel mapping function -- perform computations giving the new values for r, g, b and a -- ... return r, g, b, a end
ImageData:mapPixel( pixelFunction )
function pixelFunction
Nothing.
Available since LÖVE 0.9.0
This variant is not supported in earlier versions.
ImageData:mapPixel( pixelFunction, x, y, width, height )
function pixelFunction
number x
number y
number width
number height
Nothing.
function brighten( x, y, r, g, b, a ) r = math.min(r * 3, 255) g = math.min(g * 3, 255) b = math.min(b * 3, 255) return r,g,b,a end imageData:mapPixel( brighten )
function stripey( x, y, r, g, b, a ) r = math.min(r * math.sin(x*100)*2, 255) g = math.min(g * math.cos(x*150)*2, 255) b = math.min(b * math.sin(x*50)*2, 255) return r,g,b,a end imageData:mapPixel( stripey )
source: http://khason.net/blog/hlsl-pixel-shader-effects-tutorial/ (broken 11/16. See blogs.microsoft.co.il or archive.org mirrors.)
© 2006–2016 LÖVE Development Team
Licensed under the GNU Free Documentation License, Version 1.3.
https://love2d.org/wiki/ImageData:mapPixel