I'm trying to flip an image vertically (in C). This is what I've done so far. I think it works in theory, but when I run it I get segmentation fault. I somehow managed to fix this error a few days ago, but I didn't save it. This function that you see gives segmentation fault when I try to run. Is there a way to fix it so that it doesn't give that error and flips an image vertically?
void vertical( uint8_t array[],
unsigned int cols,
unsigned int rows )
{
unsigned int top = 0;
unsigned int bottom = rows-1;
for(int r = 0; r < cols; r++)
{
while(top != bottom && bottom > top)
{
int index1= r * cols + top;
int index2= r * cols + bottom;
int temp= array[index1];
array[index1]= array[index2];
array[index2] = temp;
bottom++;
top++;
}
top =0;
bottom= rows-1;
}
}
Aucun commentaire:
Enregistrer un commentaire