mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 21:22:46 +00:00 
			
		
		
		
	LibGfx: Add Bitmap::scaled_to_size()
This commit is contained in:
		
							parent
							
								
									3907374621
								
							
						
					
					
						commit
						a4dec92ed0
					
				
					 2 changed files with 7 additions and 2 deletions
				
			
		|  | @ -362,7 +362,6 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::scaled(int sx, int sy) const | |||
|     return new_bitmap; | ||||
| } | ||||
| 
 | ||||
| // http://fourier.eng.hmc.edu/e161/lectures/resize/node3.html
 | ||||
| ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::scaled(float sx, float sy) const | ||||
| { | ||||
|     VERIFY(sx >= 0.0f && sy >= 0.0f); | ||||
|  | @ -371,8 +370,13 @@ ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::scaled(float sx, float sy) const | |||
| 
 | ||||
|     int scaled_width = (int)ceilf(sx * (float)width()); | ||||
|     int scaled_height = (int)ceilf(sy * (float)height()); | ||||
|     return scaled_to_size({ scaled_width, scaled_height }); | ||||
| } | ||||
| 
 | ||||
|     auto new_bitmap = TRY(Gfx::Bitmap::create(format(), { scaled_width, scaled_height }, scale())); | ||||
| // http://fourier.eng.hmc.edu/e161/lectures/resize/node3.html
 | ||||
| ErrorOr<NonnullRefPtr<Gfx::Bitmap>> Bitmap::scaled_to_size(Gfx::IntSize size) const | ||||
| { | ||||
|     auto new_bitmap = TRY(Gfx::Bitmap::create(format(), size, scale())); | ||||
| 
 | ||||
|     auto old_width = physical_width(); | ||||
|     auto old_height = physical_height(); | ||||
|  |  | |||
|  | @ -114,6 +114,7 @@ public: | |||
|     ErrorOr<NonnullRefPtr<Gfx::Bitmap>> flipped(Gfx::Orientation) const; | ||||
|     ErrorOr<NonnullRefPtr<Gfx::Bitmap>> scaled(int sx, int sy) const; | ||||
|     ErrorOr<NonnullRefPtr<Gfx::Bitmap>> scaled(float sx, float sy) const; | ||||
|     ErrorOr<NonnullRefPtr<Gfx::Bitmap>> scaled_to_size(Gfx::IntSize) const; | ||||
|     ErrorOr<NonnullRefPtr<Gfx::Bitmap>> cropped(Gfx::IntRect, Optional<BitmapFormat> new_bitmap_format = {}) const; | ||||
|     ErrorOr<NonnullRefPtr<Gfx::Bitmap>> to_bitmap_backed_by_anonymous_buffer() const; | ||||
|     [[nodiscard]] ErrorOr<ByteBuffer> serialize_to_byte_buffer() const; | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Nico Weber
						Nico Weber