If you think your solution is not fast enough, figuring out why is not as simple as looking at one piece of code.
This code chunk is only a small part of your process it sounds like, and may not be where your code is “slow”.
You should start by profiling your code as best as possible,
check out
https://docs.unrealengine.com/latest/INT/Engine/Performance/
You need to figure out if your gpu or cpu bound and continue your investigation from there.
You might need to add timers in your code if you want more specific performance metrics. see https://answers.unrealengine.com/questions/77017/how-to-get-high-resolution-time-stamp-for-timing-o.html
You can go all out trying to over optimize your small chunk of code like this (not tested, my not be syntactically correct)
int x, y, offsetY, offsetLocal, offsetFrame, sizeX = VideoSize.X, sizeY = VideoSize.Y; // Variables defined once.
WheverTheTypeOf"Data"is& localColor; // will reference one Data[offsetTotal] point
auto& frameColorData = frame->data; // Get a direct reference to data, once;
for (y = 0; y < sizeY ; y++)
{
offsetY = (y * sizeX); // calculate once per row
for (x = 0; x < sizeX ; x++)
{
offsetLocal = x + offsetY;
offsetFrame= offsetLocal*3; // Do the *3 once
localColor = Data[offsetLocal ]; // Do the array lookup once
localColor.B = frameColorData[offsetFrame + 0];
localColor.G = frameColorData[offsetFrame + 1];
localColor.R = frameColorData[offsetFrame + 2];
}
}
The compiler might make all kinds of these substitutions for you, or it might not. The above changes might run slower, or run the same as yours. This is why you need to focus on profiling and figuring out where the time is actually being spent, and weather any changes you make actually run faster.
Edit: Here is another over optimized way, again this may not help performance at all, or it could totally make it worse
// This is a basic array copy from frame->data into Data
int i, offsetFrame, size = VideoSize.X * VideoSize.Y; // Variables defined once.
WheverTheTypeOf"Data"is& localColor; // will reference one Data* point
auto& frameColorData = frame->data; // Get a direct reference to data, once;
for (i = 0; i < size ; ++i)
{
offsetFrame = i*3; // Do the *3 once
localColor = Data*; // Do the array lookup once
localColor.B = frameColorData[offsetFrame + 0];
localColor.G = frameColorData[offsetFrame + 1];
localColor.R = frameColorData[offsetFrame + 2];
}