Compare commits

..

8 Commits

15 changed files with 1139 additions and 128 deletions

405
Cargo.lock generated
View File

@ -2,6 +2,172 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 3
[[package]]
name = "addr2line"
version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb"
dependencies = [
"gimli",
]
[[package]]
name = "adler"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "anstream"
version = "0.6.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e2e1ebcb11de5c03c67de28a7df593d32191b44939c482e97702baaaa6ab6a5"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7079075b41f533b8c61d2a4d073c4676e1f8b249ff94a393b0595db304e0dd87"
[[package]]
name = "anstyle-parse"
version = "0.2.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648"
dependencies = [
"windows-sys",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7"
dependencies = [
"anstyle",
"windows-sys",
]
[[package]]
name = "backtrace"
version = "0.3.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2089b7e3f35b9dd2d0ed921ead4f6d318c27680d4a5bd167b3ee120edb105837"
dependencies = [
"addr2line",
"cc",
"cfg-if",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
]
[[package]]
name = "cc"
version = "1.0.83"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
dependencies = [
"libc",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "clap"
version = "4.4.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e578d6ec4194633722ccf9544794b71b1385c3c027efe0c55db226fc880865c"
dependencies = [
"clap_builder",
"clap_derive",
]
[[package]]
name = "clap_builder"
version = "4.4.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4df4df40ec50c46000231c914968278b1eb05098cf8f1b3a518a95030e71d1c7"
dependencies = [
"anstream",
"anstyle",
"clap_lex",
"strsim",
]
[[package]]
name = "clap_derive"
version = "4.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cf9804afaaf59a91e75b022a30fb7229a7901f60c755489cc61c9b423b836442"
dependencies = [
"heck",
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "clap_lex"
version = "0.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "702fc72eb24e5a1e48ce58027a675bc24edd52096d5397d4aea7c6dd9eca0bd1"
[[package]]
name = "color-eyre"
version = "0.6.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a667583cca8c4f8436db8de46ea8233c42a7d9ae424a82d338f2e4675229204"
dependencies = [
"backtrace",
"color-spantrace",
"eyre",
"indenter",
"once_cell",
"owo-colors",
"tracing-error",
]
[[package]]
name = "color-spantrace"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cd6be1b2a7e382e2b98b43b2adcca6bb0e465af0bdd38123873ae61eb17a72c2"
dependencies = [
"once_cell",
"owo-colors",
"tracing-core",
"tracing-error",
]
[[package]]
name = "colorchoice"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7"
[[package]] [[package]]
name = "console" name = "console"
version = "0.15.8" version = "0.15.8"
@ -26,20 +192,49 @@ version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "eyre"
version = "0.6.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6267a1fa6f59179ea4afc8e50fd8612a3cc60bc858f786ff877a4a8cb042799"
dependencies = [
"indenter",
"once_cell",
]
[[package]] [[package]]
name = "gegl" name = "gegl"
version = "0.0.0" version = "0.0.0"
dependencies = [ dependencies = [
"indexmap", "indexmap",
"insta", "insta",
"paste",
] ]
[[package]]
name = "gimli"
version = "0.28.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4271d37baee1b8c7e4b708028c57d816cf9d2434acb33a549475f78c181f6253"
[[package]] [[package]]
name = "hashbrown" name = "hashbrown"
version = "0.14.3" version = "0.14.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604"
[[package]]
name = "heck"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]]
name = "indenter"
version = "0.3.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ce23b50ad8242c51a442f3ff322d56b02f08852c77e4c0b4d3fd684abc89c683"
[[package]] [[package]]
name = "indexmap" name = "indexmap"
version = "2.1.0" version = "2.1.0"
@ -63,6 +258,17 @@ dependencies = [
"yaml-rust", "yaml-rust",
] ]
[[package]]
name = "interlinked"
version = "0.0.0"
dependencies = [
"clap",
"color-eyre",
"gegl",
"insta",
"subprocess",
]
[[package]] [[package]]
name = "lazy_static" name = "lazy_static"
version = "1.4.0" version = "1.4.0"
@ -81,12 +287,211 @@ version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f"
[[package]]
name = "memchr"
version = "2.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "523dc4f511e55ab87b694dc30d0f820d60906ef06413f93d4d7a1385599cc149"
[[package]]
name = "miniz_oxide"
version = "0.7.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e7810e0be55b428ada41041c41f32c9f1a42817901b4ccf45fa3d4b6561e74c7"
dependencies = [
"adler",
]
[[package]]
name = "object"
version = "0.32.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a6a622008b6e321afc04970976f62ee297fdbaa6f95318ca343e3eebb9648441"
dependencies = [
"memchr",
]
[[package]]
name = "once_cell"
version = "1.19.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdb12b2476b595f9358c5161aa467c2438859caa136dec86c26fdd2efe17b92"
[[package]]
name = "owo-colors"
version = "3.5.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1b04fb49957986fdce4d6ee7a65027d55d4b6d2265e5848bbb507b58ccfdb6f"
[[package]]
name = "paste"
version = "1.0.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "de3145af08024dea9fa9914f381a17b8fc6034dfb00f3a84013f7ff43f29ed4c"
[[package]]
name = "pin-project-lite"
version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8afb450f006bf6385ca15ef45d71d2288452bc3683ce2e2cacc0d18e4be60b58"
[[package]]
name = "proc-macro2"
version = "1.0.78"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e2422ad645d89c99f8f3e6b88a9fdeca7fabeac836b1002371c4367c8f984aae"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.35"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef"
dependencies = [
"proc-macro2",
]
[[package]]
name = "rustc-demangle"
version = "0.1.23"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
[[package]]
name = "sharded-slab"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f40ca3c46823713e0d4209592e8d6e826aa57e928f09752619fc696c499637f6"
dependencies = [
"lazy_static",
]
[[package]] [[package]]
name = "similar" name = "similar"
version = "2.4.0" version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "32fea41aca09ee824cc9724996433064c89f7777e60762749a4170a14abbfa21" checksum = "32fea41aca09ee824cc9724996433064c89f7777e60762749a4170a14abbfa21"
[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73473c0e59e6d5812c5dfe2a064a6444949f089e20eec9a2e5506596494e4623"
[[package]]
name = "subprocess"
version = "0.2.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c2e86926081dda636c546d8c5e641661049d7562a68f5488be4a1f7f66f6086"
dependencies = [
"libc",
"winapi",
]
[[package]]
name = "syn"
version = "2.0.48"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0f3531638e407dfc0814761abb7c00a5b54992b849452a0646b7f65c9f770f3f"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "thread_local"
version = "1.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fdd6f064ccff2d6567adcb3873ca630700f00b5ad3f060c25b5dcfd9a4ce152"
dependencies = [
"cfg-if",
"once_cell",
]
[[package]]
name = "tracing"
version = "0.1.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef"
dependencies = [
"pin-project-lite",
"tracing-core",
]
[[package]]
name = "tracing-core"
version = "0.1.32"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54"
dependencies = [
"once_cell",
"valuable",
]
[[package]]
name = "tracing-error"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d686ec1c0f384b1277f097b2f279a2ecc11afe8c133c1aabf036a27cb4cd206e"
dependencies = [
"tracing",
"tracing-subscriber",
]
[[package]]
name = "tracing-subscriber"
version = "0.3.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ad0f048c97dbd9faa9b7df56362b8ebcaa52adb06b498c050d2f4e32f90a7a8b"
dependencies = [
"sharded-slab",
"thread_local",
"tracing-core",
]
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "utf8parse"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]]
name = "valuable"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d"
[[package]]
name = "winapi"
version = "0.3.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419"
dependencies = [
"winapi-i686-pc-windows-gnu",
"winapi-x86_64-pc-windows-gnu",
]
[[package]]
name = "winapi-i686-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
[[package]]
name = "winapi-x86_64-pc-windows-gnu"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]] [[package]]
name = "windows-sys" name = "windows-sys"
version = "0.52.0" version = "0.52.0"

View File

@ -2,7 +2,8 @@
[workspace] [workspace]
members = [ members = [
"gegl" "gegl",
"interlinked",
] ]
resolver = "2" resolver = "2"

View File

@ -3,7 +3,7 @@
[package] [package]
name = "gegl" name = "gegl"
description = "GEGL data structure library for Rust." description = "GEGL data structure library for Rust."
repository = "https://git.bauke.xyz/driftingnebula/gegl" repository = "https://git.bauke.xyz/driftingnebula/interlinked"
license = "AGPL-3.0-or-later" license = "AGPL-3.0-or-later"
version = "0.0.0" version = "0.0.0"
authors = ["Bauke <me@bauke.xyz>"] authors = ["Bauke <me@bauke.xyz>"]
@ -18,6 +18,7 @@ workspace = true
[dependencies] [dependencies]
indexmap = "2.1.0" indexmap = "2.1.0"
paste = "1.0.14"
[dev-dependencies] [dev-dependencies]
insta = "1.34.0" insta = "1.34.0"

View File

@ -15,16 +15,27 @@ pub type GeglData = indexmap::IndexMap<&'static str, String>;
/// The [`GeglOperation`] trait defines a set of common functions for the /// The [`GeglOperation`] trait defines a set of common functions for the
/// individual operations to implement so they can be used with the GEGL CLI. /// individual operations to implement so they can be used with the GEGL CLI.
pub trait GeglOperation: Default + std::fmt::Debug { pub trait GeglOperation: std::fmt::Debug + Send + Sync {
/// Some GEGL operations will run infinitely unless you limit the buffer in /// Some GEGL operations will run infinitely unless you limit the buffer in
/// some way, so all operations must indicate whether or not they should be /// some way, so all operations must indicate whether or not they should be
/// followed by a crop operation. /// followed by a crop operation.
fn append_crop_operation(&self) -> bool; fn append_crop_operation(&self) -> bool;
/// Return the default values for the operation as a [`GeglData`].
///
/// The reason this can't use [`Default`] is because we want the trait to be
/// object-safe so we can use [`Box<dyn GeglOperation>`]. Implementing
/// [`Default`] makes the trait [`Sized`] and no longer object-safe.
///
/// The [`gegl_operation`] macro still implements and calls [`Default`] anyway
/// so it's easy to instantiate operations but we have to go in a roundabout
/// way to actually get the values from it for this function.
fn default_values(&self) -> GeglData;
/// Creates the parameters for the graph to be used with the GEGL CLI. /// Creates the parameters for the graph to be used with the GEGL CLI.
fn graph(&self, include_default_values: bool) -> Vec<String> { fn graph(&self, include_default_values: bool) -> Vec<String> {
let mut graph = vec![self.name().to_string()]; let mut graph = vec![self.name().to_string()];
let defaults = Self::default().values(); let defaults = self.default_values();
for (key, value) in self.values() { for (key, value) in self.values() {
if !include_default_values && defaults.get(key) == Some(&value) { if !include_default_values && defaults.get(key) == Some(&value) {

View File

@ -3,6 +3,7 @@
use crate::gegl_enum; use crate::gegl_enum;
gegl_enum!( gegl_enum!(
/// The shape for [`FocusBlur`][super::FocusBlur].
FocusBlurShape, FocusBlurShape,
Circle => "circle", Circle => "circle",
Square => "square", Square => "square",
@ -12,24 +13,28 @@ gegl_enum!(
); );
gegl_enum!( gegl_enum!(
/// The type for [`FocusBlur`][super::FocusBlur].
FocusBlurType, FocusBlurType,
Gaussian => "gaussian", Gaussian => "gaussian",
Lens => "lens", Lens => "lens",
); );
gegl_enum!( gegl_enum!(
/// The algorithm type for [`Maze`][super::Maze].
MazeAlgorithmType, MazeAlgorithmType,
DepthFirst => "depth-first", DepthFirst => "depth-first",
Prim => "prim", Prim => "prim",
); );
gegl_enum!( gegl_enum!(
/// The abyss policy for [`MedianBlur`][super::MedianBlur].
MedianBlurAbyssPolicy, MedianBlurAbyssPolicy,
None => "none", None => "none",
Clamp => "clamp", Clamp => "clamp",
); );
gegl_enum!( gegl_enum!(
/// The neighborhood for [`MedianBlur`][super::MedianBlur].
MedianBlurNeighborhood, MedianBlurNeighborhood,
Square => "square", Square => "square",
Circle => "circle", Circle => "circle",
@ -37,6 +42,7 @@ gegl_enum!(
); );
gegl_enum!( gegl_enum!(
/// The tile type for [`Mosaic`][super::Mosaic].
MosaicTileType, MosaicTileType,
Squares => "squares", Squares => "squares",
Hexagons => "hexagons", Hexagons => "hexagons",
@ -45,6 +51,7 @@ gegl_enum!(
); );
gegl_enum!( gegl_enum!(
/// The pattern for [`Newsprint`][super::Newsprint].
NewsprintPattern, NewsprintPattern,
Line => "line", Line => "line",
Circle => "circle", Circle => "circle",
@ -54,9 +61,37 @@ gegl_enum!(
); );
gegl_enum!( gegl_enum!(
/// The color model for [`Newsprint`][super::Newsprint].
NewsprintColorModel, NewsprintColorModel,
BlackOnWhite => "black-on-white", BlackOnWhite => "black-on-white",
Cmyk => "cmyk", Cmyk => "cmyk",
Rgb => "rgb", Rgb => "rgb",
WhiteOnBlack => "white-on-black", WhiteOnBlack => "white-on-black",
); );
gegl_enum!(
/// The sampler type for [`StereographicProjection`][super::StereographicProjection].
StereographicProjectionSamplerType,
Nearest => "nearest",
Linear => "linear",
Cubic => "cubic",
Nohalo => "nohalo",
Lohalo => "lohalo",
);
gegl_enum!(
/// The fill for [`Waterpixels`][super::Waterpixels].
WaterpixelsFill,
Average => "average",
Random => "random",
);
gegl_enum!(
/// The sampler type for [`Waves`][super::Waves].
WavesSamplerType,
Nearest => "nearest",
Linear => "linear",
Cubic => "cubic",
Nohalo => "nohalo",
Lohalo => "lohalo",
);

View File

@ -7,17 +7,39 @@ macro_rules! gegl_operation {
struct_name: $struct_name:ident, struct_name: $struct_name:ident,
gegl_name: $gegl_name:expr, gegl_name: $gegl_name:expr,
append_crop: $append_crop:expr, append_crop: $append_crop:expr,
values: ($($key:ident: $key_type:ty, $key_default:expr, $key_doc:expr),*,), values: (
$(
$(#[$key_meta:meta])*
$key:ident: $key_type:ty, $key_default:expr
),*,
),
) => { ) => {
#[doc = concat!(" The `gegl:", $gegl_name, "` operation.")] #[doc = concat!(" The `gegl:", $gegl_name, "` operation.")]
#[derive(Debug)] #[derive(Debug)]
pub struct $struct_name { pub struct $struct_name {
$( $(
#[doc = concat!(" ", $key_doc)] $(#[$key_meta])*
pub $key: $key_type, pub $key: $key_type,
)* )*
} }
paste::paste! {
impl $struct_name {
$(
#[doc = concat!(" Builder function to assign `", stringify!($key), "`.")]
pub fn [<with_ $key>](mut self, value: $key_type) -> $struct_name {
self.$key = value;
self
}
)*
/// Get this operation inside a [`Box`].
pub fn boxed(self) -> Box<$struct_name> {
Box::new(self)
}
}
}
impl Default for $struct_name { impl Default for $struct_name {
fn default() -> $struct_name { fn default() -> $struct_name {
$struct_name { $struct_name {
@ -31,6 +53,10 @@ macro_rules! gegl_operation {
$append_crop $append_crop
} }
fn default_values(&self) -> $crate::GeglData {
Self::default().values()
}
fn name(&self) -> &'static str { fn name(&self) -> &'static str {
concat!("gegl:", $gegl_name) concat!("gegl:", $gegl_name)
} }
@ -48,14 +74,15 @@ macro_rules! gegl_operation {
#[macro_export] #[macro_export]
macro_rules! gegl_enum { macro_rules! gegl_enum {
( (
$(#[$enum_meta:meta])*
$enum_name:ident, $enum_name:ident,
$($key:ident => $value:expr),*, $($key:ident => $value:expr),*,
) => { ) => {
#[doc = "TODO: Generate documentation for [`gegl_enum!`]."] $(#[$enum_meta])*
#[derive(Debug)] #[derive(Debug)]
pub enum $enum_name { pub enum $enum_name {
$( $(
#[doc = "TODO: Generate documentation for [`gegl_enum!`]."] #[doc = concat!("The [`", stringify!($enum_name), "`] `", $value, "`." )]
$key, $key,
)* )*
} }

View File

@ -12,11 +12,16 @@ gegl_operation!(
gegl_name: "bloom", gegl_name: "bloom",
append_crop: false, append_crop: false,
values: ( values: (
limit_exposure: bool, false, "Don't over-expose highlights.", /// Don't over-expose highlights.
radius: f64, 10.0, "Glow radius.", limit_exposure: bool, false,
softness: f64, 25.0, "Glow-area edge softness.", /// Glow radius.
strength: f64, 50.0, "Glow strength.", radius: f64, 10.0,
threshold: f64, 50.0, "Glow-area brightness threshold.", /// Glow-area edge softness.
softness: f64, 25.0,
/// Glow strength.
strength: f64, 50.0,
/// Glow-area brightness threshold.
threshold: f64, 50.0,
), ),
); );
@ -25,8 +30,10 @@ gegl_operation!(
gegl_name: "cartoon", gegl_name: "cartoon",
append_crop: true, append_crop: true,
values: ( values: (
mask_radius: f64, 7.0, "The mask radius.", /// The mask radius.
pct_black: f64, 0.2, "The percentage of black.", mask_radius: f64, 7.0,
/// The percentage of black.
pct_black: f64, 0.2,
), ),
); );
@ -35,12 +42,18 @@ gegl_operation!(
gegl_name: "cell-noise", gegl_name: "cell-noise",
append_crop: true, append_crop: true,
values: ( values: (
iterations: i64, 1, "The number of noise octaves.", /// The number of noise octaves.
palettize: bool, false, "Fill each cell with a random color.", iterations: i64, 1,
rank: i64, 1, "Select the n-th closest point", /// Fill each cell with a random color.
scale: f64, 1.0, "The scale of the noise function.", palettize: bool, false,
seed: f64, 0.0, "The random seed for the noise function.", /// Select the n-th closest point
shape: f64, 2.0, "Interpolate between Manhattan and Euclidean distance.", rank: i64, 1,
/// The scale of the noise function.
scale: f64, 1.0,
/// The random seed for the noise function.
seed: f64, 0.0,
/// Interpolate between Manhattan and Euclidean distance.
shape: f64, 2.0,
), ),
); );
@ -49,11 +62,16 @@ gegl_operation!(
gegl_name: "crop", gegl_name: "crop",
append_crop: false, append_crop: false,
values: ( values: (
height: f64, 0.0, "The wanted height of the buffer.", /// The wanted height of the buffer.
reset_origin: bool, false, "Reset the origin for the coordinates.", height: f64, 0.0,
width: f64, 0.0, "The wanted width of the buffer.", /// Reset the origin for the coordinates.
x: f64, 0.0, "The X coordinate to start from.", reset_origin: bool, false,
y: f64, 0.0, "The Y coordinate to start from.", /// The wanted width of the buffer.
width: f64, 0.0,
/// The X coordinate to start from.
x: f64, 0.0,
/// The Y coordinate to start from.
y: f64, 0.0,
), ),
); );
@ -62,20 +80,34 @@ gegl_operation!(
gegl_name: "diffraction-patterns", gegl_name: "diffraction-patterns",
append_crop: true, append_crop: true,
values: ( values: (
blue_contours: f64, 0.97, "Number of contours (blue);", /// Number of contours (blue);
blue_frequency: f64, 1.12, "Light frequency (blue).", blue_contours: f64, 0.97,
blue_sedges: f64, 0.64, "Number of sharp edges (blue).", /// Light frequency (blue).
brightness: f64, 0.07, "Brightness and shifting/fattening of contours.", blue_frequency: f64, 1.12,
green_contours: f64, 0.82, "Number of contours (green);", /// Number of sharp edges (blue).
green_frequency: f64, 1.22, "Light frequency (green).", blue_sedges: f64, 0.64,
green_sedges: f64, 0.68, "Number of sharp edges (green).", /// Brightness and shifting/fattening of contours.
height: i64, 200, "Height of the generated buffer.", brightness: f64, 0.07,
polarization: f64, -0.47, "Polarization.", /// Number of contours (green);
red_contours: f64, 0.82, "Number of contours (red);", green_contours: f64, 0.82,
red_frequency: f64, 0.81, "Light frequency (red).", /// Light frequency (green).
red_sedges: f64, 0.61, "Number of sharp edges (red).", green_frequency: f64, 1.22,
scattering: f64, 37.13, "Scattering (speed vs. quality).", /// Number of sharp edges (green).
width: i64, 200, "Width of the generated buffer.", green_sedges: f64, 0.68,
/// Height of the generated buffer.
height: i64, 200,
/// Polarization.
polarization: f64, -0.47,
/// Number of contours (red);
red_contours: f64, 0.82,
/// Light frequency (red).
red_frequency: f64, 0.81,
/// Number of sharp edges (red).
red_sedges: f64, 0.61,
/// Scattering (speed vs. quality).
scattering: f64, 37.13,
/// Width of the generated buffer.
width: i64, 200,
), ),
); );
@ -84,20 +116,34 @@ gegl_operation!(
gegl_name: "focus-blur", gegl_name: "focus-blur",
append_crop: false, append_crop: false,
values: ( values: (
aspect_ratio: f64, 0.0, "The aspect ratio of the focus region.", /// The aspect ratio of the focus region.
blur_radius: f64, 25.0, "Out-of-focus blur radius.", aspect_ratio: f64, 0.0,
blur_type: FocusBlurType, FocusBlurType::Gaussian, "The blur type.", /// Out-of-focus blur radius.
focus: f64, 0.25, "The focus region's inner limit.", blur_radius: f64, 25.0,
highlight_factor: f64, 0.0, "Relative highlight strength.", /// The blur type.
highlight_threshold_high: f64, 1.0, "Highlight threshold (high).", blur_type: FocusBlurType, FocusBlurType::Gaussian,
highlight_threshold_low: f64, 0.0, "Highlight threshold (low).", /// The focus region's inner limit.
high_quality: bool, false, "Generate more accurate and consistent output.", focus: f64, 0.25,
midpoint: f64, 0.5, "The focus region's transition midpoint.", /// Relative highlight strength.
radius: f64, 0.75, "The focus region's outer radius.", highlight_factor: f64, 0.0,
rotation: f64, 0.0, "The rotation of the focus region.", /// Highlight threshold (high).
shape: FocusBlurShape, FocusBlurShape::Circle, "The blur shape.", highlight_threshold_high: f64, 1.0,
x: f64, 0.5, "The X coordinate for the center of the blur.", /// Highlight threshold (low).
y: f64, 0.5, "The Y coordinate for the center of the blur.", highlight_threshold_low: f64, 0.0,
/// Generate more accurate and consistent output.
high_quality: bool, false,
/// The focus region's transition midpoint.
midpoint: f64, 0.5,
/// The focus region's outer radius.
radius: f64, 0.75,
/// The rotation of the focus region.
rotation: f64, 0.0,
/// The blur shape.
shape: FocusBlurShape, FocusBlurShape::Circle,
/// The X coordinate for the center of the blur.
x: f64, 0.5,
/// The Y coordinate for the center of the blur.
y: f64, 0.5,
), ),
); );
@ -106,13 +152,20 @@ gegl_operation!(
gegl_name: "maze", gegl_name: "maze",
append_crop: false, append_crop: false,
values: ( values: (
algorithm_type: MazeAlgorithmType, MazeAlgorithmType::DepthFirst, "Maze algorithm type", /// Maze algorithm type
bg_color: String, "#fff".to_string(), "The background color.", algorithm_type: MazeAlgorithmType, MazeAlgorithmType::DepthFirst,
fg_color: String, "#000".to_string(), "The foreground color.", /// The background color.
seed: f64, 0.0, "The random seed.", bg_color: String, "#fff".to_string(),
tileable: bool, false, "Whether the maze should be tileable.", /// The foreground color.
x: i64, 16, "Horizontal width of cells pixels.", fg_color: String, "#000".to_string(),
y: i64, 16, "Vertical width of cells pixels.", /// The random seed.
seed: f64, 0.0,
/// Whether the maze should be tileable.
tileable: bool, false,
/// Horizontal width of cells pixels.
x: i64, 16,
/// Vertical width of cells pixels.
y: i64, 16,
), ),
); );
@ -121,12 +174,19 @@ gegl_operation!(
gegl_name: "median-blur", gegl_name: "median-blur",
append_crop: false, append_crop: false,
values: ( values: (
abyss_policy: MedianBlurAbyssPolicy, MedianBlurAbyssPolicy::Clamp, "How image edges are handled.", /// How image edges are handled.
alpha_percentile: f64, 50.0, "Neighborhood alpha percentile.", abyss_policy: MedianBlurAbyssPolicy, MedianBlurAbyssPolicy::Clamp,
high_precision: bool, false, "Avoid clipping and quantization", /// Neighborhood alpha percentile.
neighborhood: MedianBlurNeighborhood, MedianBlurNeighborhood::Circle, "Neighborhood type.", alpha_percentile: f64, 50.0,
percentile: f64, 50.0, "Neighborhood color percentile.", /// Avoid clipping and quantization
radius: f64, 3.0, "Neighborhood radius, a negative value will calculate with inverted percentiles.", high_precision: bool, false,
/// Neighborhood type.
neighborhood: MedianBlurNeighborhood, MedianBlurNeighborhood::Circle,
/// Neighborhood color percentile.
percentile: f64, 50.0,
/// Neighborhood radius, a negative value will calculate with inverted
/// percentiles.
radius: f64, 3.0,
), ),
); );
@ -135,19 +195,32 @@ gegl_operation!(
gegl_name: "mirrors", gegl_name: "mirrors",
append_crop: false, append_crop: false,
values: ( values: (
clip: bool, true, "Clip result to input size.", /// Clip result to input size.
c_x: f64, 0.5, "X coordinate of symmetry center in output.", clip: bool, true,
c_y: f64, 0.5, "Y coordinate of symmetry center in output.", /// X coordinate of symmetry center in output.
input_scale: f64, 100.0, "Scale factor to make rendering size bigger.", c_x: f64, 0.5,
m_angle: f64, 0.0, "Rotation applied to the mirrors.", /// Y coordinate of symmetry center in output.
n_segs: i64, 6, "Number of mirrors to use.", c_y: f64, 0.5,
output_scale: f64, 1.0, "Scale factor to make rendering size bigger.", /// Scale factor to make rendering size bigger.
o_x: f64, 0.0, "X axis ratio for the center of mirroring", input_scale: f64, 100.0,
o_y: f64, 0.0, "Y axis ratio for the center of mirroring", /// Rotation applied to the mirrors.
r_angle: f64, 0.0, "Rotation applied to the result.", m_angle: f64, 0.0,
trim_x: f64, 0.0, "X axis ratio for trimming mirror expanse", /// Number of mirrors to use.
trim_y: f64, 0.0, "Y axis ratio for trimming mirror expanse", n_segs: i64, 6,
warp: bool, true, "Fill full output area.", /// Scale factor to make rendering size bigger.
output_scale: f64, 1.0,
/// X axis ratio for the center of mirroring
o_x: f64, 0.0,
/// Y axis ratio for the center of mirroring
o_y: f64, 0.0,
/// Rotation applied to the result.
r_angle: f64, 0.0,
/// X axis ratio for trimming mirror expanse
trim_x: f64, 0.0,
/// Y axis ratio for trimming mirror expanse
trim_y: f64, 0.0,
/// Fill full output area.
warp: bool, true,
), ),
); );
@ -156,20 +229,34 @@ gegl_operation!(
gegl_name: "mosaic", gegl_name: "mosaic",
append_crop: false, append_crop: false,
values: ( values: (
antialiasing: bool, true, "Enables smoother tile output.", /// Enables smoother tile output.
color_averaging: bool, true, "Tile color based on average of subsumed pixels.", antialiasing: bool, true,
color_variation: f64, 0.2, "Magnitude of random color variations.", /// Tile color based on average of subsumed pixels.
joints_color: String, "#000".to_string(), "Joints color.", color_averaging: bool, true,
light_color: String, "#fff".to_string(), "Light color.", /// Magnitude of random color variations.
light_dir: f64, 135.0, "Direction of light-source (in degrees).", color_variation: f64, 0.2,
seed: f64, 0.0, "Random seed.", /// Joints color.
tile_allow_split: bool, true, "Allows splitting tiles at hard edges.", joints_color: String, "#000".to_string(),
tile_height: f64, 4.0, "Apparent height of each tile (in pixels).", /// Light color.
tile_neatness: f64, 0.65, "Deviation from perfectly formed tiles.", light_color: String, "#fff".to_string(),
tile_size: f64, 15.0, "Average diameter of each tile (in pixels).", /// Direction of light-source (in degrees).
tile_spacing: f64, 1.0, "Inter-tile spacing (in pixels).", light_dir: f64, 135.0,
tile_surface: bool, false, "Surface characteristics.", /// Random seed.
tile_type: MosaicTileType, MosaicTileType::Hexagons, "What shape to use for tiles.", seed: f64, 0.0,
/// Allows splitting tiles at hard edges.
tile_allow_split: bool, true,
/// Apparent height of each tile (in pixels).
tile_height: f64, 4.0,
/// Deviation from perfectly formed tiles.
tile_neatness: f64, 0.65,
/// Average diameter of each tile (in pixels).
tile_size: f64, 15.0,
/// Inter-tile spacing (in pixels).
tile_spacing: f64, 1.0,
/// Surface characteristics.
tile_surface: bool, false,
/// What shape to use for tiles.
tile_type: MosaicTileType, MosaicTileType::Hexagons,
), ),
); );
@ -178,24 +265,49 @@ gegl_operation!(
gegl_name: "newsprint", gegl_name: "newsprint",
append_crop: false, append_crop: false,
values: ( values: (
aa_samples: i64, 16, "Number of samples that are averaged for antialiasing the result.", /// Number of samples that are averaged for antialiasing the result.
angle: f64, 75.0, "Black angle.", aa_samples: i64, 16,
angle2: f64, 15.0, "Red and cyan angle.", /// Black angle.
angle3: f64, 45.0, "Green and magenta angle.", angle: f64, 75.0,
angle4: f64, 0.0, "Blue and yellow angle.", /// Red and cyan angle.
angleboost: f64, 0.0, "Multiplication factor for desired rotation of the local space for texture, the way this is computed makes it weak for desaturated colors and possibly stronger where there is color.", angle2: f64, 15.0,
black_pullout: f64, 1.0, "How much of common gray to pull out of CMY.", /// Green and magenta angle.
blocksize: f64, -1.0, "Number of periods per tile, this tiling avoids high frequency anomaly that angle boost causes.", angle3: f64, 45.0,
color_model: NewsprintColorModel, NewsprintColorModel::BlackOnWhite, "How many inks to use.", /// Blue and yellow angle.
pattern: NewsprintPattern, NewsprintPattern::Line, "Black halftoning/dot pattern to use.", angle4: f64, 0.0,
pattern2: NewsprintPattern, NewsprintPattern::Line, "Red and cyan halftoning/dot pattern to use.", /// Multiplication factor for desired rotation of the local space for
pattern3: NewsprintPattern, NewsprintPattern::Line, "Green and magenta halftoning/dot pattern to use.", /// texture, the way this is computed makes it weak for desaturated colors
pattern4: NewsprintPattern, NewsprintPattern::Line, "Blue and yellow halftoning/dot pattern to use.", /// and possibly stronger where there is color.
period: f64, 12.0, "Black number of pixels across one repetition of a base pattern at base resolution.", angleboost: f64, 0.0,
period2: f64, 12.0, "Red and cyan number of pixels across one repetition of a base pattern at base resolution.", /// How much of common gray to pull out of CMY.
period3: f64, 12.0, "Green and magenta number of pixels across one repetition of a base pattern at base resolution.", black_pullout: f64, 1.0,
period4: f64, 12.0, "Blue and yellow number of pixels across one repetition of a base pattern at base resolution.", /// Number of periods per tile, this tiling avoids high frequency anomaly
turbulence: f64, 0.0, "Color saturation dependent compression of period.", /// that angle boost causes.
blocksize: f64, -1.0,
/// How many inks to use.
color_model: NewsprintColorModel, NewsprintColorModel::BlackOnWhite,
/// Black halftoning/dot pattern to use.
pattern: NewsprintPattern, NewsprintPattern::Line,
/// Red and cyan halftoning/dot pattern to use.
pattern2: NewsprintPattern, NewsprintPattern::Line,
/// Green and magenta halftoning/dot pattern to use.
pattern3: NewsprintPattern, NewsprintPattern::Line,
/// Blue and yellow halftoning/dot pattern to use.
pattern4: NewsprintPattern, NewsprintPattern::Line,
/// Black number of pixels across one repetition of a base pattern at base
/// resolution.
period: f64, 12.0,
/// Red and cyan number of pixels across one repetition of a base pattern at
/// base resolution.
period2: f64, 12.0,
/// Green and magenta number of pixels across one repetition of a base pattern
/// at base resolution.
period3: f64, 12.0,
/// Blue and yellow number of pixels across one repetition of a base pattern
/// at base resolution.
period4: f64, 12.0,
/// Color saturation dependent compression of period.
turbulence: f64, 0.0,
), ),
); );
@ -204,9 +316,12 @@ gegl_operation!(
gegl_name: "noise-pick", gegl_name: "noise-pick",
append_crop: true, append_crop: true,
values: ( values: (
pct_random: f64, 50.0, "Randomization percentage.", /// Randomization percentage.
repeat: i64, 1, "Amount of repetitions to make.", pct_random: f64, 50.0,
seed: f64, 0.0, "Random seed.", /// Amount of repetitions to make.
repeat: i64, 1,
/// Random seed.
seed: f64, 0.0,
), ),
); );
@ -215,10 +330,14 @@ gegl_operation!(
gegl_name: "oilify", gegl_name: "oilify",
append_crop: false, append_crop: false,
values: ( values: (
exponent: i64, 8, "Exponent for processing, controls smoothness.", /// Exponent for processing, controls smoothness.
intensities: i64, 128, "Histogram size.", exponent: i64, 8,
mask_radius: i64, 4, "Radius of circle around pixel.", /// Histogram size.
use_inten: bool, true, "Use pixel luminance values.", intensities: i64, 128,
/// Radius of circle around pixel.
mask_radius: i64, 4,
/// Use pixel luminance values.
use_inten: bool, true,
), ),
); );
@ -227,12 +346,18 @@ gegl_operation!(
gegl_name: "plasma", gegl_name: "plasma",
append_crop: false, append_crop: false,
values: ( values: (
height: i64, 768, "Height of the generated buffer", /// Height of the generated buffer.
seed: f64, 0.0, "Random seed.", height: i64, 768,
turbulence: f64, 1.0, "High values give more variation in details.", /// Random seed.
width: i64, 1024, "Width of the generated buffer.", seed: f64, 0.0,
x: i64, 0, "X coordinate start of the generated buffer.", /// High values give more variation in details.
y: i64, 0, "Y coordinate start of the generated buffer.", turbulence: f64, 1.0,
/// Width of the generated buffer.
width: i64, 1024,
/// X coordinate start of the generated buffer.
x: i64, 0,
/// Y coordinate start of the generated buffer.
y: i64, 0,
), ),
); );
@ -241,8 +366,109 @@ gegl_operation!(
gegl_name: "simplex-noise", gegl_name: "simplex-noise",
append_crop: true, append_crop: true,
values: ( values: (
iterations: i64, 1, "The number of noise octaves.", /// The number of noise octaves.
scale: f64, 1.0, "The scale of the noise function.", iterations: i64, 1,
seed: f64, 1.0, "The random seed for the noise function.", /// The scale of the noise function.
scale: f64, 1.0,
/// The random seed for the noise function.
seed: f64, 1.0,
),
);
gegl_operation!(
struct_name: Softglow,
gegl_name: "softglow",
append_crop: false,
values: (
/// Brightness intensity.
brightness: f64, 0.3,
/// Glow radius.
glow_radius: f64, 10.0,
/// Sharpness of the highlights.
sharpness: f64, 0.85,
),
);
gegl_operation!(
struct_name: StereographicProjection,
gegl_name: "stereographic-projection",
append_crop: false,
values: (
/// Output/rendering height in pixels, -1 for input height.
height: i64, -1,
/// Do the inverse mapping.
inverse: bool, false,
/// Horizontal camera panning.
pan: f64, 0.0,
/// Image resampling method to use.
sampler_type: StereographicProjectionSamplerType, StereographicProjectionSamplerType::Nearest,
/// Spin angle around camera axis.
spin: f64, 0.,
/// Vertical camera panning.
tilt: f64, 90.,
/// Output/rendering width in pixels, -1 for input width.
width: i64, -1,
/// Zoom level.
zoom: f64, 100.0,
),
);
gegl_operation!(
struct_name: TileGlass,
gegl_name: "tile-glass",
append_crop: false,
values: (
/// Tile height.
tile_height: i64, 25,
/// Tile width.
tile_width: i64, 25,
),
);
gegl_operation!(
struct_name: TileSeamless,
gegl_name: "tile-seamless",
append_crop: false,
values: (,),
);
gegl_operation!(
struct_name: Waterpixels,
gegl_name: "waterpixels",
append_crop: false,
values: (
/// How to fill superpixels.
fill: WaterpixelsFill, WaterpixelsFill::Average,
/// Spatial regularization, trade-off between superpixel regularity and
/// adherence to object boundaries.
regularization: i64, 0,
/// Superpixels size.
size: i64, 32,
/// Gradient smoothness.
smoothness: f64, 1.0,
),
);
gegl_operation!(
struct_name: Waves,
gegl_name: "waves",
append_crop: true,
values: (
/// Amplitude of the wave ripples.
amplitude: f64, 25.0,
/// Aspect ratio.
aspect: f64, 1.0,
/// Limit deformation in the image area.
clamp: bool, false,
/// Period/wavelength of the ripples.
period: f64, 100.0,
/// Phase shift of the waves.
phi: f64, 0.0,
/// Mathematical method for reconstructing pixel values.
sampler_type: WavesSamplerType, WavesSamplerType::Cubic,
/// Center X coordinate to start the waves from.
x: f64, 0.5,
/// Center Y coordinate to start the waves from.
y: f64, 0.5,
), ),
); );

33
interlinked/Cargo.toml Normal file
View File

@ -0,0 +1,33 @@
# https://doc.rust-lang.org/cargo/reference/manifest.html
[package]
name = "interlinked"
description = "Generative art with GIMP, GEGL and ImageMagick."
repository = "https://git.bauke.xyz/driftingnebula/interlinked"
license = "AGPL-3.0-or-later"
version = "0.0.0"
authors = ["Bauke <me@bauke.xyz>"]
edition = "2021"
readme = "../README.md"
[lib]
path = "source/lib.rs"
[[bin]]
name = "interlinked"
path = "source/main.rs"
[lints]
workspace = true
[dependencies]
color-eyre = "0.6.2"
gegl = { path = "../gegl" }
subprocess = "0.2.9"
[dependencies.clap]
features = ["derive"]
version = "4.4.18"
[dev-dependencies]
insta = "1.34.0"

View File

@ -0,0 +1,21 @@
//! The [`clap`] command-line definitions.
mod run;
pub use {clap::Parser, run::*};
/// The Interlinked CLI.
#[derive(Debug, Parser)]
pub struct CliArgs {
/// Only render projects starting with the filter.
#[clap(short, long)]
pub filter: Option<String>,
/// Include default values in the GEGL graphs.
#[clap(long, default_value = "false")]
pub include_defaults: bool,
/// Don't render any images.
#[clap(long, default_value = "false")]
pub no_render: bool,
}

View File

@ -0,0 +1,123 @@
//! The CLI logic.
use {
crate::{all_projects, utilities::shell_command, CliArgs, Parser},
color_eyre::{eyre::OptionExt, Result},
gegl::GeglOperation,
std::{
fs::{create_dir_all, write},
path::Path,
time::Instant,
},
};
/// Run the CLI.
pub fn run() -> Result<()> {
let args = CliArgs::parse();
let projects = if let Some(filter) = args.filter {
all_projects()
.into_iter()
.filter(|project| project.name.starts_with(&filter))
.collect::<Vec<_>>()
} else {
all_projects().into_iter().collect()
};
let base_out_dir = Path::new("output/rust/");
for project in projects {
let start = Instant::now();
let (width, height) = project.resolution;
let out_dir = base_out_dir.join(&project.name);
create_dir_all(&out_dir)?;
println!(
"→ {} ({}x{}, {} base operations ({} including crops))",
project.name,
width,
height,
project.operations.len(),
project
.operations
.iter()
.map(|op| if op.append_crop_operation() { 2 } else { 1 })
.sum::<i32>(),
);
let graph = project
.operations
.into_iter()
.flat_map(|op| {
let mut graph = vec![op.graph(args.include_defaults)];
if op.append_crop_operation() {
graph.push(
gegl::Crop::default()
.with_height(height as f64)
.with_width(width as f64)
.graph(args.include_defaults),
)
}
graph
})
.collect::<Vec<_>>();
let pretty_graph = graph
.iter()
.map(|params| {
params
.iter()
.map(|param| {
if param.starts_with("gegl:") {
param.to_string()
} else {
format!(" {}", param)
}
})
.collect::<Vec<_>>()
.join("\n")
})
.collect::<Vec<_>>()
.join("\n\n");
let graph_file = out_dir.join(format!("{}.txt", project.name));
write(graph_file, pretty_graph)?;
if args.no_render {
let end = Instant::now();
println!("{:?} (not rendered)", end - start);
continue;
}
let out_file = out_dir.join(format!("{}.png", project.name));
let out_file = out_file
.to_str()
.ok_or_eyre("Failed to convert out_file to str")?;
let input = if project.create_input_image {
shell_command(format!(
"convert -size {}x{} xc:white {}",
width, height, out_file
))?;
format!("-i {}", out_file)
} else {
String::new()
};
let graph = graph
.into_iter()
.map(|op| op.join(" "))
.collect::<Vec<_>>()
.join(" ");
shell_command(format!("gegl {} -o {} -- {}", input, out_file, graph))?;
if project.turn_off_alpha {
shell_command(format!("convert {0} -alpha Off {0}", out_file))?;
}
let end = Instant::now();
println!("{:?}", end - start);
}
Ok(())
}

36
interlinked/source/lib.rs Normal file
View File

@ -0,0 +1,36 @@
//! # Interlinked.
//!
//! > **Generative art with GIMP, GEGL and ImageMagick.**
mod cli;
pub mod projects;
pub mod utilities;
use gegl::GeglOperation;
pub use {cli::*, projects::all_projects};
/// An individual project with all the operations to generate it.
#[derive(Debug)]
pub struct Project {
/// Whether to start from an empty input image.
///
/// Some operations require an input buffer to start from so this will create
/// an empty image with `imagemagick` and then use that as the input.
pub create_input_image: bool,
/// The name of this project.
pub name: String,
/// The list of operations.
pub operations: Vec<Box<dyn GeglOperation>>,
/// The resolution of the image as a tuple of width and height.
pub resolution: (i64, i64),
/// Whether to explicitly turn off the image's alpha channel after finishing
/// rendering the operations.
///
/// TODO: Explain why this exists after I've figured it out myself again. x)
pub turn_off_alpha: bool,
}

View File

@ -0,0 +1,7 @@
//! # Interlinked.
//!
//! > **Generative art with GIMP, GEGL and ImageMagick.**
fn main() -> color_eyre::Result<()> {
interlinked::run()
}

View File

@ -0,0 +1,10 @@
//! All [`Project`]s created with Interlinked.
use crate::Project;
pub mod year_2022;
/// Get all [`Project`]s in a single [`Vec`].
pub fn all_projects() -> Vec<Project> {
vec![year_2022::day_2022_03_06()]
}

View File

@ -0,0 +1,59 @@
//! The project made on 2022-03-06.
use {crate::Project, gegl::*};
/// The project made on 2022-03-06.
pub fn day_2022_03_06() -> Project {
Project {
create_input_image: false,
name: "2022-03-06".to_string(),
operations: vec![
SimplexNoise::default()
.with_scale(4.0)
.with_seed(2_071_140_406.0)
.boxed(),
Newsprint::default()
.with_color_model(NewsprintColorModel::Rgb)
.with_pattern2(NewsprintPattern::Line)
.with_period2(200.0)
.with_angle2(15.0)
.with_pattern3(NewsprintPattern::Line)
.with_period3(200.0)
.with_angle3(45.0)
.with_pattern4(NewsprintPattern::Line)
.with_period4(200.0)
.with_angle4(0.0)
.boxed(),
Mirrors::default().boxed(),
Softglow::default().boxed(),
Newsprint::default().boxed(),
StereographicProjection::default().with_tilt(123.0).boxed(),
FocusBlur::default()
.with_blur_radius(11.5)
.with_blur_type(FocusBlurType::Gaussian)
.with_midpoint(0.6)
.with_radius(0.9)
.boxed(),
Newsprint::default()
.with_color_model(NewsprintColorModel::Rgb)
.with_pattern2(NewsprintPattern::Diamond)
.with_period2(200.0)
.with_angle2(0.0)
.with_pattern3(NewsprintPattern::Diamond)
.with_period3(200.0)
.with_angle3(35.0)
.with_pattern4(NewsprintPattern::Diamond)
.with_period4(200.0)
.with_angle4(55.0)
.boxed(),
FocusBlur::default()
.with_blur_radius(11.5)
.with_blur_type(FocusBlurType::Gaussian)
.with_midpoint(0.6)
.with_radius(0.9)
.boxed(),
],
resolution: (1920, 1080),
turn_off_alpha: false,
}
}

View File

@ -0,0 +1,16 @@
//! Helper and utility functions.
use {
color_eyre::Result,
subprocess::{Exec, NullFile},
};
/// Run a command using [`subprocess`] and discard the output.
pub fn shell_command(command: String) -> Result<()> {
Exec::shell(command)
.stdout(NullFile)
.stderr(NullFile)
.capture()?;
Ok(())
}