From 32cd3f280945e714a85d3123e7d66dc0cdf039bb Mon Sep 17 00:00:00 2001 From: Jason Nelson Date: Mon, 11 Jun 2018 12:03:09 -0700 Subject: [PATCH] Eliminate subsample allocation in JpegEncoder --- src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs index 37279d526..aa624838c 100644 --- a/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs +++ b/src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs @@ -1,6 +1,7 @@ // Copyright (c) Six Labors and contributors. // Licensed under the Apache License, Version 2.0. +using System; using System.IO; using System.Runtime.CompilerServices; @@ -736,16 +737,16 @@ namespace SixLabors.ImageSharp.Formats.Jpeg private void WriteStartOfFrame(int width, int height, int componentCount) { // "default" to 4:2:0 - byte[] subsamples = { 0x22, 0x11, 0x11 }; + Span subsamples = stackalloc byte[] { 0x22, 0x11, 0x11 }; byte[] chroma = { 0x00, 0x01, 0x01 }; switch (this.subsample) { case JpegSubsample.Ratio444: - subsamples = new byte[] { 0x11, 0x11, 0x11 }; + subsamples = stackalloc byte[] { 0x11, 0x11, 0x11 }; break; case JpegSubsample.Ratio420: - subsamples = new byte[] { 0x22, 0x11, 0x11 }; + subsamples = stackalloc byte[] { 0x22, 0x11, 0x11 }; break; }