Created
April 5, 2016 23:19
-
-
Save RyuaNerin/b91aa8ea961efd2ba6cd936ef46ad726 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
| private static void RLEDecompress(byte[] data, byte[] output, int count) | |
| { | |
| // https://en.wikipedia.org/wiki/PackBits | |
| int dind = 0; | |
| int ind = 0; | |
| int len; | |
| byte val; | |
| while (ind < count) | |
| { | |
| len = data[dind++]; | |
| // (1 + n) literal bytes of data | |
| // bin sb ub | |
| // 0000 0000 0 128 | |
| // 0111 1111 127 127 | |
| if (len < 128) // 0 ~ 127 | |
| { | |
| while (len-- >= 0) | |
| output[ind++] = data[dind++]; | |
| } | |
| // One byte of data, repeated (1 – n) times in the decompressed output | |
| // bin sb ub not +2 1-n | |
| // 1111 1111 -1 256 0000 0000 0000 0010 2 | |
| // 1000 0001 -127 129 0111 1110 1000 0000 128 | |
| else if (128 < len) | |
| { | |
| val = data[dind++]; | |
| len = (len ^ 0xFF) + 2; | |
| while (len-- > 0) | |
| output[ind++] = val; | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment