mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 09:37:34 +00:00
LibPDF: Convert LAB values to bytes differently
Gfx::ICC::Profile's current API takes bytes, so we need to do some contortions for LAB values to go through. This will probably become nicer once we implement all the backward transforms in Gfx::ICC::Profile, but for now let's hack it in on the LibPDF side. Makes colors in 0000651.pdf looks good, especially on pages 1 and 7-12.
This commit is contained in:
parent
715d0bacdb
commit
4cb0593daf
1 changed files with 14 additions and 2 deletions
|
@ -499,9 +499,21 @@ PDFErrorOr<Color> ICCBasedColorSpace::color(ReadonlySpan<Value> arguments) const
|
||||||
s_srgb_profile = TRY(Gfx::ICC::sRGB());
|
s_srgb_profile = TRY(Gfx::ICC::sRGB());
|
||||||
|
|
||||||
Vector<u8> bytes;
|
Vector<u8> bytes;
|
||||||
for (auto const& arg : arguments) {
|
for (size_t i = 0; i < arguments.size(); ++i) {
|
||||||
|
auto const& arg = arguments[i];
|
||||||
VERIFY(arg.has_number());
|
VERIFY(arg.has_number());
|
||||||
bytes.append(static_cast<u8>(arg.to_float() * 255.0f));
|
float number = arg.to_float();
|
||||||
|
|
||||||
|
if (m_profile->data_color_space() == Gfx::ICC::ColorSpace::CIELAB) {
|
||||||
|
// CIELAB channels go from 0..100 and -128..127 instead of from 0..1.
|
||||||
|
// FIXME: We should probably have an API on Gfx::ICC::Profile that takes floats instead of bytes and that does this internally instead.
|
||||||
|
if (i == 0)
|
||||||
|
number /= 100.0f;
|
||||||
|
else
|
||||||
|
number = (number + 128.0f) / 255.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
bytes.append(static_cast<u8>(number * 255.0f));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto pcs = TRY(m_profile->to_pcs(bytes));
|
auto pcs = TRY(m_profile->to_pcs(bytes));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue