Image(ID) wrapper: get_pixels()/write_pixels() functions
When working with animated textures, UDIM tiles, or multilayer EXR files it's often necessary to be able to access specific frames, passes or layers of the image datablock with python.
Currently this only possible for loading by doing everything manually (loading the specific image frame/pass/layer into a opengl buffer and reading the pixel values there) as image datablocks that have for example an animated medium loaded into them, only allow access to the current frame with the pixels property. Likewise, accessing the data of multilayered formats like MultilayerEXRs is afaik not possible with the pixels property. This makes it not easy to understand or utilize.
Also, writing to those specific image datablocks is completely impossible utilizing the current wrapper.
My idea would be to add new functions called get_pixels() and write_pixels() which would be using the same parameters as the gl_load(frame=0, layer_index=0, pass_index=0) function but instead give the user a copy of the image pixels as a list/let the user write to those pixels by providing the new image pixels as a list. That way it would be utilizing the same format as the pixels property and make updating the code to the new functions very easy to do.
This would also implement this idea here: blender.community/c/rightclickselect/A1n7/ and reduce performance headaches for new developers which usually use something along the lines of pixels = image.pixels and work with that reference which results in a lot of image.pixel calls to the image wrapper.
This ability would open up a lot of doors for addon developers, and allow for the easier creation of for example more sophisticated tracking tools, machine learning tools or conversion tools.
1 Comment
Bumping. There is also an existing known issue in slicing the pixels() array as it is, so this would be a very nice thing to add on top of that.