Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Preparing NDK node

Nuke offers a few methods to handle image rendering. Usually for simple image processing this is the row based rendering. With DCC oxidizer only the PlanarIop is supported. This creates ImagePlane buffers. These can be translated to images in Rust. For simple image processing plugins, where simple pixel manipulations are done (row based), this FFI approach is a bit overkill. Just write those in native C++.

Create the node as usual. A ready to use example is available in the examples in the repository. It is recommended to use the entire example as a starting point, and change it to your needs. This should be ready to compile immediately.

In your PlanarIop C++ file, make sure to import your created header thats created in build.rs.

The important part of the file is the renderStripe method.

void ExampleUVOverlay::renderStripe(DD::Image::ImagePlane &output_plane) {
  input0().fetchPlane(output_plane);

  ImagePlaneBuffer image_plane_buffer;
  image_plane_buffer.channels = output_plane.channels().size();
  image_plane_buffer.data = output_plane.writable();
  image_plane_buffer.invert_rows = false;
  image_plane_buffer.length = calculate_buffer_size(&output_plane);
  image_plane_buffer.packed = output_plane.packed();
  image_plane_buffer.resolution[0] = output_plane.bounds().w();
  image_plane_buffer.resolution[1] = output_plane.bounds().h();

  render(&image_plane_buffer, resolution[0], resolution[1],
         output_plane.bounds().y());
}

What we do here is create a ImagePlaneBuffer struct to get the necessary data for Rust to understand the ImagePlane. Make sure all data is set correctly. If you prefer to do your image processing in Rust in the common y0x0 is top left format instead of bottom left, set invert_rows to true.

You can of course modify the render call in Rust to allow additional data to be passed to your code.

We then call the render function to render the image in Rust.