From e9053dfc17b79dcc82fd60c2c8b2e6d257658105 Mon Sep 17 00:00:00 2001 From: 1bugproof <254564796+1bugproof@users.noreply.github.com> Date: Wed, 6 May 2026 11:27:40 +0200 Subject: [PATCH] core: Fix LoaderInfo.width/height returning 0 for loaded raster images --- core/common/src/tag_utils.rs | 7 +++++-- core/src/loader.rs | 10 +++++++++- swf/src/types.rs | 4 ++-- .../loaded-content-properties/output.ruffle.txt | 4 ++-- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/core/common/src/tag_utils.rs b/core/common/src/tag_utils.rs index c6c9f3e90732..371775c28d26 100644 --- a/core/common/src/tag_utils.rs +++ b/core/common/src/tag_utils.rs @@ -177,8 +177,11 @@ impl SwfMovie { } /// Construct a movie based on a loaded image (JPEG, GIF or PNG). - pub fn from_loaded_image(url: String, length: usize) -> Self { - let header = HeaderExt::default_with_uncompressed_len(length as i32); + pub fn from_loaded_image(url: String, length: usize, width: u32, height: u32) -> Self { + let stage_size = Rectangle::ZERO + .with_width(Twips::from_pixels_i32(width as i32)) + .with_height(Twips::from_pixels_i32(height as i32)); + let header = HeaderExt::default_with_uncompressed_len(length as i32, stage_size); let sandbox_type = SandboxType::infer(url.as_str(), &header); let mut movie = Self { header, diff --git a/core/src/loader.rs b/core/src/loader.rs index 20a1712155b5..59a9da42020c 100644 --- a/core/src/loader.rs +++ b/core/src/loader.rs @@ -1625,7 +1625,15 @@ impl<'gc> MovieLoader<'gc> { Arc::new(movie) } ContentType::Gif | ContentType::Jpeg | ContentType::Png => { - Arc::new(SwfMovie::from_loaded_image(url.clone(), length)) + let (width, height) = + ruffle_render::utils::decode_define_bits_jpeg_dimensions(data) + .unwrap_or((0, 0)); + Arc::new(SwfMovie::from_loaded_image( + url.clone(), + length, + width, + height, + )) } ContentType::Unknown => Arc::new(SwfMovie::error_movie(url.clone())), }; diff --git a/swf/src/types.rs b/swf/src/types.rs index 7e6619e963ad..f56c43d786df 100644 --- a/swf/src/types.rs +++ b/swf/src/types.rs @@ -126,11 +126,11 @@ impl HeaderExt { } /// Returns the header for a loaded image (JPEG, GIF or PNG). - pub fn default_with_uncompressed_len(length: i32) -> Self { + pub fn default_with_uncompressed_len(length: i32, stage_size: Rectangle) -> Self { let header = Header { compression: Compression::None, version: 0, - stage_size: Default::default(), + stage_size, frame_rate: Fixed8::ONE, num_frames: 1, }; diff --git a/tests/tests/swfs/from_shumway/as3-loader/loaderinfo/loaded-content-properties/output.ruffle.txt b/tests/tests/swfs/from_shumway/as3-loader/loaderinfo/loaded-content-properties/output.ruffle.txt index 69403b38d760..7972e3a69349 100644 --- a/tests/tests/swfs/from_shumway/as3-loader/loaderinfo/loaded-content-properties/output.ruffle.txt +++ b/tests/tests/swfs/from_shumway/as3-loader/loaderinfo/loaded-content-properties/output.ruffle.txt @@ -33,7 +33,7 @@ childSandboxBridge: null content: [object Bitmap] contentType: image/jpeg frameRate: 1 -height: 0 +height: 140 isURLInaccessible: false loader: [object Loader] loaderURL: alf.jpg @@ -45,4 +45,4 @@ sharedEvents: [object EventDispatcher] swfVersion: 0 uncaughtErrorEvents: [object UncaughtErrorEvents] url: alf.jpg -width: 0 +width: 140