core: Make get_pixels_as_byte_array not sync if the pixel is outside a dirty region

This commit is contained in:
Nathan Adams 2023-03-24 19:04:01 +01:00
parent fd0ba4a753
commit e6d36ade7f
1 changed files with 5 additions and 9 deletions

View File

@ -1333,16 +1333,12 @@ pub fn get_pixels_as_byte_array<'gc>(
height: i32, height: i32,
) -> Result<ByteArrayStorage, Error<'gc>> { ) -> Result<ByteArrayStorage, Error<'gc>> {
let mut result = ByteArrayStorage::new(); 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 read = target.read_area(region);
let y0 = y.max(0) as u32; for y in region.min_y..region.max_y {
let x1 = (x + width).clamp(0, target.width() as i32) as u32; for x in region.min_x..region.max_x {
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 color = read.get_pixel32_raw(x, y); let color = read.get_pixel32_raw(x, y);
result.write_int(color.to_un_multiplied_alpha().into())?; result.write_int(color.to_un_multiplied_alpha().into())?;
} }