Skip to content

Commit

Permalink
dbg
Browse files Browse the repository at this point in the history
Signed-off-by: sagudev <[email protected]>
  • Loading branch information
sagudev committed Sep 26, 2024
1 parent 8468e81 commit 3959b63
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
13 changes: 13 additions & 0 deletions webrender_api/src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use euclid::{size2, Box2D, num::Zero};
use peek_poke::PeekPoke;
use std::ops::{Add, Sub};
use std::str::FromStr;
use std::sync::Arc;
// local imports
use crate::{IdNamespace, TileSize};
Expand Down Expand Up @@ -173,6 +174,18 @@ pub enum ImageFormat {
RGBA8 = 8,
}

impl FromStr for ImageFormat {
type Err = ();

fn from_str(s: &str) -> Result<Self, Self::Err> {
match s.to_ascii_lowercase().as_str() {
"rgba" | "rgba8" => Ok(Self::RGBA8),
"bgra" | "bgra8" => Ok(Self::BGRA8),
_ => Err(())
}
}
}

impl ImageFormat {
/// Returns the number of bytes per pixel for the given format.
pub fn bytes_per_pixel(self) -> i32 {
Expand Down
16 changes: 10 additions & 6 deletions wrench/src/yaml_frame_reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ fn generate_checkerboard_image(
tile_x_count: u32,
tile_y_count: u32,
kind: CheckerboardKind,
format: ImageFormat,
) -> (ImageDescriptor, ImageData) {
let width = 2 * border + tile_x_size * tile_x_count;
let height = 2 * border + tile_y_size * tile_y_count;
Expand Down Expand Up @@ -240,7 +241,7 @@ fn generate_checkerboard_image(
};

(
ImageDescriptor::new(width as i32, height as i32, ImageFormat::BGRA8, flags),
ImageDescriptor::new(width as i32, height as i32, format, flags),
ImageData::new(pixels),
)
}
Expand Down Expand Up @@ -632,18 +633,20 @@ impl YamlFrameReader {
(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() {
3 => {
let (x_size, y_size, x_count, y_count, format) = match args.len() {
3 | 4 => {
let size = args.get(1).unwrap_or(&"32").parse::<u32>().unwrap();
let count = args.get(2).unwrap_or(&"8").parse::<u32>().unwrap();
(size, size, count, count)
let format = args.get(3).map(|x| x.parse::<ImageFormat>().unwrap()).unwrap_or(ImageFormat::BGRA8);
(size, size, count, count, format)
}
5 => {
5 | 6 => {
let x_size = args.get(1).unwrap_or(&"32").parse::<u32>().unwrap();
let y_size = args.get(2).unwrap_or(&"32").parse::<u32>().unwrap();
let x_count = args.get(3).unwrap_or(&"8").parse::<u32>().unwrap();
let y_count = args.get(4).unwrap_or(&"8").parse::<u32>().unwrap();
(x_size, y_size, x_count, y_count)
let format = args.get(5).map(|x| x.parse::<ImageFormat>().unwrap()).unwrap_or(ImageFormat::BGRA8);
(x_size, y_size, x_count, y_count, format)
}
_ => {
panic!("invalid checkerboard function");
Expand All @@ -663,6 +666,7 @@ impl YamlFrameReader {
x_count,
y_count,
kind,
format,
)
}
_ => {
Expand Down

0 comments on commit 3959b63

Please sign in to comment.