In the two for loops below, I want the checksum variable to hold the same value for both even though one loop starts at row 12 and another at row 0.
Any ideas how I can combine these loops so that I don't have to iterate the same buffer twice?
std::uint32_t Checksum = 0;
std::uint32_t CheckSum2 = 0;
std::uint8_t* Ptr = Pixels;
int K = Width < 12 ? 1 : 12;
for (int I = K; I < Height; ++I) //Start at row K offset.
{
for (int J = 0; J < Width; ++J)
{
R += *(Ptr++);
G += *(Ptr++);
B += *(Ptr++);
CheckSum += *(Ptr++);
}
}
Ptr = Pixels;
for (int I = 0; I < Height; ++I) //Start at 0 offset
{
for (int J = 0; J < Width; ++J)
{
CR += *(Ptr++);
CG += *(Ptr++);
CB += *(Ptr++);
if (I >= K) //if we are at row K?
CheckSum2 += *(Ptr++);
}
}
However, CheckSum != Checksum2 so I'm not sure how I can combine them :S