mirror of
https://github.com/RGBCube/serenity
synced 2025-05-30 16:58:11 +00:00
LibGfx: Add CMYKBitmap
This is a simple container for 2d CMYK data. This is a new class instead of a new format in Bitmap because: * Almost all clients of Bitmap will want to deal with RGB data * It keeps the ARGB32 typedef working * Bitmap already does a lot of things The idea is that a few select places will be able to use CMYKBitmap and a color profile to do a better CMYK -> RGB conversion than an image decoder could do, and then store the result in a Bitmap for later display then. CMYKBitmap misses some of Bitmap's features, such as shared memory support, high-dpi scaling capability, etc.
This commit is contained in:
parent
c997ee7b9d
commit
bc6eebb1d7
4 changed files with 88 additions and 0 deletions
18
Userland/Libraries/LibGfx/CMYKBitmap.cpp
Normal file
18
Userland/Libraries/LibGfx/CMYKBitmap.cpp
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024, Nico Weber <thakis@chromium.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <LibGfx/CMYKBitmap.h>
|
||||||
|
|
||||||
|
namespace Gfx {
|
||||||
|
|
||||||
|
ErrorOr<NonnullRefPtr<CMYKBitmap>> CMYKBitmap::create_with_size(IntSize const& size)
|
||||||
|
{
|
||||||
|
VERIFY(size.width() >= 0 && size.height() >= 0);
|
||||||
|
auto data = TRY(ByteBuffer::create_uninitialized(size.width() * size.height() * sizeof(CMYK)));
|
||||||
|
return adopt_ref(*new CMYKBitmap(size, move(data)));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
68
Userland/Libraries/LibGfx/CMYKBitmap.h
Normal file
68
Userland/Libraries/LibGfx/CMYKBitmap.h
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024, Nico Weber <thakis@chromium.org>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/ByteBuffer.h>
|
||||||
|
#include <AK/NonnullRefPtr.h>
|
||||||
|
#include <AK/RefCounted.h>
|
||||||
|
#include <LibGfx/Size.h>
|
||||||
|
|
||||||
|
namespace Gfx {
|
||||||
|
|
||||||
|
struct CMYK {
|
||||||
|
u8 c;
|
||||||
|
u8 m;
|
||||||
|
u8 y;
|
||||||
|
u8 k;
|
||||||
|
};
|
||||||
|
|
||||||
|
class CMYKBitmap : public RefCounted<CMYKBitmap> {
|
||||||
|
public:
|
||||||
|
static ErrorOr<NonnullRefPtr<CMYKBitmap>> create_with_size(IntSize const& size);
|
||||||
|
|
||||||
|
IntSize const& size() const { return m_size; }
|
||||||
|
|
||||||
|
[[nodiscard]] CMYK* scanline(int y);
|
||||||
|
[[nodiscard]] CMYK const* scanline(int y) const;
|
||||||
|
|
||||||
|
[[nodiscard]] CMYK* begin();
|
||||||
|
[[nodiscard]] CMYK* end();
|
||||||
|
|
||||||
|
private:
|
||||||
|
CMYKBitmap(IntSize const& size, ByteBuffer data)
|
||||||
|
: m_size(size)
|
||||||
|
, m_data(move(data))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
IntSize m_size;
|
||||||
|
ByteBuffer m_data;
|
||||||
|
};
|
||||||
|
|
||||||
|
inline CMYK* CMYKBitmap::scanline(int y)
|
||||||
|
{
|
||||||
|
VERIFY(y >= 0 && y < m_size.height());
|
||||||
|
return reinterpret_cast<CMYK*>(m_data.data() + y * m_size.width() * sizeof(CMYK));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline CMYK const* CMYKBitmap::scanline(int y) const
|
||||||
|
{
|
||||||
|
VERIFY(y >= 0 && y < m_size.height());
|
||||||
|
return reinterpret_cast<CMYK const*>(m_data.data() + y * m_size.width() * sizeof(CMYK));
|
||||||
|
}
|
||||||
|
|
||||||
|
inline CMYK* CMYKBitmap::begin()
|
||||||
|
{
|
||||||
|
return reinterpret_cast<CMYK*>(m_data.data());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline CMYK* CMYKBitmap::end()
|
||||||
|
{
|
||||||
|
return reinterpret_cast<CMYK*>(m_data.data() + m_data.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -3,6 +3,7 @@ set(SOURCES
|
||||||
AntiAliasingPainter.cpp
|
AntiAliasingPainter.cpp
|
||||||
Bitmap.cpp
|
Bitmap.cpp
|
||||||
BitmapMixer.cpp
|
BitmapMixer.cpp
|
||||||
|
CMYKBitmap.cpp
|
||||||
ClassicStylePainter.cpp
|
ClassicStylePainter.cpp
|
||||||
ClassicWindowTheme.cpp
|
ClassicWindowTheme.cpp
|
||||||
Color.cpp
|
Color.cpp
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
namespace Gfx {
|
namespace Gfx {
|
||||||
|
|
||||||
class Bitmap;
|
class Bitmap;
|
||||||
|
class CMYKBitmap;
|
||||||
class ImmutableBitmap;
|
class ImmutableBitmap;
|
||||||
class CharacterBitmap;
|
class CharacterBitmap;
|
||||||
class Color;
|
class Color;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue