Skip to content

Commit ffa3935

Browse files
Merge pull request #1750 from SixLabors/bp/tiffjpegcompression
Revert unoptimized edits to Jpeg Encoder.
2 parents 659daff + b4a5335 commit ffa3935

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,15 +104,15 @@ public float this[int idx]
104104
{
105105
GuardBlockIndex(idx);
106106
ref float selfRef = ref Unsafe.As<Block8x8F, float>(ref this);
107-
return Unsafe.Add(ref selfRef, idx);
107+
return Unsafe.Add(ref selfRef, (nint)(uint)idx);
108108
}
109109

110110
[MethodImpl(MethodImplOptions.AggressiveInlining)]
111111
set
112112
{
113113
GuardBlockIndex(idx);
114114
ref float selfRef = ref Unsafe.As<Block8x8F, float>(ref this);
115-
Unsafe.Add(ref selfRef, idx) = value;
115+
Unsafe.Add(ref selfRef, (nint)(uint)idx) = value;
116116
}
117117
}
118118

src/ImageSharp/Formats/Jpeg/Components/Encoder/RgbForwardConverter{TPixel}.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ private static void CopyToBlock(Span<Rgb24> rgbSpan, ref Block8x8F redBlock, ref
103103

104104
for (int i = 0; i < Block8x8F.Size; i++)
105105
{
106-
Rgb24 c = Unsafe.Add(ref rgbStart, i);
106+
Rgb24 c = Unsafe.Add(ref rgbStart, (nint)(uint)i);
107107

108108
redBlock[i] = c.R;
109109
greenBlock[i] = c.G;

src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -567,14 +567,14 @@ private void WriteStartOfFrame(int width, int height, int componentCount, ReadOn
567567
// This uses a C#'s compiler optimization that refers to the static data segment of the assembly,
568568
// and doesn't incur any allocation at all.
569569
// "default" to 4:2:0
570-
ReadOnlySpan<byte> subsamples = stackalloc byte[]
570+
ReadOnlySpan<byte> subsamples = new byte[]
571571
{
572572
0x22,
573573
0x11,
574574
0x11
575575
};
576576

577-
ReadOnlySpan<byte> chroma = stackalloc byte[]
577+
ReadOnlySpan<byte> chroma = new byte[]
578578
{
579579
0x00,
580580
0x01,
@@ -583,7 +583,7 @@ private void WriteStartOfFrame(int width, int height, int componentCount, ReadOn
583583

584584
if (this.colorType == JpegColorType.Luminance)
585585
{
586-
subsamples = stackalloc byte[]
586+
subsamples = new byte[]
587587
{
588588
0x11,
589589
0x00,
@@ -596,7 +596,7 @@ private void WriteStartOfFrame(int width, int height, int componentCount, ReadOn
596596
{
597597
case JpegColorType.YCbCrRatio444:
598598
case JpegColorType.Rgb:
599-
subsamples = stackalloc byte[]
599+
subsamples = new byte[]
600600
{
601601
0x11,
602602
0x11,
@@ -605,7 +605,7 @@ private void WriteStartOfFrame(int width, int height, int componentCount, ReadOn
605605

606606
if (this.colorType == JpegColorType.Rgb)
607607
{
608-
chroma = stackalloc byte[]
608+
chroma = new byte[]
609609
{
610610
0x00,
611611
0x00,
@@ -615,7 +615,7 @@ private void WriteStartOfFrame(int width, int height, int componentCount, ReadOn
615615

616616
break;
617617
case JpegColorType.YCbCrRatio420:
618-
subsamples = stackalloc byte[]
618+
subsamples = new byte[]
619619
{
620620
0x22,
621621
0x11,
@@ -658,7 +658,7 @@ private void WriteStartOfScan(int componentCount, ReadOnlySpan<byte> componentId
658658
{
659659
// This uses a C#'s compiler optimization that refers to the static data segment of the assembly,
660660
// and doesn't incur any allocation at all.
661-
ReadOnlySpan<byte> huffmanId = stackalloc byte[]
661+
ReadOnlySpan<byte> huffmanId = new byte[]
662662
{
663663
0x00,
664664
0x11,
@@ -668,7 +668,7 @@ private void WriteStartOfScan(int componentCount, ReadOnlySpan<byte> componentId
668668
// Use the same DC/AC tables for all channels for RGB.
669669
if (this.colorType == JpegColorType.Rgb)
670670
{
671-
huffmanId = stackalloc byte[]
671+
huffmanId = new byte[]
672672
{
673673
0x00,
674674
0x00,

0 commit comments

Comments
 (0)