Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * <summary> Flips the image by performing 2 rotations clockwise by 90 degrees </summmary>
- * <params>
- * "img" = 2 dimensional array containing the image bits
- * "size" = Max size of img's row and column dimensions
- * </params>
- * <precond> "size" > 0 </precond>
- */
- void flip(int img[][MAX_SIZE], int size)
- {
- /* Flip is equivalent to 2 rotations */
- rotate(img,size);
- rotate(img,size);
- }
- /*
- * <summary> Rotates the image clockwise by 90 degrees </summmary>
- * <params>
- * "img" = 2 dimensional array containing the image bits
- * "size" = Max size of img's row and column dimensions
- * </params>
- * <precond> "size" > 0 </precond>
- */
- void rotate(int img[][MAX_SIZE], int size)
- {
- int temp[MAX_SIZE][MAX_SIZE];
- int row, col, newRow,newCol;
- /*
- * Copy each element from img row-wise (from row 0)
- * to temp array column-wise(from col size-1)
- */
- for(row = 0, newCol = size - 1; row < size; row++, newCol--)
- for(col = 0, newRow = 0; col < size; col++, newRow++)
- temp[newRow][newCol] = img[row][col];
- /* Copy whole of temp to img array */
- for(row = 0; row< size; row++)
- for(col = 0; col < size; col++)
- img[row][col] = temp[row][col];
- }
Advertisement
Add Comment
Please, Sign In to add comment