I want to know if it is possible to pass bpy.data.images["image"].as_pointer() to a C function to update image pixels directly, instead of using pixels.foreach_set() and pixels.foreach_get()
Edit:
I tried the following to change the float_buffer,but this did not work, the image stays the same. I have tried updating the image by setting the dirty flag, but this results in illegal memory access crash. I also tried calling image.update() and image.pixels.update() on the Python side hoping for a miracle lol.
void EXPORT set_all_pixels_to_white(ImBuf *buf) {
float *pixels = buf->float_buffer.data;
int num_pixels = buf->x * buf->y * buf->channels;
for (int i = 0; i < num_pixels; i += buf->channels) {
pixels[i] = 1;
pixels[i + 1] = 0;
pixels[i + 2] = 0;
pixels[i + 3] = 1;
}
}
Python side:
scene.mydll.set_all_pixels_to_red.argtypes = [POINTER(c_uint8)]
scene.mydll.set_all_pixels_to_red(byref(ctypes.c_uint8(my_image.as_pointer())))