From af14ed6b2e3348baeb484f344bd01e8f06b4d130 Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Fri, 23 Jun 2023 00:15:49 -0400 Subject: [PATCH] LibGfx/JPEG: Accept grayscale images with an App14 segment The adobe specification doesn't even consider JPEG images with a single component. So let's not consider the content of the App14 segment for grayscale images. --- Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp index f9ce0a33df..6ef7be07af 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp @@ -1687,7 +1687,9 @@ static void ycck_to_rgb(JPEGLoadingContext const& context, Vector& m static ErrorOr handle_color_transform(JPEGLoadingContext const& context, Vector& macroblocks) { - if (context.color_transform.has_value()) { + // Note: This is non-standard but some encoder still add the App14 segment for grayscale images. + // So let's ignore the color transform value if we only have one component. + if (context.color_transform.has_value() && context.components.size() != 1) { // https://www.itu.int/rec/dologin_pub.asp?lang=e&id=T-REC-T.872-201206-I!!PDF-E&type=items // 6.5.3 - APP14 marker segment for colour encoding