mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 17:32:44 +00:00 
			
		
		
		
	LibGfx: Convert Gfx::Bitmap to east const style
This commit is contained in:
		
							parent
							
								
									d85d741c59
								
							
						
					
					
						commit
						16f064d9be
					
				
					 2 changed files with 28 additions and 28 deletions
				
			
		|  | @ -55,7 +55,7 @@ size_t Bitmap::minimum_pitch(size_t physical_width, BitmapFormat format) | |||
|     return physical_width * element_size; | ||||
| } | ||||
| 
 | ||||
| static bool size_would_overflow(BitmapFormat format, const IntSize& size, int scale_factor) | ||||
| static bool size_would_overflow(BitmapFormat format, IntSize const& size, int scale_factor) | ||||
| { | ||||
|     if (size.width() < 0 || size.height() < 0) | ||||
|         return true; | ||||
|  | @ -67,7 +67,7 @@ static bool size_would_overflow(BitmapFormat format, const IntSize& size, int sc | |||
|     return Checked<size_t>::multiplication_would_overflow(pitch, size.height() * scale_factor); | ||||
| } | ||||
| 
 | ||||
| RefPtr<Bitmap> Bitmap::try_create(BitmapFormat format, const IntSize& size, int scale_factor) | ||||
| RefPtr<Bitmap> Bitmap::try_create(BitmapFormat format, IntSize const& size, int scale_factor) | ||||
| { | ||||
|     auto backing_store_or_error = Bitmap::allocate_backing_store(format, size, scale_factor); | ||||
|     if (backing_store_or_error.is_error()) | ||||
|  | @ -75,20 +75,20 @@ RefPtr<Bitmap> Bitmap::try_create(BitmapFormat format, const IntSize& size, int | |||
|     return adopt_ref(*new Bitmap(format, size, scale_factor, backing_store_or_error.release_value())); | ||||
| } | ||||
| 
 | ||||
| ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_create_shareable(BitmapFormat format, const IntSize& size, int scale_factor) | ||||
| ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_create_shareable(BitmapFormat format, IntSize const& size, int scale_factor) | ||||
| { | ||||
|     if (size_would_overflow(format, size, scale_factor)) | ||||
|         return Error::from_string_literal("Gfx::Bitmap::try_create_shareable size overflow"sv); | ||||
| 
 | ||||
|     const auto pitch = minimum_pitch(size.width() * scale_factor, format); | ||||
|     const auto data_size = size_in_bytes(pitch, size.height() * scale_factor); | ||||
|     auto const pitch = minimum_pitch(size.width() * scale_factor, format); | ||||
|     auto const data_size = size_in_bytes(pitch, size.height() * scale_factor); | ||||
| 
 | ||||
|     auto buffer = TRY(Core::AnonymousBuffer::create_with_size(round_up_to_power_of_two(data_size, PAGE_SIZE))); | ||||
|     auto bitmap = TRY(Bitmap::try_create_with_anonymous_buffer(format, buffer, size, scale_factor, {})); | ||||
|     return bitmap; | ||||
| } | ||||
| 
 | ||||
| Bitmap::Bitmap(BitmapFormat format, const IntSize& size, int scale_factor, const BackingStore& backing_store) | ||||
| Bitmap::Bitmap(BitmapFormat format, IntSize const& size, int scale_factor, BackingStore const& backing_store) | ||||
|     : m_size(size) | ||||
|     , m_scale(scale_factor) | ||||
|     , m_data(backing_store.data) | ||||
|  | @ -134,7 +134,7 @@ RefPtr<Bitmap> Bitmap::try_load_from_fd_and_close(int fd, String const& path, in | |||
|     if (path.ends_with(Ext, CaseSensitivity::CaseInsensitive)) {                                                                   \ | ||||
|         auto file = MappedFile::map_from_fd_and_close(fd, highdpi_icon_path.to_string());                                          \ | ||||
|         if (!file.is_error())                                                                                                      \ | ||||
|             bmp = load_##Name##_from_memory((const u8*)file.value()->data(), file.value()->size(), highdpi_icon_path.to_string()); \ | ||||
|             bmp = load_##Name##_from_memory((u8 const*)file.value()->data(), file.value()->size(), highdpi_icon_path.to_string()); \ | ||||
|     } | ||||
|         ENUMERATE_IMAGE_FORMATS | ||||
| #undef __ENUMERATE_IMAGE_FORMAT | ||||
|  | @ -152,7 +152,7 @@ RefPtr<Bitmap> Bitmap::try_load_from_fd_and_close(int fd, String const& path, in | |||
|     if (path.ends_with(Ext, CaseSensitivity::CaseInsensitive)) {                                           \ | ||||
|         auto file = MappedFile::map_from_fd_and_close(fd, path);                                           \ | ||||
|         if (!file.is_error())                                                                              \ | ||||
|             return load_##Name##_from_memory((const u8*)file.value()->data(), file.value()->size(), path); \ | ||||
|             return load_##Name##_from_memory((u8 const*)file.value()->data(), file.value()->size(), path); \ | ||||
|     } | ||||
|     ENUMERATE_IMAGE_FORMATS | ||||
| #undef __ENUMERATE_IMAGE_FORMAT | ||||
|  | @ -160,7 +160,7 @@ RefPtr<Bitmap> Bitmap::try_load_from_fd_and_close(int fd, String const& path, in | |||
|     return nullptr; | ||||
| } | ||||
| 
 | ||||
| Bitmap::Bitmap(BitmapFormat format, const IntSize& size, int scale_factor, size_t pitch, void* data) | ||||
| Bitmap::Bitmap(BitmapFormat format, IntSize const& size, int scale_factor, size_t pitch, void* data) | ||||
|     : m_size(size) | ||||
|     , m_scale(scale_factor) | ||||
|     , m_data(data) | ||||
|  | @ -174,7 +174,7 @@ Bitmap::Bitmap(BitmapFormat format, const IntSize& size, int scale_factor, size_ | |||
|     allocate_palette_from_format(format, {}); | ||||
| } | ||||
| 
 | ||||
| static bool check_size(const IntSize& size, int scale_factor, BitmapFormat format, unsigned actual_size) | ||||
| static bool check_size(IntSize const& size, int scale_factor, BitmapFormat format, unsigned actual_size) | ||||
| { | ||||
|     // FIXME: Code duplication of size_in_bytes() and m_pitch
 | ||||
|     unsigned expected_size_min = Bitmap::minimum_pitch(size.width() * scale_factor, format) * size.height() * scale_factor; | ||||
|  | @ -194,7 +194,7 @@ static bool check_size(const IntSize& size, int scale_factor, BitmapFormat forma | |||
|     return true; | ||||
| } | ||||
| 
 | ||||
| ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_create_with_anonymous_buffer(BitmapFormat format, Core::AnonymousBuffer buffer, const IntSize& size, int scale_factor, const Vector<RGBA32>& palette) | ||||
| ErrorOr<NonnullRefPtr<Bitmap>> Bitmap::try_create_with_anonymous_buffer(BitmapFormat format, Core::AnonymousBuffer buffer, IntSize const& size, int scale_factor, Vector<RGBA32> const& palette) | ||||
| { | ||||
|     if (size_would_overflow(format, size, scale_factor)) | ||||
|         return Error::from_string_literal("Gfx::Bitmap::try_create_with_anonymous_buffer size overflow"); | ||||
|  | @ -290,7 +290,7 @@ ByteBuffer Bitmap::serialize_to_byte_buffer() const | |||
|     return buffer; | ||||
| } | ||||
| 
 | ||||
| Bitmap::Bitmap(BitmapFormat format, Core::AnonymousBuffer buffer, const IntSize& size, int scale_factor, const Vector<RGBA32>& palette) | ||||
| Bitmap::Bitmap(BitmapFormat format, Core::AnonymousBuffer buffer, IntSize const& size, int scale_factor, Vector<RGBA32> const& palette) | ||||
|     : m_size(size) | ||||
|     , m_scale(scale_factor) | ||||
|     , m_data(buffer.data<void>()) | ||||
|  | @ -593,8 +593,8 @@ ErrorOr<BackingStore> Bitmap::allocate_backing_store(BitmapFormat format, IntSiz | |||
|     if (size_would_overflow(format, size, scale_factor)) | ||||
|         return Error::from_string_literal("Gfx::Bitmap backing store size overflow"sv); | ||||
| 
 | ||||
|     const auto pitch = minimum_pitch(size.width() * scale_factor, format); | ||||
|     const auto data_size_in_bytes = size_in_bytes(pitch, size.height() * scale_factor); | ||||
|     auto const pitch = minimum_pitch(size.width() * scale_factor, format); | ||||
|     auto const data_size_in_bytes = size_in_bytes(pitch, size.height() * scale_factor); | ||||
| 
 | ||||
|     int map_flags = MAP_ANONYMOUS | MAP_PRIVATE; | ||||
| #ifdef __serenity__ | ||||
|  | @ -608,7 +608,7 @@ ErrorOr<BackingStore> Bitmap::allocate_backing_store(BitmapFormat format, IntSiz | |||
|     return BackingStore { data, pitch, data_size_in_bytes }; | ||||
| } | ||||
| 
 | ||||
| void Bitmap::allocate_palette_from_format(BitmapFormat format, const Vector<RGBA32>& source_palette) | ||||
| void Bitmap::allocate_palette_from_format(BitmapFormat format, Vector<RGBA32> const& source_palette) | ||||
| { | ||||
|     size_t size = palette_size(format); | ||||
|     if (size == 0) | ||||
|  |  | |||
|  | @ -90,7 +90,7 @@ enum RotationDirection { | |||
| 
 | ||||
| class Bitmap : public RefCounted<Bitmap> { | ||||
| public: | ||||
|     [[nodiscard]] static RefPtr<Bitmap> try_create(BitmapFormat, const IntSize&, int intrinsic_scale = 1); | ||||
|     [[nodiscard]] static RefPtr<Bitmap> try_create(BitmapFormat, IntSize const&, int intrinsic_scale = 1); | ||||
|     [[nodiscard]] static ErrorOr<NonnullRefPtr<Bitmap>> try_create_shareable(BitmapFormat, IntSize const&, int intrinsic_scale = 1); | ||||
|     [[nodiscard]] static ErrorOr<NonnullRefPtr<Bitmap>> try_create_wrapper(BitmapFormat, IntSize const&, int intrinsic_scale, size_t pitch, void*); | ||||
|     [[nodiscard]] static RefPtr<Bitmap> try_load_from_file(String const& path, int scale_factor = 1); | ||||
|  | @ -98,7 +98,7 @@ public: | |||
|     [[nodiscard]] static ErrorOr<NonnullRefPtr<Bitmap>> try_create_with_anonymous_buffer(BitmapFormat, Core::AnonymousBuffer, IntSize const&, int intrinsic_scale, Vector<RGBA32> const& palette); | ||||
|     [[nodiscard]] static RefPtr<Bitmap> try_create_from_serialized_byte_buffer(ByteBuffer&& buffer); | ||||
| 
 | ||||
|     static bool is_path_a_supported_image_format(const StringView& path) | ||||
|     static bool is_path_a_supported_image_format(StringView const& path) | ||||
|     { | ||||
| #define __ENUMERATE_IMAGE_FORMAT(Name, Ext)                    \ | ||||
|     if (path.ends_with(Ext, CaseSensitivity::CaseInsensitive)) \ | ||||
|  | @ -124,9 +124,9 @@ public: | |||
|     ~Bitmap(); | ||||
| 
 | ||||
|     [[nodiscard]] u8* scanline_u8(int physical_y); | ||||
|     [[nodiscard]] const u8* scanline_u8(int physical_y) const; | ||||
|     [[nodiscard]] u8 const* scanline_u8(int physical_y) const; | ||||
|     [[nodiscard]] RGBA32* scanline(int physical_y); | ||||
|     [[nodiscard]] const RGBA32* scanline(int physical_y) const; | ||||
|     [[nodiscard]] RGBA32 const* scanline(int physical_y) const; | ||||
| 
 | ||||
|     [[nodiscard]] IntRect rect() const { return { {}, m_size }; } | ||||
|     [[nodiscard]] IntSize size() const { return m_size; } | ||||
|  | @ -213,7 +213,7 @@ public: | |||
|     template<StorageFormat> | ||||
|     [[nodiscard]] Color get_pixel(int physical_x, int physical_y) const; | ||||
|     [[nodiscard]] Color get_pixel(int physical_x, int physical_y) const; | ||||
|     [[nodiscard]] Color get_pixel(const IntPoint& physical_position) const | ||||
|     [[nodiscard]] Color get_pixel(IntPoint const& physical_position) const | ||||
|     { | ||||
|         return get_pixel(physical_position.x(), physical_position.y()); | ||||
|     } | ||||
|  | @ -221,7 +221,7 @@ public: | |||
|     template<StorageFormat> | ||||
|     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) | ||||
|     void set_pixel(IntPoint const& physical_position, Color color) | ||||
|     { | ||||
|         set_pixel(physical_position.x(), physical_position.y(), color); | ||||
|     } | ||||
|  | @ -238,12 +238,12 @@ public: | |||
| 
 | ||||
| private: | ||||
|     Bitmap(BitmapFormat, IntSize const&, int, BackingStore const&); | ||||
|     Bitmap(BitmapFormat, const IntSize&, int, size_t pitch, void*); | ||||
|     Bitmap(BitmapFormat, Core::AnonymousBuffer, const IntSize&, int, const Vector<RGBA32>& palette); | ||||
|     Bitmap(BitmapFormat, IntSize const&, int, size_t pitch, void*); | ||||
|     Bitmap(BitmapFormat, Core::AnonymousBuffer, IntSize const&, int, Vector<RGBA32> const& palette); | ||||
| 
 | ||||
|     static ErrorOr<BackingStore> allocate_backing_store(BitmapFormat format, IntSize const& size, int scale_factor); | ||||
| 
 | ||||
|     void allocate_palette_from_format(BitmapFormat, const Vector<RGBA32>& source_palette); | ||||
|     void allocate_palette_from_format(BitmapFormat, Vector<RGBA32> const& source_palette); | ||||
| 
 | ||||
|     IntSize m_size; | ||||
|     int m_scale; | ||||
|  | @ -262,10 +262,10 @@ inline u8* Bitmap::scanline_u8(int y) | |||
|     return reinterpret_cast<u8*>(m_data) + (y * m_pitch); | ||||
| } | ||||
| 
 | ||||
| inline const u8* Bitmap::scanline_u8(int y) const | ||||
| inline u8 const* Bitmap::scanline_u8(int y) const | ||||
| { | ||||
|     VERIFY(y >= 0 && y < physical_height()); | ||||
|     return reinterpret_cast<const u8*>(m_data) + (y * m_pitch); | ||||
|     return reinterpret_cast<u8 const*>(m_data) + (y * m_pitch); | ||||
| } | ||||
| 
 | ||||
| inline RGBA32* Bitmap::scanline(int y) | ||||
|  | @ -273,9 +273,9 @@ inline RGBA32* Bitmap::scanline(int y) | |||
|     return reinterpret_cast<RGBA32*>(scanline_u8(y)); | ||||
| } | ||||
| 
 | ||||
| inline const RGBA32* Bitmap::scanline(int y) const | ||||
| inline RGBA32 const* Bitmap::scanline(int y) const | ||||
| { | ||||
|     return reinterpret_cast<const RGBA32*>(scanline_u8(y)); | ||||
|     return reinterpret_cast<RGBA32 const*>(scanline_u8(y)); | ||||
| } | ||||
| 
 | ||||
| template<> | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling