Invert

The Invert kernel inverts the colours on its input. It also applies a gain, controlled by the Multiply parameter.

// Copyright (c) 2024 The Foundry Visionmongers Ltd.  All Rights Reserved.
// WARNING: This file is referenced within Kernels.rst. Line number references will need updating if changes are made to this file.
/// Invert kernel: Inverts the colour of the input
kernel Invert : ImageComputationKernel<eComponentWise>
{
  Image<eRead> src;   // Input image
  Image<eWrite> dst;  // Output image

  param:
    float multiply;  // This parameter is made available to the user.

  local:
    float whiteAccessPoint;  //This local variable is not exposed to the user.

  // In define(), parameters can be given labels and default values.
  void define() {
    defineParam(multiply, "Multiply", 1.0f);
  }

  // The init() function is run once before any calls to process().
  void init() {
    whiteAccessPoint = 1.0f;  //Local variables can be initialised here.
  }

  // The process function is run at every pixel to produce the output.
  void process() {
    //Invert the input value from src and multiply:
    dst() = (whiteAccessPoint - src()) * multiply;
   }
};