Hi. I’m trying to read pixel data (not set pixel data) from an image that was dynamically drawn to an atlas. What’s the recommended way of doing this?
So you already have the functionality to set a pixel? Aren’t you able to also read pixels then?
The reading part is done in a separate script / game object as the setting part, therefore I don’t already have a stream open to the image resource that I can pull from.
I’m wondering if there’s a different (faster, more efficient) way to read from an image when you don’t have any intention to write to the image.
In order for me to write, I do the following:
local CANVAS_WIDTH = 1024
local CANVAS_HEIGHT = 512
local BUFFER_SIZE = CANVAS_WIDTH * CANVAS_HEIGHT
local BUFFER_INFO = { {
name = hash("rgba"),
type = buffer.VALUE_TYPE_UINT8,
count = 4
} }
local HEADER = {
width = CANVAS_WIDTH,
height = CANVAS_HEIGHT,
type = resource.TEXTURE_TYPE_2D,
format = resource.TEXTURE_FORMAT_RGBA,
num_mip_maps = 1
}
function init(self)
self.buffer = buffer.create(BUFFER_SIZE, BUFFER_INFO)
self.stream = buffer.get_stream(self.buffer, hash("rgba"))
end
It would be a little annoying to duplicate all of this in another script just to read some pixels.
Store the buffer and stream in a Lua module and access that when both reading and writing from your various scripts.
2 Likes