mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-23 09:48:56 +00:00
LibGfx: Add support for YCCK jpeg files
This commit is contained in:
parent
7b0b6e7493
commit
19bee8393d
Notes:
github-actions[bot]
2025-03-22 16:36:27 +00:00
Author: https://github.com/aplefull
Commit: 19bee8393d
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3887
Reviewed-by: https://github.com/nico ✅
1 changed files with 34 additions and 1 deletions
|
@ -81,8 +81,10 @@ ErrorOr<void> JPEGLoadingContext::decode()
|
|||
if (jpeg_read_header(&cinfo, TRUE) != JPEG_HEADER_OK)
|
||||
return Error::from_string_literal("Failed to read JPEG header");
|
||||
|
||||
if (cinfo.jpeg_color_space == JCS_CMYK || cinfo.jpeg_color_space == JCS_YCCK) {
|
||||
if (cinfo.jpeg_color_space == JCS_CMYK) {
|
||||
cinfo.out_color_space = JCS_CMYK;
|
||||
} else if (cinfo.jpeg_color_space == JCS_YCCK) {
|
||||
cinfo.out_color_space = JCS_YCCK;
|
||||
} else {
|
||||
cinfo.out_color_space = JCS_EXT_BGRX;
|
||||
}
|
||||
|
@ -112,6 +114,37 @@ ErrorOr<void> JPEGLoadingContext::decode()
|
|||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// If image is in YCCK color space, we convert it to CMYK
|
||||
// and then CMYK code path will handle the rest
|
||||
if (cinfo.out_color_space == JCS_YCCK) {
|
||||
for (int i = 0; i < cmyk_bitmap->size().height(); ++i) {
|
||||
for (int j = 0; j < cmyk_bitmap->size().width(); ++j) {
|
||||
auto const& cmyk = cmyk_bitmap->scanline(i)[j];
|
||||
|
||||
auto y = cmyk.c;
|
||||
auto cb = cmyk.m;
|
||||
auto cr = cmyk.y;
|
||||
auto k = cmyk.k;
|
||||
|
||||
int r = y + 1.402f * (cr - 128);
|
||||
int g = y - 0.3441f * (cb - 128) - 0.7141f * (cr - 128);
|
||||
int b = y + 1.772f * (cb - 128);
|
||||
|
||||
y = clamp(r, 0, 255);
|
||||
cb = clamp(g, 0, 255);
|
||||
cr = clamp(b, 0, 255);
|
||||
k = 255 - k;
|
||||
|
||||
cmyk_bitmap->scanline(i)[j] = {
|
||||
y,
|
||||
cb,
|
||||
cr,
|
||||
k,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JOCTET* icc_data_ptr = nullptr;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue