mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 11:07:35 +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
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/Concepts.h>
|
||||||
#include <AK/NonnullOwnPtr.h>
|
#include <AK/NonnullOwnPtr.h>
|
||||||
#include <LibGfx/Bitmap.h>
|
#include <LibGfx/Bitmap.h>
|
||||||
#include <LibGfx/ImageFormats/TIFFMetadata.h>
|
#include <LibGfx/ImageFormats/TIFFMetadata.h>
|
||||||
|
|
||||||
namespace Gfx {
|
namespace Gfx {
|
||||||
|
|
||||||
|
namespace Detail {
|
||||||
|
|
||||||
|
template<typename BitmapLike>
|
||||||
class ExifOrientedBitmap {
|
class ExifOrientedBitmap {
|
||||||
public:
|
public:
|
||||||
template<typename... Args>
|
|
||||||
static ErrorOr<ExifOrientedBitmap> create(TIFF::Orientation orientation, IntSize size, BitmapFormat format)
|
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)));
|
auto bitmap = TRY(Bitmap::create(format, oriented_size(size, orientation)));
|
||||||
return ExifOrientedBitmap(move(bitmap), 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));
|
auto bitmap = TRY(CMYKBitmap::create_with_size(oriented_size(size, orientation)));
|
||||||
m_bitmap->scanline(new_position.y())[new_position.x()] = color.value();
|
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;
|
return m_bitmap;
|
||||||
}
|
}
|
||||||
|
@ -51,7 +64,7 @@ public:
|
||||||
private:
|
private:
|
||||||
using Orientation = TIFF::Orientation;
|
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_bitmap(move(bitmap))
|
||||||
, m_orientation(orientation)
|
, m_orientation(orientation)
|
||||||
, m_width(size.width())
|
, m_width(size.width())
|
||||||
|
@ -90,10 +103,16 @@ private:
|
||||||
VERIFY_NOT_REACHED();
|
VERIFY_NOT_REACHED();
|
||||||
}
|
}
|
||||||
|
|
||||||
NonnullRefPtr<Bitmap> m_bitmap;
|
NonnullRefPtr<BitmapLike> m_bitmap;
|
||||||
Orientation m_orientation;
|
Orientation m_orientation;
|
||||||
|
|
||||||
u32 m_width {};
|
u32 m_width {};
|
||||||
u32 m_height {};
|
u32 m_height {};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
using ExifOrientedBitmap = Detail::ExifOrientedBitmap<Bitmap>;
|
||||||
|
using ExifOrientedCMYKBitmap = Detail::ExifOrientedBitmap<CMYKBitmap>;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1750,7 +1750,7 @@ public:
|
||||||
to_u8(m_channels[*alpha_channel].get(x, y)),
|
to_u8(m_channels[*alpha_channel].get(x, y)),
|
||||||
};
|
};
|
||||||
}();
|
}();
|
||||||
oriented_bitmap.set_pixel(x, y, color);
|
oriented_bitmap.set_pixel(x, y, color.value());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -272,7 +272,7 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
last_color = color;
|
last_color = color;
|
||||||
oriented_bitmap.set_pixel(column, scanline, color);
|
oriented_bitmap.set_pixel(column, scanline, color.value());
|
||||||
}
|
}
|
||||||
|
|
||||||
decoded_stream->align_to_byte_boundary();
|
decoded_stream->align_to_byte_boundary();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue