public static AccessibleBitmap Decompress(byte[] source, int width, int height, int pixelBytes) { BitStreamFIFO bs = new BitStreamFIFO(source); // Convert the image into a bitstream bool verticallyCompressed = bs.ReadBool(); // Store if image was vertically compressed or not int maxBitCount = bs.ReadByte(); // Get the highest bitcount value AccessibleBitmap bmp = new AccessibleBitmap(width, height, pixelBytes); // Create new bitmap to write all pixels to // Ints to keep track of coords int x = 0; int y = 0; // Loop while there are still bits to read while (bs.Length > maxBitCount) { int counterValue = bs.ReadInt(maxBitCount); // Get the counter value of the next pixel value byte[] pixel = bs.ReadByteArray(pixelBytes); // Get the pixel value for (int i = 0; i < counterValue; i++) { bmp.SetPixel(x, y, pixel); if (verticallyCompressed) { y++; if (y >= height) { x++; y = 0; } }else { x++; if (x >= width) { y++; x = 0; } } } } // Return the bitmap return bmp; }