Fast getPixel on canvas
Posted: Mon Aug 06, 2018 1:05 pm
I'd like to get the color value of pixels on my canvas in real time.
I was able to get very fast results using a FFI pointer on ImageData but I really need to use a canvas because I don't want to reimplement all the graphical functions of Love: rectangle, circle etc.
I tried with a more standard solution: generating an imageData object from the canvas and using the getPixel method but it's impossible in my case as I need to get/set a lot of pixels per frame. I tried with a dirty flag to avoid generating the imageData on each frame and to speed up things a bit but it's just poor code optimisation.
Do you know of any methods to get a pointer on the video memory or a canvas directly?
Or more precisely, is it possible to get the color value of a pixel on the screen without generating an imageData object, which is so slow? Is there a way to keep the link between canvas/imageData and to refresh data after some drawings?
Thank you happy lovers!
I was able to get very fast results using a FFI pointer on ImageData but I really need to use a canvas because I don't want to reimplement all the graphical functions of Love: rectangle, circle etc.
I tried with a more standard solution: generating an imageData object from the canvas and using the getPixel method but it's impossible in my case as I need to get/set a lot of pixels per frame. I tried with a dirty flag to avoid generating the imageData on each frame and to speed up things a bit but it's just poor code optimisation.
Do you know of any methods to get a pointer on the video memory or a canvas directly?
Or more precisely, is it possible to get the color value of a pixel on the screen without generating an imageData object, which is so slow? Is there a way to keep the link between canvas/imageData and to refresh data after some drawings?
Thank you happy lovers!