|
|
|
@ -606,16 +606,9 @@ namespace SixLabors.ImageSharp.Formats.Png |
|
|
|
/// <param name="header">The <see cref="PngHeader"/>.</param>
|
|
|
|
private void WriteHeaderChunk(Stream stream, in PngHeader header) |
|
|
|
{ |
|
|
|
BinaryPrimitives.WriteInt32BigEndian(this.chunkDataBuffer.AsSpan(0, 4), header.Width); |
|
|
|
BinaryPrimitives.WriteInt32BigEndian(this.chunkDataBuffer.AsSpan(4, 4), header.Height); |
|
|
|
header.WriteTo(this.chunkDataBuffer); |
|
|
|
|
|
|
|
this.chunkDataBuffer[8] = header.BitDepth; |
|
|
|
this.chunkDataBuffer[9] = (byte)header.ColorType; |
|
|
|
this.chunkDataBuffer[10] = header.CompressionMethod; |
|
|
|
this.chunkDataBuffer[11] = header.FilterMethod; |
|
|
|
this.chunkDataBuffer[12] = (byte)header.InterlaceMethod; |
|
|
|
|
|
|
|
this.WriteChunk(stream, PngChunkType.Header, this.chunkDataBuffer, 0, 13); |
|
|
|
this.WriteChunk(stream, PngChunkType.Header, this.chunkDataBuffer, 0, PngHeader.Size); |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
@ -697,28 +690,24 @@ namespace SixLabors.ImageSharp.Formats.Png |
|
|
|
switch (meta.ResolutionUnits) |
|
|
|
{ |
|
|
|
case PixelResolutionUnit.AspectRatio: |
|
|
|
|
|
|
|
this.chunkDataBuffer[8] = 0; |
|
|
|
BinaryPrimitives.WriteInt32BigEndian(hResolution, (int)Math.Round(meta.HorizontalResolution)); |
|
|
|
BinaryPrimitives.WriteInt32BigEndian(vResolution, (int)Math.Round(meta.VerticalResolution)); |
|
|
|
break; |
|
|
|
|
|
|
|
case PixelResolutionUnit.PixelsPerInch: |
|
|
|
|
|
|
|
this.chunkDataBuffer[8] = 1; // Per meter
|
|
|
|
BinaryPrimitives.WriteInt32BigEndian(hResolution, (int)Math.Round(UnitConverter.InchToMeter(meta.HorizontalResolution))); |
|
|
|
BinaryPrimitives.WriteInt32BigEndian(vResolution, (int)Math.Round(UnitConverter.InchToMeter(meta.VerticalResolution))); |
|
|
|
break; |
|
|
|
|
|
|
|
case PixelResolutionUnit.PixelsPerCentimeter: |
|
|
|
|
|
|
|
this.chunkDataBuffer[8] = 1; // Per meter
|
|
|
|
BinaryPrimitives.WriteInt32BigEndian(hResolution, (int)Math.Round(UnitConverter.CmToMeter(meta.HorizontalResolution))); |
|
|
|
BinaryPrimitives.WriteInt32BigEndian(vResolution, (int)Math.Round(UnitConverter.CmToMeter(meta.VerticalResolution))); |
|
|
|
break; |
|
|
|
|
|
|
|
default: |
|
|
|
|
|
|
|
this.chunkDataBuffer[8] = 1; // Per meter
|
|
|
|
BinaryPrimitives.WriteInt32BigEndian(hResolution, (int)Math.Round(meta.HorizontalResolution)); |
|
|
|
BinaryPrimitives.WriteInt32BigEndian(vResolution, (int)Math.Round(meta.VerticalResolution)); |
|
|
|
@ -782,26 +771,22 @@ namespace SixLabors.ImageSharp.Formats.Png |
|
|
|
break; |
|
|
|
|
|
|
|
case PngFilterMethod.Sub: |
|
|
|
|
|
|
|
this.sub = this.memoryAllocator.AllocateManagedByteBuffer(resultLength, AllocationOptions.Clean); |
|
|
|
break; |
|
|
|
|
|
|
|
case PngFilterMethod.Up: |
|
|
|
|
|
|
|
this.up = this.memoryAllocator.AllocateManagedByteBuffer(resultLength, AllocationOptions.Clean); |
|
|
|
break; |
|
|
|
|
|
|
|
case PngFilterMethod.Average: |
|
|
|
|
|
|
|
this.average = this.memoryAllocator.AllocateManagedByteBuffer(resultLength, AllocationOptions.Clean); |
|
|
|
break; |
|
|
|
|
|
|
|
case PngFilterMethod.Paeth: |
|
|
|
|
|
|
|
this.paeth = this.memoryAllocator.AllocateManagedByteBuffer(resultLength, AllocationOptions.Clean); |
|
|
|
break; |
|
|
|
case PngFilterMethod.Adaptive: |
|
|
|
|
|
|
|
case PngFilterMethod.Adaptive: |
|
|
|
this.sub = this.memoryAllocator.AllocateManagedByteBuffer(resultLength, AllocationOptions.Clean); |
|
|
|
this.up = this.memoryAllocator.AllocateManagedByteBuffer(resultLength, AllocationOptions.Clean); |
|
|
|
this.average = this.memoryAllocator.AllocateManagedByteBuffer(resultLength, AllocationOptions.Clean); |
|
|
|
|