/// <summary> /// Old Decompress method not using .NET compressor /// </summary> /// <param name="Data"></param> /// <returns></returns> public byte[] DecompressOld(byte[] Data) { byte[] decompressedPixelData = new byte[UncompressedLength]; // ZLIB if (version > BgfFile.VERSION9) { // init streams MemoryStream destStream = new MemoryStream(decompressedPixelData, true); ZOutputStream destZ = new ZOutputStream(destStream); // decompress destZ.Write(Data, 0, Data.Length); destZ.Flush(); destZ.finish(); // cleanup destStream.Dispose(); destZ.Dispose(); } // CRUSH else { #if WINCLR && X86 // decompress Crush32.Decompress(Data, 0, decompressedPixelData, 0, (int)UncompressedLength, CompressedLength); #else throw new Exception(ERRORCRUSHPLATFORM); #endif } // set decompressed array to pixeldata return decompressedPixelData; }
/// <summary> /// Returns a compressed byte[] of PixelData argument /// </summary> /// <param name="Data"></param> /// <returns></returns> public byte[] Compress(byte[] Data) { // allocate a buffer with uncompressed length to write compressed stream to byte[] tempBuffer = new byte[UncompressedLength]; int compressedLength; // ZLIB if (version > BgfFile.VERSION9) { // init streams MemoryStream destStream = new MemoryStream(tempBuffer, true); ZOutputStream destZ = new ZOutputStream(destStream, zlibConst.Z_BEST_COMPRESSION); // compress destZ.Write(Data, 0, Data.Length); destZ.Flush(); destZ.finish(); // update compressed length compressedLength = (int)destZ.TotalOut; // cleanup destStream.Dispose(); destZ.Dispose(); } // CRUSH else { #if WINCLR && X86 // compress to tempBuffer compressedLength = Crush32.Compress(Data, 0, tempBuffer, 0, (int)UncompressedLength); #else throw new Exception(ERRORCRUSHPLATFORM); #endif } // copy all bytes we actually used from tempBuffer to new PixelData byte[] newPixelData = new byte[compressedLength]; Array.Copy(tempBuffer, 0, newPixelData, 0, compressedLength); return newPixelData; }