Browse Source

Merge pull request #1750 from SixLabors/bp/tiffjpegcompression

Revert unoptimized edits to Jpeg Encoder.
pull/1756/head
James Jackson-South 5 years ago
committed by GitHub
parent
commit
ffa3935809
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/ImageSharp/Formats/Jpeg/Components/Block8x8F.cs
  2. 2
      src/ImageSharp/Formats/Jpeg/Components/Encoder/RgbForwardConverter{TPixel}.cs
  3. 16
      src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs

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

@ -104,7 +104,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
{ {
GuardBlockIndex(idx); GuardBlockIndex(idx);
ref float selfRef = ref Unsafe.As<Block8x8F, float>(ref this); ref float selfRef = ref Unsafe.As<Block8x8F, float>(ref this);
return Unsafe.Add(ref selfRef, idx); return Unsafe.Add(ref selfRef, (nint)(uint)idx);
} }
[MethodImpl(MethodImplOptions.AggressiveInlining)] [MethodImpl(MethodImplOptions.AggressiveInlining)]
@ -112,7 +112,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components
{ {
GuardBlockIndex(idx); GuardBlockIndex(idx);
ref float selfRef = ref Unsafe.As<Block8x8F, float>(ref this); ref float selfRef = ref Unsafe.As<Block8x8F, float>(ref this);
Unsafe.Add(ref selfRef, idx) = value; Unsafe.Add(ref selfRef, (nint)(uint)idx) = value;
} }
} }

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

@ -103,7 +103,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg.Components.Encoder
for (int i = 0; i < Block8x8F.Size; i++) for (int i = 0; i < Block8x8F.Size; i++)
{ {
Rgb24 c = Unsafe.Add(ref rgbStart, i); Rgb24 c = Unsafe.Add(ref rgbStart, (nint)(uint)i);
redBlock[i] = c.R; redBlock[i] = c.R;
greenBlock[i] = c.G; greenBlock[i] = c.G;

16
src/ImageSharp/Formats/Jpeg/JpegEncoderCore.cs

@ -567,14 +567,14 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
// This uses a C#'s compiler optimization that refers to the static data segment of the assembly, // This uses a C#'s compiler optimization that refers to the static data segment of the assembly,
// and doesn't incur any allocation at all. // and doesn't incur any allocation at all.
// "default" to 4:2:0 // "default" to 4:2:0
ReadOnlySpan<byte> subsamples = stackalloc byte[] ReadOnlySpan<byte> subsamples = new byte[]
{ {
0x22, 0x22,
0x11, 0x11,
0x11 0x11
}; };
ReadOnlySpan<byte> chroma = stackalloc byte[] ReadOnlySpan<byte> chroma = new byte[]
{ {
0x00, 0x00,
0x01, 0x01,
@ -583,7 +583,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
if (this.colorType == JpegColorType.Luminance) if (this.colorType == JpegColorType.Luminance)
{ {
subsamples = stackalloc byte[] subsamples = new byte[]
{ {
0x11, 0x11,
0x00, 0x00,
@ -596,7 +596,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
{ {
case JpegColorType.YCbCrRatio444: case JpegColorType.YCbCrRatio444:
case JpegColorType.Rgb: case JpegColorType.Rgb:
subsamples = stackalloc byte[] subsamples = new byte[]
{ {
0x11, 0x11,
0x11, 0x11,
@ -605,7 +605,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
if (this.colorType == JpegColorType.Rgb) if (this.colorType == JpegColorType.Rgb)
{ {
chroma = stackalloc byte[] chroma = new byte[]
{ {
0x00, 0x00,
0x00, 0x00,
@ -615,7 +615,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
break; break;
case JpegColorType.YCbCrRatio420: case JpegColorType.YCbCrRatio420:
subsamples = stackalloc byte[] subsamples = new byte[]
{ {
0x22, 0x22,
0x11, 0x11,
@ -658,7 +658,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
{ {
// This uses a C#'s compiler optimization that refers to the static data segment of the assembly, // This uses a C#'s compiler optimization that refers to the static data segment of the assembly,
// and doesn't incur any allocation at all. // and doesn't incur any allocation at all.
ReadOnlySpan<byte> huffmanId = stackalloc byte[] ReadOnlySpan<byte> huffmanId = new byte[]
{ {
0x00, 0x00,
0x11, 0x11,
@ -668,7 +668,7 @@ namespace SixLabors.ImageSharp.Formats.Jpeg
// Use the same DC/AC tables for all channels for RGB. // Use the same DC/AC tables for all channels for RGB.
if (this.colorType == JpegColorType.Rgb) if (this.colorType == JpegColorType.Rgb)
{ {
huffmanId = stackalloc byte[] huffmanId = new byte[]
{ {
0x00, 0x00,
0x00, 0x00,

Loading…
Cancel
Save