mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-04 05:20:30 +00:00
LibGfx/ExifOrientedBitmap: Add support for CMYKBitmap
This commit is contained in:
parent
c80b2cf782
commit
3f4bf7a0c7
Notes:
sideshowbarker
2024-07-17 06:00:02 +09:00
Author: https://github.com/LucasChollet Commit: https://github.com/SerenityOS/serenity/commit/3f4bf7a0c7 Pull-request: https://github.com/SerenityOS/serenity/pull/22856 Reviewed-by: https://github.com/ADKaster ✅ Reviewed-by: https://github.com/nico ✅
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>;
|
||||
|
||||
}
|
||||
|
|
|
@ -1750,7 +1750,7 @@ public:
|
|||
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;
|
||||
oriented_bitmap.set_pixel(column, scanline, color);
|
||||
oriented_bitmap.set_pixel(column, scanline, color.value());
|
||||
}
|
||||
|
||||
decoded_stream->align_to_byte_boundary();
|
||||
|
|
Loading…
Reference in a new issue