-
Will this work
Hi everyone , can someone please double check that this should work :
Code:
// A procedure that will scroll an image vertically and return back into matrix
void Image_vertical_scroll(int image_data[EP100_LIB_MAX_X][EP100_LIB_MAX_Y], int scroll, int height, int width)
{
int row, column, row_new;
int inverted_image[EP100_LIB_MAX_X][EP100_LIB_MAX_Y];
for (row=0;row<height;row++)
{
//We must loop the columns of the image's array , increasing it by 1 until the width of the image becomes the same as the height.
for (column=0;column<width;column++)
{
// Adding the scroll ammount
row_new = row + scroll;
while (row_new >= height) // Have to make sure that total is less than height
{
row_new = row_new - height;
}
inverted_image[row_new][column] = image_data[row][column];
}
}
}
I have no way to test this code . In theory it should work ?
-
If we assume that scroll is less than height, then the "while" only needs to be an "if".
Code:
row_new = row + scroll;
while (row_new >= height) // Have to make sure that total is less than height
{
row_new = row_new - height;
}
Another option is to do "row_new = (row + scroll) % height;"
Also, you can use memcpy() to copy the data in the whole row at once:
Code:
memcpy(inverted_image[row], image_data[row], sizeof(image_data[0][0]) * width);
Although, on second thought, I'm not sure that works - you seem to have swapped your columns and rows around - the first dimension in your array appears to be X by the incoming variable declaration - X in my world is column, Y is row. So you probably want to switch your row/column around. [Which means that memcpy doesn't work in this case]
--
Mats