@@ -167,14 +167,10 @@ public void Encode<TPixel>(Image<TPixel> image, Stream stream, CancellationToken
167167 /// <param name="colorType">The color type.</param>
168168 /// <returns>true, if color type is supported.</returns>
169169 private static bool IsSupportedColorType ( JpegColorType ? colorType )
170- {
171- if ( colorType == JpegColorType . YCbCrRatio444 || colorType == JpegColorType . YCbCrRatio420 || colorType == JpegColorType . Luminance || colorType == JpegColorType . Rgb )
172- {
173- return true ;
174- }
175-
176- return false ;
177- }
170+ => colorType == JpegColorType . YCbCrRatio444
171+ || colorType == JpegColorType . YCbCrRatio420
172+ || colorType == JpegColorType . Luminance
173+ || colorType == JpegColorType . Rgb ;
178174
179175 /// <summary>
180176 /// Gets the component ids.
@@ -571,14 +567,14 @@ private void WriteStartOfFrame(int width, int height, int componentCount, ReadOn
571567 // This uses a C#'s compiler optimization that refers to the static data segment of the assembly,
572568 // and doesn't incur any allocation at all.
573569 // "default" to 4:2:0
574- ReadOnlySpan < byte > subsamples = new byte [ ]
570+ ReadOnlySpan < byte > subsamples = stackalloc byte [ ]
575571 {
576572 0x22 ,
577573 0x11 ,
578574 0x11
579575 } ;
580576
581- ReadOnlySpan < byte > chroma = new byte [ ]
577+ ReadOnlySpan < byte > chroma = stackalloc byte [ ]
582578 {
583579 0x00 ,
584580 0x01 ,
@@ -587,7 +583,7 @@ private void WriteStartOfFrame(int width, int height, int componentCount, ReadOn
587583
588584 if ( this . colorType == JpegColorType . Luminance )
589585 {
590- subsamples = new byte [ ]
586+ subsamples = stackalloc byte [ ]
591587 {
592588 0x11 ,
593589 0x00 ,
@@ -600,7 +596,7 @@ private void WriteStartOfFrame(int width, int height, int componentCount, ReadOn
600596 {
601597 case JpegColorType . YCbCrRatio444 :
602598 case JpegColorType . Rgb :
603- subsamples = new byte [ ]
599+ subsamples = stackalloc byte [ ]
604600 {
605601 0x11 ,
606602 0x11 ,
@@ -609,7 +605,7 @@ private void WriteStartOfFrame(int width, int height, int componentCount, ReadOn
609605
610606 if ( this . colorType == JpegColorType . Rgb )
611607 {
612- chroma = new byte [ ]
608+ chroma = stackalloc byte [ ]
613609 {
614610 0x00 ,
615611 0x00 ,
@@ -619,7 +615,7 @@ private void WriteStartOfFrame(int width, int height, int componentCount, ReadOn
619615
620616 break ;
621617 case JpegColorType . YCbCrRatio420 :
622- subsamples = new byte [ ]
618+ subsamples = stackalloc byte [ ]
623619 {
624620 0x22 ,
625621 0x11 ,
@@ -662,7 +658,7 @@ private void WriteStartOfScan(int componentCount, ReadOnlySpan<byte> componentId
662658 {
663659 // This uses a C#'s compiler optimization that refers to the static data segment of the assembly,
664660 // and doesn't incur any allocation at all.
665- ReadOnlySpan < byte > huffmanId = new byte [ ]
661+ ReadOnlySpan < byte > huffmanId = stackalloc byte [ ]
666662 {
667663 0x00 ,
668664 0x11 ,
@@ -672,7 +668,7 @@ private void WriteStartOfScan(int componentCount, ReadOnlySpan<byte> componentId
672668 // Use the same DC/AC tables for all channels for RGB.
673669 if ( this . colorType == JpegColorType . Rgb )
674670 {
675- huffmanId = new byte [ ]
671+ huffmanId = stackalloc byte [ ]
676672 {
677673 0x00 ,
678674 0x00 ,
0 commit comments