#include "DDImage/PlanarIop.h"
#include "DDImage/Knobs.h"
#include "DDImage/NukeWrapper.h"
#include "DDImage/Blink.h"
#include "Blink/Blink.h"
#include "blurAndGainExampleKernels.h"
static const char* const CLASS = "BlinkBlurAndGain";
static const char* const HELP = "Example of a simple box blur and gain operator that uses the Blink API.";
{
protected:
public:
: PlanarIop(node)
, _gpuDevice(
Blink::ComputeDevice::CurrentGPUDevice())
, _useGPUIfAvailable(true)
, _blurProgram(BlurKernel)
, _gainProgram(GainKernel)
{
_radius = 3;
_gain = 2.0f;
}
void knobs(DD::Image::Knob_Callback f);
void getRequests(
const DD::Image::Box& box,
const DD::Image::ChannelSet& channels,
int count, DD::Image::RequestOutput &reqData)
const;
const char*
Class()
const {
return CLASS; }
const char*
node_help()
const {
return HELP; }
};
{
Newline(f, "Local GPU: ");
std::string gpuName = hasGPU ?
_gpuDevice.name() :
"Not available";
Named_Text_knob(f, "gpuName", gpuName.c_str());
Newline(f);
Divider(f);
Tooltip(f, "The radius of the blur.");
Float_knob(f, &
_gain, DD::Image::IRange(0, 10),
"gain");
Tooltip(f, "The amount of gain to apply.");
}
{
copy_info();
}
void BlinkBlurAndGain::getRequests(
const DD::Image::Box& box,
const DD::Image::ChannelSet& channels,
int count, DD::Image::RequestOutput &reqData)
const
{
DD::Image::Box inputBox = box;
reqData.request(&input0(), inputBox, channels, count);
}
{
DD::Image::Box inputBox = outputPlane.bounds();
inputBox.intersect(input0().info());
DD::Image::ImagePlaneDescriptor inputDescriptor(inputBox,
outputPlane.packed(),
outputPlane.channels(),
outputPlane.nComps());
DD::Image::ImagePlane inputPlane(inputDescriptor);
input0().fetchPlane(inputPlane);
outputPlane.makeWritable();
Blink::Image outputPlaneAsImage;
Blink::Image inputPlaneAsImage;
bool success = (DD::Image::Blink::ImagePlaneAsBlinkImage(outputPlane, outputPlaneAsImage) &&
DD::Image::Blink::ImagePlaneAsBlinkImage(inputPlane, inputPlaneAsImage));
if (!success) {
error("Unable to fetch Blink image for image plane.");
return;
}
Blink::Image intermediateImage = usingGPU ? inputPlaneAsImage.makeLike(
_gpuDevice) : inputPlaneAsImage.makeLike(Blink::ComputeDevice::CurrentCPUDevice());
Blink::ComputeDevice computeDevice = usingGPU ?
_gpuDevice : Blink::ComputeDevice::CurrentCPUDevice();
Blink::Image inputImageOnComputeDevice = inputPlaneAsImage.distributeTo(computeDevice);
Blink::ComputeDeviceBinder binder(computeDevice);
std::vector<Blink::Image> images;
images.push_back(inputImageOnComputeDevice);
images.push_back(intermediateImage);
computeDevice,
images,
kBlinkCodegenDefault);
horizontalBlurKernel.setParamValue(
"Radius",
_radius);
horizontalBlurKernel.setParamValue("Horizontal", true);
horizontalBlurKernel.iterate();
Blink::Image outputImage = usingGPU ? outputPlaneAsImage.makeLike(
_gpuDevice) : outputPlaneAsImage;
images.clear();
images.push_back(intermediateImage);
images.push_back(outputImage);
computeDevice,
images,
kBlinkCodegenDefault);
verticalBlurKernel.setParamValue(
"Radius",
_radius);
verticalBlurKernel.setParamValue("Horizontal", false);
verticalBlurKernel.iterate();
images.clear();
images.push_back(outputImage);
computeDevice,
images,
kBlinkCodegenDefault);
gainKernel.setParamValue(
"Gain",
_gain);
gainKernel.iterate();
if (usingGPU) {
outputPlaneAsImage.copyFrom(outputImage);
}
}
{
return true;
}
{
return 256;
}
static DD::Image::Iop* BlinkBlurAndGainCreate(Node* node)
{
}
BlinkBlurAndGainCreate);