1212using System ;
1313using System . Collections . Generic ;
1414using System . IO ;
15+ using System . IO . Compression ;
1516using System . Linq ;
1617using System . Net ;
1718using System . Text ;
18- using ICSharpCode . SharpZipLib . Zip . Compression ;
19- using ICSharpCode . SharpZipLib . Zip . Compression . Streams ;
2019using OpenRA . Graphics ;
2120using OpenRA . Primitives ;
2221
2322namespace OpenRA . FileFormats
2423{
2524 public class Png
2625 {
27- public enum Compression : byte
28- {
29- BEST_COMPRESSION = Deflater . BEST_COMPRESSION ,
30- BEST_SPEED = Deflater . BEST_SPEED ,
31- }
32-
3326 static readonly byte [ ] Signature = [ 0x89 , 0x50 , 0x4e , 0x47 , 0x0d , 0x0a , 0x1a , 0x0a ] ;
3427
3528 public int Width { get ; }
@@ -139,7 +132,7 @@ public Png(Stream s)
139132 {
140133 using ( var ns = new MemoryStream ( data . ToArray ( ) ) )
141134 {
142- using ( var ds = new InflaterInputStream ( ns ) )
135+ using ( var ds = new ZLibStream ( ns , CompressionMode . Decompress ) )
143136 {
144137 var pxStride = PixelStride ;
145138 var rowStride = Width * pxStride ;
@@ -340,7 +333,7 @@ static void WritePngChunk(MemoryStream output, string type, MemoryStream input)
340333 output . Write ( IPAddress . NetworkToHostOrder ( ( int ) finalCrc ) ) ;
341334 }
342335
343- public byte [ ] Save ( Compression compression = Compression . BEST_COMPRESSION )
336+ public byte [ ] Save ( CompressionLevel compression = CompressionLevel . SmallestSize )
344337 {
345338 using ( var output = new MemoryStream ( ) )
346339 {
@@ -392,7 +385,7 @@ public byte[] Save(Compression compression = Compression.BEST_COMPRESSION)
392385
393386 using ( var data = new MemoryStream ( ) )
394387 {
395- using ( var compressed = new DeflaterOutputStream ( data , new Deflater ( ( int ) compression ) ) )
388+ using ( var compressed = new ZLibStream ( data , compression , true ) )
396389 {
397390 var rowStride = Width * PixelStride ;
398391 for ( var y = 0 ; y < Height ; y ++ )
@@ -402,12 +395,9 @@ public byte[] Save(Compression compression = Compression.BEST_COMPRESSION)
402395 compressed . WriteByte ( FilterType ) ;
403396 compressed . Write ( Data , y * rowStride , rowStride ) ;
404397 }
405-
406- compressed . Flush ( ) ;
407- compressed . Finish ( ) ;
408-
409- WritePngChunk ( output , "IDAT" , data ) ;
410398 }
399+
400+ WritePngChunk ( output , "IDAT" , data ) ;
411401 }
412402
413403 foreach ( var kv in EmbeddedData )
@@ -424,7 +414,7 @@ public byte[] Save(Compression compression = Compression.BEST_COMPRESSION)
424414 }
425415 }
426416
427- public void Save ( string path , Compression compression = Compression . BEST_COMPRESSION )
417+ public void Save ( string path , CompressionLevel compression = CompressionLevel . SmallestSize )
428418 {
429419 File . WriteAllBytes ( path , Save ( compression ) ) ;
430420 }
0 commit comments