core: Re-arrange internal implementation of 'pixelDissolve()'.
This commit is contained in:
parent
deae231176
commit
0f30b378b0
|
@ -1618,8 +1618,19 @@ pub fn set_pixels_from_byte_array<'gc>(
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns at least 2. Always returns an even number.
|
#[allow(clippy::too_many_arguments)]
|
||||||
fn get_feistel_block_size(sequence_length: u32) -> u32 {
|
pub fn pixel_dissolve<'gc>(
|
||||||
|
mc: MutationContext<'gc, '_>,
|
||||||
|
target: BitmapDataWrapper<'gc>,
|
||||||
|
source_bitmap: BitmapDataWrapper<'gc>,
|
||||||
|
src_rect: (i32, i32, i32, i32),
|
||||||
|
dest_point: (i32, i32),
|
||||||
|
random_seed: i32,
|
||||||
|
num_pixels: i32,
|
||||||
|
fill_color: i32,
|
||||||
|
) -> i32 {
|
||||||
|
/// Returns at least 2. Always returns an even number.
|
||||||
|
fn get_feistel_block_size(sequence_length: u32) -> u32 {
|
||||||
let sequence_length = sequence_length.max(2);
|
let sequence_length = sequence_length.max(2);
|
||||||
|
|
||||||
// For the given sequence length, figure out the number of bits required to
|
// For the given sequence length, figure out the number of bits required to
|
||||||
|
@ -1639,16 +1650,19 @@ fn get_feistel_block_size(sequence_length: u32) -> u32 {
|
||||||
}
|
}
|
||||||
|
|
||||||
bit_number + (bit_number % 2)
|
bit_number + (bit_number % 2)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Meant to be a bijective function that takes a raw index and gives the corresponding
|
/// Meant to be a bijective function that takes a raw index and gives the corresponding
|
||||||
/// Feistel index.
|
/// Feistel index.
|
||||||
///
|
///
|
||||||
/// # Arguments
|
/// # Arguments
|
||||||
///
|
///
|
||||||
/// * `raw_permutation_index` - Must obey '0 <= permutation_raw_index < permutation_length`.
|
/// * `raw_permutation_index` - Must obey '0 <= permutation_raw_index < permutation_length`.
|
||||||
/// * `feistel_block_size` - See `get_feistel_block_size()`.
|
/// * `feistel_block_size` - See `get_feistel_block_size()`.
|
||||||
fn pixel_dissolve_raw_to_feistel_index(raw_permutation_index: u32, feistel_block_size: u32) -> u32 {
|
fn pixel_dissolve_raw_to_feistel_index(
|
||||||
|
raw_permutation_index: u32,
|
||||||
|
feistel_block_size: u32,
|
||||||
|
) -> u32 {
|
||||||
// Discussion on Feistel networks:
|
// Discussion on Feistel networks:
|
||||||
// https://github.com/ruffle-rs/ruffle/issues/10962
|
// https://github.com/ruffle-rs/ruffle/issues/10962
|
||||||
|
|
||||||
|
@ -1678,19 +1692,38 @@ fn pixel_dissolve_raw_to_feistel_index(raw_permutation_index: u32, feistel_block
|
||||||
let new_halfpiece2 = halfpiece1 ^ result_before_xor;
|
let new_halfpiece2 = halfpiece1 ^ result_before_xor;
|
||||||
|
|
||||||
(new_halfpiece2 << feistel_halfpiece_size) | new_halfpiece1
|
(new_halfpiece2 << feistel_halfpiece_size) | new_halfpiece1
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(clippy::too_many_arguments)]
|
fn write_pixel(
|
||||||
pub fn pixel_dissolve<'gc>(
|
write: &mut RefMut<BitmapData>,
|
||||||
mc: MutationContext<'gc, '_>,
|
different_source_than_target: &Option<Ref<BitmapData>>,
|
||||||
target: BitmapDataWrapper<'gc>,
|
|
||||||
source_bitmap: BitmapDataWrapper<'gc>,
|
|
||||||
src_rect: (i32, i32, i32, i32),
|
|
||||||
dest_point: (i32, i32),
|
|
||||||
random_seed: i32,
|
|
||||||
num_pixels: i32,
|
|
||||||
fill_color: i32,
|
fill_color: i32,
|
||||||
) -> i32 {
|
transparency: bool,
|
||||||
|
base_point: (u32, u32),
|
||||||
|
read_offset: (u32, u32),
|
||||||
|
write_offset: (u32, u32),
|
||||||
|
) {
|
||||||
|
let read_point = (read_offset.0 + base_point.0, read_offset.1 + base_point.1);
|
||||||
|
let write_point = (write_offset.0 + base_point.0, write_offset.1 + base_point.1);
|
||||||
|
|
||||||
|
match different_source_than_target {
|
||||||
|
None => {
|
||||||
|
write.set_pixel32_raw(
|
||||||
|
write_point.0,
|
||||||
|
write_point.1,
|
||||||
|
Color::from(fill_color).to_premultiplied_alpha(transparency),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Some(different_source) => {
|
||||||
|
write.set_pixel32_raw(
|
||||||
|
write_point.0,
|
||||||
|
write_point.1,
|
||||||
|
different_source.get_pixel32_raw(read_point.0, read_point.1),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Apparently,
|
// Apparently,
|
||||||
// "numPixels:int (default = 0) — The default is 1/30 of the source area (width x height). "
|
// "numPixels:int (default = 0) — The default is 1/30 of the source area (width x height). "
|
||||||
// is wrong.
|
// is wrong.
|
||||||
|
@ -1727,36 +1760,6 @@ pub fn pixel_dissolve<'gc>(
|
||||||
let write_offset = (dest_region.x_min, dest_region.y_min);
|
let write_offset = (dest_region.x_min, dest_region.y_min);
|
||||||
let read_offset = (source_region.x_min, source_region.y_min);
|
let read_offset = (source_region.x_min, source_region.y_min);
|
||||||
|
|
||||||
fn write_pixel(
|
|
||||||
write: &mut RefMut<BitmapData>,
|
|
||||||
different_source_than_target: &Option<Ref<BitmapData>>,
|
|
||||||
fill_color: i32,
|
|
||||||
transparency: bool,
|
|
||||||
base_point: (u32, u32),
|
|
||||||
read_offset: (u32, u32),
|
|
||||||
write_offset: (u32, u32),
|
|
||||||
) {
|
|
||||||
let read_point = (read_offset.0 + base_point.0, read_offset.1 + base_point.1);
|
|
||||||
let write_point = (write_offset.0 + base_point.0, write_offset.1 + base_point.1);
|
|
||||||
|
|
||||||
match different_source_than_target {
|
|
||||||
None => {
|
|
||||||
write.set_pixel32_raw(
|
|
||||||
write_point.0,
|
|
||||||
write_point.1,
|
|
||||||
Color::from(fill_color).to_premultiplied_alpha(transparency),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
Some(different_source) => {
|
|
||||||
write.set_pixel32_raw(
|
|
||||||
write_point.0,
|
|
||||||
write_point.1,
|
|
||||||
different_source.get_pixel32_raw(read_point.0, read_point.1),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let different_source_than_target = if source_bitmap.ptr_eq(target) {
|
let different_source_than_target = if source_bitmap.ptr_eq(target) {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue