From d8ada20bae5c640d7e7454ca0ac9618d04fc5ded Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Sun, 7 Jan 2024 22:18:18 -0500 Subject: [PATCH] LibGfx: Allow images to report that they are originally grayscale ...and implement it in JPEGLoader. Since it's easy to get the grayscale data off a Bitmap, don't add a grayscale_frame() accessor. --- Userland/Libraries/LibGfx/ImageFormats/ImageDecoder.h | 1 + Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/ImageDecoder.h b/Userland/Libraries/LibGfx/ImageFormats/ImageDecoder.h index 92626d37c4..7f4ff02ecc 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/ImageDecoder.h +++ b/Userland/Libraries/LibGfx/ImageFormats/ImageDecoder.h @@ -31,6 +31,7 @@ struct VectorImageFrameDescriptor { enum class NaturalFrameFormat { RGB, + Grayscale, CMYK, Vector, }; diff --git a/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp index 3f8bc1a27a..6ae1b4cb3b 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/JPEGLoader.cpp @@ -2010,7 +2010,11 @@ NaturalFrameFormat JPEGImageDecoderPlugin::natural_frame_format() const if (m_context->state == JPEGLoadingContext::State::Error) return NaturalFrameFormat::RGB; VERIFY(m_context->state >= JPEGLoadingContext::State::HeaderDecoded); - return m_context->components.size() == 4 ? NaturalFrameFormat::CMYK : NaturalFrameFormat::RGB; + if (m_context->components.size() == 1) + return NaturalFrameFormat::Grayscale; + if (m_context->components.size() == 4) + return NaturalFrameFormat::CMYK; + return NaturalFrameFormat::RGB; } ErrorOr> JPEGImageDecoderPlugin::cmyk_frame()