2020-01-18 08:38:21 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2019-01-09 01:06:04 +00:00
|
|
|
#pragma once
|
|
|
|
|
2020-02-14 22:02:47 +00:00
|
|
|
#include <AK/Forward.h>
|
2019-06-21 16:58:45 +00:00
|
|
|
#include <AK/RefCounted.h>
|
2019-06-25 18:33:24 +00:00
|
|
|
#include <AK/RefPtr.h>
|
2020-02-14 22:02:47 +00:00
|
|
|
#include <LibGfx/Color.h>
|
2020-03-29 17:04:05 +00:00
|
|
|
#include <LibGfx/Forward.h>
|
2020-02-14 22:02:47 +00:00
|
|
|
#include <LibGfx/Rect.h>
|
2019-01-14 19:00:42 +00:00
|
|
|
|
2020-06-15 12:13:12 +00:00
|
|
|
#define ENUMERATE_IMAGE_FORMATS \
|
2020-06-21 09:00:22 +00:00
|
|
|
__ENUMERATE_IMAGE_FORMAT(pbm, ".pbm") \
|
2020-06-22 12:19:57 +00:00
|
|
|
__ENUMERATE_IMAGE_FORMAT(pgm, ".pgm") \
|
2020-06-15 12:13:12 +00:00
|
|
|
__ENUMERATE_IMAGE_FORMAT(png, ".png") \
|
2020-06-22 08:58:04 +00:00
|
|
|
__ENUMERATE_IMAGE_FORMAT(ppm, ".ppm") \
|
2020-06-17 19:37:16 +00:00
|
|
|
__ENUMERATE_IMAGE_FORMAT(gif, ".gif") \
|
2020-06-16 01:36:05 +00:00
|
|
|
__ENUMERATE_IMAGE_FORMAT(bmp, ".bmp") \
|
2020-06-22 07:03:56 +00:00
|
|
|
__ENUMERATE_IMAGE_FORMAT(ico, ".ico") \
|
|
|
|
__ENUMERATE_IMAGE_FORMAT(jpg, ".jpg") \
|
|
|
|
__ENUMERATE_IMAGE_FORMAT(jpg, ".jpeg")
|
2020-06-15 12:13:12 +00:00
|
|
|
|
2020-02-06 10:56:38 +00:00
|
|
|
namespace Gfx {
|
|
|
|
|
2020-02-14 22:02:47 +00:00
|
|
|
enum class BitmapFormat {
|
|
|
|
Invalid,
|
2020-06-17 19:37:16 +00:00
|
|
|
Indexed1,
|
|
|
|
Indexed2,
|
|
|
|
Indexed4,
|
|
|
|
Indexed8,
|
2021-03-16 10:48:42 +00:00
|
|
|
BGRx8888,
|
|
|
|
BGRA8888,
|
2020-02-14 22:02:47 +00:00
|
|
|
};
|
|
|
|
|
2021-01-16 22:57:57 +00:00
|
|
|
inline bool is_valid_bitmap_format(unsigned format)
|
|
|
|
{
|
|
|
|
switch (format) {
|
|
|
|
case (unsigned)BitmapFormat::Invalid:
|
|
|
|
case (unsigned)BitmapFormat::Indexed1:
|
|
|
|
case (unsigned)BitmapFormat::Indexed2:
|
|
|
|
case (unsigned)BitmapFormat::Indexed4:
|
|
|
|
case (unsigned)BitmapFormat::Indexed8:
|
2021-03-16 10:48:42 +00:00
|
|
|
case (unsigned)BitmapFormat::BGRx8888:
|
|
|
|
case (unsigned)BitmapFormat::BGRA8888:
|
2021-01-16 22:57:57 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-09-06 21:59:20 +00:00
|
|
|
enum class StorageFormat {
|
|
|
|
Indexed8,
|
2021-03-16 11:00:43 +00:00
|
|
|
BGRx8888,
|
|
|
|
BGRA8888,
|
2020-09-06 21:59:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static StorageFormat determine_storage_format(BitmapFormat format)
|
|
|
|
{
|
|
|
|
switch (format) {
|
2021-03-16 10:48:42 +00:00
|
|
|
case BitmapFormat::BGRx8888:
|
2021-03-16 11:00:43 +00:00
|
|
|
return StorageFormat::BGRx8888;
|
2021-03-16 10:48:42 +00:00
|
|
|
case BitmapFormat::BGRA8888:
|
2021-03-16 11:00:43 +00:00
|
|
|
return StorageFormat::BGRA8888;
|
2020-09-06 21:59:20 +00:00
|
|
|
case BitmapFormat::Indexed1:
|
|
|
|
case BitmapFormat::Indexed2:
|
|
|
|
case BitmapFormat::Indexed4:
|
|
|
|
case BitmapFormat::Indexed8:
|
|
|
|
return StorageFormat::Indexed8;
|
|
|
|
default:
|
2021-02-23 19:42:32 +00:00
|
|
|
VERIFY_NOT_REACHED();
|
2020-09-06 21:59:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-09-12 16:17:50 +00:00
|
|
|
struct BackingStore;
|
|
|
|
|
2020-04-12 10:19:18 +00:00
|
|
|
enum RotationDirection {
|
|
|
|
Left,
|
|
|
|
Right
|
|
|
|
};
|
|
|
|
|
2020-02-06 10:56:38 +00:00
|
|
|
class Bitmap : public RefCounted<Bitmap> {
|
2019-01-09 01:06:04 +00:00
|
|
|
public:
|
2021-01-15 11:09:37 +00:00
|
|
|
enum class ShouldCloseAnonymousFile {
|
|
|
|
No,
|
|
|
|
Yes,
|
|
|
|
};
|
|
|
|
|
2021-01-19 17:10:47 +00:00
|
|
|
static RefPtr<Bitmap> create(BitmapFormat, const IntSize&, int intrinsic_scale = 1);
|
|
|
|
static RefPtr<Bitmap> create_shareable(BitmapFormat, const IntSize&, int intrinsic_scale = 1);
|
|
|
|
static RefPtr<Bitmap> create_purgeable(BitmapFormat, const IntSize&, int intrinsic_scale = 1);
|
|
|
|
static RefPtr<Bitmap> create_wrapper(BitmapFormat, const IntSize&, int intrinsic_scale, size_t pitch, void*);
|
2021-01-18 21:26:45 +00:00
|
|
|
static RefPtr<Bitmap> load_from_file(const StringView& path, int scale_factor = 1);
|
2021-01-19 17:10:47 +00:00
|
|
|
static RefPtr<Bitmap> create_with_anon_fd(BitmapFormat, int anon_fd, const IntSize&, int intrinsic_scale, const Vector<RGBA32>& palette, ShouldCloseAnonymousFile);
|
2020-11-07 19:37:03 +00:00
|
|
|
static RefPtr<Bitmap> create_from_serialized_byte_buffer(ByteBuffer&& buffer);
|
2020-06-15 12:13:12 +00:00
|
|
|
static bool is_path_a_supported_image_format(const StringView& path)
|
|
|
|
{
|
2020-11-13 00:25:27 +00:00
|
|
|
#define __ENUMERATE_IMAGE_FORMAT(Name, Ext) \
|
|
|
|
if (path.ends_with(Ext, CaseSensitivity::CaseInsensitive)) \
|
2020-06-15 12:13:12 +00:00
|
|
|
return true;
|
|
|
|
ENUMERATE_IMAGE_FORMATS
|
|
|
|
#undef __ENUMERATE_IMAGE_FORMAT
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2019-12-08 16:07:44 +00:00
|
|
|
|
2020-09-12 11:20:34 +00:00
|
|
|
RefPtr<Gfx::Bitmap> clone() const;
|
|
|
|
|
2020-04-15 09:57:24 +00:00
|
|
|
RefPtr<Gfx::Bitmap> rotated(Gfx::RotationDirection) const;
|
|
|
|
RefPtr<Gfx::Bitmap> flipped(Gfx::Orientation) const;
|
2021-01-15 21:36:36 +00:00
|
|
|
RefPtr<Bitmap> to_bitmap_backed_by_anon_fd() const;
|
2020-11-07 19:37:03 +00:00
|
|
|
ByteBuffer serialize_to_byte_buffer() const;
|
2020-03-29 17:04:05 +00:00
|
|
|
|
2021-01-15 21:36:36 +00:00
|
|
|
ShareableBitmap to_shareable_bitmap() const;
|
2019-12-08 16:07:44 +00:00
|
|
|
|
2020-02-06 10:56:38 +00:00
|
|
|
~Bitmap();
|
2019-01-09 01:06:04 +00:00
|
|
|
|
2021-01-19 17:10:47 +00:00
|
|
|
u8* scanline_u8(int physical_y);
|
|
|
|
const u8* scanline_u8(int physical_y) const;
|
|
|
|
RGBA32* scanline(int physical_y);
|
|
|
|
const RGBA32* scanline(int physical_y) const;
|
2019-01-09 01:06:04 +00:00
|
|
|
|
2020-06-10 08:57:59 +00:00
|
|
|
IntRect rect() const { return { {}, m_size }; }
|
|
|
|
IntSize size() const { return m_size; }
|
2019-01-09 01:06:04 +00:00
|
|
|
int width() const { return m_size.width(); }
|
|
|
|
int height() const { return m_size.height(); }
|
2021-01-19 17:10:47 +00:00
|
|
|
int scale() const { return m_scale; }
|
|
|
|
|
|
|
|
IntRect physical_rect() const { return rect() * scale(); }
|
|
|
|
IntSize physical_size() const { return size() * scale(); }
|
|
|
|
int physical_width() const { return physical_size().width(); }
|
|
|
|
int physical_height() const { return physical_size().height(); }
|
2019-01-12 20:45:45 +00:00
|
|
|
size_t pitch() const { return m_pitch; }
|
2019-12-08 16:07:44 +00:00
|
|
|
|
2020-06-22 19:35:22 +00:00
|
|
|
ALWAYS_INLINE bool is_indexed() const
|
|
|
|
{
|
|
|
|
return is_indexed(m_format);
|
|
|
|
}
|
|
|
|
|
2020-06-17 19:37:16 +00:00
|
|
|
ALWAYS_INLINE static bool is_indexed(BitmapFormat format)
|
|
|
|
{
|
|
|
|
return format == BitmapFormat::Indexed8 || format == BitmapFormat::Indexed4
|
|
|
|
|| format == BitmapFormat::Indexed2 || format == BitmapFormat::Indexed1;
|
|
|
|
}
|
|
|
|
|
2020-11-30 19:53:23 +00:00
|
|
|
static size_t palette_size(BitmapFormat format)
|
2020-06-22 19:35:22 +00:00
|
|
|
{
|
|
|
|
switch (format) {
|
|
|
|
case BitmapFormat::Indexed1:
|
|
|
|
return 2;
|
|
|
|
case BitmapFormat::Indexed2:
|
|
|
|
return 4;
|
|
|
|
case BitmapFormat::Indexed4:
|
|
|
|
return 16;
|
|
|
|
case BitmapFormat::Indexed8:
|
|
|
|
return 256;
|
|
|
|
default:
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector<RGBA32> palette_to_vector() const;
|
|
|
|
|
2020-04-15 09:57:24 +00:00
|
|
|
static unsigned bpp_for_format(BitmapFormat format)
|
2019-06-25 18:33:24 +00:00
|
|
|
{
|
2020-04-15 09:57:24 +00:00
|
|
|
switch (format) {
|
2020-06-17 19:37:16 +00:00
|
|
|
case BitmapFormat::Indexed1:
|
|
|
|
return 1;
|
|
|
|
case BitmapFormat::Indexed2:
|
|
|
|
return 2;
|
|
|
|
case BitmapFormat::Indexed4:
|
|
|
|
return 4;
|
2020-02-14 22:02:47 +00:00
|
|
|
case BitmapFormat::Indexed8:
|
2019-06-25 18:33:24 +00:00
|
|
|
return 8;
|
2021-03-16 10:48:42 +00:00
|
|
|
case BitmapFormat::BGRx8888:
|
|
|
|
case BitmapFormat::BGRA8888:
|
2019-06-25 18:33:24 +00:00
|
|
|
return 32;
|
|
|
|
default:
|
2021-02-23 19:42:32 +00:00
|
|
|
VERIFY_NOT_REACHED();
|
2020-02-14 22:02:47 +00:00
|
|
|
case BitmapFormat::Invalid:
|
2019-09-29 19:02:49 +00:00
|
|
|
return 0;
|
2019-06-25 18:33:24 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-19 17:10:47 +00:00
|
|
|
static size_t minimum_pitch(size_t physical_width, BitmapFormat);
|
2020-09-06 21:59:20 +00:00
|
|
|
|
2020-04-15 09:57:24 +00:00
|
|
|
unsigned bpp() const
|
|
|
|
{
|
|
|
|
return bpp_for_format(m_format);
|
|
|
|
}
|
|
|
|
|
2019-06-10 17:29:50 +00:00
|
|
|
void fill(Color);
|
|
|
|
|
2021-03-16 10:48:42 +00:00
|
|
|
bool has_alpha_channel() const { return m_format == BitmapFormat::BGRA8888; }
|
2020-02-14 22:02:47 +00:00
|
|
|
BitmapFormat format() const { return m_format; }
|
2019-02-19 00:42:53 +00:00
|
|
|
|
2019-06-02 12:58:02 +00:00
|
|
|
void set_mmap_name(const StringView&);
|
2019-04-30 11:46:03 +00:00
|
|
|
|
2021-01-19 17:10:47 +00:00
|
|
|
static constexpr size_t size_in_bytes(size_t pitch, int physical_height) { return pitch * physical_height; }
|
|
|
|
size_t size_in_bytes() const { return size_in_bytes(m_pitch, physical_height()); }
|
2019-05-06 12:04:54 +00:00
|
|
|
|
2019-07-03 19:17:35 +00:00
|
|
|
Color palette_color(u8 index) const { return Color::from_rgba(m_palette[index]); }
|
|
|
|
void set_palette_color(u8 index, Color color) { m_palette[index] = color.value(); }
|
2019-05-06 17:32:56 +00:00
|
|
|
|
2020-09-06 21:59:20 +00:00
|
|
|
template<StorageFormat>
|
2021-01-19 17:10:47 +00:00
|
|
|
Color get_pixel(int physical_x, int physical_y) const;
|
|
|
|
Color get_pixel(int physical_x, int physical_y) const;
|
|
|
|
Color get_pixel(const IntPoint& physical_position) const
|
2019-06-14 17:10:59 +00:00
|
|
|
{
|
2021-01-19 17:10:47 +00:00
|
|
|
return get_pixel(physical_position.x(), physical_position.y());
|
2019-06-14 17:10:59 +00:00
|
|
|
}
|
|
|
|
|
2020-09-06 21:59:20 +00:00
|
|
|
template<StorageFormat>
|
2021-01-19 17:10:47 +00:00
|
|
|
void set_pixel(int physical_x, int physical_y, Color);
|
|
|
|
void set_pixel(int physical_x, int physical_y, Color);
|
|
|
|
void set_pixel(const IntPoint& physical_position, Color color)
|
2019-06-14 17:10:59 +00:00
|
|
|
{
|
2021-01-19 17:10:47 +00:00
|
|
|
set_pixel(physical_position.x(), physical_position.y(), color);
|
2019-06-14 17:10:59 +00:00
|
|
|
}
|
|
|
|
|
2019-12-18 19:50:05 +00:00
|
|
|
bool is_purgeable() const { return m_purgeable; }
|
|
|
|
bool is_volatile() const { return m_volatile; }
|
|
|
|
void set_volatile();
|
|
|
|
[[nodiscard]] bool set_nonvolatile();
|
|
|
|
|
2021-01-15 11:09:37 +00:00
|
|
|
int anon_fd() const { return m_anon_fd; }
|
|
|
|
|
2019-01-09 01:06:04 +00:00
|
|
|
private:
|
2020-08-26 19:52:24 +00:00
|
|
|
enum class Purgeable {
|
|
|
|
No,
|
|
|
|
Yes
|
|
|
|
};
|
2021-01-19 17:10:47 +00:00
|
|
|
Bitmap(BitmapFormat, const IntSize&, int, Purgeable, const BackingStore&);
|
|
|
|
Bitmap(BitmapFormat, const IntSize&, int, size_t pitch, void*);
|
|
|
|
Bitmap(BitmapFormat, int anon_fd, const IntSize&, int, void*, const Vector<RGBA32>& palette);
|
2019-01-09 01:06:04 +00:00
|
|
|
|
2021-01-19 17:10:47 +00:00
|
|
|
static Optional<BackingStore> allocate_backing_store(BitmapFormat, const IntSize&, int, Purgeable);
|
2020-09-12 16:17:50 +00:00
|
|
|
|
2020-08-26 19:52:24 +00:00
|
|
|
void allocate_palette_from_format(BitmapFormat, const Vector<RGBA32>& source_palette);
|
2020-06-17 19:37:16 +00:00
|
|
|
|
2020-06-10 08:57:59 +00:00
|
|
|
IntSize m_size;
|
2021-01-19 17:10:47 +00:00
|
|
|
int m_scale;
|
2020-09-06 21:59:20 +00:00
|
|
|
void* m_data { nullptr };
|
2019-05-06 17:32:56 +00:00
|
|
|
RGBA32* m_palette { nullptr };
|
2019-01-12 20:29:05 +00:00
|
|
|
size_t m_pitch { 0 };
|
2020-02-14 22:02:47 +00:00
|
|
|
BitmapFormat m_format { BitmapFormat::Invalid };
|
2019-04-26 16:25:05 +00:00
|
|
|
bool m_needs_munmap { false };
|
2019-12-18 19:50:05 +00:00
|
|
|
bool m_purgeable { false };
|
|
|
|
bool m_volatile { false };
|
2021-01-15 11:09:37 +00:00
|
|
|
int m_anon_fd { -1 };
|
2019-01-09 01:06:04 +00:00
|
|
|
};
|
2019-01-16 18:43:01 +00:00
|
|
|
|
2020-06-17 19:37:16 +00:00
|
|
|
inline u8* Bitmap::scanline_u8(int y)
|
|
|
|
{
|
2021-02-23 19:42:32 +00:00
|
|
|
VERIFY(y >= 0 && y < physical_height());
|
2020-09-06 21:59:20 +00:00
|
|
|
return reinterpret_cast<u8*>(m_data) + (y * m_pitch);
|
2020-06-17 19:37:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
inline const u8* Bitmap::scanline_u8(int y) const
|
|
|
|
{
|
2021-02-23 19:42:32 +00:00
|
|
|
VERIFY(y >= 0 && y < physical_height());
|
2020-09-06 21:59:20 +00:00
|
|
|
return reinterpret_cast<const u8*>(m_data) + (y * m_pitch);
|
2020-06-17 19:37:16 +00:00
|
|
|
}
|
|
|
|
|
2020-02-06 10:56:38 +00:00
|
|
|
inline RGBA32* Bitmap::scanline(int y)
|
2019-01-16 18:43:01 +00:00
|
|
|
{
|
2020-06-17 19:37:16 +00:00
|
|
|
return reinterpret_cast<RGBA32*>(scanline_u8(y));
|
2019-01-16 18:43:01 +00:00
|
|
|
}
|
|
|
|
|
2020-02-06 10:56:38 +00:00
|
|
|
inline const RGBA32* Bitmap::scanline(int y) const
|
2019-01-16 18:43:01 +00:00
|
|
|
{
|
2020-06-17 19:37:16 +00:00
|
|
|
return reinterpret_cast<const RGBA32*>(scanline_u8(y));
|
2019-01-16 18:43:01 +00:00
|
|
|
}
|
2019-05-06 17:32:56 +00:00
|
|
|
|
2019-06-15 09:06:02 +00:00
|
|
|
template<>
|
2021-03-16 11:00:43 +00:00
|
|
|
inline Color Bitmap::get_pixel<StorageFormat::BGRx8888>(int x, int y) const
|
2019-06-15 09:06:02 +00:00
|
|
|
{
|
2021-02-23 19:42:32 +00:00
|
|
|
VERIFY(x >= 0 && x < physical_width());
|
2019-06-15 09:06:02 +00:00
|
|
|
return Color::from_rgb(scanline(y)[x]);
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
2021-03-16 11:00:43 +00:00
|
|
|
inline Color Bitmap::get_pixel<StorageFormat::BGRA8888>(int x, int y) const
|
2019-06-15 09:06:02 +00:00
|
|
|
{
|
2021-02-23 19:42:32 +00:00
|
|
|
VERIFY(x >= 0 && x < physical_width());
|
2019-06-15 09:06:02 +00:00
|
|
|
return Color::from_rgba(scanline(y)[x]);
|
|
|
|
}
|
|
|
|
|
2020-06-17 19:37:16 +00:00
|
|
|
template<>
|
2020-09-06 21:59:20 +00:00
|
|
|
inline Color Bitmap::get_pixel<StorageFormat::Indexed8>(int x, int y) const
|
2019-06-15 09:06:02 +00:00
|
|
|
{
|
2021-02-23 19:42:32 +00:00
|
|
|
VERIFY(x >= 0 && x < physical_width());
|
2020-09-05 23:10:33 +00:00
|
|
|
return Color::from_rgb(m_palette[scanline_u8(y)[x]]);
|
2019-06-15 09:06:02 +00:00
|
|
|
}
|
|
|
|
|
2020-02-06 10:56:38 +00:00
|
|
|
inline Color Bitmap::get_pixel(int x, int y) const
|
2019-06-15 09:06:02 +00:00
|
|
|
{
|
2020-09-06 21:59:20 +00:00
|
|
|
switch (determine_storage_format(m_format)) {
|
2021-03-16 11:00:43 +00:00
|
|
|
case StorageFormat::BGRx8888:
|
|
|
|
return get_pixel<StorageFormat::BGRx8888>(x, y);
|
|
|
|
case StorageFormat::BGRA8888:
|
|
|
|
return get_pixel<StorageFormat::BGRA8888>(x, y);
|
2020-09-06 21:59:20 +00:00
|
|
|
case StorageFormat::Indexed8:
|
|
|
|
return get_pixel<StorageFormat::Indexed8>(x, y);
|
2019-06-15 09:06:02 +00:00
|
|
|
default:
|
2021-02-23 19:42:32 +00:00
|
|
|
VERIFY_NOT_REACHED();
|
2019-06-15 09:06:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
template<>
|
2021-03-16 11:00:43 +00:00
|
|
|
inline void Bitmap::set_pixel<StorageFormat::BGRx8888>(int x, int y, Color color)
|
2019-06-15 09:06:02 +00:00
|
|
|
{
|
2021-02-23 19:42:32 +00:00
|
|
|
VERIFY(x >= 0 && x < physical_width());
|
2019-06-15 09:06:02 +00:00
|
|
|
scanline(y)[x] = color.value();
|
|
|
|
}
|
|
|
|
template<>
|
2021-03-16 11:00:43 +00:00
|
|
|
inline void Bitmap::set_pixel<StorageFormat::BGRA8888>(int x, int y, Color color)
|
2019-06-15 09:06:02 +00:00
|
|
|
{
|
2021-02-23 19:42:32 +00:00
|
|
|
VERIFY(x >= 0 && x < physical_width());
|
2020-09-06 21:59:20 +00:00
|
|
|
scanline(y)[x] = color.value(); // drop alpha
|
2019-06-15 09:06:02 +00:00
|
|
|
}
|
2020-02-06 10:56:38 +00:00
|
|
|
inline void Bitmap::set_pixel(int x, int y, Color color)
|
2019-06-15 09:06:02 +00:00
|
|
|
{
|
2020-09-06 21:59:20 +00:00
|
|
|
switch (determine_storage_format(m_format)) {
|
2021-03-16 11:00:43 +00:00
|
|
|
case StorageFormat::BGRx8888:
|
|
|
|
set_pixel<StorageFormat::BGRx8888>(x, y, color);
|
2019-06-15 09:06:02 +00:00
|
|
|
break;
|
2021-03-16 11:00:43 +00:00
|
|
|
case StorageFormat::BGRA8888:
|
|
|
|
set_pixel<StorageFormat::BGRA8888>(x, y, color);
|
2019-06-15 09:06:02 +00:00
|
|
|
break;
|
2020-09-06 21:59:20 +00:00
|
|
|
case StorageFormat::Indexed8:
|
2021-02-23 19:42:32 +00:00
|
|
|
VERIFY_NOT_REACHED();
|
2019-06-15 09:06:02 +00:00
|
|
|
default:
|
2021-02-23 19:42:32 +00:00
|
|
|
VERIFY_NOT_REACHED();
|
2019-06-15 09:06:02 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-06 10:56:38 +00:00
|
|
|
|
|
|
|
}
|