🎥 Make videos programmatically with React
test out fill method
Jonny Burgera760540cb565
diff --git a/rust/compositor.rs b/rust/compositor.rsindex d1a19e75fb..0a5fe7187b 100644--- a/rust/compositor.rs+++ b/rust/compositor.rs@@ -2,9 +2,21 @@ use std::fs::File;use image::{ImageBuffer, Rgba};-use crate::{errors, payloads::payloads::ImageLayer};+use crate::{+ errors,+ payloads::payloads::{ImageLayer, Layer, SolidLayer},+};-pub fn draw_layer(img: &mut ImageBuffer<image::Rgba<u8>, Vec<u8>>, layer: ImageLayer) {+fn draw_solid_layer(img: &mut ImageBuffer<image::Rgba<u8>, Vec<u8>>, layer: SolidLayer) {+ for y in layer.y..(layer.height + layer.y) {+ for x in layer.x..(layer.width + layer.x) {+ let px: Rgba<u8> = Rgba(layer.fill);+ img.put_pixel(x, y, px)+ }+ }+}++fn draw_image_layer(img: &mut ImageBuffer<image::Rgba<u8>, Vec<u8>>, layer: ImageLayer) {let file = match File::open(layer.src) {Ok(content) => content,Err(err) => {@@ -25,8 +37,8 @@ pub fn draw_layer(img: &mut ImageBuffer<image::Rgba<u8>, Vec<u8>>, layer: ImageL};let bytes = &buf[..info.buffer_size()];- for y in 0..info.height {- for x in 0..info.width {+ for y in layer.y..(info.height + layer.y) {+ for x in layer.x..(info.width + layer.x) {let r = bytes[((y * info.width + x) * 4) as usize];let g = bytes[((y * info.width + x) * 4 + 1) as usize];let b = bytes[((y * info.width + x) * 4 + 2) as usize];@@ -38,3 +50,14 @@ pub fn draw_layer(img: &mut ImageBuffer<image::Rgba<u8>, Vec<u8>>, layer: ImageL}}}++pub fn draw_layer(img: &mut ImageBuffer<image::Rgba<u8>, Vec<u8>>, layer: Layer) {+ match layer {+ Layer::Image(layer) => {+ draw_image_layer(img, layer);+ }+ Layer::Solid(layer) => {+ draw_solid_layer(img, layer);+ }+ }+}diff --git a/rust/payload.json b/rust/payload.jsonindex 33e685c127..a1e43703d3 100644--- a/rust/payload.json+++ b/rust/payload.json@@ -5,9 +5,22 @@"output": "imglol.png","layers": [{- "src": "/var/folders/hs/mbxg3j_55ls1b_dhn50w32t00000gn/T/react-motion-renderqyvqrH/element-049.png",- "x": 0,- "y": 0+ "type": "Solid",+ "params": {+ "fill": [255, 0, 255, 255],+ "x": 0,+ "y": 0,+ "width": 100,+ "height": 100+ }+ },+ {+ "type": "Image",+ "params": {+ "src": "/var/folders/hs/mbxg3j_55ls1b_dhn50w32t00000gn/T/react-motion-renderqyvqrH/element-049.png",+ "x": 0,+ "y": 0+ }}]}diff --git a/rust/payloads.rs b/rust/payloads.rsindex dbe6fb2edb..f645a198da 100644--- a/rust/payloads.rs+++ b/rust/payloads.rs@@ -8,8 +8,24 @@ pub mod payloads {#[derive(Serialize, Deserialize, Debug)]pub struct ImageLayer {pub src: String,- pub x: u8,- pub y: u8,+ pub x: u32,+ pub y: u32,+ }++ #[derive(Serialize, Deserialize, Debug)]+ pub struct SolidLayer {+ pub fill: [u8; 4],+ pub x: u32,+ pub y: u32,+ pub width: u32,+ pub height: u32,+ }++ #[derive(Serialize, Deserialize, Debug)]+ #[serde(tag = "type", content = "params")]+ pub enum Layer {+ Image(ImageLayer),+ Solid(SolidLayer),}#[derive(Serialize, Deserialize, Debug)]@@ -18,7 +34,7 @@ pub mod payloads {pub output: String,pub width: u32,pub height: u32,- pub layers: Vec<ImageLayer>,+ pub layers: Vec<Layer>,}pub fn parse_cli(json: &str) -> CliInput {