diff --git a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
index 32d2a6a9a6..d325b0df02 100644
--- a/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
+++ b/src/ImageSharp/Formats/Jpeg/JpegDecoderCore.cs
@@ -530,6 +530,12 @@ private JpegColorSpace DeduceJpegColorSpace(byte componentCount)
return JpegColorSpace.RGB;
}
+ // If these values are 1-3 for a 3-channel image, then the image is assumed to be YCbCr.
+ if (this.Components[2].Id == 3 && this.Components[1].Id == 2 && this.Components[0].Id == 1)
+ {
+ return JpegColorSpace.YCbCr;
+ }
+
// 3-channel non-subsampled images are assumed to be RGB.
if (this.Components[2].VerticalSamplingFactor == 1 && this.Components[1].VerticalSamplingFactor == 1 && this.Components[0].VerticalSamplingFactor == 1 &&
this.Components[2].HorizontalSamplingFactor == 1 && this.Components[1].HorizontalSamplingFactor == 1 && this.Components[0].HorizontalSamplingFactor == 1)
diff --git a/src/ImageSharp/Formats/Webp/WebpDecoderCore.cs b/src/ImageSharp/Formats/Webp/WebpDecoderCore.cs
index 0e00f037ca..7f1f8023fe 100644
--- a/src/ImageSharp/Formats/Webp/WebpDecoderCore.cs
+++ b/src/ImageSharp/Formats/Webp/WebpDecoderCore.cs
@@ -660,14 +660,22 @@ private uint ReadChunkSize()
///
/// The chunk type.
/// True, if its an optional chunk type.
- private static bool IsOptionalVp8XChunk(WebpChunkType chunkType) => chunkType switch
+ private static bool IsOptionalVp8XChunk(WebpChunkType chunkType)
{
- WebpChunkType.Alpha => true,
- WebpChunkType.Animation => true,
- WebpChunkType.Exif => true,
- WebpChunkType.Iccp => true,
- WebpChunkType.Xmp => true,
- _ => false
- };
+ switch (chunkType)
+ {
+ case WebpChunkType.Alpha:
+ case WebpChunkType.Iccp:
+ case WebpChunkType.Exif:
+ case WebpChunkType.Xmp:
+ return true;
+ case WebpChunkType.AnimationParameter:
+ case WebpChunkType.Animation:
+ WebpThrowHelper.ThrowNotSupportedException("Animated webp are not yet supported.");
+ return false;
+ default:
+ return false;
+ }
+ }
}
}
diff --git a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
index 1faa6f0f4c..d12c840a1b 100644
--- a/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
+++ b/tests/ImageSharp.Tests/Formats/Jpg/JpegDecoderTests.cs
@@ -216,6 +216,19 @@ public void Issue2057_DecodeWorks(TestImageProvider provider)
}
}
+ // https://github.com/SixLabors/ImageSharp/issues/2133
+ [Theory]
+ [WithFile(TestImages.Jpeg.Issues.Issue2133DeduceColorSpace, PixelTypes.Rgba32)]
+ public void Issue2133_DeduceColorSpace(TestImageProvider provider)
+ where TPixel : unmanaged, IPixel
+ {
+ using (Image image = provider.GetImage(JpegDecoder))
+ {
+ image.DebugSave(provider);
+ image.CompareToOriginal(provider);
+ }
+ }
+
// DEBUG ONLY!
// The PDF.js output should be saved by "tests\ImageSharp.Tests\Formats\Jpg\pdfjs\jpeg-converter.htm"
// into "\tests\Images\ActualOutput\JpegDecoderTests\"
diff --git a/tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs b/tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs
index f29fa5d793..275ff0b0fe 100644
--- a/tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs
+++ b/tests/ImageSharp.Tests/Formats/WebP/WebpDecoderTests.cs
@@ -1,6 +1,7 @@
// Copyright (c) Six Labors.
// Licensed under the Apache License, Version 2.0.
+using System;
using System.IO;
using SixLabors.ImageSharp.Formats.Webp;
using SixLabors.ImageSharp.PixelFormats;
@@ -369,6 +370,19 @@ public void WebpDecoder_ThrowImageFormatException_OnInvalidImages(TestIm
}
});
+ // https://github.com/SixLabors/ImageSharp/issues/2154
+ [Theory]
+ [WithFile(Lossless.Issue2154, PixelTypes.Rgba32)]
+ public void WebpDecoder_ThrowsNotSupportedException_Issue2154(TestImageProvider provider)
+ where TPixel : unmanaged, IPixel =>
+ Assert.Throws(
+ () =>
+ {
+ using (provider.GetImage(WebpDecoder))
+ {
+ }
+ });
+
#if SUPPORTS_RUNTIME_INTRINSICS
private static void RunDecodeLossyWithHorizontalFilter()
{
diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs
index 25f3b0e549..13f965a592 100644
--- a/tests/ImageSharp.Tests/TestImages.cs
+++ b/tests/ImageSharp.Tests/TestImages.cs
@@ -265,6 +265,7 @@ public static class Issues
public const string Issue2057App1Parsing = "Jpg/issues/Issue2057-App1Parsing.jpg";
public const string ExifNullArrayTag = "Jpg/issues/issue-2056-exif-null-array.jpg";
public const string ValidExifArgumentNullExceptionOnEncode = "Jpg/issues/Issue2087-exif-null-reference-on-encode.jpg";
+ public const string Issue2133DeduceColorSpace = "Jpg/issues/Issue2133.jpg";
public static class Fuzz
{
@@ -631,6 +632,9 @@ public static class Lossless
public const string LossLessCorruptImage3 = "Webp/lossless_color_transform.webp"; // cross_color, predictor
public const string LossLessCorruptImage4 = "Webp/near_lossless_75.webp"; // predictor, cross_color.
+
+ // Issues
+ public const string Issue2154 = "Webp/issues/Issue2154.webp";
}
public static class Lossy
diff --git a/tests/Images/Input/Jpg/issues/Issue2133.jpg b/tests/Images/Input/Jpg/issues/Issue2133.jpg
new file mode 100644
index 0000000000..c51962a607
--- /dev/null
+++ b/tests/Images/Input/Jpg/issues/Issue2133.jpg
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:7be837f931a350906f04542a868c3654a35b4f463ec814939aed3d134c7e56fe
+size 1140
diff --git a/tests/Images/Input/Webp/issues/Issue2154.webp b/tests/Images/Input/Webp/issues/Issue2154.webp
new file mode 100644
index 0000000000..85048eb91a
--- /dev/null
+++ b/tests/Images/Input/Webp/issues/Issue2154.webp
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:df1160649539a1f73d4c52043358092c59c584763daf18007ff73b72865ddbc1
+size 37342