Skip to content

Commit 0d87319

Browse files
committed
LibPDF: Make indexed lab color spaces work
We have to use the scale of the underlying color space. For most color spaces, that's [0.0, 1.0], but not for lab color spaces. The spec comment at the start of this function already tells us what to do, but the code used to not do it. Now it does.
1 parent 8dd302a commit 0d87319

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

Userland/Libraries/LibPDF/ColorSpace.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -703,7 +703,8 @@ PDFErrorOr<NonnullRefPtr<ColorSpace>> IndexedColorSpace::create(Document* docume
703703
return Error { Error::Type::MalformedPDF, "Indexed color space expects stream or string for third arg" };
704704
}
705705

706-
size_t needed_size = (hival + 1) * base->number_of_components();
706+
size_t const n = base->number_of_components();
707+
size_t needed_size = (hival + 1) * n;
707708
if (lookup.size() - 1 == needed_size) {
708709
// FIXME: Could do this if lookup.size() > needed_size generally, but so far I've only seen files that had one byte too much.
709710
lookup.resize(needed_size);
@@ -714,9 +715,10 @@ PDFErrorOr<NonnullRefPtr<ColorSpace>> IndexedColorSpace::create(Document* docume
714715
}
715716

716717
Vector<float> lookup_float;
718+
auto decode = base->default_decode();
717719
lookup_float.resize(lookup.size());
718720
for (size_t i = 0; i < lookup.size(); ++i)
719-
lookup_float[i] = lookup[i] / 255.0f;
721+
lookup_float[i] = mix(decode[2 * (i % n)], decode[2 * (i % n) + 1], lookup[i] / 255.0f);
720722

721723
auto color_space = adopt_ref(*new IndexedColorSpace(move(base)));
722724
color_space->m_hival = hival;

0 commit comments

Comments
 (0)