Created
July 31, 2013 12:30
-
-
Save Deathspike/6121579 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public byte[] Delta() { | |
| // Make a snapshot of the pixels in RGBA format. | |
| byte[] Snapshot = _Capturer.Snapshot(); | |
| // Check if the previous snapshot is invalid. | |
| if (_PreviousSnapshot != null) { | |
| // Initialize a new instance of the MemoryStream class. | |
| using (MemoryStream MemoryStream = new MemoryStream()) { | |
| using (var zipper = new GZipStream(MemoryStream, CompressionLevel.Fastest)) { | |
| // Initialize a new instance of the BinaryWriter class. | |
| using (BinaryWriter BinaryWriter = new BinaryWriter(zipper)) { | |
| // Iterate through each pixel on each channel. | |
| for (int i = 0; i < Snapshot.Length; i += 4) { | |
| // Check if the pixel has changed a channel. | |
| if (Snapshot[i] != _PreviousSnapshot[i] || Snapshot[i + 1] != _PreviousSnapshot[i + 1] || Snapshot[i + 2] != _PreviousSnapshot[i + 2]) { | |
| // Write the pixel position. | |
| BinaryWriter.Write(i); | |
| // Write the red channel value. | |
| BinaryWriter.Write(Snapshot[i]); | |
| // Write the green channel value. | |
| BinaryWriter.Write(Snapshot[i + 1]); | |
| // Write the blue channel value. | |
| BinaryWriter.Write(Snapshot[i + 2]); | |
| } | |
| } | |
| // Check if a delta has been established. | |
| if (MemoryStream.Length != 0) { | |
| BinaryWriter.Flush(); | |
| zipper.Flush(); | |
| // Set the previous snapshot. | |
| _PreviousSnapshot = Snapshot; | |
| // Return the delta. | |
| return MemoryStream.ToArray(); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| // Set the previous snapshot. | |
| _PreviousSnapshot = Snapshot; | |
| // Return the delta. | |
| return null; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment