Skip to content

Commit 45b7490

Browse files
Remove enum boxing allocations (#863)
1 parent 5eb0122 commit 45b7490

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

src/ImageSharp/Formats/Gif/GifEncoderCore.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream)
9292
ImageMetaData metaData = image.MetaData;
9393
this.gifMetaData = metaData.GetFormatMetaData(GifFormat.Instance);
9494
this.colorTableMode = this.colorTableMode ?? this.gifMetaData.ColorTableMode;
95-
bool useGlobalTable = this.colorTableMode.Equals(GifColorTableMode.Global);
95+
bool useGlobalTable = this.colorTableMode == GifColorTableMode.Global;
9696

9797
// Quantize the image returning a palette.
9898
QuantizedFrame<TPixel> quantized =

src/ImageSharp/Formats/Png/PngEncoderCore.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ public PngEncoderCore(MemoryAllocator memoryAllocator, IPngEncoderOptions option
185185
this.pngColorType = options.ColorType;
186186

187187
// Specification recommends default filter method None for paletted images and Paeth for others.
188-
this.pngFilterMethod = options.FilterMethod ?? (options.ColorType.Equals(PngColorType.Palette)
188+
this.pngFilterMethod = options.FilterMethod ?? (options.ColorType == PngColorType.Palette
189189
? PngFilterMethod.None
190190
: PngFilterMethod.Paeth);
191191
this.compressionLevel = options.CompressionLevel;
@@ -217,7 +217,7 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream)
217217
this.writeGamma = this.gamma > 0;
218218
this.pngColorType = this.pngColorType ?? pngMetaData.ColorType;
219219
this.pngBitDepth = this.pngBitDepth ?? pngMetaData.BitDepth;
220-
this.use16Bit = this.pngBitDepth.Equals(PngBitDepth.Bit16);
220+
this.use16Bit = this.pngBitDepth == PngBitDepth.Bit16;
221221

222222
// Ensure we are not allowing impossible combinations.
223223
if (!ColorTypes.ContainsKey(this.pngColorType.Value))
@@ -329,7 +329,7 @@ private void CollectGrayscaleBytes<TPixel>(ReadOnlySpan<TPixel> rowSpan)
329329
Span<byte> rawScanlineSpan = this.rawScanline.GetSpan();
330330
ref byte rawScanlineSpanRef = ref MemoryMarshal.GetReference(rawScanlineSpan);
331331

332-
if (this.pngColorType.Equals(PngColorType.Grayscale))
332+
if (this.pngColorType == PngColorType.Grayscale)
333333
{
334334
if (this.use16Bit)
335335
{
@@ -761,7 +761,7 @@ private void WriteGammaChunk(Stream stream)
761761
private void WriteTransparencyChunk(Stream stream, PngMetaData pngMetaData)
762762
{
763763
Span<byte> alpha = this.chunkDataBuffer.AsSpan();
764-
if (pngMetaData.ColorType.Equals(PngColorType.Rgb))
764+
if (pngMetaData.ColorType == PngColorType.Rgb)
765765
{
766766
if (pngMetaData.TransparentRgb48.HasValue && this.use16Bit)
767767
{
@@ -782,7 +782,7 @@ private void WriteTransparencyChunk(Stream stream, PngMetaData pngMetaData)
782782
this.WriteChunk(stream, PngChunkType.Transparency, this.chunkDataBuffer, 0, 6);
783783
}
784784
}
785-
else if (pngMetaData.ColorType.Equals(PngColorType.Grayscale))
785+
else if (pngMetaData.ColorType == PngColorType.Grayscale)
786786
{
787787
if (pngMetaData.TransparentGray16.HasValue && this.use16Bit)
788788
{

0 commit comments

Comments
 (0)