Skip to content

Commit

Permalink
Merge branch 'master' into WHIP-server
Browse files Browse the repository at this point in the history
  • Loading branch information
wkazmierczak committed Dec 18, 2024
2 parents 491b8b9 + e620c11 commit 6d42fb3
Show file tree
Hide file tree
Showing 177 changed files with 2,759 additions and 934 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@
### 💥 Breaking changes

- Drop support for `SHADER_UNUSED_VERTEX_OUTPUT` `wgpu` feature. ([#733](https://github.com/software-mansion/live-compositor/pull/733)) by [@jerzywilczek](https://github.com/jerzywilczek)
- Rename component properties describing color. Remove `_rgba` suffix. ([#896](https://github.com/software-mansion/live-compositor/issues/896)) by [@BrtqKr](https://github.com/BrtqKr)

### ✨ New features

- Add `loop` option for MP4 input. ([#699](https://github.com/software-mansion/live-compositor/pull/699) by [@WojciechBarczynski](https://github.com/WojciechBarczynski))
- Add `LIVE_COMPOSITOR_LOG_FILE` environment variable to enable logging to file ([#853](https://github.com/software-mansion/live-compositor/pull/853) by [@wkozyra95](https://github.com/wkozyra95))
- Add border, border radius and box shadow options to `Rescaler` and `View` components. ([#815](https://github.com/software-mansion/live-compositor/pull/815) by [@WojciechBarczynski](https://github.com/WojciechBarczynski), ([#839](https://github.com/software-mansion/live-compositor/pull/839), [#842](https://github.com/software-mansion/live-compositor/pull/842), [#858](https://github.com/software-mansion/live-compositor/pull/858) by [@wkozyra95](https://github.com/wkozyra95))

- Extend supported color formats. ([#896](https://github.com/software-mansion/live-compositor/issues/896)) by [@BrtqKr](https://github.com/BrtqKr)

### 🐛 Bug fixes

Expand Down
4 changes: 2 additions & 2 deletions build_tools/nix/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
# Fixes "ffplay" used in examples on Linux (not needed on NixOS)
env.LIBGL_DRIVERS_PATH = "${pkgs.mesa.drivers}/lib/dri";

env.LIBCLANG_PATH = "${pkgs.llvmPackages_16.libclang.lib}/lib";
env.LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
env.LD_LIBRARY_PATH = lib.makeLibraryPath (libcefDependencies ++ [ pkgs.mesa.drivers pkgs.libGL pkgs.blackmagic-desktop-video ]);

inputsFrom = [ packageWithoutChromium ];
Expand All @@ -89,7 +89,7 @@
nixos = pkgs.mkShell {
packages = devDependencies ++ [ pkgs.blackmagic-desktop-video];

env.LIBCLANG_PATH = "${pkgs.llvmPackages_16.libclang.lib}/lib";
env.LIBCLANG_PATH = "${pkgs.llvmPackages.libclang.lib}/lib";
env.LD_LIBRARY_PATH = lib.makeLibraryPath (libcefDependencies ++ [ pkgs.blackmagic-desktop-video ]);

inputsFrom = [ packageWithoutChromium ];
Expand Down
7 changes: 4 additions & 3 deletions build_tools/nix/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
, ffmpeg_7-headless
, openssl
, pkg-config
, llvmPackages_16
, llvmPackages
, libGL
, cmake
, libopus
Expand All @@ -20,6 +20,7 @@ let
libopus
libGL
vulkan-loader
stdenv.cc.cc
] ++ lib.optionals stdenv.isDarwin [
darwin.apple_sdk.frameworks.Metal
darwin.apple_sdk.frameworks.Foundation
Expand All @@ -43,9 +44,9 @@ rustPlatform.buildRustPackage {
doCheck = false;

inherit buildInputs;
nativeBuildInputs = [ pkg-config llvmPackages_16.clang cmake makeWrapper ];
nativeBuildInputs = [ pkg-config llvmPackages.clang cmake makeWrapper ];

env.LIBCLANG_PATH = "${llvmPackages_16.libclang.lib}/lib";
env.LIBCLANG_PATH = "${llvmPackages.libclang.lib}/lib";

postFixup =
''
Expand Down
1 change: 1 addition & 0 deletions compositor_api/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ mod audio;
mod component;
#[cfg(not(target_arch = "wasm32"))]
mod from_audio;
mod from_color;
mod from_component;
#[cfg(not(target_arch = "wasm32"))]
mod from_register_input;
Expand Down
14 changes: 7 additions & 7 deletions compositor_api/src/types/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ pub struct View {
pub overflow: Option<Overflow>,

/// (**default=`"#00000000"`**) Background color in a `"#RRGGBBAA"` format.
pub background_color_rgba: Option<RGBAColor>,
pub background_color: Option<RGBAColor>,

/// (**default=`0.0`**) Radius of a rounded corner.
pub border_radius: Option<f32>,
Expand All @@ -88,7 +88,7 @@ pub struct View {
pub border_width: Option<f32>,

/// (**default=`"#00000000"`**) Border color in a `"#RRGGBBAA"` format.
pub border_color_rgba: Option<RGBAColor>,
pub border_color: Option<RGBAColor>,

/// List of box shadows.
pub box_shadow: Option<Vec<BoxShadow>>,
Expand All @@ -99,7 +99,7 @@ pub struct View {
pub struct BoxShadow {
pub offset_x: Option<f32>,
pub offset_y: Option<f32>,
pub color_rgba: Option<RGBAColor>,
pub color: Option<RGBAColor>,
pub blur_radius: Option<f32>,
}

Expand Down Expand Up @@ -190,7 +190,7 @@ pub struct Rescaler {
pub border_width: Option<f32>,

/// (**default=`"#00000000"`**) Border color in a `"#RRGGBBAA"` format.
pub border_color_rgba: Option<RGBAColor>,
pub border_color: Option<RGBAColor>,

/// List of box shadows.
pub box_shadow: Option<Vec<BoxShadow>>,
Expand Down Expand Up @@ -311,9 +311,9 @@ pub struct Text {
/// Distance between lines in pixels. Defaults to the value of the `font_size` property.
pub line_height: Option<f32>,
/// (**default=`"#FFFFFFFF"`**) Font color in `#RRGGBBAA` format.
pub color_rgba: Option<RGBAColor>,
pub color: Option<RGBAColor>,
/// (**default=`"#00000000"`**) Background color in `#RRGGBBAA` format.
pub background_color_rgba: Option<RGBAColor>,
pub background_color: Option<RGBAColor>,
/// (**default=`"Verdana"`**) Font family. Provide [family-name](https://www.w3.org/TR/2018/REC-css-fonts-3-20180920/#family-name-value)
/// for a specific font. "generic-family" values like e.g. "sans-serif" will not work.
pub font_family: Option<Arc<str>>,
Expand Down Expand Up @@ -399,7 +399,7 @@ pub struct Tiles {
pub height: Option<f32>,

/// (**default=`"#00000000"`**) Background color in a `"#RRGGBBAA"` format.
pub background_color_rgba: Option<RGBAColor>,
pub background_color: Option<RGBAColor>,
/// (**default=`"16:9"`**) Aspect ratio of a tile in `"W:H"` format, where W and H are integers.
pub tile_aspect_ratio: Option<AspectRatio>,
/// (**default=`0`**) Margin of each tile in pixels.
Expand Down
250 changes: 250 additions & 0 deletions compositor_api/src/types/from_color.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,250 @@
use compositor_render::scene;

use super::util::*;

impl TryFrom<RGBAColor> for scene::RGBAColor {
type Error = TypeError;
fn try_from(value: RGBAColor) -> std::result::Result<Self, Self::Error> {
let s = &value.0.trim();
if let Some(named_color) = parse_named_color(s) {
return Ok(named_color);
}
if s.starts_with('#') {
return match s.len() {
7 => parse_hex(s),
9 => parse_hex_rgba(s),
_ => Err(TypeError::new(
"Invalid format. Color has to be in #RRGGBB or #RRGGBBAA format.",
)),
};
}
if s.starts_with("rgb(") {
return parse_rgb(s);
}

if s.starts_with("rgba(") {
return parse_rgba(s);
}

Err(TypeError::new("Unsupported color format."))
}
}

fn parse_color_channel(value: &str, radix: u32) -> Result<u8, TypeError> {
u8::from_str_radix(value.trim(), radix).map_err(|_err| {
TypeError::new("Invalid format. Color representation is not a valid number.")
})
}

fn parse_hex(s: &str) -> Result<scene::RGBAColor, TypeError> {
let (r, g, b) = (&s[1..3], &s[3..5], &s[5..7]);
Ok(scene::RGBAColor(
parse_color_channel(r, 16)?,
parse_color_channel(g, 16)?,
parse_color_channel(b, 16)?,
255,
))
}

fn parse_hex_rgba(s: &str) -> Result<scene::RGBAColor, TypeError> {
let (r, g, b, a) = (&s[1..3], &s[3..5], &s[5..7], &s[7..9]);
Ok(scene::RGBAColor(
parse_color_channel(r, 16)?,
parse_color_channel(g, 16)?,
parse_color_channel(b, 16)?,
parse_color_channel(a, 16)?,
))
}

fn parse_rgb(s: &str) -> Result<scene::RGBAColor, TypeError> {
let inner_s = s.trim_start_matches("rgb(").trim_end_matches(')');
let parts: Vec<&str> = inner_s.split(',').collect();
match parts.as_slice() {
[r, g, b] => Ok(scene::RGBAColor(
parse_color_channel(r, 10)?,
parse_color_channel(g, 10)?,
parse_color_channel(b, 10)?,
255,
)),
_ => Err(TypeError::new("Invalid RGB format.")),
}
}

fn parse_rgba(s: &str) -> Result<scene::RGBAColor, TypeError> {
let inner_s = s.trim_start_matches("rgba(").trim_end_matches(')');
let parts: Vec<&str> = inner_s.split(',').collect();
let [r, g, b, a] = parts.as_slice() else {
return Err(TypeError::new(
"Expected three color components and alpha channel.",
));
};
let a = a
.parse::<f32>()
.map_err(|_| TypeError::new("Alpha channel parsing failed."))?;
if !(0.0..=1.0).contains(&a) {
return Err(TypeError::new(
"Alpha value out of range. It must be between 0.0 and 1.0",
));
}
Ok(scene::RGBAColor(
parse_color_channel(r, 10)?,
parse_color_channel(g, 10)?,
parse_color_channel(b, 10)?,
(a * 255.0).round() as u8,
))
}

fn parse_named_color(color_name: &str) -> Option<scene::RGBAColor> {
match color_name {
"aliceblue" => Some(scene::RGBAColor(240, 248, 255, 255)),
"antiquewhite" => Some(scene::RGBAColor(250, 235, 215, 255)),
"aqua" => Some(scene::RGBAColor(0, 255, 255, 255)),
"aquamarine" => Some(scene::RGBAColor(127, 255, 212, 255)),
"azure" => Some(scene::RGBAColor(240, 255, 255, 255)),
"beige" => Some(scene::RGBAColor(245, 245, 220, 255)),
"bisque" => Some(scene::RGBAColor(255, 228, 196, 255)),
"black" => Some(scene::RGBAColor(0, 0, 0, 255)),
"blanchedalmond" => Some(scene::RGBAColor(255, 235, 205, 255)),
"blue" => Some(scene::RGBAColor(0, 0, 255, 255)),
"blueviolet" => Some(scene::RGBAColor(138, 43, 226, 255)),
"brown" => Some(scene::RGBAColor(165, 42, 42, 255)),
"burlywood" => Some(scene::RGBAColor(222, 184, 135, 255)),
"burntsienna" => Some(scene::RGBAColor(234, 126, 93, 255)),
"cadetblue" => Some(scene::RGBAColor(95, 158, 160, 255)),
"chartreuse" => Some(scene::RGBAColor(127, 255, 0, 255)),
"chocolate" => Some(scene::RGBAColor(210, 105, 30, 255)),
"coral" => Some(scene::RGBAColor(255, 127, 80, 255)),
"cornflowerblue" => Some(scene::RGBAColor(100, 149, 237, 255)),
"cornsilk" => Some(scene::RGBAColor(255, 248, 220, 255)),
"crimson" => Some(scene::RGBAColor(220, 20, 60, 255)),
"cyan" => Some(scene::RGBAColor(0, 255, 255, 255)),
"darkblue" => Some(scene::RGBAColor(0, 0, 139, 255)),
"darkcyan" => Some(scene::RGBAColor(0, 139, 139, 255)),
"darkgoldenrod" => Some(scene::RGBAColor(184, 134, 11, 255)),
"darkgray" => Some(scene::RGBAColor(169, 169, 169, 255)),
"darkgreen" => Some(scene::RGBAColor(0, 100, 0, 255)),
"darkgrey" => Some(scene::RGBAColor(169, 169, 169, 255)),
"darkkhaki" => Some(scene::RGBAColor(189, 183, 107, 255)),
"darkmagenta" => Some(scene::RGBAColor(139, 0, 139, 255)),
"darkolivegreen" => Some(scene::RGBAColor(85, 107, 47, 255)),
"darkorange" => Some(scene::RGBAColor(255, 140, 0, 255)),
"darkorchid" => Some(scene::RGBAColor(153, 50, 204, 255)),
"darkred" => Some(scene::RGBAColor(139, 0, 0, 255)),
"darksalmon" => Some(scene::RGBAColor(233, 150, 122, 255)),
"darkseagreen" => Some(scene::RGBAColor(143, 188, 143, 255)),
"darkslateblue" => Some(scene::RGBAColor(72, 61, 139, 255)),
"darkslategray" => Some(scene::RGBAColor(47, 79, 79, 255)),
"darkslategrey" => Some(scene::RGBAColor(47, 79, 79, 255)),
"darkturquoise" => Some(scene::RGBAColor(0, 206, 209, 255)),
"darkviolet" => Some(scene::RGBAColor(148, 0, 211, 255)),
"deeppink" => Some(scene::RGBAColor(255, 20, 147, 255)),
"deepskyblue" => Some(scene::RGBAColor(0, 191, 255, 255)),
"dimgray" => Some(scene::RGBAColor(105, 105, 105, 255)),
"dimgrey" => Some(scene::RGBAColor(105, 105, 105, 255)),
"dodgerblue" => Some(scene::RGBAColor(30, 144, 255, 255)),
"firebrick" => Some(scene::RGBAColor(178, 34, 34, 255)),
"floralwhite" => Some(scene::RGBAColor(255, 250, 240, 255)),
"forestgreen" => Some(scene::RGBAColor(34, 139, 34, 255)),
"fuchsia" => Some(scene::RGBAColor(255, 0, 255, 255)),
"gainsboro" => Some(scene::RGBAColor(220, 220, 220, 255)),
"ghostwhite" => Some(scene::RGBAColor(248, 248, 255, 255)),
"gold" => Some(scene::RGBAColor(255, 215, 0, 255)),
"goldenrod" => Some(scene::RGBAColor(218, 165, 32, 255)),
"gray" => Some(scene::RGBAColor(128, 128, 128, 255)),
"green" => Some(scene::RGBAColor(0, 128, 0, 255)),
"greenyellow" => Some(scene::RGBAColor(173, 255, 47, 255)),
"grey" => Some(scene::RGBAColor(128, 128, 128, 255)),
"honeydew" => Some(scene::RGBAColor(240, 255, 240, 255)),
"hotpink" => Some(scene::RGBAColor(255, 105, 180, 255)),
"indianred" => Some(scene::RGBAColor(205, 92, 92, 255)),
"indigo" => Some(scene::RGBAColor(75, 0, 130, 255)),
"ivory" => Some(scene::RGBAColor(255, 255, 240, 255)),
"khaki" => Some(scene::RGBAColor(240, 230, 140, 255)),
"lavender" => Some(scene::RGBAColor(230, 230, 250, 255)),
"lavenderblush" => Some(scene::RGBAColor(255, 240, 245, 255)),
"lawngreen" => Some(scene::RGBAColor(124, 252, 0, 255)),
"lemonchiffon" => Some(scene::RGBAColor(255, 250, 205, 255)),
"lightblue" => Some(scene::RGBAColor(173, 216, 230, 255)),
"lightcoral" => Some(scene::RGBAColor(240, 128, 128, 255)),
"lightcyan" => Some(scene::RGBAColor(224, 255, 255, 255)),
"lightgoldenrodyellow" => Some(scene::RGBAColor(250, 250, 210, 255)),
"lightgray" => Some(scene::RGBAColor(211, 211, 211, 255)),
"lightgreen" => Some(scene::RGBAColor(144, 238, 144, 255)),
"lightgrey" => Some(scene::RGBAColor(211, 211, 211, 255)),
"lightpink" => Some(scene::RGBAColor(255, 182, 193, 255)),
"lightsalmon" => Some(scene::RGBAColor(255, 160, 122, 255)),
"lightseagreen" => Some(scene::RGBAColor(32, 178, 170, 255)),
"lightskyblue" => Some(scene::RGBAColor(135, 206, 250, 255)),
"lightslategray" => Some(scene::RGBAColor(119, 136, 153, 255)),
"lightslategrey" => Some(scene::RGBAColor(119, 136, 153, 255)),
"lightsteelblue" => Some(scene::RGBAColor(176, 196, 222, 255)),
"lightyellow" => Some(scene::RGBAColor(255, 255, 224, 255)),
"lime" => Some(scene::RGBAColor(0, 255, 0, 255)),
"limegreen" => Some(scene::RGBAColor(50, 205, 50, 255)),
"linen" => Some(scene::RGBAColor(250, 240, 230, 255)),
"magenta" => Some(scene::RGBAColor(255, 0, 255, 255)),
"maroon" => Some(scene::RGBAColor(128, 0, 0, 255)),
"mediumaquamarine" => Some(scene::RGBAColor(102, 205, 170, 255)),
"mediumblue" => Some(scene::RGBAColor(0, 0, 205, 255)),
"mediumorchid" => Some(scene::RGBAColor(186, 85, 211, 255)),
"mediumpurple" => Some(scene::RGBAColor(147, 112, 219, 255)),
"mediumseagreen" => Some(scene::RGBAColor(60, 179, 113, 255)),
"mediumslateblue" => Some(scene::RGBAColor(123, 104, 238, 255)),
"mediumspringgreen" => Some(scene::RGBAColor(0, 250, 154, 255)),
"mediumturquoise" => Some(scene::RGBAColor(72, 209, 204, 255)),
"mediumvioletred" => Some(scene::RGBAColor(199, 21, 133, 255)),
"midnightblue" => Some(scene::RGBAColor(25, 25, 112, 255)),
"mintcream" => Some(scene::RGBAColor(245, 255, 250, 255)),
"mistyrose" => Some(scene::RGBAColor(255, 228, 225, 255)),
"moccasin" => Some(scene::RGBAColor(255, 228, 181, 255)),
"navajowhite" => Some(scene::RGBAColor(255, 222, 173, 255)),
"navy" => Some(scene::RGBAColor(0, 0, 128, 255)),
"oldlace" => Some(scene::RGBAColor(253, 245, 230, 255)),
"olive" => Some(scene::RGBAColor(128, 128, 0, 255)),
"olivedrab" => Some(scene::RGBAColor(107, 142, 35, 255)),
"orange" => Some(scene::RGBAColor(255, 165, 0, 255)),
"orangered" => Some(scene::RGBAColor(255, 69, 0, 255)),
"orchid" => Some(scene::RGBAColor(218, 112, 214, 255)),
"palegoldenrod" => Some(scene::RGBAColor(238, 232, 170, 255)),
"palegreen" => Some(scene::RGBAColor(152, 251, 152, 255)),
"paleturquoise" => Some(scene::RGBAColor(175, 238, 238, 255)),
"palevioletred" => Some(scene::RGBAColor(219, 112, 147, 255)),
"papayawhip" => Some(scene::RGBAColor(255, 239, 213, 255)),
"peachpuff" => Some(scene::RGBAColor(255, 218, 185, 255)),
"peru" => Some(scene::RGBAColor(205, 133, 63, 255)),
"pink" => Some(scene::RGBAColor(255, 192, 203, 255)),
"plum" => Some(scene::RGBAColor(221, 160, 221, 255)),
"powderblue" => Some(scene::RGBAColor(176, 224, 230, 255)),
"purple" => Some(scene::RGBAColor(128, 0, 128, 255)),
"rebeccapurple" => Some(scene::RGBAColor(102, 51, 153, 255)),
"red" => Some(scene::RGBAColor(255, 0, 0, 255)),
"rosybrown" => Some(scene::RGBAColor(188, 143, 143, 255)),
"royalblue" => Some(scene::RGBAColor(65, 105, 225, 255)),
"saddlebrown" => Some(scene::RGBAColor(139, 69, 19, 255)),
"salmon" => Some(scene::RGBAColor(250, 128, 114, 255)),
"sandybrown" => Some(scene::RGBAColor(244, 164, 96, 255)),
"seagreen" => Some(scene::RGBAColor(46, 139, 87, 255)),
"seashell" => Some(scene::RGBAColor(255, 245, 238, 255)),
"sienna" => Some(scene::RGBAColor(160, 82, 45, 255)),
"silver" => Some(scene::RGBAColor(192, 192, 192, 255)),
"skyblue" => Some(scene::RGBAColor(135, 206, 235, 255)),
"slateblue" => Some(scene::RGBAColor(106, 90, 205, 255)),
"slategray" => Some(scene::RGBAColor(112, 128, 144, 255)),
"slategrey" => Some(scene::RGBAColor(112, 128, 144, 255)),
"snow" => Some(scene::RGBAColor(255, 250, 250, 255)),
"springgreen" => Some(scene::RGBAColor(0, 255, 127, 255)),
"steelblue" => Some(scene::RGBAColor(70, 130, 180, 255)),
"tan" => Some(scene::RGBAColor(210, 180, 140, 255)),
"teal" => Some(scene::RGBAColor(0, 128, 128, 255)),
"thistle" => Some(scene::RGBAColor(216, 191, 216, 255)),
"tomato" => Some(scene::RGBAColor(255, 99, 71, 255)),
"turquoise" => Some(scene::RGBAColor(64, 224, 208, 255)),
"violet" => Some(scene::RGBAColor(238, 130, 238, 255)),
"wheat" => Some(scene::RGBAColor(245, 222, 179, 255)),
"white" => Some(scene::RGBAColor(255, 255, 255, 255)),
"whitesmoke" => Some(scene::RGBAColor(245, 245, 245, 255)),
"yellow" => Some(scene::RGBAColor(255, 255, 0, 255)),
"yellowgreen" => Some(scene::RGBAColor(154, 205, 50, 255)),
_ => None,
}
}
Loading

0 comments on commit 6d42fb3

Please sign in to comment.