Skip to content

Commit

Permalink
wrench: Introduce transparent-checkerboard, which is useful to test m…
Browse files Browse the repository at this point in the history
…asking.
  • Loading branch information
emilio committed Oct 20, 2018
1 parent 05c247f commit 293b766
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 6 deletions.
14 changes: 14 additions & 0 deletions wrench/reftests/mask/checkerboard-tiling.yaml
@@ -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 added wrench/reftests/mask/checkerboard.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 13 additions & 0 deletions wrench/reftests/mask/checkerboard.yaml
@@ -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
2 changes: 2 additions & 0 deletions wrench/reftests/mask/reftest.list
Expand Up @@ -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
37 changes: 31 additions & 6 deletions wrench/src/yaml_frame_reader.rs
Expand Up @@ -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;
Expand All @@ -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);
}
}
}
}
}
Expand Down Expand Up @@ -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() {
Expand All @@ -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,
)
}
_ => {
Expand Down

0 comments on commit 293b766

Please sign in to comment.