pixel access in image or texture?
Is there a way to access (and change) pixels directly in a Texture, Sprite or Image object? I want to experiment with some line drawing and polygon fill algorithms and I'm looking for something like framebuffer access. I'm aware of Image.from_data where I can load binary data directly to create an image and I could do that to create an Image for every frame, but is there another way? Speed isn't terribly important, I just want to play with the algorithms and see the results.
not really. iOS doesn't really let you have direct access to the framebuffer, as I understand things.
I have experimented with a few methods of emulating this.
This was part of an apple is simulator, which wanted a "blit" method to set pixels in a region of the screen. It has a backing numpy array, and use matplotlib.imsave to write to bytesio that then gets read into from_data. The update method handles updates in a threaded manner, allowing multiple pixel updates to get queued up. Although this project didn't need it, it would be possible to make the class look like a numpy array, such that you could set data directly, and would call update automatically.
Imsave/bytesio/from_data is the fastest method I've been able to find for working with raw pixels. Using numpy arrays makes things convenient, moreso then PIL Images, imo. Jpg is a lot faster than png, and is necessary for real time speed, but you could change the call to png if you want bit perfect rendering.
Do you know what formats from_data accepts? I was hoping for something relatively simple, uncompressed RGB or RGBA based like .TGA (TARGA).
See this example at the end of the discussion. I hope that it is useful. (Note that the update function is now available on the latest version of pythonista.)