Browse Source

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.
Nico Weber 1 year ago
parent
commit
d8ada20bae

+ 1 - 0
Userland/Libraries/LibGfx/ImageFormats/ImageDecoder.h

@@ -31,6 +31,7 @@ struct VectorImageFrameDescriptor {
 
 enum class NaturalFrameFormat {
     RGB,
+    Grayscale,
     CMYK,
     Vector,
 };

+ 5 - 1
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<NonnullRefPtr<CMYKBitmap>> JPEGImageDecoderPlugin::cmyk_frame()