• 05-04-2006
hkl01
Hello , im trying to read an array[256][256] in 8x8 blocks , i need to break the array into a 8x8 matrix and send it to a funcion. This is how i was trying to do it , but it seems that only one line 8x256 is being read. Please help..

Code:

``` temp[8][8]; array[256][256]; for(int i=0; i<256; i+=8){ for(int x=i; x<i+8; x++) for(int y=i; y<i+8; y++) temp[x-i][y-i]=array[x][y]; function(temp); //....... //rest //...... }```
Thanks
• 05-04-2006
dwks
The first iteration of your loop results in temp[-1][-1] being accessed. You need to re-think your loops.
• 05-04-2006
hkl01
It seems to be correct for me , i may be wrong im a begineer but i test that code with the following

Code:

```int main(){ int temp[8][8]; for(int i=0; i<256; i+=8){ for(int x=i; x<i+8; x++) for(int y=i; y<i+8; y++) temp[x-i][y-i]=y; for(int x=i; x<i+8; x++){         cout<<endl; for(int y=i; y<i+8; y++) cout<<x-i<<"  "<<y-i<<" "; getchar(); } for(int x=i; x<i+8; x++){         cout<<endl; for(int y=i; y<i+8; y++) cout<<temp[x-i][y-i]<<" "; getchar(); } } }```
• 05-04-2006
pityocamptes
Quote:

Originally Posted by hkl01
Hello , im trying to read an array[256][256] in 8x8 blocks , i need to break the array into a 8x8 matrix and send it to a funcion. This is how i was trying to do it , but it seems that only one line 8x256 is being read. Please help..

Code:

``` temp[8][8]; array[256][256]; for(int i=0; i<256; i+=8){ for(int x=i; x<i+8; x++) for(int y=i; y<i+8; y++) temp[x-i][y-i]=array[x][y]; function(temp); //....... //rest //...... }```
Thanks

Code:

``` for(int i=0; i<256; i+=8) {     for(int x=0; x<8; x++)     {           for(int y=0; y<8; y++)         {               temp[x+i][y]=array[x][y];         }     } }```
• 05-04-2006
neoragexxx
ok from what i see it you are missing parts of the array ...

so you read array[0][0] till array[7][7] the first loop
then you start again from array[8][8] to array[15][15] etc..

or array[15][16-255] ... ? etc.

I hope you understand what you missed ;)

EDIT: what pityocamptes posted is wrong.
• 05-04-2006
hkl01
Yes im reading only the first column 8x8 ... but i cant think about how to read the other 31 8x8 matrix :( , thanks neoragexxx and pityocamptes
• 05-04-2006
hkl01
I think i found the solution can you check it please to be sure ... Thanks!

Code:

```for(int i=0; i<256; i+=8){ for(int j=0; j<256; j+=8){ for(int x=i; x<i+8; x++){         cout<<endl; for(int y=j; y<j+8; y++){ temp[x-i][y-j]=image[x][y]; cout<<"image["<<x<<"]["<<y<<"]"<<endl; } } getchar();```
• 05-04-2006
pityocamptes
Quote:

Originally Posted by hkl01
Yes im reading only the first column 8x8 ... but i cant think about how to read the other 31 8x8 matrix :( , thanks neoragexxx and pityocamptes

Ok, miss read what you were trying to do. Looks like you might need another for loop to move you through the columns.

Code:

``` for(int rowBlock=0; rowBlock<256; rowBlock+=8)  {     for(int colBlock=0; colBlock<256;colBlock+=8)     {           for(int row=0; row<8; row++)           {               for(int col=0; col<8; col++)               {                     temp[row+rowBlock][col+colBlock]=array[row][col];               }           }       } }```
• 05-04-2006
hkl01
pityocamptes and neoragexxx thanks a lot for your help.

i got the same code as pityocamptes.

thanks
• 05-04-2006
hkl01
your code is right pityocamptes is just that in the temp[][] i use "-" instead of + because temp is [8][8]

thanks again pityocamptes