Mail Archives: djgpp/1999/07/14/05:25:55
> Alan Wills wrote in message <7mf2qk$nlg$1 AT rockall DOT cc DOT strath DOT ac DOT uk>...
> >void flip_image(int array[], int rows, int cols)
> >{
> >int row_count, col_count, total_pixelsp;
> >
> > for(row_count = 0; row_count < rows; row_count++)
> > {
> > for(col_count = 0; col_count < cols; col_count++)
> > {
>
> // Something like this ? (note: this is untested)
> tmp = array[row_count * cols + col_count];
> array[row_count * cols + col_count] = array[(row_count + 1) * cols - 1 -
> col_count];
> array[(row_count + 1) * cols - 1 - col_count] = tmp;
>
> > }
> > }
> >}
I think you should use second array.
Your code should look like this (this is untested too):
void flip_image(int array[], int rows, int cols)
{
int row_count, col_count, total_pixelsp;
int *atmp; // to dynamically allocate memory
atmp = (int*)malloc(sizeof(int) * rows * cols);
for(row_count = 0; row_count < rows; row_count++)
for(col_count = 0; col_count < cols; col_count++)
atmp[row_count * cols + cols - col_count] = array[row_count *
cols + col_count];
// second array is flipped in this moment
for(row_count = 0; row_count < rows; row_count++)
memcpy(&array[row_count * cols], atmp[row_count * cols], sizeof(int)
* cols]);
// copy second array to first array
free(atmp);
}
Maybe there is small mistake but the idea is right.
--
mailto:pienkny AT friko6 DOT onet DOT pl
+4822368951
- Raw text -