Skip to content

Instantly share code, notes, and snippets.

@olokobayusuf
Created May 27, 2017 15:25
Show Gist options
  • Save olokobayusuf/c407ba17ae65bb206d521661d90e6684 to your computer and use it in GitHub Desktop.
Save olokobayusuf/c407ba17ae65bb206d521661d90e6684 to your computer and use it in GitHub Desktop.
public static void RotateImage (Color32[] dst, Color32[] src, int width, int height, byte orientation) {
int rotation = ..., mirror = ...; // Extract the rotation and mirror bits from the orientation byte
Func<int, int> kernel = null;
switch (rotation) {
case 0: kernel = i => i; break; // 0
case 1: kernel = i => height * (width - 1 - i % width) + i / width; break; // 90
case 2: kernel = i => src.Length - 1 - i; break; // 180
case 3: kernel = i => src.Length - 1 - (height * (width - 1 - i % width) + i / width); break; // 270
}
for (int i = 0; i < src.Length; i++) dst[kernel(i)] = src[i]; // Reposition the pixels // Memory accesses for the destination buffer are all over the place
if (mirror == 1) ...;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment