mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-24 01:42:17 +00:00
Some checks are pending
CI / macOS, arm64, Sanitizer_CI, Clang (push) Waiting to run
CI / Linux, x86_64, Fuzzers_CI, Clang (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, GNU (push) Waiting to run
CI / Linux, x86_64, Sanitizer_CI, Clang (push) Waiting to run
Package the js repl as a binary artifact / Linux, arm64 (push) Waiting to run
Package the js repl as a binary artifact / macOS, arm64 (push) Waiting to run
Package the js repl as a binary artifact / Linux, x86_64 (push) Waiting to run
Run test262 and test-wasm / run_and_update_results (push) Waiting to run
Lint Code / lint (push) Waiting to run
Label PRs with merge conflicts / auto-labeler (push) Waiting to run
Push notes / build (push) Waiting to run
This makes it a bit easier to reason about where bitmaps should be available.
41 lines
1.2 KiB
C++
41 lines
1.2 KiB
C++
/*
|
|
* Copyright (c) 2024, Nico Weber <thakis@chromium.org>
|
|
*
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
*/
|
|
|
|
#include <AK/Checked.h>
|
|
#include <LibGfx/CMYKBitmap.h>
|
|
|
|
namespace Gfx {
|
|
|
|
ErrorOr<NonnullRefPtr<CMYKBitmap>> CMYKBitmap::create_with_size(IntSize const& size)
|
|
{
|
|
VERIFY(size.width() >= 0 && size.height() >= 0);
|
|
Checked<int> final_size { size.width() };
|
|
final_size.mul(size.height());
|
|
final_size.mul(sizeof(CMYK));
|
|
if (final_size.has_overflow())
|
|
return Error::from_string_literal("Image dimensions cause an integer overflow");
|
|
auto data = TRY(ByteBuffer::create_uninitialized(final_size.value()));
|
|
return adopt_ref(*new CMYKBitmap(size, move(data)));
|
|
}
|
|
|
|
ErrorOr<NonnullRefPtr<Bitmap>> CMYKBitmap::to_low_quality_rgb() const
|
|
{
|
|
if (!m_rgb_bitmap) {
|
|
m_rgb_bitmap = TRY(Bitmap::create(BitmapFormat::BGRx8888, m_size));
|
|
|
|
for (int y = 0; y < m_size.height(); ++y) {
|
|
for (int x = 0; x < m_size.width(); ++x) {
|
|
auto const& cmyk = scanline(y)[x];
|
|
u8 k = 255 - cmyk.k;
|
|
m_rgb_bitmap->scanline(y)[x] = Color((255 - cmyk.c) * k / 255, (255 - cmyk.m) * k / 255, (255 - cmyk.y) * k / 255).value();
|
|
}
|
|
}
|
|
}
|
|
|
|
return *m_rgb_bitmap;
|
|
}
|
|
|
|
}
|