Skip to content

Commit 247caeb

Browse files
committed
Use ZlibStream for PNG compression instead of DeflateStream
1 parent 58ad31b commit 247caeb

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

source/AsepriteDotNet/IO/PngWriter.cs

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ private static void WriteSignature(BinaryWriter writer)
9292
// Bit Depth:
9393
// 1-byte integer that indicates the number of bits per sample. Valid
9494
// values depend on the color type used
95-
//
95+
//
9696
// -----------------------------------------------
9797
// | Color Type | Allowed bit depths |
9898
// -----------------------------------------------
@@ -128,8 +128,8 @@ private static void WriteSignature(BinaryWriter writer)
128128
//
129129
// Interlace Method:
130130
// 1-byte integer that indicates the transmission order of the image
131-
// data.
132-
//
131+
// data.
132+
//
133133
// ---------------------------------------
134134
// | Interlace Method | Value |
135135
// ---------------------------------------
@@ -159,7 +159,7 @@ private static void WriteIHDR(BinaryWriter writer, int width, int height)
159159
// the compression stream.
160160
//
161161
// The compression stream is a deflate stream including the Adler-32
162-
// trailer.
162+
// trailer.
163163
//
164164
// Each scanline of the image begins with a single byte that defines the
165165
// filter used on that scanline.
@@ -215,13 +215,9 @@ void FlushAll(MemoryStream stream)
215215

216216
using MemoryStream ms = new();
217217

218-
// Zlib deflate header for Default Compression
219-
ms.WriteByte(0x78);
220-
ms.WriteByte(0x9C);
221-
222218
Adler32 adler = new();
223219

224-
using (DeflateStream deflate = new DeflateStream(ms, CompressionMode.Compress, leaveOpen: true))
220+
using (ZLibStream deflate = new ZLibStream(ms, CompressionMode.Compress, leaveOpen: true))
225221
{
226222
ReadOnlySpan<byte> filter = stackalloc byte[1] { 0 }; // Filter mode 0
227223
for (int i = 0; i < data.Length; i += width)
@@ -278,7 +274,7 @@ private static void WriteIEND(BinaryWriter writer)
278274
//
279275
// If there is no data (Length = 0), then the data chunk is not written
280276
//
281-
// Length:
277+
// Length:
282278
// A 4-byte unsigned integer giving the number of bytes in the chunk's
283279
// data field. Only the data field. Do not include the length field
284280
// itself, the chunk type field, or the crc field
@@ -329,12 +325,12 @@ private static void WriteChunk(BinaryWriter writer, string chunkType, ReadOnlySp
329325

330326

331327
// Per https://www.w3.org/TR/png-3/#7Integers-and-byte-order
332-
//
333-
// "All integers that require more than one byte shall be in network
328+
//
329+
// "All integers that require more than one byte shall be in network
334330
// byte order"
335331
//
336-
// Basically, we have to ensure that all integer type values are in
337-
// BigEndian.
332+
// Basically, we have to ensure that all integer type values are in
333+
// BigEndian.
338334
//
339335
// This method will check for endianess and convert to BigEndian if needed.
340336
private static int ToBigEndian(int value)

0 commit comments

Comments
 (0)