Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly support tiling clip mask images. #3220

Merged
merged 11 commits into from Oct 23, 2018

wrench: Introduce transparent-checkerboard, which is useful to test m…

…asking.
  • Loading branch information
emilio committed Oct 23, 2018
commit e6e0f1880b740873458ea058a34045e620426cc6
@@ -0,0 +1,14 @@
---
root:
items:
- type: clip
bounds: [0, 0, 200, 200]
image-mask:
image: transparent-checkerboard(2, 16, 16)
rect: [0, 0, 200, 200]
repeat: false
tile-size: 37 # Intentional
items:
- type: rect
bounds: [0, 0, 200, 200]
color: blue
Binary file not shown.
@@ -0,0 +1,13 @@
---
root:
items:
- type: clip
bounds: [0, 0, 200, 200]
image-mask:
image: transparent-checkerboard(2, 16, 16)
rect: [0, 0, 200, 200]
repeat: false
items:
- type: rect
bounds: [0, 0, 200, 200]
color: blue
@@ -11,3 +11,5 @@ platform(linux,mac) fuzzy(1,8750) == mask-atomicity.yaml mask-atomicity-ref.yaml
platform(linux,mac) fuzzy(1,8750) == mask-atomicity-tiling.yaml mask-atomicity-ref.yaml
== mask-perspective.yaml mask-perspective.png
== mask-perspective-tiling.yaml mask-perspective.yaml
== checkerboard.yaml checkerboard.png
== checkerboard.yaml checkerboard-tiling.yaml
@@ -72,12 +72,18 @@ fn broadcast<T: Clone>(base_vals: &[T], num_items: usize) -> Vec<T> {
vals
}

enum CheckerboardKind {
BlackGrey,
BlackTransparent,
}

fn generate_checkerboard_image(
border: u32,
tile_x_size: u32,
tile_y_size: u32,
tile_x_count: u32,
tile_y_count: u32,
kind: CheckerboardKind,
) -> (ImageDescriptor, ImageData) {
let width = 2 * border + tile_x_size * tile_x_count;
let height = 2 * border + tile_y_size * tile_y_count;
@@ -94,11 +100,22 @@ fn generate_checkerboard_image(
} else {
let xon = ((x - border) % (2 * tile_x_size)) < tile_x_size;
let yon = ((y - border) % (2 * tile_y_size)) < tile_y_size;
let value = if xon ^ yon { 0xff } else { 0x7f };
pixels.push(value);
pixels.push(value);
pixels.push(value);
pixels.push(0xff);
match kind {
CheckerboardKind::BlackGrey => {
let value = if xon ^ yon { 0xff } else { 0x7f };
pixels.push(value);
pixels.push(value);
pixels.push(value);
pixels.push(0xff);
}
CheckerboardKind::BlackTransparent => {
let value = if xon ^ yon { 0xff } else { 0x00 };
pixels.push(value);
pixels.push(value);
pixels.push(value);
pixels.push(value);
}
}
}
}
}
@@ -476,7 +493,8 @@ impl YamlFrameReader {
args.get(4).unwrap_or(&"1000").parse::<u32>().unwrap(),
args.get(5).unwrap_or(&"1000").parse::<u32>().unwrap(),
),
("checkerboard", args, _) => {
(name @ "transparent-checkerboard", args, _) |
(name @ "checkerboard", args, _) => {
let border = args.get(0).unwrap_or(&"4").parse::<u32>().unwrap();

let (x_size, y_size, x_count, y_count) = match args.len() {
@@ -497,12 +515,19 @@ impl YamlFrameReader {
}
};

let kind = if name == "transparent-checkerboard" {
CheckerboardKind::BlackTransparent
} else {
CheckerboardKind::BlackGrey
};

generate_checkerboard_image(
border,
x_size,
y_size,
x_count,
y_count,
kind,
)
}
_ => {
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.