Code:
for(i=Y_min;i<=Y_max;i++){
for(j=XL;j<=XR;j++){
temp[(i*width)+j]= (unsigned char)output[i][j];
}
}
With this code you probably don't get a linear arry of unsigned char, with no memory holes.
e.g:
width = 10; height = 5;
Situation: ouy are at the end of the first line:
i = 0 and j = 5 => temp[(0*10)+5] = temp[5]
The next char you'll put in the temp array will be at position:
i = 1 j = 0 => temp[(1*10)+0] = temp[10]
You should write it like this to get a well formed array:
Code:
int count = 0;
for( i = >_min; i <= Y_MAX; i++)
{
for(j = XL; j <= XR; j++)
{
temp[count] = (unsigned char)output[i][j]; //or ... = output[i][j]
count++;
}
}