Write pixels to a TOP

Hi,

I am doing some pixel manipulation on a TOP with the script CHOP but I am not able to write the updated pixel values back to the TOP once my script has run.
What am I missing? I don’t seem to find anything in the Python doc for the movie file in or TOP for how to write pixels.

Thanks

I ended up using a C++ TOP to solve this issue, it is also probably faster than using Python. I uploaded a full example with source code [url]https://github.com/dotminic/cppTOPBase[/url]

Here is the main piece of code:

[code]void CppTOP::execute( TOP_OutputFormatSpecs* outputFormat, const OP_Inputs* inputs, TOP_Context* context, void reserved1)
{
int memLocation = 0;
float
mem = (float*)outputFormat->cpuPixelData[memLocation];
OP_TOPInput const* inputTOP = inputs->getInputTOP(0);

if (inputTOP != nullptr)
{
	OP_TOPInputDownloadOptions options;
	options.downloadType = OP_TOPInputDownloadType::Instant;
	options.cpuMemPixelType = OP_CPUMemPixelType::RGBA32Float;
	options.verticalFlip = false;
	
	float const* src = (float const*)inputs->getTOPDataInCPUMemory(inputTOP, &options);

	if (src != nullptr)
	{
		m_mult = (float)inputs->getParDouble("Color");
		for (int y = 0; y < inputTOP->height; y++)
		{
			for (int x = 0; x < inputTOP->width; x++)
			{
				int pixelIndex = (y * inputTOP->width + x) * sizeof(float);
				mem[pixelIndex + 0] = src[pixelIndex + 0] * m_mult;
				mem[pixelIndex + 1] = src[pixelIndex + 1] * m_mult;
				mem[pixelIndex + 2] = src[pixelIndex + 2] * m_mult;
				mem[pixelIndex + 3] = src[pixelIndex + 3];
			}
		}
	}
}

outputFormat->newCPUPixelDataLocation = memLocation;

}[/code]

Hi there,

I’m not sure what you exactly trying to achieve. The C++ TOP looks like you’re copying the input pixels (TOP) to an output and multiply it with a scalar. This is similar to the levelTOP.
To write to a TOP you can use the CHOPtoTOP node. This converts chop data to a TOP. Though this is not the fastest indeed.
Best is if you want to alter TOPs, is to use a GLSLTOP. Using GLSL you can manipulate the pixels on the GPU instead of the CPU, which is super fast.

Cheers,
tim

Hey Tim,

I wanted to read in the pixels from an input TOP and do some pixel sorting but I couldn’t find how to do that in Python so I thought I’d just make a CplusPlus TOP. The code I posted there is just a super basic example for anyone else who is looking to do some pixel manipulation that for some reason has to run on the CPU. In my case I am doing pixel sorting which is super easy on the CPU and not as straight forward on the GPU.

Aah okay… yeah definitely agreeing with the pixel sorting :smiley:
Thanks for sharing!