コード例 #1
0
 public ZopfliStream(Stream inner, ZopfliFormat type, ZopfliOptions options, bool leaveOpen)
 {
     _innerStream   = inner;
     this.type      = type;
     this.options   = options;
     this.leaveOpen = leaveOpen;
 }
コード例 #2
0
ファイル: Zopfli.cs プロジェクト: miked30/libzopfli-sharp
        /// <summary>
        /// Internal convert method to convert byte array to compressed byte array
        /// </summary>
        /// <param name="data_in">Uncompressed data array</param>
        /// <param name="type">Format type, DEFLATE, GZIP, ZLIB</param>
        /// <param name="options">Compression options</param>
        /// <returns>Compressed data array</returns>
        public static byte[] compress(byte[] data_in, ZopfliFormat type, ZopfliOptions options)
        {
            IntPtr  result      = IntPtr.Zero;
            UIntPtr result_size = UIntPtr.Zero;

            try
            {
                // Get image data length
                UIntPtr data_size = (UIntPtr)data_in.Length;

                // Compress the data via native methods
                if (Environment.Is64BitProcess)
                {
                    ZopfliCompressor64.ZopfliCompress(ref options, type, data_in, data_in.Length, ref result, ref result_size);
                }
                else
                {
                    ZopfliCompressor32.ZopfliCompress(ref options, type, data_in, data_in.Length, ref result, ref result_size);
                }

                // Copy data back to managed memory and return
                return(NativeUtilities.GetDataFromUnmanagedMemory(result, (int)result_size));
            }
            catch
            {
                throw;
            }
            finally
            {
                // Free unmanaged memory
                Marshal.FreeHGlobal(result);
            }
        }
コード例 #3
0
 public ZopfliStream(Stream inner, ZopfliFormat type, bool leaveOpen)
 {
     _innerStream   = inner;
     this.type      = type;
     options        = new ZopfliOptions();
     this.leaveOpen = leaveOpen;
 }
コード例 #4
0
 public ZopfliStream(Stream inner, ZopfliFormat type, ZopfliOptions options)
 {
     _innerStream   = inner;
     this.type      = type;
     this.options   = options;
     this.leaveOpen = false;
 }
コード例 #5
0
 public ZopfliStream(Stream inner, ZopfliFormat type)
 {
     _innerStream   = inner;
     this.type      = type;
     options        = new ZopfliOptions();
     this.leaveOpen = false;
 }
コード例 #6
0
 public ZopfliStream(Stream inner)
 {
     _innerStream   = inner;
     type           = ZopfliFormat.ZOPFLI_FORMAT_DEFLATE;
     options        = new ZopfliOptions();
     this.leaveOpen = false;
 }
コード例 #7
0
 protected override void Dispose(bool disposing)
 {
     base.Dispose(disposing);
     if (!leaveOpen)
     {
         _innerStream.Dispose();
     }
     options = null;
 }
コード例 #8
0
 protected override void Dispose(bool disposing)
 {
     base.Dispose(disposing);
     _innerStream.Dispose();
     options = null;
 }
コード例 #9
0
 public ZopfliStream(Stream inner)
 {
     _innerStream = inner;
     type         = ZopfliFormat.ZOPFLI_FORMAT_DEFLATE;
     options      = new ZopfliOptions();
 }