Oli Smart
Oli Smart

Reputation: 67

C++ Array convert from 512x512 to 16x16x32x32

I have an array which is 512x512 of ints ranging from 0-255.

I want to split up the 512x512 into 16x16 and in each of the 16x16; there are 32x32.

Visual Illustration: Visual

Because I want to be able to compare a of the 16x16 blocks to another (so technically compare one 32x32 array to another 32x32 array).

Upvotes: 1

Views: 220

Answers (1)

rpy
rpy

Reputation: 4023

Allocate a proper 16x16 matrix of 32x32 matrices and then enumerate your rows and cols from the 512x512 matrix.

For each row r and column c from the source the "address" with the 16x16 matrix is given by r/32 and c/32 ( "/" denoting integer division) and the index values for the 32x32 matrix with the 16x16 slot addressed is given by r%32 and c%32 /"%" identifying integer remainder operator.

If performance is an issue you might also exploit bit operations and replace "/32" by ">>5" and "%32" by "&0x1f".

Upvotes: 1

Related Questions