mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 11:18:11 +00:00
LibWeb: Implement CRC2D.imageSmoothingEnabled
We now select between nearest neighbor and bilinear filtering when scaling images in CRC2D.drawImage(). This patch also adds CRC2D.imageSmoothingQuality but it's ignored for now as we don't have a bunch of different quality levels to map it to. Work towards #17993 (Ruffle Flash Player)
This commit is contained in:
parent
e4b71495f5
commit
e77552519e
7 changed files with 75 additions and 2 deletions
|
@ -11,6 +11,7 @@
|
|||
#include <LibGfx/Quad.h>
|
||||
#include <LibGfx/Rect.h>
|
||||
#include <LibUnicode/Segmentation.h>
|
||||
#include <LibWeb/Bindings/CanvasRenderingContext2DPrototype.h>
|
||||
#include <LibWeb/Bindings/Intrinsics.h>
|
||||
#include <LibWeb/HTML/CanvasRenderingContext2D.h>
|
||||
#include <LibWeb/HTML/HTMLCanvasElement.h>
|
||||
|
@ -173,7 +174,12 @@ WebIDL::ExceptionOr<void> CanvasRenderingContext2D::draw_image_internal(CanvasIm
|
|||
if (!painter)
|
||||
return {};
|
||||
|
||||
painter->draw_scaled_bitmap_with_transform(destination_rect.to_rounded<int>(), *bitmap, source_rect, drawing_state().transform, 1.0f, Gfx::Painter::ScalingMode::BilinearBlend);
|
||||
auto scaling_mode = Gfx::Painter::ScalingMode::NearestNeighbor;
|
||||
if (drawing_state().image_smoothing_enabled) {
|
||||
// FIXME: Honor drawing_state().image_smoothing_quality
|
||||
scaling_mode = Gfx::Painter::ScalingMode::BilinearBlend;
|
||||
}
|
||||
painter->draw_scaled_bitmap_with_transform(destination_rect.to_rounded<int>(), *bitmap, source_rect, drawing_state().transform, 1.0f, scaling_mode);
|
||||
|
||||
// 7. If image is not origin-clean, then set the CanvasRenderingContext2D's origin-clean flag to false.
|
||||
if (image_is_not_origin_clean(image))
|
||||
|
@ -560,4 +566,24 @@ bool image_is_not_origin_clean(CanvasImageSource const& image)
|
|||
});
|
||||
}
|
||||
|
||||
bool CanvasRenderingContext2D::image_smoothing_enabled() const
|
||||
{
|
||||
return drawing_state().image_smoothing_enabled;
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::set_image_smoothing_enabled(bool enabled)
|
||||
{
|
||||
drawing_state().image_smoothing_enabled = enabled;
|
||||
}
|
||||
|
||||
Bindings::ImageSmoothingQuality CanvasRenderingContext2D::image_smoothing_quality() const
|
||||
{
|
||||
return drawing_state().image_smoothing_quality;
|
||||
}
|
||||
|
||||
void CanvasRenderingContext2D::set_image_smoothing_quality(Bindings::ImageSmoothingQuality quality)
|
||||
{
|
||||
drawing_state().image_smoothing_quality = quality;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue