mirror of
https://github.com/UglyToad/PdfPig.git
synced 2025-04-05 20:55:01 +08:00
Use BinaryPrimitives
This commit is contained in:
parent
03fd2832ac
commit
247303983a
@ -1,6 +1,7 @@
|
||||
namespace UglyToad.PdfPig.Images.Png
|
||||
{
|
||||
using System;
|
||||
using System.Buffers.Binary;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Text;
|
||||
@ -155,7 +156,7 @@
|
||||
return false;
|
||||
}
|
||||
|
||||
var length = StreamHelper.ReadBigEndianInt32(headerBytes, 0);
|
||||
var length = BinaryPrimitives.ReadInt32BigEndian(headerBytes.AsSpan(0, 4));
|
||||
|
||||
var name = Encoding.ASCII.GetString(headerBytes, 4, 4);
|
||||
|
||||
@ -195,8 +196,8 @@
|
||||
throw new InvalidOperationException($"Did not read 4 bytes for the CRC, only found: {read}.");
|
||||
}
|
||||
|
||||
var width = StreamHelper.ReadBigEndianInt32(ihdrBytes, 0);
|
||||
var height = StreamHelper.ReadBigEndianInt32(ihdrBytes, 4);
|
||||
var width = BinaryPrimitives.ReadInt32BigEndian(ihdrBytes.AsSpan(0, 4));
|
||||
var height = BinaryPrimitives.ReadInt32BigEndian(ihdrBytes.AsSpan(4, 4));
|
||||
var bitDepth = ihdrBytes[8];
|
||||
var colorType = ihdrBytes[9];
|
||||
var compressionMethod = ihdrBytes[10];
|
||||
|
@ -11,12 +11,6 @@
|
||||
+ (ReadOrTerminate(stream) << 8) + ReadOrTerminate(stream);
|
||||
}
|
||||
|
||||
public static int ReadBigEndianInt32(byte[] bytes, int offset)
|
||||
{
|
||||
return (bytes[0 + offset] << 24) + (bytes[1 + offset] << 16)
|
||||
+ (bytes[2 + offset] << 8) + bytes[3 + offset];
|
||||
}
|
||||
|
||||
public static void WriteBigEndianInt32(Stream stream, int value)
|
||||
{
|
||||
stream.WriteByte((byte)(value >> 24));
|
||||
|
Loading…
Reference in New Issue
Block a user