From e6d36ade7fcb7084b94b29b0bcea5dc9b58cb4a0 Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Fri, 24 Mar 2023 19:04:01 +0100 Subject: [PATCH] core: Make get_pixels_as_byte_array not sync if the pixel is outside a dirty region --- core/src/bitmap/bitmap_data_operations.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/core/src/bitmap/bitmap_data_operations.rs b/core/src/bitmap/bitmap_data_operations.rs index a44a42fa8..76a0a31b6 100644 --- a/core/src/bitmap/bitmap_data_operations.rs +++ b/core/src/bitmap/bitmap_data_operations.rs @@ -1333,16 +1333,12 @@ pub fn get_pixels_as_byte_array<'gc>( height: i32, ) -> Result> { let mut result = ByteArrayStorage::new(); + let mut region = PixelRegion::for_region_i32(x, y, width, height); + region.clamp(target.width(), target.height()); - let x0 = x.max(0) as u32; - let y0 = y.max(0) as u32; - let x1 = (x + width).clamp(0, target.width() as i32) as u32; - let y1 = (y + height).clamp(0, target.height() as i32) as u32; - - let target = target.sync(); - let read = target.read(); - for y in y0..y1 { - for x in x0..x1 { + let read = target.read_area(region); + for y in region.min_y..region.max_y { + for x in region.min_x..region.max_x { let color = read.get_pixel32_raw(x, y); result.write_int(color.to_un_multiplied_alpha().into())?; }