mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 19:07:35 +00:00
LibGfx/JPEG+CMYKBitmap: Extract the CMYK to RGB conversion code
Right now, the JPEG decoder is the only one supporting CMYK, but that won't last for long. So, let's move the conversion to CMYKBitmap.
This commit is contained in:
parent
0462858247
commit
09b2b3539b
3 changed files with 23 additions and 19 deletions
|
@ -1694,24 +1694,6 @@ static void invert_colors_for_adobe_images(JPEGLoadingContext const& context, Ve
|
|||
}
|
||||
}
|
||||
|
||||
static ErrorOr<void> cmyk_to_rgb(JPEGLoadingContext& context)
|
||||
{
|
||||
VERIFY(context.cmyk_bitmap);
|
||||
VERIFY(!context.bitmap);
|
||||
|
||||
context.bitmap = TRY(Bitmap::create(BitmapFormat::BGRx8888, { context.frame.width, context.frame.height }));
|
||||
|
||||
for (int y = 0; y < context.frame.height; ++y) {
|
||||
for (int x = 0; x < context.frame.width; ++x) {
|
||||
auto const& cmyk = context.cmyk_bitmap->scanline(y)[x];
|
||||
u8 k = 255 - cmyk.k;
|
||||
context.bitmap->scanline(y)[x] = Color((255 - cmyk.c) * k / 255, (255 - cmyk.m) * k / 255, (255 - cmyk.y) * k / 255).value();
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
static void ycck_to_cmyk(Vector<Macroblock>& macroblocks)
|
||||
{
|
||||
// 7 - Conversions between colour encodings
|
||||
|
@ -2026,7 +2008,7 @@ ErrorOr<ImageFrameDescriptor> JPEGImageDecoderPlugin::frame(size_t index, Option
|
|||
}
|
||||
|
||||
if (m_context->cmyk_bitmap && !m_context->bitmap)
|
||||
TRY(cmyk_to_rgb(*m_context));
|
||||
return ImageFrameDescriptor { TRY(m_context->cmyk_bitmap->to_low_quality_rgb()), 0 };
|
||||
|
||||
return ImageFrameDescriptor { m_context->bitmap, 0 };
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue