mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 15:37:46 +00:00
LibGfx/ExifOrientedBitmap: Add support for CMYKBitmap
This commit is contained in:
parent
c80b2cf782
commit
3f4bf7a0c7
3 changed files with 29 additions and 10 deletions
|
@ -1,32 +1,45 @@
|
|||
/*
|
||||
* Copyright (c) 2023, Lucas Chollet <lucas.chollet@serenityos.org>
|
||||
* Copyright (c) 2023-2024, Lucas Chollet <lucas.chollet@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <AK/Concepts.h>
|
||||
#include <AK/NonnullOwnPtr.h>
|
||||
#include <LibGfx/Bitmap.h>
|
||||
#include <LibGfx/ImageFormats/TIFFMetadata.h>
|
||||
|
||||
namespace Gfx {
|
||||
|
||||
namespace Detail {
|
||||
|
||||
template<typename BitmapLike>
|
||||
class ExifOrientedBitmap {
|
||||
public:
|
||||
template<typename... Args>
|
||||
static ErrorOr<ExifOrientedBitmap> create(TIFF::Orientation orientation, IntSize size, BitmapFormat format)
|
||||
requires(SameAs<BitmapLike, Bitmap>)
|
||||
{
|
||||
auto bitmap = TRY(Bitmap::create(format, oriented_size(size, orientation)));
|
||||
return ExifOrientedBitmap(move(bitmap), size, orientation);
|
||||
}
|
||||
|
||||
void set_pixel(u32 x, u32 y, Color color)
|
||||
static ErrorOr<ExifOrientedBitmap> create(TIFF::Orientation orientation, IntSize size)
|
||||
requires(SameAs<BitmapLike, CMYKBitmap>)
|
||||
{
|
||||
auto const new_position = oriented_position(IntPoint(x, y));
|
||||
m_bitmap->scanline(new_position.y())[new_position.x()] = color.value();
|
||||
auto bitmap = TRY(CMYKBitmap::create_with_size(oriented_size(size, orientation)));
|
||||
return ExifOrientedBitmap(move(bitmap), size, orientation);
|
||||
}
|
||||
|
||||
NonnullRefPtr<Bitmap>& bitmap()
|
||||
template<OneOf<ARGB32, CMYK> Value>
|
||||
void set_pixel(u32 x, u32 y, Value color)
|
||||
{
|
||||
auto const new_position = oriented_position(IntPoint(x, y));
|
||||
m_bitmap->scanline(new_position.y())[new_position.x()] = color;
|
||||
}
|
||||
|
||||
NonnullRefPtr<BitmapLike>& bitmap()
|
||||
{
|
||||
return m_bitmap;
|
||||
}
|
||||
|
@ -51,7 +64,7 @@ public:
|
|||
private:
|
||||
using Orientation = TIFF::Orientation;
|
||||
|
||||
ExifOrientedBitmap(NonnullRefPtr<Bitmap> bitmap, IntSize size, Orientation orientation)
|
||||
ExifOrientedBitmap(NonnullRefPtr<BitmapLike> bitmap, IntSize size, Orientation orientation)
|
||||
: m_bitmap(move(bitmap))
|
||||
, m_orientation(orientation)
|
||||
, m_width(size.width())
|
||||
|
@ -90,10 +103,16 @@ private:
|
|||
VERIFY_NOT_REACHED();
|
||||
}
|
||||
|
||||
NonnullRefPtr<Bitmap> m_bitmap;
|
||||
NonnullRefPtr<BitmapLike> m_bitmap;
|
||||
Orientation m_orientation;
|
||||
|
||||
u32 m_width {};
|
||||
u32 m_height {};
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
using ExifOrientedBitmap = Detail::ExifOrientedBitmap<Bitmap>;
|
||||
using ExifOrientedCMYKBitmap = Detail::ExifOrientedBitmap<CMYKBitmap>;
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue