swf: Fix blur scaling in filters
The blur of 1.0 is invariant, so that it should be preserved when scaling. Using `blur * scale` also scales the invariant, which is wrong. Tests show that `(blur - 1) * scale + 1` matches FP's behavior.
This commit is contained in:
parent
0c4d551e90
commit
88a9c74ee0
|
@ -35,8 +35,8 @@ impl BevelFilter {
|
|||
}
|
||||
|
||||
pub fn scale(&mut self, x: f32, y: f32) {
|
||||
self.blur_x *= Fixed16::from_f32(x);
|
||||
self.blur_y *= Fixed16::from_f32(y);
|
||||
self.blur_x = BlurFilter::scale_blur(self.blur_x, x);
|
||||
self.blur_y = BlurFilter::scale_blur(self.blur_y, y);
|
||||
self.distance *= Fixed16::from_f32(y);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,8 +23,8 @@ impl BlurFilter {
|
|||
}
|
||||
|
||||
pub fn scale(&mut self, x: f32, y: f32) {
|
||||
self.blur_x *= Fixed16::from_f32(x);
|
||||
self.blur_y *= Fixed16::from_f32(y);
|
||||
self.blur_x = Self::scale_blur(self.blur_x, x);
|
||||
self.blur_y = Self::scale_blur(self.blur_y, y);
|
||||
}
|
||||
|
||||
pub fn impotent(&self) -> bool {
|
||||
|
@ -42,6 +42,11 @@ impl BlurFilter {
|
|||
y_max: source_rect.y_max + y,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub(crate) fn scale_blur(blur: Fixed16, factor: f32) -> Fixed16 {
|
||||
(blur - Fixed16::ONE) * Fixed16::from_f32(factor) + Fixed16::ONE
|
||||
}
|
||||
}
|
||||
|
||||
bitflags! {
|
||||
|
|
|
@ -37,8 +37,8 @@ impl DropShadowFilter {
|
|||
}
|
||||
|
||||
pub fn scale(&mut self, x: f32, y: f32) {
|
||||
self.blur_x *= Fixed16::from_f32(x);
|
||||
self.blur_y *= Fixed16::from_f32(y);
|
||||
self.blur_x = BlurFilter::scale_blur(self.blur_x, x);
|
||||
self.blur_y = BlurFilter::scale_blur(self.blur_y, y);
|
||||
self.distance *= Fixed16::from_f32(y);
|
||||
}
|
||||
|
||||
|
|
|
@ -32,8 +32,8 @@ impl GlowFilter {
|
|||
}
|
||||
|
||||
pub fn scale(&mut self, x: f32, y: f32) {
|
||||
self.blur_x *= Fixed16::from_f32(x);
|
||||
self.blur_y *= Fixed16::from_f32(y);
|
||||
self.blur_x = BlurFilter::scale_blur(self.blur_x, x);
|
||||
self.blur_y = BlurFilter::scale_blur(self.blur_y, y);
|
||||
}
|
||||
|
||||
pub fn calculate_dest_rect(&self, source_rect: Rectangle<Twips>) -> Rectangle<Twips> {
|
||||
|
|
|
@ -34,8 +34,8 @@ impl GradientFilter {
|
|||
}
|
||||
|
||||
pub fn scale(&mut self, x: f32, y: f32) {
|
||||
self.blur_x *= Fixed16::from_f32(x);
|
||||
self.blur_y *= Fixed16::from_f32(y);
|
||||
self.blur_x = BlurFilter::scale_blur(self.blur_x, x);
|
||||
self.blur_y = BlurFilter::scale_blur(self.blur_y, y);
|
||||
self.distance *= Fixed16::from_f32(y);
|
||||
}
|
||||
|
||||
|
|
Binary file not shown.
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 4.7 KiB |
Loading…
Reference in New Issue