From 3f4bf7a0c743223071dde28771428af6080b2f32 Mon Sep 17 00:00:00 2001 From: Lucas CHOLLET Date: Thu, 18 Jan 2024 19:56:46 -0500 Subject: [PATCH] LibGfx/ExifOrientedBitmap: Add support for `CMYKBitmap` --- .../LibGfx/ImageFormats/ExifOrientedBitmap.h | 35 ++++++++++++++----- .../LibGfx/ImageFormats/JPEGXLLoader.cpp | 2 +- .../LibGfx/ImageFormats/TIFFLoader.cpp | 2 +- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/Userland/Libraries/LibGfx/ImageFormats/ExifOrientedBitmap.h b/Userland/Libraries/LibGfx/ImageFormats/ExifOrientedBitmap.h index c4d5f8ed93e..21f135c2fd0 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/ExifOrientedBitmap.h +++ b/Userland/Libraries/LibGfx/ImageFormats/ExifOrientedBitmap.h @@ -1,32 +1,45 @@ /* - * Copyright (c) 2023, Lucas Chollet + * Copyright (c) 2023-2024, Lucas Chollet * * SPDX-License-Identifier: BSD-2-Clause */ #pragma once +#include #include #include #include namespace Gfx { + +namespace Detail { + +template class ExifOrientedBitmap { public: - template static ErrorOr create(TIFF::Orientation orientation, IntSize size, BitmapFormat format) + requires(SameAs) { 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 create(TIFF::Orientation orientation, IntSize size) + requires(SameAs) { - 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() + template 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& bitmap() { return m_bitmap; } @@ -51,7 +64,7 @@ public: private: using Orientation = TIFF::Orientation; - ExifOrientedBitmap(NonnullRefPtr bitmap, IntSize size, Orientation orientation) + ExifOrientedBitmap(NonnullRefPtr 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 m_bitmap; + NonnullRefPtr m_bitmap; Orientation m_orientation; u32 m_width {}; u32 m_height {}; }; + +} + +using ExifOrientedBitmap = Detail::ExifOrientedBitmap; +using ExifOrientedCMYKBitmap = Detail::ExifOrientedBitmap; + } diff --git a/Userland/Libraries/LibGfx/ImageFormats/JPEGXLLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/JPEGXLLoader.cpp index d79a7c21de6..2e1ea6e7e56 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/JPEGXLLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/JPEGXLLoader.cpp @@ -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()); } } diff --git a/Userland/Libraries/LibGfx/ImageFormats/TIFFLoader.cpp b/Userland/Libraries/LibGfx/ImageFormats/TIFFLoader.cpp index 37ae162c4f3..9b66836d2d2 100644 --- a/Userland/Libraries/LibGfx/ImageFormats/TIFFLoader.cpp +++ b/Userland/Libraries/LibGfx/ImageFormats/TIFFLoader.cpp @@ -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();