Преглед изворни кода

LibPDF: Extract ICCBasedColorSpace::sRGB() helper

Nico Weber пре 1 година
родитељ
комит
c161b2d2f9
2 измењених фајлова са 10 додато и 4 уклоњено
  1. 8 4
      Userland/Libraries/LibPDF/ColorSpace.cpp
  2. 2 0
      Userland/Libraries/LibPDF/ColorSpace.h

+ 8 - 4
Userland/Libraries/LibPDF/ColorSpace.cpp

@@ -499,9 +499,6 @@ ICCBasedColorSpace::ICCBasedColorSpace(NonnullRefPtr<Gfx::ICC::Profile> profile)
 
 
 PDFErrorOr<ColorOrStyle> ICCBasedColorSpace::style(ReadonlySpan<Value> arguments) const
 PDFErrorOr<ColorOrStyle> ICCBasedColorSpace::style(ReadonlySpan<Value> arguments) const
 {
 {
-    if (!s_srgb_profile)
-        s_srgb_profile = TRY(Gfx::ICC::sRGB());
-
     Vector<u8> bytes;
     Vector<u8> bytes;
     for (size_t i = 0; i < arguments.size(); ++i) {
     for (size_t i = 0; i < arguments.size(); ++i) {
         auto const& arg = arguments[i];
         auto const& arg = arguments[i];
@@ -522,7 +519,7 @@ PDFErrorOr<ColorOrStyle> ICCBasedColorSpace::style(ReadonlySpan<Value> arguments
 
 
     auto pcs = TRY(m_profile->to_pcs(bytes));
     auto pcs = TRY(m_profile->to_pcs(bytes));
     Array<u8, 3> output;
     Array<u8, 3> output;
-    TRY(s_srgb_profile->from_pcs(m_profile, pcs, output.span()));
+    TRY(sRGB()->from_pcs(m_profile, pcs, output.span()));
 
 
     return Color(output[0], output[1], output[2]);
     return Color(output[0], output[1], output[2]);
 }
 }
@@ -553,6 +550,13 @@ Vector<float> ICCBasedColorSpace::default_decode() const
     }
     }
 }
 }
 
 
+NonnullRefPtr<Gfx::ICC::Profile> ICCBasedColorSpace::sRGB()
+{
+    if (!s_srgb_profile)
+        s_srgb_profile = MUST(Gfx::ICC::sRGB());
+    return *s_srgb_profile;
+}
+
 PDFErrorOr<NonnullRefPtr<LabColorSpace>> LabColorSpace::create(Document* document, Vector<Value>&& parameters)
 PDFErrorOr<NonnullRefPtr<LabColorSpace>> LabColorSpace::create(Document* document, Vector<Value>&& parameters)
 {
 {
     if (parameters.size() != 1)
     if (parameters.size() != 1)

+ 2 - 0
Userland/Libraries/LibPDF/ColorSpace.h

@@ -188,6 +188,8 @@ public:
     Vector<float> default_decode() const override;
     Vector<float> default_decode() const override;
     ColorSpaceFamily const& family() const override { return ColorSpaceFamily::ICCBased; }
     ColorSpaceFamily const& family() const override { return ColorSpaceFamily::ICCBased; }
 
 
+    static NonnullRefPtr<Gfx::ICC::Profile> sRGB();
+
 private:
 private:
     ICCBasedColorSpace(NonnullRefPtr<Gfx::ICC::Profile>);
     ICCBasedColorSpace(NonnullRefPtr<Gfx::ICC::Profile>);