mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 09:47:35 +00:00
LibPDF: Propogate errors from ColorSpace::color()
This commit is contained in:
parent
e989008471
commit
9a0e1dde42
3 changed files with 25 additions and 25 deletions
|
@ -69,7 +69,7 @@ NonnullRefPtr<DeviceGrayColorSpace> DeviceGrayColorSpace::the()
|
|||
return instance;
|
||||
}
|
||||
|
||||
Color DeviceGrayColorSpace::color(Vector<Value> const& arguments) const
|
||||
PDFErrorOr<Color> DeviceGrayColorSpace::color(Vector<Value> const& arguments) const
|
||||
{
|
||||
VERIFY(arguments.size() == 1);
|
||||
auto gray = static_cast<u8>(arguments[0].to_float() * 255.0f);
|
||||
|
@ -87,7 +87,7 @@ NonnullRefPtr<DeviceRGBColorSpace> DeviceRGBColorSpace::the()
|
|||
return instance;
|
||||
}
|
||||
|
||||
Color DeviceRGBColorSpace::color(Vector<Value> const& arguments) const
|
||||
PDFErrorOr<Color> DeviceRGBColorSpace::color(Vector<Value> const& arguments) const
|
||||
{
|
||||
VERIFY(arguments.size() == 3);
|
||||
auto r = static_cast<u8>(arguments[0].to_float() * 255.0f);
|
||||
|
@ -107,7 +107,7 @@ NonnullRefPtr<DeviceCMYKColorSpace> DeviceCMYKColorSpace::the()
|
|||
return instance;
|
||||
}
|
||||
|
||||
Color DeviceCMYKColorSpace::color(Vector<Value> const& arguments) const
|
||||
PDFErrorOr<Color> DeviceCMYKColorSpace::color(Vector<Value> const& arguments) const
|
||||
{
|
||||
VERIFY(arguments.size() == 4);
|
||||
auto c = arguments[0].to_float();
|
||||
|
@ -265,7 +265,7 @@ constexpr Array<float, 3> convert_to_srgb(Array<float, 3> xyz)
|
|||
return matrix_multiply(conversion_matrix, xyz);
|
||||
}
|
||||
|
||||
Color CalRGBColorSpace::color(Vector<Value> const& arguments) const
|
||||
PDFErrorOr<Color> CalRGBColorSpace::color(Vector<Value> const& arguments) const
|
||||
{
|
||||
VERIFY(arguments.size() == 3);
|
||||
auto a = clamp(arguments[0].to_float(), 0.0f, 1.0f);
|
||||
|
@ -329,10 +329,10 @@ ICCBasedColorSpace::ICCBasedColorSpace(NonnullRefPtr<Gfx::ICC::Profile> profile)
|
|||
{
|
||||
}
|
||||
|
||||
Color ICCBasedColorSpace::color(Vector<Value> const& arguments) const
|
||||
PDFErrorOr<Color> ICCBasedColorSpace::color(Vector<Value> const& arguments) const
|
||||
{
|
||||
if (!s_srgb_profile)
|
||||
s_srgb_profile = MUST(Gfx::ICC::sRGB());
|
||||
s_srgb_profile = TRY(Gfx::ICC::sRGB());
|
||||
|
||||
Vector<u8> bytes;
|
||||
for (auto const& arg : arguments) {
|
||||
|
@ -340,9 +340,9 @@ Color ICCBasedColorSpace::color(Vector<Value> const& arguments) const
|
|||
bytes.append(static_cast<u8>(arg.to_float() * 255.0f));
|
||||
}
|
||||
|
||||
auto pcs = MUST(m_profile->to_pcs(bytes));
|
||||
auto pcs = TRY(m_profile->to_pcs(bytes));
|
||||
Array<u8, 3> output;
|
||||
MUST(s_srgb_profile->from_pcs(pcs, output.span()));
|
||||
TRY(s_srgb_profile->from_pcs(pcs, output.span()));
|
||||
|
||||
return Color(output[0], output[1], output[2]);
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ public:
|
|||
|
||||
virtual ~ColorSpace() = default;
|
||||
|
||||
virtual Color color(Vector<Value> const& arguments) const = 0;
|
||||
virtual PDFErrorOr<Color> color(Vector<Value> const& arguments) const = 0;
|
||||
virtual int number_of_components() const = 0;
|
||||
virtual Vector<float> default_decode() const = 0;
|
||||
virtual ColorSpaceFamily const& family() const = 0;
|
||||
|
@ -67,7 +67,7 @@ public:
|
|||
|
||||
~DeviceGrayColorSpace() override = default;
|
||||
|
||||
Color color(Vector<Value> const& arguments) const override;
|
||||
PDFErrorOr<Color> color(Vector<Value> const& arguments) const override;
|
||||
int number_of_components() const override { return 1; }
|
||||
Vector<float> default_decode() const override;
|
||||
ColorSpaceFamily const& family() const override { return ColorSpaceFamily::DeviceGray; }
|
||||
|
@ -82,7 +82,7 @@ public:
|
|||
|
||||
~DeviceRGBColorSpace() override = default;
|
||||
|
||||
Color color(Vector<Value> const& arguments) const override;
|
||||
PDFErrorOr<Color> color(Vector<Value> const& arguments) const override;
|
||||
int number_of_components() const override { return 3; }
|
||||
Vector<float> default_decode() const override;
|
||||
ColorSpaceFamily const& family() const override { return ColorSpaceFamily::DeviceRGB; }
|
||||
|
@ -97,7 +97,7 @@ public:
|
|||
|
||||
~DeviceCMYKColorSpace() override = default;
|
||||
|
||||
Color color(Vector<Value> const& arguments) const override;
|
||||
PDFErrorOr<Color> color(Vector<Value> const& arguments) const override;
|
||||
int number_of_components() const override { return 4; }
|
||||
Vector<float> default_decode() const override;
|
||||
ColorSpaceFamily const& family() const override { return ColorSpaceFamily::DeviceCMYK; }
|
||||
|
@ -112,7 +112,7 @@ public:
|
|||
|
||||
~CalRGBColorSpace() override = default;
|
||||
|
||||
Color color(Vector<Value> const& arguments) const override;
|
||||
PDFErrorOr<Color> color(Vector<Value> const& arguments) const override;
|
||||
int number_of_components() const override { return 3; }
|
||||
Vector<float> default_decode() const override;
|
||||
ColorSpaceFamily const& family() const override { return ColorSpaceFamily::CalRGB; }
|
||||
|
@ -132,7 +132,7 @@ public:
|
|||
|
||||
~ICCBasedColorSpace() override = default;
|
||||
|
||||
Color color(Vector<Value> const& arguments) const override;
|
||||
PDFErrorOr<Color> color(Vector<Value> const& arguments) const override;
|
||||
int number_of_components() const override { VERIFY_NOT_REACHED(); }
|
||||
Vector<float> default_decode() const override;
|
||||
ColorSpaceFamily const& family() const override { return ColorSpaceFamily::ICCBased; }
|
||||
|
|
|
@ -523,7 +523,7 @@ RENDERER_HANDLER(set_painting_space)
|
|||
|
||||
RENDERER_HANDLER(set_stroking_color)
|
||||
{
|
||||
state().stroke_color = state().stroke_color_space->color(args);
|
||||
state().stroke_color = TRY(state().stroke_color_space->color(args));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -534,13 +534,13 @@ RENDERER_HANDLER(set_stroking_color_extended)
|
|||
if (last_arg.has<NonnullRefPtr<Object>>() && last_arg.get<NonnullRefPtr<Object>>()->is<NameObject>())
|
||||
TODO();
|
||||
|
||||
state().stroke_color = state().stroke_color_space->color(args);
|
||||
state().stroke_color = TRY(state().stroke_color_space->color(args));
|
||||
return {};
|
||||
}
|
||||
|
||||
RENDERER_HANDLER(set_painting_color)
|
||||
{
|
||||
state().paint_color = state().paint_color_space->color(args);
|
||||
state().paint_color = TRY(state().paint_color_space->color(args));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -551,49 +551,49 @@ RENDERER_HANDLER(set_painting_color_extended)
|
|||
if (last_arg.has<NonnullRefPtr<Object>>() && last_arg.get<NonnullRefPtr<Object>>()->is<NameObject>())
|
||||
TODO();
|
||||
|
||||
state().paint_color = state().paint_color_space->color(args);
|
||||
state().paint_color = TRY(state().paint_color_space->color(args));
|
||||
return {};
|
||||
}
|
||||
|
||||
RENDERER_HANDLER(set_stroking_color_and_space_to_gray)
|
||||
{
|
||||
state().stroke_color_space = DeviceGrayColorSpace::the();
|
||||
state().stroke_color = state().stroke_color_space->color(args);
|
||||
state().stroke_color = TRY(state().stroke_color_space->color(args));
|
||||
return {};
|
||||
}
|
||||
|
||||
RENDERER_HANDLER(set_painting_color_and_space_to_gray)
|
||||
{
|
||||
state().paint_color_space = DeviceGrayColorSpace::the();
|
||||
state().paint_color = state().paint_color_space->color(args);
|
||||
state().paint_color = TRY(state().paint_color_space->color(args));
|
||||
return {};
|
||||
}
|
||||
|
||||
RENDERER_HANDLER(set_stroking_color_and_space_to_rgb)
|
||||
{
|
||||
state().stroke_color_space = DeviceRGBColorSpace::the();
|
||||
state().stroke_color = state().stroke_color_space->color(args);
|
||||
state().stroke_color = TRY(state().stroke_color_space->color(args));
|
||||
return {};
|
||||
}
|
||||
|
||||
RENDERER_HANDLER(set_painting_color_and_space_to_rgb)
|
||||
{
|
||||
state().paint_color_space = DeviceRGBColorSpace::the();
|
||||
state().paint_color = state().paint_color_space->color(args);
|
||||
state().paint_color = TRY(state().paint_color_space->color(args));
|
||||
return {};
|
||||
}
|
||||
|
||||
RENDERER_HANDLER(set_stroking_color_and_space_to_cmyk)
|
||||
{
|
||||
state().stroke_color_space = DeviceCMYKColorSpace::the();
|
||||
state().stroke_color = state().stroke_color_space->color(args);
|
||||
state().stroke_color = TRY(state().stroke_color_space->color(args));
|
||||
return {};
|
||||
}
|
||||
|
||||
RENDERER_HANDLER(set_painting_color_and_space_to_cmyk)
|
||||
{
|
||||
state().paint_color_space = DeviceCMYKColorSpace::the();
|
||||
state().paint_color = state().paint_color_space->color(args);
|
||||
state().paint_color = TRY(state().paint_color_space->color(args));
|
||||
return {};
|
||||
}
|
||||
|
||||
|
@ -795,7 +795,7 @@ PDFErrorOr<NonnullRefPtr<Gfx::Bitmap>> Renderer::load_image(NonnullRefPtr<Stream
|
|||
sample = sample.slice(bytes_per_component);
|
||||
component_values[i] = Value { component_value_decoders[i].interpolate(component[0]) };
|
||||
}
|
||||
auto color = color_space->color(component_values);
|
||||
auto color = TRY(color_space->color(component_values));
|
||||
bitmap->set_pixel(x, y, color);
|
||||
++x;
|
||||
if (x == width) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue